sr2lua/vint_lib.lua

  1. GAME_BUILD_DATE = "0000-00-00 20:00:00" 
  2.  
  3. MENU_NUM_SLIDER_ACCEL_REPEAT =	0.08 
  4. MENU_NUM_SLIDER_ACCEL_FACTOR =	15 
  5. MENU_NUM_SLIDER_ACCEL_LIMIT =		1000 
  6.  
  7. Pcr_open_plastic_surgeon = false 
  8.  
  9. COLOR_DEFAULT_TEXT = { r = 230, g = 230, b = 230 } 
  10.  
  11. -- some docs need to know what menu mode we are doing 
  12. -- set this from C before loading menu docs 
  13. Menu_mode_current = "" 
  14.  
  15. Main_menu_controller_selected = false 
  16. Main_menu_gameboot_complete = false 
  17. Menu_swap_in_progress = false 
  18.  
  19. Main_menu_can_has_input = false 
  20.  
  21.  --stored here so we know how to properly restart the clothing store 
  22. Clothing_store_name = "DEBUG_CLOTHING_STORE" 
  23. Clothing_store_display_name = 0 
  24. Clothing_store_original_name = "DEBUG_CLOTHING_STORE" 
  25. Clothing_store_original_display_name = 0 
  26. Menu_swap_interface_unload_handle = 0 
  27. Menu_swap_interface_reload_name = 0 
  28. Menu_swap_callback_function = 0 
  29. Menu_swap_hud_hidden = false; 
  30.  
  31. INVALID_NUM_FRAMES = -1 
  32. Num_frames_from_switch = INVALID_NUM_FRAMES 
  33.  
  34. Pause_menu_save_for_server_drop = false 
  35.  
  36. DIALOG_OPEN_SOUND 		= "SYS_HUD_HELPTEXT" 
  37. DIALOG_SERIOUS_SOUND	= "SYS_HUD_CONF_SERIOUS" 
  38. Menu_sound_item_nav		= "SYS_MENU_CLICK_UD"		-- Current menu item changes 
  39. Menu_sound_value_nav	= "SYS_MENU_CLICK_LR"		-- Value of current item changes 
  40. Menu_sound_select		= "SYS_MENU_SELECT"			-- Current item selected 
  41. Menu_sound_scroll		= "SYS_MENU_TRIGGER_LR"		-- Horizontal menu changes 
  42. Menu_sound_back			= "SYS_MENU_BACK"			-- Current menu changes to previous 
  43. Menu_sound_open			= "SYS_MENU_OPEN"			-- Menu system is opened 
  44. Menu_sound_close		= "SYS_MENU_CLOSE"			-- Menu system is closed 
  45. Menu_sound_warning		= "SYS_MENU_OPEN"			-- Warning dialog opens 
  46. Menu_sound_purchase		= "SYS_MENU_PURCHASE"		-- Any item is purchased 
  47. Menu_sound_confirm		= "SYS_HUD_CONF_SERIOUS"	-- Confirmation/warning dialog opens 
  48. Menu_sound_reward		= "SYS_HUD_CONF_REWARD"		-- Reward notification dialog 
  49.  
  50.  
  51. function vint_init_general_audio() 
  52. 	DIALOG_OPEN_SOUND 		= audio_get_audio_id(DIALOG_OPEN_SOUND) 
  53. 	DIALOG_SERIOUS_SOUND	= audio_get_audio_id(DIALOG_SERIOUS_SOUND) 
  54. 	Menu_sound_item_nav		= audio_get_audio_id(Menu_sound_item_nav) 
  55. 	Menu_sound_value_nav	= audio_get_audio_id(Menu_sound_value_nav) 
  56. 	Menu_sound_select		= audio_get_audio_id(Menu_sound_select)	 
  57. 	Menu_sound_scroll		= audio_get_audio_id(Menu_sound_scroll)	 
  58. 	Menu_sound_back			= audio_get_audio_id(Menu_sound_back) 
  59. 	Menu_sound_open			= audio_get_audio_id(Menu_sound_open) 
  60. 	Menu_sound_close		= audio_get_audio_id(Menu_sound_close) 
  61. 	Menu_sound_warning		= audio_get_audio_id(Menu_sound_warning) 
  62. 	Menu_sound_purchase		= audio_get_audio_id(Menu_sound_purchase) 
  63. 	Menu_sound_confirm		= audio_get_audio_id(Menu_sound_confirm) 
  64. 	Menu_sound_reward		= audio_get_audio_id(Menu_sound_reward) 
  65. end 
  66.  
  67. function vint_menu_swap_thread() 
  68. 	while true do 
  69. 		if Menu_swap_interface_reload_name ~= 0 then 
  70. 			if Menu_swap_hud_hidden == false then 
  71. 				hud_hide(true); 
  72. 				Menu_swap_hud_hidden = true 
  73. 			end 
  74. 			if Num_frames_from_switch ~= INVALID_NUM_FRAMES then 
  75. 				Num_frames_from_switch = Num_frames_from_switch + 1 
  76. 			end 
  77. 			if Num_frames_from_switch > 2 then 
  78. 				if Menu_swap_interface_reload_name ~= 0 then 
  79. 					vint_document_load(Menu_swap_interface_reload_name) 
  80. 					Menu_swap_interface_reload_name = 0 
  81. 					Num_frames_from_switch = INVALID_NUM_FRAMES 
  82. 					Menu_swap_in_progress = false 
  83. 					if Menu_swap_callback_function ~= 0 then 
  84. 						Menu_swap_callback_function() 
  85. 						Menu_swap_callback_function = 0 
  86. 					end 
  87. 				end 
  88. 			end 
  89. 		end 
  90. 		thread_yield() 
  91. 	end 
  92. end 
  93.  
  94. function vint_menu_swap_invalidate() 
  95. 	Menu_swap_interface_reload_name = 0 
  96. 	Num_frames_from_switch = INVALID_NUM_FRAMES 
  97. 	Clothing_store_name = "DEBUG_CLOTHING_STORE" 
  98. 	Clothing_store_display_name = 0 
  99. 	Clothing_store_original_name = "DEBUG_CLOTHING_STORE" 
  100. 	Clothing_store_original_display_name = 0 
  101. 	Menu_swap_interface_unload_handle = 0 
  102. 	Menu_swap_interface_reload_name = 0 
  103. 	Menu_swap_in_progress = false 
  104. 	hud_hide(false); 
  105. 	Menu_swap_hud_hidden = false 
  106. end 
  107.  
  108. function vint_menu_swap_unload() 
  109. 	vint_document_unload(Menu_swap_interface_unload_handle) 
  110. 	Num_frames_from_switch = 0 
  111. end 
  112.  
  113. function argument_unwrapper(arguments, start) 
  114. 	if start < arguments.n then 
  115. 		return arguments[start + 1], argument_unwrapper(arguments, start + 1) 
  116. 	end	 
  117. end 
  118.  
  119. function vint_dataresponder_request(data_responder_name, callback_function_name, max_records_to_return, ...) 
  120. 	vint_internal_dataresponder_request(data_responder_name, callback_function_name, max_records_to_return, argument_unwrapper(arg, 0)) 
  121. 	while(vint_dataresponder_finished(data_responder_name) ~= true) do 
  122. 		thread_yield() 
  123. 		vint_internal_dataresponder_request(data_responder_name, callback_function_name, max_records_to_return, argument_unwrapper(arg, 0)) 
  124. 	end 
  125. end 
  126.  
  127. --[[ 
  128. ######################################################################### 
  129. UTILITY FUNCTIONS  
  130. ######################################################################### 
  131. ]] 
  132.  
  133. function set_text_tag(text_element_h, text_crc, text_string) 
  134. 	--Set Label 
  135. 	if text_crc == 0 and text_string == nil then 
  136. 		--no string 
  137. 		vint_set_property(text_element_h,"text_tag", "") 
  138. 	elseif text_crc == 0 then 
  139. 		--use string 
  140. 		vint_set_property(text_element_h, "text_tag", text_string) 
  141. 	elseif text_crc == nil then 
  142. 		--Label crc invalid 
  143. 		vint_set_property(text_element_h,"text_tag", "") 
  144. 	else 
  145. 		--use crc 
  146. 		vint_set_property(text_element_h, "text_tag_crc",text_crc) 
  147. 	end 
  148. end 
  149.  
  150. --Easy Start Anim 
  151. function lua_play_anim(anim_h, start_time_offset, doc) 
  152. 	if start_time_offset == nil then 
  153. 		start_time_offset = 0 
  154. 	end 
  155. 	 
  156. 	local start_time = vint_get_time_index(doc) + start_time_offset 
  157. 	 
  158. 	vint_set_property(anim_h, "is_paused", false) 
  159. 	vint_set_property(anim_h, "start_time", start_time) 
  160. end 
  161.  
  162. --Easy Play tween method 
  163. function lua_play_tween(tween_handle, target_handle, start_time_offset) 
  164. 	vint_set_property(tween_handle, "target_handle",	target_handle) 
  165. 	vint_set_property(tween_handle, "start_time",		vint_get_time_index() + start_time_offset) 
  166. 	vint_set_property(tween_handle, "state",				"running") 
  167. end 
  168.  
  169. function var_to_string(var) 
  170. 	if type(var) == "table" then 
  171. 		return "{table}" 
  172. 	elseif var == nil then 
  173. 		return "nil" 
  174. 	elseif var == true then 
  175. 		return "true" 
  176. 	elseif var == false then 
  177. 		return "false" 
  178. 	else 
  179. 		return var 
  180. 	end 
  181. end 
  182.  
  183. --Sets actual size of the element. This is independant of the parent scaler values. 
  184. function element_set_actual_size(element_h, width, height) 
  185. 	local current_width, current_height = vint_get_property(element_h, "unscaled_size") 
  186. 	if current_width == nil or current_height == nil then 
  187. 		debug_print("vint", "Can't set actual size, element handle: " .. element_h .. " does not exist.\n") 
  188. 		return 
  189. 	end 
  190. 	local scale_x = width/current_width 
  191. 	local scale_y = height/current_height 
  192. 	vint_set_property(element_h, "scale", scale_x, scale_y) 
  193. end 
  194.  
  195. --Returns actual size of the element, indpendant from the parent scaler values. 
  196. function element_get_actual_size(element_h) 
  197. 	local width, height = vint_get_property(element_h, "unscaled_size") 
  198. 	local scale_x, scale_y = vint_get_property(element_h, "scale") 
  199. 	width = width * scale_x 
  200. 	height = height * scale_y 
  201. 	return width, height 
  202. end 
  203.  
  204. --Useful Mod function 
  205. function mod(number, divisor) 
  206. 	return number - (divisor * floor(number/divisor)) 
  207. end 
  208.  
  209. -- Support for hud monkey business 
  210. Hud_has_focus = true 
  211.  
  212. -- Math stuffs 
  213. PI = 3.1415 
  214. PI2 = 6.283 
  215.  
  216. --======================================= 
  217. --MP Utilities 
  218. --======================================= 
  219. MP_gameplay_mode_names = { 
  220. 	"Pre-game lobby", 
  221. 	"Gangsta Brawl", 
  222. 	"Team Gangsta Brawl", 
  223. 	"Braveheart", 
  224. 	"Multiplayer Creation", 
  225. 	"Multiplayer Customization", 
  226. 	"Multiplayer Game Results", 
  227. 	"Multiplayer Scoreboard", 
  228. 	"Multiplayer Tutorial", 
  229. } 
  230.  
  231. function mp_is_enabled() 
  232. 	--Get some multiplayer Data 
  233. 	local gp_mode = get_pending_game_play_mode() 
  234. 	for i, m in pairs( MP_gameplay_mode_names ) do 
  235. 		if gp_mode == m then 
  236. 			--found a match 
  237. 			return true 
  238. 		end 
  239. 	end 
  240. 	 
  241. 	gp_mode = get_game_play_mode() 
  242. 	for i, m in pairs( MP_gameplay_mode_names ) do 
  243. 		if gp_mode == m then 
  244. 			--found a match 
  245. 			return true 
  246. 		end 
  247. 	end 
  248. 	return false 
  249. end 
  250.  
  251.  
  252.  
  253. --####################################### 
  254. --Audio Delay 
  255. --####################################### 
  256. function audio_play_delayed(sound_id, offset) 
  257. 	thread_new("audio_play_delayed_thread", sound_id, offset) 
  258. end 
  259.  
  260. function audio_play_delayed_thread(sound_id, offset) 
  261. 	delay(offset) 
  262. 	audio_play(sound_id) 
  263. end 
  264.  
  265. function format_cash(cash) 
  266. 	return format_int_to_string(cash) 
  267. end 
  268.  
  269. function format_cash_add_padding(c) 
  270. 	if c < 10 then 
  271. 		return "00" .. c 
  272. 	elseif c < 100 then 
  273. 		return "0" .. c 
  274. 	else  
  275. 		return c 
  276. 	end 
  277. end 
  278.  
  279. function format_clock(time_in_seconds) 
  280.  
  281. 	local neg_symbol = "" 
  282. 	 
  283. 	if time_in_seconds < 0 then 
  284. 		time_in_seconds = abs(time_in_seconds) 
  285. 		neg_symbol  = "-" 
  286. 	end 
  287.  
  288. 	---Format the time 
  289. 	local minutes = floor(time_in_seconds / 60) 
  290. 	local seconds =  mod(time_in_seconds, 60) 
  291. 	--Pad the seconds for the timer 
  292. 	if seconds < 10 then 
  293. 		seconds = "0" .. seconds 
  294. 	end 
  295. 	return neg_symbol .. minutes .. ":" .. seconds 
  296. end 
  297.  
  298. -- this is now unofficially get_confirm_button! 
  299. function get_a_button() 
  300. 	local button 
  301. 	if get_platform() == "XBOX360" then 
  302. 		button = "ui_ctrl_360_btn_a" 
  303. 	elseif get_platform() == "PS3" then 
  304. 		local button_swap = get_ps3_button_swap() 
  305. 		if button_swap == true then 
  306. 			button = "ui_ctrl_ps3_btn_circle" 
  307. 		else  
  308. 		-- old standard 
  309. 			button = "ui_ctrl_ps3_btn_cross" 
  310. 		end 
  311. 	elseif get_platform() == "PC" then 
  312. 		button = "ui_ctrl_PC_btn_enter" 
  313. 	end 
  314. 	 
  315. 	return button 
  316. end 
  317.  
  318. function get_x_button() 
  319. 	local button 
  320. 	if get_platform() == "XBOX360" then 
  321. 		button = "ui_ctrl_360_btn_x" 
  322. 	elseif get_platform() == "PS3" then 
  323. 		button = "ui_ctrl_ps3_btn_square" 
  324. 	elseif get_platform() == "PC" then 
  325. 		button = "ui_ctrl_PC_btn_x" 
  326. 	end 
  327. 	return button 
  328. end 
  329.  
  330. -- this is now unofficially get_back_button! 
  331. function get_b_button() 
  332. 	local button 
  333. 	if get_platform() == "XBOX360" then 
  334. 		button = "ui_ctrl_360_btn_b" 
  335. 	elseif get_platform() == "PS3" then 
  336. 			local button_swap = get_ps3_button_swap() 
  337. 		if button_swap == true then 
  338. 			button = "ui_ctrl_ps3_btn_cross" 
  339. 		else  
  340. 			button = "ui_ctrl_ps3_btn_circle" 
  341. 		end 
  342. 	elseif get_platform() == "PC" then 
  343. 		button = "ui_ctrl_PC_key_esc" 
  344. 	end 
  345. 	return button 
  346. end 
  347.  
  348. function get_y_button() 
  349. 	local button 
  350. 	if get_platform() == "XBOX360" then 
  351. 		button = "ui_ctrl_360_btn_y" 
  352. 	elseif get_platform() == "PS3" then 
  353. 		button = "ui_ctrl_ps3_btn_triangle" 
  354. 	elseif get_platform() == "PC" then 
  355. 		button = "ui_ctrl_PC_key_e" 
  356. 	end 
  357. 	return button 
  358. end 
  359.  
  360. function get_right_stick() 
  361. 	local button 
  362. 	if get_platform() == "XBOX360" then 
  363. 		button = "ui_ctrl_360_btn_rs" 
  364. 	elseif get_platform() == "PS3" then 
  365. 		button = "ui_ctrl_ps3_btn_r3" 
  366. 	elseif get_platform() == "PC" then 
  367. 		button = "ui_ctrl_PC_mouse" 
  368. 	end 
  369. 	return button 
  370. end 
  371.  
  372. function get_lt_button() 
  373. 	local button 
  374. 	if get_platform() == "XBOX360" then 
  375. 		button = "ui_ctrl_360_btn_lt" 
  376. 	elseif get_platform() == "PS3" then 
  377. 		button = "ui_ctrl_ps3_btn_l1" 
  378. 	elseif get_platform() == "PC" then 
  379. 		button = "ui_ctrl_PC_key_ctrl" 
  380. 	end 
  381. 	return button 
  382. end 
  383.  
  384. function get_rt_button() 
  385. 	local button 
  386. 	if get_platform() == "XBOX360" then 
  387. 		button = "ui_ctrl_360_btn_rt" 
  388. 	elseif get_platform() == "PS3" then 
  389. 		button = "ui_ctrl_ps3_btn_r1" 
  390. 	elseif get_platform() == "PC" then 
  391. 		button = "ui_ctrl_PC_key_shift" 
  392. 	end 
  393. 	return button 
  394. end 
  395.  
  396. function get_lb_button() 
  397. 	local button 
  398. 	if get_platform() == "XBOX360" then 
  399. 		button = "ui_ctrl_360_btn_lb" 
  400. 	elseif get_platform() == "PS3" then 
  401. 		button = "ui_ctrl_ps3_btn_l2" 
  402. 	elseif get_platform() == "PC" then 
  403. 		button = "ui_ctrl_PC_key_ctrl" 
  404. 	end 
  405. 	return button 
  406. end 
  407.  
  408. function get_rb_button() 
  409. 	local button 
  410. 	if get_platform() == "XBOX360" then 
  411. 		button = "ui_ctrl_360_btn_rb" 
  412. 	elseif get_platform() == "PS3" then 
  413. 		button = "ui_ctrl_ps3_btn_r2" 
  414. 	elseif get_platform() == "PC" then 
  415. 		button = "ui_ctrl_PC_key_shift" 
  416. 	end 
  417. 	return button 
  418. end 
  419.  
  420. function get_left_right() 
  421. 	local button 
  422. 	if get_platform() == "XBOX360" then 
  423. 		button = "ui_ctrl_360_dpad_lr" 
  424. 	elseif get_platform() == "PS3" then 
  425. 		button = "ui_ctrl_ps3_dapd_lr" 
  426. 	elseif get_platform() == "PC" then 
  427. 		button = "ui_ctrl_PC_dpad_lr" 
  428. 	end 
  429. 	return button 
  430. end 
  431.  
  432. function get_up_down() 
  433. 	local button 
  434. 	if get_platform() == "XBOX360" then 
  435. 		button = "ui_ctrl_360_dpad_ud" 
  436. 	elseif get_platform() == "PS3" then 
  437. 		button = "ui_ctrl_ps3_dpad_ud" 
  438. 	elseif get_platform() == "PC" then 
  439. 		button = "ui_ctrl_360_dpad_ud" 
  440. 	end 
  441. 	return button 
  442. end 
  443.  
  444. function get_left_trigger() 
  445. 	local button 
  446. 	if get_platform() == "XBOX360" then 
  447. 		button = "ui_ctrl_360_btn_lt" 
  448. 	elseif get_platform() == "PS3" then 
  449. 		button = "ui_ctrl_ps3_btn_l2" 
  450. 	elseif get_platform() == "PC" then 
  451. 		button = "ui_ctrl_PC_key_ctrl" 
  452. 	end 
  453. 	return button 
  454. end 
  455.  
  456. function get_right_trigger() 
  457. 	local button 
  458. 	if get_platform() == "XBOX360" then 
  459. 		button = "ui_ctrl_360_btn_rt" 
  460. 	elseif get_platform() == "PS3" then 
  461. 		button = "ui_ctrl_ps3_btn_r2" 
  462. 	elseif get_platform() == "PC" then 
  463. 		button = "ui_ctrl_PC_key_shift" 
  464. 	end 
  465. 	return button 
  466. end 
  467.  
  468. function get_control_stick_base() 
  469. 	local image 
  470. 	if get_platform() == "XBOX360" then 
  471. 		image = "ui_hud_base_radial_base_xbox" 
  472. 	elseif get_platform() == "PS3" then 
  473. 		image = "ui_hud_base_radial_base_ps3" 
  474. 	elseif get_platform() == "PC" then 
  475. 		image = "ui_hud_base_radial_base_xbox" 
  476. 	end 
  477. 	return image 
  478. end 
  479.  
  480. function get_control_stick_thumb() 
  481. 	local image 
  482. 	if get_platform() == "XBOX360" then 
  483. 		image = "ui_hud_base_radial_thumb_xbox" 
  484. 	elseif get_platform() == "PS3" then 
  485. 		image = "ui_hud_base_radial_thumb_ps3" 
  486. 	elseif get_platform() == "PC" then 
  487. 		image = "ui_hud_base_radial_thumb_xbox" 
  488. 	end 
  489. 	return image 
  490. end 
  491.  
  492. function get_control_stick_text() 
  493. 	local text 
  494. 	 
  495. 	if pause_menu_is_using_southpaw_control_scheme() == true and is_local_player_in_vehicle() == false then 
  496. 		if get_platform() == "XBOX360" then 
  497. 			text = "RS" 
  498. 		elseif get_platform() == "PS3" then 
  499. 			text = "R3" 
  500. 		elseif get_platform() == "PC" then 
  501. 			text = "" 
  502. 		end	 
  503. 	else  
  504. 		if get_platform() == "XBOX360" then 
  505. 			text = "LS" 
  506. 		elseif get_platform() == "PS3" then 
  507. 			text = "L3" 
  508. 		elseif get_platform() == "PC" then 
  509. 			text = "" 
  510. 		end 
  511. 	end  
  512. 	return text 
  513. end 
  514.  
  515. function get_dpad_image() 
  516. 	local image 
  517. 	if get_platform() == "XBOX360" then 
  518. 		image = "ui_hud_base_radial_dpad_xbox" 
  519. 	elseif get_platform() == "PS3" then 
  520. 		image = "ui_hud_base_radial_dpad_ps3" 
  521. 	elseif get_platform() == "PC" then 
  522. 		image = "ui_hud_base_radial_dpad_xbox" 
  523. 	end 
  524. 	return image 
  525. end 
  526.  
  527. function get_dpad_lr_image() 
  528. 	local image 
  529. 	if get_platform() == "XBOX360" then 
  530. 		image = "ui_ctrl_360_dpad_lr" 
  531. 	elseif get_platform() == "PS3" then 
  532. 		image = "ui_ctrl_ps3_dpad_lr" 
  533. 	elseif get_platform() == "PC" then 
  534. 		image = "ui_ctrl_360_dpad_lr" 
  535. 	end 
  536. 	return image 
  537. end 
  538.  
  539. function get_dpad_ud_image() 
  540. 	local image 
  541. 	if get_platform() == "XBOX360" then 
  542. 		image = "ui_ctrl_360_dpad_ud" 
  543. 	elseif get_platform() == "PS3" then 
  544. 		image = "ui_ctrl_ps3_dpad_ud" 
  545. 	elseif get_platform() == "PC" then 
  546. 		image = "ui_ctrl_360_dpad_ud" 
  547. 	end 
  548. 	return image 
  549. end 
  550.  
  551. function table_clone(src) 
  552. 	local dst = { } 
  553. 	 
  554. 	for k, v in src do 
  555. --		if type(v) == "table" then 
  556. --			dst[k] = table_clone(v) 
  557. --		else 
  558. 			dst[k] = v 
  559. --		end 
  560. 	end 
  561. 	 
  562. 	return dst 
  563. end 
  564.  
  565. -- convert anything to a bool 
  566. function var_to_bool(var) 
  567. 	if var == true then 
  568. 		return true 
  569. 	elseif var == false then 
  570. 		return false 
  571. 	elseif var == nil then 
  572. 		return false 
  573. 	elseif type(var) == "function" then 
  574. 		return var() 
  575. 	else 
  576. 		return false 
  577. 	end 
  578. end 
  579.