Skip to content

Commit

Permalink
Text Entry patch (#2724)
Browse files Browse the repository at this point in the history
* Added 'Entered' boolean output to Text Entry

* Disabled background blur on Text Entry

* Text Entry fix

* More patches

* Hold timer will be removed on text entry entity removal
  • Loading branch information
stepa2 authored Oct 30, 2023
1 parent 47682de commit 269b3b9
Showing 1 changed file with 47 additions and 21 deletions.
68 changes: 47 additions & 21 deletions lua/entities/gmod_wire_textentry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if CLIENT then
net.Receive("wire_textentry_show",function()
local self=net.ReadEntity()
if not IsValid(self) then return end
panel = Derma_StringRequest(
panel = Derma_StringRequestNoBlur(
"Wire Text Entry",
"Enter text below",
"",
Expand Down Expand Up @@ -50,11 +50,23 @@ if CLIENT then
return
end

function ENT:GetHoldClamped()
return math.max(self:GetHold(), 0)
end

function ENT:GetHoldTimerName()
return "wire_textentry_" .. self:EntIndex()
end

function ENT:RemoveHoldTimer()
timer.Remove(self:GetHoldTimerName())
end

----------------------------------------------------
-- UpdateOverlay
----------------------------------------------------
function ENT:UpdateOverlay()
local hold = math.Round(math.max(self:GetHold(),0),1)
local hold = math.Round(self:GetHoldClamped(),1)
local txt = "Hold Length: " .. (hold > 0 and hold or "Forever")

if self.BlockInput then
Expand All @@ -77,10 +89,16 @@ function ENT:Initialize()
self:PhysicsInit(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)

self.Inputs=WireLib.CreateInputs(self,{"Block Input (When set to a non-zero value, blocks any further inputs.)","Prompt (When set to a non-zero value, opens the prompt popup for the driver of the linked vehicle.\nIf no vehicle is linked, opens the prompt for the owner of this entity instead.)"})
self.Outputs=WireLib.CreateOutputs(self,{"In Use","Text [STRING]","User [ENTITY]"})
self.Inputs=WireLib.CreateInputs(self,{
"Block Input (When set to a non-zero value, blocks any further inputs.)",
"Prompt (When set to a non-zero value, opens the prompt popup for the driver of the linked vehicle.\n"
.."If no vehicle is linked, opens the prompt for the owner of this entity instead.)"})
self.Outputs=WireLib.CreateOutputs(self,{
"In Use","Text [STRING]","User [ENTITY]",
"Entered (Set to 1 for a bit when text is successfully entered)"
})

self.BlockInput=false
self.BlockInput = false
self.NextPrompt = 0

self:UpdateOverlay()
Expand Down Expand Up @@ -146,6 +164,8 @@ function ENT:OnRemove()
self.Vehicle.WireTextEntry = nil
end

self:RemoveHoldTimer()

self:Unprompt( true )
end

Expand All @@ -164,23 +184,31 @@ net.Receive("wire_textentry_action",function(len,ply)
self:Unprompt() -- in all cases, make text entry available for use again

if ok and not self.BlockInput then
WireLib.TriggerOutput( self, "Text", text )

local timername = "wire_textentry_" .. self:EntIndex()
timer.Remove( timername )
if math.max(self:GetHold(),0) > 0 then
timer.Create( timername, math.max(self:GetHold(),0), 1, function()
if IsValid( self ) then
WireLib.TriggerOutput( self, "User", nil )
WireLib.TriggerOutput( self, "Text", "" )
end
end)
end
self:OnTextEntered(text)


end

self:UpdateOverlay()
end)

function ENT:OnTextEntered(text)
WireLib.TriggerOutput( self, "Text", text )
WireLib.TriggerOutput( self, "Entered", 1 )
WireLib.TriggerOutput( self, "Entered", 0 )

local timername = self:GetHoldTimerName()
timer.Remove( timername )
if self:GetHoldClamped() > 0 then
timer.Create( timername, self:GetHoldClamped(), 1, function()
if not self:IsValid() then return end

WireLib.TriggerOutput( self, "User", nil )
WireLib.TriggerOutput( self, "Text", "" )
end)
end
end

----------------------------------------------------
-- Prompt
-- Sends prompt to user etc
Expand All @@ -201,8 +229,7 @@ function ENT:Prompt( ply )
WireLib.TriggerOutput( self, "User", ply )
WireLib.TriggerOutput( self, "In Use", 1 )

local timername = "wire_textentry_" .. self:EntIndex()
timer.Remove( timername )
self:RemoveHoldTimer()

net.Start( "wire_textentry_show" )
net.WriteEntity( self )
Expand All @@ -226,8 +253,7 @@ function ENT:Unprompt( kickuser )
net.Start( "wire_textentry_kick" ) net.Send( self.User )
end

local timername = "wire_textentry_" .. self:EntIndex()
timer.Remove( timername )
self:RemoveHoldTimer()

self.User = nil
WireLib.TriggerOutput( self, "In Use", 0 )
Expand Down

0 comments on commit 269b3b9

Please sign in to comment.