sr2lua/mp_hud_lobby.lua

  1. -- Variable section 
  2. Mp_hud_lobby_data = { 
  3. 	player_data = {}, 
  4. } 
  5.  
  6. -- Init and cleanup functions 
  7. function mp_hud_lobby_init() 
  8.  
  9. 	-- Hide the HUD map 
  10. 	hud_hide_map() 
  11. 	 
  12. 	-- Set up some handles 
  13. 	Mp_hud_lobby_data.line_h = vint_object_clone(vint_object_find("hud_player_line")) 
  14. 	 
  15. 	-- Subscribe to updates 
  16. 	vint_datagroup_add_subscription("sr2_multi_lobby_player_data", "update", "mp_hud_lobby_data_update") 
  17. 	vint_datagroup_add_subscription("sr2_multi_lobby_player_data", "insert", "mp_hud_lobby_data_update") 
  18. 	vint_datagroup_add_subscription("sr2_multi_lobby_player_data", "remove", "mp_hud_lobby_data_update") 
  19. end 
  20.  
  21. function mp_hud_lobby_cleanup() 
  22. 	-- Unload Pegs 
  23.  
  24. end 
  25.  
  26. function mp_hud_lobby_data_update(di_h, event) 
  27. 	 
  28. 	local team, name, voip, host = vint_dataitem_get(di_h) 
  29. 	 
  30. 	if event == "insert" then -- Make a new line 
  31. 		-- Clone up a new line 
  32. 		local line_h = vint_object_clone(Mp_hud_lobby_data.line_h) 
  33. 		Mp_hud_lobby_data.player_data[di_h] = {team = team, voip = voip, line_h = line_h} 
  34. 		 
  35. 		-- Set name text 
  36. 		local name_text = vint_object_find("text", Mp_hud_lobby_data.player_data[di_h].line_h) 
  37. 		vint_set_property(name_text, "text_tag", name) 
  38. 		 
  39. 		-- Set team color 
  40. 		mp_hud_lobby_set_team(di_h, host) 
  41. 		 
  42. 		-- Set voip icon 
  43. 		mp_hud_lobby_set_voip(di_h) 
  44. 		 
  45. 		-- Rebuild the line list 
  46. 		mp_hud_lobby_arrange_lines() 
  47. 		 
  48. 	elseif event == "update" then -- Update an existing line 
  49. 		if Mp_hud_lobby_data.player_data[di_h] ~= nil then 
  50. 		 
  51. 			-- Hang on to old values 
  52. 			local team_old = Mp_hud_lobby_data.player_data[di_h].team 
  53. 			local voip_old = Mp_hud_lobby_data.player_data[di_h].voip 
  54. 		 
  55. 			-- Update the global variables 
  56. 			Mp_hud_lobby_data.player_data[di_h].team = team 
  57. 			Mp_hud_lobby_data.player_data[di_h].voip = voip 
  58. 		 
  59. 			if voip ~= voip_old then -- Update voip icon 
  60. 				mp_hud_lobby_set_voip(di_h) 
  61. 			end 
  62. 			 
  63. 			if team ~= team_old then -- Update team 
  64. 				if host == false then 
  65. 					-- Change color 
  66. 					mp_hud_lobby_set_team(di_h, host) 
  67. 				end 
  68. 				-- Rebuild the line list 
  69. 				mp_hud_lobby_arrange_lines() 
  70. 			end 
  71. 		end 
  72. 		 
  73. 	elseif event == "remove" then -- Remove existing line 
  74. 		if Mp_hud_lobby_data.player_data[di_h] ~= nil then 
  75. 			vint_object_destroy(Mp_hud_lobby_data.player_data[di_h].line_h) 
  76. 			Mp_hud_lobby_data.player_data[di_h] = nil 
  77. 			 
  78. 			-- Fix the rest of the lines 
  79. 			mp_hud_lobby_arrange_lines() 
  80. 		end 
  81. 	end 
  82. 	 
  83. end 
  84.  
  85. function mp_hud_lobby_set_team(idx, host) 
  86. 	if Mp_hud_lobby_data.player_data[idx] ~= nil then 
  87. 		if host == true then -- Host, set to yellow 
  88. 			vint_set_property(Mp_hud_lobby_data.player_data[idx].line_h, "tint", 0.9451, 0.8902, 0.004) 
  89. 		else 
  90. 			if Mp_hud_lobby_data.player_data[idx].team == 0 then -- Blue team 
  91. 				vint_set_property(Mp_hud_lobby_data.player_data[idx].line_h, "tint", 0.0, 0.5, 1.0) 
  92. 			elseif Mp_hud_lobby_data.player_data[idx].team == 1 then -- Red team 
  93. 				vint_set_property(Mp_hud_lobby_data.player_data[idx].line_h, "tint", 0.8, 0.0, 0.0) 
  94. 			end 
  95. 		end 
  96. 	end 
  97. end 
  98.  
  99. function mp_hud_lobby_set_voip(idx) 
  100. 	if Mp_hud_lobby_data.player_data[idx] ~= nil then 
  101. 		local voip_speaker = vint_object_find("voip_speaker", Mp_hud_lobby_data.player_data[idx].line_h) 
  102. 		local voip_speaker_on = vint_object_find("voip_speaker_on", Mp_hud_lobby_data.player_data[idx].line_h) 
  103. 		 
  104. 		if Mp_hud_lobby_data.player_data[idx].voip == 0 then -- No voip 
  105. 			vint_set_property(voip_speaker, "visible", false) 
  106. 			vint_set_property(voip_speaker_on, "visible", false) 
  107. 			 
  108. 		elseif Mp_hud_lobby_data.player_data[idx].voip == 1 then -- Plugged in 
  109. 			vint_set_property(voip_speaker, "visible", true) 
  110. 			vint_set_property(voip_speaker_on, "visible", false) 
  111. 			 
  112. 		elseif Mp_hud_lobby_data.player_data[idx].voip == 2 then -- Talking 
  113. 			vint_set_property(voip_speaker, "visible", true) 
  114. 			vint_set_property(voip_speaker_on, "visible", true) 
  115. 		end 
  116. 	end 
  117. end 
  118.  
  119. function mp_hud_lobby_arrange_lines() 
  120.  
  121. 	local line_width, line_height = vint_get_property(Mp_hud_lobby_data.line_h,"screen_size") 
  122. 	line_height = line_height * 0.82 
  123. 	 
  124. 	local current_line = 0 
  125. 	local x, y = vint_get_property(Mp_hud_lobby_data.line_h, "anchor") 
  126.  
  127. 	 -- Draw all blue team lines 
  128. 	for idx, val in Mp_hud_lobby_data.player_data do 
  129. 		if Mp_hud_lobby_data.player_data[idx].team == 0 then 
  130. 			 
  131. 			local new_y = y + (current_line * line_height) 
  132. 			vint_set_property(Mp_hud_lobby_data.player_data[idx].line_h, "anchor", x, new_y) 
  133. 			vint_set_property(Mp_hud_lobby_data.player_data[idx].line_h, "visible", true) 
  134. 			 
  135. 			current_line = current_line + 1 
  136. 		end 
  137. 	end 
  138.  
  139. 	 -- Draw all red team lines 
  140. 	for idx, val in Mp_hud_lobby_data.player_data do 
  141. 		if Mp_hud_lobby_data.player_data[idx].team == 1 then 
  142. 			 
  143. 			local new_y = y + (current_line * line_height) 
  144. 			vint_set_property(Mp_hud_lobby_data.player_data[idx].line_h, "anchor", x, new_y) 
  145. 			vint_set_property(Mp_hud_lobby_data.player_data[idx].line_h, "visible", true) 
  146. 			 
  147. 			current_line = current_line + 1 
  148. 		end 
  149. 	end 
  150. end