Skip to content

Commit 396fd52

Browse files
committed
Add option to show/hide sidebar
1 parent 25eb4dc commit 396fd52

File tree

7 files changed

+103
-52
lines changed

7 files changed

+103
-52
lines changed

lua/custom_chat/client/config.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function Config:Reset()
1111
self.fontSize = 18
1212
self.allowAnyURL = false
1313
self.timestamps = false
14+
self.hideSidebar = false
1415
self.themeId = "default"
1516
end
1617

@@ -78,6 +79,7 @@ function Config:Load()
7879
SetNumber( self, "fontSize", data.font_size, 10, 64 )
7980
SetBool( self, "timestamps", data.timestamps )
8081
SetBool( self, "allowAnyURL", data.allow_any_url )
82+
SetBool( self, "hideSidebar", data.hide_sidebar )
8183

8284
self.themeId = CustomChat.IsStringValid( data.theme_id ) and data.theme_id or "default"
8385
end
@@ -100,8 +102,9 @@ function Config:Save( immediate )
100102
offset_bottom = self.offsetBottom,
101103

102104
font_size = self.fontSize,
103-
allow_any_url = self.allowAnyURL,
104105
timestamps = self.timestamps,
106+
allow_any_url = self.allowAnyURL,
107+
hide_sidebar = self.hideSidebar,
105108
theme_id = self.themeId
106109
} ) )
107110
end

lua/custom_chat/client/main.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function CustomChat:CreateFrame()
135135
self.frame:SetScreenLock( true )
136136
self.frame:SetMinWidth( 250 )
137137
self.frame:SetMinHeight( 150 )
138+
self.frame:SetSidebarEnabled( not Config.hideSidebar )
138139

139140
self.frame._MouseReleased = self.frame.OnMouseReleased
140141

@@ -314,6 +315,16 @@ function CustomChat:OpenContextMenu( data )
314315

315316
optionsMenu:AddSpacer()
316317

318+
optionsMenu:AddOption( L"channel.open_dm", function()
319+
self.frame:OpenDirectMessage()
320+
end ):SetIcon( "icon16/add.png" )
321+
322+
optionsMenu:AddOption( L( Config.hideSidebar and "side_bar.show" or "side_bar.hide" ), function()
323+
Config.hideSidebar = not Config.hideSidebar
324+
Config:Save()
325+
self.frame:SetSidebarEnabled( not Config.hideSidebar )
326+
end ):SetIcon( Config.hideSidebar and "icon16/application_side_expand.png" or "icon16/application_side_contract.png" )
327+
317328
optionsMenu:AddOption( L( Config.timestamps and "timestamps.disable" or "timestamps.enable" ), function()
318329
Config.timestamps = not Config.timestamps
319330
Config:Save()

lua/custom_chat/client/vgui/chat_frame.lua

Lines changed: 76 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,7 @@ function PANEL:Init()
77

88
self.channels = {}
99
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 )
3411

3512
self.history = vgui.Create( "CustomChat_History", self )
3613
self.history:Dock( FILL )
@@ -153,6 +130,64 @@ function PANEL:Init()
153130
self:CloseChat()
154131
end
155132

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+
156191
function PANEL:OpenChat()
157192
self.entryDock:SetTall( 20 )
158193
self.history:ScrollToBottom()
@@ -219,7 +254,7 @@ function PANEL:NextChannel()
219254
local currentIndex = 1
220255

221256
for i, id in ipairs( self.channelIndexes ) do
222-
if self.channels[id].button.isSelected then
257+
if self.channels[id].isSelected then
223258
currentIndex = i
224259
break
225260
end
@@ -239,8 +274,9 @@ function PANEL:CreateChannel( id, name, icon )
239274

240275
if channel then
241276
channel.name = name
242-
channel.button:SetTooltip( name )
243-
channel.button:SetIcon( icon )
277+
channel.icon = icon
278+
279+
self:UpdateChannelList()
244280

245281
return channel
246282
end
@@ -249,20 +285,14 @@ function PANEL:CreateChannel( id, name, icon )
249285

250286
channel = {
251287
name = name,
252-
missedCount = 0
288+
icon = icon,
289+
missedCount = 0,
290+
notificationCount = 0
253291
}
254292

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-
264293
self.channels[id] = channel
265294
self.channelIndexes[#self.channelIndexes + 1] = id
295+
self:UpdateChannelList()
266296

267297
return channel
268298
end
@@ -276,10 +306,10 @@ function PANEL:RemoveChannel( id )
276306

277307
self.history:QueueJavascript( "RemoveChannel('" .. id .. "');" )
278308

279-
self.channels[id].button:Remove()
280-
self.channels[id] = nil
281-
282309
table.RemoveByValue( self.channelIndexes, id )
310+
311+
self.channels[id] = nil
312+
self:UpdateChannelList()
283313
end
284314

285315
function PANEL:SetActiveChannel( id )
@@ -296,7 +326,7 @@ function PANEL:SetActiveChannel( id )
296326
end
297327

298328
for chid, c in pairs( self.channels ) do
299-
c.button.isSelected = chid == id
329+
c.isSelected = chid == id
300330
end
301331

302332
if id == "team" then
@@ -318,12 +348,14 @@ function PANEL:SetActiveChannel( id )
318348

319349
if self.isChatOpen then
320350
self.entry:RequestFocus()
351+
self:UpdateChannelList()
321352
end
322353
end
323354

324355
function PANEL:SetChannelNotificationCount( id, count )
325356
if self.channels[id] then
326-
self.channels[id].button.notificationCount = count
357+
self.channels[id].notificationCount = count
358+
self:UpdateChannelList()
327359
end
328360
end
329361

@@ -352,12 +384,9 @@ function PANEL:LoadThemeData( data )
352384
self.entry:SetHighlightColor( self.highlightColor )
353385

354386
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
360388

389+
self:UpdateChannelList()
361390
self:InvalidateChildren()
362391
end
363392

resource/localization/en/custom_chat.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ custom_chat.time.hours=hours
152152
custom_chat.time.minutes=minutes
153153
custom_chat.time.seconds=seconds
154154
custom_chat.last_seen2=ago.
155-
custom_chat.server_dms_disabled=Direct messages are disabled on this server.
155+
custom_chat.server_dms_disabled=Direct messages are disabled on this server.
156+
custom_chat.side_bar.show=Show sidebar
157+
custom_chat.side_bar.hide=Hide sidebar

resource/localization/pt-br/custom_chat.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ custom_chat.time.hours=horas
152152
custom_chat.time.minutes=minutos
153153
custom_chat.time.seconds=segundos
154154
custom_chat.last_seen2=atrás.
155-
custom_chat.server_dms_disabled=Conversas privadas estão desabilitadas neste servidor.
155+
custom_chat.server_dms_disabled=Conversas privadas estão desabilitadas neste servidor.
156+
custom_chat.side_bar.show=Mostrar barra lateral
157+
custom_chat.side_bar.hide=Esconder barra lateral

resource/localization/ru/custom_chat.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ custom_chat.time.hours=ч.
152152
custom_chat.time.minutes=мин.
153153
custom_chat.time.seconds=сек.
154154
custom_chat.last_seen2=назад.
155-
custom_chat.server_dms_disabled=На этом сервере отключены личные переписки.
155+
custom_chat.server_dms_disabled=На этом сервере отключены личные переписки.
156+
custom_chat.side_bar.show=Показать боковую панель
157+
custom_chat.side_bar.hide=Скрыть боковую панель

resource/localization/tr/custom_chat.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ custom_chat.time.hours=saat
152152
custom_chat.time.minutes=dakika
153153
custom_chat.time.seconds=saniye
154154
custom_chat.last_seen2=önce oynadı.
155-
custom_chat.server_dms_disabled=Bu sunucuda Doğrudan Mesajlar devre dışı bırakıldı.
155+
custom_chat.server_dms_disabled=Bu sunucuda Doğrudan Mesajlar devre dışı bırakıldı.
156+
custom_chat.side_bar.show=Kenar çubuğunu göster
157+
custom_chat.side_bar.hide=Kenar çubuğunu gizle

0 commit comments

Comments
 (0)