Advertisement
Guest User

Untitled

a guest
May 15th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.85 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[2] = vgui.Create("DLabel", self)
  25. self.cols[2]:SetText(GetTranslation("sb_deaths"))
  26.  
  27. self.cols[3] = vgui.Create("DLabel", self)
  28. self.cols[3]:SetText(GetTranslation("sb_score"))
  29.  
  30. self.cols[5] = vgui.Create("DLabel", self)
  31. self.cols[5]:SetText("Rank")
  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. ----EDIT THESE TO ADD MORE COLOURS----
  64. ----Example: test = COLOR_BLUE----
  65. ---Make sure to put a comma after each line until the end (Last one doesn't have one---
  66.  
  67. local namecolor = {
  68. default = COLOR_WHITE,
  69. dev = Color(100, 240, 105, 255),
  70. Owner = Color(0, 0, 204, 255),
  71. CoOwner = Color(255, 128, 0, 255),
  72. SuperAdmin = Color(0, 0, 0, 255),
  73. HeadAdmin = Color(102, 0, 0, 255),
  74. Admin = Color(255, 0, 0, 255),
  75. TrialAdmin = Color(255, 0, 0, 255),
  76. DonatorAdmin = Color(153, 0, 153, 255),
  77. Mod = Color(0, 255, 255, 255),
  78. TrialMod = Color(0, 255, 255, 255),
  79. Operator = Color(128, 128, 0, 255),
  80. G-VIP = Color(255, 215, 0, 255),
  81. S-VIP = Color(192, 192, 192, 255),
  82. B-VIP = Color(166, 125, 51, 255),
  83. VIP = Color(255, 215, 0, 255),
  84. Donator = Color(0, 255, 0, 255),
  85. Addicted = Color(255, 153, 255, 255),
  86. Regular = Color(255, 0, 255, 255),
  87. default = Color(100, 240, 105, 255),
  88. };
  89.  
  90. function GM:TTTScoreboardColorForPlayer(ply)
  91. if not IsValid(ply) then return namecolor.default end
  92.  
  93. --ADD NAMECOLOURS HERE--
  94. if ply:SteamID() == "STEAM_0:0:1963640" then
  95. return namecolor.dev
  96. elseif ply:IsUserGroup("owner") then
  97. return namecolor.Owner
  98. elseif ply:IsUserGroup("co-owner") then
  99. return namecolor.CoOwner
  100. elseif ply:IsUserGroup("superadmin") then
  101. return namecolor.SuperAdmin
  102. elseif ply:IsUserGroup("head admin") then
  103. return namecolor.HeadAdmin
  104. elseif ply:IsUserGroup("admin") then
  105. return namecolor.Admin
  106. elseif ply:IsUserGroup("trial-admin") then
  107. return namecolor.TrialAdmin
  108. elseif ply:IsUserGroup("donator admin") then
  109. return namecolor.DonatorAdmin
  110. elseif ply:IsUserGroup("moderator") then
  111. return namecolor.Mod
  112. elseif ply:IsUserGroup("trial-moderator") then
  113. return namecolor.TrialMod
  114. elseif ply:IsUserGroup("operator") then
  115. return namecolor.Operator
  116. elseif ply:IsUserGroup("g-vip") then
  117. return namecolor.G-VIP
  118. elseif ply:IsUserGroup("s-vip") then
  119. return namecolor.S-VIP
  120. elseif ply:IsUserGroup("b-vip") then
  121. return namecolor.B-VIP
  122. elseif ply:IsUserGroup("vip") then
  123. return namecolor.VIP
  124. elseif ply:IsUserGroup("donator") then
  125. return namecolor.Donator
  126. --[[
  127. elseif ply:IsUserGroup("addicted") then
  128. return namecolor.Addicted
  129. elseif ply:IsUserGroup("regular") then
  130. return namecolor.Regular
  131. ]]
  132. end
  133. return namecolor.default
  134. end
  135.  
  136. local function ColorForPlayer(ply)
  137. if IsValid(ply) then
  138. local c = hook.Call("TTTScoreboardColorForPlayer", GAMEMODE, ply)
  139.  
  140. -- verify that we got a proper color
  141. if c and type(c) == "table" and c.r and c.b and c.g and c.a then
  142. return c
  143. else
  144. ErrorNoHalt("TTTScoreboardColorForPlayer hook returned something that isn't a color!\n")
  145. end
  146. end
  147. return namecolor.default
  148. end
  149.  
  150. function PANEL:Paint()
  151. if not IsValid(self.Player) then return end
  152.  
  153. -- if ( self.Player:GetFriendStatus() == "friend" ) then
  154. -- color = Color( 236, 181, 113, 255 )
  155. -- end
  156.  
  157. local ply = self.Player
  158.  
  159. if ply:IsTraitor() then
  160. surface.SetDrawColor(255, 0, 0, 30)
  161. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT)
  162. elseif ply:IsDetective() then
  163. surface.SetDrawColor(0, 0, 255, 30)
  164. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT)
  165. end
  166.  
  167.  
  168. if ply == LocalPlayer() then
  169. surface.SetDrawColor( 200, 200, 200, math.Clamp(math.sin(RealTime() * 2) * 50, 0, 100))
  170. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT )
  171. end
  172.  
  173. return true
  174. end
  175.  
  176. function PANEL:SetPlayer(ply)
  177. self.Player = ply
  178. self.avatar:SetPlayer(ply)
  179.  
  180. if not self.info then
  181. local g = ScoreGroup(ply)
  182. if g == GROUP_TERROR and ply != LocalPlayer() then
  183. self.info = vgui.Create("TTTScorePlayerInfoTags", self)
  184. self.info:SetPlayer(ply)
  185.  
  186. self:InvalidateLayout()
  187. elseif g == GROUP_FOUND or g == GROUP_NOTFOUND then
  188. self.info = vgui.Create("TTTScorePlayerInfoSearch", self)
  189. self.info:SetPlayer(ply)
  190. self:InvalidateLayout()
  191. end
  192. else
  193. self.info:SetPlayer(ply)
  194.  
  195. self:InvalidateLayout()
  196. end
  197.  
  198. self.voice.DoClick = function()
  199. if IsValid(ply) and ply != LocalPlayer() then
  200. ply:SetMuted(not ply:IsMuted())
  201. end
  202. end
  203.  
  204. self:UpdatePlayerData()
  205. end
  206.  
  207. function PANEL:GetPlayer() return self.Player end
  208.  
  209. function PANEL:UpdatePlayerData()
  210. if not IsValid(self.Player) then return end
  211.  
  212. local ply = self.Player
  213. self.cols[1]:SetText(ply:Ping())
  214. self.cols[2]:SetText(ply:Deaths())
  215. self.cols[3]:SetText(ply:Frags())
  216.  
  217. if self.cols[4] then
  218. self.cols[4]:SetText(math.Round(ply:GetBaseKarma()))
  219. end
  220.  
  221. self.nick:SetText(ply:Nick())
  222. self.nick:SizeToContents()
  223. self.nick:SetTextColor(ColorForPlayer(ply))
  224.  
  225. if ply:IsUserGroup("owner") then
  226. self.cols[5]:SetText("Owner")
  227. self.cols[5]:SetTextColor(namecolor.Owner)
  228. elseif ply:IsUserGroup("co-owner") then
  229. self.cols[5]:SetText("Co-Owner")
  230. self.cols[5]:SetTextColor(namecolor.CoOwner)
  231. elseif ply:IsUserGroup("superadmin") then
  232. self.cols[5]:SetText("Admin++")
  233. self.cols[5]:SetTextColor(namecolor.SuperAdmin)
  234. elseif ply:IsUserGroup("head admin") then
  235. self.cols[5]:SetText("Head Admin")
  236. self.cols[5]:SetTextColor(namecolor.HeadAdmin)
  237. elseif ply:IsUserGroup("admin") then
  238. self.cols[5]:SetText("Admin")
  239. self.cols[5]:SetTextColor(namecolor.Admin)
  240. elseif ply:IsUserGroup("trial-admin") then
  241. self.cols[5]:SetText("Trial-Admin")
  242. self.cols[5]:SetTextColor(namecolor.TrialAdmin)
  243. elseif ply:IsUserGroup("donator admin") then
  244. self.cols[5]:SetText("Donator Admin")
  245. self.cols[5]:SetTextColor(namecolor.DonatorAdmin)
  246. elseif ply:IsUserGroup("moderator") then
  247. self.cols[5]:SetText("Moderator")
  248. self.cols[5]:SetTextColor(namecolor.Mod)
  249. elseif ply:IsUserGroup("trial-moderator") then
  250. self.cols[5]:SetText("Trial-Moderator")
  251. self.cols[5]:SetTextColor(namecolor.TrialMod)
  252. elseif ply:IsUserGroup("operator") then
  253. self.cols[5]:SetText("OP")
  254. self.cols[5]:SetTextColor(namecolor.Operator)
  255. elseif ply:IsUserGroup("g-vip") then
  256. self.cols[5]:SetText("G-VIP")
  257. self.cols[5]:SetTextColor(namecolor.GVIP)
  258. elseif ply:IsUserGroup("s-vip") then
  259. self.cols[5]:SetText("S-VIP")
  260. self.cols[5]:SetTextColor(namecolor.SVIP)
  261. elseif ply:IsUserGroup("b-vip") then
  262. self.cols[5]:SetText("B-VIP")
  263. self.cols[5]:SetTextColor(namecolor.BVIP)
  264. elseif ply:IsUserGroup("vip") then
  265. self.cols[5]:SetText("VIP")
  266. self.cols[5]:SetTextColor(namecolor.VIP)
  267. elseif ply:IsUserGroup("donator") then
  268. self.cols[5]:SetText("Donator")
  269. self.cols[5]:SetTextColor(namecolor.Donator)
  270. elseif ply:IsUserGroup("addicted") then
  271. self.cols[5]:SetText("Addicted")
  272. self.cols[5]:SetTextColor(namecolor.Addicted)
  273. elseif ply:IsUserGroup("regular") then
  274. self.cols[5]:SetText("Regular")
  275. self.cols[5]:SetTextColor(namecolor.Regular)
  276. elseif ply:IsUserGroup("user") then
  277. self.cols[5]:SetText("Guest")
  278. self.cols[5]:SetTextColor(namecolor.Guest)
  279.  
  280. -- elseif ply:IsUserGroup("admin") th
  281. -- self.cols[5]:SetText("Admin")
  282. -- self.cols[5]:SetTextColor(Color(220, 180, 0, 255))
  283. -- Delete the -- and change the settings to your liking. DO NOT DELETE THE 'end'
  284. end
  285.  
  286. local ptag = ply.sb_tag
  287. if ScoreGroup(ply) != GROUP_TERROR then
  288. ptag = nil
  289. end
  290.  
  291. self.tag:SetText(ptag and GetTranslation(ptag.txt) or "")
  292. self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)
  293.  
  294. self.sresult:SetVisible(ply.search_result != nil)
  295.  
  296. -- more blue if a detective searched them
  297. if ply.search_result and (LocalPlayer():IsDetective() or (not ply.search_result.show)) then
  298. self.sresult:SetImageColor(Color(200, 200, 255))
  299. end
  300.  
  301. -- cols are likely to need re-centering
  302. self:LayoutColumns()
  303.  
  304. if self.info then
  305. self.info:UpdatePlayerData()
  306. end
  307.  
  308. if self.Player != LocalPlayer() then
  309. local muted = self.Player:IsMuted()
  310. self.voice:SetImage(muted and "icon16/sound_mute.png" or "icon16/sound.png")
  311. else
  312. self.voice:Hide()
  313. end
  314. end
  315.  
  316. function PANEL:ApplySchemeSettings()
  317. for k,v in pairs(self.cols) do
  318. v:SetFont("treb_small")
  319. v:SetTextColor(COLOR_WHITE)
  320. end
  321.  
  322. self.nick:SetFont("treb_small")
  323. self.nick:SetTextColor(ColorForPlayer(self.Player))
  324.  
  325. local ptag = self.Player and self.Player.sb_tag
  326. self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)
  327. self.tag:SetFont("treb_small")
  328.  
  329. self.sresult:SetImage("icon16/magnifier.png")
  330. self.sresult:SetImageColor(Color(170, 170, 170, 150))
  331. end
  332.  
  333. function PANEL:LayoutColumns()
  334. for k,v in ipairs(self.cols) do
  335. v:SizeToContents()
  336. v:SetPos(self:GetWide() - (50*k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
  337. end
  338.  
  339. self.tag:SizeToContents()
  340. self.tag:SetPos(self:GetWide() - (50 * 6) - self.tag:GetWide()/2, (SB_ROW_HEIGHT - self.tag:GetTall()) / 2)
  341.  
  342. self.sresult:SetPos(self:GetWide() - (50*6) - 8, (SB_ROW_HEIGHT - 16) / 2)
  343. end
  344.  
  345. function PANEL:PerformLayout()
  346. self.avatar:SetPos(0,0)
  347. self.avatar:SetSize(SB_ROW_HEIGHT,SB_ROW_HEIGHT)
  348.  
  349. if not self.open then
  350. self:SetSize(self:GetWide(), SB_ROW_HEIGHT)
  351.  
  352. if self.info then self.info:SetVisible(false) end
  353. elseif self.info then
  354. self:SetSize(self:GetWide(), 100 + SB_ROW_HEIGHT)
  355.  
  356. self.info:SetVisible(true)
  357. self.info:SetPos(5, SB_ROW_HEIGHT + 5)
  358. self.info:SetSize(self:GetWide(), 100)
  359. self.info:PerformLayout()
  360.  
  361. self:SetSize(self:GetWide(), SB_ROW_HEIGHT + self.info:GetTall())
  362. end
  363.  
  364. self.nick:SizeToContents()
  365.  
  366. self.nick:SetPos(SB_ROW_HEIGHT + 10, (SB_ROW_HEIGHT - self.nick:GetTall()) / 2)
  367.  
  368. self:LayoutColumns()
  369.  
  370. self.voice:SetVisible(not self.open)
  371. self.voice:SetSize(16, 16)
  372. self.voice:DockMargin(4, 4, 4, 4)
  373. self.voice:Dock(RIGHT)
  374. end
  375.  
  376. function PANEL:DoClick(x, y)
  377. self:SetOpen(not self.open)
  378. end
  379.  
  380. function PANEL:SetOpen(o)
  381. if self.open then
  382. surface.PlaySound("ui/buttonclickrelease.wav")
  383. else
  384. surface.PlaySound("ui/buttonclick.wav")
  385. end
  386.  
  387. self.open = o
  388.  
  389. self:PerformLayout()
  390. self:GetParent():PerformLayout()
  391. sboard_panel:PerformLayout()
  392. end
  393.  
  394. function PANEL:DoRightClick()
  395. end
  396.  
  397. vgui.Register( "TTTScorePlayerRow", PANEL, "Button" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement