./main_sl_rewards_list.lua

  1. local ID_TYPE_REWARDS_INVALID = -1 
  2. local ID_TYPE_REWARDS_RECEIVED = 1 
  3. local ID_TYPE_REWARDS_UNLOCKED = 2 
  4. local ID_REWARDS_RECEIVED = 3 
  5. local ID_REWARDS_UNLOCKED = 4 
  6.  
  7. Rewards_list_doc_h = 0 
  8.  
  9. local Rewards_list = {} 
  10. Rewards_list.row_alignment = {ALIGN_LEFT, ALIGN_RIGHT} 
  11. Rewards_list.row_column_count = 2 
  12.  
  13. local Input_tracker	 
  14. local Mouse_input_tracker 
  15. local List_offset = 25 
  16. local SL_LIST_MAX_BUTTONS = 7 
  17.  
  18.  
  19. local Spinner_obj = 0 
  20.  
  21. local Screen_width 
  22. if vint_is_std_res() then 
  23. 	Screen_width = 750 
  24. else 
  25. 	Screen_width = 840 
  26. end 
  27.  
  28. function main_sl_rewards_list_init() 
  29. 	Rewards_list_doc_h = vint_document_find("main_sl_rewards_list") 
  30. 	 
  31. 	-- Subscribe to the button presses we need 
  32. 	Input_tracker = Vdo_input_tracker:new() 
  33. 	Input_tracker:add_input("select", 		"main_sl_rewards_list_button_a", 50) 
  34. 	Input_tracker:add_input("back", 			"main_sl_rewards_list_button_b", 50) 
  35. 	Input_tracker:add_input("nav_up", 		"main_sl_rewards_list_nav_up", 50) 
  36. 	Input_tracker:add_input("nav_down", 	"main_sl_rewards_list_nav_down", 50) 
  37. 	Input_tracker:subscribe(false) 
  38. 	 
  39. 	-- Jeff - column titles are slightly different for rewards unlocked / received. 
  40.  
  41. 	--Initialize Spinner 
  42. 	Spinner_obj = Vdo_spinner:new("spinner") 
  43. 	 
  44. 	local columns_grp_h = vint_object_find("columns_grp") 
  45. 	vint_set_property(columns_grp_h, "visible", false) 
  46. 	 
  47. 	--Initialize Header 
  48. 	Header_obj:show_me(false) 
  49.  
  50. 	local column_01_h = vint_object_find("column_01", 0, Rewards_list_doc_h) 
  51. 	local column_02_h = vint_object_find("column_02", 0, Rewards_list_doc_h) 
  52. 	if Silverlink_rewards_type == ID_TYPE_REWARDS_RECEIVED then 
  53. 		Header_mini_obj:set_text("SL_TITLE_REWARDS_RECEIVED") 
  54. 		vint_set_property(column_01_h, "text_tag", "SL_REWARD_REWARD") 
  55. 		vint_set_property(column_02_h, "text_tag", "SL_REWARD_UNLOCKED_FROM") 
  56. 	else 
  57. 		Header_mini_obj:set_text("SL_TITLE_REWARDS_UNLOCKED") 
  58. 		vint_set_property(column_01_h, "text_tag", "SL_REWARD_ACHIEVMENT") 
  59. 		vint_set_property(column_02_h, "text_tag", "SL_REWARD_UNLOCKED_IN") 
  60. 	end 
  61. 	Header_mini_obj:set_visible(true) 
  62. 	 
  63. 	--set up the list in twns 
  64. 	local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle) 
  65. 	local x, y = list_back_in:get_property("start_value") 
  66. 	local y_offset = y + List_offset 
  67. 	list_back_in:set_property("start_value", x, y_offset) 
  68. 	list_back_in:set_property("end_value", x, y_offset) 
  69. 	 
  70. 	local list_back_out = Vdo_tween_object:new("back_out_twn3", Screen_back_out_anim.handle) 
  71. 	list_back_out:set_property("start_value",  x, y_offset) 
  72. 	list_back_out:set_property("end_value",  x, y_offset) 
  73. 	 
  74. 	--set up the list out twns 
  75. 	local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle) 
  76. 	list_slide_out:set_property("start_value",  x, y_offset)	 
  77. 	list_slide_out:set_property("end_value",  x, y_offset) 
  78. 	 
  79. 	local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle) 
  80. 	list_slide_in:set_property("start_value",  x, y_offset) 
  81. 	list_slide_in:set_property("end_value",  x, y_offset) 
  82.  
  83. 	--Setup Button Hints 
  84. 	local hint_data = { 
  85. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  86. 	} 
  87. 	Menu_hint_bar:set_hints(hint_data)   
  88. 		 
  89. 	--Store some locals to the pause menu common for screen processing. 
  90. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  91. 	 
  92. 	bg_saints_show(true) 
  93. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim)	 
  94.  
  95. 	--Hide the list... 
  96. 	List:set_visible(false) 
  97. 	 
  98. 	local info_text_h = vint_object_find("info_text", 0, Rewards_list_doc_h) 
  99. 	vint_set_property(info_text_h, "visible", false) 
  100.  
  101. 	--TODO: Show spinner until silverlink_rweards_data_avail() is called from C++ 
  102. 	vint_dataresponder_request("silverlink_rewards_populate", "main_sl_rewards_list_unlocked_populate", 0, Silverlink_rewards_type) 
  103. 	 
  104. 	--Some stuff i'm not sure what it does yet (JMH- 4/30/2013) 
  105. 	if First_time then 
  106. 		Screen_in_anim:play(0) 
  107. 		bg_saints_slide_in(Screen_width) 
  108. 		First_time = false 
  109. 	end 
  110. 	 
  111. 	-- Add mouse inputs for the PC 
  112. 	if game_get_platform() == "PC" then 
  113. 		Menu_hint_bar:set_highlight(0) 
  114. 		 
  115. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  116. 		List:add_mouse_inputs("main_sl_rewards_list", Mouse_input_tracker) 
  117. 		Menu_hint_bar:add_mouse_inputs("main_sl_rewards_list", Mouse_input_tracker) 
  118. 		Mouse_input_tracker:subscribe(true) 
  119. 	end 
  120. 	 
  121. 	--fade screen in 
  122. 	local screen_in_anim_h = vint_object_find("screen_in") 
  123. 	lua_play_anim(screen_in_anim_h) 
  124. 	 
  125. 	--Disable event listener for button updates... 
  126. 	vdo_mega_list_enable_listener(false) 
  127. end 
  128.  
  129. function main_sl_rewards_list_cleanup() 
  130. 	-- Nuke all button subscriptions 
  131. 	Input_tracker:subscribe(false) 
  132. 	if Mouse_input_tracker ~= nil then 
  133. 		Mouse_input_tracker:subscribe(false) 
  134. 	end 
  135. 	List:enable_toggle_input(false) 
  136. 	 
  137. 	Header_obj:show_me(true) 
  138. 	Header_mini_obj:set_visible(false) 
  139. 	 
  140. 	local x, y = List:get_anchor() 
  141.  
  142. 	--set up the list in twns 
  143. 	local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle) 
  144. 	local x, y = list_back_in:get_property("start_value") 
  145. 	local y_offset = y - List_offset 
  146. 	list_back_in:set_property("start_value", x, y_offset) 
  147. 	list_back_in:set_property("end_value", x, y_offset) 
  148. 	 
  149. 	local list_back_out = Vdo_tween_object:new("back_out_twn3", Screen_back_out_anim.handle) 
  150. 	list_back_out:set_property("start_value",  x, y_offset) 
  151. 	list_back_out:set_property("end_value",  x, y_offset) 
  152. 	 
  153. 	--set up the list out twns 
  154. 	local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle) 
  155. 	list_slide_out:set_property("start_value",  x, y_offset)	 
  156. 	list_slide_out:set_property("end_value",  x, y_offset) 
  157. 	 
  158. 	local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle) 
  159. 	list_slide_in:set_property("start_value",  x, y_offset) 
  160. 	list_slide_in:set_property("end_value",  x, y_offset) 
  161. 	 
  162. 	--Restore event listening 
  163. 	vdo_mega_list_enable_listener(true) 
  164. end 
  165.  
  166. function main_sl_rewards_list_nav_up(event, acceleration) 
  167. 	-- Move highlight up 
  168. 	List:move_cursor(-1) 
  169. 	 
  170. 	--Make sure our button is gone... 
  171. 	List:highlight_set_button("") 
  172. end 
  173.  
  174. function main_sl_rewards_list_nav_down(event, acceleration) 
  175. 	-- Move highlight down 
  176. 	List:move_cursor(1) 
  177. 	 
  178. 	--Make sure our button is gone... 
  179. 	List:highlight_set_button("") 
  180. end 
  181.  
  182. function main_sl_rewards_list_button_a(event, acceleration) 
  183. 	--DOES NOTHING 
  184. end 
  185.  
  186.  
  187. function main_sl_rewards_list_button_b(event, acceleration) 
  188. 	List:button_b() 
  189.  
  190. 	Input_tracker:subscribe(false) 
  191. 	if Mouse_input_tracker ~= nil then 
  192. 		Mouse_input_tracker:subscribe(false) 
  193. 	end 
  194. 	 
  195. 	--fade screen out 
  196. 	local screen_out_anim_h = vint_object_find("screen_out", 0, Rewards_list_doc_h) 
  197. 	lua_play_anim(screen_out_anim_h, 0, Rewards_list_doc_h) 
  198. 	 
  199. 	-- final pop... 
  200. 	--Remove current menu from the stack 
  201. 	menu_common_stack_remove() 
  202. 	 
  203. 	--Pop Screen off the list 
  204. 	menu_common_transition_pop(1) 
  205. end 
  206.  
  207. function main_sl_rewards_list_mouse_click(event, target_handle) 
  208. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  209. 	if hint_index == 1 then 
  210. 		main_sl_rewards_list_button_b() 
  211. 	end 
  212.  
  213. 	 
  214. 	--[[ 
  215. 	local new_index = List:get_button_index(target_handle) 
  216. 	if new_index ~= 0 then 
  217. 		List:set_selection(new_index) 
  218. 		main_sl_rewards_list_button_a() 
  219. 		List:highlight_set_button("") 
  220. 	end 
  221. 	]] 
  222. end 
  223.  
  224. function main_sl_rewards_list_mouse_move(event, target_handle) 
  225. 	Menu_hint_bar:set_highlight(0) 
  226. 	 
  227. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  228. 	if hint_index ~= 0 then 
  229. 		Menu_hint_bar:set_highlight(hint_index) 
  230. 	end 
  231. 	 
  232. 	local new_index = List:get_button_index(target_handle) 
  233. 	if new_index ~= 0 then 
  234. 		List:set_selection(new_index) 
  235. 		List:move_cursor(0, true) 
  236. 		List:highlight_set_button("") 
  237. 	end 
  238. end 
  239.  
  240. ------------------------------------------------------------------------------- 
  241. -- Populate function for the rewards unlocked screen 
  242. -- @acheivment_name 	Name of Acheivment 
  243. -- @unlocked_in		Game that award is unlocked in... 
  244. -- 
  245. function main_sl_rewards_list_unlocked_populate(acheivment_name, unlocked_in) 
  246. 	local num_items = #Rewards_list + 1 
  247. 	Rewards_list[num_items] = { 
  248. 		type = TYPE_ROW, 
  249. 		--Info for displaying the Vdo_pause_row 
  250. 		label_1 = acheivment_name, 
  251. 		label_2 = unlocked_in 
  252. 	} 
  253. end 
  254.  
  255.  
  256. -- Calls form C 
  257.  
  258.  
  259. -- data_error - whether there was an error retrieving data 
  260. -- num_results - number of results (may be 0) to expect if no error 
  261. function silverlink_rewards_data_avail(success, num_results) 
  262.  
  263. 	local error_message_string = "" 
  264.  
  265. 	local info_text_h = vint_object_find("info_text", 0, Rewards_list_doc_h) 
  266. 	vint_set_property(info_text_h, "visible", false) 
  267. 	 
  268. 	if success == true then 
  269. 		--Empty rewards list and retreive data because the data are here... 
  270. 		Rewards_list = {} 
  271. 		 
  272. 		if num_results == 0 then 
  273. 			--No results...  
  274. 			if Silverlink_rewards_type == ID_TYPE_REWARDS_RECEIVED then 
  275. 				error_message_string = "SL_REWARDS_NONE_RECEIVED" 
  276. 			else 
  277. 				error_message_string = "SL_REWARDS_NONE_UNLOCKED" 
  278. 			end 
  279. 		else 
  280. 			 
  281. 			--Set row columns for list... 
  282. 			Rewards_list.row_alignment = {ALIGN_LEFT, ALIGN_RIGHT} 
  283. 			Rewards_list.row_column_count = 2 
  284. 			 
  285. 			--get data... 
  286. 			vint_dataresponder_request("silverlink_rewards_populate", "main_sl_rewards_list_unlocked_populate", 0, Silverlink_rewards_type + 2) 
  287. 		end 
  288. 	else 
  289. 		--problem retreiving data... 
  290. 		error_message_string = "SL_REWARDS_PROBLEM_RETREIVING_DATA" 
  291. 	end 
  292. 	 
  293. 	--Hide Spinner 
  294. 	Spinner_obj:set_visible(false) 
  295. 	 
  296. 	if error_message_string == "" then 
  297. 		--No errors... 
  298. 		--Refresh and show the list... 
  299. 		List:draw_items(Rewards_list, 1, Screen_width, SL_LIST_MAX_BUTTONS) 
  300. 		List:highlight_set_button("") 
  301. 		List:set_visible(true) 
  302. 		 
  303. 		if Mouse_input_tracker ~= nil then 
  304. 			Mouse_input_tracker:remove_all() 
  305. 			Menu_hint_bar:add_mouse_inputs("main_sl_rewards_list", Mouse_input_tracker) 
  306. 			List:add_mouse_inputs("main_sl_rewards_list", Mouse_input_tracker) 
  307. 			Mouse_input_tracker:subscribe(true) 
  308. 		end 
  309. 		 
  310. 		--Show Columns or not... 
  311. 		local columns_grp_h = vint_object_find("columns_grp") 
  312. 		vint_set_property(columns_grp_h, "visible", true) 
  313. 	else 
  314. 		--error show error message... 
  315. 		vint_set_property(info_text_h, "text_tag", error_message_string) 
  316. 		vint_set_property(info_text_h, "visible", true) 
  317. 		 
  318. 		--Hide the columns 
  319. 		local columns_grp_h = vint_object_find("columns_grp") 
  320. 		vint_set_property(columns_grp_h, "visible", false) 
  321. 		 
  322. 		 
  323. 		 
  324. 	end 
  325. end 
  326.