./vdo_dialog.lua

  1. -- Inherited from Vdo_base_object 
  2. Vdo_dialog = Vdo_base_object:new_base() 
  3.  
  4. -- Global Locals 
  5. local DIALOG_ALIGN_CENTER 	= 0 
  6. local DIALOG_ALIGN_LEFT		= 1 
  7.  
  8. local DIALOG_BOX_MIN_WIDTH = 450 
  9. local DIALOG_BOX_DEFAULT_TEXT_LINES = 11 
  10.  
  11. local DIALOG_BOX_CONTENT_START_X 			= 9 
  12. local DIALOG_BOX_CONTENT_START_Y 			= 40  
  13. local DIALOG_BOX_SPINNER_SIZE 				= 80					 
  14. local DIALOG_BOX_SPINNER_PADDING				= 20					 
  15. local DIALOG_BOX_CONTENT_VERTICAL_SPACING = 17 
  16. local DIALOG_BOX_CONTENT_OPTIONS_SPACING 	= 37 
  17. local DIALOG_BOX_CONTENT_OPTIONS_HORIZONTAL_SPACING 	= 20 
  18. local DIALOG_BOX_CONTENT_OPTIONS_HORIZONTAL_OFFSET = 20 
  19. local DIALOG_BOX_SCROLLBAR_WIDTH	= 18 								--width of scrollbar... 
  20. local DIALOG_BOX_SCROLLBAR_PADDING	= 10 							--spacing for scrollbar ... 
  21. local DIALOG_BOX_TEXT_MASK_PADDING	= 6 							--Padding for mask on text... 
  22.  
  23. local DIALOG_BOX_TEXT_UNSELECTED 	= {R = 218/255, G = 226/255; B = 230/255} 
  24. local DIALOG_BOX_TEXT_SELECTED		= {R = 0/255, G = 0/255; B = 0/255} 
  25.  
  26. -- Widget types... 
  27. DIALOG_WIDGET_TYPE_OPTION 		= 0 
  28. DIALOG_WIDGET_TYPE_TITLE	 	= 1 
  29. DIALOG_WIDGET_TYPE_TEXT			= 2 
  30. DIALOG_WIDGET_TYPE_IMAGE		= 3 
  31. DIALOG_WIDGET_TYPE_SPINNER		= 4 
  32.  
  33. DIALOG_ACTION_NONE 				= -1 
  34. DIALOG_ACTION_SELECT				= 0 
  35. DIALOG_ACTION_BACK				= 1 
  36.  
  37. local Vdo_dialog_gamepad_listener = -1 
  38.  
  39. --init dialog script 
  40. function vdo_dialog_init() 
  41. end 
  42.  
  43. --cleanup dialog script 
  44. function vdo_dialog_cleanup() 
  45. 	if game_get_platform() == "PC" then 
  46. 		vint_scriptevent_stop_listening( Vdo_dialog_gamepad_listener ) 
  47. 	end 
  48. end 
  49.  
  50. ------------------------------------------------------------------------------- 
  51. -- Init Dialog VDO! 
  52. ------------------------------------------------------------------------------- 
  53. function Vdo_dialog:init() 
  54. 	self.header = "" 
  55. 	self.base_content_h = vint_object_find("content", self.handle) 
  56. 	self.previous_content_h = -1 
  57. 	 
  58. 	--Configure highlight for  
  59. 	self.highlight = Vdo_button_highlight:new("options_highlight", self.base_content_h) 
  60. 	self.highlight:show_button(CTRL_MENU_BUTTON_A) 
  61. 	 
  62. 	local h = vint_object_find("spinner_obj", self.handle) 
  63. 	vint_set_property(h, "visible", false) 
  64. 	vint_set_property(h, "visible", false) 
  65. 	local h = vint_object_find("text_obj", self.handle) 
  66. 	vint_set_property(h, "visible", false) 
  67. 	local h = vint_object_find("options_obj", self.handle) 
  68. 	vint_set_property(h, "visible", false) 
  69. 	local h = vint_object_find("hint_bar_grp", self.handle) 
  70. 	vint_set_property(h, "visible", false) 
  71. 	self.hint_bar = Vdo_hint_bar:new("hint_bar", self.handle) 
  72. 	 
  73. 	local h = vint_object_find("dialog_img", self.handle) 
  74. 	vint_set_property(h, "visible", false) 
  75. 	 
  76. 	--Store references to shadow... 
  77. 	self.shadow = {} 
  78. 	self.shadow.nw		= vint_object_find("shadow_nw", self.handle) 
  79. 	self.shadow.n		= vint_object_find("shadow_n", self.handle) 
  80. 	self.shadow.ne		= vint_object_find("shadow_ne", self.handle) 
  81. 	self.shadow.e 		= vint_object_find("shadow_e", self.handle) 
  82. 	self.shadow.se 	= vint_object_find("shadow_se", self.handle) 
  83. 	self.shadow.s 		= vint_object_find("shadow_s", self.handle) 
  84. 	self.shadow.sw 	= vint_object_find("shadow_sw", self.handle) 
  85. 	self.shadow.w 		= vint_object_find("shadow_w", self.handle) 
  86. 	 
  87. 	--Get and store the size of the body text element... 
  88. 	local h = vint_object_find("body_txt", self.handle) 
  89. 	vint_set_property(h, "text_tag", "XXXX") 
  90. 	local width, height = element_get_actual_size(h) 
  91. 	self.text_line_height = height 
  92. 	 
  93. 	self.alignment = DIALOG_ALIGN_CENTER 
  94. 	 
  95. 	self.current_dialog	 = -1 
  96. 	 
  97. 	if game_get_platform() == "PC" then 
  98. 		Vdo_dialog_gamepad_listener = vint_scriptevent_listen( "gamepad_active", "vdo_dialog_update_gamepad_state" ) 
  99. 	end 
  100. end 
  101.  
  102. --[[ 
  103. 	Dialogs[handle] = { 
  104. 		base_object = -1, 
  105. 		header = -1, 
  106. 		widgets = {}, 
  107. 		widget_count = 0, 
  108. 	} 
  109. ]] 
  110. ------------------------------------------------------------------------------- 
  111. -- Creates the dialog data.... 
  112. -- 
  113. -- @param	dialog_data			{ full of data...} 
  114. -- @param 	do_morph				bool (true or false) 
  115. ------------------------------------------------------------------------------- 
  116. function Vdo_dialog:create(dialog_data, do_morph, morph_complete_cb) 
  117. 	 
  118. 	if self.morph_playing == true then 
  119. 		self:morph_complete() 
  120. 	end 
  121. 	 
  122. 	if do_morph == true then 
  123. 		--Need to clone and delete old dialog content when finished... 
  124. 		--our morph callback will handle any remaining cleanup.. 
  125. 		self.previous_content_h = vint_object_clone(self.base_content_h) 
  126. 		 
  127. 		--Move content behind new content... 
  128. 		vint_set_property(self.previous_content_h, "depth", 5000) 
  129. 		 
  130. 		if morph_complete_cb ~= nil then 
  131. 			self.morph_complete_cb = morph_complete_cb 
  132. 		else 
  133. 			self.morph_complete_cb = nil 
  134. 		end 
  135. 	else 
  136. 		self.morph_complete_cb = nil 
  137. 	end 
  138. 	 
  139. 	-- Clear out old dialog cloned objects out of our current dialog... 
  140. 	if self.current_dialog ~= -1 then 
  141. 		local clones = self.current_dialog.widget_clones 
  142. 		for key, val in pairs(clones) do  
  143. 			vint_object_destroy(val) 
  144. 		end 
  145. 	end 
  146.  
  147.  
  148. 	--hide all objects that we clone from... 
  149. 	local widget_h = vint_object_find("text_obj", self.base_content_h) 
  150. 	vint_set_property(widget_h, "visible", false) 
  151. 	widget_h = vint_object_find("dialog_img", self.base_content_h) 
  152. 	vint_set_property(widget_h, "visible", false) 
  153. 	widget_h = vint_object_find("spinner_obj", self.base_content_h) 
  154. 	vint_set_property(widget_h, "visible", false) 
  155. 	widget_h = vint_object_find("options_obj", self.base_content_h) 
  156. 	vint_set_property(widget_h, "visible", false) 
  157. 	widget_h = vint_object_find("hint_bar_grp", self.base_content_h) 
  158. 	vint_set_property(widget_h, "visible", false) 
  159. 	 
  160. 	--Reset current dialog table... 
  161. 	self.current_dialog = {} 
  162.  
  163. 	-- handle body... 
  164. 	local title_txt = "" 
  165. 		 
  166. 	local options = {} 
  167. 	local option_count = 0 
  168. 	local selected_index = 0 
  169. 	 
  170. 	-- Tables and variables used to keep track of cloned objects... 
  171. 	self.current_dialog.widgets = {} 
  172. 	self.current_dialog.widget_clones = {} 
  173. 	self.current_dialog.option_has_clone 	= false 
  174. 	self.current_dialog.text_has_clone 		= false 
  175. 	self.current_dialog.image_has_clone 	= false 
  176. 	self.current_dialog.spinner_has_clone 	= false 
  177. 			 
  178. 	local widgets = {} 
  179. 	local widgets_count 		= 0 
  180. 	local widgets_width		= 0 
  181. 	local widgets_height		= DIALOG_BOX_CONTENT_START_Y			--Default height for widgets, in case there are none. 
  182. 	 
  183. 	--loop through widgets and unpack them into objects...... 
  184. 	for i = 0, dialog_data.widgets_count - 1 do 
  185. 		local widget = dialog_data[i]			 
  186. 		local widget_type = widget.type 
  187. 		local widget_h							-- Handle to current widget... 
  188. 		local do_position_widget = true	-- Should we position the widget? 
  189. 		local num_lines	= 0 
  190. 		local width 		= 0					-- Used to position the widgets... 
  191. 		local height 		= 0 					-- Used to position the widgets... 
  192. 		local is_waiting 	= widget.is_waiting or false 
  193. 		local is_massive 	= false 
  194. 		 
  195. 		--process odd type widgets first... 
  196. 		if widget_type == DIALOG_WIDGET_TYPE_TITLE then 
  197. 			-- Store  title to use later... 
  198. 			title_txt = widget.title 
  199. 			 
  200. 			do_position_widget = false 
  201. 		elseif widget_type == DIALOG_WIDGET_TYPE_OPTION then 
  202. 			-- Store options to process later... 
  203. 			options[option_count] =  { 
  204. 				has_second_option = widget.has_second_option, 
  205. 				tag_1		 	= widget.tag_1, 
  206. 				tag_2 		= widget.tag_2, 
  207. 				option_id 	= widget.option_id, 
  208. 				disabled 	= widget.disabled, 
  209. 			} 
  210. 			 
  211. 			--Set current option to be selected if we are... 
  212. 			if widget.selected == true then 
  213. 				selected_index = widget.option_id 
  214. 			end 
  215. 			 
  216. 			option_count = option_count + 1 
  217. 			do_position_widget = false 
  218. 		elseif widget_type == DIALOG_WIDGET_TYPE_TEXT then 
  219. 			--Text field for dialog... 
  220. 			local text_tag		= 	widget.text_tag 
  221. 			num_lines 			=	widget.num_lines  
  222. 			is_massive 	=	widget.is_massive  
  223.  
  224. 			if not is_waiting  then 
  225. 				if self.current_dialog.text_has_clone == false then 
  226. 					widget_h = vint_object_find("text_obj", self.base_content_h) 
  227. 					self.current_dialog.text_has_clone = true 
  228. 				else 
  229. 					local h = vint_object_find("text_obj", self.base_content_h) 
  230. 					widget_h = vint_object_clone(h) 
  231. 					self:add_clone_to_list(widget_h) 
  232. 				end 
  233. 				 
  234. 				 
  235. 				local body_txt_h = vint_object_find("body_txt", widget_h) 
  236. 				 
  237. 				if is_massive == true then 
  238. 					vint_set_property(body_txt_h, "text_scale", 0.5, 0.5) 
  239. 					vint_set_property(body_txt_h, "wrap_width", 800) 
  240. 					vint_set_property(body_txt_h, "word_wrap", true) 
  241. 				else 
  242. 					vint_set_property(body_txt_h, "text_scale", 0.7, 0.7) 
  243. 				end 
  244. 				 
  245. 				 
  246. 				if num_lines ~= 0 then 
  247. 					vint_set_property(body_txt_h, "text_tag_crc", text_tag) 
  248. 				else 
  249. 					vint_set_property(body_txt_h, "text_tag", text_tag) 
  250. 				end 
  251. 					 
  252. 				width, height = element_get_actual_size(body_txt_h) 
  253. 				vint_set_property(widget_h, "visible", true) 
  254. 			else 
  255. 				widget_h = vint_object_find("hint_bar_grp") 
  256. 				local data = { 
  257. 					{CTRL_MENU_BUTTON_B, "CONTROL_CANCEL"}, 
  258. 				} 
  259. 				self.hint_bar:set_hints(data) 
  260. 				height = self.text_line_height + 5 
  261. 				vint_set_property(widget_h, "visible", true) 
  262. 			end 
  263. 		elseif widget_type == DIALOG_WIDGET_TYPE_IMAGE then 
  264. 			--Image field for dialog... 
  265. 			local image_name 	= 	widget.image_name 
  266. 			 
  267. 			if self.current_dialog.image_has_clone == false then 
  268. 				widget_h = vint_object_find("dialog_img", self.base_content_h) 
  269. 				self.current_dialog.image_has_clone = true 
  270. 			else 
  271. 				local h = vint_object_find("dialog_img", self.base_content_h) 
  272. 				widget_h = vint_object_clone(h) 
  273. 				self:add_clone_to_list(widget_h) 
  274. 			end 
  275. 			 
  276. 			vint_set_property(widget_h, "visible", true) 
  277. 			vint_set_property(widget_h, "image", image_name) 
  278. 			width, height = element_get_actual_size(widget_h) 
  279. 			 
  280. 		elseif widget_type == DIALOG_WIDGET_TYPE_SPINNER then 
  281. 			--Spinner field for dialog... 
  282. 			local spinner_txt = widget.spinner_txt 
  283. 			widget_h = vint_object_find("spinner_obj", self.base_content_h) 
  284. 			vint_set_property(widget_h, "visible", true) 
  285. 			 
  286. 			--Set text tag of spinner... 
  287. 			local spinner_txt_h = vint_object_find("spinner_txt", widget_h) 
  288. 			local spinner_txt_width, spinner_txt_height = element_get_actual_size(spinner_txt_h) 
  289. 			local spinner_txt_x, spinner_txt_y = vint_get_property(spinner_txt_h, "anchor") 
  290. 			vint_set_property(spinner_txt_h, "text_tag", spinner_txt) 
  291. 			 
  292. 			--Clone and target animation... 
  293. 			local spinner_anim_h = vint_object_find("spinner_anim", self.handle) 
  294. 			vint_set_property(spinner_anim_h, "target_handle", widget_h)  
  295. 			vint_set_property(spinner_anim_h, "is_paused", false) 
  296. 			 
  297. 			--get width/height for box... 
  298. 			local spinner_gfx_h = vint_object_find("spinner_gfx_1", self.base_content_h) 
  299. 			width = spinner_txt_width 
  300. 			height = DIALOG_BOX_SPINNER_SIZE 
  301. 		end 
  302. 		 
  303. 		if do_position_widget == true then 
  304. 			--store widget data for alignment later... 
  305. 			widgets[widgets_count] = { 
  306. 				h = widget_h, 
  307. 				type = widget_type, 
  308. 				width = width, 
  309. 				height = height, 
  310. 				num_lines = num_lines, 
  311. 				is_waiting = is_waiting, 
  312. 				is_massive = is_massive, 
  313. 			} 
  314. 			widgets_count = widgets_count + 1 
  315. 			 
  316. 			widgets_width = max(widgets_width, width) 
  317. 		end 
  318. 	end 
  319. 	widgets.widgets_count = widgets_count 
  320. 	 
  321. 		 
  322. 	--Set Title 
  323. 	local title_txt_obj = Vdo_base_object:new("title_txt", self.base_content_h) 
  324. 	title_txt_obj:set_text(title_txt) 
  325. 	 
  326. 	local title_width, title_height = title_txt_obj:get_actual_size() 
  327. 	title_width = title_width + 6	--for padding 
  328. 	-- Build options... 
  329. 	 
  330. 	-- Position base options  
  331. 	local options_h = vint_object_find("options_obj", self.base_content_h) 
  332. 	local option_h = vint_object_find("option", options_h) 
  333. 	local option_1_width 
  334. 	local option_2_width 
  335. 	local option_1_largest_width = 0 
  336. 	local option_1_with_second_option_largest_width = 0 		 
  337. 	local option_2_largest_width = 125 	-- This is also the default width of the text box... Approximatly 8 characters... 
  338. 	if game_get_platform() == "PC" then 
  339. 		option_2_largest_width = 250 -- Double it on PC so typing directly in it isn't so jarring 
  340. 	end 
  341. 	local x = 0  
  342. 	local y = 0 
  343. 	for i = 0, option_count - 1 do 
  344. 		local current_option_h  
  345. 		local option_is_clone = false 
  346. 		if i == 0 then 
  347. 			current_option_h = option_h 
  348. 			x, y = vint_get_property(current_option_h, "anchor") 
  349. 		else 
  350. 			current_option_h = vint_object_clone(option_h) 
  351. 			y = y + DIALOG_BOX_CONTENT_OPTIONS_SPACING	 
  352. 			option_is_clone = true 
  353. 		end 
  354.  
  355. 		local option_txt_1_h = vint_object_find("option_txt_1", current_option_h) 
  356. 		local option_txt_2_h = vint_object_find("option_txt_2", current_option_h) 
  357. 		local option_2_grp_h = vint_object_find("option_2_grp", current_option_h) 
  358. 		 
  359. 		vint_set_property(current_option_h, "anchor", x, y) 
  360. 		 
  361. 		--force tags to nothing if no data was sent in... 
  362. 		if options[i].tag_1 == nil then 
  363. 			options[i].tag_1 = "" 
  364. 		end 
  365. 		 
  366. 		if options[i].tag_2 == nil then 
  367. 			options[i].tag_2 = "" 
  368. 		end 
  369. 		 
  370. 		--Set text tags... 
  371. 		vint_set_property(option_txt_1_h, "text_tag", options[i].tag_1) 
  372. 		vint_set_property(option_txt_2_h, "text_tag", options[i].tag_2) 
  373. 		 
  374. 		 
  375. 		--Find largest elements for alignment later... 
  376. 		option_1_width = element_get_actual_size(option_txt_1_h) 
  377. 		option_2_width = element_get_actual_size(option_txt_2_h) 
  378. 		 
  379. 		option_1_largest_width = max(option_1_width, option_1_largest_width) 
  380. 		 
  381. 		--Do we show the second option? 
  382. 		if options[i].has_second_option == true then 
  383. 			vint_set_property(option_2_grp_h, "visible", true) 
  384. 			--Now calculate the width of the largest first option with a second option... 
  385. 			option_1_with_second_option_largest_width = max(option_1_width, option_1_with_second_option_largest_width) 
  386. 			option_2_largest_width = max(option_2_width, option_2_largest_width) 
  387. 		else 
  388. 			vint_set_property(option_2_grp_h, "visible", false) 
  389. 		end 
  390. 		 
  391.  
  392. 		options[i].h = current_option_h 
  393. 	 
  394. 		--Add to widget clone table if option is clone... 
  395. 		if option_is_clone then 
  396. 			self.current_dialog.widget_clones[i] = current_option_h 
  397. 		end 
  398. 	end 
  399. 	 
  400. 	-- Align second options... 
  401. 	-- todo align right side of box to width of the shit... 
  402. 	for i = 0, option_count - 1 do 
  403. 		local current_option_h = options[i].h  
  404. 		local option_txt_1_h = vint_object_find("option_txt_1", current_option_h) 
  405. 		local option_2_grp_h = vint_object_find("option_2_grp", current_option_h) 
  406. 		local x, y = vint_get_property(option_txt_1_h, "anchor") 
  407. 		vint_set_property(option_2_grp_h, "anchor", x + option_1_with_second_option_largest_width + DIALOG_BOX_CONTENT_OPTIONS_HORIZONTAL_SPACING, y) 
  408. 		 
  409. 		--Set size of option2 box, + 10 to account for padding... 
  410. 		local option_2_box_width = option_2_largest_width + 10 
  411. 		 
  412. 		--Resize background  
  413. 		local box_bg_h = vint_object_find("option_box_bg", current_option_h) 
  414. 		local box_bg_width, box_bg_height = element_get_actual_size(box_bg_h) 
  415. 		element_set_actual_size(box_bg_h, option_2_box_width - 4, box_bg_height)	--its the box width.. - 4 is the width of the size so we subtract it... 
  416. 		 
  417. 		--Resize the north and south sides of the box... 
  418. 		local box_n_h = vint_object_find("option_box_n", current_option_h) 
  419. 		local box_s_h = vint_object_find("option_box_s", current_option_h) 
  420. 		 
  421. 		local box_width, box_height = element_get_actual_size(box_n_h) 
  422. 		element_set_actual_size(box_n_h, option_2_box_width, box_height) 
  423. 		element_set_actual_size(box_s_h, option_2_box_width, box_height) 
  424. 		 
  425. 		--Reposition right side of box... 
  426. 		local box_e_h = vint_object_find("option_box_e", current_option_h) 
  427. 		local box_x, box_y  = vint_get_property(box_e_h, "anchor") 
  428. 		vint_set_property(box_e_h, "anchor", option_2_box_width, box_y) 
  429. 	end 
  430. 	 
  431. 	local options_height 
  432. 	 
  433. 	--the largest width is either the first option or the combined width of first option or second option... 
  434. 	local options_largest_width = max(option_1_largest_width, option_1_with_second_option_largest_width + option_2_largest_width + 5) 
  435. 	 
  436. 	--calculate the total width of the options... 
  437. 	local options_width = x + options_largest_width + DIALOG_BOX_CONTENT_OPTIONS_HORIZONTAL_SPACING + DIALOG_BOX_CONTENT_OPTIONS_HORIZONTAL_OFFSET 
  438. 	 
  439. 	-- Show options if we have them... 
  440. 	if option_count > 0 then 
  441. 		vint_set_property(options_h, "visible", true) 
  442. 		--Use options height... 
  443. 		options_height = y + DIALOG_BOX_CONTENT_OPTIONS_SPACING - 9 
  444. 	else 
  445. 		vint_set_property(options_h, "visible", true) 
  446. 		options_height = 0 
  447. 	end 
  448.  
  449. 	--Store off option data for later... 
  450. 	options.option_count = option_count 
  451. 	self.current_dialog.options = options 
  452. 	 
  453. 	--Highlight current option... 
  454. 	self:highlight_option(selected_index, true) 
  455.  
  456. 	--Pre-calculate size of box...  
  457. 	local dialog_box_width = max(DIALOG_BOX_MIN_WIDTH, options_width) 
  458.  
  459. 	dialog_box_width = max(widgets_width, dialog_box_width) 
  460. 	dialog_box_width = max(title_width, dialog_box_width) 
  461.  
  462. 	local dialog_box_height = 0 			-- This will be calculated as we place everything... 
  463.  
  464. 	--Position widgets... 
  465. 	local widget_x = DIALOG_BOX_CONTENT_START_X 
  466. 	local widget_y = DIALOG_BOX_CONTENT_START_Y 
  467. 	 
  468. 	for i = 0, widgets_count - 1 do 
  469. 		local widget_h 	= widgets[i].h 
  470. 		local widget_type = widgets[i].type 
  471. 		local width 		= widgets[i].width 
  472. 		local height 		= widgets[i].height 
  473. 		local num_lines 	= widgets[i].num_lines 
  474. 		local	is_waiting 	= widgets[i].is_waiting  
  475. 		local	is_massive 	= widgets[i].is_massive 
  476. 		 
  477. 		if widget_type == DIALOG_WIDGET_TYPE_TEXT then 
  478. 			if not is_waiting then 
  479. 				local body_txt_h = vint_object_find("body_txt", widget_h) 
  480. 				if body_txt_h ~= 0 then 
  481. 					local scroll_h = vint_object_find("scroll", widget_h) 
  482. 					 
  483. 					local wrap_width = dialog_box_width - DIALOG_BOX_SCROLLBAR_WIDTH - DIALOG_BOX_SCROLLBAR_PADDING 
  484. 					 
  485. 					vint_set_property(body_txt_h, "wrap_width", wrap_width) 
  486. 					vint_set_property(body_txt_h, "word_wrap", true) 
  487. 					 
  488. 					 
  489. 					 
  490. 					--Move scrollbar to edge of text box... 
  491. 					local scroll_x, scroll_y = vint_get_property(scroll_h, "anchor") 
  492. 					local body_txt_x, body_txt_y = vint_get_property(body_txt_h, "anchor") 
  493. 					vint_set_property(scroll_h, "anchor", body_txt_x + wrap_width + DIALOG_BOX_SCROLLBAR_PADDING, scroll_y) 
  494. 					 
  495. 					--Replace width and height values... 
  496. 					local text_width, text_height = element_get_actual_size(body_txt_h) 
  497. 					 
  498. 					if num_lines == 0 then 
  499. 						num_lines = DIALOG_BOX_DEFAULT_TEXT_LINES 
  500. 					end 
  501. 					 
  502. 					height = self.text_line_height * num_lines  
  503. 					 
  504. 					--This means we don't need to scroll... 
  505. 		--[[ DAD - 8/17/11 - Removed the scroll bar.. keeping this here for SR4 though 
  506. 					if text_height <= height then 
  507. 						height = text_height 
  508. 						vint_set_property(scroll_h, "visible", false) 
  509. 					else 
  510. 						vint_set_property(scroll_h, "visible", true) 
  511. 					end 
  512. 					]]-- 
  513. 					 
  514. 					-- This section can be removed if the above is uncommented 
  515. 					if text_height <= height then 
  516. 						height = text_height 
  517. 					else  
  518. 						height = text_height 
  519. 					end 
  520. 					vint_set_property(scroll_h, "visible", false) 
  521. 					-- End section 
  522. 					 
  523. 					--adjust size of mask 
  524. 					local mask_h = vint_object_find("mask", widget_h) 
  525. 					element_set_actual_size(mask_h, dialog_box_width, height + DIALOG_BOX_TEXT_MASK_PADDING) 
  526. 				end 
  527. 				 
  528. 			else 
  529. 				height = self.text_line_height + 5 
  530. 			end	 
  531. 		elseif widget_type == DIALOG_WIDGET_TYPE_SPINNER then 
  532. 			--Set text tag of spinner... 
  533. 			local spinner_txt_h = vint_object_find("spinner_txt", widget_h) 
  534. 			local wrap_width = dialog_box_width - DIALOG_BOX_SPINNER_SIZE - DIALOG_BOX_SPINNER_PADDING 
  535. 			vint_set_property(spinner_txt_h, "wrap_width", wrap_width) 
  536. 			vint_set_property(spinner_txt_h, "word_wrap", true) 
  537. 						 
  538. 			---if the text is wrapping more than 3 lines we have problems and need to reposition the spinner... 
  539. 			local y = 0 
  540. 			local spinner_txt_width, spinner_txt_height = element_get_actual_size(spinner_txt_h) 
  541. 			local spinner_internal_grp_h = vint_object_find("spinner_internal_grp", widget_h) 
  542. 			 
  543. 			if  spinner_txt_height > DIALOG_BOX_SPINNER_SIZE then 
  544. 				y = (spinner_txt_height - DIALOG_BOX_SPINNER_SIZE) * .5 
  545. 			end 
  546. 			vint_set_property(spinner_internal_grp_h, "anchor", 0, y) 
  547. 			height = height + (y * 2) 
  548. 		end 
  549. 		 
  550. 		--position widget... 
  551. 		local target_widget_y = widget_y 
  552. 		if widget_type == DIALOG_WIDGET_TYPE_IMAGE then 
  553. 			--if its an image shift it by 5 pixels... 
  554. 			target_widget_y = target_widget_y + 5 
  555. 		end 
  556. 		 
  557. 		vint_set_property(widget_h, "anchor", widget_x, target_widget_y) 
  558. 		 
  559. 		--Calculate position for next widget... 
  560. 		widget_y = widget_y + height + DIALOG_BOX_CONTENT_VERTICAL_SPACING 
  561.  
  562. 		--Store off widget height (last positioned object plus the height of it... 
  563. 		widgets_height = widget_y 
  564. 	end 
  565. 	 
  566. 	-- Position base options  
  567. 	local options_h = vint_object_find("options_obj", self.base_content_h) 
  568. 	vint_set_property(options_h, "anchor", widget_x, widgets_height) 
  569. 	 
  570. 	dialog_box_height = 	widgets_height - DIALOG_BOX_CONTENT_START_Y + options_height 
  571. 	 
  572. 	self.current_dialog.widgets = widgets 
  573. 	 
  574. 	--Change to new size... 
  575. 	self:morph_size(dialog_box_width, dialog_box_height, do_morph) 
  576. end 
  577.  
  578. function Vdo_dialog:morph_size(width, height, do_morph) 
  579. 	if do_morph then 
  580. 		local morph_anim_h = vint_object_find("morph_anim", self.handle) 
  581. 		local morph_twn_h = vint_object_find("morph_twn",morph_anim_h) 
  582. 		local content_alpha_twn_h = vint_object_find("content_alpha_twn", morph_anim_h) 
  583. 		local new_content_alpha_twn_h = vint_object_find("new_content_alpha_twn", morph_anim_h) 
  584. 	 
  585. 		--Use the following data to convert pixels to widths... 
  586. 		local fill_h = vint_object_find("fill", self.handle) 
  587. 		local start_width, start_height = vint_get_property(fill_h, "unscaled_size") 
  588. 		 
  589. 		vint_set_property(morph_twn_h, "start_value", self.width/start_width, self.height/start_height) 
  590. 		vint_set_property(morph_twn_h, "end_value", width/start_width, height/start_height) 
  591. 		 
  592. 		local callback_string = self:package_tween_callback("size_update") 
  593. 		vint_set_property(morph_twn_h, "per_frame_event", callback_string) 
  594. 		 
  595. 		local callback_string = self:package_tween_callback("morph_complete") 
  596. 		vint_set_property(morph_twn_h, "end_event", callback_string) 
  597. 		 
  598. 		--set targets for fade in and out tweens... 
  599. 		vint_set_property(content_alpha_twn_h, "target_handle", self.previous_content_h)		--target the new content (this tween fades out) 
  600. 		vint_set_property(new_content_alpha_twn_h, "target_handle", self.content_h)			--target the new content (this tween fades in) 
  601. 		 
  602. 		lua_play_anim(morph_anim_h) 
  603. 		self.morph_playing = true 
  604. 	else 
  605. 		self:set_size(width, height) 
  606. 	end 
  607. end 
  608.  
  609. function Vdo_dialog:size_update() 
  610. 	local fill_h  = vint_object_find("fill", self.handle) 
  611. 	local width, height = element_get_actual_size(fill_h) 
  612. 	self:set_size(width, height) 
  613. end 
  614.  
  615. function Vdo_dialog:set_size(width, height) 
  616. 	local border_h 			= vint_object_find("border", self.handle) 
  617. 	local fill_h  				= vint_object_find("fill", self.handle) 
  618. 	local dialog_clip_h  	= vint_object_find("dialog_clip", self.handle) 
  619.  
  620. 	--Calculate background element sizes... 
  621. 	local border_width 	= width + 10 
  622. 	local border_height 	= height + 38 
  623. 	local clip_width 		= width + 1 
  624. 	local clip_height 	= height + 33 
  625. 	 
  626. 	--[[ 
  627. 		relative sizes... 
  628. 		fill: 	420, 217 
  629. 		border:	430, 255 
  630. 		dialog_clip:	420, 250 
  631. 	]] 
  632.  
  633. 	--Adjust background elements... 
  634. 	element_set_actual_size(fill_h, width, height) 
  635. 	element_set_actual_size(border_h, border_width, border_height) 
  636. 	element_set_actual_size(dialog_clip_h, clip_width, clip_height) 
  637. 	 
  638. 	self:set_shadow(width, height) 
  639. 	 
  640. 	--Set highlight width on option bar... 
  641. 	self.highlight:set_width(width) 
  642. 	 
  643. 	--Align box to screen... 
  644. 	local box_h = vint_object_find("dialog_grp", self.handle) 
  645. 	if self.alignment == DIALOG_ALIGN_CENTER then 
  646. 		--get parent scale... of object.(this isn't standard... but handles us if we are scaled by a parent document... 
  647. 		local scale_x, scale_y  
  648. 		if vint_is_std_res() then 
  649. 			scale_x = 0.667 
  650. 			scale_y = 0.667 
  651. 			vint_set_property(self.handle, "scale", scale_x, scale_y)			 
  652. 		else 
  653. 			scale_x = 1.0 
  654. 			scale_y = 1.0 
  655. 			vint_set_property(self.handle, "scale", scale_x, scale_y)	 
  656. 		end 
  657. 		 
  658. 		--Set box to center... screen center, minus half the box width... 
  659. 		local x = (((Screen_center_x / scale_x)- (border_width/2)) ) 
  660. 		local y = (((Screen_center_y / scale_y) - (border_height/2)) ) 
  661. 		vint_set_property(box_h, "anchor", x, y) 
  662. 	elseif self.alignment == DIALOG_ALIGN_LEFT then 
  663. 		 
  664. 	end 
  665. 	self.width = width 
  666. 	self.height = height 
  667. end 
  668.  
  669. function Vdo_dialog:morph_complete() 
  670. 	self.morph_playing = false 
  671. 	 
  672. 	--destroy content... 
  673. 	if self.previous_content_h ~= -1 then 
  674. 		vint_object_destroy(self.previous_content_h) 
  675. 		self.previous_content_h = -1 
  676. 	end 
  677. 	 
  678. 	if self.morph_complete_cb ~= nil then 
  679. 		self.morph_complete_cb() 
  680. 	end 
  681. end 
  682.  
  683. ------------------------------------------------------------------------------- 
  684. -- Sets the shadow for the dialog box... 
  685. -- @param	width			Width of shadow...	 
  686. -- @param	height		Height of shadow... 
  687. ------------------------------------------------------------------------------- 
  688. function Vdo_dialog:set_shadow(width, height) 
  689.  
  690. 	-- Find shadow objects 
  691. 	local nw_h 	= self.shadow.nw 
  692. 	local n_h 	= self.shadow.n	 
  693. 	local ne_h 	= self.shadow.ne 
  694. 	local e_h 	= self.shadow.e 
  695. 	local se_h 	= self.shadow.se 
  696. 	local s_h 	= self.shadow.s 
  697. 	local sw_h 	= self.shadow.sw 
  698. 	local w_h 	= self.shadow.w 
  699. 	 
  700. 	--Top left Corner 
  701. 	local start_x = 0 
  702. 	local start_y = 0 
  703. 	 
  704. 	--Padding if width/height are a bit less than the outside of the box... 
  705. 	local pad_width	= 10 
  706. 	local pad_height 	= 38 
  707. 	 
  708. 	width = width + pad_width 
  709. 	height = height + pad_height 
  710. 	 
  711. 	local sides_width, sides_height = element_get_actual_size(n_h) 
  712. 	 
  713. 	--N 
  714. 	element_set_actual_size(n_h, width, sides_height) 
  715. 	 
  716. 	--NE 
  717. 	vint_set_property(ne_h, "anchor", width + start_x, start_y) 
  718. 	 
  719. 	--E 
  720. 	vint_set_property(e_h, "anchor", width + start_x, start_y) 
  721. 	element_set_actual_size(e_h, height, sides_height) 
  722. 	 
  723. 	--SE 
  724. 	vint_set_property(se_h, "anchor", width + start_x, height + start_y) 
  725. 	 
  726. 	--S 
  727. 	vint_set_property(s_h, "anchor", start_x, height + start_y) 
  728. 	element_set_actual_size(s_h, width, -sides_height) 
  729. 	 
  730. 	--SW 
  731. 	vint_set_property(sw_h, "anchor", start_x, height + start_y) 
  732. 	--element_set_actual_size(sw_h, width, sides_height) 
  733. 	 
  734. 	--W 
  735. 	element_set_actual_size(w_h, height, sides_height)	 
  736. end 
  737.  
  738. ------------------------------------------------------------------------------- 
  739. -- Moves highlight bar to index... 
  740. ------------------------------------------------------------------------------- 
  741. function Vdo_dialog:add_clone_to_list(clone_h) 
  742. 	local clone_count = #self.current_dialog.widget_clones 
  743. 	self.current_dialog.widget_clones[clone_count] = clone_h 
  744. end 
  745.  
  746. ------------------------------------------------------------------------------- 
  747. -- Moves highlight bar to index... 
  748. ------------------------------------------------------------------------------- 
  749. function Vdo_dialog:highlight_option(idx, skip) 
  750.  
  751. 	local options = self.current_dialog.options 
  752. 	local selected_option = options.selected_option 
  753. 	 
  754. 	if skip == nil or skip == false then 
  755. 		if options.selected_option ~= nil then 
  756. 			dialog_option_end_kbd_input(self.dialog_handle, options.selected_option) 
  757. 		end 
  758. 	end 
  759. 	 
  760.  
  761. 	dialog_option_accept_kbd_input(self.dialog_handle, idx) 
  762. 	 
  763. 	--Check to make sure index isn't out of range... 
  764. 	if idx > options.option_count - 1 then 
  765. 		idx = options.option_count - 1 
  766. 	end 
  767. 	 
  768. 	if options[idx] ~= nil and options[idx].disabled ~= nil and options[idx].disabled then 
  769. 		return 
  770. 	end 
  771. 	 
  772. 	--hide highlight if there are no options... 
  773. 	if options.option_count == 0 then 
  774. 		vint_set_property(self.highlight.handle, "visible", false) 
  775. 		return 
  776. 	else 
  777. 		vint_set_property(self.highlight.handle, "visible", true) 
  778. 	end 
  779. 	--move highlight bar... 
  780. 	local x, y = vint_get_property(options[idx].h, "anchor") 
  781. 	vint_set_property(self.highlight.handle, "anchor", x, y) 
  782. 	 
  783. 	--Color options... 
  784. 	for i = 0, options.option_count - 1 do  
  785. 		local option_h = options[i].h 
  786. 		local option_1_h = vint_object_find("option_txt_1", option_h) 
  787. 		if idx == i then 
  788. 			vint_set_property(option_1_h, "tint", DIALOG_BOX_TEXT_SELECTED.R, DIALOG_BOX_TEXT_SELECTED.G, DIALOG_BOX_TEXT_SELECTED.B) 
  789. 		else 
  790. 			vint_set_property(option_1_h, "tint", DIALOG_BOX_TEXT_UNSELECTED.R, DIALOG_BOX_TEXT_UNSELECTED.G, DIALOG_BOX_TEXT_UNSELECTED.B) 
  791. 		end 
  792. 	end 
  793. 	 
  794. 	options.selected_option = idx 
  795. end 
  796.  
  797. ------------------------------------------------------------------------------- 
  798. --   
  799. ------------------------------------------------------------------------------- 
  800. function Vdo_dialog:set_dialog_callback() 
  801. end 
  802.  
  803. ------------------------------------------------------------------------------- 
  804. --  opens dialog... 
  805. ------------------------------------------------------------------------------- 
  806. function Vdo_dialog:open(do_trans_in) 
  807. 	self:show() 
  808.  
  809. 	-- stop fade out 
  810. 	local anim_h = vint_object_find("fade_out_anim", self.handle) 
  811. 	self:close_finished() 
  812. 	 
  813. 	if do_trans_in == true then 
  814. 		-- start fade in 
  815. 		anim_h = vint_object_find("fade_in_anim", self.handle) 
  816. 		vint_set_property(anim_h, "target_handle", self.handle) 
  817. 		lua_play_anim(anim_h) 
  818. 	else 
  819. 		vint_set_property(self.handle, "alpha", 1.0) 
  820. 	end 
  821. end 
  822.  
  823. ------------------------------------------------------------------------------- 
  824. --  Closes dialog... 
  825. ------------------------------------------------------------------------------- 
  826. function Vdo_dialog:close() 
  827.  
  828. 	--start fade out... 
  829. 	local anim_out_h = vint_object_find("fade_out_anim", self.handle) 
  830. 	local tween_h = vint_object_find("new_tween2_1", anim_out_h)	 
  831. 	vint_set_property(anim_out_h, "target_handle", self.handle) 
  832. 	 
  833. 	local callback_string = self:package_tween_callback("close_finished") 
  834. 	vint_set_property(tween_h, "end_event", callback_string) 
  835. 		 
  836. 	lua_play_anim(anim_out_h) 
  837. end 
  838.  
  839. function Vdo_dialog:close_finished() 
  840. 	dialog_close_finished() 
  841. end 
  842.  
  843. ------------------------------------------------------------------------------- 
  844. -- Show 
  845. ------------------------------------------------------------------------------- 
  846. function Vdo_dialog:show() 
  847. 	vint_set_property(self.handle, "visible", true) 
  848. end 
  849.  
  850. ------------------------------------------------------------------------------- 
  851. -- Hide 
  852. ------------------------------------------------------------------------------- 
  853. function Vdo_dialog:hide() 
  854. 	vint_set_property(self.handle, "visible", false) 
  855. end 
  856.  
  857. function Vdo_dialog:set_color(main_bg_color, highlight_color) 
  858. 	local border_h = vint_object_find("border", self.handle) 
  859. 	vint_set_property(border_h, "tint", main_bg_color.R, main_bg_color.G, main_bg_color.B) 
  860. 	 
  861. 	self.highlight:set_highlight_color(highlight_color) 
  862.  
  863. 	local spinner_gfx_h = vint_object_find("spinner_gfx_1", self.base_content_h) 
  864. 	vint_set_property(spinner_gfx_h, "tint", main_bg_color.R, main_bg_color.G, main_bg_color.B)	 
  865. end 
  866.  
  867.  
  868. ------------------------------------------------------------------------------- 
  869. -- Navigation... 
  870. ------------------------------------------------------------------------------- 
  871. function Vdo_dialog:nav(direction) 
  872. 	local options = self.current_dialog.options 
  873. 	local selected_option = options.selected_option 
  874. 	local option_count = options.option_count 
  875.  
  876. 	if option_count <= 0 then 
  877. 		return false 
  878. 	end 
  879. 	 
  880. 	if selected_option == nil then 
  881. 		options.selected_option = 0 
  882. 		selected_option = 0 
  883. 	end 
  884.  
  885. 	local new_option = selected_option + direction 
  886. 	if new_option < 0 then 
  887. 		new_option = options.option_count - 1 
  888. 	elseif new_option == options.option_count then 
  889. 		--exceeded limit go 
  890. 		new_option = 0 
  891. 	end 
  892. 	 
  893. 	if options[new_option] ~= nil and options[new_option].disabled ~= nil and options[new_option].disabled then -- if the option is disabled, try again. 
  894. 		if direction == 0 then 
  895. 			direction = direction + 1 
  896. 		end 
  897. 		new_option = new_option + direction 
  898. 		if new_option < 0 then 
  899. 			new_option = options.option_count - 1 
  900. 		elseif new_option == options.option_count then 
  901. 			--exceeded limit go 
  902. 			new_option = 0 
  903. 		end 
  904. 	end 
  905.  
  906. 	dialog_box_set_current_option(self.dialog_handle, new_option) 
  907. 	 
  908. 	self:highlight_option(new_option) 
  909.  
  910. 	return true 
  911. end 
  912.  
  913. -- Add mouse inputs to the options 
  914. function Vdo_dialog:add_mouse_inputs(callback_action, callback_nav, input_tracker, priority) 
  915. 	local options = self.current_dialog.options 
  916. 	if (options == nil) or (callback_action == nil) or (callback_nav == nil) then 
  917. 		return 
  918. 	end 
  919. 	 
  920. 	-- Default priority value to 200 
  921. 	priority = priority or 200 
  922. 	 
  923. 	-- Clear out old wide hitboxes 
  924. 	if self.wide_hitboxes ~= nil then 
  925. 		for idx, wide_hitbox in pairs(self.wide_hitboxes) do 
  926. 			vint_object_destroy(wide_hitbox.handle) 
  927. 		end 
  928. 	end 
  929. 	self.wide_hitboxes = {} 
  930.  
  931. 	local highlight_w, highlight_h = vint_get_property(self.highlight.handle, "screen_size") 
  932. 	local options_obj_handle = vint_object_find("options_obj", self.handle) 
  933. 	 
  934. 	for i = 0, options.option_count - 1 do 
  935. 		if options[i].disabled == nil or options[i].disabled == false then 
  936. 			-- X = 0 
  937. 			-- Width = highlight.width 
  938. 			-- Y = option[i].y 
  939. 			-- Height = option[i].height 
  940. 			local option_x, option_y = vint_get_property(options[i].h, "anchor") 
  941. 			local option_w, option_h = vint_get_property(options[i].h, "screen_size") 
  942. 			 
  943. 			local wide_index = #self.wide_hitboxes + 1 
  944. 			local wide_name = "wide_hitbox"..wide_index 
  945. 			local wide_handle = vint_object_create(wide_name, "bitmap", options_obj_handle) 
  946. 			 
  947. 			self.wide_hitboxes[wide_index] = {} 
  948. 			self.wide_hitboxes[wide_index].handle = wide_handle 
  949. 			self.wide_hitboxes[wide_index].idx = i 
  950. 			vint_set_property(wide_handle, "auto_offset", "w") 
  951. 			vint_set_property(wide_handle, "visible", false) 
  952. 			vint_set_property(wide_handle, "depth", 100) 
  953. 			vint_set_property(wide_handle, "screen_size", highlight_w - 8, option_h + 2) 
  954. 			vint_set_property(wide_handle, "anchor", 0, option_y + 1) 
  955. 			vint_set_property(wide_handle, "mouse_depth", -5000) 
  956. 			options[i].wide_handle = wide_handle 
  957. 		 
  958. 			input_tracker:add_mouse_input("mouse_click", callback_action, priority, options[i].wide_handle) 
  959. 			input_tracker:add_mouse_input("mouse_move", callback_nav, priority, options[i].wide_handle) 
  960. 		end 
  961. 	end 
  962. 	 
  963. 	local bg_h = vint_object_find("background", self.handle) 
  964. 	vint_set_property(bg_h, "mouse_depth", -4000) 
  965. 	input_tracker:add_mouse_input("mouse_move", callback_nav, priority, bg_h) 
  966. 	input_tracker:add_mouse_input("mouse_click", callback_action, priority, bg_h) 
  967.  
  968. 	--loop through and see if we have any hintbars to add inputs to... 
  969. 	local widgets_count = self.current_dialog.widgets.widgets_count	 
  970. 	for i = 0, widgets_count - 1 do 
  971. 		local widget = self.current_dialog.widgets[i] 
  972. 		local widget_type = widget.type 
  973. 		if widget_type == DIALOG_WIDGET_TYPE_TEXT then 
  974. 			local is_waiting 	=	widget.is_waiting  
  975. 			if is_waiting then 
  976. 				self.hint_bar:add_mouse_inputs("dialog", input_tracker) 
  977. 				self.hint_bar:override_mouse_depths(-5000) 
  978. 			end 
  979. 		end 
  980. 	end	 
  981. end 
  982.  
  983. -- Search through the options and match the index 
  984. function Vdo_dialog:get_option_index(handle) 
  985. 	local options = self.current_dialog.options 
  986. 	 
  987. 	for i = 0, options.option_count - 1 do 
  988. 		if options[i].wide_handle == handle then 
  989. 			return i 
  990. 		end 
  991. 	end 
  992. 	 
  993. 	return -1 
  994. end 
  995.  
  996. ------------------------------------------------------------------------------- 
  997. -- Selects current option, sends data to callback... 
  998. ------------------------------------------------------------------------------- 
  999. function Vdo_dialog:select() 
  1000. 	local options = self.current_dialog.options 
  1001. 	local selected_option = options.selected_option 
  1002. 	 
  1003. 	if selected_option ~= nil and options[selected_option] ~= nil and options[selected_option].disabled ~= nil and options[selected_option].disabled then 
  1004. 		return 
  1005. 	end 
  1006. 	 
  1007. 	--if game_get_platform() == "PC" and options[selected_option] ~= nil and options[selected_option].has_second_option then 
  1008. 	--	return 
  1009. 	--end 
  1010.  
  1011. 	return dialog_box_set_result(self.dialog_handle, selected_option, DIALOG_ACTION_SELECT) 
  1012. end 
  1013.  
  1014. ------------------------------------------------------------------------------- 
  1015. -- Returns the currently selected option 
  1016. ------------------------------------------------------------------------------- 
  1017. function Vdo_dialog:get_selected() 
  1018. 	return self.current_dialog.options.selected_option 
  1019. end 
  1020.  
  1021. ------------------------------------------------------------------------------- 
  1022. -- Returns whether the option has a second option 
  1023. ------------------------------------------------------------------------------- 
  1024. function Vdo_dialog:has_second_option(option_idx) 
  1025. 	if self.current_dialog == nil or self.current_dialog.options == nil or self.current_dialog.options[option_idx] == nil then 
  1026. 		return false 
  1027. 	end 
  1028. 	return self.current_dialog.options[option_idx].has_second_option 
  1029. end 
  1030.  
  1031. ------------------------------------------------------------------------------- 
  1032. -- Fires back event... 
  1033. ------------------------------------------------------------------------------- 
  1034. function Vdo_dialog:back() 
  1035. 	local options = self.current_dialog.options 
  1036. 	local selected_option = options.selected_option 
  1037. 	return dialog_box_set_result(self.dialog_handle, selected_option, DIALOG_ACTION_BACK) 
  1038. end 
  1039.  
  1040. ------------------------------------------------------------------------------- 
  1041. -- cleanup Dialog VDO! 
  1042. ------------------------------------------------------------------------------- 
  1043. function Vdo_dialog:cleanup() 
  1044. end 
  1045.  
  1046. -- Given a set of options, return several width metric about them 
  1047. -- 
  1048. -- options: Set of dialog options to work with. Usually self.current_dialog.options, unless called from create() 
  1049. -- 
  1050. -- return 1: the maximum width of all single options that has no second option 
  1051. -- return 2: the maximum width of all single options that does have a second option 
  1052. -- return 3: the maximum width of all second options 
  1053. function Vdo_dialog:get_option_widths(options) 
  1054. 	local option_count = options.option_count 
  1055. 	 
  1056. 	local solo_option_1_max_width = 0 
  1057. 	local paired_option_1_max_width = 0 
  1058. 	local paired_option_2_max_width = 125 	-- This is also the default width of the text box... Approximatly 8 characters... 
  1059. 	if game_get_platform() == "PC" then 
  1060. 		paired_option_2_max_width = 250 -- Double it on PC so typing directly in it isn't so jarring 
  1061. 	end 
  1062. 	 
  1063. 	for i = 0, option_count - 1 do 
  1064. 		local option_1_text_h = vint_object_find("option_txt_1", options[i].h)		 
  1065. 		local option_1_width = element_get_actual_size(option_1_text_h) 
  1066. 		 
  1067. 		if options[i].has_second_option == true then 
  1068. 			local option_2_text_h = vint_object_find("option_txt_2", options[i].h) 
  1069. 			local option_2_width = element_get_actual_size(option_2_text_h) 
  1070. 			 
  1071. 			paired_option_1_max_width = max(paired_option_1_max_width, option_1_width) 
  1072. 			paired_option_2_max_width = max(paired_option_2_max_width, option_2_width) 
  1073. 		else 
  1074. 			solo_option_1_max_width = max(solo_option_1_max_width, option_1_width) 
  1075. 		end 
  1076. 	end 
  1077. 	 
  1078. 	return solo_option_1_max_width, paired_option_1_max_width, paired_option_2_max_width 
  1079. end 
  1080.  
  1081. -- Given a set of options, return the necessary width of the dialog box to contain them 
  1082. -- 
  1083. -- options: Set of dialog options to work with. Usually self.current_dialog.options, unless called from create() 
  1084. -- 
  1085. -- return 1: the necessary width of the dialog box 
  1086. function Vdo_dialog:get_dialog_width(options, widgets) 
  1087. 	local options_obj_h = vint_object_find("options_obj", self.base_content_h) 
  1088. 	local base_option_obj_h = vint_object_find("option", options_obj_h)	 
  1089. 	 
  1090. 	local x, y = vint_get_property(base_option_obj_h, "anchor") 
  1091. 	 
  1092. 	local solo_option_1_max_width, paired_option_1_max_width, paired_option_2_max_width = self:get_option_widths(options) 
  1093. 	 
  1094. 	local options_largest_width = max(solo_option_1_max_width, paired_option_1_max_width + paired_option_2_max_width + 5) 
  1095. 	local options_width = x + options_largest_width + DIALOG_BOX_CONTENT_OPTIONS_HORIZONTAL_SPACING + DIALOG_BOX_CONTENT_OPTIONS_HORIZONTAL_OFFSET 
  1096.  
  1097. 	local widgets_width = self:get_widgets_width(widgets) 
  1098. 	 
  1099. -- SMH: I'm sure leaving these lines commented out is "wrong", but in the only case this 
  1100. -- function is being used, it's necessary to prevent lua from failing to find the title 
  1101. -- text obj and then try to index null when I try to get its size. 
  1102.  
  1103. --	local title_txt_obj = vint_object_find("title_txt", self.base_content_h) 
  1104. --	local title_width, title_height = title_txt_obj:get_actual_size() 
  1105. --	title_width = title_width + 6	--for padding 
  1106. 	 
  1107. 	local dialog_width = max(DIALOG_BOX_MIN_WIDTH, options_width) 
  1108. 	dialog_width = max(dialog_width, widgets_width) 
  1109. --	dialog_width = max(dialog_width, title_width) 
  1110.  
  1111. 	return dialog_width 
  1112. end 
  1113.  
  1114. -- Given a set of options, return their cumulative height 
  1115. -- 
  1116. -- options: Set of dialog options to work with. Usually self.current_dialog.options, unless called from create() 
  1117. -- 
  1118. function Vdo_dialog:get_options_height(options) 
  1119. 	local option_count = options.option_count 
  1120. 	 
  1121. 	if option_count <= 0 then 
  1122. 		return 0 
  1123. 	end 
  1124. 	 
  1125. 	local x, y = vint_get_property(options[option_count-1].h, "anchor") 
  1126. 	return y + DIALOG_BOX_CONTENT_OPTIONS_SPACING - 9 
  1127. end 
  1128.  
  1129. -- Given a set of options, return their cumulative height 
  1130. -- 
  1131. -- return 1: the maximum height of widgets 
  1132. function Vdo_dialog:get_widgets_height(widgets) 
  1133. 	local widgets_count = widgets.widgets_count 
  1134. 	 
  1135. 	local max_widget_y = DIALOG_BOX_CONTENT_START_Y 
  1136. 	for i = 0, widgets_count - 1 do 
  1137. 		local height = widgets[i].height 
  1138. 		local width = widgets[i].width 
  1139. 		local x, y 
  1140. 		 
  1141. 		if widgets[i].type == DIALOG_WIDGET_TYPE_TEXT then 
  1142. 			--height = self.text_line_height * widgets[i].num_lines 
  1143. 		end 
  1144.  
  1145. 		x, y = vint_get_property(widgets[i].h, "anchor") 
  1146. 		 
  1147. 		max_widget_y = max(max_widget_y, y + height + DIALOG_BOX_CONTENT_VERTICAL_SPACING) 
  1148. 	end 
  1149. 	 
  1150. 	return max_widget_y - DIALOG_BOX_CONTENT_START_Y 
  1151. end 
  1152.  
  1153. -- Given a set of options, return their cumulative width 
  1154. -- 
  1155. -- return 1: the maximum height of widgets 
  1156. function Vdo_dialog:get_widgets_width(widgets) 
  1157. 	local widgets_count = #widgets 
  1158. 	 
  1159. 	local widgets_width = 0 
  1160. 	for i = 0, widgets_count - 1 do 
  1161. 		widgets_width = max(widgets_width, widgets[i].width) 
  1162. 	end 
  1163. 	 
  1164. 	return widgets_width 
  1165. end 
  1166.  
  1167. function Vdo_dialog:resize_options(options) 
  1168. 	local option_count = options.option_count 
  1169. 	local solo_option_1_max_width, paired_option_1_max_width, paired_option_2_max_width = self:get_option_widths(options) 
  1170.  
  1171. 	-- Align second options... 
  1172. 	-- todo align right side of box to width of the shit... 
  1173. 	for i = 0, option_count - 1 do 
  1174. 		local current_option_h = options[i].h  
  1175. 		local option_txt_1_h = vint_object_find("option_txt_1", current_option_h) 
  1176. 		local option_2_grp_h = vint_object_find("option_2_grp", current_option_h) 
  1177. 		local x, y = vint_get_property(option_txt_1_h, "anchor") 
  1178. 		vint_set_property(option_2_grp_h, "anchor", x + paired_option_1_max_width + DIALOG_BOX_CONTENT_OPTIONS_HORIZONTAL_SPACING, y) 
  1179. 		 
  1180. 		--Set size of option2 box, + 10 to account for padding... 
  1181. 		local option_2_box_width = paired_option_2_max_width + 10 
  1182. 		 
  1183. 		--Resize background  
  1184. 		local box_bg_h = vint_object_find("option_box_bg", current_option_h) 
  1185. 		local box_bg_width, box_bg_height = element_get_actual_size(box_bg_h) 
  1186. 		element_set_actual_size(box_bg_h, option_2_box_width - 4, box_bg_height)	--its the box width.. - 4 is the width of the size so we subtract it... 
  1187. 		 
  1188. 		--Resize the north and south sides of the box... 
  1189. 		local box_n_h = vint_object_find("option_box_n", current_option_h) 
  1190. 		local box_s_h = vint_object_find("option_box_s", current_option_h) 
  1191. 		 
  1192. 		local box_width, box_height = element_get_actual_size(box_n_h) 
  1193. 		element_set_actual_size(box_n_h, option_2_box_width, box_height) 
  1194. 		element_set_actual_size(box_s_h, option_2_box_width, box_height) 
  1195. 		 
  1196. 		--Reposition right side of box... 
  1197. 		local box_e_h = vint_object_find("option_box_e", current_option_h) 
  1198. 		local box_x, box_y  = vint_get_property(box_e_h, "anchor") 
  1199. 		vint_set_property(box_e_h, "anchor", option_2_box_width, box_y) 
  1200. 	end 
  1201. end 
  1202.  
  1203. -- Given a set of options and widgets, return the necessary height of a dialog box to contain them 
  1204. -- 
  1205. -- return 1: The necessary height of the dialog box 
  1206. function Vdo_dialog:get_dialog_height(options, widgets) 
  1207. 	return self:get_options_height(options) + self:get_widgets_height(widgets) 
  1208. end 
  1209.  
  1210. function Vdo_dialog:set_option_text(option_idx, new_text, do_morph, morph_complete_cb) 
  1211. 	if self.morph_playing == true then 
  1212. 		self:morph_complete() 
  1213. 	end 
  1214. 	 
  1215. 	local options = self.current_dialog.options 
  1216. 	 
  1217. 	local option_1_text_h = vint_object_find("option_txt_1", options[option_idx].h)		 
  1218. 	 
  1219. 	if options[option_idx].has_second_option == true then 
  1220. 		options[option_idx].tag_2 = new_text 
  1221. 		local option_2_text_h = vint_object_find("option_txt_2", options[option_idx].h) 
  1222. 		vint_set_property(option_2_text_h, "text_tag", options[option_idx].tag_2) 
  1223. 	else 
  1224. 		options[option_idx].tag_1 = new_text 
  1225. 		local option_1_text_h = vint_object_find("option_txt_1", options[option_idx].h) 
  1226. 		vint_set_property(option_1_text_h, "text_tag", options[option_idx].tag_1)	 
  1227. 	end 
  1228. 	 
  1229. 	self:resize_options(options) 
  1230.  
  1231. 	local dialog_box_width = self:get_dialog_width(options, self.current_dialog.widgets) 
  1232. 	local dialog_box_height = self:get_dialog_height(options, self.current_dialog.widgets) 
  1233.  
  1234. 	if self.width ~= dialog_box_width or self.height ~= dialog_box_height then 
  1235. 		if do_morph == true then 
  1236. 			--Need to clone and delete old dialog content when finished... 
  1237. 			--our morph callback will handle any remaining cleanup.. 
  1238. 			self.previous_content_h = vint_object_clone(self.base_content_h) 
  1239. 			 
  1240. 			--Move content behind new content... 
  1241. 			vint_set_property(self.previous_content_h, "depth", 5000) 
  1242. 			 
  1243. 			if morph_complete_cb ~= nil then 
  1244. 				self.morph_complete_cb = morph_complete_cb 
  1245. 			else 
  1246. 				self.morph_complete_cb = nil 
  1247. 			end 
  1248. 		else 
  1249. 			self.morph_complete_cb = nil 
  1250. 		end 
  1251.  
  1252. 		--Change to new size... 
  1253. 		self:morph_size(dialog_box_width, dialog_box_height, do_morph) 
  1254. 	end 
  1255. end 
  1256.  
  1257. --[[ --------------------------------------------------------------------- 
  1258. -- Function - vdo_dialog_update_gamepad_state 
  1259. -- Description - Called by code anytime gamepad is plugged or unplugged. 
  1260. -- Parameters - none 
  1261. -- Returns - nil 
  1262. ]]-- --------------------------------------------------------------------- 
  1263. function vdo_dialog_update_gamepad_state() 
  1264. 	Dialog_object_0.highlight:show_button(CTRL_MENU_BUTTON_A) 
  1265. 	Dialog_object_1.highlight:show_button(CTRL_MENU_BUTTON_A) 
  1266. end