./pause_menu_top.lua

  1. -- Globals 
  2. -- These are from mission_info.h 
  3. local MT_MISSION_NONE 		= -1 
  4. local MT_MISSION 				= 0 
  5. local MT_ACTIVITY				= 1 
  6. local MT_SILENT				= 2 
  7. local MT_STRONGHOLD			= 3 
  8. local	MT_DIVERSION_ACTIVE	= 4 
  9.  
  10. local HORDE_RETRY_INDEX	= 2 
  11. local HORDE_NEW_INDEX	= 3 
  12.  
  13. local ID_SAVE_GAME		= 1 
  14. local ID_LOAD_GAME		= 2 
  15. local ID_OPTIONS			= 3 
  16. local ID_CO_OP				= 4 
  17. local ID_QUIT_GAME		= 5 
  18. local ID_HORDE_RETRY		= 6 
  19. local ID_HORDE_NEW		= 7 
  20. local ID_CANCEL_MISSION	= 8 
  21. local ID_RECORD_MODE		= 9 
  22. local ID_CASUAL_RECORD_MODE = 10 
  23. local ID_PLAYBACK_MODE	= 11 
  24.  
  25. local Quit_message_normal = "QUIT_GAME_TEXT_FULL" 
  26. local Quit_message_horde = "HORDE_MODE_QUIT_TEXT" 
  27.  
  28. local Quit_message 
  29.  
  30. local Data 
  31. local Save_button = { 
  32. 	type = TYPE_BUTTON, 
  33. 	label = "SAVELOAD_SAVE_GAME", 
  34. 	id = ID_SAVE_GAME, 
  35. } 
  36.  
  37. local Load_button = { 
  38. 	type = TYPE_BUTTON, 
  39. 	label = "SAVELOAD_LOAD_GAME", 
  40. 	id = ID_LOAD_GAME, 
  41. } 
  42.  
  43. local Options_button = { 
  44. 	type = TYPE_BUTTON, 
  45. 	label = "PAUSE_MENU_OPTIONS", 
  46. 	id = ID_OPTIONS, 
  47. } 
  48.  
  49. local Coop_button = { 
  50. 	type = TYPE_BUTTON, 
  51. 	label = "PAUSE_MENU_COOP", 
  52. 	id = ID_CO_OP, 
  53. } 
  54.  
  55. local Record_button = { 
  56. 	type = TYPE_BUTTON, 
  57. 	label = "PAUSE_MENU_RECORD_MODE", 
  58. 	id = ID_RECORD_MODE, 
  59. } 
  60.  
  61. local Casual_record_button = { 
  62. 	type = TYPE_BUTTON, 
  63. 	label = "MENU_VIDEO_RECORD_MODE", 
  64. 	id = ID_CASUAL_RECORD_MODE, 
  65. } 
  66.  
  67. local Playback_button = { 
  68. 	type = TYPE_BUTTON, 
  69. 	label = "PAUSE_MENU_PLAYBACK_MODE", 
  70. 	id = ID_PLAYBACK_MODE, 
  71. } 
  72.  
  73. local Quit_button = { 
  74. 	type = TYPE_BUTTON, 
  75. 	label = "HORDE_MODE_MENU_EXIT", 
  76. 	id = ID_QUIT_GAME, 
  77. } 
  78.  
  79. local Horde_retry_button = { 
  80. 	type = TYPE_BUTTON, 
  81. 	id = ID_HORDE_RETRY, 
  82. 	label = "HORDE_MODE_MENU_RETRY" 
  83. } 
  84.  
  85. local Horde_new_button = { 
  86. 	type = TYPE_BUTTON, 
  87. 	id = ID_HORDE_NEW, 
  88. 	label = "HORDE_MODE_MENU_NEW_GAME" 
  89. } 
  90.  
  91. local Cancel_button = { 
  92. 	type = TYPE_BUTTON, 
  93. 	id = ID_CANCEL_MISSION, 
  94. 	label = "HUD_CANCEL_MISSION", 
  95. } 
  96.  
  97. local Anims = {} 
  98.  
  99. local Input_tracker 
  100. local Mouse_input_tracker 
  101. local Online_check_thread = -1 
  102.  
  103. local Screen_width = 495 
  104. local Tween_done = true 
  105.  
  106. local Checking_dlc = false 
  107.  
  108. ---------------------------------------------------------------------------  
  109. -- Initialize Pause Menu Top (First Level of Pause Menu) 
  110. --------------------------------------------------------------------------- 
  111. function pause_menu_top_init() 
  112. 	-- Subscribe to the button presses we need 
  113. 	 
  114. 	Input_tracker = Vdo_input_tracker:new() 
  115. 	Input_tracker:add_input("select", "pause_menu_top_button_a", 50) 
  116. 	Input_tracker:add_input("pause", "pause_menu_top_button_b", 50) 
  117. 	Input_tracker:add_input("back", "pause_menu_top_button_b", 50) 
  118. 	Input_tracker:add_input("nav_up", "pause_menu_top_nav_up", 50) 
  119. 	Input_tracker:add_input("nav_down", "pause_menu_top_nav_down", 50) 
  120. 	Input_tracker:add_input("nav_left", "pause_menu_top_nav_left", 50) 
  121. 	Input_tracker:add_input("nav_right", "pause_menu_top_nav_right", 50) 
  122. 	Input_tracker:subscribe(false) 
  123.  
  124. 	--Initialize Header 
  125. 	Header_obj:set_text("SYSTEM_PAUSED", Screen_width) --("MENU_GAME_PAUSED") 
  126.  
  127. 	-- Clear pause menu and build a new one 
  128. 	Data = {} 
  129. 	 
  130. 	if horde_mode_is_active() == false then 
  131. 		if game_machinima_is_recording() == false then 
  132. 			Data[#Data+1] = Save_button 
  133. 			Data[#Data+1] = Load_button 
  134. 		end 
  135. 		 
  136. 		local gameplay_type = game_get_in_progress_type() 
  137. 		local cancel_button_tag = nil 
  138. 		if gameplay_type == MT_MISSION then 
  139. 			cancel_button_tag = "HUD_CANCEL_MISSION" 
  140. 		elseif gameplay_type == MT_ACTIVITY then 
  141. 			cancel_button_tag = "HUD_CANCEL_ACTIVITY" 
  142. 		elseif gameplay_type == MT_STRONGHOLD then 
  143. 			cancel_button_tag = "HUD_CANCEL_STRONGHOLD" 
  144. 		elseif gameplay_type == MT_DIVERSION_ACTIVE then 
  145. 			cancel_button_tag = "HUD_CANCEL_DIVERSION" 
  146. 		end 
  147.  
  148. 		if cancel_button_tag then 
  149. 			Data[#Data+1] = Cancel_button 
  150. 			Cancel_button.label = cancel_button_tag 
  151. 			if pause_menu_cant_retry_because_host_in_creation() then 
  152. 				Cancel_button.disabled = true 
  153. 			end 
  154. 		end 
  155. 		 
  156. 		Data[#Data+1] = Options_button 
  157.  
  158. 		if game_get_is_host() == false and cancel_button_tag ~= nil then 
  159. 			Load_button.disabled = true 
  160. 		end 
  161. 		 
  162. 		if game_machinima_is_recording() == false then 
  163. 			Data[#Data+1] = Coop_button 
  164. 		end 
  165.  
  166. 		if game_record_mode_is_supported() then 
  167. 			Data[#Data+1] = Casual_record_button 
  168. 			--[[if game_machinima_is_recording() == true then 
  169. 				Data[#Data+1] = Playback_button; 
  170. 			else 
  171. 				Data[#Data+1] = Record_button; 
  172. 			end]] 
  173. 		end 
  174.  
  175. 		Data[#Data+1] = Quit_button 
  176. 		 
  177. 		Quit_message = Quit_message_normal 
  178. 	else  
  179. 		Data[#Data+1] = Options_button 
  180. 		 
  181. 		if game_get_is_host() then 
  182. 			Data[#Data+1] = Horde_retry_button 
  183. 			Data[#Data+1] = Horde_new_button 
  184. 		end 
  185. 		 
  186. 		if game_record_mode_is_supported() then 
  187. 			Data[#Data+1] = Casual_record_button 
  188. 		end 
  189. 		 
  190. 		Data[#Data+1] = Quit_button 
  191. 		 
  192. 		if coop_is_active() then 
  193. 			Quit_message = Quit_message_horde 
  194. 		else 
  195. 			Quit_message = Quit_message_normal 
  196. 		end 
  197. 	end 
  198. 	 
  199. 	--Setup button hints 
  200. 	local hint_data = { 
  201. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  202. 	} 
  203. 	Menu_hint_bar:set_hints(hint_data) 
  204. 	 
  205. 	--Get the selection option from when the menu was last loaded 
  206. 	local last_option_selected = menu_common_stack_get_index(Data) 
  207. 	 
  208. 	--this HACK stinks, we should get the longest string width back and adjust for that 
  209. 	if game_get_language() == "DE" then 
  210. 		Screen_width = 680 
  211. 	end 
  212. 	 
  213. 	-- Initialize and draw list object 
  214. 	List:draw_items(Data, last_option_selected, Screen_width)	 
  215. 	 
  216. 	--Store some locals to the pause menu common for screen processing. 
  217. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  218. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim, pause_menu_top_anim_in_done) 
  219. 	 
  220. 	 
  221. 	-- Add mouse input subscriptions for the PC 
  222. 	if game_get_platform() == "PC" then 
  223. 		Menu_hint_bar:set_highlight(0) 
  224. 	 
  225. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  226. 		List:add_mouse_inputs("pause_menu_top", Mouse_input_tracker) 
  227. 		Menu_hint_bar:add_mouse_inputs("pause_menu_top", Mouse_input_tracker) 
  228. 		Mouse_input_tracker:subscribe(true) 
  229. 	end 
  230. 	 
  231. 	if First_time then 
  232. 		local bg_anchor = 100 
  233. 		if vint_is_std_res() then 
  234. 			bg_anchor = 74 
  235. 		end 
  236. 		Screen_in_anim:play(0) 
  237. 		bg_saints_slide_in(Screen_width, bg_anchor) 
  238. 		bg_saints_dimmer_show(true)	--Dim out the game... 
  239. 		First_time = false 
  240. 	end 
  241.  
  242. end 
  243.  
  244. function pause_menu_top_gained_focus() 
  245. 	--Initialize Header 
  246. 	Header_obj:set_text("SYSTEM_PAUSED") --("MENU_GAME_PAUSED") 
  247.  
  248. 		--Setup button hints 
  249. 	local hint_data = { 
  250. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  251. 	} 
  252. 	Menu_hint_bar:set_hints(hint_data) 
  253.  
  254. 	--Get the selection option from when the menu was last loaded 
  255. 	local last_option_selected = menu_common_stack_get_index(Data) 
  256. 	 
  257. 	-- Remove subscriptions 
  258. 	if Mouse_input_tracker ~= nil then 
  259. 		Mouse_input_tracker:remove_all() 
  260. 	end 
  261. 	 
  262. 	-- Initialize and draw list object 
  263. 	List:draw_items(Data, last_option_selected, Screen_width)	 
  264. 	 
  265. 	-- Re-add subscriptions 
  266. 	if Mouse_input_tracker ~= nil then 
  267. 		List:add_mouse_inputs("pause_menu_top", Mouse_input_tracker) 
  268. 		Menu_hint_bar:add_mouse_inputs("pause_menu_top", Mouse_input_tracker) 
  269. 		Mouse_input_tracker:subscribe(true) 
  270. 	end 
  271. 	 
  272. 	--Store some locals to the pause menu common for screen processing. 
  273. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  274. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim, pause_menu_top_anim_in_done) 
  275.  
  276. end 
  277.  
  278. function pause_menu_top_lost_focus() 
  279. 	-- Nuke all button subscriptions 
  280. 	Input_tracker:subscribe(false) 
  281. 	 
  282. 	if Mouse_input_tracker ~= nil then 
  283. 		Mouse_input_tracker:subscribe(false) 
  284. 	end 
  285. 	List:enable_toggle_input(false) 
  286. end 
  287.  
  288. function pause_menu_top_cleanup() 
  289. 	if Online_check_thread ~= -1 then 
  290. 		thread_kill(Online_check_thread) 
  291. 	end 
  292. 	 
  293. 	-- Nuke all button subscriptions 
  294. 	Input_tracker:subscribe(false) 
  295. 	 
  296. 	if Mouse_input_tracker ~= nil then 
  297. 		Mouse_input_tracker:subscribe(false) 
  298. 	end 
  299. 	List:enable_toggle_input(false) 
  300. end 
  301.  
  302. function pause_menu_top_anim_in_done() 
  303. 	if Exit_after_closing == true then 
  304. 		Input_tracker:subscribe(false) 
  305. 		 
  306. 		if Mouse_input_tracker ~= nil then 
  307. 			Mouse_input_tracker:subscribe(false) 
  308. 		end 
  309. 	else 
  310. 		Input_tracker:subscribe(true) 
  311. 	 
  312. 		if Mouse_input_tracker ~= nil then 
  313. 			Mouse_input_tracker:subscribe(true) 
  314. 		end 
  315. 	end 
  316. 	 
  317. 	pause_menu_common_top_finished_loading() 
  318. end 
  319.  
  320. function pause_menu_top_nav_up(event, acceleration) 
  321. 	-- Move highlight up 
  322. 	List:move_cursor(-1) 
  323. end 
  324.  
  325. function pause_menu_top_nav_down(event, acceleration) 
  326. 	-- Move highlight down 
  327. 	List:move_cursor(1) 
  328. end 
  329.  
  330. function pause_menu_top_nav_left(event, acceleration) 
  331. 	-- Move highlight left 
  332. 	List:move_slider(-1) 
  333. end 
  334.  
  335. function pause_menu_top_nav_right(event, acceleration) 
  336. 	-- Move highlight right 
  337. 	List:move_slider(1) 
  338. end 
  339.  
  340. function pause_menu_save_callback(result, action) 
  341. 	menu_common_transition_push("pause_save_game") 
  342. end 
  343.  
  344. function coop_dlc_checked(has_dlc, cancelled) 
  345. 	if has_dlc then 
  346. 		Input_tracker:subscribe(true)	 
  347. 		menu_common_transition_push("pause_co_op_menu") 
  348. 		List:button_a() 
  349. 		return 
  350. 	end 
  351. 	 
  352. 	if not cancelled then  
  353. 		dialog_box_message("DIALOG_COOP_DLC_TITLE", "DIALOG_COOP_DLC_BODY") 
  354. 	end 
  355. 	Input_tracker:subscribe(true) 
  356. end 
  357.  
  358. function pause_menu_top_button_a(event, acceleration) 
  359. 	if Tween_done == true then 
  360. 		--Set the screen data to the list data 
  361. 		Data = List:return_data() 
  362. 		local current_id = List:get_id() 
  363. 		 
  364. 		--Add current selection to the stack to store the selected position on the menu 
  365. 		menu_common_stack_add(current_id) 
  366. 		 
  367. 		--pass off the input to the list  
  368. 		 
  369. 		if current_id == ID_SAVE_GAME then 
  370. 			-- check if the game is autosaving 
  371. 			if game_is_autosaving() then 
  372. 				dialog_box_message("MENU_TITLE_NOTICE", "SAVELOAD_CANT_ENTER_AUTOSAVE") 
  373. 			else 
  374. 				Save_system_operation = SAVE_OPERATION_SAVE_GAME 
  375. 				List:button_a() 
  376. 				local progress_type = game_get_in_progress_type() 
  377. 				if Save_message_displayed == false and (progress_type == MT_MISSION or progress_type == MT_SILENT or progress_type == MT_STRONGHOLD) then 
  378. 					dialog_box_message("MENU_TITLE_WARNING", "SAVELOAD_MISSION_WARNING", nil, nil, "pause_menu_save_callback") 
  379. 				elseif Save_message_displayed == false and (progress_type == MT_ACTIVITY or progress_type == MT_DIVERSION_ACTIVE) then 
  380. 					dialog_box_message("MENU_TITLE_WARNING", "SAVELOAD_ACTIVITY_WARNING", nil, nil, "pause_menu_save_callback") 
  381. 				else 
  382. 					menu_common_transition_push("pause_save_game") 
  383. 				end 
  384. 				Save_message_displayed = true			 
  385. 			end 
  386. 			return 
  387. 		elseif current_id == ID_LOAD_GAME then 
  388. 			-- check if the game is autosaving 
  389. 			if game_is_autosaving() then 
  390. 				dialog_box_message("MENU_TITLE_NOTICE", "SAVELOAD_CANT_ENTER_AUTOSAVE") 
  391. 			elseif game_is_waiting_for_partner() then 
  392. 				dialog_box_message("MENU_TITLE_NOTICE", "SAVELOAD_CANT_ENTER_JOINING") 
  393. 			else 
  394. 				Save_system_operation = SAVE_OPERATION_LOAD_GAME 
  395. 				menu_common_transition_push("pause_save_game") 
  396. 				List:button_a() 
  397. 			end 
  398. 			return	 
  399. 		elseif current_id == ID_OPTIONS then 
  400. 			menu_common_transition_push("pause_options_menu") 
  401. 			List:button_a() 
  402. 		 
  403. 			return	 
  404. 		elseif current_id == ID_CO_OP then 
  405. 			Input_tracker:subscribe(false) 
  406. 			game_check_coop_dlc("coop_dlc_checked") 
  407. 			return	 
  408. 		elseif current_id == ID_CANCEL_MISSION then 
  409. 			game_cancel_mission() 
  410. 			return 
  411. 		elseif current_id == ID_QUIT_GAME then 
  412. 			dialog_box_destructive_confirmation("PAUSE_MENU_QUIT_TITLE", Quit_message,"pause_menu_top_confirm_quit") 
  413. 			if Mouse_input_tracker ~= nil then 
  414. 				Mouse_input_tracker:subscribe(false) 
  415. 			end 
  416. 			return	 
  417. 		elseif current_id == ID_HORDE_RETRY then 
  418. 			dialog_box_destructive_confirmation("HORDE_MODE_MENU_RETRY", "HORDE_MODE_RETRY_TEXT", "horde_retry_confirm") 
  419. 		elseif current_id == ID_HORDE_NEW then 
  420. 			dialog_box_destructive_confirmation("HORDE_MODE_MENU_NEW_GAME", "HORDE_MODE_NEW_TEXT", "horde_new_confirm") 
  421. 		elseif current_id == ID_RECORD_MODE then 
  422. 			--dialog_box_destructive_confirmation("RECORD_MODE_WARNING", "RECORD_MODE_WARNING_TEXT", "record_mode_confirm")			 
  423. 		elseif current_id == ID_CASUAL_RECORD_MODE then 
  424. 			menu_common_transition_push("pause_options_record_mode") 
  425. 		elseif current_id == ID_PLAYBACK_MODE then 
  426. 			dialog_box_destructive_confirmation("PLAYBACK_MODE_WARNING", "PLAYBACK_MODE_WARNING_TEXT", "playback_mode_confirm") 
  427. 		end 
  428. 	end 
  429. end 
  430.  
  431. function pause_menu_top_confirm_quit(result, action) 
  432. --	if action == 1 then 
  433. --		return 
  434. --	end 
  435. 	 
  436. 	if result == 0 then 
  437. 		-- Dialog box result YES 
  438. 		if horde_mode_is_active() then 
  439. 			audio_object_post_event("ui_whr_quit_gameplay") 
  440. 		end 
  441. 		Input_tracker:subscribe(false) 
  442. 		pause_menu_quit_game_internal() 
  443. --		menu_common_transition_pop(2) 
  444. --		bg_saints_slide_out() 
  445. 	elseif result == 1 then 
  446. 		-- Dialog box result NO 
  447. 		-- Restore inputs to the pause menu 
  448. 		if Mouse_input_tracker ~= nil then 
  449. 			Mouse_input_tracker:subscribe(true) 
  450. 		end 
  451. 	end 
  452. end 
  453.  
  454. function horde_retry_confirm(result, action) 
  455. 	if result == 0 then 
  456. 		-- Dialog box result YES 
  457. 		pause_menu_horde_mode_retry() 
  458. 		menu_common_transition_pop(2) 
  459. 	elseif result == 1 then 
  460. 		-- Dialog box result NO 
  461. 		-- Restore inputs to the pause menu 
  462. 		if Mouse_input_tracker ~= nil then 
  463. 			Mouse_input_tracker:subscribe(true) 
  464. 		end 
  465. 	end 
  466. end 
  467.  
  468. function horde_new_confirm(result, action) 
  469. 	if result == 0 then 
  470. 		-- Dialog box result YES 
  471. 		pause_menu_horde_mode_new() 
  472. 		menu_common_transition_pop(2) 
  473. 	elseif result == 1 then 
  474. 		-- Dialog box result NO 
  475. 		-- Restore inputs to the pause menu 
  476. 		if Mouse_input_tracker ~= nil then 
  477. 			Mouse_input_tracker:subscribe(true) 
  478. 		end 
  479. 	end 
  480. end 
  481.  
  482. function record_mode_confirm(result, action) 
  483. 	if result == 0 then 
  484. 		-- Dialog box result YES 
  485. 		game_machinima_record() 
  486. 		menu_common_transition_pop(2) 
  487. 	elseif result == 1 then 
  488. 		-- Dialog box result NO 
  489. 		-- Restore inputs to the pause menu 
  490. 		if Mouse_input_tracker ~= nil then 
  491. 			Mouse_input_tracker:subscribe(true) 
  492. 		end 
  493. 	end 
  494. end 
  495.  
  496. function playback_mode_confirm(result, action) 
  497. 	if result == 0 then 
  498. 		-- Dialog box result YES 
  499. 		game_machinima_playback_enter("machinima") 
  500. 		menu_common_transition_pop(2) 
  501. 	elseif result == 1 then 
  502. 		-- Dialog box result NO 
  503. 		-- Restore inputs to the pause menu 
  504. 		if Mouse_input_tracker ~= nil then 
  505. 			Mouse_input_tracker:subscribe(true) 
  506. 		end 
  507. 	end 
  508. end 
  509.  
  510. function pause_menu_top_button_b(event, acceleration) 
  511. 	if Tween_done == true then 
  512. 		Input_tracker:subscribe(false) 
  513. 		if Mouse_input_tracker ~= nil then 
  514. 			Mouse_input_tracker:subscribe(true) 
  515. 		end 
  516. 		List:button_b() 
  517. 		menu_common_transition_pop(2) 
  518. 		bg_saints_slide_out() 
  519. 	end 
  520. end 
  521.  
  522. function pause_menu_top_mouse_click(event, target_handle) 
  523. 	-- First check if the target_handle is in the hint bar 
  524. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  525. 	if hint_index == 1 then 
  526. 		pause_menu_top_button_b() 
  527. 	end 
  528.  
  529. 	local new_index = List:get_button_index(target_handle) 
  530. 	if new_index ~= 0 then 
  531. 		-- Enter an option if the target_handle is in the List 
  532. 		List:set_selection(new_index) 
  533. 		pause_menu_top_button_a() 
  534. 	end 
  535. end 
  536.  
  537. function pause_menu_top_mouse_move(event, target_handle) 
  538. 	-- Reset highlights 
  539. 	Menu_hint_bar:set_highlight(0) 
  540. 	 
  541. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  542. 	if hint_index ~= 0 then 
  543. 		Menu_hint_bar:set_highlight(hint_index) 
  544. 	end 
  545. 	 
  546. 	local new_index = List:get_button_index(target_handle) 
  547. 	if new_index ~= 0 then 
  548. 		-- Set the button as the new selected highlight 
  549. 		List:set_selection(new_index) 
  550. 		List:move_cursor(0, true) 
  551. 	end 
  552. end