Permalink
Browse files

Prop search now auto updates the search results

Still need to add a progress bar that looks decent
  • Loading branch information...
1 parent ca68b67 commit 68393173a353e87a1a17c53d39357db93b6237f1 @robotboy655 robotboy655 committed May 3, 2016
Showing with 30 additions and 38 deletions.
  1. +30 −38 garrysmod/gamemodes/sandbox/gamemode/cl_search_models.lua
@@ -1,13 +1,12 @@
-
local function GetAllFiles( tab, folder, extension, path )
local files, folders = file.Find( folder .. "/*", path )
for k, v in pairs( files ) do
if ( v:EndsWith( extension ) ) then
- table.insert( tab, (folder .. v):lower() )
+ table.insert( tab, ( folder .. v ):lower() )
end
end
@@ -18,13 +17,10 @@ local function GetAllFiles( tab, folder, extension, path )
end )
end
- if ( folder == "models/" ) then
- hook.Run( "SearchUpdate" )
- end
+ hook.Run( "SearchUpdate" )
end
-
local model_list = nil
--
-- Model Search
@@ -37,7 +33,6 @@ search.AddProvider( function( str )
model_list = {}
GetAllFiles( model_list, "models/", ".mdl", "GAME" )
- timer.Simple( 1, function() hook.Run( "SearchUpdate" ) end )
end
@@ -49,15 +44,14 @@ search.AddProvider( function( str )
if ( IsUselessModel( v ) ) then continue end
- local entry =
- {
+ local entry = {
text = v:GetFileFromFilename(),
func = function() RunConsoleCommand( "gm_spawn", v ) end,
icon = spawnmenu.CreateContentIcon( "model", g_SpawnMenu.SearchPropPanel, { model = v } ),
words = { v }
}
-
- table.insert( list, entry )
+
+ table.insert( list, entry )
end
@@ -67,7 +61,7 @@ search.AddProvider( function( str )
return list
-end );
+end )
--
-- Entity, vehicles
@@ -78,58 +72,56 @@ search.AddProvider( function( str )
local results = {}
- local ents = {}
- --table.Add( ents, scripted_ents.GetSpawnable() );
- table.Add( ents, list.Get( "SpawnableEntities" ) );
+ local entities = {}
+ --table.Add( entities, scripted_ents.GetSpawnable() )
+ table.Add( entities, list.Get( "SpawnableEntities" ) )
for k, v in pairs( list.Get( "Vehicles" ) ) do
-
+
v.ClassName = k
v.PrintName = v.Name
v.ScriptedEntityType = 'vehicle'
- table.insert( ents, v )
-
+ table.insert( entities, v )
+
end
-
+
for k, v in pairs( list.Get( "NPC" ) ) do
-
+
v.ClassName = k
v.PrintName = v.Name
v.ScriptedEntityType = 'npc'
- table.insert( ents, v )
-
+ table.insert( entities, v )
+
end
for k, v in pairs( list.Get( "Weapon" ) ) do
-
+
v.ClassName = k
v.PrintName = v.PrintName
v.ScriptedEntityType = 'weapon'
- table.insert( ents, v )
-
+ table.insert( entities, v )
+
end
- for k, v in pairs( ents ) do
+ for k, v in pairs( entities ) do
local name = v.ClassName or v.PrintName
if ( !name ) then continue end
if ( name:lower():find( str ) ) then
- local entry =
- {
+ local entry = {
text = v.PrintName or v.ClassName,
- icon = spawnmenu.CreateContentIcon( v.ScriptedEntityType or "entity", nil,
- {
- nicename = v.PrintName or v.ClassName,
- spawnname = v.ClassName,
- material = "entities/"..v.ClassName..".png",
- admin = v.AdminOnly
- }),
+ icon = spawnmenu.CreateContentIcon( v.ScriptedEntityType or "entity", nil, {
+ nicename = v.PrintName or v.ClassName,
+ spawnname = v.ClassName,
+ material = "entities/"..v.ClassName..".png",
+ admin = v.AdminOnly
+ } ),
words = { v }
}
-
- table.insert( results, entry )
+
+ table.insert( results, entry )
end
@@ -139,4 +131,4 @@ search.AddProvider( function( str )
return results
-end );
+end )

0 comments on commit 6839317

Please sign in to comment.