sr2lua/garage.lua

  1. ---------------------- 
  2. -- GARAGE INTERFACE -- 
  3. ---------------------- 
  4. -- "global" variables 
  5.  
  6.  
  7. ---------------------- 
  8. --	SYSTEM FUNCTIONS -- 
  9. ---------------------- 
  10. --[ INITIALIZE AND SHUTDOWN ]-- 
  11. ------------------------------- 
  12. --	Initialize the menu 
  13. function garage_init() 
  14. 	--Event Tracking 
  15. 	event_tracking_interface_enter("Garage") 
  16.  
  17. 	menu_store_init(false) 
  18. 	menu_init() 
  19. 	menu_horz_init(Garage_vehicle_horz_menu) 
  20. end 
  21.  
  22. -- Shutdown and cleanup the menu 
  23. function garage_cleanup() 
  24. 	 
  25. end 
  26.  
  27. --[ EXIT ]-- 
  28. ------------ 
  29. function garage_exit(menu_data) 
  30. 	local body = "GARAGE_EXIT_PROMPT" 
  31. 	local heading = "MENU_TITLE_WARNING" 
  32. 	 
  33. 	dialog_box_confirmation(heading, body, "garage_exit_confirm") 
  34. end 
  35. function garage_exit_confirm(result, action) 
  36. 	if action ~= DIALOG_ACTION_CLOSE then 
  37. 		return 
  38. 	end 
  39. 	 
  40. 	if result == 0 then 
  41. 		menu_close(garage_exit_final) 
  42. 	end 
  43. end 
  44. function garage_exit_final() 
  45. 	vint_document_unload(vint_document_find("garage"))	 
  46. end 
  47.  
  48. ------------------------ 
  49. --	MENU FUNCTIONALITY -- 
  50. ------------------------ 
  51.  
  52. function garage_show(menu_data) 
  53. 	menu_data.num_items = 0 
  54. 	 
  55. 	vint_dataresponder_request("garage_populate", "garage_populate", 0) 
  56.  
  57. 	if menu_data.num_items == 0 then 
  58. 		menu_data.num_items = 1 
  59. 		menu_data.nothing = true 
  60. 		menu_data[0] = { label = "GARAGE_NONE", type = MENU_ITEM_TYPE_SELECTABLE } 
  61. 	end 
  62. end 
  63.  
  64. function garage_post_show(menu_data) 
  65. 	if menu_data.nothing == true then 
  66. 		return 
  67. 	end 
  68. 	 
  69. 	garage_preview_vehicle(menu_data[menu_data.highlighted_item].index) 
  70. end 
  71.  
  72. function garage_populate(vehicle_name, repair_cost, reward_vehicle, vehicle_index) 
  73. 	local num_items = Garage_menu.num_items 
  74. 	Garage_menu[num_items] = { label = vehicle_name, type = MENU_ITEM_TYPE_SELECTABLE, on_select = garage_show_vehicle_menu, repair_cost = repair_cost, reward_vehicle = reward_vehicle, index = vehicle_index } 
  75. 	Garage_menu.num_items = num_items + 1 
  76. end 
  77.  
  78. function garage_show_vehicle_menu() 
  79. 	if garage_get_repair_cost() == false then 
  80. 		return 
  81. 	end 
  82. 	 
  83. 	Garage_vehicle_menu.parent_menu = Menu_active 
  84. 	menu_show(Garage_vehicle_menu, MENU_TRANSITION_SWEEP_LEFT) 
  85. 	 
  86. end 
  87.  
  88. function garage_nav(menu_data) 
  89. 	if menu_data.nothing == true then 
  90. 		return 
  91. 	end 
  92.  
  93. 	local hl_item = menu_data.highlighted_item 
  94. 	garage_preview_vehicle(menu_data[hl_item].index) 
  95. end 
  96.  
  97. function garage_vehicle_show(menu_data) 
  98. 	local last_data = Menu_active[Menu_active.highlighted_item] 
  99. 	menu_data.header_label_str = last_data.label 
  100. 	local repair_cost = garage_get_repair_cost() 
  101. 	 
  102. 	if repair_cost ~= 0 then 
  103. 		local insert_values = { [0] = repair_cost } 
  104. 		local tag = vint_insert_values_in_string("GARAGE_REPAIR_RETRIEVE", insert_values) 
  105. 		menu_data[0].label = tag 
  106. 		menu_data[0].on_select = garage_repair_retrieve 
  107. 		menu_data[0].repair_cost = repair_cost 
  108. 	else 
  109. 		menu_data[0].label = "GARAGE_RETRIEVE_VEHICLE" 
  110. 		menu_data[0].on_select = garage_retrieve 
  111. 	end 
  112.  
  113. 	menu_data.highlighted_item = 0 
  114. end	 
  115.  
  116. function garage_retrieve_unrepaired(result, action) 
  117. 	if action ~= DIALOG_ACTION_CLOSE then 
  118. 		return 
  119. 	end 
  120. 	 
  121. 	if result == 0 then 
  122. 		garage_retrieve_vehicle() 
  123. 		menu_close(garage_exit_final) 
  124. 	else 
  125. 		menu_show(Garage_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  126. 		audio_play(Menu_sound_back) 
  127. 	end	 
  128. end 
  129.  
  130. function garage_repair_retrieve(menu_label, menu_data) 
  131. 	if Style_cluster_player_cash < menu_data.repair_cost then 
  132. 		dialog_box_confirmation("STORE_TITLE_INSUFFICIENT_FUNDS", "GARAGE_TEXT_INSUFFICIENT_FUNDS", "garage_retrieve_unrepaired") 
  133. 		return 
  134. 	end 
  135. 	 
  136. --[[ 
  137. 	local insert_values = { [0] = menu_data.repair_cost } 
  138. 	local tag = vint_insert_values_in_string("GARAGE_REPAIR_PROMPT", insert_values) 
  139. 	 
  140. 	dialog_box_confirmation("GARAGE_REPAIR", tag, "garage_repair_confirm")  
  141. ]] 
  142. 	garage_repair_vehicle() 
  143. 	garage_retrieve(menu_label, menu_data) 
  144. end 
  145.  
  146. function garage_retrieve(menu_label, menu_data) 
  147. 	garage_retrieve_vehicle() 
  148. 	menu_close(garage_exit_final) 
  149. end  
  150.  
  151. function garage_remove(menu_label, menu_data) 
  152. 	dialog_box_confirmation("MENU_TITLE_WARNING", "GARAGE_REMOVE_PROMPT", "garage_remove_confirm") 
  153. end 
  154. 	 
  155. function garage_remove_confirm(result, action) 
  156. 	if action ~= DIALOG_ACTION_CLOSE then 
  157. 		return 
  158. 	end 
  159. 	 
  160. 	if result == 0 then 
  161. 		garage_remove_vehicle() 
  162. 		menu_show(Garage_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  163. 		audio_play(Menu_sound_back) 
  164. 	end	 
  165. end 
  166.  
  167. --------------- 
  168. --Button Tips 
  169. -------------- 
  170. Garage_btn_tips = { 
  171. 	a_button 	= 	{ label = "CONTROL_SELECT", 	enabled = btn_tips_default_a, }, 
  172. 	b_button 	= 	{ label = "MENU_RESUME", 			enabled = btn_tips_default_a, }, 
  173. } 
  174.  
  175. Garage_inner_btn_tips = { 
  176. 	a_button 	= 	{ label = "CONTROL_SELECT", 	enabled = btn_tips_default_a, }, 
  177. 	b_button 	= 	{ label = "MENU_BACK", 			enabled = btn_tips_default_a, }, 
  178. } 
  179.  
  180.  
  181. --------------- 
  182. -- MENU DATA -- 
  183. --------------- 
  184. Garage_vehicle_menu = { 
  185. 	header_label_str = "NONE", 
  186. 	on_show = garage_vehicle_show, 
  187. 	btn_tips = Garage_inner_btn_tips, 
  188. 	num_items = 2, 
  189.  
  190. 	[0] = { label = "GARAGE_REPAIR_RETRIEVE", type = MENU_ITEM_TYPE_SELECTABLE, on_select = garage_repair_retrieve }, 
  191. 	[1] = { label = "GARAGE_REMOVE_VEHICLE", type = MENU_ITEM_TYPE_SELECTABLE, on_select = garage_remove }, 
  192. } 
  193.  
  194. Garage_menu = { 
  195. 	header_label_str = "GARAGE_CRIB_NAME", 
  196. 	on_show 	  		= garage_show, 
  197. 	on_post_show 	= garage_post_show, 
  198. 	on_nav			= garage_nav,  
  199. 	on_back			= garage_exit, 
  200. 	btn_tips			= Garage_btn_tips, 
  201. 	num_items  		= 0, 
  202. } 
  203.  
  204. Garage_vehicle_horz_menu = { 
  205. 	num_items = 1, 
  206. 	current_selection = 0, 
  207. 	on_back = garage_exit, 
  208.  
  209. 	[0] = { label = "GARAGE_CRIB_NAME",	sub_menu = Garage_menu	}, 
  210. } 
  211.