./cmp_fail.lua

  1. local GAMEPLAY_TYPE_MISSION = 3 
  2. local GAMEPLAY_TYPE_STRONGHOLD = 4 
  3. local GAMEPLAY_TYPE_ACTIVITY = 5 
  4.  
  5. Cmp_fail_data = {} 
  6. Cmp_fail_doc = -1 
  7.  
  8. local COMPLETION_RESTART							= 0 
  9. local COMPLETION_RESTART_FROM_CHECKPOINT		= 1 
  10. local COMPLETION_EXIT								= 2 
  11. local COMPLETION_CONTINUE							= 3 
  12.  
  13.  
  14. local Input_tracker 
  15. local Mouse_input_tracker 
  16. local Menu_hint_bar 
  17.  
  18. local List 
  19. local First_screen_started = false 
  20. local Cmp_screen_is_finished = false				-- Used to determine state of completion screen... 
  21. local Cmp_screen_can_skip = false					-- Determines if we can skip the completion screen... 
  22. local Checkpoint_retry_disabled = false			-- Coop player has disconnected or player isn't yet to ckpt 
  23.  
  24. local Cmp_fail_coop_dialog_handle = 0 
  25.  
  26. Cmp_screen_base_x = 0				-- Base position x 
  27. Cmp_screen_base_y = 0				-- Base position Y 
  28. local Camera_shake_multiplier = 0 
  29.  
  30. local Coop_hint_data = { 
  31. 	{CTRL_MENU_BUTTON_BACK, "COMPLETION_COOP_DISCONNECT"}, 
  32. } 
  33.  
  34. --Populate options list depending on gameplay type... 
  35. -- This is what we will use to populate the menus 
  36.  
  37. --Mission fail menu... 
  38. local Cmp_fail_list_mission_data = { 
  39. 		[1] = { 
  40. 			type = TYPE_BUTTON, 
  41. 			label = "COMPLETION_RESTART_CHECKPOINT", 
  42. 			id = COMPLETION_RESTART_FROM_CHECKPOINT, 
  43. 		}, 
  44. 		[2] = { 
  45. 			type = TYPE_BUTTON, 
  46. 			label = "COMPLETION_RESTART_BEGINNING", 
  47. 			id = COMPLETION_RESTART, 
  48. 		}, 
  49. 		[3] = { 
  50. 			type = TYPE_BUTTON, 
  51. 			label = "COMPLETION_EXIT_MISSION", 
  52. 			id = COMPLETION_EXIT, 
  53. 		} 
  54. 	} 
  55. 	 
  56. -- Stronghold fail menu... 
  57. local Cmp_fail_list_stronghold_data = { 
  58. 		[1] = { 
  59. 			type = TYPE_BUTTON, 
  60. 			label = "COMPLETION_RESTART_CHECKPOINT",	 
  61. 			id = COMPLETION_RESTART_FROM_CHECKPOINT, 
  62. 		}, 
  63. 		[2] = { 
  64. 			type = TYPE_BUTTON, 
  65. 			label = "COMPLETION_RETRY_STRONGHOLD", 
  66. 			id = COMPLETION_RESTART, 
  67. 		}, 
  68. 		[3] = { 
  69. 			type = TYPE_BUTTON, 
  70. 			label = "COMPLETION_EXIT_STRONGHOLD", 
  71. 			id = COMPLETION_EXIT, 
  72. 		} 
  73. 	} 
  74.  
  75. -- Activity fail menu... 
  76. local Cmp_fail_list_activity_data = { 
  77. 		[1] = { 
  78. 			type = TYPE_BUTTON, 
  79. 			label = "COMPLETION_RETRY_ACTIVITY", 
  80. 			id = COMPLETION_RESTART, 
  81. 		}, 
  82. 		[2] = { 
  83. 			type = TYPE_BUTTON, 
  84. 			label = "COMPLETION_EXIT_ACTIVITY", 
  85. 			id = COMPLETION_EXIT, 
  86. 		} 
  87. 	} 
  88.  
  89. --Grouped fail menus to be retreived via data later... 
  90. local Cmp_fail_list = { 
  91. 	[GAMEPLAY_TYPE_MISSION] = Cmp_fail_list_mission_data, 
  92. 	[GAMEPLAY_TYPE_ACTIVITY] = Cmp_fail_list_activity_data, 
  93. 	[GAMEPLAY_TYPE_STRONGHOLD] = Cmp_fail_list_stronghold_data, 
  94. } 
  95.  
  96. function cmp_fail_init() 
  97.  
  98. 	bg_saints_set_type(BG_TYPE_CENTER,false,1280) 
  99.  
  100. 	Cmp_fail_doc = vint_document_find("cmp_fail") 
  101.  
  102. 	-- Init shake and audio callbacks... 
  103. 	cmp_fail_callack_enable(true) 
  104. 	 
  105. 	-- Setup screen complete... 
  106. 	local h = vint_object_find("screen_complete_twn") 
  107. 	vint_set_property(h, "end_event", "cmp_fail_anim_complete_cb") 
  108.  
  109. 	h = vint_object_find("screen_can_skip_twn") 
  110. 	vint_set_property(h, "end_event", "cmp_fail_anim_can_skip_cb") 
  111. 	 
  112. 	--Screen group... 
  113. 	h = vint_object_find("screen_grp") 
  114. 	Cmp_screen_base_x, Cmp_screen_base_y = vint_get_property(h, "anchor") 
  115.  
  116. 	--Populate data... 
  117. 	vint_dataresponder_request("cmp_fail_populate", "cmp_fail_populate", 0) 
  118. 	 
  119. 	--Force screen to start... 
  120. 	cmp_common_screen_start(0) 
  121. end 
  122.  
  123. function cmp_fail_cleanup() 
  124. 	if Input_tracker ~= nil then 
  125. 		Input_tracker:subscribe(false) 
  126. 	end 
  127. 	if Mouse_input_tracker ~= nil then 
  128. 		Mouse_input_tracker:subscribe(false) 
  129. 	end 
  130. end 
  131.  
  132. -- This is called when the screen needs to start. 
  133. -- Porting over function from cmp_common, because we don't use any of the common elements 
  134. -- On the fail screen... 
  135. function cmp_common_screen_start() 
  136.  
  137. 	if First_screen_started == true then 
  138. 		return 
  139. 	end 
  140. 	First_screen_started = true 
  141.  
  142. 	local gameplay_name_txt_h = vint_object_find("gameplay_name_txt") 
  143. 	local condition_detail_txt_h = vint_object_find("condition_detail_txt") 
  144. 	 
  145. 	--Set text for screen... 
  146. 	vint_set_property(gameplay_name_txt_h, "text_tag", Cmp_fail_data.mission_name) 
  147. 	vint_set_property(condition_detail_txt_h, "text_tag", Cmp_fail_data.failure_text) 
  148. 	 
  149. 	if Cmp_fail_data.is_coop_screen then 
  150. 		local coop_screen_base_h = vint_object_find("coop_base") 
  151. 		 
  152. 		--set waiting text... 
  153. 		local coop_gamer_tag = Completion_get_other_player_name() 
  154. 		local values = {[0] = coop_gamer_tag} 
  155. 		local waiting_string = vint_insert_values_in_string("COMPLETION_COOP_WAITING", values) 
  156. 		local coop_wait_h = vint_object_find("coop_wait", coop_screen_base_h) 
  157. 		vint_set_property(coop_wait_h,"text_tag", waiting_string) 
  158. 		 
  159. 		--Show coop info.. 
  160. 		vint_set_property(coop_screen_base_h, "visible", true) 
  161. 		vint_set_property(coop_screen_base_h, "alpha", 1) 
  162. 		 
  163. 		--Hide list... 
  164. 		local list_h = vint_object_find("options_list") 
  165. 		vint_set_property(list_h, "visible", false) 
  166. 		 
  167. 		--Setup hints... 
  168. 		Menu_hint_bar = Vdo_hint_bar:new("coop_hint_bar") 
  169. 		Menu_hint_bar:set_hints(Coop_hint_data) 
  170. 		Menu_hint_bar:enable_text_shadow(true) 
  171. 		 
  172. 		--Subscribe to input... 
  173. 		Input_tracker = Vdo_input_tracker:new() 
  174. 		Input_tracker:add_input("map", "cmp_fail_coop_input", 50) 
  175. 		Input_tracker:add_input("all_unassigned", "cmp_fail_coop_input", 50) 
  176. 		 
  177. 		-- Add mouse inputs for the PC 
  178. 		if game_get_platform() == "PC" then 
  179. 			Menu_hint_bar:set_highlight(0)			 
  180. 			Mouse_input_tracker = Vdo_input_tracker:new() 
  181. 			Menu_hint_bar:add_mouse_inputs("cmp_fail", Mouse_input_tracker) 
  182. 		end 
  183. 	else 
  184. 		-- Draw mega list... 
  185. 		--Get list data from gameplay type... 
  186. 		local list_data = Cmp_fail_list[Cmp_fail_data.gameplay_type] 
  187. 		 
  188. 		--Initalize list and draw it... 
  189. 		List = Vdo_pause_mega_list:new("options_list", nil, Cmp_fail_doc) 
  190. 		List:draw_items(list_data, 1) 
  191. 		 
  192. 		List:set_highlight_color(COLOR_CMP_FAIL) 
  193. 		 
  194. 		--Subscribe to input... 
  195. 		Input_tracker = Vdo_input_tracker:new() 
  196. 		Input_tracker:add_input("nav_up", "cmp_fail_nav_up", 50) 
  197. 		Input_tracker:add_input("nav_down", "cmp_fail_nav_down", 50) 
  198. 		Input_tracker:add_input("select", "cmp_fail_input", 50) 
  199. 		Input_tracker:add_input("all_unassigned", "cmp_fail_input", 50) 
  200. 		 
  201. 		-- Add mouse inputs for the PC 
  202. 		if game_get_platform() == "PC" then 
  203. 			Mouse_input_tracker = Vdo_input_tracker:new() 
  204. 			List:add_mouse_inputs("cmp_fail", Mouse_input_tracker) 
  205. 		end 
  206. 	end 
  207. 	 
  208. 	--Animate screen in... 
  209. 	local anim_in_h = vint_object_find("fail_in_anim") 
  210. 	lua_play_anim(anim_in_h) 
  211. 	 
  212. 	ui_audio_post_event("Mission_Fail") 
  213. end 
  214.  
  215. ------------------------------------------------------------- 
  216. --Populates the script from the dataresponder... 
  217. ------------------------------------------------------------- 
  218.  
  219. -- @param	mission_name						This is the mission/activity name... "DEATH AT SMILING	 JACKS", "INSURANCE FRAUD" 
  220. -- @param	failure_text						Text description the reason the player failed the mission. 
  221. -- @param	gameplay_type						Enum 
  222. function cmp_fail_populate(gameplay_type, mission_name, failure_text, restart_ckp_remove_option, exit_remove_option) 
  223.  
  224. 	-- This should be set to true only if we are in coop mode, and this user is the client 
  225. 	local is_coop_screen = Completion_is_client() 
  226.  
  227. 	if exit_remove_option == true then 
  228. 		cmp_fail_exit_remove() 
  229. 	end 
  230.  
  231. 	if restart_ckp_remove_option == true then 
  232. 		cmp_fail_restart_remove() 
  233. 		Checkpoint_retry_disabled = true 
  234. 	end 
  235.  
  236. 	Cmp_fail_data = { 
  237. 		mission_name = mission_name, 
  238. 		failure_text = failure_text, 
  239. 		gameplay_type = gameplay_type, 
  240. 		is_coop_screen = is_coop_screen 
  241. 	} 
  242.  
  243. --		SR2 Legacy FAIL DATA... (Reference use only) 
  244. --		MISSION FAIL... 
  245. --		completion_init_mission_failure(mission_number, team, mission_name, failure_text, image_base) 
  246. -- 
  247. --		ACTIVITY FAIL... 
  248. --		completion_init_activity_failure(district, activity_name, level, failure_text, activity_type) 
  249. --		 
  250. --		--STRONGHOLD FAIL... 
  251. --		completion_init_stronghold_failure(team, stronghold_name, ) 
  252. end 
  253.  
  254. --Selection input... 
  255. function cmp_fail_input(event, acceleration) 
  256. 	if event == "select" then 
  257. 		if Cmp_screen_is_finished == false then 
  258. 			return 
  259. 		end 
  260. 		local current_id = List:get_id() 
  261. 		 
  262. 		--send ID off to game as to what to do... 
  263. 		completion_call_callback(current_id) 
  264. 		 
  265. 		--pass off the input to the list 
  266. 		List:button_a() 
  267. 		 
  268. 		--prevent us from hitting A again 
  269. 		Input_tracker:subscribe(false) 
  270.  
  271. 		if Mouse_input_tracker ~= nil then 
  272. 			Mouse_input_tracker:subscribe(false) 
  273. 		end 
  274. 		 
  275. 		--Fade out screen... 
  276. 		local anim_h = vint_object_find("fail_out_anim") 
  277. 		lua_play_anim(anim_h) 
  278. 		completion_screen_finished() 
  279. 	end 
  280. end 
  281.  
  282. -- Nav Up 
  283. function cmp_fail_nav_up(event, acceleration) 
  284. 	if Cmp_screen_is_finished == false then 
  285. 		return 
  286. 	end 
  287. 	-- Move highlight up 
  288. 	List:move_cursor(-1) 
  289. end 
  290.  
  291. -- Nav Down 
  292. function cmp_fail_nav_down(event, acceleration) 
  293. 	if Cmp_screen_is_finished == false then 
  294. 		return 
  295. 	end 
  296. 	-- Move highlight down 
  297. 	List:move_cursor(1) 
  298. end 
  299.  
  300. --Input for coop waiting screen... 
  301. function cmp_fail_coop_input(event, acceleration) 
  302. 	if event == "map" then 
  303. 		if Cmp_screen_is_finished == false then 
  304. 			if Cmp_screen_can_skip == true then 
  305. 				cmp_fail_anim_force_end() 
  306. 				return 
  307. 			end 
  308. 			return 
  309. 		end 
  310. 		--Do coop escape... 
  311. 		cmp_fail_coop_quit_dialog() 
  312. 	end 
  313. end 
  314.  
  315. --Coop quit dialog brings up the quit dialog for the coop player(Client) if they want to quit or not... 
  316. function cmp_fail_coop_quit_dialog() 
  317. 	local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  318. 	Cmp_fail_coop_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "cmp_fail_coop_disconnect", 1, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false) 
  319. end	 
  320.  
  321.  
  322. function cmp_fail_coop_disconnect(result, action) 
  323. 	if result == 0 then 
  324. 		dialog_box_disconnect() 
  325. 	end 
  326. 	 
  327. 	Cmp_fail_coop_dialog_handle = 0 
  328. end 
  329.  
  330. --Removes the exit option from the menu structures.  May only be called before cmp_fail_restart_remove... 
  331. function cmp_fail_exit_remove() 
  332. 	Cmp_fail_list_mission_data[3] = nil 
  333. 	Cmp_fail_list_stronghold_data[3] = nil 
  334. end 
  335.  
  336. --Removes the restart option from the menu structures... 
  337. function cmp_fail_restart_remove() 
  338. 	Cmp_fail_list_mission_data[1] = table_clone(Cmp_fail_list_mission_data[2]) 
  339. 	Cmp_fail_list_mission_data[2] = table_clone(Cmp_fail_list_mission_data[3]) 
  340. 	Cmp_fail_list_mission_data[3] = nil 
  341.  
  342. 	Cmp_fail_list_stronghold_data[1] = table_clone(Cmp_fail_list_stronghold_data[2]) 
  343. 	Cmp_fail_list_stronghold_data[2] = table_clone(Cmp_fail_list_stronghold_data[3]) 
  344. 	Cmp_fail_list_stronghold_data[3] = nil 
  345. end 
  346.  
  347. --Callback for audio events for slamming... 
  348. function cmp_fail_audio_slam() 
  349. end 
  350.  
  351.  
  352. --Wrapper for c++ camera shake function... 
  353. function cmp_fail_camera_shake() 
  354. 	local anim_h = vint_object_find("shake_anim") 
  355. 	local shake_twn_h = vint_object_find("shake_twn") 
  356. 	vint_set_property(shake_twn_h, "per_frame_event", "cmp_fail_camera_shake_anim_cb") 
  357. 	lua_play_anim(anim_h) 
  358. 	Camera_shake_multiplier = Camera_shake_multiplier + 15 
  359. end 
  360.  
  361. function cmp_fail_camera_shake_anim_cb() 
  362. 	Camera_shake_multiplier = (Camera_shake_multiplier * .84) 
  363. 	local screen_h = vint_object_find("screen_grp") 
  364. 	local x = Cmp_screen_base_x + (rand_float(-Camera_shake_multiplier,Camera_shake_multiplier)) 
  365. 	local y = Cmp_screen_base_y + (rand_float(-Camera_shake_multiplier,Camera_shake_multiplier)) 
  366. 	vint_set_property(screen_h, "anchor", x, y) 
  367. end 
  368.  
  369.  
  370. -- Forces main Animation to the end and  
  371. function cmp_fail_anim_force_end() 
  372. 	--Stop all audio callbacks and slams 
  373. 	cmp_fail_callack_enable(false) 
  374. 	 
  375. 	--Fast Forward Anim... 
  376. 	local fail_in_anim_h = vint_object_find("fail_in_anim", 0, Cmp_fail_doc) 
  377. 	lua_play_anim(fail_in_anim_h, -10, Cmp_fail_doc) 
  378. 	 
  379. 	--Repair two callbacks.. 
  380. 	local h = vint_object_find("slam_4_twn") 
  381. 	vint_set_property(h, "end_event", "cmp_fail_camera_shake")	 
  382. 	h = vint_object_find("slam_audio_4_twn") 
  383. 	vint_set_property(h, "end_event", "cmp_fail_audio_slam") 
  384. end 
  385.  
  386. -- Callback from main animation when playback is complete... 
  387. function cmp_fail_anim_complete_cb() 
  388. 	Cmp_screen_is_finished = true 
  389. end 
  390.  
  391. --Callback from main animation tween determining if the player can skip through the screen... 
  392. function cmp_fail_anim_can_skip_cb() 
  393. 	Cmp_screen_can_skip = true 
  394. end 
  395.  
  396. -- Easy way to initialize or clear out the callbacks for sound and camera shakes. 
  397. function cmp_fail_callack_enable(is_enabled) 
  398. 	local camera_shake_cb			 = "cmp_fail_camera_shake" 
  399. 	local cmp_fail_audio_slam_cb	 = "cmp_fail_audio_slam" 
  400.  
  401. 	if is_enabled == false then 
  402. 		camera_shake_cb			=	nil 
  403. 		cmp_fail_audio_slam_cb	=	nil 
  404. 	end 
  405. 	 
  406. 	--Init shake callbacks... 
  407. 	local h = vint_object_find("slam_1_twn") 
  408. 	vint_set_property(h, "end_event", camera_shake_cb) 
  409. 	h = vint_object_find("slam_2_twn") 
  410. 	vint_set_property(h, "end_event", camera_shake_cb) 
  411. 	h = vint_object_find("slam_3_twn") 
  412. 	vint_set_property(h, "end_event", camera_shake_cb) 
  413. 	h = vint_object_find("slam_4_twn") 
  414. 	vint_set_property(h, "end_event", camera_shake_cb) 
  415. 	 
  416. 	--Init sound callbacks... 
  417. 	local h = vint_object_find("slam_audio_1_twn") 
  418. 	vint_set_property(h, "end_event", cmp_fail_audio_slam_cb) 
  419. 	h = vint_object_find("slam_audio_2_twn") 
  420. 	vint_set_property(h, "end_event", cmp_fail_audio_slam_cb) 
  421. 	h = vint_object_find("slam_audio_3_twn") 
  422. 	vint_set_property(h, "end_event", cmp_fail_audio_slam_cb) 
  423. 	h = vint_object_find("slam_audio_4_twn") 
  424. 	vint_set_property(h, "end_event", cmp_fail_audio_slam_cb) 
  425. end 
  426.  
  427. function completion_coop_disconnected() 
  428. 	 
  429. 	if Checkpoint_retry_disabled == false then 
  430. 		if Mouse_input_tracker ~= nil then 
  431. 			Mouse_input_tracker:remove_all() 
  432. 		end 
  433. 		 
  434. 		cmp_fail_restart_remove() 
  435. 		local list_data = Cmp_fail_list[Cmp_fail_data.gameplay_type] 
  436. 		 
  437. 		--Initalize list and draw it... 
  438. 		List:draw_items(list_data, 1, nil, nil, nil, true) 
  439.  
  440. 		if Mouse_input_tracker ~= nil then 
  441. 			List:add_mouse_inputs("cmp_fail", Mouse_input_tracker) 
  442. 			Mouse_input_tracker:subscribe(true) 
  443. 		end 
  444. 		--Redraw the items... 
  445. 		Checkpoint_retry_disabled = true 
  446. 	end 
  447. end 
  448. --function Vdo_pause_mega_list:draw_items(data, current_option, width, max_buttons, alignment, refresh) 
  449.  
  450. function cmp_fail_input_ready() 
  451. 	Input_tracker:subscribe(true) 
  452. 	if Mouse_input_tracker ~= nil then 
  453. 		Mouse_input_tracker:subscribe(true) 
  454. 	end 
  455. end 
  456.  
  457. function cmp_fail_mouse_click(event, target_handle) 
  458. 	if Menu_hint_bar ~= nil then 
  459. 		local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  460. 		if hint_index == 1 then 
  461. 			cmp_fail_coop_input("map") 
  462. 		end 
  463. 	end 
  464.  
  465. 	if List ~= nil then 
  466. 		local new_index = List:get_button_index(target_handle) 
  467. 		if new_index ~= 0 then 
  468. 			List:set_selection(new_index) 
  469. 			cmp_fail_input("select") 
  470. 		end 
  471. 	end 
  472. end 
  473.  
  474. function cmp_fail_mouse_move(event, target_handle) 
  475. 	if Menu_hint_bar ~= nil then 
  476. 		Menu_hint_bar:set_highlight(0) 
  477. 		 
  478. 		local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  479. 		if hint_index ~= 0 then 
  480. 			Menu_hint_bar:set_highlight(hint_index) 
  481. 		end 
  482. 	end 
  483. 	 
  484. 	if List ~= nil then 
  485. 		local new_index = List:get_button_index(target_handle) 
  486. 		if new_index ~= 0 then 
  487. 			List:set_selection(new_index) 
  488. 			List:move_cursor(0, true) 
  489. 		end 
  490. 	end 
  491. end 
  492.