sr2lua/television.lua

  1. ----------------------- 
  2. --  MISSION REPLAY   -- 
  3. ----------------------- 
  4.  
  5. Television_building_menu = 0 
  6.  
  7. ---------------------- 
  8. --	SYSTEM FUNCTIONS -- 
  9. ---------------------- 
  10.  
  11. --	Initialize the menu 
  12. function television_init() 
  13. 	television_build_all_menus() 
  14.  
  15. 	menu_store_use_hud(false) 
  16. 	menu_init() 
  17. 	 
  18. 	--Event Tracking 
  19. 	event_tracking_interface_enter("Crib Television") 
  20. 	 
  21. 	menu_horz_init(Television_horz) 
  22. 	 
  23. 	interface_effect_begin("pause") 
  24. end 
  25.  
  26. function television_build_all_menus() 
  27. 	-- build the menus dynamically 
  28. 	television_menu_build({"tssp-intro2", "tssp0"}, "HELP_CAT_PROL") 
  29. 	television_menu_build({"br"}, "GANG_NAME_TB") 
  30. 	television_menu_build({"ro"}, "GANG_NAME_TR") 
  31. 	television_menu_build({"ss"}, "GANG_NAME_SOS") 
  32. 	television_menu_build({"tsse"}, "HELP_CAT_EPI") 
  33. 	television_menu_build({"bon"}, "SLOT_EXTRAS") 
  34. 	television_menu_build({"video_games"}, "Videogames") 
  35. 	 
  36. 	local i = 0 
  37. 	 
  38. 	if Television_menus["tssp-intro2"] ~= nil then 
  39. 		Television_horz[i] = { 
  40. 			label = "HELP_CAT_PROL", 
  41. 			type = MENU_ITEM_TYPE_SUB_MENU, 
  42. 			sub_menu = Television_menus["tssp-intro2"] 
  43. 		} 
  44. 		 
  45. 		Television_menus["tssp-intro2"].on_back = television_exit 
  46. 		 
  47. 		i = i + 1 
  48. 	end 
  49. 	 
  50. 	if Television_menus["br"] ~= nil or Television_menus["ro"] ~= nil or Television_menus["ss"] ~= nil then 
  51. 		local j = 0 
  52. 		local gangs_menu = { 
  53. 			header_label_str = "HELP_CAT_GANGS", 
  54. 			on_back = television_exit, 
  55. 		} 
  56. 		 
  57. 		if Television_menus["br"] ~= nil then 
  58. 			gangs_menu[j] = { 
  59. 				label = "GANG_NAME_TB", 
  60. 				type = MENU_ITEM_TYPE_SUB_MENU, 
  61. 				sub_menu = Television_menus["br"] 
  62. 			} 
  63. 			 
  64. 			j = j + 1 
  65. 		end 
  66. 	 
  67. 		if Television_menus["ro"] ~= nil then 
  68. 			gangs_menu[j] = { 
  69. 				label = "GANG_NAME_TR", 
  70. 				type = MENU_ITEM_TYPE_SUB_MENU, 
  71. 				sub_menu = Television_menus["ro"] 
  72. 			} 
  73. 			 
  74. 			j = j + 1 
  75. 		end 
  76.  
  77. 		if Television_menus["ss"] ~= nil then 
  78. 			gangs_menu[j] = { 
  79. 				label = "GANG_NAME_SOS", 
  80. 				type = MENU_ITEM_TYPE_SUB_MENU, 
  81. 				sub_menu = Television_menus["ss"] 
  82. 			} 
  83. 			 
  84. 			j = j + 1 
  85. 		end 
  86. 		 
  87. 		gangs_menu.num_items = j 
  88.  
  89. 		Television_horz[i] = { 
  90. 			label = "HELP_CAT_GANGS", 
  91. 			type = MENU_ITEM_TYPE_SUB_MENU, 
  92. 			sub_menu = gangs_menu, 
  93. 		} 
  94. 		 
  95. 		i = i + 1 
  96. 	end 
  97. 	 
  98. 	if Television_menus["tsse"] ~= nil then 
  99. 		Television_horz[i] = { 
  100. 			label = "HELP_CAT_EPI", 
  101. 			type = MENU_ITEM_TYPE_SUB_MENU, 
  102. 			sub_menu = Television_menus["tsse"] 
  103. 		} 
  104. 		 
  105. 		Television_menus["tsse"].on_back = television_exit 
  106.  
  107. 		i = i + 1 
  108. 	end 
  109.  
  110. 	if Television_menus["bon"] ~= nil then 
  111. 		Television_horz[i] = { 
  112. 			label = "SLOT_EXTRAS", 
  113. 			type = MENU_ITEM_TYPE_SUB_MENU, 
  114. 			sub_menu = Television_menus["bon"] 
  115. 		} 
  116. 		 
  117. 		Television_menus["bon"].on_back = television_exit 
  118. 		 
  119. 		i = i + 1 
  120. 	end 
  121.  
  122. 	if Television_menus["video_games"] ~= nil then 
  123. 		Television_horz[i] = { 
  124. 			label = "Videogames", 
  125. 			type = MENU_ITEM_TYPE_SUB_MENU, 
  126. 			sub_menu = Television_menus["video_games"] 
  127. 		} 
  128. 		 
  129. 		Television_menus["video_games"].on_back = television_exit 
  130. 		 
  131. 		i = i + 1 
  132. 	end 
  133.  
  134. 	Television_horz.num_items = i 
  135. 	 
  136. 	debug_print("vint", "built "..i.." menus\n") 
  137. end 
  138.  
  139. -- Shutdown and cleanup the menu 
  140. function television_cleanup() 
  141. 	interface_effect_end() 
  142. end 
  143.  
  144. function television_exit() 
  145. 	dialog_box_confirmation("MENU_TITLE_WARNING", "STORE_EXIT_TELEVISION", "television_exit_confirm") 
  146. end 
  147.  
  148. function television_exit_confirm(result, action) 
  149. 	if action == DIALOG_ACTION_CLOSE and result == 0 then 
  150. 		menu_close(television_exit_final) 
  151. 	end 
  152. end 
  153.  
  154. function television_exit_final() 
  155. 	vint_document_unload(vint_document_find("television"))	 
  156. end 
  157.  
  158. ------------------------ 
  159. -- MENU FUNCTIONALITY -- 
  160. ------------------------ 
  161.  
  162. -- support 
  163. function television_consume_data(internal_name, display_name, prompt, close_on_activate) 
  164. 	local item = { 
  165. 		type = MENU_ITEM_TYPE_SELECTABLE, 
  166. 		internal_name = internal_name, 
  167. 		label = display_name, 
  168. 		close_on_activate = close_on_activate, 
  169. 		prompt = prompt, 
  170. 		on_select = television_scene_select, 
  171. 	} 
  172.  
  173. 	local i = Television_building_menu.num_items 
  174. 	Television_building_menu[i] = item 
  175. 	Television_building_menu.num_items = i + 1 
  176. end 
  177.  
  178. function television_menu_build(menu_name, display_name)	 
  179.  
  180. 	Television_building_menu = { num_items = 0 } 
  181. 	 
  182. 	for k, v in menu_name do 
  183. 		vint_dataresponder_request("television", "television_consume_data", 0, "list_scenes", v) 
  184. 	end 
  185. 		 
  186. 	if Television_building_menu.num_items ~= 0 then 
  187. 		Television_building_menu.header_label_str = display_name 
  188. 		Television_menus[menu_name[1]] = Television_building_menu 
  189. 	end 
  190. 	 
  191. 	Television_building_menu = 0 
  192. 	 
  193. 	interface_effect_begin("pause") 
  194. end 
  195.  
  196. function television_play_scene(scene_name) 
  197. 	interface_effect_end() 
  198.  
  199. 	local sf = vint_object_find("safe_frame") 
  200. 	local sf2 = vint_object_find("safe_frame", nil, MENU_BASE_DOC_HANDLE) 
  201. 	 
  202. 	menu_release_input() 
  203. 	vint_set_property(sf, "visible", false) 
  204. 	vint_set_property(sf2, "visible", false) 
  205. 	vint_dataresponder_request("television", "", 0, "start_scene", scene_name) 
  206. 	vint_set_property(sf, "visible", true) 
  207. 	vint_set_property(sf2, "visible", true) 
  208. 	menu_grab_input() 
  209. end 
  210.  
  211. function television_game_play_success(s) 
  212. 	if s == true then 
  213. 		menu_close(television_exit_final) 
  214. 	end 
  215. end 
  216.  
  217. function television_game_play_start(name) 
  218. 	vint_dataresponder_request("television", "television_game_play_success", 0, "start_scene", name) 
  219. end 
  220.  
  221. function television_replay_response(response, action) 
  222. 	if action == DIALOG_ACTION_CLOSE and response == DIALOG_RESULT_YES then  
  223. 		local item = Menu_active[Menu_active.highlighted_item] 
  224. 		 
  225. 		if item.close_on_activate == true then 
  226. 			thread_new("television_game_play_start", item.internal_name) 
  227. 		else 
  228. 			thread_new("television_play_scene", item.internal_name) 
  229. 		end 
  230. 	end 
  231. end 
  232.  
  233. function television_scene_select() 
  234. 	local item = Menu_active[Menu_active.highlighted_item] 
  235. 	dialog_box_confirmation("MISSION_COOP_REPLAY_PROMPT", item.prompt, "television_replay_response") 
  236. end 
  237.  
  238. --------------- 
  239. -- MENU DATA -- 
  240. --------------- 
  241.  
  242. -- all dynamically built 
  243. Television_menus = { } 
  244.  
  245. Television_horz = { num_items = 0 } 
  246.