sr2lua/menu_base.lua

  1. ------------------------------------------------------------------------------------------------------- 
  2. ------------------------------------------------------------------------------------------------------- 
  3. -- MENU DATA 
  4.  
  5. MENU_TRANSITION_NONE				= 0 
  6. MENU_TRANSITION_SWAP				= 1 
  7. MENU_TRANSITION_SWEEP_RIGHT	= 2 
  8. MENU_TRANSITION_SWEEP_LEFT		= 3 
  9.  
  10. MENU_ITEM_TYPE_SUB_MENU 		= 0 
  11. MENU_ITEM_TYPE_SELECTABLE 		= 1 
  12. MENU_ITEM_TYPE_NUM_SLIDER 		= 2 
  13. MENU_ITEM_TYPE_TEXT_SLIDER 	= 3 
  14. MENU_ITEM_TYPE_GRID 				= 4 
  15. MENU_ITEM_TYPE_PALETTE 			= 5 
  16. MENU_ITEM_TYPE_INFO_BOX 		= 6 
  17. MENU_ITEM_TYPE_MARQUEE			= 7 
  18.  
  19. MENU_MIN_LABEL_W = 100 
  20. MENU_MIN_MENU_W = 238 
  21. MENU_MAX_MENU_H = 375 
  22. MENU_CONTROL_W = 220 
  23. MENU_ITEM_HEIGHT = 32 
  24. MENU_BASE_DOC_HANDLE = 0 
  25. MENU_SWATCH_DEFAULT_ROW_HEIGHT = 69 
  26. MENU_SWATCH_DEFAULT_COL_WIDTH = 78 
  27.  
  28. MENU_FOOTER_CASH_BROKE_COLOR = {["R"] = 0.8, ["G"] = 0, ["B"] = 0} 				--RED 
  29. MENU_FOOTER_CASH_NORMAL_COLOR = {["R"] = 0.88, ["G"] = 0.749, ["B"] = 0.05}	--YELLOW 
  30.  
  31. MENU_MARQUEE_SPEED = 0.009				--	Multiplier for how fast it goes. Closer to 0 this gets, the faster it gets 
  32. MENU_MARQUEE_DELAY = 0.5				-- Delay between pausing and restarting 
  33. MENU_MARQUEE_SCROLL_CORRECTION = 7	--	For adjusting how long it is for it to scroll. The smaller this number, the longer the line can be. 
  34.  
  35. INVALID_PALETTE_INDEX = -1 
  36.  
  37. Menu_palette_stored_index = INVALID_PALETTE_INDEX 
  38.  
  39. Menu_scaler = 1 
  40. Menu_active_anchor_end_x = 0 
  41. Menu_active_anchor_end_y = 0 
  42. Menu_horz_label_clip_x = 0 
  43. Menu_horz_label_clip_y = 0 
  44.  
  45. Menu_fade_to_black = false 
  46. Menu_input_blocked = 0 
  47. Menu_new = false 
  48. Menu_active = 0 
  49. Menu_inactive = 0 
  50. Menu_horz_active = 0 
  51. Menu_close_cb = 0 
  52. Menu_input_accelleration = 1 
  53. Menu_use_hud = false 
  54. Menu_option_labels = { } 
  55. Menu_option_labels_inactive = { } 
  56.  
  57. Menu_nav_bars = {}	 
  58. Menu_transition_data = { tweens = { } } 
  59. Menu_fading_label = 0 
  60. Menu_marquee_info = { } 
  61.  
  62. Menu_anims = {}				--Handles to cloned animations 
  63. Menu_trans_in_twns = {}		--Handles to menu transition tweens (IN) 
  64. Menu_trans_out_twns = {}	--Handles to menu transition tweens (OUT) 
  65. Menu_input_subscriptions = {} 
  66.  
  67. --Threads 
  68. Menu_horz_update_label_thread = -1 
  69.  
  70. Menu_transition_in_progress = false 
  71. Menu_swap_center = false 
  72. Menu_hud_hidden = false 
  73.  
  74. function menu_base_init() 
  75. 	MENU_BASE_DOC_HANDLE = vint_document_find("menu_base") 
  76. 	vint_set_property(vint_object_find("menu_trans_in",  		nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  77. 	vint_set_property(vint_object_find("menu_trans_out", 		nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  78. 	vint_set_property(vint_object_find("cash_trans_in",  		nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  79. 	vint_set_property(vint_object_find("cash_trans_out",  		nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  80. 	vint_set_property(vint_object_find("menu_horz_lt_anim", 	nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  81. 	vint_set_property(vint_object_find("menu_horz_rt_anim", 	nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  82. 	vint_set_property(vint_object_find("menu_horz_up_anim", 	nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  83. 	vint_set_property(vint_object_find("menu_horz_dn_anim", 	nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  84. 	vint_set_property(vint_object_find("swap_message_trans_in", nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  85. 	vint_set_property(vint_object_find("swap_message_trans_out",nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  86. 	vint_set_property(vint_object_find("black_fade_out", 		nil, MENU_BASE_DOC_HANDLE) , "is_paused", true) 
  87. 	vint_set_property(vint_object_find("menu_btn_tips_anim", 		nil, MENU_BASE_DOC_HANDLE) , "is_paused", true) 
  88. end 
  89.  
  90. -- calls release function for this control type 
  91. function menu_release_control(control) 
  92. 	local cb = Menu_control_callbacks[control.type] 
  93.  
  94. 	if cb.on_release ~= nil then 
  95. 		cb.on_release(control) 
  96. 	end 
  97. end 
  98.  
  99. function menu_num_slider_on_enter(menu_label, menu_data) 
  100. 	if menu_label.control.is_highlighted == false then 
  101. 		local g = menu_label.control.grp_h 
  102. 		vint_set_property(vint_object_find("large_thumb", g), "visible", true) 
  103. 		vint_set_property(vint_object_find("small_thumb", g), "visible", true) 
  104. 		vint_set_property(menu_label.control.grp_h, "depth", 0) 
  105. 		vint_set_property(vint_object_find("num_slider_arrow_e", g), "tint", 0.8941, 0.8489, 0.051) 
  106. 		vint_set_property(vint_object_find("num_slider_arrow_w", g), "tint", 0.8941, 0.8489, 0.051) 
  107. 		menu_label.control.is_highlighted = true 
  108. 		 
  109. 		menu_label.input1 = vint_subscribe_to_input_event(nil, "nav_right", "menu_num_slider_nav_right", 5) 
  110. 		vint_set_input_params(menu_label.input1, MENU_NUM_SLIDER_ACCEL_REPEAT, MENU_NUM_SLIDER_ACCEL_FACTOR, MENU_NUM_SLIDER_ACCEL_LIMIT, true) 
  111. 		menu_label.input2 = vint_subscribe_to_input_event(nil, "nav_left", "menu_num_slider_nav_left", 5) 
  112. 		vint_set_input_params(menu_label.input2, MENU_NUM_SLIDER_ACCEL_REPEAT, MENU_NUM_SLIDER_ACCEL_FACTOR, MENU_NUM_SLIDER_ACCEL_LIMIT, true) 
  113. 		 
  114. 		--Anim in 
  115. 		menu_label.control.anim_in_h = vint_object_clone(vint_object_find("menu_num_slider_in_anim")) 
  116. 		vint_set_property(menu_label.control.anim_in_h, "target_handle", g) 
  117. 		lua_play_anim(menu_label.control.anim_in_h, 0) 
  118. 		 
  119. 		--Trigger pulsing animation	 
  120. 		menu_label.control.anim_pulse_h = vint_object_clone(vint_object_find("menu_num_slider_pulse_anim")) 
  121. 		vint_set_property(menu_label.control.anim_pulse_h, "target_handle", g) 
  122. 		lua_play_anim(menu_label.control.anim_pulse_h, 0) 
  123. 	end 
  124. end 
  125.  
  126. function menu_num_slider_on_leave(menu_label, menu_data) 
  127. 	if menu_label.control.is_highlighted == true then 
  128. 	 
  129. 		--Destroy animations 
  130. 		if menu_label.control.anim_in_h ~= nil then 
  131. 			vint_object_destroy(menu_label.control.anim_in_h) 
  132. 		end 
  133. 		if menu_label.control.anim_pulse_h ~= nil then 
  134. 			vint_object_destroy(menu_label.control.anim_pulse_h) 
  135. 		end 
  136. 	 
  137. 		local g = menu_label.control.grp_h 
  138. 		vint_set_property(vint_object_find("num_slide_bg_1_left", g), "alpha", 1) 
  139. 		vint_set_property(vint_object_find("num_slide_bg_1_right", g), "alpha", 1) 
  140. 		vint_set_property(vint_object_find("num_slide_bg_2_right", g), "alpha", 0) 
  141. 		vint_set_property(vint_object_find("num_slide_bg_2_left", g), "alpha", 0) 
  142. 		 
  143. 		vint_set_property(vint_object_find("large_thumb", g), "alpha", 0) 
  144. 		vint_set_property(vint_object_find("small_thumb", g), "alpha", 1) 
  145. 		vint_set_property(vint_object_find("small_thumb", g), "scale", 1, 1) 
  146. 		vint_set_property(menu_label.control.grp_h, "depth", menu_label.depth) 
  147. 		vint_set_property(vint_object_find("value_text", g), "scale", 0.68, 0.68) 
  148. 		local arrow_e_h = vint_object_find("num_slider_arrow_e", g) 
  149. 		local arrow_w_h = vint_object_find("num_slider_arrow_w", g) 
  150. 		vint_set_property(arrow_e_h, "tint", 0.3647, 0.3725, 0.3804) 
  151. 		vint_set_property(arrow_w_h, "tint", 0.3647, 0.3725, 0.3804) 
  152. 		vint_set_property(arrow_e_h, "offset", -11, -15) 
  153. 		vint_set_property(arrow_w_h, "offset", -11, -15) 
  154. 		 
  155. 		menu_label.control.is_highlighted = false 
  156.  
  157. 		if menu_label.input1 ~= nil then 
  158. 			vint_unsubscribe_to_input_event(menu_label.input1) 
  159. 			vint_unsubscribe_to_input_event(menu_label.input2) 
  160. 			menu_label.input1 = nil 
  161. 			menu_label.input2 = nil 
  162. 		end 
  163. 	end 
  164. end 
  165.  
  166. function menu_num_slider_nav_left(target, event, accelleration) 
  167. 	local menu_label = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  168. 	local menu_data = Menu_active[Menu_active.highlighted_item] 
  169.  
  170. 	if menu_input_is_blocked() then 
  171. 		return 
  172. 	end 
  173. 	 
  174. 	if menu_data.cur_value > 0 then 
  175. 		local delta = 0.01 * accelleration 
  176. 		if delta > 0.03 then delta = 0.03 end 
  177. 		menu_data.cur_value = menu_data.cur_value - delta 
  178.  
  179. 		if menu_data.cur_value < 0 then 
  180. 			menu_data.cur_value = 0 
  181. 		end 
  182.  
  183. 		audio_play(Menu_sound_value_nav) 
  184. 		menu_num_slider_update_value(menu_label, menu_data) 
  185. 	end 
  186. end 
  187.  
  188. function menu_num_slider_nav_right(target, event, accelleration) 
  189. 	local menu_label = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  190. 	local menu_data = Menu_active[Menu_active.highlighted_item] 
  191. 	 
  192. 	if menu_input_is_blocked() then 
  193. 		return 
  194. 	end 
  195. 	 
  196. 	if menu_data.cur_value < 1 then 
  197. 		local delta = 0.01 * accelleration 
  198. 		if delta > 0.03 then delta = 0.03 end 
  199. 		menu_data.cur_value = menu_data.cur_value + delta 
  200.  
  201. 		if menu_data.cur_value > 1 then 
  202. 			menu_data.cur_value = 1 
  203. 		end 
  204.  
  205. 		audio_play(Menu_sound_value_nav) 
  206. 		menu_num_slider_update_value(menu_label, menu_data) 
  207. 	end 
  208. end 
  209.  
  210. function menu_num_slider_update_value(menu_label, menu_data) 
  211. 	local left = 30 + (183 - menu_data.thumb_width) * menu_data.cur_value 
  212.  
  213. 	local h = vint_object_find("all_thumbs", menu_label.control.grp_h) 
  214. 	vint_set_property(h, "anchor", left, 0) 
  215.  
  216. 	if menu_data.on_value_update ~= nil then 
  217. 		-- this is the user callback 
  218. 		menu_data.on_value_update(menu_label, menu_data) 
  219. 	end 
  220. end 
  221.  
  222. function menu_num_slider_show(menu_label, menu_data) 
  223. 	local control = menu_label.control 
  224.  
  225. 	if control ~= nil then 
  226. 		if control.type ~= MENU_ITEM_TYPE_NUM_SLIDER then 
  227. 			-- this isn't a MENU_ITEM_TYPE_NUM_SLIDER so release it 
  228. 			menu_release_control(control) 
  229. 			control = nil 
  230. 		end 
  231. 	end 
  232.  
  233. 	if control == nil then 
  234. 		local control_h = vint_object_clone(vint_object_find("menu_number_slider", Menu_option_labels.control_parent)) 
  235. 		control = { grp_h = control_h, type = MENU_ITEM_TYPE_NUM_SLIDER, is_highlighted = true } 
  236. 	end 
  237.  
  238. 	menu_label.control = control 
  239. 	 
  240. 	vint_set_property(control.grp_h, "visible", true) 
  241. 	vint_set_property(control.grp_h, "anchor", menu_label.anchor_x + Menu_option_labels.max_label_w + 5, 
  242. 		menu_label.anchor_y) 
  243. 	vint_set_property(control.grp_h, "depth", menu_label.depth) 
  244. 	menu_num_slider_update_value(menu_label, menu_data) 
  245. 	local h = vint_object_find("value_text", control.grp_h) 
  246. 	vint_set_property(h, "anchor", menu_data.thumb_width * 0.5 -2, 0) 
  247.  
  248. 	-- position the thumb elements 
  249. 	h = vint_object_find("large_thumb_bg", control.grp_h) 
  250. 	vint_set_property(h, "source_se", menu_data.thumb_width - 5, 45) 
  251. 	h = vint_object_find("large_thumb_bg_hl", control.grp_h) 
  252. 	vint_set_property(h, "source_se", menu_data.thumb_width - 5, 45) 
  253. 	 
  254. 	h = vint_object_find("large_thumb_ns", control.grp_h) 
  255. 	vint_set_property(h, "source_se", menu_data.thumb_width - 24, 69) 
  256. 	h = vint_object_find("large_thumb_e", control.grp_h) 
  257. 	vint_set_property(h, "anchor", menu_data.thumb_width - 14, -32) 
  258.  
  259. 	h = vint_object_find("small_thumb_bg", control.grp_h) 
  260. 	vint_set_property(h, "source_se", menu_data.thumb_width - 5, 45) 
  261. 	h = vint_object_find("small_thumb_ns", control.grp_h) 
  262. 	vint_set_property(h, "source_se", menu_data.thumb_width - 22, 69) 
  263. 	h = vint_object_find("small_thumb_e", control.grp_h) 
  264. 	vint_set_property(h, "anchor", menu_data.thumb_width - 12, -22) 
  265. end 
  266.  
  267. function menu_num_slider_release(control) 
  268. 	vint_object_destroy(control.grp_h) 
  269. end 
  270.  
  271. function menu_control_on_select(menu_label, menu_data) 
  272. 	if menu_data.on_select ~= nil then 
  273. 		menu_data.on_select(menu_label, menu_data) 
  274. 	end 
  275. end 
  276.  
  277. function menu_submenu_on_select(menu_label, menu_data) 
  278. 	if menu_data.on_select ~= nil then 
  279. 		menu_data.on_select(menu_label, menu_data) 
  280. 	end 
  281. 	 
  282. 	if menu_data.sub_menu ~= nil then 
  283. 		menu_data.sub_menu.parent_menu = Menu_active 
  284. 		menu_show(menu_data.sub_menu, MENU_TRANSITION_SWEEP_LEFT) 
  285. 	end 
  286. end 
  287.  
  288. function menu_grid_update_swatches(menu_data, focus_row) 
  289. 	local num_vis_rows = menu_data.visible_rows 
  290.  
  291. 	local first_vis_row = 0 
  292.  
  293. 	if focus_row < 2 then 
  294. 		first_vis_row = 0 
  295. 	elseif focus_row >= menu_data.total_rows - 1 then 
  296. 		first_vis_row = menu_data.total_rows - menu_data.visible_rows 
  297. 	elseif focus_row < menu_data.first_vis_row + 1 then 
  298. 		first_vis_row = focus_row - 1 
  299. 	elseif focus_row >= menu_data.first_vis_row + menu_data.visible_rows - 1 then 
  300. 		first_vis_row = focus_row - num_vis_rows + 2 
  301. 	else 
  302. 		return 
  303. 	end 
  304.  
  305. 	if first_vis_row == menu_data.first_vis_row then 
  306. 		return 
  307. 	end 
  308.  
  309. 	local last_vis_row = first_vis_row + num_vis_rows - 1 
  310.  
  311. 	local idx = 0 
  312. 	local row, col = 0, 0 
  313. 	local swatch_id 
  314. 	local pos_x, pos_y 
  315. 	local swatches = menu_data.swatches 
  316. 	local swatch_bin = swatches.swatch_bin 
  317.  
  318. 	-- recycle any unused swatch clusters 
  319. 	while idx < swatches.num_swatches do 
  320. 		if row < first_vis_row or row > last_vis_row then 
  321. 			if swatches[idx].swatch_h ~= nil then 
  322. 				swatch_id = swatches[idx].swatch_h 
  323. 				swatch_bin[swatch_id] = true 
  324. 				vint_set_property(swatch_id, "visible", false) 
  325. 				vint_set_property(swatch_id, "depth", 10 - row) 
  326. 				swatches[idx].swatch_h = nil 
  327. 			end 
  328. 		end 
  329.  
  330. 		idx = idx + 1 
  331. 		col = col + 1 
  332. 		if col >= menu_data.num_cols then 
  333. 			col = 0 
  334. 			row = row + 1 
  335. 		end 
  336. 	end 
  337.  
  338. 	local offset_v = menu_data.offset_v + 3 
  339. 	local offset_h = menu_data.offset_h + menu_data.col_width * 0.5 
  340. 	local icon_h = 0 
  341.  
  342. 	row, col, idx = 0, 0, 0 
  343. 	while idx < swatches.num_swatches do 
  344. 		if row >= first_vis_row and row <= last_vis_row then 
  345. 			local swatch = swatches[idx] 
  346. 			 
  347. 			if swatch.swatch_h == nil then 
  348. 				for key, value in swatch_bin do 
  349. 					-- pull a swatch from the recycle bin 
  350. 					swatch.swatch_h = key 
  351. 					swatch.swatch_bg_h = vint_object_find("bg", key) 
  352. 					swatch_bin[key] = nil 
  353. 					break 
  354. 				end 
  355. 			end 
  356. 			 
  357. 			if swatch.swatch_h ~= nil then 
  358. 				swatch_id = swatch.swatch_h 
  359. 				pos_x = col * menu_data.col_width + offset_h 
  360. 				pos_y = (row - first_vis_row) * menu_data.row_height + offset_v 
  361. 				vint_set_property(swatch_id, "visible", true) 
  362. 				 
  363. 				if swatch.swatch_crc ~= nil then 
  364. 					vint_set_property(vint_object_find("icon", swatch_id), "image_crc", swatch.swatch_crc) 
  365. 				elseif swatch.swatch_str ~= nil then 
  366. 					vint_set_property(vint_object_find("icon", swatch_id), "image", swatch.swatch_str) 
  367. 				end 
  368. 				 
  369. 				vint_set_property(swatch_id, "anchor", pos_x, pos_y) 
  370. 				vint_set_property(swatch_id, "scale", menu_data.unhighlight_scale, menu_data.unhighlight_scale) 
  371. 				 
  372. 				vint_set_property(swatch.swatch_bg_h, "tint", .75, .75, .75) 
  373. 				 
  374. 				-- allow custom tweaking 
  375. 				if menu_data.update_swatch ~= nil then 
  376. 					menu_data.update_swatch(swatch, row, col, idx) 
  377. 				end 
  378. 			end 
  379. 		end 
  380.  
  381. 		idx = idx + 1 
  382. 		col = col + 1 
  383. 		if col >= menu_data.num_cols then 
  384. 			col = 0 
  385. 			row = row + 1 
  386. 		end 
  387. 	end 
  388.  
  389. 	menu_data.first_vis_row = first_vis_row 
  390. 	menu_scroll_bar_set_thumb_pos(first_vis_row / (menu_data.total_rows - menu_data.visible_rows)) 
  391. end 
  392.  
  393. function menu_grid_update_highlighted(menu_data, new_col, new_row) 
  394. 	--move the grid to the appropriate place 
  395. 	menu_grid_update_swatches(menu_data, new_row) 
  396. 	 
  397. 	local swatches = menu_data.swatches 
  398. 	local new_idx = new_row * menu_data.num_cols + new_col 
  399.  
  400. 	if new_idx >= swatches.num_swatches then 
  401. 		return 
  402. 	end 
  403.  
  404. 	local cur_idx = menu_data.cur_row * menu_data.num_cols + menu_data.cur_col 
  405. 	local new_idx = new_row * menu_data.num_cols + new_col 
  406.  
  407. 	--Animate highlighted swatch in 
  408. 	--Find, Retarget, set values, and play 
  409. 	local swatch_anim_h = vint_object_find("menu_swatch_in_anim") 
  410. 	local swatch_twn_h = vint_object_find("swatch_general_scale_twn_1", swatch_anim_h) 
  411. 	vint_set_property(swatch_twn_h, "target_handle", swatches[new_idx].swatch_h) 
  412. 	vint_set_property(swatch_twn_h, "end_value", menu_data.highlight_scale, menu_data.highlight_scale) 
  413. 	lua_play_anim(swatch_anim_h, 0) 
  414. 		 
  415. 	--Move the depth of highlighted swatch to bring it to front 
  416. 	vint_set_property(swatches[new_idx].swatch_h, "depth", -20) 
  417. 	 
  418. 	--Tint background 
  419. 	vint_set_property(swatches[new_idx].swatch_bg_h, "tint", 1, 1, 1) 
  420. 		 
  421. 	--Now reset last swatch 
  422. 	if cur_idx ~= new_idx then 
  423. 		vint_set_property(swatches[cur_idx].swatch_h, "scale", menu_data.unhighlight_scale, menu_data.unhighlight_scale) 
  424. 		vint_set_property(swatches[cur_idx].swatch_h, "depth", 10 - menu_data.cur_row) 
  425. 		 
  426. 		vint_set_property(swatches[cur_idx].swatch_bg_h, "tint", .75, .75, .75) 
  427.  
  428. 		if menu_data.on_leave ~= nil then 
  429. 			menu_data.on_leave(swatches[cur_idx]) 
  430. 		end 
  431. 	end 
  432. 	 
  433. 	local pos_x = new_col * menu_data.col_width + menu_data.offset_h + menu_data.col_width * 0.5 
  434. 	local pos_y = (new_row - menu_data.first_vis_row) * menu_data.row_height + menu_data.offset_v + 3 
  435. 	vint_set_property(menu_data.arrow_grp, "anchor", pos_x, pos_y) 
  436. 	 
  437. 	 
  438. 	--	Hide the left arrow 
  439. 	if new_col == 0 then 
  440. 		vint_set_property(menu_data.arrow_w_h, "visible", false) 
  441. 	else 
  442. 		vint_set_property(menu_data.arrow_w_h, "visible", true) 
  443. 	end 
  444. 	-- Hide the top arrow 
  445. 	if new_row == 0 then 
  446. 		vint_set_property(menu_data.arrow_n_h, "visible", false) 
  447. 	else 
  448. 		vint_set_property(menu_data.arrow_n_h, "visible", true) 
  449. 	end 
  450. 	-- Hide the right arrow 
  451. 	local next_swatch_idx = new_row * menu_data.num_cols + (new_col + 1) 
  452. 	if new_col == menu_data.num_cols - 1 or swatches.num_swatches == 1 or next_swatch_idx >= swatches.num_swatches then 
  453. 		vint_set_property(menu_data.arrow_e_h, "visible", false) 
  454. 	else 
  455. 		vint_set_property(menu_data.arrow_e_h, "visible", true) 
  456. 	end 
  457. 	-- Hide the bottom arrow 
  458. 	next_swatch_idx = (new_row + 1) * menu_data.num_cols + new_col 
  459. 	if new_row == menu_data.total_rows - 1 or next_swatch_idx >= swatches.num_swatches then 
  460. 		vint_set_property(menu_data.arrow_s_h, "visible", false) 
  461. 	else 
  462. 		vint_set_property(menu_data.arrow_s_h, "visible", true) 
  463. 	end 
  464. 	 
  465. 	--If the grid is suppose to pulse then do it... 
  466. 	if menu_data.pulse_swatch == true then 
  467. 		 
  468. 		--Clear out the cloned highlights and pulsing 
  469. 		if menu_data.swatch_highlight_h ~= nil then 
  470. 			vint_object_destroy(menu_data.swatch_highlight_h) 
  471. 		end 
  472. 		if menu_data.swatch_highlight_anim_h ~= nil then 
  473. 			vint_object_destroy(menu_data.swatch_highlight_anim_h) 
  474. 		end 
  475.  
  476. 		--Create pulsing animations 
  477. 		local root_anim = vint_object_find("root_animation") 
  478. 		--Retrigger Arrow Anim 
  479. 		local arrow_anim_h = vint_object_find("menu_swatch_arrows_pulse_anim") 
  480. 		lua_play_anim(arrow_anim_h, 0) 
  481. 		 
  482. 		--Play pulsing animation 
  483. 		local ico_h = vint_object_find("icon", swatches[new_idx].swatch_h) 
  484. 		 
  485. 		if ico_h ~= 0 then 
  486. 			local swatch_highlight_h = vint_object_clone(ico_h) 
  487. 			local swatch_depth = vint_get_property(ico_h, "depth") 
  488. 			vint_set_property(swatch_highlight_h, "depth", swatch_depth - 1) 
  489. 			vint_set_property(swatch_highlight_h, "render_mode", "additive_alpha") 
  490. 			 
  491. 			local swatch_highlight_anim_h = vint_object_clone(vint_object_find("menu_swatch_icon_pulse_anim"), root_anim) 
  492. 			local twn_h = vint_object_find("icon_highlight_alpha_twn_1", swatch_highlight_anim_h) 
  493. 			vint_set_property(twn_h, "target_handle", swatch_highlight_h) 
  494. 			vint_set_property(twn_h, "target_property", "alpha") 
  495. 			vint_set_property(twn_h, "state", 1) 
  496. 			lua_play_anim(swatch_highlight_anim_h, 0) 
  497. 			 
  498. 			menu_data.swatch_highlight_h = swatch_highlight_h 
  499. 			menu_data.swatch_highlight_anim_h = swatch_highlight_anim_h 
  500. 		end 
  501. 	end 
  502. 	 
  503. 	-- update footer text 
  504. 	if swatches[new_idx].label_crc ~= nil then 
  505. 		vint_set_property(menu_data.footer_txt_h, "text_tag_crc", swatches[new_idx].label_crc) 
  506. 	elseif swatches[new_idx].label_str ~= nil then 
  507. 		vint_set_property(menu_data.footer_txt_h, "text_tag", swatches[new_idx].label_str) 
  508. 	else 
  509. 		vint_set_property(menu_data.footer_txt_h, "text_tag", "") 
  510. 	end 
  511. 	 
  512. 	menu_data.cur_row = new_row 
  513. 	menu_data.cur_col = new_col 
  514. 	menu_data.cur_idx = new_idx 
  515. 	menu_data.prev_idx = cur_idx 
  516. 	 
  517. 	if menu_data.on_enter ~= nil then 
  518. 			menu_data.on_enter(swatches[new_idx]) 
  519. 	end 
  520. end 
  521.  
  522. function menu_grid_nav_left(menu_label, menu_data) 
  523. 	local swatches = menu_data.swatches 
  524. 	local col = menu_data.cur_col 
  525. 	if col == 0 then 
  526. 		col = menu_data.num_cols - 1 
  527. 	else 
  528. 		col = col - 1 
  529. 	end 
  530.  
  531. 	if menu_data.cur_row * menu_data.num_cols + col >= swatches.num_swatches then 
  532. 		col = swatches.num_swatches - 1 - (menu_data.num_cols * (menu_data.total_rows - 1)) 
  533. 	end 
  534.  
  535. 	menu_grid_update_highlighted(menu_data, col, menu_data.cur_row) 
  536. 	audio_play(Menu_sound_value_nav) 
  537.  
  538. 	if menu_data.on_nav ~= nil then 
  539. 		menu_data.on_nav(menu_label, menu_data) 
  540. 	end 
  541. end 
  542.  
  543. function menu_grid_nav_right(menu_label, menu_data) 
  544. 	local swatches = menu_data.swatches 
  545. 	local col = menu_data.cur_col 
  546. 	if col == menu_data.num_cols - 1 then 
  547. 		col = 0 
  548. 	else 
  549. 		col = col + 1 
  550. 	end 
  551.  
  552. 	if menu_data.cur_row * menu_data.num_cols + col >= swatches.num_swatches then 
  553. 		col = 0 
  554. 	end 
  555.  
  556. 	menu_grid_update_highlighted(menu_data, col, menu_data.cur_row) 
  557. 	audio_play(Menu_sound_value_nav) 
  558.  
  559. 	if menu_data.on_nav ~= nil then 
  560. 		menu_data.on_nav(menu_label, menu_data) 
  561. 	end 
  562. end 
  563.  
  564. function menu_grid_nav_up(menu_label, menu_data) 
  565. 	local swatches = menu_data.swatches 
  566. 	local row = menu_data.cur_row 
  567. 	if row == 0 then 
  568. 		row = menu_data.total_rows - 1 
  569. 	else 
  570. 		row = row - 1 
  571. 	end 
  572.  
  573. 	if row * menu_data.num_cols + menu_data.cur_col >= swatches.num_swatches then 
  574. 		row = menu_data.total_rows - 2 
  575. 	end 
  576.  
  577. 	menu_grid_update_swatches(menu_data, row) 
  578. 	menu_grid_update_highlighted(menu_data, menu_data.cur_col, row) 
  579. 	audio_play(Menu_sound_item_nav) 
  580. 	if menu_data.on_nav ~= nil then 
  581. 		menu_data.on_nav(menu_label, menu_data) 
  582. 	end 
  583. end 
  584.  
  585. function menu_grid_nav_down(menu_label, menu_data) 
  586. 	local swatches = menu_data.swatches 
  587. 	local row = menu_data.cur_row 
  588. 	if row == menu_data.total_rows - 1 then 
  589. 		row = 0 
  590. 	else 
  591. 		row = row + 1 
  592. 	end 
  593.  
  594. 	if row * menu_data.num_cols + menu_data.cur_col >= swatches.num_swatches then 
  595. 		row = 0 
  596. 	end 
  597.  
  598. 	menu_grid_update_swatches(menu_data, row) 
  599. 	menu_grid_update_highlighted(menu_data, menu_data.cur_col, row) 
  600. 	audio_play(Menu_sound_item_nav) 
  601.  
  602. 	if menu_data.on_nav ~= nil then 
  603. 		menu_data.on_nav(menu_label, menu_data) 
  604. 	end 
  605. end 
  606.  
  607. function menu_grid_get_width(menu_data) 
  608. 	local w = menu_data.col_width * menu_data.num_cols 
  609. 	if menu_data.scroll_bar_visible == true then 
  610. 		w = w + 25 
  611. 	end 
  612. 	return w - 1 
  613. end 
  614.  
  615. function menu_grid_get_height(menu_data) 
  616. 	return menu_data.row_height * menu_data.visible_rows 
  617. end 
  618.  
  619. function menu_grid_release(menu_data) 
  620. 	local swatches = menu_data.swatches 
  621.  
  622. 	for i = 0, swatches.num_swatches - 1 do 
  623. 		if swatches[i].swatch_h ~= nil then 
  624. 			vint_object_destroy(swatches[i].swatch_h) 
  625. 			swatches[i].swatch_h = nil 
  626. 		end 
  627. 	end 
  628. 	 
  629. 	--Destroy highlights 
  630. 	if menu_data.swatch_highlight_h  ~= nil then 
  631. 		vint_object_destroy(menu_data.swatch_highlight_h) 
  632. 	end 
  633. 	if menu_data.swatch_highlight_anim_h ~= nil then 
  634. 		vint_object_destroy(menu_data.swatch_highlight_anim_h) 
  635. 	end 
  636. 	 
  637. 	for key, value in menu_data.swatches.swatch_bin do 
  638. 		vint_object_destroy(key) 
  639. 	end 
  640.  
  641. 	menu_data.swatches = nil 
  642.  
  643. 	vint_object_destroy(menu_data.arrow_grp) 
  644. 	 
  645. 	local footer = menu_data.footer 
  646. 	 
  647. 	if footer ~= nil and footer.footer_grp ~= nil then 
  648. 		vint_object_destroy(footer.footer_grp) 
  649. 	end 
  650.  
  651. 	menu_data.arrow_grp = nil 
  652. 	menu_data.footer = nil 
  653. 	menu_data.cur_idx = nil 
  654. end 
  655.  
  656. function menu_grid_show(menu_data, menu_item, master_swatch_h, do_not_animate) 
  657. 	 
  658. 	if master_swatch_h == nil then 
  659. 		master_swatch_h = vint_object_find("swatch_general", nil, MENU_BASE_DOC_HANDLE) 
  660. 		menu_item.custom_swatch = false 
  661. 	else 
  662. 		menu_item.custom_swatch = true 
  663. 	end 
  664.  
  665. 	if do_not_animate == true then 
  666. 		--No animations for this swatch 
  667. 		menu_item.pulse_swatch = false 
  668. 	else 
  669. 		--Do the pulsing animation by default 
  670. 		menu_item.pulse_swatch = true 
  671. 	end 
  672. 	 
  673. 	local swatches = menu_item.swatches 
  674. 	swatches.swatch_bin = { } 
  675. 	local swatch_bin = swatches.swatch_bin 
  676. 		 
  677. 	if menu_data.max_height == nil then 
  678. 		menu_data.max_height = MENU_MAX_MENU_H 
  679. 	end 
  680.  
  681. 	local max_rows = floor(menu_data.max_height / menu_item.row_height) 
  682. 	local total_rows = swatches.num_swatches / menu_item.num_cols 
  683.  
  684. 	if floor(total_rows) ~= total_rows then 
  685. 		total_rows = floor(total_rows) + 1 
  686. 	end 
  687.  
  688. 	local visible_rows = total_rows 
  689. 	if visible_rows > max_rows then 
  690. 		visible_rows = max_rows 
  691. 	end 
  692.  
  693. 	if menu_item.cur_idx ~= nil then 
  694. 		menu_item.cur_row = floor(menu_item.cur_idx / menu_item.num_cols) 
  695. 		menu_item.cur_col = menu_item.cur_idx - (menu_item.cur_row * menu_item.num_cols) 
  696. 		menu_item.cur_idx = nil 
  697. 	else 
  698. 		menu_item.cur_row = 0 
  699. 		menu_item.cur_col = 0 
  700. 	end 
  701.  
  702. 	menu_item.first_vis_row = -1 
  703. 	menu_item.visible_rows = visible_rows 
  704. 	menu_item.total_rows = total_rows 
  705.  
  706. 	-- offset used in a couple of places 
  707. 	local offset_h = 21 
  708. 	 
  709. 	--[[	this use of Menu_active seemed suspicious so i replaced it with below 2008.05.30 SDR 
  710. 	local offset_v = 60 + menu_item.row_height * 0.5 
  711. 	if Menu_active ~= 0 then 
  712. 		offset_v =  Menu_active.header_height + menu_item.row_height * 0.5 
  713. 	end ]] 
  714. 	 
  715. 	local offset_v = menu_data.header_height + menu_item.row_height * 0.5 
  716. 	 
  717. 	menu_item.offset_h = offset_h 
  718. 	menu_item.offset_v = offset_v 
  719.  
  720. 	-- build up the swatch objects 
  721. 	local max_swatches = visible_rows * menu_item.num_cols 
  722.  
  723. 	if max_swatches > swatches.num_swatches then 
  724. 		max_swatches = swatches.num_swatches 
  725. 	end 
  726.  
  727. 	local swatch_id 
  728. 	local parent_h = Menu_option_labels.control_parent 
  729. 	for i = 0, max_swatches - 1 do 
  730. 		swatch_id = vint_object_clone(master_swatch_h, parent_h) 
  731. 		swatch_bin[swatch_id] = true 
  732. 	end  
  733.  
  734. 	-- set up arrows 
  735. 	local arrow_grp_orig = vint_object_find("swatch_arrows", nil, MENU_BASE_DOC_HANDLE) 
  736. 	local arrow_grp = vint_object_clone(arrow_grp_orig, parent_h) 
  737. 	local arrow = vint_object_find("swatch_arrow_n", arrow_grp) 
  738. 	menu_item.arrow_n_h = arrow 
  739. 	local offset_x = (menu_item.col_width * 0.5) * menu_item.highlight_scale + 20 
  740. 	local offset_y = (menu_item.row_height * 0.5) * menu_item.highlight_scale + 20 
  741. 	vint_set_property(arrow, "anchor", 0, -offset_y) 
  742. 	arrow = vint_object_find("swatch_arrow_s", arrow_grp) 
  743. 	menu_item.arrow_s_h = arrow 
  744. 	vint_set_property(arrow, "anchor", 0, offset_y) 
  745. 	arrow = vint_object_find("swatch_arrow_e", arrow_grp) 
  746. 	menu_item.arrow_e_h = arrow 
  747. 	vint_set_property(arrow, "anchor", offset_x, 0) 
  748. 	arrow = vint_object_find("swatch_arrow_w", arrow_grp) 
  749. 	menu_item.arrow_w_h = arrow 
  750. 	vint_set_property(arrow, "anchor", -offset_x, 0) 
  751. 	menu_item.arrow_grp = arrow_grp 
  752. 	 
  753. 	--Retarget arrow animations 
  754. 	local arrow_anim_h = vint_object_find("menu_swatch_arrows_pulse_anim") 
  755. 	vint_set_property(arrow_anim_h, "target_handle", arrow_grp )	 
  756. 	lua_play_anim(arrow_anim_h, 0) 
  757. 	 
  758. 	vint_set_property(arrow_grp, "visible", menu_item.hide_arrows ~= true) 
  759. 	 
  760. 	--Footer 
  761. 	-- eliminate old footer if it exists 
  762. 	local footer = menu_data.footer 
  763. 	if footer ~= nil and footer.footer_grp ~= nil then 
  764. 		vint_object_destroy(footer.footer_grp) 
  765. 	end 
  766. 	 
  767. 	local width = menu_item.col_width * menu_item.num_cols  
  768. 	local footer_grp = vint_object_clone(vint_object_find("swatch_footer", nil, MENU_BASE_DOC_HANDLE), parent_h) 
  769. 	menu_data.footer = { } 
  770. 	menu_data.footer.footer_grp = footer_grp 
  771. 	menu_item.footer_txt_h = vint_object_find("text", footer_grp) 
  772. 		 
  773. 	if menu_data.footer_height == 0 and menu_data.footer ~= nil then 
  774. 		vint_set_property(menu_data.footer.footer_grp, "visible", 0) 
  775. 	else 
  776. 		--Reset footer visibility 
  777. 		vint_set_property(menu_data.footer.footer_grp, "visible", true) 
  778. 	end 
  779.  
  780. 	-- might need a scroll bar 
  781. 	if visible_rows < total_rows then 
  782. 		local menu = Menu_option_labels.frame 
  783. 		local bar_height = visible_rows * menu_item.row_height + 12 
  784. 		menu_scroll_bar_show(menu) 
  785. 		menu_scroll_bar_set_bar_height(bar_height) 
  786. 		menu_scroll_bar_set_thumb_size((visible_rows / total_rows)) 
  787. 		menu_scroll_bar_set_pos(width + 22, Menu_active.header_height) 
  788. 		menu_item.scroll_bar_visible = true 
  789. 	else 
  790. 		menu_scroll_bar_hide() 
  791. 		menu_item.scroll_bar_visible = false 
  792. 	end 
  793.  
  794. 	menu_grid_update_swatches(menu_item, 0) 
  795. 	menu_grid_update_highlighted(menu_item, menu_item.cur_col, menu_item.cur_row) 
  796. end 
  797.  
  798. function menu_horz_init(menu_data) 
  799. 	Menu_horz_active = menu_data 
  800. 	local item 
  801.  
  802. 	if menu_data.current_selection == nil or menu_data.current_selection >= menu_data.num_items then 
  803. 		menu_data.current_selection = 0 
  804. 	end 
  805.  
  806. 	if Menu_horz_label_clip_x == 0 or Menu_horz_label_clip_y == 0 then 
  807. 		local label_clip_h = vint_object_find("horz_label_clip", nil, MENU_BASE_DOC_HANDLE) 
  808. 		Menu_horz_label_clip_x, Menu_horz_label_clip_y = vint_get_property(label_clip_h, "anchor") 
  809. 	end 
  810.  
  811. 	--Need to unhide the horz menu and button tips 
  812. 	local h = vint_object_find("menu_horz", nil, MENU_BASE_DOC_HANDLE) 
  813. 	vint_set_property(h, "visible", true) 
  814. 	 
  815. 	local h = vint_object_find("menu_tips", nil, MENU_BASE_DOC_HANDLE) 
  816. 	vint_set_property(h, "visible", true) 
  817. 	 
  818. 	--The original that if the current selection is zero then we need to do something differenct. 
  819. 	if menu_data.current_selection ~= 0 then 
  820. 		menu_data.previous_selection = 0 
  821. 	end 
  822. 	 
  823. 	local master_label_h = vint_object_find("menu_horz_label0", nil, MENU_BASE_DOC_HANDLE) 
  824. 	Menu_horz_active[0].label_h = master_label_h 
  825. 	 
  826. 	if Menu_horz_active[0].label_crc ~= nil then 
  827. 		vint_set_property(master_label_h, "text_tag_crc", Menu_horz_active[0].label_crc) 
  828. 	else 
  829. 		vint_set_property(master_label_h, "text_tag", Menu_horz_active[0].label) 
  830. 	end 
  831. 	 
  832. 	-- show the second label if more than one item 
  833. 	master_label_h = vint_object_find("menu_horz_label1", nil, MENU_BASE_DOC_HANDLE) 
  834. 	if Menu_horz_active.num_items > 1 then 
  835. 		Menu_horz_active[1].label_h = master_label_h 
  836. 		vint_set_property(master_label_h, "visible", true) 
  837.  
  838. 		if Menu_horz_active[1].label_crc ~= nil then 
  839. 			vint_set_property(master_label_h, "text_tag_crc", Menu_horz_active[1].label_crc) 
  840. 		else 
  841. 			vint_set_property(master_label_h, "text_tag", Menu_horz_active[1].label) 
  842. 		end 
  843. 		 
  844. 		-- Set the button images 
  845. 		local h = vint_object_find("upper_nav_trigger_right", nil, MENU_BASE_DOC_HANDLE) 
  846. 		vint_set_property(h, "image", get_rt_button()) 
  847. 		vint_set_property(h, "visible", true) 
  848. 		h = vint_object_find("upper_nav_trigger_right_hl", nil, MENU_BASE_DOC_HANDLE) 
  849. 		vint_set_property(h, "image", get_rt_button()) 
  850. 		vint_set_property(h, "visible", true) 
  851. 		h = vint_object_find("upper_nav_trigger_left", nil, MENU_BASE_DOC_HANDLE) 
  852. 		vint_set_property(h, "image", get_lt_button()) 
  853. 		vint_set_property(h, "visible", true) 
  854. 		h = vint_object_find("upper_nav_trigger_left_hl", nil, MENU_BASE_DOC_HANDLE) 
  855. 		vint_set_property(h, "image", get_lt_button()) 
  856. 		vint_set_property(h, "visible", true) 
  857. 		local label_clip_h = vint_object_find("horz_label_clip", nil, MENU_BASE_DOC_HANDLE) 
  858. 		vint_set_property(label_clip_h, "anchor", Menu_horz_label_clip_x, Menu_horz_label_clip_y) 
  859. 	else 
  860. 		--Reformat heading if there is only one item 
  861. 		vint_set_property(master_label_h, "visible", false) 
  862. 		 
  863. 		--No button images should be displayed 
  864. 		local h = vint_object_find("upper_nav_trigger_right", nil, MENU_BASE_DOC_HANDLE) 
  865. 		vint_set_property(h, "visible", false) 
  866. 		h = vint_object_find("upper_nav_trigger_right_hl", nil, MENU_BASE_DOC_HANDLE) 
  867. 		vint_set_property(h, "visible", false) 
  868. 		h = vint_object_find("upper_nav_trigger_left", nil, MENU_BASE_DOC_HANDLE) 
  869. 		vint_set_property(h, "visible", false) 
  870. 		h = vint_object_find("upper_nav_trigger_left_hl", nil, MENU_BASE_DOC_HANDLE) 
  871. 		vint_set_property(h, "visible", false) 
  872. 		local label_clip_h = vint_object_find("horz_label_clip", nil, MENU_BASE_DOC_HANDLE) 
  873. 		vint_set_property(label_clip_h, "anchor", Menu_horz_label_clip_x - 84, Menu_horz_label_clip_y) 
  874. 	end 
  875. 	 
  876. 	if Menu_horz_active.num_items > 2 then 
  877. 		-- create new labels 
  878. 		local copy_label_h 
  879. 		for i = 2, Menu_horz_active.num_items - 1 do 
  880. 			copy_label_h = vint_object_clone(master_label_h) 
  881. 			Menu_horz_active[i].label_h = copy_label_h 
  882.  
  883. 			if Menu_horz_active[i].label_crc ~= nil then 
  884. 				vint_set_property(copy_label_h, "text_tag_crc", Menu_horz_active[i].label_crc) 
  885. 			else 
  886. 				vint_set_property(copy_label_h, "text_tag", Menu_horz_active[i].label) 
  887. 			end 
  888. 		end 
  889. 	end 
  890. 	 
  891. 	 
  892.  
  893. 	-- store the scale and color of highlighted and highlighted 
  894. 	Menu_horz_active.hl_item = { scale = {}, tint = {} } 
  895. 	Menu_horz_active.norm_item = { scale = {}, tint = {} } 
  896. 	local hl = Menu_horz_active.hl_item 
  897. 	local norm = Menu_horz_active.norm_item 
  898.  
  899. 	hl.scale.x, hl.scale.y = vint_get_property(Menu_horz_active[0].label_h, "scale") 
  900. 	hl.tint.r, hl.tint.g, hl.tint.b = vint_get_property(Menu_horz_active[0].label_h, "tint") 
  901.  
  902. 	if Menu_horz_active.num_items > 1 then 
  903. 		norm.scale.x, norm.scale.y = vint_get_property(Menu_horz_active[1].label_h, "scale") 
  904. 		norm.tint.r, norm.tint.g, norm.tint.b = vint_get_property(Menu_horz_active[1].label_h, "tint") 
  905. 	end 
  906. 	 
  907. 	--	initialize button tips 
  908. 	btn_tips_init() 
  909. 	 
  910. 	menu_show(Menu_horz_active[Menu_horz_active.current_selection].sub_menu, MENU_TRANSITION_NONE) 
  911. 	 
  912. 	menu_horz_animate_label_pos() 
  913. 	 
  914. 	--Play menu opening animation 
  915. 	menu_trans_in_animation() 
  916.  
  917. 	-- input subscriptions 
  918. 	local subs_h = vint_subscribe_to_input_event(Menu_horz_active[0].label_h, "scroll_left", "menu_horz_nav") 
  919. 	Menu_input_subscriptions[subs_h] = subs_h 
  920. 	subs_h = vint_subscribe_to_input_event(Menu_horz_active[0].label_h, "scroll_right", "menu_horz_nav") 
  921. 	Menu_input_subscriptions[subs_h] = subs_h 
  922.  
  923. 	--Even tracking 
  924. 	local horz_item = Menu_horz_active[Menu_horz_active.current_selection] 
  925. 	if horz_item.label_crc ~= nil then 
  926. 		event_tracking_interface_tab_change_string(horz_item.label_crc) 
  927. 	else 
  928. 		event_tracking_interface_tab_change_string(horz_item.label) 
  929. 	end 
  930. 	 
  931. end 
  932.  
  933. function menu_horz_close(complete_cb) 
  934. end 
  935.  
  936. function menu_horz_update_scrolling() 
  937. 	local total_width = 0 
  938. 	local label_widths = { } 
  939. 	local label_w_pos = { } 
  940. 	local label_e_pos = { } 
  941. 	local clip_w = vint_get_property(vint_object_find("horz_label_clip", nil, MENU_BASE_DOC_HANDLE), "clip_size") 
  942. 	local sel_index = Menu_horz_active.current_selection 
  943. 	local orig_scale = { } 
  944. 	 
  945. 	-- determine the total width of the controls and position of each label 
  946. 	for i = 0, Menu_horz_active.num_items - 1 do 
  947. 		-- reset scale to baseline for maths 
  948. 		local item = Menu_horz_active[i] 
  949. 		orig_scale.x, orig_scale.y = vint_get_property(item.label_h, "scale") 
  950. 		vint_set_property(item.label_h, "scale", 0.4, 0.4) 
  951. 	 
  952. 		local w = element_get_actual_size(item.label_h) 
  953. 		 
  954. 		if i == sel_index then 
  955. 			w = w * 1.25		-- current selection should be scaled up 
  956. 		end 
  957. 		 
  958. 		label_widths[i] = w 
  959. 		label_w_pos[i] = total_width 
  960. 		total_width = total_width + w + 15 
  961. 		label_e_pos[i] = total_width 
  962.  
  963. 		-- restore scale 
  964. 		vint_set_property(item.label_h, "scale", orig_scale.x, orig_scale.y) 
  965. 	end 
  966. 	 
  967. 	-- are we narrow enough to not disable scrolling? 
  968. 	local scrolling = (total_width > clip_w) 
  969.  
  970. 	vint_set_property(vint_object_find("horz_arrow_e", nil, MENU_BASE_DOC_HANDLE), "visible", scrolling) 
  971. 	vint_set_property(vint_object_find("horz_arrow_w", nil, MENU_BASE_DOC_HANDLE), "visible", scrolling) 
  972. 	 
  973. 	if scrolling == false then 
  974. 		vint_set_property(vint_object_find("horz_label_grp", nil, MENU_BASE_DOC_HANDLE), "anchor", 0, 0) 
  975. 		return 
  976. 	end 
  977.  
  978. 	local anchor_x = 0 
  979. 	 
  980. 	-- if the selected label is far enough to the right we are right bound 
  981. 	if label_w_pos[sel_index] > total_width - clip_w then 
  982. 		anchor_x = -(total_width - clip_w) 
  983. 	elseif sel_index > 0 then 
  984. 		anchor_x = -(label_w_pos[sel_index - 1]) 
  985. 	end 
  986. 	 
  987. 	-- build the tween and let it rip 
  988. 	local tween_h = vint_object_find("horz_label_grp_anchor_twn_1", nil, MENU_BASE_DOC_HANDLE) 
  989. 	vint_set_property(tween_h, "start_value", vint_get_property(vint_object_find("horz_label_grp", nil, MENU_BASE_DOC_HANDLE), "anchor")) 
  990. 	vint_set_property(tween_h, "end_value", anchor_x, 0) 
  991. 	lua_play_anim(vint_object_find("horz_label_grp_anim_1", nil, MENU_BASE_DOC_HANDLE)) 
  992. end 
  993.  
  994. function menu_horz_nav(target_h, event_name) 
  995. 	if Menu_horz_active == 0 or menu_input_is_blocked() == true then 
  996. 		return 
  997. 	end 
  998. 	 
  999. 	--No naving allowed if there is only one item(JMH July 03, 2008) 
  1000. 	if Menu_horz_active.num_items == 1 then 
  1001. 		return 
  1002. 	end 
  1003. 	 
  1004. 	local previous = Menu_horz_active.current_selection 
  1005. 	local current = 0 
  1006. 	if event_name == "scroll_left" then 
  1007. 	 
  1008. 		Menu_horz_active.trans_animation = "menu_horz_lt_anim" 
  1009. 		current = Menu_horz_active.current_selection - 1 
  1010.  
  1011. 		if current < 0 then 
  1012. 			current = Menu_horz_active.num_items - 1 
  1013. 		end 
  1014. 	elseif event_name == "scroll_right" then 
  1015.  
  1016. 		Menu_horz_active.trans_animation = "menu_horz_rt_anim" 
  1017. 		current = Menu_horz_active.current_selection + 1 
  1018.  
  1019. 		if current >= Menu_horz_active.num_items then 
  1020. 			current = 0 
  1021. 		end 
  1022. 	else 
  1023. 		return 
  1024. 	end 
  1025. 	lua_play_anim(vint_object_find(Menu_horz_active.trans_animation, nil, MENU_BASE_DOC_HANDLE), 0, MENU_BASE_DOC_HANDLE) 
  1026. 	 
  1027. 	if Menu_active.on_horz_show ~= nil then 
  1028. 		Menu_active.on_horz_show(current) 
  1029. 	else 
  1030. 	 
  1031. 		audio_play(Menu_sound_scroll) 
  1032. 		Menu_horz_active.previous_selection = previous 
  1033. 		Menu_horz_active.current_selection = current 
  1034. 		 
  1035. 		if Menu_horz_active.on_nav ~= nil then 
  1036. 			Menu_horz_active.on_nav(Menu_horz_active[Menu_horz_active.current_selection].sub_menu) 
  1037. 		end 
  1038.  
  1039. 		--Morph Horz Menu Items 
  1040. 		menu_horz_animate_label_pos() 
  1041. 		Menu_horz_active[Menu_horz_active.current_selection].sub_menu.highlighted_item = 0 
  1042. 		menu_show(Menu_horz_active[Menu_horz_active.current_selection].sub_menu, MENU_TRANSITION_SWAP) 
  1043. 	end 
  1044. 	 
  1045. 	--Publish data to the event tracking system 
  1046. 	local horz_item = Menu_horz_active[Menu_horz_active.current_selection] 
  1047. 	if horz_item.label_crc ~= nil then 
  1048. 		event_tracking_interface_tab_change_string(horz_item.label_crc) 
  1049. 	else 
  1050. 		event_tracking_interface_tab_change_string(horz_item.label) 
  1051. 	end 
  1052. end 
  1053.  
  1054. --Used by the pause menu for special swapping functionality. 
  1055. function menu_horz_do_nav(index) 
  1056. 	Menu_horz_active.previous_selection = Menu_horz_active.current_selection 
  1057. 	Menu_horz_active.current_selection = index 
  1058. 	audio_play(Menu_sound_scroll) 
  1059. 	--Morph Horz Menu Items 
  1060. 	menu_horz_animate_label_pos() 
  1061. end 
  1062.  
  1063. function menu_horz_animate_label_pos() 
  1064. 	local cur_x, cur_y = vint_get_property(Menu_horz_active[0].label_h, "anchor") 
  1065. 	local hl = Menu_horz_active.hl_item 
  1066. 	local norm = Menu_horz_active.norm_item 
  1067. 	local item 
  1068. 	 
  1069. 	menu_horz_update_scrolling() 
  1070. 	 
  1071. 	for i = 0,Menu_horz_active.num_items - 1 do 
  1072. 		item = Menu_horz_active[i] 
  1073. 		if i == Menu_horz_active.current_selection then 
  1074. 			--Animate text scale up 
  1075. 			local anim_up = vint_object_find("menu_horz_up_anim", nil, MENU_BASE_DOC_HANDLE) 
  1076.  
  1077. 			--Scale Tween 
  1078. 			local twn = vint_object_find("menu_horz_up_twn_1", anim_up) 
  1079. 			vint_set_property(twn, "target_handle", item.label_h) 
  1080. 			vint_set_property(twn, "state", "waiting") 
  1081. 			vint_set_property(twn, "end_event", "menu_horz_update_end") 
  1082. 			 
  1083. 			--Color Tween 
  1084. 			twn = vint_object_find("menu_horz_up_twn_2", anim_up) 
  1085. 			vint_set_property(twn, "target_handle", item.label_h) 
  1086. 			vint_set_property(twn, "state", "waiting") 
  1087.  
  1088. 			lua_play_anim(anim_up, 0, MENU_BASE_DOC_HANDLE) 
  1089. 			 
  1090. 		elseif i == Menu_horz_active.previous_selection then  
  1091. 			--Animate text scale down 
  1092. 			--Retarget Tween 
  1093. 			local anim_down = vint_object_find("menu_horz_dn_anim", nil, MENU_BASE_DOC_HANDLE) 
  1094. 			local twn = vint_object_find("menu_horz_dn_twn_1", anim_down) 
  1095. 			 
  1096. 			--Scale Tween 
  1097. 			vint_set_property(twn, "target_handle", item.label_h) 
  1098. 			vint_set_property(twn, "state", "waiting") 
  1099. 			vint_set_property(twn, "end_event", "menu_horz_update_end") 
  1100. 			 
  1101. 			--Color Tween 
  1102. 			twn = vint_object_find("menu_horz_dn_twn_2", anim_down) 
  1103. 			vint_set_property(twn, "target_handle", item.label_h) 
  1104. 			vint_set_property(twn, "state", "waiting") 
  1105. 			lua_play_anim(anim_down, 0, MENU_BASE_DOC_HANDLE) 
  1106. 			 
  1107. 		else 
  1108. 			--Anything left over should snap to the original size 
  1109. 			vint_set_property(item.label_h, "tint", norm.tint.r, norm.tint.g, norm.tint.b) 
  1110. 			vint_set_property(item.label_h, "scale", norm.scale.x, norm.scale.y) 
  1111. 		end 
  1112. 	end 
  1113. 	 
  1114. 	if Menu_horz_update_label_thread == -1 then  
  1115. 		Menu_horz_update_label_thread = thread_new("menu_horz_update_labels") 
  1116. 	end 
  1117. end 
  1118.  
  1119. --Updates horizontal menu options on a perframe basis 
  1120. function menu_horz_update_labels() 
  1121. 	while true do 
  1122. 		menu_horz_align_labels() 
  1123. 		thread_yield() 
  1124. 	end 
  1125. end 
  1126.  
  1127. function menu_horz_align_labels() 
  1128. 	local cur_x, cur_y = vint_get_property(Menu_horz_active[0].label_h, "anchor") 
  1129. 	local item, w 
  1130.  
  1131. 	for i = 0, Menu_horz_active.num_items - 1 do 
  1132. 		item = Menu_horz_active[i] 
  1133. 		vint_set_property(item.label_h, "anchor", cur_x, cur_y) 
  1134. 		w = element_get_actual_size(item.label_h) 
  1135. 		cur_x = cur_x + 15 + w 
  1136. 	end 
  1137. end 
  1138.  
  1139. function menu_horz_update_end() 
  1140. 	if Menu_horz_update_label_thread ~= -1 then 
  1141. 		menu_horz_align_labels() 
  1142. 		thread_kill(Menu_horz_update_label_thread) 
  1143. 		Menu_horz_update_label_thread = -1 
  1144. 	end 
  1145. end 
  1146.  
  1147. function menu_scroll_bar_init(option_labels, bar_grp) 
  1148. 	-- menu_h is the handle to the parent menu for the scroll bar 
  1149. 	if bar_grp == nil then 
  1150. 		bar_grp = vint_object_find("menu_scroll_bar", option_labels.frame) 
  1151. 	end 
  1152.  
  1153. 	vint_set_property(bar_grp, "visible", false) 
  1154. 	 
  1155. 	local scroll_data = { 
  1156. 		visible =			false, 
  1157. 		bar_grp =			bar_grp, 
  1158. 		bg_n_h =				vint_object_find("menu_scroll_bg_n", bar_grp), 
  1159. 		bg_c_h =				vint_object_find("menu_scroll_bg_c", bar_grp), 
  1160. 		bg_s_h =				vint_object_find("menu_scroll_bg_s", bar_grp), 
  1161. 		thumb_n_h =			vint_object_find("menu_scroll_thumb_n", bar_grp), 
  1162. 		thumb_s_h =			vint_object_find("menu_scroll_thumb_s", bar_grp), 
  1163. 		thumb_blend_h =	vint_object_find("menu_scroll_thumb_blend", bar_grp), 
  1164. 		thumb_pos =			0, 
  1165. 		bar_height =		332, 
  1166. 		thumb_height =		332, 
  1167. 	} 
  1168.  
  1169. 	option_labels.scroll_bar = scroll_data 
  1170. end 
  1171.  
  1172. function menu_scroll_bar_update(scroll_data) 
  1173. 	if scroll_data.visible == false then 
  1174. 		return 
  1175. 	end 
  1176.  
  1177. 	-- update the thumb pos 
  1178. 	local thumb_offset = scroll_data.thumb_pos * (scroll_data.bar_height - scroll_data.thumb_height) + 10  
  1179. 	thumb_offset = floor(thumb_offset) 
  1180.  
  1181. 	vint_set_property(scroll_data.thumb_n_h,		"anchor", 3, thumb_offset) 
  1182. 	vint_set_property(scroll_data.thumb_s_h,		"anchor", 3, thumb_offset + scroll_data.thumb_height - 20) --Magic Number represents the offset from the thumb height 
  1183. 	vint_set_property(scroll_data.thumb_blend_h,	"anchor", 3, thumb_offset + scroll_data.thumb_height - 63) --Magic Number represents the offset from the thumb height 
  1184. end 
  1185.  
  1186. function menu_scroll_bar_show() 
  1187. 	local scroll_data = Menu_option_labels.scroll_bar 
  1188. 	vint_set_property(scroll_data.bar_grp, "visible", true) 
  1189. 	scroll_data.visible = true 
  1190. end 
  1191.  
  1192. function menu_scroll_bar_set_pos(x, y) 
  1193. 	vint_set_property(Menu_option_labels.scroll_bar.bar_grp, "anchor", x, y) 
  1194. end 
  1195.  
  1196. function menu_scroll_bar_set_bar_height(new_height) 
  1197. 	local scroll_data = Menu_option_labels.scroll_bar 
  1198. 	scroll_data.bar_height = new_height - 54 --This magic number will allow you to change the base height of the scrollbar 
  1199.  
  1200. 	vint_set_property(scroll_data.bg_s_h, "anchor", 38, new_height - 10) 
  1201. 	vint_set_property(scroll_data.bg_c_h, "source_se", 10, new_height - 28) 
  1202.  
  1203. 	menu_scroll_bar_update(scroll_data) 
  1204. end 
  1205.  
  1206. function menu_scroll_bar_set_thumb_size(height) 
  1207. 	local scroll_data = Menu_option_labels.scroll_bar 
  1208. 	scroll_data.thumb_height = floor(height * scroll_data.bar_height) 
  1209. 	 
  1210. 	if scroll_data.thumb_height < 60 then 
  1211. 		scroll_data.thumb_height = 60 
  1212. 	end 
  1213. 	 
  1214. 	vint_set_property(scroll_data.thumb_n_h, "source_se", 32, scroll_data.thumb_height - 20) 
  1215. 	menu_scroll_bar_update(scroll_data) 
  1216. end 
  1217.  
  1218. function menu_scroll_bar_set_thumb_pos(value) 
  1219. 	local scroll_data = Menu_option_labels.scroll_bar 
  1220. 	if scroll_data.thumb_pos ~= value then 
  1221. 		scroll_data.thumb_pos = value 
  1222. 		menu_scroll_bar_update(scroll_data) 
  1223. 	end 
  1224. end 
  1225.  
  1226. function menu_scroll_bar_hide() 
  1227. 	local scroll_data = Menu_option_labels.scroll_bar 
  1228. 	vint_set_property(scroll_data.bar_grp, "visible", false) 
  1229. 	scroll_data.visible = false 
  1230. end 
  1231.  
  1232. function menu_set_custom_control_callbacks(custom_callbacks) 
  1233. 	for key, val in custom_callbacks do 
  1234. 		Menu_control_callbacks[key] = val 
  1235. 	end 
  1236. end 
  1237.  
  1238. function menu_init() 
  1239. 	vint_init_general_audio() 
  1240.  
  1241. 	if Menu_use_hud == false then 
  1242. 		Menu_hud_hidden = true; 
  1243. 		hud_hide(true) 
  1244. 	end 
  1245.  
  1246. 	if Menu_option_labels.frame ~= nil then 
  1247. 		vint_object_destroy(Menu_option_labels.frame) 
  1248. 	end 
  1249. 	 
  1250. 	if Menu_option_labels_inactive.frame ~= nil then 
  1251. 		vint_object_destroy(Menu_option_labels_inactive.frame) 
  1252. 	end 
  1253. 	 
  1254. 	-- build the initial active label list 
  1255. 	local active_frame = vint_object_find("menu", nil, MENU_BASE_DOC_HANDLE) 
  1256. 	 
  1257. 	Menu_active_anchor_end_x, Menu_active_anchor_end_y = vint_get_property(active_frame, "anchor") 
  1258.  
  1259. 	active_frame = vint_object_clone(active_frame, vint_object_find("safe_frame")) 
  1260. 	Menu_option_labels.frame = active_frame 
  1261. 	local clip_h = vint_object_find("marquee_clip", active_frame) 
  1262. 	 
  1263. 	local label_h = vint_object_find("menu_option_label00", active_frame) 
  1264. 	local stripe_h = vint_object_find("menu_stripe00", active_frame) 
  1265. 	Menu_option_labels[0] = { label_h = label_h, stripe_h = stripe_h } 
  1266. 	Menu_option_labels.clip_h = clip_h 
  1267. 	Menu_option_labels.hl_bar = vint_object_find("menu_sel_bar", active_frame) 
  1268. 	Menu_option_labels.hl_clip = vint_object_find("marquee_clip_sel_bar", active_frame) 
  1269. 	Menu_option_labels.control_parent = vint_object_find("transition_clip", active_frame) 
  1270. 	vint_set_property(active_frame, "visible", false) 
  1271.  
  1272. 	--Reset Scaler for menu internals 
  1273. 	local frame_scale_x, frame_scale_y = vint_get_property(active_frame, "scale") 
  1274. 	Menu_scaler = 1/frame_scale_x 
  1275. 	 
  1276. 	-- build the initial inactive label list 
  1277. 	local inactive_frame = vint_object_clone(active_frame) 
  1278. 	Menu_option_labels_inactive.frame = inactive_frame 
  1279. 	local clip2_h   = vint_object_find("marquee_clip", inactive_frame) 
  1280. 		 
  1281. 	local label2_h  = vint_object_find("menu_option_label00", inactive_frame) 
  1282. 	local stripe2_h = vint_object_find("menu_stripe00", inactive_frame) 
  1283. 	Menu_option_labels_inactive[0] = { label_h =label2_h, stripe_h = stripe2_h } 
  1284. 	Menu_option_labels_inactive.clip_h = clip2_h 
  1285. 	Menu_option_labels_inactive.hl_bar = vint_object_find("menu_sel_bar", inactive_frame) 
  1286. 	Menu_option_labels_inactive.hl_clip = vint_object_find("marquee_clip_sel_bar", inactive_frame) 
  1287. 	Menu_option_labels_inactive.control_parent = vint_object_find("transition_clip", inactive_frame) 
  1288. 	vint_set_property(inactive_frame, "visible", false) 
  1289.  
  1290. 	-- pause all menu animations 
  1291. 	menu_init_anims() 
  1292. 	 
  1293. 	menu_scroll_bar_init(Menu_option_labels) 
  1294. 	menu_scroll_bar_init(Menu_option_labels_inactive) 
  1295. 	 
  1296. 	menu_grab_input() 
  1297. end 
  1298.  
  1299. function menu_grab_input() 
  1300. 	-- subscribe to input 
  1301. 	local subs_h = vint_subscribe_to_input_event(nil, "nav_up", "menu_nav") 
  1302. 	Menu_input_subscriptions[subs_h] = subs_h 
  1303. 	subs_h = vint_subscribe_to_input_event(nil, "nav_down", "menu_nav") 
  1304. 	Menu_input_subscriptions[subs_h] = subs_h 
  1305. 	subs_h = vint_subscribe_to_input_event(nil, "nav_right", "menu_nav") 
  1306. 	Menu_input_subscriptions[subs_h] = subs_h 
  1307. 	subs_h = vint_subscribe_to_input_event(nil, "nav_left", "menu_nav") 
  1308. 	Menu_input_subscriptions[subs_h] = subs_h 
  1309. 	subs_h = vint_subscribe_to_input_event(nil, "select", "menu_nav") 
  1310. 	Menu_input_subscriptions[subs_h] = subs_h 
  1311. 	subs_h = vint_subscribe_to_input_event(nil, "back", "menu_nav") 
  1312. 	Menu_input_subscriptions[subs_h] = subs_h 
  1313. 	subs_h = vint_subscribe_to_input_event(nil, "map", "menu_nav") 
  1314. 	Menu_input_subscriptions[subs_h] = subs_h 
  1315. 	subs_h = vint_subscribe_to_input_event(nil, "pause", "menu_nav") 
  1316. 	Menu_input_subscriptions[subs_h] = subs_h 
  1317. 	subs_h = vint_subscribe_to_input_event(nil, "alt_select", "menu_nav") 
  1318. 	Menu_input_subscriptions[subs_h] = subs_h 
  1319. 	subs_h = vint_subscribe_to_input_event(nil, "exit", "menu_nav") 
  1320. 	Menu_input_subscriptions[subs_h] = subs_h 
  1321.  
  1322. 	if Menu_horz_active ~= 0 then 
  1323. 		subs_h = vint_subscribe_to_input_event(Menu_horz_active[0].label_h, "scroll_left", "menu_horz_nav") 
  1324. 		Menu_input_subscriptions[subs_h] = subs_h 
  1325. 		subs_h = vint_subscribe_to_input_event(Menu_horz_active[0].label_h, "scroll_right", "menu_horz_nav") 
  1326. 		Menu_input_subscriptions[subs_h] = subs_h 
  1327. 	end 
  1328. end 
  1329.  
  1330. function menu_trans_in_tweens_kill() 
  1331. 	for idx, val in Menu_trans_in_twns  do 
  1332. 		vint_object_destroy(val, nil) 
  1333. 	end 
  1334. 	 
  1335. 	Menu_trans_in_twns = {} 
  1336. 	vint_set_property(vint_object_find("menu_trans_in", nil, MENU_BASE_DOC_HANDLE), "is_paused", true) 
  1337. 	 
  1338. 	menu_input_block(false) 
  1339. end 
  1340.  
  1341. function menu_trans_out_tweens_kill() 
  1342. 	for idx, val in Menu_trans_out_twns  do 
  1343. 		vint_object_destroy(val, nil) 
  1344. 	end 
  1345. 	 
  1346. 	--TODO: PUT SOMETHING HERE THAT TURNS OFF ALL THE LIGHTS IF Menu_fade_to_black IS TRUE!! - JHG 
  1347. 	 
  1348. 	Menu_trans_out_twns = {} 
  1349. 		 
  1350. 	-- destroy the extra item labels, leaving the two master items 
  1351. 	for i = 2, Menu_horz_active.num_items - 1 do 
  1352. 		vint_object_destroy(Menu_horz_active[i].label_h, MENU_BASE_DOC_HANDLE) 
  1353. 		Menu_horz_active[i].label_h = nil 
  1354. 	end 
  1355. 	 
  1356. 	--Reset horizontal menu item stems 
  1357. 	local i = Menu_horz_active.hl_item 
  1358. 	vint_set_property(Menu_horz_active[0].label_h, "scale", i.scale.x, i.scale.y) 
  1359. 	vint_set_property(Menu_horz_active[0].label_h, "tint", i.tint.r, i.tint.g, i.tint.b) 
  1360.  
  1361. 	if Menu_horz_active.num_items > 1 then 
  1362. 		i = Menu_horz_active.norm_item 
  1363. 		vint_set_property(Menu_horz_active[1].label_h, "scale", i.scale.x, i.scale.y) 
  1364. 		vint_set_property(Menu_horz_active[1].label_h, "tint", i.tint.r, i.tint.g, i.tint.b) 
  1365. 	end 
  1366. 	 
  1367. 	menu_close_finalize() 
  1368. end 
  1369.  
  1370. function menu_trans_in_animation() 
  1371. 	--Find intro animation 
  1372. 	local intro_anim = vint_object_find("menu_trans_in", nil, MENU_BASE_DOC_HANDLE) 
  1373.  
  1374. 	--Hide first two horizontal menu items 
  1375. 	vint_set_property(Menu_horz_active[0].label_h, "alpha", 0) 
  1376. 	 
  1377. 	if Menu_horz_active.num_items > 1 then 
  1378. 		vint_set_property(Menu_horz_active[1].label_h, "alpha", 0) 
  1379. 	end 
  1380. 	 
  1381. 	--Duplicate tweens and stagger time for other menu items 
  1382. 	local twn_h = vint_object_find("menu_horz_label1_alpha_twn_2", intro_anim, MENU_BASE_DOC_HANDLE) 
  1383. 	local start_time = vint_get_property(twn_h, "start_time") 
  1384. 	local duration = vint_get_property(twn_h, "duration") 
  1385. 	 
  1386. 	--Tweens for horizontal labels 
  1387. 	local twn_clone_h 
  1388. 	for i = 2, Menu_horz_active.num_items - 1 do 
  1389. 		local label_h = Menu_horz_active[i].label_h 
  1390. 		twn_clone_h = vint_object_clone(twn_h) 
  1391. 		start_time = start_time + .03 
  1392. 		vint_set_property(twn_clone_h, "start_time", start_time)  
  1393. 		vint_set_property(twn_clone_h, "target_handle", label_h) 
  1394. 		vint_set_property(label_h, "alpha", 0) 
  1395. 		Menu_trans_in_twns[twn_clone_h] = twn_clone_h 
  1396. 	end 
  1397. 	 
  1398. 	--Find out whats longer the last btn text alpha tween or the btn_tips and base our tween callback on that. 
  1399. 	local btn_tip_twn_h = vint_object_find("menu_btn_tip_ext_00_alpha_twn_1", intro_anim) 
  1400. 	local tab_twn_time = duration + start_time 
  1401. 	local btn_tip_twn_time = vint_get_property(btn_tip_twn_h, "duration") + vint_get_property(btn_tip_twn_h, "start_time") 
  1402. 	 
  1403. 	if btn_tip_twn_time > tab_twn_time or twn_clone_h == nil then 
  1404. 		vint_set_property(btn_tip_twn_h, "end_event", "menu_trans_in_tweens_kill")	 
  1405. 	else 
  1406. 		vint_set_property(twn_clone_h, "end_event", "menu_trans_in_tweens_kill")		 
  1407. 	end 
  1408. 	lua_play_anim(intro_anim, 0, MENU_BASE_DOC_HANDLE) 
  1409.  
  1410. 	--Slide in menu 
  1411. 	local twn = vint_object_create("menu_in_twn_1", "tween", vint_object_find("root_animation")) 
  1412.  
  1413. 	local frame_x, frame_y =  vint_get_property(Menu_option_labels.frame, "anchor") 
  1414. 	 
  1415. 	vint_set_property(twn, "target_handle",  Menu_option_labels.frame) 
  1416. 	vint_set_property(twn, "target_property",  "anchor") 
  1417. 	local x, y = vint_get_property(Menu_option_labels.frame, "anchor") 
  1418. 	vint_set_property(twn, "start_value", 0 - Menu_active.menu_width - 100, frame_y) 
  1419. 	vint_set_property(twn, "end_value", x, y) 
  1420. 	vint_set_property(twn, "start_time", vint_get_time_index()) 
  1421. 	vint_set_property(twn, "duration", 0.2) 
  1422. 	Menu_trans_out_twns[twn] = twn 
  1423. 	 
  1424. 	menu_input_block(true) 
  1425. 	audio_play(Menu_sound_open) 
  1426. end 
  1427.  
  1428. function menu_release_input() 
  1429. 	for index, value in Menu_input_subscriptions do 
  1430. 		vint_unsubscribe_to_input_event(index) 
  1431. 	end 
  1432. end 
  1433.  
  1434. function menu_trans_out_animation() 
  1435.  
  1436. 	local exit_anim 
  1437.  
  1438. 	if Menu_fade_to_black then 
  1439. 		exit_anim = vint_object_find("black_fade_out", nil, MENU_BASE_DOC_HANDLE) 
  1440. 		 
  1441. 		vint_set_property(vint_object_find("black_fade_alpha", exit_anim), "end_event", "menu_trans_out_tweens_kill") 
  1442. 		lua_play_anim(exit_anim, 0, MENU_BASE_DOC_HANDLE) 
  1443. 	else 
  1444. 		exit_anim = vint_object_find("menu_trans_out", nil, MENU_BASE_DOC_HANDLE) 
  1445.  
  1446. 		--Duplicate tweens and stagger time for other menu items 
  1447. 		local twn_h = vint_object_find("menu_horz_label1_alpha_twn_2", exit_anim, MENU_BASE_DOC_HANDLE) 
  1448. 		local start_time = vint_get_property(twn_h, "start_time") 
  1449. 		 
  1450. 		local duration_twn_h = vint_object_find("horz_clip_offset_twn_1", exit_anim, MENU_BASE_DOC_HANDLE) 
  1451. 		local duration = vint_get_property(duration_twn_h, "duration") 
  1452. 		duration = (duration/2)/Menu_horz_active.num_items 
  1453. 		 
  1454. 		for i = 2, Menu_horz_active.num_items - 1 do 
  1455. 			local label_h = Menu_horz_active[i].label_h 
  1456. 			local twn_clone_h = vint_object_clone(twn_h) 
  1457. 			start_time = start_time + duration 
  1458. 			vint_set_property(twn_clone_h, "start_time", start_time)  
  1459. 			vint_set_property(twn_clone_h, "target_handle", label_h) 
  1460. 			vint_set_property(twn_clone_h, "duration", duration) 
  1461. 			vint_set_property(label_h, "alpha", 1) 
  1462. 			Menu_trans_out_twns[twn_clone_h] = twn_clone_h 
  1463. 		end 
  1464.  
  1465. 		--Callback to kill tweens 
  1466. 		vint_set_property(vint_object_find("menu_btn_tip_ext_00_alpha_twn_2", exit_anim), "end_event", "menu_trans_out_tweens_kill")	 
  1467. 		lua_play_anim(exit_anim, 0, MENU_BASE_DOC_HANDLE) 
  1468. 	end 
  1469. 	 
  1470. 	--Slide out menu 
  1471. 	local twn = vint_object_create("menu_out_twn_1", "tween", vint_object_find("root_animation")) 
  1472.  
  1473. 	vint_set_property(twn, "target_handle",  Menu_option_labels.frame) 
  1474. 	vint_set_property(twn, "target_property",  "anchor") 
  1475. 	local x, y = vint_get_property(Menu_option_labels.frame, "anchor") 
  1476. 	vint_set_property(twn, "start_value", x, y) 
  1477. 	vint_set_property(twn, "end_value", 0 - Menu_active.menu_width - 100, y) 
  1478. 	vint_set_property(twn, "start_time", vint_get_time_index()) 
  1479. 	vint_set_property(twn, "duration", 0.2) 
  1480. 	Menu_trans_out_twns[twn] = twn 
  1481. 	 
  1482. 	audio_play(Menu_sound_close) 
  1483. 	 
  1484. end 
  1485.  
  1486. function menu_close(complete_cb) 
  1487. 	-- currently all closing goodness is handled by menu_horz_close() 
  1488. 	-- this may not be adequate since not all menus will use the horz menu 
  1489. 	-- like food 
  1490. 	if complete_cb ~= nil then 
  1491. 		Menu_close_cb = complete_cb 
  1492. 	else 
  1493. 		Menu_close_cb = 0 
  1494. 	end 
  1495. 	 
  1496. 	menu_input_block(true) 
  1497.  
  1498. 	--Hide style cluster 
  1499. 	if Style_cluster_enabled == true then 
  1500. 		local cash_trans_out = vint_object_find("cash_trans_out", nil, MENU_BASE_DOC_HANDLE) 
  1501. 		lua_play_anim(cash_trans_out, 0) 
  1502. 	end 
  1503. 	 
  1504. 	--JMT for some reason the transition out isn't happening on coop start, so skip it 
  1505. 	if Menu_horz_active ~= nil and Menu_horz_active ~= 0 and is_coop_start_screen() == false then 
  1506. 		menu_trans_out_animation() 
  1507. 	else 
  1508. 		-- shouldn't we transition something out? 
  1509. 		menu_close_finalize() 
  1510. 	end 
  1511. 	 
  1512.  
  1513. end 
  1514.  
  1515. function menu_close_finalize() 
  1516. 	menu_input_block(false) 
  1517. 	menu_release_input() 
  1518.  
  1519. 	if Menu_use_hud == false then 
  1520. 		hud_hide(false) 
  1521. 		Menu_hud_hidden = false; 
  1522. 	end 
  1523. 	 
  1524. 	if Menu_close_cb ~= 0 then 
  1525. 		Menu_close_cb() 
  1526. 	end 
  1527. end 
  1528.  
  1529. function menu_anim_clone_and_pause(name, parent, pause) 
  1530. 	local h = vint_object_find(name, nil, MENU_BASE_DOC_HANDLE) 
  1531. 	h = vint_object_clone(h, parent) 
  1532. 	 
  1533. 	if pause ~= false then 
  1534. 		vint_set_property(h, "is_paused", true) 
  1535. 	end 
  1536. 	 
  1537. 	return h 
  1538. end 
  1539.  
  1540. function menu_init_anims() 
  1541. 	local r = vint_object_find("root_animation") 
  1542. 	 
  1543. 	for idx, val in Menu_anims do	--	Clear out old menu animations 
  1544. 		vint_object_destroy(val) 
  1545. 	end 
  1546. 	 
  1547. 	Menu_anims[0] = menu_anim_clone_and_pause("menu_item_hl_pulse_anim", r, false) 
  1548. 	Menu_anims[1] = menu_anim_clone_and_pause("menu_num_slider_in_anim", r) 
  1549. 	Menu_anims[2] = menu_anim_clone_and_pause("menu_num_slider_pulse_anim", r, false) 
  1550. 	Menu_anims[3] = menu_anim_clone_and_pause("menu_option_label_in_anim", r) 
  1551. 	Menu_anims[4] = menu_anim_clone_and_pause("menu_option_label_out_anim", r) 
  1552. 	Menu_anims[5] = menu_anim_clone_and_pause("menu_sel_bar_fade_in_anim", r) 
  1553. 	Menu_anims[6] = menu_anim_clone_and_pause("menu_sel_bar_fade_out_anim", r) 
  1554. 	Menu_anims[7] = menu_anim_clone_and_pause("menu_swatch_arrows_pulse_anim", r) 
  1555. 	Menu_anims[8] = menu_anim_clone_and_pause("menu_swatch_in_anim", r) 
  1556. 	Menu_anims[9] = menu_anim_clone_and_pause("menu_swatch_icon_select_anim", r) 
  1557. 	Menu_anims[10] = menu_anim_clone_and_pause("menu_swatch_icon_pulse_anim", r) 
  1558. 	Menu_anims[11] = menu_anim_clone_and_pause("menu_text_slider_pulse_anim", r) 
  1559. end 
  1560.  
  1561. function menu_input_block(block) 
  1562. 	if block == true then 
  1563. 		Menu_input_blocked = Menu_input_blocked + 1 
  1564. 	elseif Menu_input_blocked > 0 then 
  1565. 		--don't go below 0 
  1566. 		Menu_input_blocked = Menu_input_blocked - 1 
  1567. 	end 
  1568. end 
  1569.  
  1570. function menu_input_is_blocked() 
  1571. 	return Menu_input_blocked > 0 
  1572. end 
  1573.  
  1574. function menu_nav(target, event, accelleration) 
  1575. 	if menu_input_is_blocked() == true or Menu_active == 0 then 
  1576. 		return 
  1577. 	end 
  1578. 	 
  1579. 	btn_tips_update() 
  1580. 	local item_type = 0 
  1581. 	if Menu_active.num_items > 0 then 
  1582. 		item_type = Menu_active[Menu_active.highlighted_item].type 
  1583. 		Menu_input_accelleration = accelleration 
  1584. 	end 
  1585.  
  1586. 	if event == "nav_up" then 
  1587. 		if Menu_control_callbacks[item_type].on_nav_up ~= nil then 
  1588. 			local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1589. 			Menu_control_callbacks[item_type].on_nav_up(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1590. 		else 
  1591. 			if Menu_active.num_items > 1 then 
  1592. 				local new_item = Menu_active.highlighted_item - 1 
  1593. 			 
  1594. 				if new_item < 0 then 
  1595. 					new_item = Menu_active.num_items - 1 
  1596. 				end 
  1597. 				 
  1598. 				-- skip disabled 
  1599. 				while Menu_active[new_item].disabled == true and new_item ~= Menu_active.highlighted_item do 
  1600. 					new_item = new_item - 1 
  1601. 					 
  1602. 					if new_item < 0 then 
  1603. 						new_item = Menu_active.num_items - 1 
  1604. 					end 
  1605. 				end 
  1606.  
  1607. 				menu_update_nav_bar(new_item) 
  1608. 				audio_play(Menu_sound_item_nav) 
  1609. 				 
  1610. 				if Menu_active.on_nav ~= nil then 
  1611. 					Menu_active.on_nav(Menu_active) 
  1612. 				end 
  1613. 			end 
  1614. 		end 
  1615. 	elseif event == "nav_down" then 
  1616. 		if Menu_control_callbacks[item_type].on_nav_down ~= nil then 
  1617. 			local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1618. 			Menu_control_callbacks[item_type].on_nav_down(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1619. 		else 
  1620. 			if Menu_active.num_items > 1 then 
  1621. 				local new_item = Menu_active.highlighted_item + 1 
  1622.  
  1623. 				if new_item >= Menu_active.num_items then 
  1624. 					new_item = 0 
  1625. 				end 
  1626. 				 
  1627. 				-- skip disabled 
  1628. 				while Menu_active[new_item].disabled == true and new_item ~= Menu_active.highlighted_item do 
  1629. 					new_item = new_item + 1 
  1630. 					 
  1631. 					if new_item >= Menu_active.num_items then 
  1632. 						new_item = 0 
  1633. 					end 
  1634. 				end 
  1635.  
  1636. 				menu_update_nav_bar(new_item) 
  1637. 				audio_play(Menu_sound_item_nav) 
  1638.  
  1639. 				if Menu_active.on_nav ~= nil then 
  1640. 					Menu_active.on_nav(Menu_active) 
  1641. 				end 
  1642. 			end 
  1643. 		end 
  1644.  
  1645. 	elseif event == "select" then 
  1646. 		if Menu_control_callbacks[item_type].on_select ~= nil then 
  1647. 			local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1648. 			Menu_control_callbacks[item_type].on_select(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1649. 			audio_play(Menu_sound_select) 
  1650. 			 
  1651. 		elseif Menu_active.on_select ~= nil then 
  1652. 			local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1653. 			Menu_active.on_select(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1654. 			audio_play(Menu_sound_select) 
  1655. 		end 
  1656.  
  1657. 	elseif event == "back" then 
  1658. 	 
  1659. 		if Menu_active.on_back ~= nil then 
  1660. 			audio_play(Menu_sound_back) 
  1661. 			Menu_active.on_back(Menu_active) 
  1662. 		elseif Menu_active.parent_menu ~= nil then 
  1663. 			audio_play(Menu_sound_back) 
  1664. 			menu_show(Menu_active.parent_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  1665. 		end 
  1666.  
  1667. 	elseif event == "nav_right" then 
  1668. 		if Menu_control_callbacks[item_type].on_nav_right ~= nil then 
  1669. 			local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1670. 			Menu_control_callbacks[item_type].on_nav_right(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1671. 		end 
  1672.  
  1673. 	elseif event == "nav_left" then 
  1674. 		if Menu_control_callbacks[item_type].on_nav_left ~= nil then 
  1675. 			local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1676. 			Menu_control_callbacks[item_type].on_nav_left(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1677. 		end 
  1678. 		 
  1679. 	elseif event == "alt_select" then 
  1680. 		if Menu_control_callbacks[item_type].on_alt_select ~= nil then 
  1681. 			-- control gets first stab at event 
  1682. 			local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1683. 			Menu_control_callbacks[item_type].on_alt_select(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1684. 			 
  1685. 		elseif Menu_active.on_alt_select ~= nil then 
  1686. 			-- fallback to menu 
  1687. 			local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1688. 			Menu_active.on_alt_select(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1689. 		end 
  1690. 	elseif event == "pause" then 
  1691. 		if Menu_active.on_pause ~= nil then 
  1692. 			Menu_active.on_pause(Menu_active) 
  1693. 		elseif vint_document_find("main_menu") ~= 0 then 
  1694. 			-- same as select above 
  1695. 			if Menu_control_callbacks[item_type].on_select ~= nil then 
  1696. 				local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1697. 				Menu_control_callbacks[item_type].on_select(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1698. 				audio_play(Menu_sound_select) 
  1699. 				 
  1700. 			elseif Menu_active.on_select ~= nil then 
  1701. 				local menu_option = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  1702. 				Menu_active.on_select(menu_option, Menu_active[Menu_active.highlighted_item]) 
  1703. 				audio_play(Menu_sound_select) 
  1704. 			end 
  1705. 		else 
  1706. 			--	Call regular pause  
  1707. 			dialog_open_pause_display() 
  1708. 		end 
  1709. 	elseif event == "map" then 
  1710. 		if Menu_active.on_map ~= nil then 
  1711. 			Menu_active.on_map(Menu_active) 
  1712. 		end 
  1713. 	elseif event == "exit" then 
  1714. 		--	Call Menu_active.on_exit ? 
  1715. 	end 
  1716.  
  1717. end 
  1718.  
  1719. function menu_transition_complete() 
  1720. 	for index, value in Menu_transition_data.tweens do 
  1721. 		vint_object_destroy(index) 
  1722. 	end 
  1723.  
  1724. 	-- release all the controls on the inactive menu 
  1725. 	if Menu_option_labels_inactive.max_rows ~= nil then 
  1726. 		for i = 0, Menu_option_labels_inactive.max_rows - 1 do 
  1727. 			if Menu_option_labels_inactive[i].control ~= nil then 
  1728. 				menu_release_control(Menu_option_labels_inactive[i].control) 
  1729. 				Menu_option_labels_inactive[i].control = nil 
  1730. 			end 
  1731. 		end 
  1732. 	end 
  1733. 	 
  1734. 	if Menu_inactive ~= 0 then 
  1735. 		if Menu_inactive.on_release ~= nil then 
  1736. 			Menu_inactive.on_release(Menu_inactive) 
  1737. 		end 
  1738.  
  1739. 		-- release footer 
  1740. 		if Menu_inactive.footer ~= nil then 
  1741. 			vint_object_destroy(Menu_inactive.footer.footer_grp) 
  1742. 			vint_object_destroy(Menu_inactive.footer.hr_h) 
  1743. 			Menu_inactive.footer = nil 
  1744. 		end 
  1745. 		 
  1746. 		--Reset size parameters 
  1747. 		Menu_inactive.header_width = nil 
  1748. 		Menu_inactive.width = 0 
  1749. 		Menu_inactive.height = 0 
  1750. 	end 
  1751.  
  1752. 	 
  1753. 	 
  1754. 	--Reset Scrollbar 
  1755. 	Menu_option_labels_inactive.scroll_bar_visible = false 
  1756. 	 
  1757. 	vint_set_property(Menu_option_labels_inactive.frame, "visible", false) 
  1758.  
  1759. 	if Menu_active ~= 0 and Menu_active.custom_show ~= true then 
  1760. 		vint_set_property(Menu_option_labels.frame, "visible", true) 
  1761. 	else 
  1762. 		vint_set_property(Menu_option_labels.frame, "visible", false) 
  1763. 	end 
  1764. 	 
  1765. 	if Menu_active ~= 0 then 
  1766. 		vint_set_property(Menu_option_labels.frame, "anchor", menu_get_transition_end(Menu_active)) 
  1767. 	end 
  1768.  
  1769. 	Menu_transition_data = { tweens = { } } 
  1770. 	menu_input_block(false) 
  1771. 	Menu_transition_in_progress = false 
  1772. 	 
  1773. 	if Menu_hide_active_pending == true then 
  1774. 		menu_hide_active() 
  1775. 		Menu_hide_active_pending = false 
  1776. 	end 
  1777. end 
  1778.  
  1779. function menu_create_tween(name, target_h, target_prop, duration) 
  1780. 	local tween_h = vint_object_create(name, "tween", vint_object_find("root_animation")) 
  1781. 	 
  1782. 	vint_set_property(tween_h, "duration", duration) 
  1783. 	vint_set_property(tween_h, "target_handle", target_h) 
  1784. 	vint_set_property(tween_h, "algorithm", "linear") 
  1785. 	vint_set_property(tween_h, "target_property", target_prop) 
  1786. 	vint_set_property(tween_h, "start_time",	vint_get_time_index()) 
  1787. 	vint_set_property(tween_h, "is_paused", false) 
  1788. 	return tween_h 
  1789. end 
  1790.  
  1791. function menu_transition_swap_stage2(tween_h) 
  1792. 	vint_set_property(Menu_option_labels_inactive.frame, "visible", false) 
  1793. 	 
  1794. 	if Menu_active ~= 0 then 
  1795. 		local end_x, end_y = menu_get_transition_end(Menu_active) 
  1796. 		local start_x = 0 - Menu_active.menu_width - 30 
  1797. 		vint_set_property(tween_h, "target_handle", Menu_option_labels.frame) 
  1798. 		vint_set_property(Menu_option_labels.frame, "anchor", start_x, end_y) 
  1799. 		vint_set_property(tween_h, "start_value", start_x, end_y) 
  1800. 		vint_set_property(tween_h, "end_value", end_x, end_y) 
  1801. 		vint_set_property(tween_h, "start_time",	vint_get_time_index()) 
  1802. 		vint_set_property(tween_h, "is_paused", false) 
  1803. 		vint_set_property(tween_h, "end_event", "menu_transition_complete") 
  1804. 		vint_set_property(tween_h, "state", "waiting") 
  1805. 		if Menu_active.custom_show == true then 
  1806. 			vint_set_property(Menu_option_labels.frame, "visible", false) 
  1807. 		else 
  1808. 			vint_set_property(Menu_option_labels.frame, "visible", true) 
  1809. 		end 
  1810. 	else 
  1811. 		vint_set_property(Menu_option_labels.frame, "visible", false) 
  1812. 		menu_transition_complete() 
  1813. 	end 
  1814. end 
  1815.  
  1816. function menu_get_transition_end(menu_data) 
  1817. 	local end_x, end_y 
  1818. 	if Menu_swap_center == true then 
  1819. 		end_x = Menu_active_anchor_end_x - (menu_data.menu_width * 0.5 * (1 / Menu_scaler)) 
  1820. 		end_y = Menu_active_anchor_end_y - (menu_data.menu_height * 0.5 * (1 / Menu_scaler)) 
  1821. 	else 
  1822. 		end_x = Menu_active_anchor_end_x 
  1823. 		end_y = Menu_active_anchor_end_y 
  1824. 	end 
  1825. 	return end_x, end_y 
  1826. end 
  1827.  
  1828. function menu_transition_swap_begin() 
  1829. 	menu_input_block(true) 
  1830. 	Menu_transition_in_progress = true 
  1831. 	vint_set_property(Menu_option_labels.frame, "visible", false) 
  1832. 	local tween_h = menu_create_tween("menu_transition1", Menu_option_labels_inactive.frame, "anchor", 0.1) 
  1833. 	Menu_transition_data.tweens[tween_h] = true 
  1834.  
  1835. 	if Menu_inactive ~= 0 then 
  1836. 		local end_x, end_y = menu_get_transition_end(Menu_inactive) 
  1837. 		vint_set_property(tween_h, "start_value", end_x, end_y) 
  1838. 		vint_set_property(tween_h, "end_value", 0 - Menu_inactive.menu_width - 30, end_y) 
  1839. 		vint_set_property(tween_h, "end_event", "menu_transition_swap_stage2") 
  1840. 	 
  1841. 		if Menu_inactive.custom_show == true then 
  1842. 			vint_set_property(Menu_option_labels_inactive.frame, "visible", false) 
  1843. 		else 
  1844. 			vint_set_property(Menu_option_labels_inactive.frame, "visible", true) 
  1845. 		end 
  1846. 	else 
  1847. 		vint_set_property(Menu_option_labels_inactive.frame, "visible", false) 
  1848. 		menu_transition_swap_stage2(tween_h) 
  1849. 	end 
  1850. end 
  1851.  
  1852. function menu_transition_sweep_end() 
  1853.  
  1854. 	local h = vint_object_find("menu_bg",	Menu_option_labels.frame) 
  1855. 	vint_set_property(h, "visible", true) 
  1856. 	 
  1857. 	h = vint_object_find("menu_bg", Menu_option_labels_inactive.frame) 
  1858. 	vint_set_property(h, "anchor", 0, 0) 
  1859. 	 
  1860. 	h = vint_object_find("menu_fg", Menu_option_labels.frame) 
  1861. 	vint_set_property(h, "visible", true) 
  1862. 	 
  1863. 	h = vint_object_find("menu_fg", Menu_option_labels_inactive.frame) 
  1864. 	vint_set_property(h, "anchor", 0, 0) 
  1865. 	 
  1866. 	h = vint_object_find("transition_clip", Menu_option_labels_inactive.frame) 
  1867. 	vint_set_property(h, "clip_enabled", false) 
  1868.  
  1869. 	h = vint_object_find("transition_clip", Menu_option_labels.frame) 
  1870. 	vint_set_property(h, "clip_enabled", false) 
  1871. 	 
  1872. 	h = vint_object_find("menu_frame_middle", Menu_option_labels_inactive.frame) 
  1873. 	vint_set_property(h, "visible", true) 
  1874. 	 
  1875. 	vint_object_destroy(Menu_transition_data.backdrop_clone) 
  1876.  
  1877. 	menu_transition_complete() 
  1878. end 
  1879.  
  1880. function menu_transition_sweep_begin(sweep_left) 
  1881. 	if Menu_inactive ~= 0 then 
  1882. 		Menu_transition_in_progress = true 
  1883. 		menu_input_block(true) 
  1884. 		local duration = .15 
  1885. 		local option_active, menu_active, option_inactive, menu_inactive 
  1886. 		local t1, t2 
  1887. 		 
  1888. 			option_active = Menu_option_labels 
  1889. 			menu_active = Menu_active 
  1890. 			option_inactive = Menu_option_labels_inactive 
  1891. 			menu_inactive = Menu_inactive 
  1892. 			 
  1893. 		local end_x, end_y = menu_get_transition_end(Menu_active) 
  1894. 		local start_x, start_y = menu_get_transition_end(Menu_inactive) 
  1895. 		 
  1896. 		-- sweep in new menu 
  1897. 		local tween_h = menu_create_tween("menu_transition1", option_active.frame, "anchor", duration) 
  1898. 		Menu_transition_data.tweens[tween_h] = true 
  1899. 		 
  1900. 		if sweep_left == true then 
  1901. 			t1 = start_x + menu_inactive.menu_width / Menu_scaler 
  1902. 		else 
  1903. 			t1 = start_x - menu_inactive.menu_width / Menu_scaler 
  1904. 		end 
  1905.  
  1906. 		vint_set_property(tween_h, "start_value", t1, start_y) 
  1907. 		vint_set_property(tween_h, "end_value", end_x, end_y) 
  1908. 		vint_set_property(tween_h, "end_event", "menu_transition_sweep_end") 
  1909.  
  1910. 		-- reuse old menu's frame so reverse sweep it so it appears stationary 
  1911. 		local h = vint_object_find("menu_bg", option_inactive.frame) 
  1912. 		tween_h = menu_create_tween("menu_transition2", h, "anchor", duration) 
  1913. 		Menu_transition_data.tweens[tween_h] = true 
  1914. 		 
  1915. 		if sweep_left == true then 
  1916. 			t1 = menu_inactive.menu_width 
  1917. 		else 
  1918. 			t1 = -menu_inactive.menu_width 
  1919. 		end 
  1920. 		 
  1921. 		vint_set_property(tween_h, "start_value", 0, 0) 
  1922. 		vint_set_property(tween_h, "end_value", t1, 0) 
  1923. 		 
  1924. 		--Clone background frame tween on the foreground frame 
  1925. 		h = vint_object_find("menu_fg", option_inactive.frame) 
  1926. 		tween_h = vint_object_clone(tween_h) 
  1927. 		vint_set_property(tween_h, "target_handle", h) 
  1928. 		Menu_transition_data.tweens[tween_h] = true 
  1929. 		 
  1930. 		-- sweep out old menu 
  1931. 		tween_h = menu_create_tween("menu_transition3", option_inactive.frame, "anchor", duration) 
  1932. 		Menu_transition_data.tweens[tween_h] = true 
  1933. 		 
  1934. 		if sweep_left == true then 
  1935. 			t1 = start_x - menu_inactive.menu_width / Menu_scaler 
  1936. 			t2 = end_x - menu_inactive.menu_width / Menu_scaler 
  1937. 		else 
  1938. 			t1 = start_x + menu_inactive.menu_width / Menu_scaler 
  1939. 			t2 = end_x + menu_inactive.menu_width / Menu_scaler 
  1940. 		end 
  1941. 		 
  1942. 		vint_set_property(tween_h, "start_value",  start_x, start_y) 
  1943. 		vint_set_property(tween_h, "end_value", t2, end_y) 
  1944.  
  1945. 		-- hide new menu's frame 
  1946. 		h = vint_object_find("menu_bg", option_active.frame) 
  1947. 		vint_set_property(h, "visible", false) 
  1948. 		h = vint_object_find("menu_fg", option_active.frame) 
  1949. 		vint_set_property(h, "visible", false) 
  1950. 		 
  1951. 		-- these tweens handle the resizing 
  1952. 		 
  1953. 		-- Resize backdrop 
  1954. 		 
  1955. 		-- so that the gray backdrop is below both menus, clone the inactive's backdrop 
  1956. 		-- and hide the original. it will need to be unhidden after transition is complete 
  1957. 		local orig_h = vint_object_find("menu_frame_middle", option_inactive.frame) 
  1958.  
  1959. 		h = vint_object_clone(orig_h, vint_object_find("safe_frame")) 
  1960. 		Menu_transition_data.backdrop_clone = h 
  1961. 		--vint_set_property(h, "anchor", start_x + (17*Menu_scaler), start_y + (12*Menu_scaler)) 
  1962. 		vint_set_property(h, "anchor", start_x , start_y ) 
  1963. 	 
  1964. 		-- set original as hidden after we clone it 
  1965. 		vint_set_property(orig_h, "visible", false) 
  1966.  
  1967. 		-- animate the scale on phony backdrop 
  1968. 		tween_h = menu_create_tween("menu_transition4", h, "scale", duration) 
  1969. 		Menu_transition_data.tweens[tween_h] = true 
  1970. 		vint_set_property(tween_h, "start_value", option_inactive.trim_c_scale_x / Menu_scaler, option_inactive.trim_c_scale_y / Menu_scaler) 
  1971. 		vint_set_property(tween_h, "end_value", option_active.trim_c_scale_x / Menu_scaler, option_active.trim_c_scale_y / Menu_scaler) 
  1972. 		 
  1973. 		-- animate the anchor on phony backdrop 
  1974. 		tween_h = menu_create_tween("menu_transition4", h, "anchor", duration) 
  1975. 		Menu_transition_data.tweens[tween_h] = true 
  1976. 		vint_set_property(tween_h, "start_value", start_x + (17 /Menu_scaler), start_y + (12/Menu_scaler)) 
  1977. 		vint_set_property(tween_h, "end_value", end_x + (17/Menu_scaler), end_y + (12/Menu_scaler)) 
  1978.  
  1979. 		-- move and resize the bottom trim 
  1980. 		h = vint_object_find("menu_mid_trm_btm_line_img", option_inactive.frame) 
  1981. 		tween_h = menu_create_tween("menu_transition5", h, "anchor", duration) 
  1982. 		Menu_transition_data.tweens[tween_h] = true 
  1983. 		vint_set_property(tween_h, "start_value", option_inactive.trim_s_pos_x, option_inactive.trim_s_pos_y) 
  1984. 		vint_set_property(tween_h, "end_value", option_active.trim_s_pos_x, option_active.trim_s_pos_y) 
  1985.  
  1986. 		tween_h = menu_create_tween("menu_transition6", h, "source_se", duration) 
  1987. 		Menu_transition_data.tweens[tween_h] = true 
  1988. 		vint_set_property(tween_h, "start_value", option_inactive.trim_s_src_w, option_inactive.trim_s_src_h) 
  1989. 		vint_set_property(tween_h, "end_value", option_active.trim_s_src_w, option_active.trim_s_src_h) 
  1990. 		 
  1991. 		-- position the se ornate 
  1992. 		h = vint_object_find("menu_mid_trm_btm_right", option_inactive.frame) 
  1993. 		tween_h = menu_create_tween("menu_transition7", h, "anchor", duration) 
  1994. 		Menu_transition_data.tweens[tween_h] = true 
  1995. 		vint_set_property(tween_h, "start_value", option_inactive.trim_se_x, option_inactive.trim_se_y) 
  1996. 		vint_set_property(tween_h, "end_value", option_active.trim_se_x, option_active.trim_se_y) 
  1997.  
  1998. 		-- position and size of e border 
  1999. 		h = vint_object_find("menu_frame_brdr_r", option_inactive.frame) 
  2000. 		tween_h = menu_create_tween("menu_transition8", h, "anchor", duration) 
  2001. 		Menu_transition_data.tweens[tween_h] = true 
  2002. 		vint_set_property(tween_h, "start_value", option_inactive.trim_w_pos_x, option_inactive.trim_w_pos_y) 
  2003. 		vint_set_property(tween_h, "end_value", option_active.trim_w_pos_x, option_active.trim_w_pos_y) 
  2004.  
  2005. 		tween_h = menu_create_tween("menu_transition9", h, "source_se", duration) 
  2006. 		Menu_transition_data.tweens[tween_h] = true 
  2007. 		vint_set_property(tween_h, "start_value", option_inactive.trim_w_src_w, option_inactive.trim_w_src_h) 
  2008. 		vint_set_property(tween_h, "end_value", option_active.trim_w_src_w, option_active.trim_w_src_h) 
  2009.  
  2010. 		-- size of w border 
  2011. 		h = vint_object_find("menu_frame_brdr_l", option_inactive.frame) 
  2012. 		tween_h = menu_create_tween("menu_transition10", h, "source_se", duration) 
  2013. 		Menu_transition_data.tweens[tween_h] = true 
  2014. 		vint_set_property(tween_h, "start_value", option_inactive.trim_w_src_w, option_inactive.trim_w_src_h) 
  2015. 		vint_set_property(tween_h, "end_value", option_active.trim_w_src_w, option_active.trim_w_src_h) 
  2016.  
  2017. 		-- position and size of ne 
  2018. 		h = vint_object_find("menu_mid_trm_btm_line_img2", option_inactive.frame) 
  2019. 		tween_h = menu_create_tween("menu_transition11", h, "anchor", duration) 
  2020. 		Menu_transition_data.tweens[tween_h] = true 
  2021. 		vint_set_property(tween_h, "start_value", option_inactive.trim_ne_pos_x, option_inactive.trim_ne_pos_y) 
  2022. 		vint_set_property(tween_h, "end_value", option_active.trim_ne_pos_x, option_active.trim_ne_pos_y) 
  2023.  
  2024. 		tween_h = menu_create_tween("menu_transition12", h, "source_se", duration) 
  2025. 		Menu_transition_data.tweens[tween_h] = true 
  2026. 		vint_set_property(tween_h, "start_value", option_inactive.trim_ne_src_w, option_inactive.trim_ne_src_h) 
  2027. 		vint_set_property(tween_h, "end_value", option_active.trim_ne_src_w, option_active.trim_ne_src_h) 
  2028.  
  2029. 		-- size of nw border 
  2030. 		h = vint_object_find("menu_mid_trm_btm_line_img1", option_inactive.frame) 
  2031. 		tween_h = menu_create_tween("menu_transition13", h, "source_se", duration) 
  2032. 		Menu_transition_data.tweens[tween_h] = true 
  2033. 		vint_set_property(tween_h, "start_value", option_inactive.trim_ne_src_w, option_inactive.trim_ne_src_h) 
  2034. 		vint_set_property(tween_h, "end_value", option_active.trim_ne_src_w, option_active.trim_ne_src_h) 
  2035. 		 
  2036. 		-- size of nw border 
  2037. 		h = vint_object_find("menu_mid_trm_top_m", option_inactive.frame) 
  2038. 		tween_h = menu_create_tween("menu_transition14", h, "anchor", duration) 
  2039. 		Menu_transition_data.tweens[tween_h] = true 
  2040. 		vint_set_property(tween_h, "start_value", option_inactive.trim_n_pos_x, option_inactive.trim_n_pos_y) 
  2041. 		vint_set_property(tween_h, "end_value", option_active.trim_n_pos_x, option_active.trim_n_pos_y) 
  2042. 		 
  2043. 		-- set up inactive menu clip 
  2044. 		h = vint_object_find("transition_clip", option_inactive.frame) 
  2045. 		vint_set_property(h, "clip_enabled", true) 
  2046.  
  2047. 		tween_h = menu_create_tween("menu_transition15", h, "offset", duration) 
  2048. 		Menu_transition_data.tweens[tween_h] = true 
  2049.  
  2050. 		if sweep_left == true then 
  2051. 			t1 = (menu_inactive.menu_width + 20)  
  2052. 			t2 = 20 
  2053. 		else 
  2054. 			t1 = (-menu_inactive.menu_width - 10)  
  2055. 			t2 = -10 
  2056. 		end 
  2057.  
  2058. 		vint_set_property(tween_h, "start_value", t2, 13) 
  2059. 		vint_set_property(tween_h, "end_value", t1, 13) 
  2060.  
  2061. 		tween_h = menu_create_tween("menu_transition16", h, "clip_size", duration) 
  2062. 		Menu_transition_data.tweens[tween_h] = true 
  2063. 		vint_set_property(tween_h, "start_value", (menu_inactive.menu_width + 26) , (menu_inactive.menu_height - 8) ) 
  2064. 		vint_set_property(tween_h, "end_value", (menu_active.menu_width + 26), (menu_active.menu_height  - 8)) 
  2065. 		 
  2066. 		-- set up active menu clip 
  2067. 		h = vint_object_find("transition_clip", option_active.frame) 
  2068. 		vint_set_property(h, "clip_enabled", true) 
  2069.  
  2070. 		if sweep_left == true then 
  2071. 			t1 = -menu_inactive.menu_width - 10 
  2072. 			t2 = -10 
  2073. 		else 
  2074. 			t1 = menu_inactive.menu_width  + 20 
  2075. 			t2 = 20 
  2076. 		end 
  2077.  
  2078. 		tween_h = menu_create_tween("menu_transition17", h, "offset", duration) 
  2079. 		Menu_transition_data.tweens[tween_h] = true 
  2080. 		vint_set_property(tween_h, "start_value", t1, 13) --t1, 13 
  2081. 		vint_set_property(tween_h, "end_value", t2, 13) 
  2082. 	 
  2083. 	 
  2084. 	 
  2085. 		tween_h = menu_create_tween("menu_transition18", h, "clip_size", duration) 
  2086. 		Menu_transition_data.tweens[tween_h] = true 
  2087. 		vint_set_property(tween_h, "start_value", (menu_inactive.menu_width + 26) , (menu_inactive.menu_height - 8) ) 
  2088. 		vint_set_property(tween_h, "end_value", (menu_active.menu_width + 26), (menu_active.menu_height- 8) ) 
  2089.  
  2090. 	end 
  2091. end 
  2092.  
  2093. -- special case function to just hide the current menu 
  2094. Menu_hide_active_pending = false 
  2095. function menu_hide_active() 
  2096. 	if Menu_transition_in_progress == true then 
  2097. 		Menu_hide_active_pending = true 
  2098. 		return 
  2099. 	end 
  2100. 	 
  2101. 	if Menu_active ~= 0 then 
  2102. 		local o = Menu_option_labels 
  2103. 		 
  2104. 		-- call on_leave for the active control 
  2105. 		local cur_item = Menu_active.highlighted_item 
  2106. 		local cb = Menu_control_callbacks[Menu_active[cur_item].type].on_leave 
  2107. 		if cb ~= nil then 
  2108. 			cb(Menu_option_labels[cur_item - Menu_active.first_vis_item], Menu_active[cur_item]) 
  2109. 		end 
  2110. 		 
  2111. 		Menu_option_labels = Menu_option_labels_inactive 
  2112. 		Menu_option_labels_inactive = o 
  2113.  
  2114. 		Menu_inactive = Menu_active 
  2115. 		Menu_active = 0 
  2116.  
  2117. 		menu_transition_swap_begin() 
  2118. 	end 
  2119. end 
  2120.  
  2121. function menu_show(menu_data, transition) 
  2122. 	if Menu_transition_in_progress == true then 
  2123. 		-- access denied! 
  2124. 		return 
  2125. 	end 
  2126. 	 
  2127. 	if Menu_active ~= 0 then 
  2128. 		-- call on_leave for the active control 
  2129. 		local cur_item = Menu_active.highlighted_item 
  2130. 		local cb = Menu_control_callbacks[Menu_active[cur_item].type].on_leave 
  2131. 		if cb ~= nil then 
  2132. 			cb(Menu_option_labels[cur_item - Menu_active.first_vis_item], Menu_active[cur_item]) 
  2133. 		end 
  2134. 				 
  2135. 		if Menu_active.on_exit ~= nil then 
  2136. 			Menu_active.on_exit(Menu_active) 
  2137. 		end 
  2138. 		 
  2139. 		if menu_data.parent_menu == nil then 
  2140. 			menu_data.parent_menu = Menu_active 
  2141. 		end 
  2142. 		 
  2143. 		-- swap the label set 
  2144. 		local labels = Menu_option_labels_inactive 
  2145. 		Menu_option_labels_inactive = Menu_option_labels 
  2146. 		Menu_option_labels = labels 
  2147. 	else  
  2148. 		menu_data.parent_menu = nil 
  2149. 	end 
  2150. 	 
  2151. 	Menu_inactive = Menu_active 
  2152. 	 
  2153. 	if menu_data.hide_header ~= true then 
  2154. 		menu_data.hide_header = false 
  2155. 	end 
  2156. 	 
  2157. 	if menu_data.hide_header == false then 
  2158. 		if menu_data.header_height == nil then 
  2159. 			menu_data.header_height = 64 
  2160. 		end 
  2161. 	elseif menu_data.hide_frame == true then 
  2162. 		menu_data.header_height = 0 
  2163. 	else 
  2164. 		-- leave room for ornate junk 
  2165. 		menu_data.header_height = 24 
  2166. 	end 
  2167.  
  2168. 	if menu_data.on_show ~= nil then 
  2169. 		menu_data.on_show(menu_data) 
  2170. 	end 
  2171.  
  2172. 	-- set up footer 
  2173. 	if menu_data.footer_height == nil then 
  2174. 		menu_data.footer_height = 0 
  2175. 	end 
  2176.  
  2177. 	if menu_data.footer_height == 0 then 
  2178. 		local footer = menu_data.footer 
  2179. 		 
  2180. 		if footer ~= nil and footer.footer_grp ~= nil then 
  2181. 			vint_object_destroy(footer.footer_grp) 
  2182. 		end 
  2183. 		 
  2184. 		menu_data.footer = nil 
  2185. 	end 
  2186.  
  2187. 	local hl_item = menu_data.highlighted_item 
  2188. 	if hl_item == nil or hl_item >= menu_data.num_items then 
  2189. 		hl_item = 0 
  2190. 	end 
  2191. 	 
  2192. 	local use_specified_header_width = true 
  2193. 	if menu_data.header_width == nil then 
  2194. 		menu_data.header_width = MENU_MIN_MENU_W 
  2195. 		use_specified_header_width = false 
  2196. 	end 
  2197. 		 
  2198. 	if menu_data.max_height == nil then 
  2199. 		menu_data.max_height = MENU_MAX_MENU_H 
  2200. 	end 
  2201. 	 
  2202. 	--Store off old max rows 
  2203. 	local old_menu_options_max_rows = 0 
  2204. 	if Menu_option_labels.max_rows ~= nil then 
  2205. 		old_menu_options_max_rows = Menu_option_labels.max_rows  
  2206. 	end 
  2207. 	 
  2208. 	--Calculate current max rows 
  2209. 	Menu_option_labels.max_rows = floor((menu_data.max_height - menu_data.header_height - menu_data.footer_height) / MENU_ITEM_HEIGHT) 
  2210. 	 
  2211. 	-- create more label objects 
  2212. 	for i = 1, Menu_option_labels.max_rows - 1 do 
  2213. 		if Menu_option_labels[i] == nil then 
  2214. 			Menu_option_labels[i] = { 
  2215. 				label_h = vint_object_clone(Menu_option_labels[0].label_h), 
  2216. 				stripe_h = vint_object_clone(Menu_option_labels[0].stripe_h) 
  2217. 			} 
  2218. 		end 
  2219.  
  2220. 	end 
  2221. 	 
  2222. 	-- scan to the first item not disabled 
  2223. 	if hl_item >= 0 then 
  2224. 		local start = hl_item 
  2225. 		while true do 
  2226. 			if menu_data[hl_item].disabled == true then 
  2227. 				hl_item = hl_item + 1 
  2228. 				 
  2229. 				if hl_item >= menu_data.num_items then 
  2230. 					hl_item = 0 
  2231. 				end 
  2232. 				 
  2233. 				if hl_item == start then 
  2234. 					hl_item = -1 
  2235. 					break 
  2236. 				end 
  2237. 			else 
  2238. 				break 
  2239. 			end 
  2240. 		end 
  2241. 	else 
  2242. 		hl_item = -1 
  2243. 	end 
  2244. 	 
  2245. 	menu_data.highlighted_item = hl_item 
  2246. 	menu_data.first_vis_item = -1 
  2247. 	 
  2248. 	-- set the header text 
  2249. 	vint_set_property(Menu_option_labels.frame, "visible", true) 
  2250. 	local show_header_elements = menu_data.hide_header == false 
  2251.  
  2252. 	if menu_data.hide_header == false then 
  2253. 		local header_text = vint_object_find("menu_header_text", Menu_option_labels.frame) 
  2254. 		 
  2255. 		if menu_data.header_obj ~= nil then 
  2256. 			local x, y = vint_get_property(header_text, "anchor") 
  2257. 			vint_set_property(menu_data.header_obj, "anchor", x, y) 
  2258. 			vint_set_property(menu_data.header_obj, "visible", true) 
  2259. 		elseif menu_data.header_label_crc ~= nil then 
  2260. 			vint_set_property(header_text, "text_tag_crc", menu_data.header_label_crc) 
  2261. 		elseif menu_data.header_label_str ~= nil then 
  2262. 			vint_set_property(header_text, "text_tag", menu_data.header_label_str) 
  2263. 		else	-- apearently no text or object, must be blank 
  2264. 			show_header_elements = false 
  2265. 		end 
  2266. 		 
  2267. 		--if the header is not custom then 
  2268. 		if use_specified_header_width == false then 
  2269. 			--Get size of the header text 
  2270. 			menu_data.header_width = element_get_actual_size(header_text) 
  2271. 		end 
  2272. 	end 
  2273.  
  2274. 	--show/hides header elements 
  2275. 	vint_set_property(vint_object_find("menu_header_text", Menu_option_labels.frame), "visible", show_header_elements) 
  2276. 	vint_set_property(vint_object_find("menu_bg_header_hr", Menu_option_labels.frame), "visible", show_header_elements) 
  2277.  
  2278. 	-- vert resize 
  2279. 	local num_rows = menu_data.num_items 
  2280. 	 
  2281. 	if num_rows > Menu_option_labels.max_rows then 
  2282. 		num_rows = Menu_option_labels.max_rows 
  2283. 	end 
  2284.  
  2285. 	local pos_x = 17 
  2286. 	local pos_y = menu_data.header_height + MENU_ITEM_HEIGHT * 0.5 + 5 
  2287. 	 
  2288. 	--Hide all rows that "could be there" 
  2289. 	for i = 0, old_menu_options_max_rows - 1 do 
  2290. 		vint_set_property(Menu_option_labels[i].label_h, "visible", false) 
  2291. 		vint_set_property(Menu_option_labels[i].stripe_h, "visible", false) 
  2292. 	end 
  2293. 	 
  2294. 	--Show Active Rows 
  2295. 	for i = 0, Menu_option_labels.max_rows - 1 do 
  2296. 		if i < num_rows then 
  2297. 			local object = Menu_option_labels[i] 
  2298. 			vint_set_property(object.label_h, "anchor", pos_x, pos_y) 
  2299. 			vint_set_property(object.stripe_h, "anchor", pos_x, pos_y) 
  2300. 			vint_set_property(object.label_h, "visible", true) 
  2301. 			vint_set_property(object.stripe_h, "visible", true) 
  2302. 			object.anchor_x = pos_x 
  2303. 			object.anchor_y = pos_y 
  2304. 			object.depth = Menu_option_labels.max_rows - i 
  2305. 			pos_y = pos_y + MENU_ITEM_HEIGHT 
  2306. 		end 
  2307. 	end 
  2308. 	 
  2309. 	-- special case: don't deal with the scroll bars if the only 
  2310. 	-- item wants it 
  2311. 	local handle_scroll_bar = true 
  2312. 	if num_rows == 1 then 
  2313. 		if Menu_control_callbacks[menu_data[0].type].uses_scroll_bar == true then 
  2314. 			handle_scroll_bar = false 
  2315. 		end 
  2316. 	end 
  2317.  
  2318. 	if handle_scroll_bar == true then 
  2319. 		if menu_data.num_items > Menu_option_labels.max_rows then 
  2320. 			-- unhide scroll bar 
  2321. 			local thumb_size = Menu_option_labels.max_rows / menu_data.num_items 
  2322. 			menu_scroll_bar_show() 
  2323. 			menu_scroll_bar_set_bar_height(Menu_option_labels.max_rows * MENU_ITEM_HEIGHT + 15) 
  2324. 			menu_scroll_bar_set_thumb_size(thumb_size) 
  2325. 			Menu_option_labels.scroll_bar_visible = true 
  2326. 		else 
  2327. 			-- hide scroll bar 
  2328. 			menu_scroll_bar_hide(Menu_option_labels.frame) 
  2329. 			Menu_option_labels.scroll_bar_visible = false 
  2330. 		end 
  2331. 	end 
  2332.  
  2333. 	-- horz size 
  2334. 	local label_h = Menu_option_labels[0].label_h 
  2335. 	local label_w, max_label_w = 0, 0 
  2336. 	local has_controls = false 
  2337. 	 
  2338. 	for i = 0, menu_data.num_items - 1 do 
  2339. 		local menu_item = menu_data[i] 
  2340. 		 
  2341. 		if menu_item.label_crc ~= nil then 
  2342. 			vint_set_property(label_h, "text_tag_crc", menu_item.label_crc) 
  2343. 		elseif menu_item.label ~= nil then 
  2344. 			vint_set_property(label_h, "text_tag", menu_item.label) 
  2345. 		else 
  2346. 			vint_set_property(label_h, "text_tag", "") 
  2347. 		end 
  2348. 		 
  2349. 		if menu_item.get_width ~= nil then 
  2350. 			label_w = menu_item.get_width(menu_item) 
  2351. 		elseif Menu_control_callbacks[menu_item.type].get_width ~= nil then 
  2352. 			label_w = Menu_control_callbacks[menu_item.type].get_width(menu_item) 
  2353. 		else 
  2354. 			label_w = element_get_actual_size(label_h)  
  2355. 		end 
  2356.  
  2357. 		if label_w > max_label_w then 
  2358. 			max_label_w = label_w 
  2359. 		end 
  2360.  
  2361. 		if Menu_control_callbacks[menu_item.type].has_control == true then 
  2362. 			has_controls = true 
  2363. 		end 
  2364.  
  2365. 		vint_set_property(label_h, "tint", 0.2, 0.2, 0.2) 
  2366.  
  2367. 	end 
  2368.  
  2369. 	--Get the control width for each menu item 
  2370. 	local control_min_width = 0 
  2371. 	for i = 0, menu_data.num_items - 1 do 
  2372. 		local menu_item = menu_data[i] 
  2373. 		local item_type = menu_data[i].type 
  2374. 		 
  2375. 		--Get the minimum width for the control 
  2376. 		local cb = Menu_control_callbacks[item_type] 
  2377. 		if cb ~= nil then	 
  2378. 			if cb.get_min_width ~= nil then 
  2379. 				local control_width = cb.get_min_width(menu_item) 
  2380. 				if control_width > control_min_width then 
  2381. 					control_min_width = control_width 
  2382. 				end  
  2383. 			end 	 
  2384. 		end 
  2385. 	end 
  2386. 	--Our control min width cannot be less than the default 
  2387. 	if control_min_width < MENU_CONTROL_W then 
  2388. 		control_min_width = MENU_CONTROL_W  
  2389. 	end 
  2390. 	 
  2391. 	--Store the control width for the future 
  2392. 	menu_data.control_width = control_min_width 
  2393. 	 
  2394. 	if Menu_option_labels.scroll_bar_visible == true then 
  2395. 		max_label_w = max_label_w + 35 
  2396. 	end 
  2397.  
  2398. 	if max_label_w < MENU_MIN_LABEL_W then 
  2399. 		max_label_w = MENU_MIN_LABEL_W 
  2400. 	end 
  2401.  
  2402. 	if menu_data.max_label_w ~= nil then 
  2403. 		if max_label_w > menu_data.max_label_w then 
  2404. 			max_label_w = menu_data.max_label_w 
  2405. 		end 
  2406. 	end 
  2407. 	 
  2408. 	Menu_option_labels.max_label_w = max_label_w 
  2409.  
  2410. 	-- height and width of the area occupied by labels and controls 
  2411. 	local height, width 
  2412.  
  2413. 	-- special case: this may be a single control menu so it might tell me it's height 
  2414. 	if num_rows == 1 then 
  2415. 		local cb = Menu_control_callbacks[menu_data[0].type].get_height 
  2416. 		if cb ~= nil then 
  2417. 			height = menu_data.header_height + cb(menu_data[0]) 
  2418. 		end 
  2419. 	end 
  2420.  
  2421. 	-- check to see if menu would like to dictate the size 
  2422. 	if menu_data.get_width ~= nil then 
  2423. 		local menu_width = 10 + menu_data.get_width(menu_data) 
  2424. 		width = menu_width 
  2425. 	end 
  2426. 	 
  2427. 	if menu_data.get_height ~= nil then 
  2428. 		height = menu_data.header_height + menu_data.get_height(menu_data) 
  2429. 	end 
  2430. 	 
  2431. 	-- standard case: each item is MENU_ITEM_HEIGHT pixels high 
  2432. 	if height == nil then 
  2433. 		height = pos_y - MENU_ITEM_HEIGHT + 15 
  2434. 	end 
  2435. 	 
  2436. 	if menu_data.footer_height ~= 0 then 
  2437. 		height = height + menu_data.footer_height + 15 
  2438. 	end 
  2439.  
  2440. 	-- position the footer 
  2441. 	if menu_data.footer_height ~= 0 and menu_data.footer ~= nil then 
  2442. 		menu_data.footer.pos_y = height - menu_data.footer_height - 2 
  2443. 		vint_set_property(menu_data.footer.footer_grp, "anchor", 20, menu_data.footer.pos_y) 
  2444. 	end 
  2445.  
  2446. 	--Make sure our width is not less than the control width 
  2447. 	if width == nil then 
  2448. 		width = max_label_w 
  2449.  
  2450. 		if has_controls == true then 
  2451. 			width = width + menu_data.control_width 
  2452. 			if Menu_option_labels.scroll_bar_visible == true then 
  2453. 				--controls and scrollbar 
  2454. 				width = width + 40 
  2455. 			end 
  2456. 		end 
  2457. 	end 
  2458. 	 
  2459. 	--If our header is wider than our menu then expand 
  2460. 	if menu_data.header_width > width then 
  2461. 		width = menu_data.header_width 
  2462. 	end 
  2463. 		 
  2464. 	--If menu width is less than the mininum size then set it so... 
  2465. 	if width < MENU_MIN_MENU_W then 
  2466. 		width = MENU_MIN_MENU_W 
  2467. 	end 
  2468.  
  2469. 	-- make room for ornate 
  2470. 	width = width + 22 
  2471.  
  2472. 	local bg_h 
  2473.  
  2474. 	--Resize Selector bar 
  2475. 	local frame_h = Menu_option_labels.frame 
  2476. 	local sel_bar_width = floor(width) - 8 
  2477. 	 
  2478. 	if Menu_option_labels.scroll_bar_visible == true then 
  2479. 		sel_bar_width = sel_bar_width - 40 
  2480. 	end 
  2481. 	 
  2482. 	Menu_option_labels.item_width = sel_bar_width 
  2483. 	 
  2484. 	bg_h = vint_object_find("menu_sel_bar_w", frame_h) 
  2485. 	vint_set_property(bg_h, "source_se", sel_bar_width, 36) 
  2486. 	 
  2487. 	bg_h = vint_object_find("menu_sel_bar_w_hl", frame_h) 
  2488. 	vint_set_property(bg_h, "source_se", sel_bar_width, 36) 
  2489. 	 
  2490. 	bg_h = vint_object_find("menu_sel_bar_e", frame_h) 
  2491. 	local menu_bar_e_anchor_x, menu_bar_e_anchor_y = vint_get_property(bg_h, "anchor") 
  2492. 	menu_bar_e_anchor_x = sel_bar_width + 5 
  2493. 	vint_set_property(bg_h, "anchor", menu_bar_e_anchor_x, menu_bar_e_anchor_y) 
  2494. 	 
  2495. 	local bg_h = vint_object_find("menu_sel_bar_e_hl", frame_h) 
  2496. 	vint_set_property(bg_h, "anchor", menu_bar_e_anchor_x - 1, menu_bar_e_anchor_y) 
  2497. 	 
  2498. 	vint_set_property(Menu_option_labels.hl_clip, "offset", 12, -15) 
  2499. 	vint_set_property(Menu_option_labels.hl_clip, "clip_size", width - 17, MENU_ITEM_HEIGHT) 
  2500. 	 
  2501. 	--Adjust scrollbar 
  2502. 	if Menu_option_labels.scroll_bar_visible == true then 
  2503. 		menu_scroll_bar_set_pos(width - 25, menu_data.header_height + 2) 
  2504. 	end 
  2505. 	 
  2506. 	if menu_data.hide_frame ~= true then 
  2507. 		menu_data.hide_frame = false 
  2508. 	end 
  2509. 	 
  2510. 	vint_set_property(vint_object_find("menu_bg", frame_h), "visible", menu_data.hide_frame == false) 
  2511. 	vint_set_property(vint_object_find("menu_fg", frame_h), "visible", menu_data.hide_frame == false) 
  2512.  
  2513. 	bg_h = vint_object_find("menu_frame_middle", frame_h) 
  2514. 	Menu_option_labels.trim_c_scale_x = width / 16  
  2515. 	Menu_option_labels.trim_c_scale_y = height / 16  
  2516. 	vint_set_property(bg_h, "scale", Menu_option_labels.trim_c_scale_x, Menu_option_labels.trim_c_scale_y)  
  2517. 	 
  2518. 	bg_h = vint_object_find("menu_frame_brdr_l", frame_h) 
  2519. 	Menu_option_labels.trim_w_src_w = 19 
  2520. 	Menu_option_labels.trim_w_src_h = height 
  2521. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_w_src_w, Menu_option_labels.trim_w_src_h) 
  2522.  
  2523. 	bg_h = vint_object_find("menu_frame_brdr_r", frame_h) 
  2524. 	Menu_option_labels.trim_w_pos_x = width + 17 
  2525. 	Menu_option_labels.trim_w_pos_y = 13 
  2526. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_w_pos_x, Menu_option_labels.trim_w_pos_y) 
  2527. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_w_src_w, Menu_option_labels.trim_w_src_h) 
  2528.  
  2529. 	bg_h = vint_object_find("menu_mid_trm_btm_right", frame_h) 
  2530. 	Menu_option_labels.trim_se_x = width - 50 
  2531. 	Menu_option_labels.trim_se_y = height - 36 
  2532. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_se_x, Menu_option_labels.trim_se_y) 
  2533.  
  2534. 	bg_h = vint_object_find("menu_mid_trm_btm_line_img", frame_h) 
  2535. 	Menu_option_labels.trim_s_pos_x = 6 
  2536. 	Menu_option_labels.trim_s_pos_y = height + 7 
  2537. 	Menu_option_labels.trim_s_src_w = width - 50 
  2538. 	Menu_option_labels.trim_s_src_h = 12 
  2539. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_s_pos_x, Menu_option_labels.trim_s_pos_y) 
  2540. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_s_src_w, Menu_option_labels.trim_s_src_h) 
  2541.  
  2542. 	bg_h = vint_object_find("menu_bg_header_hr", frame_h) 
  2543. 	 
  2544. 	vint_set_property(bg_h, "anchor", 23, menu_data.header_height - 10) 
  2545. 	vint_set_property(bg_h, "source_se", width - 10, 10) 
  2546.  
  2547. 	if menu_data.footer_height ~= 0 and menu_data.footer ~= nil then 
  2548. 		menu_data.footer.hr_h = vint_object_clone(bg_h) 
  2549. 		vint_set_property(menu_data.footer.hr_h, "anchor", 23, menu_data.footer.pos_y - 8) 
  2550. 		vint_set_property(bg_h, "source_se", width - 10, 10) 
  2551. 	end 
  2552.  
  2553. 	Menu_option_labels.trim_ne_src_w = width / 2 - 60 
  2554. 	Menu_option_labels.trim_ne_src_h = 12 
  2555. 	bg_h = vint_object_find("menu_mid_trm_btm_line_img1", frame_h) 
  2556. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_ne_src_w, Menu_option_labels.trim_ne_src_h) 
  2557.  
  2558. 	Menu_option_labels.trim_ne_pos_x = width + 35 
  2559. 	Menu_option_labels.trim_ne_pos_y = 9 
  2560. 	bg_h = vint_object_find("menu_mid_trm_btm_line_img2", frame_h) 
  2561. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_ne_pos_x, Menu_option_labels.trim_ne_pos_y) 
  2562. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_ne_src_w, Menu_option_labels.trim_ne_src_w) 
  2563.  
  2564. 	Menu_option_labels.trim_n_pos_x = (width + 38) / 2 
  2565. 	Menu_option_labels.trim_n_pos_y = 12 
  2566. 	bg_h = vint_object_find("menu_mid_trm_top_m", frame_h) 
  2567. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_n_pos_x, Menu_option_labels.trim_n_pos_y) 
  2568.  
  2569. 	--	Set the clipping area 
  2570. 	vint_set_property(Menu_option_labels.clip_h, "clip_size", sel_bar_width + 10, height) 
  2571. 	 
  2572. 	Menu_active = menu_data 
  2573. 	menu_data.menu_height = height 
  2574. 	menu_data.menu_width = width 
  2575. 	 
  2576. 	Menu_new = true 
  2577.  
  2578. 	menu_update_nav_bar(Menu_active.highlighted_item) 
  2579. 	 
  2580. 	if Menu_active.on_post_show ~= nil then 
  2581. 		Menu_active.on_post_show(Menu_active) 
  2582. 	end 
  2583.  
  2584. 	btn_tips_update()	 
  2585. 	 
  2586. 	if transition == MENU_TRANSITION_SWAP then 
  2587. 		menu_transition_swap_begin() 
  2588. 	elseif transition == MENU_TRANSITION_SWEEP_RIGHT then 
  2589. 		menu_transition_sweep_begin(false) 
  2590. 	elseif transition == MENU_TRANSITION_SWEEP_LEFT then 
  2591. 		menu_transition_sweep_begin(true) 
  2592. 	else 
  2593. 		menu_input_block(true) 
  2594. 		menu_transition_complete() 
  2595. 	end 
  2596. end 
  2597.  
  2598. --CDPLC: this function is nearly a copy of of menu_show(). Changed fragments are marked in order to ease future merges. 
  2599. function menu_resize() 
  2600.  
  2601. --CDPLC: whole fragment commented 
  2602. --	if Menu_transition_in_progress == true then 
  2603. --		-- access denied! 
  2604. --		return 
  2605. --	end 
  2606. 	 
  2607. --	if Menu_active ~= 0 then 
  2608. --		-- call on_leave for the active control 
  2609. --		local cur_item = Menu_active.highlighted_item 
  2610. --		local cb = Menu_control_callbacks[Menu_active[cur_item].type].on_leave 
  2611. --		if cb ~= nil then 
  2612. --			cb(Menu_option_labels[cur_item - Menu_active.first_vis_item], Menu_active[cur_item]) 
  2613. --		end 
  2614. 				 
  2615. --		if Menu_active.on_exit ~= nil then 
  2616. --			Menu_active.on_exit(Menu_active) 
  2617. --		end 
  2618. 		 
  2619. --		if menu_data.parent_menu == nil then 
  2620. --			menu_data.parent_menu = Menu_active 
  2621. --		end 
  2622. 		 
  2623. --		-- swap the label set 
  2624. --		local labels = Menu_option_labels_inactive 
  2625. --		Menu_option_labels_inactive = Menu_option_labels 
  2626. --		Menu_option_labels = labels 
  2627. --	else  
  2628. --		menu_data.parent_menu = nil 
  2629. --	end 
  2630. 	 
  2631. --	Menu_inactive = Menu_active 
  2632.  
  2633. 	--CDPLC: added 
  2634. 	local menu_data = Menu_active 
  2635.  
  2636. 	if menu_data.hide_header ~= true then 
  2637. 		menu_data.hide_header = false 
  2638. 	end 
  2639. 	 
  2640. 	if menu_data.hide_header == false then 
  2641. 		if menu_data.header_height == nil then 
  2642. 			menu_data.header_height = 64 
  2643. 		end 
  2644. 	elseif menu_data.hide_frame == true then 
  2645. 		menu_data.header_height = 0 
  2646. 	else 
  2647. 		-- leave room for ornate junk 
  2648. 		menu_data.header_height = 24 
  2649. 	end 
  2650.  
  2651. 	if menu_data.on_show ~= nil then 
  2652. 		menu_data.on_show(menu_data) 
  2653. 	end 
  2654.  
  2655. 	-- set up footer 
  2656. 	if menu_data.footer_height == nil then 
  2657. 		menu_data.footer_height = 0 
  2658. 	end 
  2659.  
  2660. 	if menu_data.footer_height == 0 then 
  2661. 		local footer = menu_data.footer 
  2662. 		 
  2663. 		if footer ~= nil and footer.footer_grp ~= nil then 
  2664. 			vint_object_destroy(footer.footer_grp) 
  2665. 		end 
  2666. 		 
  2667. 		menu_data.footer = nil 
  2668. 	end 
  2669.  
  2670. 	local hl_item = menu_data.highlighted_item 
  2671. 	if hl_item == nil or hl_item >= menu_data.num_items then 
  2672. 		hl_item = 0 
  2673. 	end 
  2674. 	 
  2675. 	local use_specified_header_width = true 
  2676. 	if menu_data.header_width == nil then 
  2677. 		menu_data.header_width = MENU_MIN_MENU_W 
  2678. 		use_specified_header_width = false 
  2679. 	end 
  2680. 		 
  2681. 	if menu_data.max_height == nil then 
  2682. 		menu_data.max_height = MENU_MAX_MENU_H 
  2683. 	end 
  2684. 	 
  2685. 	--Store off old max rows 
  2686. 	local old_menu_options_max_rows = 0 
  2687. 	if Menu_option_labels.max_rows ~= nil then 
  2688. 		old_menu_options_max_rows = Menu_option_labels.max_rows  
  2689. 	end 
  2690. 	 
  2691. 	--Calculate current max rows 
  2692. 	Menu_option_labels.max_rows = floor((menu_data.max_height - menu_data.header_height - menu_data.footer_height) / MENU_ITEM_HEIGHT) 
  2693. 	 
  2694. 	-- create more label objects 
  2695. 	for i = 1, Menu_option_labels.max_rows - 1 do 
  2696. 		if Menu_option_labels[i] == nil then 
  2697. 			Menu_option_labels[i] = { 
  2698. 				label_h = vint_object_clone(Menu_option_labels[0].label_h), 
  2699. 				stripe_h = vint_object_clone(Menu_option_labels[0].stripe_h) 
  2700. 			} 
  2701. 		end 
  2702.  
  2703. 	end 
  2704. 	 
  2705. 	-- scan to the first item not disabled 
  2706. 	if hl_item >= 0 then 
  2707. 		local start = hl_item 
  2708. 		while true do 
  2709. 			if menu_data[hl_item].disabled == true then 
  2710. 				hl_item = hl_item + 1 
  2711. 				 
  2712. 				if hl_item >= menu_data.num_items then 
  2713. 					hl_item = 0 
  2714. 				end 
  2715. 				 
  2716. 				if hl_item == start then 
  2717. 					hl_item = -1 
  2718. 					break 
  2719. 				end 
  2720. 			else 
  2721. 				break 
  2722. 			end 
  2723. 		end 
  2724. 	else 
  2725. 		hl_item = -1 
  2726. 	end 
  2727. 	 
  2728. 	menu_data.highlighted_item = hl_item 
  2729. 	menu_data.first_vis_item = -1 
  2730. 	 
  2731. 	-- set the header text 
  2732. 	vint_set_property(Menu_option_labels.frame, "visible", true) 
  2733. 	local show_header_elements = menu_data.hide_header == false 
  2734.  
  2735. 	if menu_data.hide_header == false then 
  2736. 		local header_text = vint_object_find("menu_header_text", Menu_option_labels.frame) 
  2737. 		 
  2738. 		if menu_data.header_obj ~= nil then 
  2739. 			local x, y = vint_get_property(header_text, "anchor") 
  2740. 			vint_set_property(menu_data.header_obj, "anchor", x, y) 
  2741. 			vint_set_property(menu_data.header_obj, "visible", true) 
  2742. 		elseif menu_data.header_label_crc ~= nil then 
  2743. 			vint_set_property(header_text, "text_tag_crc", menu_data.header_label_crc) 
  2744. 		elseif menu_data.header_label_str ~= nil then 
  2745. 			vint_set_property(header_text, "text_tag", menu_data.header_label_str) 
  2746. 		else	-- apearently no text or object, must be blank 
  2747. 			show_header_elements = false 
  2748. 		end 
  2749. 		 
  2750. 		--if the header is not custom then 
  2751. 		if use_specified_header_width == false then 
  2752. 			--Get size of the header text 
  2753. 			menu_data.header_width = element_get_actual_size(header_text) 
  2754. 		end 
  2755. 	end 
  2756.  
  2757. 	--show/hides header elements 
  2758. 	vint_set_property(vint_object_find("menu_header_text", Menu_option_labels.frame), "visible", show_header_elements) 
  2759. 	vint_set_property(vint_object_find("menu_bg_header_hr", Menu_option_labels.frame), "visible", show_header_elements) 
  2760.  
  2761. 	-- vert resize 
  2762. 	local num_rows = menu_data.num_items 
  2763. 	 
  2764. 	if num_rows > Menu_option_labels.max_rows then 
  2765. 		num_rows = Menu_option_labels.max_rows 
  2766. 	end 
  2767.  
  2768. 	local pos_x = 17 
  2769. 	local pos_y = menu_data.header_height + MENU_ITEM_HEIGHT * 0.5 + 5 
  2770. 	 
  2771. 	--Hide all rows that "could be there" 
  2772. 	for i = 0, old_menu_options_max_rows - 1 do 
  2773. 		vint_set_property(Menu_option_labels[i].label_h, "visible", false) 
  2774. 		vint_set_property(Menu_option_labels[i].stripe_h, "visible", false) 
  2775. 	end 
  2776. 	 
  2777. 	--Show Active Rows 
  2778. 	for i = 0, Menu_option_labels.max_rows - 1 do 
  2779. 		if i < num_rows then 
  2780. 			local object = Menu_option_labels[i] 
  2781. 			vint_set_property(object.label_h, "anchor", pos_x, pos_y) 
  2782. 			vint_set_property(object.stripe_h, "anchor", pos_x, pos_y) 
  2783. 			vint_set_property(object.label_h, "visible", true) 
  2784. 			vint_set_property(object.stripe_h, "visible", true) 
  2785. 			object.anchor_x = pos_x 
  2786. 			object.anchor_y = pos_y 
  2787. 			object.depth = Menu_option_labels.max_rows - i 
  2788. 			pos_y = pos_y + MENU_ITEM_HEIGHT 
  2789. 		end 
  2790. 	end 
  2791. 	 
  2792. 	-- special case: don't deal with the scroll bars if the only 
  2793. 	-- item wants it 
  2794. 	local handle_scroll_bar = true 
  2795. 	if num_rows == 1 then 
  2796. 		if Menu_control_callbacks[menu_data[0].type].uses_scroll_bar == true then 
  2797. 			handle_scroll_bar = false 
  2798. 		end 
  2799. 	end 
  2800.  
  2801. 	if handle_scroll_bar == true then 
  2802. 		if menu_data.num_items > Menu_option_labels.max_rows then 
  2803. 			-- unhide scroll bar 
  2804. 			local thumb_size = Menu_option_labels.max_rows / menu_data.num_items 
  2805. 			menu_scroll_bar_show() 
  2806. 			menu_scroll_bar_set_bar_height(Menu_option_labels.max_rows * MENU_ITEM_HEIGHT + 15) 
  2807. 			menu_scroll_bar_set_thumb_size(thumb_size) 
  2808. 			Menu_option_labels.scroll_bar_visible = true 
  2809. 		else 
  2810. 			-- hide scroll bar 
  2811. 			menu_scroll_bar_hide(Menu_option_labels.frame) 
  2812. 			Menu_option_labels.scroll_bar_visible = false 
  2813. 		end 
  2814. 	end 
  2815.  
  2816. 	-- horz size 
  2817. 	local label_h = Menu_option_labels[0].label_h 
  2818. 	local label_w, max_label_w = 0, 0 
  2819. 	local has_controls = false 
  2820. 	 
  2821. 	for i = 0, menu_data.num_items - 1 do 
  2822. 		local menu_item = menu_data[i] 
  2823. 		 
  2824. 		if menu_item.label_crc ~= nil then 
  2825. 			vint_set_property(label_h, "text_tag_crc", menu_item.label_crc) 
  2826. 		elseif menu_item.label ~= nil then 
  2827. 			vint_set_property(label_h, "text_tag", menu_item.label) 
  2828. 		else 
  2829. 			vint_set_property(label_h, "text_tag", "") 
  2830. 		end 
  2831. 		 
  2832. 		if menu_item.get_width ~= nil then 
  2833. 			label_w = menu_item.get_width(menu_item) 
  2834. 		elseif Menu_control_callbacks[menu_item.type].get_width ~= nil then 
  2835. 			label_w = Menu_control_callbacks[menu_item.type].get_width(menu_item) 
  2836. 		else 
  2837. 			label_w = element_get_actual_size(label_h)  
  2838. 		end 
  2839.  
  2840. 		if label_w > max_label_w then 
  2841. 			max_label_w = label_w 
  2842. 		end 
  2843.  
  2844. 		if Menu_control_callbacks[menu_item.type].has_control == true then 
  2845. 			has_controls = true 
  2846. 		end 
  2847.  
  2848. 		vint_set_property(label_h, "tint", 0.2, 0.2, 0.2) 
  2849.  
  2850. 	end 
  2851.  
  2852. 	--Get the control width for each menu item 
  2853. 	local control_min_width = 0 
  2854. 	for i = 0, menu_data.num_items - 1 do 
  2855. 		local menu_item = menu_data[i] 
  2856. 		local item_type = menu_data[i].type 
  2857. 		 
  2858. 		--Get the minimum width for the control 
  2859. 		local cb = Menu_control_callbacks[item_type] 
  2860. 		if cb ~= nil then	 
  2861. 			if cb.get_min_width ~= nil then 
  2862. 				local control_width = cb.get_min_width(menu_item) 
  2863. 				if control_width > control_min_width then 
  2864. 					control_min_width = control_width 
  2865. 				end  
  2866. 			end 	 
  2867. 		end 
  2868. 	end 
  2869. 	--Our control min width cannot be less than the default 
  2870. 	if control_min_width < MENU_CONTROL_W then 
  2871. 		control_min_width = MENU_CONTROL_W  
  2872. 	end 
  2873. 	 
  2874. 	--Store the control width for the future 
  2875. 	menu_data.control_width = control_min_width 
  2876. 	 
  2877. 	if Menu_option_labels.scroll_bar_visible == true then 
  2878. 		max_label_w = max_label_w + 35 
  2879. 	end 
  2880.  
  2881. 	if max_label_w < MENU_MIN_LABEL_W then 
  2882. 		max_label_w = MENU_MIN_LABEL_W 
  2883. 	end 
  2884.  
  2885. 	if menu_data.max_label_w ~= nil then 
  2886. 		if max_label_w > menu_data.max_label_w then 
  2887. 			max_label_w = menu_data.max_label_w 
  2888. 		end 
  2889. 	end 
  2890. 	 
  2891. 	Menu_option_labels.max_label_w = max_label_w 
  2892.  
  2893. 	-- height and width of the area occupied by labels and controls 
  2894. 	local height, width 
  2895.  
  2896. 	-- special case: this may be a single control menu so it might tell me it's height 
  2897. 	if num_rows == 1 then 
  2898. 		local cb = Menu_control_callbacks[menu_data[0].type].get_height 
  2899. 		if cb ~= nil then 
  2900. 			height = menu_data.header_height + cb(menu_data[0]) 
  2901. 		end 
  2902. 	end 
  2903.  
  2904. 	-- check to see if menu would like to dictate the size 
  2905. 	if menu_data.get_width ~= nil then 
  2906. 		local menu_width = 10 + menu_data.get_width(menu_data) 
  2907. 		width = menu_width 
  2908. 	end 
  2909. 	 
  2910. 	if menu_data.get_height ~= nil then 
  2911. 		height = menu_data.header_height + menu_data.get_height(menu_data) 
  2912. 	end 
  2913. 	 
  2914. 	-- standard case: each item is MENU_ITEM_HEIGHT pixels high 
  2915. 	if height == nil then 
  2916. 		height = pos_y - MENU_ITEM_HEIGHT + 15 
  2917. 	end 
  2918. 	 
  2919. 	if menu_data.footer_height ~= 0 then 
  2920. 		height = height + menu_data.footer_height + 15 
  2921. 	end 
  2922.  
  2923. 	-- position the footer 
  2924. 	if menu_data.footer_height ~= 0 and menu_data.footer ~= nil then 
  2925. 		menu_data.footer.pos_y = height - menu_data.footer_height - 2 
  2926. 		vint_set_property(menu_data.footer.footer_grp, "anchor", 20, menu_data.footer.pos_y) 
  2927. 	end 
  2928.  
  2929. 	--Make sure our width is not less than the control width 
  2930. 	if width == nil then 
  2931. 		width = max_label_w 
  2932.  
  2933. 		if has_controls == true then 
  2934. 			width = width + menu_data.control_width 
  2935. 			if Menu_option_labels.scroll_bar_visible == true then 
  2936. 				--controls and scrollbar 
  2937. 				width = width + 40 
  2938. 			end 
  2939. 		end 
  2940. 	end 
  2941. 	 
  2942. 	--If our header is wider than our menu then expand 
  2943. 	if menu_data.header_width > width then 
  2944. 		width = menu_data.header_width 
  2945. 	end 
  2946. 		 
  2947. 	--If menu width is less than the mininum size then set it so... 
  2948. 	if width < MENU_MIN_MENU_W then 
  2949. 		width = MENU_MIN_MENU_W 
  2950. 	end 
  2951.  
  2952. 	-- make room for ornate 
  2953. 	width = width + 22 
  2954.  
  2955. 	local bg_h 
  2956.  
  2957. 	--Resize Selector bar 
  2958. 	local frame_h = Menu_option_labels.frame 
  2959. 	local sel_bar_width = floor(width) - 8 
  2960. 	 
  2961. 	if Menu_option_labels.scroll_bar_visible == true then 
  2962. 		sel_bar_width = sel_bar_width - 40 
  2963. 	end 
  2964. 	 
  2965. 	Menu_option_labels.item_width = sel_bar_width 
  2966. 	 
  2967. 	bg_h = vint_object_find("menu_sel_bar_w", frame_h) 
  2968. 	vint_set_property(bg_h, "source_se", sel_bar_width, 36) 
  2969. 	 
  2970. 	bg_h = vint_object_find("menu_sel_bar_w_hl", frame_h) 
  2971. 	vint_set_property(bg_h, "source_se", sel_bar_width, 36) 
  2972. 	 
  2973. 	bg_h = vint_object_find("menu_sel_bar_e", frame_h) 
  2974. 	local menu_bar_e_anchor_x, menu_bar_e_anchor_y = vint_get_property(bg_h, "anchor") 
  2975. 	menu_bar_e_anchor_x = sel_bar_width + 5 
  2976. 	vint_set_property(bg_h, "anchor", menu_bar_e_anchor_x, menu_bar_e_anchor_y) 
  2977. 	 
  2978. 	local bg_h = vint_object_find("menu_sel_bar_e_hl", frame_h) 
  2979. 	vint_set_property(bg_h, "anchor", menu_bar_e_anchor_x - 1, menu_bar_e_anchor_y) 
  2980. 	 
  2981. 	vint_set_property(Menu_option_labels.hl_clip, "offset", 12, -15) 
  2982. 	vint_set_property(Menu_option_labels.hl_clip, "clip_size", width - 17, MENU_ITEM_HEIGHT) 
  2983. 	 
  2984. 	--Adjust scrollbar 
  2985. 	if Menu_option_labels.scroll_bar_visible == true then 
  2986. 		menu_scroll_bar_set_pos(width - 25, menu_data.header_height + 2) 
  2987. 	end 
  2988. 	 
  2989. 	if menu_data.hide_frame ~= true then 
  2990. 		menu_data.hide_frame = false 
  2991. 	end 
  2992. 	 
  2993. 	vint_set_property(vint_object_find("menu_bg", frame_h), "visible", menu_data.hide_frame == false) 
  2994. 	vint_set_property(vint_object_find("menu_fg", frame_h), "visible", menu_data.hide_frame == false) 
  2995.  
  2996. 	bg_h = vint_object_find("menu_frame_middle", frame_h) 
  2997. 	Menu_option_labels.trim_c_scale_x = width / 16  
  2998. 	Menu_option_labels.trim_c_scale_y = height / 16  
  2999. 	vint_set_property(bg_h, "scale", Menu_option_labels.trim_c_scale_x, Menu_option_labels.trim_c_scale_y)  
  3000. 	 
  3001. 	bg_h = vint_object_find("menu_frame_brdr_l", frame_h) 
  3002. 	Menu_option_labels.trim_w_src_w = 19 
  3003. 	Menu_option_labels.trim_w_src_h = height 
  3004. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_w_src_w, Menu_option_labels.trim_w_src_h) 
  3005.  
  3006. 	bg_h = vint_object_find("menu_frame_brdr_r", frame_h) 
  3007. 	Menu_option_labels.trim_w_pos_x = width + 17 
  3008. 	Menu_option_labels.trim_w_pos_y = 13 
  3009. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_w_pos_x, Menu_option_labels.trim_w_pos_y) 
  3010. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_w_src_w, Menu_option_labels.trim_w_src_h) 
  3011.  
  3012. 	bg_h = vint_object_find("menu_mid_trm_btm_right", frame_h) 
  3013. 	Menu_option_labels.trim_se_x = width - 50 
  3014. 	Menu_option_labels.trim_se_y = height - 36 
  3015. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_se_x, Menu_option_labels.trim_se_y) 
  3016.  
  3017. 	bg_h = vint_object_find("menu_mid_trm_btm_line_img", frame_h) 
  3018. 	Menu_option_labels.trim_s_pos_x = 6 
  3019. 	Menu_option_labels.trim_s_pos_y = height + 7 
  3020. 	Menu_option_labels.trim_s_src_w = width - 50 
  3021. 	Menu_option_labels.trim_s_src_h = 12 
  3022. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_s_pos_x, Menu_option_labels.trim_s_pos_y) 
  3023. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_s_src_w, Menu_option_labels.trim_s_src_h) 
  3024.  
  3025. 	bg_h = vint_object_find("menu_bg_header_hr", frame_h) 
  3026. 	 
  3027. 	vint_set_property(bg_h, "anchor", 23, menu_data.header_height - 10) 
  3028. 	vint_set_property(bg_h, "source_se", width - 10, 10) 
  3029.  
  3030. 	if menu_data.footer_height ~= 0 and menu_data.footer ~= nil then 
  3031. 		menu_data.footer.hr_h = vint_object_clone(bg_h) 
  3032. 		vint_set_property(menu_data.footer.hr_h, "anchor", 23, menu_data.footer.pos_y - 8) 
  3033. 		vint_set_property(bg_h, "source_se", width - 10, 10) 
  3034. 	end 
  3035.  
  3036. 	Menu_option_labels.trim_ne_src_w = width / 2 - 60 
  3037. 	Menu_option_labels.trim_ne_src_h = 12 
  3038. 	bg_h = vint_object_find("menu_mid_trm_btm_line_img1", frame_h) 
  3039. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_ne_src_w, Menu_option_labels.trim_ne_src_h) 
  3040.  
  3041. 	Menu_option_labels.trim_ne_pos_x = width + 35 
  3042. 	Menu_option_labels.trim_ne_pos_y = 9 
  3043. 	bg_h = vint_object_find("menu_mid_trm_btm_line_img2", frame_h) 
  3044. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_ne_pos_x, Menu_option_labels.trim_ne_pos_y) 
  3045. 	vint_set_property(bg_h, "source_se", Menu_option_labels.trim_ne_src_w, Menu_option_labels.trim_ne_src_w) 
  3046.  
  3047. 	Menu_option_labels.trim_n_pos_x = (width + 38) / 2 
  3048. 	Menu_option_labels.trim_n_pos_y = 12 
  3049. 	bg_h = vint_object_find("menu_mid_trm_top_m", frame_h) 
  3050. 	vint_set_property(bg_h, "anchor", Menu_option_labels.trim_n_pos_x, Menu_option_labels.trim_n_pos_y) 
  3051.  
  3052. 	--	Set the clipping area 
  3053. 	vint_set_property(Menu_option_labels.clip_h, "clip_size", sel_bar_width + 10, height) 
  3054. 	 
  3055. 	Menu_active = menu_data 
  3056. 	menu_data.menu_height = height 
  3057. 	menu_data.menu_width = width 
  3058. 	 
  3059. 	Menu_new = true 
  3060.  
  3061. 	menu_update_nav_bar(Menu_active.highlighted_item) 
  3062. 	 
  3063. 	if Menu_active.on_post_show ~= nil then 
  3064. 		Menu_active.on_post_show(Menu_active) 
  3065. 	end 
  3066.  
  3067. 	btn_tips_update()	 
  3068. 	 
  3069. 	--CDPLC: added, set transition to none 
  3070. 	local transition = MENU_TRANSITION_NONE 
  3071.  
  3072. 	if transition == MENU_TRANSITION_SWAP then 
  3073. 		menu_transition_swap_begin() 
  3074. 	elseif transition == MENU_TRANSITION_SWEEP_RIGHT then 
  3075. 		menu_transition_sweep_begin(false) 
  3076. 	elseif transition == MENU_TRANSITION_SWEEP_LEFT then 
  3077. 		menu_transition_sweep_begin(true) 
  3078. 	else 
  3079. 		menu_input_block(true) 
  3080. 		menu_transition_complete() 
  3081. 	end 
  3082. end 
  3083.  
  3084. -- updates the text prop on all labels 
  3085. -- called when menu is built or scrolls 
  3086. function menu_update_labels() 
  3087. 	local h, ch, item, label_w, control 
  3088. 	 
  3089. 	local control_min_width = 0 
  3090. 	local control_width = 0 
  3091. 	 
  3092. 	-- set the labels and hide unused 
  3093. 	for i = 0, Menu_option_labels.max_rows - 1 do 
  3094. 		h = Menu_option_labels[i].label_h 
  3095.  
  3096. 		item = Menu_active.first_vis_item + i 
  3097. 		 
  3098. 		if item < Menu_active.num_items then 
  3099. 			local item_type = Menu_active[item].type 
  3100. 			vint_set_property(h, "visible", true) 
  3101.  
  3102. 			if Menu_active[item].label_crc ~= nil then 
  3103. 				vint_set_property(h, "text_tag_crc", Menu_active[item].label_crc) 
  3104. 			else 
  3105. 				vint_set_property(h, "text_tag", Menu_active[item].label) 
  3106. 			end 
  3107.  
  3108. 			if Menu_active[item].disabled == true and Menu_active[item].dimm_disabled == true then 
  3109. 				if Menu_active[item].it_is_caption_label == true then 
  3110. 					vint_set_property(h, "tint", 0.2, 0.5, 0.8 ) 
  3111. 				else 
  3112. 					vint_set_property(h, "tint", 0.17, 0.17, 0.2) 
  3113. 				end 
  3114. 			else 
  3115. 				vint_set_property(h, "tint", 0.364, 0.368, 0.376) 
  3116. 			end 
  3117.  
  3118. 			-- maybe hide stripe 
  3119. 			if Menu_control_callbacks[Menu_active[item].type].hide_label_stripe == true then 
  3120. 				vint_set_property(Menu_option_labels[i].stripe_h, "visible", false) 
  3121. 			else 
  3122. 				vint_set_property(Menu_option_labels[i].stripe_h, "visible", true) 
  3123. 			end 
  3124.  
  3125. 			-- update control 
  3126. 			local cb = Menu_control_callbacks[item_type] 
  3127. 			if cb ~= nil then 
  3128. 				if cb.on_show ~= nil then 
  3129. 					cb.on_show(Menu_option_labels[i], Menu_active[item]) 
  3130. 				else 
  3131. 					if Menu_option_labels[i].control ~= nil then 
  3132. 						menu_release_control(Menu_option_labels[i].control) 
  3133. 						Menu_option_labels[i].control = nil 
  3134. 					end 
  3135. 				end 
  3136. 				 
  3137. 				--set width of control using the base control width of the menu set in menu_show() 
  3138. 				if cb.set_width ~= nil then 
  3139. 					cb.set_width(Menu_option_labels[i], Menu_active[item], Menu_active.control_width) 
  3140. 				end	 
  3141.  
  3142. 				-- hmmmm... is this right?  -sdr 
  3143. 				if cb.on_leave ~= nil then 
  3144. 					cb.on_leave(Menu_option_labels[i], Menu_active[item]) 
  3145. 				end 
  3146. 			end 
  3147. 				 
  3148. 		else 
  3149. 			vint_set_property(Menu_option_labels[i].stripe_h, "visible", false) 
  3150. 			vint_set_property(h, "visible", false) 
  3151. 		end 
  3152. 	end 
  3153. 	 
  3154. 	-- update scroll bar 
  3155. 	if Menu_option_labels.scroll_bar_visible == true then 
  3156. 		menu_scroll_bar_set_thumb_pos(Menu_active.first_vis_item / (Menu_active.num_items - Menu_option_labels.max_rows) ) 
  3157. 	end 
  3158. end 
  3159.  
  3160. function limit(value, low, high) 
  3161. 	if value < low then 
  3162. 		value = low 
  3163. 	elseif value > high then 
  3164. 		value = high 
  3165. 	end 
  3166. 	 
  3167. 	return value 
  3168. end 
  3169.  
  3170. -- moves the nav bar and checks for possible scrolling 
  3171. function menu_update_nav_bar(new_item) 
  3172. 	-- check to see if we need to scroll 
  3173. 	local first_vis_item = 0 
  3174. 	local prev_first_vis_item = Menu_active.first_vis_item 
  3175. 	local prev_row = Menu_active.highlighted_item - prev_first_vis_item 
  3176. 	 
  3177. 	if Menu_active.num_items > Menu_option_labels.max_rows then 
  3178. 		local half_max = floor(Menu_option_labels.max_rows / 2) 
  3179. 		first_vis_item = limit(new_item - half_max, 0, Menu_active.num_items - Menu_option_labels.max_rows) 
  3180. 	end 
  3181. 	 
  3182. 	-- maybe scroll 
  3183. 	if first_vis_item ~= Menu_active.first_vis_item then 
  3184. 		Menu_active.first_vis_item = first_vis_item 
  3185. 		menu_update_labels() 
  3186. 	else 
  3187. 		-- Unhighlight control 
  3188. 		if Menu_option_labels[prev_row].control ~= nil then 
  3189. 			local cb = Menu_control_callbacks[Menu_option_labels[prev_row].control.type].on_leave 
  3190. 			if cb ~= nil then 
  3191. 				cb(Menu_option_labels[prev_row], Menu_active[Menu_active.highlighted_item]) 
  3192. 			end 
  3193. 		end 
  3194. 	end 
  3195. 	 
  3196. 	-- highlight current control 
  3197. 	if Menu_active.num_items < 1 then 
  3198. 		-- stop crashies 
  3199. 		return 
  3200. 	end 
  3201. 	 
  3202. 	-- no item highlighted - not entirely sure what Jeff wants so I'll just bail 
  3203. 	if new_item == -1 then 
  3204. 		return 
  3205. 	end 
  3206.  
  3207. 	local hilight_row = new_item - first_vis_item 
  3208. 	 
  3209. 	------ 
  3210. 	-- Move the on enter callback from THIS spot to the bottom so that 
  3211. 	-- the hl_bar_sel_label would be correct when its called. 
  3212. 	-- Not sure if it can break anything anywhere - DAD 1/8/08 
  3213. 	------ 
  3214. 	 
  3215. 	if Menu_fading_label ~= 0 then 
  3216. 		vint_set_property(Menu_fading_label, "tint", 0.3647, 0.3686, 0.3765) 
  3217. 		Menu_fading_label = 0 
  3218. 	end 
  3219. 	 
  3220. 	if Menu_control_callbacks[Menu_active[new_item].type].hide_select_bar == true then 
  3221. 		--Control type so we do different types of fading 
  3222. 		 
  3223. 		vint_set_property(Menu_option_labels.hl_bar, "visible", false) 
  3224. 		 
  3225. 		local anim_h = vint_object_find("menu_option_label_in_anim") 
  3226. 		vint_set_property(anim_h, "target_handle", Menu_option_labels[hilight_row].label_h) 
  3227. 		local twn_h = vint_object_find("menu_option_label_in_tint_twn", anim_h) 
  3228. 		vint_set_property(twn_h, "state", "paused") 
  3229. 		lua_play_anim(anim_h, 0) 
  3230. 	else 
  3231. 		vint_set_property(Menu_option_labels.hl_bar, "visible", true) 
  3232. 		 
  3233. 		--Move Highlight Bar 
  3234. 		vint_set_property(Menu_option_labels.hl_bar, "anchor", 
  3235. 			Menu_option_labels[hilight_row].anchor_x - 5, Menu_option_labels[hilight_row].anchor_y) 
  3236.  
  3237. 		--Update text of highlight bar 
  3238. 		local hl_bar_label_h = vint_object_find("menu_sel_bar_label", Menu_option_labels.hl_bar) 
  3239. 		local menu_item = Menu_active[new_item] 
  3240. 		 
  3241. 		local show_label = false 
  3242. 		if menu_item.label_crc ~= nil then 
  3243. 			vint_set_property(hl_bar_label_h, "text_tag_crc", menu_item.label_crc) 
  3244. 			show_label = true 
  3245. 		elseif menu_item.label ~= nil then 
  3246. 			vint_set_property(hl_bar_label_h, "text_tag", menu_item.label) 
  3247. 			show_label = true 
  3248. 		end 
  3249. 		 
  3250. 		vint_set_property(hl_bar_label_h, "visible", show_label) 
  3251.  
  3252. 		--Retarget Nav Fade In Animation and Play 
  3253. 		vint_set_property(vint_object_find("sel_bar_in_twn"), "target_handle", Menu_option_labels.hl_bar) 
  3254. 		lua_play_anim(vint_object_find("menu_sel_bar_fade_in_anim"), 0) 
  3255. 	end 
  3256.  
  3257. 	if Menu_new == false then 
  3258. 		 
  3259. 		local item_diff = hilight_row + Menu_active.highlighted_item - new_item 
  3260. 		-- if we have scrolled, move all of the fading hl bars 
  3261. 		if prev_first_vis_item ~= first_vis_item then 
  3262. 			for index, value in Menu_nav_bars do 
  3263. 				--calculate offset from current first vis row 
  3264. 				local highlight_row_offset = value.item_num - first_vis_item 
  3265.  
  3266. 				if highlight_row_offset >= Menu_option_labels.max_rows or highlight_row_offset < 0 then 
  3267. 					-- kill the item if it has scrolled off the screen 
  3268. 					menu_duplicate_nav_bar_kill(index) 
  3269. 				else 
  3270. 					-- alls good, move it 
  3271. 					vint_set_property(value.obj_h, "anchor", 
  3272. 						Menu_option_labels[highlight_row_offset].anchor_x - 5, Menu_option_labels[highlight_row_offset].anchor_y) 
  3273. 				end 
  3274. 			end 
  3275. 		end 
  3276.  
  3277. 		if item_diff < Menu_option_labels.max_rows and item_diff >= 0 then 
  3278. 			local target_row = Menu_active.highlighted_item - first_vis_item 
  3279. 				 
  3280. 			if Menu_control_callbacks[Menu_active[Menu_active.highlighted_item].type].hide_select_bar == true then 
  3281. 				 
  3282. 					if Menu_control_callbacks[Menu_active[new_item].type].hide_select_bar ~= true then 
  3283. 						--Disable the fade in tween only if the new item doesn't have a select bar. 
  3284. 						--This is because the tween maintains its old target so it needs to be turned off. 
  3285. 						local anim_h = vint_object_find("menu_option_label_in_anim") 
  3286. 						vint_set_property(anim_h, "is_paused", true) 
  3287. 						local twn_h = vint_object_find("menu_option_label_in_tint_twn", anim_h) 
  3288. 						vint_set_property(twn_h, "state", "disabled") 
  3289. 					end 
  3290. 		 
  3291. 				vint_set_property(Menu_option_labels[target_row].label_h, "tint", 0.3647, 0.3686, 0.3765) 
  3292. 			else 
  3293. 				-- dup nav bar and fade it 
  3294. 				local nav_bar_clone = vint_object_clone(Menu_option_labels.hl_bar) 
  3295. 				vint_set_property(nav_bar_clone, "anchor", Menu_option_labels[target_row].anchor_x - 5, Menu_option_labels[target_row].anchor_y) 
  3296.  
  3297. 				--Clone, Retarget and Play Animation to fade out 
  3298. 				local nav_bar_anim_clone = vint_object_clone(vint_object_find("menu_sel_bar_fade_out_anim")) 
  3299. 				local nav_bar_twn = vint_object_find("sel_bar_out_twn", nav_bar_anim_clone) 
  3300. 				vint_set_property(nav_bar_twn, "target_handle", nav_bar_clone) 
  3301. 				vint_set_property(nav_bar_twn, "end_event", "menu_duplicate_nav_bar_kill") 
  3302. 				lua_play_anim(nav_bar_anim_clone, 0) 
  3303. 				 
  3304. 				--Update text of highlight bar 
  3305. 				local hl_bar_label_h = vint_object_find("menu_sel_bar_label", nav_bar_clone) 
  3306. 				 
  3307. 				if Menu_active[Menu_active.highlighted_item].label_crc ~= nil then 
  3308. 					vint_set_property(hl_bar_label_h, "text_tag_crc", Menu_active[Menu_active.highlighted_item].label_crc) 
  3309. 				else 
  3310. 					vint_set_property(hl_bar_label_h, "text_tag", Menu_active[Menu_active.highlighted_item].label) 
  3311. 				end 
  3312. 				 
  3313. 				--Store References 
  3314. 				Menu_nav_bars[nav_bar_twn] = { 
  3315. 					obj_h = nav_bar_clone, 
  3316. 					anim_h = nav_bar_anim_clone, 
  3317. 					twn_h =  nav_bar_twn, 
  3318. 					item_num = Menu_active.highlighted_item, 
  3319. 				} 
  3320. 			end 
  3321. 		end 
  3322. 	else 
  3323. 		--Retarget Pulse Animation 
  3324. 		local target = vint_object_find("menu_sel_bar_e_hl", Menu_option_labels.hl_bar) 
  3325. 		vint_set_property(vint_object_find("menu_item_pulse_0_tween"), "target_handle", target) 
  3326. 		target = vint_object_find("menu_sel_bar_w_hl", Menu_option_labels.hl_bar) 
  3327. 		vint_set_property(vint_object_find("menu_item_pulse_1_tween"), "target_handle", target) 
  3328. 		 
  3329. 		Menu_new = false 
  3330. 	end 
  3331. 	 
  3332. 	Menu_option_labels.highlighted = hilight_row 
  3333. 	Menu_active.highlighted_item = new_item 
  3334. 	 
  3335. 	local cb = Menu_control_callbacks[Menu_active[new_item].type] 
  3336. 	if cb ~= nil then 
  3337. 		if cb.on_enter ~= nil then 
  3338. 			cb.on_enter(Menu_option_labels[hilight_row], Menu_active[new_item]) 
  3339. 		end 
  3340. 	end 
  3341.  
  3342. end 
  3343.  
  3344. function menu_duplicate_nav_bar_kill(tween_h, event_name)	 
  3345. 	for index, value in Menu_nav_bars do 
  3346. 		if value.twn_h == tween_h then 
  3347. 			vint_object_destroy(value.obj_h) 
  3348. 			vint_object_destroy(value.anim_h) 
  3349. 			vint_set_property(value.label_h, "tint", 0.364, 0.368, 0.376) 
  3350. 			Menu_nav_bars[index] = nil 
  3351. 			return 
  3352. 		end 
  3353. 	end 
  3354. end 
  3355.  
  3356. function menu_text_slider_show(menu_label, menu_data) 
  3357. 	local control = menu_label.control 
  3358.  
  3359. 	if control ~= nil then 
  3360. 		if control.type ~= MENU_ITEM_TYPE_TEXT_SLIDER then 
  3361. 			menu_release_control(control) 
  3362. 			control = nil 
  3363. 		end 
  3364. 	end 
  3365.  
  3366. 	if control == nil then 
  3367. 		local control_h = vint_object_clone(vint_object_find("menu_text_slider"), Menu_option_labels.control_parent) 
  3368. 		control = { grp_h = control_h, type = MENU_ITEM_TYPE_TEXT_SLIDER, is_highlighted = true} 
  3369. 	end 
  3370.  
  3371. 	menu_label.control = control 
  3372. 	vint_set_property(control.grp_h, "visible", true) 
  3373. 	 
  3374. 	--Check if the item is selected and set its depth based on that 
  3375. 	if menu_label.control.is_highlighted == true then 
  3376. 		vint_set_property(control.grp_h, "depth", 0) 
  3377. 	else 
  3378. 		--reset the depth 
  3379. 		vint_set_property(control.grp_h, "depth", menu_label.depth) 
  3380. 	end 
  3381. 	 
  3382. 	--Reposition Slider with the menu label 
  3383. 	vint_set_property(control.grp_h, "anchor", menu_label.anchor_x + Menu_option_labels.max_label_w + 5, menu_label.anchor_y) 
  3384.  
  3385. 	--menu_label.slider_disabled = true 
  3386. 	if menu_data.slider_disabled == true then 
  3387. 		--Hide Arrows 
  3388. 		local arrow_h = vint_object_find("text_slider_arrow_w", control.grp_h) 
  3389. 		vint_set_property(arrow_h, "visible", false) 
  3390. 		local arrow_h = vint_object_find("text_slider_arrow_e", control.grp_h) 
  3391. 		vint_set_property(arrow_h, "visible", false) 
  3392. 		 
  3393. 		--Tint BG Reset 
  3394. 		local large_frame_h = vint_object_find("large_frame", control.grp_h) 
  3395. 		local bg_h = vint_object_find("text_slider_large_frame_bg", large_frame_h) 
  3396. 		vint_set_property(bg_h, "tint", .8, .8, .8) 
  3397. 		bg_h = vint_object_find("text_slider_large_frame_bg_hl", large_frame_h) 
  3398. 		vint_set_property(bg_h, "tint", .8, .8, .8) 
  3399. 	else 
  3400. 		--Show Arrows 
  3401. 		local arrow_h = vint_object_find("text_slider_arrow_w", control.grp_h) 
  3402. 		vint_set_property(arrow_h, "visible", true) 
  3403. 		local arrow_h = vint_object_find("text_slider_arrow_e", control.grp_h) 
  3404. 		vint_set_property(arrow_h, "visible", true) 
  3405. 		 
  3406. 		--Tint BG  
  3407. 		local large_frame_h = vint_object_find("large_frame", control.grp_h) 
  3408. 		local bg_h = vint_object_find("text_slider_large_frame_bg", large_frame_h) 
  3409. 		vint_set_property(bg_h, "tint", 1, 1, 1) 
  3410. 		bg_h = vint_object_find("text_slider_large_frame_bg_hl", large_frame_h) 
  3411. 		vint_set_property(bg_h, "tint", 1, 1, 1) 
  3412. 	end 
  3413. 		 
  3414. 	if menu_data.text_slider_values.cur_value == nil then 
  3415. 		menu_data.text_slider_values.cur_value = 0 
  3416. 	end 
  3417. 	 
  3418. 	menu_text_slider_update_value(menu_label, menu_data) 
  3419. end 
  3420.  
  3421. function menu_text_slider_on_enter(menu_label, menu_data) 
  3422. 	if menu_label.control.is_highlighted == false then 
  3423. 		local g = menu_label.control.grp_h 
  3424. 		vint_set_property(vint_object_find("large_frame", g), "visible", true) 
  3425. 		vint_set_property(vint_object_find("small_frame", g), "visible", false) 
  3426. 		vint_set_property(menu_label.control.grp_h, "depth", 0) 
  3427. 		vint_set_property(vint_object_find("value_text", g), "scale", 1, 1) 
  3428. 		vint_set_property(vint_object_find("text_slider_arrow_w", g), "tint", 0.8941, 0.8489, 0.051) 
  3429. 		vint_set_property(vint_object_find("text_slider_arrow_e", g), "tint", 0.8941, 0.8489, 0.051) 
  3430. 			 
  3431. 		--Trigger pulsing animation	 
  3432. 		menu_label.control.anim_pulse_h = vint_object_clone(vint_object_find("menu_text_slider_pulse_anim")) 
  3433. 		vint_set_property(menu_label.control.anim_pulse_h, "target_handle", g) 
  3434. 		lua_play_anim(menu_label.control.anim_pulse_h, 0) 
  3435. 		 
  3436. 		menu_label.control.is_highlighted = true 
  3437. 		 
  3438. 		if menu_label.input1 == nil then  
  3439. 			menu_label.input1 = vint_subscribe_to_input_event(nil, "nav_right", "menu_text_slider_nav_right", 5) 
  3440. 		end 
  3441. 		if menu_label.input2 == nil then  
  3442. 			menu_label.input2 = vint_subscribe_to_input_event(nil, "nav_left", "menu_text_slider_nav_left", 5) 
  3443. 		end 
  3444. 	end 
  3445. end 
  3446.  
  3447. function menu_text_slider_on_leave(menu_label, menu_data) 
  3448. 	if menu_label.control == nil then 
  3449. 		debug_print("vint", "Control is nil for: " .. menu_data.label .. "\n") 
  3450. 		return 
  3451. 	end 
  3452.  
  3453. 	 
  3454. 	if menu_label.control.is_highlighted ~= false then 
  3455. 		 
  3456. 		local g = menu_label.control.grp_h 
  3457. 		vint_set_property(vint_object_find("large_frame", g), "visible", false) 
  3458. 		vint_set_property(vint_object_find("small_frame", g), "visible", true) 
  3459. 		vint_set_property(menu_label.control.grp_h, "depth", menu_label.depth) 
  3460. 		 
  3461. 		vint_set_property(vint_object_find("value_text", g), "scale", 0.68, 0.68) 
  3462. 		vint_set_property(vint_object_find("text_slider_arrow_w", g), "tint", 0.3647, 0.3725, 0.3804) 
  3463. 		vint_set_property(vint_object_find("text_slider_arrow_e", g), "tint", 0.3647, 0.3725, 0.3804) 
  3464. 		vint_set_property(vint_object_find("text_slider_arrow_w", g), "offset", -11, -15) 
  3465. 		vint_set_property(vint_object_find("text_slider_arrow_e", g), "offset", -11, -15) 
  3466. 		menu_label.control.is_highlighted = false 
  3467.  
  3468. 		if menu_label.control.anim_pulse_h ~= nil then 
  3469. 			vint_object_destroy(menu_label.control.anim_pulse_h) 
  3470. 		end 
  3471. 		 
  3472. 		if menu_label.input1 ~= nil then 
  3473. 			vint_unsubscribe_to_input_event(menu_label.input1) 
  3474. 			vint_unsubscribe_to_input_event(menu_label.input2) 
  3475. 			menu_label.input1 = nil 
  3476. 			menu_label.input2 = nil 
  3477. 		end 
  3478. 	end 
  3479. end 
  3480.  
  3481. function menu_text_slider_release(control) 
  3482. 	vint_object_destroy(control.grp_h) 
  3483. end 
  3484.  
  3485. function menu_text_slider_update_value(menu_label, menu_data) 
  3486. 	local values = menu_data.text_slider_values 
  3487. 	local v = values[values.cur_value] 
  3488. 	 
  3489. 	if menu_label.control == nil then 
  3490. 		return 
  3491. 	end 
  3492.  
  3493. 	local h = vint_object_find("value_text", menu_label.control.grp_h) 
  3494. 	 
  3495. 	if v.label_crc ~= nil then 
  3496. 		vint_set_property(h, "text_tag_crc", v.label_crc) 
  3497. 	else 
  3498. 		vint_set_property(h, "text_tag", v.label) 
  3499. 	end 
  3500. 	 
  3501. --[[  DAD: 5/12/08 - If text sliders start acting funky, this might need to go back here. Moved it to the nav functions where the value actually IS changing 
  3502. 	if menu_data.on_value_update ~= nil then 
  3503. 		menu_data.on_value_update(menu_label, menu_data) 
  3504. 	end 
  3505. ]] 
  3506. end 
  3507.  
  3508. function menu_text_slider_nav_right() 
  3509. 	local menu_label = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  3510. 	local menu_data = Menu_active[Menu_active.highlighted_item] 
  3511. 	local values = menu_data.text_slider_values 
  3512. 	 
  3513. 	if menu_label == nil or menu_data == nil or values == nil then 
  3514. 		return 
  3515. 	end 
  3516. 	 
  3517. 	if menu_input_is_blocked() then 
  3518. 		return 
  3519. 	end 
  3520. 	 
  3521. 	if menu_data.slider_disabled == true then 
  3522. 		--Do nothing, control is disabled 
  3523. 		return 
  3524. 	end 
  3525. 	 
  3526. 		--Loop to increment over disabled slots... 
  3527. 	local value_not_disabled = false 
  3528. 	local option_count = 0 
  3529. 	while value_not_disabled == false do 
  3530. 		 
  3531. 		--Increment current value 
  3532. 		values.cur_value = values.cur_value + 1 
  3533. 		 
  3534. 		--Verify that its not the last in the list 
  3535. 		if values.cur_value >= values.num_values then 
  3536. 			values.cur_value = 0 
  3537. 		end 
  3538. 		 
  3539. 		--If the item is not disabled, then get out of our loop... 
  3540. 		if menu_data.text_slider_values[values.cur_value].disabled ~= true then 
  3541. 			value_not_disabled = true 
  3542. 		end 
  3543. 		 
  3544. 		--Increment option counter 
  3545. 		option_count = option_count + 1 
  3546. 		 
  3547. 		if option_count > values.num_values then 
  3548. 			--We've superceeded our loop count so, All items are disabled for whatever reason... do not update 
  3549. 			return 
  3550. 		end 
  3551. 	end 
  3552. 	 
  3553. 	menu_text_slider_update_value(menu_label, menu_data) 
  3554. 	audio_play(Menu_sound_value_nav) 
  3555. 	 
  3556. 	if menu_data.on_value_update ~= nil then 
  3557. 		menu_data.on_value_update(menu_label, menu_data) 
  3558. 	end 
  3559. 	 
  3560. end 
  3561.  
  3562. function menu_text_slider_nav_left() 
  3563. 	local menu_label = Menu_option_labels[Menu_active.highlighted_item - Menu_active.first_vis_item] 
  3564. 	local menu_data = Menu_active[Menu_active.highlighted_item] 
  3565. 	local values = menu_data.text_slider_values 
  3566. 	 
  3567. 	if menu_label == nil or menu_data == nil or values == nil then 
  3568. 		return 
  3569. 	end 
  3570. 	 
  3571. 	if menu_input_is_blocked() then 
  3572. 		return 
  3573. 	end 
  3574. 	 
  3575. 	if menu_data.slider_disabled == true then 
  3576. 		--Do nothing, control is disabled 
  3577. 		return 
  3578. 	end 
  3579. 	 
  3580. 	--Loop to increment over disabled slots... 
  3581. 	local value_not_disabled = false 
  3582. 	local option_count = 0 
  3583. 	while value_not_disabled == false do 
  3584. 		 
  3585. 		--Increment current value 
  3586. 		values.cur_value = values.cur_value - 1 
  3587. 		 
  3588. 		--Verify that its not the last in the list 
  3589. 		if values.cur_value < 0 then 
  3590. 			values.cur_value = values.num_values - 1 
  3591. 		end 
  3592. 		 
  3593. 		--If the item is not disabled, then get out of our loop... 
  3594. 		if menu_data.text_slider_values[values.cur_value].disabled ~= true then 
  3595. 			value_not_disabled = true 
  3596. 		end 
  3597. 		 
  3598. 		--Increment option counter 
  3599. 		option_count = option_count + 1 
  3600. 		 
  3601. 		if option_count > values.num_values then 
  3602. 			--We've superceeded our loop count so, All items are disabled for whatever reason... do not update 
  3603. 			return 
  3604. 		end 
  3605. 	end	 
  3606. 	 
  3607. 	menu_text_slider_update_value(menu_label, menu_data) 
  3608. 	audio_play(Menu_sound_value_nav) 
  3609. 	 
  3610. 	if menu_data.on_value_update ~= nil then 
  3611. 		menu_data.on_value_update(menu_label, menu_data) 
  3612. 	end 
  3613. end 
  3614.  
  3615. function menu_text_slider_get_min_width(menu_item) 
  3616.  
  3617. 	--Get length of slider variable 
  3618. 	local slider_values = menu_item.text_slider_values 
  3619. 	local text_label 
  3620. 	local text_h = vint_object_find("value_text", vint_object_find("menu_text_slider")) 
  3621. 	 
  3622. 	--Reset the scale of the text to full size 
  3623. 	vint_set_property(text_h, "scale", 1, 1) 
  3624.  
  3625. 	local width = 0 
  3626. 	local min_width = 0 
  3627. 	local v 
  3628. 	--Check all the values within slider values 
  3629. 	for i = 0, slider_values.num_values - 1  do 
  3630. 		v = slider_values[i] 
  3631. 		if v.label_crc ~= nil then 
  3632. 			vint_set_property(text_h, "text_tag_crc", v.label_crc) 
  3633. 		else 
  3634. 			vint_set_property(text_h, "text_tag", v.label) 
  3635. 		end 
  3636. 		 
  3637. 		width = element_get_actual_size(text_h)		 
  3638. 		if width > min_width then 
  3639. 			min_width = width 
  3640. 		end 
  3641. 	end 
  3642. 	 
  3643. 	return floor(min_width + 57) 
  3644. end 
  3645.  
  3646. function menu_info_box_get_min_width(menu_item) 
  3647. 	 
  3648. 	--Get length of slider variable 
  3649. 	local text_h = vint_object_find("value_text", vint_object_find("menu_text_slider")) 
  3650. 	 
  3651. 	if menu_item.info_text_crc ~= nil then 
  3652. 		vint_set_property(text_h, "text_tag_crc", menu_item.info_text_crc) 
  3653. 	else 
  3654. 		vint_set_property(text_h, "text_tag",  menu_item.info_text_str) 
  3655. 	end 
  3656. 	 
  3657. 	--Reset the scale of the text to full size 
  3658. 	vint_set_property(text_h, "scale", 1, 1) 
  3659. 	 
  3660. 	--Check its width 
  3661. 	local min_width = element_get_actual_size(text_h)	 
  3662. 	-- return floor(min_width + 57) -- 57 is a nice looking number (I like 5 in general)... but personally I prefer 94 
  3663. 	return floor(min_width + 94) 
  3664. end 
  3665. --------------------[ PALETTE CONTROL ]---------------------- 
  3666.  
  3667. MENU_PALETTE_SWATCH_SCALE_SMALL	= 0.65 
  3668. MENU_PALETTE_SWATCH_SCALE_BIG		= 1 
  3669.  
  3670. function menu_pallette_update_selected(menu_label, menu_data, new_index) 
  3671. 	local colors = menu_data.palette_colors 
  3672. 	for i = 0, 2 do 
  3673. 		local swatch = vint_object_find("swatch_color_"..i, menu_label.control.grp_h) 
  3674. 		 
  3675. 		if i < colors.num_colors then 
  3676. 			if i == new_index then 
  3677. 				vint_set_property(swatch, "scale", MENU_PALETTE_SWATCH_SCALE_BIG, MENU_PALETTE_SWATCH_SCALE_BIG) 
  3678. 				vint_set_property(swatch, "depth", 0) 
  3679. 				 
  3680. 				local x = vint_get_property(swatch, "anchor") 
  3681. 				vint_set_property(vint_object_find("arrow_w", menu_label.control.grp_h), "anchor", x - 12, 0) 
  3682. 				vint_set_property(vint_object_find("arrow_e", menu_label.control.grp_h), "anchor", x + 80, 0) 
  3683. 			else 
  3684. 				vint_set_property(swatch, "depth", 50) 
  3685. 				vint_set_property(swatch, "scale", MENU_PALETTE_SWATCH_SCALE_SMALL, MENU_PALETTE_SWATCH_SCALE_SMALL) 
  3686. 			end 
  3687. 		else 
  3688. 			vint_set_property(swatch, "visible", false) 
  3689. 		end 
  3690. 	end 
  3691. 	 
  3692. 	menu_label.control.highlighted_index = new_index 
  3693. end 
  3694.  
  3695. function menu_palette_show(menu_label, menu_data) 
  3696. 	local control = menu_label.control 
  3697.  
  3698. 	if control ~= nil then 
  3699. 		if control.type ~= MENU_ITEM_TYPE_PALETTE then 
  3700. 			menu_release_control(control) 
  3701. 			control = nil 
  3702. 		end 
  3703. 	end 
  3704.  
  3705. 	if control == nil then 
  3706. 		local control_h = vint_object_clone(vint_object_find("menu_palette", nil, MENU_BASE_DOC_HANDLE), Menu_option_labels.control_parent) 
  3707. 		control = { grp_h = control_h, type = MENU_ITEM_TYPE_PALETTE, is_highlighted = true, highlighted_index = 0 } 
  3708. 	end 
  3709.  
  3710. 	menu_label.control = control 
  3711. 	vint_set_property(control.grp_h, "visible", true) 
  3712. 	vint_set_property(control.grp_h, "depth", menu_label.depth) 
  3713. 	vint_set_property(control.grp_h, "anchor", menu_label.anchor_x + Menu_option_labels.max_label_w + 5, 
  3714. 		menu_label.anchor_y) 
  3715.  
  3716. 	local p = menu_data.palette_colors 
  3717. 	local num_colors = p.num_colors 
  3718. 	 
  3719. 	for i = 0, 2 do 
  3720. 		local h = vint_object_find("swatch_color_"..i, control.grp_h) 
  3721. 		 
  3722. 		if i < num_colors then 
  3723. 			vint_set_property(h, "visible", true) 
  3724. 			vint_set_property(vint_object_find("fill", h), "tint", p[i].red, p[i].green, p[i].blue) 
  3725. 		else 
  3726. 			vint_set_property(h, "visible", false) 
  3727. 		end 
  3728. 	end 
  3729. 	 
  3730. 	menu_pallette_update_selected(menu_label, menu_data, 0) 
  3731. end 
  3732.  
  3733. function menu_palette_invalidate() 
  3734. 	Menu_palette_stored_index = INVALID_PALETTE_INDEX 
  3735. end 
  3736.  
  3737. function menu_palette_on_enter(menu_label, menu_data) 
  3738. 	if menu_label.control.is_highlighted == false then 
  3739. 		if Menu_palette_stored_index ~= INVALID_PALETTE_INDEX then 
  3740. 			menu_pallette_update_selected(menu_label, menu_data, Menu_palette_stored_index) 
  3741. 			Menu_palette_stored_index = INVALID_PALETTE_INDEX 
  3742. 		end 
  3743. 		 
  3744. 		local g = menu_label.control.grp_h 
  3745. 		vint_set_property(vint_object_find("swatch_color_"..menu_label.control.highlighted_index, g), "scale", 1, 1) 
  3746. 		vint_set_property(menu_label.control.grp_h, "depth", -50) 
  3747. 		 
  3748. 		if menu_data.palette_colors.num_colors > 1 then 
  3749. 			vint_set_property(vint_object_find("arrow_e", g), "visible", true) 
  3750. 			vint_set_property(vint_object_find("arrow_w", g), "visible", true) 
  3751. 			menu_label.input1 = vint_subscribe_to_input_event(nil, "nav_right", "menu_palette_nav", 5) 
  3752. 			menu_label.input2 = vint_subscribe_to_input_event(nil, "nav_left", "menu_palette_nav", 5) 
  3753. 		end 
  3754. 		 
  3755. 		menu_label.control.is_highlighted = true 
  3756. 	end 
  3757. end 
  3758.  
  3759. function menu_palette_on_leave(menu_label, menu_data) 
  3760. 	if menu_label.control.is_highlighted == true then 
  3761. 		if Menu_palette_stored_index == INVALID_PALETTE_INDEX then 
  3762. 			Menu_palette_stored_index = menu_label.control.highlighted_index 
  3763. 		end 
  3764. 		 
  3765. 		local g = menu_label.control.grp_h 
  3766. 		local hl = menu_label.control.highlighted_index 
  3767. 		 
  3768. 		if hl ~= nil then 
  3769. 			vint_set_property(vint_object_find("swatch_color_"..hl, g), "scale", MENU_PALETTE_SWATCH_SCALE_SMALL, MENU_PALETTE_SWATCH_SCALE_SMALL) 
  3770. 		end 
  3771. 		 
  3772. 		vint_set_property(menu_label.control.grp_h, "depth", menu_label.depth) 
  3773. 		vint_set_property(vint_object_find("arrow_e", g), "visible", false) 
  3774. 		vint_set_property(vint_object_find("arrow_w", g), "visible", false) 
  3775. 		menu_label.control.is_highlighted = false 
  3776.  
  3777. 		if menu_label.input1 ~= nil then 
  3778. 			vint_unsubscribe_to_input_event(menu_label.input1) 
  3779. 			vint_unsubscribe_to_input_event(menu_label.input2) 
  3780. 			menu_label.input1 = nil 
  3781. 			menu_label.input2 = nil 
  3782. 		end 
  3783. 	end 
  3784. end 
  3785.  
  3786. function menu_palette_release(control) 
  3787. 	vint_object_destroy(control.grp_h) 
  3788. end 
  3789.  
  3790. function menu_palette_nav(target, event) 
  3791. 	local menu_data = Menu_active[Menu_active.highlighted_item] 
  3792. 	local label_data = Menu_option_labels[Menu_active.highlighted_item] 
  3793. 	local colors = menu_data.palette_colors 
  3794. 	local new_idx = label_data.control.highlighted_index 
  3795.  
  3796. 	if event == "nav_right" then 
  3797. 		new_idx = new_idx + 1 
  3798. 		 
  3799. 		if new_idx >= colors.num_colors then 
  3800. 			new_idx = 0 
  3801. 		end 
  3802. 	else 
  3803. 		new_idx = new_idx - 1 
  3804. 		 
  3805. 		if new_idx < 0 then 
  3806. 			new_idx = colors.num_colors - 1 
  3807. 		end 
  3808. 	end 
  3809. 	 
  3810. 	audio_play(Menu_sound_item_nav) 
  3811. 	 
  3812. 	menu_pallette_update_selected(label_data, menu_data, new_idx) 
  3813. end 
  3814.  
  3815. --------------------[ INFO BOX CONTROL ]---------------------- 
  3816.  
  3817. function menu_info_box_show(menu_label, menu_data) 
  3818. 	local control = menu_label.control 
  3819.  
  3820. 	if control ~= nil then 
  3821. 		if control.type ~= MENU_ITEM_TYPE_INFO_BOX then 
  3822. 			menu_release_control(control) 
  3823. 			control = nil 
  3824. 		end 
  3825. 	end 
  3826.  
  3827. 	-- reuse the text slider element cluster 
  3828. 	if control == nil then 
  3829. 		local control_h = vint_object_clone(vint_object_find("menu_text_slider"), Menu_option_labels.control_parent) 
  3830. 		vint_set_property(vint_object_find("text_slider_arrow_w", control_h), "visible", false) 
  3831. 		vint_set_property(vint_object_find("text_slider_arrow_e", control_h), "visible", false) 
  3832. 		control = { grp_h = control_h, type = MENU_ITEM_TYPE_INFO_BOX,  is_highlighted = true } 
  3833. 	end 
  3834.  
  3835. 	menu_label.control = control 
  3836. 	vint_set_property(control.grp_h, "visible", true) 
  3837. 	vint_set_property(control.grp_h, "depth", menu_label.depth) 
  3838. 	vint_set_property(control.grp_h, "anchor", menu_label.anchor_x + Menu_option_labels.max_label_w + 5, 
  3839. 		menu_label.anchor_y) 
  3840. 		 
  3841. 	menu_info_box_update_value(menu_label, menu_data) 
  3842. 	 
  3843. 	--Hard code width for now 
  3844. 	menu_info_box_set_width(menu_label, menu_data, 215) 
  3845.  
  3846. 	--fix leftover events 
  3847. 	if menu_label.input1 ~= nil then 
  3848. 		vint_unsubscribe_to_input_event(menu_label.input1) 
  3849. 		vint_unsubscribe_to_input_event(menu_label.input2) 
  3850. 		menu_label.input1 = nil 
  3851. 		menu_label.input2 = nil 
  3852. 	end 
  3853. end 
  3854.  
  3855. function menu_info_box_update_value(menu_label, menu_data) 
  3856. 	if menu_label.control == nil then 
  3857. 		return 
  3858. 	end 
  3859. 	 
  3860. 	if menu_data.info_text_crc ~= nil then 
  3861. 		vint_set_property(vint_object_find("value_text", menu_label.control.grp_h), "text_tag_crc", menu_data.info_text_crc) 
  3862. 	else 
  3863. 		vint_set_property(vint_object_find("value_text", menu_label.control.grp_h), "text_tag", menu_data.info_text_str) 
  3864. 	end 
  3865. end 
  3866.  
  3867. function menu_info_box_on_enter(menu_label, menu_data) 
  3868. 	if menu_label.control.is_highlighted == false then 
  3869. 		local g = menu_label.control.grp_h 
  3870. 		vint_set_property(vint_object_find("large_frame", g), "visible", true) 
  3871. 		vint_set_property(vint_object_find("small_frame", g), "visible", false) 
  3872. 		vint_set_property(menu_label.control.grp_h, "depth", 0) 
  3873. 		vint_set_property(vint_object_find("value_text", g), "scale", 1, 1) 
  3874. 		menu_label.control.is_highlighted = true 
  3875. 		 
  3876. 		--Trigger pulsing animation	 
  3877. 		menu_label.control.anim_pulse_h = vint_object_clone(vint_object_find("menu_text_slider_pulse_anim")) 
  3878. 		vint_set_property(menu_label.control.anim_pulse_h, "target_handle", g) 
  3879. 		lua_play_anim(menu_label.control.anim_pulse_h, 0) 
  3880.  
  3881. 	end 
  3882. end 
  3883.  
  3884. function menu_info_box_on_leave(menu_label, menu_data) 
  3885. 	if menu_label.control == nil then 
  3886. 		return 
  3887. 	end 
  3888. 	 
  3889. 	if menu_label.control.is_highlighted == true then 
  3890. 		local g = menu_label.control.grp_h 
  3891. 		vint_set_property(vint_object_find("large_frame", g), "visible", false) 
  3892. 		vint_set_property(vint_object_find("small_frame", g), "visible", true) 
  3893. 		vint_set_property(menu_label.control.grp_h, "depth", menu_label.depth) 
  3894. 		vint_set_property(vint_object_find("value_text", g), "scale", 0.68, 0.68) 
  3895. 		menu_label.control.is_highlighted = false 
  3896. 		 
  3897. 		if menu_label.control.anim_pulse_h ~= nil then 
  3898. 			vint_object_destroy(menu_label.control.anim_pulse_h) 
  3899. 		end 
  3900. 	end 
  3901. end 
  3902.  
  3903. function menu_info_box_release(control) 
  3904. 	vint_object_destroy(control.grp_h) 
  3905. end 
  3906.  
  3907. function menu_info_box_set_width(menu_label, menu_data, width) 
  3908. 	--what is the width? 
  3909. 	--width is the size of the actual control... not the text 
  3910. 	 
  3911. 	--Resize parts of the box 
  3912. 	local control_h = menu_label.control.grp_h 
  3913. 	local large_frame_h = vint_object_find("large_frame", control_h) 
  3914. 	local small_frame_h = vint_object_find("small_frame", control_h) 
  3915.  
  3916. 	--Large Frame 
  3917. 	local frame_ns_h = vint_object_find("frame_ns", large_frame_h) 
  3918. 	local frame_bg_h = vint_object_find("text_slider_large_frame_bg", large_frame_h) 
  3919. 	local frame_bg2_h = vint_object_find("text_slider_large_frame_bg_hl", large_frame_h) 
  3920. 	local frame_e_h = vint_object_find("frame_e", large_frame_h) 
  3921. 	 
  3922. 	--Small Frame 
  3923. 	local s_frame_ns_h = vint_object_find("frame_ns", small_frame_h) 
  3924. 	local s_frame_bg_h = vint_object_find("frame_bg", small_frame_h) 
  3925. 	local s_frame_e_h = vint_object_find("frame_e", small_frame_h) 
  3926.  
  3927. 	--Additional right arrow 
  3928. 	local arrow_e_h = vint_object_find("text_slider_arrow_e", menu_label.control.grp_h) 
  3929. 	 
  3930. 	-- Subtract 46 from the width sent in to make the control that actual size in pixels 
  3931. 	width = width - 46 
  3932. 		 
  3933. 	--Background of frame 
  3934. 	local frame_bg_se_x, frame_bg_se_y = vint_get_property(frame_bg_h, "source_se") 
  3935. 	vint_set_property(frame_bg_h, "source_se", width, frame_bg_se_y) 
  3936. 	vint_set_property(frame_bg2_h, "source_se", width, frame_bg_se_y) 
  3937. 	 
  3938. 	local frame_bg_se_x, frame_bg_se_y = vint_get_property(s_frame_bg_h, "source_se") 
  3939. 	vint_set_property(s_frame_bg_h, "source_se", width + 2, frame_bg_se_y) 
  3940.  
  3941. 	--Middle of the frame 
  3942. 	local frame_ns_se_x, frame_ns_se_y =  vint_get_property(frame_ns_h, "source_se") 
  3943. 	vint_set_property(frame_ns_h, "source_se", width - 13, frame_ns_se_y) 
  3944. 	local frame_ns_se_x, frame_ns_se_y =  vint_get_property(s_frame_ns_h, "source_se") 
  3945. 	vint_set_property(s_frame_ns_h, "source_se", width - 12, frame_ns_se_y) 
  3946. 	 
  3947. 	--East Side of Frame 
  3948. 	local frame_e_x, frame_e_y = vint_get_property(frame_e_h, "anchor") 
  3949. 	vint_set_property(frame_e_h, "anchor", width + 10, frame_e_y) 
  3950. 	 
  3951. 	local frame_e_x, frame_e_y = vint_get_property(s_frame_e_h, "anchor") 
  3952. 	vint_set_property(s_frame_e_h, "anchor", width + 8, frame_e_y) 
  3953. 	 
  3954. 	--x = base size + 51 
  3955. 	local arrow_e_x, arrow_e_y = vint_get_property(arrow_e_h, "anchor") 
  3956. 	vint_set_property(arrow_e_h, "anchor", width + 51, arrow_e_y) 
  3957. end 
  3958.  
  3959.  
  3960. --------------------[ SELECTABLE / MARQUEE CONTROL ]---------------------- 
  3961.  
  3962. function menu_marquee_show(menu_label, menu_data) 
  3963. 	local control = menu_label.control 
  3964. 	 
  3965. 	if control ~= nil then 
  3966. 		if control.type ~= MENU_ITEM_TYPE_MARQUEE then 
  3967. 			menu_release_control(control) 
  3968. 			control = nil 
  3969. 		end 
  3970. 	end 
  3971.  
  3972. 	if control == nil then 
  3973. 		control = { type = MENU_ITEM_TYPE_MARQUEE } 
  3974. 	end 
  3975. 	 
  3976. 	menu_label.control = control 
  3977. end 
  3978.  
  3979. function menu_marquee_on_enter(menu_label, menu_data) 
  3980. 	-- vint_object_create("name", "tween", vint_object_find("root_animation")) 
  3981. 	-- properties: target_handle, target_property, start_value, end_value, start_time (in seconds), duration (in seconds), end_event (callback) 
  3982. 	-- probably get screen_size for text width -  
  3983. 	-- start_time: vint_get_time_index() (its in seconds) 
  3984. 	-- Globals for scroll_speed and delay amount for tweaking are a good idea 
  3985. 	-- end_event: "function_name"  - Start new thread for the delays and restarting to not muck things up. 
  3986.  
  3987. 	local hl_bar_label_h = vint_object_find("menu_sel_bar_label", Menu_option_labels.hl_bar) 
  3988.  
  3989. 	local text_width, text_height = vint_get_property(hl_bar_label_h, "screen_size") 
  3990. 	local clip_x, clip_y = vint_get_property(Menu_option_labels.hl_clip, "clip_size") 
  3991. 	 
  3992. 	local clipped_width = text_width - (clip_x - MENU_MARQUEE_SCROLL_CORRECTION) 
  3993.  
  3994. 	-- Doesn't need to scroll 
  3995. 	if clipped_width < 0 then 
  3996. 		vint_set_property(Menu_marquee_info.label_h, "offset", 0, 0)	 
  3997. 		return 
  3998. 	end 
  3999. 	 
  4000. 	local twn = vint_object_create("marquee_tween", "tween", vint_object_find("root_animation")) 
  4001. 	vint_set_property(twn, "target_handle", hl_bar_label_h) 
  4002. 	vint_set_property(twn, "target_property", "offset") 
  4003. 	vint_set_property(twn, "start_value", 0, 0) 
  4004. 	vint_set_property(twn, "end_value", 0 - clipped_width, 0)	 
  4005. 	vint_set_property(twn, "duration", MENU_MARQUEE_SPEED * clipped_width) 
  4006. 	vint_set_property(twn, "end_event", "menu_marquee_twn_end") 
  4007. 	vint_set_property(twn, "start_time", vint_get_time_index() + MENU_MARQUEE_DELAY) 
  4008. 	if Menu_marquee_info.twn ~= nil then 
  4009. 		vint_object_destroy(Menu_marquee_info.twn) 
  4010. 	end 
  4011. 	 
  4012. 	Menu_marquee_info.twn = twn 
  4013. 	Menu_marquee_info.label_h = hl_bar_label_h 
  4014. 	Menu_marquee_info.clipped_width = clipped_width 
  4015. end 
  4016.  
  4017. function menu_marquee_twn_end() 
  4018.    if Menu_marquee_info.thread ~= nil then 
  4019. 		thread_kill(Menu_marquee_info.thread) 
  4020. 	end 
  4021. 	 
  4022. 	Menu_marquee_info.thread = thread_new("menu_marquee_twn_restart") 
  4023. end 
  4024.  
  4025. function menu_marquee_twn_restart() 
  4026. 	delay(MENU_MARQUEE_DELAY) 
  4027. 	vint_set_property(Menu_marquee_info.label_h, "offset", 0, 0) 
  4028. 	delay(MENU_MARQUEE_DELAY) 
  4029. 	vint_set_property(Menu_marquee_info.twn, "state", "waiting") 
  4030. 	vint_set_property(Menu_marquee_info.twn, "start_time", vint_get_time_index()) 
  4031. end 
  4032.  
  4033. function menu_marquee_on_leave(menu_label, menu_data) 
  4034. 	if Menu_marquee_info.thread ~= nil then 
  4035. 		thread_kill(Menu_marquee_info.thread) 
  4036. 		Menu_marquee_info.thread = nil 
  4037. 	end 
  4038. 	 
  4039. 	if Menu_marquee_info.twn ~= nil then 
  4040. 		vint_object_destroy(Menu_marquee_info.twn) 
  4041. 		Menu_marquee_info.twn = nil 
  4042. 	end 
  4043. 	 
  4044. 	vint_set_property(Menu_marquee_info.label_h, "offset", 0, 0)	 
  4045. end 
  4046.  
  4047. ---------------------------------------------------------------------------------- 
  4048. ------------------------------------[ Footer ]------------------------------------ 
  4049. ---------------------------------------------------------------------------------- 
  4050. Menu_footer_price_h				= 0 
  4051. Menu_footer_style_h				= 0 
  4052. Menu_footer_label_h				= 0 
  4053.  
  4054. function menu_footer_build_style_footer(menu_data) 
  4055. 	local footer = menu_data.footer 
  4056. 	if footer ~= nil and footer.footer_grp ~= nil then 
  4057. 		vint_object_destroy(footer.footer_grp) 
  4058. 	end 
  4059. 	 
  4060. 	menu_data.footer = { } 
  4061.  
  4062. 	local grp = vint_object_clone(vint_object_find("style_footer", nil, MENU_BASE_DOC_HANDLE), Menu_option_labels.control_parent) 
  4063. 	vint_set_property(grp, "visible", true) 
  4064. 	menu_data.footer.footer_grp = grp 
  4065. 	Menu_footer_price_h = vint_object_find("price_amount", grp) 
  4066. 	Menu_footer_style_h = vint_object_find("style_amount", grp) 
  4067. 	Menu_footer_label_h = vint_object_find("price_label", grp) 
  4068. 	vint_set_property(Menu_footer_label_h, "text_tag", "FOOTER_PRICE") 
  4069. end 
  4070.  
  4071. function menu_footer_update_style_footer(price, style, tint_enable) 
  4072. 	 
  4073. 	vint_set_property(Menu_footer_price_h, "visible", true) 
  4074. 	vint_set_property(Menu_footer_style_h, "visible", true) 
  4075. 	vint_set_property(Menu_footer_label_h, "visible", true) 
  4076. 	 
  4077. 	--Localize style tag 
  4078. 	local style_value = { [0] = style } 
  4079. 	local style_string = vint_insert_values_in_string("STORE_ITEM_STYLE_AWARD", style_value) 
  4080. 	 
  4081. 	if tint_enable == true then 
  4082. 		vint_set_property(Menu_footer_price_h, "tint", 0.88, 0.749, 0.05) 
  4083. 	else 
  4084. 		vint_set_property(Menu_footer_price_h, "tint", 1, 0, 0) 
  4085. 	end 
  4086. 	vint_set_property(Menu_footer_price_h, "text_tag", "$".. format_cash(price)) 
  4087. 	vint_set_property(Menu_footer_style_h, "text_tag", style_string) 
  4088. end 
  4089.  
  4090. function	menu_footer_remove_style_footer(menu_data) 
  4091. 	vint_set_property(menu_data.footer.footer_grp, "visible", false) 
  4092. 	vint_object_destroy(menu_data.footer.footer_grp) 
  4093. end 
  4094.  
  4095. -- Finish it up 
  4096. function menu_footer_finalize_style_footer(menu_data) 
  4097. 	vint_set_property(Menu_footer_price_h, "anchor", menu_data.menu_width - 20, 0) 
  4098. end 
  4099.  
  4100. ----------------------------------------------------------------------------------- 
  4101. ---------------------------------[ Style Cluster ]--------------------------------- 
  4102. ----------------------------------------------------------------------------------- 
  4103. Style_cluster_player_cash	 		= -1		--	Cash the player has 
  4104. Style_cluster_displayed_cash 		= -1		--	Displayed in the style cluster 
  4105. Style_cluster_cash_anim_h 			= 0		--	Thread handle for cash anim 
  4106. Style_cluster_cash_style_grp_h 	= 0		--	Cash + Style meter 
  4107. Style_cluster_cash_style_anim_h 	= 0		--	Handle for the cash counting down animation 
  4108. Style_cluster_player_style 		= { }		--	Player's style info 
  4109. Style_cluster_enabled 				= false 
  4110. Style_cluster_data_subs				= false	-- Have data subscriptions been inited? 
  4111.  
  4112. function menu_store_init(awards_style) 
  4113. 	Style_cluster_cash_style_grp_h = vint_object_find("cash_style_cluster", nil, MENU_BASE_DOC_HANDLE) 
  4114. 	Style_cluster_cash_style_grp_h = vint_object_find("cash_style_cluster", nil, MENU_BASE_DOC_HANDLE) 
  4115. 	Style_cluster_cash_style_anim_h = vint_object_find("add_style_anim", nil, MENU_BASE_DOC_HANDLE) 
  4116. 	vint_set_property(Style_cluster_cash_style_grp_h, "visible", true) 
  4117. 	 
  4118. 	--Animation Style cluster in 
  4119. 	local cash_trans_in = vint_object_find("cash_trans_in", nil, MENU_BASE_DOC_HANDLE) 
  4120. 	lua_play_anim(cash_trans_in, 0) 
  4121. 	 
  4122. 	-- subscribe to data 
  4123. 	if Style_cluster_data_subs == false then 
  4124. 		vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "style_cluster_cash_update") 
  4125. 		vint_dataitem_add_subscription("local_player_style", "update", "style_cluster_style_update") 
  4126. 	end 
  4127.  
  4128. 	-- hide/unhide style elements and adjust offset of cash text 
  4129. 	if awards_style == true then 
  4130. 		vint_set_property(vint_object_find("style_grp", Style_cluster_cash_style_grp_h), "visible", true) 
  4131. 		vint_set_property(vint_object_find("cash_style_base", Style_cluster_cash_style_grp_h), "visible", true) 
  4132. 		vint_set_property(vint_object_find("cash_frame", Style_cluster_cash_style_grp_h), "offset", 0, 0) 
  4133. 		vint_set_property(vint_object_find("style_add_text", Style_cluster_cash_style_grp_h), "visible", false) 
  4134. 	else  
  4135. 		vint_set_property(vint_object_find("style_grp", Style_cluster_cash_style_grp_h), "visible", false) 
  4136. 		vint_set_property(vint_object_find("cash_style_base", Style_cluster_cash_style_grp_h), "visible", false) 
  4137. 		vint_set_property(vint_object_find("cash_frame", Style_cluster_cash_style_grp_h), "offset", -30, 0) 
  4138. 		vint_set_property(vint_object_find("style_add_text", Style_cluster_cash_style_grp_h), "visible", true) 
  4139. 	end 
  4140. 	 
  4141. 	Style_cluster_enabled = true 
  4142. end 
  4143.  
  4144. function menu_base_cleanup() 
  4145. 	if (Menu_hud_hidden) then 
  4146. 		hud_hide(false) 
  4147. 	end 
  4148. 	 
  4149. 	vint_document_unload(vint_document_find("menu_style_dialog")) 
  4150. 	 
  4151. 	--Event Tracking(Exit Menu) 
  4152. 	event_tracking_interface_exit() 
  4153. end 
  4154.  
  4155. function menu_store_use_hud(use_hud) 
  4156. 	Menu_use_hud = use_hud 
  4157. end 
  4158.  
  4159. function menu_store_get_player_cash() 
  4160. 	if Style_cluster_enabled == true then 
  4161. 		return Style_cluster_player_cash 
  4162. 	else 
  4163. 		return 0 
  4164. 	end 
  4165. end 
  4166.  
  4167. function style_cluster_cash_update(di_h) 
  4168. 	local cash = vint_dataitem_get(di_h) 
  4169. 	 
  4170. 	if Style_cluster_player_cash == -1 then 
  4171. 		Style_cluster_player_cash = cash 
  4172. 		Style_cluster_displayed_cash = cash 
  4173. 		style_cluster_animate_cash() 
  4174. 	end 
  4175. 	 
  4176. 	if cash ~= Style_cluster_player_cash then 
  4177. 		Style_cluster_player_cash = cash 
  4178. 		 
  4179. 		if Style_cluster_cash_anim_h == 0 then 
  4180. 			Style_cluster_cash_anim_h = thread_new("style_cluster_animate_cash") 
  4181. 		end 
  4182. 	end 
  4183. end 
  4184.  
  4185. function style_cluster_cleanup() 
  4186. 	Style_cluster_enabled = false 
  4187. 	vint_set_property(Style_cluster_cash_style_grp_h, "visible", false)	 
  4188. end 
  4189.  
  4190. function style_cluster_animate_cash() 
  4191. 	local d, d_abs 
  4192. 	while true do 
  4193. 		d = Style_cluster_player_cash - Style_cluster_displayed_cash 
  4194. 		 
  4195. 		if d < 0 then 
  4196. 			d_abs = d * -1 
  4197. 		else 
  4198. 			d_abs = d 
  4199. 		end 
  4200.  
  4201. 		if d_abs <= 5 then 
  4202. 			Style_cluster_displayed_cash = Style_cluster_player_cash 
  4203. 			vint_set_property(vint_object_find("cash_text", Style_cluster_cash_style_grp_h), "text_tag", "$"..format_cash(Style_cluster_displayed_cash)) 
  4204. 			Style_cluster_cash_anim_h = 0 
  4205. 			return 
  4206. 		end 
  4207. 	 
  4208. 		Style_cluster_displayed_cash = floor(Style_cluster_displayed_cash + (d * 0.5)) 
  4209. 		vint_set_property(vint_object_find("cash_text", Style_cluster_cash_style_grp_h), "text_tag", "$"..format_cash(Style_cluster_displayed_cash)) 
  4210. 		thread_yield() 
  4211. 	end 
  4212. end 
  4213.  
  4214. function style_cluster_style_update(di_h) 
  4215. 	local style_points, style_level, style_percent, respect_bonus = vint_dataitem_get(di_h) 
  4216. 	 
  4217. 	local s = Style_cluster_player_style 
  4218. 	local points_awarded = 0 
  4219. 	local animation_style = 0		-- 0 = no animation, 1 = 1 pass, 2 = 2 pass 
  4220. 	local enable_level_dialog = true 
  4221. 	 
  4222. 	-- check if this is the first data push 
  4223. 	if s.style_points == nil then 
  4224. 		s.level = 0 
  4225. 		s.percent = 0 
  4226. 		s.bonus = 0 
  4227. 		animation_style = 1 
  4228. 		enable_level_dialog = false 
  4229. 	else 
  4230. 		points_awarded = style_points - s.style_points 
  4231. 	end 
  4232. 			 
  4233. 	if points_awarded > 0 then 
  4234. 		if s.percent < style_percent then 
  4235. 			animation_style = 1 
  4236. 		else 
  4237. 			animation_style = 2 
  4238. 		end 
  4239. 	end 
  4240. 	 
  4241. 	if animation_style > 0 then 
  4242. 		-- set text of style level 
  4243. 		vint_set_property(vint_object_find("style_level_text", Style_cluster_cash_style_grp_h), "text_tag", style_level) 
  4244. 		 
  4245. 		if points_awarded > 0 then 
  4246. 			--Format Style tag with value insert 
  4247. 			local style_insert = {[0] = points_awarded} 
  4248. 			local style_string = vint_insert_values_in_string("STORE_ITEM_STYLE_AWARD", style_insert) 
  4249. 			vint_set_property(vint_object_find("style_add_text", Style_cluster_cash_style_grp_h), "text_tag", style_string) 
  4250. 			vint_set_property(vint_object_find("style_add_text_flair", Style_cluster_cash_style_grp_h), "text_tag", style_string) 
  4251. 			vint_set_property(vint_object_find("style_add_text", Style_cluster_cash_style_grp_h), "visible", true) 
  4252. 		else 
  4253. 			vint_set_property(vint_object_find("style_add_text", Style_cluster_cash_style_grp_h), "visible", false) 
  4254. 		end 
  4255.  
  4256. 		-- set up animation 
  4257. 		local r1 = style_percent * PI2 
  4258. 		local r2 = style_level * PI2 
  4259. 		local pr1 = s.percent * PI2 
  4260. 		local pr2 = s.level * PI2 
  4261. 		 
  4262. 		if animation_style == 1 then 
  4263. 			-- single stage rotation 
  4264. 			local object = vint_object_find("cash_style_bg_end_angle_twn_1", Style_cluster_cash_style_anim_h) 
  4265. 			vint_set_property(object, "start_value", pr1) 
  4266. 			vint_set_property(object, "end_value", r1) 
  4267. 			vint_set_property(object, "duration", 0.5) 
  4268. 			 
  4269. 			object = vint_object_find("cash_style_fill_end_angle_twn_1", Style_cluster_cash_style_anim_h) 
  4270. 			if pr1 > 0.13 then 
  4271. 				vint_set_property(object, "start_value", pr1 - 0.13) 
  4272. 			else 
  4273. 				vint_set_property(object, "start_value", 0) 
  4274. 			end 
  4275. 			 
  4276. 			if r1 > 0.13 then 
  4277. 				vint_set_property(object, "end_value", r1 - 0.13) 
  4278. 			else 
  4279. 				vint_set_property(object, "end_value", 0) 
  4280. 			end 
  4281. 			 
  4282. 			vint_set_property(object, "duration", 0.5) 
  4283.  
  4284. 			object = vint_object_find("cash_style_bg_end_angle_twn_2", Style_cluster_cash_style_anim_h) 
  4285. 			vint_set_property(object, "state", "disabled") 
  4286.  
  4287. 			object = vint_object_find("cash_style_fill_end_angle_twn_2", Style_cluster_cash_style_anim_h) 
  4288. 			vint_set_property(object, "state", "disabled") 
  4289. 			 
  4290. 			-- level label 
  4291. 			object = vint_object_find("style_level_grp_rotation_twn_1", Style_cluster_cash_style_anim_h) 
  4292. 			vint_set_property(object, "start_value", pr1) 
  4293. 			vint_set_property(object, "end_value", r1) 
  4294. 			vint_set_property(object, "duration", 0.5) 
  4295. 			vint_set_property(object, "state", "waiting") 
  4296.  
  4297. 			object = vint_object_find("style_level_text_rotation_twn_1", Style_cluster_cash_style_anim_h) 
  4298. 			vint_set_property(object, "start_value", pr1 * -1) 
  4299. 			vint_set_property(object, "end_value", r1 * -1) 
  4300. 			vint_set_property(object, "duration", 0.5) 
  4301. 			vint_set_property(object, "state", "waiting") 
  4302.  
  4303. 			vint_set_property(vint_object_find("style_level_grp_rotation_twn_2", Style_cluster_cash_style_anim_h), "state", "disabled") 
  4304. 			vint_set_property(vint_object_find("style_level_text_rotation_twn_2", Style_cluster_cash_style_anim_h), "state", "disabled") 
  4305. 		else 
  4306. 			-- two stage rotation 
  4307. 			local t = (1 - s.percent + style_percent) * style_percent 
  4308. 			local t2 = 0.5 * t 
  4309. 			local t1 = 0.5 * (1 - t) 
  4310. 			 
  4311. 			local object = vint_object_find("cash_style_bg_end_angle_twn_1", Style_cluster_cash_style_anim_h) 
  4312. 			vint_set_property(object, "start_value", pr1) 
  4313. 			vint_set_property(object, "end_value", PI2) 
  4314. 			vint_set_property(object, "duration", t1) 
  4315. 			 
  4316. 			object = vint_object_find("cash_style_bg_end_angle_twn_2", Style_cluster_cash_style_anim_h) 
  4317. 			vint_set_property(object, "start_value", 0) 
  4318. 			vint_set_property(object, "end_value", r1) 
  4319. 			vint_set_property(object, "state", "waiting") 
  4320. 			vint_set_property(object, "duration", t2) 
  4321. 			vint_set_property(object, "start_time", t1) 
  4322.  
  4323. 			object = vint_object_find("cash_style_fill_end_angle_twn_1", Style_cluster_cash_style_anim_h) 
  4324. 			if pr1 > 0.13 then 
  4325. 				vint_set_property(object, "start_value", pr1 - 0.13) 
  4326. 			else 
  4327. 				vint_set_property(object, "start_value", 0) 
  4328. 			end 
  4329. 			vint_set_property(object, "end_value", PI2) 
  4330. 			vint_set_property(object, "duration", t1) 
  4331.  
  4332. 			object = vint_object_find("cash_style_fill_end_angle_twn_2", Style_cluster_cash_style_anim_h) 
  4333. 			vint_set_property(object, "start_value", 0) 
  4334. 			if r1 > 0.13 then 
  4335. 				vint_set_property(object, "end_value", r1 - 0.13) 
  4336. 			else 
  4337. 				vint_set_property(object, "end_value", 0) 
  4338. 			end 
  4339. 			vint_set_property(object, "state", "waiting") 
  4340. 			vint_set_property(object, "duration", t2) 
  4341. 			vint_set_property(object, "start_time", t1) 
  4342. 			 
  4343. 			-- level label 
  4344. 			object = vint_object_find("style_level_grp_rotation_twn_1", Style_cluster_cash_style_anim_h) 
  4345. 			vint_set_property(object, "start_value", pr1) 
  4346. 			vint_set_property(object, "end_value", PI2) 
  4347. 			vint_set_property(object, "duration", t1) 
  4348.  
  4349. 			object = vint_object_find("style_level_text_rotation_twn_1", Style_cluster_cash_style_anim_h) 
  4350. 			vint_set_property(object, "start_value", pr1 * -1) 
  4351. 			vint_set_property(object, "end_value", PI2 * -1) 
  4352. 			vint_set_property(object, "duration", t1) 
  4353.  
  4354. 			object = vint_object_find("style_level_grp_rotation_twn_2", Style_cluster_cash_style_anim_h) 
  4355. 			vint_set_property(object, "start_value", 0) 
  4356. 			vint_set_property(object, "end_value", r1) 
  4357. 			vint_set_property(object, "start_time", t1) 
  4358. 			vint_set_property(object, "duration", t2) 
  4359. 			vint_set_property(object, "state", "waiting") 
  4360.  
  4361. 			object = vint_object_find("style_level_text_rotation_twn_2", Style_cluster_cash_style_anim_h) 
  4362. 			vint_set_property(object, "start_value", 0) 
  4363. 			vint_set_property(object, "end_value", r1 * -1) 
  4364. 			vint_set_property(object, "start_time", t1) 
  4365. 			vint_set_property(object, "duration", t2) 
  4366. 			vint_set_property(object, "state", "waiting") 
  4367. 		end 
  4368.  
  4369. 		vint_set_property(Style_cluster_cash_style_anim_h, "start_time", vint_get_time_index(MENU_BASE_DOC_HANDLE)) 
  4370.  
  4371. 		if enable_level_dialog == true and style_level > s.level then 
  4372. 			s.level = style_level 
  4373. 			s.bonus = respect_bonus 
  4374. 			vint_document_load("menu_style_dialog") 
  4375. 		end 
  4376. 	end 
  4377. 	 
  4378. 	s.level = style_level 
  4379. 	s.percent = style_percent 
  4380. 	s.style_points = style_points 
  4381. 	s.bonus = respect_bonus 
  4382. end 
  4383.  
  4384. ----------------------------------------------------------------------------------- 
  4385. ---------------------------------[ Interface Swap ]-------------------------------- 
  4386. ----------------------------------------------------------------------------------- 
  4387.  
  4388. Menu_interface_swap_complete_cb = 0 
  4389.  
  4390. function menu_swap_interface(msg, on_complete) 
  4391. 	if on_complete == nil then 
  4392. 		Menu_interface_swap_complete_cb = 0 
  4393. 	else 
  4394. 		Menu_interface_swap_complete_cb = on_complete 
  4395. 	end 
  4396.  
  4397. 	local insert_values = {[0] = msg} 
  4398. 	local title_str = vint_insert_values_in_string("STORE_SWITCHING_TITLE", insert_values) 
  4399. 	 
  4400. 	lua_play_anim(vint_object_find("swap_message_trans_in", nil, MENU_BASE_DOC_HANDLE)) 
  4401. 	vint_set_property(vint_object_find("swap_title", nil, MENU_BASE_DOC_HANDLE), "text_tag", title_str) 
  4402.  
  4403. 	menu_close(menu_swap_finalize) 
  4404. 	 
  4405. end 
  4406.  
  4407. function menu_swap_finalize() 
  4408. 	thread_new("menu_swap_finalize_delayed") 
  4409. end 
  4410.  
  4411. function menu_swap_finalize_delayed() 
  4412. 	delay(1) 
  4413. 	lua_play_anim(vint_object_find("swap_message_trans_out", nil, MENU_BASE_DOC_HANDLE)) 
  4414. 	 
  4415. 	if Menu_interface_swap_complete_cb ~= 0 then 
  4416. 		Menu_interface_swap_complete_cb() 
  4417. 		Menu_interface_swap_complete_cb = 0 
  4418. 	end 
  4419. end 
  4420.  
  4421. ------------------------------------------------------------------------------ 
  4422. -------------------------------[ Button Tips ]-------------------------------- 
  4423. ------------------------------------------------------------------------------ 
  4424. Menu_base_btn_tips = { [0] = { }, [1] = { }, [2] = { }, [3] = { } } 
  4425. Button_tips_is_init = false 
  4426. Menu_base_btn_tips_pause_ind_h = -1 
  4427. Menu_base_btn_tips_pause_ind_x = 0 
  4428. Menu_base_btn_tips_pause_ind_y = 0 
  4429. Menu_base_btn_tips_pause_ind_width = 0 
  4430.  
  4431. function btn_tips_init() 
  4432. 	if Button_tips_is_init == true then 
  4433. 		return 
  4434. 	end 
  4435. 	local label_h = vint_object_find("menu_btn_tip_label", nil, MENU_BASE_DOC_HANDLE) 
  4436. 	local bitmap_h = vint_object_find("menu_btn_tip_bmp", nil, MENU_BASE_DOC_HANDLE) 
  4437. 	 
  4438. 	Menu_base_btn_tips[0].label_h = label_h 
  4439. 	Menu_base_btn_tips[0].bitmap_h = bitmap_h 
  4440. 	vint_set_property(Menu_base_btn_tips[0].bitmap_h, "image", "ui_ctrl_360_btn_a") 
  4441. 	 
  4442. 	Menu_base_btn_tips[1].label_h = vint_object_clone(label_h) 
  4443. 	Menu_base_btn_tips[1].bitmap_h = vint_object_clone(bitmap_h) 
  4444. 	vint_set_property(Menu_base_btn_tips[1].bitmap_h, "image", "ui_ctrl_360_btn_x") 
  4445. 	 
  4446. 	Menu_base_btn_tips[2].label_h = vint_object_clone(label_h) 
  4447. 	Menu_base_btn_tips[2].bitmap_h = vint_object_clone(bitmap_h) 
  4448. 	vint_set_property(Menu_base_btn_tips[2].bitmap_h, "image", "ui_ctrl_360_btn_b") 
  4449. 	 
  4450. 	Menu_base_btn_tips[3].label_h = vint_object_clone(label_h) 
  4451. 	Menu_base_btn_tips[3].bitmap_h = vint_object_clone(bitmap_h) 
  4452. 	vint_set_property(Menu_base_btn_tips[3].bitmap_h, "image", "ui_ctrl_360_btn_rs") 
  4453.  
  4454. 	Menu_base_btn_tips[3].independent_label_h = vint_object_find("menu_btn_tip_ext_label", nil, MENU_BASE_DOC_HANDLE) 
  4455. 	Menu_base_btn_tips[3].independent_bitmap_h = vint_object_find("menu_btn_tip_ext_bmp", nil, MENU_BASE_DOC_HANDLE) 
  4456. 	Menu_base_btn_tips[3].independent_group_h = vint_object_find("menu_btn_tips_ext", nil, MENU_BASE_DOC_HANDLE) 
  4457. 	vint_set_property(Menu_base_btn_tips[3].independent_bitmap_h, "image", "ui_ctrl_360_btn_rs") 
  4458. 	 
  4459. 	Menu_base_btn_tips_pause_ind_h = vint_object_find("pause_menu_indicator", nil, MENU_BASE_DOC_HANDLE) 
  4460. 	Menu_base_btn_tips_pause_ind_x, Menu_base_btn_tips_pause_ind_y = vint_get_property(Menu_base_btn_tips_pause_ind_h, "anchor") 
  4461. 	local width, height = element_get_actual_size(Menu_base_btn_tips_pause_ind_h) 
  4462. 	Menu_base_btn_tips_pause_ind_width = width 
  4463. 	 
  4464. 	Button_tips_is_init = true 
  4465. end 
  4466.  
  4467. function btn_tips_update() 
  4468. 	local main_menu_doc_h = vint_document_find("main_menu") 
  4469. 	if Menu_horz_active == 0 and main_menu_doc_h == 0 and Pause_menu_save_for_server_drop == false then 
  4470. 		return 
  4471. 	end 
  4472. 	 
  4473. 	local btn_tips = { } 
  4474. 	if Menu_active.btn_tips == nil then 
  4475. 		btn_tips = BTN_TIPS_DEFAULT 
  4476. 	else 
  4477. 		btn_tips = Menu_active.btn_tips 
  4478. 	end 
  4479. 	 
  4480. 	local no_a_button = false; 
  4481. 	if btn_tips.a_button ~= nil and var_to_bool(btn_tips.a_button.enabled) == true then 
  4482. 		vint_set_property(Menu_base_btn_tips[0].label_h, "visible", true) 
  4483. 		vint_set_property(Menu_base_btn_tips[0].bitmap_h, "visible", true) 
  4484. 		 
  4485. 		vint_set_property(Menu_base_btn_tips[0].bitmap_h, "image", get_a_button()) 
  4486. 		vint_set_property(Menu_base_btn_tips[0].label_h, "text_tag", btn_tips.a_button.label) 
  4487. 		Menu_base_btn_tips[0].visible = true 
  4488. 	else 
  4489. 		vint_set_property(Menu_base_btn_tips[0].label_h, "visible", false) 
  4490. 		vint_set_property(Menu_base_btn_tips[0].bitmap_h, "visible", false) 
  4491. 		Menu_base_btn_tips[0].visible = false 
  4492. 		no_a_button = true 
  4493. 	end 
  4494. 	 
  4495. 	if btn_tips.x_button ~= nil and var_to_bool(btn_tips.x_button.enabled) == true then 
  4496. 		if no_a_button == true then 
  4497. 		end 
  4498. 	 
  4499. 		vint_set_property(Menu_base_btn_tips[1].label_h, "visible", true) 
  4500. 		vint_set_property(Menu_base_btn_tips[1].bitmap_h, "visible", true) 
  4501. 		 
  4502. 		vint_set_property(Menu_base_btn_tips[1].bitmap_h, "image", get_x_button()) 
  4503. 		vint_set_property(Menu_base_btn_tips[1].label_h, "text_tag", btn_tips.x_button.label) 
  4504. 		Menu_base_btn_tips[1].visible = true 
  4505. 	else 
  4506. 		vint_set_property(Menu_base_btn_tips[1].label_h, "visible", false) 
  4507. 		vint_set_property(Menu_base_btn_tips[1].bitmap_h, "visible", false) 
  4508. 		Menu_base_btn_tips[1].visible = false 
  4509. 	end 
  4510.  
  4511. 	if btn_tips.b_button ~= nil and var_to_bool(btn_tips.b_button.enabled) == true then 
  4512. 		vint_set_property(Menu_base_btn_tips[2].label_h, "visible", true) 
  4513. 		vint_set_property(Menu_base_btn_tips[2].bitmap_h, "visible", true) 
  4514. 		 
  4515. 		vint_set_property(Menu_base_btn_tips[2].bitmap_h, "image", get_b_button()) 
  4516. 		vint_set_property(Menu_base_btn_tips[2].label_h, "text_tag", btn_tips.b_button.label) 
  4517. 		Menu_base_btn_tips[2].visible = true 
  4518. 	else 
  4519. 		vint_set_property(Menu_base_btn_tips[2].label_h, "visible", false) 
  4520. 		vint_set_property(Menu_base_btn_tips[2].bitmap_h, "visible", false) 
  4521. 		Menu_base_btn_tips[2].visible = false 
  4522. 	end 
  4523.  
  4524. 	if btn_tips.right_stick ~= nil and var_to_bool(btn_tips.right_stick.enabled) == true then 
  4525. 		if btn_tips.right_stick.independent == false then 
  4526. 			vint_set_property(Menu_base_btn_tips[3].label_h, "visible", true) 
  4527. 			vint_set_property(Menu_base_btn_tips[3].bitmap_h, "visible", true) 
  4528. 			vint_set_property(Menu_base_btn_tips[3].label_h, "text_tag", btn_tips.right_stick.label) 
  4529.  
  4530. 			if btn_tips.right_stick.use_dpad == true then 
  4531. 				vint_set_property(Menu_base_btn_tips[3].bitmap_h, "image", get_up_down()) 
  4532. 			else 
  4533. 				vint_set_property(Menu_base_btn_tips[3].bitmap_h, "image", get_right_stick()) 
  4534. 			end 
  4535. 			vint_set_property(Menu_base_btn_tips[3].independent_group_h, "visible", false) 
  4536. 		else 
  4537. 			vint_set_property(Menu_base_btn_tips[3].label_h, "visible", false) 
  4538. 			vint_set_property(Menu_base_btn_tips[3].bitmap_h, "visible", false) 
  4539. 	 
  4540. 			vint_set_property(Menu_base_btn_tips[3].independent_group_h, "visible", true) 
  4541. 			vint_set_property(Menu_base_btn_tips[3].independent_label_h, "visible", true) 
  4542. 			if btn_tips.right_stick.in_playlist == true then 
  4543. 				vint_set_property(Menu_base_btn_tips[3].independent_bitmap_h, "visible", false) 
  4544. 			else 
  4545. 				vint_set_property(Menu_base_btn_tips[3].independent_bitmap_h, "visible", true) 
  4546. 			end 
  4547.  
  4548. 			if btn_tips.right_stick.use_dpad == true then 
  4549. 				vint_set_property(Menu_base_btn_tips[3].independent_bitmap_h, "image", get_up_down()) 
  4550. 			else 
  4551. 				vint_set_property(Menu_base_btn_tips[3].independent_bitmap_h, "image", get_right_stick()) 
  4552. 			end 
  4553. 			 
  4554. 			if btn_tips.right_stick.in_playlist == true then 
  4555. 				vint_set_property(Menu_base_btn_tips[3].independent_label_h, "force_case", "upper") 
  4556. 				local str = vint_insert_values_in_string(btn_tips.right_stick.label, { [0] = btn_tips.right_stick.label_text }) 
  4557. 				vint_set_property(Menu_base_btn_tips[3].independent_label_h, "text_tag", str ) 
  4558. 			else 
  4559. 				vint_set_property(Menu_base_btn_tips[3].independent_label_h, "text_tag", btn_tips.right_stick.label) 
  4560. 			end 
  4561. 			 
  4562. 			local width = element_get_actual_size(Menu_base_btn_tips[3].independent_label_h) 
  4563. 			local resolution_adjust = 0 
  4564. 			 
  4565. 			-- Awesome fun magic numbers that force the right stick graphic into the right position 
  4566. 			if vint_hack_is_std_res() then 
  4567. 				resolution_adjust = 747 
  4568. 			else 
  4569. 				resolution_adjust = 1015 
  4570. 			end 
  4571. 			 
  4572. 			local Xpos, Ypos = vint_get_property(Menu_base_btn_tips[3].independent_group_h, "anchor") 
  4573. 			vint_set_property(Menu_base_btn_tips[3].independent_group_h, "anchor", resolution_adjust - width, Ypos) 
  4574. 		end 
  4575. 		 
  4576. 		 
  4577. 		Menu_base_btn_tips[3].visible = true 
  4578. 	else 
  4579. 		vint_set_property(Menu_base_btn_tips[3].label_h, "visible", false) 
  4580. 		vint_set_property(Menu_base_btn_tips[3].bitmap_h, "visible", false) 
  4581. 		vint_set_property(Menu_base_btn_tips[3].independent_group_h, "visible", false) 
  4582.  
  4583. 		Menu_base_btn_tips[3].visible = false 
  4584. 	end 
  4585.  
  4586. 	 
  4587. 	local element, x, w, w2 
  4588. 	local junk, y = vint_get_property(Menu_base_btn_tips[0].label_h, "anchor") 
  4589. 	 
  4590. 	local btn_padding = 0 
  4591. 	local tip_padding = 15 
  4592. 	local idx_offset = -1 
  4593. 	 
  4594. 	local tip_count = 0 
  4595. 	 
  4596. 	for idx, val in Menu_base_btn_tips do 
  4597. 		tip_count = tip_count + 1 
  4598. 	end 
  4599.  
  4600. 	local tip_width = 0  
  4601. 	for idx = 0, tip_count - 1 do 
  4602. 		local val = Menu_base_btn_tips[idx] 
  4603. 		 
  4604. 		if idx_offset < 0 and val.visible == true then 
  4605. 			--do first pass (its a little different than the rest) 
  4606. 			vint_set_property(val.label_h, "force_case", "upper") 
  4607. 			x = vint_get_property(Menu_base_btn_tips[0].bitmap_h, "anchor") 
  4608. 			vint_set_property(val.bitmap_h, "anchor", x, y) 
  4609. 			w = element_get_actual_size(val.bitmap_h) 
  4610. 			w2 = element_get_actual_size(val.label_h) 
  4611. 			x = x + w/2 + btn_padding			 
  4612. 			vint_set_property(val.label_h, "anchor", x, y) 
  4613. 			idx_offset = idx 
  4614. 			 
  4615. 			--Calculate size for possible centering 
  4616. 			tip_width = tip_width + w + w2 + btn_padding + tip_padding 
  4617. 		elseif (idx ~= 3 or (idx == 3 and btn_tips.right_stick ~= nil and btn_tips.right_stick.independent == false)) and val.visible == true then 
  4618. 			--Arrange button 
  4619. 			vint_set_property(val.label_h, "force_case", "upper") 
  4620. 			x = vint_get_property(Menu_base_btn_tips[idx_offset].label_h, "anchor") 
  4621. 			w = element_get_actual_size(Menu_base_btn_tips[idx_offset].label_h) 
  4622. 			w2 = element_get_actual_size(val.bitmap_h) 
  4623. 			x = x + w2 / 2 + w + tip_padding 
  4624. 			vint_set_property(val.bitmap_h, "anchor", x, 0) 
  4625. 		 
  4626. 			--Arrange text 
  4627. 			x = vint_get_property(val.bitmap_h, "anchor") 
  4628. 			w = w2 
  4629. 			x = x + w/2 + btn_padding 
  4630. 			vint_set_property(val.label_h, "anchor", x, y) 
  4631. 			 
  4632. 			idx_offset = idx 
  4633. 			 
  4634. 			--Calculate size for possible centering 
  4635. 			w = element_get_actual_size(val.label_h) 
  4636. 			w2 = element_get_actual_size(val.bitmap_h) 
  4637. 			tip_width = tip_width + w + w2 + btn_padding + tip_padding 
  4638. 		end 
  4639. 		 
  4640. 	end 
  4641. 	 
  4642. 	--Check if we should move the pause menu indicator because it may overlap the button tips 
  4643. 	if vint_document_find("pause_menu") ~= 0 then 
  4644. 		local safe_frame_width = 1088 
  4645. 		if vint_hack_is_std_res() then 
  4646. 			--Because we are comparing against actual size safe frame width is 1.5 * 545 
  4647. 			safe_frame_width = 816 
  4648. 		end 
  4649. 		 
  4650. 		local left_over_space = safe_frame_width - tip_width 
  4651. 		 
  4652. 		if Menu_base_btn_tips_pause_ind_width > left_over_space then 
  4653. 			--We have overlapping text 
  4654. 			--Moving pause indicator to left side right above button tips 
  4655. 			vint_set_property(Menu_base_btn_tips_pause_ind_h, "anchor", 98, 39) 
  4656. 			vint_set_property(Menu_base_btn_tips_pause_ind_h, "auto_offset", "W") 
  4657. 		else 
  4658. 			--Moving back to original position 
  4659. 			vint_set_property(Menu_base_btn_tips_pause_ind_h, "anchor", Menu_base_btn_tips_pause_ind_x, Menu_base_btn_tips_pause_ind_y) 
  4660. 			vint_set_property(Menu_base_btn_tips_pause_ind_h, "auto_offset", "NE") 
  4661. 		end 
  4662. 	end 
  4663. 	 
  4664. 	--if main menu then we center button tips 
  4665. 	if main_menu_doc_h ~= 0 then 
  4666. 		--Center button tips 
  4667. 		local center_x = 640 
  4668. 		if vint_hack_is_std_res() == true then 
  4669. 			--Yes this is a magic number but it works. 
  4670. 			center_x = 510 
  4671. 		end 
  4672. 		local tips_h = vint_object_find("menu_btn_tips", nil, MENU_BASE_DOC_HANDLE) 
  4673. 		local target_x = center_x - tip_width * 0.5		 
  4674. 		local x, y = vint_get_property(tips_h, "anchor") 
  4675. 		vint_set_property(tips_h, "anchor", target_x, y) 
  4676. 	end 
  4677. end 
  4678.  
  4679. function btn_tips_default_a() 
  4680. 	return true 
  4681. end 
  4682.  
  4683. function btn_tips_default_b() 
  4684. 	return true 
  4685. end 
  4686.  
  4687. function btn_tips_default_x() 
  4688. 	if Menu_active.on_alt_select ~= nil or Menu_active[Menu_active.highlighted_item].on_alt_select ~= nil then 
  4689. 		return true 
  4690. 	else 
  4691. 		return false 
  4692. 	end 
  4693. end 
  4694.  
  4695. function btn_tips_default_rs() 
  4696. 	return false 
  4697. end 
  4698.  
  4699. function btn_tips_footer_build(parent_h, offset_x, offset_y) 
  4700. 	local footer_grp = vint_object_clone(vint_object_find("footer_btn_tips", nil, MENU_BASE_DOC_HANDLE), parent_h) 
  4701. 	 
  4702. 	--Space everything based on localization 
  4703. 	local btn_spacing = 3 --Spacing between button -> text  
  4704. 	local txt_spacing = 30 -- Spacing between text -> button 
  4705. 	local btn_a_h = vint_object_find("footer_tip_a_bmp", footer_grp) 
  4706. 	local txt_a_h = vint_object_find("footer_tip_a_label", footer_grp) 
  4707. 	local btn_b_h = vint_object_find("footer_tip_b_bmp", footer_grp) 
  4708. 	local txt_b_h = vint_object_find("footer_tip_b_label", footer_grp) 
  4709.  
  4710. 	--Replace buttons 
  4711. 	vint_set_property(btn_a_h, "image", get_a_button()) 
  4712. 	vint_set_property(btn_b_h, "image", get_b_button()) 
  4713.  
  4714. 	local x, y = vint_get_property(btn_a_h, "anchor") 
  4715. 	 
  4716. 	--Apply offsets 
  4717. 	vint_set_property(footer_grp, "anchor", offset_x, offset_y) 
  4718.  
  4719. 	local width, height = element_get_actual_size(btn_a_h) 
  4720. 	vint_set_property(txt_a_h, "anchor", x + width/2 + btn_spacing , y) 
  4721.  
  4722. 	x, y = vint_get_property(txt_a_h, "anchor") 
  4723. 	width, height = element_get_actual_size(txt_a_h) 
  4724. 	vint_set_property(btn_b_h, "anchor", x + width + txt_spacing, y) 
  4725. 	 
  4726. 	local x, y = vint_get_property(btn_b_h, "anchor") 
  4727. 	local width, height = element_get_actual_size(btn_b_h) 
  4728. 	vint_set_property(txt_b_h, "anchor", x + width/2 + btn_spacing, y) 
  4729.  
  4730. 	--Derive full control width 
  4731. 	local width, height = element_get_actual_size(txt_b_h) 
  4732. 	width = width + x + 10 
  4733.  
  4734. 	return footer_grp, width 
  4735. end 
  4736. function btn_tips_footer_attach(menu_data) 
  4737. 	local parent_h = Menu_option_labels.control_parent 
  4738. 	local footer_grp, width = btn_tips_footer_build(parent_h, 0, 0) 
  4739. 	 
  4740. 	menu_data.footer = { } 
  4741. 	menu_data.footer.width = floor(width) 
  4742. 	 
  4743. 	menu_data.footer.footer_grp = footer_grp 
  4744. 	menu_data.footer_height = 25 
  4745. end 
  4746.  
  4747. function btn_tips_footer_set_width(menu_data) 
  4748. 	--Do nothing` 
  4749. end 
  4750.  
  4751. function menu_clone(src) 
  4752. 	-- copy the original 
  4753. 	local dst = table_clone(src) 
  4754. 	 
  4755. 	-- clear out any instance data 
  4756. 	for i = 0, dst.num_items - 1 do 
  4757. 		if dst[i].control ~= nil then 
  4758. 			menu_release_control(dst[i]) 
  4759. 		end 
  4760. 	end 
  4761. 	 
  4762. 	if dst.footer ~= nil then 
  4763. 		vint_object_destroy(dst.footer.footer_grp) 
  4764. 		vint_object_destroy(dst.footer.hr_h) 
  4765. 		dst.footer = nil 
  4766. 	end 
  4767. 	 
  4768. 	return dst 
  4769. end 
  4770.  
  4771. BTN_TIPS_DEFAULT = { 
  4772. 	a_button = { label = "CONTROL_SELECT", enabled = btn_tips_default_a, }, 
  4773. 	x_button = { label = "PLAYER_CREATION_RANDOMIZE", enabled = btn_tips_default_x, }, 
  4774. 	b_button = { label = "CONTROL_RESUME", enabled = btn_tips_default_b, }, 
  4775. 	right_stick = { label = "CONTROL_ZOOM_AND_ROTATE", enabled = btn_tips_default_rs, independent = true }, 
  4776. } 
  4777.  
  4778. Menu_control_callbacks = { 
  4779. 	[MENU_ITEM_TYPE_NUM_SLIDER] = { 
  4780. 		on_show =			menu_num_slider_show, 
  4781. 		on_enter =			menu_num_slider_on_enter, 
  4782. 		on_leave =			menu_num_slider_on_leave, 
  4783. 		on_select =			menu_control_on_select, 
  4784. 		on_release =		menu_num_slider_release, 
  4785. 		has_control =		true, 
  4786. 		hide_select_bar =	true 
  4787. 	}, 
  4788.  
  4789. 	[MENU_ITEM_TYPE_SELECTABLE] = { 
  4790. 		on_select =		menu_control_on_select, 
  4791. 	}, 
  4792.  
  4793. 	[MENU_ITEM_TYPE_SUB_MENU] = { 
  4794. 		on_select =		menu_submenu_on_select, 
  4795. 	}, 
  4796.  
  4797. 	[MENU_ITEM_TYPE_TEXT_SLIDER] = { 
  4798. 		on_show =			menu_text_slider_show, 
  4799. 		on_enter =			menu_text_slider_on_enter, 
  4800. 		on_leave =			menu_text_slider_on_leave, 
  4801. 		on_select =			menu_control_on_select, 
  4802. 		on_release =		menu_text_slider_release, 
  4803. 		get_min_width =	menu_text_slider_get_min_width, 
  4804. 		set_width =			menu_info_box_set_width, 
  4805. 		has_control =		true, 
  4806. 		hide_select_bar =	true 
  4807. 	}, 
  4808.  
  4809. 	[MENU_ITEM_TYPE_GRID] = { 
  4810. 		on_select =				menu_control_on_select, 
  4811. 		on_nav_left =			menu_grid_nav_left, 
  4812. 		on_nav_right =			menu_grid_nav_right, 
  4813. 		on_nav_up =				menu_grid_nav_up, 
  4814. 		on_nav_down =			menu_grid_nav_down, 
  4815. 		get_width =				menu_grid_get_width, 
  4816. 		get_height =			menu_grid_get_height, 
  4817. 		uses_scroll_bar =		true, 
  4818. 		hide_select_bar =		true, 
  4819. 		hide_label_stripe =	true, 
  4820. 	}, 
  4821. 	 
  4822. 	[MENU_ITEM_TYPE_PALETTE] = { 
  4823. 		on_show =				menu_palette_show, 
  4824. 		on_enter =				menu_palette_on_enter, 
  4825. 		on_leave =				menu_palette_on_leave, 
  4826. 		on_select =				menu_control_on_select, 
  4827. 		on_release =			menu_palette_release, 
  4828. 		has_control =			true, 
  4829. 		hide_select_bar =		true, 
  4830. 		hide_label_stripe =	true, 
  4831. 	}, 
  4832.  
  4833. 	[MENU_ITEM_TYPE_INFO_BOX] = { 
  4834. 		on_show =				menu_info_box_show, 
  4835. 		on_select =				menu_control_on_select, 
  4836. 		on_enter =				menu_info_box_on_enter, 
  4837. 		on_leave =				menu_info_box_on_leave, 
  4838. 		on_release =			menu_info_box_release, 
  4839. 		set_width =				menu_info_box_set_width, 
  4840. 		get_min_width =		menu_info_box_get_min_width, 
  4841. 		has_control =			true, 
  4842. 		hide_select_bar =		true, 
  4843. 		hide_label_stripe =	true, 
  4844. 	}, 
  4845. 	 
  4846. 	[MENU_ITEM_TYPE_MARQUEE] = { 
  4847. 		on_show	 =		menu_marquee_show, 
  4848. 		on_select =		menu_control_on_select, 
  4849. 		on_enter  =		menu_marquee_on_enter, 
  4850. 		on_leave  =		menu_marquee_on_leave, 
  4851. 	}, 
  4852.  
  4853. } 
  4854.