./vint_lib.lua

  1. TEST_TABLE = { 
  2. 	["monkey"] = { 1, 2, 3 }, 
  3. 	[12] = 12, 
  4. } 
  5.  
  6. TEST_TABLE2 = { 
  7. 	["FREAKY"] = TEST_TABLE, 
  8. 	[46] = TEST_TABLE, 
  9. } 
  10.  
  11. TEST_TABLE["super_monkey"] = TEST_TABLE2 
  12.  
  13. function test_error_me() 
  14. 	X = 5 
  15. end 
  16.  
  17. GAME_BUILD_DATE = "0000-00-00 20:00:00" 
  18.  
  19. -- legacy for menu_base... 
  20. --MENU_NUM_SLIDER_ACCEL_REPEAT =	0.08 
  21. --MENU_NUM_SLIDER_ACCEL_FACTOR =	15 
  22. --MENU_NUM_SLIDER_ACCEL_LIMIT =		1000 
  23.  
  24. FEET_PER_METER = 3.2808399 
  25.  
  26. Pcr_open_plastic_surgeon = false 
  27.  
  28.  
  29. -- some docs need to know what menu mode we are doing 
  30. -- set this from C before loading menu docs 
  31. Menu_mode_current = "" 
  32.  
  33. --Main Menu Globals... 
  34. Main_menu_controller_is_selected = false			-- Determines if we've got a controller selected for the game, used by main menu... 
  35. Main_menu_gameboot_complete = false				--Determines if we've already loaded the main menu(we use this to determine to show loading and press start or not). 
  36. Menu_swap_in_progress = false 
  37.  
  38. --LEGACY DELETE THIS when unreferenced by the main menu... 
  39. Main_menu_controller_selected = false			-- Determines if we've got a controller selected for the game, used by main menu... LEGACY 
  40.  
  41.  
  42. Main_menu_can_has_input = false 
  43.  
  44.  --stored here so we know how to properly restart the clothing store 
  45. Clothing_store_name = "DEBUG_CLOTHING_STORE" 
  46. Clothing_store_display_name = 0 
  47. Clothing_store_original_name = "DEBUG_CLOTHING_STORE" 
  48. Clothing_store_original_display_name = 0 
  49. Menu_swap_interface_unload_handle = 0 
  50. Menu_swap_interface_reload_name = 0 
  51. Menu_swap_callback_function = 0 
  52. Menu_swap_hud_hidden = false; 
  53.  
  54. INVALID_NUM_FRAMES = -1 
  55. Num_frames_from_switch = INVALID_NUM_FRAMES 
  56.  
  57. Pause_menu_save_for_server_drop = false 
  58.  
  59. DIALOG_OPEN_SOUND 		= "SYS_HUD_HELPTEXT" 
  60. DIALOG_SERIOUS_SOUND	= "SYS_HUD_CONF_SERIOUS" 
  61. Menu_sound_item_nav		= "SYS_MENU_CLICK_UD"		-- Current menu item changes 
  62. Menu_sound_value_nav	= "SYS_MENU_CLICK_LR"		-- Value of current item changes 
  63. Menu_sound_select		= "UI_Main_Menu_Select"			-- Current item selected 
  64. Menu_sound_scroll		= "SYS_MENU_TRIGGER_LR"		-- Horizontal menu changes 
  65. Menu_sound_back			= "SYS_MENU_BACK"			-- Current menu changes to previous 
  66. Menu_sound_open			= "SYS_MENU_OPEN"			-- Menu system is opened 
  67. Menu_sound_close		= "SYS_MENU_CLOSE"			-- Menu system is closed 
  68. Menu_sound_warning		= "SYS_MENU_OPEN"			-- Warning dialog opens 
  69. Menu_sound_purchase		= "SYS_MENU_PURCHASE"		-- Any item is purchased 
  70. Menu_sound_confirm		= "SYS_HUD_CONF_SERIOUS"	-- Confirmation/warning dialog opens 
  71. Menu_sound_reward		= "SYS_HUD_CONF_REWARD"		-- Reward notification dialog 
  72.  
  73.  
  74.  
  75. --Tween States 
  76. VINT_TWEEN_STATE_WAITING 	= 0 
  77. VINT_TWEEN_STATE_RUNNING	= 1 
  78. VINT_TWEEN_STATE_PAUSED		= 2 
  79. VINT_TWEEN_STATE_DISABLED	= 3 
  80. VINT_TWEEN_STATE_FINISHED	= 4 
  81.  
  82. Screen_center_x = 640 
  83. Screen_center_y = 360 
  84.  
  85. Safe_frame_e	= 0 
  86. Safe_frame_w	= 0 
  87. Safe_frame_n	= 0 
  88. Safe_frame_s	= 0 
  89.  
  90. VINT_OBJECT_INVALID 	= -1 
  91. VINT_OBJECT_GROUP 	= 0 
  92. VINT_OBJECT_BITMAP 	= 1 
  93. VINT_OBJECT_TEXT 		= 2 
  94.  
  95. function vint_lib_init_constants() 
  96. 	if vint_is_std_res() then 
  97. 		Screen_center_x = 320 
  98. 		Screen_center_y = 240 
  99. 	else 
  100. 		Screen_center_x = 640 
  101. 		Screen_center_y = 360 
  102. 	end 
  103. 	 
  104. 	--Get safe frame... 
  105. 	Safe_frame_w, Safe_frame_n, Safe_frame_e, Safe_frame_s = vint_get_safe_frame() 
  106. end 
  107.  
  108. function vint_menu_swap_thread() 
  109. 	while true do 
  110. 		if Menu_swap_interface_reload_name ~= 0 then 
  111. 			if Menu_swap_hud_hidden == false then 
  112. 				game_hud_hide(true); 
  113. 				Menu_swap_hud_hidden = true 
  114. 			end 
  115. 			if Num_frames_from_switch ~= INVALID_NUM_FRAMES then 
  116. 				Num_frames_from_switch = Num_frames_from_switch + 1 
  117. 			end 
  118. 			if Num_frames_from_switch > 2 then 
  119. 				if Menu_swap_interface_reload_name ~= 0 then 
  120. 					vint_document_load(Menu_swap_interface_reload_name) 
  121. 					Menu_swap_interface_reload_name = 0 
  122. 					Num_frames_from_switch = INVALID_NUM_FRAMES 
  123. 					Menu_swap_in_progress = false 
  124. 					if Menu_swap_callback_function ~= 0 then 
  125. 						Menu_swap_callback_function() 
  126. 						Menu_swap_callback_function = 0 
  127. 					end 
  128. 				end 
  129. 			end 
  130. 		end 
  131. 		thread_yield() 
  132. 	end 
  133. end 
  134.  
  135. function vint_menu_swap_invalidate() 
  136. 	Menu_swap_interface_reload_name = 0 
  137. 	Num_frames_from_switch = INVALID_NUM_FRAMES 
  138. 	Clothing_store_name = "DEBUG_CLOTHING_STORE" 
  139. 	Clothing_store_display_name = 0 
  140. 	Clothing_store_original_name = "DEBUG_CLOTHING_STORE" 
  141. 	Clothing_store_original_display_name = 0 
  142. 	Menu_swap_interface_unload_handle = 0 
  143. 	Menu_swap_interface_reload_name = 0 
  144. 	Menu_swap_in_progress = false 
  145. 	game_hud_hide(false); 
  146. 	Menu_swap_hud_hidden = false 
  147. end 
  148.  
  149. function vint_menu_swap_unload() 
  150. 	vint_document_unload(Menu_swap_interface_unload_handle) 
  151. 	Num_frames_from_switch = 0 
  152. end 
  153.  
  154. function argument_unwrapper(arguments, start) 
  155. 	if start < arguments.n then 
  156. 		return arguments[start + 1], argument_unwrapper(arguments, start + 1) 
  157. 	end	 
  158. end 
  159.  
  160. function vint_dataresponder_request(data_responder_name, callback_function_name, max_records_to_return, ...) 
  161. 	vint_internal_dataresponder_request(data_responder_name, callback_function_name, max_records_to_return, argument_unwrapper(arg, 0)) 
  162. 	while(vint_dataresponder_finished(data_responder_name) ~= true) do 
  163. 		thread_yield() 
  164. 		vint_internal_dataresponder_request(data_responder_name, callback_function_name, max_records_to_return, argument_unwrapper(arg, 0)) 
  165. 	end 
  166. end 
  167.  
  168. --[[ 
  169. ######################################################################### 
  170. UTILITY FUNCTIONS  
  171. ######################################################################### 
  172. ]] 
  173.  
  174. function set_text_tag(text_element_h, text_crc, text_string) 
  175. 	--Set Label 
  176. 	if text_crc == 0 and text_string == nil then 
  177. 		--no string 
  178. 		vint_set_property(text_element_h,"text_tag", "") 
  179. 	elseif text_crc == 0 then 
  180. 		--use string 
  181. 		vint_set_property(text_element_h, "text_tag", text_string) 
  182. 	elseif text_crc == nil then 
  183. 		--Label crc invalid 
  184. 		vint_set_property(text_element_h,"text_tag", "") 
  185. 	else 
  186. 		--use crc 
  187. 		vint_set_property(text_element_h, "text_tag_crc",text_crc) 
  188. 	end 
  189. end 
  190.  
  191. --Easy Start Anim 
  192. function lua_play_anim(anim_h, start_time_offset, doc) 
  193. 	if start_time_offset == nil then 
  194. 		start_time_offset = 0 
  195. 	end 
  196. 	 
  197. 	local start_time = vint_get_time_index(doc) + start_time_offset 
  198. 	 
  199. 	vint_set_property(anim_h, "is_paused", false) 
  200. 	vint_set_property(anim_h, "start_time", start_time) 
  201. end 
  202.  
  203. --Easy Play tween method 
  204. function lua_play_tween(tween_handle, target_handle, start_time_offset) 
  205. 	vint_set_property(tween_handle, "target_handle",	target_handle) 
  206. 	vint_set_property(tween_handle, "start_time",		vint_get_time_index() + start_time_offset) 
  207. 	vint_set_property(tween_handle, "state",				"running") 
  208. end 
  209.  
  210. function var_to_string(var) 
  211. 	if type(var) == "table" then 
  212. 		return "{table}" 
  213. 	elseif var == nil then 
  214. 		return "nil" 
  215. 	elseif var == true then 
  216. 		return "true" 
  217. 	elseif var == false then 
  218. 		return "false" 
  219. 	else 
  220. 		return var 
  221. 	end 
  222. end 
  223.  
  224. --Sets actual size of the element. This is independant of the parent scaler values. 
  225. function element_set_actual_size(element_h, width, height) 
  226. 	local current_width, current_height = vint_get_property(element_h, "unscaled_size") 
  227. 	if current_width == nil or current_height == nil then 
  228. 		debug_print("vint", "Can't set actual size, element handle: " .. element_h .. " does not exist.\n") 
  229. 		return false 
  230. 	end 
  231. 	if width == nil or width == nil then 
  232. 		debug_print("vint", "Can't set actual size, element handle: " .. element_h .. " does not exist.\n") 
  233. 		return false 
  234. 	end 
  235. 	 
  236. 	local scale_x = width/current_width 
  237. 	local scale_y = height/current_height 
  238. 	vint_set_property(element_h, "scale", scale_x, scale_y) 
  239. 	return true 
  240. end 
  241.  
  242. --Returns actual size of the element, indpendant from the parent scaler values. 
  243. function element_get_actual_size(element_h) 
  244. 	local width, height = vint_get_property(element_h, "unscaled_size") 
  245. 	local scale_x, scale_y = vint_get_property(element_h, "scale") 
  246. 	if width == nil or width == nil or scale_x == nil or scale_y == nil then 
  247. 		debug_print("vint", "Can't get actual size, element handle: " .. element_h .. " does not exist.\n") 
  248. 		return 0, 0 
  249. 	end 
  250. 	 
  251. 	width = width * scale_x 
  252. 	height = height * scale_y 
  253. 	return width, height 
  254. end 
  255.  
  256. function element_get_scale_from_size(element_h, width, height) 
  257. 	local current_width, current_height = vint_get_property(element_h, "unscaled_size") 
  258. 	if current_width == nil or current_height == nil then 
  259. 		debug_print("vint", "Can't set actual size, element handle: " .. element_h .. " does not exist.\n") 
  260. 		return 0, 0 
  261. 	end 
  262. 	local scale_x = width/current_width 
  263. 	local scale_y = height/current_height 
  264. 	return scale_x, scale_y 
  265. end 
  266.  
  267. ------------------------------------------------------------------------------- 
  268. -- Returns the size of the first level elements within a group. 
  269. -- Notes: (ONLY 1 Deep, does not recurse), (Does not work on Vdos) 
  270. --  
  271. -- 
  272. function group_get_actual_size(group_h) 
  273. 	if group_h == 0 or group_h == nil then 
  274. 		debug_print("vint", "Not a valid group handle. Found data type: " .. type(group_h) .. "\n") 
  275. 	end 
  276.  
  277. 	local a_x, a_y, b_x, b_y 
  278.  
  279. 	local child_h = vint_object_first_child(group_h) 
  280. 	while true do 
  281.  
  282. 		local x, y = vint_get_property(child_h, "anchor") 
  283. 		local width, height = element_get_actual_size(child_h) 
  284. 		 
  285. 		local c_x = x 
  286. 		local c_y = y 
  287. 		local d_x = x + width 
  288. 		local d_y = y + height 
  289. 		 
  290. 		if a_x == nil then 
  291. 			a_x = x 
  292. 			a_y = y 
  293. 			b_x = x 
  294. 			b_y = y 
  295. 		end 
  296. 		 
  297. 		a_x = min(c_x, a_x) 
  298. 		a_y = min(c_y, a_y) 
  299. 		b_x = max(d_x, b_x) 
  300. 		b_y = max(d_y, b_y) 
  301.  
  302. 		child_h = vint_object_next_sibling(child_h) 
  303. 		if child_h == nil or child_h == 0 then 
  304. 			break 
  305. 		end 
  306. 	end 
  307. 	 
  308. 	local width 	= b_x - a_x 
  309. 	local height 	= b_y - a_y  
  310. 	 
  311. 	return width, height 
  312. end 
  313.  
  314. ------------------------------------------------------------------------------- 
  315. -- Align elements in vertical direction... 
  316. --		 local data = { 
  317. --				{	h = handle, 
  318. --					type = VINT_OBJECT_GROUP 
  319. --					space = 10,}, 
  320. --				{	h = handle, 
  321. --					type = VINT_OBJECT_GROUP 
  322. --					space = 10,}, 
  323. --			} 
  324. -- @returns width and height of all the elements 
  325. ------------------------------------------------------------------------------- 
  326. ------------------------------------------------------------------------------- 
  327. -- Align elements in vertical direction... 
  328. --		 local data = { 
  329. --				{	h = handle, 
  330. --					type = VINT_OBJECT_GROUP 
  331. --					space = 10,}, 
  332. --				{	h = handle, 
  333. --					type = VINT_OBJECT_GROUP 
  334. --					space = 10,}, 
  335. --			} 
  336. -- @returns width and height of all the elements 
  337. ------------------------------------------------------------------------------- 
  338. function vint_align_elements(data) 
  339. 	local x, y, width, height 
  340. 	local space = 0  
  341. 	local prev_x 		= 0 
  342. 	local prev_y 		= 0 
  343. 	local prev_width 	= 0 
  344. 	local prev_height = 0 
  345. 	local start_x, start_y  
  346. 	for idx, element in pairs(data) do 
  347. 		x, y = vint_get_property(element.h, "anchor") 
  348. 		if idx < 2 then 
  349. 			--first element will start their positions from original spot. 
  350. 			start_x = x 
  351. 			prev_x = x 
  352. 			start_y = y 
  353. 			prev_y = y 
  354. 			--skip spacing of first element. 
  355. 			space = 0 
  356. 		else 
  357. 			--elements after 1 will use the spacing variable... 
  358. 			space = element.space 
  359. 		end 
  360. 		if element.type == VINT_OBJECT_GROUP then 
  361. 			width, height = group_get_actual_size(element.h) 
  362. 		elseif element.type == VINT_OBJECT_INVALID then 
  363. 			width = 0 
  364. 			height = 0 
  365. 		else 
  366. 			width, height = element_get_actual_size(element.h) 
  367. 		end 
  368. 		 
  369. 		y = prev_y + prev_height + space 
  370. 		vint_set_property(element.h, "anchor", x, y) 
  371. 		prev_x = x 
  372. 		prev_y = y 
  373. 		prev_width 	= width 
  374. 		prev_height = height 
  375. 	end 
  376. 	width 	= x + width - start_x  
  377. 	height 	= y + height - start_y 
  378. 	return width, height 
  379. end 
  380.  
  381. ------------------------------------------------------------------------------- 
  382. -- A debug function that does a debug_print of values of a dataitem paired with strings. 
  383. -- Outputs to the console window the dataitem handle along with the paired values 
  384. -- for the strings entered. 
  385. -- 
  386. -- @param di_h		The dataitem that you would like to print. 
  387. -- @param ...		Arguments each item in dataitem 
  388.  
  389. -- Example: dataitem_to_debug(di_h, "icon_bmp_name", "coord_x", "coord_y") 
  390. ------------------------------------------------------------------------------- 
  391. function dataitem_to_debug(di_h, ...) 
  392. 	local data = {} 
  393. 	data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23], data[24] = vint_dataitem_get(di_h)  
  394. 	 
  395. 	local return_string = "\n" 
  396. 	 
  397. 	debug_print("vint", "DATAITEM: di_h\n") 
  398. 	 
  399. 	for idx, val in pairs(arg) do 
  400. 		if type(idx) ~= "string" then 
  401. 			if idx > 25 then 
  402. 				debug_print("vint", "Too much data for this debug function dataitem_to_debug(). Increase number of arguments on the dataitem get.\n") 
  403. 				return 
  404. 			end 
  405. 			 
  406. 			if idx > 0 then  
  407. 				--Print... dataitem_name, and value... 
  408. 				if idx == arg.n then 
  409. 					--Last string in list... do a double return. 
  410. 					return_string = "\n\n" 
  411. 				end 
  412. 				debug_print("vint", "  " .. val .. ":\t\t" .. var_to_string(data[idx]) .. return_string) 
  413. 			end 
  414. 		end		 
  415. 	end 
  416. end 
  417.  
  418. --------------------------------------------------------------- 
  419. --  Returns scaled value if game is in standard def 
  420. -- 
  421. -- @param value          - Value to scale for std def 
  422. -- @param operator       - Determines which operator 
  423. --                         to perform on value 
  424. --                              
  425. --                       0 = multiply (default) 
  426. --                       1 = divide 
  427. --------------------------------------------------------------- 
  428. function vint_to_std_res(value, operator) 
  429. 	if vint_is_std_res() then  
  430.       if operator == nil or operator == 0 then 
  431. 			value = value * SCALE_STD_RES 
  432. 		elseif operator == 1 then 
  433. 			value = value / SCALE_STD_RES 
  434. 		end 
  435.     return value 
  436. 	end 
  437. 	return value 
  438. end	 
  439.  
  440. -- Support for hud monkey business 
  441. Hud_has_focus = true 
  442.  
  443. -- Math stuffs 
  444. PI = 3.1415 
  445. PI2 = 6.283 
  446.  
  447. --======================================= 
  448. --MP Utilities 
  449. --======================================= 
  450. MP_gameplay_mode_names = { 
  451. 	"Pre-game lobby", 
  452. 	"Gangsta Brawl", 
  453. 	"Team Gangsta Brawl", 
  454. 	"Braveheart", 
  455. 	"Multiplayer Creation", 
  456. 	"Multiplayer Customization", 
  457. 	"Multiplayer Game Results", 
  458. 	"Multiplayer Scoreboard", 
  459. 	"Multiplayer Tutorial", 
  460. } 
  461.  
  462. function mp_is_enabled() 
  463. 	--Get some multiplayer Data 
  464. 	local gp_mode = game_get_pending_game_play_mode() 
  465. 	for i, m in pairs( MP_gameplay_mode_names ) do 
  466. 		if gp_mode == m then 
  467. 			--found a match 
  468. 			return true 
  469. 		end 
  470. 	end 
  471. 	 
  472. 	gp_mode = game_get_game_play_mode() 
  473. 	for i, m in pairs( MP_gameplay_mode_names ) do 
  474. 		if gp_mode == m then 
  475. 			--found a match 
  476. 			return true 
  477. 		end 
  478. 	end 
  479. 	return false 
  480. end 
  481.  
  482. function ui_audio_post_event( event_name ) 
  483. 	audio_object_post_event(event_name, nil, nil, nil, false) 
  484. end 
  485.  
  486. --####################################### 
  487. --Audio Delay 
  488. --####################################### 
  489. function audio_play_delayed(sound_id, offset) 
  490. 	thread_new("audio_play_delayed_thread", sound_id, offset) 
  491. end 
  492.  
  493. function audio_play_delayed_thread(sound_id, offset) 
  494. 	delay(offset) 
  495. 	game_audio_play(sound_id) 
  496. end 
  497.  
  498. function format_cash(cash) 
  499. 	return game_format_int_to_string(cash) 
  500. end 
  501.  
  502. function format_cash_add_padding(c) 
  503. 	if c < 10 then 
  504. 		return "00" .. c 
  505. 	elseif c < 100 then 
  506. 		return "0" .. c 
  507. 	else  
  508. 		return c 
  509. 	end 
  510. end 
  511.  
  512. function format_distance(distance_in_meters) 
  513.  
  514. 	local distance_in_feet 
  515. 	local distance_str 
  516. 	 
  517. 	if game_use_imperial_units() then 
  518. 	 
  519. 		distance_in_feet = distance_in_meters * FEET_PER_METER		 
  520. 		distance_str = floor(distance_in_feet).." ft" 
  521. 		 
  522. 		return distance_str 
  523. 	 
  524. 	else 
  525. 		 
  526. 		distance_str = floor(distance_in_meters).." m" 
  527. 	 
  528. 		return distance_str 
  529. 	 
  530. 	end 
  531.  
  532. end 
  533.  
  534. ------------------------------------------------------------------------------- 
  535. -- Formats seconds into clock format 
  536. -- @param	time_in_seconds	time in seconds 
  537. -- @param	show_ms				whether or not you want to show ms (00:00 or 00:00.00) 
  538. -- 
  539. function format_clock(time_in_seconds, show_ms) 
  540. 	 
  541. 	local neg_symbol = "" 
  542. 	 
  543. 	if time_in_seconds < 0 then 
  544. 		time_in_seconds = abs(time_in_seconds) 
  545. 		neg_symbol  = "-" 
  546. 	end 
  547.  
  548. 	-- Format the time 
  549. 	local minutes = floor(time_in_seconds / 60) 
  550. 	local milliseconds =  (time_in_seconds * 1000) % 1000 
  551. 	local seconds = floor(time_in_seconds) % 60 
  552. 	 
  553. 	seconds = abs(seconds) -- Negative time is handled earlier, this should always be positive. 
  554. 	 
  555. 	-- Pad the seconds for the timer 
  556. 	if seconds < 10 and minutes > 0 then 
  557. 		seconds = "0" .. seconds 
  558. 	end 
  559. 	 
  560. 	if show_ms == true then 
  561. 		-- Only show one decimal place 
  562. 		milliseconds = milliseconds * .01 
  563. 	 
  564. 		milliseconds = floor(milliseconds)	 
  565. 	 
  566. 		if minutes > 0 then 
  567. 			return neg_symbol .. minutes .. ":" .. seconds .. "." .. milliseconds 
  568. 		else 
  569. 			return neg_symbol .. seconds .. "." .. milliseconds 
  570. 		end 
  571. 	else 
  572. 		if minutes > 0 then 
  573. 			return neg_symbol .. minutes .. ":" .. seconds  
  574. 		else 
  575. 			return neg_symbol .. seconds 
  576. 		end 
  577. 	end 
  578. end 
  579.  
  580.  
  581. ---------------------------------------------------------------------------------------------- 
  582. -- Formats seconds into time format 00:00 min or 00:00.00 min 
  583. -- @param	time_in_seconds	time in seconds 
  584. -- @param	show_ms				whether or not you want to show ms 
  585. -- @param	show_units			whether or not you want to show units of time ("mins" or "secs") 
  586. -- 
  587. function format_time(time_in_seconds, show_ms, show_units) 
  588. 	 
  589. 	-- since show_units is a new addition and the default behavior is to show units 
  590. 	-- defaulting nil to true 
  591. 	if show_units == nil then 
  592. 		show_units = true 
  593. 	end 
  594. 	 
  595. 	local neg_symbol = "" 
  596. 	 
  597. 	if time_in_seconds < 0 then 
  598. 		time_in_seconds = abs(time_in_seconds) 
  599. 		neg_symbol  = "-" 
  600. 	end 
  601.  
  602. 	-- Format the time 
  603. 	local minutes = floor(time_in_seconds / 60) 
  604. 	local milliseconds =  (time_in_seconds * 1000) % 1000 
  605. 	local seconds = floor(time_in_seconds) % 60 
  606. 	 
  607. 	seconds = abs(seconds) -- Negative time is handled earlier, this should always be positive. 
  608. 	 
  609. 	-- Pad the seconds for the timer 
  610. 	if seconds < 10 and minutes > 0 then 
  611. 		seconds = "0" .. seconds 
  612. 	end 
  613. 	 
  614. 	if show_ms == true then 
  615. 	 
  616. 		-- Only show one decimal place 
  617. 		milliseconds = milliseconds * .01 
  618. 	 
  619. 		milliseconds = floor(milliseconds)	 
  620. 	 
  621. 		--localize "secs" and "mins" then return string 
  622. 		if minutes > 0 then 
  623. 			if show_units == false then 
  624. 				return neg_symbol .. minutes .. ":" .. seconds .. ".".. milliseconds 
  625. 			else 
  626. 				local insert_values = {[0] = neg_symbol .. minutes .. ":" .. seconds .. ".".. milliseconds} 
  627. 				local body = vint_insert_values_in_string("FORMAT_TIME_MINS", insert_values) 
  628. 				return body 
  629. 			end 
  630. 		else 
  631. 			if show_units == false then 
  632. 				return neg_symbol .. seconds .. "."..milliseconds 
  633. 			else 
  634. 				local insert_values = {[0] = neg_symbol .. seconds .. "."..milliseconds} 
  635. 				local body = vint_insert_values_in_string("FORMAT_TIME_SECS", insert_values) 
  636. 				return body			 
  637. 			end	 
  638. 		end 
  639. 	else 
  640. 		if minutes > 0 then 
  641. 			if show_units == false then 
  642. 				return neg_symbol .. minutes .. ":" .. seconds 
  643. 			else 
  644. 				local insert_values = {[0] = neg_symbol .. minutes .. ":" .. seconds} 
  645. 				local body = vint_insert_values_in_string("FORMAT_TIME_MINS", insert_values) 
  646. 				return body		 
  647. 			end			 
  648. 		else 
  649. 			if show_units == false then 
  650. 				return neg_symbol .. seconds 
  651. 			else 
  652. 				local insert_values = {[0] = neg_symbol .. seconds} 
  653. 				local body = vint_insert_values_in_string("FORMAT_TIME_SECS", insert_values) 
  654. 				return body			 
  655. 			end 
  656. 		end 
  657. 	end 
  658. end 
  659.  
  660.  
  661. ---------------------------------------------------------------------------------------------------- 
  662. -- Button remapping... 
  663. ---------------------------------------------------------------------------------------------------- 
  664. --Map buttons for globals on ui init 
  665. CTRL_MENU_BUTTON_A = -1 
  666. CTRL_GAMEPLAY_BUTTON_A = -1 
  667. CTRL_MENU_BUTTON_B = -1 
  668. CTRL_GAMEPLAY_BUTTON_B = -1 
  669. CTRL_BUTTON_X = -1 
  670. CTRL_BUTTON_Y = -1 
  671.  
  672. CTRL_BUTTON_LB = -1 
  673. CTRL_BUTTON_LT = -1 
  674. CTRL_BUTTON_RB = -1 
  675. CTRL_BUTTON_RT = -1 
  676.  
  677. CTRL_BUTTON_LS = -1 
  678. CTRL_BUTTON_LS_PRESS = -1 
  679. CTRL_BUTTON_RS = -1 
  680. CTRL_BUTTON_RS_PRESS = -1 
  681.  
  682. CTRL_BUTTON_DPAD = -1 
  683. CTRL_BUTTON_DPAD_UP = -1 
  684. CTRL_BUTTON_DPAD_DOWN = -1 
  685. CTRL_BUTTON_DPAD_LEFT = -1 
  686. CTRL_BUTTON_DPAD_RIGHT = -1 
  687.  
  688. CTRL_BUTTON_DPAD_UP_DOWN = -1 
  689. CTRL_BUTTON_DPAD_LEFT_RIGHT = -1 
  690.  
  691. CTRL_MENU_BUTTON_BACK = -1 
  692. CTRL_BUTTON_START = -1 
  693.  
  694. function vint_lib_init_buttons() 
  695. 	--Map buttons for globals on ui init 
  696. 	-- 
  697. 	-- SEH 8/15/2011: PS3 can swap the meaning of the accept and cancel buttons for menus, but we don't want to 
  698. 	-- swap them for gameplay.  Making separate variables to handle this.  Ideally, for SR4, the other buttons will 
  699. 	-- get renamed to be more consistent, or how this is handled will be changed. 
  700. 	-- 
  701. 	CTRL_MENU_BUTTON_A = get_a_button(false) 
  702. 	CTRL_GAMEPLAY_BUTTON_A = get_a_button(true) 
  703. 	CTRL_MENU_BUTTON_B = get_b_button(false) 
  704. 	CTRL_GAMEPLAY_BUTTON_B = get_b_button(true)	 
  705. 	CTRL_BUTTON_X = get_x_button() 
  706. 	CTRL_BUTTON_Y = get_y_button() 
  707.  
  708. 	CTRL_BUTTON_LB = get_lb_button() 
  709. 	CTRL_BUTTON_LT = get_lt_button() 
  710. 	CTRL_BUTTON_RB = get_rb_button() 
  711. 	CTRL_BUTTON_RT = get_rt_button() 
  712.  
  713. 	CTRL_BUTTON_LS 		= get_left_stick() 
  714. 	CTRL_BUTTON_LS_PRESS = get_ls_press_image() 
  715. 	CTRL_BUTTON_RS 		= get_right_stick() 
  716. 	CTRL_BUTTON_RS_PRESS = get_rs_press_image() 
  717.  
  718. 	CTRL_BUTTON_DPAD = get_dpad_image() 
  719. 	CTRL_BUTTON_DPAD_UP = get_dpad_up_image() 
  720. 	CTRL_BUTTON_DPAD_DOWN = get_dpad_down_image() 
  721. 	CTRL_BUTTON_DPAD_LEFT = get_dpad_left_image() 
  722. 	CTRL_BUTTON_DPAD_RIGHT = get_dpad_right_image() 
  723. 	CTRL_BUTTON_DPAD_UP_DOWN = get_dpad_ud_image() 
  724.    CTRL_BUTTON_DPAD_LEFT_RIGHT = get_dpad_lr_image() 
  725. 	 
  726. 	CTRL_MENU_BUTTON_BACK =  get_back_image() 
  727. 	CTRL_BUTTON_START = get_start_image() 
  728. end 
  729.  
  730. -- this is now unofficially get_confirm_button! 
  731. function get_a_button(for_gameplay) 
  732. 	local button 
  733. 	local platform = game_get_platform() 
  734. 	if (platform == "XBOX360") or (platform == "PC") then 
  735. 		button = "ui_ctrl_360_btn_a" 
  736. 	else 
  737. 		local button_swap = game_get_ps3_button_swap() and for_gameplay == false 
  738. 		if button_swap == true then 
  739. 			button = "ui_ctrl_ps3_btn_circle" 
  740. 		else  
  741. 		-- old standard 
  742. 			button = "ui_ctrl_ps3_btn_cross" 
  743. 		end 
  744. 	end 
  745. 	 
  746. 	return button 
  747. end 
  748.  
  749. function get_x_button() 
  750. 	local button 
  751. 	local platform = game_get_platform() 
  752. 	if (platform == "XBOX360") or (platform == "PC") then 
  753. 		button = "ui_ctrl_360_btn_x" 
  754. 	else 
  755. 		button = "ui_ctrl_ps3_btn_square" 
  756. 	end 
  757. 	return button 
  758. end 
  759.  
  760. -- this is now unofficially get_back_button! 
  761. function get_b_button(for_gameplay) 
  762. 	local button 
  763. 	local platform = game_get_platform() 
  764. 	if (platform == "XBOX360") or (platform == "PC") then 
  765. 		button = "ui_ctrl_360_btn_b" 
  766. 	else 
  767. 		local button_swap = game_get_ps3_button_swap() and for_gameplay == false 
  768. 		if button_swap == true then 
  769. 			button = "ui_ctrl_ps3_btn_cross" 
  770. 		else  
  771. 			button = "ui_ctrl_ps3_btn_circle" 
  772. 		end 
  773. 	end 
  774. 	return button 
  775. end 
  776.  
  777. function get_y_button() 
  778. 	local button 
  779. 	local platform = game_get_platform() 
  780. 	if (platform == "XBOX360") or (platform == "PC") then 
  781. 		button = "ui_ctrl_360_btn_y" 
  782. 	else 
  783. 		button = "ui_ctrl_ps3_btn_triangle" 
  784. 	end 
  785. 	return button 
  786. end 
  787.  
  788. function get_right_stick() 
  789. 	local button 
  790. 	local platform = game_get_platform() 
  791. 	if (platform == "XBOX360") or (platform == "PC") then 
  792. 		button = "ui_ctrl_360_btn_rs" 
  793. 	else 
  794. 		button = "ui_ctrl_ps3_btn_r" 
  795. 	end 
  796. 	return button 
  797. end 
  798.  
  799. function get_left_stick() 
  800. 	local button 
  801. 	local platform = game_get_platform() 
  802. 	if (platform == "XBOX360") or (platform == "PC") then 
  803. 		button = "ui_ctrl_360_btn_ls" 
  804. 	else 
  805. 		button = "ui_ctrl_ps3_btn_l" 
  806. 	end 
  807. 	return button 
  808. end 
  809.  
  810. function get_lt_button() 
  811. 	local button 
  812. 	local platform = game_get_platform() 
  813. 	if (platform == "XBOX360") or (platform == "PC") then 
  814. 		button = "ui_ctrl_360_btn_lt" 
  815. 	else 
  816. 		button = "ui_ctrl_ps3_btn_l1" 
  817. 	end 
  818. 	return button 
  819. end 
  820.  
  821. function get_rt_button() 
  822. 	local button 
  823. 	local platform = game_get_platform() 
  824. 	if (platform == "XBOX360") or (platform == "PC") then 
  825. 		button = "ui_ctrl_360_btn_rt" 
  826. 	else 
  827. 		button = "ui_ctrl_ps3_btn_r1" 
  828. 	end 
  829. 	return button 
  830. end 
  831.  
  832. function get_lb_button() 
  833. 	local button 
  834. 	local platform = game_get_platform() 
  835. 	if (platform == "XBOX360") or (platform == "PC") then 
  836. 		button = "ui_ctrl_360_btn_lb" 
  837. 	else 
  838. 		button = "ui_ctrl_ps3_btn_l2" 
  839. 	end 
  840. 	return button 
  841. end 
  842.  
  843. function get_rb_button() 
  844. 	local button 
  845. 	local platform = game_get_platform() 
  846. 	if (platform == "XBOX360") or (platform == "PC") then 
  847. 		button = "ui_ctrl_360_btn_rb" 
  848. 	else 
  849. 		button = "ui_ctrl_ps3_btn_r2" 
  850. 	end 
  851. 	return button 
  852. end 
  853.  
  854. function get_left_right() 
  855. 	local button 
  856. 	local platform = game_get_platform() 
  857. 	if (platform == "XBOX360") or (platform == "PC") then 
  858. 		button = "ui_ctrl_360_dpad_lr" 
  859. 	else 
  860. 		button = "ui_ctrl_ps3_dapd_lr" 
  861. 	end 
  862. 	return button 
  863. end 
  864.  
  865. function get_up_down() 
  866. 	local button 
  867. 	local platform = game_get_platform() 
  868. 	if (platform == "XBOX360") or (platform == "PC") then 
  869. 		button = "ui_ctrl_360_dpad_ud" 
  870. 	else 
  871. 		button = "ui_ctrl_ps3_dpad_ud" 
  872. 	end 
  873. 	return button 
  874. end 
  875.  
  876. function get_left_trigger() 
  877. 	local button 
  878. 	local platform = game_get_platform() 
  879. 	if (platform == "XBOX360") or (platform == "PC") then 
  880. 		button = "ui_ctrl_360_btn_lt" 
  881. 	else 
  882. 		button = "ui_ctrl_ps3_btn_l2" 
  883. 	end 
  884. 	return button 
  885. end 
  886.  
  887. function get_right_trigger() 
  888. 	local button 
  889. 	local platform = game_get_platform() 
  890. 	if (platform == "XBOX360") or (platform == "PC") then 
  891. 		button = "ui_ctrl_360_btn_rt" 
  892. 	else 
  893. 		button = "ui_ctrl_ps3_btn_r2" 
  894. 	end 
  895. 	return button 
  896. end 
  897.  
  898. function get_control_stick_base() 
  899. 	local image 
  900. 	local platform = game_get_platform() 
  901. 	if (platform == "XBOX360") or (platform == "PC") then 
  902. 		image = "ui_hud_radial_stick_base_xbox2" 
  903. 	else 
  904. 		image = "ui_hud_radial_stick_base_ps3" 
  905. 	end 
  906. 	return image 
  907. end 
  908.  
  909. function get_control_stick_thumb() 
  910. 	local image 
  911. 	local platform = game_get_platform() 
  912. 	if (platform == "XBOX360") or (platform == "PC") then 
  913. 		image = "ui_hud_radial_stick_thumb_xbox2" 
  914. 	else 
  915. 		image = "ui_hud_radial_stick_thumb_ps3" 
  916. 	end 
  917. 	return image 
  918. end 
  919.  
  920. function get_control_stick_text() 
  921. 	local text 
  922. 	local platform = game_get_platform() 
  923. 	 
  924. 	if pause_menu_is_using_southpaw_control_scheme() == true and game_is_local_player_in_vehicle() == false then 
  925. 		if (platform == "XBOX360") or (platform == "PC") then 
  926. 			text = "RS" 
  927. 		else 
  928. 			text = "R" 
  929. 		end	 
  930. 	elseif pause_menu_is_using_vehicle_southpaw_control_scheme() == true and game_is_local_player_in_vehicle() == true then 
  931. 		if (platform == "XBOX360") or (platform == "PC") then 
  932. 			text = "RS" 
  933. 		else 
  934. 			text = "R" 
  935. 		end 
  936. 	else  
  937. 		if (platform == "XBOX360") or (platform == "PC") then 
  938. 			text = "LS" 
  939. 		else 
  940. 			text = "L" 
  941. 		end	 
  942. 	end  
  943. 	return text 
  944. end 
  945.  
  946. function get_dpad_image() 
  947. 	local image 
  948. 	local platform = game_get_platform() 
  949. 	if (platform == "XBOX360") or (platform == "PC") then 
  950. 		image = "ui_hud_radial_dpad_xbox2" 
  951. 	else 
  952. 		image = "ui_hud_radial_dpad_ps3" 
  953. 	end 
  954. 	return image 
  955. end 
  956.  
  957. function get_dpad_lr_image() 
  958. 	local image 
  959. 	local platform = game_get_platform() 
  960. 	if (platform == "XBOX360") or (platform == "PC") then 
  961. 		image = "ui_ctrl_360_dpad_lr" 
  962. 	else 
  963. 		image = "ui_ctrl_ps3_dpad_lr" 
  964. 	end 
  965. 	return image 
  966. end 
  967.  
  968. function get_dpad_ud_image() 
  969. 	local image 
  970. 	local platform = game_get_platform() 
  971. 	if (platform == "XBOX360") or (platform == "PC") then 
  972. 		image = "ui_ctrl_360_dpad_ud" 
  973. 	else 
  974. 		image = "ui_ctrl_ps3_dpad_ud" 
  975. 	end 
  976. 	return image 
  977. end 
  978.  
  979. function get_dpad_image() 
  980. 	local image 
  981. 	local platform = game_get_platform() 
  982. 	if (platform == "XBOX360") or (platform == "PC") then 
  983. 		image = "ui_ctrl_360_dpad_n" 
  984. 	else 
  985. 		image = "ui_ctrl_ps3_dpad_n" 
  986. 	end 
  987. 	return image 
  988. end 
  989.  
  990. function get_dpad_up_image() 
  991. 	local image 
  992. 	local platform = game_get_platform() 
  993. 	if (platform == "XBOX360") or (platform == "PC") then 
  994. 		image = "ui_ctrl_360_dpad_u" 
  995. 	else 
  996. 		image = "ui_ctrl_ps3_dpad_u" 
  997. 	end 
  998. 	return image 
  999. end 
  1000.  
  1001. function get_dpad_down_image() 
  1002. 	local image 
  1003. 	local platform = game_get_platform() 
  1004. 	if (platform == "XBOX360") or (platform == "PC") then 
  1005. 		image = "ui_ctrl_360_dpad_d" 
  1006. 	else 
  1007. 		image = "ui_ctrl_ps3_dpad_d" 
  1008. 	end 
  1009. 	return image 
  1010. end 
  1011.  
  1012. function get_dpad_left_image() 
  1013. 	local image 
  1014. 	local platform = game_get_platform() 
  1015. 	if (platform == "XBOX360") or (platform == "PC") then 
  1016. 		image = "ui_ctrl_360_dpad_l" 
  1017. 	else 
  1018. 		image = "ui_ctrl_ps3_dpad_l" 
  1019. 	end 
  1020. 	return image 
  1021. end 
  1022.  
  1023. function get_dpad_right_image() 
  1024. 	local image 
  1025. 	local platform = game_get_platform() 
  1026. 	if (platform == "XBOX360") or (platform == "PC") then 
  1027. 		image = "ui_ctrl_360_dpad_r" 
  1028. 	else 
  1029. 		image = "ui_ctrl_ps3_dpad_r" 
  1030. 	end 
  1031. 	return image 
  1032. end 
  1033.  
  1034. function get_ls_press_image() 
  1035. 	local image 
  1036. 	local platform = game_get_platform() 
  1037. 	if (platform == "XBOX360") or (platform == "PC") then 
  1038. 		image = "ui_ctrl_360_btn_ls_press" 
  1039. 	else 
  1040. 		image = "ui_ctrl_ps3_btn_l3" 
  1041. 	end 
  1042. 	return image 
  1043. end 
  1044.  
  1045. function get_rs_press_image() 
  1046. 	local image 
  1047. 	local platform = game_get_platform() 
  1048. 	if (platform == "XBOX360") or (platform == "PC") then 
  1049. 		image = "ui_ctrl_360_btn_rs_press" 
  1050. 	else 
  1051. 		image = "ui_ctrl_ps3_btn_r3" 
  1052. 	end 
  1053. 	return image 
  1054. end 
  1055.  
  1056.  
  1057. function get_start_image() 
  1058. 	local image 
  1059. 	local platform = game_get_platform() 
  1060. 	if (platform == "XBOX360") or (platform == "PC") then 
  1061. 		image = "ui_ctrl_360_btn_start" 
  1062. 	else 
  1063. 		image = "ui_ctrl_ps3_btn_start" 
  1064. 	end 
  1065. 	return image 
  1066. end 
  1067.  
  1068. function get_back_image() 
  1069. 	local image 
  1070. 	local platform = game_get_platform() 
  1071. 	if (platform == "XBOX360") or (platform == "PC") then 
  1072. 		image = "ui_ctrl_360_btn_back" 
  1073. 	else 
  1074. 		image = "ui_ctrl_ps3_btn_select" 
  1075. 	end 
  1076. 	return image 
  1077. end 
  1078.  
  1079. function get_actual_a_button() 
  1080. 	local button 
  1081. 	local platform = game_get_platform() 
  1082. 	if (platform == "XBOX360") or (platform == "PC") then 
  1083. 		button = "ui_ctrl_360_btn_a" 
  1084. 	else 
  1085. 		button = "ui_ctrl_ps3_btn_cross" 
  1086. 	end 
  1087. 	 
  1088. 	return button 
  1089. end 
  1090.  
  1091. function get_actual_b_button() 
  1092. 	local button 
  1093. 	local platform = game_get_platform() 
  1094. 	if (platform == "XBOX360") or (platform == "PC") then 
  1095. 		button = "ui_ctrl_360_btn_b" 
  1096. 	else 
  1097. 		button = "ui_ctrl_ps3_btn_circle" 
  1098. 	end 
  1099. 	return button 
  1100. end 
  1101.  
  1102. function table_clone(src) 
  1103. 	local dst = { } 
  1104.  
  1105. 	if src == nil then 
  1106. 		return nil 
  1107. 	end 
  1108. 	 
  1109. 	for k, v in pairs(src) do 
  1110. --		if type(v) == "table" then 
  1111. --			dst[k] = table_clone(v) 
  1112. --		else 
  1113. 			dst[k] = v 
  1114. --		end 
  1115. 	end 
  1116. 	 
  1117. 	return dst 
  1118. end 
  1119.  
  1120. ------------------------------------------------------------------------------- 
  1121. -- Prints all the key value pairs for a table. (Does not do deep tables) 
  1122. -- 
  1123. function lua_debug_table(table) 
  1124. 	for key, val in pairs(table) do 
  1125. 		debug_print("vint", "key: " .. var_to_string(key) .. "| val: " .. var_to_string(val) .. "\n") 
  1126. 	end 
  1127. end 
  1128.  
  1129. --Limits value between low and high 
  1130. function limit(value, low, high) 
  1131. 	if value < low then 
  1132. 		value = low 
  1133. 	elseif value > high then 
  1134. 		value = high 
  1135. 	end 
  1136. 	 
  1137. 	return value 
  1138. end 
  1139.  
  1140. -- Helper function for list options that wraps indexes 
  1141. -- 
  1142. -- current_idx: current value 
  1143. -- direction: value to add/subtract 
  1144. -- max_idx: maximum index value 
  1145. -- min_idx: (optional) minimum index value, defaults to 1 
  1146. function wrap_index(current_idx, direction, max_idx, min_idx) 
  1147. 	min_idx = min_idx or 1 
  1148.  
  1149. 	local idx0 = (current_idx + direction - min_idx)	-- Base 0 
  1150. 	local base = max_idx - min_idx + 1 
  1151. 	 
  1152. 	return (idx0 % base) + min_idx 
  1153. end 
  1154.  
  1155.  
  1156. -- Helper function to hide children objects... 
  1157. -- 
  1158. -- object_h: object with children underneath to hide... 
  1159. function vint_hide_children(object_h) 
  1160. 	local h = vint_object_first_child(object_h) 
  1161. 	while true do  
  1162. 		if h == nil then 
  1163. 			break 
  1164. 		end 
  1165. 		vint_set_property(h, "visible", false) 
  1166. 		h = vint_object_next_sibling(h) 
  1167. 	end 
  1168. end 
  1169.  
  1170.  
  1171. -- Simple Callback function to loop animations from tweens... 
  1172. -- usage: vint_set_property(twn_h, "end_event", "vint_anim_loop_callback") 
  1173. -- This will cause the animation to continue to loop... 
  1174. function vint_anim_loop_callback(tween_h, event) 
  1175. 	local anim_h = vint_object_parent(tween_h) 
  1176. 	lua_play_anim(anim_h) 
  1177. end 
  1178.  
  1179. -- Helper function to dump pause map to get more memory in certain screens 
  1180. -- 
  1181. function pause_map_dump() 
  1182. 	game_peg_unload("ui_map_world_city") 
  1183. end 
  1184.  
  1185. function do_nothing() 
  1186. end 
  1187.  
  1188. -- Helper function to reload pause map 
  1189. -- 
  1190. function pause_map_restore() 
  1191. 	if (game_is_going_to_main_menu() == false) and (game_is_debug_reloading_level() == false) then 
  1192. 		game_peg_load_with_cb("do_nothing", 1, "ui_map_world_city")	 
  1193. 	end 
  1194. end 
  1195.  
  1196. -- Returns the widest element... useful for finding the longest string or element in a field... 
  1197. --  
  1198. --	@param	data	= { element_1_h, element_2_h, element_3_h }	(these are handles to elements you want to evaluate) 
  1199. -- 
  1200. -- @return largest_element_h		handle to largest element. 
  1201. -- @return largest_width			width of largest element... 
  1202. function find_widest_text_element(data) 
  1203. 	local width, height 
  1204. 	local largest_width = 0 
  1205. 	local largest_element_h = 0 
  1206. 	for idx, val in pairs(data) do 
  1207. 		width, height = element_get_actual_size(val) 
  1208. 		if width > largest_width then 
  1209. 			largest_width = width 
  1210. 			largest_element_h = val 
  1211. 		end 
  1212. 	end 
  1213. 	return largest_element_h, floor(largest_width) 
  1214. end 
  1215.  
  1216. ------------------------------------------------------------------------------- 
  1217. -- Debug prints all objects in the document tree 
  1218. -- @param vint_doc_name string for vint document e.g. "hud" 
  1219. --  
  1220. function vint_debug_safe_frame(vint_doc_name) 
  1221. 	local doc_h = vint_document_find(vint_doc_name) 
  1222. 	if doc_h == 0 or doc_h == nil then 
  1223. 		debug_print("vint", "vint_debug_safe_frame() " .. var_to_string(vint_doc_name) .. " was not found...\n") 
  1224. 		return 
  1225. 	end 
  1226.  
  1227. 	local safe_frame_h = vint_object_find("safe_frame", 0, doc_h) 
  1228. 	vint_debug_safe_frame_objects(safe_frame_h, 0) 
  1229. end 
  1230.  
  1231. ------------------------------------------------------------------------------- 
  1232. -- Debug prints all objects below the element sent in, 
  1233. -- @param vint_doc_name string for vint document e.g. "hud" 
  1234. --  
  1235. function vint_debug_safe_frame_objects(object_h, depth) 
  1236. 	if depth == nil then 
  1237. 		depth = 0 
  1238. 	end 
  1239. 	if object_h ~= nil and object_h ~= 0 then 
  1240. 		local depth_str = "" 
  1241. 		for i = 1, depth do 
  1242. 			depth_str = depth_str .. "   " 
  1243. 		end 
  1244. 		 
  1245. 		--Name, object 
  1246. 		local name = vint_object_get_name_from_handle(object_h) 
  1247. 		local debug_str = depth_str .."Name: " .. name 
  1248. 		debug_str = debug_str .. "(" ..  var_to_string(object_h) ..  ")\n" 
  1249. 		 
  1250. 		--Print it... 
  1251. 		debug_print("vint", debug_str) 
  1252. 	end 
  1253. 	 
  1254. 	local child_h = vint_object_first_child(object_h) 
  1255. 	if child_h ~= 0 and child_h ~= nil then 
  1256. 		vint_debug_safe_frame_objects(child_h, depth + 1) 
  1257. 	end 
  1258. 	 
  1259. 	local next_sibling_h = vint_object_next_sibling(object_h)  
  1260. 	if next_sibling_h ~= 0 and next_sibling_h ~= nil then 
  1261. 		vint_debug_safe_frame_objects(next_sibling_h, depth) 
  1262. 	end 
  1263. end 
  1264.  
  1265. ------------------------------------------------------------------------------- 
  1266. -- Online and Privilege  
  1267. ------------------------------------------------------------------------------- 
  1268. ONLINE_VALIDATOR_PASSED 				= 0 
  1269. ONLINE_VALIDATOR_NO_ONLINE_PRIV		= 1 
  1270. ONLINE_VALIDATOR_NOT_SIGNED_IN		= 2 
  1271. ONLINE_VALIDATOR_NOT_ONLINE			= 3 
  1272. ONLINE_VALIDATOR_NO_ETHERNET			= 4 
  1273. ONLINE_VALIDATOR_IN_PROGRESS			= 5 
  1274.  
  1275. Online_validator_result = ONLINE_VALIDATOR_PASSED 
  1276. Online_validator_privilege_check_service = false 
  1277. Online_validator_privilege_check_online = false 
  1278. Online_validator_privilege_check_chat = false 
  1279. Online_validator_privilege_fail_on_chat = false 
  1280.  
  1281. function online_validator_check_privs() 
  1282. 	-- We need to wait a frame for PS3 to process the new multi login, otherwise the privileges are not up to date 
  1283. 	thread_yield() 
  1284. 	 
  1285. 	if Online_validator_privilege_check_online and main_menu_check_online_privilege() == false then 
  1286. 		dialog_box_message("MENU_TITLE_WARNING", "MAIN_MENU_PRIVILEGE_DENIED") 
  1287. 		Online_validator_result = ONLINE_VALIDATOR_NO_ONLINE_PRIV 
  1288. 		online_validator_set_checking(false) 
  1289. 		return 
  1290. 	end 
  1291. 	 
  1292. 	-- Chat most likely doesn't need a return code. It's just a warning 
  1293. 	-- also, we don't call it if it's already been shown for this login 
  1294. 	if Online_validator_privilege_check_chat and main_menu_check_chat_priv() == false then 
  1295. 		if Online_validator_privilege_fail_on_chat then 
  1296. 			Online_validator_result = ONLINE_VALIDATOR_NO_ONLINE_PRIV 
  1297. 			dialog_box_message("MENU_TITLE_WARNING", "USER_CONTENT_PRIV_DENIED") 
  1298. 			return 
  1299. 		else 
  1300. 			main_menu_maybe_show_voice_dialog() 
  1301. 		end 
  1302. 	end 
  1303. 	 
  1304. 	Online_validator_result = ONLINE_VALIDATOR_PASSED 
  1305. 	online_validator_set_checking(false) 
  1306. end 
  1307.  
  1308. function online_validator_sign_in_cb(result) 
  1309. 	main_menu_supress_profile_change(false) 
  1310. 	if game_is_signed_in() == false or  
  1311. 		(Online_validator_privilege_check_service and game_is_connected_to_service() == false) then 
  1312. 		if game_get_platform() ~= "PS3" then 
  1313. 			dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN") 
  1314. 		end 
  1315. 		Online_validator_result = ONLINE_VALIDATOR_NOT_ONLINE 
  1316. 		online_validator_set_checking(false) 
  1317. 	else  
  1318. 		thread_new("online_validator_check_privs") 
  1319. 	end 
  1320. end 
  1321.  
  1322. function online_validator_profile_cb(result, action) 
  1323. 	if result == 0 then 
  1324. 		main_menu_supress_profile_change(true) 
  1325. 		game_sign_into_network(true, "online_validator_sign_in_cb") 
  1326. 	else 
  1327. 		Online_validator_result = ONLINE_VALIDATOR_NOT_SIGNED_IN 
  1328. 		online_validator_set_checking(false) 
  1329. 	end 
  1330. end 
  1331.  
  1332. function online_and_privilege_validator_begin(can_sign_in, check_service, check_online_priv, check_chat_priv, in_game, fail_on_chat) 
  1333. 	Online_validator_result = ONLINE_VALIDATOR_IN_PROGRESS  
  1334.  
  1335. 	Online_validator_privilege_check_service = check_service or false 
  1336. 	Online_validator_privilege_check_online = check_online_priv or false 
  1337. 	Online_validator_privilege_check_chat = check_chat_priv or false 
  1338. 	 
  1339. 	-- DAD - 9/14/11 - This is hacked in last minute, this should get cleaned up later 
  1340. 	Online_validator_privilege_fail_on_chat = fail_on_chat or false 
  1341. 	 
  1342. 	if game_is_connected_to_network() == false then 
  1343. 		dialog_box_message("MENU_TITLE_WARNING", "NO_NETWORK_CONNECTION") 
  1344. 		Online_validator_result = ONLINE_VALIDATOR_NO_ETHERNET 
  1345. 		return 
  1346. 	end 
  1347.  
  1348. 	online_validator_set_checking(true) 
  1349. 	 
  1350. 	--see if we're on a profile 
  1351. 	if game_is_signed_in() == false then 
  1352. 		if can_sign_in then 
  1353. 			dialog_box_confirmation("CONTROL_SIGN_IN", "MUST_SIGN_IN_PROFILE_CONFIRM", "online_validator_profile_cb") 
  1354. 		else 
  1355. 			dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN") 
  1356. 		 
  1357. 			Online_validator_result = ONLINE_VALIDATOR_NOT_SIGNED_IN 
  1358. 			online_validator_set_checking(false) 
  1359. 		end 
  1360. 		return 
  1361. 	end 
  1362.  
  1363. 	-- See if we're connected to PSN or XBL 
  1364. 	if check_service == true and game_is_connected_to_service() == false then 
  1365. 		if game_get_platform() == "PC" then 
  1366. 			Online_validator_result = ONLINE_VALIDATOR_NOT_SIGNED_IN 
  1367. 			game_sign_into_network(true, "online_validator_sign_in_cb") 
  1368. 		elseif game_get_platform() == "PS3" then 
  1369. 			game_sign_into_network(true, "online_validator_sign_in_cb") 
  1370. 		else 
  1371. 			-- According to TCR/TRC, PS3 doesn't want a sign in prompt before hand, MS does. 
  1372. 			if in_game then 
  1373. 				dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN") 
  1374. 				Online_validator_result = ONLINE_VALIDATOR_NOT_ONLINE 
  1375. 				online_validator_set_checking(false) 
  1376. 			else 
  1377. 				dialog_box_confirmation("CONTROL_SIGN_IN", "MUST_LOG_IN_CONFIRM", "online_validator_profile_cb") 
  1378. 			end 
  1379. 		end 
  1380. 		return 
  1381. 	end 
  1382. 		 
  1383. 	online_validator_check_privs() 
  1384. 	 
  1385. 	if Online_validator_result == ONLINE_VALIDATOR_IN_PROGRESS then 
  1386. 		Online_validator_result = ONLINE_VALIDATOR_PASSED 
  1387. 	end 
  1388. 	online_validator_set_checking(false) 
  1389. end 
  1390.  
  1391. ------------------------------------------------------------------------------- 
  1392. -- Test Function 
  1393. ------------------------------------------------------------------------------- 
  1394. function test_interp_linear(time, start, delta) 
  1395. 	return delta * time + start 
  1396. end 
  1397.