Skip to content

Commit

Permalink
Fixed spawnmenu_reload duplicating spawnlists
Browse files Browse the repository at this point in the history
After changing spawnlists
  • Loading branch information
robotboy655 committed May 4, 2016
1 parent 6839317 commit 1baf0c4
Showing 1 changed file with 39 additions and 60 deletions.
99 changes: 39 additions & 60 deletions garrysmod/lua/includes/modules/spawnmenu.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@

local spawnmenu_engine = spawnmenu

--[[---------------------------------------------------------
-----------------------------------------------------------]]

module( "spawnmenu", package.seeall )


local g_ToolMenu = {}
local CreationMenus = {}
local PropTable = {}
Expand Down Expand Up @@ -43,90 +38,74 @@ function GetToolMenu( name, label, icon )
icon = icon or "icon16/wrench.png"

for k, v in ipairs( g_ToolMenu ) do

if ( v.Name == name ) then return v.Items end

end

local NewMenu = { Name = name, Items = {}, Label = label, Icon = icon }
table.insert( g_ToolMenu, NewMenu )

--
-- Order the tabs by NAME
--
table.SortByMember( g_ToolMenu, "Name", true )

return NewMenu.Items

end

end

--[[---------------------------------------------------------
-----------------------------------------------------------]]
function ClearToolMenus()
g_ToolMenu = {}
g_ToolMenu = {}
end


--[[---------------------------------------------------------
-----------------------------------------------------------]]
function AddToolTab( strName, strLabel, Icon )

GetToolMenu( strName, strLabel, Icon )

end



--[[---------------------------------------------------------
-----------------------------------------------------------]]
function AddToolCategory( tab, RealName, PrintName )

local tab = GetToolMenu( tab )

-- Does this category already exist?
for k, v in ipairs( tab ) do

if ( v.Text == PrintName ) then return end
if ( v.ItemName == RealName ) then return end

end

table.insert( tab, { Text = PrintName, ItemName = RealName } )

end

--[[---------------------------------------------------------
-----------------------------------------------------------]]
function AddToolMenuOption( tab, category, itemname, text, command, controls, cpanelfunction, TheTable )

local Menu = GetToolMenu( tab )
local CategoryTable = nil

for k, v in ipairs( Menu ) do
if ( v.ItemName && v.ItemName == category ) then CategoryTable = v break end
end

-- No table found.. lets create one
if ( !CategoryTable ) then
CategoryTable = { Text = "#"..category, ItemName = category }
table.insert( Menu, CategoryTable )
end

TheTable = TheTable or {}

TheTable.ItemName = itemname
TheTable.Text = text
TheTable.Command = command
TheTable.Controls = controls
TheTable.CPanelFunction = cpanelfunction

table.insert( CategoryTable, TheTable )

-- Keep the table sorted
table.SortByMember( CategoryTable, "Text", true )

Expand All @@ -140,7 +119,7 @@ function AddCreationTab( strName, pFunction, pMaterial, iOrder, strTooltip )
iOrder = iOrder or 1000

pMaterial = pMaterial or "icon16/exclamation.png"

CreationMenus[ strName ] = { Function = pFunction, Icon = pMaterial, Order = iOrder, Tooltip = strTooltip }

end
Expand All @@ -150,17 +129,16 @@ end
-----------------------------------------------------------]]
function GetCreationTabs()

return CreationMenus
return CreationMenus

end


--[[---------------------------------------------------------
GetPropTable
-----------------------------------------------------------]]
function GetPropTable()

return PropTable
return PropTable

end

Expand All @@ -169,18 +147,18 @@ end
-----------------------------------------------------------]]
function AddPropCategory( strFilename, strName, tabContents, icon, id, parentid, needsapp )

id = id or math.random( 1000, 9999 )
parentid = parentid or 0
id = id or math.random( 1000, 9999 )
parentid = parentid or 0

PropTable[ strFilename ] = {

name = strName,
icon = icon,
id = id,
parentid = parentid,
contents = tabContents,
needsapp = needsapp

}

end
Expand All @@ -190,6 +168,10 @@ end
-----------------------------------------------------------]]
function PopulateFromEngineTextFiles()

-- Reset the already loaded prop list before loading them again.
-- This caused the spawnlists to duplicate into crazy trees when spawnmenu_reload'ing after saving edited spawnlists
PropTable = {}

spawnmenu_engine.PopulateFromTextFiles( AddPropCategory )

end
Expand All @@ -203,7 +185,6 @@ function DoSaveToTextFiles( props )

end


--[[
Content Providers
Expand All @@ -221,8 +202,6 @@ spawnmenu.AddContentType( "model", MyFunction )
--]]



local cp = {}

function AddContentType( name, func )
Expand All @@ -232,10 +211,10 @@ end
function GetContentType( name, func )

if ( !cp[ name ] ) then

cp[ name ] = function() end
Msg( "spawnmenu.GetContentType( ", name, " ) - not found!\n" )

end

return cp[ name ]
Expand All @@ -245,29 +224,29 @@ function CreateContentIcon( type, parent, tbl )

local cp = GetContentType( type )
if ( cp ) then return cp( parent, tbl ) end

end

function SwitchToolTab( id )

local Tab = g_SpawnMenu:GetToolMenu():GetToolPanel( id )
if ( !IsValid( Tab ) ) then return end
if ( !IsValid( Tab ) ) then return end

--Tab:GetParent():GetParent().Tab:DoClick()

end

function ActivateToolPanel( id, cp )

local Tab = g_SpawnMenu:GetToolMenu():GetToolPanel( id )
if ( !IsValid( Tab ) ) then return end
if ( !IsValid( Tab ) ) then return end

spawnmenu.SetActiveControlPanel( cp )

if ( cp ) then
Tab:SetActive( cp )
end

SwitchToolTab( id )

end
Expand All @@ -285,7 +264,7 @@ function ActivateTool( strName, noCommand )
if ( !noCommand && item.Command ) then
RunConsoleCommand( unpack( string.Explode( " ", item.Command ) ) )
end

local cp = controlpanel.Get( strName )
if ( !cp:GetInitialized() ) then
cp:FillViaTable( { Text = item.Text, ControlPanelBuildFunction = item.CPanelFunction, Controls = item.Controls } )
Expand All @@ -294,7 +273,7 @@ function ActivateTool( strName, noCommand )
ActivateToolPanel( tab, cp )

break

end

end
Expand Down

0 comments on commit 1baf0c4

Please sign in to comment.