@@ -7,30 +7,7 @@ function PANEL:Init()
7
7
8
8
self .channels = {}
9
9
self .channelIndexes = {}
10
-
11
- self .channelList = vgui .Create ( " DPanel" , self )
12
- self .channelList :SetWide ( 30 )
13
- self .channelList :Dock ( LEFT )
14
- self .channelList :DockMargin ( 0 , - 24 , 4 , 0 )
15
- self .channelList :DockPadding ( 2 , 2 , 2 , 2 )
16
- self .channelList ._backgroundColor = Color ( 0 , 0 , 0 )
17
-
18
- self .channelList .Paint = function ( s , w , h )
19
- surface .SetDrawColor ( s ._backgroundColor :Unpack () )
20
- surface .DrawRect ( 0 , 0 , w , h )
21
- end
22
-
23
- local buttonOpenDM = vgui .Create ( " DButton" , self .channelList )
24
- buttonOpenDM :SetText ( " " )
25
- buttonOpenDM :SetIcon ( " icon16/add.png" )
26
- buttonOpenDM :SetTall ( 26 )
27
- buttonOpenDM :SetTooltip ( L " channel.open_dm" )
28
- buttonOpenDM :SetPaintBackground ( false )
29
- buttonOpenDM :Dock ( BOTTOM )
30
-
31
- buttonOpenDM .DoClick = function ()
32
- self :OpenDirectMessage ()
33
- end
10
+ self .channelListBackgroundColor = Color ( 0 , 0 , 0 )
34
11
35
12
self .history = vgui .Create ( " CustomChat_History" , self )
36
13
self .history :Dock ( FILL )
@@ -153,6 +130,64 @@ function PANEL:Init()
153
130
self :CloseChat ()
154
131
end
155
132
133
+ function PANEL :SetSidebarEnabled ( enable )
134
+ if not enable then
135
+ if IsValid ( self .channelList ) then
136
+ self .channelList :Remove ()
137
+ end
138
+
139
+ self .channelList = nil
140
+ return
141
+ end
142
+
143
+ self .channelList = vgui .Create ( " DPanel" , self )
144
+ self .channelList :SetWide ( 30 )
145
+ self .channelList :Dock ( LEFT )
146
+ self .channelList :DockMargin ( 0 , - 24 , 4 , 0 )
147
+ self .channelList :DockPadding ( 2 , 2 , 2 , 2 )
148
+
149
+ self .channelList .Paint = function ( _ , w , h )
150
+ surface .SetDrawColor ( self .channelListBackgroundColor :Unpack () )
151
+ surface .DrawRect ( 0 , 0 , w , h )
152
+ end
153
+
154
+ self :UpdateChannelList ()
155
+ end
156
+
157
+ function PANEL :UpdateChannelList ()
158
+ if not self .channelList then return end
159
+
160
+ self .channelList :Clear ()
161
+ self .channelList :SetVisible ( self .isChatOpen )
162
+
163
+ for _ , id in ipairs ( self .channelIndexes ) do
164
+ local channel = self .channels [id ]
165
+
166
+ local button = vgui .Create ( " CustomChat_ChannelButton" , self .channelList )
167
+ button :SetTall ( 28 )
168
+ button :SetTooltip ( channel .name )
169
+ button :SetIcon ( channel .icon )
170
+ button :Dock ( TOP )
171
+ button :DockMargin ( 0 , 0 , 0 , 2 )
172
+ button .channelId = id
173
+ button .isSelected = channel .isSelected
174
+ button .colorSelected = self .highlightColor
175
+ button .notificationCount = channel .notificationCount
176
+ end
177
+
178
+ local buttonOpenDM = vgui .Create ( " DButton" , self .channelList )
179
+ buttonOpenDM :SetText ( " " )
180
+ buttonOpenDM :SetIcon ( " icon16/add.png" )
181
+ buttonOpenDM :SetTall ( 26 )
182
+ buttonOpenDM :SetTooltip ( L " channel.open_dm" )
183
+ buttonOpenDM :SetPaintBackground ( false )
184
+ buttonOpenDM :Dock ( BOTTOM )
185
+
186
+ buttonOpenDM .DoClick = function ()
187
+ self :OpenDirectMessage ()
188
+ end
189
+ end
190
+
156
191
function PANEL :OpenChat ()
157
192
self .entryDock :SetTall ( 20 )
158
193
self .history :ScrollToBottom ()
@@ -219,7 +254,7 @@ function PANEL:NextChannel()
219
254
local currentIndex = 1
220
255
221
256
for i , id in ipairs ( self .channelIndexes ) do
222
- if self .channels [id ].button . isSelected then
257
+ if self .channels [id ].isSelected then
223
258
currentIndex = i
224
259
break
225
260
end
@@ -239,8 +274,9 @@ function PANEL:CreateChannel( id, name, icon )
239
274
240
275
if channel then
241
276
channel .name = name
242
- channel .button :SetTooltip ( name )
243
- channel .button :SetIcon ( icon )
277
+ channel .icon = icon
278
+
279
+ self :UpdateChannelList ()
244
280
245
281
return channel
246
282
end
@@ -249,20 +285,14 @@ function PANEL:CreateChannel( id, name, icon )
249
285
250
286
channel = {
251
287
name = name ,
252
- missedCount = 0
288
+ icon = icon ,
289
+ missedCount = 0 ,
290
+ notificationCount = 0
253
291
}
254
292
255
- channel .button = vgui .Create ( " CustomChat_ChannelButton" , self .channelList )
256
- channel .button :SetTall ( 28 )
257
- channel .button :SetTooltip ( name )
258
- channel .button :SetIcon ( icon )
259
- channel .button :Dock ( TOP )
260
- channel .button :DockMargin ( 0 , 0 , 0 , 2 )
261
- channel .button .channelId = id
262
- channel .button .colorSelected = self .highlightColor
263
-
264
293
self .channels [id ] = channel
265
294
self .channelIndexes [# self .channelIndexes + 1 ] = id
295
+ self :UpdateChannelList ()
266
296
267
297
return channel
268
298
end
@@ -276,10 +306,10 @@ function PANEL:RemoveChannel( id )
276
306
277
307
self .history :QueueJavascript ( " RemoveChannel('" .. id .. " ');" )
278
308
279
- self .channels [id ].button :Remove ()
280
- self .channels [id ] = nil
281
-
282
309
table .RemoveByValue ( self .channelIndexes , id )
310
+
311
+ self .channels [id ] = nil
312
+ self :UpdateChannelList ()
283
313
end
284
314
285
315
function PANEL :SetActiveChannel ( id )
@@ -296,7 +326,7 @@ function PANEL:SetActiveChannel( id )
296
326
end
297
327
298
328
for chid , c in pairs ( self .channels ) do
299
- c .button . isSelected = chid == id
329
+ c .isSelected = chid == id
300
330
end
301
331
302
332
if id == " team" then
@@ -318,12 +348,14 @@ function PANEL:SetActiveChannel( id )
318
348
319
349
if self .isChatOpen then
320
350
self .entry :RequestFocus ()
351
+ self :UpdateChannelList ()
321
352
end
322
353
end
323
354
324
355
function PANEL :SetChannelNotificationCount ( id , count )
325
356
if self .channels [id ] then
326
- self .channels [id ].button .notificationCount = count
357
+ self .channels [id ].notificationCount = count
358
+ self :UpdateChannelList ()
327
359
end
328
360
end
329
361
@@ -352,12 +384,9 @@ function PANEL:LoadThemeData( data )
352
384
self .entry :SetHighlightColor ( self .highlightColor )
353
385
354
386
self .entryDock ._backgroundColor = self .inputBackgroundColor
355
- self .channelList ._backgroundColor = self .inputBackgroundColor
356
-
357
- for _ , c in pairs ( self .channels ) do
358
- c .button .colorSelected = self .highlightColor
359
- end
387
+ self .channelListBackgroundColor = self .inputBackgroundColor
360
388
389
+ self :UpdateChannelList ()
361
390
self :InvalidateChildren ()
362
391
end
363
392
0 commit comments