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