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