sr2lua/dialog_box.lua

  1. -- Menu Dialog 
  2.  
  3. Dialog_box = {  
  4. 	handles = { }, 
  5. } 
  6.  
  7. DIALOG_BOX_OPTION_OFFSET = 30	--	Space between options 
  8. DIALOG_BOX_MAX_WIDTH = 515	--	Maximum width of dialog box text 
  9. DIALOG_BOX_MIN_WIDTH = 192	--	Minimum width of dialog box text 
  10. DIALOG_BOX_BUTTON_WIDTH = 0	--Size of button to include with width of text 
  11. DIALOG_BOX_CENTER_SIZE = { X = -1, Y = -1 } 
  12. DIALOG_BOX_ANCHOR_OFFSET = { X = -1, Y = -1 } 
  13. DIALOG_BOX_UNSELECT_TEXT	= { ["R"] = 0.6235, ["G"] = 0.6353, ["B"] = 0.644 }	-- Color of text when not on the bar 
  14. DIALOG_BOX_HIGHLIGHT_TEXT 	= { ["R"] = 0, ["G"] = 0, ["B"] = 0 }								--	Color of text when on the bar 
  15.  
  16. DIALOG_RESULT_INVALID 		= -1 
  17.  
  18. DIALOG_ACTION_INVALID 		= -1 
  19. DIALOG_ACTION_NONE 			= 0 
  20. DIALOG_ACTION_FORCE_CLOSED = 1 
  21. DIALOG_ACTION_CLOSE 			= 2 
  22. DIALOG_ACTION_NAVIGATE 		= 3 
  23.  
  24. DIALOG_PRIORITY_INFORMATION 		= 0 
  25. DIALOG_PRIORITY_ACTION 				= 1 
  26. DIALOG_PRIORITY_GAME_CRITICAL		= 2 
  27. DIALOG_PRIORITY_SYSTEM_CRITICAL	= 3 
  28.  
  29. DIALOG_RESULT_YES = 0 
  30. DIALOG_RESULT_NO 	= 1 
  31.  
  32. Dialog_input_block = false 
  33. Dialog_on_top = false 
  34. Dialog_menu_base_input_block = false 
  35. Dialog_pause_disconnect_dialog_handle = 0 
  36.  
  37. ------------------------- 
  38. --[ UTILITY FUNCTIONS ]-- 
  39. ------------------------- 
  40. -- helper function to set a text tag 
  41. function dialog_box_set_tag(handle, value) 
  42. 	if type(value) == "number" then 
  43. 		vint_set_property(handle, "text_tag_crc", value) 
  44. 	elseif type(value) == "string" then 
  45. 		vint_set_property(handle, "text_tag", value) 
  46. 	else 
  47. 	end 
  48. end 
  49.  
  50. ------------------------------- 
  51. --[ INITIALIZE AND SHUTDOWN ]-- 
  52. ------------------------------- 
  53. function dialog_box_init() 
  54. 	debug_print("vint", "Dialog Init Start()\n") 
  55. 	local dialog_h = vint_object_find("dialog_box") 
  56. 	local d = Dialog_box    	 
  57. 	d.handles = { } 
  58. 	d.handles["dialog"] 		= dialog_h 
  59. 	d.handles["box"] 			=  vint_object_find("box", dialog_h) 
  60. 	d.handles["background"] =  vint_object_find("background", dialog_h) 
  61. 	d.handles["heading"]		 = vint_object_find("header_text", dialog_h) 
  62. 	d.handles["body"]			= vint_object_find("body_text", dialog_h) 
  63. 	d.handles["spinner"]			= vint_object_find("spinner", dialog_h) 
  64. 	d.handles["option"]		= vint_object_find("option_text", dialog_h) 
  65. 	d.handles["select"]		= vint_object_find("select_bar", dialog_h) 
  66. 	d.handles["selections"]	= vint_object_find("selections", dialog_h) 
  67. 	d.handles["sel_bar_e"] = vint_object_find("sel_bar_e", dialog_h) 
  68. 	d.handles["sel_bar_e_highlight"] = vint_object_find("sel_bar_e_highlight", dialog_h) 
  69. 	d.handles["sel_bar_w"] = vint_object_find("sel_bar_w", dialog_h) 
  70. 	d.handles["sel_bar_w_highlight"] = vint_object_find("sel_bar_w_highlight", dialog_h) 
  71. 	 
  72. 	d.heading_x, d.heading_y = vint_get_property(d.handles["heading"]	, "anchor") 
  73. 	d.body_x, d.body_y = vint_get_property(d.handles["body"]	, "anchor") 
  74. 	 
  75. 	local box_h = vint_object_find("static_elements", dialog_h) 
  76. 	d.handles["box_c"] = vint_object_find("box_c", box_h) 
  77. 	d.handles["box_e"] = vint_object_find("box_e", box_h) 
  78. 	d.handles["box_n"] = vint_object_find("box_n", box_h) 
  79. 	d.handles["box_ne"] = vint_object_find("box_ne", box_h) 
  80. 	d.handles["box_w"] = vint_object_find("box_w", box_h) 
  81. 	d.handles["box_s"] = vint_object_find("box_s", box_h) 
  82. 	d.handles["box_sw"] = vint_object_find("box_sw", box_h) 
  83. 	d.handles["box_se"] = vint_object_find("box_se", box_h) 
  84. 		 
  85. 	--Animations 
  86. 	d.handles["fade_in_anim"] = vint_object_find("fade_in") 
  87. 	d.handles["fade_out_anim"] = vint_object_find("fade_out") 
  88. 	vint_set_property(d.handles["fade_in_anim"], "is_paused", true) 
  89. 	vint_set_property(d.handles["fade_out_anim"], "is_paused", true) 
  90. 	 
  91. 	--Paused stuff 
  92. 	d.handles["paused"] = vint_object_find("paused") 
  93. 	d.handles["partner_paused"] = vint_object_find("partner_paused", d.handles["paused"]) 
  94. 	d.handles["paused_background"] = vint_object_find("background", d.handles["paused"]) 
  95. 	 
  96. 	--Coop invite message 
  97. 	d.handles.player_invited_you = vint_object_find("player_invited_you") 
  98. 	d.handles.player_invited_you_text = vint_object_find("invite_text", d.handles.player_invited_you) 
  99. 	 
  100. 	--..Coop invite fade out 
  101. 	d.handles.coop_invite_fade_out = vint_object_find("coop_invite_fade_out") 
  102. 	vint_set_property(d.handles.coop_invite_fade_out, "is_paused", true) 
  103. 	 
  104. 	--end callback 
  105. 	local twn_h = vint_object_find("background_alpha_twn_1", d.handles["fade_out_anim"]) 
  106. 	vint_set_property(twn_h, "end_event", "dialog_box_close_thesequel") 
  107. 	 
  108. 	--Initialize Spinner 
  109. 	dialog_box_use_spinner(false) 
  110. 	 
  111. 	DIALOG_BOX_CENTER_SIZE.X, DIALOG_BOX_CENTER_SIZE.Y = element_get_actual_size(d.handles["box_c"]) 
  112. 	DIALOG_BOX_ANCHOR_OFFSET.X, DIALOG_BOX_ANCHOR_OFFSET.Y = vint_get_property(d.handles["box"], "anchor") 
  113. 	 
  114. 	--Hide all elements until needed. 
  115. 	vint_set_property(d.handles["paused"], "visible", false) 
  116. 	vint_set_property(dialog_h, "visible", false) 
  117.  
  118. 	--Set A Button 
  119. 	local btn_h = vint_object_find("btn_select") 
  120. 	vint_set_property(btn_h, "image", get_a_button()) 
  121.  
  122. 	if get_platform() == "PC" then 
  123. 		vint_set_property(btn_h, "visible", false) 
  124. 	end 
  125.  
  126. 	local btn_h = vint_object_find("btn_select_highlight") 
  127. 	vint_set_property(btn_h, "image", get_a_button()) 
  128.  
  129. 	if get_platform() == "PC" then 
  130. 		vint_set_property(btn_h, "visible", false) 
  131. 	end 
  132.  
  133. 	--This is evil, but will help with menu swapping. 
  134. 	thread_new("vint_menu_swap_thread") 
  135. end 
  136.  
  137. function dialog_box_cleanup() 
  138.  
  139. end 
  140.  
  141. --------------------- 
  142. --[ FUNCTIONALITY	]-- 
  143. --------------------- 
  144. function dialog_box_grab_input() 
  145. 	if Dialog_box.input_subs ~= nil then 
  146. 		return 
  147. 	end 
  148. 	 
  149. 	local subscription_priority = 125 
  150. 	if Dialog_on_top == true then 
  151. 		subscription_priority = 200 
  152. 	end 
  153. 	 
  154. 	--	Subscribe to the input 
  155. 	Dialog_box.input_subs = {	 
  156. 		vint_subscribe_to_input_event(nil, "nav_up",				"dialog_box_input", subscription_priority), 
  157. 		vint_subscribe_to_input_event(nil, "nav_down",			"dialog_box_input", subscription_priority), 
  158. 		vint_subscribe_to_input_event(nil, "select",				"dialog_box_input", subscription_priority), 
  159. 		vint_subscribe_to_input_event(nil, "pause",				"dialog_box_input", subscription_priority), 
  160. 		vint_subscribe_to_input_event(nil, "back",				"dialog_box_input", subscription_priority), 
  161. 		vint_subscribe_to_input_event(nil, "all_unassigned",	"dialog_box_input", subscription_priority), 
  162. 	} 
  163. end 
  164.  
  165. function dialog_box_release_input() 
  166. 	if Dialog_box.input_subs == nil then 
  167. 		return 
  168. 	end 
  169. 	 
  170. 	--	Unsubscribe to input 
  171. 	for idx, val in Dialog_box.input_subs do 
  172. 		vint_unsubscribe_to_input_event(val) 
  173. 	end 
  174. 	Dialog_box.input_subs = nil 
  175. end 
  176.  
  177. function dialog_box_open(header, body, options, callback, default, priority, is_confirmation, is_spinner, is_close_on_death, is_close_on_damage) 
  178. 	if Dialog_menu_base_input_block == false then 
  179. 		if vint_document_find("menu_base") ~= 0 then 
  180. 			Dialog_menu_base_input_block = true 
  181. 			menu_input_block(true) 
  182. 		end	 
  183. 	end 
  184. 	 
  185. 	if priority == nil then 
  186. 		priority = DIALOG_PRIORITY_ACTION 
  187. 	end 
  188.  
  189. 	if callback == nil then 
  190. 		callback = "dialog_box_do_nothing" 
  191. 	end 
  192. 	 
  193. 	if is_confirmation ~= true then 
  194. 		is_confirmation = false 
  195. 	end 
  196. 	 
  197. 	if is_spinner ~= true then 
  198. 		is_spinner = false 
  199. 	end 
  200. 	 
  201. 	if is_close_on_death == nil then 
  202. 		is_close_on_death = true 
  203. 	end 
  204. 	if is_close_on_damage == nil then 
  205. 		is_close_on_damage = false 
  206. 	end 
  207.  
  208. 	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) 
  209. 	Dialog_input_block = false 
  210. 	 
  211. 	return handle 
  212. end 
  213.  
  214. function dialog_box_open_internal(handle, header, body, default, is_spinner, is_confirmation, priority, fullscreen_fade, option_1, option_2, option_3, option_4) 
  215. 	local d = Dialog_box 
  216. 	d.handle 	= handle 
  217.  
  218. 	-- Store the header and body 
  219. 	d.header = header 
  220. 	d.body = body 
  221. 	d.is_confirmation = is_confirmation 
  222. 	 
  223. 	-- Make sure we deleted old options (chained dialogs) 
  224. 	if d.options ~= nil then 
  225. 		-- Delete the clones, 1st one isn't a clone 
  226. 		for i = 1, d.options.num_options - 1 do 
  227. 			vint_object_destroy(d.options[i].label_h) 
  228. 		end 
  229. 		d.options.num_options = 0 
  230. 	end 
  231.  
  232. 	--	Store the options 
  233. 	d.options = { num_options = 0 } 
  234. 	if option_1 ~= nil then 
  235. 		d.options[d.options.num_options] = { label = option_1 } 
  236. 		d.options.num_options = d.options.num_options + 1 
  237. 	end 
  238. 	if option_2 ~= nil then 
  239. 		d.options[d.options.num_options] = { label = option_2 } 
  240. 		d.options.num_options = d.options.num_options + 1 
  241. 	end 
  242. 	if option_3 ~= nil then 
  243. 		d.options[d.options.num_options] = { label = option_3 } 
  244. 		d.options.num_options = d.options.num_options + 1 
  245. 	end 
  246. 	if option_4 ~= nil then 
  247. 		d.options[d.options.num_options] = { label = option_4 } 
  248. 		d.options.num_options = d.options.num_options + 1 
  249. 	end 
  250. 	 
  251. 	d.cur_idx = 0 
  252. 	 
  253. 	--	Set the current item selected in the dialog 
  254. 	if default < d.options.num_options and default >= 0 then 
  255. 		d.cur_idx = default 
  256. 	end 
  257. 	 
  258. 	--	Get the current position for the options 
  259. 	local anchor = { } 
  260. 	anchor.x, anchor.y = vint_get_property(d.handles["option"], "anchor") 
  261. 	 
  262. 	-- Set Text Tags and positions 
  263. 	dialog_box_set_tag(d.handles["heading"], d.header) 
  264. 	dialog_box_set_tag(d.handles["body"], d.body) 
  265. 	 
  266. 	--Reset header and spinersize 
  267. 	vint_set_property(d.handles["heading"], "scale", 1, 1) 
  268. 	vint_set_property(d.handles["spinner"], "scale", 1, 1) 
  269. 	 
  270. 	--Move body to original position 
  271. 	vint_set_property(d.handles["body"], "anchor", d.body_x, d.body_y) 
  272. 	 
  273. 	--check width of box without word wrap 
  274. 	vint_set_property(d.handles["body"], "word_wrap" , false) 
  275. 	 
  276. 	--Dialog box has to be smaller if we are using a spinner 
  277. 	local dialog_box_max_width_internal = DIALOG_BOX_MAX_WIDTH 
  278. 	if is_spinner == true then 
  279. 		dialog_box_max_width_internal  = DIALOG_BOX_MAX_WIDTH - 33 
  280. 	end 
  281. 	 
  282. 	--Get width / height of body of text in dialog 
  283. 	local body_width, body_height =	element_get_actual_size(d.handles["body"]) 
  284. 	local heading_width, heading_height = element_get_actual_size(d.handles["heading"]) 
  285. 	local max_text_width = body_width 
  286.  
  287. 	if body_width > dialog_box_max_width_internal then 
  288. 		--If text is larger than max width reset the word wrap to true 
  289. 		vint_set_property(d.handles["body"], "word_wrap" , true) 
  290. 				 
  291. 		--Reset the wrap width 
  292. 		vint_set_property(d.handles["body"], "wrap_width" , dialog_box_max_width_internal) 
  293. 		max_text_width = dialog_box_max_width_internal 
  294. 	end 
  295. 	 
  296. 	if heading_width > max_text_width then 
  297. 		if heading_width > dialog_box_max_width_internal then 
  298. 			--heading is too big... we need to resize it. 
  299. 			local target_scale = dialog_box_max_width_internal / heading_width 
  300. 			local og_heading_height = heading_height 
  301. 			vint_set_property(d.handles["heading"], "scale", target_scale, target_scale)	 
  302.  
  303. 			--reset sizes after we resized stuff 
  304. 			heading_width, heading_height = element_get_actual_size(d.handles["heading"]) 
  305. 			 
  306. 			--move position of body 
  307. 			local body_vertical_offset = og_heading_height - heading_height 
  308. 			 
  309. 			vint_set_property(d.handles["body"], "anchor", d.body_x, d.heading_y + heading_height ) 
  310. 		end 
  311. 		 
  312. 		--Oh k... so the header is larger than where we want the body to be... 
  313. 		vint_set_property(d.handles["body"], "wrap_width" , heading_width) 
  314. 		max_text_width = heading_width  
  315. 	end 
  316. 	 
  317. 	--Sizes likely have changed so lets verify everything. 
  318. 	body_width, body_height =	element_get_actual_size(d.handles["body"]) 
  319. 	 
  320. 	--	Adjust the position for the first option 
  321. 	local body_anchor = { } 
  322. 	body_anchor.x, body_anchor.y = vint_get_property(d.handles["body"], "anchor") 
  323. 	 
  324. 	local selections_anchor = {} 
  325. 	selections_anchor.x, selections_anchor.y = vint_get_property(d.handles["selections"], "anchor") 
  326. 	selections_anchor.y = body_anchor.y + body_height 
  327. 	vint_set_property(d.handles["selections"], "anchor", selections_anchor.x, selections_anchor.y) 
  328.  
  329. 	local option_max_width = 0 
  330. 	if d.options.num_options > 0 then 
  331. 		--	Create the options 
  332. 		d.options[0].label_h = d.handles["option"] 
  333.  
  334. 		dialog_box_set_tag(d.options[0].label_h, d.options[0].label) 
  335. 		vint_set_property(d.options[0].label_h, "tint", DIALOG_BOX_UNSELECT_TEXT.R, DIALOG_BOX_UNSELECT_TEXT.G, DIALOG_BOX_UNSELECT_TEXT.B) 
  336. 		vint_set_property(d.options[0].label_h, "anchor", anchor.x, anchor.y ) 
  337. 		vint_set_property(d.options[0].label_h, "visible", true) 
  338. 		 
  339. 		option_max_width = element_get_actual_size(d.options[0].label_h) + DIALOG_BOX_BUTTON_WIDTH 
  340. 		if option_max_width > max_text_width then 
  341. 			max_text_width = option_max_width 
  342. 		end 
  343. 		 
  344. 		for i = 1, d.options.num_options - 1 do 
  345. 			d.options[i].label_h = vint_object_clone(d.handles["option"]) 
  346. 			dialog_box_set_tag(d.options[i].label_h, d.options[i].label) 
  347. 			anchor.y = anchor.y + DIALOG_BOX_OPTION_OFFSET 
  348. 			vint_set_property(d.options[i].label_h, "anchor", anchor.x, anchor.y) 
  349. 			vint_set_property(d.options[i].label_h, "tint", DIALOG_BOX_UNSELECT_TEXT.R, DIALOG_BOX_UNSELECT_TEXT.G, DIALOG_BOX_UNSELECT_TEXT.B) 
  350. 			 
  351. 			option_max_width = element_get_actual_size(d.options[i].label_h) + DIALOG_BOX_BUTTON_WIDTH 
  352. 			if option_max_width > max_text_width then 
  353. 				max_text_width = option_max_width 
  354. 			end 
  355. 		end 
  356. 	end		 
  357. 	 
  358. 	--	Resize the dialog to fit all the text 
  359. 	local center_width = floor(max_text_width) 
  360. 	local center_height = floor(anchor.y + selections_anchor.y) 
  361. 	local se_x, se_y, anchor_x, anchor_y 
  362. 	 
  363. 	if center_width < DIALOG_BOX_MIN_WIDTH then 
  364. 		center_width = DIALOG_BOX_MIN_WIDTH  
  365. 	end 
  366. 	 
  367. 	--Add/subtract padding to accomodate for box padding 
  368. 	 
  369. 	center_width = center_width + 10 
  370. 	center_height = center_height - 48 
  371.  
  372. 	if d.options.num_options == 0 then 
  373. 		center_width = dialog_box_max_width_internal 
  374. 	end 
  375.  
  376. 	element_set_actual_size(d.handles["box_c"], center_width, center_height) 
  377. 	 
  378. 	local WEST_TO_CENTER_OFFSET = 79 
  379. 	local EAST_TO_CENTER_OFFSET = 72 
  380. 	local EAST_TO_CENTER_BOTTOM_OFFSET = EAST_TO_CENTER_OFFSET + 6 
  381. 	local CENTER_X, CENTER_Y = vint_get_property(d.handles["box_c"], "anchor") 
  382. 	local CENTER_OFFSET = WEST_TO_CENTER_OFFSET + EAST_TO_CENTER_OFFSET 
  383. 	 
  384. 	--NORTH 
  385. 	se_x, se_y = vint_get_property(d.handles["box_n"], "source_se") 
  386. 	vint_set_property(d.handles["box_n"], "source_se", center_width - CENTER_OFFSET, se_y) 
  387.  
  388. 	--NORTHEAST 
  389. 	anchor_x, anchor_y = vint_get_property(d.handles["box_ne"], "anchor") 
  390. 	vint_set_property(d.handles["box_ne"], "anchor", center_width - EAST_TO_CENTER_OFFSET + CENTER_X , anchor_y) 
  391. 	 
  392. 	--EAST 
  393. 	se_x, se_y = vint_get_property(d.handles["box_e"], "source_se") 
  394. 	vint_set_property(d.handles["box_e"], "source_se", se_x, center_height) 
  395. 	anchor_x, anchor_y = vint_get_property(d.handles["box_e"], "anchor") 
  396. 	vint_set_property(d.handles["box_e"], "anchor", center_width + CENTER_X, anchor_y) 
  397. 		 
  398. 	--SOUTHEAST 
  399. 	anchor_x, anchor_y = vint_get_property(d.handles["box_se"], "anchor") 
  400. 	vint_set_property(d.handles["box_se"], "anchor", center_width - EAST_TO_CENTER_OFFSET + CENTER_X, center_height + CENTER_Y) 
  401. 	 
  402. 	--SOUTH 
  403. 	se_x, se_y = vint_get_property(d.handles["box_s"], "source_se") 
  404. 	vint_set_property(d.handles["box_s"], "source_se", center_width - EAST_TO_CENTER_BOTTOM_OFFSET - WEST_TO_CENTER_OFFSET, se_y) 
  405. 	anchor_x, anchor_y = vint_get_property(d.handles["box_s"], "anchor") 
  406. 	vint_set_property(d.handles["box_s"], "anchor", anchor_x, center_height + CENTER_Y) 
  407. 	 
  408. 	--SOUTHWEST 
  409. 	anchor_x, anchor_y = vint_get_property(d.handles["box_sw"], "anchor") 
  410. 	vint_set_property(d.handles["box_sw"], "anchor", anchor_x, center_height + CENTER_Y) 
  411. 	 
  412. 	--WEST 
  413. 	se_x, se_y = vint_get_property(d.handles["box_w"], "source_se") 
  414. 	vint_set_property(d.handles["box_w"], "source_se", se_x, center_height) 
  415. 	 
  416. 	-- Show the Dialog 
  417. 	vint_set_property(d.handles["dialog"], "visible", true) 
  418. 	 
  419. 	--	Move the selector bar 
  420. 	if d.options.num_options > 0 then 
  421. 		local select_anchor = { } 
  422. 		 
  423. 		select_anchor.x, select_anchor.y = vint_get_property(d.options[d.cur_idx].label_h, "anchor") 
  424. 		select_anchor.x = vint_get_property(d.handles["select"], "anchor") 
  425. 		vint_set_property(d.handles["select"], "anchor", select_anchor.x, select_anchor.y) 
  426. 		 
  427. 		--	Adjust the position for the first option 
  428. 		local body_anchor = { } 
  429. 		body_anchor.x, body_anchor.y = vint_get_property(d.handles["body"], "anchor") 
  430. 		 
  431. 		local selections_anchor = {} 
  432. 		selections_anchor.x, selections_anchor.y = vint_get_property(d.handles["selections"], "anchor") 
  433. 		selections_anchor.y = body_anchor.y + body_height 
  434. 		vint_set_property(d.handles["selections"], "visible", true) 
  435. 		vint_set_property(d.handles["selections"], "anchor", selections_anchor.x, selections_anchor.y) 
  436. 		vint_set_property(d.options[d.cur_idx].label_h, "tint", DIALOG_BOX_HIGHLIGHT_TEXT.R, DIALOG_BOX_HIGHLIGHT_TEXT.G, DIALOG_BOX_HIGHLIGHT_TEXT.B) 
  437. 	else 
  438. 		vint_set_property(d.handles["selections"], "visible", false) 
  439. 	end 
  440. 	 
  441. 	local SELECTOR_BAR_WIDTH_OFFSET = 0 
  442. 	--Resize selector bar 
  443. 	se_x, se_y = vint_get_property(d.handles["sel_bar_w"] , "source_se") 
  444. 	vint_set_property(d.handles["sel_bar_w"] , "source_se", center_width + SELECTOR_BAR_WIDTH_OFFSET , se_y) 
  445. 	vint_set_property(d.handles["sel_bar_w_highlight"] , "source_se", center_width + SELECTOR_BAR_WIDTH_OFFSET , se_y) 
  446. 	 
  447. 	anchor_x, anchor_y = vint_get_property(d.handles["sel_bar_e"], "anchor") 
  448. 	local selector_anchor = { } 
  449. 	selector_anchor.x, selector_anchor.y = vint_get_property(d.handles["sel_bar_w"], "anchor") 
  450. 	vint_set_property(d.handles["sel_bar_e"], "anchor", center_width + selector_anchor.x + SELECTOR_BAR_WIDTH_OFFSET , anchor_y) 
  451. 	vint_set_property(d.handles["sel_bar_e_highlight"], "anchor", center_width + selector_anchor.x + SELECTOR_BAR_WIDTH_OFFSET , anchor_y) 
  452. 	 
  453. 	local original_offset = {} 
  454. 	original_offset.x = DIALOG_BOX_ANCHOR_OFFSET.X + (DIALOG_BOX_CENTER_SIZE.X / 2 ) 
  455. 	original_offset.y = DIALOG_BOX_ANCHOR_OFFSET.Y + (DIALOG_BOX_CENTER_SIZE.Y / 2 ) 
  456. 	 
  457. 	local current_offset = {} 
  458. 	current_offset.x = DIALOG_BOX_ANCHOR_OFFSET.X + (center_width / 2 ) 
  459. 	current_offset.y = DIALOG_BOX_ANCHOR_OFFSET.Y + (center_height / 2 ) 
  460.  
  461. 	vint_set_property(d.handles["box"], "anchor", DIALOG_BOX_ANCHOR_OFFSET.X - (current_offset.x - original_offset.x), DIALOG_BOX_ANCHOR_OFFSET.Y - (current_offset.y - original_offset.y)) 
  462.  
  463. 	Dialog_input_block = false 
  464.  
  465. 	if priority == DIALOG_PRIORITY_SYSTEM_CRITICAL then	 
  466. 		Dialog_on_top = true 
  467. 	else 
  468. 		Dialog_on_top = false 
  469. 	end 
  470. 		 
  471. 	--Set depth of pause/dialog 
  472. 	if Dialog_on_top == true then 
  473. 		vint_set_property(d.handles["dialog"], "depth", -10) 
  474. 		vint_set_property(d.handles["paused"], "depth", 0) 
  475. 	else 
  476. 		vint_set_property(d.handles["dialog"], "depth", 0) 
  477. 		vint_set_property(d.handles["paused"], "depth", -10) 
  478. 	end 
  479. 	 
  480. 	dialog_box_grab_input() 
  481. 	 
  482. 	-- Play the open sound 
  483. 	if d.options.num_options < 2 then 
  484. 		audio_play(DIALOG_OPEN_SOUND)	 
  485. 	else 
  486. 		audio_play(DIALOG_SERIOUS_SOUND) 
  487. 	end 
  488.  
  489. 	-- Use the spinner if necessary 
  490. 	dialog_box_use_spinner(is_spinner) 
  491. 	 
  492. 	--	 FADE IN ANIMATION GOES HERE 
  493. 	if fullscreen_fade == true then 
  494. 		vint_set_property(d.handles["background"], "alpha", 1) 
  495. 		vint_set_property(d.handles["box"], "alpha", 1) 
  496. 	else 
  497. 		vint_set_property(d.handles["background"], "alpha", 0.5) 
  498. 		vint_set_property(d.handles["fade_out_anim"], "is_paused", true) 
  499. 		lua_play_anim(d.handles["fade_in_anim"], 0) 
  500. 	end 
  501. end 
  502.  
  503. function dialog_box_input(target, event, accelleration) 
  504. 	if Dialog_input_block == true then 
  505. 		return 
  506. 	end 
  507. 	local d = Dialog_box 
  508. 	local old_idx = -1 
  509. 	 
  510. 	if d.options.num_options == 0 then 
  511. 		-- this is a system dialog so no input 
  512. 		return 
  513. 	end 
  514. 	 
  515. 	-- Up 
  516. 	if event == "nav_up" then 
  517. 		old_idx = d.cur_idx				--	Store the old index 
  518. 		if d.cur_idx == 0 then			--	Wrap around if we have to 
  519. 			d.cur_idx = d.options.num_options - 1 
  520. 		else 
  521. 			d.cur_idx = d.cur_idx - 1	--	Otherwise move it up 
  522. 		end 
  523. 	-- Down 
  524. 	elseif event == "nav_down" then 
  525. 		old_idx = d.cur_idx				--	Store the old index 
  526. 		if d.cur_idx == d.options.num_options - 1 then 
  527. 			d.cur_idx = 0					--	Wrap around... 
  528. 		else 
  529. 			d.cur_idx = d.cur_idx + 1	--	Move it down 
  530. 		end 
  531. 	-- Select 
  532. 	elseif event == "select" then 
  533. 		Dialog_input_block = true 
  534. 		dialog_box_select() 
  535. 	-- Cancel 
  536. --	elseif event == "back" then 
  537. --		--if d.is_confirmation == true then 
  538. --		if d.options.num_options > 0 then 
  539. --			Dialog_input_block = true 
  540. --			dialog_box_set_result(d.handle, DIALOG_RESULT_INVALID, DIALOG_ACTION_FORCE_CLOSED) 
  541. --		end 
  542. 	end 
  543.  
  544. 	-- Move the select bar if we changed options 
  545. 	if old_idx ~= -1 then 
  546. 		--	Get the anchor of the top one 
  547. 		local anchor = { } 
  548. 		anchor.x, anchor.y = vint_get_property(d.handles["option"], "anchor") 
  549. 		anchor.x = vint_get_property(d.handles["select"], "anchor") 
  550. 		 
  551. 		--	Fix the color on the old option 
  552. 		vint_set_property(d.options[old_idx].label_h, "tint", DIALOG_BOX_UNSELECT_TEXT.R, DIALOG_BOX_UNSELECT_TEXT.G, DIALOG_BOX_UNSELECT_TEXT.B) 
  553. 		-- Move the selection bar 
  554. 		vint_set_property(d.handles["select"], "anchor", anchor.x, anchor.y + (d.cur_idx * DIALOG_BOX_OPTION_OFFSET)) 
  555. 		--	Fix the tint on the new option 
  556. 		vint_set_property(d.options[d.cur_idx].label_h, "tint", DIALOG_BOX_HIGHLIGHT_TEXT.R, DIALOG_BOX_HIGHLIGHT_TEXT.G, DIALOG_BOX_HIGHLIGHT_TEXT.B) 
  557. 		dialog_box_set_result(d.handle, d.cur_idx, DIALOG_ACTION_NAVIGATE) 
  558. 	end 
  559. end 
  560.  
  561. function dialog_box_close(force) 
  562. 	local d = Dialog_box 
  563. 	if force == true then 
  564. 		--	FORCE CLOSE 
  565. 		dialog_box_close_thesequel() 
  566. 	else 
  567. 		-- DON'T FORCE CLOSE, JUST ANIMATE OUT, callback will occur 
  568. 		lua_play_anim(d.handles["fade_out_anim"], 0) 
  569. 	end 
  570. end 
  571.  
  572. function dialog_box_close_thesequel() 
  573. 	local d = Dialog_box 
  574. 	 
  575. 	if Dialog_menu_base_input_block == true then 
  576. 		Dialog_menu_base_input_block = false 
  577. 		if vint_document_find("menu_base") ~=0 then 
  578. 			menu_input_block(false) 
  579. 		end 
  580. 	end 
  581.  
  582. 	if d.handles ~= nil then 
  583. 		--	Hide the Dialog Box 
  584. 		vint_set_property(d.handles["dialog"], "visible", false) 
  585. 	end 
  586. 	 
  587. 	if d.options ~= nil then 
  588. 		-- Delete the clones, 1st one isn't a clone 
  589. 		for i = 1, d.options.num_options - 1 do 
  590. 			vint_object_destroy(d.options[i].label_h) 
  591. 		end 
  592. 		d.options.num_options = 0 
  593. 	end 
  594. 	 
  595. 	dialog_box_release_input() 
  596. end 
  597.  
  598. function dialog_box_use_spinner(is_active) 
  599. 	local d = Dialog_box 
  600. 	if is_active == true then 
  601. 		--show spinner and update layout 
  602. 		vint_set_property(d.handles["spinner"], "visible", true) 
  603. 		local w, h = element_get_actual_size(d.handles["spinner"]) 
  604. 		local s_w, s_h = vint_get_property(d.handles["heading"], "scale") 
  605. 		local x = d.heading_x + w * s_w 
  606. 		vint_set_property(d.handles["heading"], "anchor", x, d.heading_y) 
  607. 	else 
  608. 		--hide spinner and update layout 
  609. 		vint_set_property(d.handles["heading"], "anchor", d.heading_x, d.heading_y) 
  610. 		vint_set_property(d.handles["spinner"], "visible", false) 
  611. 	end 
  612. end 
  613.  
  614.  
  615. function dialog_box_select() 
  616. 	local d = Dialog_box 
  617. 	 
  618. --	dialog_box_close() 
  619. 	audio_play(Menu_sound_select) 
  620. 	 
  621. 	-- Send the selection to C 
  622. 	dialog_box_set_result(d.handle, d.cur_idx, DIALOG_ACTION_CLOSE) 
  623. end 
  624.  
  625. function dialog_box_do_nothing(option, action) 
  626. end 
  627.  
  628. --------------------- 
  629. --[	TEMPLATES	]-- 
  630. --------------------- 
  631. function dialog_box_confirmation(header, body, callback, is_close_on_death, is_close_on_damage) 
  632. 	local default = 0 
  633. 	local priority = DIALOG_PRIORITY_ACTION 
  634. 	local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  635. 	return dialog_box_open(header, body, options, callback, default, priority, true, nil, is_close_on_death, is_close_on_damage) 
  636. end 
  637.  
  638. function dialog_box_message(header, body, is_close_on_death, is_close_on_damage) 
  639. 	local default = 0 
  640. 	local priority = DIALOG_PRIORITY_ACTION 
  641. 	local options = { [0] = "CONTROL_CONTINUE" } 
  642. 	return dialog_box_open(header, body, options, nil, 0, priority, false, nil, is_close_on_death, is_close_on_damage) 
  643. end 
  644.  
  645. function dialog_box_message_critical(header, body, is_close_on_death, is_close_on_damage) 
  646. 	local default = 0 
  647. 	local priority = DIALOG_PRIORITY_SYSTEM_CRITICAL 
  648. 	local options = { [0] = "CONTROL_CONTINUE" } 
  649. 	return dialog_box_open(header, body, options, nil, 0, priority, false, nil, is_close_on_death, is_close_on_damage) 
  650. end 
  651.  
  652. --------------------- 
  653. --[	PAUSED	]-- 
  654. --------------------- 
  655. Dialog_pause_input_subs = 0 
  656. Dialog_pause_partner_paused = false 
  657. Dialog_pause_input_block = false 
  658. Dialog_pause_allow_disconnect = false 
  659.  
  660. function dialog_pause_show(partner_paused, just_show_disconnect) 
  661. 	local d = Dialog_box 
  662. 	vint_set_property(d.handles["paused"], "visible", true) 
  663. 	vint_set_property(d.handles["paused"], "alpha", 1) 
  664. 	vint_set_property(d.handles["paused_background"], "visible", true) 
  665. 	 
  666. 	if Dialog_pause_input_subs ~= 0 then 
  667. 		return 
  668. 	end 
  669. 	 
  670. 	if partner_paused == true then 
  671. 		Dialog_pause_partner_paused = true 
  672. 		vint_set_property(d.handles["partner_paused"], "visible", true) 
  673. 		vint_set_property(d.handles["partner_paused"], "text_tag", "DIALOG_PAUSE_START_TO_DISCONNECT") 
  674. 	else 
  675. 		Dialog_pause_partner_paused = false 
  676. 	end 
  677.  
  678. 	if just_show_disconnect == true then 
  679. 		Dialog_pause_allow_disconnect = true 
  680. 		vint_set_property(d.handles["partner_paused"], "visible", true) 
  681. 		vint_set_property(d.handles["partner_paused"], "text_tag", "COOP_DISCONNECT") 
  682. 	else 
  683. 		Dialog_pause_allow_disconnect = false 
  684. 	end 
  685. 	 
  686. 	--	Subscribe to the input 
  687. 	Dialog_pause_input_subs = {	 
  688. 		vint_subscribe_to_input_event(nil, "pause",				"dialog_pause_input", 150), 
  689. 		vint_subscribe_to_input_event(nil, "map",				"dialog_pause_input", 150), 
  690. 		vint_subscribe_to_input_event(nil, "all_unassigned",	"dialog_pause_input", 150), 
  691. 	} 
  692. 	Dialog_pause_input_block = false 
  693. end 
  694.  
  695. function dialog_pause_hide() 
  696. 	local d = Dialog_box 
  697. 	vint_set_property(d.handles["paused"], "visible", false) 
  698. 	vint_set_property(d.handles["partner_paused"], "visible", false) 
  699. 	vint_set_property(d.handles["paused_background"], "visible", false) 
  700. 	if Dialog_pause_input_subs == 0 then 
  701. 		return 
  702. 	end 
  703. 		 
  704. 	if Dialog_pause_disconnect_dialog_handle  ~= 0 then 
  705. 		dialog_box_force_close(Dialog_pause_disconnect_dialog_handle) 
  706. 		Dialog_pause_disconnect_dialog_handle = 0 
  707. 	end 
  708. 	 
  709. 	--	Unsubscribe to input 
  710. 	for idx, val in Dialog_pause_input_subs do 
  711. 		vint_unsubscribe_to_input_event(val) 
  712. 	end 
  713. 	Dialog_pause_input_subs = 0 
  714. 	 
  715. end 
  716.  
  717. function dialog_ps3_show() 
  718. 	vint_set_property(vint_object_find("ps3_login"), "visible", true) 
  719. end 
  720.  
  721. function dialog_ps3_hide() 
  722. 	vint_set_property(vint_object_find("ps3_login"), "visible", false) 
  723. end 
  724.  
  725. function dialog_pause_disconnect(result, action) 
  726. 	if action ~= DIALOG_ACTION_CLOSE then 
  727. 		return 
  728. 	end 
  729. 	 
  730. 	if result == 0 then 
  731. 		dialog_box_disconnect() 
  732. 	else 
  733. 		Dialog_pause_input_block = false 
  734. 	end 
  735. 	 
  736. 	Dialog_pause_disconnect_dialog_handle = 0 
  737. end 
  738.  
  739. function dialog_pause_input(target, event, accelleration) 
  740. 	if Dialog_pause_input_block == true then 
  741. 		return 
  742. 	end 
  743. 	 
  744. 	if Dialog_pause_partner_paused == true then 
  745. 		if event == "map" then 
  746. 			--Map is the button to exit out of a partner paused situation 
  747. 			local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  748. 			Dialog_pause_disconnect_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "dialog_pause_disconnect", 0, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false) 
  749. 			Dialog_pause_input_block = false 
  750. 		end 
  751. 	else 
  752. 		if event == "map" and Dialog_pause_allow_disconnect == true then 
  753. 			--Map is the button to exit out of a partner paused situation 
  754. 			local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  755. 			Dialog_pause_disconnect_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "dialog_pause_disconnect", 0, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false) 
  756. 			Dialog_pause_input_block = false 
  757. 		elseif event == "pause" then 
  758. 			--Pause is the event in a normal paused situation. 
  759. 			dialog_pause_unpause() 
  760. 		end 
  761. 	end 
  762. end 
  763.  
  764.  
  765.  
  766. --------------------------- 
  767. --[[ COOP INVITE MESSAGE ]] 
  768. --------------------------- 
  769. Dialog_box_invite = { } 
  770.  
  771. function dialog_show_coop_invite(player_name) 
  772. 	audio_play(audio_get_audio_id("SYS_OBJECTIVE_COMPLETE")) 
  773. 	local values = { [0] = player_name} 
  774. 	local player_tag = vint_insert_values_in_string("PS3_INVITE_TEXT_CONFIRM", values) 
  775. 	vint_set_property(Dialog_box.handles.player_invited_you_text, "text_tag", player_tag) 
  776. 	vint_set_property(Dialog_box.handles.player_invited_you, "visible", true) 
  777. 	lua_play_anim(Dialog_box.handles.coop_invite_fade_out, 0) 
  778. 	local tween_h = vint_object_find("coop_invite_fade_3", Dialog_box.handles.coop_invite_fade_out) 
  779. 	vint_set_property(tween_h, "end_event", "dialog_hide_coop_invite") 
  780. 	Dialog_box_invite.pause_pressed = false 
  781. 	 
  782. 	--	Subscribe to the input 
  783. 	local subscription_priority = 100 
  784.  
  785. 	Dialog_box_invite.input_subs = {	 
  786. 		vint_subscribe_to_input_event(nil, "pause",				"dialog_box_invite_input", subscription_priority), 
  787. 	} 
  788. 	 
  789. end 
  790.  
  791. function dialog_box_invite_input(target, event, accelleration) 
  792. 	if event == "pause" then 
  793. 		Dialog_box_invite.pause_pressed = true 
  794. 		dialog_hide_coop_invite() 
  795. 		dialog_coop_invite_start_pressed() 
  796. 	end 
  797. end 
  798. 	 
  799. function dialog_hide_coop_invite() 
  800. 	if Dialog_box_invite.input_subs ~= nil then 
  801. 		--	Unsubscribe to input 
  802. 		for idx, val in Dialog_box_invite.input_subs do 
  803. 			vint_unsubscribe_to_input_event(val) 
  804. 		end 
  805. 		Dialog_box_invite.input_subs = nil 
  806. 	end 
  807. 	 
  808. 	if Dialog_box_invite.pause_pressed ~= true then 
  809. 		dialog_coop_invite_timeout() 
  810. 	end 
  811. 	 
  812. 	vint_set_property(Dialog_box.handles.player_invited_you, "visible", false) 
  813. end 
  814.