Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Entry patch #2724

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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