./store_vendor.lua

  1. local STORE_VENDOR_LOA_DUST = 0 
  2. local STORE_VENDOR_BSOD = 1 
  3. local STORE_VENDOR_ALLEY_JUICE = 2 
  4. local STORE_VENDOR_BATH_SALTS = 3 
  5.  
  6. local Data = { 
  7. 	[STORE_VENDOR_LOA_DUST] = { 
  8. 		title = "LOA DUST", 
  9. 		image = "ui_vend_loa_dust", 
  10. 		price = 100, 
  11. 		desc = "Smoke a bulb.  Walk through walls."	 
  12. 	}, 
  13. 	[STORE_VENDOR_BSOD] = { 
  14. 		title = "BSOD", 
  15. 		image = "ui_vend_bsod", 
  16. 		price = 120, 
  17. 		desc = "Expose the errors of the Dominatrix.  Go on a text adventure."	 
  18. 	}, 
  19. 	[STORE_VENDOR_ALLEY_JUICE] = { 
  20. 		title = "ALLEY JUICE", 
  21. 		image = "ui_vend_alley_juice", 
  22. 		price = 20, 
  23. 		desc = "Do you trust it?  Peds become transformed."	 
  24. 	}, 
  25. 	[STORE_VENDOR_BATH_SALTS] = { 
  26. 		title = "BATH SALTS", 
  27. 		image = "ui_vend_bath_salts", 
  28. 		price = 80, 
  29. 		desc = "Dispose of human shields in a face melting way."	 
  30. 	}, 
  31. } 
  32.  
  33.  
  34. local Store_vendor_doc_handle = -1 
  35. local Input_tracker = -1 
  36. local Buttons_h = {} 
  37. local Curr_index = 0 
  38. local Num_items = 0 
  39. local Audio_intro_h = -1 
  40.  
  41. function store_vendor_init() 
  42. 	Store_vendor_doc_handle = vint_document_find("store_vendor") 
  43. 	 
  44. 	Input_tracker = Vdo_input_tracker:new() 
  45. 	 
  46. 	--lock inputs until intro anim is finished 
  47. 	Input_tracker:add_input("all_unassigned", "store_vendor_grid_nav_do_nothing", 50)	 
  48. 	Input_tracker:subscribe(true) 
  49.  
  50. 	--set hints 
  51. 	local hint_data = { 
  52. 		{CTRL_MENU_BUTTON_A, "PURCHASE"}, 
  53. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  54. 	} 
  55. 	local hint_bar = Vdo_hint_bar:new("hint_bar", 0, Store_vendor_doc_handle) 
  56. 	hint_bar:set_hints(hint_data) 
  57. 	 
  58. 	--display cash 
  59. 	vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "store_vendor_cash_update")	 
  60. 	 
  61. 	--draw grid 
  62. 	store_vendor_grid_draw_items(Data, 0) 
  63. 	store_vendor_grid_set_highlight() 
  64. 	 
  65. 	--load peg 
  66. 	pause_map_dump() 
  67. 	 
  68. 	--FOR TEST ONLY 
  69. 	thread_new("store_vendor_test") 
  70. 	 
  71. 	--setup screen initial state 
  72. 	local intro_anim_h = vint_object_find("intro_anim") 
  73. 	local end_event_twn_h = vint_object_find("end_event_twn", intro_anim_h) 
  74. 	vint_set_property(end_event_twn_h, "end_event", "store_vendor_unlock_inputs") 
  75. 	vint_apply_start_values(intro_anim_h) 
  76. end 
  77.  
  78.  
  79. function store_vendor_test() 
  80. 	delay(.005) 
  81. 	store_vendor_peg_load() 
  82. end 
  83.  
  84. function store_vendor_cleanup() 
  85. 	game_peg_unload("ui_bms_store_vend") 
  86. 	pause_map_restore() 
  87. end 
  88.  
  89.  
  90. function store_vendor_peg_load() 
  91. 	game_peg_load_with_cb("store_vendor_play_intro", 1, "ui_bms_store_vend") 
  92. end 
  93.  
  94.  
  95. function store_vendor_play_intro() 
  96. 	local intro_anim_h = vint_object_find("intro_anim") 
  97. 	 
  98. 	lua_play_anim(intro_anim_h) 
  99. 	 
  100. 	Audio_intro_h = audio_object_post_event("Drug_Dealer_VO",nil,nil,nil,false) 
  101. end 
  102.  
  103.  
  104. function store_vendor_unlock_inputs() 
  105. 	Input_tracker:add_input("nav_left", "store_vendor_grid_nav_left", 50)	 
  106. 	Input_tracker:add_input("nav_right", "store_vendor_grid_nav_right", 50)	 
  107. 	Input_tracker:add_input("back", "store_vendor_exit", 50)	 
  108. 	Input_tracker:add_input("select", "store_vendor_purchase_item", 50)	 
  109. 	Input_tracker:subscribe(true) 
  110. end 
  111.  
  112.  
  113. function store_vendor_exit() 
  114. 	local outro_anim_h = vint_object_find("outro_anim")		 
  115. 	local outro_event_twn_h = vint_object_find("end_event_twn", outro_anim_h) 
  116. 	 
  117. 	vint_set_property(outro_event_twn_h, "end_event", "store_vendor_exit_anim_complete")	 
  118. 	 
  119. 	lua_play_anim(outro_anim_h) 
  120. 	 
  121. 	audio_stop(Audio_intro_h) 
  122. end 
  123.  
  124. function store_vendor_exit_anim_complete() 
  125. 	Input_tracker:subscribe(false) 
  126. 	pop_screen() 
  127. end 
  128.  
  129.  
  130. function store_vendor_purchase_item()	 
  131. 	if Curr_index >= STORE_VENDOR_LOA_DUST and Curr_index <= STORE_VENDOR_BATH_SALTS then 
  132. 		--call c to make purchase 
  133. 		store_vendor_purchase(Curr_index) 
  134. 		 
  135. 		ui_audio_post_event("Drug_Dealer_Purchase") 
  136. 		 
  137. 		store_vendor_exit() 
  138. 	end 
  139. end 
  140.  
  141.  
  142. function store_vendor_cash_update(di_h) 
  143. 	local cash = vint_dataitem_get(di_h) 
  144. 	local cash_txt_h = vint_object_find("cash_txt", 0, Store_vendor_doc_handle) 
  145. 	 
  146. 	vint_set_property(cash_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(cash))	 
  147. end 
  148.  
  149.  
  150. function store_vendor_grid_draw_items(data, index) 
  151. 	local base_button_grp_h = vint_object_find("base_button_grp") 
  152. 	local base_button_x, base_button_y = vint_get_property(base_button_grp_h, "anchor") 
  153. 	 
  154. 	Buttons_h = {} 
  155. 	Num_items = #data	 
  156. 	Curr_index = index 
  157. 	 
  158. 	local GRID_SPACE = 120 
  159. 	 
  160. 	for i = 0, Num_items do 
  161. 		--clone button 
  162. 		Buttons_h[i] = vint_object_clone(base_button_grp_h)		 
  163. 		local button_img_h = vint_object_find("button_img", Buttons_h[i]) 
  164. 						 
  165. 		--set image 
  166. 		vint_set_property(button_img_h, "image", data[i].image) 
  167. 		 
  168. 		--position button 
  169. 		local new_x = base_button_x + (GRID_SPACE * i)				 
  170. 		vint_set_property(Buttons_h[i], "anchor", new_x, base_button_y) 
  171. 	end	 
  172. 	 
  173. 	vint_set_property(base_button_grp_h, "visible", false)	 
  174. end 
  175.  
  176.  
  177. function store_vendor_grid_move_cursor(direction) 
  178. 	--updated index		 
  179. 	Curr_index = Curr_index + direction 
  180. 	 
  181. 	--handle wrapping 
  182. 	if Curr_index > Num_items then 
  183. 		Curr_index = 0 
  184. 	elseif Curr_index < 0 then 
  185. 		Curr_index = Num_items 
  186. 	end	 
  187. 	 
  188. 	--call set highlight 
  189. 	store_vendor_grid_set_highlight() 
  190. end 
  191.  
  192.  
  193. function store_vendor_grid_set_highlight() 
  194. 	local highlight_grp_h = vint_object_find("button_highlight_grp") 
  195. 	 
  196. 	--position highlight 
  197. 	local button_x, button_y = vint_get_property(Buttons_h[Curr_index],"anchor") 
  198. 	vint_set_property(highlight_grp_h, "anchor", button_x, button_y) 
  199. 	 
  200. 	--scale highlighted item and reset scale of all other images 
  201. 	for i = 0, Num_items do 
  202. 		local button_img_h = vint_object_find("button_img", Buttons_h[i]) 
  203. 		 
  204. 		if i == Curr_index then 
  205. 			vint_set_property(button_img_h, "scale", 1.2,1.2) 
  206. 		else 
  207. 			vint_set_property(button_img_h, "scale", 1.0,1.0) 
  208. 		end 
  209. 	end 
  210. 	 
  211. 	--update info 
  212. 	local title_txt_h = vint_object_find("title_txt", 0, Store_vendor_doc_handle) 
  213. 	local price_txt_h = vint_object_find("price_txt", 0, Store_vendor_doc_handle) 
  214. 	local desc_txt_h = vint_object_find("desc_txt", 0, Store_vendor_doc_handle) 
  215.  
  216. 	vint_set_property(title_txt_h, "text_tag", Data[Curr_index].title)	 
  217. 	vint_set_property(price_txt_h, "text_tag", "{GAME_CASH}" .. format_cash(Data[Curr_index].price)) 
  218. 	vint_set_property(desc_txt_h, "text_tag", Data[Curr_index].desc)	 
  219. 	 
  220. 	--play audio 
  221. 	game_UI_audio_play("UI_Cell_Nav") 
  222. end 
  223.  
  224.  
  225. function store_vendor_grid_nav_left() 
  226. 	store_vendor_grid_move_cursor(-1) 
  227. end 
  228.  
  229.  
  230. function store_vendor_grid_nav_right() 
  231. 	store_vendor_grid_move_cursor(1) 
  232. end 
  233.  
  234. function store_vendor_grid_nav_do_nothing() 
  235. end 
  236.