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 | diff --git a/lua/mapvote/client/modules/map_vote.lua b/lua/mapvote/client/modules/map_vote.lua index 039788d..f9fdc50 100644 --- a/lua/mapvote/client/modules/map_vote.lua +++ b/lua/mapvote/client/modules/map_vote.lua @@ -28,6 +28,14 @@ function MapVote.StartVote( maps, endTime ) frame:SetTitle( "" ) frame:SetHideOnClose( true ) + frame.OnVisibilityChanged = function( _, 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,6 +93,7 @@ function MapVote.StartVote( maps, endTime ) MapVote.Panel = frame hook.Run( "MapVote_VoteStarted" ) + hook.Run( "MapVote_VotePanelOpened" ) end hook.Add( "Tick", "MapVote_RequestState", function() 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" )