./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 		= 320 
  6. local STORE_WEAPON_RADIAL_CACHE_SD_X 	= 260 
  7. local STORE_WEAPON_RADIAL_STORE_X 		= 260 
  8. local STORE_WEAPON_RADIAL_STORE_SD_X 	= 245 
  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. Store_weapon_doc_handle = -1 
  16.  
  17. local Store_weapon_radial 
  18.  
  19. local Hint_bar_mouse_input_tracker 
  20. local Radial_mouse_input_tracker 
  21. local Game_platform 
  22.  
  23. local Store_weapon_in_mission = false 
  24. local Gsi_is_updated = false 
  25.  
  26. local MENU_TIER	= 1 
  27. local RADIAL_TIER	= 2 
  28. local WEAPON_TIER	= 3 
  29. local LEVEL_TIER	= 4 
  30. local GRENADE_UPGRADE_TIER = 5 
  31. local Current_tier = MENU_TIER 
  32. local Skip_next_populate = false 
  33. local Restore_weapon_radial_inputs = false 
  34.  
  35. local Current_slot = -1 
  36. local Prev_slot = -1 
  37.  
  38. local Radial_cache_x = STORE_WEAPON_RADIAL_CACHE_X 
  39. local Radial_store_x = STORE_WEAPON_RADIAL_STORE_X 
  40.  
  41. -- Hint bar and store header vdo's. 
  42.  
  43. local Store_logo1 
  44. local Store_logo2 
  45. local Not_popup_grp 
  46. local Reward_image 
  47. local Weapon_bg_grp 
  48. local Weapon_stats_grp 
  49. local Store_weapon_not_bg_grp 
  50. local Slot_stats_grp 
  51. local Weapons_owned = {} 
  52. local Weapons_available = {} 
  53. local Stats_initialized = false 
  54. local Weapon_store_highlight_color = {} 
  55.  
  56. -- We used this as a reference to the current submenu we are building. 
  57. local Store_weapon_building_menu = {} 
  58.  
  59. local Store_weapon_loaded_from_crib = false 
  60.  
  61. -- Determines if we're in "store" or "cache" mode. 
  62. local Store_weapon_is_cache = false 
  63.  
  64. -- Stores data regarding ammo that is not stored in the radial menu vdo. 
  65. local Store_weapon_ammo_info = {} 
  66. local Store_weapon_thrown_ammo_info = {} 
  67.  
  68. -- Info on weapon that may be purchaed. 
  69. local Store_weapon_current_info = {} 
  70.  
  71. -- Used to flag we are leaving UI because the player entered the cache with no weapons 
  72. local Store_weapon_cache_no_weapons = false 
  73.  
  74. -- True if we're currently waiting on a weapon swap/load 
  75. local Store_weapon_is_loading = false 
  76.  
  77. -- Save the previous grid index to prevent mouse move triggering every frame 
  78. local Old_index = 0 
  79.  
  80. -- Used to track weapon radial input and state 
  81. Store_weapon_inventory = { 
  82. 	stick_mag = 0, 
  83. 	is_pressed = false, 
  84. 	selected_cb = nil, 
  85. 	nav_cb = nil 
  86. } 
  87.  
  88. -- Stores data regarding the grid selector for weapons 
  89. local Weapon_grid_data = {} 
  90.  
  91. -- Index of the starting weapon grid choice to highlight. 
  92. local Weapon_grid_idx = 1 
  93.  
  94. local Store_weapon_tool_mode = false 
  95.  
  96. local Store_weapon_categories = { 
  97. 	[1] = { label = "WPN_STORE_MELEE_TITLE",		category = "melee",		info = {} 		}, 
  98. 	[2] = { label = "WPN_STORE_PISTOL_TITLE",		category = "pistol",		info = {} 		}, 
  99. 	[3] = { label = "WPN_STORE_SMG_TITLE", 		category = "smg", 		info = {} 		}, 
  100. 	[4] = { label = "WPN_STORE_SHOTGUN_TITLE",	category = "shotgun", 	info = {} 		}, 
  101. 	[5] = { label = "WPN_STORE_RIFLE_TITLE", 		category = "rifle", 		info = {} 		}, 
  102. 	[6] = { label = "WPN_STORE_EXPLOSIVE_TITLE", category = "explosive", info = {} 		}, 
  103. 	[7] = { label = "WPN_STORE_SPECIAL_TITLE",	category = "special", 	info = {} 		}, 
  104. 	[8] = { label = "WPN_STORE_THROWN_TITLE", 	category = "thrown", 	info = {} 		}, 
  105. 	[9] = { label = "WPN_STORE_THROWN_TITLE", 	category = "thrown", 	info = {} 		}, 
  106. 	[10] = { label = "WPN_STORE_THROWN_TITLE", 	category = "thrown",		info = {} 		}, 
  107. 	[11] = { label = "WPN_STORE_THROWN_TITLE", 	category = "thrown", 	info = {} 		}, 
  108. } 
  109.  
  110. ---------------------------------------------------------------------------  
  111. -- Initialize Weapon Store 
  112. --------------------------------------------------------------------------- 
  113. function store_weapon_init() 
  114.  
  115. 	Game_platform = game_get_platform() 
  116.  
  117. 	Store_weapon_loaded_from_crib = store_common_crib_is_loaded() 
  118.  
  119. 	-- If we're in the crib, we're only doing cache (not store). 
  120. 	Store_weapon_is_cache = Store_weapon_loaded_from_crib 
  121. 	 
  122. 	Store_weapon_doc_handle = vint_document_find("store_weapon") 
  123.  
  124. 	Store_weapon_radial = Vdo_weapon_radial:new("weapon_radial", 0, Store_weapon_doc_handle) 
  125. 	Store_weapon_radial:set_visible(false) 
  126. 	if Store_weapon_loaded_from_crib then 
  127. 		Weapon_store_highlight_color = COLOR_STORE_REWARDS_PRIMARY 
  128. 	else 
  129. 		Weapon_store_highlight_color = COLOR_STORE_WEAPON_PRIMARY 
  130. 	end 
  131.  
  132. 	Store_common_current_highlight_color = Weapon_store_highlight_color 
  133. 	 
  134. 	Store_weapon_radial:set_highlight_color(Weapon_store_highlight_color) 
  135. 	 
  136. 	Store_weapon_not_bg_grp = Vdo_base_object:new("weapon_not_bg_grp", 0, Store_weapon_doc_handle) 
  137. 	 
  138. 	-- This turns on "store mode" for weapon radial, which makes changes like shows hint buttons and disables choices. 
  139. 	Store_weapon_radial:store_mode_enable(true) 
  140. 		 
  141. 	-- Set up some callbacks for the common store script 
  142. 	Store_common_populate_list_cb 	= store_weapon_populate_list 
  143. 	Store_common_exit_cb					= store_weapon_exit 
  144.  
  145. 	-- Initialize mouse input trackers and create mouse tracker for the hint bar 
  146. 	if Game_platform == "PC" then 
  147. 		Mouse_input_tracker:subscribe(false) 
  148. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  149. 		Radial_mouse_input_tracker = Vdo_input_tracker:new() 
  150. 	end 
  151. 	 
  152. 	-- Subscribe to the button presses we need, Input_tracker is created in store_common.lua 
  153. 	store_lock_controls() 
  154. 	 
  155. 	--Setup Button Hints 
  156. 	local hint_data = { 
  157. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  158. 		--{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  159. 		--{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"}, 
  160. 	} 
  161. 	Store_common_hint_bar:set_hints(hint_data)  
  162. 	Store_common_hint_bar:set_visible(true) 
  163. 	 
  164. 	-- SEH: 6/28/11: cut zoom/rotate 
  165. 	-- Hint_bar_rotate = Vdo_hint_bar:new("hint_rotate", 0, Store_common_doc_handle) 
  166. 	-- local hint_rotate_data = { 
  167. 		-- {CTRL_BUTTON_RS, "STORE_ZOOM_ROTATE"}, 
  168. 	-- } 
  169. 	-- Hint_bar_rotate:set_hints(hint_rotate_data) 
  170. 	-- Hint_bar_rotate:set_visible(true) 
  171. 	 
  172. 	Store_header:set_visible(true) 
  173. 		 
  174. 	-- Everything that is not in the popup so we can fade it when the popup is active 
  175. 	Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle) 
  176. 	 
  177. 	-- Setup purchase popup 
  178. 	Store_common_popup:set_visible(false) 
  179. 	Store_common_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5)) 
  180. 	 
  181. 	-- Setup Color grid 
  182. 	Store_common_color_grid:set_visible(false) 
  183. 	 
  184. 	-- Setup weapon stats 
  185. 	Weapon_stats_grp = Vdo_base_object:new("weapon_stats_grp", 0, Store_weapon_doc_handle) 
  186. 	Weapon_stats_grp:set_visible(false) 
  187. 	 
  188. 	local gsi_grp = Vdo_base_object:new("gsi_grp",0, Store_weapon_doc_handle) 
  189. 	gsi_grp:set_visible(false) 
  190. 	 
  191. 	-- Setup slot stats 
  192. 	Slot_stats_grp = Vdo_base_object:new("slot_stats_grp", 0, Store_weapon_doc_handle) 
  193. 	Slot_stats_grp:set_visible(false) 
  194. 	 
  195. 	-- don't do anything else when we're in customization camera tool mode 
  196. 	if vcust_is_camera_tool_mode() then 
  197. 	 
  198. 		Store_header:set_visible(false) 
  199. 	 
  200. 		-- make background so it is behind the weapon 
  201. 		Weapon_bg_grp = Vdo_base_object:new("bg_grp", 0, Store_weapon_doc_handle)	 
  202. 		Weapon_bg_grp:set_property("background", true)	 
  203. 		 
  204. 		-- draw bogus weapon info 
  205. 		local weapon_title = Vdo_base_object:new("weapon_title", 0, Store_weapon_doc_handle) 
  206. 		local weapon_level = Vdo_base_object:new("weapon_level", 0, Store_weapon_doc_handle) 
  207. 		 
  208. 		-- Display weapon stats 
  209. 		weapon_title:set_text("BOGUS WEAPON NAME") 
  210. 		local insert = { [0] = 1 } 
  211. 		local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert)		 
  212. 		weapon_level:set_text("Weapon description") 
  213. 		 
  214. 		Weapon_stats_grp:set_visible(true) 
  215. 		 
  216. 		Store_weapon_tool_mode = true 
  217. 		return 
  218. 	end 
  219. 	 
  220. 	if vint_is_std_res() then 
  221. 		--Store_header:reformat_and_resize(false,306) 
  222. 		Radial_cache_x = STORE_WEAPON_RADIAL_CACHE_SD_X 
  223. 		Radial_store_x = STORE_WEAPON_RADIAL_STORE_SD_X 
  224. 	end 
  225.  
  226. 	if Store_weapon_loaded_from_crib then 
  227. 		-- Get reference to the Saints background for future use 
  228. 		--Weapon_bg_grp = Vdo_base_object:new("crib_bg_grp", 0, Bg_saints_doc_handle) 
  229. 		 
  230. 		-- Get reference to the weapon store background for future use 
  231. 		Weapon_bg_grp = Vdo_base_object:new("bg_grp", 0, Store_weapon_doc_handle)	 
  232. 		 
  233. 		local bg_gradient_top_h = vint_object_find("bg_gradient_top",0,Store_weapon_doc_handle) 
  234. 		--vint_set_property(bg_gradient_top_h,"visible",true) 
  235. 		 
  236. 		-- From the crib, we just go straight to the weapon radial 
  237. 		Active_list:set_visible(false) 
  238.  
  239. 		-- Set the hint based on the platform 
  240. 		local hint_data = {} 
  241. 		if game_get_platform() == "PC" then 
  242. 			hint_data = { 
  243. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  244. 			} 
  245. 		else  
  246. 			hint_data = { 
  247. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  248. 				{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  249. 				{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"}, 
  250. 			} 
  251. 		end 
  252. 		Store_common_hint_bar:set_hints(hint_data)  
  253. 		if Hint_bar_mouse_input_tracker ~= nil then 
  254. 			Store_common_hint_bar:add_mouse_inputs("store_weapon", Hint_bar_mouse_input_tracker) 
  255. 			Hint_bar_mouse_input_tracker:subscribe(true) 
  256. 		end 
  257. 		 
  258. 		--store_weapon_cache_open_radial() 
  259. 		 
  260. 		-- Hide weapon store background since we use the saints background in crib 
  261. 		local weapon_store_bg_grp = Vdo_base_object:new("bg_texture_group", 0, Store_weapon_doc_handle) 
  262. 		weapon_store_bg_grp:set_visible(false) 
  263. 		local weapon_logo_grp = Vdo_base_object:new("logo_grp", 0, Store_weapon_doc_handle) 
  264. 		weapon_logo_grp:set_visible(false) 
  265. 		 
  266. 		local red_bar_h = vint_object_find("red_bar",0,Store_weapon_doc_handle) 
  267. 		local grey = 30/255 
  268. 		vint_set_property(red_bar_h,"tint",grey,grey,grey) 
  269. 		 
  270. 		local header_txt = Vdo_base_object:new("header_txt", 0, Store_weapon_doc_handle) 
  271. 		header_txt:set_color(Weapon_store_highlight_color.R,Weapon_store_highlight_color.G,Weapon_store_highlight_color.B) 
  272. 	 
  273. 		local weapon_title = Vdo_base_object:new("weapon_title", 0, Store_weapon_doc_handle) 
  274. 		weapon_title:set_color(Weapon_store_highlight_color.R,Weapon_store_highlight_color.G,Weapon_store_highlight_color.B) 
  275. 		 
  276. 		local texture_bg = vint_object_find("bg_texture_grp", 0, Store_weapon_doc_handle) 
  277. 		vint_set_property(texture_bg, "background", true) 
  278. 		vint_set_property(texture_bg, "visible", false) 
  279. 		 
  280. 		Store_common_color_grid:set_highlight_color(Weapon_store_highlight_color) 
  281. 		 
  282. 		Store_header:push_title(nil, "WPNSTOR_TITLE_WEAPON_CACHE") 
  283. 		Store_header:enable_price_respect(false) 
  284. 		 
  285. 		store_weapon_cover_weapon(true)	 
  286. 		 
  287. 		local mask_h = vint_object_find("mask",0,Store_weapon_doc_handle) 
  288. 		vint_set_property(mask_h,"scale",150,71) 
  289. 		 
  290. 		local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle) 
  291. 		store_main_grp:set_anchor(0,0) 
  292. 		 
  293. 		bg_saints_set_type(BG_TYPE_CENTER,true,1280) 
  294. 		 
  295. 		local anim_in = Vdo_anim_object:new("store_weapon_crib_anim_in", 0, Store_weapon_doc_handle) 
  296. 		local store_intro_anim = Vdo_anim_object:new("store_common_in_anim",0, Store_common_doc_handle) 
  297. 		local end_event_twn = Vdo_tween_object:new("end_event_twn", store_intro_anim.handle) 
  298.  
  299. 		end_event_twn:set_end_event("store_weapon_intro_anim_complete") 
  300. 		 
  301. 		vint_apply_start_values(store_intro_anim.handle) 
  302. 		vint_apply_start_values(anim_in.handle)		 
  303. 				 
  304. 		-- Start animation now 
  305. 		anim_in:play(0) 
  306. 		store_intro_anim:play(0) 
  307. 		 
  308. 		Current_tier = RADIAL_TIER 
  309. 		 
  310. 	else 
  311. 		Menu_data = { 
  312. 			on_cancel = store_weapon_cancel_radial, 
  313. 			[1] = { label = "STORE_WEAPON_AMMO", type = TYPE_BUTTON, on_select = store_weapon_ammo_open_radial }, 
  314. 			[2] = { label = "STORE_WEAPON_BUY_UPGRADE", type = TYPE_BUTTON, on_select = store_weapon_purchase_open_radial }, 
  315. 			[3] = { label = "STORE_WEAPON_CACHE", type = TYPE_BUTTON,  on_select = store_weapon_cache_open_radial }, 
  316. 			[4] = { label = "STORE_EXIT", type = TYPE_BUTTON,  on_select = store_weapon_exit }, 
  317. 		}	 
  318. 		 
  319. 		-- Are we in mission 3?  Show GSI and fade out logo_grp 
  320. 		if cell_is_mission_complete("m03") == false then 
  321. 			Store_weapon_in_mission = true 
  322. 		end 
  323. 		 
  324. 		local gsi_grp = Vdo_base_object:new("gsi_grp",0, Store_weapon_doc_handle) 
  325. 		local obj_txt = Vdo_base_object:new("obj_txt", 0, Store_weapon_doc_handle) 
  326. 		local gsi_bg = Vdo_base_object:new("gsi_bg", 0, Store_weapon_doc_handle) 
  327. 		local logo_grp = Vdo_base_object:new("logo_grp", 0, Store_weapon_doc_handle) 
  328. 		 
  329. 		if Store_weapon_in_mission then 
  330. 			obj_txt:set_text("M03_OBJ_PURCHASE_AN_UPGRADE")			 
  331. 			 
  332. 			local obj_txt_x, obj_txt_y = obj_txt:get_anchor() 
  333. 			local obj_txt_width, obj_txt_height = element_get_actual_size(obj_txt.handle) 
  334. 			local gsi_bg_width, gsi_bg_height = element_get_actual_size(gsi_bg.handle) 
  335. 			 
  336. 			element_set_actual_size(gsi_bg.handle, obj_txt_x + obj_txt_width + 5, gsi_bg_height) 
  337. 						 
  338. 			logo_grp:set_alpha(.35) 
  339. 			 
  340. 			gsi_grp:set_visible(true) 
  341. 		else 
  342. 			gsi_grp:set_visible(false) 
  343. 		end 
  344. 		 
  345. 		local logo_intro_anim = Vdo_anim_object:new("store_weapon_logo_intro", 0, Store_weapon_doc_handle) 
  346. 		local store_intro_anim = Vdo_anim_object:new("store_common_in_anim",0, Store_common_doc_handle) 
  347. 		local bg_anim = Vdo_anim_object:new("store_weapon_anim_in",0, Store_weapon_doc_handle) 
  348. 		local end_event_twn = Vdo_tween_object:new("end_event_twn", store_intro_anim.handle) 
  349.  
  350. 		end_event_twn:set_end_event("store_weapon_intro_anim_complete")	 
  351. 		 
  352. 		vint_apply_start_values(logo_intro_anim.handle) 
  353. 		vint_apply_start_values(store_intro_anim.handle) 
  354. 		vint_apply_start_values(bg_anim.handle) 
  355. 	 
  356. 		logo_intro_anim:play(0)	 
  357. 		store_intro_anim:play(0)	 
  358. 		bg_anim:play(0) 
  359. 		 
  360. 		ui_audio_post_event("enter_friendly_fire") 
  361. 		 
  362. 		-- Set Store Header colors 
  363. 		Store_header:set_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY, COLOR_STORE_WEAPON_TERTIARY)		 
  364. 		Active_list:set_highlight_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY)		 
  365. 		Store_common_popup:set_color(Weapon_store_highlight_color, COLOR_STORE_WEAPON_SECONDARY, COLOR_STORE_WEAPON_TERTIARY) 
  366. 		 
  367. 		-- Pass the table data to the megalist vdo. 
  368. 		store_weapon_populate_list(Menu_data, 1) 
  369. 		Active_list:set_visible(true) 
  370. 		 
  371.  
  372. 		-- Get reference to the weapon store background for future use 
  373. 		Weapon_bg_grp = Vdo_base_object:new("bg_grp", 0, Store_weapon_doc_handle)	 
  374. 		 
  375. 		Current_tier = MENU_TIER 
  376. 		 
  377. 		store_weapon_cover_weapon(false)	 
  378. 	end	 
  379. 		 
  380. 	-- Subscribe to data group that will give us the currently equipped inventory 
  381. 	vint_datagroup_add_subscription("sr2_local_player_inventory", "update", "store_weapon_radial_update") 
  382. 	vint_datagroup_add_subscription("sr2_local_player_inventory", "insert", "store_weapon_radial_update") 
  383. 	 
  384. end 
  385.  
  386. function store_weapon_intro_anim_complete() 
  387. 	store_weapon_process_post_bg_covered() 
  388. 	store_common_bg_anim_complete() 
  389.  
  390. 	if Store_weapon_loaded_from_crib == false then 
  391. 		store_unlock_controls() 
  392. 	else 
  393. 		-- Don't unlock radial input if we are showing the "you don't own any weapons" popup 
  394. 		if Store_weapon_cache_no_weapons == false then 
  395. 			store_weapon_cache_open_radial()	 
  396. 			store_weapon_unlock_radial() 
  397. 		else 
  398. 			Store_weapon_cache_no_weapons = false 
  399. 		end 
  400. 	end 
  401. end 
  402.  
  403. -- Cleanup function called on document unload. 
  404. -- 
  405. function store_weapon_cleanup() 
  406. 	 
  407. 	if Hint_bar_mouse_input_tracker ~= nil then 
  408. 		Hint_bar_mouse_input_tracker:remove_all() 
  409. 	end 
  410. 	 
  411. 	if Radial_mouse_input_tracker ~= nil then 
  412. 		Radial_mouse_input_tracker:remove_all() 
  413. 	end 
  414.  
  415. 	if Store_weapon_tool_mode == false then 
  416. 		if Store_weapon_loaded_from_crib == false then 
  417. 			-- Nuke all button subscriptions 
  418. 			store_lock_controls()	 
  419. 		end 
  420. 	end	 
  421. 	if Store_weapon_inventory.thread ~= nil then 
  422. 		thread_kill(Store_weapon_inventory.thread) 
  423. 		Store_weapon_inventory.thread = nil 
  424. 	end 
  425. 	Store_weapon_radial:cleanup() 
  426. 	 
  427. 	-- Some things need to be cleaned up right away when a store doc is unloading, particular disabled inputs which have 
  428. 	-- callbacks to the script that is unloading. 
  429. 	store_common_cleanup_current_store() 
  430. 	 
  431. 	-- clean out end events 
  432. 	local store_intro_anim = Vdo_anim_object:new("store_common_in_anim",0, Store_common_doc_handle) 
  433. 	local end_event_twn = Vdo_tween_object:new("end_event_twn", store_intro_anim.handle) 
  434. 	end_event_twn:set_end_event(nil) 
  435. 	 
  436. 	-- clean out radial inputs 
  437. 	store_weapon_lock_radial()	 
  438. end 
  439.  
  440. function store_lock_controls() 
  441. 	Input_tracker:subscribe(false) 
  442. 	store_weapon_enable_mouse(false) 
  443. end 
  444.  
  445. function store_unlock_controls() 
  446. 	Input_tracker:subscribe(true) 
  447. 	store_weapon_enable_mouse(true) 
  448. end 
  449.  
  450. function store_weapon_lock_radial() 
  451. 	--lock all the radial input 
  452. 	if Store_weapon_inventory.subs_x ~= nil then 
  453. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_x) 
  454. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_y) 
  455. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_up) 
  456. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_right) 
  457. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_down) 
  458. 		vint_unsubscribe_to_raw_input(Store_weapon_inventory.subs_left) 
  459. 		 
  460. 		if Store_weapon_inventory.extra_buttons ~= nil then 
  461. 			for idx, val in pairs(Store_weapon_inventory.extra_buttons) do  
  462. 				vint_unsubscribe_to_input_event(val) 
  463. 			end 
  464. 		end 
  465. 	end 
  466. end 
  467.  
  468. function store_weapon_unlock_radial() 
  469. 	Store_weapon_inventory.extra_buttons = { 
  470. 		vint_subscribe_to_input_event("select", "store_weapon_inventory_input"), 
  471. 		vint_subscribe_to_input_event("back", "store_weapon_inventory_input"), 
  472. 		vint_subscribe_to_input_event("map", "store_weapon_inventory_input"), 
  473. 		vint_subscribe_to_input_event("pause", "store_weapon_inventory_input"), 
  474. 	} 
  475.  
  476. 	Store_weapon_inventory.subs_x = vint_subscribe_to_raw_input("inventory_x", "store_weapon_inventory_input") 
  477. 	Store_weapon_inventory.subs_y = vint_subscribe_to_raw_input("inventory_y", "store_weapon_inventory_input") 
  478. 	Store_weapon_inventory.subs_up = vint_subscribe_to_raw_input("inventory_up", "store_weapon_inventory_input") 
  479. 	Store_weapon_inventory.subs_right = vint_subscribe_to_raw_input("inventory_right", "store_weapon_inventory_input") 
  480. 	Store_weapon_inventory.subs_down = vint_subscribe_to_raw_input("inventory_down", "store_weapon_inventory_input") 
  481. 	Store_weapon_inventory.subs_left = vint_subscribe_to_raw_input("inventory_left", "store_weapon_inventory_input") 
  482. end 
  483.  
  484. function store_weapon_exit() 
  485. 	-- no confirmation needed if we're just going back to the crib menu 
  486. 	if Store_weapon_loaded_from_crib then 
  487. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  488. 		store_lock_controls() 
  489. 		store_weapon_lock_radial() 
  490. 		-- make background so player is covered up 
  491. 		bg_saints_set_background(false) 
  492. 		local back_out_anim = Vdo_anim_object:new("store_crib_out_anim", 0, Store_common_doc_handle) 
  493. 		local weapon_back_out_anim = Vdo_anim_object:new("store_weapon_crib_anim_out",0, Store_weapon_doc_handle) 
  494. 		local back_out_end_twn = Vdo_tween_object:new("common_anchor_out_twn", back_out_anim.handle) 
  495. 		back_out_end_twn:set_end_event("store_weapon_crib_exit") 
  496. 		back_out_anim:play(0) 
  497. 		weapon_back_out_anim:play(0) 
  498. 	else 
  499. 		Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2) 
  500. 		Store_common_popup:set_title("MENU_TITLE_WARNING") 
  501. 		 
  502. 		if Store_weapon_is_cache then 
  503. 			Store_common_popup:set_text("WPN_STORE_EXIT_PROMPT") 
  504. 		else 
  505. 			Store_common_popup:set_text("STORE_EXIT_WARNING_BODY") 
  506. 		end 
  507. 		 
  508. 		Store_common_popup:nav_enable(true, "store_weapon_exit_final", "store_weapon_popup_nav") 
  509. 		Not_popup_grp:set_alpha(.5) 
  510. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  511. 		 
  512. 		game_UI_audio_play("UI_HUD_HELP") 
  513. 		 
  514. 		store_weapon_enable_mouse(false) 
  515. 	end 
  516. 	 
  517. 	if Mouse_input_tracker ~= 0 then 
  518. 		Mouse_input_tracker:subscribe(false) 
  519. 	end 
  520. end 
  521.  
  522. function store_weapon_crib_exit() 
  523. 	-- called when we slide out to the crib 
  524. 	pop_screen() 
  525. end 
  526.  
  527. function store_weapon_exit_final(event) 
  528. 	Store_common_popup:nav_enable(false, nil, nil) 
  529. 		 
  530. 	-- The user hit the B button and is exiting 
  531. 	-- This is redundant to selecting "No" in the list 
  532. 	if event == "back" then 
  533. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  534. 		Not_popup_grp:set_alpha(1) 
  535. 		Store_weapon_not_bg_grp:set_alpha(1)				 
  536. 		store_weapon_enable_mouse(true) 
  537. 		return 
  538. 	end 
  539. 	 
  540. 	game_UI_audio_play("UI_Main_Menu_Select") 
  541. 	 
  542. 	-- Did we select yes?  This assumes yes is the first item 
  543. 	if Store_common_popup:get_selected_data() ~= 1 then 
  544. 		Not_popup_grp:set_alpha(1) 
  545. 		Store_weapon_not_bg_grp:set_alpha(1) 
  546. 		store_weapon_enable_mouse(true) 
  547. 		return 
  548. 	end 
  549. 	 
  550. 	ui_audio_post_event("UI_Store_Exit") 
  551. 	 
  552. 	store_lock_controls() 
  553. 	 
  554. 	Not_popup_grp:set_alpha(0) 
  555. 	Store_weapon_not_bg_grp:set_alpha(0) 
  556. 	-- exit the interface 
  557. 	local anim_out = Vdo_anim_object:new("store_weapon_anim_out", 0, Store_weapon_doc_handle) 
  558. 	anim_out:play(0) 
  559. 	pop_screen() 
  560. end 
  561.  
  562. function store_weapon_no_weapons() 
  563. 	Store_common_popup:nav_enable(false, nil, nil) 
  564. 	game_UI_audio_play("UI_Main_Menu_Select") 
  565. 	Not_popup_grp:set_alpha(1) 
  566. 	Store_weapon_not_bg_grp:set_alpha(1) 
  567. 	Store_common_popup:set_visible(false) 
  568. 	 
  569. 	if Store_weapon_loaded_from_crib then 
  570. 		store_weapon_lock_radial() 
  571. 	else 
  572. 		store_weapon_cancel_radial() 
  573. 	end 
  574. 	 
  575. 	if Store_weapon_loaded_from_crib then 
  576. 		-- exit the interface 
  577. 		pop_screen()		 
  578. 	end 
  579. end 
  580.  
  581. -- Handles navigation of any popups 
  582. function store_weapon_popup_nav(event, value) 
  583. 	if event == "nav_up" then	 
  584. 		Store_common_popup.list:move_cursor(-1)	 
  585. 	elseif event == "nav_down" then 
  586. 		Store_common_popup.list:move_cursor(1) 
  587. 	elseif event == "mouse_move" then 
  588. 		-- value contains the target_handle in this case 
  589. 		local new_index = Store_common_popup.list:get_button_index(value) 
  590. 		if new_index ~= 0 then 
  591. 			Store_common_popup.list:set_selection(new_index) 
  592. 			Store_common_popup.list:move_cursor(0, true) 
  593. 		end 
  594. 	else 
  595. 		--do nothing 
  596. 	end 
  597. end 
  598.  
  599. -- Handle navigation of the grid 
  600. function store_weapon_grid_nav(event, value) 
  601.  
  602. 	-- Reset all highlights 
  603. 	Store_common_hint_bar:set_highlight(0) 
  604.  
  605. 	local prev_index = Store_common_color_grid:return_selected_index() 
  606.  
  607. 	if event == "nav_up" then	 
  608. 		Store_common_color_grid:move_cursor(-2)	 
  609. 	elseif event == "nav_down" then 
  610. 		Store_common_color_grid:move_cursor(2) 
  611. 	elseif event == "nav_left" then 
  612. 		Store_common_color_grid:move_cursor(-1) 
  613. 	elseif event == "nav_right" then 
  614. 		Store_common_color_grid:move_cursor(1) 
  615. 	elseif event == "mouse_move" then 
  616. 		-- value contains the target_handle in this case 
  617. 		local new_index = Store_common_color_grid:get_data_index(value) 
  618. 		debug_print("vint", "new_index "..new_index.."old idx "..Old_index.."\n\n") 
  619. 		if new_index ~= 0 then 
  620. 			if Old_index ~= new_index then 
  621. 				Store_common_color_grid:set_selection(new_index) 
  622. 				Store_common_color_grid:move_cursor(0, false, false) 
  623. 				Old_index = new_index 
  624. 			end 
  625. 		end 
  626. 	else 
  627. 		--do nothing 
  628. 	end 
  629. 	 
  630. 	-- Get the currently selected weapon info 
  631. 	local idx = Store_common_color_grid:return_selected_index() 
  632. 	 
  633. 	-- if index hasn't changed, don't proceed 
  634. 	if idx == prev_index then 
  635. 		return 
  636. 	end 
  637. 	 
  638. 	local weapon_info = Weapon_grid_data[idx] 
  639. 		 
  640. 	if weapon_info ~= nil then 
  641. 		-- Preview the model of the selected weapon 
  642. 		store_weapon_change_weapon_preview(Weapon_grid_data.category, weapon_info.id, weapon_info.dual_wield, Store_weapon_is_cache)	 
  643. 		 
  644. 		Weapon_grid_idx = idx 
  645. 		 
  646. 		-- Show the weapon/upgrade price 
  647. 		if weapon_info.price == 0 or Store_weapon_is_cache == true then 
  648. 			Store_header:set_price(nil) 
  649. 		else 
  650. 			Store_header:set_price(weapon_info.price) 
  651. 		end 
  652. 		Store_header:set_respect(nil) 
  653. 	end 
  654. end 
  655.  
  656. function store_weapon_fail_msg(event) 
  657. 	Store_common_popup:nav_enable(false, nil, nil) 
  658. 	game_UI_audio_play("UI_Main_Menu_Select") 
  659. 	Not_popup_grp:set_alpha(1) 
  660. 	Store_weapon_not_bg_grp:set_alpha(1) 
  661. 	 
  662. 	-- Enable the active list or weapon radial if it's showing 
  663. 	if Current_tier ~= RADIAL_TIER then 
  664. 		store_weapon_enable_mouse(true) 
  665. 	else 
  666. 		if Hint_bar_mouse_input_tracker ~= nil then 
  667. 			Hint_bar_mouse_input_tracker:subscribe(true) 
  668. 			Radial_mouse_input_tracker:subscribe(true) 
  669. 		end 
  670. 	end 
  671. end 
  672.  
  673. -- Populate the active megalist menu, and hide the previous menu 
  674. -- 
  675. -- list_data: 		this table contains the data to populate the megalist 
  676. -- current_index: 	the current index in the menu that's selected 
  677. -- 
  678. function store_weapon_populate_list(list_data, current_index) 
  679. 	-- override the mega list width for standard def STORE_COMMON_LIST_SIZE 
  680. 	Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10, SCALE_FONT_STORE_WEAPON_LIST)	 
  681. 	--Active_list:set_visible(true) 
  682. 	--local hint_data = { 
  683. 	--	{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  684. 	--} 
  685. 	--Store_common_hint_bar:set_hints(hint_data)  
  686. 	 
  687. 	-- Add mouse input subscriptions 
  688. 	if Mouse_input_tracker ~= 0 then 
  689. 		Hint_bar_mouse_input_tracker:remove_all() 
  690. 		Store_common_hint_bar:add_mouse_inputs("store_weapon", Hint_bar_mouse_input_tracker) 
  691. 		 
  692. 		Mouse_input_tracker:remove_all() 
  693. 		Radial_mouse_input_tracker:remove_all() 
  694. 		Active_list:set_store("store_weapon") 
  695. 		Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  696. 		store_weapon_enable_mouse(true) 
  697. 		-- 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) 
  698. 		if Skip_next_populate == true then 
  699. 			Skip_next_populate = false 
  700. 			Mouse_input_tracker:subscribe(false) 
  701. 			Hint_bar_mouse_input_tracker:subscribe(true) 
  702. 			if Restore_weapon_radial_inputs then 
  703. 				Store_weapon_radial:add_mouse_inputs("store_weapon", Radial_mouse_input_tracker, 50) 
  704. 				Radial_mouse_input_tracker:subscribe(true) 
  705. 			end 
  706. 		end 
  707. 		Restore_weapon_radial_inputs = false 
  708. 	end	 
  709. 	 
  710. 	 
  711. end 
  712.  
  713. -- User is going back to top level menu 
  714. function store_weapon_cancel_radial() 
  715. 	Store_header:set_price(nil) 
  716. 	Store_header:pop_title() 
  717. 	store_weapon_close_radial() 
  718. 	 
  719. 	game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  720. 	 
  721. 	-- Hide weapon and stats/description 
  722. 	store_weapon_cover_weapon(false) 
  723. 	--Weapon_stats_grp:set_visible(false) 
  724. 		 
  725. 	-- Hide the weapon preview 
  726. 	store_weapon_hide_weapon() 
  727. 	Current_tier = MENU_TIER 
  728. end 
  729.  
  730. -- Close the ammo purchasing interface 
  731. -- 
  732. function store_weapon_close_radial()	 
  733. 	-- Show megalist menu 
  734. 	Active_list:set_visible(true) 
  735. 	 
  736. 	local hint_data = { 
  737. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  738. 	} 
  739. 	Store_common_hint_bar:set_hints(hint_data) 	 
  740. 	 
  741. 	-- Hide radial and stop input/thread. 
  742. 	store_weapon_inventory_hide() 
  743. 	Current_tier = MENU_TIER 
  744. end 
  745.  
  746. -- Ammo purchasing ****************************************************************************************** 
  747.  
  748. -- Open the ammo purchasing radial menu. 
  749. -- 
  750. function store_weapon_ammo_open_radial(menu_data) 
  751. 	Active_list:set_visible(false) 
  752. 		 
  753. 	store_weapon_stats_update(1, false)	 
  754. 	 
  755. 	store_weapon_cover_weapon(true) 
  756. 	store_weapon_hide_weapon() 
  757. 	 
  758. 	Store_weapon_is_cache = false 
  759. 	 
  760. 	-- Set the callback to use when the user selects a cateogory from the radial menu 
  761. 	Store_weapon_inventory.selected_cb = store_weapon_ammo_purchase 
  762. 	Store_weapon_inventory.nav_cb = store_weapon_ammo_nav 
  763. 	 
  764. 	Store_weapon_ammo_info = {} 
  765. 	Store_weapon_thrown_ammo_info = {} 
  766. 	vint_dataresponder_request("store_weapon_populate_ammo", "store_weapon_ammo_add_items", 0)	 
  767. 	 
  768. 	-- Disable first two slots that don't use ammo 
  769. 	Store_weapon_radial:slot_disable(0) 
  770. 	Store_weapon_radial:slot_disable(1) 
  771. 	 
  772. 	-- Show grenades 
  773. 	Store_weapon_radial:show_dpad_menu(true) 
  774. 	Store_weapon_radial:set_anchor(Radial_store_x,395) 
  775. 	 
  776. 	-- Disable any slots where we can't buy ammo 
  777. 	for i = 2, 7 do 
  778. 		local ammo_info = store_weapon_ammo_find_by_id(i) 
  779. 		if ammo_info == nil then 
  780. 			Store_weapon_radial:slot_disable(i) 
  781. 		else 
  782. 			Store_weapon_radial:slot_enable(i) 
  783. 		end 
  784. 		 
  785. 	end 
  786. 		 
  787. 	-- Open the radial menu 
  788. 	store_weapon_inventory_show(menu_data) 
  789.  
  790. end 
  791.  
  792. function store_weapon_ammo_nav(slot_id) 
  793. 	-- Can't purchase ammo for some categories 
  794. 	if slot_id < 2 then 
  795. 		Store_header:set_price(nil)	 
  796. 		return 
  797. 	end 
  798.  
  799. 	local ammo_info 
  800.  
  801. 	-- is this thrown or normal weapon? 
  802. 	if slot_id < 8 then 
  803. 		ammo_info = store_weapon_ammo_find_by_id(slot_id) 
  804. 	else 
  805. 		ammo_info = store_weapon_thrown_ammo_find_by_id(slot_id - 8) 
  806. 	end 
  807. 	 
  808. 	-- ammo is not available for this category 
  809. 	if ammo_info == nil then 
  810. 		Store_header:set_price(nil)	 
  811. 		return 
  812. 	end 
  813. 	 
  814. 	-- Show the ammo price 
  815. 	if ammo_info.price == 0 then 
  816. 		Store_header:set_price(nil) 
  817. 	else 
  818. 		Store_header:set_price(ammo_info.price) 
  819. 	end 
  820. 	 
  821. 	store_weapon_stats_update(slot_id, false) 
  822. 	 
  823. end 
  824.  
  825. function store_weapon_stats_update(slot_id, show_available, force_update) 
  826. 	 
  827. 	-- If force_update is set to true, we want to stay on the same slot id 
  828. 	if force_update == true then 
  829. 		if slot_id == -1 then 
  830. 			slot_id = Prev_slot 
  831. 		end 
  832. 	else  
  833. 		if slot_id == Prev_slot then 
  834. 			return 
  835. 		end 
  836. 		 
  837. 		Prev_slot = slot_id 
  838. 	end 
  839. 	 
  840. 	Stats_initialized = true 
  841. 	 
  842. 	--[[Info in Weapon_grid_data 
  843. 	 
  844. 		icon = icon_name, 
  845. 		label = name_str, 
  846. 		color = { red = 1, green = 1, blue = 1 }, 
  847. 		is_owned = own, 
  848. 		id = id, 
  849. 		dual_wield = dual_wield, 
  850. 		price = price, 
  851. 		level = upgrade_level, 
  852. 		level_desc = desc_crc, 
  853. 		is_checked = false, 
  854. 		equipped = equipped, 
  855. 		 
  856. 	]]-- 
  857. 	 
  858. 	-- Get new data for Weapon_grid_data 
  859. 	store_weapon_populate_weapon_grid(Store_weapon_categories[slot_id].category, slot_id) 
  860. 	 
  861. 	-- Display slot info 
  862. 	local header_txt = Vdo_base_object:new("header_txt", 0, Store_weapon_doc_handle) 
  863. 	local owned_grp = Vdo_base_object:new("owned_grp", 0, Store_weapon_doc_handle) 
  864. 	local available_grp = Vdo_base_object:new("available_grp", 0, Store_weapon_doc_handle) 
  865. 	local owned_txt = Vdo_base_object:new("owned_txt", 0, Store_weapon_doc_handle) 
  866. 	local available_txt = Vdo_base_object:new("available_txt", 0, Store_weapon_doc_handle) 
  867. 	local base_weapon_txt = Vdo_base_object:new("base_weapon_txt", 0, Store_weapon_doc_handle) 
  868. 	local ammo_txt = Vdo_base_object:new("ammo_text", 0, Store_weapon_doc_handle) 
  869. 	local base_txt_x, base_txt_y = base_weapon_txt:get_anchor()	 
  870. 	local base_txt_width, base_txt_height = element_get_actual_size(base_weapon_txt.handle) 
  871. 	local num_weapons = #Weapon_grid_data 
  872. 	local new_x, new_y = base_txt_x, base_txt_y 
  873. 	local WEAPON_TXT_BUFFER_HD = 1	 
  874. 	local WEAPON_TXT_BUFFER_SD = 10	 
  875. 	local HEADER_TXT_MAX_WIDTH_HD = 530 
  876. 	local HEADER_TXT_MAX_WIDTH_SD = 350 
  877. 	local Weapon_txt_buffer = WEAPON_TXT_BUFFER_HD 
  878. 	local max_header_width = HEADER_TXT_MAX_WIDTH_HD	 
  879. 	 
  880. 	-- Set headers 
  881. 	header_txt:set_text(Store_weapon_categories[slot_id].label)	 
  882. 	owned_txt:set_text("STORE_WEAPON_OWNED")	 
  883. 	available_txt:set_text("STORE_WEAPON_AVAILABLE")		 
  884. 	base_weapon_txt:set_visible(false)	 
  885. 	 
  886. 	-- Resize header text to fit in other languages 
  887. 	if vint_is_std_res() then 
  888. 		max_header_width = HEADER_TXT_MAX_WIDTH_SD 
  889. 		base_weapon_txt:set_property("wrap_width", 320) 
  890. 		Weapon_txt_buffer = WEAPON_TXT_BUFFER_SD 
  891. 	end 
  892. 	 
  893. 	header_txt:set_scale(1, 1)	 
  894. 	local header_width, header_height = element_get_actual_size(header_txt.handle) 
  895. 	 
  896. 	if header_width >= max_header_width then 
  897. 		local text_scale = max_header_width/header_width 
  898. 		header_txt:set_scale(text_scale, text_scale) 
  899. 	end 
  900. 	 
  901. 	new_y = new_y + base_txt_height + Weapon_txt_buffer 
  902. 	 
  903. 	-- Destroy clones and reset tables 
  904. 	for i = 1, #Weapons_owned do 
  905. 		Weapons_owned[i]:object_destroy()	 
  906. 	end 
  907. 	Weapons_owned = {} 
  908. 	 
  909. 	for i = 1, #Weapons_available do 
  910. 		Weapons_available[i]:object_destroy() 
  911. 	end	 
  912. 	Weapons_available = {} 
  913. 	 
  914. 	-- Create "owned" list 
  915. 	local num_weapons_owned = 1 
  916. 	for i = 1, num_weapons do 
  917. 		local info = Weapon_grid_data[i] 
  918. 		if info.is_owned == true then 
  919. 			--clone text			 
  920. 			local cur_weapon 
  921. 			local skip_dual_item = false 
  922. 			if info.dual_wield == true then 
  923. 				skip_dual_item = true 
  924. 				cur_weapon = Weapons_owned[num_weapons_owned-1] 
  925. 			else 
  926. 				cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle) 
  927. 			end 
  928. 					 
  929. 			-- Append level to each weapon and equipped status 
  930. 			local body, insert_values 
  931. 			 
  932. 			-- Note: incrementing weapon level because code uses base 0 
  933. 			if info.equipped == true then 
  934. 				local color = "[format][color:#B8492F]" 
  935. 				if Store_weapon_loaded_from_crib then 
  936. 					color = "[format][color:#9400c5]" 
  937. 				end 
  938. 				insert_values = {[0] = info.label, [1] = info.level + 1, [2] = color } 
  939. 				body = vint_insert_values_in_string("STORE_WEAPON_OWNED_EQUIPPED", insert_values) 
  940. 				--body = vint_insert_values_in_string("{0} !!LEVEL {1} [format][color:#B8492F](!!EQUIPPED)[/format]", insert_values) 
  941. 			else  
  942. 				insert_values = {[0] = info.label, [1] = info.level + 1} 
  943. 				body = vint_insert_values_in_string("STORE_WEAPON_OWNED_NOT_EQUIPPED", insert_values) 
  944. 			end 
  945. 			 
  946. 			cur_weapon:set_text(body)			 
  947. 						 
  948. 			local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle) 
  949. 									 
  950. 			cur_weapon:set_anchor(new_x, new_y) 
  951. 			 
  952. 			new_y = new_y + cur_weapon_height + Weapon_txt_buffer 
  953. 			 
  954. 			cur_weapon:set_visible(true) 
  955. 			 
  956. 			--Store to global for cleanup 
  957. 			if skip_dual_item == false then 
  958. 				Weapons_owned[num_weapons_owned] = cur_weapon 
  959. 				num_weapons_owned = num_weapons_owned + 1 
  960. 			end 
  961. 		end 
  962. 	end	 
  963. 	 
  964. 	-- Display none if no weapons are owned 
  965. 	if Weapons_owned[1] == nil then 
  966. 		local cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle)  
  967. 		 
  968. 		cur_weapon:set_text("LOCALIZE_NONE")			 
  969. 		 
  970. 		local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle)	 
  971. 		 
  972. 		cur_weapon:set_anchor(new_x, new_y) 
  973. 		 
  974. 		new_y = new_y + cur_weapon_height + Weapon_txt_buffer	 
  975. 		 
  976. 		cur_weapon:set_visible(true) 
  977. 		 
  978. 		--Store for cleanup 
  979. 		Weapons_owned[1] = cur_weapon 
  980. 	end 
  981. 	 
  982. 	-- Get positioning for next list 
  983. 	local avail_x, avail_y = available_grp:get_anchor() 
  984. 	 
  985. 	new_y = new_y + Weapon_txt_buffer * 2		 
  986. 	 
  987. 	available_grp:set_anchor(avail_x, new_y)  
  988. 	 
  989. 	-- Create "available" list 
  990. 	local num_available_weapons = 1 
  991. 	for i = 1, num_weapons do 
  992. 		local info = Weapon_grid_data[i] 
  993. 		if info.is_owned == false then 
  994. 			--clone text 
  995. 			local cur_weapon = Vdo_base_object:clone(base_weapon_txt.handle) 
  996. 			 
  997. 			cur_weapon:set_text(info.label)			 
  998. 			 
  999. 			local cur_weapon_width, cur_weapon_height = element_get_actual_size(cur_weapon.handle) 
  1000. 			new_y = new_y + cur_weapon_height + Weapon_txt_buffer	 
  1001. 						 
  1002. 			cur_weapon:set_anchor(new_x, new_y) 
  1003. 			 
  1004. 			cur_weapon:set_visible(true) 
  1005. 			 
  1006. 			--Store to global for cleanup 
  1007. 			Weapons_available[num_available_weapons] = cur_weapon 
  1008. 			num_available_weapons = num_available_weapons + 1 
  1009. 		end 
  1010. 	end	 
  1011.  
  1012. 	-- Show available weapons group? 
  1013. 	if show_available ~= nil then 
  1014. 		if #Weapons_available > 0 then 
  1015. 			available_grp:set_visible(show_available)	 
  1016. 			for i = 1, #Weapons_available do 
  1017. 				Weapons_available[i]:set_visible(show_available) 
  1018. 			end 
  1019. 		else 
  1020. 			available_grp:set_visible(false)	 
  1021. 		end 
  1022. 	else 
  1023. 		if Weapons_available[1] ~= nil then 
  1024. 			available_grp:set_visible(true)	 
  1025. 		else	 
  1026. 			available_grp:set_visible(false)	 
  1027. 		end 
  1028. 	end	 
  1029. 	 
  1030. 	--is the list of weapons past safe frame?  If so, move it up by that amount 
  1031.  
  1032. 	local new_stats_y = STORE_WEAPON_STATS_GRP_Y 
  1033. 	 
  1034. 	if new_y > STORE_WEAPON_STATS_GRP_MAX then 
  1035. 		new_stats_y = new_stats_y - (new_y - STORE_WEAPON_STATS_GRP_MAX) 
  1036. 	end 
  1037. 	 
  1038. 	if vint_is_std_res() then 
  1039. 		Slot_stats_grp:set_anchor(STORE_WEAPON_STATS_GRP_SD_X, new_stats_y) 
  1040. 	else 
  1041. 		Slot_stats_grp:set_anchor(STORE_WEAPON_STATS_GRP_X, new_stats_y) 
  1042. 	end 
  1043. 	 
  1044. end 
  1045.  
  1046. function store_weapon_populate_weapon_grid(category, slot) 
  1047. 	-- Initialize data for grid 
  1048. 	Weapon_grid_data = {} 
  1049. 	Weapon_grid_data.category = category 
  1050. 	 
  1051. 	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	 
  1052. end 
  1053.  
  1054.  
  1055. function store_weapon_ammo_find_by_id(id) 
  1056. 	for i = 1, #Store_weapon_ammo_info do 
  1057. 		if Store_weapon_ammo_info[i].id == id then 
  1058. 			debug_print("store_weapon","returning ammo info with name "..Store_weapon_ammo_info[i].icon_name.."\n") 
  1059. 			return Store_weapon_ammo_info[i] 
  1060. 		end 
  1061. 	end 
  1062. 	 
  1063. 	return nil 
  1064. end 
  1065.  
  1066. function store_weapon_thrown_ammo_find_by_id(id) 
  1067. 	for i = 1, #Store_weapon_thrown_ammo_info do 
  1068. 		if Store_weapon_thrown_ammo_info[i].thrown_wpn_id == id then 
  1069. 			return Store_weapon_thrown_ammo_info[i] 
  1070. 		end 
  1071. 	end 
  1072. 	 
  1073. 	return nil 
  1074. end 
  1075.  
  1076. -- Callback for data responder that populates ammo information for each category. 
  1077. -- 
  1078. function store_weapon_ammo_add_items(unused, icon_name, unused, price, clip_size, current_amount, max_amount, id, thrown_wpn_id) 
  1079.  
  1080. 	if thrown_wpn_id == nil or thrown_wpn_id == -1 then 
  1081.  
  1082. 		local index = #Store_weapon_ammo_info + 1 
  1083.  
  1084. 		Store_weapon_ammo_info[index] = { 
  1085. 			price = price, icon_name = icon_name, clip_size = clip_size, ammo_current = current_amount, ammo_max = max_amount, id = id, thrown_wpn_id = nil 
  1086. 		} 
  1087. 	else 
  1088. 	 
  1089. 		local index = #Store_weapon_thrown_ammo_info + 1 
  1090.  
  1091. 		-- SEH: make const for 1000 (special value from code) 
  1092. 		Store_weapon_thrown_ammo_info[index] = { 
  1093. 			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 
  1094. 		}	 
  1095. 	end 
  1096. end 
  1097.  
  1098. -- Purchase ammo from the radial menu. 
  1099. -- 
  1100. -- slot:		the slot number chosen in the radial menu. 
  1101. -- 
  1102. function store_weapon_ammo_purchase(slot) 
  1103.  
  1104. 	-- Can't purchase ammo for some categories 
  1105. 	if slot < 2 then 
  1106. 		return 
  1107. 	end 
  1108.  
  1109. 	local ammo_info 
  1110.  
  1111. 	-- is this thrown or normal weapon? 
  1112. 	if slot < 8 then 
  1113. 		ammo_info = store_weapon_ammo_find_by_id(slot) 
  1114. 	else 
  1115. 		ammo_info = store_weapon_thrown_ammo_find_by_id(slot - 8) 
  1116. 	end 
  1117. 	 
  1118. 	-- ammo is not available for this category 
  1119. 	if ammo_info == nil then 
  1120. 		return 
  1121. 	end 
  1122. 	 
  1123. 	-- Check if we have space for ammo, and enough money. 
  1124. 	if ammo_info.ammo_current < ammo_info.ammo_max then 
  1125. 		if Store_common_player_cash >= ammo_info.price then 
  1126. 			local saved_cash = Store_common_player_cash 
  1127. 			 
  1128. 			-- Make the purchase. 
  1129. 			store_weapon_purchase_ammo(ammo_info.id, ammo_info.thrown_wpn_id, ammo_info.clip_size, ammo_info.price) 
  1130. 			ammo_info.ammo_current = ammo_info.ammo_current + ammo_info.clip_size 
  1131.  
  1132. 			if ammo_info.ammo_current > ammo_info.ammo_max then 
  1133. 				ammo_info.ammo_current = ammo_info.ammo_max 
  1134. 			end 
  1135. 			 
  1136. 			--play the purchase sound 
  1137. 			ui_audio_post_event("ammo_purchase") 
  1138. 			 
  1139. 			-- Refresh the ammo information 
  1140. 			Store_weapon_ammo_info = {} 
  1141. 			Store_weapon_thrown_ammo_info = {}			 
  1142. 			vint_dataresponder_request("store_weapon_populate_ammo", "store_weapon_ammo_add_items", 0)		 
  1143.  
  1144. 			-- refresh the stats info 
  1145. 			store_weapon_stats_update(-1, false, true)	 
  1146. 			 
  1147. 		else 
  1148. 			Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1149. 			Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  1150. 			Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")		 
  1151. 			Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  1152. 			Not_popup_grp:set_alpha(.5)	 
  1153. 			Store_weapon_not_bg_grp:set_alpha(.5) 
  1154. 			game_UI_audio_play("UI_HUD_HELP") 
  1155. 			store_weapon_enable_mouse(false) 
  1156. 			return		 
  1157. 		end 
  1158. 	else 
  1159. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1160. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  1161. 		Store_common_popup:set_text("WPNSTOR_TEXT_MAX_AMMO_STORE")		 
  1162. 		Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  1163. 		Not_popup_grp:set_alpha(.5)		 
  1164. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  1165. 		game_UI_audio_play("UI_HUD_HELP") 
  1166. 		store_weapon_enable_mouse(false) 
  1167. 		return			 
  1168. 	end 
  1169. 	 
  1170. end 
  1171.  
  1172. -- Weapon purchasing and upgrading ****************************************************************************************** 
  1173.  
  1174. -- Open the weapon purchasing and upgrading radial menu. 
  1175. -- 
  1176. function store_weapon_purchase_open_radial(menu_data) 
  1177. 	Active_list:set_visible(false) 
  1178. 	 
  1179. 	store_weapon_cover_weapon(true) 
  1180. 	store_weapon_hide_weapon() 
  1181. 	 
  1182. 	-- Set the hint based on the platform 
  1183. 	local hint_data = {} 
  1184. 	if game_get_platform() == "PC" then 
  1185. 		hint_data = { 
  1186. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1187. 		} 
  1188. 	else  
  1189. 		hint_data = { 
  1190. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1191. 			{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  1192. 			{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"}, 
  1193. 		} 
  1194. 	end 
  1195. 	Store_common_hint_bar:set_hints(hint_data) 	 
  1196. 	if Hint_bar_mouse_input_tracker ~= nil then 
  1197. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  1198. 	end 
  1199. 	 
  1200. 	Store_weapon_is_cache = false 
  1201. 	 
  1202. 	-- Set the callback to use when the user selects a cateogory from the radial menu 
  1203. 	Store_weapon_inventory.selected_cb = store_weapon_grid_open 
  1204. 	Store_weapon_inventory.nav_cb = store_weapon_purchase_nav 
  1205. 	 
  1206. 	-- Disable the unarmed slot 
  1207. 	Store_weapon_radial:slot_disable(0) 
  1208. 	 
  1209. 	-- Show grenades 
  1210. 	Store_weapon_radial:show_dpad_menu(true) 
  1211. 	Store_weapon_radial:set_anchor(Radial_store_x,395) 
  1212. 	 
  1213. 	-- Enable or disable slots based on availability 
  1214. 	for i = 1, 7 do 
  1215. 		-- Initialize data for grid 
  1216. 		Weapon_grid_data = {} 
  1217. 		 
  1218. 		local category = Store_weapon_categories[i].category 
  1219. 		 
  1220. 		-- if category == "thrown" == true then 
  1221. 			-- vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category) 
  1222. 		-- else 
  1223. 			vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  1224. 		--end	 
  1225. 		 
  1226. 		-- If there are no choices, then disable 
  1227. 		if #Weapon_grid_data == 0 then 
  1228. 			Store_weapon_radial:slot_disable(i) 
  1229. 		else 
  1230. 			Store_weapon_radial:slot_enable(i) 
  1231. 		end 
  1232. 		 
  1233. 		Store_weapon_categories[i].info = Weapon_grid_data 
  1234. 		 
  1235. 	end	 
  1236. 	 
  1237. 	-- Open the radial menu 
  1238. 	store_weapon_inventory_show(menu_data)	 
  1239. end 
  1240.  
  1241. function store_weapon_purchase_nav(slot_id) 
  1242. 	 
  1243. 	store_weapon_stats_update(slot_id) 
  1244. 	store_weapon_cover_weapon(true) 
  1245.  
  1246. end 
  1247.  
  1248.  
  1249. -- Purchase or upgrade weapons from the radial menu. 
  1250. -- 
  1251. -- slot:		the slot number chosen in the radial menu. 
  1252. -- 
  1253. function store_weapon_grid_open(slot) 
  1254. 	debug_print("store_weapon", "called store_weapon_grid_open\n")	 
  1255.  
  1256. 	Current_slot = slot 
  1257. 	 
  1258. 	Old_index = 0 
  1259. 	 
  1260. 	-- Can't purchase some categories 
  1261. 	if slot < 1 then 
  1262. 		return 
  1263. 	end 
  1264. 		 
  1265. 	-- Initialize data for grid 
  1266. 	Weapon_grid_data = {} 
  1267. 	Weapon_grid_idx = 1 
  1268. 	 
  1269. 	-- Get the category name string for the chosen slot. 
  1270. 	local category = Store_weapon_categories[slot].category 
  1271. 	 
  1272. 	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 
  1273.  
  1274. 	-- If there are no choices, don't go to grid 
  1275. 	if #Weapon_grid_data == 0 then 
  1276. 		debug_print("store_weapon", "not opening grid because there are no choices\n")	 
  1277. 		return 
  1278. 	end	 
  1279. 	 
  1280. 	store_weapon_grid_populate_weapon_stats(Weapon_grid_idx)	 
  1281. 	 
  1282. 	-- set the titles on top 
  1283. 	Store_header:push_title( nil, Store_weapon_categories[slot].label )	 
  1284. 	 
  1285. 	-- display the grid	 
  1286. 	Weapon_grid_data.category = category 
  1287. 	Store_common_color_grid:set_highlight_color(Weapon_store_highlight_color) 
  1288. 	Store_common_color_grid:draw_items(Weapon_grid_data, Weapon_grid_idx, 3, 3, 120, 100, 40, nil, nil, false) 
  1289. 	Store_common_color_grid:set_visible(true) 
  1290. 	Store_common_color_grid:nav_enable(true, "store_weapon_grid_selected", "store_weapon_grid_nav")	 
  1291. 	--Weapon_stats_grp:set_visible(true) 
  1292. 	 
  1293. 	-- hide grid highlighted name 
  1294. 	Store_common_color_grid.highlight_name:set_visible(false) 
  1295. 	 
  1296. 	-- Close the radial before we show the grid. 
  1297. 	store_weapon_close_radial() 
  1298. 	 
  1299. 	-- Hide the megalist (close_radial function unhides it). 
  1300. 	Active_list:set_visible(false) 
  1301. 	local hint_data = { 
  1302. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1303. 	} 
  1304. 	Store_common_hint_bar:set_hints(hint_data) 	 
  1305. 	 
  1306. 	-- Get the currently selected weapon info 
  1307. 	local idx = Store_common_color_grid:return_selected_index() 
  1308. 	local weapon_info = Weapon_grid_data[idx]	 
  1309. 	 
  1310. 	-- Preview the model of the selected weapon	 
  1311. 	store_weapon_change_weapon_preview(Weapon_grid_data.category, weapon_info.id, weapon_info.dual_wield, Store_weapon_is_cache)		 
  1312. 	 
  1313. 	-- Show the weapon/upgrade price 
  1314. 	if weapon_info.price == 0 or Store_weapon_is_cache == true then 
  1315. 		Store_header:set_price(nil) 
  1316. 	else 
  1317. 		Store_header:set_price(weapon_info.price) 
  1318. 	end 
  1319.  
  1320. 	-- For thrown weapons, bypass the grid 
  1321. 	if category == "thrown" then 
  1322. 		Current_tier = GRENADE_UPGRADE_TIER 
  1323. 		store_weapon_grid_selected("select") 
  1324. 		if Mouse_input_tracker ~= 0 then 
  1325. 			Mouse_input_tracker:subscribe(false) 
  1326. 		end 
  1327. 		if Radial_mouse_input_tracker ~= nil then 
  1328. 			Radial_mouse_input_tracker:subscribe(false) 
  1329. 		end 
  1330. 	else 
  1331. 		Current_tier = WEAPON_TIER 
  1332. 		if Mouse_input_tracker ~= 0 then 
  1333. 			Mouse_input_tracker:subscribe(false) 
  1334. 		end 
  1335. 		if Radial_mouse_input_tracker ~= nil then 
  1336. 			Radial_mouse_input_tracker:subscribe(false) 
  1337. 		end 
  1338. 	end 
  1339. end 
  1340.  
  1341. function store_weapon_grid_populate_weapon_stats(idx) 
  1342. 	-- Get the currently selected weapon info 
  1343. 	local weapon_info = Weapon_grid_data[idx]		 
  1344. 	local weapon_title = Vdo_base_object:new("weapon_title", 0, Store_weapon_doc_handle) 
  1345. 	local weapon_level = Vdo_base_object:new("weapon_level", 0, Store_weapon_doc_handle) 
  1346. 	local level_desc = Vdo_base_object:new("level_desc", 0, Store_weapon_doc_handle) 
  1347. 	 
  1348. 	if vint_is_std_res() then 
  1349. 		level_desc:set_property("wrap_width",340) 
  1350. 	end 
  1351.  
  1352. 	-- Display weapon stats 
  1353. 	weapon_title:set_text(weapon_info.label) 
  1354. 	local insert = { [0] = Weapon_grid_data[idx].level + 1 } 
  1355. 	local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert)			 
  1356. 	weapon_level:set_text(body) 
  1357. 	level_desc:set_text_crc(weapon_info.level_desc) 
  1358. 	 
  1359. 	--Weapon_stats_grp:set_visible(true) 
  1360. end 
  1361.  
  1362. function store_weapon_cover_weapon(show_slot_stats) 
  1363. 	-- make background so it covers the weapon 
  1364. 	Weapon_bg_grp:set_property("background", false) 
  1365. 	bg_saints_set_background(false) 
  1366. 	 
  1367. 	-- this should be the situations when we don't want to show stats too 
  1368. 	Weapon_stats_grp:set_visible(false) 
  1369. 	 
  1370. 	Slot_stats_grp:set_visible(show_slot_stats and Stats_initialized)	 
  1371. 	 
  1372. 	-- SEH: 6/28/11: cut zoom/rotate 
  1373. 	-- Hide zoom/rotate hint 
  1374. 	--Hint_bar_rotate:set_visible(false)	 
  1375. 	 
  1376. end 
  1377.  
  1378. function store_weapon_uncover_weapon() 
  1379. 	-- make background so it is behind the weapon 
  1380. 	Weapon_bg_grp:set_property("background", true) 
  1381. 	bg_saints_set_background(true) 
  1382. 	 
  1383. 	-- this should be the situations when we don't want to show stats too 
  1384. 	Weapon_stats_grp:set_visible(true)	 
  1385. 		 
  1386. 	-- determine if we're at the grid or upgrade level 
  1387. 	if Store_common_color_grid:get_visible() == true then 
  1388. 		local idx = Weapon_grid_idx 
  1389. 		if idx ~= nil and idx >= 1 then 
  1390. 			store_weapon_grid_populate_weapon_stats(idx) 
  1391. 		end 
  1392. 	else		 
  1393. 		-- Show the correct stats/description 
  1394. 		store_weapon_upgrade_populate_weapon_stats(Store_weapon_current_info.level, Store_weapon_current_info.desc)	 
  1395. 	end 
  1396. 	 
  1397. 	Slot_stats_grp:set_visible(false) 
  1398. 	 
  1399. 	-- SEH: 6/28/11: cut zoom/rotate		 
  1400. 	-- Show zoom/rotate hint 
  1401. 	--Hint_bar_rotate:set_visible(true) 
  1402. 	 
  1403. 	Store_weapon_is_loading = false 
  1404. 	 
  1405. end 
  1406.  
  1407.  
  1408. 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) 
  1409.  
  1410. 	local grid_idx = #Weapon_grid_data + 1 
  1411. 	 
  1412. 	Weapon_grid_data[grid_idx] = { 
  1413. 		icon = icon_name, 
  1414. 		label = name_str, 
  1415. 		color = { red = 1, green = 1, blue = 1 }, 
  1416. 		is_owned = own, 
  1417. 		id = id, 
  1418. 		dual_wield = dual_wield, 
  1419. 		price = price, 
  1420. 		level = upgrade_level, 
  1421. 		level_desc = desc_crc, 
  1422. 		is_checked = own, 
  1423. 		equipped = equipped, 
  1424. 	}	 
  1425. 	 
  1426. 	if equipped == true then 
  1427. 		Weapon_grid_idx = grid_idx 
  1428. 	end 
  1429.  
  1430. 	if	Store_weapon_is_cache then 
  1431. 		Weapon_grid_data[grid_idx].is_checked = false 
  1432. 	end	 
  1433. end 
  1434.  
  1435. 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) 
  1436. 	 
  1437. 	local grid_idx = #Weapon_grid_data + 1 
  1438. 	 
  1439. 	Weapon_grid_data[grid_idx] = { 
  1440. 		icon = icon_name, 
  1441. 		label = name_str, 
  1442. 		color = { red = 1, green = 1, blue = 1 }, 
  1443. 		is_owned = own, 
  1444. 		id = id, 
  1445. 		dual_wield = dual_wield, 
  1446. 		price = price, 
  1447. 		level = upgrade_level, 
  1448. 		level_desc = desc_crc, 
  1449. 		is_checked = own, 
  1450. 		equipped = equipped,		 
  1451. 	} 
  1452. 	 
  1453. 	--Store_weapon_categories[slot].info = Weapon_grid_data[grid_idx] 
  1454. 	 
  1455. 	if equipped == true then 
  1456. 		Weapon_grid_idx = grid_idx 
  1457. 	end	 
  1458. 	 
  1459. 	if	Store_weapon_is_cache then 
  1460. 		Weapon_grid_data[grid_idx].is_checked = false 
  1461. 	end	 
  1462. end 
  1463.  
  1464. -- Callback to handle when the player is on the weapon purchase/upgrade grid and makes a selection or cancels. 
  1465. -- 
  1466. function store_weapon_grid_selected(event) 
  1467.  
  1468. 	-- if the weapon is still loading, don't allow grid selection 
  1469. 	if store_weapon_allow_grid_input() == false then 
  1470. 		return 
  1471. 	end 
  1472.  
  1473. 	-- Reset skip flag if the grid is used 
  1474. 	if Mouse_input_tracker ~= 0 then 
  1475. 		Skip_next_populate = false 
  1476. 	end 
  1477. 	 
  1478. 	--Did the player select a weapon? 
  1479. 	if event == "select" or event == "mouse_click" then 
  1480. 	 
  1481. 		local weapon_info = Weapon_grid_data[Store_common_color_grid:get_selection()]	 
  1482. 		 
  1483. 		-- Save off currently selected grid index, so we can know which one to start at when backing out of the upgrade menu. 
  1484. 		Weapon_grid_idx = Store_common_color_grid:get_selection() 
  1485. 	 
  1486. 		-- If we're in the weapon cache, we're just equipping it, so no need for the other checks done below for purchasing. 
  1487. 		if Store_weapon_is_cache then 
  1488. 			 
  1489. 			game_UI_audio_play("UI_Main_Menu_Select") 
  1490. 			-- Equip weapon if in cache 
  1491. 			store_weapon_purchase_weapon(Weapon_grid_data.category, weapon_info.id, Store_weapon_is_cache, 0)				 
  1492. 			 
  1493. 			-- Go back to main menu. 
  1494. 			Store_common_color_grid:nav_enable(false, nil, nil) 
  1495. 			Store_common_color_grid:set_visible(false) 
  1496. 			Store_common_color_grid:cleanup() 
  1497. 			 
  1498. 			store_weapon_cover_weapon(true)				 
  1499. 			 
  1500. 			-- do this so holding down the button doesn't cause repeated actions 
  1501. 			Input_tracker:subscribe(false)		 
  1502. 			Input_tracker:subscribe(true)	 
  1503. 			 
  1504. 			-- pop off header titles 
  1505. 			Store_header:pop_title() 
  1506. 			--Store_header:pop_title() 
  1507. 			Store_header:set_price(nil) 
  1508. 			 
  1509. 			--Active_list:set_visible(true) 
  1510. 			-- Open the radial menu 
  1511. 			store_weapon_inventory_show()	 
  1512. 			 
  1513. 			if Store_weapon_loaded_from_crib then 
  1514. 				store_weapon_unlock_radial() 
  1515. 			end 
  1516. 			 
  1517. 			return 
  1518. 		end 
  1519. 	 
  1520. 		-- Hide the grid 
  1521. 		Store_common_color_grid:nav_enable(false, nil, nil) 
  1522. 		Store_common_color_grid:set_visible(false) 
  1523. 		Store_common_color_grid:cleanup()	 
  1524. 		 
  1525. 		game_UI_audio_play("UI_Main_Menu_Select") 
  1526. 		 
  1527. 		Store_weapon_current_info = weapon_info 
  1528. 		-- We are now going to go to another menu (megalist) with the upgrade levels	 
  1529. 		store_weapon_upgrade_show(Weapon_grid_data.category, weapon_info.id)	 
  1530. 		 
  1531. 	else 
  1532. 			 
  1533. 		Old_index = 0 
  1534.  
  1535. 		-- Go back to main menu. 
  1536. 		Store_common_color_grid:nav_enable(false, nil, nil) 
  1537. 		Store_common_color_grid:set_visible(false) 
  1538. 		Store_common_color_grid:cleanup() 
  1539. 		 
  1540. 		store_weapon_cover_weapon(true)				 
  1541. 		store_weapon_hide_weapon()		 
  1542. 				 
  1543. 		-- And hide the weapon as well 
  1544. 		--store_weapon_hide_weapon()		 
  1545. 		 
  1546. 		-- If we came from the crib, we need to pop this doc off the stack 
  1547. 		--[[if Store_weapon_loaded_from_crib then	 
  1548. 			store_lock_controls()			 
  1549. 			pop_screen() 
  1550. 			return 
  1551. 		end	]]		 
  1552. 		 
  1553. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  1554. 		 
  1555. 		-- pop off header titles 
  1556. 		Store_header:pop_title() 
  1557. 		--Store_header:pop_title()	 
  1558. 		Store_header:set_price(nil)		 
  1559. 		 
  1560. 		--Active_list:set_visible(true)		 
  1561. 		-- Open the radial menu 
  1562. 		store_weapon_inventory_show()	 
  1563. 		 
  1564. 		if Store_weapon_loaded_from_crib then 
  1565. 			store_weapon_unlock_radial() 
  1566. 		end 
  1567. 		 
  1568. 		Current_tier = RADIAL_TIER 
  1569. 	end		 
  1570. 	 
  1571. end 
  1572.  
  1573. function store_weapon_upgrade_show(category, id) 
  1574.  
  1575. 	Active_list:set_visible(true) 
  1576. 	 
  1577. 	-- Get data to populate the megalist 
  1578. 	Store_weapon_building_menu = {} 
  1579. 	vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, category, id) 
  1580. 	store_common_push_menu(Store_weapon_building_menu) 
  1581. 	 
  1582. 	-- Show the correct stats/description 
  1583. 	local start_index = Store_weapon_building_menu.start_index or 1 
  1584. 	store_weapon_upgrade_populate_weapon_stats(start_index, Store_weapon_building_menu[start_index].level_desc)	 
  1585.  
  1586. 	Current_tier = LEVEL_TIER 
  1587. end 
  1588.  
  1589. function store_weapon_upgrade_add_items(desc_crc, price, is_purchased, is_locked) 
  1590. 	local menu_idx = #Store_weapon_building_menu + 1 
  1591.  
  1592. 	local insert = { [0] = menu_idx} 
  1593. 	local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert) 
  1594. 	 
  1595. 	local new_item = { 
  1596. 		type = TYPE_BUTTON, 
  1597. 		id = #Store_weapon_building_menu, 
  1598. 		level_desc = desc_crc, 
  1599. 		label = body, 
  1600. 		is_purchased = is_purchased, 
  1601. 		is_locked = is_locked, 
  1602. 		price = price, 
  1603. 		on_nav = store_weapon_upgrade_nav, 
  1604. 		on_select = store_weapon_upgrade_purchase, 
  1605. 		on_cancel = store_weapon_upgrade_revert, 
  1606. 	}		 
  1607.  
  1608. 	Store_weapon_building_menu[menu_idx] = new_item 
  1609. 	 
  1610. 	if is_purchased == true and is_locked == false then 
  1611. 		Store_weapon_building_menu.start_index = menu_idx 
  1612. 		 
  1613. 		-- Show the weapon/upgrade price 
  1614. 		if price == 0 then 
  1615. 			Store_header:set_price(nil) 
  1616. 		else 
  1617. 			Store_header:set_price(price) 
  1618. 		end 
  1619. 		Store_header:set_respect(nil)			 
  1620. 	end 
  1621. end 
  1622.  
  1623. function store_weapon_upgrade_nav(menu_data) 
  1624.  
  1625. 	-- Preview the model of the selected weapon at the right upgrade level 
  1626. 	store_weapon_change_weapon_preview(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_current_info.dual_wield, Store_weapon_is_cache, menu_data.id)		 
  1627. 	 
  1628. 	Store_weapon_current_info.level = menu_data.id + 1 
  1629. 	Store_weapon_current_info.desc = menu_data.level_desc 
  1630. 	 
  1631. 	-- Show the correct stats/description 
  1632. 	--store_weapon_upgrade_populate_weapon_stats(menu_data.id + 1, menu_data.level_desc) 
  1633. 	 
  1634. 	-- Show the weapon/upgrade price 
  1635. 	if menu_data.price <= 0 then 
  1636. 		Store_header:set_price(nil) 
  1637. 	else 
  1638. 		Store_header:set_price(menu_data.price) 
  1639. 	end 
  1640. 	Store_header:set_respect(nil)		 
  1641. end 
  1642.  
  1643. function store_weapon_upgrade_populate_weapon_stats(level, level_desc_crc) 
  1644.  
  1645. 	local weapon_level = Vdo_base_object:new("weapon_level", 0, Store_weapon_doc_handle) 
  1646. 	local level_desc = Vdo_base_object:new("level_desc", 0, Store_weapon_doc_handle) 
  1647. 	 
  1648. 	--debug_print("store_weapon","setting weapon level desc to "..level_desc_crc.."\n") 
  1649. 	 
  1650. 	if vint_is_std_res() then 
  1651. 		level_desc:set_property("wrap_width",340) 
  1652. 	end 
  1653. 	 
  1654. 	-- Display weapon stats 
  1655. 	local insert = { [0] = level } 
  1656. 	local body = vint_insert_values_in_string("STORE_WEAPON_LEVEL", insert) 
  1657. 	weapon_level:set_text(body) 
  1658. 	level_desc:set_text_crc(level_desc_crc) 
  1659. 	--vint_set_property(weapon_level, "text_tag", body) 
  1660. 	--vint_set_property(level_desc_h, "text_tag_crc", level_desc_crc) 
  1661. 	 
  1662. 	--Weapon_stats_grp:set_visible(true) 
  1663. end 
  1664.  
  1665. function store_weapon_upgrade_purchase(menu_data) 
  1666.  
  1667. 	-- Now check if the player can purchase this weapon. 
  1668. 	if menu_data.is_purchased or menu_data.is_locked then 
  1669. 		return 
  1670. 	end 
  1671. 	 
  1672. 	if Store_common_player_cash >= menu_data.price then				 
  1673. 		Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)				 
  1674. 		Store_common_popup:set_title("MENU_TITLE_CONFIRM") 
  1675. 		local insert = { [0] = menu_data.label, [1] = format_cash(menu_data.price) } 
  1676. 		local body = vint_insert_values_in_string("WPN_STORE_PURCHASE_PROMPT", insert)				 
  1677. 		Store_common_popup:set_text(body)		 
  1678. 		Store_common_popup:nav_enable(true, "store_weapon_grid_confirm", "store_weapon_popup_nav") 
  1679. 		Not_popup_grp:set_alpha(.5)	 
  1680. 		Store_weapon_not_bg_grp:set_alpha(.5)	 
  1681. 		store_weapon_enable_mouse(false) 
  1682. 		game_UI_audio_play("UI_HUD_HELP") 
  1683. 	else 
  1684. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1685. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  1686. 		Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")		 
  1687. 		Store_common_popup:nav_enable(true, "store_weapon_fail_msg", "store_weapon_popup_nav") 
  1688. 		Not_popup_grp:set_alpha(.5)					 
  1689. 		Store_weapon_not_bg_grp:set_alpha(.5) 
  1690. 		store_weapon_enable_mouse(false) 
  1691. 		game_UI_audio_play("UI_HUD_HELP") 
  1692. 	end 
  1693. end 
  1694.  
  1695. -- Backing out from upgrade menu 
  1696. -- 
  1697. function store_weapon_upgrade_revert(menu_data) 
  1698.  
  1699. 	-- for thrown weapons, go back to the radial 
  1700. 	if Weapon_grid_data.category == "thrown" then 
  1701. 		store_weapon_grid_selected("back")	 
  1702. 		Current_tier = RADIAL_TIER 
  1703. 		Restore_weapon_radial_inputs = true 
  1704. 	else 
  1705. 		-- save off currently highlighted weapon - otherwise it will get overwritten to the currently equipped weapon 
  1706. 		local current_idx = Weapon_grid_idx 
  1707. 	 
  1708. 		store_weapon_populate_weapon_grid(Weapon_grid_data.category, Current_slot) 
  1709. 		 
  1710. 		--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 
  1711. 		Store_common_color_grid:draw_items(Weapon_grid_data, current_idx, 3, 3, 120, 100, 40, nil, nil, false) 
  1712. 		Store_common_color_grid:set_visible(true) 
  1713. 		Weapon_grid_idx = current_idx		 
  1714. 		 
  1715. 		Store_common_color_grid:nav_enable(true, "store_weapon_grid_selected", "store_weapon_grid_nav")	 
  1716. 		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)		 
  1717. 		store_weapon_grid_populate_weapon_stats(Weapon_grid_idx) 
  1718. 		Current_tier = WEAPON_TIER		 
  1719. 		Restore_weapon_radial_inputs = false 
  1720. 	end 
  1721. 	 
  1722. 	-- Skip adding mouse_inputs in the next populate_list (see store_weapon_populate_list) 
  1723. 	if Mouse_input_tracker ~= 0 then 
  1724. 		Mouse_input_tracker:remove_all() 
  1725. 		Skip_next_populate = true 
  1726. 	end 
  1727. 	Active_list:set_visible(false) 
  1728. 	 
  1729. 	-- refresh the stats info 
  1730. 	store_weapon_stats_update(-1, true, true)	 
  1731. end 
  1732.  
  1733. -- Confirm purchase of a weapon/upgrade 
  1734. -- 
  1735. function store_weapon_grid_confirm(event) 
  1736. 	store_weapon_enable_mouse(true) 
  1737.  
  1738. 	Store_common_popup:nav_enable(false, nil, nil) 
  1739. 	Not_popup_grp:set_alpha(1)	 
  1740. 	Store_weapon_not_bg_grp:set_alpha(1) 
  1741. 	 
  1742. 	-- The user hit the B button and are cancelling the purchase 
  1743. 	-- This is redundant to selecting "No" in the list 
  1744. 	if event == "back" then 
  1745. 		game_UI_audio_play("UI_Main_Menu_Nav_Back")	 
  1746. 		return 
  1747. 	end 
  1748. 	 
  1749. 	game_UI_audio_play("UI_Main_Menu_Select") 
  1750. 	 
  1751. 	-- Did we select yes?  This assumes yes is the first item 
  1752. 	if Store_common_popup:get_selected_data() ~= 1 then 
  1753. 		return 
  1754. 	end 
  1755.  
  1756. 	-- find current selection to get price 
  1757. 	local menu_data = Active_list:return_selected_data() 
  1758. 	 
  1759. 	store_weapon_purchase_weapon(Weapon_grid_data.category, Store_weapon_current_info.id, Store_weapon_is_cache, menu_data.price) 
  1760. 	game_hud_update_inventory() 
  1761. 	 
  1762. 	-- Update GSI if in mission 
  1763. 	if Store_weapon_in_mission and Gsi_is_updated == false then 
  1764. 		local obj_txt = Vdo_base_object:new("obj_txt",0, Store_weapon_doc_handle) 
  1765. 		local gsi_bg = Vdo_base_object:new("gsi_bg", 0, Store_weapon_doc_handle) 
  1766. 		 
  1767. 		obj_txt:set_text("M03_OBJ_EXIT_STORE")					 
  1768. 		 
  1769. 		local obj_txt_x, obj_txt_y = obj_txt:get_anchor() 
  1770. 		local obj_txt_width, obj_txt_height = element_get_actual_size(obj_txt.handle) 
  1771. 		local gsi_bg_width, gsi_bg_height = element_get_actual_size(gsi_bg.handle) 
  1772. 		 
  1773. 		element_set_actual_size(gsi_bg.handle, obj_txt_x + obj_txt_width + 5, gsi_bg_height) 
  1774. 		--gsi_bg:set_screen_size(obj_txt_x + obj_txt_width + 5, gsi_bg_height) 
  1775. 		 
  1776. 		--don't call this again once it's updated 
  1777. 		Gsi_is_updated = true 
  1778. 	end 
  1779. 	 
  1780. 	-- Need to refresh the mega list 
  1781. 	Store_weapon_building_menu = {} 
  1782. 	vint_dataresponder_request("store_weapon_populate_upgrades", "store_weapon_upgrade_add_items", 0, Weapon_grid_data.category, Store_weapon_current_info.id) 
  1783. 	Menu_data = Store_weapon_building_menu 
  1784. 	store_weapon_populate_list(Menu_data, Menu_data.start_index) 
  1785. 	 
  1786. 	-- This is necessary to "reload" the ammo purchases for thrown weapons 
  1787. 	vint_dataresponder_request("store_weapon_populate_ammo", "store_common_do_nothing", 0) 
  1788. 	 
  1789. 	ui_audio_post_event("weapon_purchase") 
  1790. 	 
  1791. 	-- do this so holding down the button doesn't cause repeated actions 
  1792. 	Input_tracker:subscribe(false)		 
  1793. 	Input_tracker:subscribe(true)	 
  1794. end 
  1795.  
  1796. -- Weapon cache  ****************************************************************************************** 
  1797.  
  1798. -- Open the weapon cache radial menu 
  1799. -- 
  1800. function store_weapon_cache_open_radial(menu_data) 
  1801. 	Active_list:set_visible(false) 
  1802.  
  1803. 	Store_weapon_is_cache = true 
  1804. 	 
  1805. 	debug_print("store_weapon", "called store_weapon_cache_open_radial\n")		 
  1806. 	 
  1807. 	-- Set the callback to use when the user selects a cateogory from the radial menu 
  1808. 	Store_weapon_inventory.selected_cb = store_weapon_grid_open 
  1809. 	Store_weapon_inventory.nav_cb = store_weapon_cache_nav	 
  1810. 	 
  1811. 	-- Disable the unarmed slot 
  1812. 	Store_weapon_radial:slot_disable(0)	 
  1813. 	 
  1814. 	-- Hide grenades for weapon cache 
  1815. 	Store_weapon_radial:show_dpad_menu(false) 
  1816. 	Store_weapon_radial:set_anchor(Radial_cache_x,395) 
  1817. 	 
  1818. 	-- Enable or disable slots based on availability 
  1819. 	for i = 1, 7 do 
  1820. 		-- Initialize data for grid 
  1821. 		Weapon_grid_data = {} 
  1822. 		 
  1823. 		local category = Store_weapon_categories[i].category 
  1824. 		 
  1825. 		vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  1826. 		 
  1827. 		-- If there are no choices, then disable 
  1828. 		if #Weapon_grid_data == 0 then 
  1829. 			Store_weapon_radial:slot_disable(i) 
  1830. 		else 
  1831. 			Store_weapon_radial:slot_enable(i) 
  1832. 		end 
  1833. 	end		 
  1834.  
  1835. 	-- Open the radial menu 
  1836. 	store_weapon_inventory_show(menu_data) 
  1837. 	 
  1838. 	-- Set the hint based on the platform 
  1839. 	local hint_data = {} 
  1840. 	if game_get_platform() == "PC" then 
  1841. 		hint_data = { 
  1842. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1843. 		} 
  1844. 	else  
  1845. 		hint_data = { 
  1846. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  1847. 			{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  1848. 			--{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"}, 
  1849. 		} 
  1850. 	end 
  1851. 	Store_common_hint_bar:set_hints(hint_data)  
  1852. 	if Hint_bar_mouse_input_tracker ~= nil then 
  1853. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  1854. 	end 
  1855. end 
  1856.  
  1857. function store_weapon_cache_nav(slot_id) 
  1858. 	store_weapon_stats_update(slot_id, false, true) 
  1859. 	store_weapon_cover_weapon(true) 
  1860. end 
  1861.  
  1862.  
  1863. --Updates the Weapon Radial Menu VDO 
  1864. function store_weapon_radial_update(di_h) 
  1865. 	Store_weapon_radial:slots_update(di_h) 
  1866. 	 
  1867. 	-- May be needed to update ammo totals 
  1868. 	--Store_weapon_radial:weapon_highlight(-1, true, true) 
  1869. end 
  1870.  
  1871. -- Stuff copied from HUD script for weapon radial ******************************************************** 
  1872.  
  1873.  
  1874. --Input handling for the radial 
  1875. function store_weapon_inventory_input(event, value) 
  1876. 	if event == "inventory" then 
  1877. 		-- nothing 
  1878. 	elseif event == "select" then 
  1879. 		-- A/accept button pushed, do callback for appropriate category 
  1880. 		local slot = Store_weapon_radial:get_selected_slot() 
  1881. 		Store_weapon_inventory.selected_cb(slot) 
  1882. 		game_UI_audio_play("UI_Main_Menu_Select") 
  1883. 		 
  1884. 	elseif event == "back" then 
  1885. 		-- B/cancel button pushed, close radial menu		 
  1886.  
  1887. 		-- If we came from the crib, we need to pop this doc off the stack 
  1888. 		if Store_weapon_loaded_from_crib then 
  1889. 			store_weapon_exit() 
  1890. 		else 
  1891. 			store_weapon_cancel_radial() 
  1892. 		end 
  1893. 		if Radial_mouse_input_tracker ~= nil then 
  1894. 			Radial_mouse_input_tracker:subscribe(false) 
  1895. 		end 
  1896. 		 
  1897. 	elseif event == "inventory_x" then 
  1898. 		--Move Analog Stick X 
  1899. 		if Store_weapon_inventory.x ~= value then 
  1900. 			Store_weapon_inventory.x = value 
  1901. 			Store_weapon_inventory.stale = true 
  1902. 		end 
  1903. 		 
  1904. 	elseif event == "inventory_y" then 
  1905. 		--Move Analog Stick Y 
  1906. 		if Store_weapon_inventory.y ~= value then 
  1907. 			Store_weapon_inventory.y = value 
  1908. 			Store_weapon_inventory.stale = true	 
  1909. 		end 
  1910. 		 
  1911. 	elseif Store_weapon_is_cache == false then 
  1912. 		local slot = 0 
  1913. 		if event == "inventory_up" and value > INVENTORY_DPAD_THRESHOLD then 
  1914. 			slot = 8 
  1915. 		elseif event == "inventory_right" and value > INVENTORY_DPAD_THRESHOLD then 
  1916. 			slot = 9 
  1917. 		elseif event == "inventory_down" and value > INVENTORY_DPAD_THRESHOLD then 
  1918. 			slot = 10 
  1919. 		elseif event == "inventory_left" and value > INVENTORY_DPAD_THRESHOLD then	 
  1920. 			slot = 11 
  1921. 		end 
  1922. 		 
  1923. 		-- Only highlight the slot if it isn't disabled 
  1924. 		if slot ~= 0 and Store_weapon_radial:slot_is_disabled(slot) ~= true then 
  1925. 			Store_weapon_radial:weapon_highlight(slot) 
  1926. 			 
  1927. 			-- Initialize data for grid 
  1928. 			Weapon_grid_data = {} 
  1929. 			Weapon_grid_idx = 1 
  1930. 			 
  1931. 			-- Get the category name string for the chosen slot. 
  1932. 			local category = Store_weapon_categories[slot].category 
  1933. 			 
  1934. 			vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category, slot - 8) 
  1935. 			 
  1936. 			-- If there are no choices, don't show weapon stats 
  1937. 			if #Weapon_grid_data ~= 0 then 
  1938. 				store_weapon_grid_populate_weapon_stats(Weapon_grid_idx)	 
  1939. 			end					 
  1940. 			 
  1941. 			-- Call navigation callback 
  1942. 			if Store_weapon_inventory.nav_cb ~= nil then 
  1943. 				Store_weapon_inventory.nav_cb(slot) 
  1944. 			end 
  1945. 		end 
  1946. 	end 
  1947. end 
  1948.  
  1949. -- Input handling for slots  
  1950. function store_weapon_inventory_show(menu_data) 
  1951.  
  1952. 	--game_store_weapon_update_inventory() 
  1953. 		 
  1954. 	Current_tier = RADIAL_TIER 
  1955. 	 
  1956. 	-- Disable menu input. 
  1957. 	store_lock_controls() 
  1958. 	 
  1959. 	-- Set the titles on top; if menu_data is nil, that is because we are only returning to the radial from the weapons grid, 
  1960. 	-- and we don't need to add a title because they are already there. 
  1961. 	if menu_data ~= nil then 
  1962. 		local title = nil 
  1963. 		local title_crc = nil 
  1964. 		title_crc = menu_data.label_crc 
  1965. 		if title_crc == nil then 
  1966. 			title = menu_data.label 
  1967. 		end 
  1968. 		Store_header:push_title( title_crc, title )	 
  1969. 	end 
  1970.  
  1971. 	if Store_weapon_inventory.thread == nil then 
  1972. 		--game_UI_audio_play("UI_HUD_Open_Weapon_Radial") 
  1973. 		 
  1974. 		--TODO: Show Inventory 
  1975. 		Store_weapon_radial:show(true) 
  1976. 		 
  1977. 		--Reset visual analog stick and get the proper text tag on it. 
  1978. 		Store_weapon_inventory.x = 0 
  1979. 		Store_weapon_inventory.y = 0		 
  1980. 		 
  1981. 		if Store_weapon_loaded_from_crib == false then 
  1982. 			--Subscribe to input 
  1983. 			store_weapon_unlock_radial() 
  1984. 		end 
  1985. 		 
  1986. 		--Highlight Currently equipped slots 
  1987. 		local selected_slot = Store_weapon_radial:get_selected_slot() 
  1988. 		if selected_slot < 0 or selected_slot >= 12 then 
  1989. 			selected_slot = 0 
  1990. 		end	 
  1991. 		 
  1992. 		if Store_weapon_radial:slot_is_disabled(selected_slot) then 
  1993. 			selected_slot = 0 
  1994. 		end 
  1995. 		 
  1996. 		--If in cache and thrown is selected set slot back to 0 
  1997. 		if Store_weapon_is_cache and selected_slot >= 8 then 
  1998. 			selected_slot = 0 
  1999. 		end 
  2000. 		 
  2001. 		--Walk through weapon radial to find first enabled slot 
  2002. 		while Store_weapon_radial:slot_is_disabled(selected_slot) and selected_slot < 12 do 
  2003. 			selected_slot = selected_slot + 1 
  2004. 		end 
  2005. 		 
  2006. 		if selected_slot >= 8 and Store_weapon_is_cache then 
  2007. 			-- hide everything and show popup 
  2008. 			Store_weapon_radial:set_visible(false) 
  2009. 			Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  2010. 			Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  2011. 			Store_common_popup:set_text("HUD_SHOP_NO_WEAPONS")		 
  2012. 			Store_common_popup:nav_enable(true, "store_weapon_no_weapons", "store_weapon_popup_nav") 
  2013. 			Not_popup_grp:set_alpha(.5)	 
  2014. 			Store_weapon_not_bg_grp:set_alpha(.5)	 
  2015. 			Store_common_popup:set_visible(true)	 
  2016. 			game_UI_audio_play("UI_HUD_HELP") 
  2017. 			 
  2018. 			Store_weapon_cache_no_weapons = true 
  2019. 			return 
  2020. 		end 
  2021. 		 
  2022. 		Store_weapon_radial:weapon_highlight(selected_slot, true)		 
  2023. 		 
  2024. 		Store_weapon_radial:stick_update_position(0, 0) 
  2025. 		Store_weapon_radial:stick_update_tag()	 
  2026. 		Store_weapon_radial:stick_arrow_reset()	 
  2027.  
  2028. 		Store_weapon_inventory.thread = thread_new("store_weapon_inventory_process")			 
  2029. 		 
  2030. 		-- Preview the model of the selected weapon 
  2031. 		if selected_slot >= 1 then 
  2032. 			local selected_cat_index = selected_slot - 1 
  2033. 								 
  2034. 			-- Initialize data for grid 
  2035. 			Weapon_grid_data = {} 
  2036. 			Weapon_grid_idx = 1 
  2037. 			 
  2038. 			-- Get the category name string for the chosen slot. 
  2039. 			local category = Store_weapon_categories[selected_slot].category 
  2040. 			 
  2041. 			if category == "thrown" == true then 
  2042. 				vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category, selected_slot - 8) 
  2043. 			else 
  2044. 				vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  2045. 			end	 
  2046. 			 
  2047. 			-- If there are no choices, don't show weapon stats 
  2048. 			if #Weapon_grid_data ~= 0 then 
  2049. 				store_weapon_grid_populate_weapon_stats(Weapon_grid_idx)	 
  2050. 			end			 
  2051. 			 
  2052. 			-- Call navigation callback 
  2053. 			if Store_weapon_inventory.nav_cb ~= nil then 
  2054. 				Store_weapon_inventory.nav_cb(selected_slot) 
  2055. 			end			 
  2056. 			 
  2057. 		end 
  2058. 	end 
  2059. 	 
  2060. 	-- Set the hint based on the platform 
  2061. 	local hint_data = {} 
  2062. 	if game_get_platform() == "PC" then 
  2063. 		hint_data = { 
  2064. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  2065. 		} 
  2066. 		if Radial_mouse_input_tracker ~= nil then 
  2067. 			-- Also add inputs for the weapon radial 
  2068. 			Store_weapon_radial:add_mouse_inputs("store_weapon", Radial_mouse_input_tracker, 50) 
  2069. 			Radial_mouse_input_tracker:subscribe(true) 
  2070. 		end 
  2071. 	else  
  2072. 		if Store_weapon_is_cache == true then 
  2073. 			hint_data = { 
  2074. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  2075. 				{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  2076. 			}		 
  2077. 		else 
  2078. 			hint_data = { 
  2079. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  2080. 				{CTRL_BUTTON_LS, "STORE_WEAPON_NAVIGATE"}, 
  2081. 				{CTRL_BUTTON_DPAD, "STORE_WEAPON_NAVIGATE"}, 
  2082. 			}	 
  2083. 		end 
  2084. 	end 
  2085. 	Store_common_hint_bar:set_hints(hint_data)	 
  2086. 	if Hint_bar_mouse_input_tracker ~= nil then 
  2087. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  2088. 	end 
  2089. end 
  2090.  
  2091. function store_weapon_inventory_hide() 
  2092. 		-- Enable menu controls 
  2093. 	store_unlock_controls() 
  2094.  
  2095. 	-- if aborted == false then 
  2096. 		-- Store_weapon_radial:game_equip_selected_slots() 
  2097. 	-- end 
  2098. 	 
  2099. 	--Hide Radial Menu 
  2100. 	Store_weapon_radial:show(false) 
  2101. 	 
  2102. 	store_weapon_lock_radial() 
  2103.  
  2104. 	if Store_weapon_inventory.thread ~= nil then	 
  2105. 		Store_weapon_inventory.extra_buttons = nil				 
  2106. 		thread_kill(Store_weapon_inventory.thread) 
  2107. 		Store_weapon_inventory.thread = nil		 
  2108. 	end 
  2109. end 
  2110.  
  2111. -- Radial input handling 
  2112. function store_weapon_inventory_process() 
  2113. 	while true do  
  2114. 		if Store_weapon_inventory.stale == true then 
  2115. 				 
  2116. 			local x = Store_weapon_inventory.x 
  2117. 			local y = Store_weapon_inventory.y 
  2118. 			local selected_weapon_index = 0 
  2119. 			local mag = sqrt((x * x) + (y * y)) 
  2120. 			local pi = 3.14159 
  2121. 			 
  2122. 			if mag > 0.5 then 
  2123. 				 
  2124. 				-- Y resolves out so don't bother with it 
  2125. 				x = x/mag 
  2126. 				local radians = acos(x) 
  2127. 				 
  2128. 				if y < 0.0 then 
  2129. 					radians = pi + (pi - radians) 
  2130. 				end 
  2131. 	 
  2132. 				local eighth = pi / 8 
  2133. 				local fourth = pi / 4 
  2134. 				local selected_weapon_index = 0 
  2135. 				 
  2136. 				if radians < eighth then 
  2137. 					selected_weapon_index = 2; 
  2138. 				elseif radians < (fourth + eighth) then 
  2139. 					selected_weapon_index = 1 
  2140. 				elseif radians < (2.0 * fourth + eighth) then 
  2141. 					selected_weapon_index = 0 
  2142. 				elseif radians < (3.0 * fourth + eighth) then 
  2143. 					selected_weapon_index = 7 
  2144. 				elseif radians < (4.0 * fourth + eighth) then 
  2145. 					selected_weapon_index = 6 
  2146. 				elseif radians < (5.0 * fourth + eighth) then 
  2147. 				 
  2148. 					selected_weapon_index = 5 
  2149. 				elseif radians < (6.0 * fourth + eighth) then 
  2150. 					selected_weapon_index = 4; 
  2151. 				elseif radians < (7.0 * fourth + eighth) then				 
  2152. 					selected_weapon_index = 3; 
  2153. 				else 
  2154. 					selected_weapon_index = 2; 
  2155. 				end 
  2156. 				 
  2157. 				-- Only highlight the slot if it isn't disabled 
  2158. 				if Store_weapon_radial:slot_is_disabled(selected_weapon_index) ~= true and selected_weapon_index >= 1 then 
  2159. 															 
  2160. 					-- Call navigation callback 
  2161. 					if Store_weapon_inventory.nav_cb ~= nil then 
  2162. 						Store_weapon_inventory.nav_cb(selected_weapon_index) 
  2163. 					end 
  2164. 					 
  2165. 					Store_weapon_radial:weapon_highlight(selected_weapon_index)	 
  2166. 					 
  2167. 					-- Initialize data for grid 
  2168. 					Weapon_grid_data = {} 
  2169. 					Weapon_grid_idx = 1 
  2170. 					 
  2171. 					-- Get the category name string for the chosen slot. 
  2172. 					local category = Store_weapon_categories[selected_weapon_index].category 
  2173. 					 
  2174. 					if category == "thrown" == true then 
  2175. 						vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category) 
  2176. 					else 
  2177. 						vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  2178. 					end	 
  2179. 					 
  2180. 					-- If there are no choices, don't show weapon stats 
  2181. 					if #Weapon_grid_data ~= 0 then 
  2182. 						store_weapon_grid_populate_weapon_stats(Weapon_grid_idx)	 
  2183. 					end 
  2184. 				end 
  2185. 		 
  2186. 				Store_weapon_radial:stick_update_arrow(radians) 
  2187. 				 
  2188. 			end 
  2189. 	 
  2190. 			--Update Stick location on radial menu 
  2191. 			Store_weapon_radial:stick_update_position(Store_weapon_inventory.x, Store_weapon_inventory.y) 
  2192. 			Store_weapon_inventory.stick_mag = mag 
  2193. 			Store_weapon_inventory.stale = false 
  2194. 		end 
  2195. 		thread_yield() 
  2196. 	end 
  2197. end 
  2198.  
  2199. function store_weapon_change_weapon_preview(category, id, dual_wield, is_cache, upgrade_level) 
  2200.  
  2201. 	-- If we're only doing an upgrade swap, we don't need to lock grid input 
  2202. 	if upgrade_level == nil then 
  2203. 		-- lock input until the swap is done 
  2204. 		Store_weapon_is_loading = true 
  2205. 	end 
  2206.  
  2207. 	-- Tell C to replace model 
  2208. 	store_weapon_change_weapon(category, id, dual_wield, is_cache, upgrade_level) 
  2209. end	 
  2210.  
  2211. function store_weapon_allow_grid_input() 
  2212. 	return Store_weapon_is_loading == false 
  2213. end 
  2214.  
  2215. -- ===================================== 
  2216. --       Mouse Specific Functions 
  2217. -- ===================================== 
  2218.  
  2219. function store_weapon_enable_mouse(enable) 
  2220. 	if Game_platform == "PC" and enable ~= nil then 
  2221. 		if Mouse_input_tracker ~= 0 then 
  2222. 			Mouse_input_tracker:subscribe(enable) 
  2223. 		end 
  2224. 		 
  2225. 		if Hint_bar_mouse_input_tracker ~= nil then 
  2226. 			Hint_bar_mouse_input_tracker:subscribe(enable) 
  2227. 		end 
  2228. 		 
  2229. 		if enable == false then 
  2230. 			if Radial_mouse_input_tracker ~= nil then 
  2231. 				Radial_mouse_input_tracker:subscribe(false) 
  2232. 			end 
  2233. 		end 
  2234. 	end 
  2235. end 
  2236.  
  2237. function store_weapon_mouse_click(event, target_handle) 
  2238. 	local hint_index = Store_common_hint_bar:get_hint_index(target_handle) 
  2239. 	if hint_index ~= 0 then 
  2240. 		if Current_tier == MENU_TIER then 
  2241. 			store_common_button_b() 
  2242. 		elseif Current_tier == LEVEL_TIER then 
  2243. 			store_common_button_b() 
  2244. 		elseif Current_tier == RADIAL_TIER then 
  2245. 			store_weapon_inventory_input("back") 
  2246. 		elseif Current_tier == WEAPON_TIER or Current_tier == GRENADE_UPGRADE_TIER then 
  2247. 			store_weapon_grid_selected("back") 
  2248. 		end 
  2249. 	end 
  2250. 	 
  2251. 	local weapon_index = Store_weapon_radial:get_slot_index(target_handle) 
  2252. 	if weapon_index ~= 0 then 
  2253. 		-- Highlight the correct weapon, and select it 
  2254. 		Store_weapon_radial:weapon_highlight(weapon_index) 
  2255. 		store_weapon_inventory_input("select") 
  2256. 	end 
  2257. end 
  2258.  
  2259. function store_weapon_mouse_move(event, target_handle) 
  2260. 	-- Reset all highlights 
  2261. 	Store_common_hint_bar:set_highlight(0) 
  2262. 	 
  2263. 	-- Check if the mouse is over the hint bar buttons 
  2264. 	local hint_index = Store_common_hint_bar:get_hint_index(target_handle) 
  2265. 	if hint_index ~= 0 then 
  2266. 		Store_common_hint_bar:set_highlight(hint_index, Store_common_current_highlight_color) 
  2267. 		return 
  2268. 	end 
  2269. 	 
  2270. 	-- Check if the mouse is over a button on the mega list 
  2271. 	local old_index = Active_list:get_selection() 
  2272. 	local new_index = Active_list:get_button_index(target_handle) 
  2273. 	if new_index ~= 0 and new_index ~= old_index then 
  2274. 		Active_list:set_selection(new_index) 
  2275. 		Active_list:move_cursor(0, true) 
  2276. 		 
  2277. 		-- If the item has a callback for navigation, do it (such as putting clothes on) 
  2278. 		local data_item = Active_list:return_selected_data() 
  2279. 		if data_item.on_nav ~= nil then 
  2280. 			data_item.on_nav(data_item) 
  2281. 		end 
  2282. 		return 
  2283. 	end 
  2284. 	 
  2285. 	local weapon_index = Store_weapon_radial:get_slot_index(target_handle) 
  2286. 	if weapon_index ~= 0 and Old_index ~= weapon_index then 
  2287.  
  2288. 		-- Only highlight the slot if it isn't disabled 
  2289. 		if Store_weapon_radial:slot_is_disabled(weapon_index) ~= true and weapon_index>= 1 then 
  2290. 													 
  2291. 			-- Call navigation callback 
  2292. 			if Store_weapon_inventory.nav_cb ~= nil then 
  2293. 				Store_weapon_inventory.nav_cb(weapon_index) 
  2294. 			end 
  2295. 			 
  2296. 			Store_weapon_radial:weapon_highlight(weapon_index, true, true)	 
  2297. 			 
  2298. 			-- Initialize data for grid 
  2299. 			Weapon_grid_data = {} 
  2300. 			Weapon_grid_idx = 1 
  2301. 			 
  2302. 			-- Get the category name string for the chosen slot. 
  2303. 			local category = Store_weapon_categories[weapon_index].category 
  2304. 			 
  2305. 			if category == "thrown" == true then 
  2306. 				vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_thrown_items", 0, Store_weapon_is_cache, category) 
  2307. 			else 
  2308. 				vint_dataresponder_request("store_weapon_populate_weapons", "store_weapon_grid_add_items", 0, Store_weapon_is_cache, category) 
  2309. 			end	 
  2310. 			 
  2311. 			-- If there are no choices, don't show weapon stats 
  2312. 			if #Weapon_grid_data ~= 0 then 
  2313. 				store_weapon_grid_populate_weapon_stats(Weapon_grid_idx)	 
  2314. 			end 
  2315. 			 
  2316. 			Old_index = weapon_index 
  2317. 		end 
  2318. 	end 
  2319. end 
  2320.  
  2321. function store_weapon_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  2322. end 
  2323.  
  2324. function store_weapon_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  2325. end 
  2326.  
  2327. function store_weapon_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  2328. end 
  2329.