· 9 years ago · Jan 31, 2017, 05:08 PM
1--[[
2 Scoreboard
3
4 Please do not modifiy any code below.
5
6 Credits:
7 AC² - Main code
8 BlackVoid - Help with vgui.RegisterTable and his deathrun scoreboard
9 The internet - Images
10--]]
11
12
13-- Safe
14if (gScoreboard) then
15 gScoreboard:Remove()
16end
17
18-- Fonts
19surface.CreateFont("scoreboard.player", {font = "Trebuchet18", size = 14, weight = 700, antialias = true})
20surface.CreateFont("scoreboard.player_title", {font = "Trebuchet18", size = 12, weight = 600, antialias = true})
21
22-- Cache materials we will use.
23local bg = Material("spiceworks/scoreboard/scoreboard_header.png", "smooth alphatest")
24local adminicon = Cure.Config.pIcons.admin
25local usericon = Cure.Config.pIcons.user
26
27-- How to sort teams
28local SortedTeams = {
29 [3] = 1000,
30 [2] = 0,
31 [1] = 2000,
32}
33
34-- Other settings
35local MAX_HEIGHT = 762
36
37--[[
38 Create a table that will hold all our functions for a player line in the scorebaord
39--]]
40local PLAYER_LINE = {
41 -- Initialize
42 Init = function(self)
43 -- Default
44 self:SetWide(800)
45 self:SetTall(35)
46
47 -- Avatar
48 self.pAvatar = self:Add("AvatarImage")
49 self.pAvatar:SetPos(1, 0)
50 self.pAvatar:SetSize(34, 34)
51 self.pAvatar:SetMouseInputEnabled( false )
52
53 -- Name
54 self.pName = self:Add("DLabel")
55 self.pName:SetFont("scoreboard.player")
56 self.pName:SetPos(40, 5)
57
58 -- Title
59 self.pTitle = self:Add("DLabel")
60 self.pTitle:SetFont("scoreboard.player_title")
61 self.pTitle:SetPos(40, 18)
62
63 -- Level
64 self.pLevel = self:Add("DLabel")
65 self.pLevel:SetFont("scoreboard.player")
66 self.pLevel:SetPos(430, 8)
67 end,
68
69 -- Define player, update labels, etc
70 Setup = function(self, pl)
71 -- Valid
72 if not (pl:IsValid()) then return end
73
74 -- Cache
75 self.pPlayer = pl
76
77 -- Avatar
78 self.pAvatar:SetPlayer(pl)
79 -- Name
80 self.pName:SetText(pl:Nick())
81 self.pName:SizeToContents()
82
83 -- Level
84 self.pLevel:SetText("Lvl "..(pl:GetNWInt("level") or 0))
85
86 -- Title
87 self.pTitle:SetText("Guest")
88 self.pTitle:SizeToContents()
89
90 -- Get Color
91 --local playercolor = GAMEMODE:GetScoreboardNameColor(self.pPlayer) or hook.Call("GetScoreboardNameColor", nil, self.pPlayer) or Color(255, 255, 255, 255)
92 local playercolor = color_white
93 self.pName:SetTextColor(playercolor)
94
95 -- Update
96 self:Think(self)
97 end,
98
99 -- Update thigns
100 Think = function(self)
101 -- Valid
102 if not (IsValid(self.pPlayer)) then
103 self:Remove()
104 return
105 end
106
107 local team = self.pPlayer:Team()
108
109 if not (self.pPlayer:Alive()) then
110 team = 1
111 end
112
113 -- Sort alive
114 self:SetZPos(SortedTeams[team] or 2000)
115 end,
116
117 -- Draw etc
118 Paint = function(self, w, h)
119 -- Valid
120 if not (IsValid(self.pPlayer)) then
121 return
122 end
123
124 -- Special kinds of backgrounds
125 if (Cure.Config.pBackgrounds[self.pPlayer:SteamID()]) then
126 surface.SetDrawColor(Color(255, 255, 255, 255))
127 surface.SetMaterial(Cure.Config.pBackgrounds[self.pPlayer:SteamID()])
128 surface.DrawTexturedRect(0, 0, w, h)
129 else
130 if (self.pPlayer:Team() == TEAM_DEATH) and (self.pPlayer:Alive()) then
131 surface.SetDrawColor(Color(177, 25, 25, 155))
132 elseif (self.pPlayer:Team() == TEAM_RUNNER) and (self.pPlayer:Alive()) then
133 surface.SetDrawColor(Color(45, 162, 191, 255))
134 else
135 surface.SetDrawColor(Color(160, 160, 160, 255))
136 end
137
138 -- Background
139 surface.DrawRect(0, 0, self:GetWide(), self:GetTall())
140 end
141
142 -- Team color
143 if (self.pPlayer:Team() == TEAM_DEATH) and (self.pPlayer:Alive()) then
144 surface.SetMaterial(Cure.Config.pBackgrounds[3])
145 elseif (self.pPlayer:Team() == TEAM_RUNNER) and (self.pPlayer:Alive()) then
146 surface.SetMaterial(Cure.Config.pBackgrounds[2])
147 else
148 surface.SetMaterial(Cure.Config.pBackgrounds[1])
149 end
150
151 -- Background
152 surface.SetDrawColor(color_white)
153 surface.DrawTexturedRect(0, 0, self:GetWide(), self:GetTall())
154
155 -- Border
156 surface.SetDrawColor(Color(17, 17, 17, 255))
157 surface.DrawOutlinedRect(0, 0, self:GetWide(), self:GetTall())
158
159 -- Reset draw color
160 surface.SetDrawColor(Color(255, 255, 255, 255))
161
162 -- Icon
163 surface.SetMaterial(Cure.Config.pIcons[self.pPlayer:GetRank()])
164
165 -- User/Admin icon
166 surface.DrawTexturedRect(self:GetWide() - 66, 8, 16, 16)
167
168 -- Background behind 'ping'
169 draw.RoundedBox(0, self:GetWide() - 40, 0, 30, self:GetTall(), Color(0, 0, 0, 100))
170
171 -- Ping
172 draw.SimpleText(self.pPlayer:Ping(), "scoreboard.player", self:GetWide() - 25, 9, color_white, TEXT_ALIGN_CENTER)
173 end
174}
175
176-- Register
177PLAYER_LINE = vgui.RegisterTable(PLAYER_LINE, "DPanel")
178
179--[[
180 Basiclly, the scoreboard itself, holds players and header
181--]]
182SCOREBOARD = {
183 -- Initialize
184 Init = function(self)
185 -- Size
186 self:SetWide(800)
187 self:SetTall(MAX_HEIGHT)
188
189 -- Center
190 self:Center()
191
192 -- Scrollbar
193 self.ScrollList = self:Add("DScrollPanel")
194 self.ScrollList:SetSize(self:GetWide() - 1, self:GetTall() - 100)
195 self.ScrollList:SetPos(0, 163)
196
197 -- Player holder
198 self.pPlayerList = self.ScrollList:Add("DIconLayout")
199 self.pPlayerList:SetWide(self.ScrollList:GetWide())
200
201 end,
202
203 PerformLayout = function(self)
204 -- Recalculate height
205 self:SetTall(164 + (#player.GetAll() * 35))
206
207 -- Maximume
208 if (self:GetTall() >= MAX_HEIGHT) then
209 self:SetTall(MAX_HEIGHT)
210 end
211
212 -- Center
213 self:Center()
214 end,
215
216 -- Think
217 Think = function(self)
218 -- Cache
219 local players = player.GetAll()
220
221 -- Loop through all the players and create a line if non exists
222 for k, v in pairs(players) do
223 -- Important to check if everything is valid
224 if (v.pPlayerLine) and (v.pPlayerLine:IsValid()) then
225 v.pPlayerLine:Setup(v)
226
227 -- Scrollbar
228 if (self:GetTall() >= MAX_HEIGHT) then
229 v.pPlayerLine:SetWide(800 - 16)
230 end
231 else
232 if (v:IsValid()) then
233 -- Create a new line for a NEW player
234 v.pPlayerLine = vgui.CreateFromTable(PLAYER_LINE)
235 v.pPlayerLine:Setup(v)
236 v.pPlayerLine:SetWide(self.pPlayerList:GetWide())
237
238 -- AddItem != Add
239 self.pPlayerList:Add(v.pPlayerLine)
240 end
241 --end
242 end
243 end
244
245 -- Sorts everything, hope this doesn't destroy and re-create
246 self.pPlayerList:Layout()
247 end,
248
249 -- Draw etc
250 Paint = function(self, w, h)
251 -- Main frame
252 draw.RoundedBox(0, 0, 0, self:GetWide(), self:GetTall(), Color(30, 30, 30, 255))
253
254 -- Header
255 surface.SetDrawColor(Color(255, 255, 255, 255))
256 surface.SetMaterial(bg)
257 surface.DrawTexturedRect(2, 2, self:GetWide() - 4, 162)
258
259 -- Header text and such
260 draw.SimpleText("Name", "HudHintTextSmall", 40, 147, color_white, TEXT_ALIGN_LEFT)
261 draw.SimpleText("Level", "HudHintTextSmall", 440, 147, color_white, TEXT_ALIGN_CENTER)
262
263 if (h >= MAX_HEIGHT) then
264 draw.SimpleText("Rank", "HudHintTextSmall", self:GetWide() - 50 - 16, 147, color_white, TEXT_ALIGN_RIGHT)
265 draw.SimpleText("Ping", "HudHintTextSmall", self:GetWide() - 20 - 16, 147, color_white, TEXT_ALIGN_RIGHT)
266 else
267 draw.SimpleText("Rank", "HudHintTextSmall", self:GetWide() - 50, 147, color_white, TEXT_ALIGN_RIGHT)
268 draw.SimpleText("Ping", "HudHintTextSmall", self:GetWide() - 20, 147, color_white, TEXT_ALIGN_RIGHT)
269 end
270 end,
271}
272
273-- Register
274SCOREBOARD = vgui.RegisterTable(SCOREBOARD, "EditablePanel")
275
276-- Called when pressing tab
277function GM:ScoreboardShow()
278 if not (IsValid(gScoreboard)) then
279 gScoreboard = vgui.CreateFromTable(SCOREBOARD)
280 end
281
282 if (IsValid( gScoreboard)) then
283 gScoreboard:Show()
284 gScoreboard:MakePopup()
285 gScoreboard:SetKeyboardInputEnabled(false)
286 end
287end
288
289-- Called when stopped pressing tab
290function GM:ScoreboardHide()
291 if (IsValid(gScoreboard)) then
292 gScoreboard:Hide()
293 end
294end
295
296-- No idea
297function GM:HUDDrawScoreBoard()
298end