Skip to content

Commit 7f61d84

Browse files
authored
Merge pull request #29 from conred-gmod/pr_menu_hook
Implement hiding game menu using new `OnPauseMenuShow` hook
2 parents e19b1d9 + 58029f6 commit 7f61d84

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

lua/custom_chat/client/main.lua

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -515,27 +515,21 @@ local function CustomChat_HUDShouldDraw( name )
515515
if name == "CHudChat" then return false end
516516
end
517517

518-
local isGamePaused = false
519-
520518
local function CustomChat_Think()
521519
if not CustomChat.frame then return end
522520

523-
-- Hide the chat box if the game is paused
524-
if gui.IsGameUIVisible() then
525-
if isGamePaused == false then
526-
isGamePaused = true
521+
if not gui.IsGameUIVisible() and not CustomChat.frame:IsVisible() then
522+
CustomChat.frame:SetVisible( true )
523+
end
524+
end
527525

528-
CustomChat.frame:SetVisible( false )
526+
local function CustomChat_OnPauseMenuShow()
527+
if not CustomChat.frame then return end
529528

530-
if CustomChat.frame.isChatOpen then
531-
chat.Close()
532-
end
533-
end
534-
else
535-
if isGamePaused == true then
536-
isGamePaused = false
537-
CustomChat.frame:SetVisible( true )
538-
end
529+
if CustomChat.frame:IsVisible() then
530+
CustomChat.frame:SetVisible( false )
531+
532+
return false
539533
end
540534
end
541535

@@ -548,6 +542,7 @@ function CustomChat:Enable()
548542
hook.Add( "PlayerBindPress", "CustomChat.OnPlayerBindPress", CustomChat_OnPlayerBindPress )
549543
hook.Add( "HUDShouldDraw", "CustomChat.HUDShouldDraw", CustomChat_HUDShouldDraw )
550544
hook.Add( "Think", "CustomChat.Think", CustomChat_Think )
545+
hook.Add( "OnPauseMenuShow", "CustomChat.OnPauseMenuShow", CustomChat_OnPauseMenuShow )
551546

552547
if IsValid( CustomChat.frame ) then
553548
CustomChat.frame:SetVisible( true )
@@ -567,6 +562,7 @@ function CustomChat:Disable()
567562
hook.Remove( "PlayerBindPress", "CustomChat.OnPlayerBindPress" )
568563
hook.Remove( "HUDShouldDraw", "CustomChat.HUDShouldDraw" )
569564
hook.Remove( "Think", "CustomChat.Think" )
565+
hook.Remove( "OnPauseMenuShow", "CustomChat.OnPauseMenuShow" )
570566

571567
chat.AddText = CustomChat.DefaultAddText
572568
chat.Close = CustomChat.DefaultClose

0 commit comments

Comments
 (0)