2007-05-09 17:34:00 +00:00
|
|
|
--Wire graphics tablet by greenarrow
|
|
|
|
--http://forums.facepunchstudios.com/greenarrow
|
|
|
|
|
|
|
|
AddCSLuaFile( "cl_init.lua" )
|
|
|
|
AddCSLuaFile( "shared.lua" )
|
|
|
|
include('shared.lua')
|
|
|
|
|
|
|
|
ENT.WireDebugName = "Graphics Tablet"
|
2007-07-01 16:15:46 +00:00
|
|
|
ENT.outputMode = false
|
2007-05-09 17:34:00 +00:00
|
|
|
|
|
|
|
function ENT:Initialize()
|
|
|
|
self.Entity:PhysicsInit( SOLID_VPHYSICS )
|
|
|
|
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
|
|
|
|
self.Entity:SetSolid( SOLID_VPHYSICS )
|
2007-07-01 16:15:46 +00:00
|
|
|
self.Outputs = Wire_CreateOutputs(self.Entity, { "X", "Y", "Use", "OnScreen" })
|
2007-05-09 17:34:00 +00:00
|
|
|
|
2007-07-01 16:15:46 +00:00
|
|
|
Wire_TriggerOutput(self.Entity, "X", 0)
|
|
|
|
Wire_TriggerOutput(self.Entity, "Y", 0)
|
|
|
|
Wire_TriggerOutput(self.Entity, "Use", 0)
|
|
|
|
Wire_TriggerOutput(self.Entity, "OnScreen", 0)
|
|
|
|
|
|
|
|
self.lastOnscreen = 0
|
2007-05-09 17:34:00 +00:00
|
|
|
self.lastX = 0
|
|
|
|
self.lastY = 0
|
2007-07-01 16:15:46 +00:00
|
|
|
self.lastClick = 0
|
|
|
|
self:SetupParams()
|
2007-05-09 17:34:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Setup(gmode)
|
|
|
|
self.outputMode = gmode
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Use()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Think()
|
|
|
|
self.BaseClass.Think(self)
|
2007-07-01 16:15:46 +00:00
|
|
|
local onScreen = 0
|
|
|
|
local clickActive = 0
|
2007-06-06 00:07:43 +00:00
|
|
|
|
2007-07-01 16:15:46 +00:00
|
|
|
for i, player in pairs(player.GetAll()) do
|
2007-05-09 17:34:00 +00:00
|
|
|
local trace = {}
|
2007-07-01 16:15:46 +00:00
|
|
|
trace.start = player:GetShootPos()
|
|
|
|
trace.endpos = (player:GetAimVector() * self.workingDistance) + trace.start
|
|
|
|
trace.filter = player
|
2007-05-09 17:34:00 +00:00
|
|
|
local trace = util.TraceLine(trace)
|
|
|
|
|
|
|
|
if (trace.Entity == self.Entity) then
|
2007-08-11 13:06:35 +00:00
|
|
|
if (player:KeyDown (IN_ATTACK) or player:KeyDown (IN_USE)) then
|
|
|
|
clickActive = 1
|
|
|
|
end
|
2007-07-01 16:15:46 +00:00
|
|
|
local pos = self.Entity:WorldToLocal(trace.HitPos)
|
|
|
|
local xval = (self.x1 - pos.y) / (self.x1 - self.x2)
|
|
|
|
local yval = (self.y1 - pos.z) / (self.y1 - self.y2)
|
2007-06-06 00:07:43 +00:00
|
|
|
|
2007-07-01 16:15:46 +00:00
|
|
|
if (xval >= 0 and yval >= 0 and xval <= 1 and yval <= 1) then
|
|
|
|
onScreen = 1
|
|
|
|
if (xval ~= self.lastX or yval ~= self.lastY) then
|
|
|
|
if (self.outputMode) then
|
|
|
|
xval = (xval * 2) - 1
|
|
|
|
yval = (-yval * 2) + 1
|
|
|
|
end
|
|
|
|
Wire_TriggerOutput(self.Entity, "X", xval)
|
|
|
|
Wire_TriggerOutput(self.Entity, "Y", yval)
|
|
|
|
self:ShowOutput(xval, yval, self.lastClick, self.lastOnScreen)
|
|
|
|
self.lastX = xval
|
|
|
|
self.lastY = yval
|
2007-05-09 17:34:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-07-01 16:15:46 +00:00
|
|
|
if (onScreen ~= self.lastOnScreen) then
|
|
|
|
Wire_TriggerOutput(self.Entity, "OnScreen", onScreen)
|
|
|
|
self:ShowOutput(self.lastX, self.lastY, self.lastClick, onScreen)
|
|
|
|
self.lastOnScreen = onScreen
|
|
|
|
end
|
|
|
|
|
|
|
|
if (clickActive ~= self.lastClick) then
|
|
|
|
Wire_TriggerOutput(self.Entity, "Use", clickActive)
|
|
|
|
self:ShowOutput(self.lastX, self.lastY, clickActive, self.lastOnScreen)
|
|
|
|
self.lastClick = clickActive
|
2007-05-09 17:34:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.Entity:NextThink(CurTime()+0.08)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:ShowOutput(xval, yval, activeval, osval)
|
2007-07-01 16:15:46 +00:00
|
|
|
self:SetOverlayText(string.format("X = %f, Y = %f, Use = %d, On Screen = %d\n", xval, yval, activeval, osval))
|
2007-05-09 17:34:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:OnRestore()
|
|
|
|
self.BaseClass.OnRestore(self)
|
2007-07-01 16:15:46 +00:00
|
|
|
Wire_AdjustOutputs(self.Entity, { "X", "Y", "Use", "OnScreen" })
|
2007-05-09 17:34:00 +00:00
|
|
|
end
|