Advertisement
Guest User

Untitled

a guest
Dec 18th, 2012
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.55 KB | None | 0 0
  1.  
  2. ---- Scoreboard player score row, based on sandbox version
  3.  
  4. include("sb_info.lua")
  5.  
  6.  
  7. local GetTranslation = LANG.GetTranslation
  8. local GetPTranslation = LANG.GetParamTranslation
  9.  
  10.  
  11. SB_ROW_HEIGHT = 24 --16
  12.  
  13. local PANEL = {}
  14.  
  15. function PANEL:Init()
  16. -- cannot create info card until player state is known
  17. self.info = nil
  18.  
  19. self.open = false
  20.  
  21. self.cols = {}
  22. self.cols[1] = vgui.Create("DLabel", self)
  23. self.cols[1]:SetText(GetTranslation("sb_ping"))
  24.  
  25. self.cols[5] = vgui.Create("DLabel", self)
  26. self.cols[5]:SetText("")
  27.  
  28. self.cols[2] = vgui.Create("DLabel", self)
  29. self.cols[2]:SetText(GetTranslation("sb_deaths"))
  30.  
  31. self.cols[3] = vgui.Create("DLabel", self)
  32. self.cols[3]:SetText(GetTranslation("sb_score"))
  33.  
  34. if KARMA.IsEnabled() then
  35. self.cols[4] = vgui.Create("DLabel", self)
  36. self.cols[4]:SetText(GetTranslation("sb_karma"))
  37. end
  38.  
  39. for _, c in ipairs(self.cols) do
  40. c:SetMouseInputEnabled(false)
  41. end
  42.  
  43. self.tag = vgui.Create("DLabel", self)
  44. self.tag:SetText("")
  45. self.tag:SetMouseInputEnabled(false)
  46.  
  47. self.sresult = vgui.Create("DImage", self)
  48. self.sresult:SetSize(16,16)
  49. self.sresult:SetMouseInputEnabled(false)
  50.  
  51. self.avatar = vgui.Create( "AvatarImage", self )
  52. self.avatar:SetSize(SB_ROW_HEIGHT, SB_ROW_HEIGHT)
  53. self.avatar:SetMouseInputEnabled(false)
  54.  
  55. self.nick = vgui.Create("DLabel", self)
  56. self.nick:SetMouseInputEnabled(false)
  57.  
  58. self.voice = vgui.Create("DImageButton", self)
  59. self.voice:SetSize(16,16)
  60.  
  61. self:SetCursor( "hand" )
  62. end
  63.  
  64.  
  65. local namecolor = {
  66. default = COLOR_WHITE,
  67. admin = Color(220, 180, 0, 255),
  68. dev = Color(100, 240, 105, 255)
  69. };
  70.  
  71. function GM:TTTScoreboardColorForPlayer(ply)
  72. if not IsValid(ply) then return namecolor.default end
  73.  
  74. if ply:SteamID() == "STEAM_0:0:1963640" then
  75. return namecolor.dev
  76. elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
  77. return namecolor.admin
  78. end
  79. return namecolor.default
  80. end
  81.  
  82. local function ColorForPlayer(ply)
  83. if IsValid(ply) then
  84. local c = hook.Call("TTTScoreboardColorForPlayer", GAMEMODE, ply)
  85.  
  86. -- verify that we got a proper color
  87. if c and type(c) == "table" and c.r and c.b and c.g and c.a then
  88. return c
  89. else
  90. ErrorNoHalt("TTTScoreboardColorForPlayer hook returned something that isn't a color!\n")
  91. end
  92. end
  93. return namecolor.default
  94. end
  95.  
  96. function PANEL:Paint()
  97. if not IsValid(self.Player) then return end
  98.  
  99. -- if ( self.Player:GetFriendStatus() == "friend" ) then
  100. -- color = Color( 236, 181, 113, 255 )
  101. -- end
  102.  
  103. local ply = self.Player
  104.  
  105. if ply:IsTraitor() then
  106. surface.SetDrawColor(255, 0, 0, 30)
  107. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT)
  108. elseif ply:IsDetective() then
  109. surface.SetDrawColor(0, 0, 255, 30)
  110. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT)
  111. end
  112.  
  113.  
  114. if ply == LocalPlayer() then
  115. surface.SetDrawColor( 200, 200, 200, math.Clamp(math.sin(RealTime() * 2) * 50, 0, 100))
  116. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT )
  117. end
  118.  
  119. return true
  120. end
  121.  
  122. function PANEL:SetPlayer(ply)
  123. self.Player = ply
  124. self.avatar:SetPlayer(ply)
  125.  
  126. if not self.info then
  127. local g = ScoreGroup(ply)
  128. if g == GROUP_TERROR and ply != LocalPlayer() then
  129. self.info = vgui.Create("TTTScorePlayerInfoTags", self)
  130. self.info:SetPlayer(ply)
  131.  
  132. self:InvalidateLayout()
  133. elseif g == GROUP_FOUND or g == GROUP_NOTFOUND then
  134. self.info = vgui.Create("TTTScorePlayerInfoSearch", self)
  135. self.info:SetPlayer(ply)
  136. self:InvalidateLayout()
  137. end
  138. else
  139. self.info:SetPlayer(ply)
  140.  
  141. self:InvalidateLayout()
  142. end
  143.  
  144. self.voice.DoClick = function()
  145. if IsValid(ply) and ply != LocalPlayer() then
  146. ply:SetMuted(not ply:IsMuted())
  147. end
  148. end
  149.  
  150. self:UpdatePlayerData()
  151. end
  152.  
  153. function PANEL:GetPlayer() return self.Player end
  154.  
  155. function PANEL:UpdatePlayerData()
  156. if not IsValid(self.Player) then return end
  157.  
  158. local ply = self.Player
  159. self.cols[1]:SetText(ply:Ping())
  160. self.cols[2]:SetText(ply:Deaths())
  161. self.cols[3]:SetText(ply:Frags())
  162.  
  163. if ply:IsUserGroup("manager") then
  164. self.cols[5]:SetText("Manager")
  165. self.cols[5]:SetTextColor(Color(252,192,13,252))
  166. end
  167.  
  168. if ply:IsUserGroup("admin") then
  169. self.cols[5]:SetText("Admin")
  170. self.cols[5]:SetTextColor(Color(0,239,255,255))
  171. end
  172.  
  173. if ply:IsUserGroup("headadmin") then
  174. self.cols[5]:SetText("H.Admin")
  175. self.cols[5]:SetTextColor(Color(0,239,255,255))
  176. end
  177.  
  178. if ply:IsUserGroup("superadmin") then
  179. self.cols[5]:SetText("S.Admin")
  180. self.cols[5]:SetTextColor(Color(0,239,255,255))
  181. end
  182.  
  183. if ply:IsUserGroup("superadmind") then
  184. self.cols[5]:SetText("S.Admin")
  185. self.cols[5]:SetTextColor(Color(0,239,255,255))
  186. end
  187.  
  188. if ply:IsUserGroup("trialadmin") then
  189. self.cols[5]:SetText("T.Admin")
  190. self.cols[5]:SetTextColor(Color(0,239,255,255))
  191. end
  192.  
  193. if ply:IsUserGroup("trusted") then
  194. self.cols[5]:SetText("Trusted")
  195. self.cols[5]:SetTextColor(Color(0,255,0,255))
  196. end
  197.  
  198. if ply:IsUserGroup("donator") then
  199. self.cols[5]:SetText("Donator")
  200. self.cols[5]:SetTextColor(Color(172,41,229,172))
  201. end
  202.  
  203.  
  204. if self.cols[4] then
  205. self.cols[4]:SetText(math.Round(ply:GetBaseKarma()))
  206. end
  207.  
  208. self.nick:SetText(ply:Nick())
  209. self.nick:SizeToContents()
  210. self.nick:SetTextColor(ColorForPlayer(ply))
  211.  
  212. local ptag = ply.sb_tag
  213. if ScoreGroup(ply) != GROUP_TERROR then
  214. ptag = nil
  215. end
  216.  
  217. self.tag:SetText(ptag and GetTranslation(ptag.txt) or "")
  218. self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)
  219.  
  220. self.sresult:SetVisible(ply.search_result != nil)
  221.  
  222. -- more blue if a detective searched them
  223. if ply.search_result and (LocalPlayer():IsDetective() or (not ply.search_result.show)) then
  224. self.sresult:SetImageColor(Color(200, 200, 255))
  225. end
  226.  
  227. -- cols are likely to need re-centering
  228. self:LayoutColumns()
  229.  
  230. if self.info then
  231. self.info:UpdatePlayerData()
  232. end
  233.  
  234. if self.Player != LocalPlayer() then
  235. local muted = self.Player:IsMuted()
  236. self.voice:SetImage(muted and "icon16/sound_mute.png" or "icon16/sound.png")
  237. else
  238. self.voice:Hide()
  239. end
  240. end
  241.  
  242. function PANEL:ApplySchemeSettings()
  243. for k,v in pairs(self.cols) do
  244. v:SetFont("treb_small")
  245. v:SetTextColor(COLOR_WHITE)
  246. end
  247.  
  248. self.nick:SetFont("treb_small")
  249. self.nick:SetTextColor(ColorForPlayer(self.Player))
  250.  
  251. local ptag = self.Player and self.Player.sb_tag
  252. self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)
  253. self.tag:SetFont("treb_small")
  254.  
  255. self.sresult:SetImage("icon16/magnifier.png")
  256. self.sresult:SetImageColor(Color(170, 170, 170, 150))
  257. end
  258.  
  259. function PANEL:LayoutColumns()
  260. for k,v in ipairs(self.cols) do
  261. v:SizeToContents()
  262. v:SetPos(self:GetWide() - (50*k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
  263. end
  264.  
  265. self.tag:SizeToContents()
  266. self.tag:SetPos(self:GetWide() - (50 * 6) - self.tag:GetWide()/2, (SB_ROW_HEIGHT - self.tag:GetTall()) / 2)
  267.  
  268. self.sresult:SetPos(self:GetWide() - (50*6) - 8, (SB_ROW_HEIGHT - 16) / 2)
  269. end
  270.  
  271. function PANEL:PerformLayout()
  272. self.avatar:SetPos(0,0)
  273. self.avatar:SetSize(SB_ROW_HEIGHT,SB_ROW_HEIGHT)
  274.  
  275. if not self.open then
  276. self:SetSize(self:GetWide(), SB_ROW_HEIGHT)
  277.  
  278. if self.info then self.info:SetVisible(false) end
  279. elseif self.info then
  280. self:SetSize(self:GetWide(), 100 + SB_ROW_HEIGHT)
  281.  
  282. self.info:SetVisible(true)
  283. self.info:SetPos(5, SB_ROW_HEIGHT + 5)
  284. self.info:SetSize(self:GetWide(), 100)
  285. self.info:PerformLayout()
  286.  
  287. self:SetSize(self:GetWide(), SB_ROW_HEIGHT + self.info:GetTall())
  288. end
  289.  
  290. self.nick:SizeToContents()
  291.  
  292. self.nick:SetPos(SB_ROW_HEIGHT + 10, (SB_ROW_HEIGHT - self.nick:GetTall()) / 2)
  293.  
  294. self:LayoutColumns()
  295.  
  296. self.voice:SetVisible(not self.open)
  297. self.voice:SetSize(16, 16)
  298. self.voice:DockMargin(4, 4, 4, 4)
  299. self.voice:Dock(RIGHT)
  300. end
  301.  
  302. function PANEL:DoClick(x, y)
  303. self:SetOpen(not self.open)
  304. end
  305.  
  306. function PANEL:SetOpen(o)
  307. if self.open then
  308. surface.PlaySound("ui/buttonclickrelease.wav")
  309. else
  310. surface.PlaySound("ui/buttonclick.wav")
  311. end
  312.  
  313. self.open = o
  314.  
  315. self:PerformLayout()
  316. self:GetParent():PerformLayout()
  317. sboard_panel:PerformLayout()
  318. end
  319.  
  320. function PANEL:DoRightClick()
  321. end
  322.  
  323. vgui.Register( "TTTScorePlayerRow", PANEL, "Button" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement