./store_weapon.lua

  1. STORE_WEAPON_INVALID_INDEX 		= -1 
  2. STORE_WEAPON_INVALID_INDEX 		= -1 
  3. SCALE_FONT_STORE_WEAPON_LIST 		= 0.8 
  4.  
  5. local STORE_WEAPON_RADIAL_CACHE_X 		= 345 
  6. local STORE_WEAPON_RADIAL_CACHE_SD_X 	= 285 
  7. local STORE_WEAPON_RADIAL_STORE_X 		= 345 
  8. local STORE_WEAPON_RADIAL_STORE_SD_X 	= 285 
  9.  
  10. local STORE_WEAPON_STATS_GRP_X = 645 
  11. local STORE_WEAPON_STATS_GRP_SD_X = 526 
  12. local STORE_WEAPON_STATS_GRP_Y = 230 
  13. local STORE_WEAPON_STATS_GRP_MAX = 393 
  14.  
  15. --Keep track of current costume name and description 
  16. local Current_costume_name_crc = nil 
  17. local Current_costume_desc_crc = nil 
  18. local Current_skin_name_crc = nil 
  19. local Store_weapon_default_crc = -1 
  20.  
  21. --Were we forced out by taking damage rather than exiting by choice 
  22. --True until the player exits the store 
  23. local Store_weapon_forced_out = true 
  24. local Store_weapon_skin_was_previewed = false 
  25.  
  26. --Used in store_weapon_costume_add_items() to pick out the info we need 
  27. --this function isn't called in a loop, so we need globals 
  28. local Store_weapon_parsed_costume_name_crc 
  29. local Store_weapon_parsed_costume_desc_crc 
  30.  
  31. --Need lighter color for weapon info in crib mode 
  32. local STORE_CRIB_TITLE_COLOR = {R = 167/255, G = 191/255, B = 216/255} 
  33. local STORE_CRIB_DESC_COLOR = {R = 32/255, G = 32/255, B = 32/255} 
  34.  
  35. local STORE_WEAPON_CUSTOMIZE_OPTION = 1 
  36.  
  37. Store_weapon_doc_handle = -1 
  38.  
  39. --Thread id for dumping pause map and loading store weapon pegs 
  40. local Store_weapon_pegs_thread_id = -1 
  41.  
  42. local Store_weapon_radial 
  43.  
  44. local Hint_bar_mouse_input_tracker 
  45. local Radial_mouse_input_tracker 
  46. local Game_platform 
  47.  
  48. local Store_weapon_in_mission = false 
  49. local Weapon_gsi_is_updated = false 
  50. local Upgrade_gsi_is_updated = false 
  51.  
  52. local MENU_TIER	= 1 
  53. local RADIAL_TIER	= 2 
  54. local WEAPON_TIER	= 3 
  55. local LEVEL_TIER	= 4 
  56. local GRENADE_UPGRADE_TIER = 5 
  57. local Current_tier = MENU_TIER 
  58. local Skip_next_populate = false 
  59. local Restore_weapon_radial_inputs = false 
  60.  
  61. local Current_slot = -1 
  62. local Prev_slot = -1 
  63.  
  64. local Radial_cache_x = STORE_WEAPON_RADIAL_CACHE_X 
  65. local Radial_store_x = STORE_WEAPON_RADIAL_STORE_X 
  66. local Radial_y = 0 
  67.  
  68. -- Hint bar and store header vdo's. 
  69.  
  70. local Store_logo1 
  71. local Store_logo2 
  72. local Not_popup_grp 
  73. local Reward_image 
  74. local Weapon_bg_grp 
  75. local Weapon_stats_grp 
  76. local Store_weapon_not_bg_grp 
  77. local Slot_stats_grp 
  78. local Weapons_owned = {} 
  79. local Weapons_available = {} 
  80. local Stats_initialized = false 
  81. local Weapon_store_highlight_color = {} 
  82.  
  83. local Store_weapon_new_image = -1 
  84. local Store_weapon_loading_img = nil 
  85. local Store_weapon_unload_img  = nil 
  86.  
  87. local Store_weapon_img_update_thread = -1 
  88. -- We used this as a reference to the current submenu we are building. 
  89. local Store_weapon_building_menu = {} 
  90.  
  91. local Store_weapon_loaded_from_crib = false 
  92.  
  93. -- Determines if we're in "store" or "cache" mode. 
  94. local Store_weapon_is_cache = false 
  95.  
  96. -- Stores data regarding ammo that is not stored in the radial menu vdo. 
  97. local Store_weapon_ammo_info = {} 
  98. local Store_weapon_thrown_ammo_info = {} 
  99.  
  100. -- Info on weapon that may be purchaed. 
  101. local Store_weapon_current_info = {} 
  102.  
  103. -- Used to flag we are leaving UI because the player entered the cache with no weapons 
  104. local Store_weapon_cache_no_weapons = false 
  105.  
  106. -- True if we're currently waiting on a weapon swap/load 
  107. local Store_weapon_is_loading = false 
  108.  
  109. -- Save the previous grid index to prevent mouse move triggering every frame 
  110. local Old_index = 0 
  111.  
  112. -- Store off costume id 
  113. local Costume_id = 0 
  114.  
  115. -- Used to track weapon radial input and state 
  116. Store_weapon_inventory = { 
  117. 	stick_mag = 0, 
  118. 	is_pressed = false, 
  119. 	selected_cb = nil, 
  120. 	nav_cb = nil 
  121. } 
  122.  
  123. -- local Hint_bar_rotate 
  124.  
  125. -- Stores data regarding the grid selector for weapons 
  126. local Weapon_grid_data = {} 
  127.  
  128. -- Index of the starting weapon grid choice to highlight. 
  129. local Weapon_grid_idx = 1 
  130.  
  131. local Store_weapon_tool_mode = false 
  132.  
  133. -- Menu category enums 
  134. local STORE_WEAPON_CATEGORY_AMMO 			= 2 
  135. local STORE_WEAPON_CATEGORY_UPGRADES 		= 3 
  136. local STORE_WEAPON_CATEGORY_WEAPON_CACHE 	= 4 
  137.  
  138. -- Start on the first selection 
  139. local Store_weapon_menu_category 			= STORE_WEAPON_CATEGORY_AMMO 
  140.  
  141. -- Used to find where we are in the flow 
  142. local STORE_WEAPON_LEVEL_MAIN = 1 
  143. local STORE_WEAPON_LEVEL_GRID = 2 
  144. local STORE_WEAPON_LEVEL_UPGRADE = 3 
  145. local STORE_WEAPON_LEVEL_COSTUME = 4 
  146.  
  147. local Store_weapon_menu_level = STORE_WEAPON_LEVEL_MAIN 
  148.  
  149. local Store_weapon_categories = { 
  150. 	[1] = { label = "WPN_STORE_MELEE_TITLE",		category = "melee",		info = {} 		}, 
  151. 	[2] = { label = "WPN_STORE_PISTOL_TITLE",		category = "pistol",		info = {} 		}, 
  152. 	[3] = { label = "WPN_STORE_SMG_TITLE", 		category = "smg", 		info = {} 		}, 
  153. 	[4] = { label = "WPN_STORE_SHOTGUN_TITLE",	category = "shotgun", 	info = {} 		}, 
  154. 	[5] = { label = "WPN_STORE_RIFLE_TITLE", 		category = "rifle", 		info = {} 		}, 
  155. 	[6] = { label = "WPN_STORE_EXPLOSIVE_TITLE", category = "explosive", info = {} 		}, 
  156. 	[7] = { label = "WPN_STORE_SPECIAL_TITLE",	category = "special", 	info = {} 		}, 
  157. 	[8] = { label = "WPN_STORE_THROWN_TITLE", 	category = "thrown", 	info = {} 		}, 
  158. 	[9] = { label = "WPN_STORE_THROWN_TITLE", 	category = "thrown", 	info = {} 		}, 
  159. 	[10] = { label = "WPN_STORE_THROWN_TITLE", 	category = "thrown",		info = {} 		}, 
  160. 	[11] = { label = "WPN_STORE_THROWN_TITLE", 	category = "thrown", 	info = {} 		}, 
  161. } 
  162.  
  163. local Store_weapon_alien = { 
  164. 	[1] = {label = "ui_hud_inv_35_abduction"}, 
  165. 	[2] = {label = "ui_hud_inv_35_black_hole"}, 
  166. 	[3] = {label = "ui_hud_inv_35_disintegrator"}, 
  167. 	[4] = {label = "ui_hud_inv_35_glitch"}, 
  168. 	[5] = {label = "ui_hud_inv_35_laser_mg"},			 
  169. 	[6] = {label = "ui_hud_inv_35_minefield"}, 
  170. 	[7] = {label = "ui_hud_inv_35_plasma"},	 
  171. 	[8] = {label = "ui_hud_inv_35_shrink"}, 
  172. 	[9] = {label = "ui_hud_inv_35_tentacle"}, 
  173. } 
  174.  
  175. local Store_weapon_always_loaded_icons = { 
  176. 	[1] = "ui_hud_inv_35_abduction", 
  177. 	[2] = "ui_hud_inv_35_black_hole", 
  178. 	[3] = "ui_hud_inv_35_disintegrator", 
  179. 	[4] = "ui_hud_inv_35_glitch", 
  180. 	[5] = "ui_hud_inv_35_laser_mg",			 
  181. 	[6] = "ui_hud_inv_35_minefield", 
  182. 	[7] = "ui_hud_inv_35_plasma",	 
  183. 	[8] = "ui_hud_inv_35_shrink", 
  184. 	[9] = "ui_hud_inv_35_tentacle", 
  185. 	[10] = "ui_hud_inv_spc_dubstep", 
  186. 	[11] = "ui_hud_inv_35_probe", 
  187. 	[12] = "ui_hud_inv_s_spc_merica", 
  188. 	[13] = "ui_hud_inv_s_spc_murder_laser", 
  189. 	[14] = "ui_hud_inv_35_locust",			 
  190. 	[15] = "ui_hud_inv_exp_satchels", 
  191. 	[16] = "ui_hud_inv_melee_killbane",	 
  192. 	[17] = "ui_hud_inv_s_exp_murder_mine", 
  193. 	[18] = "ui_hud_inv_spc_airstrike",	 
  194. 	[19] = "ui_hud_inv_spc_chumgun",	 
  195. 	[20] = "ui_hud_inv_spc_genkigun",	 
  196. 	[21] = "ui_hud_inv_brute_flame",	 
  197. 	[22] = "ui_hud_inv_pick_luchadore_gl",	 
  198. 	[23] = "ui_hud_inv_pick_brute_mg",	 
  199. 	[24] = "ui_hud_inv_spc_sonicgun",	 
  200. 	[25] = "ui_hud_inv_dlc_brute_mg", 
  201. 	[26] = "ui_hud_inv_dlc_brute_flame", 
  202. 	[27] = "ui_hud_inv_dlc_dubstep", 
  203. 	[28] = "ui_hud_inv_s_dlc_hillbilly_pg", 
  204. 	[29] = "ui_hud_inv_dlc_knifelauncher", 
  205. 	[30] = "ui_hud_inv_dlc_bb_gun", 
  206. 	[31] = "ui_hud_inv_s_dlc_dub_xmas", 
  207. 	[32] = "ui_hud_inv_dlc_polar", 
  208. 	[33] = "ui_hud_inv_tf2_flame", 
  209. 	[34] = "ui_hud_inv_tf2_rainblower", 
  210. 	[35] = "ui_hud_inv_tf2_rocket", 
  211. 	[36] = "ui_hud_inv_dlc_bb_gun", 
  212. } 
  213.  
  214. local Notoriety_level_clear_cost_data = {} 
  215.  
  216. -- Removing these weapons from the alien category because they use ammo now 
  217. --"ui_hud_inv_35_laser_smg" 
  218. --"ui_hud_inv_35_laser_rifle" 
  219. --"ui_hud_inv_35_railgun" 
  220. --"ui_hud_inv_35_revolver" 
  221. --"ui_hud_inv_35_locust" 
  222.  
  223.  
  224. --[[Weapon_data = { 
  225. 	[WEAPON_1] = { 
  226. 		title = ".45 SHEPERD", 
  227. 		id = 1, 
  228. 		attributes = { 
  229. 			[ATTRIBUTE_1] = { 
  230. 				label = "AMMO CAPACITY" 
  231. 				max_levels = 6 
  232. 				levels_owned = 1 
  233. 				level_data = { 
  234. 					[LEVEL_1] = { 
  235. 						desc = "Increase ammo capcity by 20%", 
  236. 						price = 1000, 
  237. 					}, 
  238. 					[LEVEL_2] = { 
  239. 						desc = "Increase ammo capcity by 30%", 
  240. 						price = 2000, 
  241. 					}, 
  242. 					[LEVEL_3] = { 
  243. 						desc = "Increase ammo capcity by 40%", 
  244. 						price = 3000, 
  245. 					}, 
  246. 					[LEVEL_4] = { 
  247. 						desc = "Increase ammo capcity by 50%", 
  248. 						price = 4000, 
  249. 					}, 
  250. 					[LEVEL_5] = { 
  251. 						desc = "Increase ammo capcity by 60%", 
  252. 						price = 5000, 
  253. 					}, 
  254. 					[LEVEL_6] = { 
  255. 						desc = "Increase ammo capcity by 70%", 
  256. 						price = 6000, 
  257. 					},				 
  258. 				} 
  259. 			}, 
  260. 			[ATTRIBUTE_2] = { 
  261. 				label = "RELOAD SPEED" 
  262. 				max_levels = 4 
  263. 				levels_owned = 2 
  264. 				level_data = { 
  265. 					[LEVEL_1] = { 
  266. 						desc = "Increase reload speed by 20%", 
  267. 						price = 1000, 
  268. 					}, 
  269. 					[LEVEL_2] = { 
  270. 						desc = "Increase reload speed by 30%", 
  271. 						price = 2000, 
  272. 					}, 
  273. 					[LEVEL_3] = { 
  274. 						desc = "Increase reload speed by 40%", 
  275. 						price = 3000, 
  276. 					}, 
  277. 					[LEVEL_4] = { 
  278. 						desc = "Increase reload speed by 50%", 
  279. 						price = 4000, 
  280. 					},		 
  281. 				} 
  282. 			},		 
  283. 		} 
  284. 	} 
  285. }]] 
  286.  
  287.  
  288. ---------------------------------------------------------------------------  
  289. -- Initialize Weapon Store 
  290. --------------------------------------------------------------------------- 
  291. function store_weapon_init() 
  292. 	Game_platform = game_get_platform() 
  293.  
  294. 	Store_weapon_loaded_from_crib = store_common_crib_is_loaded() 
  295.  
  296. 	-- If we're in the crib, we're only doing cache (not store). 
  297. 	Store_weapon_is_cache = Store_weapon_loaded_from_crib 
  298. 		 
  299. 	Store_weapon_doc_handle = vint_document_find("store_weapon") 
  300.  
  301. 	Store_weapon_radial = Vdo_weapon_radial:new("weapon_radial", 0, Store_weapon_doc_handle) 
  302. 	Store_weapon_radial:set_visible(false) 
  303. 	 
  304. 	Store_weapon_radial:cache_mode_enable(Store_weapon_is_cache) 
  305. 	 
  306. 	--No grenades in SR4, just powers... hide the dpad in the store. 
  307. 	Store_weapon_radial:show_dpad_menu(false) 
  308. 	 
  309. 	--Get y of weapon radial in vint doc 
  310. 	local radial_x, new_y = Store_weapon_radial:get_anchor()	 
  311. 	Radial_y = new_y 
  312. 	 
  313. 	if Store_weapon_loaded_from_crib then 
  314. 		Weapon_store_highlight_color = COLOR_STORE_CRIB_PRIMARY 
  315. 	else 
  316. 		Weapon_store_highlight_color = COLOR_STORE_WEAPON_PRIMARY 
  317. 	end 
  318.  
  319. 	-- Iniitialize weapon store image... 
  320. 	Reward_image = Vdo_bitmap_viewer:new("reward_image", 0, Store_weapon_doc_handle)	 
  321. 	 
  322. 	-- Hide description 
  323. 	Reward_image:set_description(" ", nil) 
  324. 	Reward_image:set_visible(false) 
  325. 	Store_common_current_highlight_color = Weapon_store_highlight_color 
  326. 	 
  327. 	Store_weapon_radial:set_highlight_color(Weapon_store_highlight_color) 
  328. 	 
  329. 	Store_weapon_not_bg_grp = Vdo_base_object:new("weapon_not_bg_grp", 0, Store_weapon_doc_handle) 
  330. 	 
  331. 	-- This turns on "store mode" for weapon radial, which makes changes like shows hint buttons and disables choices. 
  332. 	Store_weapon_radial:store_mode_enable(true)	 
  333. 		 
  334. 	-- Set up some callbacks for the common store script 
  335. 	Store_common_populate_list_cb 	= store_weapon_populate_list 
  336. 	Store_common_exit_cb					= store_weapon_exit 
  337. 	 
  338. 	-- Initialize mouse input trackers and create mouse tracker for the hint bar 
  339. 	if Game_platform == "PC" then 
  340. 		Mouse_input_tracker:subscribe(false) 
  341. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  342. 		Radial_mouse_input_tracker = Vdo_input_tracker:new() 
  343. 	end 
  344. 	 
  345. 	-- Subscribe to the button presses we need, Input_tracker is created in store_common.lua 
  346. 	store_lock_controls() 
  347. 	 
  348. 	--Setup Button Hints 
  349. 	local hint_data = { 
  350. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  351. 		--{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  352. 		--{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"}, 
  353. 	} 
  354. 	Store_common_hint_bar:set_hints(hint_data)  
  355. 	Store_common_hint_bar:set_visible(true) 
  356. 	 
  357. 	-- SEH: 6/28/11: cut zoom/rotate 
  358. 	-- Hint_bar_rotate = Vdo_hint_bar:new("hint_rotate", 0, Store_common_doc_handle) 
  359. 	-- local hint_rotate_data = { 
  360. 		-- {CTRL_BUTTON_RS, "CONTROL_ROTATE"}, 
  361. 	-- } 
  362. 	-- Hint_bar_rotate:set_hints(hint_rotate_data) 
  363. 	-- if game_is_active_input_gamepad() == true then 
  364. 		-- Hint_bar_rotate:set_visible(true) 
  365. 	-- end 
  366. 	 
  367. 	Store_header:set_visible(true) 
  368. 		 
  369. 	-- Everything that is not in the popup so we can fade it when the popup is active 
  370. 	Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle) 
  371. 	 
  372. 	-- Setup purchase popup 
  373. 	Store_common_popup:set_visible(false) 
  374. 	Store_common_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5)) 
  375. 	 
  376. 	-- Setup Color grid 
  377. 	Store_common_color_grid:set_visible(false) 
  378. 	Store_common_color_grid:set_ui_screen("store_weapon") 
  379. 	 
  380. 	-- Setup weapon stats 
  381. 	Weapon_stats_grp = Vdo_base_object:new("weapon_stats_grp", 0, Store_weapon_doc_handle) 
  382. 	Weapon_stats_grp:set_visible(false) 
  383. 		 
  384. 	-- Setup slot stats 
  385. 	Slot_stats_grp = Vdo_base_object:new("slot_stats_grp", 0, Store_weapon_doc_handle) 
  386. 	Slot_stats_grp:set_visible(false) 
  387. 	 
  388. 	-- don't do anything else when we're in customization camera tool mode 
  389. 	if vcust_is_camera_tool_mode() then 
  390. 	 
  391. 		Store_header:set_visible(false) 
  392. 	 
  393. 		-- make background so it is behind the weapon 
  394. 		--Weapon_bg_grp = Vdo_base_object:new("bg_grp", 0, Store_weapon_doc_handle)	 
  395. 		--Weapon_bg_grp:set_property("background", true)	 
  396. 		 
  397. 		-- draw bogus weapon info 
  398. 		local weapon_title = Vdo_base_object:new("weapon_title", 0, Store_weapon_doc_handle) 
  399. 		local weapon_level = Vdo_base_object:new("weapon_level", 0, Store_weapon_doc_handle) 
  400. 		 
  401. 		-- Display weapon stats 
  402. 		weapon_title:set_text("BOGUS WEAPON NAME") 
  403. 		local insert = { [0] = 1 } 
  404. 		local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert)		 
  405. 		weapon_level:set_text("Weapon description") 
  406. 		 
  407. 		Weapon_stats_grp:set_visible(true) 
  408. 		 
  409. 		Store_weapon_tool_mode = true 
  410. 		return 
  411. 	end 
  412. 	 
  413. 	if vint_is_std_res() then 
  414. 		Radial_cache_x = STORE_WEAPON_RADIAL_CACHE_SD_X 
  415. 		Radial_store_x = STORE_WEAPON_RADIAL_STORE_SD_X 
  416. 	end 
  417.  
  418. 	if Store_weapon_loaded_from_crib then 
  419. 		 
  420. 		-- Get reference to the weapon store background for future use 
  421. 		Weapon_bg_grp = Vdo_base_object:new("bg_grp", 0, Store_weapon_doc_handle)	 
  422. 			 
  423. 		-- From the crib, we just go straight to the weapon radial 
  424. 		Active_list:set_visible(false) 
  425.  
  426. 		-- Set the hint based on the platform 
  427. 		local hint_data = {} 
  428. 		if game_get_platform() == "PC" then 
  429. 			hint_data = { 
  430. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  431. 			} 
  432. 		else  
  433. 			hint_data = { 
  434. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  435. 				{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  436. 			} 
  437. 		end 
  438. 		 
  439. 		Store_common_hint_bar:set_hints(hint_data)  
  440. 		 
  441. 		if Hint_bar_mouse_input_tracker ~= nil then 
  442. 			Store_common_hint_bar:add_mouse_inputs("store_weapon", Hint_bar_mouse_input_tracker) 
  443. 			Hint_bar_mouse_input_tracker:subscribe(true) 
  444. 		end 
  445. 		 
  446. 		-- Hide separate bullet tile grp 
  447. 		local bullet_tile_grp_h = vint_object_find("bullet_tile_grp", 0, Store_weapon_doc_handle) 
  448. 		vint_set_property(bullet_tile_grp_h, "visible", false) 
  449. 		 
  450. 		-- Hide vignette 
  451. 		local vignette_grp_h = vint_object_find("vignette_grp", 0, Store_weapon_doc_handle) 
  452. 		vint_set_property(vignette_grp_h, "visible", false) 
  453. 		 
  454. 		-- Hide weapon store background since we use the saints background in crib 
  455. 		local weapon_store_bg_grp = Vdo_base_object:new("bg_texture_group", 0, Store_weapon_doc_handle) 
  456. 		weapon_store_bg_grp:set_visible(false) 
  457. 		 
  458. 		local weapon_logo_grp = Vdo_base_object:new("logo_grp", 0, Store_weapon_doc_handle) 
  459. 		weapon_logo_grp:set_visible(false) 
  460. 		 
  461. 		local red_bar_h = vint_object_find("red_bar",0,Store_weapon_doc_handle) 
  462. 		local grey = 30/255 
  463. 		vint_set_property(red_bar_h,"tint",grey,grey,grey) 
  464. 		Weapon_bg_grp:set_property("visible", false) 
  465. 		 
  466. 		local header_txt = Vdo_base_object:new("header_txt", 0, Store_weapon_doc_handle) 
  467. 		header_txt:set_color(Weapon_store_highlight_color.R,Weapon_store_highlight_color.G,Weapon_store_highlight_color.B) 
  468. 	 
  469. 		local weapon_title = Vdo_base_object:new("weapon_title", 0, Store_weapon_doc_handle) 
  470. 		weapon_title:set_color(Weapon_store_highlight_color.R,Weapon_store_highlight_color.G,Weapon_store_highlight_color.B) 
  471. 		 
  472. 		local texture_bg = vint_object_find("bg_texture_grp", 0, Store_weapon_doc_handle) 
  473. 		vint_set_property(texture_bg, "background", true) 
  474. 		vint_set_property(texture_bg, "visible", false) 
  475. 		 
  476. 		Store_common_color_grid:set_highlight_color(COLOR_STORE_CRIB_PRIMARY) 
  477. 		 
  478. 		Store_header:push_title(nil, "WPNSTOR_TITLE_WEAPON_CACHE") 
  479. 		Store_header:enable_price_respect(false) 
  480. 		 
  481. 		store_weapon_cover_weapon(true)	 
  482. 		 
  483. 		local mask_h = vint_object_find("mask",0,Store_weapon_doc_handle) 
  484. 		vint_set_property(mask_h,"scale",150,71) 
  485. 		 
  486. 		local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle) 
  487. 		store_main_grp:set_anchor(0,0) 
  488. 		 
  489. 		bg_saints_set_type(BG_TYPE_CRIB,true,1280) 
  490. 		 
  491. 		local anim_in = Vdo_anim_object:new("store_weapon_crib_anim_in", 0, Store_weapon_doc_handle) 
  492. 		local store_intro_anim = Vdo_anim_object:new("store_common_in_anim",0, Store_common_doc_handle) 
  493. 		local end_event_twn = Vdo_tween_object:new("end_event_twn", store_intro_anim.handle) 
  494.  
  495. 		end_event_twn:set_end_event("store_weapon_intro_anim_complete") 
  496. 		 
  497. 		vint_apply_start_values(store_intro_anim.handle) 
  498. 		vint_apply_start_values(anim_in.handle)		 
  499. 				 
  500. 		-- Start animation now 
  501. 		anim_in:play(0) 
  502. 		store_intro_anim:play(0) 
  503. 		 
  504. 		Current_tier = RADIAL_TIER 
  505. 		 
  506. 	else 
  507. 		--Populate store common list with store weapon main menu data 
  508. 		Menu_data = { 
  509. 			on_cancel = store_weapon_cancel_radial, 
  510. 			[1] = { label = "STORE_WEAPON_WIPE_NOTORIETY", type = TYPE_BUTTON, on_select = store_weapon_wipe_notoriety, on_nav = store_weapon_main_menu_nav }, 
  511. 			[2] = { label = "STORE_WEAPON_AMMO", type = TYPE_BUTTON, on_select = store_weapon_ammo_open_radial, on_nav = store_weapon_main_menu_nav }, 
  512. 			[3] = { label = "STORE_WEAPON_BUY_UPGRADE", type = TYPE_BUTTON, on_select = store_weapon_purchase_open_radial, on_nav = store_weapon_main_menu_nav }, 
  513. 		} 
  514. 		 
  515. 		--if store_weapon_is_tutorial_mode() == false then 
  516. 			Menu_data[#Menu_data + 1] = { label = "STORE_WEAPON_CACHE", type = TYPE_BUTTON,  on_select = store_weapon_cache_open_radial } 
  517. 		--end 
  518. 				 
  519. 		Menu_data[#Menu_data + 1] = { label = "STORE_EXIT", type = TYPE_BUTTON,  on_select = store_weapon_exit } 
  520. 		 
  521. 		local logo_grp_h = vint_object_find("logo_grp", 0, Store_weapon_doc_handle) 
  522. 		 
  523. 		-- Are we in mission mm_1_1?  Show GSI and fade out logo_grp 
  524. 		if store_weapon_is_tutorial_mode() == true then 
  525. 		 
  526. 			Store_weapon_in_mission = true 
  527. 			 
  528. 			 
  529. 			-- Does the player have any weapons?  If yes, then skip to buy upgrade objective 
  530. 			--if store_weapon_any_weapon_equipped() == true then 
  531. 				Store_common_gsi:update("MM_1_1_OBJ_PURCHASE_AN_UPGRADE", "ui_target_icon_use")	 
  532. 				Weapon_gsi_is_updated = true 
  533. 			--else 
  534. 			--	Store_common_gsi:update("MM_1_1_OBJ_PURCHASE_A_WEAPON", "ui_target_icon_use")	 
  535. 			--end								 
  536. 			 
  537. 			vint_set_property(logo_grp_h, "alpha", .35)			 
  538. 		end 
  539. 		 
  540. 		local logo_intro_anim = Vdo_anim_object:new("store_weapon_logo_intro", 0, Store_weapon_doc_handle) 
  541. 		local store_intro_anim = Vdo_anim_object:new("store_common_in_anim",0, Store_common_doc_handle) 
  542. 		local bg_anim = Vdo_anim_object:new("store_weapon_anim_in",0, Store_weapon_doc_handle) 
  543. 		local end_event_twn = Vdo_tween_object:new("end_event_twn", store_intro_anim.handle) 
  544. 		local tile_anim = Vdo_anim_object:new("store_weapon_bullet_tile_anim",0, Store_weapon_doc_handle) 
  545.  
  546. 		end_event_twn:set_end_event("store_weapon_intro_anim_complete")	 
  547. 		 
  548. 		vint_apply_start_values(logo_intro_anim.handle) 
  549. 		vint_apply_start_values(store_intro_anim.handle) 
  550. 		vint_apply_start_values(bg_anim.handle) 
  551. 	 
  552. 		logo_intro_anim:play(0)	 
  553. 		store_intro_anim:play(0)	 
  554. 		bg_anim:play(0) 
  555. 		tile_anim:play(0) 
  556. 		 
  557. 		ui_audio_post_event("enter_friendly_fire") 
  558. 		 
  559. 		-- Set Store Header colors 
  560. 		Store_header:set_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY, COLOR_STORE_WEAPON_TERTIARY)		 
  561. 		Active_list:set_highlight_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY)		 
  562. 		Store_common_popup:set_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY, COLOR_STORE_WEAPON_TERTIARY) 
  563. 		 
  564. 		-- Pass the table data to the megalist vdo. 
  565. 		store_weapon_populate_list(Menu_data, 1) 
  566. 		Active_list:set_visible(true) 
  567. 		 
  568.  
  569. 		-- Get reference to the weapon store background for future use 
  570. 		Weapon_bg_grp = Vdo_base_object:new("bg_black", 0, Store_weapon_doc_handle)	 
  571. 		 
  572. 		Current_tier = MENU_TIER 
  573. 		 
  574. 		store_weapon_cover_weapon(false)	 
  575. 		 
  576. 		Notoriety_level_clear_cost_data = {} -- reset the cost data 
  577.  
  578. 		vint_dataresponder_request("store_weapon_populate_notoriety", "store_weapon_notoriety_cost_update", 0) 
  579.  
  580. 		local player_notoriety_level = vint_get_player_notoriety(); 
  581.  
  582. 		if player_notoriety_level > 6 then 
  583. 			player_notoriety_level = 6 
  584. 		end 
  585.  
  586. 		if player_notoriety_level > 0 then 
  587. 			Store_header:set_price(Notoriety_level_clear_cost_data[player_notoriety_level].cost) 
  588. 		else 
  589. 			Store_header:set_price(nil) 
  590. 		end 
  591.  
  592. 	end	 
  593. 		 
  594. 	-- Subscribe to data group that will give us the currently equipped inventory 
  595. 	vint_datagroup_add_subscription("sr2_local_player_inventory", "update", "store_weapon_radial_update") 
  596. 	vint_datagroup_add_subscription("sr2_local_player_inventory", "insert", "store_weapon_radial_update")		 
  597. 	 
  598. 	--Dump the pause map to make room for store images 
  599. 	Store_weapon_pegs_thread_id = thread_new("store_weapon_load_pegs") 
  600. 	 
  601. 	--Set global flag if store weapon is loaded. 
  602. 	Store_weapon_is_loaded = true 
  603. end 
  604.  
  605. ------------------------------------------------------------------------------- 
  606. -- Dump pause map and load store weapon pegs 
  607. -- 
  608. function store_weapon_load_pegs() 
  609. 	pause_map_dump() 
  610.  
  611. 	game_peg_load_with_cb("store_weapon_load_peg_complete", 2, "ui_bms_store_weapon", "ui_bms_store_weapon_costumes") 
  612. end 
  613.  
  614.  
  615. ------------------------------------------------------------------------------- 
  616. -- Store weapon pegs are loaded 
  617. -- 
  618. function store_weapon_load_peg_complete() 
  619. end 
  620.  
  621.  
  622. -- Cleanup function called on document unload. 
  623. -- 
  624. function store_weapon_cleanup()	 
  625. 	if Hint_bar_mouse_input_tracker ~= nil then 
  626. 		Hint_bar_mouse_input_tracker:remove_all() 
  627. 	end 
  628. 	 
  629. 	if Radial_mouse_input_tracker ~= nil then 
  630. 		Radial_mouse_input_tracker:remove_all() 
  631. 	end 
  632.  
  633. 	if Store_weapon_tool_mode == false then 
  634. 		if Store_weapon_loaded_from_crib == false then 
  635. 			-- Nuke all button subscriptions 
  636. 			store_lock_controls()	 
  637. 		end 
  638. 	end	 
  639. 	if Store_weapon_inventory.thread ~= nil then 
  640. 		thread_kill(Store_weapon_inventory.thread) 
  641. 		Store_weapon_inventory.thread = nil 
  642. 	end 
  643. 	Store_weapon_radial:cleanup() 
  644. 	 
  645. 	-- Some things need to be cleaned up right away when a store doc is unloading, particular disabled inputs which have 
  646. 	-- callbacks to the script that is unloading. 
  647. 	store_common_cleanup_current_store() 
  648. 	 
  649. 	-- If we were forced out call preview one last time to make sure the equipped weapon has the correct skin 
  650. 	if Store_weapon_forced_out == true and Store_weapon_skin_was_previewed == true and Weapon_grid_data.category ~= nil then 
  651. 		local weapon_info = Weapon_grid_data[Weapon_grid_idx]		 
  652. 		--store_weapon_change_weapon(Weapon_grid_data.category, weapon_info.id, weapon_info.dual_wield, Store_weapon_is_cache, nil, weapon_info.costume_id, weapon_info.skin_id, true)	 
  653. 		--store_weapon_set_costume(Weapon_grid_data.category, weapon_info.id, weapon_info.costume_id) 
  654. 	end 
  655. 	 
  656. 	-- clean out end events 
  657. 	local store_intro_anim = Vdo_anim_object:new("store_common_in_anim",0, Store_common_doc_handle) 
  658. 	local end_event_twn = Vdo_tween_object:new("end_event_twn", store_intro_anim.handle) 
  659. 	end_event_twn:set_end_event(nil) 
  660. 	 
  661. 	-- clean out radial inputs 
  662. 	store_weapon_lock_radial()	 
  663.  
  664. 	local current_image = Reward_image:get_image()	 
  665. 	if current_image ~= nil then 
  666. 		game_peg_unload(current_image) 
  667. 	end	 
  668. 	if Store_weapon_unload_img ~= nil then 
  669. 		game_peg_unload(Store_weapon_unload_img) 
  670. 	end 
  671. 	if Store_weapon_loading_img ~= nil then 
  672. 		game_peg_unload(Store_weapon_loading_img) 
  673. 	end 
  674. 	-- Unload store weapon pegs and reload pause map 
  675. 	game_peg_unload("ui_bms_store_weapon") 
  676. 	game_peg_unload("ui_bms_store_weapon_costumes") 
  677. 	pause_map_restore()	 
  678. 	 
  679. 	-- Kill peg load thread 
  680. 	thread_kill(Store_weapon_pegs_thread_id) 
  681. 	Store_weapon_pegs_thread_id = -1 
  682. 	 
  683. 	--Set global store weapon is no longer loaded... 
  684. 	Store_weapon_is_loaded = false 
  685. end	 
  686.  
  687.  
  688.  
  689. function store_weapon_intro_anim_complete() 
  690. 	--Turn the lights on 
  691. 	store_weapon_enable_lights(true) 
  692.  
  693. 	store_weapon_process_post_bg_covered() 
  694. 	store_common_bg_anim_complete() 
  695.  
  696. 	if Store_weapon_loaded_from_crib == false then 
  697. 		store_unlock_controls() 
  698. 	else 
  699. 		-- Don't unlock radial input if we are showing the "you don't own any weapons" popup 
  700. 		if Store_weapon_cache_no_weapons == false then 
  701. 			store_weapon_cache_open_radial()	 
  702. 			store_weapon_unlock_radial() 
  703. 		else 
  704. 			Store_weapon_cache_no_weapons = false 
  705. 		end 
  706. 	end 
  707. end 
  708.  
  709.  
  710.  
  711. function store_lock_controls() 
  712. 	Input_tracker:subscribe(false) 
  713. 	store_weapon_enable_mouse(false) 
  714. end 
  715.  
  716. function store_unlock_controls() 
  717. 	Input_tracker:subscribe(true) 
  718. 	store_weapon_enable_mouse(true) 
  719. end 
  720.  
  721. function store_weapon_lock_radial() 
  722. 	--lock all the radial input 
  723. 	if Store_weapon_inventory.subs_x ~= nil then 
  724. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_x) 
  725. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_y) 
  726. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_up) 
  727. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_right) 
  728. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_down) 
  729. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_left) 
  730. 		 
  731. 		if Store_weapon_inventory.extra_buttons ~= nil then 
  732. 			for idx, val in pairs(Store_weapon_inventory.extra_buttons) do  
  733. 				vint_unsubscribe_to_input_event(val) 
  734. 			end 
  735. 		end 
  736. 	end 
  737. end 
  738.  
  739. function store_weapon_unlock_radial() 
  740. 	Store_weapon_inventory.extra_buttons = { 
  741. 		vint_subscribe_to_input_event("select", "store_weapon_inventory_input"), 
  742. 		vint_subscribe_to_input_event("back", "store_weapon_inventory_input"), 
  743. 		vint_subscribe_to_input_event("map", "store_weapon_inventory_input"), 
  744. 		vint_subscribe_to_input_event("pause", "store_weapon_inventory_input"), 
  745. 	} 
  746.  
  747. 	Store_weapon_inventory.subs_x = vint_subscribe_to_raw_input("inventory_x", "store_weapon_inventory_input") 
  748. 	Store_weapon_inventory.subs_y = vint_subscribe_to_raw_input("inventory_y", "store_weapon_inventory_input") 
  749. 	Store_weapon_inventory.subs_up = vint_subscribe_to_raw_input("inventory_up", "store_weapon_inventory_input") 
  750. 	Store_weapon_inventory.subs_right = vint_subscribe_to_raw_input("inventory_right", "store_weapon_inventory_input") 
  751. 	Store_weapon_inventory.subs_down = vint_subscribe_to_raw_input("inventory_down", "store_weapon_inventory_input") 
  752. 	Store_weapon_inventory.subs_left = vint_subscribe_to_raw_input("inventory_left", "store_weapon_inventory_input") 
  753. end 
  754.  
  755. function store_weapon_exit() 
  756. 	-- no confirmation needed if we're just going back to the crib menu 
  757. 	if Store_weapon_loaded_from_crib then 
  758. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  759. 		store_lock_controls() 
  760. 		store_weapon_lock_radial() 
  761. 		 
  762. 		-- make background so player is covered up 
  763. 		bg_saints_set_background(false) 
  764. 		local back_out_anim = Vdo_anim_object:new("store_crib_out_anim", 0, Store_common_doc_handle) 
  765. 		local weapon_back_out_anim = Vdo_anim_object:new("store_weapon_crib_anim_out",0, Store_weapon_doc_handle) 
  766. 		local back_out_end_twn = Vdo_tween_object:new("common_anchor_out_twn", back_out_anim.handle) 
  767. 		back_out_end_twn:set_end_event("store_weapon_crib_exit") 
  768. 		back_out_anim:play(0) 
  769. 		weapon_back_out_anim:play(0) 
  770. 	else 
  771. 		Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2) 
  772. 		Store_common_popup:set_title("MENU_TITLE_WARNING") 
  773. 		 
  774. 		if Store_weapon_is_cache then 
  775. 			Store_common_popup:set_text("WPN_STORE_EXIT_PROMPT") 
  776. 		else 
  777. 			Store_common_popup:set_text("STORE_EXIT_WARNING_BODY") 
  778. 		end 
  779. 		 
  780. 		Store_common_popup:nav_enable(true, "store_weapon_exit_final", "store_weapon_popup_nav") 
  781. 		Not_popup_grp:set_alpha(.5) 
  782. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  783. 		 
  784. 		game_UI_audio_play("UI_HUD_HELP") 
  785. 		 
  786. 		store_weapon_enable_mouse(false) 
  787. 	end 
  788. 	 
  789. 	if Mouse_input_tracker ~= 0 then 
  790. 		Mouse_input_tracker:subscribe(false) 
  791. 	end 
  792. end 
  793.  
  794. function store_weapon_crib_exit() 
  795. 	--Player exiting by choice, was not forced out from damage 
  796. 	Store_weapon_forced_out = false 
  797.  
  798. 	-- called when we slide out to the crib 
  799. 	pop_screen() 
  800. end 
  801.  
  802. function store_weapon_exit_final(event) 
  803. 	Store_common_popup:nav_enable(false, nil, nil) 
  804. 		 
  805. 	-- The user hit the B button and is exiting 
  806. 	-- This is redundant to selecting "No" in the list 
  807. 	if event == "back" then 
  808. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  809. 		Not_popup_grp:set_alpha(1) 
  810. 		Store_weapon_not_bg_grp:set_alpha(1)				 
  811. 		store_weapon_enable_mouse(true) 
  812. 		return 
  813. 	end 
  814. 	 
  815. 	game_UI_audio_play("UI_Main_Menu_Select") 
  816. 	 
  817. 	-- Did we select yes?  This assumes yes is the first item 
  818. 	if Store_common_popup:get_selected_data() ~= 1 then 
  819. 		Not_popup_grp:set_alpha(1) 
  820. 		Store_weapon_not_bg_grp:set_alpha(1) 
  821. 		store_weapon_enable_mouse(true) 
  822. 		return 
  823. 	end 
  824. 	 
  825. 	ui_audio_post_event("UI_Store_Exit") 
  826. 	 
  827. 	store_lock_controls() 
  828. 	 
  829. 	Not_popup_grp:set_alpha(0) 
  830. 	Store_weapon_not_bg_grp:set_alpha(0) 
  831. 	 
  832. 	--Turn the lights off 
  833. 	store_weapon_enable_lights(false) 
  834. 	 
  835. 	--Player exiting by choice, was not forced out from damage 
  836. 	Store_weapon_forced_out = false 
  837. 	 
  838. 	-- exit the interface 
  839. 	local anim_out = Vdo_anim_object:new("store_weapon_anim_out", 0, Store_weapon_doc_handle) 
  840. 	anim_out:play(0) 
  841. 	pop_screen() 
  842. end 
  843.  
  844. function store_weapon_no_weapons() 
  845. 	Store_common_popup:nav_enable(false, nil, nil) 
  846. 	game_UI_audio_play("UI_Main_Menu_Select") 
  847. 	Not_popup_grp:set_alpha(1) 
  848. 	Store_weapon_not_bg_grp:set_alpha(1) 
  849. 	Store_common_popup:set_visible(false) 
  850. 	 
  851. 	if Store_weapon_loaded_from_crib then 
  852. 		store_weapon_lock_radial() 
  853. 	else 
  854. 		store_weapon_cancel_radial() 
  855. 	end 
  856. 	 
  857. 	if Store_weapon_loaded_from_crib then 
  858. 		-- exit the interface 
  859. 		store_weapon_tutorial_mode(false) 
  860. 		pop_screen()		 
  861. 	end 
  862. end 
  863.  
  864. -- Handles navigation of any popups 
  865. function store_weapon_popup_nav(event, value) 
  866. 	if event == "nav_up" then	 
  867. 		Store_common_popup.list:move_cursor(-1)	 
  868. 	elseif event == "nav_down" then 
  869. 		Store_common_popup.list:move_cursor(1) 
  870. 	elseif event == "mouse_move" then 
  871. 		-- value contains the target_handle in this case 
  872. 		local new_index = Store_common_popup.list:get_button_index(value) 
  873. 		if new_index ~= 0 then 
  874. 			Store_common_popup.list:set_selection(new_index) 
  875. 			Store_common_popup.list:move_cursor(0, true) 
  876. 		end 
  877. 	else 
  878. 		--do nothing 
  879. 	end 
  880. end 
  881.  
  882. -- Handle navigation of the grid 
  883. function store_weapon_grid_nav(event, value) 
  884. 	-- Reset all highlights 
  885. 	Store_common_hint_bar:set_highlight(0) 
  886.  
  887. 	local prev_index = Store_common_color_grid:return_selected_index() 
  888.  
  889. 	if event == "nav_up" then	 
  890. 		Store_common_color_grid:move_cursor(-2)	 
  891. 	elseif event == "nav_down" then 
  892. 		Store_common_color_grid:move_cursor(2) 
  893. 	elseif event == "nav_left" then 
  894. 		Store_common_color_grid:move_cursor(-1) 
  895. 	elseif event == "nav_right" then 
  896. 		Store_common_color_grid:move_cursor(1) 
  897. 	elseif event == "mouse_move" then 
  898. 		-- value contains the target_handle in this case 
  899. 		local new_index = Store_common_color_grid:get_data_index(value) 
  900. 		if new_index ~= 0 then 
  901. 			if Old_index ~= new_index then 
  902. 				Store_common_color_grid:set_selection(new_index) 
  903. 				Store_common_color_grid:move_cursor(0, false, false) 
  904. 				Old_index = new_index 
  905. 			end 
  906. 		end 
  907. 	else 
  908. 		--do nothing 
  909. 	end 
  910. 	 
  911. 	-- Get the currently selected weapon info 
  912. 	local idx = Store_common_color_grid:return_selected_index() 
  913. 	 
  914. 	-- if index hasn't changed, don't proceed 
  915. 	if idx == prev_index then 
  916. 		return 
  917. 	end 
  918. 	 
  919. 	local weapon_info = Weapon_grid_data[idx] 
  920. 		 
  921. 	if weapon_info ~= nil then 
  922. 		-- Preview the model of the selected weapon 
  923. 		store_weapon_change_weapon_preview(Weapon_grid_data.category, weapon_info.id, weapon_info.dual_wield, Store_weapon_is_cache, nil, weapon_info.costume_id, weapon_info.skin_id, weapon_info.store_name_crc)	 
  924. 		 
  925. 		Weapon_grid_idx = idx 
  926. 		 
  927. 		--Update current costume name and description 
  928. 		Current_costume_name_crc = weapon_info.costume_name_crc 
  929. 		Current_costume_desc_crc = weapon_info.costume_desc_crc 
  930. 		Current_skin_name_crc = weapon_info.skin_name_crc 
  931. 		 
  932. 		store_weapon_price_update() 
  933. 		 
  934. 		Store_header:set_respect(nil) 
  935. 	end 
  936. end 
  937.  
  938.  
  939. function store_weapon_fail_msg(event) 
  940. 	Store_common_popup:nav_enable(false, nil, nil) 
  941. 	game_UI_audio_play("UI_Main_Menu_Select") 
  942. 	Not_popup_grp:set_alpha(1) 
  943. 	Store_weapon_not_bg_grp:set_alpha(1) 
  944. 	 
  945. 	-- Enable the active list or weapon radial if it's showing 
  946. 	if Current_tier ~= RADIAL_TIER and Current_tier ~= WEAPON_TIER then 
  947. 		store_weapon_enable_mouse(true) 
  948. 	else 
  949. 		if Hint_bar_mouse_input_tracker ~= nil then 
  950. 			Hint_bar_mouse_input_tracker:subscribe(true) 
  951. 			Radial_mouse_input_tracker:subscribe(true) 
  952. 		end 
  953. 	end 
  954. end 
  955.  
  956. ------------------------------------------------------------------------------- 
  957. -- Function store_weapon_populate_list() 
  958. -- 
  959. -- Populate the megalist. Update Store_weapon_building_menu with new data 
  960. -- 
  961. -- @param list_data 					-- data to display in the megalist 
  962. -- @param current_index 			-- current index to highlight 
  963. -- @param animate_list				-- determines whether we should animate the list 
  964. -- 
  965. ------------------------------------------------------------------------------- 
  966. function store_weapon_populate_list(list_data, current_index, animate_list) 
  967.  
  968. 	-- override the mega list width for standard def STORE_COMMON_LIST_SIZE 
  969. 	-- data, current_option, width, max_buttons, font_scale, force_width, animate_list	 
  970. 	Active_list:set_scale_text_if_too_big(true) 
  971. 	Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10, LIST_FONT_SCALE, false, animate_list)	 
  972. 	 
  973. 	-- Make sure our data matches what is sent to the megalist 
  974. 	Store_weapon_building_menu = list_data 
  975. 	 
  976. 	-- Add mouse input subscriptions 
  977. 	if Mouse_input_tracker ~= 0 then 
  978. 		Hint_bar_mouse_input_tracker:remove_all() 
  979. 		Store_common_hint_bar:add_mouse_inputs("store_weapon", Hint_bar_mouse_input_tracker) 
  980. 		 
  981. 		Mouse_input_tracker:remove_all() 
  982. 		Radial_mouse_input_tracker:remove_all() 
  983. 		Active_list:set_store("store_weapon") 
  984. 		Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  985. 		store_weapon_enable_mouse(true) 
  986. 		 
  987. 		-- When we're coming back from the upgrade screen, adjust what gets mouse inputs (best way to override behavior that's due to store_common) 
  988. 		if Skip_next_populate == true then 
  989. 			Skip_next_populate = false 
  990. 			Mouse_input_tracker:subscribe(false) 
  991. 			Hint_bar_mouse_input_tracker:subscribe(true) 
  992. 			if Restore_weapon_radial_inputs then 
  993. 				Store_weapon_radial:add_mouse_inputs("store_weapon", Radial_mouse_input_tracker, 50) 
  994. 				Radial_mouse_input_tracker:subscribe(true) 
  995. 			end 
  996. 		end 
  997. 		Restore_weapon_radial_inputs = false 
  998. 	end		 
  999. end 
  1000.  
  1001. -- User is going back to top level menu 
  1002. function store_weapon_cancel_radial() 
  1003. 	Store_header:set_price(nil) 
  1004. 	Store_header:pop_title() 
  1005. 	store_weapon_close_radial() 
  1006. 	 
  1007. 	game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  1008. 	 
  1009. 	-- Hide weapon and stats/description 
  1010. 	store_weapon_cover_weapon(false) 
  1011. 	--Weapon_stats_grp:set_visible(false) 
  1012. 		 
  1013. 	-- Hide the weapon preview 
  1014. 	store_weapon_hide_weapon() 
  1015.   
  1016. 	Current_tier = MENU_TIER 
  1017. 	 
  1018. 	--Save where we are in the flow 
  1019. 	Store_weapon_menu_level = STORE_WEAPON_LEVEL_MAIN 
  1020. end 
  1021.  
  1022.  
  1023. -- Close the ammo purchasing interface 
  1024. -- 
  1025. function store_weapon_close_radial()	 
  1026. 	-- Show megalist menu 
  1027. 	Active_list:set_visible(true) 
  1028. 	 
  1029. 	local hint_data = { 
  1030. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1031. 	} 
  1032. 	Store_common_hint_bar:set_hints(hint_data) 	 
  1033. 	 
  1034. 	-- Hide radial and stop input/thread. 
  1035. 	store_weapon_inventory_hide() 
  1036. 	 
  1037. 	--Set the list data back to first level options 
  1038. 	store_weapon_menu_data_reset() 
  1039. 		 
  1040. 	Current_tier = MENU_TIER 
  1041. end 
  1042.  
  1043.  
  1044. -- Ammo purchasing ****************************************************************************************** 
  1045.  
  1046. -- Open the ammo purchasing radial menu. 
  1047. -- 
  1048. function store_weapon_ammo_open_radial(menu_data) 
  1049. 	Store_weapon_menu_category = STORE_WEAPON_CATEGORY_AMMO 
  1050. 	Active_list:set_visible(false) 
  1051. 		 
  1052. 	store_weapon_stats_update(1, false)	 
  1053. 	 
  1054. 	store_weapon_cover_weapon(true) 
  1055. 	store_weapon_hide_weapon() 
  1056. 	 
  1057. 	Store_weapon_is_cache = false 
  1058. 		 
  1059. 	-- Set the callback to use when the user selects a cateogory from the radial menu 
  1060. 	Store_weapon_inventory.selected_cb = store_weapon_ammo_purchase 
  1061. 	Store_weapon_inventory.nav_cb = store_weapon_ammo_nav 
  1062. 	 
  1063. 	Store_weapon_ammo_info = {} 
  1064. 	Store_weapon_thrown_ammo_info = {} 
  1065. 	vint_dataresponder_request("store_weapon_populate_ammo", "store_weapon_ammo_add_items", 0)	 
  1066. 	 
  1067. 	-- Disable first two slots that don't use ammo 
  1068. 	Store_weapon_radial:slot_disable(0) 
  1069. 	Store_weapon_radial:slot_disable(1) 
  1070. 	 
  1071. 	--disable super powers slots 
  1072. 	for i=8, 11 do 
  1073. 		Store_weapon_radial:slot_disable(i) 
  1074. 	end 
  1075. 	 
  1076. 	--Hide grenades 
  1077. 	Store_weapon_radial:show_dpad_menu(false) 
  1078. 	 
  1079. 	--Position radial 
  1080. 	Store_weapon_radial:set_anchor(Radial_store_x,Radial_y) 
  1081. 	 
  1082. 	-- Disable any slots where we can't buy ammo  
  1083. 	for slot_i = 2, 7 do 
  1084. 		local ammo_info = store_weapon_ammo_find_by_id(slot_i) 
  1085. 		if ammo_info == nil then 
  1086. 			Store_weapon_radial:slot_disable(slot_i) 
  1087. 			Store_weapon_radial:slot_show_ammo(slot_i, false) 
  1088. 		else 
  1089. 			Store_weapon_radial:slot_enable(slot_i) 
  1090. 			Store_weapon_radial:slot_show_ammo(slot_i, true) 
  1091. 		end 
  1092. 		 
  1093. 		-- Disable alien weapon slots 
  1094. 		for weapon_i = 1, #Store_weapon_alien do 
  1095. 			if Store_weapon_radial:get_weapon_name(slot_i) == Store_weapon_alien[weapon_i].label then 
  1096. 				Store_weapon_radial:slot_disable(slot_i) 
  1097. 				Store_weapon_radial:slot_show_ammo(slot_i, false) 
  1098. 			end 
  1099. 		end 
  1100.  
  1101. 		-- Disable if this weapon has infinite ammo 
  1102. 		if Store_weapon_radial:slot_has_infinite_ammo(slot_i) then 
  1103. 			Store_weapon_radial:slot_disable(slot_i) 
  1104. 			Store_weapon_radial:slot_show_ammo(slot_i, false) 
  1105. 		end 
  1106. 	end 
  1107. 	 
  1108. 	-- Open the radial menu 
  1109. 	store_weapon_inventory_show(menu_data) 
  1110. end 
  1111.  
  1112. function store_weapon_ammo_nav(slot_id) 
  1113. 	-- Can't purchase ammo for some categories 
  1114. 	if slot_id < 2 then 
  1115. 		Store_header:set_price(nil)	 
  1116. 		return 
  1117. 	end 
  1118.  
  1119. 	local ammo_info 
  1120.  
  1121. 	-- is this thrown or normal weapon? 
  1122. 	if slot_id < 8 then 
  1123. 		ammo_info = store_weapon_ammo_find_by_id(slot_id) 
  1124. 	else 
  1125. 		ammo_info = store_weapon_thrown_ammo_find_by_id(slot_id - 8) 
  1126. 	end 
  1127. 	 
  1128. 	-- ammo is not available for this category 
  1129. 	if ammo_info == nil then 
  1130. 		Store_header:set_price(nil)	 
  1131. 		return 
  1132. 	end 
  1133.  
  1134. 	-- Disable if this weapon has infinite ammo 
  1135. 	if Store_weapon_radial:slot_has_infinite_ammo(slot_id) then 
  1136. 		Store_header:set_price(nil)	 
  1137. 		return 
  1138. 	end 
  1139. 	 
  1140. 	-- Show the ammo price 
  1141. 	if ammo_info.price == 0 then 
  1142. 		Store_header:set_price(nil) 
  1143. 	else 
  1144. 		Store_header:set_price(ammo_info.price) 
  1145. 	end 
  1146. 	 
  1147. 	store_weapon_stats_update(slot_id, false)	 
  1148. end 
  1149.  
  1150.  
  1151. function store_weapon_stats_update(slot_id, show_available, force_update)	 
  1152. 	-- If force_update is set to true, we want to stay on the same slot id 
  1153. 	if force_update == true then 
  1154. 		if slot_id == -1 then 
  1155. 			slot_id = Prev_slot 
  1156. 		end 
  1157. 	else  
  1158. 		if slot_id == Prev_slot then 
  1159. 			return 
  1160. 		end 
  1161. 		 
  1162. 		Prev_slot = slot_id 
  1163. 	end 
  1164. 	 
  1165. 	Stats_initialized = true 
  1166. 	 
  1167. 	--[[Info in Weapon_grid_data 
  1168. 	 
  1169. 		icon = icon_name, 
  1170. 		label = name_str, 
  1171. 		color = { red = 1, green = 1, blue = 1 }, 
  1172. 		is_owned = own, 
  1173. 		id = id, 
  1174. 		dual_wield = dual_wield, 
  1175. 		price = price, 
  1176. 		level = upgrade_level, 
  1177. 		level_desc = desc_crc, 
  1178. 		is_checked = false, 
  1179. 		equipped = equipped, 
  1180. 		 
  1181. 	]]-- 
  1182. 	 
  1183. 	-- Get new data for Weapon_grid_data 
  1184. 	store_weapon_populate_weapon_grid(Store_weapon_categories[slot_id].category, slot_id) 
  1185. 	 
  1186. 	-- Display slot info 
  1187. 	local header_txt = Vdo_base_object:new("header_txt", 0, Store_weapon_doc_handle) 
  1188. 	local owned_grp = Vdo_base_object:new("owned_grp", 0, Store_weapon_doc_handle) 
  1189. 	local available_grp = Vdo_base_object:new("available_grp", 0, Store_weapon_doc_handle) 
  1190. 	local owned_txt = Vdo_base_object:new("owned_txt", 0, Store_weapon_doc_handle) 
  1191. 	local available_txt = Vdo_base_object:new("available_txt", 0, Store_weapon_doc_handle) 
  1192. 	local base_weapon_txt = Vdo_base_object:new("base_weapon_txt", 0, Store_weapon_doc_handle) 
  1193. 	local base_txt_x, base_txt_y = base_weapon_txt:get_anchor()	 
  1194. 	local base_txt_width, base_txt_height = element_get_actual_size(base_weapon_txt.handle) 
  1195. 	local num_weapons = #Weapon_grid_data 
  1196. 	local new_x, new_y = base_txt_x, base_txt_y 
  1197. 	local WEAPON_TXT_BUFFER_HD = 5	 
  1198. 	local WEAPON_TXT_BUFFER_SD = 12	 
  1199. 	local HEADER_TXT_MAX_WIDTH_HD = 530 
  1200. 	local HEADER_TXT_MAX_WIDTH_SD = 350 
  1201. 	local Weapon_txt_buffer = WEAPON_TXT_BUFFER_HD 
  1202. 	local max_header_width = HEADER_TXT_MAX_WIDTH_HD	 
  1203. 	 
  1204. 	-- Set headers 
  1205. 	header_txt:set_text(Store_weapon_categories[slot_id].label)	 
  1206. 	owned_txt:set_text("STORE_WEAPON_OWNED")	 
  1207. 	available_txt:set_text("STORE_WEAPON_AVAILABLE")		 
  1208. 	base_weapon_txt:set_visible(false)	 
  1209. 	 
  1210. 	-- Resize header text to fit in other languages 
  1211. 	if vint_is_std_res() then 
  1212. 		max_header_width = HEADER_TXT_MAX_WIDTH_SD 
  1213. 		base_weapon_txt:set_property("wrap_width", 320) 
  1214. 		Weapon_txt_buffer = WEAPON_TXT_BUFFER_SD 
  1215. 	end 
  1216. 	 
  1217. 	--Change color if we're in the crib cache 
  1218. 	local subheader_bar_h = vint_object_find("subheader_bar", owned_grp.handle, Store_weapon_doc_handle) 
  1219. 	local subheader_bar_1_h = vint_object_find("subheader_bar_1", available_grp.handle, Store_weapon_doc_handle) 
  1220. 	 
  1221. 	if Store_weapon_loaded_from_crib then		 
  1222. 		vint_set_property(subheader_bar_h, "alpha", 1) 
  1223. 		vint_set_property(subheader_bar_1_h, "alpha", 1) 
  1224. 		 
  1225. 		base_weapon_txt:set_color(STORE_CRIB_DESC_COLOR.R, STORE_CRIB_DESC_COLOR.G, STORE_CRIB_DESC_COLOR.B) 
  1226. 		 
  1227. 		header_txt:set_color(STORE_CRIB_TITLE_COLOR.R, STORE_CRIB_TITLE_COLOR.G, STORE_CRIB_TITLE_COLOR.B) 
  1228. 	end 
  1229. 	 
  1230. 	header_txt:set_scale(1, 1)	 
  1231. 	local header_width, header_height = element_get_actual_size(header_txt.handle) 
  1232. 	 
  1233. 	if header_width >= max_header_width then 
  1234. 		local text_scale = max_header_width/header_width 
  1235. 		header_txt:set_scale(text_scale, text_scale) 
  1236. 	end 
  1237. 	 
  1238. 	new_y = new_y + base_txt_height + Weapon_txt_buffer 
  1239. 	 
  1240. 	-- Destroy clones and reset tables 
  1241. 	for i = 1, #Weapons_owned do 
  1242. 		Weapons_owned[i]:object_destroy()	 
  1243. 	end 
  1244. 	Weapons_owned = {} 
  1245. 	 
  1246. 	for i = 1, #Weapons_available do 
  1247. 		Weapons_available[i]:object_destroy() 
  1248. 	end	 
  1249. 	Weapons_available = {} 
  1250. 	 
  1251. 	-- Create "owned" list 
  1252. 	local num_weapons_owned = 1 
  1253. 	for i = 1, num_weapons do 
  1254. 		local info = Weapon_grid_data[i] 
  1255. 		if info.is_owned == true then 
  1256. 			--clone text			 
  1257. 			local cur_weapon 
  1258. 			local skip_dual_item = false 
  1259. 			if info.dual_wield == true then 
  1260. 				skip_dual_item = true 
  1261. 				cur_weapon = Weapons_owned[num_weapons_owned-1] 
  1262. 			else 
  1263. 				cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle) 
  1264. 			end 
  1265. 					 
  1266. 			-- Append level to each weapon and equipped status 
  1267. 			local body, insert_values 
  1268. 			 
  1269. 			-- Display weapon name and equipped status 
  1270. 			if info.equipped == true then 
  1271. 				local color = "[format][color:#ff932a]" 
  1272. 				if Store_weapon_loaded_from_crib then 
  1273. 					color = "[format][color:#b6d6f6]" 
  1274. 				end 
  1275. 				insert_values = {[0] = info.label, [1] = color } 
  1276. 				body = vint_insert_values_in_string("STORE_WEAPON_OWNED_EQUIPPED", insert_values)				 
  1277. 			else  
  1278. 				insert_values = {[0] = info.label} 
  1279. 				body = vint_insert_values_in_string("STORE_WEAPON_OWNED_NOT_EQUIPPED", insert_values) 
  1280. 			end 
  1281. 			 
  1282. 			cur_weapon:set_text(body)			 
  1283. 						 
  1284. 			local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle) 
  1285. 									 
  1286. 			cur_weapon:set_anchor(new_x, new_y) 
  1287. 			 
  1288. 			new_y = new_y + cur_weapon_height + Weapon_txt_buffer 
  1289. 			 
  1290. 			cur_weapon:set_visible(true) 
  1291. 			 
  1292. 			--Store to global for cleanup 
  1293. 			if skip_dual_item == false then 
  1294. 				Weapons_owned[num_weapons_owned] = cur_weapon 
  1295. 				num_weapons_owned = num_weapons_owned + 1 
  1296. 			end 
  1297. 		end 
  1298. 	end	 
  1299. 	 
  1300. 	-- Display none if no weapons are owned 
  1301. 	if Weapons_owned[1] == nil then 
  1302. 		local cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle)  
  1303. 		 
  1304. 		cur_weapon:set_text("LOCALIZE_NONE")			 
  1305. 		 
  1306. 		local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle)	 
  1307. 		 
  1308. 		cur_weapon:set_anchor(new_x, new_y) 
  1309. 		 
  1310. 		new_y = new_y + cur_weapon_height + Weapon_txt_buffer	 
  1311. 		 
  1312. 		cur_weapon:set_visible(true) 
  1313. 		 
  1314. 		--Store for cleanup 
  1315. 		Weapons_owned[1] = cur_weapon 
  1316. 	end 
  1317. 	 
  1318. 	-- Get positioning for next list 
  1319. 	local avail_x, avail_y = available_grp:get_anchor() 
  1320. 	 
  1321. 	if vint_is_std_res() then	 
  1322. 		new_y = new_y + Weapon_txt_buffer * 2 
  1323. 	else 
  1324. 		new_y = new_y + Weapon_txt_buffer * 4 
  1325. 	end 
  1326. 	 
  1327. 	available_grp:set_anchor(avail_x, new_y)  
  1328. 	 
  1329. 	-- Create "available" list 
  1330. 	local num_available_weapons = 1 
  1331. 	for i = 1, num_weapons do 
  1332. 		local info = Weapon_grid_data[i] 
  1333. 		if info.is_owned == false then 
  1334. 			--clone text 
  1335. 			local cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle) 
  1336. 			 
  1337. 			cur_weapon:set_text(info.label)			 
  1338. 			 
  1339. 			local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle) 
  1340. 			new_y = new_y + cur_weapon_height + Weapon_txt_buffer	 
  1341. 						 
  1342. 			cur_weapon:set_anchor(new_x, new_y) 
  1343. 			 
  1344. 			cur_weapon:set_visible(true) 
  1345. 			 
  1346. 			--Store to global for cleanup 
  1347. 			Weapons_available[num_available_weapons] = cur_weapon 
  1348. 			num_available_weapons = num_available_weapons + 1 
  1349. 		end 
  1350. 	end	 
  1351.  
  1352. 	-- Show available weapons group? 
  1353. 	if show_available ~= nil then 
  1354. 		if #Weapons_available > 0 then 
  1355. 			available_grp:set_visible(show_available)	 
  1356. 			for i = 1, #Weapons_available do 
  1357. 				Weapons_available[i]:set_visible(show_available) 
  1358. 			end 
  1359. 		else 
  1360. 			available_grp:set_visible(false)	 
  1361. 		end 
  1362. 	else 
  1363. 		if Weapons_available[1] ~= nil then 
  1364. 			available_grp:set_visible(true)	 
  1365. 		else	 
  1366. 			available_grp:set_visible(false)	 
  1367. 		end 
  1368. 	end	 
  1369. 	 
  1370. 	--is the list of weapons past safe frame?  If so, move it up by that amount 
  1371.  
  1372. 	local new_stats_y = STORE_WEAPON_STATS_GRP_Y 
  1373. 	 
  1374. 	if new_y > STORE_WEAPON_STATS_GRP_MAX then 
  1375. 		new_stats_y = new_stats_y - (new_y - STORE_WEAPON_STATS_GRP_MAX) 
  1376. 	end 
  1377. 	 
  1378. 	if vint_is_std_res() then 
  1379. 		Slot_stats_grp:set_anchor(STORE_WEAPON_STATS_GRP_SD_X, new_stats_y) 
  1380. 	else 
  1381. 		Slot_stats_grp:set_anchor(STORE_WEAPON_STATS_GRP_X, new_stats_y) 
  1382. 	end 
  1383. end 
  1384.  
  1385. function store_weapon_populate_weapon_grid(category, slot) 
  1386.  
  1387. 	-- Initialize data for grid 
  1388. 	Weapon_grid_data = {} 
  1389. 	Weapon_grid_data.category = category 
  1390. 	 
  1391. 	vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category, slot - 8)	-- last param is only used for grenade slot index	 
  1392. end 
  1393.  
  1394.  
  1395. function store_weapon_ammo_find_by_id(id) 
  1396. 	for i = 1, #Store_weapon_ammo_info do 
  1397. 		if Store_weapon_ammo_info[i].id == id then 
  1398. 			debug_print("store_weapon","returning ammo info with name "..Store_weapon_ammo_info[i].icon_name.."\n") 
  1399. 			return Store_weapon_ammo_info[i] 
  1400. 		end 
  1401. 	end 
  1402. 	 
  1403. 	return nil 
  1404. end 
  1405.  
  1406.  
  1407. function store_weapon_thrown_ammo_find_by_id(id) 
  1408. 	for i = 1, #Store_weapon_thrown_ammo_info do 
  1409. 		if Store_weapon_thrown_ammo_info[i].thrown_wpn_id == id then 
  1410. 			return Store_weapon_thrown_ammo_info[i] 
  1411. 		end 
  1412. 	end 
  1413. 	 
  1414. 	return nil 
  1415. end 
  1416.  
  1417.  
  1418. -- Callback for data responder that populates ammo information for each category. 
  1419. -- 
  1420. function store_weapon_ammo_add_items(unused, icon_name, unused, price, clip_size, current_amount, max_amount, id, thrown_wpn_id) 
  1421.  
  1422. 	if thrown_wpn_id == nil or thrown_wpn_id == -1 then 
  1423.  
  1424. 		local index = #Store_weapon_ammo_info + 1 
  1425.  
  1426. 		Store_weapon_ammo_info[index] = { 
  1427. 			price = price, icon_name = icon_name, clip_size = clip_size, ammo_current = current_amount, ammo_max = max_amount, id = id, thrown_wpn_id = nil 
  1428. 		} 
  1429. 	else 
  1430. 	 
  1431. 		local index = #Store_weapon_thrown_ammo_info + 1 
  1432.  
  1433. 		-- SEH: make const for 1000 (special value from code) 
  1434. 		Store_weapon_thrown_ammo_info[index] = { 
  1435. 			price = price, icon_name = icon_name, clip_size = clip_size, ammo_current = current_amount, ammo_max = max_amount, id = 1000, thrown_wpn_id = thrown_wpn_id 
  1436. 		}	 
  1437. 	end 
  1438. end 
  1439.  
  1440.  
  1441. -- Purchase ammo from the radial menu. 
  1442. -- 
  1443. -- slot:		the slot number chosen in the radial menu. 
  1444. -- 
  1445. function store_weapon_ammo_purchase(slot) 
  1446. 	-- Can't purchase ammo for some categories 
  1447. 	if slot < 2 then 
  1448. 		return 
  1449. 	end 
  1450.  
  1451. 	-- Disable if this weapon has infinite ammo 
  1452. 	if Store_weapon_radial:slot_has_infinite_ammo(slot) then 
  1453. 		return 
  1454. 	end 
  1455.  
  1456. 	local ammo_info 
  1457.  
  1458. 	-- is this thrown or normal weapon? 
  1459. 	if slot < 8 then 
  1460. 		ammo_info = store_weapon_ammo_find_by_id(slot) 
  1461. 	else 
  1462. 		ammo_info = store_weapon_thrown_ammo_find_by_id(slot - 8) 
  1463. 	end 
  1464. 	 
  1465. 	-- ammo is not available for this category 
  1466. 	if ammo_info == nil then 
  1467. 		return 
  1468. 	end 
  1469. 	 
  1470. 	-- Check if we have space for ammo, and enough money. 
  1471. 	if ammo_info.ammo_current < ammo_info.ammo_max then 
  1472. 		if Store_common_player_cash >= ammo_info.price then 
  1473. 			local saved_cash = Store_common_player_cash 
  1474. 			 
  1475. 			-- Make the purchase. 
  1476. 			store_weapon_purchase_ammo(ammo_info.id, ammo_info.thrown_wpn_id, ammo_info.clip_size, ammo_info.price) 
  1477. 			ammo_info.ammo_current = ammo_info.ammo_current + ammo_info.clip_size 
  1478.  
  1479. 			if ammo_info.ammo_current > ammo_info.ammo_max then 
  1480. 				ammo_info.ammo_current = ammo_info.ammo_max 
  1481. 			end 
  1482. 			 
  1483. 			--play the purchase sound 
  1484. 			ui_audio_post_event("ammo_purchase") 
  1485. 			 
  1486. 			-- Refresh the ammo information 
  1487. 			Store_weapon_ammo_info = {} 
  1488. 			Store_weapon_thrown_ammo_info = {}			 
  1489. 			vint_dataresponder_request("store_weapon_populate_ammo", "store_weapon_ammo_add_items", 0)		 
  1490.  
  1491. 			-- refresh the stats info 
  1492. 			store_weapon_stats_update(-1, false, true)	 
  1493. 			 
  1494. 		else 
  1495. 			Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1496. 			Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  1497. 			Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")		 
  1498. 			Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  1499. 			Not_popup_grp:set_alpha(.5)	 
  1500. 			Store_weapon_not_bg_grp:set_alpha(.5) 
  1501. 			game_UI_audio_play("UI_HUD_HELP") 
  1502. 			store_weapon_enable_mouse(false) 
  1503. 			return		 
  1504. 		end 
  1505. 	else 
  1506. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1507. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  1508. 		Store_common_popup:set_text("WPNSTOR_TEXT_MAX_AMMO_STORE")		 
  1509. 		Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  1510. 		Not_popup_grp:set_alpha(.5)		 
  1511. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  1512. 		game_UI_audio_play("UI_HUD_HELP") 
  1513. 		store_weapon_enable_mouse(false) 
  1514. 		return			 
  1515. 	end	 
  1516. end 
  1517.  
  1518.  
  1519. -- Weapon purchasing and upgrading ****************************************************************************************** 
  1520.  
  1521. -- Open the weapon purchasing and upgrading radial menu. 
  1522. -- 
  1523. function store_weapon_purchase_open_radial(menu_data) 
  1524. 	Store_weapon_menu_category = STORE_WEAPON_CATEGORY_UPGRADES 
  1525. 	Active_list:set_visible(false) 
  1526. 	 
  1527. 	store_weapon_cover_weapon(true) 
  1528. 	store_weapon_hide_weapon() 
  1529. 	 
  1530. 	-- Set the hint based on the platform 
  1531. 	local hint_data = {} 
  1532. 	if game_get_platform() == "PC" then 
  1533. 		hint_data = { 
  1534. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1535. 		} 
  1536. 	else  
  1537. 		hint_data = { 
  1538. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1539. 			{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  1540. 		} 
  1541. 	end 
  1542. 	 
  1543. 	Store_common_hint_bar:set_hints(hint_data) 	 
  1544. 	if Hint_bar_mouse_input_tracker ~= nil then 
  1545. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  1546. 	end 
  1547. 	 
  1548. 	Store_weapon_is_cache = false 
  1549. 	 
  1550. 	-- Set the callback to use when the user selects a cateogory from the radial menu 
  1551. 	Store_weapon_inventory.selected_cb = store_weapon_grid_open 
  1552. 	Store_weapon_inventory.nav_cb = store_weapon_purchase_nav 
  1553. 	 
  1554. 	-- Disable the unarmed slot 
  1555. 	Store_weapon_radial:slot_disable(0) 
  1556. 		 
  1557. 	--Hide grenades 
  1558. 	Store_weapon_radial:show_dpad_menu(false) 
  1559. 	 
  1560. 	Store_weapon_radial:set_anchor(Radial_store_x,Radial_y)	 
  1561. 	 
  1562. 	-- Enable or disable slots based on availability 
  1563. 	for i = 1, 7 do 
  1564. 	 
  1565. 		--Hide ammo when only dealing with weapons 
  1566. 		Store_weapon_radial:slot_show_ammo(i, false)	 
  1567. 		 
  1568. 		-- Initialize data for grid 
  1569. 		Weapon_grid_data = {} 
  1570. 		 
  1571. 		local category = Store_weapon_categories[i].category 
  1572. 		 
  1573. 		vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  1574. 		 
  1575. 		-- If there are no choices, then disable 
  1576. 		if #Weapon_grid_data == 0 then 
  1577. 			Store_weapon_radial:slot_disable(i) 
  1578. 		else 
  1579. 			Store_weapon_radial:slot_enable(i) 
  1580. 		end 
  1581. 		 
  1582. 		Store_weapon_categories[i].info = Weapon_grid_data		 
  1583. 	end	 
  1584. 	 
  1585. 	-- Open the radial menu 
  1586. 	store_weapon_inventory_show(menu_data)	 
  1587. end 
  1588.  
  1589.  
  1590. function store_weapon_purchase_nav(slot_id)	 
  1591. 	store_weapon_stats_update(slot_id) 
  1592. 	store_weapon_cover_weapon(true) 
  1593. end 
  1594.  
  1595.  
  1596. ------------------------------------------------------------------------------- 
  1597. -- Function store_weapon_grid_open() 
  1598. -- 
  1599. -- Purchase or upgrade weapons from the radial menu. 
  1600. -- 
  1601. -- @param slot						-- the slot number chosen in the radial menu 
  1602. -- @param grid_index  			-- which item in grid is selected. default is 1 
  1603. -- @param push_title				-- determines if we push a new title to Store_header 
  1604. -- 
  1605. ------------------------------------------------------------------------------- 
  1606. function store_weapon_grid_open(slot, grid_index, push_title) 
  1607. 	debug_print("store_weapon", "called store_weapon_grid_open\n")	 
  1608.  
  1609. 	Current_slot = slot 
  1610. 	 
  1611. 	Old_index = 0 
  1612. 	 
  1613. 	-- Can't purchase some categories 
  1614. 	if slot < 1 then 
  1615. 		return 
  1616. 	end 
  1617. 		 
  1618. 	-- Initialize data for grid 
  1619. 	Weapon_grid_data = {} 
  1620. 	 
  1621. 	-- Get the category name string for the chosen slot. 
  1622. 	local category = Store_weapon_categories[slot].category 
  1623. 	 
  1624. 	vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category, slot - 8)	-- last param is only used for grenade slot index 
  1625.  
  1626. 	-- If there are no choices, don't go to grid 
  1627. 	if #Weapon_grid_data == 0 then 
  1628. 		debug_print("store_weapon", "not opening grid because there are no choices\n")	 
  1629. 		return 
  1630. 	end	 
  1631. 	 
  1632. 	-- Save of where we are in the flow 
  1633. 	Store_weapon_menu_level = STORE_WEAPON_LEVEL_GRID 
  1634. 	 
  1635. 	--Force a specific grid index if specified.  Otherwise use 1 
  1636. 	--Weapon_grid_idx = grid_index or 1	 
  1637. 	 
  1638. 	-- set the titles on top 
  1639. 	if push_title ~= false then 
  1640. 		Store_header:push_title( nil, Store_weapon_categories[slot].label )	 
  1641. 	end 
  1642. 	 
  1643. 	-- display the grid	 
  1644. 	Weapon_grid_data.category = category 
  1645. 	Store_common_color_grid:set_highlight_color(Weapon_store_highlight_color) 
  1646. 	Store_common_color_grid:draw_items(Weapon_grid_data, Weapon_grid_idx, 3, 3, 120, 100, 40, nil, nil, false) 
  1647. 	Store_common_color_grid:set_visible(true) 
  1648. 	Store_common_color_grid:nav_enable(true, "store_weapon_grid_selected", "store_weapon_grid_nav")	 
  1649. 		 
  1650. 	-- hide grid highlighted name 
  1651. 	Store_common_color_grid.highlight_name:set_visible(false) 
  1652. 	 
  1653. 	-- Close the radial before we show the grid. 
  1654. 	store_weapon_close_radial() 
  1655. 	 
  1656. 	-- Hide the megalist (close_radial function unhides it). 
  1657. 	Active_list:set_visible(false) 
  1658. 	 
  1659. 	if Game_platform == "PC" then 
  1660. 		Hint_bar_mouse_input_tracker:subscribe(false) 
  1661. 	end 
  1662. 	 
  1663. 	local hint_data = { 
  1664. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1665. 	} 
  1666. 	Store_common_hint_bar:set_hints(hint_data) 	 
  1667. 	 
  1668. 	if Game_platform == "PC" then 
  1669. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  1670. 	end	 
  1671. 	 
  1672. 	-- Get the currently selected weapon info 
  1673. 	local idx = Store_common_color_grid:return_selected_index() 
  1674. 	local weapon_info = Weapon_grid_data[idx]	 
  1675. 	 
  1676. 	--Update current costume name and description 
  1677. 	Current_costume_name_crc = weapon_info.costume_name_crc 
  1678. 	Current_costume_desc_crc = weapon_info.costume_desc_crc	 
  1679. 	Current_skin_name_crc = weapon_info.skin_name_crc 
  1680. 	 
  1681. 	-- Preview the model of the selected weapon 
  1682. 	--local current_idx = Store_common_color_grid:get_selection() 
  1683. 	local current_weapon_info = Weapon_grid_data[Weapon_grid_idx] 
  1684. 	store_weapon_populate_weapon_stats(current_weapon_info.label, Current_costume_name_crc, current_weapon_info.level_desc)	 
  1685. 	store_weapon_change_weapon_preview(Weapon_grid_data.category, weapon_info.id, weapon_info.dual_wield, Store_weapon_is_cache, nil, weapon_info.costume_id, weapon_info.skin_id, weapon_info.store_name_crc) 
  1686. 	 
  1687. 	-- Update price 
  1688. 	store_weapon_price_update() 
  1689. 	 
  1690. 	-- For thrown weapons, bypass the grid 
  1691. 	if category == "thrown" then 
  1692. 		Current_tier = GRENADE_UPGRADE_TIER 
  1693. 		store_weapon_grid_selected("select") 
  1694. 		if Mouse_input_tracker ~= 0 then 
  1695. 			Mouse_input_tracker:subscribe(false) 
  1696. 		end 
  1697. 		if Radial_mouse_input_tracker ~= nil then 
  1698. 			Radial_mouse_input_tracker:subscribe(false) 
  1699. 		end 
  1700. 	else 
  1701. 		Current_tier = WEAPON_TIER 
  1702. 		if Mouse_input_tracker ~= 0 then 
  1703. 			Mouse_input_tracker:subscribe(false) 
  1704. 		end 
  1705. 		if Radial_mouse_input_tracker ~= nil then 
  1706. 			Radial_mouse_input_tracker:subscribe(false) 
  1707. 		end 
  1708. 	end 
  1709. end 
  1710.  
  1711. -- Updates price in weapon grid.  Displays "OWNED" if weapon is owned. 
  1712. -- 
  1713. function store_weapon_price_update() 
  1714. 	local weapon_info = Weapon_grid_data[Weapon_grid_idx] 
  1715.  
  1716. 	-- Show the weapon/upgrade price 
  1717. 	if weapon_info.price == 0 or Store_weapon_is_cache == true then 
  1718. 		Store_header:set_price(nil) 
  1719. 	else 
  1720. 		Store_header:set_price(weapon_info.price) 
  1721. 	end 
  1722. 	 
  1723. 	--Show "OWNED" if weapon is owned 
  1724. 	if weapon_info.is_owned == true and Store_weapon_is_cache ~=true then 
  1725. 		Store_header:set_price("STORE_WEAPON_OWNED") 
  1726. 	end 
  1727. end 
  1728.  
  1729. -- Updates the price for notoriety wipe. Does not display price if notoriety level is 0 
  1730. -- 
  1731. function store_weapon_notoriety_price_update() 
  1732. 	local wipe_price = 100; 
  1733. 	-- Show the weapon/upgrade price 
  1734. 	if wipe_price == 0 then 
  1735. 		Store_header:set_price(nil) 
  1736. 	else 
  1737. 		Store_header:set_price(wipe_price) 
  1738. 	end 
  1739. end 
  1740.  
  1741.  
  1742. -- Updates weapon title, description, and/or costume name on right side of the screen 
  1743. -- 
  1744. function store_weapon_populate_weapon_stats(title, costume_name, desc_crc) 
  1745. 	 
  1746. 	local weapon_info 		= Weapon_grid_data[Weapon_grid_idx] 
  1747. 	local new_title		 	= title or weapon_info.label 
  1748. 	local new_costume_name	= costume_name or 0 
  1749. 	local new_desc_crc		= desc_crc or weapon_info.costume_desc_crc or weapon_info.level_desc 
  1750. 	 
  1751. 	-- Get the currently selected weapon info 
  1752. 	local weapon_title_h = vint_object_find("weapon_title", 0, Store_weapon_doc_handle) 
  1753. 	local weapon_level_h = vint_object_find("weapon_level", 0, Store_weapon_doc_handle) 
  1754. 	local level_desc_h = vint_object_find("level_desc", 0, Store_weapon_doc_handle) 
  1755. 	 
  1756. 	if vint_is_std_res() then 
  1757. 		vint_set_property(level_desc_h, "wrap_width", 340) 
  1758. 	end 
  1759. 	 
  1760. 	--Change color and alpha if in crib 
  1761. 	local weapon_level_bar_h = vint_object_find("weapon_level_bar", 0, Store_weapon_doc_handle) 
  1762. 	if Store_weapon_loaded_from_crib then 
  1763. 		vint_set_property(weapon_level_bar_h, "alpha", 1) 
  1764. 		 
  1765. 		vint_set_property(weapon_title_h, "tint", STORE_CRIB_TITLE_COLOR.R, STORE_CRIB_TITLE_COLOR.G, STORE_CRIB_TITLE_COLOR.B) 
  1766. 		vint_set_property(level_desc_h, "tint", STORE_CRIB_DESC_COLOR.R, STORE_CRIB_DESC_COLOR.G, STORE_CRIB_DESC_COLOR.B) 
  1767. 	end 
  1768.  
  1769. 	-- Set weapon title/category 
  1770. 	-- Determine if we're a string or crc 
  1771. 	if type(new_title) == "string" then 
  1772. 		vint_set_property(weapon_title_h, "text_tag", new_title) 
  1773. 	else	 
  1774. 		vint_set_property(weapon_title_h, "text_tag_crc", new_title) 
  1775. 	end 
  1776. 	 
  1777. 	-- Shrink title text to fit in safe frame 
  1778. 	resize_text_element(weapon_title_h, 350)		 
  1779. 	 
  1780. 	-- Set costume name (shown in grey bar) 
  1781. 	-- Determine if we're a string or crc 
  1782. 	if type(new_costume_name) == "string" then 
  1783. 		vint_set_property(weapon_level_h, "text_tag", new_costume_name) 
  1784. 	else 
  1785. 		vint_set_property(weapon_level_h, "text_tag_crc", new_costume_name) 
  1786. 	end	 
  1787. 	 
  1788. 	vint_set_property(level_desc_h, "text_tag_crc", new_desc_crc) 
  1789. end 
  1790.  
  1791.  
  1792. function store_weapon_cover_weapon(show_slot_stats) 
  1793. 	 
  1794. 	if Store_weapon_menu_level == STORE_WEAPON_LEVEL_MAIN or show_slot_stats == true then 
  1795. 		-- this should be the situations when we don't want to show stats too 
  1796. 		Weapon_stats_grp:set_visible(false) 
  1797. 	end 
  1798. 	 
  1799. 	Slot_stats_grp:set_visible(show_slot_stats and Stats_initialized)	 
  1800. 	 
  1801. 	-- Hide zoom/rotate hint 
  1802. 	-- Hint_bar_rotate:set_visible(false)		 
  1803. end 
  1804.  
  1805.  
  1806. function store_weapon_uncover_weapon() 
  1807. 	-- make background so it is behind the weapon 
  1808. 	--Weapon_bg_grp:set_property("background", true) 
  1809. 	bg_saints_set_background(true) 
  1810. 		 
  1811. 	-- this should be the situations when we don't want to show stats too 
  1812. 	 Weapon_stats_grp:set_visible(true)	 
  1813.  
  1814. 	-- Get current grid idx 
  1815. 	--local current_idx = Store_common_color_grid:get_selection() 
  1816. 	 
  1817. 	--Get data for current weapon 
  1818. 	local current_weapon_info = Weapon_grid_data[Weapon_grid_idx] 
  1819. 	 
  1820.    --Determine where we are in the flow 
  1821. 	if Store_weapon_menu_level == STORE_WEAPON_LEVEL_COSTUME then 
  1822. 			 
  1823. 		local current_idx = Active_list:get_selection()	 
  1824. 			 
  1825. 		-- Update costume info 
  1826. 		store_weapon_populate_weapon_stats(Store_weapon_building_menu[current_idx].label_crc, nil, Store_weapon_building_menu[current_idx].costume_desc_crc) 
  1827. 		 
  1828. 	elseif Store_weapon_menu_level == STORE_WEAPON_LEVEL_UPGRADE then 
  1829. 	 
  1830. 		-- Update costume info 
  1831. 		store_weapon_populate_weapon_stats(Current_costume_name_crc, Current_skin_name_crc, Current_costume_desc_crc) 
  1832. 	 
  1833. 	else 
  1834. 		-- Show weapon category info 
  1835. 		store_weapon_populate_weapon_stats(current_weapon_info.label, current_weapon_info.costume_name_crc, current_weapon_info.level_desc)	 
  1836. 	end 
  1837. 	 
  1838. 	Slot_stats_grp:set_visible(false) 
  1839. 	 
  1840. 	-- Show zoom/rotate hint 
  1841. 	-- if game_is_active_input_gamepad() == true then 
  1842. 		-- hint_bar_rotate:set_visible(true) 
  1843. 	-- end 
  1844. 	 
  1845. 	Store_weapon_is_loading = false	 
  1846. end 
  1847.  
  1848.  
  1849. function store_weapon_grid_add_thrown_items(name_str, icon_name, price, own, equipped, id, ammo_current, ammo_max, unlimited_ammo, dual_wield, upgrade_level, desc_crc, costume_id, num_costumes, costume_name_crc, store_name_str) 
  1850. 	local grid_idx = #Weapon_grid_data + 1 
  1851. 	 
  1852. 	Weapon_grid_data[grid_idx] = { 
  1853. 		icon = icon_name, 
  1854. 		label = name_str, 
  1855. 		color = { red = 1, green = 1, blue = 1 }, 
  1856. 		is_owned = own, 
  1857. 		id = id, 
  1858. 		dual_wield = dual_wield, 
  1859. 		price = price, 
  1860. 		level = upgrade_level, 
  1861. 		level_desc = desc_crc, 
  1862. 		is_checked = own, 
  1863. 		equipped = equipped, 
  1864. 		costume_id = costume_id, 
  1865. 		num_costumes = num_costumes, 
  1866. 		costume_name_crc = costume_name_crc, 
  1867. 		store_name_crc = store_name_str, 
  1868. 	}	 
  1869. 	 
  1870. 	if equipped == true then 
  1871. 		Weapon_grid_idx = grid_idx 
  1872. 	end 
  1873.  
  1874. 	if	Store_weapon_is_cache then 
  1875. 		Weapon_grid_data[grid_idx].is_checked = false 
  1876. 	end	 
  1877. end 
  1878.  
  1879.  
  1880. function store_weapon_grid_add_items(name_str, icon_name, price, own, equipped, id, ammo_current, ammo_max, unlimited_ammo, dual_wield, upgrade_level, desc_crc, costume_id, num_costumes, costume_name_crc, skin_id, costume_desc_crc, skin_name_crc, is_streamed, store_name_str)	 
  1881. 	local grid_idx = #Weapon_grid_data + 1 
  1882. 	 
  1883. 	--Append "_c" to weapon costume icons that have to be streamed 
  1884. 	--They are pulled from ui_bms_store_weapon_costumes 
  1885. 	local temp_icon_name = icon_name	 
  1886. 	if is_streamed then 
  1887. 		temp_icon_name = icon_name.."_c" 
  1888. 		 
  1889. 		-- Some weapons are sent in by code as streamed, but their icons are always loaded 
  1890. 		-- Check that table and make sure to use their always loaded icon 
  1891. 		for i = 1, #Store_weapon_always_loaded_icons do 
  1892. 			if icon_name == Store_weapon_always_loaded_icons[i] then 
  1893. 				temp_icon_name = icon_name	 
  1894. 			end 
  1895. 		end 
  1896. 	end	 
  1897. 	 
  1898. 	Weapon_grid_data[grid_idx] = { 
  1899. 		icon = temp_icon_name, 
  1900. 		label = costume_name_crc, --name_str 
  1901. 		color = { red = 1, green = 1, blue = 1 }, 
  1902. 		is_owned = own, 
  1903. 		id = id, 
  1904. 		dual_wield = dual_wield, 
  1905. 		price = price, 
  1906. 		level = upgrade_level, 
  1907. 		level_desc = desc_crc, 
  1908. 		is_checked = own, 
  1909. 		equipped = equipped,		 
  1910. 		costume_id = costume_id, 
  1911. 		num_costumes = num_costumes, 
  1912. 		costume_name_crc = name_str, --costume_name_crc 
  1913. 		skin_id = skin_id,  -- Sean, this id needs to be added - it is currently nil 
  1914. 		costume_desc_crc = costume_desc_crc, 
  1915. 		skin_name_crc = skin_name_crc, --skin_name_crc 
  1916. 		store_name_crc = store_name_str, 
  1917. 	} 
  1918. 	 
  1919. 	if equipped == true then 
  1920. 		Weapon_grid_idx = grid_idx		 
  1921. 	end	 
  1922. 	 
  1923. 	if	Store_weapon_is_cache then 
  1924. 		Weapon_grid_data[grid_idx].is_checked = false 
  1925. 	end	 
  1926. end 
  1927.  
  1928.  
  1929. -- Callback to handle when the player is on the weapon purchase/upgrade grid and makes a selection or cancels. 
  1930. -- 
  1931. function store_weapon_grid_selected(event) 
  1932. 	-- if the weapon is still loading, don't allow grid selection 
  1933. 	if store_weapon_allow_grid_input() == false then 
  1934. 		return 
  1935. 	end 
  1936.  
  1937. 	-- Reset skip flag if the grid is used 
  1938. 	if Mouse_input_tracker ~= 0 then 
  1939. 		Skip_next_populate = false 
  1940. 	end 
  1941. 	 
  1942. 	--Did the player select a weapon? 
  1943. 	if event == "select" or event == "mouse_click" then 
  1944. 	 
  1945. 		-- Save off currently selected grid index, so we can know which one to start at when backing out of the upgrade menu. 
  1946. 		Weapon_grid_idx = Store_common_color_grid:get_selection() 
  1947.  
  1948. 		local weapon_info = Weapon_grid_data[Weapon_grid_idx]	 
  1949. 			 
  1950. 		-- If we're in the weapon cache, we're just equipping it, so no need for the other checks done below for purchasing. 
  1951. 		if Store_weapon_is_cache then 
  1952. 			 
  1953. 			game_UI_audio_play("UI_Main_Menu_Select") 
  1954. 			-- Equip weapon if in cache 
  1955. 			store_weapon_purchase_weapon(Weapon_grid_data.category, weapon_info.id, Store_weapon_is_cache, 0)				 
  1956. 			 
  1957. 			-- Go back to main menu. 
  1958. 			Store_common_color_grid:nav_enable(false, nil, nil) 
  1959. 			Store_common_color_grid:set_visible(false) 
  1960. 			Store_common_color_grid:cleanup() 
  1961. 			 
  1962. 			store_weapon_cover_weapon(true)	 
  1963. 			store_weapon_hide_weapon()	 
  1964. 			 
  1965. 			local current_image = Reward_image:get_image()	 
  1966. 			if current_image ~= nil then 
  1967. 				game_peg_unload(current_image) 
  1968. 			end	 
  1969.  
  1970. 			Reward_image:set_visible(false)	 
  1971. 			Store_weapon_loading_img = nil		 
  1972. 			 
  1973. 			-- do this so holding down the button doesn't cause repeated actions 
  1974. 			Input_tracker:subscribe(false)		 
  1975. 			Input_tracker:subscribe(true)	 
  1976. 			 
  1977. 			-- pop off header titles 
  1978. 			Store_header:pop_title() 
  1979. 			--Store_header:pop_title() 
  1980. 			Store_header:set_price(nil) 
  1981. 			 
  1982. 			--Active_list:set_visible(true) 
  1983. 			-- Open the radial menu 
  1984. 			store_weapon_inventory_show()	 
  1985. 			 
  1986. 			if Store_weapon_loaded_from_crib then 
  1987. 				store_weapon_unlock_radial() 
  1988. 			end 
  1989. 			 
  1990. 			return 
  1991. 		end 
  1992. 	 
  1993. 		-- Hide the grid 
  1994. 		Store_common_color_grid:nav_enable(false, nil, nil) 
  1995. 		Store_common_color_grid:set_visible(false) 
  1996. 		Store_common_color_grid:cleanup()	 
  1997. 		 
  1998. 		game_UI_audio_play("UI_Main_Menu_Select") 
  1999. 		 
  2000. 		Store_weapon_current_info = weapon_info 
  2001. 		 
  2002. 		--Bring up purchase popup if weapon is not owned.  Otherwise advance to upgrades. 
  2003. 		if weapon_info.is_owned == false then 
  2004. 			store_weapon_grid_purchase(weapon_info) 
  2005. 		else		 
  2006. 			-- We are now going to go to another menu (megalist) with the upgrade levels	 
  2007. 			store_weapon_upgrade_show(Weapon_grid_data.category, weapon_info.id)	 
  2008. 		end		 
  2009. 	else 
  2010. 			 
  2011. 		Old_index = 0 
  2012.  
  2013. 		-- Go back to main menu. 
  2014. 		Store_common_color_grid:nav_enable(false, nil, nil) 
  2015. 		Store_common_color_grid:set_visible(false) 
  2016. 		Store_common_color_grid:cleanup() 
  2017. 		 
  2018. 		store_weapon_cover_weapon(true)				 
  2019. 		store_weapon_hide_weapon()		 
  2020. 		 
  2021. 		local current_image = Reward_image:get_image()	 
  2022. 		if current_image ~= nil then 
  2023. 			game_peg_unload(current_image) 
  2024. 		end	 
  2025.  
  2026. 		Reward_image:set_visible(false) 
  2027. 		Store_weapon_loading_img = nil 
  2028. 		-- If we came from the crib, we need to pop this doc off the stack 
  2029. 		--[[if Store_weapon_loaded_from_crib then	 
  2030. 			store_lock_controls()			 
  2031. 			pop_screen() 
  2032. 			return 
  2033. 		end	]]		 
  2034. 		 
  2035. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  2036. 		 
  2037. 		-- pop off header titles 
  2038. 		Store_header:pop_title() 
  2039. 		 
  2040. 		--Store_header:pop_title()	 
  2041. 		Store_header:set_price(nil)		 
  2042. 		 
  2043. 		--Did we back out/cancel from the weapon cache?  If so, make sure we go back to the weapon cache radial 
  2044. 		if Store_weapon_is_cache then 
  2045. 			store_weapon_cache_open_radial() 
  2046. 		else		 
  2047. 			-- Else open store radial 
  2048. 			store_weapon_purchase_open_radial() 
  2049. 		end 
  2050. 		 
  2051. 		if Store_weapon_loaded_from_crib then 
  2052. 			store_weapon_unlock_radial() 
  2053. 		end 
  2054. 		 
  2055. 		Current_tier = RADIAL_TIER 
  2056. 	end			 
  2057. end 
  2058.  
  2059. -- Handle purchase popup for purchasing weapons from the grid 
  2060. -- 
  2061. function store_weapon_grid_purchase(menu_data) 
  2062. 	if Store_common_player_cash >= menu_data.price then				 
  2063. 		Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)				 
  2064. 		Store_common_popup:set_title("MENU_TITLE_CONFIRM") 
  2065. 		local insert = { [0] = menu_data.label, [1] = format_cash(menu_data.price) } 
  2066. 		local body = vint_insert_values_in_string("WPN_STORE_PURCHASE_PROMPT", insert)				 
  2067. 		Store_common_popup:set_text(body)		 
  2068. 		Store_common_popup:nav_enable(true, "store_weapon_grid_confirm", "store_weapon_popup_nav") 
  2069. 		Not_popup_grp:set_alpha(.5)	 
  2070. 		Store_weapon_not_bg_grp:set_alpha(.5)	 
  2071. 		store_weapon_enable_mouse(false) 
  2072. 		game_UI_audio_play("UI_HUD_HELP") 
  2073. 	else 
  2074. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  2075. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  2076. 		Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")		 
  2077. 		Store_common_popup:nav_enable(true, "store_weapon_grid_refresh", "store_weapon_popup_nav") 
  2078. 		Not_popup_grp:set_alpha(.5)					 
  2079. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  2080. 		store_weapon_enable_mouse(false) 
  2081. 		game_UI_audio_play("UI_HUD_HELP") 
  2082. 	end 
  2083. end 
  2084.  
  2085.  
  2086. ------------------------------------------------------------------------------- 
  2087. -- Hide popup and bring weapon grid back 
  2088. -- 
  2089. function store_weapon_grid_refresh() 
  2090. 	 
  2091. 	--Open the grid again, but don't push another title to Store_header 
  2092. 	store_weapon_grid_open(Current_slot, Weapon_grid_idx, false) 
  2093. 	 
  2094. 	store_weapon_fail_msg() 
  2095. end 
  2096.  
  2097.  
  2098. function store_weapon_upgrade_confirm(event) 
  2099. 	store_weapon_enable_mouse(true) 
  2100.  
  2101. 	Store_common_popup:nav_enable(false, nil, nil) 
  2102. 	Not_popup_grp:set_alpha(1)	 
  2103. 	Store_weapon_not_bg_grp:set_alpha(1) 
  2104. 	 
  2105. 	local upgrade_idx = Active_list:get_selection() 
  2106. 	 
  2107. 	-- The user hit the B button and are cancelling the purchase 
  2108. 	-- This is the same as selecting "No" in the list 
  2109. 	if event == "back" or Store_common_popup:get_selected_data() ~= 1 then 
  2110. 		 
  2111. 		--Return to upgrades menu 
  2112. 		store_weapon_upgrade_refresh(upgrade_idx) 
  2113. 		 
  2114. 		--Pop current selection title that store_common pushes after we draw a new menu 
  2115. 		Store_header:pop_title() 
  2116. 		 
  2117. 		return 
  2118. 	end 
  2119. 	 
  2120. 	game_UI_audio_play("UI_Main_Menu_Select") 
  2121. 	 
  2122. 	--Call C to make the purchase 
  2123. 	store_weapon_purchase_weapon_upgrade(Weapon_grid_data.category, Weapon_grid_data[Weapon_grid_idx].id, Store_weapon_building_menu[upgrade_idx].attribute_id) 
  2124. 	 
  2125. 	--Call purchase weapon to equip the weapon since an upgrade was purchased for it 
  2126. 	store_weapon_purchase_weapon(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_is_cache, 0) 
  2127. 	 
  2128. 	game_hud_update_inventory() 
  2129. 		 
  2130. 	-- Update GSI if in mission 
  2131. 	if Store_weapon_in_mission and Upgrade_gsi_is_updated == true then 
  2132. 		Store_common_gsi:update("MM_1_1_OBJ_EXIT_STORE", "ui_target_icon_use")				 
  2133. 		 
  2134. 		--don't call this again once it's updated 
  2135. 		Upgrade_gsi_is_updated = true 
  2136. 	end		 
  2137. 	 
  2138. 	store_weapon_upgrade_refresh(upgrade_idx) 
  2139. 	 
  2140. 	--Pop current selection title that store_common pushes after we draw a new menu 
  2141. 	Store_header:pop_title() 
  2142. 	 
  2143. 	ui_audio_post_event("weapon_purchase") 
  2144. end 
  2145.  
  2146.  
  2147. ------------------------------------------------------------------------------- 
  2148. -- Update the megalist after a purchase is made 
  2149. -- 
  2150. function store_weapon_upgrade_refresh(idx)	 
  2151.  
  2152. 	Store_weapon_menu_level = STORE_WEAPON_LEVEL_UPGRADE 
  2153.  
  2154. 	Active_list:set_visible(true) 
  2155. 	Store_header:set_price(nil) 
  2156. 		 
  2157. 	-- Get data to populate the megalist 
  2158. 	Store_weapon_building_menu = {} 
  2159. 	 
  2160. 	local current_weapon = Weapon_grid_data[Weapon_grid_idx] 
  2161. 	 
  2162. 	--Do we have costumes? 
  2163. 	if current_weapon.num_costumes == 1 then 
  2164. 		Store_weapon_building_menu = { 
  2165. 			[1] = { 
  2166. 				type = TYPE_HEADER, 
  2167. 				label = "MENU_UPGRADES", 
  2168. 			} 
  2169. 		}	 
  2170. 	elseif current_weapon.num_costumes > 1 then 		 
  2171. 		--Make the first selection the style option	 
  2172. 		Store_weapon_building_menu = { 
  2173. 			[1] = { 
  2174. 				type = TYPE_HEADER, 
  2175. 				label = "MENU_STYLE", 
  2176. 			}, 
  2177. 			[2] = { 
  2178. 				type = TYPE_BUTTON, 
  2179. 				id = STORE_WEAPON_CUSTOMIZE_OPTION, 
  2180. 				label = "STORE_WEAPON_CUSTOMIZE", --current_weapon.costume_name_crc, 
  2181. 				costume_desc_crc = current_weapon.costume_desc_crc, 
  2182. 				price = 0, 
  2183. 				on_nav = store_weapon_upgrade_nav, 
  2184. 				on_select = store_weapon_upgrade_purchase, 
  2185. 				on_cancel = store_weapon_upgrade_back, 
  2186. 			}, 
  2187. 			[3] = { 
  2188. 				type = TYPE_HEADER, 
  2189. 				label = "MENU_UPGRADES", 
  2190. 			} 
  2191. 		} 
  2192. 	end	 
  2193. 		 
  2194. 	vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, Weapon_grid_data.category, current_weapon.id)	 
  2195. 	 
  2196. 	--Make sure idx is valid (if we came from a callback it could be a table) 
  2197. 	if type(idx) == "table" or idx == nil then 
  2198. 		idx = 2 
  2199. 	end 
  2200. 	 
  2201. 	Store_weapon_building_menu.start_index = idx 
  2202. 	 
  2203. 	Menu_data = Store_weapon_building_menu 
  2204. 	 
  2205. 	Active_list:set_selection(idx) 
  2206. 	 
  2207. 	store_common_push_menu(Store_weapon_building_menu) 
  2208. 	--store_weapon_populate_list(Store_weapon_building_menu, Store_weapon_building_menu.start_index, false) 
  2209.  
  2210. 	local current_selection = Active_list:get_selection() 
  2211. 	 
  2212. 	--Are we on costume or upgrade? 
  2213. 	if current_weapon.num_costumes > 1 and current_selection == 2 then 
  2214. 		 
  2215. 		--Update the name and description 
  2216. 		store_weapon_populate_weapon_stats(Current_costume_name_crc, Current_skin_name_crc, Current_costume_desc_crc) 
  2217. 				 
  2218. 		--Change the weapon model 
  2219. 		store_weapon_change_weapon_preview(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_current_info.dual_wield, Store_weapon_is_cache, -1, Weapon_grid_data[Weapon_grid_idx].costume_id, Weapon_grid_data[Weapon_grid_idx].skin_id, Weapon_grid_data[Weapon_grid_idx].store_name_crc) 
  2220. 	else 
  2221. 		--Upate upgrade info 
  2222. 		store_weapon_upgrade_nav(Store_weapon_building_menu[current_selection]) 
  2223. 	end 
  2224. 	 
  2225. 	Weapon_stats_grp:set_visible(true)	 
  2226. end 
  2227.  
  2228.  
  2229. ------------------------------------------------------------------------------- 
  2230. -- Function store_weapon_menu_data_refresh() 
  2231. -- 
  2232. -- Menu_data may have been overwritten.  This function is called 
  2233. -- when we return to the main menu to reset the menu back to store weapon's 
  2234. -- initial choices 
  2235. -- 
  2236. ------------------------------------------------------------------------------- 
  2237. function store_weapon_menu_data_reset() 
  2238.  
  2239. 	--Remove any pushed menus 
  2240. 	store_common_stack_clear_menu() 
  2241. 	 
  2242. 	--Populate store common list with store weapon main menu data 
  2243. 	Menu_data = { 
  2244. 		on_cancel = store_weapon_cancel_radial, 
  2245. 		[1] = { label = "STORE_WEAPON_WIPE_NOTORIETY", type = TYPE_BUTTON, on_select = store_weapon_wipe_notoriety, on_nav = store_weapon_main_menu_nav }, 
  2246. 		[2] = { label = "STORE_WEAPON_AMMO", type = TYPE_BUTTON, on_select = store_weapon_ammo_open_radial, on_nav = store_weapon_main_menu_nav }, 
  2247. 		[3] = { label = "STORE_WEAPON_BUY_UPGRADE", type = TYPE_BUTTON, on_select = store_weapon_purchase_open_radial, on_nav = store_weapon_main_menu_nav }, 
  2248. 	} 
  2249. 	 
  2250. 	--if store_weapon_is_tutorial_mode() == false then 
  2251. 		Menu_data[#Menu_data + 1] = { label = "STORE_WEAPON_CACHE", type = TYPE_BUTTON,  on_select = store_weapon_cache_open_radial } 
  2252. 	--end 
  2253. 			 
  2254. 	Menu_data[#Menu_data + 1] = { label = "STORE_EXIT", type = TYPE_BUTTON,  on_select = store_weapon_exit } 
  2255.  
  2256. 	--Draw the new list 
  2257. 	store_weapon_populate_list(Menu_data, Store_weapon_menu_category)	 
  2258. end 
  2259.  
  2260.  
  2261. ------------------------------------------------------------------------------- 
  2262. -- Function store_weapon_upgrade_show 
  2263. -- 
  2264. -- Draw the costume (optional) and upgrade list for the first time 
  2265. -- 
  2266. -- @param cateogry			-Weapon category ex: melee, pistol, etc. 
  2267. -- @param id					-Weapon id 
  2268. -- @param start_index		-Starting index for the list 
  2269. -- 
  2270. ------------------------------------------------------------------------------- 
  2271. function store_weapon_upgrade_show(category, id, start_index) 
  2272. 	 
  2273. 	Store_weapon_menu_level = STORE_WEAPON_LEVEL_UPGRADE 
  2274. 	 
  2275. 	--Hide list and price until we're done updating 
  2276. 	Active_list:set_visible(true) 
  2277. 	Store_header:set_price(nil) 
  2278. 				 
  2279. 	--Get data to populate the megalist 
  2280. 	Store_weapon_building_menu = {}	 
  2281. 	 
  2282. 	--Save reference to current weapon 
  2283. 	local current_weapon = Weapon_grid_data[Weapon_grid_idx] 
  2284. 	 
  2285. 	--Do we have costumes? 
  2286. 	if current_weapon.num_costumes == 1 then 
  2287. 	 
  2288. 		--No costumes, go straight to upgrades 
  2289. 		Store_weapon_building_menu = { 
  2290. 			[1] = { 
  2291. 				type = TYPE_HEADER, 
  2292. 				label = "MENU_UPGRADES", 
  2293. 			} 
  2294. 		}		 
  2295. 	elseif current_weapon.num_costumes > 1 then 		 
  2296. 	 
  2297. 		--Costumes, Default the first selection to the costume option 
  2298. 		Store_weapon_building_menu = { 
  2299. 			[1] = { 
  2300. 				type = TYPE_HEADER, 
  2301. 				label = "MENU_STYLE", 
  2302. 			}, 
  2303. 			[2] = { 
  2304. 				type = TYPE_BUTTON, 
  2305. 				id = STORE_WEAPON_CUSTOMIZE_OPTION, 
  2306. 				label = "STORE_WEAPON_CUSTOMIZE", --current_weapon.costume_name_crc, 
  2307. 				costume_desc_crc = current_weapon.costume_desc_crc, 
  2308. 				price = 0, 
  2309. 				on_nav = store_weapon_upgrade_nav, 
  2310. 				on_select = store_weapon_upgrade_purchase, 
  2311. 				on_cancel = store_weapon_upgrade_back, 
  2312. 			}, 
  2313. 			[3] = { 
  2314. 				type = TYPE_HEADER, 
  2315. 				label = "MENU_UPGRADES", 
  2316. 			} 
  2317. 		}		 
  2318. 	end 
  2319. 	 
  2320. 	--Get upgrade data from code 
  2321. 	vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, category, id)	 
  2322. 	 
  2323. 	--Set intial start index for the list 
  2324. 	Store_weapon_building_menu.start_index = start_index or 2	 
  2325. 	 
  2326. 	--store_weapon_populate_list(Store_weapon_building_menu, Store_weapon_building_menu.start_index) 
  2327. 	store_common_push_menu(Store_weapon_building_menu) 
  2328. 	 
  2329. 	-- Add mouse input subscriptions 
  2330. 	if Mouse_input_tracker ~= 0 then 
  2331. 		Mouse_input_tracker:remove_all() 
  2332. 		Active_list:set_store("store_weapon") 
  2333. 		Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  2334. 		store_weapon_enable_mouse(true) 
  2335. 	end	 
  2336. 			 
  2337. 	--Determine which description to display based on if costumes are present 
  2338. 	local current_selection = Active_list:get_selection() 
  2339. 	 
  2340. 	if current_weapon.num_costumes > 1 and current_selection == 2 then 
  2341. 	 
  2342. 		--Update name and description		 
  2343. 		store_weapon_populate_weapon_stats(Current_costume_name_crc, Current_skin_name_crc, Current_costume_desc_crc)	 
  2344. 	else 
  2345. 	 
  2346. 		--We're on an upgrade - show upgrade desc 
  2347. 		local desc_crc = Store_weapon_building_menu[current_selection].upgrade_desc_crc 
  2348. 		local label_crc = Store_weapon_building_menu[current_selection].label_crc 
  2349. 		 
  2350. 		store_weapon_populate_weapon_stats( label_crc, nil, desc_crc ) 
  2351. 		 
  2352. 		Store_header:set_price(Store_weapon_building_menu[current_selection].price) 
  2353. 	end			 
  2354. 		 
  2355. 	Current_tier = LEVEL_TIER 
  2356. 	 
  2357. 	--Override the titles coming from store_common 
  2358. 	Store_header:pop_title() 
  2359. 	Store_header:push_title(nil, "MENU_UPGRADES") 
  2360. 	 
  2361. 	 Weapon_stats_grp:set_visible(true)	 
  2362. end 
  2363.  
  2364.  
  2365. --Get data for upgrade list 
  2366. function store_weapon_upgrade_add_items(upgrade_desc_crc, level_desc_crc, level_price, current_level, max_level, attribute_id, is_ultimate) 
  2367. 	local menu_idx = #Store_weapon_building_menu + 1 
  2368. 	 
  2369. 	local new_item = { 
  2370. 		type = TYPE_PIP, 
  2371. 		id = #Store_weapon_building_menu, 
  2372. 		upgrade_desc_crc = level_desc_crc,  
  2373. 		label_crc = upgrade_desc_crc, 
  2374. 		max_level = max_level, 
  2375. 		level = current_level, 
  2376. 		price = level_price, 
  2377. 		attribute_id = attribute_id, 
  2378. 		on_nav = store_weapon_upgrade_nav, 
  2379. 		on_select = store_weapon_upgrade_purchase, 
  2380. 		on_cancel = store_weapon_upgrade_back, 
  2381. 	}		 
  2382.  
  2383. 	Store_weapon_building_menu[menu_idx] = new_item 
  2384. 	 
  2385. 	-- if level_is_locked == false then 
  2386. 		-- Store_weapon_building_menu.start_index = menu_idx 
  2387. 		 
  2388. 		-- -- Show the weapon/upgrade price 
  2389. 		-- if level_price == 0 then 
  2390. 			-- Store_header:set_price(nil) 
  2391. 		-- else 
  2392. 			-- Store_header:set_price(level_price) 
  2393. 		-- end 
  2394. 		-- Store_header:set_respect(nil)			 
  2395. 	-- end 
  2396. end 
  2397.  
  2398.  
  2399. ------------------------------------------------------------------------------- 
  2400. -- Function store_weapon_upgrade_nav() 
  2401. -- 
  2402. -- @param menu_data		--data for currently selected item 
  2403. -- 
  2404. -- Updates price and description for highlighted weapon 
  2405. -- 
  2406. ------------------------------------------------------------------------------- 
  2407. function store_weapon_upgrade_nav(menu_data) 
  2408.  
  2409. 	-- Show the weapon/upgrade price 
  2410. 	if menu_data.price <= 0 then 
  2411. 		Store_header:set_price(nil) 
  2412. 	else 
  2413. 		Store_header:set_price(menu_data.price) 
  2414. 	end 
  2415. 	 
  2416. 	-- Don't show respect 
  2417. 	Store_header:set_respect(nil)		 
  2418. 	 
  2419. 	local current_weapon = Weapon_grid_data[Weapon_grid_idx] 
  2420. 	local current_selection = Active_list:get_selection() 
  2421. 	 
  2422. 	if current_weapon.num_costumes > 1 and current_selection == 2 then 
  2423. 		store_weapon_populate_weapon_stats(menu_data.label_crc, Current_skin_name_crc, menu_data.upgrade_desc_crc)	 
  2424. 	else 
  2425. 		store_weapon_populate_weapon_stats(menu_data.label_crc, nil, menu_data.upgrade_desc_crc)	 
  2426. 	end 
  2427. end 
  2428.  
  2429.  
  2430. function store_weapon_upgrade_purchase(weapon_data) 
  2431. 	 
  2432. 	-- Now check if the player can purchase this weapon. 
  2433. 	if weapon_data.is_purchased or weapon_data.is_locked then 
  2434. 		return 
  2435. 	end 
  2436. 	 
  2437. 	--If we hit the customize option bring up list of costumes 
  2438. 	if weapon_data.id == STORE_WEAPON_CUSTOMIZE_OPTION and Weapon_grid_data[Weapon_grid_idx].num_costumes > 1 then		 
  2439. 		store_weapon_upgrade_populate_costumes() 
  2440.  
  2441. 		--Cover the weapon and stats until they're streamed in 
  2442. 		store_weapon_cover_weapon(false) 
  2443. 		return 
  2444. 	end	 
  2445.  
  2446. 	local upgrade_idx = Active_list:get_selection() 
  2447. 		 
  2448. 	if Store_common_player_cash >= weapon_data.price then				 
  2449. 		if Store_weapon_building_menu[upgrade_idx].level == weapon_data.max_level then 
  2450. 			--Upgrade is at max level, show popup and return to upgrade list 
  2451. 			Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  2452. 			Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  2453. 			Store_common_popup:set_text("STORE_WEAPON_UPGRADE_MAX_LEVEL")		 
  2454. 			Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  2455. 			Not_popup_grp:set_alpha(.5)					 
  2456. 			Store_weapon_not_bg_grp:set_alpha(.5) 
  2457. 			store_weapon_enable_mouse(false) 
  2458. 			game_UI_audio_play("UI_HUD_HELP")	 
  2459. 		else 
  2460. 			--Valid purchase 
  2461. 			Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)				 
  2462. 			Store_common_popup:set_title("MENU_TITLE_CONFIRM") 
  2463. 			local insert = { [0] = weapon_data.label_crc, [1] = format_cash(weapon_data.price) } 
  2464. 			local body = vint_insert_values_in_string("WPN_STORE_UPGRADE_PROMPT", insert)				 
  2465. 			Store_common_popup:set_text(body)		 
  2466. 			Store_common_popup:nav_enable(true, "store_weapon_upgrade_confirm", "store_weapon_popup_nav") 
  2467. 			Not_popup_grp:set_alpha(.5)	 
  2468. 			Store_weapon_not_bg_grp:set_alpha(.5)	 
  2469. 			store_weapon_enable_mouse(false) 
  2470. 			game_UI_audio_play("UI_HUD_HELP") 
  2471. 		end 
  2472. 	else 
  2473. 		--Not enough funds 
  2474. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  2475. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  2476. 		Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")		 
  2477. 		Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  2478. 		Not_popup_grp:set_alpha(.5)					 
  2479. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  2480. 		store_weapon_enable_mouse(false) 
  2481. 		game_UI_audio_play("UI_HUD_HELP") 
  2482. 	end 
  2483. end 
  2484.  
  2485.  
  2486. ------------------------------------------------------------------------------- 
  2487. -- Backing out from upgrade menu 
  2488. -- 
  2489. function store_weapon_upgrade_back(menu_data) 
  2490.  
  2491. 	if store_weapon_allow_grid_input() == false then 
  2492. 		return 
  2493. 	end 
  2494.  
  2495. 	-- for thrown weapons, go back to the radial 
  2496. 	if Weapon_grid_data.category == "thrown" then 
  2497. 		store_weapon_grid_selected("back")	 
  2498. 		Current_tier = RADIAL_TIER 
  2499. 		Restore_weapon_radial_inputs = true 
  2500. 	else 
  2501. 		-- save off currently highlighted weapon - otherwise it will get overwritten to the currently equipped weapon 
  2502. 		local current_idx = Weapon_grid_idx 
  2503. 	 
  2504. 		store_weapon_populate_weapon_grid(Weapon_grid_data.category, Current_slot) 
  2505. 				 
  2506. 		-- Save of where we are in the flow 
  2507. 		Store_weapon_menu_level = STORE_WEAPON_LEVEL_GRID 
  2508. 		 
  2509. 		--input_data, current_option, max_width, max_height, button_w, button_h, hint_button_offset, current_category, outline_scale, background_enabled, show_current_button, grid_padding, set_size 
  2510. 		Store_common_color_grid:draw_items(Weapon_grid_data, current_idx, 3, 3, 120, 100, 40, nil, nil, false) 
  2511. 		Store_common_color_grid:set_visible(true) 
  2512. 		Weapon_grid_idx = current_idx		 
  2513. 		 
  2514. 		Store_common_color_grid:nav_enable(true, "store_weapon_grid_selected", "store_weapon_grid_nav")	 
  2515. 		store_weapon_change_weapon_preview(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_current_info.dual_wield, Store_weapon_is_cache, Weapon_grid_data[Weapon_grid_idx].level, Store_weapon_current_info.costume_id, Store_weapon_current_info.skin_id, Store_weapon_current_info.store_name_crc)		 
  2516. 		 
  2517. 		store_weapon_populate_weapon_stats(nil, Current_costume_name_crc, Weapon_grid_data[Weapon_grid_idx].level_desc) 
  2518. 		 
  2519. 		store_weapon_price_update() 
  2520. 		 
  2521. 		Current_tier = WEAPON_TIER		 
  2522. 		Restore_weapon_radial_inputs = false		 
  2523. 		 
  2524. 		--Cover the weapon and stats until they're streamed in 
  2525. 		store_weapon_cover_weapon(false) 
  2526. 	end 
  2527. 	 
  2528. 	-- Skip adding mouse_inputs in the next populate_list (see store_weapon_populate_list) 
  2529. 	if Mouse_input_tracker ~= 0 then 
  2530. 		Mouse_input_tracker:remove_all() 
  2531. 		Skip_next_populate = true 
  2532. 	end 
  2533. 	 
  2534. 	Active_list:set_visible(false) 
  2535. 	 
  2536. 	-- refresh the stats info 
  2537. 	store_weapon_stats_update(-1, true, true)	 
  2538. 	store_lock_controls() 
  2539. 	store_unlock_controls() 
  2540. end 
  2541.  
  2542.  
  2543. ------------------------------------------------------------------------------- 
  2544. -- Populate list with weapon costumes 
  2545. -- 
  2546. function store_weapon_upgrade_populate_costumes()	 
  2547. 	Store_weapon_menu_level = STORE_WEAPON_LEVEL_COSTUME 
  2548. 	 
  2549. 	Store_weapon_building_menu = { } 
  2550. 	vint_dataresponder_request("store_weapon_populate_costumes", "store_weapon_costume_add_items", 0, Weapon_grid_data.category, Store_weapon_current_info.id) 
  2551. 	 
  2552. 	--Find our current costume for initial selection 
  2553. 	local current_weapon = Weapon_grid_data[Weapon_grid_idx] 
  2554. 	 
  2555. 	store_common_push_menu(Store_weapon_building_menu) 
  2556. 	 
  2557. 	--Override the titles coming from store_common 
  2558. 	Store_header:pop_title() 
  2559. 	Store_header:push_title(nil, "MENU_STYLE") 
  2560. 	 
  2561. 	--Update the description and title to the highlighted costume 
  2562. 	store_weapon_costume_nav() 
  2563. 	 
  2564. 	local current_selection = Active_list:get_selection() 
  2565. 	Weapon_grid_data[Weapon_grid_idx].costume_desc_crc = Store_weapon_building_menu[current_selection].costume_desc_crc 
  2566. end 
  2567.  
  2568.  
  2569. ------------------------------------------------------------------------------- 
  2570. -- Function store_weapon_costume_add_items() 
  2571. -- 
  2572. -- Builds costume/skins table 
  2573. -- 
  2574. -- @param id						-- id for costume or skin 
  2575. -- @param label_crc				-- name of costume 
  2576. -- @param costume_desc_crc		-- description for costume 
  2577. -- @param is_costume				-- determines if item is a costume or skin 
  2578. -- @param is_equipped			-- is the costume equipped? 
  2579. -- @param is_dlc 					-- is the costume part of dlc 
  2580. -- 
  2581. ------------------------------------------------------------------------------- 
  2582. function store_weapon_costume_add_items( id, label_crc, costume_desc_crc, is_costume, is_equipped, is_dlc ) 
  2583. 	 
  2584. 	local menu_idx = #Store_weapon_building_menu + 1 
  2585. 	local new_item 
  2586. 		 
  2587. 	-- Determine if we're a skin or costume 
  2588. 	-- If starting a new costume, add a header 
  2589. 	if is_costume == true then 
  2590. 		Costume_id = id 
  2591. 		Store_weapon_parsed_costume_name_crc = label_crc 
  2592. 		Store_weapon_parsed_costume_desc_crc = costume_desc_crc 
  2593. 		 
  2594. 		new_item = { 
  2595. 			type = TYPE_HEADER, 
  2596. 			is_costume = is_costume, 
  2597. 			label_crc = label_crc, 
  2598. 			costume_id = Costume_id, 
  2599. 			is_dlc = is_dlc, 
  2600. 		}				 
  2601. 	else 
  2602. 	 
  2603. 		-- Find the crc for the "default" skin 
  2604. 		-- Only need to do this once 
  2605. 		if Store_weapon_default_crc == -1 then 
  2606. 			Store_weapon_default_crc = label_crc 
  2607. 		end 
  2608. 	 
  2609. 		new_item = { 
  2610. 			type = TYPE_BUTTON, 
  2611. 			costume_id = Costume_id, 
  2612. 			skin_id = id, 
  2613. 			label_crc = label_crc, 
  2614. 			costume_desc_crc = costume_desc_crc, 
  2615. 			on_nav = store_weapon_costume_nav,		 
  2616. 			on_select = store_weapon_costume_purchase, 
  2617. 			on_cancel = store_weapon_costume_revert, 
  2618. 			default_costume_name_crc = Store_weapon_parsed_costume_name_crc, 
  2619. 			default_costume_desc_crc = Store_weapon_parsed_costume_desc_crc, 
  2620. 			is_dlc = is_dlc, 
  2621. 		}			 
  2622. 	end 
  2623. 	 
  2624. 	Store_weapon_building_menu[menu_idx] = new_item	 
  2625. 	 
  2626. 	-- Find our current costume for initial selection 
  2627. 	local current_costume_id = Weapon_grid_data[Weapon_grid_idx].costume_id 
  2628. 	local current_skin_id = Weapon_grid_data[Weapon_grid_idx].skin_id	 
  2629.  
  2630. 	if current_costume_id == Costume_id and current_skin_id == id then 
  2631. 		Store_weapon_building_menu.start_index = menu_idx 
  2632. 	end 
  2633. 		 
  2634. 	menu_idx = #Store_weapon_building_menu + 1		 
  2635. end 
  2636.  
  2637.  
  2638. ------------------------------------------------------------------------------- 
  2639. -- Function store_weapon_costume_revert() 
  2640. -- 
  2641. -- Pops store header title added by store_common, resets list back to 
  2642. -- upgrades with the costume highlighted, and reverts any costume changes. 
  2643. -- 
  2644. ------------------------------------------------------------------------------- 
  2645. function store_weapon_costume_revert() 
  2646. 	Store_header:pop_title() 
  2647. 	 
  2648. 	store_weapon_upgrade_refresh(2)	 
  2649. 	 
  2650. 	--Cover the weapon and stats until they're streamed in 
  2651. 	store_weapon_cover_weapon(false) 
  2652. end 
  2653.  
  2654.  
  2655. ------------------------------------------------------------------------------- 
  2656. -- Function store_weapon_costume_nav() 
  2657. -- 
  2658. -- Handle navigation for cosutmes. Updates the costume and description.  
  2659. -- 
  2660. ------------------------------------------------------------------------------- 
  2661. function store_weapon_costume_nav() 
  2662. 			 
  2663. 	--Get highlighted costume id 
  2664. 	local current_idx = Active_list:get_selection()	 
  2665. 	 
  2666. 	--Get highlighted costume info 
  2667. 	local current_item = Store_weapon_building_menu[current_idx]	 
  2668. 	 
  2669. 	--Change the weapon model 
  2670. 	store_weapon_change_weapon_preview(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_current_info.dual_wield, Store_weapon_is_cache, -1, current_item.costume_id, current_item.skin_id, current_item.store_name_crc)   
  2671. 			 
  2672. 	--Update description 
  2673. 	store_weapon_populate_weapon_stats(current_item.label_crc, nil, current_item.costume_desc_crc)	 
  2674. end 
  2675.  
  2676.  
  2677. ------------------------------------------------------------------------------- 
  2678. -- Set the costume of the current weapon 
  2679. -- 
  2680. function store_weapon_costume_purchase(event) 
  2681. 	 
  2682. 	local current_idx = Active_list:get_selection()	 
  2683. 	local current_item = Store_weapon_building_menu[current_idx] 
  2684. 	 
  2685. 	--Update costume id 
  2686. 	Store_weapon_current_info.costume_id = current_item.costume_id 
  2687. 	 
  2688. 	--Tell code the new costume 
  2689. 	store_weapon_set_costume(Weapon_grid_data.category, Store_weapon_current_info.id, current_item.costume_id) 
  2690. 	 
  2691. 	--Select costume 
  2692. 	store_weapon_purchase_weapon(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_is_cache, 0) 
  2693.  
  2694. 	--Update current costume name and description 
  2695. 	Current_costume_name_crc = current_item.default_costume_name_crc 
  2696. 	Current_costume_desc_crc = current_item.default_costume_desc_crc 
  2697. 	 
  2698. 	--Update the current skin name.  Set it to blank if it's default 
  2699. 	if current_item.label_crc ~= Store_weapon_default_crc then 
  2700. 		Current_skin_name_crc = current_item.label_crc 
  2701. 	else 
  2702. 		Current_skin_name_crc = nil 
  2703. 	end 
  2704.  
  2705. 	--Update costume name for this category 
  2706. 	Weapon_grid_data[Weapon_grid_idx].costume_name_crc = Current_costume_name_crc 
  2707. 	 
  2708. 	--Save off skin id 
  2709. 	Weapon_grid_data[Weapon_grid_idx].skin_id = current_item.skin_id 
  2710. 	 
  2711. 	--Pop "STYLE" title 
  2712. 	Store_header:pop_title() 
  2713. 	 
  2714. 	--Refresh upgrades/style menu 
  2715. 	store_weapon_upgrade_refresh() 
  2716. 	 
  2717. 	--Cover the weapon and stats until they're streamed in 
  2718. 	store_weapon_cover_weapon(false) 
  2719. 	 
  2720. 	--Pop current selection title that store common pushes after we draw a new menu 
  2721. 	Store_header:pop_title() 
  2722. end 
  2723.  
  2724.  
  2725. ------------------------------------------------------------------------------- 
  2726. -- Backing out from costumes and skins 
  2727. -- 
  2728. function store_weapon_upgrade_customize_revert() 
  2729. 	--store_weapon_upgrade_show(Weapon_grid_data.category, Store_weapon_current_info.id)	 
  2730. end 
  2731.  
  2732.  
  2733. -- Confirm purchase of a weapon/upgrade 
  2734. -- 
  2735. function store_weapon_grid_confirm(event) 
  2736. 	store_weapon_enable_mouse(true) 
  2737.  
  2738. 	Store_common_popup:nav_enable(false, nil, nil) 
  2739. 	Not_popup_grp:set_alpha(1)	 
  2740. 	Store_weapon_not_bg_grp:set_alpha(1) 
  2741. 	 
  2742. 	-- The user hit the B button and are cancelling the purchase 
  2743. 	-- This is redundant to selecting "No" in the list 
  2744. 	if event == "back" or Store_common_popup:get_selected_data() ~= 1 then 
  2745. 		store_weapon_grid_refresh() 
  2746. 		return 
  2747. 	end 
  2748. 	 
  2749. 	game_UI_audio_play("UI_Main_Menu_Select") 
  2750. 	 
  2751. 	--Purchase weapon 
  2752. 	store_weapon_purchase_weapon(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_is_cache, Store_weapon_current_info.price) 
  2753. 	 
  2754. 	--Update game inventory 
  2755. 	game_hud_update_inventory() 
  2756. 	 
  2757. 	-- Update GSI if in mission 
  2758. 	if Store_weapon_in_mission and Weapon_gsi_is_updated == false then 
  2759. 		--Store_common_gsi:update("MM_1_1_OBJ_PURCHASE_AN_UPGRADE", "ui_target_icon_use")				 
  2760. 		 
  2761. 		--don't call this again once it's updated 
  2762. 		Weapon_gsi_is_updated = true 
  2763. 	end 
  2764. 	 
  2765. 	--Play weapon purchase audio 
  2766. 	ui_audio_post_event("weapon_purchase") 
  2767. 	 
  2768. 	--Continue to upgrade/costume flow 
  2769. 	store_weapon_upgrade_show(Weapon_grid_data.category, Store_weapon_current_info.id) 
  2770.  
  2771. 	-- Update GSI if in mission 
  2772. 	if Store_weapon_in_mission  then 
  2773. 		Store_common_gsi:update("MM_1_1_OBJ_EXIT_STORE", "ui_target_icon_use")				 
  2774. 		 
  2775. 		--don't call this again once it's updated 
  2776. 		Upgrade_gsi_is_updated = true 
  2777. 	end	 
  2778. 	 
  2779. 	--[[ 
  2780. 	-- Need to refresh the mega list 
  2781. 	Store_weapon_building_menu = {} 
  2782. 	vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, Weapon_grid_data.category, Store_weapon_current_info.id) 
  2783. 	 
  2784. 	-- This is necessary to "reload" the ammo purchases for thrown weapons 
  2785. 	vint_dataresponder_request("store_weapon_populate_ammo", "store_common_do_nothing", 0) 
  2786. 	 
  2787. 	ui_audio_post_event("weapon_purchase") 
  2788. 	 
  2789. 	-- do this so holding down the button doesn't cause repeated actions 
  2790. 	Input_tracker:subscribe(false)		 
  2791. 	Input_tracker:subscribe(true)	 
  2792. 	]]-- 
  2793. end 
  2794.  
  2795.  
  2796. -- Weapon cache  ****************************************************************************************** 
  2797.  
  2798. -- Open the weapon cache radial menu 
  2799. -- 
  2800. function store_weapon_cache_open_radial(menu_data) 
  2801. 	Store_weapon_menu_category = STORE_WEAPON_CATEGORY_WEAPON_CACHE 
  2802. 	Active_list:set_visible(false) 
  2803.  
  2804. 	Store_weapon_is_cache = true	 
  2805. 	 
  2806. 	debug_print("store_weapon", "called store_weapon_cache_open_radial\n")		 
  2807. 	 
  2808. 	-- Set the callback to use when the user selects a cateogory from the radial menu 
  2809. 	Store_weapon_inventory.selected_cb = store_weapon_grid_open 
  2810. 	Store_weapon_inventory.nav_cb = store_weapon_cache_nav	 
  2811. 	 
  2812. 	-- Disable the unarmed slot 
  2813. 	Store_weapon_radial:slot_disable(0)	 
  2814. 	 
  2815. 	-- Hide grenades for weapon cache 
  2816. 	Store_weapon_radial:show_dpad_menu(false) 
  2817. 	 
  2818. 	Store_weapon_radial:set_anchor(Radial_store_x,Radial_y) 
  2819. 	 
  2820. 	-- Enable or disable slots based on availability 
  2821. 	for i = 1, 7 do 
  2822. 		-- Initialize data for grid 
  2823. 		Weapon_grid_data = {} 
  2824. 		 
  2825. 		local category = Store_weapon_categories[i].category 
  2826. 		 
  2827. 		vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  2828. 		 
  2829. 		-- If there are no choices, then disable 
  2830. 		if #Weapon_grid_data == 0 then 
  2831. 			Store_weapon_radial:slot_disable(i) 
  2832. 		else		 
  2833. 			Store_weapon_radial:slot_enable(i) 
  2834. 		end 
  2835. 	end		 
  2836.  
  2837. 	-- Open the radial menu 
  2838. 	store_weapon_inventory_show(menu_data) 
  2839. 	 
  2840. 	-- Set the hint based on the platform 
  2841. 	local hint_data = {} 
  2842. 	if game_get_platform() == "PC" then 
  2843. 		hint_data = { 
  2844. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  2845. 		} 
  2846. 	else  
  2847. 		hint_data = { 
  2848. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  2849. 			{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  2850. 			--{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"}, 
  2851. 		} 
  2852. 	end 
  2853. 	Store_common_hint_bar:set_hints(hint_data)  
  2854. 	if Hint_bar_mouse_input_tracker ~= nil then 
  2855. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  2856. 	end 
  2857. end 
  2858.  
  2859.  
  2860. function store_weapon_cache_nav(slot_id) 
  2861. 	store_weapon_stats_update(slot_id, false, true) 
  2862. 	store_weapon_cover_weapon(true) 
  2863. end 
  2864.  
  2865.  
  2866. --Updates the Weapon Radial Menu VDO 
  2867. function store_weapon_radial_update(di_h) 
  2868. 	Store_weapon_radial:slots_update(di_h) 
  2869. 	 
  2870. 	-- May be needed to update ammo totals 
  2871. 	--Store_weapon_radial:weapon_highlight(-1, true, true) 
  2872. end 
  2873.  
  2874.  
  2875. -- Stuff copied from HUD script for weapon radial ******************************************************** 
  2876. --Input handling for the radial 
  2877. function store_weapon_inventory_input(event, value) 
  2878. 	if event == "inventory" then 
  2879. 		-- nothing 
  2880. 	elseif event == "select" then 
  2881. 		-- A/accept button pushed, do callback for appropriate category 
  2882. 		local slot = Store_weapon_radial:get_selected_slot() 
  2883. 		Store_weapon_inventory.selected_cb(slot) 
  2884. 		game_UI_audio_play("UI_Main_Menu_Select") 
  2885. 		 
  2886. 	elseif event == "back" then 
  2887. 		-- B/cancel button pushed, close radial menu		 
  2888.  
  2889. 		-- If we came from the crib, we need to pop this doc off the stack 
  2890. 		if Store_weapon_loaded_from_crib then 
  2891. 			store_weapon_exit() 
  2892. 		else 
  2893. 			store_weapon_cancel_radial() 
  2894. 		end 
  2895. 		if Radial_mouse_input_tracker ~= nil then 
  2896. 			Radial_mouse_input_tracker:subscribe(false) 
  2897. 		end 
  2898. 		 
  2899. 	elseif event == "inventory_x" then 
  2900. 		--Move Analog Stick X 
  2901. 		if Store_weapon_inventory.x ~= value then 
  2902. 			Store_weapon_inventory.x = value 
  2903. 			Store_weapon_inventory.stale = true 
  2904. 		end 
  2905. 		 
  2906. 	elseif event == "inventory_y" then 
  2907. 		--Move Analog Stick Y 
  2908. 		if Store_weapon_inventory.y ~= value then 
  2909. 			Store_weapon_inventory.y = value 
  2910. 			Store_weapon_inventory.stale = true	 
  2911. 		end 
  2912. 	elseif( event == "pause" ) then 
  2913. 		-- Allow pause in the radial view 
  2914. 		dialog_open_pause_display() 
  2915. 	elseif Store_weapon_is_cache == false then 
  2916. 		local slot = 0 
  2917. 		if event == "inventory_up" and value > INVENTORY_DPAD_THRESHOLD then 
  2918. 			slot = 8 
  2919. 		elseif event == "inventory_right" and value > INVENTORY_DPAD_THRESHOLD then 
  2920. 			slot = 9 
  2921. 		elseif event == "inventory_down" and value > INVENTORY_DPAD_THRESHOLD then 
  2922. 			slot = 10 
  2923. 		elseif event == "inventory_left" and value > INVENTORY_DPAD_THRESHOLD then	 
  2924. 			slot = 11 
  2925. 		end 
  2926. 		 
  2927. 		-- Only highlight the slot if it isn't disabled 
  2928. 		if slot ~= 0 and Store_weapon_radial:slot_is_disabled(slot) ~= true then 
  2929. 			Store_weapon_radial:weapon_highlight(slot) 
  2930. 			 
  2931. 			-- Initialize data for grid 
  2932. 			Weapon_grid_data = {} 
  2933. 			Weapon_grid_idx = 1 
  2934. 			 
  2935. 			-- Get the category name string for the chosen slot. 
  2936. 			local category = Store_weapon_categories[slot].category 
  2937. 			 
  2938. 			vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category, slot - 8) 
  2939. 			 
  2940. 			-- If there are no choices, don't show weapon stats 
  2941. 			if #Weapon_grid_data ~= 0 then 
  2942. 				store_weapon_populate_weapon_stats()		 
  2943. 			end					 
  2944. 			 
  2945. 			-- Call navigation callback 
  2946. 			if Store_weapon_inventory.nav_cb ~= nil then 
  2947. 				Store_weapon_inventory.nav_cb(slot) 
  2948. 			end 
  2949. 		end 
  2950. 	end 
  2951. end 
  2952.  
  2953.  
  2954. -- Input handling for slots  
  2955. function store_weapon_inventory_show(menu_data) 
  2956. 	--game_store_weapon_update_inventory() 
  2957. 		 
  2958. 	Current_tier = RADIAL_TIER 
  2959. 	 
  2960. 	-- Disable menu input. 
  2961. 	store_lock_controls() 
  2962. 	 
  2963. 	-- Set the titles on top; if menu_data is nil, that is because we are only returning to the radial from the weapons grid, 
  2964. 	-- and we don't need to add a title because they are already there. 
  2965. 	if menu_data ~= nil then 
  2966. 		local title = nil 
  2967. 		local title_crc = nil 
  2968. 		title_crc = menu_data.label_crc 
  2969. 		if title_crc == nil then 
  2970. 			title = menu_data.label 
  2971. 		end 
  2972. 		Store_header:push_title( title_crc, title )	 
  2973. 	end 
  2974.  
  2975. 	if Store_weapon_inventory.thread == nil then 
  2976. 		 
  2977. 		--Show Inventory 
  2978. 		Store_weapon_radial:show(true) 
  2979. 		 
  2980. 		--Reset visual analog stick and get the proper text tag on it. 
  2981. 		Store_weapon_inventory.x = 0 
  2982. 		Store_weapon_inventory.y = 0		 
  2983. 		 
  2984. 		if Store_weapon_loaded_from_crib == false then 
  2985. 			--Subscribe to input 
  2986. 			store_weapon_unlock_radial() 
  2987. 		end 
  2988. 		 
  2989. 		--Highlight Currently equipped slots 
  2990. 		local selected_slot = Store_weapon_radial:get_selected_slot() 
  2991. 		if selected_slot < 0 or selected_slot >= 12 then 
  2992. 			selected_slot = 0 
  2993. 		end	 
  2994. 		 
  2995. 		if Store_weapon_radial:slot_is_disabled(selected_slot) then 
  2996. 			selected_slot = 0 
  2997. 		end 
  2998. 		 
  2999. 		--Disable grenades for 3.5 since we have "powers" now 
  3000. 		if selected_slot >= 8 then 
  3001. 			selected_slot = 0 
  3002. 		end 
  3003. 		 
  3004. 		--Walk through weapon radial to find first enabled slot 
  3005. 		while Store_weapon_radial:slot_is_disabled(selected_slot) and selected_slot < 11 do 
  3006. 			selected_slot = selected_slot + 1 
  3007. 		end 
  3008. 		 
  3009. 		if selected_slot >= 8 then 
  3010. 			-- hide everything and show popup 
  3011. 			Store_weapon_radial:set_visible(false) 
  3012. 			Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  3013. 			Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  3014. 			Store_common_popup:set_text("HUD_SHOP_NO_WEAPONS")		 
  3015. 			Store_common_popup:nav_enable(true, "store_weapon_no_weapons", "store_weapon_popup_nav") 
  3016. 			Not_popup_grp:set_alpha(.5)	 
  3017. 			Store_weapon_not_bg_grp:set_alpha(.5)	 
  3018. 			Store_common_popup:set_visible(true)	 
  3019. 			game_UI_audio_play("UI_HUD_HELP") 
  3020. 			 
  3021. 			Slot_stats_grp:set_visible(false) 
  3022. 			Store_weapon_cache_no_weapons = true 
  3023. 			return 
  3024. 		end 
  3025. 		 
  3026. 		Store_weapon_radial:weapon_highlight(selected_slot, true)		 
  3027. 		 
  3028. 		Store_weapon_radial:stick_update_position(0, 0) 
  3029. 		Store_weapon_radial:stick_update_tag()	 
  3030. 		Store_weapon_radial:stick_arrow_reset()	 
  3031.  
  3032. 		Store_weapon_inventory.thread = thread_new("store_weapon_inventory_process")			 
  3033. 		 
  3034. 		-- Preview the model of the selected weapon 
  3035. 		if selected_slot >= 1 then 
  3036. 			local selected_cat_index = selected_slot - 1 
  3037. 								 
  3038. 			-- Initialize data for grid 
  3039. 			Weapon_grid_data = {} 
  3040. 			Weapon_grid_idx = 1 
  3041. 			 
  3042. 			-- Get the category name string for the chosen slot. 
  3043. 			local category = Store_weapon_categories[selected_slot].category 
  3044. 			 
  3045. 			if category == "thrown" == true then 
  3046. 				vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category, selected_slot - 8) 
  3047. 			else 
  3048. 				vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  3049. 			end	 
  3050. 			 
  3051. 			-- If there are no choices, don't show weapon stats 
  3052. 			if #Weapon_grid_data ~= 0 then 
  3053. 				store_weapon_populate_weapon_stats() 
  3054. 			end			 
  3055. 			 
  3056. 			-- Call navigation callback 
  3057. 			if Store_weapon_inventory.nav_cb ~= nil then 
  3058. 				Store_weapon_inventory.nav_cb(selected_slot) 
  3059. 			end			 
  3060. 			 
  3061. 		end 
  3062. 	end 
  3063. 	 
  3064. 	-- Set the hint based on the platform 
  3065. 	local hint_data = {} 
  3066. 	if game_get_platform() == "PC" then 
  3067. 		hint_data = { 
  3068. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  3069. 		} 
  3070. 		if Radial_mouse_input_tracker ~= nil then 
  3071. 			-- Also add inputs for the weapon radial 
  3072. 			Store_weapon_radial:add_mouse_inputs("store_weapon", Radial_mouse_input_tracker, 50) 
  3073. 			Radial_mouse_input_tracker:subscribe(true) 
  3074. 		end 
  3075. 	else  
  3076. 		if Store_weapon_is_cache == true then 
  3077. 			hint_data = { 
  3078. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  3079. 				{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  3080. 			} 
  3081. 		else 
  3082. 			hint_data = { 
  3083. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  3084. 				{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  3085. 			} 
  3086. 		end 
  3087. 	end 
  3088. 	Store_common_hint_bar:set_hints(hint_data)	 
  3089. 	if Hint_bar_mouse_input_tracker ~= nil then 
  3090. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  3091. 	end 
  3092. end 
  3093.  
  3094.  
  3095. function store_weapon_inventory_hide() 
  3096. 		-- Enable menu controls 
  3097. 	store_unlock_controls() 
  3098.  
  3099. 	-- if aborted == false then 
  3100. 		-- Store_weapon_radial:game_equip_selected_slots() 
  3101. 	-- end 
  3102. 	 
  3103. 	--Hide Radial Menu 
  3104. 	Store_weapon_radial:show(false) 
  3105. 	 
  3106. 	store_weapon_lock_radial() 
  3107.  
  3108. 	if Store_weapon_inventory.thread ~= nil then	 
  3109. 		Store_weapon_inventory.extra_buttons = nil				 
  3110. 		thread_kill(Store_weapon_inventory.thread) 
  3111. 		Store_weapon_inventory.thread = nil		 
  3112. 	end 
  3113. end 
  3114.  
  3115.  
  3116. -- Radial input handling 
  3117. function store_weapon_inventory_process() 
  3118. 	while true do  
  3119. 		if Store_weapon_inventory.stale == true then 
  3120. 				 
  3121. 			local x = Store_weapon_inventory.x 
  3122. 			local y = Store_weapon_inventory.y 
  3123. 			local selected_weapon_index = 0 
  3124. 			local mag = sqrt((x * x) + (y * y)) 
  3125. 			local pi = 3.14159 
  3126. 			 
  3127. 			if mag > 0.5 then 
  3128. 				 
  3129. 				-- Y resolves out so don't bother with it 
  3130. 				x = x/mag 
  3131. 				local radians = acos(x) 
  3132. 				 
  3133. 				if y < 0.0 then 
  3134. 					radians = pi + (pi - radians) 
  3135. 				end 
  3136. 	 
  3137. 				local eighth = pi / 8 
  3138. 				local fourth = pi / 4 
  3139. 				local selected_weapon_index = 0 
  3140. 				 
  3141. 				if radians < eighth then 
  3142. 					selected_weapon_index = 2; 
  3143. 				elseif radians < (fourth + eighth) then 
  3144. 					selected_weapon_index = 1 
  3145. 				elseif radians < (2.0 * fourth + eighth) then 
  3146. 					selected_weapon_index = 0 
  3147. 				elseif radians < (3.0 * fourth + eighth) then 
  3148. 					selected_weapon_index = 7 
  3149. 				elseif radians < (4.0 * fourth + eighth) then 
  3150. 					selected_weapon_index = 6 
  3151. 				elseif radians < (5.0 * fourth + eighth) then 
  3152. 				 
  3153. 					selected_weapon_index = 5 
  3154. 				elseif radians < (6.0 * fourth + eighth) then 
  3155. 					selected_weapon_index = 4; 
  3156. 				elseif radians < (7.0 * fourth + eighth) then				 
  3157. 					selected_weapon_index = 3; 
  3158. 				else 
  3159. 					selected_weapon_index = 2; 
  3160. 				end 
  3161. 				 
  3162. 				-- Only highlight the slot if it isn't disabled 
  3163. 				if Store_weapon_radial:slot_is_disabled(selected_weapon_index) ~= true and selected_weapon_index >= 1 then 
  3164. 															 
  3165. 					-- Call navigation callback 
  3166. 					if Store_weapon_inventory.nav_cb ~= nil then 
  3167. 						Store_weapon_inventory.nav_cb(selected_weapon_index) 
  3168. 					end 
  3169. 					 
  3170. 					Store_weapon_radial:weapon_highlight(selected_weapon_index)	 
  3171. 					 
  3172. 					-- Initialize data for grid 
  3173. 					Weapon_grid_data = {} 
  3174. 					Weapon_grid_idx = 1 
  3175. 					 
  3176. 					-- Get the category name string for the chosen slot. 
  3177. 					local category = Store_weapon_categories[selected_weapon_index].category 
  3178. 					 
  3179. 					if category == "thrown" == true then 
  3180. 						vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category) 
  3181. 					else 
  3182. 						vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  3183. 					end	 
  3184. 					 
  3185. 					-- If there are no choices, don't show weapon stats 
  3186. 					if #Weapon_grid_data ~= 0 then 
  3187. 						store_weapon_populate_weapon_stats() 
  3188. 					end 
  3189. 				end 
  3190. 		 
  3191. 				Store_weapon_radial:stick_update_arrow(radians)				 
  3192. 			end 
  3193. 	 
  3194. 			--Update Stick location on radial menu 
  3195. 			Store_weapon_radial:stick_update_position(Store_weapon_inventory.x, Store_weapon_inventory.y) 
  3196. 			Store_weapon_inventory.stick_mag = mag 
  3197. 			Store_weapon_inventory.stale = false 
  3198. 		end 
  3199. 		thread_yield() 
  3200. 	end 
  3201. end 
  3202.  
  3203.  
  3204. function store_weapon_image_update() 
  3205. 	delay(0.2) 
  3206. 	if Store_weapon_unload_img ~= nil then 
  3207. 		Reward_image:set_visible(false) 
  3208. 		game_peg_unload(Store_weapon_unload_img) 
  3209. 	end 
  3210. 	if Store_weapon_loading_img ~= nil then 
  3211. 		game_peg_load_with_cb("store_weapon_show_image", 1, Store_weapon_loading_img) 
  3212. 	end 
  3213. 	Store_weapon_img_update_thread = -1 
  3214. end 
  3215.  
  3216. -- Callback for when an image is done loading. 
  3217. -- SEH: It might make sense to roll this into vdo_bitmap_viewer... 
  3218. -- 
  3219. function store_weapon_show_image() 
  3220. 	 
  3221. 	local new_image = Store_weapon_new_image 
  3222. 	local img_scale_x = 1.0 
  3223. 	local img_scale_y = 1.0 
  3224. 	 
  3225. 	if Store_weapon_loading_img == new_image and Store_weapon_loading_img ~= Store_weapon_unload_img then 
  3226. 		Reward_image:set_image(new_image, false, true, 0, 0, img_scale_x, img_scale_y, nil) 
  3227. 		if game_peg_is_loaded(new_image) then 
  3228. 			Reward_image:set_visible(true) 
  3229. 		end 
  3230. 		 
  3231. 		--Store_weapon_unload_img = Store_weapon_loading_img 
  3232. 		--Store_weapon_loading_img = nil 
  3233. 		 
  3234. 	else 
  3235. 		-- a new image was picked while we were loading - load this now, and unload the one we just loaded 
  3236. 		if new_image ~= nil then 
  3237. 			Reward_image:set_visible(false) 
  3238. 			Store_weapon_unload_img = Store_weapon_loading_img 
  3239. 			Store_weapon_loading_img = new_image 
  3240. 			Store_weapon_img_update_thread = thread_new("store_weapon_image_update")	 
  3241. 		else 
  3242. 			Reward_image:set_visible(false) 
  3243. 			game_peg_unload(Store_weapon_loading_img) 
  3244. 			Store_weapon_loading_img = nil 
  3245. 		end 
  3246. 	end 
  3247. end 
  3248.  
  3249. function store_weapon_change_weapon_preview(category, id, dual_wield, is_cache, upgrade_level, costume, skin, img_crc) 
  3250.  
  3251. 	--Flag that we are previewing the weapon so we can revert back to equipped weapon if player is forced out of the store 
  3252. 	Store_weapon_skin_was_previewed = true 
  3253.  
  3254. 	local immediate = false 
  3255. 	if costume == nil then 
  3256. 		costume = -1 
  3257. 	end 
  3258.  
  3259. 	-- Tell C to replace model 
  3260. 	local loading = store_weapon_change_weapon(category, id, dual_wield, is_cache, upgrade_level, costume, skin, immediate) 
  3261.  
  3262. 	-- If we're only doing an upgrade swap, we don't need to lock grid input 
  3263. 	if loading == true then 
  3264. 		-- lock input until the swap is done 
  3265. 		Store_weapon_is_loading = true 
  3266. 		--store_weapon_cover_weapon(false) 
  3267. 		--store_weapon_uncover_weapon(false) 
  3268.  
  3269. 		if img_crc ~= nil then 
  3270. 			Store_weapon_new_image = img_crc 
  3271. 			store_weapon_show_image() 
  3272. 		else 
  3273. 			Reward_image:set_visible(false) 
  3274. 		end 
  3275. 	end 
  3276. end	 
  3277.  
  3278.  
  3279. function store_weapon_allow_grid_input() 
  3280. 	return Store_weapon_is_loading == false 
  3281. end 
  3282.  
  3283. -- ===================================== 
  3284. --           Notoriety Wipe 
  3285. -- ===================================== 
  3286.  
  3287. function store_weapon_main_menu_nav() 
  3288. 	local menu_idx = Active_list:get_selection() 
  3289.  
  3290. 	local player_notoriety_level = vint_get_player_notoriety(); 
  3291.  
  3292. 	if player_notoriety_level > 6 then 
  3293. 		player_notoriety_level = 6 
  3294. 	end 
  3295.  
  3296. 	if menu_idx == 1 then 
  3297. 		if player_notoriety_level > 0 then 
  3298. 			Store_header:set_price(Notoriety_level_clear_cost_data[player_notoriety_level].cost) 
  3299. 		else 
  3300. 			Store_header:set_price(nil) 
  3301. 		end 
  3302. 	else 
  3303. 		Store_header:set_price(nil) 
  3304. 	end 
  3305. end 
  3306.  
  3307. function store_weapon_notoriety_cost_update( level_cost ) 
  3308. 	local cost_index = #Notoriety_level_clear_cost_data + 1 
  3309.  
  3310. 	Notoriety_level_clear_cost_data[cost_index] = { 
  3311. 		cost = level_cost 
  3312. 	} 
  3313. end 
  3314.  
  3315. function store_weapon_wipe_notoriety() 
  3316. 	 
  3317. 	local player_notoriety_level = vint_get_player_notoriety(); 
  3318.  
  3319. 	if player_notoriety_level > 6 then 
  3320. 		player_notoriety_level = 6 
  3321. 	end 
  3322. 	if mission_is_active() and game_is_prologue_complete() then 
  3323. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  3324. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  3325. 		Store_common_popup:set_text("MAP_EVENT_NOTO")	-- Going to need new string for missions 
  3326. 		Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  3327. 		Not_popup_grp:set_alpha(.5)		 
  3328. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  3329. 		game_UI_audio_play("UI_HUD_HELP") 
  3330. 		store_weapon_enable_mouse(false) 
  3331. 		return 
  3332. 	end 
  3333.  
  3334. 	-- Check if we have any notoriety, and enough money. 
  3335. 	if player_notoriety_level > 0 then 
  3336. 		if Store_common_player_cash >= Notoriety_level_clear_cost_data[player_notoriety_level].cost then 
  3337. 			 
  3338. 			--Valid purchase 
  3339. 			Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)				 
  3340. 			Store_common_popup:set_title("MENU_TITLE_CONFIRM") 
  3341. 			local insert = { [0] = format_cash(Notoriety_level_clear_cost_data[player_notoriety_level].cost) } 
  3342. 			local body = vint_insert_values_in_string("WPN_STORE_WIPE_NOTO_PROMPT", insert)				 
  3343. 			Store_common_popup:set_text(body)		 
  3344. 			Store_common_popup:nav_enable(true, "store_weapon_notoriety_wipe_confirm", "store_weapon_popup_nav") 
  3345. 			Not_popup_grp:set_alpha(.5)	 
  3346. 			Store_weapon_not_bg_grp:set_alpha(.5)	 
  3347. 			store_weapon_enable_mouse(false) 
  3348. 			game_UI_audio_play("UI_HUD_HELP") 
  3349. 			return	 
  3350. 			 
  3351. 		else 
  3352. 			Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  3353. 			Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  3354. 			Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")		 
  3355. 			Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  3356. 			Not_popup_grp:set_alpha(.5)	 
  3357. 			Store_weapon_not_bg_grp:set_alpha(.5) 
  3358. 			game_UI_audio_play("UI_HUD_HELP") 
  3359. 			store_weapon_enable_mouse(false) 
  3360. 			return		 
  3361. 		end 
  3362. 	else 
  3363. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  3364. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  3365. 		Store_common_popup:set_text("WPNSTORE_TEXT_NO_NOTORIETY")	-- Going to need new string for no notoriety	 
  3366. 		Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  3367. 		Not_popup_grp:set_alpha(.5)		 
  3368. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  3369. 		game_UI_audio_play("UI_HUD_HELP") 
  3370. 		store_weapon_enable_mouse(false) 
  3371. 		return			 
  3372. 	end	 
  3373.  
  3374. 	 
  3375. 	 
  3376. end 
  3377.  
  3378. function store_weapon_notoriety_wipe_confirm(event) 
  3379. 	store_weapon_enable_mouse(true) 
  3380.  
  3381. 	Store_common_popup:nav_enable(false, nil, nil) 
  3382. 	Not_popup_grp:set_alpha(1)	 
  3383. 	Store_weapon_not_bg_grp:set_alpha(1) 
  3384.  
  3385. 	-- The user hit the B button and are cancelling the purchase 
  3386. 	-- This is the same as selecting "No" in the list 
  3387. 	if event == "back" or Store_common_popup:get_selected_data() ~= 1 then 
  3388. 		 
  3389. 		return 
  3390. 	end 
  3391.  
  3392. 	local player_notoriety_level = vint_get_player_notoriety(); 
  3393. 	local cost = 0; 
  3394. 	if player_notoriety_level > 0 then 
  3395. 		cost = Notoriety_level_clear_cost_data[player_notoriety_level].cost 
  3396. 	end 
  3397. 	local saved_cash = Store_common_player_cash 
  3398. 			 
  3399. 	-- Make the purchase. 
  3400. 	vint_notoriety_reset("police", cost); 
  3401. 	Store_header:set_price(nil) 
  3402. 			 
  3403. 	--play the purchase sound 
  3404. 	ui_audio_post_event("ammo_purchase") 
  3405.  
  3406. 	Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  3407. 	Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  3408. 	Store_common_popup:set_text("WPNSTORE_TEXT_NOTORIETY_RESET_SUCCESS")		 
  3409. 	Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  3410. 	Not_popup_grp:set_alpha(.5)	 
  3411. 	Store_weapon_not_bg_grp:set_alpha(.5) 
  3412. 	store_weapon_enable_mouse(false) 
  3413. end 
  3414.  
  3415.  
  3416. -- ===================================== 
  3417. --       Mouse Specific Functions 
  3418. -- ===================================== 
  3419.  
  3420. function store_weapon_enable_mouse(enable) 
  3421. 	if Game_platform == "PC" and enable ~= nil then 
  3422. 		if Mouse_input_tracker ~= 0 then 
  3423. 			Mouse_input_tracker:subscribe(enable) 
  3424. 		end 
  3425. 		 
  3426. 		if Hint_bar_mouse_input_tracker ~= nil then 
  3427. 			Hint_bar_mouse_input_tracker:subscribe(enable) 
  3428. 		end 
  3429. 		 
  3430. 		if enable == false then 
  3431. 			if Radial_mouse_input_tracker ~= nil then 
  3432. 				Radial_mouse_input_tracker:subscribe(false) 
  3433. 			end 
  3434. 		end 
  3435. 	end 
  3436. end 
  3437.  
  3438.  
  3439. function store_weapon_mouse_click(event, target_handle) 
  3440. 	local hint_index = Store_common_hint_bar:get_hint_index(target_handle) 
  3441. 	if hint_index ~= 0 then 
  3442. 		if Current_tier == MENU_TIER then 
  3443. 			store_common_button_b() 
  3444. 		elseif Current_tier == LEVEL_TIER then 
  3445. 			store_common_button_b() 
  3446. 		elseif Current_tier == RADIAL_TIER then 
  3447. 			store_weapon_inventory_input("back") 
  3448. 		elseif Current_tier == WEAPON_TIER or Current_tier == GRENADE_UPGRADE_TIER then 
  3449. 			store_weapon_grid_selected("back") 
  3450. 		end 
  3451. 	end 
  3452. 	 
  3453. 	local weapon_index = Store_weapon_radial:get_slot_index(target_handle) 
  3454. 	if weapon_index ~= 0 and weapon_index < 8 then 
  3455. 		-- Highlight the correct weapon, and select it 
  3456. 		Store_weapon_radial:weapon_highlight(weapon_index) 
  3457. 		store_weapon_inventory_input("select") 
  3458. 	end 
  3459. end 
  3460.  
  3461.  
  3462. function store_weapon_mouse_move(event, target_handle) 
  3463. 	-- Reset all highlights 
  3464. 	Store_common_hint_bar:set_highlight(0) 
  3465. 	 
  3466. 	-- Check if the mouse is over the hint bar buttons 
  3467. 	local hint_index = Store_common_hint_bar:get_hint_index(target_handle) 
  3468. 	if hint_index ~= 0 then 
  3469. 		Store_common_hint_bar:set_highlight(hint_index, Store_common_current_highlight_color) 
  3470. 		return 
  3471. 	end 
  3472. 	 
  3473. 	-- Check if the mouse is over a button on the mega list 
  3474. 	local old_index = Active_list:get_selection() 
  3475. 	local new_index = Active_list:get_button_index(target_handle) 
  3476. 	if new_index ~= 0 and new_index ~= old_index then 
  3477. 		Active_list:set_selection(new_index) 
  3478. 		Active_list:move_cursor(0, true) 
  3479. 		 
  3480. 		-- If the item has a callback for navigation, do it (such as putting clothes on) 
  3481. 		local data_item = Active_list:return_selected_data() 
  3482. 		if data_item.on_nav ~= nil then 
  3483. 			data_item.on_nav(data_item) 
  3484. 		end 
  3485. 		return 
  3486. 	end 
  3487. 	 
  3488. 	local weapon_index = Store_weapon_radial:get_slot_index(target_handle) 
  3489. 	if weapon_index ~= 0 and Old_index ~= weapon_index then 
  3490.  
  3491. 		-- Only highlight the slot if it isn't disabled 
  3492. 		if Store_weapon_radial:slot_is_disabled(weapon_index) ~= true and weapon_index>= 1 then 
  3493. 													 
  3494. 			-- Call navigation callback 
  3495. 			if Store_weapon_inventory.nav_cb ~= nil then 
  3496. 				Store_weapon_inventory.nav_cb(weapon_index) 
  3497. 			end 
  3498. 			 
  3499. 			Store_weapon_radial:weapon_highlight(weapon_index, true, true)	 
  3500. 			 
  3501. 			-- Initialize data for grid 
  3502. 			Weapon_grid_data = {} 
  3503. 			Weapon_grid_idx = 1 
  3504. 			 
  3505. 			-- Get the category name string for the chosen slot. 
  3506. 			local category = Store_weapon_categories[weapon_index].category 
  3507. 			 
  3508. 			if category == "thrown" == true then 
  3509. 				vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category) 
  3510. 			else 
  3511. 				vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  3512. 			end	 
  3513. 			 
  3514. 			-- If there are no choices, don't show weapon stats 
  3515. 			if #Weapon_grid_data ~= 0 then 
  3516. 				store_weapon_populate_weapon_stats() 
  3517. 			end 
  3518. 			 
  3519. 			Old_index = weapon_index 
  3520. 		end 
  3521. 	end 
  3522. end 
  3523.  
  3524.  
  3525. function store_weapon_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  3526. 	if scroll_lines ~= 0 then 
  3527. 		if Store_common_color_grid.bg.handle == target_handle then 
  3528. 			Store_common_color_grid:scroll_list(scroll_lines * -1) 
  3529. 		end 
  3530. 	end 
  3531. end 
  3532.  
  3533.  
  3534. function store_weapon_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  3535. 	if Store_common_color_grid.scrollbar.tab_grp.handle == target_handle then 
  3536. 		local new_start_index = Store_common_color_grid.scrollbar:drag_scrolltab(mouse_y, Store_common_color_grid.rows - (Store_common_color_grid.max_height - 1)) 
  3537. 		Store_common_color_grid:scroll_list(0, new_start_index) 
  3538. 	end 
  3539. end 
  3540.  
  3541.  
  3542. function store_weapon_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  3543. 	if Store_common_color_grid.scrollbar.tab_grp.handle == target_handle then 
  3544. 		local start_row = Store_common_color_grid:get_visible_rows() 
  3545. 		Store_common_color_grid.scrollbar:release_scrolltab(start_row, Store_common_color_grid.rows - (Store_common_color_grid.max_height - 1)) 
  3546. 		Store_common_color_grid:update_mouse_inputs() 
  3547. 	end 
  3548. end 
  3549.