Permalink
Browse files

Added TOOL.Information stuff

The code isn't pretty.
* gmod_drawhelp no longer affects TOOL.DrawHUD
* Mask Lua console commands to engine console commands better ( when
removing a concommand )
  • Loading branch information...
1 parent 260d44b commit 680666b1ed62b77517d156f8b0ffc35ba34e920f @robotboy655 robotboy655 committed Jan 27, 2015
@@ -7,147 +7,195 @@ cvars.AddChangeCallback( "gmod_toolmode", function( name, old, new )
spawnmenu.ActivateTool( new )
end, "gmod_toolmode_panel" )
-include('shared.lua')
-include('cl_viewscreen.lua')
+include( "shared.lua" )
+include( "cl_viewscreen.lua" )
-SWEP.PrintName = "Tool Gun"
-SWEP.Slot = 5
-SWEP.SlotPos = 6
-SWEP.DrawAmmo = false
-SWEP.DrawCrosshair = true
+SWEP.PrintName = "Tool Gun"
+SWEP.Slot = 5
+SWEP.SlotPos = 6
+SWEP.DrawAmmo = false
+SWEP.DrawCrosshair = true
-SWEP.WepSelectIcon = surface.GetTextureID( "vgui/gmod_tool" )
-SWEP.Gradient = surface.GetTextureID( "gui/gradient" )
-SWEP.InfoIcon = surface.GetTextureID( "gui/info" )
+SWEP.WepSelectIcon = surface.GetTextureID( "vgui/gmod_tool" )
+SWEP.Gradient = surface.GetTextureID( "gui/gradient" )
+SWEP.InfoIcon = surface.GetTextureID( "gui/info" )
-SWEP.ToolNameHeight = 0
-SWEP.InfoBoxHeight = 0
+SWEP.ToolNameHeight = 0
+SWEP.InfoBoxHeight = 0
surface.CreateFont( "GModToolName",
{
- font = "Roboto Bk",
- size = 80,
- weight = 1000
+ font = "Roboto Bk",
+ size = 80,
+ weight = 1000
})
surface.CreateFont( "GModToolSubtitle",
{
- font = "Roboto Bk",
- size = 24,
- weight = 1000
+ font = "Roboto Bk",
+ size = 24,
+ weight = 1000
})
surface.CreateFont( "GModToolHelp",
{
- font = "Roboto Bk",
- size = 17,
- weight = 1000
+ font = "Roboto Bk",
+ size = 17,
+ weight = 1000
})
-
--[[---------------------------------------------------------
Draws the help on the HUD (disabled if gmod_drawhelp is 0)
-----------------------------------------------------------]]
function SWEP:DrawHUD()
- if ( !gmod_drawhelp:GetBool() ) then return end
-
local mode = gmod_toolmode:GetString()
-
+
-- Don't draw help for a nonexistant tool!
if ( !self:GetToolObject() ) then return end
-
+
self:GetToolObject():DrawHUD()
-
-
+
+ if ( !gmod_drawhelp:GetBool() ) then return end
+
-- This could probably all suck less than it already does
-
-
+
local x, y = 50, 40
local w, h = 0, 0
-
+
local TextTable = {}
local QuadTable = {}
-
- QuadTable.texture = self.Gradient
- QuadTable.color = Color( 10, 10, 10, 180 )
-
+
+ QuadTable.texture = self.Gradient
+ QuadTable.color = Color( 10, 10, 10, 180 )
+
QuadTable.x = 0
- QuadTable.y = y-8
+ QuadTable.y = y - 8
QuadTable.w = 600
- QuadTable.h = self.ToolNameHeight - (y-8)
+ QuadTable.h = self.ToolNameHeight - ( y - 8 )
draw.TexturedQuad( QuadTable )
-
+
TextTable.font = "GModToolName"
TextTable.color = Color( 240, 240, 240, 255 )
TextTable.pos = { x, y }
- TextTable.text = "#tool."..mode..".name"
-
+ TextTable.text = "#tool." .. mode .. ".name"
w, h = draw.TextShadow( TextTable, 2 )
y = y + h
TextTable.font = "GModToolSubtitle"
TextTable.pos = { x, y }
- TextTable.text = "#tool."..mode..".desc"
+ TextTable.text = "#tool." .. mode .. ".desc"
w, h = draw.TextShadow( TextTable, 1 )
y = y + h + 8
-
+
self.ToolNameHeight = y
-
- --y = y + 4
-
- QuadTable.x = 0
+
QuadTable.y = y
- QuadTable.w = 600
QuadTable.h = self.InfoBoxHeight
- local alpha = math.Clamp( 255 + (self:GetToolObject().LastMessage - CurTime())*800, 10, 255 )
+ local alpha = math.Clamp( 255 + ( self:GetToolObject().LastMessage - CurTime() ) * 800, 10, 255 )
QuadTable.color = Color( alpha, alpha, alpha, 230 )
draw.TexturedQuad( QuadTable )
-
+
y = y + 4
-
+
TextTable.font = "GModToolHelp"
- TextTable.pos = { x + self.InfoBoxHeight, y }
- TextTable.text = self:GetToolObject():GetHelpText()
- w, h = draw.TextShadow( TextTable, 1 )
- surface.SetDrawColor( 255, 255, 255, 255 )
- surface.SetTexture( self.InfoIcon )
- surface.DrawTexturedRect( x+1, y+1, h-3, h-3 )
+ if ( !self:GetToolObject().Information ) then
+ TextTable.pos = { x + self.InfoBoxHeight, y }
+ TextTable.text = self:GetToolObject():GetHelpText()
+ w, h = draw.TextShadow( TextTable, 1 )
+
+ surface.SetDrawColor( 255, 255, 255, 255 )
+ surface.SetTexture( self.InfoIcon )
+ surface.DrawTexturedRect( x + 1, y + 1, h - 3, h - 3 )
+
+ self.InfoBoxHeight = h + 8
+
+ return
+ end
+
+ local h2 = 0
+
+ for k, v in pairs( self:GetToolObject().Information ) do
+ if ( type( v ) == "string" ) then v = { name = v } end
+
+ if ( !v.name ) then continue end
+ if ( v.stage && v.stage != self:GetStage() ) then continue end
+ if ( v.op && v.op != self:GetToolObject():GetOperation() ) then continue end
+
+ local txt = "#tool." .. GetConVarString( "gmod_toolmode" ) .. "." .. v.name
+ if ( v.name == "info" ) then
+ txt = self:GetToolObject():GetHelpText()
+ end
+
+ TextTable.text = txt
+ TextTable.pos = { x + 21, y + h2 }
+
+ w, h = draw.TextShadow( TextTable, 1 )
- self.InfoBoxHeight = h + 8
+ if ( !v.icon ) then
+ if ( v.name:StartWith( "info" ) ) then v.icon = "gui/info" end
+ if ( v.name:StartWith( "left" ) ) then v.icon = "gui/lmb.png" end
+ if ( v.name:StartWith( "right" ) ) then v.icon = "gui/rmb.png" end
+ if ( v.name:StartWith( "reload" ) ) then v.icon = "gui/r.png" end
+ end
+ if ( !v.icon2 && v.name:EndsWith( "use" ) ) then v.icon2 = "gui/e.png" end
+ self.Icons = self.Icons or {}
+ if ( v.icon && !self.Icons[ v.icon ] ) then self.Icons[ v.icon ] = Material( v.icon ) end
+ if ( v.icon2 && !self.Icons[ v.icon2 ] ) then self.Icons[ v.icon2 ] = Material( v.icon2 ) end
+
+ if ( v.icon && self.Icons[ v.icon ] && !self.Icons[ v.icon ]:IsError() ) then
+ surface.SetDrawColor( 255, 255, 255, 255 )
+ surface.SetMaterial( self.Icons[ v.icon ] )
+ surface.DrawTexturedRect( x, y + h2, 16, 16 )
+ end
+
+ if ( v.icon2 && self.Icons[ v.icon2 ] && !self.Icons[ v.icon2 ]:IsError() ) then
+ surface.SetDrawColor( 255, 255, 255, 255 )
+ surface.SetMaterial( self.Icons[ v.icon2 ] )
+ surface.DrawTexturedRect( x - 25, y + h2, 16, 16 )
+
+ draw.SimpleText( "+", "default", x - 8, y + h2 + 2, color_white )
+ end
+
+ h2 = h2 + h
+
+ end
+
+ self.InfoBoxHeight = h2 + 8
+
end
function SWEP:SetStage( ... )
if ( !self:GetToolObject() ) then return end
return self:GetToolObject():SetStage( ... )
-
+
end
function SWEP:GetStage( ... )
if ( !self:GetToolObject() ) then return end
return self:GetToolObject():GetStage( ... )
-
+
end
function SWEP:ClearObjects( ... )
if ( !self:GetToolObject() ) then return end
self:GetToolObject():ClearObjects( ... )
-
+
end
function SWEP:StartGhostEntities( ... )
if ( !self:GetToolObject() ) then return end
self:GetToolObject():StartGhostEntities( ... )
-
+
end
-function SWEP:PrintWeaponInfo( x, y, alpha )
+function SWEP:PrintWeaponInfo( x, y, alpha )
end
function SWEP:FreezeMovement()
@@ -157,13 +205,12 @@ function SWEP:FreezeMovement()
if ( !self:GetToolObject() ) then return false end
return self:GetToolObject():FreezeMovement()
-
+
end
function SWEP:OnReloaded()
-- TODO: Reload the tool control panels
-- controlpanel.Clear()
-
-end
+end
@@ -1,16 +1,17 @@
local AddConsoleCommand = AddConsoleCommand
local string = string
+local Msg = Msg
--[[---------------------------------------------------------
Name: concommand
Desc: A module to take care of the registration and calling
of Lua console commands.
-----------------------------------------------------------]]
-module("concommand")
+module( "concommand" )
-local CommandList = {}
-local CompleteList = {}
+local CommandList = {}
+local CompleteList = {}
--[[---------------------------------------------------------
Name: concommand.GetTable( )
@@ -41,7 +42,6 @@ function Remove( name )
CompleteList[ LowerName ] = nil
end
-
--[[---------------------------------------------------------
Name: concommand.Run( )
Desc: Called by the engine when an unknown console command is run
@@ -55,11 +55,9 @@ function Run( player, command, arguments, args )
return true
end
- if ( player:IsValid() ) then
- player:ChatPrint( "Unknown Command: '" .. command .. "'\n" )
- end
-
- return false;
+ Msg( "Unknown command: " .. command .. "\n" )
+
+ return false
end
--[[---------------------------------------------------------
@@ -73,6 +71,5 @@ function AutoComplete( command, arguments )
if ( CompleteList[ LowerCommand ] != nil ) then
return CompleteList[ LowerCommand ]( command, arguments )
end
-
-end
+end

0 comments on commit 680666b

Please sign in to comment.