2007-02-04 01:16:06 +00:00
|
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
|
|
|
|
include('shared.lua')
|
|
|
|
|
|
|
|
ENT.WireDebugName = "Button"
|
|
|
|
ENT.OverlayDelay = 0
|
|
|
|
|
|
|
|
function ENT:Initialize()
|
|
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetUseType( SIMPLE_USE )
|
|
|
|
|
|
|
|
self.Outputs = Wire_CreateOutputs(self.Entity, { "Out" })
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Use(ply)
|
|
|
|
if (not ply:IsPlayer()) then return end
|
|
|
|
if (self.PrevUser) and (self.PrevUser:IsValid()) then return end
|
|
|
|
|
2007-05-16 04:37:10 +00:00
|
|
|
if (self:IsOn()) then
|
2007-02-04 01:16:06 +00:00
|
|
|
if (self.Toggle) then self:Switch(false) end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
self:Switch(true)
|
|
|
|
self.PrevUser = ply
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Think()
|
|
|
|
self.BaseClass.Think(self)
|
|
|
|
|
2007-05-16 04:37:10 +00:00
|
|
|
if ( self:IsOn() ) then
|
2007-02-04 01:16:06 +00:00
|
|
|
if (not self.PrevUser) or (not self.PrevUser:IsValid()) or (not self.PrevUser:KeyDown(IN_USE)) then
|
|
|
|
if (not self.Toggle) then
|
|
|
|
self:Switch(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.PrevUser = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
self.Entity:NextThink(CurTime()+0.05)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Setup(toggle, value_off, value_on)
|
|
|
|
self.Toggle = toggle
|
|
|
|
self.ValueOff = value_off
|
|
|
|
self.ValueOn = value_on
|
|
|
|
self.Value = value_off
|
2007-05-16 04:37:10 +00:00
|
|
|
self:SetOn( false )
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
self:ShowOutput(self.ValueOff)
|
|
|
|
Wire_TriggerOutput(self.Entity, "Out", self.ValueOff)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Switch(on)
|
|
|
|
if (not self.Entity:IsValid()) then return end
|
|
|
|
|
2007-05-16 04:37:10 +00:00
|
|
|
self:SetOn( on )
|
2007-02-04 01:16:06 +00:00
|
|
|
|
|
|
|
if (on) then
|
|
|
|
self:ShowOutput(self.ValueOn)
|
|
|
|
self.Value = self.ValueOn
|
|
|
|
else
|
|
|
|
self:ShowOutput(self.ValueOff)
|
|
|
|
self.Value = self.ValueOff
|
|
|
|
end
|
|
|
|
|
|
|
|
Wire_TriggerOutput(self.Entity, "Out", self.Value)
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:ShowOutput(value)
|
|
|
|
self:SetOverlayText( "(" .. self.ValueOff .. " - " .. self.ValueOn .. ") = " .. value )
|
|
|
|
end
|