Advertisement
Guest User

Untitled

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