sr2lua/mp_player_info_popup.lua

  1. -- Variable section 
  2. Mp_player_info_popup_data = { 
  3. 	handles = { 
  4. 					buttons = {}, 
  5. 					button_shine = {}, 
  6. 					button_fade_in = {}, 
  7. 					button_fade_out = {}, 
  8. 					}, 
  9. 	button_function = {}, 
  10. 	is_first_time = true, 
  11. 	current_button = 1, 
  12. 	num_buttons = 0, 
  13. 	is_leaving = false, 
  14. 	input_subscriptions = {}, 
  15. } 
  16.  
  17. -- Init and cleanup functions 
  18. function mp_player_info_popup_init() 
  19. 	 
  20. 	-- Set up animation handles 
  21. 	Mp_player_info_popup_data.handles.start_screen_anim_h = vint_object_find("start_screen_anim") 
  22. 	vint_set_property(Mp_player_info_popup_data.handles.start_screen_anim_h, "is_paused", true) 
  23. 	 
  24. 	Mp_player_info_popup_data.handles.end_screen_anim_h = vint_object_find("end_screen_anim") 
  25. 	vint_set_property(Mp_player_info_popup_data.handles.end_screen_anim_h, "is_paused", true) 
  26. 	local h = vint_object_find("background_fade_out", Mp_player_info_popup_data.handles.end_screen_anim_h) 
  27. 	vint_set_property(h, "end_event", "mp_player_info_popup_exit") 
  28. 	 
  29. 	Mp_player_info_popup_data.handles.highlight_shine_anim_h = vint_object_find("highlight_shine_anim") 
  30. 	vint_set_property(Mp_player_info_popup_data.handles.highlight_shine_anim_h, "is_paused", true) 
  31. 	 
  32. 	Mp_player_info_popup_data.handles.highlight_fade_in_h = vint_object_find("highlight_fade_in") 
  33. 	vint_set_property(Mp_player_info_popup_data.handles.highlight_fade_in_h, "is_paused", true) 
  34. 	 
  35. 	Mp_player_info_popup_data.handles.highlight_fade_out_h = vint_object_find("highlight_fade_out") 
  36. 	vint_set_property(Mp_player_info_popup_data.handles.highlight_fade_out_h, "is_paused", true) 
  37.  
  38. 	Mp_player_info_popup_data.is_first_time = true 
  39. 	 
  40. 	-- Set up the PS3 button 
  41. 	vint_set_property(vint_object_find("select_button"), "visible", false) 
  42. 	 
  43. 	--Subscribe to input 
  44. 	Mp_player_info_popup_data.input_subscriptions = {	 
  45. 		vint_subscribe_to_input_event(nil, "nav_up",				"mp_player_info_popup_input", 100), 
  46. 		vint_subscribe_to_input_event(nil, "nav_down",			"mp_player_info_popup_input", 100), 
  47. 		vint_subscribe_to_input_event(nil, "select",				"mp_player_info_popup_input", 100), 
  48. 		vint_subscribe_to_input_event(nil, "back",				"mp_player_info_popup_input", 100), 
  49. 		vint_subscribe_to_input_event(nil, "all_unassigned",  "mp_player_info_popup_input", 100), 
  50. 	} 
  51. 	 
  52. 	-- Start looking for data 
  53. 	vint_dataitem_add_subscription("mp_player_popup_data_item", "update", "mp_popup_update_data") 
  54. 	 
  55. 	--If we are in main menu hide button tips 
  56. 	if vint_document_find("main_menu") ~= 0 then 
  57. 		main_menu_btn_tips_show(false) 
  58. 	end 
  59. end 
  60.  
  61. function mp_popup_update_data(di_h, event) 
  62.  
  63. 	-- Get the game data 
  64. 	local voip, team, are_they_host, am_i_host, name, badge, earnings, kills, deaths, favorite, wins, losses, is_me, badge_description = vint_dataitem_get(di_h) 
  65. 	 
  66. 	-- Handles for voip 
  67. 	local voip_speaker_h = vint_object_find("speaker") -- , speaker) 
  68. 	local voip_speaker_on_h = vint_object_find("speaker_on") -- , speaker_on) 
  69. 	 
  70. 	-- Voip display can change while we look at this screen, so it accepts all updates 
  71. 	if voip == 0 then -- No voip 
  72. 		vint_set_property(voip_speaker_h, "visible", false) 
  73. 		vint_set_property(voip_speaker_on_h, "visible", false) 
  74. 		 
  75. 	elseif voip == 1 then -- Plugged in 
  76. 		vint_set_property(voip_speaker_h, "visible", true) 
  77. 		vint_set_property(voip_speaker_on_h, "visible", false) 
  78. 		 
  79. 	elseif voip == 2 then -- Talking 
  80. 		vint_set_property(voip_speaker_h, "visible", true) 
  81. 		vint_set_property(voip_speaker_on_h, "visible", true) 
  82. 	end 
  83. 		 
  84. 	local name_h = vint_object_find("name_text") 
  85. 	local badge_h = vint_object_find("badge") 
  86. 	local earnings_h = vint_object_find("earnings_value") 
  87. 	local kills_h = vint_object_find("kills_value") 
  88. 	local deaths_h = vint_object_find("deaths_value") 
  89. 	local favorite_h = vint_object_find("favorite_value") 
  90. 	local record_h = vint_object_find("record_value") 
  91.  
  92. 	-- Team Colors Display (handle host color) 
  93. 	if are_they_host == true then 
  94. 		-- Set text to yellow 
  95. 		vint_set_property(name_h, "tint", 241/255, 227/255, 1/255) 
  96. 	else 
  97. 		if team == 0 then 
  98. 			-- Set text to blue 
  99. 			vint_set_property(name_h, "tint", 0, 128/255, 255/255) 
  100. 		elseif team == 1 then 
  101. 			-- Set text to red 
  102. 			vint_set_property(name_h, "tint", 204/255, 0, 0) 
  103. 		end 
  104. 	end 
  105. 	 
  106. 	-- Text strings 
  107. 	vint_set_property(name_h, "text_tag", name) 
  108. 	vint_set_property(earnings_h, "text_tag", earnings) 
  109. 	vint_set_property(kills_h, "text_tag", kills) 
  110. 	vint_set_property(deaths_h, "text_tag", deaths) 
  111. 	 
  112. 	 
  113. 	if favorite == 11 then 
  114. 		vint_set_property(favorite_h, "text_tag", "MULTI_MODE_13") 
  115. 	elseif favorite == 12 then 
  116. 		vint_set_property(favorite_h, "text_tag", "MULTI_MODE_14") 
  117. 	elseif favorite == 13 then 
  118. 		vint_set_property(favorite_h, "text_tag", "MULTI_MODE_STRONGARM") 
  119. 	else 
  120. 		vint_set_property(favorite_h, "text_tag", "") 
  121. 	end 
  122. 	 
  123. 	vint_set_property(record_h, "text_tag", wins .. "/" .. losses) 
  124.  
  125. 	-- Everything else is only set up and displayed the first time the data is updated 
  126. 	if Mp_player_info_popup_data.is_first_time ~= false then 
  127. 		 
  128. 		-- Clear first time flag 
  129. 		Mp_player_info_popup_data.is_first_time = false 
  130. 		 
  131. 		-- Play sound effect 
  132. 		audio_play(DIALOG_SERIOUS_SOUND) 
  133. 		 
  134. 		-- Set badge here 
  135. 		vint_set_property(vint_object_find("badge"), "image", badge) 
  136. 		vint_set_property(vint_object_find("nickname_text"), "text_tag", badge_description) 
  137. 		 
  138. 		if is_me == false then 
  139. 			-- Add the extra splitter 
  140. 			vint_set_property(vint_object_find("splitter3"), "visible", true) 
  141. 		 
  142. 			-- Make main buttons 
  143. 			--mp_player_info_popup_add_button("MULTI_MENU_ADD_FRIEND",mp_player_info_popup_add_friend) 
  144. 			 
  145. 			-- Add 360 buttons 
  146. 			if get_platform() == "XBOX360" then 
  147. 				mp_player_info_popup_add_button("MULTI_MENU_SHOW_GAMERCARD",mp_player_info_popup_show_gamercard) 
  148. 				mp_player_info_popup_add_button("CONTROL_SUBMIT_PLAYER_REVIEW",mp_player_info_popup_submit_review) 
  149. 			end 
  150. 			 
  151. 			-- Add the kick button 
  152. 			if am_i_host == true and are_they_host == false and mp_popup_is_matchmaking() == false then 
  153. 				mp_player_info_popup_add_button("MULTI_MENU_REMOVE_PLAYER",mp_player_info_popup_kick_player) 
  154. 			end 
  155. 		end 
  156. 		 
  157. 		-- Set initial cursor position 
  158. 		mp_player_info_popup_move_cursor(0) 
  159. 		 
  160. 		-- Animate screen in 
  161. 		lua_play_anim(Mp_player_info_popup_data.handles.start_screen_anim_h, 0) 
  162. 	end 
  163. end 
  164.  
  165. function mp_player_info_popup_add_button(text, button_function) 
  166.  
  167. 	-- Get placement stuff 
  168. 	local button_spacing = 32 
  169. 	local x, y = vint_get_property(vint_object_find("button"), "anchor") 
  170. 	x = x - 16 
  171.  
  172. 	-- Increment number of buttons 
  173. 	Mp_player_info_popup_data.num_buttons = Mp_player_info_popup_data.num_buttons + 1 
  174. 	 
  175. 	-- Create a new button clone 
  176. 	Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons] = vint_object_clone(vint_object_find("button")) 
  177. 	 
  178. 	-- Add function for the button 
  179. 	Mp_player_info_popup_data.button_function[Mp_player_info_popup_data.num_buttons] = button_function 
  180. 	 
  181. 	-- Assign animations 
  182. 	Mp_player_info_popup_data.handles.button_shine[Mp_player_info_popup_data.num_buttons] = vint_object_clone(Mp_player_info_popup_data.handles.highlight_shine_anim_h) 
  183. 	vint_set_property(Mp_player_info_popup_data.handles.button_shine[Mp_player_info_popup_data.num_buttons], "is_paused", true) 
  184. 	vint_set_property(vint_object_find("highlight_shine_fade",Mp_player_info_popup_data.handles.button_shine[Mp_player_info_popup_data.num_buttons]),"target_handle", 
  185. 							vint_object_find("highlight_back_shine",Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons])) 
  186. 	 
  187. 	Mp_player_info_popup_data.handles.button_fade_in[Mp_player_info_popup_data.num_buttons] = vint_object_clone(Mp_player_info_popup_data.handles.highlight_fade_in_h) 
  188. 	vint_set_property(Mp_player_info_popup_data.handles.button_fade_in[Mp_player_info_popup_data.num_buttons], "is_paused", true) 
  189. 	vint_set_property(vint_object_find("highlight_alpha_in",Mp_player_info_popup_data.handles.button_fade_in[Mp_player_info_popup_data.num_buttons]),"target_handle", 
  190. 							vint_object_find("highlight",Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons])) 
  191. 	 
  192. 	Mp_player_info_popup_data.handles.button_fade_out[Mp_player_info_popup_data.num_buttons] = vint_object_clone(Mp_player_info_popup_data.handles.highlight_fade_out_h) 
  193. 	vint_set_property(Mp_player_info_popup_data.handles.button_fade_out[Mp_player_info_popup_data.num_buttons], "is_paused", true) 
  194. 	vint_set_property(vint_object_find("highlight_alpha_out",Mp_player_info_popup_data.handles.button_fade_out[Mp_player_info_popup_data.num_buttons]),"target_handle", 
  195. 							vint_object_find("highlight",Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons])) 
  196.  
  197. 	-- Set text labels 
  198. 	vint_set_property(vint_object_find("normal_label", Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons]), "text_tag", text) 
  199. 	vint_set_property(vint_object_find("highlight_label", Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons]), "text_tag", text) 
  200. 	 
  201. 	-- Position and draw new button 
  202. 	vint_set_property(Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons], "anchor", x, y + button_spacing * (Mp_player_info_popup_data.num_buttons - 1)) 
  203. 	vint_set_property(Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons], "visible", true) 
  204. 	 
  205. 	-- Adjust window size to hold new button 
  206. 	local window_h = vint_object_find("window") 
  207. 	local window_clip_h = vint_object_find("window_clip") 
  208. 	local btm_line_h = vint_object_find("btm_line") 
  209. 	 
  210. 	x, y = vint_get_property(window_h, "anchor") 
  211. 	y = y - 13 
  212. 	vint_set_property(window_h, "anchor", x, y) 
  213. 	 
  214. 	x, y = vint_get_property(window_clip_h, "clip_size") 
  215. 	y = y + 32.5 
  216. 	vint_set_property(window_clip_h, "clip_size", x, y) 
  217. 	 
  218. 	x, y = vint_get_property(btm_line_h, "anchor") 
  219. 	y = y + 32.5 
  220. 	vint_set_property(btm_line_h, "anchor", x, y) 
  221. end 
  222.  
  223. function mp_player_info_popup_remove_button() 
  224. 	 
  225. 	-- Make sure we have buttons to remove 
  226. 	if Mp_player_info_popup_data.num_buttons > 0 then 
  227. 	 
  228. 		-- Destroy the last button 
  229. 		vint_object_destroy(Mp_player_info_popup_data.handles.button_shine[Mp_player_info_popup_data.num_buttons]) 
  230. 		vint_object_destroy(Mp_player_info_popup_data.handles.button_fade_in[Mp_player_info_popup_data.num_buttons]) 
  231. 		vint_object_destroy(Mp_player_info_popup_data.handles.button_fade_out[Mp_player_info_popup_data.num_buttons]) 
  232. 		vint_object_destroy(Mp_player_info_popup_data.handles.buttons[Mp_player_info_popup_data.num_buttons]) 
  233. 	 
  234. 		-- Decrement number of buttons 
  235. 		Mp_player_info_popup_data.num_buttons = Mp_player_info_popup_data.num_buttons - 1 
  236. 		 
  237. 		-- Move the cursor back to the top 
  238. 		Mp_player_info_popup_data.current_button = 1 
  239. 		 
  240. 		-- Redraw the cursor 
  241. 		mp_player_info_popup_move_cursor(0) 
  242. 	end 
  243. end 
  244.  
  245. function mp_player_info_popup_input(target, event, accelleration) 
  246. 	if Mp_player_info_popup_data.is_first_time == true then 
  247. 		return 
  248. 	end 
  249. 	 
  250. 	if Mp_player_info_popup_data.is_leaving == true then 
  251. 		return 
  252. 	end 
  253. 	 
  254. 	if event == "nav_up" then 
  255. 		-- Up button pressed 
  256. 		if Mp_player_info_popup_data.num_buttons > 1 then 
  257. 			audio_play(Menu_sound_item_nav) 
  258. 		end 
  259. 		mp_player_info_popup_move_cursor(-1) 
  260. 		 
  261. 	elseif event == "nav_down" then 
  262. 		-- Down button presses 
  263. 		if Mp_player_info_popup_data.num_buttons > 1 then 
  264. 			audio_play(Menu_sound_item_nav) 
  265. 		end 
  266. 		mp_player_info_popup_move_cursor(1) 
  267. 		 
  268. 	elseif event == "select" then 
  269. 		-- Do stuff based on the current button 
  270. 		if Mp_player_info_popup_data.button_function[Mp_player_info_popup_data.current_button] ~= nil then 
  271. 			audio_play(Menu_sound_select) 
  272. 			Mp_player_info_popup_data.button_function[Mp_player_info_popup_data.current_button]() 
  273. 		end 
  274. 		 
  275. 	elseif event == "back" then 
  276. 		-- Animate out 
  277. 		Mp_player_info_popup_data.is_leaving = true 
  278. 		audio_play(Menu_sound_back) 
  279. 		lua_play_anim(Mp_player_info_popup_data.handles.end_screen_anim_h, 0) 
  280. 	end 
  281. end 
  282.  
  283. function mp_player_info_popup_add_friend() 
  284. 	-- Add player to friends 
  285. 	mp_popup_add_friend() 
  286. end 
  287.  
  288. function mp_player_info_popup_show_gamercard() 
  289. 	-- Show player's gamer card 
  290. 	mp_popup_show_gamercard() 
  291. end 
  292.  
  293. function mp_player_info_popup_submit_review() 
  294. 	-- Submit player review 
  295. 	mp_popup_submit_player_review() 
  296. end 
  297.  
  298. function mp_player_info_popup_kick_player() 
  299. 	-- Kick player 
  300. 	mp_popup_kick_player() 
  301. 	mp_player_info_popup_remove_button() 
  302. end 
  303.  
  304. function mp_player_info_popup_move_cursor(dir) 
  305.  
  306. 	if dir ~= 0 then 
  307. 		-- Hide the old button 
  308. 		vint_set_property(Mp_player_info_popup_data.handles.button_shine[Mp_player_info_popup_data.current_button], "is_paused", true) 
  309. 		lua_play_anim(Mp_player_info_popup_data.handles.button_fade_out[Mp_player_info_popup_data.current_button], 0) 
  310. 	 
  311. 		-- Do the math to figure out where the button is next 
  312. 		if dir == 1 then -- Move down 1 
  313. 			if Mp_player_info_popup_data.current_button < Mp_player_info_popup_data.num_buttons then 
  314. 				Mp_player_info_popup_data.current_button = Mp_player_info_popup_data.current_button + 1 
  315. 			else 
  316. 				Mp_player_info_popup_data.current_button = 1 
  317. 			end 
  318. 		elseif dir == -1 then -- Move up 1 
  319. 			if Mp_player_info_popup_data.current_button > 1 then 
  320. 				Mp_player_info_popup_data.current_button = Mp_player_info_popup_data.current_button - 1 
  321. 			else 
  322. 				Mp_player_info_popup_data.current_button = Mp_player_info_popup_data.num_buttons 
  323. 			end 
  324. 		end 
  325. 	end 
  326. 	 
  327. 	-- Show the new button 
  328. 	lua_play_anim(Mp_player_info_popup_data.handles.button_shine[Mp_player_info_popup_data.current_button], 0) 
  329. 	lua_play_anim(Mp_player_info_popup_data.handles.button_fade_in[Mp_player_info_popup_data.current_button], 0) 
  330. end 
  331. 	 
  332. function mp_player_info_popup_exit() 
  333. 	vint_document_unload(vint_document_find("mp_player_info_popup"))	 
  334. end	 
  335. 	 
  336. function mp_player_info_popup_cleanup() 
  337.  
  338. 	-- Kill subscriptions 
  339. 	for idx, val in Mp_player_info_popup_data.input_subscriptions do 
  340. 		vint_unsubscribe_to_input_event(val) 
  341. 	end 
  342. 	Mp_player_info_popup_data.input_subscriptions = nil 
  343. 	 
  344. 	 
  345. 	--If we are in main menu show button tips 
  346. 	if vint_document_find("main_menu") ~= 0 then 
  347. 		main_menu_btn_tips_show(true) 
  348. 	end 
  349. end 
  350.