sr2lua/gang_cust.lua

  1. ------------------------ 
  2. -- Gang Customization -- 
  3. ------------------------ 
  4.  
  5. -- "global" variables 
  6.  
  7. --	Menu stuff 
  8. Gang_menu_add_index = 0 
  9. -- Tag stuff 
  10. Gang_tag_icon_pegs = { } 
  11. Gang_tag_icon_count = 0 
  12. Gang_tag_preview_peg = "" 
  13. Gang_tag_preview_h = 0 
  14. --	Sign Stuff 
  15. Gang_signs_number_of_signs = 0 
  16. --	Vehicle stuff 
  17. Vehicle_slot = 0 
  18.  
  19. Gang_cust_is_fully_loaded = true 
  20.  
  21. ---------------------- 
  22. --	SYSTEM FUNCTIONS -- 
  23. ---------------------- 
  24. --[ INITIALIZE AND SHUTDOWN ]-- 
  25. ------------------------------- 
  26. --	Initialize the menu 
  27. function gang_cust_init() 
  28. 	--Event Tracking 
  29. 	event_tracking_interface_enter("Gang Customization")	 
  30.  
  31. 	menu_init() 
  32. 	menu_horz_init(Gang_cust_horz_menu) 
  33. 	peg_load("ui_spinner_lg") 
  34.  
  35. 	Gang_tag_preview_h = vint_object_find("gang_tag_large_preview")	 
  36. 	 
  37. 	--	Load the tag icons 
  38. 	gang_cust_gang_tag_init_swatches() 
  39. 	 
  40. 	local cash_style_grp_h = vint_object_find("cash_style_cluster", nil, MENU_BASE_DOC_HANDLE) 
  41. 	vint_set_property(cash_style_grp_h, "visible", false) 
  42. 	 
  43. 	vint_datagroup_add_subscription("gang_cust_current_object_is_loaded", "insert", "gang_cust_current_object_update") 
  44. 	vint_datagroup_add_subscription("gang_cust_current_object_is_loaded", "update", "gang_cust_current_object_update") 
  45. end 
  46.  
  47. -- Shutdown and cleanup the menu 
  48. function gang_cust_cleanup() 
  49. 	peg_unload("ui_spinner_lg") 
  50. 	 
  51. 	if Gang_tag_preview_peg ~= nil then 
  52. 		peg_unload(Gang_tag_preview_peg) 
  53. 	end 
  54. end 
  55.  
  56. --[ EXIT ]-- 
  57. ------------ 
  58. function gang_cust_exit(menu_data) 
  59. 	local body = "GANG_CUST_EXIT_PROMPT" 
  60. 	local heading = "MENU_TITLE_WARNING" 
  61. 	local options = { [0] = "OPTION_YES", [1] = "OPTION_NO"	} 
  62. 	 
  63. 	dialog_box_open(heading, body, options, "gang_cust_exit_confirm", 0) 
  64. end 
  65.  
  66. function gang_cust_exit_confirm(result, action) 
  67. 	if action ~= DIALOG_ACTION_CLOSE then 
  68. 		return 
  69. 	end 
  70. 	 
  71. 	if result == 0 then 
  72. 		menu_close(gang_cust_exit_final) 
  73. 		local loading_image = vint_object_find("gang_cust_loading_image") 
  74. 		vint_set_property(loading_image, "visible", false) 
  75. 	end 
  76. end 
  77. function gang_cust_exit_final() 
  78. 	gang_cust_gang_tag_cleanup_swatches() 
  79. 	vint_document_unload(vint_document_find("gang_cust"))	 
  80. end 
  81.  
  82. ------------------------ 
  83. --	MENU FUNCTIONALITY -- 
  84. ------------------------ 
  85. ---[ GANG MENU ]--- 
  86. ------------------- 
  87. function gang_cust_gang_nav(menu_data) 
  88. 	local selection = Gang_cust_gang_menu.highlighted_item 
  89. 	if selection == 0 or selection == 2 then 
  90. 		if Gang_tag_preview_peg ~= "" then 
  91. 			vint_set_property(Gang_tag_preview_h, "visible", false)				 
  92. 			peg_unload(Gang_tag_preview_peg) 
  93. 			Gang_tag_preview_peg = "" 
  94. 		end 
  95. 		gang_customization_show_gang() 
  96. 	elseif selection == 1 then 
  97. 		vint_dataresponder_request("gang_cust_tag_data_responder", "gang_cust_gang_tag_get_current", 0, 1) -- 1 - get default 
  98. 		vint_set_property(Gang_tag_preview_h, "visible", true) 
  99. 		gang_customization_show_tag() 
  100. 	end 
  101. end 
  102.  
  103. ------------- 
  104. --	Gang Style 
  105. function gang_cust_gang_style_build_menu(menu_data) 
  106. 	Gang_menu_add_index = 0 
  107.  	Gang_cust_gang_style_menu.highlighted_item = Gang_menu_add_index 
  108. 	vint_dataresponder_request("gang_cust_gang_style_data_responder", "gang_cust_gang_style_add_items", 0) 
  109. 	Gang_cust_gang_style_menu.num_items = Gang_menu_add_index 
  110. end 
  111.  
  112. function gang_cust_gang_style_add_items(name, is_current_gang) 
  113. 	Gang_cust_gang_style_menu[Gang_menu_add_index] =  
  114. 		{	label = name, type = MENU_ITEM_TYPE_SELECTABLE, on_select = gang_cust_gang_style_confirm_selection } 
  115. 	if is_current_gang == true then 
  116. 		Gang_cust_gang_style_menu.highlighted_item = Gang_menu_add_index 
  117. 	end 
  118. 	Gang_menu_add_index = Gang_menu_add_index + 1 
  119. end 
  120.  
  121. function gang_cust_gang_style_select_new_gang() 
  122. 	gang_customization_select_gang_style(Gang_cust_gang_style_menu.highlighted_item) 
  123. end 
  124.  
  125. function gang_cust_gang_style_confirm_selection() 
  126. 	menu_show(Gang_cust_gang_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  127. end 
  128.  
  129. function gang_cust_gang_style_revert_selection() 
  130. 	gang_customization_revert_to_old_gang() 
  131. 	menu_show(Menu_active.parent_menu, MENU_TRANSITION_SWEEP_RIGHT)	 
  132. end 
  133.  
  134. ------------ 
  135. --	Gang Tags 
  136. function gang_cust_gang_tag_build_menu(menu_data) 
  137. 	local menu_item = Gang_cust_tag_menu[0] 
  138. 	menu_item.swatches = { num_swatches = 0 } 
  139. 	menu_item.cur_idx = 0 
  140. 	Gang_menu_add_index = 0 
  141. 	 
  142. 	-- Add the swatches 
  143. 	vint_dataresponder_request("gang_cust_tag_data_responder", "gang_cust_gang_tag_add_items"	, 0) 
  144. 	 
  145. 	menu_item.swatches.num_swatches = Gang_menu_add_index 
  146. 	local master_swatch = vint_object_find("swatch_skin", nil, MENU_BASE_DOC_HANDLE) 
  147. 	menu_grid_show(menu_data, menu_item, master_swatch)	 
  148. end 
  149.  
  150. function gang_cust_gang_tag_init_swatches() 
  151. 	peg_load("ui_gang_tags") 
  152. end 
  153.  
  154. function gang_cust_gang_tag_cleanup_swatches() 
  155. 	peg_unload("ui_gang_tags") 
  156. end 
  157.  
  158. function gang_cust_gang_tag_get_current(name_str, icon_name, preview_image_peg, preview_image, current) 
  159. 		if Gang_tag_preview_peg == preview_image_peg then 
  160. 			vint_set_property(Gang_tag_preview_h, "image", preview_image .. ".tga") 
  161. 			return 
  162. 		end 
  163. 		if Gang_tag_preview_peg ~= "" then 
  164. 			peg_unload(Gang_tag_preview_peg) 
  165. 		end 
  166. 		Gang_tag_preview_peg = preview_image_peg 
  167. 		peg_load(Gang_tag_preview_peg) 
  168. 		vint_set_property(Gang_tag_preview_h, "image", preview_image .. ".tga") 
  169. 		vint_set_property(Gang_tag_preview_h, "scale", 1.25, 1.25) 
  170. end 
  171.  
  172. function gang_cust_gang_tag_add_items(name_str, icon_name, preview_image_peg, preview_image, current) 
  173. 	local swatches = Gang_cust_tag_menu[0].swatches 
  174. 	swatches[Gang_menu_add_index] = { 
  175. 		label = name_str, swatch_str = icon_name, preview_peg_str = preview_image_peg, preview_str = preview_image 
  176. 	} 
  177. 	if current == true then 
  178. 		Gang_cust_tag_menu[0].cur_idx = Gang_menu_add_index 
  179. 	end 
  180. 	 
  181. 	Gang_menu_add_index = Gang_menu_add_index + 1 
  182. end 
  183.  
  184. function gang_cust_gang_tag_select_new_tag(menu_label, menu_data) 
  185. 	--	Update the tag displayed 
  186. 	local swatches = menu_data.swatches 
  187. 	local idx = menu_data.cur_row * menu_data.num_cols + menu_data.cur_col 
  188.  
  189. 	if idx < swatches.num_swatches then 
  190. 		if Gang_tag_preview_peg ~= "" then 
  191. 			peg_unload(Gang_tag_preview_peg) 
  192. 			Gang_tag_preview_peg = "" 
  193. 		end 
  194.  
  195. 		Gang_tag_preview_peg = swatches[idx].preview_peg_str 
  196. 		peg_load(Gang_tag_preview_peg)	 
  197. 		gang_customization_change_tag() 
  198. 		--	Update the bitmap 
  199. 		vint_set_property(Gang_tag_preview_h, "image", swatches[idx].preview_str .. ".tga") 
  200. 		vint_set_property(Gang_tag_preview_h, "visible", true) 
  201. 	end 
  202. 	vint_set_property(Gang_tag_preview_h, "scale", 1.25, 1.25) 
  203. end 
  204.  
  205. function gang_cust_gang_tag_confirm_selection(menu_label, menu_data) 
  206. 	local swatches = menu_data.swatches 
  207. 	local idx = menu_data.cur_row * menu_data.num_cols + menu_data.cur_col 
  208.  
  209. 	if idx < swatches.num_swatches then 
  210. 		gang_customization_select_gang_tag(idx) 
  211. 	end 
  212. 	 
  213. 	menu_show(Gang_cust_gang_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  214. 	vint_set_property(Gang_tag_preview_h, "scale", 1.25, 1.25) 
  215. end 
  216.  
  217. function gang_cust_gang_tag_revert_selection() 
  218. 	gang_customization_revert_gang_tag() 
  219. 	menu_show(Menu_active.parent_menu, MENU_TRANSITION_SWEEP_RIGHT)	 
  220. end 
  221.  
  222. function gang_cust_gang_tag_release() 
  223. 	menu_grid_release(Gang_cust_tag_menu[0]) 
  224.  
  225. end 
  226.  
  227. ------------- 
  228. --	Gang Signs 
  229. function gang_cust_gang_sign_build_menu() 
  230.  	Gang_cust_gang_style_menu.highlighted_item = 0 
  231. 	Gang_signs_number_of_signs = 0 
  232. 	Gang_cust_gang_sign_menu.num_items = 0 
  233. 	vint_dataresponder_request("gang_cust_gang_sign_data_responder", "gang_cust_gang_sign_add_items", 0) 
  234.  
  235. end 
  236.  
  237. function gang_cust_gang_sign_add_items(sign_type, name, is_current) 
  238. 	if sign_type == 0 then 
  239. 		Gang_cust_gang_sign_menu[Gang_signs_number_of_signs] =  
  240. 			{	label = name, type = MENU_ITEM_TYPE_SELECTABLE, on_select = gang_cust_gang_sign_confirm_selection } 
  241. 		if is_current == true then 
  242. 			Gang_cust_gang_sign_menu.highlighted_item = Gang_signs_number_of_signs 
  243. 		end 
  244. 		Gang_signs_number_of_signs = Gang_signs_number_of_signs + 1 
  245. 		Gang_cust_gang_sign_menu.num_items = Gang_signs_number_of_signs 
  246. 	end 
  247. end 
  248.  
  249. function gang_cust_gang_sign_update_pose(menu_label, menu_data) 
  250. 	gang_customization_select_gang_sign(0, Gang_cust_gang_sign_menu.highlighted_item) 
  251. end 
  252.  
  253. function gang_cust_gang_sign_nav() 
  254. 	if Gang_cust_gang_sign_menu.highlighted_item == 0 then 
  255. 		gang_cust_gang_sign_update_pose(nil, Gang_cust_gang_sign_menu[0]) 
  256. 	end 
  257. end 
  258.  
  259. function gang_cust_gang_sign_confirm_selection(menu_label, menu_data) 
  260. 	local idx = Gang_cust_gang_sign_menu.highlighted_item 
  261.  
  262. 	gang_customization_confirm_gang_sign(idx) 
  263. 	 menu_show(Menu_active.parent_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  264. 	--menu_show(Gang_cust_gang_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  265. 	--vint_set_property(Gang_tag_preview_h, "scale", 1.25, 1.25) 
  266. 	 
  267. end 
  268.  
  269. function gang_cust_gang_revert_selection() 
  270. 	gang_customization_revert_gang_sign() 
  271. 	menu_show(Menu_active.parent_menu, MENU_TRANSITION_SWEEP_RIGHT)	 
  272. end 
  273.  
  274. --[ VEHICLE MENU ]-- 
  275. -------------------- 
  276. function gang_cust_vehicle_select_slot() 
  277. 	Vehicle_slot = Gang_cust_vehicle_menu.highlighted_item	 
  278. 	gang_customization_show_vehicle(Vehicle_slot) 
  279. end 
  280.  
  281. function gang_cust_vehicle_select_new_vehicle() 
  282. 	gang_customization_select_vehicle(Gang_cust_vehicle_submenu.highlighted_item, Vehicle_slot) 
  283. end 
  284.  
  285. function gang_cust_vehicle_revert_selection() 
  286. 	gang_customization_revert_vehicle(Vehicle_slot) 
  287. 	menu_show(Menu_active.parent_menu, MENU_TRANSITION_SWEEP_RIGHT)	 
  288. end 
  289.  
  290. function gang_cust_vehicle_confirm_selection() 
  291. 	gang_customization_confirm_vehicle(Vehicle_slot) 
  292. 	menu_show(Gang_cust_vehicle_menu, MENU_TRANSITION_SWEEP_RIGHT) 
  293. end 
  294.  
  295. function gang_cust_vehicle_build_submenu() 
  296. 	Gang_menu_add_index = 0 
  297. 	Gang_cust_vehicle_submenu.highlighted_item = Gang_menu_add_index 
  298. 	vint_dataresponder_request("gang_cust_vehicle_data_responder", "gang_cust_vehicle_add_items", 0, Vehicle_slot) 
  299. 	Gang_cust_vehicle_submenu.num_items = Gang_menu_add_index 
  300. end 
  301.  
  302. function gang_cust_vehicle_add_items(name, is_vehicle_in_slot) 
  303. 	Gang_cust_vehicle_submenu[Gang_menu_add_index] = { label = name, type = MENU_ITEM_TYPE_SELECTABLE, on_select=gang_cust_vehicle_confirm_selection } 
  304. 	if is_vehicle_in_slot == true then 	--	Select the current level 
  305. 		Gang_cust_vehicle_submenu.highlighted_item = Gang_menu_add_index 
  306. 	end 
  307. 	Gang_menu_add_index = Gang_menu_add_index + 1 
  308. end 
  309.  
  310. function gang_cust_show_vehicle() 
  311. 	if Gang_tag_preview_peg ~= "" then 
  312. 		peg_unload(Gang_tag_preview_peg) 
  313. 		Gang_tag_preview_peg = "" 
  314. 		vint_set_property(Gang_tag_preview_h, "visible", false) 
  315. 	end 
  316. 	 
  317. 	gang_customization_show_vehicle(Vehicle_slot) 
  318. end 
  319.  
  320.  
  321. function gang_cust_current_object_update(di_h)  
  322. 	local is_loaded  = vint_dataitem_get(di_h)  
  323. 	if Gang_cust_is_fully_loaded ~= is_loaded then 
  324. 		local loading_image = vint_object_find("gang_cust_loading_image")	 
  325. 		debug_print("freese","loading_image = " .. loading_image .. ".\n") 
  326. 		if is_loaded == true then 
  327. 			vint_set_property(loading_image, "visible", false) 
  328. 		else  
  329. 			vint_set_property(loading_image, "visible", true) 
  330. 		end 
  331. 		Gang_cust_is_fully_loaded = is_loaded  
  332. 	end 
  333. end 
  334.  
  335. --------------- 
  336. -- MENU DATA -- 
  337. --------------- 
  338.  
  339. ----[ Button Tips for the Menus ]---- 
  340. Gang_Customization_main_menu_btn_tips = { 
  341. 	a_button 	= 	{ label = "CONTROL_SELECT", 	enabled = btn_tips_default_a, }, 
  342. 	b_button 	= 	{ label = "MENU_RESUME", 			enabled = btn_tips_default_a, }, 
  343. } 
  344.  
  345. ----[ Button Tips for the Menus ]---- 
  346. Gang_Customization_sub_menu_btn_tips = { 
  347. 	a_button 	= 	{ label = "CONTROL_SELECT", 	enabled = btn_tips_default_a, }, 
  348. 	b_button 	= 	{ label = "MENU_BACK", 			enabled = btn_tips_default_a, }, 
  349. } 
  350.  
  351.  
  352. ---[ GANG MENU ]--- 
  353.  
  354. -- Submenus 
  355. Gang_cust_gang_style_menu = { 
  356. 	header_label_str = "GANG_CUST_GANG_STYLE_TITLE", 
  357. 	on_show 			= gang_cust_gang_style_build_menu, 
  358. 	on_nav  			= gang_cust_gang_style_select_new_gang, 
  359. 	on_back				= gang_cust_gang_style_revert_selection, 
  360.  
  361. 	btn_tips 			= Gang_Customization_sub_menu_btn_tips, 
  362. } 
  363.  
  364. Gang_cust_tag_menu = { 
  365. 	header_label_str = "GANG_CUST_GANG_TAG_TITLE", 
  366. 	on_show 		= gang_cust_gang_tag_build_menu, 
  367. 	on_release	= gang_cust_gang_tag_release, 
  368. 	on_back 		= gang_cust_gang_tag_revert_selection, 
  369. 	num_items	= 1, 
  370. 	 
  371. 	[0] = { label = "", type = MENU_ITEM_TYPE_GRID, on_select = gang_cust_gang_tag_confirm_selection, on_nav = gang_cust_gang_tag_select_new_tag, 
  372. 		row_height = 72, num_cols = 4, col_width = 83, highlight_scale = 1, unhighlight_scale = 0.8}, 
  373. 	 
  374. 	btn_tips 			= Gang_Customization_sub_menu_btn_tips, 
  375. } 
  376.  
  377. Gang_cust_gang_sign_menu = { 
  378. 	header_label_str = "GANG_CUST_GANG_SIGN_TITLE", 
  379. 	on_show 	= gang_cust_gang_sign_build_menu, 
  380. 	on_nav 		= gang_cust_gang_sign_update_pose, 
  381. 	on_back 	= gang_cust_gang_revert_selection,  
  382. --	on_nav	 = gang_cust_gang_sign_nav, 
  383. 	 
  384. 	btn_tips 	= Gang_Customization_sub_menu_btn_tips, 
  385. } 
  386.  
  387. -- Top Level Menu 
  388. Gang_cust_gang_menu = { 
  389. 	header_label_str = "GANG_CUST_TITLE", 
  390. 	highlighted_item = 0, 
  391. 	on_show = gang_cust_gang_nav, 
  392. 	on_nav  = gang_cust_gang_nav, 
  393. 	on_back = gang_cust_exit, 
  394. 	num_items = 3, 
  395. 	 
  396. 	[0] =	{ label = "GANG_CUST_GANG_STYLE_OPT", 	type = MENU_ITEM_TYPE_SUB_MENU, sub_menu = Gang_cust_gang_style_menu, }, 
  397. 	[1] = { label = "GANG_CUST_GANG_TAG_OPT",	 	type = MENU_ITEM_TYPE_SUB_MENU, sub_menu = Gang_cust_tag_menu,			 }, 
  398. 	[2] = { label = "GANG_CUST_GANG_SIGN_OPT",	type = MENU_ITEM_TYPE_SUB_MENU, sub_menu = Gang_cust_gang_sign_menu,  }, 
  399. 	 
  400. 	btn_tips 			= Gang_Customization_main_menu_btn_tips, 
  401. } 
  402.  
  403. --[ VEHICLE MENU ]-- 
  404. -------------------- 
  405. -- Sub Menu 
  406. Gang_cust_vehicle_submenu = { 
  407. 	header_label_str = "VEHICLE_TYPE_TITLE", 
  408. 	on_show 		= gang_cust_vehicle_build_submenu, 
  409. 	on_nav 			= gang_cust_vehicle_select_new_vehicle, 
  410. 	on_back 		= gang_cust_vehicle_revert_selection, 
  411.  
  412. 	btn_tips 			= Gang_Customization_sub_menu_btn_tips, 
  413.  
  414. } 
  415.  
  416. --Top Level Menu 
  417. Gang_cust_vehicle_menu = { 
  418. 	header_label_str = "VEHICLE_CUSTOMIZATION_TITLE", 
  419. 	on_show 	= gang_cust_show_vehicle, 
  420. 	on_back 	= gang_cust_exit, 
  421. 	on_nav 	= gang_cust_vehicle_select_slot, 
  422. 	num_items = 3, 
  423. 	 
  424. 	[0] = { label = "GANG_CUST_SLOT_1", type = MENU_ITEM_TYPE_SUB_MENU, sub_menu = Gang_cust_vehicle_submenu }, 
  425. 	[1] = { label = "GANG_CUST_SLOT_2", type = MENU_ITEM_TYPE_SUB_MENU, sub_menu = Gang_cust_vehicle_submenu },  
  426. 	[2] = { label = "GANG_CUST_SLOT_3", type = MENU_ITEM_TYPE_SUB_MENU, sub_menu = Gang_cust_vehicle_submenu },  
  427. 	 
  428. 	btn_tips 			= Gang_Customization_main_menu_btn_tips, 
  429. } 
  430.  
  431. --	Horizontal Menu 
  432. Gang_cust_horz_menu = { 
  433. 	num_items = 2, 
  434. 	 
  435. 	[0] = { label = "GANG_CUST_GANG_TITLE", 	sub_menu = Gang_cust_gang_menu    }, 
  436. 	[1] = { label = "GANG_CUST_VEHICLE_TITLE", sub_menu = Gang_cust_vehicle_menu }, 
  437. 	 
  438. }