./dialog.lua

  1. -- OLD CONSTANTS 
  2. DIALOG_RESULT_INVALID 		= -1 
  3. DIALOG_ACTION_INVALID 		= -1 
  4.  
  5. DIALOG_ACTION_NONE 			= 0 
  6. DIALOG_ACTION_FORCE_CLOSED = 1 
  7. DIALOG_ACTION_CLOSE 			= 2 
  8. DIALOG_ACTION_NAVIGATE 		= 3 
  9.  
  10. DIALOG_PRIORITY_INFORMATION 		= 0 
  11. DIALOG_PRIORITY_ACTION 				= 1 
  12. DIALOG_PRIORITY_GAME_CRITICAL		= 2 
  13. DIALOG_PRIORITY_SYSTEM_CRITICAL	= 3 
  14.  
  15. DIALOG_RESULT_YES = 0 
  16. DIALOG_RESULT_NO 	= 1 
  17.  
  18. -- New stuff... 
  19.  
  20. -- CONSTANTS 
  21.  
  22.  
  23. -- Dialog Operations 
  24. local DIALOG_OPERATION_NEW_DIALOG	= 1 
  25. local DIALOG_OPERATION_CLOSE 	 		= 2 
  26. local DIALOG_OPERATION_TRANSITION 	= 3 
  27. local DIALOG_OPERATION_SUSPEND		= 4 
  28. local DIALOG_OPERATION_RESUME			= 8 
  29. local DIALOG_OPERATION_REBUILD 		= 16 
  30.  
  31. local Input_tracker	-- Track input for dialogs... 
  32. local Pause_input_tracker -- Track input for the pause thing 
  33. local Mouse_input_tracker -- Track mouse inputs 
  34.  
  35. local Pause_input_added = false 
  36.  
  37. local Dialogs = {}	-- Where to store all the dialogs coming in from script... 
  38. local Dialog_objects = {} 
  39. Dialog_object_0 = -1 
  40. Dialog_object_1 = -1 
  41.  
  42. local Dialog_current_idx = -1 	-- Index to the current dialog we are going to modify... 
  43. local Dialog_current_handle = -1 	-- Handle to the current dialog we are going to modify... 
  44.  
  45. local Dialog_box =  { handles = { } } 
  46.  
  47. local Ignore_input = false 
  48.  
  49. ------------------------------- 
  50. -- Init Dialog Box.... 
  51. ------------------------------- 
  52. function dialog_init() 
  53. 	-- This is the first screen that can call an interface init... 
  54. 	-- Spawn any processes that need to happen before anything else... 
  55. 	 
  56. 	--This is the first screen that can call an init... So we will take advantage... 
  57. 	vint_lib_init_buttons()			--Inits all button mappings to globals... 
  58. 	vint_lib_init_constants()		--Inits any constants that get used by the game... 
  59. 	 
  60. 	local Dialog_document_handle = vint_document_find("dialog") 
  61. 	 
  62. 	local dialog_box_h = vint_object_find("box") 
  63.   
  64. 	Dialog_objects[0] = Vdo_dialog:new("box", 0, Dialog_document_handle, "dialog.lua", "Dialog_object_0") 
  65. 	Dialog_objects[1] = Vdo_dialog:clone(dialog_box_h, 0, Dialog_document_handle, "dialog.lua", "Dialog_object_1") 
  66.  
  67. 	Dialog_objects[0]:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_PRIMARY) 
  68. 	Dialog_objects[1]:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_PRIMARY) 
  69.  
  70. 	Dialog_object_0 = Dialog_objects[0] 
  71. 	Dialog_object_1 = Dialog_objects[1] 
  72. 	 
  73. 	--Clone objects... 
  74. 	vint_set_property(Dialog_objects[0].handle, "depth", -1200) 
  75. 	vint_set_property(Dialog_objects[1].handle, "depth", -1000) 
  76.  
  77. 	Dialog_current_idx = -1 
  78. 	 
  79. 	--Hide objects... 
  80. 	Dialog_objects[0]:hide() 
  81. 	Dialog_objects[1]:hide() 
  82. 	 
  83. 	--Input tracker for the dialog boxes... 
  84. 	Input_tracker = Vdo_input_tracker:new() 
  85. 	Input_tracker:add_input("select", 		"dialog_input", 200) 
  86. 	Input_tracker:add_input("back", 			"dialog_input", 200) 
  87. 	Input_tracker:add_input("nav_up", 		"dialog_input", 200) 
  88. 	Input_tracker:add_input("nav_down", 	"dialog_input", 200) 
  89. 	Input_tracker:add_input("nav_left", 	"dialog_input", 200) 
  90. 	Input_tracker:add_input("nav_right", 	"dialog_input", 200) 
  91. 	Input_tracker:add_input("pause", 		"dialog_input", 200) 
  92. 	Input_tracker:add_input("map", 			"dialog_input", 200) 
  93. 	Input_tracker:add_input("exit",			"dialog_input", 200) 
  94. 	Input_tracker:add_input("alt_select", 	"dialog_input", 200) 
  95. 	if game_get_platform() == "PC" then 
  96. 		Input_tracker:add_input("scancode", "dialog_input_tab", 50, false, 15) -- tab key 
  97. 	end 
  98.  
  99. 	Input_tracker:subscribe(false) 
  100.  
  101. 	-- Pause coop input 
  102. 	Pause_input_tracker = Vdo_input_tracker:new()	 
  103. 	Pause_input_tracker:add_input("map", 			"dialog_pause_input", 100) 
  104. 	Pause_input_tracker:add_input("select", 		"dialog_pause_input", 150) 
  105. 	Pause_input_tracker:add_input("back", 			"dialog_pause_input", 150) 
  106. 	Pause_input_tracker:add_input("nav_up", 		"dialog_pause_input", 150) 
  107. 	Pause_input_tracker:add_input("nav_down", 	"dialog_pause_input", 150) 
  108. 	Pause_input_tracker:add_input("nav_left", 	"dialog_pause_input", 150) 
  109. 	Pause_input_tracker:add_input("nav_right", 	"dialog_pause_input", 150) 
  110. 	Pause_input_tracker:add_input("exit",			"dialog_pause_input", 150) 
  111. 	Pause_input_tracker:add_input("alt_select", 	"dialog_pause_input", 150) 
  112. 	Pause_input_tracker:subscribe(false) 
  113. 	 
  114. 	-- Mouse input 
  115. 	if game_get_platform() == "PC" then 
  116. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  117. 	end 
  118. 	 
  119. 	--Paused stuff 
  120. 	local paused_h = vint_object_find("paused") 
  121. 	Dialog_box.handles.paused = paused_h 
  122. 	Dialog_box.handles.partner_paused = vint_object_find("partner_paused", paused_h) 
  123. 	Dialog_box.handles.paused_bg = vint_object_find("background", paused_h) 
  124. end 
  125.  
  126. function dialog_cleanup() 
  127. 	--Unsubscribe all inputs... 
  128. 	Input_tracker:subscribe(false) 
  129. 	Pause_input_tracker:subscribe(false) 
  130. 	 
  131. 	if Mouse_input_tracker ~= nil then 
  132. 		Mouse_input_tracker:remove_all() 
  133. 	end 
  134. end 
  135.  
  136. -- Dialog input... 
  137. function dialog_input(event, acceleration) 
  138. 	if Ignore_input == false then 
  139. 	 
  140. 		-- Hack, only accept nav up, nav down, and select events while not morphing to fix this but where if you spam the enter key on a dialog box, it will render all funny. 
  141. 		-- For reference, here's the bug "43070: [PC]: UI prompts go blank after accessing crib wardrobe, hitting random keys, then clicking on "save outfit"" 
  142. 		if not Dialog_objects[Dialog_current_idx].morph_playing then 
  143. 			if event == "nav_up" then		 
  144. 				if Dialog_objects[Dialog_current_idx]:nav(-1) then 
  145. 					if Dialog_objects[Dialog_current_idx].current_dialog.options.option_count > 1 then 
  146. 						game_UI_audio_play("UI_Reward_Store_Menu_Navigation") 
  147. 					end 
  148. 				end 
  149. 			elseif event == "nav_down" then 
  150. 				if Dialog_objects[Dialog_current_idx]:nav(1) then 
  151. 					if Dialog_objects[Dialog_current_idx].current_dialog.options.option_count > 1 then 
  152. 						game_UI_audio_play("UI_Reward_Store_Menu_Navigation") 
  153. 					end 
  154. 				end 
  155. 			elseif event == "select" or event == "pause" then 
  156. 				if Dialog_objects[Dialog_current_idx]:select() then 
  157. 					game_UI_audio_play("UI_Main_Menu_Select") 
  158. 				end 
  159. 				 
  160. 				local selected_option_idx = Dialog_objects[Dialog_current_idx]:get_selected() 
  161. 				if game_get_platform() == "PC" and game_is_active_input_gamepad() == false and Dialog_objects[Dialog_current_idx]:has_second_option(selected_option_idx) == true then 
  162. 					if Dialog_objects[Dialog_current_idx]:nav(1) then 
  163. 						game_UI_audio_play("UI_Reward_Store_Menu_Navigation") 
  164. 					end 
  165. 				end 
  166. 			end 
  167. 		end 
  168.  
  169. 		-- Don't worry about the morph for Back events. Otherwise, spinner dialogs aren't cancelable 
  170. 		if event == "back" then 
  171. 			if Dialog_objects[Dialog_current_idx]:back() then 
  172. 				game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  173. 			end 
  174. 		end 
  175. 	end 
  176. end 
  177.  
  178. function dialog_input_tab() 
  179. 	dialog_input("nav_down") 
  180. end 
  181.  
  182. function dialog_build(dialog_operation, handle, previous_handle) 
  183. 	 
  184. 	if dialog_operation == DIALOG_OPERATION_TRANSITION then 
  185. 		local dialog_data = Dialogs[previous_handle] 
  186. 		Dialogs[previous_handle] = { } 
  187. 		Dialogs[handle] = dialog_data 
  188. 		 
  189. 		local dialog = dialog_data.object		 
  190. 		dialog.dialog_handle = handle 
  191. 		Dialog_current_handle = handle 
  192. 		 
  193. 		-- Disable inputs (because this morphs the dialog) 
  194. 		dialog_disable_mouse_input() 
  195. 		 
  196. 		--Send data to vdo...		 
  197. 		dialog_data.widgets_count = 0 
  198. 		vint_dataresponder_request("dialog_populate", "dialog_populate", 0, handle) 
  199. 		 
  200. 		dialog:create(dialog_data, true, dialog_box_morph_done) 
  201. 		dialog:open() 
  202. 		vint_set_property(dialog_data.object.handle, "depth", (Dialog_current_idx + 1) * -1000) 
  203. 		 
  204. 		-- DAD - 4/22/11 - Nav to the default option 
  205. 		if dialog_data.default > 0 then 
  206. 			dialog:nav(dialog_data.default) 
  207. 		end 
  208.  
  209. 		-- Mouse inputs are added by dialog_box_morph_done 
  210. 		Input_tracker:subscribe(true) 
  211. 		 
  212. 	elseif dialog_operation == DIALOG_OPERATION_NEW_DIALOG then 
  213. 		-- determine which object the dialog should go into... 
  214. 		Dialog_current_idx = Dialog_current_idx + 1 
  215. 		assert_msg(Dialog_current_idx >= 0 and Dialog_current_idx <= 2, "Invalid Dialog_current_idx DIALOG_OPERATION_NEW_DIALOG") 
  216. 		local dialog_object = Dialog_objects[Dialog_current_idx] 
  217. 		dialog_object.dialog_handle = handle 
  218. 		 
  219. 		--Build table for dialog entry... 
  220. 		Dialogs[handle] = { 
  221. 			object = dialog_object, 
  222. 			title = -1, 
  223. 			widgets_count = 0, 
  224. 		} 
  225. 		Dialog_current_handle = handle 
  226. 		 
  227. 		-- Get dialog  data 
  228. 		vint_dataresponder_request("dialog_populate", "dialog_populate", 0, handle) 
  229.  
  230. 		--Send data to vdo... 
  231. 		local dialog_data = Dialogs[handle] 
  232. 		local dialog = dialog_data.object 
  233. 		dialog:create(dialog_data, false) 
  234. 		dialog:open(true) 
  235. 		vint_set_property(dialog_data.object.handle, "depth", (Dialog_current_idx + 1) * -1000) 
  236. 		 
  237. 		-- DAD - 4/22/11 - Nav to the default option 
  238. 		if dialog_data.default > 0 then 
  239. 			dialog:nav(dialog_data.default) 
  240. 		end 
  241. 		 
  242. 		dialog_add_mouse_inputs(dialog) 
  243. 		Input_tracker:subscribe(true) 
  244. 		 
  245. 		--play dialog sound 
  246. 		game_UI_audio_play("UI_HUD_Dialog_Critical") 
  247. 	 
  248. 	elseif dialog_operation == DIALOG_OPERATION_REBUILD then 
  249. 		local dialog_data = Dialogs[handle] 
  250. 		local dialog = dialog_data.object		 
  251. 		dialog.dialog_handle = handle 
  252. 		Dialog_current_handle = handle 
  253. 		 
  254. 		-- Disable inputs (because this morphs the dialog) 
  255. 		dialog_disable_mouse_input() 
  256. 		 
  257. 		--Send data to vdo...		 
  258. 		dialog_data.widgets_count = 0 
  259. 		vint_dataresponder_request("dialog_populate", "dialog_populate", 0, handle) 
  260. 		 
  261. 		dialog:create(dialog_data, true, dialog_box_morph_done) 
  262. 		vint_set_property(dialog_data.object.handle, "depth", (Dialog_current_idx + 1) * -1000) 
  263. 		 
  264. 		-- DAD - 4/22/11 - Nav to the default option 
  265. 		if dialog_data.default > 0 then 
  266. 			dialog:nav(dialog_data.default) 
  267. 		end 
  268.  
  269. 		--Mouse inputs are added by dialog_box_morph_done 
  270. 		--Input_tracker:subscribe(true) 
  271.  
  272. 	elseif dialog_operation == DIALOG_OPERATION_CLOSE then 
  273. 		local dialog_data = Dialogs[handle] 
  274. 		local dialog = dialog_data.object 
  275. 		dialog:close() 
  276. 		 
  277. 		local shift_index = -1 
  278. 		for i, dlg in pairs(Dialog_objects) do 
  279. 			if dlg.dialog_handle == handle then 
  280. 				if i < Dialog_current_idx then 
  281. 					shift_index = i 
  282. 				end 
  283. 			end 
  284. 		end 
  285. 		 
  286. 		-- shuffle the dialogs so that Dialog_current_idx is correct 
  287. 		-- and we don't lose any of the dialog objects 
  288. 		if shift_index >= 0 then 
  289. 			local temp = Dialog_objects[shift_index]	-- Store the closing dialog object 
  290. 			 
  291. 			-- Shift all the dialogs back one 
  292. 			for i = shift_index + 1, #Dialog_objects do 
  293. 				Dialog_objects[i - 1] = Dialog_objects[i] 
  294. 			end 
  295. 			 
  296. 			-- Push the closing one to the end 
  297. 			Dialog_objects[#Dialog_objects] = temp 
  298. 			 
  299. 			-- Current Index should now point correctly to the current dialog 
  300. 		end 
  301. 		 
  302. 		Dialog_current_idx = Dialog_current_idx - 1 
  303. 		assert_msg(Dialog_current_idx == -1 or Dialog_current_idx == 1, "Invalid Dialog_current_idx DIALOG_OPERATION_CLOSE") 
  304. 		if Dialog_current_idx < 0 then  
  305. 			Input_tracker:subscribe(false) 
  306. 			dialog_disable_mouse_input() 
  307. 		else 
  308. 			dialog_add_mouse_inputs(Dialog_objects[Dialog_current_idx]) 
  309. 		end 
  310. 	end 
  311. end 
  312.  
  313. ------------------------------------------------------------------------------- 
  314. -- Populates our dialog box... this is called via dataresponder... 
  315. ------------------------------------------------------------------------------- 
  316. function dialog_populate(handle, widget_type, ...) 
  317.  
  318. 	-- process standard type widgets...	 
  319. 	local widget = {} 
  320. 	widget.type = widget_type 
  321.  
  322. 	--process odd type widgets first... 
  323. 	if widget_type == DIALOG_WIDGET_TYPE_TITLE then 
  324. 		-- Populate title 
  325. 		widget.title = arg[1]	--Title of the dialog. 
  326. 		Dialogs[handle].default = arg[2] -- Default selection 
  327. 	elseif widget_type == DIALOG_WIDGET_TYPE_OPTION then 
  328. 		--Add option to dialog 
  329. 		widget.has_second_option 	= arg[1]		--Do we have second option or not? 
  330. 		widget.disabled 				= arg[2]		--Is the option disabled? So we can make it display differently and the user cannot select it. 
  331. 		widget.tag_1		 			= arg[3]		--tag for first part of option 
  332. 		widget.tag_2 		 			= arg[4]		--tag for second part of option 
  333. 		widget.option_id 				= arg[5]		--ID of option... this gets passed back to game so we know what has been selected 
  334. 	elseif widget_type == DIALOG_WIDGET_TYPE_TEXT then 
  335. 		--Text field for dialog... 
  336. 		widget.text_tag	 	= arg[1]		--The text tag for the widget. 
  337. 		widget.num_lines 		= arg[2]		--How many lines we should make the widget... 
  338. 		widget.is_waiting 	= arg[3]		--Determines if this text line should be a cancel/waiting button...(HACK FOR SPINNER TYPES) 
  339. 		widget.is_massive 	= arg[4]		--If this is a massive text block... used for things like EULAs. This is so we can have a special way to display this. 
  340. 	elseif widget_type == DIALOG_WIDGET_TYPE_IMAGE then 
  341. 		--Image field for dialog... 
  342. 		widget.image_name		= arg[1]		--Image name to display. 
  343. 	elseif widget_type == DIALOG_WIDGET_TYPE_SPINNER then 
  344. 		--Spinner field for dialog... 
  345. 		widget.spinner_txt	= arg[1]		--This is the text that goes along with the spinner. 
  346. 	end 
  347. 	 
  348. 	local widget_num = Dialogs[handle].widgets_count 
  349. 	Dialogs[handle][widget_num] = widget 
  350. 	Dialogs[handle].widgets_count = widget_num + 1 
  351. end 
  352.  
  353. function do_define_test(dialog_handle, widget_type, ...) 
  354. end 
  355.  
  356. ------------------------------------ 
  357. --[	Lua Dialog Box Interface	]-- 
  358. ------------------------------------ 
  359. function dialog_box_confirmation(header, body, callback, is_close_on_death, is_close_on_damage, default) 
  360. 	if default == nil then 
  361. 		default = 0 
  362. 	end 
  363. 	local priority = DIALOG_PRIORITY_ACTION 
  364. 	local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  365. 	return dialog_box_open(header, body, options, callback, default, priority, true, nil, is_close_on_death, is_close_on_damage) 
  366. end 
  367.  
  368. function dialog_box_destructive_confirmation(header, body, callback) 
  369. 	local priority = DIALOG_PRIORITY_ACTION 
  370. 	local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  371. 	local default = 1 
  372. 	return dialog_box_open(header, body, options, callback, default, priority, true) 
  373. end 
  374.  
  375. function dialog_box_message(header, body, is_close_on_death, is_close_on_damage, callback) 
  376. 	local default = 0 
  377. 	local priority = DIALOG_PRIORITY_ACTION 
  378. 	local options = { [0] = "CONTROL_CONTINUE" } 
  379. 	return dialog_box_open(header, body, options, callback, 0, priority, false, nil, is_close_on_death, is_close_on_damage) 
  380. end 
  381.  
  382. function dialog_box_message_critical(header, body, is_close_on_death, is_close_on_damage) 
  383. 	local default = 0 
  384. 	local priority = DIALOG_PRIORITY_SYSTEM_CRITICAL 
  385. 	local options = { [0] = "CONTROL_CONTINUE" } 
  386. 	return dialog_box_open(header, body, options, nil, 0, priority, false, nil, is_close_on_death, is_close_on_damage) 
  387. end 
  388.  
  389. function dialog_box_open(header, body, options, callback, default, priority, is_confirmation, is_spinner, is_close_on_death, is_close_on_damage, is_close_on_mission_end, back_option) 
  390. 	priority = priority or DIALOG_PRIORITY_ACTION 
  391. 	callback = callback or "dialog_box_do_nothing" 
  392. 	is_confirmation = is_confirmation or false 
  393. 	is_spinner = is_spinner or false 
  394. 	is_close_on_death = is_close_on_death or true 
  395. 	is_close_on_damage = is_close_on_damage or false 
  396. 	is_close_on_mission_end = is_close_on_mission_end or true 
  397. 	back_option = back_option or -1 
  398. 	 
  399. 	local handle = dialog_box_create_internal(header, body, callback, priority, is_confirmation, is_spinner, options[0], options[1], options[2], options[3], default, is_close_on_death, is_close_on_damage, is_close_on_mission_end, back_option) 
  400. 	return handle 
  401. end 
  402.  
  403. function dialog_box_do_nothing() 
  404. end 
  405.  
  406. function dialog_box_morph_done() 
  407. 	if Dialog_current_idx > -1 then 
  408. 		dialog_add_mouse_inputs(Dialog_objects[Dialog_current_idx]) 
  409. 	end 
  410. end 
  411.  
  412. ------------------------------------------------------------------------------- 
  413. -- Mouse functions 
  414. ------------------------------------------------------------------------------- 
  415.  
  416. function dialog_add_mouse_inputs(dialog) 
  417. 	if Mouse_input_tracker ~= nil then 
  418. 		Mouse_input_tracker:remove_all(true) 
  419. 		dialog:add_mouse_inputs("dialog_mouse_click", "dialog_mouse_move", Mouse_input_tracker, 150) 
  420. 		Mouse_input_tracker:subscribe(true, true) 
  421. 	end 
  422. end 
  423.  
  424. function dialog_disable_mouse_input() 
  425. 	if Mouse_input_tracker ~= nil then 
  426. 		Mouse_input_tracker:remove_all(true) 
  427. 	end 
  428. end 
  429.  
  430. function dialog_mouse_move(event, target_handle) 
  431. 	if Dialog_objects[Dialog_current_idx] ~= nil then 
  432. 		if Ignore_input == false and not Dialog_objects[Dialog_current_idx].morph_playing then 
  433. 			 
  434. 			local hint_index = Dialog_objects[Dialog_current_idx].hint_bar:get_hint_index(target_handle) 
  435. 			 
  436. 			if hint_index == 1 then 
  437. 				Dialog_objects[Dialog_current_idx].hint_bar:set_highlight(hint_index) 
  438. 			else 
  439. 				Dialog_objects[Dialog_current_idx].hint_bar:set_highlight(0) 
  440. 			end 
  441.  
  442. 			local option_id = Dialog_objects[Dialog_current_idx]:get_option_index(target_handle) 
  443. 			if option_id > -1 then 
  444. 				Dialog_objects[Dialog_current_idx]:highlight_option(option_id) 
  445. 				game_UI_audio_play("UI_Reward_Store_Menu_Navigation")	 
  446. 			end 
  447. 		end 
  448. 	end 
  449. end 
  450.  
  451. function dialog_mouse_click(event, target_handle) 
  452. 	if Ignore_input == false and not Dialog_objects[Dialog_current_idx].morph_playing then 
  453. 		local hint_index = Dialog_objects[Dialog_current_idx].hint_bar:get_hint_index(target_handle) 
  454. 		if hint_index == 1 then 
  455. 			if Dialog_objects[Dialog_current_idx]:back() then 
  456. 				game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  457. 			end 
  458. 		end 
  459. 		local option_id = Dialog_objects[Dialog_current_idx]:get_option_index(target_handle) 
  460. 		if option_id > -1 then 
  461. 			Dialog_objects[Dialog_current_idx]:highlight_option(option_id) 
  462. 			Dialog_objects[Dialog_current_idx]:select() 
  463. 			game_UI_audio_play("UI_Main_Menu_Select") 
  464. 		end 
  465. 	end 
  466. end 
  467.  
  468. ------------------------------------------------------------------------------- 
  469. -- Paused.... 
  470. ------------------------------------------------------------------------------- 
  471. Dialog_pause_disconnect_dialog_handle = 0 
  472. Dialog_pause_partner_paused = false 
  473. Dialog_pause_allow_disconnect = false 
  474.  
  475. ------------------------------------------------------------------------------- 
  476. -- Shows the simplified pause screen... this is called via game code. 
  477. -- @param partner_paused				did the coop player pause the game? 
  478. -- @param	just_show_disconnect		does not indicate that the secondary player has paused.(used in special cases) 
  479. ------------------------------------------------------------------------------- 
  480. function dialog_pause_show(partner_paused, just_show_disconnect) 
  481. 	local h = Dialog_box.handles 
  482.  
  483. 	vint_set_property(h.paused, "visible", true) 
  484. 	vint_set_property(h.paused, "alpha", 1) 
  485. 	vint_set_property(h.paused_bg, "visible", true) 
  486. 	 
  487. 	if partner_paused or just_show_disconnect then 
  488. 		vint_set_property(h.partner_paused, "visible", true) 
  489. 		vint_set_property(h.partner_paused, "alpha", 1) 
  490. 		if partner_paused then 
  491. 			Dialog_pause_partner_paused = true 
  492. 			vint_set_property(h.partner_paused, "text_tag", "DIALOG_PAUSE_START_TO_DISCONNECT") 
  493. 		end 
  494. 		if just_show_disconnect then 
  495. 			Dialog_pause_allow_disconnect = true 
  496. 			vint_set_property(h.partner_paused, "text_tag", "COOP_DISCONNECT") 
  497. 		end 
  498. 	else 
  499. 		--Hide partner paused... 
  500. 		vint_set_property(h.partner_paused, "visible", false) 
  501. 		vint_set_property(h.partner_paused, "alpha", 0) 
  502. 		Dialog_pause_partner_paused = false 
  503. 		Dialog_pause_allow_disconnect = false 
  504. 	end 
  505. 	 
  506. 	if partner_paused then 
  507. 		--make sure we only remove the pause input once... 
  508. 		if Pause_input_added == true then 
  509. 			Pause_input_tracker:remove_input("pause") 
  510. 			Pause_input_added = false  
  511. 		end 
  512. 	else 
  513. 		if Pause_input_added == false then 
  514. 			Pause_input_tracker:add_input("pause", 		"dialog_pause_input", 100) 
  515. 			Pause_input_added = true 
  516. 		end  
  517. 	end 
  518.  
  519. 	Pause_input_tracker:subscribe(true) 
  520. end 
  521.  
  522. ------------------------------------------------------------------------------- 
  523. -- Hides the simplified pause screen... this is called via game code. 
  524. ------------------------------------------------------------------------------- 
  525. function dialog_pause_hide() 
  526. 	local h = Dialog_box.handles 
  527.  
  528. 	vint_set_property(h.paused, "visible", false) 
  529. 	vint_set_property(h.partner_paused, "visible", false) 
  530. 	vint_set_property(h.paused_bg, "visible", false) 
  531. 		 
  532. 	if Dialog_pause_disconnect_dialog_handle  ~= 0 then 
  533. 		dialog_box_force_close(Dialog_pause_disconnect_dialog_handle) 
  534. 		Dialog_pause_disconnect_dialog_handle = 0 
  535. 	end 
  536. 	 
  537. 	--	Unsubscribe to input 
  538. 	Pause_input_tracker:subscribe(false) 
  539. end 
  540.  
  541. function dialog_pause_disconnect(result, action) 
  542. 	if result == 0 then 
  543. 		dialog_box_disconnect() 
  544. 	else 
  545. 		Pause_input_tracker:subscribe(true) 
  546. 	end 
  547. 	 
  548. 	Dialog_pause_disconnect_dialog_handle = 0 
  549. end 
  550.  
  551. function dialog_pause_input(event, accelleration) 
  552. 	if Ignore_input == false then 
  553. 		if Dialog_pause_partner_paused == true then 
  554. 			if event == "map" then 
  555. 				--Map is the button to exit out of a partner paused situation 
  556. 				local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  557. 				Dialog_pause_disconnect_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "dialog_pause_disconnect", 1, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false) 
  558. 				Pause_input_tracker:subscribe(false) 
  559. 			end 
  560. 		else 
  561. 			if event == "map" and Dialog_pause_allow_disconnect == true then 
  562. 				--Map is the button to exit out of a partner paused situation 
  563. 				local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  564. 				Dialog_pause_disconnect_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "dialog_pause_disconnect", 1, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false) 
  565. 				Pause_input_tracker:subscribe(false) 
  566. 			elseif event == "pause" then 
  567. 				--Pause is the event in a normal paused situation. 
  568. 				dialog_pause_unpause() 
  569. 			end 
  570. 		end 
  571. 	end 
  572. end 
  573.  
  574. ------------------------------------------------------------------------------- 
  575. -- UTILITY FUNCTIONS 
  576. ------------------------------------------------------------------------------- 
  577. -- helper function to set a text tag 
  578. function dialog_box_set_tag(handle, value) 
  579. 	if type(value) == "number" then 
  580. 		vint_set_property(handle, "text_tag_crc", value) 
  581. 	elseif type(value) == "string" then 
  582. 		vint_set_property(handle, "text_tag", value) 
  583. 	else 
  584. 	 
  585. 	end 
  586. end 
  587.  
  588. -- set whether the dialog ignores input 
  589. function dialog_ignore_input(value) 
  590. 	Ignore_input = value 
  591. end 
  592.  
  593. function dialog_text_update(option_idx, new_text) 
  594. 	assert_msg(Dialog_current_idx >= 0 and Dialog_current_idx <= 2, "Invalid Dialog_current_idx in dialog_text_update") 
  595. 	Dialog_objects[Dialog_current_idx]:set_option_text(option_idx, new_text, true, dialog_box_morph_done) 
  596. end 
  597.  
  598. function dialog_select_next() 
  599. 	Dialog_objects[Dialog_current_idx]:nav(1) 
  600. 	local selected_option_idx = Dialog_objects[Dialog_current_idx]:get_selected() 
  601. 	if Dialog_objects[Dialog_current_idx]:has_second_option(selected_option_idx) == true then 
  602. 		Dialog_objects[Dialog_current_idx]:select() 
  603. 	end 
  604. end 
  605.  
  606. ------------------------------------------------------------------------------- 
  607. -- Test Functions... 
  608. ------------------------------------------------------------------------------- 
  609. function dialog_test_populate(handle) 
  610. 		dialog_populate(handle, DIALOG_WIDGET_TYPE_TITLE, 		"EULA!") 
  611. 		dialog_populate(handle, DIALOG_WIDGET_TYPE_SPINNER, 	"Waiting for coop player. Waiting for coop player. Waiting for coop player. Waiting for coop player.")		 
  612.  
  613. 		--dialog_populate(handle, DIALOG_WIDGET_TYPE_TEXT,		"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien lectus, rhoncus eu malesuada at, sodales sed eros. Sed sollicitudin, lorem sed laoreet convallis, neque tortor placerat diam, vitae accumsan enim ante sit amet turpis. Curabitur tempor posuere mollis. Vivamus quam nisl, ultricies at tempus ut, varius id erat. Integer iaculis enim a velit sodales laoreet ultricies justo tincidunt. Vestibulum sagittis dolor lacus. Quisque varius ultrices risus sed adipiscing. Donec sit amet leo nec nisi mollis sodales. Nullam velit orci, ornare a dignissim quis, luctus in ipsum. Proin convallis felis leo, ac lacinia nunc. Donec eu ligula tellus, a molestie mauris. Quisque rutrum velit eget diam viverra vel congue ligula mollis. Etiam at consectetur nulla. Nunc et semper augue. Maecenas rutrum dui ut metus dapibus venenatis. In hac habitasse platea dictumst. Nullam aliquet metus non nibh porta eget convallis justo tristique. Cras erat augue, facilisis tempor suscipit a, placerat quis risus. ", 	"YES2", 	1) 
  614. --		dialog_populate(handle, DIALOG_WIDGET_TYPE_IMAGE, 		"ui_homie_pierce") 
  615. --		dialog_populate(handle, DIALOG_WIDGET_TYPE_IMAGE, 		"ui_homie_pierce") 
  616. 	--	dialog_populate(handle, DIALOG_WIDGET_TYPE_IMAGE, 		"ui_hud_inv_melee_bat") 
  617. 	--	dialog_populate(handle, DIALOG_WIDGET_TYPE_SPINNER, 	"This is some spinner text that i'm using to set everything to..")		 
  618. 	--	dialog_populate(handle, DIALOG_WIDGET_TYPE_TEXT,		"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien lectus, rhoncus eu malesuada at, sodales sed eros. Sed sollicitudin, lorem sed laoreet convallis, neque tortor placerat diam, vitae accumsan enim ante sit amet turpis. Curabitur tempor posuere mollis. Vivamus quam nisl, ultricies at tempus ut, varius id erat. Integer iaculis enim a velit sodales laoreet ultricies justo tincidunt. Vestibulum sagittis dolor lacus. Quisque varius ultrices risus sed adipiscing. Donec sit amet leo nec nisi mollis sodales. Nullam velit orci, ornare a dignissim quis, luctus in ipsum. Proin convallis felis leo, ac lacinia nunc. Donec eu ligula tellus, a molestie mauris. Quisque rutrum velit eget diam viverra vel congue ligula mollis. Etiam at consectetur nulla. Nunc et semper augue. Maecenas rutrum dui ut metus dapibus venenatis.", 	0) 
  619. 		 
  620. --	dialog_populate(handle, DIALOG_WIDGET_TYPE_TEXT,		"This is a block of text that we are using to represent word wrap. and more complicated matters", 	"YES2", 	1) 
  621.  
  622. 	--dialog_populate(handle, DIALOG_WIDGET_TYPE_TEXT,		"This is a block of text that we are using to", 	"YES2", 	1) 
  623. 		--dialog_populate(handle, DIALOG_WIDGET_TYPE_SPINNER, 	"This is some spinner text that i'm using to set everything to..")		 
  624. 	--	dialog_populate(handle, DIALOG_WIDGET_TYPE_OPTION,	 	"ZOMG WHAT UP?!",	nil, 	0) 
  625. 		dialog_populate(handle, DIALOG_WIDGET_TYPE_OPTION,	 	"ACCEPT",	"", 	0) 
  626. 	--	dialog_populate(handle, DIALOG_WIDGET_TYPE_OPTION, 		"REALLY LONG O...",	"FORTYNINE",	1) 
  627.  
  628. 	 dialog_populate(handle, DIALOG_WIDGET_TYPE_OPTION, 		"ZOMG REALLY LONG TEXT",	"YES2",	0) 
  629. 	--	dialog_populate(handle, DIALOG_WIDGET_TYPE_OPTION, 		"RAD2",	"NO...",	4) 
  630. --		dialog_populate(handle, DIALOG_WIDGET_TYPE_OPTION, 		"RAD2",	"NOKAY",	5) 
  631. 	--	dialog_populate(handle, DIALOG_WIDGET_TYPE_OPTION, 		"RAD2",	"NOKAY",	6) 
  632. end 
  633.  
  634. function do_test_dialog() 
  635. 	dialog_test_populate(0) 
  636. 	Dialog_objects[0]:create(Dialogs[handle], false, false) 
  637. end