./store_common.lua

  1.  
  2. -- Get the handle to the doc which holds most of the store vint elements 
  3. Store_common_doc_handle 	= -1 
  4.  
  5. Store_common_hint_bar 		= -1 
  6. Store_common_rotate_hint 	= -1 
  7. Store_common_popup 			= -1 
  8. Store_common_color_grid 	= -1 
  9. Store_common_spinner			= -1 
  10.  
  11. Store_common_bypass_animate = false 
  12.  
  13. Store_common_current_highlight_color = COLOR_SAINTS_PURPLE 
  14.  
  15. Store_header  = {} 
  16. Input_tracker = {} 
  17. Menu_data     = {} 
  18. Active_list   = {} 
  19. Store_common_sub_menu = {} 
  20. Store_common_gsi = {} 
  21.  
  22. Mouse_input_tracker = 0 
  23. Character_mouse_input_tracker = 0 
  24. Character_mouse_drag_region = 0 
  25.  
  26. -- Width of the store menus. 
  27. --TODO MODIFY THESE FOR BOTH HD/SD (JMH 5/4/2011) 
  28. --STORE_COMMON_HEADER_SIZE = 		--vint_to_std_res(428,  
  29. STORE_COMMON_LIST_SIZE = 435		--vint_to_std_res(428, -378) 
  30. STORE_COMMON_LIST_NO_PRICE_Y = 247 
  31. STORE_COMMON_GRID_NO_PRICE_Y = 270 
  32. STORE_COMMON_GRID_VEHICLE_Y = 280 
  33.  
  34. Store_common_allow_input_cb	= 0 
  35. Store_common_populate_list_cb = 0 
  36. Store_common_exit_cb				= 0 
  37.  
  38. Store_common_gallery_download_only = false 
  39. Store_common_gallery_cancel		  = false 
  40.  
  41. -- Current amount of cash player has 
  42. Store_common_player_cash = 0 
  43.  
  44. -- Override input if someone presses both back and select together 
  45. Store_common_override_input = false 
  46.  
  47. Yes_no_choices = { 
  48. 	[1] = { 
  49. 		type = TYPE_BUTTON, 
  50. 		label = "PAUSE_MENU_ACCEPT", 
  51. 		id = 1, 
  52. 	}, 
  53. 	[2] = { 
  54. 		type = TYPE_BUTTON, 
  55. 		label = "CONTROL_CANCEL", 
  56. 		id = 2, 
  57. 	}, 
  58. } 
  59.  
  60. Ok_choice = { 
  61. 	[1] = { 
  62. 		type = TYPE_BUTTON, 
  63. 		label = "CONTROL_OKAY", 
  64. 		id = 1, 
  65. 	}, 
  66. } 
  67.  
  68. ---------------------------------------------------------------------------  
  69. -- Stack tracking for the stores.  ID's are unique numbers for categories, 
  70. -- items, etc.  Indexes are the order in the menu that was selected. 
  71. --------------------------------------------------------------------------- 
  72. Store_common_stack_id = {} 
  73. Store_common_stack_index = {} 
  74. Store_common_stack_menu = {} 
  75.  
  76. function store_common_init() 
  77. 	Store_common_stack_id.current_stack = 0 
  78. 	Store_common_stack_index.current_stack = 0 
  79.  
  80. 	-- Get the handle to the doc which holds most of the store vint elements 
  81. 	Store_common_doc_handle = vint_document_find("store_common") 
  82. 	 
  83. 	Store_common_hint_bar = Vdo_hint_bar:new("hint_bar", 0, Store_common_doc_handle) 
  84. 	Store_common_rotate_hint = Vdo_hint_bar:new("hint_rotate", 0, Store_common_doc_handle) 
  85. 	Store_common_popup = Vdo_store_popup:new("store_popup", 0, Store_common_doc_handle) 
  86. 	Store_common_color_grid = Vdo_grid_list:new("color_grid", 0, Store_common_doc_handle) 
  87. 	Store_common_spinner = Vdo_spinner:new("store_spinner", 0, Store_common_doc_handle) 
  88. 	 
  89. 	bg_saints_show(false) 
  90. 	 
  91. 	local upgrade_desc = Vdo_base_object:new("upgrade_desc", 0, Store_common_doc_handle) 
  92. 	local crib_random_grp = Vdo_base_object:new("crib_random_grp", 0, Store_common_doc_handle) 
  93. 	 
  94.  
  95. 	-- Hide everything then turn on what we need in the individual stores 
  96. 	upgrade_desc:set_visible(false) 
  97. 	crib_random_grp:set_visible(false) 
  98. 	 
  99. 	Store_common_hint_bar:enable_text_shadow(true) 
  100. 	 
  101. 	Store_common_hint_bar:set_visible(false) 
  102. 	Store_common_rotate_hint:set_visible(false)	 
  103. 	Store_common_popup:set_visible(false) 
  104. 	Store_common_color_grid:set_visible(false) 
  105. 	Store_common_spinner:set_visible(false) 
  106. 	 
  107. 	Store_common_hint_bar:enable_text_shadow(true) 
  108. 	Store_common_rotate_hint:enable_text_shadow(true) 
  109. 	 
  110. 	-- Initially, list_1 is the active list 
  111. 	Active_list = Vdo_mega_list:new("list_1", 0, Store_common_doc_handle, "store_common.lua", "Active_list") 
  112. 	Active_list:set_visible(false) 
  113. 	 
  114. 	--Setup header 
  115. 	Store_header = Vdo_store_header:new("store_header", 0, Store_common_doc_handle) 
  116. 	 
  117. 	-- Initialize the store header 
  118. 	Store_header:set_title()	 
  119. 	Store_header:set_price(nil) 
  120. 	Store_header:set_respect(nil) 
  121. 	Store_header:set_visible(false) 
  122. 	 
  123. 	Store_common_gsi = Vdo_gsi_lite:new("store_common_gsi", 0, Store_common_doc_handle) 
  124. 		 
  125. 	-- set up data items for player status 
  126. 	vint_dataitem_add_subscription("sr2_local_player_respect", "update", "store_common_respect_update") 
  127. 	vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "store_common_cash_update")	 
  128.  
  129. 	-- subscribe to common inputs 
  130. 	Input_tracker = Vdo_input_tracker:new() 
  131. 	Input_tracker:add_input("pause", "store_common_pause", 50) 
  132. 	Input_tracker:add_input("map", "store_common_do_nothing", 50) 
  133. 	Input_tracker:add_input("back", "store_common_button_b", 50) 
  134. 	Input_tracker:add_input("select", "store_common_button_a", 50) 
  135. 	Input_tracker:add_input("nav_up", "store_common_nav_up", 50) 
  136. 	Input_tracker:add_input("nav_down", "store_common_nav_down", 50) 
  137. 	Input_tracker:add_input("nav_left", "store_common_nav_left", 50) 
  138. 	Input_tracker:add_input("nav_right", "store_common_nav_right", 50) 
  139. 	 
  140. 	Active_list:set_input_tracker(Input_tracker) 
  141. 	Store_common_color_grid:set_input_tracker(Input_tracker) 
  142. 	 
  143. 	-- Create the mouse's input tracker 
  144. 	if game_get_platform() == "PC" then 
  145. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  146. 		 
  147. 		Character_mouse_drag_region = vint_object_find("hidden_mouse_mask_bg", 0, Store_common_doc_handle) 
  148. 		if Character_mouse_drag_region ~= 0 then 
  149. 			Character_mouse_input_tracker = Vdo_input_tracker:new() 
  150. 			Character_mouse_input_tracker:add_mouse_input("mouse_click", "character_mouse_click", 50, Character_mouse_drag_region) 
  151. 			Character_mouse_input_tracker:add_mouse_input("mouse_scroll", "character_mouse_scroll", 50, Character_mouse_drag_region) 
  152. 			Character_mouse_input_tracker:add_mouse_input("mouse_move", "character_mouse_move", 50, Character_mouse_drag_region) 
  153. 			Character_mouse_input_tracker:add_mouse_input("mouse_drag", "character_mouse_drag", 50, Character_mouse_drag_region) 
  154. 			Character_mouse_input_tracker:add_mouse_input("mouse_drag_release", "character_mouse_drag_release", 50, Character_mouse_drag_region) 
  155. 			character_enable_mouse_drag(false) 
  156. 		end 
  157. 	end 
  158.  
  159. end 
  160.  
  161. function store_common_safe_frame_show() 
  162. 	 
  163. 	local safe_frame = vint_object_find("safe_frame", 0, Store_common_doc_handle) 
  164. 	vint_set_property(safe_frame, "visible", true) 
  165. 	 
  166. end 
  167.  
  168. function store_common_cleanup() 
  169. 	Store_common_hint_bar:cleanup() 
  170. 	Store_common_rotate_hint:cleanup() 
  171. 	Store_common_popup:cleanup() 
  172. 	Store_common_color_grid:nav_enable(false, nil, nil)	 
  173. 	Store_common_color_grid:cleanup() 
  174. 	 
  175. 	if Mouse_input_tracker ~= 0 then 
  176. 		Mouse_input_tracker:subscribe(false) 
  177. 	end 
  178. 	 
  179. 	if Character_mouse_input_tracker ~= 0 then 
  180. 		Character_mouse_input_tracker:subscribe(false) 
  181. 		vint_set_mouse_cursor("") 
  182. 		store_common_mouse_zoom(0.0) 
  183. 	end 
  184. end 
  185.  
  186. -- Some things need to be cleaned up right away when a store doc is unloading, particular disabled inputs which have 
  187. -- callbacks to the script that is unloading. 
  188. -- 
  189. function store_common_cleanup_current_store() 
  190. 	Store_common_popup:cleanup() 
  191. 	Store_common_color_grid:nav_enable(false, nil, nil) 
  192. 	Store_common_color_grid:cleanup() 
  193. end 
  194.  
  195. ---------------------------------------------------------------------------  
  196. -- Adds an element to the stack. Use when making a selection on the menu. 
  197. -- @param id	ID of the current selected option 
  198. --------------------------------------------------------------------------- 
  199. function store_common_stack_add_id(id) 
  200. 	Store_common_stack_id[Store_common_stack_id.current_stack + 1] = id 
  201. 	Store_common_stack_id.current_stack = Store_common_stack_id.current_stack + 1 
  202. end 
  203.  
  204. ---------------------------------------------------------------------------  
  205. -- Removes an element from the stack. Use when going back a menu. 
  206. --------------------------------------------------------------------------- 
  207. function store_common_stack_remove_id() 
  208. 	--Nothing in menu stack return default selection 
  209. 	if Store_common_stack_id.current_stack == 0 then 
  210. 		return 
  211. 	end 
  212.  
  213. 	--Remove value of current stack 
  214. 	Store_common_stack_id[Store_common_stack_id.current_stack] = nil 
  215. 	Store_common_stack_id.current_stack = Store_common_stack_id.current_stack - 1 
  216. end 
  217.  
  218. ---------------------------------------------------------------------------  
  219. -- Returns the current id for the current menu. 
  220. --------------------------------------------------------------------------- 
  221. function store_common_stack_get_id() 
  222. 	--Nothing stored in the current stack then return default id 
  223. 	if Store_common_stack_id[Store_common_stack_id.current_stack] == nil then 
  224. 		return 0 
  225. 	end 
  226. 	 
  227. 	--Return value of current stack 
  228. 	return Store_common_stack_id[Store_common_stack_id.current_stack] 
  229. end 
  230.  
  231. ---------------------------------------------------------------------------  
  232. -- Removes all elements from the stack. Use when starting from the top. 
  233. --------------------------------------------------------------------------- 
  234. function store_common_stack_clear_id() 
  235. 	Store_common_stack_id.current_stack = 0 
  236. end 
  237.  
  238. ---------------------------------------------------------------------------  
  239. -- Adds an element to the stack. Use when making a selection on the menu. 
  240. -- @param index	Index of the current selected option 
  241. --------------------------------------------------------------------------- 
  242. function store_common_stack_add_index(index) 
  243. 	Store_common_stack_index[Store_common_stack_index.current_stack] = index 
  244. 	Store_common_stack_index.current_stack = Store_common_stack_index.current_stack + 1 
  245. end 
  246.  
  247. ---------------------------------------------------------------------------  
  248. -- Removes an element from the stack. Use when going back a menu. 
  249. --------------------------------------------------------------------------- 
  250. function store_common_stack_remove_index() 
  251. 	--Nothing in menu stack return default selection 
  252. 	if Store_common_stack_index.current_stack == 0 then 
  253. 		return 
  254. 	end 
  255.  
  256. 	--Remove value of current stack 
  257. 	Store_common_stack_index[Store_common_stack_index.current_stack] = nil 
  258. 	Store_common_stack_index.current_stack = Store_common_stack_index.current_stack - 1 
  259. end 
  260.  
  261. ---------------------------------------------------------------------------  
  262. -- Returns the current index for the current menu. 
  263. --------------------------------------------------------------------------- 
  264. function store_common_stack_get_index() 
  265. 	--Nothing stored in the current stack then return default index 
  266. 	if Store_common_stack_index[Store_common_stack_index.current_stack] == nil then 
  267. 		return 1 
  268. 	end 
  269. 	 
  270. 	--Return value of current stack 
  271. 	return Store_common_stack_index[Store_common_stack_index.current_stack] 
  272. end 
  273.  
  274. ---------------------------------------------------------------------------  
  275. -- Removes all elements from the stack. Use when starting from the top. 
  276. --------------------------------------------------------------------------- 
  277. function store_common_stack_clear_index() 
  278. 	Store_common_stack_index.current_stack = 0 
  279. end 
  280.  
  281. ---------------------------------------------------------------------------  
  282. -- Adds an element to the stack. Use when making a selection on the menu. 
  283. -- @param menu	- sub menu to store 
  284. --------------------------------------------------------------------------- 
  285. function store_common_stack_add_menu(menu) 
  286. 	Store_common_stack_menu[#Store_common_stack_menu + 1] = menu 
  287. end 
  288.  
  289. ---------------------------------------------------------------------------  
  290. -- Removes an element from the stack. Use when going back a menu. 
  291. --------------------------------------------------------------------------- 
  292. function store_common_stack_remove_menu() 
  293. 	--Nothing in menu stack return default selection 
  294. 	if #Store_common_stack_menu == 0 then 
  295. 		return 
  296. 	end 
  297.  
  298. 	--Remove value of current stack 
  299. 	Store_common_stack_menu[#Store_common_stack_menu] = nil 
  300. end 
  301.  
  302. ---------------------------------------------------------------------------  
  303. -- Returns the current menu on the stack. 
  304. --------------------------------------------------------------------------- 
  305. function store_common_stack_get_menu() 
  306. 	--Nothing stored in the current stack then return default menu 
  307. 	if #Store_common_stack_menu == 0 then 
  308. 		return nil 
  309. 	end 
  310. 	 
  311. 	--Return value of current stack 
  312. 	return Store_common_stack_menu[#Store_common_stack_menu] 
  313. end 
  314.  
  315. ---------------------------------------------------------------------------  
  316. -- Removes all elements from the stack. Use when starting from the top. 
  317. --------------------------------------------------------------------------- 
  318. function store_common_stack_clear_menu() 
  319. 	Store_common_stack_menu = {} 
  320. end 
  321.  
  322. -- This function is called when the player respect data item is updated 
  323. -- 
  324. -- di_h: data item handle 
  325. -- 
  326. function store_common_respect_update(di_h) 
  327. 	--[[ 
  328. 		respect_total		= total respect earned 
  329. 		respect_needed		= respect % to reach next level 
  330. 		respect_level		= current respect level 
  331. 		show_upgrades		= should we show the "upgrade ready" indication 
  332. 	]]-- 
  333.  
  334. 	local respect_total, respect_needed, respect_level, show_upgrades = vint_dataitem_get(di_h) 
  335. 	Store_header.respect_meter:update_respect(respect_total, respect_needed, respect_level) 
  336. end 
  337.  
  338. -- This function is called when the player status data item is updated, used for cash 
  339. -- 
  340. -- di_h: data item handle 
  341. -- 
  342. function store_common_cash_update(di_h) 
  343. 	--[[ 
  344. 		cash		= player's cash 
  345. 		The rest are unused. 
  346. 	]]-- 
  347. 	 
  348. 	local cash = vint_dataitem_get(di_h) 
  349. 	Store_common_player_cash = cash 
  350. 	Store_header:set_cash(cash) 
  351. end 
  352.  
  353.  
  354. function store_common_pause(event) 
  355. 	dialog_open_pause_display() 
  356. end 
  357.  
  358. function store_common_do_nothing(event) 
  359. end 
  360.  
  361. -- If a store has registered an allow_input callback, call it and see if input is not allowed. 
  362. -- Returns true if input is allowed, false otherwise. 
  363. -- 
  364. function store_common_allow_input(event) 
  365.  
  366. 	if Store_common_allow_input_cb ~= 0 then 
  367. 		return Store_common_allow_input_cb(event) 
  368. 	else 
  369. 		return true 
  370. 	end 
  371. end 
  372.  
  373. -- Pushes a new menu on the stack, but one that isn't a submenu of an existing menu item 
  374. -- 
  375. function store_common_push_menu(menu_data) 
  376.  
  377. 	local current_id = Active_list:get_id() 
  378. 	local current_index = Active_list:get_selection() 
  379. 	 
  380. 	--Add current selection to the stack to store the selected position on the menu 
  381. 	store_common_stack_add_id(current_id) 
  382. 	store_common_stack_add_index(current_index) 
  383. 	 
  384. 	-- Store off tables we need for backing out of the menu	 
  385. 	store_common_stack_add_menu(Menu_data)	 
  386.  
  387. 	-- SEH, probably don't want this... 
  388. 	-- set the titles on top 
  389. 	local title = nil 
  390. 	local title_crc = nil 
  391. 	title_crc = Menu_data[Active_list:get_selection()].label_crc 
  392. 	if title_crc == nil then 
  393. 		title = Menu_data[Active_list:get_selection()].label 
  394. 	end 
  395. 	Store_header:push_title( title_crc, title ) 
  396.  
  397. 	-- Now move to the new sub menu 
  398. 	Menu_data = menu_data 
  399. 	 
  400. 	-- populate the new list 
  401. 	if Store_common_populate_list_cb ~= 0 then 
  402. 	 
  403. 		-- sub_menu_fill may have decided that our starting selection was something other than the first 
  404. 		local start_index = 1 
  405. 		if Menu_data.start_index ~= nil and Menu_data.start_index >= 1 and Menu_data.start_index <= #Menu_data then  
  406. 			start_index = Menu_data.start_index 
  407. 		end 
  408. 		Store_common_populate_list_cb(Menu_data, start_index) 
  409. 	end 
  410. 	 
  411. 	-- Call on_enter function since we're entering the menu 
  412. 	if Menu_data.on_enter ~= nil then 
  413. 		Menu_data.on_enter(Menu_data) 
  414. 	end	 
  415. 	 
  416. 	-- do this so holding down the button doesn't cause repeated actions 
  417. 	--Input_tracker:subscribe(false)		 
  418. 	--Input_tracker:subscribe(true)	 
  419. end 
  420.  
  421. -- Handle A/accept button action on a menu item. 
  422. -- 
  423. function store_common_button_a(event) 
  424. 	if store_common_allow_input(event) == false or Store_common_override_input then 
  425. 		return 
  426. 	end 
  427.  
  428. 	--Do NOT allow input until list is finish animating 
  429. 	if Active_list:list_is_playing() == false then	 
  430. 		local current_id = Active_list:get_id() 
  431. 		local current_index = Active_list:get_selection() 
  432. 		 
  433. 		-- If this is not a button choice (ie. it's a toggle or slider) then don't do normal menu processing 
  434. 		if Menu_data[current_index].type == TYPE_TOGGLE then 
  435. 			store_common_nav_right() 
  436. 		elseif Menu_data[current_index].type == TYPE_TOGGLE_COLOR then 
  437. 			game_UI_audio_play("UI_Main_Menu_Select") 
  438. 		else   
  439. 			if Menu_data[current_index].equiped ~= true or Menu_data[current_index].is_purchased ~= true then 
  440. 				game_UI_audio_play("UI_Main_Menu_Select") 
  441. 			end 
  442. 		end 
  443. 		 
  444. 		if Menu_data[current_index].on_select ~= nil then 
  445. 			-- Save off a local to determine if we have a sub menu to enter, because the on_select callback could 
  446. 			-- change Menu_data!  If the callback does this, this selection should never expect to have a sub menu. 
  447. 			local enter_sub_menu = true 
  448. 			if Menu_data[current_index].on_sub_menu_fill == nil and Menu_data[current_index].sub_menu == nil then 
  449. 				enter_sub_menu = false 
  450. 			end 
  451. 			Menu_data[current_index].on_select(Menu_data[current_index]) 
  452.  
  453. 			-- we're done, unless there is a sub menu 
  454. 			if enter_sub_menu == false then 
  455. 				return 
  456. 			end		 
  457. 		end 
  458.  
  459. 		Store_common_sub_menu = {} 
  460. 		 
  461. 		-- submenu exists, but still needs to be generated 
  462. 		if Menu_data[current_index].on_sub_menu_fill ~= nil then 
  463. 			Menu_data[current_index].sub_menu = {} 
  464. 			Menu_data[current_index].on_sub_menu_fill(Menu_data[current_index])  
  465. 		else  
  466. 			if Menu_data.default_on_sub_menu_fill ~= nil then 
  467. 				Menu_data[current_index].sub_menu = {} 
  468. 				Menu_data.default_on_sub_menu_fill(Menu_data[current_index]) 
  469. 			end 
  470. 		end 
  471. 		 
  472. 		 
  473. 		if (Menu_data[current_index].sub_menu == nil or #Menu_data[current_index].sub_menu <= 0) and #Store_common_sub_menu == 0 then 
  474. 			return 
  475. 		end 
  476. 	 
  477.  
  478. 		-- reposition camera based on settings for this item	 
  479. 		if Menu_data[current_index].camera ~= nil then 
  480. 			store_set_camera_pos(Menu_data[current_index].camera) 
  481. 		end		 
  482. 		 
  483. 		-- Different C call for vehicle cameras 
  484. 		if Menu_data[current_index].vcamera ~= nil then 
  485. 			vcust_set_camera_pos(Menu_data[current_index].vcamera, true) 
  486. 			-- local hint_rotate_data = { 
  487. 				-- {CTRL_BUTTON_RS, "STORE_ZOOM"}, 
  488. 			-- } 
  489. 			-- Store_common_rotate_hint:set_hints(hint_rotate_data)	 
  490. 			Store_common_rotate_hint:set_visible(false)		 
  491. 		end 
  492. 		 
  493.  
  494. 		--Add current selection to the stack to store the selected position on the menu 
  495. 		store_common_stack_add_id(current_id) 
  496. 		store_common_stack_add_index(current_index) 
  497.  
  498. 		-- drill down further into our menu depth 
  499. 		 
  500. 		-- set the titles on top 
  501. 		local title = nil 
  502. 		local title_crc = nil 
  503. 		title_crc = Menu_data[Active_list:get_selection()].label_crc 
  504. 		if title_crc == nil then 
  505. 			title = Menu_data[Active_list:get_selection()].label 
  506. 		end 
  507. 		Store_header:push_title( title_crc, title ) 
  508. 		 
  509. 		-- Store off tables we need for backing out of the menu	 
  510. 		store_common_stack_add_menu(Menu_data) 
  511. 		 
  512. 		-- Now move to the new sub menu 
  513. 		if #Store_common_sub_menu > 0 then 
  514. 			Menu_data = Store_common_sub_menu 
  515. 		else 
  516. 			Menu_data = Menu_data[current_index].sub_menu 
  517. 		end 
  518. 		 
  519. 		-- populate the new list 
  520. 		if Store_common_populate_list_cb ~= 0 then 
  521. 		 
  522. 			-- sub_menu_fill may have decided that our starting selection was something other than the first 
  523. 			local start_index = 1 
  524. 			if Menu_data.start_index ~= nil and Menu_data.start_index >= 1 and Menu_data.start_index <= #Menu_data then  
  525. 				start_index = Menu_data.start_index 
  526. 			end 
  527. 			Store_common_populate_list_cb(Menu_data, start_index) 
  528. 		end 
  529. 		 
  530. 		-- Call on_enter function since we're entering the menu 
  531. 		if Menu_data.on_enter ~= nil then 
  532. 			Menu_data.on_enter(Menu_data) 
  533. 		end	 
  534. 		 
  535. 		Store_common_sub_menu = {} 
  536. 	end 
  537. end 
  538.  
  539. -- Handle B/back button action on a menu item. 
  540. -- 
  541. function store_common_button_b(event) 
  542. 	Store_common_override_input = true 
  543. 	if store_common_allow_input(event) == false then 
  544. 		Store_common_override_input = false 
  545. 		return 
  546. 	end 
  547. 	 
  548. 	--used to bypass the animate when vechicle store needs to backout 2 times in a row, in function store_vehicle_purchase_color_final 
  549. 	local list_is_playing = Active_list:list_is_playing() 
  550. 	if Store_common_bypass_animate then  
  551. 		list_is_playing = false 
  552. 	end 
  553. 	Store_common_bypass_animate = false --set it back to false for next time 
  554. 	 
  555. 	--Do NOT allow input until list is finish animating 
  556. 	if list_is_playing == false then 
  557. 		-- If we're at the top level, ask if player wants to leave store 
  558. 		if store_common_stack_get_menu() == nil and Store_common_exit_cb ~= 0 then 
  559. 			Store_common_exit_cb() 
  560. 			Store_common_override_input = false 
  561. 			return 
  562. 		end	 
  563. 		 
  564. 		--Removed check for open toggles since, we don't open them anymore and they are inline. JMH (4/27/2011) 
  565. 		 
  566. 		-- get index of current selection 
  567. 		local index = Active_list:get_selection()	 
  568. 		 
  569. 		-- If player needs to confirm a cancel, do that callback.  If it doesn't return true, then a confirm 
  570. 		-- isn't needed right now.  If a confirm is needed, return since we can't back up now. 
  571. 		if Menu_data[index].on_cancel_confirm ~= nil then 
  572. 			local confirm_needed = Menu_data[index].on_cancel_confirm(Menu_data[index]) 
  573. 			if confirm_needed == true then 
  574. 				Store_common_override_input = false 
  575. 				return 
  576. 			end 
  577. 		end	 
  578. 		 
  579. 		game_UI_audio_play("UI_Main_Menu_Nav_Back")		 
  580. 		 
  581. 		-- do on_cancel callback if we have one 
  582. 		if Menu_data[index].on_cancel ~= nil then 
  583. 			Menu_data[index].on_cancel(Menu_data[index]) 
  584. 		end		 
  585. 		 
  586. 		store_common_back_menu() 
  587. 	else 
  588. 		Store_common_override_input = false 
  589. 	end 
  590. end 
  591. 	 
  592. function store_common_back_menu() 
  593. 	 
  594. 	--Remove current menu from the stack 
  595. 	store_common_stack_remove_id() 
  596. 	store_common_stack_remove_index() 
  597.  
  598. 	-- do on_back callback if we have one 
  599. 	local index = Active_list:get_selection() 
  600. 	if Menu_data[index].on_back ~= nil then 
  601. 		Menu_data[index].on_back(Menu_data[index]) 
  602. 	else 
  603. 		if Menu_data.default_on_back ~= nil then 
  604. 			Menu_data.default_on_back(Menu_data[index]) 
  605. 		end 
  606. 	end 
  607. 	 
  608. 	-- pop back up our menu depth 
  609. 	 
  610. 	-- set the titles on top 
  611. 	Store_header:pop_title() 
  612. 	 
  613. 	local current_id = store_common_stack_get_id() 
  614. 	local current_index = store_common_stack_get_index()	 
  615. 	 
  616. 	-- Retrieve the previous menu 
  617. 	Menu_data = store_common_stack_get_menu() 
  618. 	store_common_stack_remove_menu()		 
  619. 	 
  620. 	-- set the new active list with the new data 
  621. 	if Store_common_populate_list_cb ~= 0 then 
  622. 		Store_common_populate_list_cb(Menu_data, current_index) 
  623. 	end 
  624.  
  625. 	-- Call on_enter function since we're entering the menu 
  626. 	if Menu_data.on_enter ~= nil then 
  627. 		Menu_data.on_enter(Menu_data) 
  628. 	end	 
  629. 	 
  630. 	-- do this so holding down the button doesn't cause repeated actions 
  631. 	--Input_tracker:subscribe(false)		 
  632. 	--Input_tracker:subscribe(true)	 
  633. 	Store_common_override_input = false 
  634. end 
  635.  
  636. -- Common up/down navigation code 
  637. -- 
  638. function store_common_nav_up_down(movement, do_not_redraw) 
  639.  
  640. 	if store_common_allow_input(movement) == false then 
  641. 		return 
  642. 	end 
  643. 	 
  644. 	--Do NOT allow input until list is finish animating 
  645. 	if Active_list:list_is_playing() == false then 
  646. 		-- Move highlight 
  647. 		Active_list:move_cursor(movement, do_not_redraw) 
  648. 		 
  649. 		if Mouse_input_tracker ~= 0 then 
  650. 			Active_list:update_mouse_inputs("store_common", Mouse_input_tracker) 
  651. 		end 
  652. 		 
  653. 		-- get a more convenient reference to the current item in the list 
  654. 		local data_item = Active_list:return_selected_data() 
  655.  
  656. 		if data_item.on_nav ~= nil then 
  657. 			data_item.on_nav(data_item) 
  658. 			return 
  659. 		end 
  660. 		 
  661. 		if Menu_data.default_on_nav ~= nil then 
  662. 			Menu_data.default_on_nav(data_item) 
  663. 		end 
  664. 	end 
  665. end 
  666.  
  667. function store_common_nav_up() 
  668. 	-- Move highlight up 
  669. 	store_common_nav_up_down(-1) 
  670. end 
  671.  
  672.  
  673. function store_common_nav_down() 
  674. 	-- Move highlight down 
  675. 	store_common_nav_up_down(1) 
  676. end 
  677.  
  678. -- Common left/right navigation code 
  679. -- 
  680. function store_common_nav_left_right(movement) 
  681.  
  682. 	if store_common_allow_input(movement) == false then 
  683. 		return 
  684. 	end 
  685. 	 
  686. 	-- Move highlight 
  687. 	Active_list:move_slider(movement) 
  688. 	 
  689. 	-- get a more convenient reference to the current item in the list 
  690. 	local data_item = Active_list:return_selected_data() 
  691. 	--local current_index = Active_list:get_selection() 
  692.  
  693. 	if data_item.on_value_update ~= nil then 
  694. 		data_item.on_value_update(data_item) 
  695. 		return 
  696. 	end 
  697. end 
  698.  
  699. -- Handle navigating left (sliders) 
  700. -- 
  701. function store_common_nav_left(event, acceleration) 
  702. 	store_common_nav_left_right(-1) 
  703. end 
  704.  
  705. -- Handle navigating right (sliders) 
  706. -- 
  707. function store_common_nav_right(event, acceleration) 
  708. 	store_common_nav_left_right(1) 
  709. end 
  710.  
  711. function store_common_mouse_click(event, target_handle, mouse_x, mouse_y) 
  712.  
  713. 	if store_common_allow_input(event) == false then 
  714. 		return 
  715. 	end 
  716. 	 
  717. 	local new_index = Active_list:get_button_index(target_handle) 
  718. 	if new_index ~= 0 then 
  719. 	 
  720. 		local old_index = Active_list:get_selection() 
  721. 		Active_list:set_selection(new_index) 
  722. 		 
  723. 		-- Check if the user clicked on the slider 
  724. 		local current_selection = Active_list:return_selected_data() 
  725. 		if current_selection.type == TYPE_SLIDER then 
  726. 			if Active_list:is_slider(target_handle) then 
  727. 				Active_list:move_slider(0, mouse_x) 
  728. 				 
  729. 				-- get a more convenient reference to the current item in the list 
  730. 				local data_item = Active_list:return_selected_data() 
  731. 				 
  732. 				if data_item.on_value_update ~= nil then 
  733. 					data_item.on_value_update(data_item) 
  734. 				end 
  735. 			end 
  736. 			 
  737. 		else 
  738. 		 
  739. 			if old_index ~= new_index then 
  740. 				-- get a more convenient reference to the current item in the list 
  741. 				local data_item = Active_list:return_selected_data() 
  742.  
  743. 				if data_item.on_nav ~= nil then 
  744. 					data_item.on_nav(data_item) 
  745. 				else 
  746. 					if Menu_data.default_on_nav ~= nil then 
  747. 						Menu_data.default_on_nav(data_item) 
  748. 					end 
  749. 				end 
  750. 			end 
  751. 		 
  752. 			store_common_button_a() 
  753. 		end 
  754. 		 
  755. 		return 
  756. 	end 
  757. 	 
  758. 	-- Check if the user clicked on the toggle/slider arrows 
  759. 	local current_selection = Active_list:return_selected_data() 
  760. 	if current_selection.type == TYPE_SLIDER or current_selection.type == TYPE_TOGGLE then 
  761. 		if Active_list:is_left_arrow(target_handle) then 
  762. 			store_common_nav_left() 
  763. 		elseif Active_list:is_right_arrow(target_handle) then 
  764. 			store_common_nav_right() 
  765. 		end 
  766. 	end 
  767.  
  768. end 
  769.  
  770. function store_common_mouse_down(event, target_handle) 
  771.  
  772.  
  773. end 
  774.  
  775. -- Each store should have its own mouse_move function to handle the mouse_move events. This is here 
  776. -- as a backup case to work on the mega list at the very least. 
  777. -- 
  778. function store_common_mouse_move(event, target_handle) 
  779.  
  780. 	vint_set_mouse_cursor("") 
  781. 	store_common_mouse_zoom(0.0) 
  782. 	 
  783. 	Store_common_hint_bar:set_highlight(0) 
  784.  
  785. 	if store_common_allow_input(event) == false then 
  786. 		return 
  787. 	end 
  788.  
  789. 	if Active_list:list_is_playing() == false then		 
  790. 		local old_index = Active_list:get_selection() 
  791. 		local new_index = Active_list:get_button_index(target_handle)	 
  792. 		if new_index ~= 0 and new_index ~= old_index then 
  793. 			Active_list:set_selection(new_index) 
  794. 			store_common_nav_up_down(0, true) 
  795. 			return 
  796. 		end 
  797. 	end 
  798. 	 
  799. 		-- Check if the mouse is over the hint bar buttons 
  800. 	local hint_index = Store_common_hint_bar:get_hint_index(target_handle) 
  801. 	if hint_index ~= 0 then 
  802. 		Store_common_hint_bar:set_highlight(hint_index, Store_common_current_highlight_color) 
  803. 		return 
  804. 	end 
  805. end 
  806.  
  807. function store_common_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  808.  
  809. 	if target_handle == Character_mouse_drag_region then 
  810. 		store_common_mouse_zoom() 
  811. 	end 
  812.  
  813. 	if Active_list:list_is_playing() == false then			 
  814. 		if scroll_lines ~= 0 then 
  815. 			if Active_list:get_scroll_region_handle() == target_handle then 
  816. 				Active_list:scroll_list(scroll_lines * -1) 
  817. 				Active_list:update_mouse_inputs("store_common", Mouse_input_tracker) 
  818. 			end 
  819. 		end 
  820. 	end 
  821. end 
  822.  
  823. function store_common_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  824.  
  825. 	if store_common_allow_input(event) == false then 
  826. 		return 
  827. 	end 
  828.   
  829. 	if Active_list.scrollbar.tab_grp.handle == target_handle then 
  830. 		local new_start_index = Active_list.scrollbar:drag_scrolltab(mouse_y, Active_list.num_buttons - (Active_list.max_buttons - 1)) 
  831. 		Active_list:scroll_list(0, new_start_index) 
  832. 		 
  833. 	elseif Active_list:is_slider(target_handle) then 
  834. 		local updated = Active_list:move_slider(0, mouse_x) 
  835. 		 
  836. 		-- Update if the slider changed 
  837. 		if updated then 
  838. 			local data_item = Active_list:return_selected_data()		 
  839. 			if data_item.on_value_update ~= nil then 
  840. 				data_item.on_value_update(data_item) 
  841. 			end 
  842. 		end 
  843. 	end 
  844. end 
  845.  
  846. -- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index 
  847. -- 
  848. function store_common_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  849.  
  850. 	if Active_list.scrollbar.tab_grp.handle == target_handle then 
  851. 		local start_index = Active_list:get_visible_indices() 
  852. 		Active_list.scrollbar:release_scrolltab(start_index, Active_list.num_buttons - (Active_list.max_buttons - 1)) 
  853. 		Active_list:update_mouse_inputs("store_common", Mouse_input_tracker) 
  854. 	end 
  855.  
  856. end 
  857.  
  858. function store_common_crib_is_loaded() 
  859. 	return vint_document_find("store_crib") ~= 0 
  860. end 
  861.  
  862. -- If store_common has just gained focus, it means we've left whatever store we were in. 
  863. -- Unload ourself. 
  864. -- 
  865. function store_common_gained_focus() 
  866. 	pop_screen() 
  867. end 
  868.  
  869. function store_common_play_anim_out() 
  870. 	local anim_out = Vdo_anim_object:new("store_common_anim_out", 0, Store_common_doc_handle) 
  871. 	anim_out:play(0) 
  872. end 
  873.  
  874.  
  875. function character_mouse_click(event, target_handle, mouse_x, mouse_y) 
  876.  
  877.  
  878. end 
  879.  
  880. function character_mouse_down(event, target_handle) 
  881.  
  882. 	if target_handle == Character_mouse_drag_region then 
  883. 		vint_set_mouse_cursor("Ui_cursor_hand_closed") 
  884. 	end 
  885.  
  886. end 
  887.  
  888. -- Each store should have its own mouse_move function to handle the mouse_move events. This is here 
  889. -- as a backup case to work on the mega list at the very least. 
  890. -- 
  891. function character_mouse_move(event, target_handle) 
  892.  
  893. 	Store_common_hint_bar:set_highlight(0) 
  894.  
  895. 	if target_handle == Character_mouse_drag_region then 
  896. 		vint_set_mouse_cursor("Ui_cursor_hand_open") 
  897. 	else 
  898. 		vint_set_mouse_cursor("") 
  899. 		store_common_mouse_zoom(0.0) 
  900. 	end 
  901.  
  902. end 
  903.  
  904. function character_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines, current_highlighted_element) 
  905.  
  906. 	if current_highlighted_element == Character_mouse_drag_region then 
  907. 		store_common_mouse_zoom() 
  908. 	else 
  909. 		store_common_mouse_zoom(0.0) 
  910. 	end 
  911. 	 
  912. end 
  913.  
  914. function character_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  915.  
  916. 	if target_handle == Character_mouse_drag_region then 
  917. 		vint_set_mouse_cursor("Ui_cursor_hand_closed") 
  918. 		store_common_rotate_mouse_drag() 
  919. 	end 
  920.  
  921. end 
  922.  
  923. -- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index 
  924. -- 
  925. function character_mouse_drag_release(event, target_handle, mouse_x, mouse_y, lines_to_scroll, current_highlighted_element) 
  926.  
  927. 	if current_highlighted_element ~= Character_mouse_drag_region then 
  928. 		vint_set_mouse_cursor("") 
  929. 		store_common_mouse_zoom(0.0) 
  930. 	elseif target_handle == Character_mouse_drag_region then 
  931. 		vint_set_mouse_cursor("Ui_cursor_hand_open") 
  932. 	end 
  933.  
  934. end 
  935.  
  936. function character_enable_mouse_drag(enable) 
  937. 	if Character_mouse_input_tracker ~= 0 and Character_mouse_input_tracker ~= nil then 
  938. 		Character_mouse_input_tracker:subscribe(enable) 
  939. 	end 
  940. 	 
  941. 	if enable == false then 
  942. 		vint_set_mouse_cursor("") 
  943. 	end 
  944. end 
  945.  
  946. -- JM: Adding this for video capturing  
  947. function store_common_hide_controls() 
  948. 	Store_common_hint_bar:set_visible(false) 
  949. 	Store_common_hint_bar:set_alpha(0) 
  950. 	Store_common_rotate_hint:set_visible(false) 
  951. 	Store_common_rotate_hint:set_alpha(0) 
  952. end 
  953.  
  954. --[[ --------------------------------------------------------------------- 
  955. -- Function - store_common_input_disable 
  956. -- Description - Disable input for store 
  957. -- Parameters - None 
  958. -- Returns - Nil 
  959. ]]-- --------------------------------------------------------------------- 
  960. function store_common_input_disable() 
  961. 	Input_tracker:subscribe(false) 
  962. 	if game_get_platform() == "PC" then	 
  963. 		Mouse_input_tracker:subscribe(false) 
  964. 		Character_mouse_input_tracker:subscribe(false) 
  965. 	end 
  966. end 
  967.  
  968. --[[ --------------------------------------------------------------------- 
  969. -- Function - store_common_input_enable 
  970. -- Description - Enables input for store 
  971. -- Parameters - None 
  972. -- Returns - Nil 
  973. ]]-- --------------------------------------------------------------------- 
  974. function store_common_input_enable() 
  975. 	Input_tracker:subscribe(true) 
  976. 	if game_get_platform() == "PC" then	 
  977. 		Mouse_input_tracker:subscribe(true) 
  978. 		Character_mouse_input_tracker:subscribe(true) 
  979. 	end 
  980. end