./powers_sub.lua

  1. -- Offset of list and header from other store layouts 
  2. local POWERS_OFFSET = 80  
  3. local POWERS_LIST_WIDTH = 0 
  4.  
  5. local DESC_GRP_SPACING = 20 
  6.  
  7. -- Hint bar and store header vdo's. 
  8. local Hint_bar 
  9. local Not_popup_grp 
  10. local Store_popup 
  11. local Powers_sub_menu_data = {} 
  12. local Upgrades_descriptions = {} 
  13. local Desc_cloned_grps = {} 
  14. local Hint_bar_mouse_input_tracker 
  15. local Large_element_icon_h 
  16.  
  17. local Cur_description_element 
  18.  
  19. local Powers_sub_doc_h = -1 
  20.  
  21. --Image 
  22. local Powers_sub_loading_img = nil 
  23. local Powers_sub_unload_img = nil 
  24.  
  25. --Title 
  26. local Title_txt_h = -1 
  27. local Power_icon_h = -1 
  28. local Element_icon_h = -1 
  29. local Desc_header_txt_h = -1 
  30. local Elements_desc_txt_h = -1 
  31. local Desc_simple_txt_h = -1 
  32. local Desc_base_grp_h = -1 
  33. local Elements_locked_grp_h 
  34. local Elements_locked_txt_h 
  35. local Elements_locked_bg_h 
  36. local Elements_locked_trim_h 
  37. local Elements_locked_trim2_h 
  38.  
  39. local Level_req_h 
  40. local Level_req_label_h 
  41. local Level_req_grp_h 
  42. --Anims 
  43. local Powers_out_anim_h 
  44.  
  45. function powers_sub_init()	 
  46. 	 
  47. 	vint_force_lua_gc() --Force Garbage Collection 
  48. 	pause_map_dump() 
  49. 	Powers_sub_doc_h = vint_document_find("powers_sub") 
  50. 		 
  51. 	--Anims 
  52. 	Powers_out_anim_h = vint_object_find("powers_out_anim", 0, Powers_sub_doc_h) 
  53. 	 
  54. 	--Set up some callbacks for the common store script 
  55. 	Store_common_populate_list_cb = powers_sub_populate_list 
  56. 	Store_common_exit_cb				= powers_sub_exit_to_main 
  57. 	 
  58. 	--Subscribe to the button presses we need 
  59. 	Input_tracker:remove_input("map") 
  60. 	Input_tracker:add_input("map", "powers_sub_input_map", 50) 
  61. 	if game_get_platform() == "PC" then 
  62. 		Input_tracker:add_input("alt_joy_up", "powers_scroll_list", 50) 
  63. 		Input_tracker:add_input("alt_joy_down", "powers_scroll_list", 50) 
  64. 	end 
  65. 	Input_tracker:subscribe(false) 
  66. 	 
  67. 	--Setup Button Hints 
  68. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Store_common_doc_handle) 
  69. 	local hint_data = { 
  70. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  71. 	} 
  72. 	Hint_bar:set_hints(hint_data) 	 
  73. 	Hint_bar:set_visible(true) 
  74. 	 
  75. 	-- Mouse input 
  76. 	if game_get_platform() == "PC" then 
  77. 		Hint_bar:set_highlight(0) 
  78. 		 
  79. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  80. 		Hint_bar:add_mouse_inputs("powers_sub", Hint_bar_mouse_input_tracker) 
  81. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  82. 	end 
  83. 	 
  84. 	--Init large element image 
  85. 	Large_element_icon_h = vint_object_find("large_element_icon", 0, Powers_sub_doc_h) 
  86. 	vint_set_property(Large_element_icon_h, "visible", false) 
  87. 	 
  88. 	--Store header 
  89. 	Store_header:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY)	 
  90. 	Store_header:set_visible(true) 
  91. 	--Store_header:set_scale(.9, .9) 
  92. 	 
  93. 	Active_list = Vdo_mega_list:new("list_1", 0, Store_common_doc_handle, "store_common.lua", "Active_list") 
  94. 	 
  95. 	 
  96. 	--turn off store logo??? 
  97. 	 
  98. 	-- Everything that is not in the popup so we can fade it when the popup is active 
  99. 	Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle) 
  100. 	 
  101. 	-- Setup purchase popup 
  102. 	Store_popup = Vdo_store_popup:new("store_popup", 0, Store_common_doc_handle) 
  103. 	Store_popup:set_visible(false) 
  104. 	Store_popup:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY) 
  105. 	Store_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5)) 
  106. 	 
  107. 	-- Needs to be done after the list is drawn/populated 
  108. 	Active_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY)	 
  109. 	 
  110. 	local powers_grp = vint_object_find("powers_grp", 0, Powers_sub_doc_h)	 
  111. 	vint_set_property(powers_grp, "visible", true) 
  112. 	 
  113. 	-- For the rewards store, we don't want the bg to render behind the player, so change this property. 
  114. 	-- Perhaps these can be organized so it's easier to do this. 
  115. 	local grp1_h = vint_object_find("lets_pretend_bg_grp", 0, Store_common_doc_handle) 
  116. 	vint_set_property(grp1_h, "background", false) 
  117. 	vint_set_property(grp1_h, "visible", false) 
  118. 	 
  119. 	-- Animate store in 
  120. 	local store_anim_h = vint_object_find("powers_anim_in", 0, Store_common_doc_handle) 
  121. 	lua_play_anim(store_anim_h, 0, Store_common_doc_handle)	 
  122. 	 
  123. 	Title_txt_h = vint_object_find("title_txt", 0, Powers_sub_doc_h) 
  124. 	Power_icon_h = vint_object_find("power_icon", 0, Powers_sub_doc_h) 
  125. 	Element_icon_h = vint_object_find("element_icon", 0, Powers_sub_doc_h) 
  126. 	Desc_header_txt_h = vint_object_find("desc_header_txt", 0, Powers_sub_doc_h) 
  127. 	Elements_desc_txt_h = vint_object_find("elements_desc_txt", 0, Powers_sub_doc_h) 
  128. 	Desc_simple_txt_h =  vint_object_find("desc_simple_txt", 0, Powers_sub_doc_h) 
  129. 	Desc_base_grp_h = vint_object_find("desc_base_grp", 0, Powers_sub_doc_h) 
  130. 	Elements_locked_grp_h = vint_object_find("elements_locked_grp", 0, Powers_sub_doc_h) 
  131. 	Elements_locked_txt_h = vint_object_find("elements_locked_txt", 0, Powers_sub_doc_h) 
  132. 	Elements_locked_bg_h = vint_object_find("elements_locked_bg", 0, Powers_sub_doc_h) 
  133. 	Elements_locked_trim_h = vint_object_find("elements_locked_trim", 0, Powers_sub_doc_h) 
  134. 	Elements_locked_trim2_h = vint_object_find("elements_locked_trim2", 0, Powers_sub_doc_h) 
  135. 	 
  136. 	Level_req_h = vint_object_find("level_req", 0, Powers_sub_doc_h) 
  137. 	Level_req_label_h = vint_object_find("level_req_label", 0, Powers_sub_doc_h) 
  138. 	Level_req_grp_h = vint_object_find("level_req_grp", 0, Powers_sub_doc_h) 
  139. 	 
  140. 	--Set Title Area 
  141. 	vint_set_property(Title_txt_h, "text_tag", Powers_cur_power_name) 
  142. 	vint_set_property(Title_txt_h, "tint", 230/255, 230/255, 230/255) 
  143. 	vint_set_property(Power_icon_h, "image", Powers_cur_power_bitmap) 
  144. 	vint_set_property(Element_icon_h, "image", Powers_cur_element_bitmap) 
  145. 	 
  146. 	--Hide element icon if not a rad power 
  147. 	if Powers_cur_type == POWERS_TYPE_RAD then 
  148. 		vint_set_property(Element_icon_h, "visible", true) 
  149. 	else 
  150. 		vint_set_property(Element_icon_h, "visible", false) 
  151. 	end 
  152. 	 
  153. 	--Are we upgrades or elements? 
  154. 	--Determine which data to populate list with 
  155. 	if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then 
  156. 		vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_upgrades", 0, "get_avail_upgrades", Powers_cur_id) 
  157. 		Store_header:push_title(nil, "POWERS_UPGRADES_HEADER") 
  158. 	else 
  159. 		if Powers_cur_id == 6 then 
  160. 			vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_elements", 0, "get_elements", Powers_cur_id) 
  161. 			Store_header:push_title(nil, "POWERS_WING_STYLE_HEADER") 
  162. 		else 
  163. 			vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_elements", 0, "get_elements", Powers_cur_id) 
  164. 			Store_header:push_title(nil, "POWERS_ELEMENTS_HEADER") 
  165. 		end 
  166. 	end 
  167. 	 
  168. 	powers_sub_populate_list(Powers_sub_menu_data, 1)	 
  169. 	powers_sub_on_enter() 
  170. 	powers_sub_unlock_controls() 
  171. 	--glitch 
  172. 	glitch_cell() 
  173. 	 
  174. end 
  175.  
  176. function powers_sub_cleanup() 
  177. 	Input_tracker:subscribe(false) 
  178. 	powers_sub_enable_mouse(false) 
  179. 	 
  180. 	if Powers_sub_unload_img ~= nil and Powers_sub_unload_img ~= -1 then 
  181. 		game_peg_unload(Powers_sub_unload_img)	 
  182. 	end 
  183. 	if Powers_sub_loading_img ~= nil and Powers_sub_loading_img ~= -1 then 
  184. 		game_peg_unload(Powers_sub_loading_img)	 
  185. 	end 
  186.  
  187. 	pause_map_restore() 
  188. 	vint_force_lua_gc() --Force Garbage Collection 
  189. end 
  190.  
  191. ----------------- 
  192. --Image Functions 
  193. ----------------- 
  194.  
  195. -- Called in a thread to delay the image updating. 
  196. -- This is done for 2 reasons: to slow down rapid scrolling updates done too quickly, 
  197. -- and because the streaming system didn't always co-operate with the images being released 
  198. -- from the callback context that was executed when another stream load completed. 
  199. -- 
  200. function powers_sub_image_update(image) 
  201. 	thread_new( "powers_sub_image_update_process", image ) 
  202. end 
  203.  
  204. function powers_sub_image_update_process(image) 
  205. 	--delay(0.2) 
  206. 	vint_set_property(Large_element_icon_h, "visible", false) 
  207. 	if Powers_sub_unload_img ~= nil and Powers_sub_unload_img ~= -1 then 
  208. 		game_peg_unload(Powers_sub_unload_img)	 
  209. 		thread_yield() 
  210. 		thread_yield() 
  211. 		thread_yield() 
  212. 	end 
  213. 	Powers_sub_loading_img = image 
  214. 	game_peg_load_with_cb("powers_sub_show_image", 1, Powers_sub_loading_img) 
  215. end 
  216.  
  217. -- Callback for when an image is done loading. 
  218. function powers_sub_show_image() 
  219. 	vint_set_property(Large_element_icon_h, "image", Powers_sub_loading_img) 
  220. 	vint_set_property(Large_element_icon_h, "visible", true) 
  221. 	Powers_sub_unload_img = Powers_sub_loading_img 
  222. end 
  223.  
  224. ----------------- 
  225. --Store Functions 
  226. ----------------- 
  227.  
  228. function powers_sub_add_upgrades(name_crc, is_locked, is_purchased, price, id, level_required, trumps, is_new, is_orb, orbs_collected, gameplay_gate) 
  229. 	local menu_idx = #Powers_sub_menu_data + 1 
  230. 	 
  231. 	level_required = level_required + 1 
  232.  
  233. 	local new_item = { 
  234. 		type = TYPE_BUTTON, 
  235. 		id = id, 
  236. 		--name_crc = name_crc, 
  237. 		label = nil, 
  238. 		label_crc = name_crc, 
  239. 		--image = image_name, 
  240. 		--description = desc_crc, 
  241. 		is_locked = is_locked, 
  242. 		is_purchased = is_purchased, 
  243. 		price = price, 
  244. 		-- Display of level and max_level disabled for now 
  245. 		level = nil, 
  246. 		max_level = nil, 
  247. 		level_required = level_required, 
  248. 		on_nav = powers_sub_item_nav, 
  249. 		on_select = powers_sub_purchase_select, 
  250. 		on_enter = powers_sub_on_enter, 
  251. 		--on_back = powers_sub_revert_header, 
  252. 		trumps = trumps, -- CRC for the name of the prerequisite 
  253. 		is_new = is_new, 
  254. 		is_orb = true, 
  255. 		orbs_collected = orbs_collected, 
  256. 		gameplay_gate = gameplay_gate, 
  257. 	}		 
  258. 	 
  259. 	Powers_sub_menu_data[menu_idx] = new_item 
  260. end 
  261.  
  262. --call this once for each list item, and it will fill in the appropriate number of descriptions 
  263. function powers_sub_add_upgrades_descriptions(description, element) 
  264. 	local i = #Upgrades_descriptions + 1 
  265. 	Upgrades_descriptions[i] = {} 
  266. 	local t = Upgrades_descriptions[i] 
  267. 	t.description = description 
  268. 	t.element = element 
  269. 	Cur_description_element = element 
  270. end 
  271.  
  272. function powers_sub_add_elements(name_crc, desc_crc, element_id, unlockable_id, is_locked, equipped, is_new, wing_id) 
  273. 	local menu_idx = #Powers_sub_menu_data + 1 
  274.  
  275. 	local new_item = { 
  276. 		type = TYPE_BUTTON, 
  277. 		id = element_id, 
  278. 		unlockable_id = unlockable_id, 
  279. 		-- label = nil, 
  280. 		label_crc = name_crc, 
  281. 		--image = image_name, 
  282. 		desc = desc_crc, 
  283. 		is_locked = is_locked, 
  284. 		owned = true, 
  285. 		equipped = equipped, 
  286. 		-- Display of level and max_level disabled for now 
  287. 		level = nil, 
  288. 		max_level = nil, 
  289. 		level_required = 0, 
  290. 		on_nav = powers_sub_item_nav, 
  291. 		on_select = powers_sub_purchase_select, 
  292. 		on_enter = powers_sub_on_enter, 
  293. 		--on_back = powers_sub_revert_header, 
  294. 		trumps = 0, -- CRC for the name of the prerequisite 
  295. 		is_new = is_new, 
  296. 		is_element = true, 
  297. 		wing_id = wing_id,  
  298. 		--is_orb = true, 
  299. 	}		 
  300. 	 
  301. 	Powers_sub_menu_data[menu_idx] = new_item 
  302. end 
  303.  
  304.  
  305. -- Populate the active megalist menu, 
  306. -- 
  307. -- list_data: 		this table contains the data to populate the megalist 
  308. -- current_index: 	the current index in the menu that's selected 
  309. -- 
  310. function powers_sub_populate_list(list_data, current_index) 
  311. 	Active_list:set_scale_text_if_too_big(true) 
  312. 	 
  313. 	if Powers_screen_state == POWERS_SCREEN_STATE_ELEMENT then 
  314. 		for i = 1, #list_data do 
  315. 			list_data[i].label = POWERS_ELEMENTS_ENUMS[list_data[i].id].short_label  
  316. 		end 
  317. 	end 
  318. 	Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10) 
  319. 	Menu_data = list_data 
  320. 	Active_list:set_visible(true)	 
  321. 	powers_sub_item_nav(Menu_data[current_index]) 
  322. 	 
  323. 	if game_get_platform() == "PC" then 
  324. 		Mouse_input_tracker:remove_all() 
  325. 		Active_list:set_store("powers_sub")  
  326. 		Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  327. 		Mouse_input_tracker:subscribe(true) 
  328. 	end 
  329. end 
  330.  
  331. function powers_sub_on_enter() 
  332. 	powers_sub_item_nav(Powers_sub_menu_data[1]) 
  333. end 
  334.  
  335. function powers_sub_item_nav(menu_data) 
  336. 	--Update text on right of screen based on highlighted item 
  337. 	 
  338. 	-- if this was marked as "new", then clear the flag since the player highlighted it 
  339. 	if menu_data.is_new then 
  340. 		local unlockable_id = menu_data.unlockable_id or menu_data.id 
  341. 		vint_dataresponder_post("cell_rewards_reward_dr", "Clear_new", unlockable_id) 
  342. 		 
  343. 		--Remove our mouse inputs first... 
  344. 		if Mouse_input_tracker ~= 0 then 
  345. 			Mouse_input_tracker:remove_all() 
  346. 		end 
  347. 		 
  348. 		--Get index from the list and then remove the flag... 
  349. 		local index = Active_list:get_index_from_id(menu_data.id) 
  350. 		if index ~= -1 then 
  351. 			Active_list:remove_new_flag(index) 
  352. 		end 
  353. 		 
  354. 		--Update cursor, 
  355. 		Active_list:move_cursor(0) 
  356. 		--Re add mouse inputs... 
  357. 		if Mouse_input_tracker ~= 0 then 
  358. 			Mouse_input_tracker:remove_all() 
  359. 			Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  360. 			Mouse_input_tracker:subscribe(true) 
  361. 		end 
  362. 	end	 
  363. 	 
  364. 	--Destroy any cloned grps 
  365. 	for i = 1, #Desc_cloned_grps do 
  366. 		vint_object_destroy(Desc_cloned_grps[i]) 
  367. 	end 
  368. 	 
  369. 	--Base upgrades desc handle and hide... 
  370. 	local desc_grp_h = vint_object_find("desc_grp", 0, Powers_sub_doc_h) 
  371. 	vint_set_property(desc_grp_h, "visible", false) 
  372. 	vint_set_property(Level_req_grp_h, "visible", false) 
  373. 	 
  374. 	--Update Description 
  375. 	if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then 
  376. 		--Hide element desc text field and image 
  377. 		vint_set_property(Large_element_icon_h, "visible", false) 
  378. 		vint_set_property(Elements_desc_txt_h, "visible", false) 
  379. 		vint_set_property(Elements_locked_grp_h, "visible", false) 
  380. 		 
  381. 		--Update Description Header 
  382. 		vint_set_property(Desc_header_txt_h, "text_tag_crc", menu_data.label_crc) 
  383. 		resize_text_element(Desc_header_txt_h, 350) 
  384. 		 
  385. 		table_clear(Upgrades_descriptions, true) 
  386. 		 
  387. 		Upgrades_descriptions = {} 
  388. 		vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_upgrades_descriptions", 0, "get_upgrade_desc", menu_data.id) 
  389. 		--[[powers_sub_add_upgrades_descriptions("Test ipsum dolor sit amet, ", 1) 
  390. 		powers_sub_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2) 
  391. 		powers_sub_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.", 3)  
  392. 		powers_sub_add_upgrades_descriptions("Test ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.", 1) 
  393. 		powers_sub_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2) 
  394. 		powers_sub_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2)]] 
  395. 		 
  396. 		 
  397. 		--use cloned grps for element specific upgrade descriptions 
  398. 		if Upgrades_descriptions[1] ~= nil then 
  399. 			if Upgrades_descriptions[1].element ~= -1 then 
  400. 				 
  401. 				vint_set_property(Desc_simple_txt_h, "visible", false) 
  402. 				 
  403. 				local prev_height = 0 
  404. 				Desc_cloned_grps = {} 
  405. 				 
  406. 				for i = 1, #Upgrades_descriptions do 
  407. 					--get data out of table 
  408. 					local description = Upgrades_descriptions[i].description 
  409. 					local element = Upgrades_descriptions[i].element 
  410. 					 
  411. 					--clone base item... 
  412. 					local h = vint_object_clone(desc_grp_h) 
  413. 					 
  414. 					--Set Text 
  415. 					local desc_type_txt_h = vint_object_find("desc_type_txt", h) 
  416. 					local desc_txt_h = vint_object_find("desc_txt", h) 
  417. 					vint_set_property(desc_type_txt_h, "text_tag", POWERS_ELEMENTS_ENUMS[element].short_label) 
  418. 					vint_set_property(desc_txt_h, "text_tag", description) 
  419. 					 
  420. 					--Set icon 
  421. 					-- TODO: add ability to show non element specific description if needed 
  422. 					local desc_icon_h = vint_object_find("desc_icon", h) 
  423. 					vint_set_property(desc_icon_h, "image", POWERS_ELEMENTS_ENUMS[element].bitmap) 
  424. 					 
  425. 					--Position grp... 
  426. 					local x, y = vint_get_property(h, "anchor") 
  427. 					local width1, height1 = element_get_actual_size(desc_type_txt_h) 
  428. 					local width2, height2 = element_get_actual_size(desc_txt_h) 
  429. 					y = ( (i - 1) * DESC_GRP_SPACING ) + prev_height 
  430. 					vint_set_property(h, "anchor", x, y ) 
  431. 					prev_height = prev_height + height1 + height2 
  432. 					 
  433. 					--store cloned grps in table to be destroyed 
  434. 					Desc_cloned_grps[i] = h 
  435. 			 
  436. 					--Show grp 
  437. 					vint_set_property(h, "visible", true) 
  438. 					 
  439. 					--scale if nessesary 
  440. 					local max_desc_height = 345 
  441. 					if prev_height > max_desc_height then 
  442. 						local scale_amount = max_desc_height/prev_height 
  443. 						vint_set_property(Desc_base_grp_h, "scale", scale_amount, scale_amount) 
  444. 					else 
  445. 						vint_set_property(Desc_base_grp_h, "scale", 1,1) 
  446. 					end 
  447. 				end 
  448. 			 
  449. 			--use simple upgrade text box if element is -1 
  450. 			else 
  451. 				vint_set_property(desc_grp_h, "visible", false) 
  452. 				vint_set_property(Desc_simple_txt_h, "text_tag", Upgrades_descriptions[1].description) 
  453. 				vint_set_property(Desc_simple_txt_h, "visible", true) 
  454. 				vint_set_property(Desc_base_grp_h, "scale", 1,1) 
  455. 			end 
  456. 			 
  457. 		else 
  458. 		--This should never get called hopefully 
  459. 			vint_set_property(desc_grp_h, "visible", false) 
  460. 			vint_set_property(Desc_simple_txt_h, "text_tag", "") 
  461. 			vint_set_property(Desc_simple_txt_h, "visible", true) 
  462. 		end 
  463. 		 
  464. 		---------------- 
  465. 		--Gameplay gated 
  466. 		---------------- 
  467. 		if menu_data.gameplay_gate ~= nil and menu_data.gameplay_gate ~= "" then 
  468. 			--show and format locked text 
  469. 			 
  470. 			local elements_locked_string = "" 
  471. 			if menu_data.gameplay_gate == "quest" then 
  472. 				elements_locked_string = "UPGRADES_LOCKED_QUEST" 
  473. 			elseif menu_data.gameplay_gate == "challenge" then 
  474. 				elements_locked_string = "UPGRADES_LOCKED_CHALLENGE" 
  475. 			end 
  476. 			vint_set_property(Elements_locked_txt_h, "text_tag", elements_locked_string) 
  477. 			local width, height = element_get_actual_size(Elements_locked_txt_h) 
  478. 			element_set_actual_size(Elements_locked_bg_h, width + 24, height + 14) 
  479. 			element_set_actual_size(Elements_locked_trim_h, width + 24, 2) 
  480. 			element_set_actual_size(Elements_locked_trim2_h, width + 24, 2) 
  481. 			vint_set_property(Elements_locked_trim_h, "anchor", 0, -(height/2) - 7) 
  482. 			vint_set_property(Elements_locked_trim2_h, "anchor", 0, (height/2) + 7) 
  483. 			vint_set_property(Elements_locked_grp_h, "visible", true) 
  484. 		else 
  485. 			vint_set_property(Elements_locked_grp_h, "visible", false) 
  486. 		end 
  487. 		 
  488. 		--tint text desc 
  489. 		if (menu_data.gameplay_gate ~= nil and menu_data.gameplay_gate ~= "") then  
  490. 			vint_set_property(Desc_base_grp_h, "alpha", .5) 
  491. 			vint_set_property(Desc_simple_txt_h, "alpha", .5) 
  492. 		elseif menu_data.is_locked == true then 
  493. 			vint_set_property(Desc_base_grp_h, "alpha", .5) 
  494. 			vint_set_property(Desc_simple_txt_h, "alpha", .5) 
  495. 			vint_set_property(Level_req_grp_h, "visible", true) 
  496. 			vint_set_property(Level_req_h, "text_tag", var_to_string(menu_data.level_required)) 
  497. 			vint_set_property(Level_req_label_h, "text_tag", "STORE_UPGRADES_REQUIRED") 
  498. 		else	 
  499. 			vint_set_property(Desc_base_grp_h, "alpha", 1) 
  500. 			vint_set_property(Desc_simple_txt_h, "alpha", 1) 
  501. 		end 
  502. 		 
  503. 	else 
  504. 		powers_sub_image_update(POWERS_ELEMENTS_ENUMS[menu_data.id].large_bitmap) 
  505. 		 
  506. 		--Update Description Header 
  507. 		vint_set_property(Desc_header_txt_h, "text_tag", POWERS_ELEMENTS_ENUMS[menu_data.id].short_label) 
  508. 		resize_text_element(Desc_header_txt_h, 350) 
  509. 		 
  510. 		if menu_data.is_locked then 
  511. 			--show and format locked text 
  512. 			vint_set_property(Large_element_icon_h, "tint", 100/255, 100/255, 100/255) 
  513. 			vint_set_property(Elements_desc_txt_h, "alpha", .5) 
  514. 			vint_set_property(Elements_locked_grp_h, "visible", true) 
  515. 			local width, height = element_get_actual_size(Elements_locked_txt_h) 
  516. 			element_set_actual_size(Elements_locked_bg_h, width + 24, height + 14) 
  517. 			element_set_actual_size(Elements_locked_trim_h, width + 24, 2) 
  518. 			element_set_actual_size(Elements_locked_trim2_h, width + 24, 2) 
  519. 			vint_set_property(Elements_locked_trim_h, "anchor", 0, -(height/2) - 7) 
  520. 			vint_set_property(Elements_locked_trim2_h, "anchor", 0, (height/2) + 7) 
  521. 		else 
  522. 			vint_set_property(Large_element_icon_h, "tint", 220/255, 220/255, 220/255) 
  523. 			vint_set_property(Elements_desc_txt_h, "alpha", 1) 
  524. 			vint_set_property(Elements_locked_grp_h, "visible", false) 
  525. 		end 
  526. 		 
  527. 		vint_set_property(Elements_desc_txt_h, "text_tag_crc", menu_data.desc) 
  528. 		vint_set_property(Desc_simple_txt_h, "visible", false) 
  529. 		vint_set_property(desc_grp_h, "visible", false) 
  530. 		vint_set_property(Elements_desc_txt_h, "visible", true) 
  531. 	end 
  532. 	--Update store header 
  533. 	Store_header:set_price(menu_data.price, menu_data.is_orb) 
  534. 	Store_header:set_level(menu_data.level_required, menu_data.is_orb) 
  535. 	if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then 
  536. 		Store_header:show_cash(true) 
  537. 		if menu_data.is_orb == true then 
  538. 			Store_header:set_cash(menu_data.orbs_collected, menu_data.is_orb) 
  539. 		else 
  540. 			Store_header:set_cash(Store_common_player_cash, menu_data.is_orb) 
  541. 		end	 
  542. 	else 
  543. 		Store_header:show_cash(false) 
  544. 	end 
  545. end 
  546.  
  547.  
  548. function powers_sub_purchase_select(menu_data) 
  549. 	if menu_data.is_locked == true or menu_data.is_purchased == true then	 
  550. 		return 
  551. 	end 
  552. 	powers_sub_enable_mouse(false) 
  553.  
  554. 	-- Are we short on orbs? 
  555.  
  556. 	if Powers_screen_state ~= POWERS_SCREEN_STATE_ELEMENT and menu_data.price > menu_data.orbs_collected then 
  557. 		Store_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  558. 		Store_popup:set_title("MENU_TITLE_NOTICE") 
  559. 		Store_popup:set_text("HUD_SHOP_INSUFFICIENT_ORBS")		 
  560. 		Store_popup:nav_enable(true, "powers_sub_fail_msg", "powers_sub_popup_nav") 
  561. 		Not_popup_grp:set_alpha(.5)		 
  562. 		--Active_list:set_visible(false) 
  563. 		return 
  564. 	end 
  565.  
  566. 	-- Make sure they want to buy this 
  567. 	 
  568. 	if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then 
  569. 		Store_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)	 
  570. 		Store_popup:set_title("STORE_TITLE_PURCHASING") 
  571. 		Store_popup:set_text("STORE_TEXT_CONFIRM_PURCHASE_BLANK")	 
  572. 		Store_popup:nav_enable(true, "powers_sub_purchase_final", "powers_sub_popup_nav") 
  573. 		Not_popup_grp:set_alpha(.5) 
  574. 		--Active_list:set_visible(false) 
  575. 		 
  576. 	else 
  577. 		if game_death_tag_is_active() then 
  578. 			Store_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  579. 			Store_popup:set_title("MENU_TITLE_NOTICE") 
  580. 			Store_popup:set_text("HUD_SHOP_ELEMENTS_DISABLED")		 
  581. 			Store_popup:nav_enable(true, "powers_sub_fail_msg", "powers_sub_popup_nav") 
  582. 			Not_popup_grp:set_alpha(.5)	 
  583. 			return			 
  584. 		else 
  585. 			 
  586. 			if Powers_cur_id == 6 then --Flight wings selection 
  587. 				local current_index = Active_list:get_selection() 
  588. 				vint_scriptevent_post( "ui_powers_main", "set_wing_type", Powers_sub_menu_data[current_index].wing_id ) 
  589. 				powers_sub_exit_to_main() 
  590. 			else 
  591. 				local current_index = Active_list:get_selection() 
  592. 				vint_scriptevent_post( "ui_powers_main", "set_element", Powers_sub_menu_data[current_index].id ) 
  593. 				vint_set_property(Element_icon_h, "image", POWERS_ELEMENTS_ENUMS[Powers_sub_menu_data[current_index].id].bitmap) 
  594. 				powers_sub_exit_to_main() 
  595. 			end 
  596. 		end 
  597. 	end 
  598. end 
  599.  
  600.  
  601. -- Finalize or cancel a purchase based on the result of the confirmation question. 
  602. function powers_sub_purchase_final(event) 
  603. 	Store_popup:nav_enable(false, nil, nil) 
  604. 	Not_popup_grp:set_alpha(1) 
  605. 	Active_list:set_visible(true) 
  606.  
  607. 	powers_sub_enable_mouse(true) 
  608. 	 
  609. 	-- The user hit the B button and are cancelling the purchase 
  610. 	-- This is redundant to selecting "No" in the list 
  611. 	if event == "back" then 
  612. 		ui_audio_post_event("UI_Hub_Menu_Back") 
  613. 		if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then 
  614. 			return 
  615. 		end 
  616. 	end 
  617. 	 
  618. 	-- Did we select yes?  This assumes yes is the first item 
  619. 	if Store_popup:get_selected_data() ~= 1 then 
  620. 		ui_audio_post_event("UI_Hub_Menu_Back") 
  621. 		return 
  622. 	end 
  623. 	 
  624. 	ui_audio_post_event("UI_Hub_Menu_Forward") 
  625. 	 
  626. 	-- give reward and take money here 
  627. 	local current_index = Active_list:get_selection() 
  628.  
  629. 	if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then 
  630. 		local unlockable_id = Powers_sub_menu_data[current_index].unlockable_id or Powers_sub_menu_data[current_index].id 
  631. 		vint_dataresponder_post("cell_rewards_reward_dr", "Purchase", unlockable_id) 
  632. 	elseif Powers_screen_state == POWERS_SCREEN_STATE_ELEMENT then 
  633. 		vint_scriptevent_post( "ui_powers_main", "set_element", Powers_sub_menu_data[current_index].id ) 
  634. 		vint_set_property(Element_icon_h, "image", POWERS_ELEMENTS_ENUMS[Powers_sub_menu_data[current_index].id].bitmap) 
  635. 	end 
  636. 	 
  637. 	 
  638.  
  639. 	-- do this so holding down the button doesn't cause repeated actions 
  640. 	Input_tracker:subscribe(false) 
  641. 	if game_get_platform() == "PC" then 
  642. 		Mouse_input_tracker:subscribe(false) 
  643. 		Hint_bar_mouse_input_tracker:subscribe(false) 
  644. 	end 
  645. 	 
  646. 	-- Save off index before we refresh the list 
  647. 	Powers_sub_menu_data.start_index = current_index 
  648. 	 
  649. end 
  650.  
  651.  
  652. function powers_sub_fail_msg(event) 
  653. 	Store_popup:nav_enable(false, nil, nil) 
  654. 	Not_popup_grp:set_alpha(1) 
  655. 	Active_list:set_visible(true) 
  656. 	powers_sub_enable_mouse(true) 
  657. end 
  658.  
  659. function powers_sub_gained_focus() 
  660. 	debug_print("vint", "powers_sub.lua :::: powers_sub_gained_focus :::: FOCUS GAINED START\n") 
  661. 	local index = Active_list:get_selection() 
  662. 	Menu_data = {} 
  663. 	Powers_sub_menu_data = Menu_data 
  664. 	if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then 
  665. 		vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_upgrades", 0, "get_avail_upgrades", Powers_cur_id) 
  666. 	else 
  667. 		vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_elements", 0, "get_elements", Powers_cur_id) 
  668. 	end 
  669. 	 
  670. 	-- May need to update image and description if list was shifted 
  671. 	powers_sub_item_nav(Powers_sub_menu_data[index])	 
  672. 	 
  673. 	powers_sub_populate_list(Menu_data, index) 
  674. 	 
  675. 	Input_tracker:subscribe(true)	 
  676. 	store_common_safe_frame_show() 
  677. 	if game_get_platform() == "PC" then 
  678. 		Mouse_input_tracker:subscribe(true) 
  679. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  680. 	end 
  681. 	 
  682. 	debug_print("vint", "powers_sub.lua :::: powers_sub_gained_focus :::: FOCUS GAINED END\n") 
  683. end 
  684.  
  685. function powers_sub_popup_nav(event, value) 
  686. 	if event == "nav_up" then	 
  687. 		Store_popup.list:move_cursor(-1)	 
  688. 	elseif event == "nav_down" then 
  689. 		Store_popup.list:move_cursor(1) 
  690. 	elseif event == "mouse_move" then 
  691. 		-- value contains the target_handle in this case 
  692. 		local new_index = Store_popup.list:get_button_index(value) 
  693. 		if new_index ~= 0 then 
  694. 			Store_popup.list:set_selection(new_index) 
  695. 			Store_popup.list:move_cursor(0, true) 
  696. 		end 
  697. 	else 
  698. 		--do nothing 
  699. 	end	 
  700. end 
  701.  
  702.  
  703. ----------------- 
  704. --Input Functions 
  705. ----------------- 
  706. function powers_sub_unlock_controls() 
  707. 	Input_tracker:subscribe(true) 
  708. 	powers_sub_enable_mouse(true) 
  709. end 
  710.  
  711. function powers_sub_lock_controls() 
  712. 	Input_tracker:subscribe(false) 
  713. 	powers_sub_enable_mouse(false) 
  714. end 
  715.  
  716. function powers_sub_input_map() 
  717. 	local anim_out_h = vint_object_find("powers_anim_out", 0, Store_common_doc_handle) 
  718. 	local powers_exit_anim_h = vint_object_find("powers_exit_anim", 0, Powers_sub_doc_h) 
  719. 	lua_play_anim(anim_out_h) 
  720. 	lua_play_anim(powers_exit_anim_h) 
  721. 	cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_POWERS, powers_sub_exit_to_game) 
  722. end 
  723.  
  724. function powers_scroll_list(event) 
  725. 	 
  726. 	--What direction did we move? 
  727. 	local direction = 0 
  728. 	if event == "alt_joy_up" then 
  729. 		direction = -1 
  730. 	elseif event == "alt_joy_down" then 
  731. 		direction = 1 
  732. 	end 
  733.  
  734. 	--scroll lines are inverted for some reason 
  735. 	local scroll_lines = direction 
  736.  
  737. 	if scroll_lines ~= 0 then 
  738. 		Active_list:scroll_list(scroll_lines)	 
  739. 		 
  740. 		if game_get_platform() == "PC" then 
  741. 			Active_list:update_mouse_inputs("store_common", Mouse_input_tracker, 50) 
  742. 		end 
  743. 	end	 
  744. end 
  745.  
  746. ---------------- 
  747. --Exit Functions 
  748. ---------------- 
  749. function powers_sub_exit_to_main(event) 
  750.  
  751. 	-- exit the interface 
  752. 	powers_sub_lock_controls() 
  753. 	ui_audio_post_event("UI_Hub_Menu_Back") 
  754. 	-- Animate reward screen out 
  755. 	local anim_out_h = vint_object_find("powers_anim_out", 0, Store_common_doc_handle) 
  756. 	lua_play_anim(anim_out_h) 
  757. 	 
  758. 	 
  759. 	local twn_h = vint_object_find("end_event_twn", Powers_out_anim_h) 
  760. 	vint_set_property(twn_h, "end_event", "powers_sub_exit_complete") 
  761. 	lua_play_anim(Powers_out_anim_h) 
  762. end 
  763.  
  764. function powers_sub_exit_complete() 
  765. 	powers_main_return_from_sub() 
  766. 	pop_screen()		 
  767. end 
  768.  
  769. function powers_sub_exit_to_game(event) 
  770. 	ui_audio_post_event("UI_Hub_Menu_Back") 
  771. 	pop_screen() 
  772. 	pop_screen() 
  773. 	pop_screen() 
  774. 	pop_screen() 
  775. end 
  776.  
  777. -- ===================================== 
  778. --       Mouse Specific Functions 
  779. -- ===================================== 
  780. function powers_sub_enable_mouse(enable) 
  781. 	if game_get_platform() == "PC" and enable ~= nil then 
  782. 		if Mouse_input_tracker ~= 0 then 
  783. 			Mouse_input_tracker:subscribe(enable) 
  784. 		end 
  785. 		 
  786. 		if Hint_bar_mouse_input_tracker ~= nil then 
  787. 			Hint_bar_mouse_input_tracker:subscribe(enable) 
  788. 		end 
  789. 	end 
  790. end 
  791.  
  792.  
  793. -- Mouse inputs 
  794. function powers_sub_mouse_click(event, target_handle, mouse_x, mouse_y) 
  795. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  796. 	if hint_index == 1 then 
  797. 		store_common_button_b() 
  798. 	end 
  799.  
  800. 	local new_index = Active_list:get_button_index(target_handle) 
  801. 	 
  802. 	--this apparently never gets used 
  803. 	if new_index ~= 0 then 
  804. 		Active_list:set_selection(new_index) 
  805. 		--cell_rewards_button_a() 
  806. 	end 
  807. end 
  808.  
  809. function powers_sub_mouse_move(event, target_handle) 
  810. 	Hint_bar:set_highlight(0) 
  811. 	 
  812. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  813. 	if hint_index ~= 0 then 
  814. 		Hint_bar:set_highlight(hint_index) 
  815. 	end 
  816. 	 
  817. 	local old_index = Active_list:get_selection() 
  818. 	local new_index = Active_list:get_button_index(target_handle) 
  819. 	if new_index ~= 0 and new_index ~= old_index then 
  820. 		Active_list:set_selection(new_index) 
  821. 		Active_list:move_cursor(0, true) 
  822. 		 
  823. 		-- If the item has a callback for navigation, do it 
  824. 		local data_item = Active_list:return_selected_data() 
  825. 		if data_item.on_nav ~= nil then 
  826. 			data_item.on_nav(data_item) 
  827. 		end 
  828. 	end 
  829. end 
  830.  
  831.