sr2lua/crib_cust.lua

  1. ------------------------ 
  2. --	Crib Customization -- 
  3. ------------------------ 
  4.  
  5. -- "defines" 
  6. CRIB_CUST_GENERATE_CRIB_MENU 	= 0 
  7. CRIB_CUST_GENERATE_LEVEL_MENU = 1 
  8.  
  9. -- "globals" 
  10. Crib_cust_current_set_selected 	= 0	--	Current set menu if we're not on the main menu. 
  11. Crib_cust_current_item_selected 	= 0	--	Item selected when purchasing 
  12. Crib_cust_menu_add_index			= 0	--	Used to index the menu items when building 
  13.  
  14. ------------------------- 
  15. --	SYSTEMISH FUNCTIONS -- 
  16. ------------------------- 
  17. function crib_cust_init() 
  18. 	menu_store_init(true) 
  19. 	 
  20. 	menu_init() 
  21. 	 
  22. 	menu_horz_init(Crib_cust_horz_menu) 
  23. 	 
  24. 	crib_cust_build_crib_menu() 
  25.  
  26. 	local level, percent, bonus = pcu_purchase_slot(-1) 
  27. 	 
  28. 	--Event Tracking 
  29. 	event_tracking_interface_enter("Crib Customization") 
  30. end 
  31.  
  32. function crib_cust_cleanup() 
  33. end 
  34.  
  35. ----------------------------- 
  36. --	SELECTION FUNCTIONALITY -- 
  37. ----------------------------- 
  38. -- exit 
  39. function crib_cust_exit_final() 
  40. 	vint_document_unload(vint_document_find("crib_cust"))	 
  41. end 
  42.  
  43. function crib_cust_exit_confirm(result, action) 
  44. 	if action ~= DIALOG_ACTION_CLOSE then 
  45. 		return 
  46. 	end 
  47. 	 
  48. 	if result == 0 then 
  49. 		menu_close() 
  50. 		--menu_horz_close(crib_cust_exit_final) 
  51. 		--	These should probably be in menu_close and not menu_horz close. 
  52. 		menu_release_input() 
  53.  
  54. 		hud_hide(false) 
  55. 		crib_cust_exit_final() 
  56. 	end 
  57. end 
  58.  
  59. function crib_cust_exit(menu_data) 
  60. 	local body = "CRIB_CUST_EXIT_PROMPT" 
  61. 	local heading = "MENU_TITLE_WARNING" 
  62. 	 
  63. 	dialog_box_confirmation(heading, body, "crib_cust_exit_confirm") 
  64. end 
  65.  
  66. ----------------------- 
  67. --	Preview Functions -- 
  68. ----------------------- 
  69. function crib_cust_update_camera(menu_data) 
  70. 	crib_customization_update_camera(menu_data.highlighted_item) 
  71. end 
  72.  
  73. function crib_cust_update_preview(menu_data) 
  74. 	if Crib_cust_current_set_selected == 0 then 
  75. 		menu_input_block(true) 
  76. 	end 
  77. 	crib_customization_update_preview(Crib_cust_current_set_selected, Crib_cust_level_menu.highlighted_item) 
  78. 	menu_footer_update_style_footer(Crib_cust_level_menu[Crib_cust_level_menu.highlighted_item].price, Crib_cust_level_menu[Crib_cust_level_menu.highlighted_item].style, Crib_cust_level_menu[Crib_cust_level_menu.highlighted_item].can_afford) 
  79. 	if Crib_cust_level_menu[Crib_cust_level_menu.highlighted_item].price == 0 then 
  80. 		vint_set_property(Menu_footer_price_h, "text_tag", "STORE_ITEM_OWNED") 
  81. 		vint_set_property(Menu_footer_price_h, "tint", 0.88, 0.749, 0.05) 
  82. 		vint_set_property(Menu_footer_label_h, "visible", false) 
  83. 		vint_set_property(Menu_footer_style_h, "visible", false) 
  84. 	end 
  85. end 
  86.  
  87. function crib_cust_revert_unchanged_props(menu_data) 
  88. 	if Crib_cust_current_set_selected == 0 then 
  89. 		menu_input_block(true) 
  90. 	end 
  91. 	crib_customization_revert_prop(Crib_cust_current_set_selected) 
  92. 	menu_footer_remove_style_footer(menu_data) 
  93. 	menu_show(Menu_active.parent_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  94. 	audio_play(Menu_sound_back) 
  95. end 
  96.  
  97. ------------------- 
  98. --	MENU CREATION --  
  99. ------------------- 
  100. --	Trigger the Crib Menu to build 
  101. function crib_cust_build_crib_menu() 
  102. 	Crib_cust_menu_add_index = 0	--	Reset the index to add at. 
  103. 	--	Request the data, giving parameter 0 which is GENERATE_CRIB_MENU. 0 Records means return all. 
  104. 	vint_dataresponder_request("sr2_crib_store_data_responder", "crib_cust_add_items_crib_menu", 0, CRIB_CUST_GENERATE_CRIB_MENU) 
  105. 	Crib_cust_crib_menu.num_items = Crib_cust_menu_add_index --	After the request is finished, set the number of items 
  106. 	 
  107. end 
  108.  
  109. --	Callback function for the data request when building the crib menu 
  110. function crib_cust_add_items_crib_menu(label_str) 
  111. 	--	Add each menu item returned from the dataresponder to the menu. 
  112. 	Crib_cust_crib_menu[Crib_cust_menu_add_index] = { label = label_str, type = MENU_ITEM_TYPE_SUB_MENU, sub_menu = Crib_cust_level_menu, on_select = crib_cust_select_set, cust_item_index = Crib_cust_menu_add_index } 
  113. 	Crib_cust_menu_add_index = Crib_cust_menu_add_index + 1 --	Next index 
  114. end 
  115.  
  116. --	Same as creating the Crib Menu, but for each level of the items 
  117. function crib_cust_build_level_menu(menu_data) 
  118. 	crib_cust_update_item_list() 
  119. 	menu_footer_build_style_footer(menu_data)	--	Build the footer for respect/cost 
  120. 	crib_cust_update_preview(Crib_cust_level_menu)	--	Update the preview/price/style 
  121. end 
  122.  
  123. function crib_cust_update_item_list() 
  124. 	Crib_cust_menu_add_index = 0 
  125. 	Crib_cust_level_menu.highlighted_item = 0 
  126. 	vint_dataresponder_request("sr2_crib_store_data_responder", "crib_cust_add_items_level_menu", 0, CRIB_CUST_GENERATE_LEVEL_MENU, Crib_cust_current_set_selected) 
  127. 	Crib_cust_level_menu.num_items = Crib_cust_menu_add_index 
  128. end 
  129.  
  130. --	Callback for the level menu 
  131. function crib_cust_add_items_level_menu(label_str, cost, respect, is_disabled, is_affordable, is_current_level) 
  132. 	Crib_cust_level_menu[Crib_cust_menu_add_index] = {  
  133. 		label = label_str, type = MENU_ITEM_TYPE_SELECTABLE, on_select = crib_cust_select_level,  
  134. 		cust_item_index = Crib_cust_menu_add_index, price = cost, style = award_style("crib", cost, true),  
  135. 		enable = is_disabled, can_afford = is_affordable 
  136. 	} 
  137. 		 
  138. 	if is_current_level == true then 	--	Select the current level 
  139. 		Crib_cust_level_menu.highlighted_item = Crib_cust_menu_add_index 
  140. 	end 
  141. 	Crib_cust_menu_add_index = Crib_cust_menu_add_index + 1 
  142. end 
  143.  
  144. ------------------------ 
  145. --	MENU FUNCTIONALITY -- 
  146. ------------------------ 
  147.  
  148. --	When something is selected on the Crib menu, build the specific crib menu 
  149. function crib_cust_select_set(menu_label, menu_data) 
  150. 	Crib_cust_current_set_selected = menu_data.cust_item_index 
  151. 	Crib_cust_level_menu.header_label_str = menu_data.label 
  152. end 
  153.  
  154. -- purchase 
  155. function crib_cust_purchase_confirm(result, action) 
  156.  
  157. 	if action ~= DIALOG_ACTION_CLOSE then 
  158. 		return 
  159. 	end 
  160. 	 
  161. 	if result == 0 and action == 2 then 
  162. 		-- make the purchase 
  163. 		crib_customization_make_purchase(Crib_cust_current_set_selected, Crib_cust_current_item_selected.cust_item_index) -- C function 
  164. 		award_style("crib", Crib_cust_current_item_selected.price) 
  165.  
  166. 		crib_cust_update_item_list(Crib_cust_level_menu) 
  167. 		menu_show(Crib_cust_crib_menu, MENU_TRANSITION_SWEEP_RIGHT)	 
  168. 		 
  169. 		audio_play(Menu_sound_purchase) 
  170. 	end 
  171. end 
  172.  
  173. --	Show the dialog confirming the purchase 
  174. function crib_cust_select_level(menu_label, menu_data) 
  175. 	if Style_cluster_player_cash < menu_data.price then 
  176. 		dialog_box_message("MENU_TITLE_NOTICE", "HUD_SHOP_INSUFFICIENT_FUNDS") 
  177. 		return 
  178. 	end 
  179. --	if menu_data.disabled == true then 
  180. 	--	dialog_box_message("ERROR", "You already own this upgrade, or a better upgrade") 
  181. 	--	return 
  182. --	end 
  183. 	 
  184. 	Crib_cust_current_item_selected = menu_data 
  185. 	 
  186. 	if menu_data.price == 0 then 
  187. 		crib_customization_make_purchase(Crib_cust_current_set_selected, Crib_cust_current_item_selected.cust_item_index) -- C function 
  188. 		crib_cust_update_item_list(Crib_cust_level_menu) 
  189. 		menu_show(Crib_cust_crib_menu, MENU_TRANSITION_SWEEP_RIGHT)	 
  190. 	else 
  191. 		local insert = { [0] = Crib_cust_level_menu.header_label_str, [1] = format_cash(menu_data.price) } 
  192. 		local body = vint_insert_values_in_string("CRIB_CUSTOMIZE_PURCHASE_PROMPT", insert) 
  193. 		local heading = "MENU_TITLE_CONFIRM" 
  194. 		 
  195. 		dialog_box_confirmation(heading, body, "crib_cust_purchase_confirm") 
  196. 	end 
  197. end 
  198.  
  199. --------------- 
  200. --Button Tips 
  201. -------------- 
  202. Crib_cust_btn_tips = { 
  203. 	a_button 	= 	{ label = "CONTROL_SELECT", 	enabled = btn_tips_default_a, }, 
  204. 	b_button 	= 	{ label = "MENU_RESUME", 			enabled = btn_tips_default_a, }, 
  205. } 
  206.  
  207. Crib_cust_inner_btn_tips = { 
  208. 	a_button 	= 	{ label = "CONTROL_SELECT", 	enabled = btn_tips_default_a, }, 
  209. 	b_button 	= 	{ label = "MENU_BACK", 			enabled = btn_tips_default_a, }, 
  210. } 
  211.  
  212.  
  213. ---------------- 
  214. -- MAIN MENUS -- 
  215. ---------------- 
  216. Crib_cust_level_menu = {  
  217. 	header_label_str = "NONE", 
  218. 	on_back = crib_cust_revert_unchanged_props, 
  219. 	on_nav  = crib_cust_update_preview, 
  220. 	on_show = crib_cust_build_level_menu, 
  221. 	on_post_show = menu_footer_finalize_style_footer, 
  222. 	btn_tips = Crib_cust_inner_btn_tips, 
  223. 	footer_height = 40, 
  224. } 
  225.  
  226. Crib_cust_crib_menu = { 
  227. 	header_label_str = "CRIBS_TABLE_HEADER", 
  228. 	on_back = crib_cust_exit, 
  229. 	on_show = crib_cust_build_crib_menu, 
  230. 	on_nav  = crib_cust_update_camera, 
  231. 	btn_tips = Crib_cust_btn_tips, 
  232. } 
  233.  
  234. Crib_cust_horz_menu = { 
  235. 	num_items = 1, 
  236. 	current_selection = 0, 
  237. 	on_back = crib_cust_exit, 
  238.  
  239. 	[0] = { label = "CRIBS_TABLE_HEADER",	sub_menu = Crib_cust_crib_menu	}, 
  240. } 
  241.  
  242.  
  243.