From 04ed077977cc76f5ef96a03276b5a31e4edcc2d6 Mon Sep 17 00:00:00 2001 From: StyledStrike Date: Thu, 3 Aug 2023 12:45:06 -0300 Subject: [PATCH 1/4] Add panel visibility hooks --- lua/mapvote/client/modules/map_vote.lua | 1 + lua/mapvote/client/modules/reopen_panel.lua | 1 + lua/mapvote/client/vgui/frame.lua | 2 ++ 3 files changed, 4 insertions(+) diff --git a/lua/mapvote/client/modules/map_vote.lua b/lua/mapvote/client/modules/map_vote.lua index 039788d..1779c13 100644 --- a/lua/mapvote/client/modules/map_vote.lua +++ b/lua/mapvote/client/modules/map_vote.lua @@ -85,6 +85,7 @@ function MapVote.StartVote( maps, endTime ) MapVote.Panel = frame hook.Run( "MapVote_VoteStarted" ) + hook.Run( "MapVote_PanelOpened" ) end hook.Add( "Tick", "MapVote_RequestState", function() diff --git a/lua/mapvote/client/modules/reopen_panel.lua b/lua/mapvote/client/modules/reopen_panel.lua index 8409d08..97a926f 100644 --- a/lua/mapvote/client/modules/reopen_panel.lua +++ b/lua/mapvote/client/modules/reopen_panel.lua @@ -20,6 +20,7 @@ hook.Add( "PlayerButtonDown", "MapVote_ReopenMapvote", function( _, button ) if button ~= KEY_F3 then return end if not IsValid( MapVote.Panel ) then return end MapVote.Panel:SetVisible( true ) + hook.Run( "MapVote_PanelOpened" ) end ) hook.Add( "HUDPaint", "MapVote_DrawOpenNotification", function() diff --git a/lua/mapvote/client/vgui/frame.lua b/lua/mapvote/client/vgui/frame.lua index 9af3aa0..6dcc761 100644 --- a/lua/mapvote/client/vgui/frame.lua +++ b/lua/mapvote/client/vgui/frame.lua @@ -78,6 +78,8 @@ function PANEL:Init() drawCircle( w / 2, h / 2 + 2, r, circleSegments ) end self.btnClose.DoClick = function() + hook.Run( "MapVote_PanelClosed" ) + if self.hideOnClose then self:SetVisible( false ) return From e0b257000d7b842264ccb8c4f247983f3133dd69 Mon Sep 17 00:00:00 2001 From: StyledStrike Date: Fri, 4 Aug 2023 19:39:22 -0300 Subject: [PATCH 2/4] Reorganize panel visibility hooks --- lua/mapvote/client/modules/map_vote.lua | 14 +++++++++++++- lua/mapvote/client/modules/reopen_panel.lua | 1 - lua/mapvote/client/vgui/frame.lua | 2 -- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lua/mapvote/client/modules/map_vote.lua b/lua/mapvote/client/modules/map_vote.lua index 1779c13..7d11685 100644 --- a/lua/mapvote/client/modules/map_vote.lua +++ b/lua/mapvote/client/modules/map_vote.lua @@ -28,6 +28,18 @@ function MapVote.StartVote( maps, endTime ) frame:SetTitle( "" ) frame:SetHideOnClose( true ) + frame._OriginalSetVisible = frame.SetVisible + + frame.SetVisible = function( self, visible ) + self._OriginalSetVisible( self, visible ) + + if visible then + hook.Run( "MapVote_VotePanelOpened" ) + else + hook.Run( "MapVote_VotePanelClosed" ) + end + end + local infoRow = vgui.Create( "Panel", frame ) --[[@as DPanel]] infoRow:Dock( TOP ) infoRow:SetTall( 40 ) @@ -85,7 +97,7 @@ function MapVote.StartVote( maps, endTime ) MapVote.Panel = frame hook.Run( "MapVote_VoteStarted" ) - hook.Run( "MapVote_PanelOpened" ) + hook.Run( "MapVote_VotePanelOpened" ) end hook.Add( "Tick", "MapVote_RequestState", function() diff --git a/lua/mapvote/client/modules/reopen_panel.lua b/lua/mapvote/client/modules/reopen_panel.lua index 97a926f..8409d08 100644 --- a/lua/mapvote/client/modules/reopen_panel.lua +++ b/lua/mapvote/client/modules/reopen_panel.lua @@ -20,7 +20,6 @@ hook.Add( "PlayerButtonDown", "MapVote_ReopenMapvote", function( _, button ) if button ~= KEY_F3 then return end if not IsValid( MapVote.Panel ) then return end MapVote.Panel:SetVisible( true ) - hook.Run( "MapVote_PanelOpened" ) end ) hook.Add( "HUDPaint", "MapVote_DrawOpenNotification", function() diff --git a/lua/mapvote/client/vgui/frame.lua b/lua/mapvote/client/vgui/frame.lua index 6dcc761..9af3aa0 100644 --- a/lua/mapvote/client/vgui/frame.lua +++ b/lua/mapvote/client/vgui/frame.lua @@ -78,8 +78,6 @@ function PANEL:Init() drawCircle( w / 2, h / 2 + 2, r, circleSegments ) end self.btnClose.DoClick = function() - hook.Run( "MapVote_PanelClosed" ) - if self.hideOnClose then self:SetVisible( false ) return From abb051b5228fe35f4275c0cf325093ac58e1e217 Mon Sep 17 00:00:00 2001 From: StyledStrike Date: Fri, 4 Aug 2023 19:39:47 -0300 Subject: [PATCH 3/4] Add panel visibility hooks to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4fddcd1..247d8c9 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,5 @@ You can create file in lua/mapvote/client/plugins and lua/mapvote/server/plugins | MapVote_ChangeMap | Called just before mapvote changes the map, return false to skip | map | server | | MapVote_RTVStart | Called when the vote has been rocked, return false to prevent map vote starting | | server | | MapVote_Loaded | Called when all lua files for mapvote have been loaded | | shared | +| MapVote_VotePanelOpened | Called when the vote panel is shown | | client | +| MapVote_VotePanelClosed | Called when the vote panel is hidden | | client | From 2d1ca3e05ccd2081896f6f4b800112757f0d3416 Mon Sep 17 00:00:00 2001 From: StyledStrike Date: Fri, 4 Aug 2023 20:00:48 -0300 Subject: [PATCH 4/4] Add frame visibility callback --- lua/mapvote/client/modules/map_vote.lua | 6 +----- lua/mapvote/client/vgui/frame.lua | 9 +++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lua/mapvote/client/modules/map_vote.lua b/lua/mapvote/client/modules/map_vote.lua index 7d11685..f9fdc50 100644 --- a/lua/mapvote/client/modules/map_vote.lua +++ b/lua/mapvote/client/modules/map_vote.lua @@ -28,11 +28,7 @@ function MapVote.StartVote( maps, endTime ) frame:SetTitle( "" ) frame:SetHideOnClose( true ) - frame._OriginalSetVisible = frame.SetVisible - - frame.SetVisible = function( self, visible ) - self._OriginalSetVisible( self, visible ) - + frame.OnVisibilityChanged = function( _, visible ) if visible then hook.Run( "MapVote_VotePanelOpened" ) else diff --git a/lua/mapvote/client/vgui/frame.lua b/lua/mapvote/client/vgui/frame.lua index 9af3aa0..90ea719 100644 --- a/lua/mapvote/client/vgui/frame.lua +++ b/lua/mapvote/client/vgui/frame.lua @@ -107,4 +107,13 @@ function PANEL:ApplyBlur() surface.DrawTexturedRect( -x, -y, ScrW(), ScrH()) end +local basePanel = baseclass.Get( "Panel" ) + +function PANEL:SetVisible( v ) + self:OnVisibilityChanged( v ) + return basePanel.SetVisible( self, v ) +end + +function PANEL:OnVisibilityChanged( _ ) end + vgui.Register( "MapVote_Frame", PANEL, "DFrame" )