From 0a134b81cc62e25cdf1e94f014b5c460e14c4dd1 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 7 May 2016 16:28:16 -0400 Subject: Various refactoring --- gamemode/cl_qmenu.lua | 125 --------------------------------------- gamemode/client/cl_inventory.lua | 63 ++------------------ gamemode/configure_me.lua | 19 +++++- gamemode/shared.lua | 39 +----------- 4 files changed, 24 insertions(+), 222 deletions(-) (limited to 'gamemode') diff --git a/gamemode/cl_qmenu.lua b/gamemode/cl_qmenu.lua index f5e8740..ebac4e6 100644 --- a/gamemode/cl_qmenu.lua +++ b/gamemode/cl_qmenu.lua @@ -99,131 +99,6 @@ end vgui.Register( "stranded_propspawn", PANEL, "DPanelList" ) -/* DToolMenu */ -local PANEL = {} - -function PANEL:Init() - self.Tools = vgui.Create( "DPanelList", self ) - self.Tools:EnableVerticalScrollbar( true ) - self.Tools:SetAutoSize( false ) - self.Tools:SetSpacing( 5 ) - self.Tools:SetPadding( 5 ) - function self.Tools:Paint() - draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 75, 75, 75 ) ) - end - - self.ContextPanel = vgui.Create( "DPanelList", self ) - self.ContextPanel:EnableVerticalScrollbar( false ) - self.ContextPanel:SetSpacing( 0 ) - self.ContextPanel:SetPadding( 5 ) - function self.ContextPanel:Paint() - draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 255, 255, 255, 150 ) ) - end - - if ( ToolsLoad == false || ToolsLoad == nil || ToolsLoad == NULL || ToolsLoad == "" ) then - AllTools = spawnmenu.GetTools() - local ToolsLoad = true - end - - local ToolTables = AllTools - - if ( !ToolTables ) then LocalPlayer():ChatPrint( "ERROR: Tools List could not be loaded." ) return end - - for k, v in pairs( ToolTables[1].Items ) do - if ( type( v ) == "table" ) then - local Name = v.ItemName - local Label = v.Text - v.ItemName = nil - v.Text = nil - self:AddCategory( Name, Label, v ) - end - end -end - -function PANEL:AddCategory( Name, Label, ToolItems ) - self.Category = vgui.Create( "DCollapsibleCategory" ) - self.Tools:AddItem( self.Category ) - self.Category:SetLabel( Label ) - self.Category:SetCookieName( "ToolMenu." .. tostring( Name ) ) - - self.CategoryContent = vgui.Create( "DPanelList" ) - self.CategoryContent:SetAutoSize( true ) - self.CategoryContent:SetDrawBackground( false ) - self.CategoryContent:SetSpacing( 0 ) - self.CategoryContent:SetPadding( 0 ) - self.Category:SetContents( self.CategoryContent ) - - local bAlt = true - local NumTools = 0 - - for k, v in pairs( ToolItems ) do - if ( table.HasValue( GMS.ProhibitedStools, v.ItemName ) && !LocalPlayer():IsAdmin() ) then continue end - NumTools = NumTools + 1 - - local Item = vgui.Create( "ToolMenuButton", self ) - Item:SetText( v.Text ) - Item.OnSelect = function( button ) self:EnableControlPanel( button ) end - concommand.Add( Format( "tool_%s", v.ItemName ), function() Item:OnSelect() end ) - - if ( v.SwitchConVar ) then - Item:AddCheckBox( v.SwitchConVar ) - end - - Item.ControlPanelBuildFunction = v.CPanelFunction - Item.Command = v.Command - Item.Name = v.ItemName - Item.Controls = v.Controls - Item.Text = v.Text - - Item:SetAlt( bAlt ) - bAlt = !bAlt - - self.CategoryContent:AddItem( Item ) - end - - if ( NumTools <= 0 ) then - self.Category:Remove() - self.CategoryContent:Remove() - end -end - -function PANEL:EnableControlPanel( button ) - if ( self.LastSelected ) then - self.LastSelected:SetSelected( false ) - end - - button:SetSelected( true ) - self.LastSelected = button - - local cp = controlpanel.Get( button.Name ) - if ( !cp:GetInitialized() ) then - cp:FillViaTable( button ) - end - - self.ContextPanel:Clear() - self.ContextPanel:AddItem( cp ) - self.ContextPanel:Rebuild() - - g_ActiveControlPanel = cp - - if ( button.Command ) then - LocalPlayer():ConCommand( button.Command ) - end -end - -function PANEL:Paint() -end - -function PANEL:PerformLayout() - self:StretchToParent( 0, 21, 0, 5 ) - self.Tools:SetPos( 5, 5 ) - self.Tools:SetSize( self:GetWide() * 0.35, self:GetTall() - 5 ) - self.ContextPanel:SetPos( self:GetWide() * 0.35 + 10, 5 ) - self.ContextPanel:SetSize( self:GetWide() - ( self:GetWide() * 0.35 ) - 14, self:GetTall() - 5 ) -end - -vgui.Register( "stranded_toolmenu", PANEL, "DPanel" ) - /* DCommandsMenu */ local PANEL = {} diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua index 598ca97..c4e1134 100644 --- a/gamemode/client/cl_inventory.lua +++ b/gamemode/client/cl_inventory.lua @@ -10,58 +10,38 @@ local dPanelHeight = 400 local curDisplay = nil local buttons = { - - { - txt = "Inventory", admin = false, - }, { - txt = "Structures", admin = false, - }, { - txt = "Combinations", admin = false, - }, { - txt = "Equipment", admin = false, - }, { - txt = "Props", admin = false, - }, { - txt = "Tools", admin = false, - }, { - txt = "Prop Protection", admin = false, - }, { - txt = "Admin", admin = true, - }, - - } surface.CreateFont( "gmNameFont", { @@ -512,10 +492,7 @@ local PANEL = {} function PANEL:Init() self.ActiveTool = "Weld" self.Tools = vgui.Create( "DListLayout", self ) - --self.Tools:EnableVerticalScrollbar( true ) self.Tools:SetSize(dPanelWidth/3, dPanelWidth) - --self.Tools:SetSpacing( 5 ) - --self.Tools:SetPadding( 5 ) function self.Tools:Paint() draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 75, 75, 75 ) ) end @@ -593,39 +570,6 @@ function PANEL:Init() GetConVar(colorvars["Blue"]):SetInt(t.b) end self.cp:AddItem(color,color_cube) - --[[ - elseif(type == "ComboBox") then - - print("Createing combo box!") - local DComboBox, label = self.cp:ComboBox(table.Label, nil) - for k,v in pairs(table.Options) do - DComboBox:AddChoice(k,v) - end - DComboBox.OnSelect = function( panel, index, value ) - for k,v in pairs(table.Options[value]) do - print("Setting " .. k .. " to " .. v) - GetConVar(k):SetInt(v) - end - end - print("Adding combo box to control") - self.cp:AddItem(DComboBox) - print("Done!") - elseif(type == "PropSelect") then - local grid = vgui.Create( "DGrid" ) - grid:SetPos( 10, 30 ) - grid:SetCols( 5 ) - grid:SetColWide( 36 ) - for k,v in pairs(table.Models) do - local icon = vgui.Create( "DModelPanel", Panel ) - icon:SetSize( 32, 32 ) - icon:SetModel( k ) - icon.DoClick = function() - GetConVar(table.ConVar):SetString(k) - end - grid:AddItem(icon) - end - self.cp:AddItem(grid) - ]] elseif(type == "Label") then self.cp:AddItem(vgui.Create("DLabel"):SetText(table.Text)) elseif(type == "Button") then @@ -653,10 +597,11 @@ function PANEL:Init() for k,v in pairs(spawnmenu.GetTools()[1]["Items"]) do for i,j in pairs(v) do if(istable(j)) then - local isprohibitied = false - for l,m in pairs(GMS.ProhibitedStools) do + local isprohibitied = true + for l,m in pairs(GMS.AllowedStools) do + print("Checking: " .. j.ItemName) if(j.ItemName == m) then - isprohibitied = true + isprohibitied = false end end if(!isprohibitied) then diff --git a/gamemode/configure_me.lua b/gamemode/configure_me.lua index 543dae2..c813a26 100644 --- a/gamemode/configure_me.lua +++ b/gamemode/configure_me.lua @@ -31,7 +31,23 @@ GMS.LootableNPCs = { GMS.Developers = { "STEAM_0:0:0" //the single-player steamid } - +GMS.AllowedStools = { + "percision", + "axis", + "ballsocket", + "elastic", + "precision_align", + "gms_rope", + "weld", + "Winch", + "lamp", + "light", + "nocollide", + "remover", + "colour", + "material", +} +--[[ GMS.ProhibitedStools = { "hydraulic", "motor", @@ -66,3 +82,4 @@ GMS.ProhibitedStools = { "rtcamera", "rb655_lightsaber" } +]] diff --git a/gamemode/shared.lua b/gamemode/shared.lua index 5588e1f..585cd0e 100644 --- a/gamemode/shared.lua +++ b/gamemode/shared.lua @@ -244,6 +244,8 @@ end function GM:CanTool( ply, tr, mode ) + if ( !table.HasValue(GMS.AllowedStools, mode) && !ply:IsAdmin()) then ply:SendMessage( "This tool is prohibited.", 3, Color( 200, 0, 0, 255 ) ) return false end + if ( mode == "gms_rope" ) then if ( SERVER && ply:GetResource( "Rope" ) < 1 ) then ply:SendMessage( "You need rope to use this tool.", 3, Color( 200, 0, 0, 255 ) ) return false end if ( CLIENT && ( !Resources[ "Rope" ] || Resources[ "Rope" ] < 1 ) ) then return false end @@ -254,8 +256,6 @@ function GM:CanTool( ply, tr, mode ) if ( CLIENT && ( !Resources[ "Welder" ] || Resources[ "Welder" ] < 1 ) ) then return false end end - if ( table.HasValue( GMS.ProhibitedStools, mode ) && !ply:IsAdmin() ) then ply:SendMessage( "This tool is prohibited.", 3, Color( 200, 0, 0, 255 ) ) return false end - local ent = tr.Entity if ( !IsValid( ent ) && ent:GetClass() != "worldspawn" ) then return end @@ -862,41 +862,6 @@ GMS.StructureEntities = { "gms_runicinfuser" } -GMS.ProhibitedStools = { - "hydraulic", - "motor", - "muscle", - "nail", - "pulley", - "slider", - "balloon", - "rope", // We use gms_rope - "button", - "duplicator", - "dynamite", - "emitter", - "hoverball", - "ignite", - "keepupright", - "magnetise", - //"nocollide", - "physprop", - "spawner", - "thruster", - "turret", - "wheel", - "eyeposer", - "faceposer", - "finger", - "inflator", - "statue", - "trails", - "camera", - "paint", - "rtcamera", - "rb655_lightsaber" -} - GMS.AllWeapons = { "gms_stonepickaxe", "gms_stonehatchet", -- cgit v1.2.3-70-g09d2