Advertisement
Guest User

sb_row.lua

a guest
Dec 23rd, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.00 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. admin = Color(220, 180, 0, 255),
  70. dev = Color(100, 240, 105, 255),
  71. test = COLOR_BLUE
  72. };
  73.  
  74. function GM:TTTScoreboardColorForPlayer(ply)
  75. if not IsValid(ply) then return namecolor.default end
  76.  
  77. --ADD NAMECOLOURS HERE--
  78. if ply:SteamID() == "STEAM_0:0:1963640" then
  79. return namecolor.dev
  80. elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
  81. return namecolor.admin
  82. elseif ply:IsUserGroup("superadmin") then
  83. return namecolor.test
  84. end
  85. return namecolor.default
  86. end
  87.  
  88. local function ColorForPlayer(ply)
  89. if IsValid(ply) then
  90. local c = hook.Call("TTTScoreboardColorForPlayer", GAMEMODE, ply)
  91.  
  92. -- verify that we got a proper color
  93. if c and type(c) == "table" and c.r and c.b and c.g and c.a then
  94. return c
  95. else
  96. ErrorNoHalt("TTTScoreboardColorForPlayer hook returned something that isn't a color!\n")
  97. end
  98. end
  99. return namecolor.default
  100. end
  101.  
  102. function PANEL:Paint()
  103. if not IsValid(self.Player) then return end
  104.  
  105. -- if ( self.Player:GetFriendStatus() == "friend" ) then
  106. -- color = Color( 236, 181, 113, 255 )
  107. -- end
  108.  
  109. local ply = self.Player
  110.  
  111. if ply:IsTraitor() then
  112. surface.SetDrawColor(255, 0, 0, 30)
  113. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT)
  114. elseif ply:IsDetective() then
  115. surface.SetDrawColor(0, 0, 255, 30)
  116. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT)
  117. end
  118.  
  119.  
  120. if ply == LocalPlayer() then
  121. surface.SetDrawColor( 200, 200, 200, math.Clamp(math.sin(RealTime() * 2) * 50, 0, 100))
  122. surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT )
  123. end
  124.  
  125. return true
  126. end
  127.  
  128. function PANEL:SetPlayer(ply)
  129. self.Player = ply
  130. self.avatar:SetPlayer(ply)
  131.  
  132. if not self.info then
  133. local g = ScoreGroup(ply)
  134. if g == GROUP_TERROR and ply != LocalPlayer() then
  135. self.info = vgui.Create("TTTScorePlayerInfoTags", self)
  136. self.info:SetPlayer(ply)
  137.  
  138. self:InvalidateLayout()
  139. elseif g == GROUP_FOUND or g == GROUP_NOTFOUND then
  140. self.info = vgui.Create("TTTScorePlayerInfoSearch", self)
  141. self.info:SetPlayer(ply)
  142. self:InvalidateLayout()
  143. end
  144. else
  145. self.info:SetPlayer(ply)
  146.  
  147. self:InvalidateLayout()
  148. end
  149.  
  150. self.voice.DoClick = function()
  151. if IsValid(ply) and ply != LocalPlayer() then
  152. ply:SetMuted(not ply:IsMuted())
  153. end
  154. end
  155.  
  156. self:UpdatePlayerData()
  157. end
  158.  
  159. function PANEL:GetPlayer() return self.Player end
  160.  
  161. function PANEL:UpdatePlayerData()
  162. if not IsValid(self.Player) then return end
  163.  
  164. local ply = self.Player
  165. self.cols[1]:SetText(ply:Ping())
  166. self.cols[2]:SetText(ply:Deaths())
  167. self.cols[3]:SetText(ply:Frags())
  168.  
  169. if self.cols[4] then
  170. self.cols[4]:SetText(math.Round(ply:GetBaseKarma()))
  171. end
  172.  
  173. self.nick:SetText(ply:Nick())
  174. self.nick:SizeToContents()
  175. self.nick:SetTextColor(ColorForPlayer(ply))
  176.  
  177.  
  178. if ply:IsUserGroup("superadmin") then
  179. self.cols[5]:SetText("User")
  180. self.cols[5]:SetTextColor(Color(255, 255, 255, 255))
  181. elseif ply:IsUserGroup("owner") then
  182. self.cols[5]:SetText("Owner")
  183. self.cols[5]:SetTextColor(Color(255, 0, 0, 255))
  184. elseif ply:IsUserGroup("co_owner") then
  185. self.cols[5]:SetText("Co-Owner")
  186. elseif ply:IsUserGroup("pony") then
  187. self.cols[5]:SetText("Pony")
  188. self.cols[5]:SetTextColor(Color(59, 64, 212, 255))
  189. elseif ply:IsUserGroup("manager") then
  190. self.cols[5]:SetText("Manager")
  191. self.cols[5]:SetTextColor(Color(30, 90, 255, 255))
  192. elseif ply:IsUserGroup("nunu") then
  193. self.cols[5]:SetText("Nunu")
  194. self.cols[5]:SetTextColor(Color(23, 197, 232, 255))
  195. elseif ply:IsUserGroup("mod") then
  196. self.cols[5]:SetText("Moderator")
  197. self.cols[5]:SetTextColor(Color(235, 37, 175, 255))
  198. elseif ply:IsUserGroup("donator") then
  199. self.cols[5]:SetText("Donator")
  200. self.cols[5]:SetTextColor(Color(114, 145, 229, 255))
  201. elseif ply:IsUserGroup("jr_mod") then
  202. self.cols[5]:SetText("Jr. Mod")
  203. self.cols[5]:SetTextColor(Color(255, 141, 221, 255))
  204. elseif ply:IsUserGroup("member") then
  205. self.cols[5]:SetText("Member")
  206. self.cols[5]:SetTextColor(Color(231, 1, 223, 255))
  207. elseif ply:IsUserGroup("donator_plus") then
  208. self.cols[5]:SetText("Donator+")
  209. self.cols[5]:SetTextColor(Color(65, 105, 255, 255))
  210. elseif ply:IsUserGroup("super_donator") then
  211. self.cols[5]:SetText("Super Donator")
  212. self.cols[5]:SetTextColor(Color(88, 84, 206, 255))
  213. elseif ply:IsUserGroup("director") then
  214. self.cols[5]:SetText("Director")
  215. self.cols[5]:SetTextColor(Color(60, 246, 240, 255))
  216. elseif ply:IsUserGroup("trusted_member") then
  217. self.cols[5]:SetText("Trusted")
  218. self.cols[5]:SetTextColor(Color(246, 183, 242, 255))
  219. elseif ply:IsUserGroup("user") then
  220. self.cols[5]:SetText("User")
  221. self.cols[5]:SetTextColor(Color(225, 255, 255, 255))
  222. elseif ply:IsUserGroup("admin") then
  223. self.cols[5]:SetText("Admin")
  224. self.cols[5]:SetTextColor(Color(225, 255, 0, 255))
  225. elseif ply:IsUserGroup("head_admin") then
  226. self.cols[5]:SetText("Head Admin")
  227. self.cols[5]:SetTextColor(Color(225, 255, 0, 255))
  228. elseif ply:IsUserGroup("sr_mod") then
  229. self.cols[5]:SetText("Sr. Mod")
  230. self.cols[5]:SetTextColor(Color(126, 0 ,172, 255))
  231. -- elseif ply:IsUserGroup("admin") then
  232. -- self.cols[5]:SetText("Admin")
  233. -- self.cols[5]:SetTextColor(Color(220, 180, 0, 255))
  234. -- Delete the -- and change the settings to your liking. DO NOT DELETE THE 'end'
  235. end
  236.  
  237. local ptag = ply.sb_tag
  238. if ScoreGroup(ply) != GROUP_TERROR then
  239. ptag = nil
  240. end
  241.  
  242. self.tag:SetText(ptag and GetTranslation(ptag.txt) or "")
  243. self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)
  244.  
  245. self.sresult:SetVisible(ply.search_result != nil)
  246.  
  247. -- more blue if a detective searched them
  248. if ply.search_result and (LocalPlayer():IsDetective() or (not ply.search_result.show)) then
  249. self.sresult:SetImageColor(Color(200, 200, 255))
  250. end
  251.  
  252. -- cols are likely to need re-centering
  253. self:LayoutColumns()
  254.  
  255. if self.info then
  256. self.info:UpdatePlayerData()
  257. end
  258.  
  259. if self.Player != LocalPlayer() then
  260. local muted = self.Player:IsMuted()
  261. self.voice:SetImage(muted and "icon16/sound_mute.png" or "icon16/sound.png")
  262. else
  263. self.voice:Hide()
  264. end
  265. end
  266.  
  267. function PANEL:ApplySchemeSettings()
  268. for k,v in pairs(self.cols) do
  269. v:SetFont("treb_small")
  270. v:SetTextColor(COLOR_WHITE)
  271. end
  272.  
  273. self.nick:SetFont("treb_small")
  274. self.nick:SetTextColor(ColorForPlayer(self.Player))
  275.  
  276. local ptag = self.Player and self.Player.sb_tag
  277. self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)
  278. self.tag:SetFont("treb_small")
  279.  
  280. self.sresult:SetImage("icon16/magnifier.png")
  281. self.sresult:SetImageColor(Color(170, 170, 170, 150))
  282. end
  283.  
  284. function PANEL:LayoutColumns()
  285. for k,v in ipairs(self.cols) do
  286. v:SizeToContents()
  287. v:SetPos(self:GetWide() - (50*k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
  288. end
  289.  
  290. self.tag:SizeToContents()
  291. self.tag:SetPos(self:GetWide() - (50 * 6) - self.tag:GetWide()/2, (SB_ROW_HEIGHT - self.tag:GetTall()) / 2)
  292.  
  293. self.sresult:SetPos(self:GetWide() - (50*6) - 8, (SB_ROW_HEIGHT - 16) / 2)
  294. end
  295.  
  296. function PANEL:PerformLayout()
  297. self.avatar:SetPos(0,0)
  298. self.avatar:SetSize(SB_ROW_HEIGHT,SB_ROW_HEIGHT)
  299.  
  300. if not self.open then
  301. self:SetSize(self:GetWide(), SB_ROW_HEIGHT)
  302.  
  303. if self.info then self.info:SetVisible(false) end
  304. elseif self.info then
  305. self:SetSize(self:GetWide(), 100 + SB_ROW_HEIGHT)
  306.  
  307. self.info:SetVisible(true)
  308. self.info:SetPos(5, SB_ROW_HEIGHT + 5)
  309. self.info:SetSize(self:GetWide(), 100)
  310. self.info:PerformLayout()
  311.  
  312. self:SetSize(self:GetWide(), SB_ROW_HEIGHT + self.info:GetTall())
  313. end
  314.  
  315. self.nick:SizeToContents()
  316.  
  317. self.nick:SetPos(SB_ROW_HEIGHT + 10, (SB_ROW_HEIGHT - self.nick:GetTall()) / 2)
  318.  
  319. self:LayoutColumns()
  320.  
  321. self.voice:SetVisible(not self.open)
  322. self.voice:SetSize(16, 16)
  323. self.voice:DockMargin(4, 4, 4, 4)
  324. self.voice:Dock(RIGHT)
  325. end
  326.  
  327. function PANEL:DoClick(x, y)
  328. self:SetOpen(not self.open)
  329. end
  330.  
  331. function PANEL:SetOpen(o)
  332. if self.open then
  333. surface.PlaySound("ui/buttonclickrelease.wav")
  334. else
  335. surface.PlaySound("ui/buttonclick.wav")
  336. end
  337.  
  338. self.open = o
  339.  
  340. self:PerformLayout()
  341. self:GetParent():PerformLayout()
  342. sboard_panel:PerformLayout()
  343. end
  344.  
  345. function PANEL:DoRightClick()
  346. end
  347.  
  348. vgui.Register( "TTTScorePlayerRow", PANEL, "Button" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement