Advertisement
Guest User

Untitled

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