From 269b3b942c27fb30a16e0285de642e112e80e216 Mon Sep 17 00:00:00 2001 From: stepa2 Date: Mon, 30 Oct 2023 21:41:10 +0300 Subject: [PATCH] Text Entry patch (#2724) * 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 --- lua/entities/gmod_wire_textentry.lua | 68 +++++++++++++++++++--------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/lua/entities/gmod_wire_textentry.lua b/lua/entities/gmod_wire_textentry.lua index 4f5a821005..b1dcf2fa53 100644 --- a/lua/entities/gmod_wire_textentry.lua +++ b/lua/entities/gmod_wire_textentry.lua @@ -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", "", @@ -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 @@ -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() @@ -146,6 +164,8 @@ function ENT:OnRemove() self.Vehicle.WireTextEntry = nil end + self:RemoveHoldTimer() + self:Unprompt( true ) end @@ -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 @@ -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 ) @@ -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 )