Permalink
Browse files

TTT: Added Scoreboard hooks

Added hooks:
"TTTScoreboardColumns" - Two arguments, Panel and Enumeration. Return nil.
"TTTScoreboardMenu" - One argument, Panel. Return PreventOpen (Boolean).

Added enumerations for TTTScoreboardColumns hook:
TTT_COLUMN_HEADING - Column headings
TTT_COLUMN_ROW - Column row/data
TTT_COLUMN_BACKGROUND - Column background (Darker columns)

Added functions PANEL:AddColumn( label, func ) to scoreboard panels.
  • Loading branch information...
1 parent 3feb9a5 commit 375d518d98d2480e352b15ce95bfee4745cf3536 @MyHatStinks MyHatStinks committed Feb 28, 2014
@@ -24,6 +24,10 @@ surface.CreateFont("treb_small", {font = "Trebuchet18",
local logo = surface.GetTextureID("VGUI/ttt/score_logo")
+TTT_COLUMN_HEADING = 0
+TTT_COLUMN_ROW = 1
+TTT_COLUMN_BACKGROUND = 2
+
local PANEL = {}
local max = math.max
@@ -120,24 +124,28 @@ function PANEL:Init()
-- the various score column headers
self.cols = {}
- self.cols[1] = vgui.Create( "DLabel", self )
- self.cols[1]:SetText( GetTranslation("sb_ping") )
-
- self.cols[2] = vgui.Create( "DLabel", self )
- self.cols[2]:SetText( GetTranslation("sb_deaths") )
-
- self.cols[3] = vgui.Create( "DLabel", self )
- self.cols[3]:SetText( GetTranslation("sb_score") )
+ self:AddColumn( GetTranslation("sb_ping") )
+ self:AddColumn( GetTranslation("sb_deaths") )
+ self:AddColumn( GetTranslation("sb_score") )
if KARMA.IsEnabled() then
- self.cols[4] = vgui.Create("DLabel", self)
- self.cols[4]:SetText(GetTranslation("sb_karma"))
+ self:AddColumn( GetTranslation("sb_karma") )
end
+
+ hook.Call( "TTTScoreboardColumns", nil, self, TTT_COLUMN_HEADING ) --We'll grab custom headers here, same hook as the rows for ease of use
self:UpdateScoreboard()
self:StartUpdateTimer()
end
+function PANEL:AddColumn( label, func )
+ local lbl = vgui.Create( "DLabel", self )
+ lbl:SetText( label )
+
+ table.insert( self.cols, lbl )
+ return lbl
+end
+
function PANEL:StartUpdateTimer()
if not timer.Exists("TTTScoreboardUpdater") then
timer.Create( "TTTScoreboardUpdater", 0.3, 0,
@@ -19,19 +19,15 @@ function PANEL:Init()
self.open = false
self.cols = {}
- self.cols[1] = vgui.Create("DLabel", self)
- self.cols[1]:SetText(GetTranslation("sb_ping"))
-
- self.cols[2] = vgui.Create("DLabel", self)
- self.cols[2]:SetText(GetTranslation("sb_deaths"))
-
- self.cols[3] = vgui.Create("DLabel", self)
- self.cols[3]:SetText(GetTranslation("sb_score"))
+ self:AddColumn( GetTranslation("sb_ping"), function(ply) return ply:Ping() end )
+ self:AddColumn( GetTranslation("sb_deaths"), function(ply) return ply:Deaths() end )
+ self:AddColumn( GetTranslation("sb_score"), function(ply) return ply:Frags() end )
if KARMA.IsEnabled() then
- self.cols[4] = vgui.Create("DLabel", self)
- self.cols[4]:SetText(GetTranslation("sb_karma"))
+ self:AddColumn( GetTranslation("sb_karma"), function(ply) return math.Round(ply:GetBaseKarma()) end )
end
+
+ hook.Call( "TTTScoreboardColumns", nil, self, TTT_COLUMN_ROW ) --Let coders add their own columns, first arg panel
for _, c in ipairs(self.cols) do
c:SetMouseInputEnabled(false)
@@ -58,6 +54,15 @@ function PANEL:Init()
self:SetCursor( "hand" )
end
+function PANEL:AddColumn( label, func )
+ local lbl = vgui.Create( "DLabel", self )
+ lbl:SetText( label )
+ lbl.func = func
+
+ table.insert( self.cols, lbl )
+ return lbl
+end
+
local namecolor = {
default = COLOR_WHITE,
@@ -153,12 +158,8 @@ function PANEL:UpdatePlayerData()
if not IsValid(self.Player) then return end
local ply = self.Player
- self.cols[1]:SetText(ply:Ping())
- self.cols[2]:SetText(ply:Deaths())
- self.cols[3]:SetText(ply:Frags())
-
- if self.cols[4] then
- self.cols[4]:SetText(math.Round(ply:GetBaseKarma()))
+ for i=1,#self.cols do
+ self.cols[i]:SetText( self.cols[i].func(ply, self.cols[i]) ) --Set text from function. First arg player, second arg label (For colours or whatever)
end
self.nick:SetText(ply:Nick())
@@ -219,9 +220,9 @@ function PANEL:LayoutColumns()
end
self.tag:SizeToContents()
- self.tag:SetPos(self:GetWide() - (50 * 6) - self.tag:GetWide()/2, (SB_ROW_HEIGHT - self.tag:GetTall()) / 2)
+ self.tag:SetPos(self:GetWide() - (50 * (#self.cols+1)) - self.tag:GetWide()/2, (SB_ROW_HEIGHT - self.tag:GetTall()) / 2)
- self.sresult:SetPos(self:GetWide() - (50*6) - 8, (SB_ROW_HEIGHT - 16) / 2)
+ self.sresult:SetPos(self:GetWide() - (50*(#self.cols+1)) - 8, (SB_ROW_HEIGHT - 16) / 2)
end
function PANEL:PerformLayout()
@@ -277,6 +278,13 @@ function PANEL:SetOpen(o)
end
function PANEL:DoRightClick()
+ local menu = DermaMenu()
+ menu.Player = self:GetPlayer()
+
+ local close = hook.Call( "TTTScoreboardMenu", nil, menu )
+ if close then menu:Remove() return end
+
+ menu:Open()
end
vgui.Register( "TTTScorePlayerRow", PANEL, "Button" )
@@ -31,6 +31,14 @@ function PANEL:Init()
self.rows_sorted = {}
self.group = "spec"
+
+ self.cols = {true,true,true, KARMA.IsEnabled() and true or nil} --We want to see the columns, so the darkening effect can match. 3 static columns, karma optional fourth
+
+ hook.Call( "TTTScoreboardColumns", nil, self, TTT_COLUMN_BACKGROUND ) --Grab custom columns
+end
+
+function PANEL:AddColumn()
+ table.insert( self.cols, true ) --We don't keed to know anything about the column, only that it exists
end
function PANEL:SetGroupInfo(name, color, group)
@@ -75,8 +83,9 @@ function PANEL:Paint()
-- Column darkening
local scr = sboard_panel.ply_frame.scroll.Enabled and 16 or 0
surface.SetDrawColor(0,0,0, 80)
- surface.DrawRect(self:GetWide() - 175 - scr, 0, 50, self:GetTall())
- surface.DrawRect(self:GetWide() - 75 - scr, 0, 50, self:GetTall())
+ for i=1,#self.cols,2 do --Odd numbers
+ surface.DrawRect(self:GetWide() - (50*i) - 25 - scr, 0, 50, self:GetTall())
+ end
end
function PANEL:AddPlayerRow(ply)

0 comments on commit 375d518

Please sign in to comment.