Permalink
Browse files

Fixed a few spawnmenu errors

  • Loading branch information...
1 parent c02baef commit 08b9b77c9fcc1d9e11424d653c20c0c3c1a559e2 @robotboy655 robotboy655 committed Aug 14, 2014
@@ -1,7 +1,7 @@
local PANEL = {}
-AccessorFunc( PANEL, "m_bHangOpen", "HangOpen" )
+AccessorFunc( PANEL, "m_bHangOpen", "HangOpen" )
function PANEL:Init()
@@ -28,7 +28,7 @@ function PANEL:Open()
self:SetHangOpen( false )
-- If the spawn menu is open, try to close it..
- if ( g_SpawnMenu:IsVisible() ) then
+ if ( g_SpawnMenu:IsVisible() ) then
g_SpawnMenu:Close( true )
end
@@ -71,7 +71,7 @@ end
function PANEL:Close( bSkipAnim )
- if ( self:GetHangOpen() ) then
+ if ( self:GetHangOpen() ) then
self:SetHangOpen( false )
return
end
@@ -98,7 +98,7 @@ function PANEL:PerformLayout()
self.Canvas:SetWide( 311 )
self.Canvas:SetPos( ScrW() - self.Canvas:GetWide() - 50, self.y )
- if ( spawnmenu.ActiveControlPanel() ) then
+ if ( IsValid( spawnmenu.ActiveControlPanel() ) ) then
spawnmenu.ActiveControlPanel():InvalidateLayout( true )
@@ -153,7 +153,12 @@ vgui.Register( "ContextMenu", PANEL, "EditablePanel" )
function CreateContextMenu()
-
+
+ if ( IsValid( g_ContextMenu ) ) then
+ g_ContextMenu:Remove()
+ g_ContextMenu = nil
+ end
+
g_ContextMenu = vgui.Create( "ContextMenu" )
g_ContextMenu:SetVisible( false )
@@ -231,8 +236,8 @@ function GM:OnContextMenuOpen()
-- Let the gamemode decide whether we should open or not..
if ( !hook.Call( "ContextMenuOpen", GAMEMODE ) ) then return end
- if ( IsValid( g_ContextMenu ) && !g_ContextMenu:IsVisible() ) then
- g_ContextMenu:Open()
+ if ( IsValid( g_ContextMenu ) && !g_ContextMenu:IsVisible() ) then
+ g_ContextMenu:Open()
menubar.ParentTo( g_ContextMenu )
end
@@ -241,8 +246,8 @@ end
function GM:OnContextMenuClose()
- if ( IsValid( g_ContextMenu ) ) then
- g_ContextMenu:Close()
+ if ( IsValid( g_ContextMenu ) ) then
+ g_ContextMenu:Close()
end
end
@@ -87,7 +87,7 @@ function PANEL:Open()
self.m_bHangOpen = false
-- If the context menu is open, try to close it..
- if ( g_ContextMenu:IsVisible() ) then
+ if ( g_ContextMenu:IsVisible() ) then
g_ContextMenu:Close( true )
end
@@ -110,7 +110,7 @@ end
-----------------------------------------------------------]]
function PANEL:Close( bSkipAnim )
- if ( self.m_bHangOpen ) then
+ if ( self.m_bHangOpen ) then
self.m_bHangOpen = false
return
end
@@ -142,7 +142,7 @@ function PANEL:PerformLayout()
self.ToolMenu:DockMargin( 0, MarginY, MarginX, MarginY )
self.ToolToggle:AlignRight( 2 )
- self.ToolToggle:AlignTop( 2 )
+ self.ToolToggle:AlignTop( 2 )
end
@@ -154,9 +154,7 @@ function PANEL:StartKeyFocus( pPanel )
self.m_pKeyFocus = pPanel
self:SetKeyboardInputEnabled( true )
self:HangOpen( true )
-
- g_ContextMenu:StartKeyFocus( pPanel )
-
+
end
--[[---------------------------------------------------------
@@ -166,8 +164,6 @@ function PANEL:EndKeyFocus( pPanel )
if ( self.m_pKeyFocus != pPanel ) then return end
self:SetKeyboardInputEnabled( false )
-
- g_ContextMenu:EndKeyFocus( pPanel )
end
@@ -180,7 +176,7 @@ vgui.Register( "SpawnMenu", PANEL, "EditablePanel" )
local function CreateSpawnMenu()
-- If we have an old spawn menu remove it.
- if ( g_SpawnMenu ) then
+ if ( IsValid( g_SpawnMenu ) ) then
g_SpawnMenu:Remove()
g_SpawnMenu = nil
@@ -218,15 +214,18 @@ local function CreateSpawnMenu()
hook.Run( "PostReloadToolsMenu" )
end
+-- Hook to create the spawnmenu at the appropriate time (when all sents and sweps are loaded)
+hook.Add( "OnGamemodeLoaded", "CreateSpawnMenu", CreateSpawnMenu )
+concommand.Add( "spawnmenu_reload", CreateSpawnMenu )
function GM:OnSpawnMenuOpen()
-- Let the gamemode decide whether we should open or not..
if ( !hook.Call( "SpawnMenuOpen", GAMEMODE ) ) then return end
- if ( g_SpawnMenu ) then
+ if ( IsValid( g_SpawnMenu ) ) then
- g_SpawnMenu:Open()
+ g_SpawnMenu:Open()
menubar.ParentTo( g_SpawnMenu )
end
@@ -235,7 +234,7 @@ end
function GM:OnSpawnMenuClose()
- if ( g_SpawnMenu ) then g_SpawnMenu:Close() end
+ if ( IsValid( g_SpawnMenu ) ) then g_SpawnMenu:Close() end
-- We're dragging from the spawnmenu but the spawnmenu is closed
-- so keep the dragging going using the screen clicker
@@ -245,23 +244,20 @@ function GM:OnSpawnMenuClose()
end
--- Hook to create the spawnmenu at the appropriate time (when all sents and sweps are loaded)
-hook.Add( "OnGamemodeLoaded", "CreateSpawnMenu", CreateSpawnMenu )
-
-
--[[---------------------------------------------------------
Name: HOOK SpawnMenuKeyboardFocusOn
Called when text entry needs keyboard focus
-----------------------------------------------------------]]
local function SpawnMenuKeyboardFocusOn( pnl )
- if ( !ValidPanel( g_SpawnMenu ) && !ValidPanel( g_ContextMenu ) ) then return end
- if ( IsValid( pnl ) && !pnl:HasParent( g_SpawnMenu ) && !pnl:HasParent( g_ContextMenu ) ) then return end
-
- g_SpawnMenu:StartKeyFocus( pnl )
+ if ( IsValid( g_SpawnMenu ) && IsValid( pnl ) && pnl:HasParent( g_SpawnMenu ) ) then
+ g_SpawnMenu:StartKeyFocus( pnl )
+ end
+ if ( IsValid( g_ContextMenu ) && IsValid( pnl ) && pnl:HasParent( g_ContextMenu ) ) then
+ g_ContextMenu:StartKeyFocus( pnl )
+ end
end
-
hook.Add( "OnTextEntryGetFocus", "SpawnMenuKeyboardFocusOn", SpawnMenuKeyboardFocusOn )
@@ -271,13 +267,15 @@ hook.Add( "OnTextEntryGetFocus", "SpawnMenuKeyboardFocusOn", SpawnMenuKeyboardFo
-----------------------------------------------------------]]
local function SpawnMenuKeyboardFocusOff( pnl )
- if ( !ValidPanel( g_SpawnMenu ) && !ValidPanel( g_ContextMenu ) ) then return end
- if ( IsValid( pnl ) && !pnl:HasParent( g_SpawnMenu ) && !pnl:HasParent( g_ContextMenu ) ) then return end
-
- g_SpawnMenu:EndKeyFocus( pnl )
+ if ( IsValid( g_SpawnMenu ) && IsValid( pnl ) && pnl:HasParent( g_SpawnMenu ) ) then
+ g_SpawnMenu:EndKeyFocus( pnl )
+ end
-end
+ if ( IsValid( g_ContextMenu ) && IsValid( pnl ) && pnl:HasParent( g_ContextMenu ) ) then
+ g_ContextMenu:EndKeyFocus( pnl )
+ end
+end
hook.Add( "OnTextEntryLoseFocus", "SpawnMenuKeyboardFocusOff", SpawnMenuKeyboardFocusOff )
--[[---------------------------------------------------------
@@ -286,13 +284,12 @@ hook.Add( "OnTextEntryLoseFocus", "SpawnMenuKeyboardFocusOff", SpawnMenuKeyboard
-----------------------------------------------------------]]
local function SpawnMenuOpenGUIMousePressed()
- if ( !ValidPanel( g_SpawnMenu ) ) then return end
+ if ( !IsValid( g_SpawnMenu ) ) then return end
if ( !g_SpawnMenu:IsVisible() ) then return end
return true
end
-
hook.Add( "GUIMousePressed", "SpawnMenuOpenGUIMousePressed", SpawnMenuOpenGUIMousePressed )
--[[---------------------------------------------------------
@@ -8,11 +8,16 @@ function menubar.Init()
menubar.Control:SetVisible( false )
hook.Run( "PopulateMenuBar", menubar.Control )
-
+
end
function menubar.ParentTo( pnl )
+ // I don't like this
+ if ( !IsValid( menubar.Control ) ) then
+ menubar.Init()
+ end
+
menubar.Control:SetParent( pnl )
menubar.Control:MoveToBack()
menubar.Control:SetHeight( 30 )
@@ -21,12 +26,14 @@ function menubar.ParentTo( pnl )
end
function menubar.IsParent( pnl )
+
return menubar.Control:GetParent() == pnl
+
end
hook.Add( "OnGamemodeLoaded", "CreateMenuBar", function()
menubar.Init()
-end )
+end )

0 comments on commit 08b9b77

Please sign in to comment.