pace.Materials = {}

pace.Materials.materials =
{
	"models/weapons/v_crowbar/crowbar_cyl",
	"models/weapons/v_crowbar/head_uvw",
	"models/weapons/v_bugbait/bugbait_sheet",
	"models/combine_advisor/arm",
	"models/combine_advisor/hose",
	"models/combine_advisor/face5",
	"models/combine_advisor/body9",
	"models/barnacle/barnacle_sheet",
	"models/headcrab_black/blackcrab_sheet",
	"models/headcrab/allinonebacup2",
	"models/headcrab_classic/headcrabsheet",
	"models/stalker/stalker_sheet",
	"models/zombie_poison/poisonzombie_sheet",
	"models/zombie_fast/fast_zombie_sheet",

	"models/gunship/gunshipsheet",
	"models/shield_scanner/minelayer_sheet",
	"models/roller/rollermine_sheet",
	"models/dog/dog_sheet",
	"models/gibs/combine_helicopter_gibs/combine_helicopter01",
	"models/synth/mainbody",
	"models/combine_room/combine_monitor001",
	"models/items/combinerifle_ammo",
	"models/shadertest/shader2",
	"models/props_combine/combine_train001",
	"models/props_combine/combinethumper001",
	"models/props_combine/health_charger001",
	"models/props_combine/masterinterface01",
	"models/props_combine/introomarea_sheet",
	"models/props_combine/combine_bunker01",
	"models/props_combine/weaponstripper_sheet",
	"models/props_combine/tpcontroller_sheet",
	"models/props_combine/combine_tower01a",
	"models/combine_mine/combine_mine03",
	"models/magnusson_teleporter/magnusson_teleporter",
	"models/combine_strider/strider_brain",
	"models/combine_advisor_pod/combine_advisor_pod",
	"models/magnusson_device/magnusson_device_basecolor",

	"models/antlion_grub/antlion_grub",
	"models/antlion/antlion_worker_wing",
	"models/antlion/antlion_worker",
	"models/ministrider/mini_skin_basecolor",
	"models/ministrider/mini_armor_basecolor",
	"models/spitball/spitball",

	"models/mossman/mossman_hair",
	"models/alyx/hairbits",

	"models/brokenglass/glassbroken_piece1",
	"models/props_halloween/flask",
	"models/props_halloween/flask_liquid",
	"models/props_halloween/flask_glass",
	"models/props_halloween/pumpkin",
	"models/props_mining/dustbowl_roof01",
	"models/props_mvm/mvm_museum_coal",
	"models/effects/partyhat",
	"models/props_gameplay/ball001",
	"models/props_gameplay/orange_cone001",

	"models/player/items/soldier/dappertopper",
	"models/weapons/c_items/c_candy_cane_red",
	"models/props_halloween/halloween_blk",
	"models/props_halloween/halloween_demoeye_glass_2",
	"models/props_halloween/halloween_demoeye_glass",
	"models/weapons/c_items/c_saxxy",
	"models/props_halloween/scary_ghost",
	"models/weapons/c_items/c_urinejar_urine",
	"models/weapons/c_items/c_xms_cold_shoulder",
	"models/props_wasteland/rockcliff02c",
	"models/props_lakeside/flat_wall_02",
	"models/props_manor/table_01b",
	"models/props_manor/volume_light_01",
	"models/props_medieval/stone_base001",
	"models/props_medieval/fort_wall",
	"models/props_mining/quarryrock02",
	"models/props_nature/rock_worn001",
	"models/props_swamp/tallgrass_01",
	"models/props_swamp/shrub_03",
	"models/props_viaduct_event/fog_plane03",
	"models/weapons/v_baseball/baseball_sheet",
	"hunter/myplastic",
	"models/player/items/all_class/all_class_ring_diamond",

	"models/effects/invulnfx_blue",
	"models/effects/invulnfx_red",
	"models/effects/goldenwrench",
	"models/effects/cappoint_beam_neutral",
	"models/effects/cappoint_beam_blue",
	"models/effects/cappoint_beam_red",
	"models/effects/medicyell",
	"models/effects/pyro/pilotlight",
	"models/effects/pyro/pilotlight_cloak",
	"models/effects/pyro/pilotlight_motion",
	"models/effects/invulnerability/invulnerability_red",
	"models/effects/invulnerability/invulnerability_blue",
	"models/effects/muzzleflash/blurmuzzle",
	"models/effects/muzzleflash/brightmuzzle",
	"models/lilchewchew/embers",
	"models/pl_hoodoo/metaldoor001",
	"models/thundermountain_fx/ibeam002_vert",
	"models/thundermountain_fx/wall025_vert",
	"models/thundermountain_fx/wood_beam03_vert",
	"models/thundermountain_fx/wood_bridge001_vert",
	"models/thundermountain_fx/wood_wall002_vert",

	"models/shadertest/envball_1",
	"models/shadertest/envball_2",
	"models/shadertest/envball_3",
	"models/shadertest/envball_4",
	"models/shadertest/envball_5",
	"models/shadertest/envball_6",
	"models/shadertest/glassbrick",
	"models/shadertest/point_camera",
	"models/shadertest/shader1",
	"models/shadertest/shader1_dudv",
	"models/shadertest/shield",
	"models/shadertest/unlitgenericmodel",
	"models/shadertest/vertexlitalphatestedtexture",

	"models/ihvtest/arm",
	"models/ihvtest/boot",
	"models/ihvtest/eyeball_l",

	-- zpankr's material list
	-- http://www.garrysmod.org/downloads/?a=view&id=18470
	"models/wireframe",
	"debug/env_cubemap_model",
	"models/shadertest/shader3",
	"models/shadertest/shader4",
	"models/shadertest/shader5",
	"models/shiny",
	"models/debug/debugwhite",
	"Models/effects/comball_sphere",
	"Models/effects/comball_tape",
	"Models/effects/splodearc_sheet",
	"Models/effects/vol_light001",
	"models/props_combine/stasisshield_sheet",
	"models/props_combine/portalball001_sheet",
	"models/props_combine/com_shield001a",
	"models/props_c17/frostedglass_01a",
	"models/props_lab/Tank_Glass001",
	"models/props_combine/tprings_globe",
	"models/rendertarget",
	"models/screenspace",
	"brick/brick_model",
	"models/props_pipes/GutterMetal01a",
	"models/props_pipes/Pipesystem01a_skin3",
	"models/props_wasteland/wood_fence01a",
	"models/props_c17/FurnitureFabric003a",
	"models/props_c17/FurnitureMetal001a",
	"models/props_c17/paper01",
	"models/flesh",
	"models/airboat/airboat_blur02",
	"models/alyx/emptool_glow",
	"models/antlion/antlion_innards",
	"models/barnacle/roots",
	"models/combine_advisor/body9",
	"models/combine_advisor/mask",
	"models/combine_scanner/scanner_eye",
	"models/debug/debugwhite",
	"models/dog/eyeglass",
	"models/effects/comball_glow1",
	"models/effects/comball_glow2",
	"models/effects/portalrift_sheet",
	"models/effects/slimebubble_sheet",
	"models/effects/splode1_sheet",
	"models/effects/splodearc_sheet",
	"models/effects/splode_sheet",
	"models/effects/vol_light001",
	"models/gibs/woodgibs/woodgibs01",
	"models/gibs/woodgibs/woodgibs02",
	"models/gibs/woodgibs/woodgibs03",
	"models/gibs/metalgibs/metal_gibs",
	"models/items/boxsniperrounds",
	"models/player/player_chrome1",
	"models/props_animated_breakable/smokestack/brickwall002a",
	"models/props_building_details/courtyard_template001c_bars",
	"models/props_building_details/courtyard_template001c_bars",
	"models/props_buildings/destroyedbuilldingwall01a",
	"models/props_buildings/plasterwall021a",
	"models/props_c17/frostedglass_01a",
	"models/props_c17/furniturefabric001a",
	"models/props_c17/furniturefabric002a",
	"models/props_c17/furnituremetal001a",
	"models/props_c17/gate_door02a",
	"models/props_c17/metalladder001",
	"models/props_c17/metalladder002",
	"models/props_c17/metalladder003",
	"models/props_canal/canalmap_sheet",
	"models/props_canal/canal_bridge_railing_01a",
	"models/props_canal/canal_bridge_railing_01b",
	"models/props_canal/canal_bridge_railing_01c",
	"models/props_canal/coastmap_sheet",
	"models/props_canal/metalcrate001d",
	"models/props_canal/metalwall005b",
	"models/props_canal/rock_riverbed01a",
	"models/props_combine/citadel_cable",
	"models/props_combine/combine_interface_disp",
	"models/props_combine/combine_monitorbay_disp",
	"models/props_combine/com_shield001a",
	"models/props_combine/health_charger_glass",
	"models/props_combine/metal_combinebridge001",
	"models/props_combine/pipes01",
	"models/props_combine/pipes03",
	"models/props_combine/prtl_sky_sheet",
	"models/props_combine/stasisfield_beam",
	"models/props_debris/building_template010a",
	"models/props_debris/building_template022j",
	"models/props_debris/composite_debris",
	"models/props_debris/concretefloor013a",
	"models/props_debris/concretefloor020a",
	"models/props_debris/concretewall019a",
	"models/props_debris/metalwall001a",
	"models/props_debris/plasterceiling008a",
	"models/props_debris/plasterwall009d",
	"models/props_debris/plasterwall021a",
	"models/props_debris/plasterwall034a",
	"models/props_debris/plasterwall034d",
	"models/props_debris/plasterwall039c",
	"models/props_debris/plasterwall040c",
	"models/props_debris/tilefloor001c",
	"models/props_foliage/driftwood_01a",
	"models/props_foliage/oak_tree01",
	"models/props_interiors/metalfence007a",
	"models/props_junk/plasticcrate01a",
	"models/props_junk/plasticcrate01b",
	"models/props_junk/plasticcrate01c",
	"models/props_junk/plasticcrate01d",
	"models/props_junk/plasticcrate01e",
	"models/props_lab/cornerunit_cloud",
	"models/props_lab/door_klab01",
	"models/props_lab/security_screens",
	"models/props_lab/security_screens2",
	"models/props_lab/Tank_Glass001",
	"models/props_lab/warp_sheet",
	"models/props_lab/xencrystal_sheet",
	"models/props_pipes/destroyedpipes01a",
	"models/props_pipes/GutterMetal01a",
	"models/props_pipes/pipeset_metal02",
	"models/props_pipes/pipesystem01a_skin1",
	"models/props_pipes/pipesystem01a_skin2",
	"models/props_vents/borealis_vent001",
	"models/props_vents/borealis_vent001b",
	"models/props_vents/borealis_vent001c",
	"models/props_wasteland/concretefloor010a",
	"models/props_wasteland/concretewall064b",
	"models/props_wasteland/concretewall066a",
	"models/props_wasteland/dirtwall001a",
	"models/props_wasteland/metal_tram001a",
	"models/props_wasteland/quarryobjects01",
	"models/props_wasteland/rockcliff02a",
	"models/props_wasteland/rockcliff02b",
	"models/props_wasteland/rockcliff02c",
	"models/props_wasteland/rockcliff04a",
	"models/props_wasteland/rockgranite02a",
	"models/props_wasteland/tugboat01",
	"models/props_wasteland/tugboat02",
	"models/props_wasteland/wood_fence01a",
	"models/props_wasteland/wood_fence01a_skin2",
	"models/roller/rollermine_glow",
	"models/weapons/v_crossbow/rebar_glow",
	"models/weapons/v_crowbar/crowbar_cyl",
	"models/weapons/v_grenade/grenade body",
	"models/weapons/v_smg1/texture5",
	"models/weapons/w_smg1/smg_crosshair",
	"models/weapons/v_slam/new light2",
	"models/weapons/v_slam/new light1",
	"models/props/cs_assault/dollar",
	"models/props/cs_assault/fireescapefloor",
	"models/props/cs_assault/metal_stairs1",
	"models/props/cs_assault/moneywrap",
	"models/props/cs_assault/moneywrap02",
	"models/props/cs_assault/moneytop",
	"models/props/cs_assault/pylon",
	"models/props/CS_militia/boulder01",
	"models/props/CS_militia/milceil001",
	"models/props/CS_militia/militiarock",
	"models/props/CS_militia/militiarockb",
	"models/props/CS_militia/milwall006",
	"models/props/CS_militia/rocks01",
	"models/props/CS_militia/roofbeams01",
	"models/props/CS_militia/roofbeams02",
	"models/props/CS_militia/roofbeams03",
	"models/props/CS_militia/RoofEdges",
	"models/props/cs_office/clouds",
	"models/props/cs_office/file_cabinet2",
	"models/props/cs_office/file_cabinet3",
	"models/props/cs_office/screen",
	"models/props/cs_office/snowmana",
	"models/props/de_inferno/de_inferno_boulder_03",
	"models/props/de_inferno/infflra",
	"models/props/de_inferno/infflrd",
	"models/props/de_inferno/inftowertop",
	"models/props/de_inferno/offwndwb_break",
	"models/props/de_inferno/roofbits",
	"models/props/de_inferno/tileroof01",
	"models/props/de_inferno/woodfloor008a",
	"models/props/de_nuke/nukconcretewalla",
	"models/props/de_nuke/nukecardboard",
	"models/props/de_nuke/pipeset_metal",
	"models/shadertest/predator",
}

pace.Materials.trails =
{
	"trails/plasma",
	"trails/tube",
	"trails/electric",
	"trails/smoke",
	"trails/laser",
	"trails/physbeam",
	"trails/love",
	"trails/lol",
	"sprites/rollermine_shock_yellow",
	"sprites/yellowlaser1",
	"particle/beam_smoke_01",
	"particle/beam_smoke_02",
	"particle/bendibeam_nofog",
	"sprites/physbeam",
	"sprites/physbeama",
	"sprites/rollermine_shock",
	"sprites/hydraspinalcord",
	"particle/Particle_Square_Gradient",
	"particle/Particle_Square_Gradient_NoFog",
}

pace.Materials.sprites =
{
	"sprites/glow04_noz",
	"sprites/grip",
	"sprites/key_0",
	"sprites/key_1",
	"sprites/key_10",
	"sprites/key_11",
	"sprites/key_12",
	"sprites/key_13",
	"sprites/key_14",
	"sprites/key_15",
	"sprites/key_2",
	"sprites/key_3",
	"sprites/key_4",
	"sprites/key_5",
	"sprites/key_6",
	"sprites/key_7",
	"sprites/key_8",
	"sprites/key_9",
	"sprites/light_ignorez",
	"sprites/muzzleflash4",
	"sprites/orangecore1",
	"sprites/orangecore2",
	"sprites/orangeflare1",
	"sprites/physg_glow1",
	"sprites/physg_glow2",
	"sprites/physgbeamb",
	"sprites/redglow1",
	"sprites/animglow02",
	"sprites/ar2_muzzle1",
	"sprites/ar2_muzzle3",
	"sprites/ar2_muzzle4",
	"sprites/arrow",
	"sprites/blueglow2",
	"sprites/bluelaser1",
	"sprites/dot",
	"sprites/flamelet1",
	"sprites/flamelet2",
	"sprites/flamelet3",
	"sprites/flamelet4",
	"sprites/flamelet5",
	"sprites/heatwave",
	"sprites/heatwavedx70",
	"sprites/hydragutbeam",
	"sprites/hydragutbeamcap",
	"sprites/light_glow02_add",
	"sprites/light_glow02_add_noz",
	"sprites/plasmaember",
	"sprites/predator",
	"sprites/qi_center",
	"sprites/reticle",
	"sprites/reticle1",
	"sprites/reticle2",
	"sprites/rico1",
	"sprites/rico1_noz",
	"sprites/scanner",
	"sprites/scanner_bottom",
	"sprites/scanner_dots1",
	"sprites/scanner_dots2",
	"sprites/strider_blackball",
	"sprites/strider_bluebeam",
	"sprites/tp_beam001",
	"sprites/bucket_bat_blue",
	"sprites/bucket_bat_red",
	"sprites/bucket_bonesaw",
	"sprites/bucket_bottle_blue",
	"sprites/bucket_bottle_red",
	"sprites/bucket_fireaxe",
	"sprites/bucket_fists_blue",
	"sprites/bucket_fists_red",
	"sprites/bucket_flamethrower_blue",
	"sprites/bucket_flamethrower_red",
	"sprites/bucket_grenlaunch",
	"sprites/bucket_knife",
	"sprites/bucket_machete",
	"sprites/bucket_medigun_blue",
	"sprites/bucket_medigun_red",
	"sprites/bucket_minigun",
	"sprites/bucket_nailgun",
	"sprites/bucket_pda",
	"sprites/bucket_pda_build",
	"sprites/bucket_pda_destroy",
	"sprites/bucket_pipelaunch",
	"sprites/bucket_pistol",
	"sprites/bucket_revolver",
	"sprites/bucket_rl",
	"sprites/bucket_sapper",
	"sprites/bucket_scatgun",
	"sprites/bucket_shotgun",
	"sprites/bucket_shovel",
	"sprites/bucket_smg",
	"sprites/bucket_sniper",
	"sprites/bucket_syrgun_blue",
	"sprites/bucket_syrgun_red",
	"sprites/bucket_tranq",
	"sprites/bucket_wrench",
	"sprites/healbeam",
	"sprites/healbeam_blue",
	"sprites/healbeam_red",
	"sprites/640_pain_down",
	"sprites/640_pain_left",
	"sprites/640_pain_right",
	"sprites/640_pain_up",
	"sprites/bomb_carried",
	"sprites/bomb_carried_ring",
	"sprites/bomb_carried_ring_offscreen",
	"sprites/bomb_dropped",
	"sprites/bomb_dropped_ring",
	"sprites/bomb_planted",
	"sprites/bomb_planted_ring",
	"sprites/c4",
	"sprites/defuser",
	"sprites/hostage_following",
	"sprites/hostage_following_offscreen",
	"sprites/hostage_rescue",
	"sprites/numbers",
	"sprites/objective_rescue",
	"sprites/objective_site_a",
	"sprites/objective_site_b",
	"sprites/player_blue_dead",
	"sprites/player_blue_dead_offscreen",
	"sprites/player_blue_offscreen",
	"sprites/player_blue_self",
	"sprites/player_blue_small",
	"sprites/player_hostage_dead",
	"sprites/player_hostage_dead_offscreen",
	"sprites/player_hostage_offscreen",
	"sprites/player_hostage_small",
	"sprites/player_radio_ring",
	"sprites/player_radio_ring_offscreen",
	"sprites/player_red_dead",
	"sprites/player_red_dead_offscreen",
	"sprites/player_red_offscreen",
	"sprites/player_red_self",
	"sprites/player_red_small",
	"sprites/player_tick",
	"sprites/radar",
	"sprites/radar_trans",
	"sprites/radio",
	"sprites/scope_arc",
	"sprites/shopping_cart",
	"sprites/spectator_3rdcam",
	"sprites/spectator_eye",
	"sprites/spectator_freecam",
	"sprites/cloudglow1_nofog",
	"sprites/core_beam1",
	"sprites/bluelight",
	"sprites/grav_flare",
	"sprites/grav_light",
	"sprites/orangelight",
	"sprites/portalgun_effects",
	"sprites/sphere_silhouette",
	"sprites/redglow_mp1",
	"sprites/sent_ball",
	"particle/fire",
	"particle/particle_composite",
	"particle/Particle_Crescent",
	"particle/Particle_Crescent_Additive",
	"particle/Particle_Glow_02",
	"particle/Particle_Glow_03",
	"particle/Particle_Glow_03_Additive",
	"particle/Particle_Glow_04",
	"particle/Particle_Glow_04_Additive",
	"particle/Particle_Glow_05",
	"particle/particle_noisesphere",
	"particle/Particle_Ring_Blur",
	"particle/particle_ring_refract_01",
	"particle/Particle_Ring_Sharp",
	"particle/Particle_Ring_Sharp_Additive",
	"particle/Particle_Ring_Wave_8",
	"particle/Particle_Ring_Wave_8_15OB_NoFog",
	"particle/Particle_Ring_Wave_Additive",
	"particle/Particle_Ring_Wave_AddNoFog",
	"particle/particle_smokegrenade",
	"particle/particle_smokegrenade1",
	"particle/particle_sphere",
	"particle/rain",
	"particle/smokesprites_0001",
	"particle/smokesprites_0002",
	"particle/smokesprites_0003",
	"particle/smokesprites_0004",
	"particle/smokesprites_0005",
	"particle/smokesprites_0006",
	"particle/smokesprites_0007",
	"particle/smokesprites_0008",
	"particle/smokesprites_0009",
	"particle/smokesprites_0010",
	"particle/smokesprites_0011",
	"particle/smokesprites_0012",
	"particle/smokesprites_0013",
	"particle/smokesprites_0014",
	"particle/smokesprites_0015",
	"particle/smokesprites_0016",
	"particle/SmokeStack",
	"particle/snow",
	"particle/sparkles",
	"particle/warp1_warp",
	"particle/warp2_warp",
	"particle/warp3_warp_NoZ",
	"particle/warp4_warp",
	"particle/warp4_warp_NoZ",
	"particle/warp5_warp",
	"particle/warp_ripple",
	"particle/glow_haze_nofog",
	"particle/smoke_black_smokestack000",
	"particle/smoke_black_smokestack001",
	"particle/smoke_black_smokestack_all",
	"particle/smokestack_nofog",
	"particle/particle_rockettrail2",
	"particles/balloon_bit",
	"particles/fire1",
	"particles/fire_glow",
	"particles/flamelet1",
	"particles/flamelet2",
	"particles/flamelet3",
	"particles/flamelet4",
	"particles/flamelet5",
	"particles/smokey",
}

local PANEL = {}

PANEL.ClassName = "mat_browser_sheet"
PANEL.Base = "DPanel"

AccessorFunc(PANEL, "m_Selected", "Selected")

function PANEL:Init()
	local list = vgui.Create("DPanelList", self)
		list:SetPadding(2)
		list:SetSpacing(2)
		list:EnableVerticalScrollbar(true)
		list:EnableHorizontal(true)
		list:Dock(FILL)
	self.MatList = list
end

function PANEL:Paint(w, h)
	surface.SetDrawColor(0,0,0, 255)
	surface.DrawRect(0, 0, w, h)
end

local cache = {}
local function IsError(path)
	if cache[path] then return true end
	if Material(path):IsError() then
		cache[path] = truer
		return true
	end
end

function PANEL:SetMaterialList(tbl)
	self:SetSelected()

	self.MaterialList = tbl

	self.MatList:Clear(true)

	for i, material in pairs(self.MaterialList) do
		-- if IsError(material) then continue end

		local image = vgui.Create("DImageButton")
		image.m_Image.LoadMaterial = function(s) s:DoLoadMaterial() end
		image:SetOnViewMaterial(material, material)
		image:SetSize(64, 64)
		image.Value = material

		self.MatList:AddItem(image)

		image.DoClick = function(image) self:SetSelected(image.Value) end

		if self:GetSelected() then
			image.PaintOver = HighlightedButtonPaint
			self:SetSelected(material)
		end
	end

	self:InvalidateLayout(true)
end

pace.RegisterPanel(PANEL)

local PANEL = {}

PANEL.Base = "DFrame"
PANEL.ClassName = "mat_browser"

function PANEL:Init()
	self:SetTitle("materials")

	local list =
	{
		{key = "default", val = table.Merge(list.Get("OverrideMaterials"), pace.Materials.materials)},
		{key = "sprites", val = pace.Materials.sprites},
		{key = "trails", val = pace.Materials.trails},
	}

	local sheet = vgui.Create("DPropertySheet", self)
	sheet:Dock(FILL)

	for _, data in pairs(list) do
		local name, tbl = data.key, data.val
		local pnl = pace.CreatePanel("mat_browser_sheet", self)
		pnl:SetMaterialList(tbl)
		pnl.SetSelected = function(_, path) self:SetSelected(path) end
		sheet:AddSheet(name, pnl)
	end

	local entry = vgui.Create("DTextEntry", self)
		entry.OnEnter = function() self:SetSelected(self.Entry:GetValue()) end
		entry:Dock(BOTTOM)
		entry:SetTall(20)
	self.Entry = entry

	self:SetDrawOnTop(true)
	self:SetSize(300, 300)
	self:SetSizable(true)
	self:Center()
end

function PANEL:SetSelected(value)
	self.Entry:SetText(value or "")

	self.m_Selected = value

	self:MaterialSelected(value)
end

function PANEL:MaterialSelected(path) end

pace.RegisterPanel(PANEL)