./store_clothing.lua

  1.  
  2. STORE_CLOTHING_INVALID_INDEX 	= -1 
  3. SCALE_FONT_STORE_CLOTHING_LIST = 0.8 
  4.  
  5. STORE_CLOTHING_CATEGORY_MAX = 150 
  6. STORE_CLOTHING_TOTAL_MAX	 = 2048 
  7.  
  8. BRAND_NONE		= -1 
  9. BRAND_ASTRO		= 0 
  10. BRAND_CROOKS	= 1 
  11. BRAND_HEYDEY	= 2 
  12. BRAND_JOYSTICK	= 3 
  13. BRAND_RIPPLE	= 4 
  14. BRAND_SOTA		= 5 
  15.  
  16. Store_clothing_doc_handle = -1 
  17.  
  18. local CRIB 				= 0 
  19. local LETS_PRETEND 		= 1 
  20. local NOBODY_LOVES_ME 	= 2 
  21. local LEATHER_AND_LACE  = 3 
  22. local PLANET_SAINTS		= 4 
  23.  
  24. local Store_clothing_data = {								  
  25. 	[CRIB] 					= { pegs = { }, 										color = COLOR_STORE_CRIB_PRIMARY,			logo_grp = "store_title_grp"}, 
  26. 	[LETS_PRETEND] 		= { pegs = { "ui_bms_store_lets_pretend" },	color = COLOR_STORE_LETS_PRETEND_PRIMARY, 	logo_grp = "store_logo_grp"}, 
  27. 	[NOBODY_LOVES_ME] 	= { pegs = { "ui_bms_store_nobody" }, 			color = COLOR_STORE_NOBODY_PRIMARY, 			logo_grp = "nobody_logo_grp"}, 
  28. 	[LEATHER_AND_LACE] 	= { pegs = { "ui_bms_store_lace" }, 			color = COLOR_STORE_LACE_PRIMARY,				logo_grp = "lace_logo_grp"}, 
  29. 	[PLANET_SAINTS] 		= { pegs = { "ui_bms_store_planet" }, 			color = COLOR_STORE_PLANET_PRIMARY, 			logo_grp = "planet_logo_grp"},	 
  30. } 
  31.  
  32. local Store_clothing_brand_data = { 
  33. 	[BRAND_ASTRO]			= { logo = "ui_store_brand_astro"}, 
  34. 	[BRAND_CROOKS]			= { logo = "ui_store_brand_crooks"}, 
  35. 	[BRAND_HEYDEY]			= { logo = "ui_store_brand_heyday"}, --the targa is spelled heyday 
  36. 	[BRAND_JOYSTICK]		= { logo = "ui_store_brand_joystick"}, 
  37. 	[BRAND_RIPPLE]			= { logo = "ui_store_brand_ripple"}, 
  38. 	[BRAND_SOTA]			= { logo = "ui_store_brand_sota"}, 
  39. } 
  40.  
  41. local Store_index = LETS_PRETEND 
  42. local Next_anim_to_play = 0 
  43.  
  44. local Online_check_thread = -1 
  45.  
  46. -- These tables hold our menu and toggle data that get populated into the vdo's. 
  47. local Toggle_data 			= {} 
  48. local Wear_opt_data 		   = {} 
  49. local Style_variant_data 	= {} 
  50. Color_grid_data 				= {} 
  51.  
  52. -- Used to determine which of three colors player is currently picking, and the index in the color grid is currently chosen. 
  53. local Color_grid_idx			= 1 
  54. local Color_slot_chosen		= 0 
  55.  
  56. -- Save off current clothing color index if player cancels change 
  57. local Color_prev_color		= 0 
  58.  
  59. -- Hint bar and store header vdo's. 
  60.  
  61. local Store_logo_grp 
  62. local Store_logo1 
  63. local Store_logo2 
  64. local Not_popup_grp 
  65. local Reward_image 
  66.  
  67. STORE_CLOTHING_PENDING_NONE				= -1 
  68. STORE_CLOTHING_PENDING_ITEM				= 1 
  69. STORE_CLOTHING_PENDING_STORE_OUTFIT		= 2 
  70. STORE_CLOTHING_PENDING_OWNED_OUTFIT		= 3 
  71.  
  72. -- Variables for background updating threads. 
  73. local Store_clothing_item_update_thread 		= -1 
  74. local Store_clothing_waiting_update_value 	= STORE_CLOTHING_PENDING_NONE 
  75. local Store_clothing_outfit_id					= -1 
  76. local Store_clothing_outfit_finalize			= false 
  77.  
  78. -- Keeps tracking of the area and category that we've currently selected 
  79. local Store_clothing_area				= -1 
  80. local Store_clothing_category 		= -1 
  81.  
  82. local Store_clothing_brands_loaded  = false 
  83.  
  84. -- This table holds a ton of information for the currently selected clothing item. 
  85. Store_clothing_item_info = { 
  86. 	colors = { [0] = { }, [1] = { }, [2] = { } } 
  87. } 
  88.  
  89. -- Determines if we're in "store" or "wardrobe" mode. 
  90. local Store_clothing_is_wardrobe = false 
  91.  
  92. local Store_clothing_loaded_from_crib = false 
  93.  
  94. -- Menu Tiers 
  95. local MENU_TIER	= 1 
  96. local COLOR_TIER	= 2 
  97. local Current_tier = MENU_TIER 
  98.  
  99. local Game_platform 
  100. Hint_bar_mouse_input_tracker = -1 
  101.  
  102. ---------------------------------------------------------------------------  
  103. -- Initialize Clothing Store 
  104. --------------------------------------------------------------------------- 
  105. function store_clothing_init() 
  106.  
  107. 	Store_clothing_doc_handle = vint_document_find("store_clothing")	 
  108.  
  109. 	-- Save boolean if we're coming from the crib 
  110. 	Store_clothing_loaded_from_crib = store_common_crib_is_loaded()		 
  111. 		 
  112. 	if Store_clothing_loaded_from_crib == false then 
  113. 		pause_map_dump() 
  114. 	end 
  115. 	 
  116. 	thread_new("store_clothing_pause_map_delay") 
  117. 	 
  118. 	-- These should either be globals, or just use vint_set_property to mark these visible false, rather than Vdo_base_object:new here 
  119. 	local lets_pretend_bg_grp = Vdo_base_object:new("lets_pretend_bg_grp", 0, Store_clothing_doc_handle) 
  120. 	local nobody_grp = Vdo_base_object:new("nobody_grp", 0, Store_clothing_doc_handle) 
  121. 	local lace_grp = Vdo_base_object:new("lace_grp", 0, Store_clothing_doc_handle) 
  122. 	local planet_grp = Vdo_base_object:new("planet_grp", 0, Store_clothing_doc_handle) 
  123. 	local brand_logo = Vdo_base_object:new("brand_logo_img", 0, Store_clothing_doc_handle) 
  124. 		 
  125. 	lets_pretend_bg_grp:set_visible(false) 
  126. 	nobody_grp:set_visible(false) 
  127. 	lace_grp:set_visible(false) 
  128. 	planet_grp:set_visible(false) 
  129. 	brand_logo:set_visible(false) 
  130. 	 
  131. 	--set the index so we know what peg to load 
  132. 	Store_index = store_clothing_get_store_id() 
  133. 	 
  134. 	--Override return if we're coming from the crib doc 
  135. 	if Store_clothing_loaded_from_crib then 
  136. 		Store_index = CRIB 
  137. 	end 
  138. 	 
  139. 	-- We don't need to animate in the background or load pegs or change colors if we're coming from the crib interface. 
  140. 	local pegs = Store_clothing_data[Store_index].pegs 
  141. 	local peg_count = #Store_clothing_data[Store_index].pegs 
  142. 	 
  143. 	if Store_index == CRIB then 
  144. 		store_clothing_set_store() 
  145. 	else 
  146. 		game_peg_load_with_cb("store_clothing_set_store", 1, pegs[1]) 
  147. 	end 
  148. 	 
  149. 	character_enable_mouse_drag(true)		 
  150. end 
  151.  
  152. -- Lock input until streaming is done, to prevent issues with backing out of menus before a previewed item appears at it doesn't get reverted. 
  153. -- 
  154. function store_clothing_allow_input(event) 
  155. 	 
  156. 	if (event == "back" ) then 
  157. 		delay( 0.1 ) 
  158. 	end 
  159. 	 
  160. 	--Assume the player is not allowed to move until proven otherwise 
  161. 	local allow = false 
  162. 	--Pull whether or not the preview of the highlighted item is still loading 
  163. 	local pcu_done = pcu_is_streaming_done()  
  164. 	--Check if the input is not "back" and not "select" 
  165. 	local not_back_select = (event ~= "back" and event ~= "select") 
  166. 	 
  167. 	--If the new item is done streaming 
  168. 	if( pcu_is_streaming_done() ) then 
  169. 		--Set allow if the preview is done streaming or if the input is not back or select 
  170. 		allow = ( pcu_done or not_back_select ) 
  171. 	--If check just in case the player has skipped over item in the nav list 
  172. 	elseif( type(event) == "number") then 
  173. 		--Allow player to move since they are just navigating the menu 
  174. 		allow = true 
  175. 	end 
  176. 	return allow 
  177. 	--[[ 
  178. 	local allow = pcu_is_streaming_done() or (event ~= "back" and event ~= "select") 
  179. 	return allow 
  180. 	]]-- 
  181. end	 
  182.  
  183. function store_clothing_set_store() 
  184.  
  185. 	Game_platform = game_get_platform() 
  186. 	 
  187. 	-- If we're in the crib, we're only doing wardrobe (not store). 
  188. 	Store_clothing_is_wardrobe = Store_clothing_loaded_from_crib 
  189. 	 
  190. 	-- Set up some callbacks for the common store script 
  191. 	Store_common_populate_list_cb = store_clothing_populate_list 
  192. 	Store_common_exit_cb				= store_clothing_exit 
  193. 	Store_common_allow_input_cb	= store_clothing_allow_input 
  194.  
  195. 	-- Subscribe to the button presses we need, Input_tracker is created in store_common.lua 
  196. 	Input_tracker:subscribe(false) 
  197.  
  198. 	local hint_data = {	 
  199. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},			 
  200. 	} 
  201. 	Store_common_hint_bar:set_hints(hint_data)  
  202. 	Store_common_hint_bar:set_visible(true) 
  203.  
  204. 	if game_is_active_input_gamepad() then 
  205. 		local hint_rotate_data = { 
  206. 			{CTRL_BUTTON_RS, "STORE_ZOOM_ROTATE"}, 
  207. 		} 
  208. 		Store_common_rotate_hint:set_hints(hint_rotate_data) 
  209. 		if Game_platform ~= "PC" then 
  210. 			Store_common_rotate_hint:set_visible(true) 
  211. 		end 
  212. 	end 
  213. 	 
  214. 	if Game_platform == "PC" then 
  215. 		Mouse_input_tracker:subscribe(false) 
  216. 		 
  217. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  218. 		Store_common_rotate_hint:set_visible(false) 
  219. 	end 
  220. 	 
  221. 	Store_header:set_visible(true) 
  222. 	 
  223. 	Store_logo_grp = Vdo_base_object:new("store_logo_grp", 0, Store_clothing_doc_handle) 
  224. 	Store_logo1 = Vdo_base_object:new("store_logo_img_1", 0, Store_clothing_doc_handle) 
  225. 	Store_logo2 = Vdo_base_object:new("store_logo_img_2", 0, Store_clothing_doc_handle) 
  226. 	 
  227. 	-- Everything that is not in the popup so we can fade it when the popup is active 
  228. 	Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle) 
  229. 	 
  230. 	-- Setup purchase popup 
  231. 	Store_common_popup:set_visible(false) 
  232. 	Store_common_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5)) 
  233. 	 
  234. 	-- Setup Color grid 
  235. 	Store_common_color_grid:set_visible(false) 
  236. 	Store_common_color_grid:set_ui_screen("store_clothing") 
  237.  
  238. 	-- Start up the background update thread. 
  239. 	if Store_clothing_item_update_thread == -1 then 
  240. 		Store_clothing_item_update_thread = thread_new("store_clothing_item_preview_update") 
  241. 	end	 
  242. 	 
  243. 	-- SEH 
  244. 	Active_list:set_highlight_color(Store_clothing_data[Store_index].color)	 
  245. 	 
  246. 	Store_common_current_highlight_color = Store_clothing_data[Store_index].color 
  247. 	if Store_clothing_loaded_from_crib then 
  248. 		Store_common_current_highlight_color = COLOR_STORE_CRIB_PRIMARY 
  249. 	end 
  250. 	 
  251. 	-- Do all our main initialization based on which mode (store or wardrobe) we're in 
  252. 	store_clothing_mode_set_init()	 
  253. 	 
  254. 	-- make background so player is on top 
  255. 	bg_saints_set_background(false) 
  256.  
  257. 	local lets_pretend_bg_grp = Vdo_base_object:new("lets_pretend_bg_grp", 0, Store_clothing_doc_handle) 
  258. 	local nobody_grp = Vdo_base_object:new("nobody_grp", 0, Store_clothing_doc_handle) 
  259. 	local lace_grp = Vdo_base_object:new("lace_grp", 0, Store_clothing_doc_handle) 
  260. 	local planet_grp = Vdo_base_object:new("planet_grp", 0, Store_clothing_doc_handle) 
  261. 		 
  262. 	-- animate in ui for clothing store (shared by all stores) 
  263. 	local store_clothing_in_anim = Vdo_anim_object:new("store_common_in_anim", 0, Store_common_doc_handle) 
  264. 	local end_event_twn = Vdo_tween_object:new("end_event_twn", store_clothing_in_anim.handle, Store_common_doc_handle) 
  265. 	end_event_twn:set_end_event("store_unlock_controls") 
  266. 	 
  267. 	-- offset if we are in the crib 
  268. 	if Store_clothing_is_wardrobe then 
  269. 		local cloth_screen_grp_twn = vint_object_find("cloth_screen_grp_twn",0,Store_common_doc_handle) 
  270. 		local twn_x,twn_y = vint_get_property(cloth_screen_grp_twn,"end_value") 
  271. 		vint_set_property(cloth_screen_grp_twn, "end_value", Store_common_screen_grp_x, twn_y) 
  272. 		local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle) 
  273. 		store_main_grp:set_anchor(0,0) 
  274. 	end 
  275. 	 
  276. 	vint_apply_start_values(store_clothing_in_anim.handle) 
  277. 	store_clothing_in_anim:play(0) 
  278. 	 
  279. 	-- Set Store Header colors 
  280. 	Store_header:set_color(Store_clothing_data[Store_index].color, COLOR_STORE_CLOTHING_SECONDARY, COLOR_STORE_CLOTHING_TERTIARY)	 
  281.  
  282. 	-- Needs to be done after the list is drawn/populated 
  283. 	--Active_list:set_highlight_color(Store_clothing_data[Store_index].color) 
  284. 	Store_common_color_grid:set_highlight_color(Store_clothing_data[Store_index].color) 
  285. 	 
  286. 	Store_common_popup:set_color(Store_clothing_data[Store_index].color, COLOR_STORE_CLOTHING_SECONDARY, COLOR_STORE_CLOTHING_TERTIARY)		 
  287. 	 
  288. 	local clothing_bg_grp = Vdo_base_object:new("screen_grp", 0, Store_clothing_doc_handle) 
  289. 	clothing_bg_grp:set_visible(true) 
  290. 	 
  291. 	if Store_index == CRIB then 
  292. 		bg_saints_set_type(BG_TYPE_CRIB,true,1280) 
  293. 		bg_saints_set_background(false) 
  294. 		 
  295. 		--hack just to get an animation for the rendering callback 
  296. 		local planet_bg_anim_in = Vdo_anim_object:new("planet_bg_anim_in", 0, Store_clothing_doc_handle) 
  297. 		local planet_bg_twn = Vdo_tween_object:new("new_tween67", planet_bg_anim_in.handle, Store_clothing_doc_handle)		 
  298. 		 
  299. 		vint_apply_start_values(planet_bg_anim_in.handle) 
  300. 		 
  301. 		planet_bg_anim_in:play(0) 
  302. 		 
  303. 		planet_bg_twn:set_end_event("store_clothing_bg_anim_done") 
  304. 		 
  305. 		--store_unlock_controls() 
  306. 		 
  307. 		-- SEH: 6/28/11: commenting out because we do need this visible for the "brand logo"- and it doesn't appear to be necessary. 
  308. 		-- Hide clothing store background since we use the saints background in crib 
  309. 		--local clothing_bg_grp = Vdo_base_object:new("screen_grp", 0, Store_clothing_doc_handle) 
  310. 		--clothing_bg_grp:set_visible(false) 
  311. 		 
  312. 	elseif  Store_index == LETS_PRETEND then 
  313. 	 
  314. 	 
  315. 				--Set background animations to running		 
  316. 				local lets_pretend_logo_anim = Vdo_anim_object:new("lets_pretend_logo_anim", 0, Store_clothing_doc_handle) 
  317. 				local bg_animation1 = Vdo_anim_object:new("rainbow1_anim", 0, Store_clothing_doc_handle) 
  318. 				local bg_animation2 = Vdo_anim_object:new("rainbow2_anim", 0, Store_clothing_doc_handle) 
  319. 				local bg_animation3 = Vdo_anim_object:new("lets_pretend_bg_anim_in", 0, Store_clothing_doc_handle) 
  320. 				local bg_animation4 = Vdo_anim_object:new("lets_pretend_bg_anim", 0, Store_clothing_doc_handle) 
  321. 				local bg_twn = Vdo_tween_object:new("rainbow_end_event_twn", bg_animation1.handle, Store_clothing_doc_handle)		 
  322. 				local bg_twn2 = Vdo_tween_object:new("rainbow_end_event_twn", bg_animation2.handle, Store_clothing_doc_handle)			 
  323. 				local bg_twn4 = Vdo_tween_object:new("desaturate_twn", bg_animation3.handle, Store_clothing_doc_handle)		 
  324. 				 
  325. 				vint_apply_start_values(lets_pretend_logo_anim.handle) 
  326. 				vint_apply_start_values(bg_animation1.handle) 
  327. 				vint_apply_start_values(bg_animation2.handle) 
  328. 				vint_apply_start_values(bg_animation3.handle)			 
  329. 				 
  330. 				lets_pretend_logo_anim:play(0) 
  331. 				 
  332. 				--bg_animation1:play(0) 
  333. 				--bg_animation2:play(0) 
  334. 				bg_animation3:play(0) 
  335. 				bg_animation4:play(0) 
  336. 				 
  337. 				ui_audio_post_event("enter_lets_pretend") 
  338. 					 
  339. 				bg_twn:set_end_event("store_loop_bg_anims") 
  340. 				--bg_twn2:set_end_event("store_loop_bg_anims") 
  341. 				bg_twn4:set_end_event("store_clothing_bg_anim_done") 
  342. 				 
  343. 		lets_pretend_bg_grp:set_visible(true) 
  344. 		 
  345. 	elseif Store_index == NOBODY_LOVES_ME then 
  346. 	 
  347. 		local nobody_logo_anim = Vdo_anim_object:new("nobody_logo_anim", 0, Store_clothing_doc_handle) 
  348. 		local nobody_bg_anim_in = Vdo_anim_object:new("nobody_bg_anim_in", 0, Store_clothing_doc_handle)		 
  349. 		 
  350. 		--tell next anim to play 
  351. 		local end_event_twn = Vdo_tween_object:new("end_event_twn", nobody_bg_anim_in.handle) 
  352. 		end_event_twn:set_end_event("store_clothing_loop_nobody_bg") 
  353. 		 
  354. 		local twn = Vdo_tween_object:new("new_tween68", nobody_bg_anim_in.handle, Store_clothing_doc_handle) 
  355. 					 
  356. 		vint_apply_start_values(nobody_logo_anim.handle) 
  357. 		vint_apply_start_values(nobody_bg_anim_in.handle) 
  358. 		 
  359. 		nobody_bg_anim_in:play(0) 
  360. 		nobody_logo_anim:play(0) 
  361. 		 
  362. 		ui_audio_post_event("enter_nobody_loves_me") 
  363. 		 
  364. 		twn:set_end_event("store_clothing_bg_anim_done") 
  365. 		 
  366. 		nobody_grp:set_visible(true)	 
  367. 		 
  368. 	elseif Store_index == LEATHER_AND_LACE then 
  369. 		 
  370. 		local lace_logo_anim = Vdo_anim_object:new("lace_logo_anim", 0, Store_clothing_doc_handle) 
  371. 		local lace_bg_anim = Vdo_anim_object:new("lace_bg_anim", 0, Store_clothing_doc_handle) 
  372. 		local lace_bg_anim_in = Vdo_anim_object:new("lace_bg_anim_in", 0, Store_clothing_doc_handle) 
  373. 		local lace_bg_twn = Vdo_tween_object:new("new_tween93", lace_bg_anim_in.handle, Store_clothing_doc_handle)		 
  374. 		 
  375. 		vint_apply_start_values(lace_bg_anim_in.handle) 
  376. 		vint_apply_start_values(lace_logo_anim.handle) 
  377. 		 
  378. 		 
  379. 		lace_bg_anim_in:play(0) 
  380. 		lace_logo_anim:play(0) 
  381. 		lace_bg_anim:play(0) 
  382. 		 
  383. 		ui_audio_post_event("enter_leatherlace") 
  384. 		 
  385. 		lace_bg_twn:set_end_event("store_clothing_bg_anim_done") 
  386. 		 
  387. 		lace_grp:set_visible(true) 
  388. 		 
  389. 	elseif Store_index == PLANET_SAINTS then 
  390. 		 
  391. 		local planet_logo_anim = Vdo_anim_object:new("planet_logo_anim", 0, Store_clothing_doc_handle) 
  392. 		local planet_bg_anim = Vdo_anim_object:new("planet_bg_anim", 0, Store_clothing_doc_handle) 
  393. 		local planet_bg_anim_in = Vdo_anim_object:new("planet_bg_anim_in", 0, Store_clothing_doc_handle) 
  394. 		local planet_bg_twn = Vdo_tween_object:new("new_tween67", planet_bg_anim_in.handle, Store_clothing_doc_handle)	 
  395. 		local planet_bg_anim2 = Vdo_anim_object:new("planet_bg_anim2", 0, Store_clothing_doc_handle) 
  396. 		 
  397. 		--tween loops in vinny 
  398. 		vint_apply_start_values(planet_logo_anim.handle) 
  399. 		vint_apply_start_values(planet_bg_anim.handle) 
  400. 		vint_apply_start_values(planet_bg_anim_in.handle) 
  401. 		 
  402. 		planet_bg_anim_in:play(0) 
  403. 		planet_logo_anim:play(0) 
  404. 		planet_bg_anim:play(0) 
  405. 		planet_bg_anim2:play(0) 
  406. 		 
  407. 		ui_audio_post_event("enter_planet_saints") 
  408. 		 
  409. 		 
  410. 		local planet_bg_anim2_h = vint_object_find("planet_bg_anim2",0,Store_clothing_doc_handle) 
  411. 		local planet_bg_anim2_twn_h = vint_object_find("end_event_twn",planet_bg_anim2_h) 
  412. 		vint_set_property(planet_bg_anim2_twn_h, "end_event", "vint_anim_loop_callback") 
  413.  
  414. 		 
  415. 		planet_bg_twn:set_end_event("store_clothing_bg_anim_done") 
  416. 		 
  417. 		planet_grp:set_visible(true) 
  418. 	end 
  419. end 
  420.  
  421. function store_clothing_pause_map_delay() 
  422. 	delay(2) 
  423. 	store_clothing_brand_load_peg() 
  424. end 
  425.  
  426. function store_clothing_brand_load_peg() 
  427. 	--Load peg for clothing store brand logos (used in ALL stores) 
  428. 	game_peg_load_with_cb("store_clothing_brand_loaded", 1, "ui_bms_store_brands") 
  429. end 
  430.  
  431. function store_clothing_brand_loaded() 
  432.  
  433. 	Store_clothing_brands_loaded = true 
  434.  
  435. end 
  436.  
  437. function store_clothing_brand_swap_logo(brand_id, show_brand) 
  438. 	 
  439. 	if Store_clothing_brands_loaded == false then 
  440. 		return 
  441. 	end 
  442. 	 
  443. 	local doc_handle = Store_clothing_doc_handle 
  444. 	 
  445. 	-- For the crib wardrobe, the logo is actually stored in the crib doc 
  446. 	if Store_index == CRIB then 
  447. 		doc_handle = Store_crib_doc_handle 
  448. 	end 
  449. 	 
  450. 	local store_logo_grp = Vdo_base_object:new(Store_clothing_data[Store_index].logo_grp, 0, doc_handle) 
  451. 	local brand_logo = Vdo_base_object:new("brand_logo_img", 0, Store_clothing_doc_handle) 
  452. 	 
  453. 	if show_brand == true then 
  454. 		--Hide store logo 
  455. 		store_logo_grp:set_visible(false) 
  456. 		 
  457. 		--Set and show brand logo 
  458. 		brand_logo:set_image(Store_clothing_brand_data[brand_id].logo) 
  459. 		brand_logo:set_visible(true) 
  460. 	else 
  461. 		--Show store logo 
  462. 		store_logo_grp:set_visible(true) 
  463. 		 
  464. 		--Hide brand logo 
  465. 		brand_logo:set_visible(false)	 
  466. 	end 
  467. end 
  468.  
  469. function store_clothing_loop_nobody_bg(tween_h) 
  470. 	--loop background anim 
  471. 	local nobody_bg_anim = Vdo_anim_object:new("nobody_bg_anim", 0, Store_clothing_doc_handle) 
  472. 	local twn_h = vint_object_find("end_event_twn", nobody_bg_anim.handle) 
  473. 	nobody_bg_anim:play(0) 
  474. 	vint_set_property(twn_h, "end_event", "vint_anim_loop_callback")	 
  475. 	 
  476. end	 
  477.  
  478. function store_unlock_controls() 
  479. 	bg_saints_set_background(true) 
  480. 	Input_tracker:subscribe(true) 
  481. 	store_clothing_enable_mouse(true) 
  482. end 
  483.  
  484. function store_loop_bg_anims(tween_handle) 
  485. 	local animation = vint_object_parent(tween_handle) 
  486. 	lua_play_anim(animation) 
  487. end 
  488.  
  489. -- Cleanup function called on document unload. 
  490. -- 
  491. function store_clothing_cleanup() 
  492. 	-- Remove anything that hasn't been purchased. 
  493. 	pcu_clear_preview_slot() 
  494.  
  495. 	-- kill update thread 
  496. 	if Store_clothing_item_update_thread ~= -1 then 
  497. 		thread_kill(Store_clothing_item_update_thread) 
  498. 		Store_clothing_item_update_thread = -1 
  499. 	end		 
  500.  
  501. 	-- Nuke all button subscriptions  
  502. 	Input_tracker:subscribe(false) 
  503. 	store_clothing_enable_mouse(false) 
  504. 	 
  505. 	local store_clothing_in_anim = Vdo_anim_object:new("store_clothing_in_anim", 0, Store_common_doc_handle) 
  506. 	local end_event_twn = Vdo_tween_object:new("end_event_twn", store_clothing_in_anim.handle, Store_common_doc_handle)	 
  507. 	end_event_twn:set_end_event(nil) 
  508.  
  509. 	-- unload all pegs 
  510. 	for key, peg_name in pairs(Store_clothing_data[Store_index].pegs) do 
  511. 		game_peg_unload(peg_name) 
  512. 	end	 
  513. 	 
  514. 	game_peg_unload("ui_bms_store_brands") 
  515. 	 
  516. 	if Store_clothing_loaded_from_crib == false then 
  517. 		pause_map_restore() 
  518. 	end 
  519. 	 
  520. 	character_enable_mouse_drag(false) 
  521. 	 
  522. 	-- Some things need to be cleaned up right away when a store doc is unloading, particular disabled inputs which have 
  523. 	-- callbacks to the script that is unloading. 
  524. 	store_common_cleanup_current_store()	 
  525. 	 
  526. 	if Online_check_thread ~= -1 then 
  527. 		thread_kill(Online_check_thread) 
  528. 	end	 
  529. end 
  530.  
  531. function store_clothing_exit() 
  532.  
  533. 	-- no confirmation needed if we're just going back to the crib menu 
  534. 	if Store_clothing_loaded_from_crib then 
  535. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  536. 		-- lock input during animation 
  537. 		Input_tracker:subscribe(false)	 
  538. 		store_clothing_enable_mouse(false) 
  539. 		-- make background so player is covered up 
  540. 		bg_saints_set_background(false) 
  541. 		local back_out_anim = Vdo_anim_object:new("store_crib_out_anim", 0, Store_common_doc_handle) 
  542. 		local back_out_end_twn = Vdo_tween_object:new("common_anchor_out_twn", back_out_anim.handle) 
  543. 		back_out_end_twn:set_end_event("store_clothing_crib_exit") 
  544. 		back_out_anim:play(0) 
  545. 	else 
  546. 		-- if we're in the wardrobe from a store, just go back to the store 
  547. 		if Store_clothing_is_wardrobe then 
  548. 			store_clothing_switch_mode() 
  549. 			return 
  550. 		end 
  551. 	 
  552. 		Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)	 
  553. 		Store_common_popup:set_title("MENU_TITLE_WARNING") 
  554. 		Store_common_popup:set_text("STORE_EXIT_WARNING_BODY") 
  555. 		 
  556. 		Store_common_popup:nav_enable(true, "store_clothing_exit_final", "store_clothing_popup_nav") 
  557. 		Not_popup_grp:set_alpha(.5) 
  558. 		Store_logo_grp:set_alpha(.5) 
  559. 		Active_list:set_visible(false) 
  560. 		store_clothing_enable_mouse(false) 
  561. 	end 
  562. end 
  563.  
  564. function store_clothing_crib_exit(tween_h, event) 
  565. 	-- called when we slide out to the crib 
  566. 	pop_screen() 
  567. end 
  568.  
  569. function store_clothing_exit_final(event) 
  570. 	Store_common_popup:nav_enable(false, nil, nil) 
  571. 		 
  572. 	-- The user hit the B button and is exiting 
  573. 	-- This is redundant to selecting "No" in the list 
  574. 	if event == "back" then 
  575. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  576. 		Not_popup_grp:set_alpha(1) 
  577. 		Store_logo_grp:set_alpha(1) 
  578. 		Active_list:set_visible(true) 
  579. 		store_clothing_enable_mouse(true) 
  580. 		return 
  581. 	end 
  582. 	 
  583. 	game_UI_audio_play("UI_Main_Menu_Select") 
  584. 	 
  585. 	-- Did we select yes?  This assumes yes is the first item 
  586. 	if Store_common_popup:get_selected_data() ~= 1 then 
  587. 		Not_popup_grp:set_alpha(1) 
  588. 		Store_logo_grp:set_alpha(1) 
  589. 		Active_list:set_visible(true) 
  590. 		store_clothing_enable_mouse(true) 
  591. 		return 
  592. 	end 
  593. 	 
  594. 	ui_audio_post_event("UI_Store_Exit") 
  595. 	 
  596. 	Input_tracker:subscribe(false) 
  597. 	store_clothing_enable_mouse(false) 
  598. 		 
  599. 	Not_popup_grp:set_alpha(0) 
  600. 	Store_logo_grp:set_alpha(0) 
  601. 	-- exit the interface 
  602. 	pop_screen() 
  603. end 
  604.  
  605. -- Called when this interface becomes the top one on the stack again. 
  606. -- 
  607. function store_clothing_gained_focus() 
  608.  
  609. 	--restore the ui color to store specific 
  610. 	Active_list:set_highlight_color(Store_clothing_data[Store_index].color)	 
  611. 	Store_header:set_color(Store_clothing_data[Store_index].color, COLOR_STORE_CLOTHING_SECONDARY, COLOR_STORE_CLOTHING_TERTIARY)	 
  612. 	 
  613. 	Input_tracker:subscribe(true)	 
  614. 	store_clothing_enable_mouse(true) 
  615. 	if Game_platform ~= "PC" then 
  616. 		Store_common_rotate_hint:set_visible(true) 
  617. 	end 
  618. 	 
  619. 	Store_common_hint_bar:set_visible(true) 
  620. 	character_enable_mouse_drag(true) 
  621. 	 
  622. 	bg_saints_show(false) 
  623. 	 
  624. 	-- Reinitialize state 
  625. 	store_clothing_mode_set_init() 
  626. 	 
  627. 	-- Set up some callbacks for the common store script 
  628. 	Store_common_populate_list_cb = store_clothing_populate_list 
  629. 	Store_common_exit_cb				= store_clothing_exit	 
  630. end 
  631.  
  632. -- Populate the active megalist menu, and hide the previous menu 
  633. -- 
  634. -- list_data: 		this table contains the data to populate the megalist 
  635. -- current_index: 	the current index in the menu that's selected 
  636. -- 
  637. function store_clothing_populate_list(list_data, current_index) 
  638.  
  639. 	Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10, SCALE_FONT_STORE_CLOTHING_LIST) 
  640. 	Active_list:set_visible(true) 
  641. 	 
  642. 	if Game_platform == "PC" then 
  643. 		Mouse_input_tracker:remove_all() 
  644. 		Active_list:set_store("store_clothing") 
  645. 		Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  646. 		Mouse_input_tracker:subscribe(true) 
  647. 	end 
  648. end 
  649.  
  650. -- Callback from C code that adds areas to Menu_data table. 
  651. -- 
  652. -- area_index: 	unique ID for the area. 
  653. -- label_crc: 	crc for the name to display.  nil if string is used instead. 
  654. -- label_str: 	string for the name to display.  nil if crc is used instead. 
  655. -- has_new_items: does this category have items that haven't been viewed in the wardrobe? 
  656. -- 
  657. function store_clothing_area_add(area_index, label_crc, label_str, has_new_items) 
  658. 	local menu_idx = #Menu_data + 1 
  659.  
  660. 	local new_item = { 
  661. 		type = TYPE_BUTTON, 
  662. 		id = area_index, 
  663. 		label = nil, 
  664. 		label_crc = nil, 
  665. 		on_nav = store_clothing_area_nav, 
  666. 		on_sub_menu_fill = store_clothing_category_get_all, 
  667. 		is_new = has_new_items, 
  668. 	}		 
  669.  
  670. 	Menu_data[menu_idx] = new_item 
  671. 	 
  672. 	-- Set the name of the menu choice, may be from crc or string itself 
  673. 	if label_crc ~= nil and label_crc ~= 0 then 
  674. 		new_item.label_crc = label_crc 
  675. 	else 
  676. 		new_item.label = label_str 
  677. 	end 
  678. 	 
  679. end 
  680.  
  681. function store_clothing_category_get_all(menu_data) 
  682. 	Store_common_sub_menu = {} 
  683. 	pcu_get_categories_in_area(Store_clothing_area, "store_clothing_category_add") 
  684. 	Store_clothing_category = Store_common_sub_menu[1].id 
  685. 	pcu_set_active_category(Store_clothing_category, Store_clothing_area)	 
  686. 	 
  687. 	-- If there is only one category in this area, just go on into the category menu! 
  688. 	if #Store_common_sub_menu == 1 then 
  689. 		local new_menu_data = {} 
  690. 		new_menu_data.id = Store_clothing_category 
  691. 		Store_common_sub_menu = {} 
  692. 		store_clothing_item_get_list(new_menu_data) 
  693. 	else 
  694. 		Store_common_sub_menu.on_enter = store_clothing_category_menu_update 
  695. 	end 
  696. end 
  697.  
  698. -- Refresh the clothing category menu when we return to it, since the "new" highlights may have been updated by browsing 
  699. -- 
  700. function store_clothing_category_menu_update(menu_data) 
  701. 	local index = Active_list:get_selection() 
  702. 	Menu_data = {} 
  703. 	Store_common_sub_menu = {} 
  704. 	pcu_set_active_category(Store_clothing_category, Store_clothing_area) 
  705. 	pcu_get_categories_in_area(Store_clothing_area, "store_clothing_category_add") 
  706. 	Menu_data = Store_common_sub_menu 
  707. 	Store_common_sub_menu = {} 
  708. 	 
  709. 	-- This can happen if we deleted the last piece of clothing we own 
  710. 	if #Menu_data == 0 then 
  711. 		store_common_back_menu() 
  712. 		return 
  713. 	end 
  714. 	 
  715. 	Menu_data.on_enter = store_clothing_category_menu_update	 
  716. 	store_clothing_populate_list(Menu_data, index) 
  717. end 
  718.  
  719. -- Callback from C code that adds categories to Menu_data table. 
  720. -- 
  721. -- area_index: 	unique ID for the category. 
  722. -- label_crc: 	crc for the name to display.  nil if string is used instead. 
  723. -- label_str: 	string for the name to display.  nil if crc is used instead. 
  724. -- has_new_items: this category contains items that haven't been viewed in the UI before. 
  725. -- 
  726. function store_clothing_category_add(cat_index, label_crc, label_str, has_new_items) 
  727. 	local menu_idx = #Store_common_sub_menu + 1 
  728.  
  729. 	local new_item = { 
  730. 		type = TYPE_BUTTON, 
  731. 		id = cat_index, 
  732. 		label = nil, 
  733. 		label_crc = nil, 
  734. 		on_nav = store_clothing_category_nav, 
  735. 		on_sub_menu_fill = store_clothing_item_get_list, 
  736. 		is_new = has_new_items, 
  737. 	}		 
  738.  
  739. 	Store_common_sub_menu[menu_idx] = new_item 
  740. 	 
  741. 	-- Set the name of the menu choice, may be from crc or string itself 
  742. 	if label_crc ~= nil and label_crc ~= 0 then 
  743. 		new_item.label_crc = label_crc 
  744. 	else 
  745. 		new_item.label = label_str 
  746. 	end 
  747. 	 
  748. end 
  749.  
  750. function store_clothing_item_get_list(menu_data) 
  751.  
  752. 	-- disable switching modes here 
  753. 	store_clothing_set_hints(false) 
  754.  
  755. 	-- force a garbage collection 
  756. 	vint_force_lua_gc() 
  757. 	 
  758. 	Store_common_sub_menu = { 
  759. 		default_on_nav = store_clothing_item_nav, 
  760. 		default_on_sub_menu_fill = store_clothing_item_details, 
  761. 		default_on_back = store_clothing_item_revert 
  762. 	} 
  763. 	 
  764. 	pcu_get_items_in_category(menu_data.id, "store_clothing_item_add") 
  765. 	 
  766. 	if #Store_common_sub_menu == 0 then 
  767. 		-- Don't think this should ever happen, if stores are set up correctly, but just in case. 
  768. 		Store_common_sub_menu[1] = { 
  769. 			type = TYPE_BUTTON, 
  770. 			id = -1, 
  771. 			label = "HAIR_CAT_NONE", 
  772. 			label_crc = nil, 
  773. 			is_owned = true, 
  774. 			price = 0, 
  775. 			style = 0, 
  776. 			is_outfit = false, 
  777. 			on_select = store_clothing_item_remove, 
  778. 		}		 
  779. 	end 
  780. 	 
  781. 	local index = Store_common_sub_menu.start_index or 1 
  782. 	store_clothing_item_nav(Store_common_sub_menu[index]) 
  783. end 
  784.  
  785. function store_clothing_outfit_none(menu_data) 
  786. 	store_clothing_item_revert(menu_data) 
  787. 	store_common_button_b() 
  788. end 
  789.  
  790. -- The player chose "none" for the item to wear.  Set player to wear nothing and go back up a menu. 
  791. -- 
  792. function store_clothing_item_remove(menu_data) 
  793. 	store_clothing_header_revert() 
  794. 	pcu_wear_current_clothing() 
  795. 	 
  796. 	-- back out of menu 
  797. 	store_common_back_menu() 
  798. end 
  799.  
  800. -- Callback from C code that adds clothing items to Menu_data table. 
  801. -- 
  802. -- item_id: 	unique id for the clothing item. 
  803. -- label_crc: 	crc for the name to display.  nil if string is used instead. 
  804. -- label_str: 	string for the name to display.  nil if crc is used instead. 
  805. -- is_outfit: 	true if this is an outfit. 
  806. -- price: 		price of the item 
  807. -- style: 		how much style the item adds. 
  808. -- inc_wardrobe_instance: instance of the wardrobe item (to distinguish duplicate items) 
  809. -- is_available: true if the item is available for purchase. 
  810. -- variant_num: id indicating which variant this is 
  811. -- variant_lbl: string for the variant text to display.  nil if crc is used instead. 
  812. -- variant_lbl_crc: crc for the variant text to display.  nil if string is used instead. 
  813. -- is_current: true if we're in the wardrobe and this item is currently worn. 
  814. --	 
  815. function store_clothing_item_add(item_id, label_crc, label_str, is_outfit, price, style, inc_wardrobe_instance, is_available, is_reward, is_unusable_dlc, is_new, is_dlc, variant_num, variant_lbl_crc, variant_lbl, is_current, brand_id, disable_removal) 
  816. 	local menu_idx = #Store_common_sub_menu + 1 
  817.  
  818. 	--debug_print("vint", "adding brand " .. brand_id .. "\n")	 
  819. 	 
  820. 	-- We only want to add a "none" choice if this isn't an outfits menu, and (obviously) we haven't added it 
  821. 	-- to the top of the list yet. 
  822. 	if menu_idx == 1 and is_outfit == false and disable_removal ~= true then 
  823. 	 
  824. 		-- first choice is to remove items of this type 
  825. 		Store_common_sub_menu[1] = { 
  826. 			id = -1, 
  827. 			label = "HAIR_CAT_NONE", 
  828. 			label_crc = nil, 
  829. 			is_owned = true, 
  830. 			price = 0, 
  831. 			style = 0, 
  832. 			is_outfit = false, 
  833. 			on_select = store_clothing_item_remove, 
  834. 			is_new = false, 
  835. 			is_dlc = false, 
  836. 		}	 
  837. 		menu_idx = 2 
  838. 	end 
  839. 	 
  840. 	local new_item = { 
  841. 		id = item_id, 
  842. 		label = nil, 
  843. 		label_crc = nil, 
  844. 		--is_owned = false, 
  845. 		variant_num = variant_num, 
  846. 		is_outfit = is_outfit,	 
  847. 		wardrobe_instance = inc_wardrobe_instance, 
  848. 		disabled = is_unusable_dlc, 
  849. 		--is_reward = is_reward, 
  850. 		--is_unusable_dlc = is_unusable_dlc, 
  851. 		brand_id = brand_id, 
  852. 		is_new = is_new, 
  853. 		is_dlc = is_dlc, 
  854. 		 
  855. 		-- on_nav = store_clothing_item_nav, 
  856. 		-- on_sub_menu_fill = store_clothing_item_details, 
  857. 		-- on_back = store_clothing_item_revert,		 
  858. 	}		 
  859. 	 
  860. 	if Store_clothing_is_wardrobe == false then 
  861. 		new_item.price = price 
  862. 		new_item.style = style 
  863. 	end 
  864. 	 
  865. 	if variant_lbl_crc == nil and variant_lbl == nil then 
  866. 		--Set the name of the menu choice, may be from crc or string itself 
  867. 		if label_crc ~= nil and label_crc ~= 0 then 
  868. 			new_item.label_crc = label_crc 
  869. 		else 
  870. 			new_item.label = label_str 
  871. 		end 
  872. 	else 
  873. 		-- Set the name of the menu choice, may be from crc or string itself 
  874. 		if variant_lbl_crc ~= nil and variant_lbl_crc ~= 0 then 
  875. 			new_item.label_crc = variant_lbl_crc 
  876. 		else 
  877. 			new_item.label = variant_lbl 
  878. 		end 
  879. 	end 
  880. 	 
  881. 	-- if is_available ~= false then 
  882. 		-- if pcu_is_item_owned(item_id, nil) == true then 
  883. 			-- -- We own all of this item's styles, so you can't actually select details 
  884. 			-- new_item.is_owned = true 
  885. 		-- end 
  886. 	-- end 
  887. 	 
  888. 	Store_common_sub_menu[menu_idx] = new_item	 
  889. 	 
  890. 	if is_current == true then 
  891. 		Store_common_sub_menu.start_index = menu_idx 
  892. 	end 
  893. end 
  894.  
  895. function store_clothing_header_revert(menu_data) 
  896. 	Store_header:set_price(nil) 
  897. 	Store_header:set_respect(nil) 
  898. end 
  899.  
  900. -- Trigger background item updates when navigating among different clothing items in the menu. 
  901. -- 
  902. -- id: unique id of the selected clothing item. 
  903. -- variant_id: unique id of the variant for this item. 
  904. -- 
  905. function store_clothing_item_nav(menu_data) 
  906.  
  907. 	--debug_print("vint", "brand is " .. menu_data.brand_id .. "\n") 
  908.  
  909. 	if menu_data.is_outfit == false then 
  910. 		Store_clothing_outfit_id = -1 
  911. 	 
  912. 		local id = menu_data.id 
  913. 		local variant_id = menu_data.variant_num	 
  914. 	 
  915. 		if Store_clothing_is_wardrobe == false then 
  916. 			store_clothing_item_get_defaults(id) 
  917. 		else 
  918. 			if id == -1 then 
  919. 				Store_clothing_item_info.item_index = -1 
  920. 			else 
  921. 				store_clothing_get_owned_item_info(menu_data.id, menu_data.wardrobe_instance) 
  922. 				Store_clothing_item_info.wardrobe_instance = menu_data.wardrobe_instance --store the instance of the current item incase we need to discard 
  923. 			end 
  924. 		end		 
  925. 		 
  926. 		if variant_id then 
  927. 			Store_clothing_item_info.variant_index = variant_id 
  928. 		end		 
  929. 		 
  930. 		Store_clothing_waiting_update_value = STORE_CLOTHING_PENDING_ITEM 
  931. 		 
  932. 		local brand_id = menu_data.brand_id 
  933. 		if brand_id == nil or brand_id == BRAND_NONE then 
  934. 			-- Swap back to store logo 
  935. 			store_clothing_brand_swap_logo(brand_id, false) 
  936. 		else 
  937. 			-- Swap back to store logo 
  938. 			store_clothing_brand_swap_logo(brand_id, true) 
  939. 		end 
  940. 		 
  941. 		-- clear out "new" status if it is true 
  942. 		if menu_data.is_new then 
  943. 			pcu_clear_item_new(menu_data.id, menu_data.wardrobe_instance) 
  944. 			 
  945. 			--Remove our mouse inputs first... 
  946. 			if Mouse_input_tracker ~= 0 then 
  947. 				Mouse_input_tracker:remove_all() 
  948. 			end 
  949. 			 
  950. 			--Get index from the list and then remove the flag... 
  951. 			local index = 1 
  952. 			local data = Active_list:return_data() 
  953. 			for data_index = 1, #data do 
  954. 				if menu_data.id == data[data_index].id then 
  955. 					if menu_data.wardrobe_instance == data[data_index].wardrobe_instance then 
  956. 						--Match!! 
  957. 						index = data_index 
  958. 						break 
  959. 					end 
  960. 				end 
  961. 			end 
  962. 			 
  963. 			--Remove the new flag from our active list... 
  964. 			Active_list:remove_new_flag(index) 
  965. 			 
  966. 			--Update cursor, 
  967. 			Active_list:move_cursor(0) 
  968. 			--Re add mouse inputs... 
  969. 			if Mouse_input_tracker ~= 0 then 
  970. 				Mouse_input_tracker:remove_all() 
  971. 				Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  972. 				Mouse_input_tracker:subscribe(true) 
  973. 			end	 
  974. 		end 
  975. 	else 
  976. 		Store_clothing_item_info.item_price = menu_data.price 
  977. 		Store_clothing_item_info.item_style = menu_data.style 
  978. 		Store_clothing_outfit_id = menu_data.id 
  979. 		Store_clothing_waiting_update_value = STORE_CLOTHING_PENDING_STORE_OUTFIT 
  980. 	end 
  981. 	 
  982. 	if Store_clothing_is_wardrobe == false then 
  983. 		-- Update the store header price and respect values 
  984. 		Store_header:set_price(Store_clothing_item_info.item_price) 
  985. 		Store_header:set_respect(Store_clothing_item_info.item_style)	 
  986. 	end 
  987. end 
  988.  
  989. -- Player hit back on clothing item instead of buying it; revert preview. 
  990. -- 
  991. function store_clothing_item_revert(menu_data) 
  992.  
  993. 	-- This will cancel the delayed preview of an item 
  994. 	Store_clothing_waiting_update_value = STORE_CLOTHING_PENDING_NONE 
  995. 	 
  996. 	store_clothing_header_revert() 
  997. 	 
  998. 	if menu_data.is_outfit then 
  999. 		pcu_set_active_category(Store_clothing_category, Store_clothing_area) 
  1000. 	else 
  1001. 		pcu_clear_preview_slot() 
  1002. 	end 
  1003. 	 
  1004. 	-- We want to re-enable mode switching at this point 
  1005. 	store_clothing_set_hints(Store_clothing_loaded_from_crib == false) 
  1006. 	 
  1007. 	-- Swap logo back 
  1008. 	store_clothing_brand_swap_logo(nil, false) 
  1009. end 
  1010.  
  1011. function store_clothing_area_nav(menu_data) 
  1012. 	local id = Active_list:get_id() 
  1013. 	Store_clothing_area = id	 
  1014. end 
  1015.  
  1016. function store_clothing_category_nav(menu_data) 
  1017. 	local id = Active_list:get_id() 
  1018. 	pcu_clear_preview_slot() 
  1019. 	Store_clothing_category = id 
  1020. 	pcu_set_active_category(Store_clothing_category, Store_clothing_area)	 
  1021. end 
  1022.  
  1023. function store_clothing_wear_option_nav(menu_data) 
  1024. 	Store_clothing_item_info.wear_option_index = Wear_opt_data[Active_list:get_toggle_selection()] 
  1025. 	store_clothing_item_preview(true)	 
  1026. end 
  1027.  
  1028. function store_clothing_style_nav(menu_data) 
  1029. 	Store_clothing_item_info.variant_index = Style_variant_data[Active_list:get_toggle_selection()] 
  1030. 	store_clothing_item_preview(true) 
  1031. end 
  1032.  
  1033. -- Calls into C code to get the default setttings for a given item. 
  1034. -- 
  1035. -- item_index: unique ID into for the item to get info on. 
  1036. -- 
  1037. function store_clothing_item_get_defaults(item_index) 
  1038. 	local t = Store_clothing_item_info 
  1039. 	 
  1040. 	if item_index >= 0 then 
  1041. 		t.slot_index, t.item_index, t.item_name_crc, t.item_name_str, 
  1042. 		t.num_variants, t.variant_index, t.variant_name_crc, t.variant_name_str, 
  1043. 		t.colors.num_colors, 
  1044. 		t.colors[0].index, t.colors[0].red, t.colors[0].green, t.colors[0].blue, 
  1045. 		t.colors[1].index, t.colors[1].red, t.colors[1].green, t.colors[1].blue, 
  1046. 		t.colors[2].index, t.colors[2].red, t.colors[2].green, t.colors[2].blue, 
  1047. 		t.num_wear_options, t.wear_option_index, t.wear_option_name_crc, t.wear_option_name_str, 
  1048. 		t.num_logos, t.logo_index, t.logo_name_crc, t.logo_name_str, t.logo_color_index, t.logo_color_red, t.logo_color_green, t.logo_color_blue, 
  1049. 		t.item_style, t.item_price, 
  1050. 		t.player_style_level, t.player_style_percent 
  1051. 		= pcu_get_item_defaults(item_index) 
  1052. 	else 
  1053. 		t.item_index = -1 
  1054. 		t.item_price = nil 
  1055. 		t.item_style = nil 
  1056. 	end 
  1057. end 
  1058.  
  1059. function store_clothing_get_owned_item_info(item_index, wardrobe_instance)  -- like get item defaults, but called when browsing the inventory 
  1060. 	local t = Store_clothing_item_info 
  1061. 	if wardrobe_instance == nil then 
  1062. 		wardrobe_instance = -1  --this should never occur, but incase it does, this will make it assert instead of crash 
  1063. 	end 
  1064. 	if item_index >= 0 then 
  1065. 		t.slot_index, t.item_index, t.item_name_crc, t.item_name_str, 
  1066. 		t.num_variants, t.variant_index, t.variant_name_crc, t.variant_name_str, 
  1067. 		t.colors.num_colors, 
  1068. 		t.colors[0].index, t.colors[0].red, t.colors[0].green, t.colors[0].blue, 
  1069. 		t.colors[1].index, t.colors[1].red, t.colors[1].green, t.colors[1].blue, 
  1070. 		t.colors[2].index, t.colors[2].red, t.colors[2].green, t.colors[2].blue, 
  1071. 		t.num_wear_options, t.wear_option_index, t.wear_option_name_crc, t.wear_option_name_str, 
  1072. 		t.num_logos, t.logo_index, t.logo_name_crc, t.logo_name_str, t.logo_color_index, t.logo_color_red, t.logo_color_green, t.logo_color_blue 
  1073. 		= pcu_get_owned_item_info(item_index, wardrobe_instance) 
  1074. 	else 
  1075. 		t.item_index = -1 
  1076. 		t.item_price = nil 
  1077. 		t.item_style = nil		 
  1078. 	end 
  1079. end 
  1080.  
  1081. -- Calls into C code to get the settingsf for the given slot. 
  1082. -- 
  1083. -- slot: ID for the slot to get the info on. 
  1084. -- 
  1085. function store_clothing_item_get_slot_info(slot) 
  1086. 	local t = Store_clothing_item_info 
  1087. 	local temp_logo_storage_color_index = t.logo_color_index 
  1088. 	local temp_logo_storage_color_red = t.logo_color_red 
  1089. 	local temp_logo_storage_color_green = t.logo_color_green 
  1090. 	local temp_logo_storage_color_blue = t.logo_color_blue 
  1091. 	 
  1092. 	t.slot_index, t.item_index, t.item_name_crc, t.item_name_str, 
  1093. 	t.num_variants, t.variant_index, t.variant_name_crc, t.variant_name_str, 
  1094. 	t.colors.num_colors, 
  1095. 	t.colors[0].index, t.colors[0].red, t.colors[0].green, t.colors[0].blue, 
  1096. 	t.colors[1].index, t.colors[1].red, t.colors[1].green, t.colors[1].blue, 
  1097. 	t.colors[2].index, t.colors[2].red, t.colors[2].green, t.colors[2].blue, 
  1098. 	t.num_wear_options, t.wear_option_index, t.wear_option_name_crc, t.wear_option_name_str, 
  1099. 	t.num_logos, t.logo_index, t.logo_name_crc, t.logo_name_str, t.logo_color_index, t.logo_color_red, t.logo_color_green, t.logo_color_blue, 
  1100. 	t.item_style, t.item_price, 
  1101. 	t.player_style_level, t.player_style_percent 
  1102. 	= pcu_get_slot_info(slot) 
  1103. 	 
  1104. 	--do this to prevent logo color from being wiped when previewing the "no logo" logo 
  1105. 	if t.logo_index == STORE_CLOTHING_INVALID_INDEX then 
  1106. 		t.logo_color_index = temp_logo_storage_color_index 
  1107. 		t.logo_color_red = temp_logo_storage_color_red 
  1108. 		t.logo_color_green = temp_logo_storage_color_green  
  1109. 		t.logo_color_blue = temp_logo_storage_color_blue 
  1110. 	end 
  1111. end 
  1112.  
  1113. -- Build the menu for the detailed actions possible for the selected item. 
  1114. -- 
  1115. function store_clothing_item_details(menu_data) 
  1116.  
  1117. 	Store_common_sub_menu = {} 
  1118. 	 
  1119. 	local new_menu = Store_common_sub_menu 
  1120. 	local menu_idx = 0 
  1121. 	 
  1122. 	if Store_clothing_outfit_id == -1 then 
  1123. 	 
  1124. 		-- get info on the item 
  1125. 		store_clothing_item_preview(true) 
  1126. 		 
  1127. 		local item = Store_clothing_item_info 
  1128. 		 
  1129. 		-- color selections 
  1130. 		if Store_clothing_is_wardrobe == false and item.colors.num_colors ~= nil and item.colors.num_colors > 0 then 
  1131. 			local c = item.colors 
  1132. 			 
  1133. 			for i = 0, c.num_colors - 1 do 
  1134. 				local color_label 
  1135. 				if i == 0 then 
  1136. 					color_label = "STORE_PRIMARY_COLOR" 
  1137. 				elseif i == 1 then 
  1138. 					color_label = "STORE_SECONDARY_COLOR" 
  1139. 				elseif i == 2 then 
  1140. 					color_label = "STORE_TERTIARY_COLOR" 
  1141. 				else 
  1142. 					color_label = "STORE_DETAIL_COLOR" 
  1143. 				end 
  1144. 				 
  1145. 				menu_idx = menu_idx + 1 
  1146. 				local new_item = { 
  1147. 					type = TYPE_TOGGLE_COLOR, 
  1148. 					id = i, 
  1149. 					label = color_label, 
  1150. 					label_crc = nil, 
  1151. 					color = c[i], 
  1152. 					on_select = store_clothing_color_select, 
  1153. 				}	 
  1154. 				new_menu[menu_idx] = new_item		 
  1155. 			end 
  1156. 		end 
  1157.  
  1158. 		-- style (variant) selections 
  1159. 		if Store_clothing_is_wardrobe == false and item.num_variants > 1 then 
  1160. 			-- get our variants to populate the toggle 
  1161. 			Toggle_data = {} 
  1162. 			Style_variant_data = {} 
  1163. 			pcu_get_variants(item.slot_index, "store_clothing_style_add") 
  1164. 		 
  1165. 			menu_idx = menu_idx + 1 
  1166. 			local new_item = { 
  1167. 				type = TYPE_TOGGLE, 
  1168. 				label = "MENU_STYLE", 
  1169. 				options = Toggle_data, 
  1170. 				current_value = 1, 
  1171. 				on_nav = store_clothing_style_nav,		 
  1172. 			}	 
  1173. 			new_menu[menu_idx] = new_item	 
  1174. 		end	 
  1175. 		 
  1176. 		-- wear option selections 
  1177. 		if item.num_wear_options > 1 then 
  1178. 			-- get our wear options to populate the toggle 
  1179. 			Toggle_data = {} 
  1180. 			Wear_opt_data = {} 
  1181. 			pcu_get_wear_options(item.slot_index, "store_clothing_wear_option_add") 
  1182. 		 
  1183. 			menu_idx = menu_idx + 1 
  1184. 			local new_item = { 
  1185. 				type = TYPE_TOGGLE, 
  1186. 				label = "CUST_MENU_WEAR_OPTION", 
  1187. 				options = Toggle_data, 
  1188. 				current_value = 1, 
  1189. 				on_nav = store_clothing_wear_option_nav, 
  1190. 			}	 
  1191. 			new_menu[menu_idx] = new_item	 
  1192. 		end 
  1193. 	end 
  1194. 	 
  1195. 	-- add the purchase item choice 
  1196. 	menu_idx = menu_idx + 1 
  1197.  
  1198. 	if Store_clothing_is_wardrobe == false then 
  1199. 		local new_item	= { 
  1200. 			type = TYPE_BUTTON, 
  1201. 			label = "STORE_PURCHASE_ITEM", 
  1202. 			label_crc = nil,	 
  1203. 			on_select = store_clothing_item_purchase 
  1204. 		} 
  1205. 		 
  1206. 		new_menu[menu_idx] = new_item			 
  1207. 	else 
  1208. 		local new_item	= { 
  1209. 			type = TYPE_BUTTON, 
  1210. 			label = "CUST_ITEM_WEAR", 
  1211. 			label_crc = nil,	 
  1212. 			on_select = store_clothing_item_wear 
  1213. 		}		 
  1214. 		 
  1215. 		new_menu[menu_idx] = new_item	 
  1216. 		menu_idx = menu_idx + 1 
  1217. 		 
  1218. 		new_item	= { 
  1219. 			type = TYPE_BUTTON, 
  1220. 			label = "STORE_DISCARD_ITEM", 
  1221. 			label_crc = nil,	 
  1222. 			on_select = store_clothing_item_discard 
  1223. 		}		 
  1224. 		 
  1225. 		new_menu[menu_idx] = new_item				 
  1226. 	end 
  1227. end 
  1228.  
  1229. -- When in the wardrobe, the player can select to wear an item.  This updates the slots and leaves menu. 
  1230. -- 
  1231. function store_clothing_item_wear() 
  1232. 	if pcu_is_streaming_done() and Store_clothing_waiting_update_value == STORE_CLOTHING_PENDING_NONE then 
  1233. 		pcu_wear_current_clothing() 
  1234. 		store_common_back_menu() 
  1235. 		store_common_back_menu()		 
  1236. 	end 
  1237. end 
  1238.  
  1239. -- When in the wardrobe, the player can select to discard an item.  This brings up a warning dialog before doing so. 
  1240. -- 
  1241. function store_clothing_item_discard() 
  1242. 	store_clothing_enable_mouse(false) 
  1243.  
  1244. 	if pcu_is_current_item_worn(Store_clothing_item_info.slot_index, Store_clothing_item_info.wardrobe_instance) then 
  1245. 		if pcu_is_underwear_category(Store_clothing_category) then 
  1246. 			Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1247. 			Store_common_popup:set_title("STORE_UNDERWEAR_WARNING") 
  1248. 			Store_common_popup:set_text("STORE_UNDERWEAR_SUB_WARNING")		 
  1249. 			Store_common_popup:nav_enable(true, "store_clothing_fail_msg", "store_clothing_popup_nav") 
  1250. 			Not_popup_grp:set_alpha(.5) 
  1251. 			Store_logo_grp:set_alpha(.5) 
  1252. 			Active_list:set_visible(false) 
  1253. 		else  
  1254. 			if pcu_is_bra_category(Store_clothing_category) and pcu_bra_required() then 
  1255. 				Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1256. 				Store_common_popup:set_title("STORE_BRA_WARNING") 
  1257. 				Store_common_popup:set_text("STORE_BRA_SUB_WARNING")		 
  1258. 				Store_common_popup:nav_enable(true, "store_clothing_fail_msg", "store_clothing_popup_nav") 
  1259. 				Not_popup_grp:set_alpha(.5)	 
  1260. 				Store_logo_grp:set_alpha(.5) 
  1261. 				Active_list:set_visible(false) 
  1262. 			else 
  1263. 				Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)	 
  1264. 				Store_common_popup:set_title("STORE_TITLE_DISCARD") 
  1265. 				Store_common_popup:set_text("STORE_TEXT_DISCARD")				 
  1266. 				Store_common_popup:nav_enable(true, "store_clothing_item_discard_confirm_1", "store_clothing_popup_nav") 
  1267. 				Not_popup_grp:set_alpha(.5)	 
  1268. 				Store_logo_grp:set_alpha(.5) 
  1269. 				Active_list:set_visible(false)				 
  1270. 			end 
  1271. 		end 
  1272. 	else 
  1273. 		Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)	 
  1274. 		Store_common_popup:set_title("STORE_TITLE_DISCARD") 
  1275. 		Store_common_popup:set_text("STORE_TEXT_DISCARD")				 
  1276. 		Store_common_popup:nav_enable(true, "store_clothing_item_discard_confirm_1", "store_clothing_popup_nav") 
  1277. 		Not_popup_grp:set_alpha(.5)	 
  1278. 		Store_logo_grp:set_alpha(.5) 
  1279. 		Active_list:set_visible(false) 
  1280. 	end 
  1281. end 
  1282.  
  1283. function store_clothing_item_discard_confirm_1(event) 
  1284.  
  1285. 	Store_common_popup:nav_enable(false, nil, nil) 
  1286. 	Not_popup_grp:set_alpha(1) 
  1287. 	Store_logo_grp:set_alpha(1) 
  1288. 	Active_list:set_visible(true) 
  1289. 	store_clothing_enable_mouse(true) 
  1290.  
  1291. 	-- The user hit the B button and are cancelling the discard 
  1292. 	-- This is redundant to selecting "No" in the list 
  1293. 	if event == "back" then 
  1294. 		game_UI_audio_play("UI_Main_Menu_Nav_Back")	 
  1295. 		return 
  1296. 	end 
  1297. 	 
  1298. 	game_UI_audio_play("UI_Main_Menu_Select") 
  1299. 	 
  1300. 	-- Did we select yes?  This assumes yes is the first item 
  1301. 	if Store_common_popup:get_selected_data() ~= 1 then 
  1302. 		return 
  1303. 	end	 
  1304. 	 
  1305. 	-- do this so holding down the button doesn't cause repeated actions 
  1306. 	Input_tracker:subscribe(false)		 
  1307. 	Input_tracker:subscribe(true)		 
  1308. 	 
  1309. 	if pcu_is_item_needed_for_outfit(Store_clothing_item_info.slot_index) then 
  1310. 		Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)	 
  1311. 		Store_common_popup:set_title("STORE_TITLE_DISCARD_OUTFIT_WARNING") 
  1312. 		Store_common_popup:set_text("STORE_TEXT_DISCARD_OUTFIT_WARNING")				 
  1313. 		Store_common_popup:nav_enable(true, "store_clothing_item_discard_confirm_2", "store_clothing_popup_nav") 
  1314. 		Not_popup_grp:set_alpha(.5)	 
  1315. 		Store_logo_grp:set_alpha(.5) 
  1316. 		Active_list:set_visible(false) 
  1317. 		store_clothing_enable_mouse(false) 
  1318. 	else 
  1319. 		pcu_discard_slot(Store_clothing_item_info.slot_index, Store_clothing_item_info.wardrobe_instance) 
  1320. 		store_common_back_menu() 
  1321. 		store_common_back_menu()	 
  1322.  
  1323. 		--If we're on the last item in the list back one more time to the categories 
  1324. 		if #Active_list.data <= 1 then 
  1325. 			Store_common_exit_cb() 
  1326. 		end		 
  1327. 	end 
  1328. end 
  1329.  
  1330. function store_clothing_item_discard_confirm_2(event) 
  1331. 	Store_common_popup:nav_enable(false, nil, nil) 
  1332. 	Not_popup_grp:set_alpha(1) 
  1333. 	Store_logo_grp:set_alpha(1) 
  1334. 	Active_list:set_visible(true) 
  1335. 	 
  1336. 	store_clothing_enable_mouse(true) 
  1337.  
  1338. 	-- The user hit the B button and are cancelling the discard 
  1339. 	-- This is redundant to selecting "No" in the list 
  1340. 	if event == "back" then 
  1341. 		game_UI_audio_play("UI_Main_Menu_Nav_Back")	 
  1342. 		return 
  1343. 	end 
  1344. 	 
  1345. 	game_UI_audio_play("UI_Main_Menu_Select") 
  1346. 	 
  1347. 	-- Did we select yes?  This assumes yes is the first item 
  1348. 	if Store_common_popup:get_selected_data() ~= 1 then 
  1349. 		return 
  1350. 	end	 
  1351. 	 
  1352. 	-- do this so holding down the button doesn't cause repeated actions 
  1353. 	Input_tracker:subscribe(false)		 
  1354. 	Input_tracker:subscribe(true)	 
  1355. 	 
  1356. 	pcu_discard_slot(Store_clothing_item_info.slot_index, Store_clothing_item_info.wardrobe_instance) 
  1357. 	store_common_back_menu() 
  1358. 	store_common_back_menu()	 
  1359. end 
  1360.  
  1361.  
  1362. function store_clothing_item_purchase(menu_data) 
  1363. 	local item = Store_clothing_item_info 
  1364. 	store_clothing_enable_mouse(false) 
  1365. 	 
  1366. 	-- Have we reached the category item limit? 
  1367. 	local num_owned = pcu_get_num_items_category(Store_clothing_category, Store_clothing_outfit_id) 
  1368. 	if num_owned >= STORE_CLOTHING_CATEGORY_MAX then 
  1369. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1370. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  1371. 		Store_common_popup:set_text("CUST_MENU_CATEGORY_LIMIT_REACHED")		 
  1372. 		Store_common_popup:nav_enable(true, "store_clothing_fail_msg", "store_clothing_popup_nav") 
  1373. 		Not_popup_grp:set_alpha(.5)	 
  1374. 		Store_logo_grp:set_alpha(.5)	 
  1375. 		Active_list:set_visible(false)		 
  1376. 		return 
  1377. 	end	 
  1378. 	 
  1379. 	-- Have we reached the total item limit?	 
  1380. 	num_owned = pcu_get_num_items_owned(Store_clothing_outfit_id) 
  1381. 	if num_owned >= STORE_CLOTHING_TOTAL_MAX then 
  1382. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1383. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  1384. 		Store_common_popup:set_text("CUST_MENU_TOTAL_LIMIT_REACHED")		 
  1385. 		Store_common_popup:nav_enable(true, "store_clothing_fail_msg", "store_clothing_popup_nav") 
  1386. 		Not_popup_grp:set_alpha(.5)	 
  1387. 		Store_logo_grp:set_alpha(.5)	 
  1388. 		Active_list:set_visible(false)		 
  1389. 		return 
  1390. 	end		 
  1391. 	 
  1392. 	-- Are we short on cash? 
  1393. 	if item.item_price > Store_common_player_cash then 
  1394. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  1395. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  1396. 		Store_common_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")		 
  1397. 		Store_common_popup:nav_enable(true, "store_clothing_fail_msg", "store_clothing_popup_nav") 
  1398. 		Not_popup_grp:set_alpha(.5)	 
  1399. 		Store_logo_grp:set_alpha(.5)	 
  1400. 		Active_list:set_visible(false)		 
  1401. 		return 
  1402. 	end 
  1403. 	 
  1404. 	-- Make sure they want to buy this 
  1405. 	Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)	 
  1406. 	Store_common_popup:set_title("STORE_TITLE_PURCHASING") 
  1407. 	Store_common_popup:set_text("STORE_TEXT_CONFIRM_PURCHASE_BLANK")				 
  1408. 	Store_common_popup:nav_enable(true, "store_clothing_item_purchase_final", "store_clothing_popup_nav") 
  1409. 	Not_popup_grp:set_alpha(.5) 
  1410. 	Store_logo_grp:set_alpha(.5) 
  1411. 	Active_list:set_visible(false) 
  1412. end 
  1413.  
  1414. function store_clothing_color_select(menu_data) 
  1415. 	Active_list:set_visible(false) 
  1416. 	 
  1417. 	-- get the colors for the palette 
  1418. 	Color_grid_data = {} 
  1419. 	Color_slot_chosen = menu_data.id 
  1420. 	Color_grid_idx = 1 
  1421. 	pcu_report_item_colors("store_clothing_color_add", Store_clothing_item_info.item_index) 
  1422. 	 
  1423. 	-- display the grid 
  1424. 	Store_common_color_grid:draw_items(Color_grid_data, Color_grid_idx, 9, 7, 53.5, 53.5, 15, nil, 1.1, true, true, -7, true) 
  1425. 	Store_common_color_grid:set_visible(true) 
  1426. 	Store_common_color_grid:nav_enable(true, "store_clothing_color_selected", "store_clothing_color_nav")	 
  1427. 	Color_prev_color = Color_grid_idx 
  1428. 	 
  1429. 	if Mouse_input_tracker ~= 0 then 
  1430. 		Mouse_input_tracker:subscribe(false) 
  1431. 	end 
  1432. 	Current_tier = COLOR_TIER 
  1433. end 
  1434.  
  1435. -- Callback to get a wear option from C and add it to our wear option toggle. 
  1436. -- 
  1437. -- option_index: 	indicates which wear option this is for 
  1438. -- name_crc:		crc to use for the toggle choice name. nil if string is used. 
  1439. -- name_str:		string to use for the toggle choice name.  nil if crc is used. 
  1440. -- 
  1441. function store_clothing_wear_option_add(option_index, name_crc, name_str) 
  1442. 	local toggle_idx = #Toggle_data + 1 
  1443. 	if name_crc ~= nil then 
  1444. 		Toggle_data[toggle_idx] = name_crc 
  1445. 	else 
  1446. 		Toggle_data[toggle_idx] = name_str 
  1447. 	end 
  1448. 	Wear_opt_data[toggle_idx] = option_index 
  1449. end 
  1450.  
  1451. -- Callback to get a style option from C and add it to our style toggle. 
  1452. -- 
  1453. -- option_index: 	indicates which style options this is for 
  1454. -- name_crc:		crc to use for the toggle choice name. nil if string is used. 
  1455. -- name_str:		string to use for the toggle choice name.  nil if crc is used. 
  1456. -- 
  1457. function store_clothing_style_add(option_index, name_crc, name_str) 
  1458. 	local toggle_idx = #Toggle_data + 1 
  1459. 	if name_crc ~= nil then 
  1460. 		Toggle_data[toggle_idx] = name_crc 
  1461. 	else 
  1462. 		Toggle_data[toggle_idx] = name_str 
  1463. 	end 
  1464. 	Style_variant_data[toggle_idx] = option_index 
  1465. end 
  1466.  
  1467. -- Callback to get a color option from C and add it to our color grid. 
  1468. -- 
  1469. -- color_index: 	indicates which color this is for 
  1470. -- label_crc:		crc to use for the toggle choice name. nil if string is used. 
  1471. -- label_str:		string to use for the toggle choice name.  nil if crc is used. 
  1472. -- red:				r value. 
  1473. -- green:			g value. 
  1474. -- blue:			b value. 
  1475. -- 
  1476. function store_clothing_color_add(color_index, label_crc, label_str, red, green, blue) 
  1477. 	local grid_idx = #Color_grid_data + 1 
  1478. 	 
  1479. 	Color_grid_data[grid_idx] = { 
  1480. 		icon = "ui_menu_veh_pnt_base", 
  1481. 		label_crc = label_crc, 
  1482. 		label = label_str, 
  1483. 		color = {red = red, green = green, blue = blue}, 
  1484. 		index = color_index, 
  1485. 	} 
  1486. 	 
  1487. 	if color_index == Store_clothing_item_info.colors[Color_slot_chosen].index then 
  1488. 		Color_grid_idx = grid_idx 
  1489. 	end 
  1490. end 
  1491.  
  1492. function store_clothing_color_selected(event) 
  1493. 	 
  1494. 	--Did the player select a color? 
  1495. 	if event == "select" or event == "mouse_click" then 
  1496. 		game_UI_audio_play("UI_Main_Menu_Select")				 
  1497. 	else 
  1498. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  1499. 		-- restore previous color 
  1500. 		Store_clothing_item_info.colors[Color_slot_chosen].index = Color_grid_data[Color_prev_color].index 
  1501. 		Store_clothing_item_info.colors[Color_slot_chosen].red = Color_grid_data[Color_prev_color].color.red 
  1502. 		Store_clothing_item_info.colors[Color_slot_chosen].green = Color_grid_data[Color_prev_color].color.green 
  1503. 		Store_clothing_item_info.colors[Color_slot_chosen].blue = Color_grid_data[Color_prev_color].color.blue	 
  1504. 			 
  1505. 		store_clothing_item_preview(true)			 
  1506. 	end 
  1507. 	 
  1508. 	store_clothing_populate_list(Menu_data, Active_list:get_selection()) 
  1509. 	 
  1510. 	Store_common_color_grid:nav_enable(false, nil, nil) 
  1511. 	Store_common_color_grid:cleanup() 
  1512. 	Color_grid_data = {} 
  1513. 	 
  1514. 	Store_common_color_grid:set_visible(false) 
  1515. 	Store_common_color_grid:cleanup() 
  1516. 	Active_list:set_visible(true) 
  1517. 	 
  1518. 	store_clothing_enable_mouse(true) 
  1519. 	Current_tier = MENU_TIER 
  1520. end 
  1521.  
  1522. function store_clothing_fail_msg(event) 
  1523. 	Store_common_popup:nav_enable(false, nil, nil) 
  1524. 	game_UI_audio_play("UI_Main_Menu_Select") 
  1525. 	Not_popup_grp:set_alpha(1) 
  1526. 	Store_logo_grp:set_alpha(1) 
  1527. 	Active_list:set_visible(true) 
  1528. 	store_clothing_enable_mouse(true) 
  1529. end 
  1530.  
  1531.  
  1532. -- Finalize or cancel a purchase based on the result of the confirmation question. 
  1533. -- 
  1534. -- response: 	how did the user respond? 
  1535. -- action: 		indicates if the dialog box was closed or some other action. 
  1536. -- 
  1537. function store_clothing_item_purchase_final(event) 
  1538.  
  1539. 	Store_common_popup:nav_enable(false, nil, nil) 
  1540. 	Not_popup_grp:set_alpha(1) 
  1541. 	Store_logo_grp:set_alpha(1) 
  1542. 	Active_list:set_visible(true) 
  1543. 	 
  1544. 	store_clothing_enable_mouse(true) 
  1545. 	 
  1546. 	-- The user hit the B button and are cancelling the purchase 
  1547. 	-- This is redundant to selecting "No" in the list 
  1548. 	if event == "back" then 
  1549. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  1550. 		return 
  1551. 	end 
  1552. 	 
  1553. 	game_UI_audio_play("UI_Main_Menu_Select") 
  1554. 	 
  1555. 	-- Did we select yes?  This assumes yes is the first item 
  1556. 	if Store_common_popup:get_selected_data() ~= 1 then 
  1557. 		return 
  1558. 	end 
  1559.  
  1560. 	-- award respect and actually purchase the item 
  1561. 	game_award_respect(Store_clothing_item_info.item_style, nil, nil, true) 
  1562. 	 
  1563. 	-- is this an outfit or an item? 
  1564. 	if Store_clothing_outfit_id == -1 then 
  1565. 		pcu_purchase_slot(Store_clothing_item_info.slot_index) 
  1566. 	else 
  1567. 		pcu_purchase_outfit(Store_clothing_outfit_id) 
  1568. 	end 
  1569. 	 
  1570. 	ui_audio_post_event("clothing_purchase") 
  1571. 	 
  1572. 	-- Go back up 2 menus 
  1573. 	store_common_back_menu() 
  1574. 	store_common_back_menu() 
  1575. 	 
  1576. 	-- do this so holding down the button doesn't cause repeated actions 
  1577. 	Input_tracker:subscribe(false)		 
  1578. 	Input_tracker:subscribe(true)		 
  1579. end 
  1580.  
  1581. function store_clothing_popup_nav(event, value) 
  1582. 	 
  1583. 	vint_set_mouse_cursor("") 
  1584. 	 
  1585. 	if event == "nav_up" then	 
  1586. 		Store_common_popup.list:move_cursor(-1)	 
  1587. 	elseif event == "nav_down" then 
  1588. 		Store_common_popup.list:move_cursor(1) 
  1589. 	elseif event == "mouse_move" then 
  1590. 		-- value contains the target_handle in this case 
  1591. 		local new_index = Store_common_popup.list:get_button_index(value) 
  1592. 		if new_index ~= 0 then 
  1593. 			Store_common_popup.list:set_selection(new_index) 
  1594. 			Store_common_popup.list:move_cursor(0, true) 
  1595. 		end 
  1596. 	else 
  1597. 		--do nothing 
  1598. 	end	 
  1599. end 
  1600.  
  1601. function store_clothing_color_nav(event, value) 
  1602. 	 
  1603. 	if event == "nav_up" then	 
  1604. 		Store_common_color_grid:move_cursor(-2)	 
  1605. 	elseif event == "nav_down" then 
  1606. 		Store_common_color_grid:move_cursor(2) 
  1607. 	elseif event == "nav_left" then 
  1608. 		Store_common_color_grid:move_cursor(-1) 
  1609. 	elseif event == "nav_right" then 
  1610. 		Store_common_color_grid:move_cursor(1) 
  1611. 	 
  1612. 	elseif event == "mouse_move" then 
  1613. 		-- value contains the target_handle in this case 
  1614. 		local new_index = Store_common_color_grid:get_data_index(value) 
  1615. 		if new_index ~= 0 then 
  1616. 			Store_common_color_grid:set_selection(new_index) 
  1617. 			Store_common_color_grid:move_cursor(0, false, true) 
  1618. 		end 
  1619. 		 
  1620. 	else 
  1621. 		--do nothing 
  1622. 	end 
  1623. 	 
  1624. 	-- set the color and preview the item 
  1625. 	local idx = Store_common_color_grid:return_selected_index() 
  1626. 	Store_clothing_item_info.colors[Color_slot_chosen].index = Color_grid_data[idx].index 
  1627. 	Store_clothing_item_info.colors[Color_slot_chosen].red = Color_grid_data[idx].color.red 
  1628. 	Store_clothing_item_info.colors[Color_slot_chosen].green = Color_grid_data[idx].color.green 
  1629. 	Store_clothing_item_info.colors[Color_slot_chosen].blue = Color_grid_data[idx].color.blue	 
  1630. 		 
  1631. 	store_clothing_item_preview(true)		 
  1632. end 
  1633.  
  1634. -- Kick off previewing an item 
  1635. -- 
  1636. -- get_specific_variant: currently unused. 
  1637. -- 
  1638. function store_clothing_item_preview(get_specific_variant) 
  1639. 	Store_clothing_waiting_update_value = STORE_CLOTHING_PENDING_ITEM -- this needs to not be = -1 so we know to update 
  1640. end 
  1641.  
  1642. -- Background thread that updates the item that is previewed. 
  1643. -- 
  1644. function store_clothing_item_preview_update()  --this thread should be always running in the background when suits are being previewed 
  1645. 	debug_print("vint", "outfit update thread started\n") 
  1646. 	while true do 
  1647. 		if pcu_is_streaming_done() then 
  1648. 			delay(0.2) 
  1649. 			 
  1650. 			if Store_clothing_waiting_update_value ~= STORE_CLOTHING_PENDING_NONE then 
  1651. 			 
  1652. 				-- clothing items 
  1653. 				if Store_clothing_waiting_update_value == STORE_CLOTHING_PENDING_ITEM then			 
  1654. 					local t = Store_clothing_item_info 
  1655. 					debug_print("vint", "updating single item with logo "..var_to_string(t.logo_index).."\n") 
  1656. 					--if t.slot_index ~= STORE_CLOTHING_INVALID_INDEX then  --makes sure the item is initialized before trying to preview it 
  1657. 						if t.item_index < 0 or t.wear_option_index < 0 then 
  1658. 							pcu_set_slots_empty(Store_clothing_category) 
  1659. 						else 
  1660. 							pcu_set_slot_info(t.slot_index, t.item_index, t.variant_index, t.colors.num_colors, t.colors[0].index, 
  1661. 							t.colors[1].index, t.colors[2].index, t.wear_option_index, t.logo_index, t.logo_color_index, true) 
  1662. 						end 
  1663. 					--end 
  1664. 					 
  1665. 					-- This appears to be necessary to make sure Preview_slot global in C is updated. 
  1666. 					if t.slot_index ~= nil then 
  1667. 						store_clothing_item_get_slot_info(t.slot_index) 
  1668. 					end 
  1669. 				end 
  1670. 				 
  1671. 				-- outfits (in store) 
  1672. 				if Store_clothing_waiting_update_value == STORE_CLOTHING_PENDING_STORE_OUTFIT then 
  1673. 					debug_print("vint", "updating store outfit\n") 
  1674. 					pcu_wear_store_outfit(Store_clothing_outfit_id) 
  1675. 				end	 
  1676. 				 
  1677. 				-- outfits (in wardrobe) 
  1678. 				if Store_clothing_waiting_update_value == STORE_CLOTHING_PENDING_OWNED_OUTFIT then 
  1679. 					debug_print("vint", "updating owned outfit\n") 
  1680. 					pcu_wear_outfit(Store_clothing_outfit_id, Store_clothing_outfit_finalize) 
  1681. 				end					 
  1682. 				 
  1683. 				Store_clothing_waiting_update_value = STORE_CLOTHING_PENDING_NONE 
  1684. 			end 
  1685.  
  1686. 		end 
  1687. 		thread_yield() 
  1688. 	end 
  1689. end 
  1690.  
  1691. -- Callback that's called when asynchronous image loading is complete 
  1692. -- 
  1693. function store_clothing_set_logo() 
  1694. 	Store_logo1:set_image("ui_store_logo_lets_pretend") 
  1695. 	Store_logo2:set_image("ui_store_logo_lets_pretend") 
  1696. 	 
  1697. 	for i = 1, 4 do 
  1698. 		local r_h  = Vdo_base_object:new("rainbow"..i, 0, Store_clothing_doc_handle) 
  1699. 		r_h:set_image("ui_store_lets_pretend_rainbow") 
  1700. 		r_h  = Vdo_base_object:new("rainbow"..i.."_1", 0, Store_clothing_doc_handle) 
  1701. 		r_h:set_image("ui_store_lets_pretend_rainbow")		 
  1702. 	end 
  1703. end 
  1704.  
  1705. -- Sets up the hint buttons - will change between store/wardrobe. 
  1706. -- 
  1707. function store_clothing_set_hints(mode_switch_enabled) 
  1708. 	local hint_data = { {CTRL_MENU_BUTTON_B, "MENU_BACK"} } 
  1709. 		 
  1710. 	Store_common_hint_bar:set_hints(hint_data) 
  1711. 	 
  1712. 	if Game_platform == "PC" then 
  1713. 		Hint_bar_mouse_input_tracker:remove_all() 
  1714. 		 
  1715. 		Store_common_hint_bar:add_mouse_inputs("store_clothing", Hint_bar_mouse_input_tracker) 
  1716. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  1717. 	end 
  1718. 	 
  1719. 	local hint_rotate_data = { 
  1720. 		{CTRL_BUTTON_RS, "STORE_ZOOM_ROTATE"}, 
  1721. 	} 
  1722. 	Store_common_rotate_hint:set_hints(hint_rotate_data)  
  1723. end 
  1724.  
  1725. -- When returning to the top level menu, we may need to restore items that were removed 
  1726. -- because they obscure other slots. 
  1727. -- 
  1728. function store_clothing_restore_items(menu_data) 
  1729. 	pcu_clear_obscured_slots() 
  1730. 	store_set_camera_pos("body")	 
  1731. end 
  1732.  
  1733. function store_clothing_wardrobe_outfit_menu_fill(menu_data) 
  1734.  
  1735. 	local store_clothing_wardrobe_outfit_menu = { 
  1736. 		on_enter = store_clothing_outfit_enter, 
  1737. 		[1] = { label = "CUST_ITEM_VIEW_OUTFITS", type = TYPE_BUTTON, on_sub_menu_fill = store_clothing_outfit_get_all, outfit_cb = store_clothing_outfit_select }, 
  1738. 		[2] = { label = "CUST_ITEM_CREATE_OUTFIT", type = TYPE_BUTTON, on_select = store_clothing_outfit_create }, 
  1739. 		[3] = { label = "CUST_ITEM_DELETE_OUTFIT", type = TYPE_BUTTON, on_sub_menu_fill = store_clothing_outfit_get_all, outfit_cb = store_clothing_outfit_delete }, 
  1740. 		[4] = { label = "CUST_ITEM_REMOVE_CLOTHING", type = TYPE_BUTTON, on_select = store_clothing_remove_clothing }, 
  1741. 	} 
  1742. 	 
  1743. 	Store_common_sub_menu = store_clothing_wardrobe_outfit_menu 
  1744. end 
  1745.  
  1746. function store_clothing_mode_set_init() 
  1747. 	-- Update our hints 
  1748. 	store_clothing_set_hints(Store_clothing_loaded_from_crib == false) 
  1749. 	 
  1750. 	-- Reset our header 
  1751. 	Store_header:clear_titles() 
  1752. 	Store_header:set_price(nil) 
  1753. 	Store_header:set_respect(nil)			 
  1754. 	 
  1755. 	-- Populate the areas and draw the first menu 
  1756. 	local store_clothing_name 
  1757. 	if Store_clothing_is_wardrobe then 
  1758. 		store_clothing_name = "wardrobe" 
  1759. 		Store_header:enable_price_respect(false) 
  1760. 		Store_header:push_title(nil, "MENU_SWAP_WARDROBE") 
  1761. 	else 
  1762. 		store_clothing_name = "DEBUG_CLOTHING_STORE" 
  1763. 		--Store_header:enable_price_respect(true)		 
  1764. 	end	 
  1765.  
  1766. 	-- reset our store stacks 
  1767. 	store_common_stack_clear_menu() 
  1768. 	store_common_stack_clear_id() 
  1769. 	store_common_stack_clear_index() 
  1770. 	 
  1771. 	Menu_data = {} 
  1772. 	pcu_get_areas(store_clothing_name, "store_clothing_area_add") 
  1773. 	Menu_data.on_enter = store_clothing_area_menu_update 
  1774. 	 
  1775. 	-- if we're in the wardrobe, add the outfit menu 
  1776. 	if Store_clothing_is_wardrobe then 
  1777. 		local item = { 
  1778. 			label = "CUST_ICON_OUTFITS", type = TYPE_BUTTON, on_sub_menu_fill = store_clothing_wardrobe_outfit_menu_fill 
  1779. 		}		 
  1780. 		Menu_data[#Menu_data + 1] = item 
  1781. 	else 
  1782. 		local item = { 
  1783. 			label = "MENU_SWAP_WARDROBE", type = TYPE_BUTTON, on_select = store_clothing_switch_mode 
  1784. 		}		 
  1785. 		Menu_data[#Menu_data + 1] = item	 
  1786. 		 
  1787. 		-- Option to switch to the online character gallery 
  1788. 		local item = { 
  1789. 			label = "STORE_CHARACTER_GALLERY", type = TYPE_BUTTON, on_select = store_clothing_load_gallery, 
  1790. 		}		 
  1791. 		Menu_data[#Menu_data + 1] = item		 
  1792.  
  1793. 		-- add exit store option 
  1794. 		local exit_item = { 
  1795. 			label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_clothing_exit 
  1796. 		}		 
  1797. 		Menu_data[#Menu_data + 1] = exit_item		 
  1798. 	end	 
  1799. 	 
  1800. 	-- Set current area to first menu choice 
  1801. 	Store_clothing_area = Menu_data[1].id	 
  1802. 	 
  1803. 	-- Pass the table data to the megalist vdo. 
  1804. 	store_clothing_populate_list(Menu_data, 1)		 
  1805. end 
  1806.  
  1807. -- Refresh the clothing area menu when we return to it, since the "new" highlights may have been updated by browsing 
  1808. -- 
  1809. function store_clothing_area_menu_update(menu_data) 
  1810. 	local store_clothing_name 
  1811. 	if Store_clothing_is_wardrobe then 
  1812. 		store_clothing_name = "wardrobe" 
  1813. 	else 
  1814. 		store_clothing_name = "DEBUG_CLOTHING_STORE"		 
  1815. 	end	 
  1816.  
  1817. 	local index = Active_list:get_selection() 
  1818. 	Menu_data = {} 
  1819. 	pcu_get_areas(store_clothing_name, "store_clothing_area_add") 
  1820. 	Menu_data.on_enter = store_clothing_area_menu_update 
  1821. 	 
  1822. 	-- if we're in the wardrobe, add the outfit menu 
  1823. 	if Store_clothing_is_wardrobe then 
  1824. 		local item = { 
  1825. 			label = "CUST_ICON_OUTFITS", type = TYPE_BUTTON, on_sub_menu_fill = store_clothing_wardrobe_outfit_menu_fill 
  1826. 		}		 
  1827. 		Menu_data[#Menu_data + 1] = item 
  1828. 	else 
  1829. 		local item = { 
  1830. 			label = "MENU_SWAP_WARDROBE", type = TYPE_BUTTON, on_select = store_clothing_switch_mode 
  1831. 		}		 
  1832. 		Menu_data[#Menu_data + 1] = item	 
  1833. 		 
  1834. 		-- Option to switch to the online character gallery 
  1835. 		local item = { 
  1836. 			label = "STORE_CHARACTER_GALLERY", type = TYPE_BUTTON, on_select = store_clothing_load_gallery, 
  1837. 		}		 
  1838. 		Menu_data[#Menu_data + 1] = item	 
  1839.  
  1840. 		-- add exit store option 
  1841. 		local exit_item = { 
  1842. 			label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_clothing_exit 
  1843. 		}		 
  1844. 		Menu_data[#Menu_data + 1] = exit_item			 
  1845. 	end	 
  1846. 	 
  1847. 	store_clothing_populate_list(Menu_data, index) 
  1848. 	 
  1849. 	-- Force removed clothing to be returned 
  1850. 	store_clothing_restore_items() 
  1851. end 
  1852.  
  1853. -- Load the online character gallery. 
  1854. -- 
  1855. function store_clothing_load_gallery() 
  1856. 	Online_check_thread = thread_new("store_clothing_check_online_for_gallery") 
  1857. end 
  1858.  
  1859. function store_clothing_check_online_for_gallery() 
  1860.  
  1861. 	Input_tracker:subscribe(false) 
  1862. 	if game_get_platform() == "PC" then	 
  1863. 		Mouse_input_tracker:subscribe(false) 
  1864. 		Hint_bar_mouse_input_tracker:subscribe(false) 
  1865. 	end 
  1866.  
  1867. 	online_and_privilege_validator_begin(false, true, true, true, true, true)	-- Check we're signed in and we have content permissions 
  1868. 	while Online_validator_result == ONLINE_VALIDATOR_IN_PROGRESS do 
  1869. 		thread_yield() 
  1870. 	end 
  1871. 			 
  1872. 	Input_tracker:subscribe(true) 
  1873. 	if game_get_platform() == "PC" then	 
  1874. 		Mouse_input_tracker:subscribe(true) 
  1875. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  1876. 	end 
  1877. 	 
  1878. 	if game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3") then 
  1879. 		if main_menu_xbox_get_age_group() ~= "adult" then 
  1880. 			dialog_box_message( "MENU_TITLE_NOTICE", "PLATFORM_XBOX_COMMUNITY_AGE_RESTRICTED" ) 
  1881. 			return 
  1882. 		end 
  1883. 	end 
  1884. 	 
  1885. 	if Online_validator_result ~= ONLINE_VALIDATOR_PASSED then 
  1886. 		return 
  1887. 	end 
  1888. 		 
  1889. 	if main_menu_check_user_content() == false then 
  1890. 		dialog_box_message("MENU_TITLE_WARNING", "USER_CONTENT_PRIV_DENIED") 
  1891. 		return 
  1892. 	end 
  1893. 	 
  1894. 	push_screen("store_gallery") 
  1895. 	 
  1896. 	--Set UI color to purple for gallery 
  1897. 	Active_list:set_highlight_color(COLOR_SAINTS_PURPLE)	 
  1898. 	Store_header:set_color(COLOR_SAINTS_PURPLE, COLOR_STORE_CLOTHING_SECONDARY, COLOR_STORE_CLOTHING_TERTIARY)	 
  1899. 	 
  1900. 	Online_check_thread = -1 
  1901. end 
  1902.  
  1903. -- Switch between store and wardrobe modes. 
  1904. -- 
  1905. function store_clothing_switch_mode() 
  1906.  
  1907. 	local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle) 
  1908. 	local store_to_wardrobe_anim = Vdo_anim_object:new("store_to_wardrobe_anim",0, Store_common_doc_handle) 
  1909. 	local wardrobe_twn_1 = Vdo_tween_object:new("wardrobe_twn_1", store_to_wardrobe_anim.handle) 
  1910. 	local wardrobe_twn_2 = Vdo_tween_object:new("wardrobe_twn_2", store_to_wardrobe_anim.handle) 
  1911. 	 
  1912. 	store_main_grp:set_property("background", true) 
  1913. 	--bg_saints_set_background(true) 
  1914. 	 
  1915. 	if Store_clothing_is_wardrobe == true then 
  1916. 		Store_clothing_is_wardrobe = false 
  1917. 		wardrobe_twn_1:set_end_event("store_clothing_switch_to_store") 
  1918. 	else 
  1919. 		Store_clothing_is_wardrobe = true 
  1920. 		wardrobe_twn_1:set_end_event("store_clothing_switch_to_wardrobe") 
  1921. 	end 
  1922. 	 
  1923. 	wardrobe_twn_2:set_end_event("store_clothing_switch_mode_complete")		 
  1924. 	 
  1925. 	store_to_wardrobe_anim:play(0) 
  1926. 	 
  1927. 	-- Lock controls until animation is done 
  1928. 	Input_tracker:subscribe(false) 
  1929. 	store_clothing_enable_mouse(false) 
  1930. 	 
  1931. 	-- Set camera position back to whole body 
  1932. 	store_set_camera_pos("body") 
  1933. end 
  1934.  
  1935. function store_clothing_switch_mode_complete() 
  1936. 	local store_main_grp = Vdo_base_object:new("store_main_grp", 0, Store_common_doc_handle) 
  1937. 	 
  1938. 	store_main_grp:set_property("background", false)	 
  1939. 	bg_saints_set_background(false) 
  1940. 	store_unlock_controls() 
  1941. end 
  1942.  
  1943. function store_clothing_switch_to_wardrobe() 
  1944. 	local store_logo_grp = Vdo_base_object:new("store_logo_grp", 0, Store_common_doc_handle) 
  1945. 	 
  1946. 	store_logo_grp:set_visible(false) 
  1947. 	Store_header:reformat_and_resize(true) 
  1948. 	 
  1949. 	store_clothing_mode_set_init() 
  1950. end 
  1951.  
  1952. function store_clothing_switch_to_store() 
  1953. 	local store_logo_grp = Vdo_base_object:new("store_logo_grp", 0, Store_common_doc_handle) 
  1954. 	 
  1955. 	store_logo_grp:set_visible(true) 
  1956. 	Store_header:reformat_and_resize(false) 
  1957. 	 
  1958. 	store_clothing_mode_set_init() 
  1959. end 
  1960.  
  1961. -- Acquire all the outfits the player has into a sub menu. 
  1962. -- 
  1963. function store_clothing_outfit_get_all(menu_data) 
  1964.  
  1965. 	-- disable switching modes here 
  1966. 	store_clothing_set_hints(false) 
  1967.  
  1968. 	Store_common_sub_menu = {} 
  1969. 	Store_common_sub_menu.cb = menu_data.outfit_cb 
  1970. 	 
  1971. 	pcu_report_outfits("store_clothing_outfit_add") 
  1972. 	 
  1973. 	if #Store_common_sub_menu == 0 then 
  1974. 		local new_item = { label = "NO_OUTFITS_DISPLAY_NAME", type = TYPE_BUTTON, on_select = store_common_back_menu } 
  1975. 		Store_common_sub_menu[1] = new_item 
  1976. 	else 
  1977. 		store_clothing_outfit_nav(Store_common_sub_menu[1]) 
  1978. 	end 
  1979. end 
  1980.  
  1981. -- Callback to add 1 outfit to the menu 
  1982. -- 
  1983. function store_clothing_outfit_add(outfit_idx, is_dlc) 
  1984. 	local menu_idx = #Store_common_sub_menu + 1 
  1985. 	local item = { label = "{OUTFIT_NAME_"..outfit_idx.."}", type = TYPE_BUTTON, outfit_index = outfit_idx, on_select = Store_common_sub_menu.cb, 
  1986. 						on_nav = store_clothing_outfit_nav, on_cancel = store_clothing_outfit_revert, is_dlc = is_dlc } 
  1987. 	Store_common_sub_menu[menu_idx] = item 
  1988. end 
  1989.  
  1990. -- Called when navigating over a different outfit. 
  1991. -- 
  1992. function store_clothing_outfit_nav(menu_data) 
  1993. 	Store_clothing_outfit_id = menu_data.outfit_index 
  1994. 	Store_clothing_outfit_finalize = false 
  1995. 	Store_clothing_waiting_update_value = STORE_CLOTHING_PENDING_OWNED_OUTFIT 
  1996. end 
  1997.  
  1998. -- Called when player backs out of outfit preview with back button. 
  1999. -- 
  2000. function store_clothing_outfit_revert(menu_data) 
  2001. 	pcu_category_nav_clear_slot(Store_clothing_area) 
  2002. end 
  2003.  
  2004. -- Handles when the player selects an outfit to preview 
  2005. -- 
  2006. function store_clothing_outfit_select() 
  2007. 	if (pcu_is_streaming_done()) then 
  2008. 		Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)	 
  2009. 		Store_common_popup:set_title("WEAR_OUTFIT_TITLE") 
  2010. 		Store_common_popup:set_text("CONFIRM_WEAR_OUTFIT")				 
  2011. 		Store_common_popup:nav_enable(true, "store_clothing_outfit_select_confirm", "store_clothing_popup_nav") 
  2012. 		Not_popup_grp:set_alpha(.5) 
  2013. 		Store_logo_grp:set_alpha(.5) 
  2014. 		Active_list:set_visible(false) 
  2015. 		 
  2016. 		store_clothing_enable_mouse(false) 
  2017. 	end 
  2018. end 
  2019.  
  2020. -- Confirmation for dialog to wear outfit. 
  2021. -- 
  2022. function store_clothing_outfit_select_confirm(event) 
  2023. 	Store_common_popup:nav_enable(false, nil, nil) 
  2024. 	Not_popup_grp:set_alpha(1)	 
  2025. 	Store_logo_grp:set_alpha(1) 
  2026. 	Active_list:set_visible(true) 
  2027. 	store_clothing_enable_mouse(true) 
  2028. 		 
  2029. 	-- The user hit the B button and is exiting 
  2030. 	-- This is redundant to selecting "No" in the list 
  2031. 	if event == "back" then 
  2032. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  2033. 		return 
  2034. 	end 
  2035. 	 
  2036. 	game_UI_audio_play("UI_Main_Menu_Select") 
  2037. 	 
  2038. 	-- Did we select yes?  This assumes yes is the first item 
  2039. 	if Store_common_popup:get_selected_data() ~= 1 then 
  2040. 		return 
  2041. 	end 
  2042. 	 
  2043. 	Store_clothing_outfit_finalize = true 
  2044. 	Store_clothing_waiting_update_value = STORE_CLOTHING_PENDING_OWNED_OUTFIT 
  2045. 	 
  2046. 	store_common_back_menu() 
  2047. end 
  2048.  
  2049. -- Create an outfit from the player's current clothes. 
  2050. -- 
  2051. function store_clothing_outfit_create() 
  2052.  
  2053. 	local success, reason_title, reason_body 
  2054. 	success, reason_title, reason_body = pcu_can_create_outfit() 
  2055. 	if success == true then 
  2056. 		-- disable switching modes here 
  2057. 		store_clothing_set_hints(false)	 
  2058. 	 
  2059. 		game_vkeyboard_input("OUTFIT_NAME_TAG", "OUTFIT_NAME_ENTRY_DIALOG", 16, "OUTFIT_NAME_TAG", "store_clothing_outfit_name_cb", true) 
  2060. 	else 
  2061. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  2062. 		Store_common_popup:set_title(reason_title) 
  2063. 		Store_common_popup:set_text(reason_body)		 
  2064. 		Store_common_popup:nav_enable(true, "store_clothing_fail_msg", "store_clothing_popup_nav") 
  2065. 		Not_popup_grp:set_alpha(.5) 
  2066. 		Store_logo_grp:set_alpha(.5) 
  2067. 		Active_list:set_visible(false) 
  2068. 		 
  2069. 		store_clothing_enable_mouse(false) 
  2070. 	end 
  2071. end 
  2072.  
  2073. -- Callback from virtual keyboard. 
  2074. -- 
  2075. function store_clothing_outfit_name_cb(success) 
  2076. 	if success == true then 
  2077. 		pcu_create_outfit("VKEYBOARD_RESULTS") 
  2078. 	end 
  2079. 	 
  2080. 	-- enable switching modes here 
  2081. 	store_clothing_set_hints(Store_clothing_loaded_from_crib == false) 
  2082. end 
  2083.  
  2084. -- Pulls up dialog to confirm if we are going to delete an outfit. 
  2085. -- 
  2086. function store_clothing_outfit_delete(menu_data) 
  2087. 	Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)	 
  2088. 	Store_common_popup:set_title("CUST_ITEM_DELETE_OUTFIT") 
  2089. 	Store_common_popup:set_text("CONFIRM_DELETE_OUTFIT")		 
  2090. 	Store_common_popup:nav_enable(true, "store_clothing_outfit_delete_confirm", "store_clothing_popup_nav") 
  2091. 	Not_popup_grp:set_alpha(.5) 
  2092. 	Store_logo_grp:set_alpha(.5) 
  2093. 	Active_list:set_visible(false) 
  2094. 	 
  2095. 	store_clothing_enable_mouse(false) 
  2096. end 
  2097.  
  2098. -- Confirmation for dialog to delete outfit. 
  2099. -- 
  2100. function store_clothing_outfit_delete_confirm(event) 
  2101. 	Store_common_popup:nav_enable(false, nil, nil) 
  2102. 	Not_popup_grp:set_alpha(1) 
  2103. 	Store_logo_grp:set_alpha(1) 
  2104. 	Active_list:set_visible(true) 
  2105. 	store_clothing_enable_mouse(true) 
  2106. 		 
  2107. 	-- The user hit the B button and is exiting 
  2108. 	-- This is redundant to selecting "No" in the list 
  2109. 	if event == "back" then 
  2110. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  2111. 		return 
  2112. 	end 
  2113. 	 
  2114. 	game_UI_audio_play("UI_Main_Menu_Select") 
  2115. 	 
  2116. 	-- Did we select yes?  This assumes yes is the first item 
  2117. 	if Store_common_popup:get_selected_data() ~= 1 then 
  2118. 		return 
  2119. 	end 
  2120. 	 
  2121. 	pcu_delete_outfit(Store_clothing_outfit_id) 
  2122. 	pcu_clear_preview_slot() 
  2123. 	store_common_back_menu() 
  2124. end 
  2125.  
  2126. function store_clothing_remove_clothing() 
  2127. 	Store_common_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)	 
  2128. 	Store_common_popup:set_title("CUST_DIALOG_DISROBE_TITLE") 
  2129. 	Store_common_popup:set_text("CUST_DIALOG_DISROBE_BODY")		 
  2130. 	Store_common_popup:nav_enable(true, "clothing_store_remove_clothing_confirm", "store_clothing_popup_nav") 
  2131. 	Not_popup_grp:set_alpha(.5) 
  2132. 	Store_logo_grp:set_alpha(.5) 
  2133. 	Active_list:set_visible(false) 
  2134. 	 
  2135. 	store_clothing_enable_mouse(false) 
  2136. end 
  2137.  
  2138. function clothing_store_remove_clothing_confirm(event) 
  2139. 	Store_common_popup:nav_enable(false, nil, nil) 
  2140. 	Not_popup_grp:set_alpha(1) 
  2141. 	Store_logo_grp:set_alpha(1) 
  2142. 	Active_list:set_visible(true) 
  2143. 	store_clothing_enable_mouse(true) 
  2144. 		 
  2145. 	-- The user hit the B button and is exiting 
  2146. 	-- This is redundant to selecting "No" in the list 
  2147. 	if event == "back" then 
  2148. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  2149. 		return 
  2150. 	end 
  2151. 	 
  2152. 	game_UI_audio_play("UI_Main_Menu_Select") 
  2153. 	 
  2154. 	-- Did we select yes?  This assumes yes is the first item 
  2155. 	if Store_common_popup:get_selected_data() ~= 1 then 
  2156. 		return 
  2157. 	end 
  2158. 	 
  2159. 	pcu_remove_clothing() 
  2160. end 
  2161.  
  2162. function store_clothing_outfit_enter(menu_data) 
  2163.  
  2164. 	-- enable switching modes here 
  2165. 	store_clothing_set_hints(Store_clothing_loaded_from_crib == false) 
  2166. 	 
  2167. end 
  2168.  
  2169. function store_clothing_play_exit_anim() 
  2170.  
  2171. 	--[[if Store_clothing_loaded_from_crib == false then 
  2172.  
  2173. 		local anim_out = Vdo_anim_object:new("lets_pretend_bg_anim_out", 0, Store_clothing_doc_handle) 
  2174. 		local end_event_twn = Vdo_tween_object:new("anim_out_end_event", anim_out.handle) 
  2175. 			 
  2176. 		end_event_twn:set_end_event("store_unload_doc") 
  2177. 		 
  2178. 		anim_out:play(0) 
  2179. 		store_common_play_anim_out() 
  2180. 	else 
  2181. 		store_unload_doc() 
  2182. 	end]]-- 
  2183. 	 
  2184. 	local anim_out 
  2185. 	local end_event_twn 
  2186.  
  2187. 	if Store_index == CRIB then 
  2188. 			 
  2189. 			store_unload_doc() 
  2190. 			 
  2191. 	elseif  Store_index == LETS_PRETEND then 
  2192. 		 
  2193. 		--Find exit anim 
  2194. 		--Find end event twn 
  2195. 		--set end event to "store_unload_doc" 
  2196. 		--Play anim 
  2197. 		 
  2198. 		anim_out = Vdo_anim_object:new("lets_pretend_bg_anim_out", 0, Store_clothing_doc_handle) 
  2199. 		end_event_twn = Vdo_tween_object:new("anim_out_end_event", anim_out.handle) 
  2200. 			 
  2201. 		end_event_twn:set_end_event("store_unload_doc") 
  2202. 		 
  2203. 		anim_out:play(0) 
  2204. 		store_common_play_anim_out()		 
  2205. 		 
  2206. 	elseif Store_index == NOBODY_LOVES_ME then 
  2207. 	 
  2208. 		anim_out = Vdo_anim_object:new("nobody_bg_anim_out", 0, Store_clothing_doc_handle) 
  2209. 		end_event_twn = Vdo_tween_object:new("end_event_twn", anim_out.handle) 
  2210. 			 
  2211. 		end_event_twn:set_end_event("store_unload_doc") 
  2212. 		 
  2213. 		anim_out:play(0) 
  2214. 		store_common_play_anim_out()	 
  2215. 		 
  2216. 	elseif Store_index == LEATHER_AND_LACE then 
  2217. 		 
  2218. 		 
  2219. 		--must stop other bg anim from playing before fade out 
  2220. 		anim_out = Vdo_anim_object:new("lace_bg_anim_out", 0, Store_clothing_doc_handle) 
  2221. 		end_event_twn = Vdo_tween_object:new("end_event_twn", anim_out.handle) 
  2222. 			 
  2223. 		end_event_twn:set_end_event("store_unload_doc") 
  2224. 		 
  2225. 		anim_out:play(0) 
  2226. 		store_common_play_anim_out() 
  2227. 		 
  2228. 	elseif Store_index == PLANET_SAINTS then 
  2229. 		 
  2230. 		anim_out = Vdo_anim_object:new("planet_bg_anim_out", 0, Store_clothing_doc_handle) 
  2231. 		end_event_twn = Vdo_tween_object:new("end_event_twn", anim_out.handle) 
  2232. 			 
  2233. 		end_event_twn:set_end_event("store_unload_doc") 
  2234. 		 
  2235. 		anim_out:play(0) 
  2236. 		store_common_play_anim_out() 
  2237. 	else 
  2238. 		store_unload_doc() 
  2239. 	end 
  2240. 		 
  2241. end 
  2242.  
  2243. function store_unload_doc() 
  2244.  
  2245. 	vint_document_unload() 
  2246. 	 
  2247. end 
  2248.  
  2249. function store_clothing_bg_anim_done() 
  2250. 	store_common_bg_anim_complete() 
  2251. end 
  2252.  
  2253. -- ===================================== 
  2254. --       Mouse Specific Functions 
  2255. -- ===================================== 
  2256. function store_clothing_enable_mouse(enable) 
  2257. 	if Game_platform == "PC" and enable ~= nil then 
  2258. 		if Mouse_input_tracker ~= 0 then 
  2259. 			Mouse_input_tracker:subscribe(enable) 
  2260. 		end 
  2261. 		 
  2262. 		if Hint_bar_mouse_input_tracker ~= -1 then 
  2263. 			Hint_bar_mouse_input_tracker:subscribe(enable) 
  2264. 		end 
  2265. 	end 
  2266. end 
  2267.  
  2268. function store_clothing_mouse_click(event, target_handle) 
  2269. 	local hint_index = Store_common_hint_bar:get_hint_index(target_handle) 
  2270. 	if hint_index ~= 0 then 
  2271. 		if Current_tier == MENU_TIER then 
  2272. 			store_common_button_b() 
  2273. 		elseif Current_tier == COLOR_TIER then 
  2274. 			store_clothing_color_selected("back") 
  2275. 		end 
  2276. 	end 
  2277. end 
  2278.  
  2279. function store_clothing_mouse_move(event, target_handle) 
  2280.   
  2281. 	vint_set_mouse_cursor("") 
  2282. 	store_common_mouse_zoom(0.0) 
  2283.  
  2284. 	Store_common_hint_bar:set_highlight(0) 
  2285. 	 
  2286. 	local hint_index = Store_common_hint_bar:get_hint_index(target_handle) 
  2287. 	if hint_index ~= 0 then 
  2288. 		Store_common_hint_bar:set_highlight(hint_index, Store_common_current_highlight_color) 
  2289. 	end 
  2290. 	 
  2291. 	local old_index = Active_list:get_selection() 
  2292. 	local new_index = Active_list:get_button_index(target_handle) 
  2293. 	if new_index ~= 0 and new_index ~= old_index then 
  2294. 		Active_list:set_selection(new_index) 
  2295. 		Active_list:move_cursor(0, true) 
  2296. 		 
  2297. 		-- If the item has a callback for navigation, do it (such as putting clothes on) 
  2298. 		local data_item = Active_list:return_selected_data() 
  2299. 		if data_item.on_nav ~= nil then 
  2300. 			data_item.on_nav(data_item) 
  2301. 		elseif Menu_data.default_on_nav ~= nil then 
  2302. 			Menu_data.default_on_nav(data_item) 
  2303. 		end 
  2304. 		return 
  2305. 	end 
  2306. end 
  2307.  
  2308. function store_clothing_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  2309. 	if scroll_lines ~= 0 then 
  2310. 		if Store_common_color_grid.bg.handle == target_handle then 
  2311. 			Store_common_color_grid:scroll_list(scroll_lines * -1) 
  2312. 		end 
  2313. 	end 
  2314. end 
  2315.  
  2316. function store_clothing_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  2317. 	if Store_common_color_grid.scrollbar.tab_grp.handle == target_handle then 
  2318. 		local new_start_index = Store_common_color_grid.scrollbar:drag_scrolltab(mouse_y, Store_common_color_grid.rows - (Store_common_color_grid.max_height - 1)) 
  2319. 		Store_common_color_grid:scroll_list(0, new_start_index) 
  2320. 	end 
  2321. end 
  2322.  
  2323. function store_clothing_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  2324. 	if Store_common_color_grid.scrollbar.tab_grp.handle == target_handle then 
  2325. 		local start_row = Store_common_color_grid:get_visible_rows() 
  2326. 		Store_common_color_grid.scrollbar:release_scrolltab(start_row, Store_common_color_grid.rows - (Store_common_color_grid.max_height - 1)) 
  2327. 		Store_common_color_grid:update_mouse_inputs() 
  2328. 	end 
  2329. end 
  2330.