[changed] cleaned up more stools' code [fixed] some ents not keeping updated values when duplicated [added] presets to some stools [fixed] some ents not being added to cleanup when duplicated [fixed] some ents not being staying frozen when duplicated [fixed] some ents cleanup & undo text [changed] moved many stools control panels over to DForm functions [changed] made easier to add preset control to cp [changed] made easier to add cleanup and undo lang to stools/bak [changed] made easier to add
121 lines
3.4 KiB
Lua
121 lines
3.4 KiB
Lua
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
include('shared.lua')
|
|
|
|
ENT.WireDebugName = "DualInput"
|
|
ENT.OverlayDelay = 0
|
|
|
|
local MODEL = Model("models/jaanus/wiretool/wiretool_input.mdl")
|
|
|
|
function ENT:Initialize()
|
|
self.Entity:SetModel( MODEL )
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
|
|
|
self.Outputs = Wire_CreateOutputs(self.Entity, { "Out" })
|
|
end
|
|
|
|
function ENT:Setup(keygroup, keygroup2, toggle, value_off, value_on, value_on2)
|
|
self.keygroup = keygroup
|
|
self.keygroup2 = keygroup2
|
|
self.toggle = (toggle == 1)
|
|
self.value_off = value_off
|
|
self.value_on = value_on
|
|
self.value_on2 = value_on2
|
|
self.Value = value_off
|
|
self.Select = 0
|
|
|
|
self:ShowOutput(self.value_off)
|
|
Wire_TriggerOutput(self.Entity, "Out", self.value_off)
|
|
end
|
|
|
|
function ENT:InputActivate( mul )
|
|
if ( self.toggle && self.Select == mul ) then
|
|
return self:Switch( !self.On, mul )
|
|
end
|
|
|
|
return self:Switch( true, mul )
|
|
end
|
|
|
|
function ENT:InputDeactivate( mul )
|
|
if ( self.toggle ) then return true end
|
|
|
|
return self:Switch( false, mul )
|
|
end
|
|
|
|
function ENT:Switch( on, mul )
|
|
if (!self.Entity:IsValid()) then return false end
|
|
|
|
self.On = on
|
|
self.Select = mul
|
|
|
|
if (on && mul == 1) then
|
|
self:ShowOutput(self.value_on)
|
|
self.Value = self.value_on
|
|
elseif (on && mul == -1) then
|
|
self:ShowOutput(self.value_on2)
|
|
self.Value = self.value_on2
|
|
else
|
|
self:ShowOutput(self.value_off)
|
|
self.Value = self.value_off
|
|
end
|
|
|
|
Wire_TriggerOutput(self.Entity, "Out", self.Value)
|
|
|
|
return true
|
|
end
|
|
|
|
function ENT:ShowOutput(value)
|
|
self:SetOverlayText( "(" .. self.value_on2 .. " - " .. self.value_off .. " - " .. self.value_on .. ") = " .. value )
|
|
end
|
|
|
|
local function On( pl, ent, mul )
|
|
if (!ent:IsValid()) then return false end
|
|
return ent:InputActivate( mul )
|
|
end
|
|
|
|
local function Off( pl, ent, mul )
|
|
if (!ent:IsValid()) then return false end
|
|
return ent:InputDeactivate( mul )
|
|
end
|
|
|
|
numpad.Register( "WireDualInput_On", On )
|
|
numpad.Register( "WireDualInput_Off", Off )
|
|
|
|
|
|
function MakeWireDualInput( pl, Pos, Ang, keygroup, keygroup2, toggle, value_off, value_on, value_on2, Vel, aVel, frozen )
|
|
if ( !pl:CheckLimit( "wire_dual_inputs" ) ) then return false end
|
|
|
|
local wire_dual_input = ents.Create( "gmod_wire_dual_input" )
|
|
if (!wire_dual_input:IsValid()) then return false end
|
|
|
|
wire_dual_input:SetAngles( Ang )
|
|
wire_dual_input:SetPos( Pos )
|
|
wire_dual_input:SetModel( Model("models/jaanus/wiretool/wiretool_input.mdl") )
|
|
wire_dual_input:Spawn()
|
|
|
|
if wire_dual_input:GetPhysicsObject():IsValid() then
|
|
local Phys = wire_dual_input:GetPhysicsObject()
|
|
Phys:EnableMotion(!frozen)
|
|
end
|
|
|
|
wire_dual_input:Setup( keygroup, keygroup2, toggle, value_off, value_on, value_on2 )
|
|
wire_dual_input:SetPlayer( pl )
|
|
wire_dual_input.pl = pl
|
|
|
|
numpad.OnDown( pl, keygroup, "WireDualInput_On", wire_dual_input, 1 )
|
|
numpad.OnUp( pl, keygroup, "WireDualInput_Off", wire_dual_input, 1 )
|
|
|
|
numpad.OnDown( pl, keygroup2, "WireDualInput_On", wire_dual_input, -1 )
|
|
numpad.OnUp( pl, keygroup2, "WireDualInput_Off", wire_dual_input, -1 )
|
|
|
|
pl:AddCount( "wire_dual_inputs", wire_dual_input )
|
|
|
|
return wire_dual_input
|
|
end
|
|
|
|
duplicator.RegisterEntityClass("gmod_wire_dual_input", MakeWireDualInput, "Pos", "Ang", "keygroup", "keygroup2", "toggle", "value_off", "value_on", "value_on2", "Vel", "aVel", "frozen")
|