./cell_menu_main.lua

  1. local Data = { 
  2. 	[ID_MAP] = { 
  3. 		label = "MENU_MAP", 
  4. 		icon = "ui_cell_icon_map" 
  5. 	}, 
  6. 	[ID_MISSIONS] = { 
  7. 		label = "MENU_MISSIONS", 
  8. 		icon = "ui_cell_icon_missions" 
  9. 	},	 
  10. 	[ID_SAINTSBOOK] = { 
  11. 		label = "MENU_SAINTS_BOOK", 
  12. 		icon = "ui_cell_icon_saintsbook", 
  13. 		can_wrap = false 
  14. 	}, 
  15. 	[ID_REWARDS] = { 
  16. 		label = "MENU_UPGRADES", 
  17. 		icon = "ui_cell_icon_rewards" 
  18. 	}, 
  19. 	[ID_MUSIC] = { 
  20. 		label = "MENU_MUSIC", 
  21. 		icon = "ui_cell_icon_music" 
  22. 	},	 
  23. 	[ID_CAMERA] = { 
  24. 		label = "MENU_CAMERA", 
  25. 		icon = "ui_cell_icon_camera" 
  26. 	}, 
  27. 	[ID_PHONE] = { 
  28. 		label = "MENU_PHONE", 
  29. 		icon = "ui_cell_icon_phone" 
  30. 	}, 
  31. 	[ID_CASH] = { 
  32. 		label = "COMPLETION_CASH", 
  33. 		icon = "ui_cell_icon_cash",		 
  34. 	}, 
  35. 	[ID_EXTRAS] = { 
  36. 		label = "MENU_EXTRAS", 
  37. 		icon = "ui_cell_icon_extras" 
  38. 	},	 
  39. 		 
  40. } 
  41.  
  42. local Menu 
  43. local Hint_bar 
  44. local Input_tracker 
  45. local Mouse_input_tracker 
  46. local Cell_menu_main_doc_h = -1 
  47. local New_item_idx = 0 
  48. local Current_idx = 0 
  49. local Found_homie = false 
  50. local Online_check_thread = -1 
  51.  
  52. Cell_rewards_to_map = false 
  53.  
  54. -- Used by a data responder to indicate there is at least one eligible homie to be called from the cell phone 
  55. function cell_phone_found_homie() 
  56. 	Found_homie = true 
  57. end 
  58.  
  59. function populate_data_is_enabled() 
  60.  
  61. 	Found_homie = false 
  62.  
  63. 	-- Data request for homies in cell phone - if there are none, disable that screen 
  64. 	vint_dataresponder_request("cell_phone_pad_populate", "cell_phone_found_homie", 0, 0)	 
  65.  
  66. 	if Found_homie == false then 
  67. 		Data[ID_PHONE].is_enabled = false 
  68. 	end 
  69. 	 
  70. 	-- cannot do missions in machina mode 
  71. 	if cell_machinima_is_recording() then 
  72. 		Data[ID_MISSIONS].is_enabled = false	 
  73. 	end 
  74. 	 
  75. 	-- camera allowed 
  76. 	if cell_allow_camera() == false then 
  77. 		Data[ID_CAMERA].is_enabled = false 
  78. 	end 
  79. 	 
  80. 	if Data[ID_MISSIONS].new_items == 0 then 
  81. 		Data[ID_MISSIONS].is_enabled = false 
  82. 	end 
  83. 	 
  84. 	-- non-release_final functionality to allow buttons on test levels 
  85. 	if cell_debug_all_enabled() then 
  86. 		return 
  87. 	end 
  88. 	 
  89. 	if (game_get_in_progress_type() == 1) then -- 1 = Activities 
  90. 		Data[ID_PHONE].is_enabled = false 
  91. 	end 
  92. 	 
  93. 	-- disable based on mission completion 
  94. 	if cell_is_mission_complete("m03") then 
  95. 		-- nothing locked 
  96. 	elseif cell_is_mission_complete("m02") then 
  97. 		-- lock saints book 
  98. 		Data[ID_SAINTSBOOK].is_enabled = false 
  99. 	else 
  100. 		-- lock map, missions, saints book, upgrades, music, and phone 
  101. 		Data[ID_MAP].is_enabled = false 
  102. 		Data[ID_MISSIONS].is_enabled = false 
  103. 		Data[ID_SAINTSBOOK].is_enabled = false 
  104. 		Data[ID_REWARDS].is_enabled = false 
  105. 		Data[ID_MUSIC].is_enabled = false 
  106. 		Data[ID_PHONE].is_enabled = false 
  107. 		Data[ID_CASH].is_enabled = false 
  108. 	end	 
  109. 	 
  110. 	--Verify that saintsbook is not enabled... 
  111. 	if sb_saintsbook_is_available() == false then 
  112. 		Data[ID_SAINTSBOOK].is_enabled = false 
  113. 	end 
  114. 	 
  115. 	-- if the map is disabled for mission or some other state, don't allow it 
  116. 	if cell_is_map_disabled() then 
  117. 		Data[ID_MAP].is_enabled = false		 
  118. 	end 
  119. end 
  120.  
  121.  
  122. function cell_menu_main_init() 
  123. 	-- Find our documents... 
  124. 	Cell_menu_main_doc_h = vint_document_find("cell_menu_main") 
  125. 	--Hide safe frame... 
  126. 	local safe_frame_h = vint_object_find("safe_frame", 0, Cell_menu_main_doc_h) 
  127. 	vint_set_property(safe_frame_h, "visible", false) 
  128. 	 
  129. 	-- Setup input tracker.+ 
  130. 	Input_tracker = Vdo_input_tracker:new() 
  131. 	Input_tracker:add_input("map", "cell_menu_main_button_b", 50) 
  132. 	Input_tracker:add_input("select", "cell_menu_main_button_a", 50) 
  133. 	Input_tracker:add_input("back", "cell_menu_main_button_b", 50) 
  134. 	Input_tracker:add_input("nav_up", "cell_menu_main_nav_up", 50) 
  135. 	Input_tracker:add_input("nav_down", "cell_menu_main_nav_down", 50) 
  136. 	Input_tracker:add_input("nav_left", "cell_menu_main_nav_left", 50) 
  137. 	Input_tracker:add_input("nav_right", "cell_menu_main_nav_right", 50) 
  138.  
  139. 	-- Setup Button Hints 
  140. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Cell_menu_main_doc_h) 
  141. 	local hint_data = { 
  142. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  143. 	} 
  144. 	Hint_bar:set_hints(hint_data)  
  145. 	 
  146. 	game_UI_audio_play("UI_Cell_Activate") 
  147.  
  148. 	vint_dataresponder_request("cell_menu_main_new_items", "cell_menu_main_set_new", 0) 
  149. 	vint_dataresponder_request("cell_menu_state_dr", "cell_menu_handle_state", 0)	 
  150. 	 
  151. 	-- Populate Data::is_enabled fields 
  152. 	-- Do this after above data responder requests, as new item count may determine button availability 
  153. 	populate_data_is_enabled()	 
  154. 	 
  155. 	Menu = Vdo_cell_menu:new("cell_menu") 
  156. 	Menu:populate_menu(Data) 
  157.  
  158. 	if game_get_platform() == "PC" then 
  159. 		Hint_bar:set_visible(true)	 
  160. 		Hint_bar:set_highlight(0) 
  161. 		 
  162. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  163. 		Menu:add_mouse_inputs("cell_menu_main", Mouse_input_tracker) 
  164. 		Hint_bar:add_mouse_inputs("cell_menu_main", Mouse_input_tracker) 
  165. 		Mouse_input_tracker:subscribe(false) 
  166. 	end 
  167. 	 
  168. 	Cell_rewards_to_map = false 
  169. end 
  170.  
  171. function cell_menu_main_cleanup() 
  172. 	if Online_check_thread ~= -1 then 
  173. 		thread_kill(Online_check_thread) 
  174. 	end 
  175. 	 
  176. 	-- Nuke all button subscriptions 
  177. 	Input_tracker:subscribe(false) 
  178. 	 
  179. 	if Mouse_input_tracker ~= nil then 
  180. 		Mouse_input_tracker:subscribe(false) 
  181. 	end 
  182. end 
  183.  
  184. function cell_menu_main_nav_up(event, acceleration) 
  185. 	Menu:nav_up() 
  186. end 
  187.  
  188. function cell_menu_main_nav_down(event, acceleration) 
  189. 	Menu:nav_down() 
  190. end 
  191.  
  192. function cell_menu_main_nav_left(event, acceleration) 
  193. 	Menu:nav_left() 
  194. end 
  195.  
  196. function cell_menu_main_nav_right(event, acceleration) 
  197. 	Menu:nav_right() 
  198. end 
  199.  
  200. function cell_menu_main_out(event, acceleration) 
  201. 	-- 2nd pop for cell_foreground doc 
  202. 	pop_screen() 
  203. 	pop_screen() 
  204. end 
  205.  
  206. function cell_menu_main_button_b(event, acceleration) 
  207. 	cell_menu_main_lost_focus() 
  208. 	cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_MAIN, cell_menu_main_out) 
  209.  
  210. 	game_UI_audio_play("UI_Cell_Close") 
  211. end 
  212.  
  213. function cell_menu_main_button_a(event, acceleration) 
  214. 		 
  215. 	--TODO: Check to see if tween is done before you move to next screen. 
  216. 	 
  217. 	local current_id = Menu:get_id() 
  218. 	 
  219. 	-- Pause_map_from_menu is initialized in cell_foreground	 
  220. 	Pause_map_from_menu = true 
  221. 	Rewards_from_menu = true 
  222. 	Missions_from_menu = true 
  223. 	 
  224. 	cell_menu_handle_state(current_id) 
  225. end 
  226.  
  227. function cell_menu_main_mouse_click(event, target_handle) 
  228. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  229. 	if hint_index == 1 then 
  230. 		cell_menu_main_button_b() 
  231. 	end 
  232. 	 
  233. 	-- If the target_handle matches a button, activate it 
  234. 	if Menu:select_button(target_handle) == true then 
  235. 		cell_menu_main_button_a() 
  236. 	end 
  237. end 
  238.  
  239. function cell_menu_main_mouse_move(event, target_handle)	 
  240. 	Hint_bar:set_highlight(0) 
  241. 	 
  242. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  243. 	if hint_index ~= 0 then 
  244. 		Hint_bar:set_highlight(hint_index) 
  245. 		game_UI_audio_play("UI_Cell_Nav") 
  246. 	end 
  247. 	 
  248. 	-- If the target_handle matches a button, highlight it and play a sound 
  249. 	if Menu:select_button(target_handle) == true then 
  250. 		game_UI_audio_play("UI_Cell_Nav") 
  251. 	end 
  252. end 
  253.  
  254. function cell_menu_check_online_for_camera() 
  255. 	online_and_privilege_validator_begin(false, true, true, false, true)	-- Check we're signed in and we have content permissions 
  256. 	while Online_validator_result == ONLINE_VALIDATOR_IN_PROGRESS do 
  257. 		thread_yield() 
  258. 	end 
  259. 			 
  260. 	cell_menu_main_unlock_controls() 
  261. 	 
  262. 	if Online_validator_result ~= ONLINE_VALIDATOR_PASSED then 
  263. 		return 
  264. 	end 
  265. 		 
  266. 	if main_menu_check_user_content() == false then 
  267. 		dialog_box_message("MENU_TITLE_WARNING", "USER_CONTENT_PRIV_DENIED") 
  268. 		return 
  269. 	end 
  270. 	 
  271. 	push_screen("cell_camera") 
  272. 	Online_check_thread = -1 
  273. end 
  274.  
  275. function cell_menu_handle_state(state) 
  276.  
  277. 	-- Don't push on a new screen if we've asked this one to close 
  278. 	if cell_is_closing() then 
  279. 		return 
  280. 	end 
  281.  
  282. 	-- If we are in a different state than -1, then we need the phone to "load that application" 
  283. 	 
  284. 	--Lose focus... 
  285. 	cell_menu_main_lost_focus() 
  286. 	 
  287. 	Current_idx = state 
  288. 	 
  289. 	if state == ID_MAP then 
  290. 		push_screen("pause_map") 
  291. 		game_UI_audio_play("UI_Cell_Select") 
  292. 	elseif state == ID_MISSIONS then 
  293. 		push_screen("cell_missions") 
  294. 		game_UI_audio_play("UI_Cell_Select") 
  295. 	elseif state == ID_SAINTSBOOK then 
  296. 		push_screen("cell_saintsbook")		 
  297. 		game_UI_audio_play("UI_Cell_Select")			 
  298. 	elseif state == ID_REWARDS then 
  299. 		push_screen("cell_rewards")		 
  300. 		game_UI_audio_play("UI_Cell_Select") 
  301. 	elseif state == ID_MUSIC then 
  302. 		push_screen("cell_music_sub") 
  303. 		game_UI_audio_play("UI_Cell_Select") 
  304. 	elseif state == ID_CAMERA then 
  305. 		game_UI_audio_play("UI_Cell_Select") 
  306. 		Online_check_thread = thread_new("cell_menu_check_online_for_camera") 
  307. 	elseif state == ID_PHONE then		 
  308. 		push_screen("cell_phone") 
  309. 		game_UI_audio_play("UI_Cell_Select") 
  310. 	elseif state == ID_EXTRAS then 
  311. 		push_screen("cell_extras") 
  312. 		game_UI_audio_play("UI_Cell_Select") 
  313. 	elseif state == ID_CASH then 
  314. 		push_screen("store_crib_cash") 
  315. 		--completion_load_lut("lut_default_xbox2") 
  316. 		game_UI_audio_play("UI_Cell_Select") 
  317. 	else  
  318. 		-- DEFAULT VIEW 
  319. 		--Hide safe frame... 
  320. 		local safe_frame_h = vint_object_find("safe_frame", 0, Cell_menu_main_doc_h) 
  321. 		vint_set_property(safe_frame_h, "visible", true) 
  322. 		-- Make the foreground and background show up with the frame 
  323. 		cell_show_frame() 
  324. 		 
  325. 		--Transition to main screen 
  326. 		cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN,  CELL_SCREEN_NONE, cell_menu_main_gained_focus) 
  327. 	end 
  328. end 
  329.  
  330. function cell_menu_main_set_new(new_items) 
  331.  
  332. 	if New_item_idx < 8 and New_item_idx ~= ID_CASH then 
  333. 		Data[New_item_idx].new_items = new_items 
  334. 	elseif New_item_idx == ID_CASH then 
  335. 		--dataresponer returns cash amount.  If we have cash then show a 1. 
  336. 		if new_items > 0 then 
  337. 			Data[New_item_idx].new_items = 1 
  338. 		else 
  339. 			Data[New_item_idx].new_items = 0 
  340. 		end 
  341. 	end 
  342. 	 
  343. 	New_item_idx = New_item_idx + 1 
  344. 	 
  345. end 
  346.  
  347. function cell_menu_main_unlock_controls() 
  348. 	Input_tracker:subscribe(true) 
  349. 	if Mouse_input_tracker ~= nil then 
  350. 		Mouse_input_tracker:subscribe(true) 
  351. 	end 
  352. end 
  353.  
  354. function cell_menu_main_lock_controls() 
  355. 	Input_tracker:subscribe(false) 
  356. 	if Mouse_input_tracker ~= nil then 
  357. 		Mouse_input_tracker:subscribe(false) 
  358. 	end 
  359. end 
  360.  
  361. function cell_menu_main_lost_focus() 
  362. 	Input_tracker:subscribe(false) 
  363. 	if Mouse_input_tracker ~= nil then 
  364. 		Mouse_input_tracker:subscribe(false) 
  365. 	end 
  366. end 
  367.  
  368. function cell_menu_main_gained_focus() 
  369. 	cell_menu_main_unlock_controls() 
  370. 	 
  371. 	--Refresh hints incase user switched between gamepad and keyboard/mouse 
  372. 	local hint_data = { 
  373. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  374. 	} 
  375. 	Hint_bar:set_hints(hint_data)  
  376. 	 
  377. 	vint_set_property(vint_object_find("safe_frame"), "visible", true) 
  378. 	 
  379. 	New_item_idx = 0 
  380. 	vint_dataresponder_request("cell_menu_main_new_items", "cell_menu_main_set_new", 0) 
  381. 	Menu:populate_menu(Data, Current_idx) 
  382. end 
  383.  
  384.  
  385. function cell_menu_main_trans_to_pause_map() 
  386. 	--pop off screen 
  387. 	Cell_rewards_to_map = true 
  388. 	pop_screen() 
  389. 	push_screen("pause_map") 
  390. end 
  391.