Permalink
Browse files

Sort addons and games alphabetically in Browse

It is a pain to search for specific addon when you have many installed.
  • Loading branch information...
1 parent 2f1fd73 commit ec4f5e1f2852d32291319d0dd126343f15fcbabc @robotboy655 robotboy655 committed May 29, 2014
@@ -7,9 +7,9 @@ local function AddRecursive( pnl, folder, path, wildcard )
if ( !string.EndsWith( v, ".mdl" ) ) then continue end
- local cp = spawnmenu.GetContentType( "model" );
- if ( cp ) then
- cp( pnl, { model = folder .. v } )
+ local cp = spawnmenu.GetContentType( "model" )
+ if ( cp ) then
+ cp( pnl, { model = folder .. v } )
end
end
@@ -26,27 +26,24 @@ end
hook.Add( "PopulateContent", "AddonProps", function( pnlContent, tree, node )
local ViewPanel = vgui.Create( "ContentContainer", pnlContent )
- ViewPanel:SetVisible( false );
+ ViewPanel:SetVisible( false )
- local MyNode = node:AddNode( "#spawnmenu.category.addons", "icon16/folder_database.png" );
+ local MyNode = node:AddNode( "#spawnmenu.category.addons", "icon16/folder_database.png" )
- local addons = engine.GetAddons()
- for _, addon in SortedPairs( addons ) do
-
- if ( !addon.downloaded ) then continue end
- if ( !addon.mounted ) then continue end
-
- if ( addon.models <= 0 ) then continue end
+ for _, addon in SortedPairsByMemberValue( engine.GetAddons(), "title" ) do
+
+ if ( !addon.downloaded || !addon.mounted ) then continue end
+ if ( addon.models <= 0 ) then continue end
- local models = MyNode:AddNode( addon.title .. " ("..addon.models..")", "icon16/bricks.png" );
- models.DoClick = function()
+ local models = MyNode:AddNode( addon.title .. " ("..addon.models..")", "icon16/bricks.png" )
+ models.DoClick = function()
- ViewPanel:Clear( true )
- AddRecursive( ViewPanel, "models/", addon.title, "*.mdl" )
- pnlContent:SwitchPanel( ViewPanel )
+ ViewPanel:Clear( true )
+ AddRecursive( ViewPanel, "models/", addon.title, "*.mdl" )
+ pnlContent:SwitchPanel( ViewPanel )
- end
-
end
+
+ end
end )
@@ -1,48 +1,48 @@
local function AddBrowseContent( ViewPanel, node, name, icon, path, pathid, pnlContent )
- local models = node:AddFolder( name, path .. "models", pathid, false );
- models:SetIcon( icon )
- models.BrowseContentType = "models";
- models.BrowseExtension = "*.mdl";
- models.ContentType = "model";
- models.ViewPanel = ViewPanel;
+ local models = node:AddFolder( name, path .. "models", pathid, false )
+ models:SetIcon( icon )
+ models.BrowseContentType = "models"
+ models.BrowseExtension = "*.mdl"
+ models.ContentType = "model"
+ models.ViewPanel = ViewPanel
- --
- -- If we click on a subnode of this tree, it gets reported upwards (to us)
- --
- models.OnNodeSelected = function( slf, node )
+ --
+ -- If we click on a subnode of this tree, it gets reported upwards (to us)
+ --
+ models.OnNodeSelected = function( slf, node )
- -- Already viewing this panel
- if ( ViewPanel && ViewPanel.CurrentNode && ViewPanel.CurrentNode == node ) then return end
+ -- Already viewing this panel
+ if ( ViewPanel && ViewPanel.CurrentNode && ViewPanel.CurrentNode == node ) then return end
- -- Clear the viewpanel in preperation for displaying it
- ViewPanel:Clear( true )
- ViewPanel.CurrentNode = node;
-
- --
- -- Fill the viewpanel with models that are in this node's folder
- --
- local Path = node:GetFolder()
- local SearchString = Path .. "/*.mdl";
+ -- Clear the viewpanel in preperation for displaying it
+ ViewPanel:Clear( true )
+ ViewPanel.CurrentNode = node
+
+ --
+ -- Fill the viewpanel with models that are in this node's folder
+ --
+ local Path = node:GetFolder()
+ local SearchString = Path .. "/*.mdl"
- local Models = file.Find( SearchString, node:GetPathID() )
- for k, v in pairs( Models ) do
+ local Models = file.Find( SearchString, node:GetPathID() )
+ for k, v in pairs( Models ) do
- local cp = spawnmenu.GetContentType( "model" );
- if ( cp ) then
- cp( ViewPanel, { model = Path .. "/" .. v } )
- end
-
+ local cp = spawnmenu.GetContentType( "model" )
+ if ( cp ) then
+ cp( ViewPanel, { model = Path .. "/" .. v } )
end
+
+ end
- --
- -- Switch to it
- --
- pnlContent:SwitchPanel( ViewPanel )
- ViewPanel.CurrentNode = node
+ --
+ -- Switch to it
+ --
+ pnlContent:SwitchPanel( ViewPanel )
+ ViewPanel.CurrentNode = node
- end
+ end
end
@@ -54,24 +54,33 @@ hook.Add( "PopulateContent", "GameProps", function( pnlContent, tree, node )
--
-- Create a node in the `other` category on the tree
--
- local MyNode = node:AddNode( "#spawnmenu.category.games", "icon16/folder_database.png" );
-
- local ViewPanel = vgui.Create( "ContentContainer", pnlContent )
- ViewPanel:SetVisible( false );
+ local MyNode = node:AddNode( "#spawnmenu.category.games", "icon16/folder_database.png" )
+
+ local ViewPanel = vgui.Create( "ContentContainer", pnlContent )
+ ViewPanel:SetVisible( false )
- AddBrowseContent( ViewPanel, MyNode, "All", "games/16/all.png", "", "GAME", pnlContent );
- AddBrowseContent( ViewPanel, MyNode, "Garry's Mod", "games/16/garrysmod.png", "", "garrysmod", pnlContent );
+ local games = engine.GetGames()
+ table.insert( games, {
+ title = "All",
+ folder = "GAME",
+ icon = "all",
+ mounted = true
+ } )
+ table.insert( games, {
+ title = "Garry's Mod",
+ folder = "garrysmod",
+ mounted = true
+ } )
- --
- -- Create a list of mounted games, allowing us to browse them
- --
- local games = engine.GetGames()
- for _, game in SortedPairs( games ) do
+ --
+ -- Create a list of mounted games, allowing us to browse them
+ --
+ for _, game in SortedPairsByMemberValue( games, "title" ) do
- if ( !game.mounted ) then continue end
+ if ( !game.mounted ) then continue end
- AddBrowseContent( ViewPanel, MyNode, game.title, "games/16/" .. game.folder .. ".png", "", game.folder, pnlContent )
+ AddBrowseContent( ViewPanel, MyNode, game.title, "games/16/" .. ( game.icon or game.folder ) .. ".png", "", game.folder, pnlContent )
- end
+ end
end )

0 comments on commit ec4f5e1

Please sign in to comment.