From e657bec419e8496ceb8bf900da08a602c94e3e69 Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Sat, 4 Aug 2018 15:46:12 +0200 Subject: [PATCH 01/12] Improved wire rendering and added visualization when making wire waypoints --- lua/weapons/gmod_tool/stools/wire_adv.lua | 106 ++++++++++++++++++++-- lua/wire/client/cl_wirelib.lua | 3 +- 2 files changed, 99 insertions(+), 10 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 64ff1874a4..03285e0763 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -45,6 +45,8 @@ TOOL.ClientConVar = { } util.PrecacheSound("weapons/pistol/pistol_empty.wav") +util.PrecacheSound("buttons/lightswitch2.wav") +util.PrecacheSound("buttons/button16.wav") local function get_active_tool(ply, tool) -- find toolgun @@ -427,6 +429,8 @@ elseif CLIENT then if IsValid( trace.Entity ) then if self:GetStage() == 0 then + self:BeginRenderingCurrentWire() + local inputs, _ = self:GetPorts( trace.Entity ) if not inputs then return end @@ -555,6 +559,7 @@ elseif CLIENT then self:SetStage(0) self.WiringRender = {} -- Empty this now so the HUD doesn't glitch self:GetOwner():EmitSound( "weapons/airboat/airboat_gun_lastshot" .. math.random(1,2) .. ".wav" ) + self:StopRenderingCurrentWire() end end @@ -568,6 +573,7 @@ elseif CLIENT then for i=1,#self.Wiring do self:WireNode( self.Wiring[i], trace.Entity, trace.HitPos + trace.HitNormal*(self:GetClientNumber("width")/2) ) end + self:GetOwner():EmitSound("buttons/lightswitch2.wav") end end @@ -648,18 +654,40 @@ elseif CLIENT then if not self then return end return self:ScrollUp(ply:GetEyeTraceNoCursor()) - elseif bind == "impulse 100" and ply:KeyDown( IN_SPEED ) then - local self = get_active_tool(ply, "wire_adv") - if not self then - self = get_active_tool(ply, "wire_debugger") - if not self then return end + elseif bind == "impulse 100" then + if ply:KeyDown( IN_SPEED ) then + local self = get_active_tool(ply, "wire_adv") + if not self then + self = get_active_tool(ply, "wire_debugger") + if not self then return end + + spawnmenu.ActivateTool( "wire_adv") -- switch back to wire adv + return true + end - spawnmenu.ActivateTool( "wire_adv") -- switch back to wire adv + spawnmenu.ActivateTool("wire_debugger") -- switch to debugger + return true + else + local self = get_active_tool(ply, "wire_adv") + if self and self:GetStage() == 1 then + local len = #self.Wiring + if len > 0 then + local nodesCount = 0 + for i=1,len do + nodesCount = nodesCount + #self.Wiring[i][4] + if #self.Wiring[i][4] > 0 then + table.remove(self.Wiring[i][4]) + end + end + + if nodesCount > 0 then + self:GetOwner():EmitSound( "buttons/button16.wav" ) + end + end + return true + end return true end - - spawnmenu.ActivateTool("wire_debugger") -- switch to debugger - return true end end @@ -981,6 +1009,66 @@ elseif CLIENT then self:DrawList( "Selected", self.WiringRender, ent, x, y, ww, hh, h ) end end + + function TOOL:StopRenderingCurrentWire() + hook.Remove("PostDrawOpaqueRenderables", "Wire.ToolWireRenderHook") + self.IsRenderingCurrentWire = false; + end + + function TOOL:BeginRenderingCurrentWire() + if self.IsRenderingCurrentWire then return end + self.IsRenderingCurrentWire = true + hook.Add("PostDrawOpaqueRenderables", "Wire.ToolWireRenderHook", function() + // Draw the wire path + render.SetColorMaterial() + for i=1, #self.Wiring do + local wiring = self.Wiring[i] + local nodes = wiring[4] + + local color = Color(self:GetClientNumber("r"), self:GetClientNumber("g"), self:GetClientNumber("b")) + local matName = self:GetClientInfo("material") + local width = self:GetClientInfo("width") + local mat = Material("cable/cable2") + local theEnt = wiring[3] + if not theEnt:IsValid() then + break + end + + local start = theEnt:LocalToWorld(wiring[2]) + + local scroll = 0.5 + render.SetMaterial(mat) + render.StartBeam((#nodes*2)+1+1+1) // + startpoint + same as last node (to not have transition to aiming point) +point where player is aiming + render.AddBeam(start, width, scroll, color) + + for j=1, #nodes do + local node = nodes[j] + + local nodeEnt = node[1] + local nodeOffset = node[2] + local nodePosition = nodeEnt:LocalToWorld(nodeOffset) + + scroll = scroll+(nodePosition-start):Length()/10 + render.AddBeam(nodePosition, width, scroll, color) + render.AddBeam(nodePosition, width, scroll, color) + + start = nodePosition + end + + render.AddBeam(start, width, scroll, Color(255,255,255,255)) + local traceData = util.GetPlayerTrace(LocalPlayer()) + traceData.filter = { LocalPlayer() } + + traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP + local traceResult = util.TraceLine(traceData) + /*if self.IsWireEntity(traceResult.Entity) then + UpdateTraceForSurface(traceResult) + end*/ + render.AddBeam(traceResult.HitPos, width, scroll, Color(100,100,100,255)) + render.EndBeam() + end + end) + end ----------------------------------------------------------------- diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 1572191aef..5d3b9788c2 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -61,7 +61,7 @@ function Wire_Render(ent) local len = #nodes if len>0 then render.SetMaterial(getmat(wiretbl.Material)) - render.StartBeam(len+1) + render.StartBeam(len * 2 + 1) render.AddBeam(start, width, scroll, color) for j=1, len do @@ -72,6 +72,7 @@ function Wire_Render(ent) scroll = scroll+(endpos-start):Length()/10 render.AddBeam(endpos, width, scroll, color) + render.AddBeam(endpos, width, scroll, color) -- A second beam in the same position ensures the line stays consistent and doesn't change width/become distorted. start = endpos end From b3537d2bdc90988c7db40ca9a0c0dd5ff1eff133 Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Wed, 8 Aug 2018 16:17:41 +0200 Subject: [PATCH 02/12] Added description on how to remove waypoints. Added checkbox to align wires to surface. --- lua/weapons/gmod_tool/stools/wire_adv.lua | 72 +++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 03285e0763..01c5aaa0c0 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -17,6 +17,7 @@ if CLIENT then language.Add( "WireTool_width", "Width:" ) language.Add( "WireTool_material", "Material:" ) language.Add( "WireTool_colour", "Colour:" ) + language.Add( "WireTool_align", "Align to surface" ) TOOL.Information = { { name = "left_0", stage = 0, text = "Select input (Shift: Select multiple; Alt: Select all)" }, { name = "right_0", stage = 0, text = "Next" }, @@ -24,6 +25,7 @@ if CLIENT then { name = "mwheel_0", stage = 0, text = "Mouse wheel: Next" }, { name = "left_1", stage = 1, text = "Select entity" }, { name = "right_1", stage = 1, text = "Add wirepoint" }, + { name = "f_0", stage = 1, text = "F: Remove wirepoint" }, { name = "reload_1", stage = 1, text = "Cancel" }, { name = "left_2", stage = 2, text = "Select output (Alt: Auto-connect matching input/outputs)" }, { name = "right_2", stage = 2, text = "Next" }, @@ -42,6 +44,7 @@ TOOL.ClientConVar = { r = 255, g = 255, b = 255, + align = 1 } util.PrecacheSound("weapons/pistol/pistol_empty.wav") @@ -414,6 +417,62 @@ elseif CLIENT then function TOOL:AutoWiringTypeLookup_Check( inputtype ) return self.AutoWiringTypeLookup_t[inputtype] end + + function TOOL:IsWireEntity(ent) + -- TODO + local inputs, outputs = WireLib.GetPorts(ent) + return inputs or outputs + end + + function TOOL:UpdateTraceForSurface(trace, parent, dir, terminate) + if self:GetClientNumber("align") == 0 then return end + if not self:IsWireEntity(trace.Entity) then return end + terminate = terminate or false + + dir = dir or 0 + local traceData = util.GetPlayerTrace(LocalPlayer()) + traceData.start = trace.HitPos + local normal + if dir == 1 then + normal = trace.Entity:GetForward() + elseif dir == 2 then + normal = trace.Entity:GetRight() + elseif dir == 3 then + normal = -trace.Entity:GetUp() + elseif dir == 4 then + normal = -trace.Entity:GetForward() + elseif dir == 5 then + normal = -trace.Entity:GetRight() + else -- if 0 then + normal = trace.Entity:GetUp() + end + traceData.endpos = trace.HitPos + normal * -1000 + traceData.filter = { LocalPlayer(), trace.Entity } + traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP + local newTrace = util.TraceLine(traceData) + if dir < 5 then + if !IsValid(parent) or newTrace.Entity ~= parent then + self:UpdateTraceForSurface(trace, parent, dir + 1, terminate) + return + end + else + if not terminate then + -- Didn't find the parent in any direction, assume whichever entity can be traced behind the entity is the "parent". + local traceData = util.GetPlayerTrace(LocalPlayer()) + traceData.filter = { LocalPlayer(), trace.Entity } + traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP + newTrace = util.TraceLine(traceData) + parent = newTrace.Entity + self:UpdateTraceForSurface(trace, parent, 0, true) + return + end + end + + if newTrace.Hit then + trace.HitPos = newTrace.HitPos + trace.Normal = newTrace.HitNormal + end + end ----------------------------------------------------------------- -- Mouse buttons @@ -429,6 +488,7 @@ elseif CLIENT then if IsValid( trace.Entity ) then if self:GetStage() == 0 then + self:UpdateTraceForSurface(trace, trace.Entity:GetParent()) self:BeginRenderingCurrentWire() local inputs, _ = self:GetPorts( trace.Entity ) @@ -452,6 +512,7 @@ elseif CLIENT then return elseif self:GetStage() == 1 then + self:UpdateTraceForSurface(trace, trace.Entity:GetParent()) local _, outputs = self:GetPorts( trace.Entity ) if not outputs then return end @@ -566,7 +627,8 @@ elseif CLIENT then function TOOL:RightClick(trace) if self.wtfgarry > CurTime() then return end self.wtfgarry = CurTime() + 0.1 - + + self:UpdateTraceForSurface(trace, trace.Entity:GetParent()) if self:GetStage() == 0 or self:GetStage() == 2 then self:ScrollDown(trace) elseif IsValid(trace.Entity) and self:GetStage() == 1 then @@ -1061,9 +1123,9 @@ elseif CLIENT then traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP local traceResult = util.TraceLine(traceData) - /*if self.IsWireEntity(traceResult.Entity) then - UpdateTraceForSurface(traceResult) - end*/ + if self:IsWireEntity(traceResult.Entity) then + self:UpdateTraceForSurface(traceResult, traceResult.Entity:GetParent()) + end render.AddBeam(traceResult.HitPos, width, scroll, Color(100,100,100,255)) render.EndBeam() end @@ -1134,6 +1196,8 @@ elseif CLIENT then Green = "wire_adv_g", Blue = "wire_adv_b" }) + + panel:CheckBox("#WireTool_align", "wire_adv_align") end end From 62fb1600b6fd1f95d447931ef625d5813b12523d Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Wed, 8 Aug 2018 16:23:51 +0200 Subject: [PATCH 03/12] Changed 'align' to 'stick'. --- lua/weapons/gmod_tool/stools/wire_adv.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 01c5aaa0c0..0e7cb83c8e 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -17,7 +17,7 @@ if CLIENT then language.Add( "WireTool_width", "Width:" ) language.Add( "WireTool_material", "Material:" ) language.Add( "WireTool_colour", "Colour:" ) - language.Add( "WireTool_align", "Align to surface" ) + language.Add( "WireTool_stick", "Stick to surfaces" ) TOOL.Information = { { name = "left_0", stage = 0, text = "Select input (Shift: Select multiple; Alt: Select all)" }, { name = "right_0", stage = 0, text = "Next" }, @@ -44,7 +44,7 @@ TOOL.ClientConVar = { r = 255, g = 255, b = 255, - align = 1 + stick = 1 } util.PrecacheSound("weapons/pistol/pistol_empty.wav") @@ -425,7 +425,7 @@ elseif CLIENT then end function TOOL:UpdateTraceForSurface(trace, parent, dir, terminate) - if self:GetClientNumber("align") == 0 then return end + if self:GetClientNumber("stick") == 0 then return end if not self:IsWireEntity(trace.Entity) then return end terminate = terminate or false @@ -1197,7 +1197,7 @@ elseif CLIENT then Blue = "wire_adv_b" }) - panel:CheckBox("#WireTool_align", "wire_adv_align") + panel:CheckBox("#WireTool_stick", "wire_adv_stick") end end From a92b001b998f28af3ae9e36a0459b15fdab5b1f2 Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Wed, 8 Aug 2018 16:41:14 +0200 Subject: [PATCH 04/12] Fixed visualized wire still following the toolgun while selecting output on target entity --- lua/weapons/gmod_tool/stools/wire_adv.lua | 58 +++++++++++++---------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 0e7cb83c8e..ab239c7fb1 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -417,18 +417,18 @@ elseif CLIENT then function TOOL:AutoWiringTypeLookup_Check( inputtype ) return self.AutoWiringTypeLookup_t[inputtype] end - + function TOOL:IsWireEntity(ent) -- TODO local inputs, outputs = WireLib.GetPorts(ent) return inputs or outputs end - + function TOOL:UpdateTraceForSurface(trace, parent, dir, terminate) if self:GetClientNumber("stick") == 0 then return end if not self:IsWireEntity(trace.Entity) then return end terminate = terminate or false - + dir = dir or 0 local traceData = util.GetPlayerTrace(LocalPlayer()) traceData.start = trace.HitPos @@ -451,7 +451,7 @@ elseif CLIENT then traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP local newTrace = util.TraceLine(traceData) if dir < 5 then - if !IsValid(parent) or newTrace.Entity ~= parent then + if not IsValid(parent) or newTrace.Entity ~= parent then self:UpdateTraceForSurface(trace, parent, dir + 1, terminate) return end @@ -467,7 +467,7 @@ elseif CLIENT then return end end - + if newTrace.Hit then trace.HitPos = newTrace.HitPos trace.Normal = newTrace.HitNormal @@ -490,7 +490,7 @@ elseif CLIENT then if self:GetStage() == 0 then self:UpdateTraceForSurface(trace, trace.Entity:GetParent()) self:BeginRenderingCurrentWire() - + local inputs, _ = self:GetPorts( trace.Entity ) if not inputs then return end @@ -627,7 +627,7 @@ elseif CLIENT then function TOOL:RightClick(trace) if self.wtfgarry > CurTime() then return end self.wtfgarry = CurTime() + 0.1 - + self:UpdateTraceForSurface(trace, trace.Entity:GetParent()) if self:GetStage() == 0 or self:GetStage() == 2 then self:ScrollDown(trace) @@ -741,7 +741,7 @@ elseif CLIENT then table.remove(self.Wiring[i][4]) end end - + if nodesCount > 0 then self:GetOwner():EmitSound( "buttons/button16.wav" ) end @@ -1071,12 +1071,12 @@ elseif CLIENT then self:DrawList( "Selected", self.WiringRender, ent, x, y, ww, hh, h ) end end - + function TOOL:StopRenderingCurrentWire() hook.Remove("PostDrawOpaqueRenderables", "Wire.ToolWireRenderHook") self.IsRenderingCurrentWire = false; end - + function TOOL:BeginRenderingCurrentWire() if self.IsRenderingCurrentWire then return end self.IsRenderingCurrentWire = true @@ -1086,6 +1086,7 @@ elseif CLIENT then for i=1, #self.Wiring do local wiring = self.Wiring[i] local nodes = wiring[4] + local outputEntity = wiring[5] local color = Color(self:GetClientNumber("r"), self:GetClientNumber("g"), self:GetClientNumber("b")) local matName = self:GetClientInfo("material") @@ -1095,38 +1096,45 @@ elseif CLIENT then if not theEnt:IsValid() then break end - + local start = theEnt:LocalToWorld(wiring[2]) - + local scroll = 0.5 render.SetMaterial(mat) render.StartBeam((#nodes*2)+1+1+1) // + startpoint + same as last node (to not have transition to aiming point) +point where player is aiming render.AddBeam(start, width, scroll, color) - + for j=1, #nodes do local node = nodes[j] - + local nodeEnt = node[1] local nodeOffset = node[2] local nodePosition = nodeEnt:LocalToWorld(nodeOffset) - + scroll = scroll+(nodePosition-start):Length()/10 render.AddBeam(nodePosition, width, scroll, color) render.AddBeam(nodePosition, width, scroll, color) start = nodePosition end - - render.AddBeam(start, width, scroll, Color(255,255,255,255)) - local traceData = util.GetPlayerTrace(LocalPlayer()) - traceData.filter = { LocalPlayer() } - traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP - local traceResult = util.TraceLine(traceData) - if self:IsWireEntity(traceResult.Entity) then - self:UpdateTraceForSurface(traceResult, traceResult.Entity:GetParent()) + render.AddBeam(start, width, scroll, Color(255,255,255,255)) + + if not IsValid(outputEntity) then + local traceData = util.GetPlayerTrace(LocalPlayer()) + traceData.filter = { LocalPlayer() } + + traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP + local traceResult = util.TraceLine(traceData) + if self:IsWireEntity(traceResult.Entity) then + self:UpdateTraceForSurface(traceResult, traceResult.Entity:GetParent()) + end + render.AddBeam(traceResult.HitPos, width, scroll, Color(100,100,100,255)) + else + local outputPos = wiring[6] + outputPos = outputEntity:LocalToWorld(outputPos) + render.AddBeam(outputPos, width, scroll, Color(100,100,100,255)) end - render.AddBeam(traceResult.HitPos, width, scroll, Color(100,100,100,255)) render.EndBeam() end end) @@ -1196,7 +1204,7 @@ elseif CLIENT then Green = "wire_adv_g", Blue = "wire_adv_b" }) - + panel:CheckBox("#WireTool_stick", "wire_adv_stick") end From 419d694cf10873383c779e5709bc351f787a478c Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Wed, 8 Aug 2018 16:58:54 +0200 Subject: [PATCH 05/12] Fixed trailing whitespace and conventions --- lua/weapons/gmod_tool/stools/wire_adv.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index ab239c7fb1..70676ecabf 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -1081,13 +1081,13 @@ elseif CLIENT then if self.IsRenderingCurrentWire then return end self.IsRenderingCurrentWire = true hook.Add("PostDrawOpaqueRenderables", "Wire.ToolWireRenderHook", function() - // Draw the wire path + -- Draw the wire path render.SetColorMaterial() for i=1, #self.Wiring do local wiring = self.Wiring[i] local nodes = wiring[4] local outputEntity = wiring[5] - + local color = Color(self:GetClientNumber("r"), self:GetClientNumber("g"), self:GetClientNumber("b")) local matName = self:GetClientInfo("material") local width = self:GetClientInfo("width") @@ -1101,7 +1101,7 @@ elseif CLIENT then local scroll = 0.5 render.SetMaterial(mat) - render.StartBeam((#nodes*2)+1+1+1) // + startpoint + same as last node (to not have transition to aiming point) +point where player is aiming + render.StartBeam((#nodes*2)+1+1+1) -- + startpoint + same as last node (to not have transition to aiming point) +point where player is aiming render.AddBeam(start, width, scroll, color) for j=1, #nodes do @@ -1119,7 +1119,7 @@ elseif CLIENT then end render.AddBeam(start, width, scroll, Color(255,255,255,255)) - + if not IsValid(outputEntity) then local traceData = util.GetPlayerTrace(LocalPlayer()) traceData.filter = { LocalPlayer() } From 53aa0ee82aaf5bbb11c941284b1d3c99dfb71b0f Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Wed, 8 Aug 2018 17:41:15 +0200 Subject: [PATCH 06/12] Changed 'Remove wirepoint' hint to 'Undo wirepoint' --- lua/weapons/gmod_tool/stools/wire_adv.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 70676ecabf..c8ce39a2b1 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -25,7 +25,7 @@ if CLIENT then { name = "mwheel_0", stage = 0, text = "Mouse wheel: Next" }, { name = "left_1", stage = 1, text = "Select entity" }, { name = "right_1", stage = 1, text = "Add wirepoint" }, - { name = "f_0", stage = 1, text = "F: Remove wirepoint" }, + { name = "f_0", stage = 1, text = "F: Undo wirepoint" }, { name = "reload_1", stage = 1, text = "Cancel" }, { name = "left_2", stage = 2, text = "Select output (Alt: Auto-connect matching input/outputs)" }, { name = "right_2", stage = 2, text = "Next" }, From 81caea2a254d1d23d28d627ff74e02ad05b1f2af Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Wed, 8 Aug 2018 18:26:48 +0200 Subject: [PATCH 07/12] Removed TOOL:IsWireEntity() in favor of WireLib.HasPorts(). --- lua/weapons/gmod_tool/stools/wire_adv.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index c8ce39a2b1..136903b581 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -418,15 +418,9 @@ elseif CLIENT then return self.AutoWiringTypeLookup_t[inputtype] end - function TOOL:IsWireEntity(ent) - -- TODO - local inputs, outputs = WireLib.GetPorts(ent) - return inputs or outputs - end - function TOOL:UpdateTraceForSurface(trace, parent, dir, terminate) if self:GetClientNumber("stick") == 0 then return end - if not self:IsWireEntity(trace.Entity) then return end + if not WireLib.HasPorts(trace.Entity) then return end terminate = terminate or false dir = dir or 0 @@ -463,6 +457,8 @@ elseif CLIENT then traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP newTrace = util.TraceLine(traceData) parent = newTrace.Entity + + -- Restart with the assumed parent. self:UpdateTraceForSurface(trace, parent, 0, true) return end @@ -1126,7 +1122,7 @@ elseif CLIENT then traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP local traceResult = util.TraceLine(traceData) - if self:IsWireEntity(traceResult.Entity) then + if WireLib.HasPorts(traceResult.Entity) then self:UpdateTraceForSurface(traceResult, traceResult.Entity:GetParent()) end render.AddBeam(traceResult.HitPos, width, scroll, Color(100,100,100,255)) From 98ab9c19fd0b1cf18cf6ee882c73cfe415180b91 Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Sat, 29 Jun 2019 19:49:09 +0200 Subject: [PATCH 08/12] Changed UpdateTraceForSurface from recursion to loop, and fixed certain cases where it would snap to the wrong surface. --- lua/weapons/gmod_tool/stools/wire_adv.lua | 99 +++++++++++++---------- lua/wire/client/cl_wirelib.lua | 2 +- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 136903b581..6309d1d300 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -417,57 +417,74 @@ elseif CLIENT then function TOOL:AutoWiringTypeLookup_Check( inputtype ) return self.AutoWiringTypeLookup_t[inputtype] end - - function TOOL:UpdateTraceForSurface(trace, parent, dir, terminate) + + -- Updates the trace hit position and normal to the surface of the parent, perpendicular to the originally hit entity. + -- As not all models have the same forward, up, etc. it checks all directions perpendicular to the hit entity, until it finds the parent. + -- If the parent is not found in any perpendicular direction, it traces the parent in the direction of the tool gun. + function TOOL:UpdateTraceForSurface(trace, parent) if self:GetClientNumber("stick") == 0 then return end if not WireLib.HasPorts(trace.Entity) then return end - terminate = terminate or false - - dir = dir or 0 - local traceData = util.GetPlayerTrace(LocalPlayer()) - traceData.start = trace.HitPos - local normal - if dir == 1 then - normal = trace.Entity:GetForward() - elseif dir == 2 then - normal = trace.Entity:GetRight() - elseif dir == 3 then - normal = -trace.Entity:GetUp() - elseif dir == 4 then - normal = -trace.Entity:GetForward() - elseif dir == 5 then - normal = -trace.Entity:GetRight() - else -- if 0 then - normal = trace.Entity:GetUp() - end - traceData.endpos = trace.HitPos + normal * -1000 - traceData.filter = { LocalPlayer(), trace.Entity } - traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP - local newTrace = util.TraceLine(traceData) - if dir < 5 then - if not IsValid(parent) or newTrace.Entity ~= parent then - self:UpdateTraceForSurface(trace, parent, dir + 1, terminate) - return + + local hasAssumedParent = false + local dir = 0 + local hitParentPos + local hitParentNormal + local closestDistanceSquared = 99999999 + local entityUp = trace.Entity:GetUp() + local entityForward = trace.Entity:GetForward() + local entityRight = trace.Entity:GetRight() + local directions = + { + entityUp, + entityForward, + entityRight, + -entityUp, + -entityForward, + -entityRight + } + + while dir <= 5 do -- While instead of for, since Lua doesn't allow setting a for iterator variable. + local traceData = util.GetPlayerTrace(LocalPlayer()) + traceData.start = trace.HitPos + local normal = directions[dir + 1] + + traceData.endpos = trace.HitPos + normal * -1000 + traceData.filter = { LocalPlayer(), trace.Entity } + traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP + local newTrace = util.TraceLine(traceData) + + local foundParent = false + if newTrace.Hit and IsValid(parent) and newTrace.Entity == parent then + local distanceSquared = (newTrace.HitPos - trace.HitPos):LengthSqr() + if distanceSquared < closestDistanceSquared then + closestDistanceSquared = distanceSquared + hitParentPos = newTrace.HitPos + hitParentNormal = newTrace.HitNormal + foundParent = true + end end - else - if not terminate then + + if not foundParent and (dir >= 5 and not hasAssumedParent) then -- Didn't find the parent in any direction, assume whichever entity can be traced behind the entity is the "parent". + -- This can happen if eg. the component is not directly on the parent. local traceData = util.GetPlayerTrace(LocalPlayer()) - traceData.filter = { LocalPlayer(), trace.Entity } + traceData.filter = { LocalPlayer(), trace.Entity } -- Ignore player and the entity we're trying to wire to. traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP newTrace = util.TraceLine(traceData) parent = newTrace.Entity - - -- Restart with the assumed parent. - self:UpdateTraceForSurface(trace, parent, 0, true) - return + + -- Check all directions again with the new assumed parent. + hasAssumedParent = true + closestDistanceSquared = 99999999 + dir = -1 -- So it gets set to 0 after the increment below. end - end - if newTrace.Hit then - trace.HitPos = newTrace.HitPos - trace.Normal = newTrace.HitNormal + dir = dir + 1 end + + -- Whatever we hit was the entity's parent. Update trace, and we're done. + trace.HitPos = hitParentPos + trace.Normal = hitParentNormal end ----------------------------------------------------------------- @@ -1204,4 +1221,4 @@ elseif CLIENT then panel:CheckBox("#WireTool_stick", "wire_adv_stick") end -end +end \ No newline at end of file diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 5d3b9788c2..f07f3bac44 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -243,4 +243,4 @@ function WireLib.hud_debug(text, oneframe) if oneframe then hook.Remove("HUDPaint","wire_hud_debug") end draw.DrawText(text,"Trebuchet24",10,200,Color(255,255,255,255),0) end) -end +end \ No newline at end of file From 8182f7519a16534d70fe9a0bca63d1451b605256 Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Sun, 30 Jun 2019 21:03:58 +0200 Subject: [PATCH 09/12] Rewrote UpdateTraceForSurface in wire_adv.lua. Other wires are now darked while wiring. --- lua/weapons/gmod_tool/stools/wire_adv.lua | 97 +++++++++++++---------- lua/wire/client/cl_wirelib.lua | 8 ++ 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 6309d1d300..375a9f674a 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -425,15 +425,15 @@ elseif CLIENT then if self:GetClientNumber("stick") == 0 then return end if not WireLib.HasPorts(trace.Entity) then return end - local hasAssumedParent = false - local dir = 0 local hitParentPos local hitParentNormal - local closestDistanceSquared = 99999999 - local entityUp = trace.Entity:GetUp() - local entityForward = trace.Entity:GetForward() - local entityRight = trace.Entity:GetRight() - local directions = + local foundParent + local closestDistanceSquared + + local entityUp = trace.Entity:GetUp() * 1000 + local entityForward = trace.Entity:GetForward() * 1000 + local entityRight = trace.Entity:GetRight() * 1000 + local traceVectors = { entityUp, entityForward, @@ -443,48 +443,60 @@ elseif CLIENT then -entityRight } - while dir <= 5 do -- While instead of for, since Lua doesn't allow setting a for iterator variable. - local traceData = util.GetPlayerTrace(LocalPlayer()) - traceData.start = trace.HitPos - local normal = directions[dir + 1] + -- Looks for the parent on all local axes, and returns the closest hit surface on the parent. + local function findParent() + foundParent = false + closestDistanceSquared = 99999999 - traceData.endpos = trace.HitPos + normal * -1000 - traceData.filter = { LocalPlayer(), trace.Entity } - traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP - local newTrace = util.TraceLine(traceData) - - local foundParent = false - if newTrace.Hit and IsValid(parent) and newTrace.Entity == parent then - local distanceSquared = (newTrace.HitPos - trace.HitPos):LengthSqr() - if distanceSquared < closestDistanceSquared then - closestDistanceSquared = distanceSquared - hitParentPos = newTrace.HitPos - hitParentNormal = newTrace.HitNormal - foundParent = true - end - end + for i = 1, 6 do + local traceVector = traceVectors[i] - if not foundParent and (dir >= 5 and not hasAssumedParent) then - -- Didn't find the parent in any direction, assume whichever entity can be traced behind the entity is the "parent". - -- This can happen if eg. the component is not directly on the parent. local traceData = util.GetPlayerTrace(LocalPlayer()) - traceData.filter = { LocalPlayer(), trace.Entity } -- Ignore player and the entity we're trying to wire to. + traceData.start = trace.HitPos -- Start from the original trace. + + traceData.endpos = trace.HitPos + traceVector + traceData.filter = { LocalPlayer(), trace.Entity } traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP - newTrace = util.TraceLine(traceData) - parent = newTrace.Entity - - -- Check all directions again with the new assumed parent. - hasAssumedParent = true - closestDistanceSquared = 99999999 - dir = -1 -- So it gets set to 0 after the increment below. + local newTrace = util.TraceLine(traceData) + + if newTrace.Hit and newTrace.Entity == parent then + local distanceSquared = newTrace.HitPos:DistToSqr(trace.HitPos) + if distanceSquared <= 75 * 75 then + if distanceSquared < closestDistanceSquared then + closestDistanceSquared = distanceSquared + hitParentPos = newTrace.HitPos + hitParentNormal = newTrace.HitNormal + foundParent = true + end + end + end + end + end + + if IsValid(parent) then + findParent() + end + + if not foundParent then + -- Didn't find the parent in any direction, treat whichever entity can be traced behind the entity as the parent. + -- This can happen if eg. the component is not directly on the parent (or if the entity just never had an actual parent). + local traceData = util.GetPlayerTrace(LocalPlayer()) + traceData.filter = { LocalPlayer(), trace.Entity } + traceData.collisiongroup = LAST_SHARED_COLLISION_GROUP + newTrace = util.TraceLine(traceData) + parent = newTrace.Entity + if not IsValid(parent) or parent == game.GetWorld() then + -- Hit the world, don't update the trace. + return end - dir = dir + 1 + findParent() -- Try again with the new assumed parent. end - -- Whatever we hit was the entity's parent. Update trace, and we're done. - trace.HitPos = hitParentPos - trace.Normal = hitParentNormal + if foundParent then + trace.HitPos = hitParentPos + trace.HitNormal = hitParentNormal + end end ----------------------------------------------------------------- @@ -672,6 +684,7 @@ elseif CLIENT then self:Holster() end + self:StopRenderingCurrentWire() self:GetOwner():EmitSound( "weapons/airboat/airboat_gun_lastshot" .. math.random(1,2) .. ".wav" ) end @@ -1088,11 +1101,13 @@ elseif CLIENT then function TOOL:StopRenderingCurrentWire() hook.Remove("PostDrawOpaqueRenderables", "Wire.ToolWireRenderHook") self.IsRenderingCurrentWire = false; + Wire_GrayOutWires = false end function TOOL:BeginRenderingCurrentWire() if self.IsRenderingCurrentWire then return end self.IsRenderingCurrentWire = true + Wire_GrayOutWires = true hook.Add("PostDrawOpaqueRenderables", "Wire.ToolWireRenderHook", function() -- Draw the wire path render.SetColorMaterial() diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index f07f3bac44..1fda852310 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -2,6 +2,7 @@ local WIRE_SCROLL_SPEED = 0.5 local WIRE_BLINKS_PER_SECOND = 2 local CurPathEnt = {} local Wire_DisableWireRender = 0 +Wire_GrayOutWires = false WIRE_CLIENT_INSTALLED = 1 @@ -56,6 +57,13 @@ function Wire_Render(ent) local start = wiretbl.StartPos if (ent:IsValid()) then start = ent:LocalToWorld(start) end local color = wiretbl.Color + if Wire_GrayOutWires then + local newColor = Color(0, 0, 0, 255) + newColor.r = color.r * 0.1 + newColor.g = color.g * 0.1 + newColor.b = color.b * 0.1 + color = newColor + end local nodes = wiretbl.Path local len = #nodes From 136b85825c20fb7ca26b590ff47cd19c0667bea5 Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Sun, 30 Jun 2019 15:35:39 -0400 Subject: [PATCH 10/12] Tweaked a couple things --- lua/weapons/gmod_tool/stools/wire_adv.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 375a9f674a..ab7e343610 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -446,7 +446,7 @@ elseif CLIENT then -- Looks for the parent on all local axes, and returns the closest hit surface on the parent. local function findParent() foundParent = false - closestDistanceSquared = 99999999 + closestDistanceSquared = math.huge for i = 1, 6 do local traceVector = traceVectors[i] @@ -461,13 +461,11 @@ elseif CLIENT then if newTrace.Hit and newTrace.Entity == parent then local distanceSquared = newTrace.HitPos:DistToSqr(trace.HitPos) - if distanceSquared <= 75 * 75 then - if distanceSquared < closestDistanceSquared then - closestDistanceSquared = distanceSquared - hitParentPos = newTrace.HitPos - hitParentNormal = newTrace.HitNormal - foundParent = true - end + if distanceSquared <= 75 * 75 and distanceSquared < closestDistanceSquared then + closestDistanceSquared = distanceSquared + hitParentPos = newTrace.HitPos + hitParentNormal = newTrace.HitNormal + foundParent = true end end end @@ -1236,4 +1234,4 @@ elseif CLIENT then panel:CheckBox("#WireTool_stick", "wire_adv_stick") end -end \ No newline at end of file +end From b557f2f389928ce78ccfa11fb9993852f340247a Mon Sep 17 00:00:00 2001 From: MulleDK19 Date: Mon, 1 Jul 2019 11:33:32 +0200 Subject: [PATCH 11/12] Fixed the active wire not having the right material. Changed method of darkening wires to setting the HSV value. --- lua/weapons/gmod_tool/stools/wire_adv.lua | 2 +- lua/wire/client/cl_wirelib.lua | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index ab7e343610..1503480f14 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -1117,7 +1117,7 @@ elseif CLIENT then local color = Color(self:GetClientNumber("r"), self:GetClientNumber("g"), self:GetClientNumber("b")) local matName = self:GetClientInfo("material") local width = self:GetClientInfo("width") - local mat = Material("cable/cable2") + local mat = Material(matName) local theEnt = wiring[3] if not theEnt:IsValid() then break diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 1fda852310..949e047534 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -58,11 +58,10 @@ function Wire_Render(ent) if (ent:IsValid()) then start = ent:LocalToWorld(start) end local color = wiretbl.Color if Wire_GrayOutWires then - local newColor = Color(0, 0, 0, 255) - newColor.r = color.r * 0.1 - newColor.g = color.g * 0.1 - newColor.b = color.b * 0.1 - color = newColor + local h, s, v = ColorToHSV(color) + v = 0.175 + local tmpColor = HSVToColor(h, s, v) + color = Color(tmpColor.r, tmpColor.g, tmpColor.b, tmpColor.a) -- HSVToColor does not return a proper Color structure. end local nodes = wiretbl.Path From b37fc5b72a75fc13de3ab7c06fdd7af84591142a Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Sat, 6 Jul 2019 02:23:38 -0400 Subject: [PATCH 12/12] Fix wire scroll --- lua/weapons/gmod_tool/stools/wire_adv.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 1503480f14..d473bbbc6c 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -1155,11 +1155,11 @@ elseif CLIENT then if WireLib.HasPorts(traceResult.Entity) then self:UpdateTraceForSurface(traceResult, traceResult.Entity:GetParent()) end - render.AddBeam(traceResult.HitPos, width, scroll, Color(100,100,100,255)) + render.AddBeam(traceResult.HitPos, width, scroll+(traceResult.HitPos-start):Length()/10, Color(100,100,100,255)) else local outputPos = wiring[6] outputPos = outputEntity:LocalToWorld(outputPos) - render.AddBeam(outputPos, width, scroll, Color(100,100,100,255)) + render.AddBeam(outputPos, width, scroll+(outputPos-start):Length()/10, Color(100,100,100,255)) end render.EndBeam() end