From aca7d7aa0adccde84456817863d25d2b213d2ba8 Mon Sep 17 00:00:00 2001 From: kosmik641 Date: Sat, 6 Dec 2025 02:51:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B5=D0=B1=D0=B0=D0=B3=20=D1=81=D0=B8?= =?UTF-8?q?=D0=B3=D0=BD=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8.?= =?UTF-8?q?=20=D0=9F=D0=BE=D1=87=D0=B8=D1=81=D1=82=D0=B8=D0=BB=20=D0=BC?= =?UTF-8?q?=D1=83=D1=81=D0=BE=D1=80=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D1=81=20=D0=B2=D1=81=D1=8E=20=D0=BE=D1=82=D1=80=D0=B8=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D1=83=20=D0=B4=D0=B5=D0=B1=D0=B0=D0=B3=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B2=20ENT:Draw()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gmod_track_autodrive_plate/cl_init.lua | 58 ++--- lua/entities/gmod_track_pa_marker/cl_init.lua | 3 +- lua/entities/gmod_track_platform/cl_init.lua | 73 ++++-- lua/entities/gmod_track_signal/cl_init.lua | 235 +++++++++--------- lua/entities/gmod_track_signs/cl_init.lua | 52 ++-- lua/entities/gmod_track_switch/cl_init.lua | 37 ++- .../gmod_train_autodrive_coil/cl_init.lua | 30 ++- 7 files changed, 245 insertions(+), 243 deletions(-) diff --git a/lua/entities/gmod_track_autodrive_plate/cl_init.lua b/lua/entities/gmod_track_autodrive_plate/cl_init.lua index d85b4d8..094318b 100644 --- a/lua/entities/gmod_track_autodrive_plate/cl_init.lua +++ b/lua/entities/gmod_track_autodrive_plate/cl_init.lua @@ -1,46 +1,26 @@ include("shared.lua") -local debug = GetConVar("metrostroi_drawsignaldebug") -local function enableDebug() - if debug:GetBool() then - hook.Add("PostDrawTranslucentRenderables","MetrostroiAutoDebug",function(bDrawingDepth,bDrawingSkybox) - for _,ent in pairs(ents.FindByClass("gmod_track_autodrive_plate")) do - if bDrawingDepth and LocalPlayer():GetPos():DistToSqr(sig:GetPos()) < 262144 then - local pos = sig:LocalToWorld(Vector(0,0,0)) - local ang = sig:LocalToWorldAngles(Angle(0,90,90)) - cam.Start3D2D(pos, ang, 0.25) - surface.SetDrawColor(125, 125, 0, 255) - surface.DrawRect(-40, -20, 80, 20) - cam.End3D2D() - end - end - end) - else - hook.Remove("PostDrawTranslucentRenderables","MetrostroiAutoDebug") - end -end -hook.Remove("PostDrawTranslucentRenderables","MetrostroiAutoDebug") -cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug) -enableDebug() +local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug") -function ENT:Initialize() -end +function ENT:Draw(flags) + self:DrawModel(flags) -function ENT:OnRemove() -end -function ENT:RemoveModels() -end + if not C_SignalDebug:GetBool() then return end + if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end -function ENT:Draw() - self:DrawModel() - if false and self.SpeedDetectors then - cam.Start3D() - for i,dist in ipairs(self.SpeedDetectors) do - render.DrawLine(self:LocalToWorld(Vector((dist-80)/0.01905,-3.3,5.5)),self:LocalToWorld(Vector((dist-80)/0.01905,3.3,5.5)), Color(255,0,0),true) - render.DrawLine(self:LocalToWorld(Vector((dist-80-0.02)/0.01905,-3.3,5.5)),self:LocalToWorld(Vector((dist-80+0.02)/0.01905,-3.3,5.5)), Color(255,0,0),true) - render.DrawLine(self:LocalToWorld(Vector((dist-80-0.02)/0.01905,3.3,5.5)),self:LocalToWorld(Vector((dist-80+0.02)/0.01905,3.3,5.5)), Color(255,0,0),true) - end - cam.End3D() + local pos = self:LocalToWorld(Vector(0,0,0)) + local ang = self:LocalToWorldAngles(Angle(0,90,90)) + cam.Start3D2D(pos, ang, 0.25) + surface.SetDrawColor(125, 125, 0, 255) + surface.DrawRect(-40, -20, 80, 20) + cam.End3D2D() + + if self.SpeedDetectors then + for i,dist in ipairs(self.SpeedDetectors) do + render.DrawLine(self:LocalToWorld(Vector((dist-80)/0.01905,-3.3,5.5)),self:LocalToWorld(Vector((dist-80)/0.01905,3.3,5.5)), Color(255,0,0),true) + render.DrawLine(self:LocalToWorld(Vector((dist-80-0.02)/0.01905,-3.3,5.5)),self:LocalToWorld(Vector((dist-80+0.02)/0.01905,-3.3,5.5)), Color(255,0,0),true) + render.DrawLine(self:LocalToWorld(Vector((dist-80-0.02)/0.01905,3.3,5.5)),self:LocalToWorld(Vector((dist-80+0.02)/0.01905,3.3,5.5)), Color(255,0,0),true) + end end end @@ -53,4 +33,4 @@ net.Receive("metrostroi_auodrive_coils",function() table.insert(ent.SpeedDetectors,net.ReadFloat()) end PrintTable(ent.SpeedDetectors) -end) \ No newline at end of file +end) diff --git a/lua/entities/gmod_track_pa_marker/cl_init.lua b/lua/entities/gmod_track_pa_marker/cl_init.lua index 0b72226..00caebf 100644 --- a/lua/entities/gmod_track_pa_marker/cl_init.lua +++ b/lua/entities/gmod_track_pa_marker/cl_init.lua @@ -7,6 +7,7 @@ function ENT:DrawTranslucent(flags) self:SetNoDraw(true) return end + if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end self:DrawModel(flags) @@ -19,7 +20,7 @@ function ENT:DrawTranslucent(flags) cam.End3D() end -cvars.AddChangeCallback("metrostroi_drawsignaldebug", function (name, oldValue, newValue) +cvars.AddChangeCallback("metrostroi_drawsignaldebug", function() local noDraw = not C_SignalDebug:GetBool() for _,ent in pairs(ents.FindByClass("gmod_track_pa_marker")) do ent:SetNoDraw(noDraw) diff --git a/lua/entities/gmod_track_platform/cl_init.lua b/lua/entities/gmod_track_platform/cl_init.lua index d979384..62cd7e1 100644 --- a/lua/entities/gmod_track_platform/cl_init.lua +++ b/lua/entities/gmod_track_platform/cl_init.lua @@ -378,32 +378,59 @@ function ENT:Think() end end +local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug") --------------------------------------------------------------------------------- --- Make sure entity is not drawn --------------------------------------------------------------------------------- function ENT:Draw() - if GetConVar("metrostroi_drawsignaldebug"):GetInt() ~= 1 then return end - local platformStart = self:GetNW2Vector("PlatformStart",false) - local platformEnd = self:GetNW2Vector("PlatformEnd",false) + if not C_SignalDebug:GetBool() then + self:SetNoDraw(true) + return + end - local pos = self:GetPos()+Vector(0,0,50) - --[[ if platformStart and platformEnd then - pos = platformStart + (platformEnd-platformStart)/2+Vector(0,0,50) - end--]] - --print(2) - local ang = self:LocalToWorldAngles(Angle(0,180,90)) - cam.Start3D2D(pos, ang, 0.25) - surface.SetDrawColor(125, 125, 0, 255) - surface.DrawRect(0, 0, 160, 24) + local pos, ang + local stationIndex = self:GetNWInt("StationIndex") + local platformIndex = self:GetNWInt("PlatformIndex") + local platformStart = self:GetNW2Vector("PlatformStart") + local platformEnd = self:GetNW2Vector("PlatformEnd") - draw.DrawText(Format("[%d]/%d",self:GetNWInt("StationIndex"),self:GetNWInt("PlatformIndex")),"Trebuchet24",5,0,Color(0,0,0,255)) - cam.End3D2D() - local ang = self:LocalToWorldAngles(Angle(0,0,90)) - cam.Start3D2D(pos, ang, 0.25) - surface.SetDrawColor(125, 125, 0, 255) - surface.DrawRect(0, 0, 160, 24) + for i=0,1 do + -- gmod_track_platform + pos = self:LocalToWorld(Vector(0,0,50)) + ang = self:LocalToWorldAngles(Angle(0,i*180,90)) + cam.Start3D2D(pos, ang, 0.25) + if i == 0 then + surface.SetDrawColor(125, 125, 0, 255) + surface.DrawRect(-75, 0, 150, 24) + end + draw.DrawText(Format("[%d]/%d",stationIndex,platformIndex,count),"Trebuchet24",-75,0,Color(0,0,0,255)) + cam.End3D2D() - draw.DrawText(Format("[%d]/%d",self:GetNWInt("StationIndex"),self:GetNWInt("PlatformIndex")),"Trebuchet24",5,0,Color(0,0,0,255)) - cam.End3D2D() + -- Start platform info_target + pos = platformStart + Vector(0,0,35) + cam.Start3D2D(pos, ang, 0.25) + if i == 0 then + surface.SetDrawColor(49, 150, 3, 255) + surface.DrawRect(-75, 0, 150, 24) + end + draw.DrawText(Format("[%d]/%d: Start",stationIndex,platformIndex),"Trebuchet24",-75,0,Color(0,0,0,255)) + cam.End3D2D() + + -- End platform info_target + pos = platformEnd + Vector(0,0,35) + cam.Start3D2D(pos, ang, 0.25) + if i == 0 then + surface.SetDrawColor(125, 50, 0) + surface.DrawRect(-75, 0, 150, 24) + end + draw.DrawText(Format("[%d]/%d: End",stationIndex,platformIndex),"Trebuchet24",-75,0,Color(0,0,0,255)) + cam.End3D2D() + + render.DrawLine(platformStart, platformEnd, Color(255,0,0,255), true) + end end + +cvars.AddChangeCallback("metrostroi_drawsignaldebug", function() + local noDraw = not C_SignalDebug:GetBool() + for _,ent in pairs(ents.FindByClass("gmod_track_platform")) do + ent:SetNoDraw(noDraw) + end +end) \ No newline at end of file diff --git a/lua/entities/gmod_track_signal/cl_init.lua b/lua/entities/gmod_track_signal/cl_init.lua index 0df96f6..62ab5dc 100644 --- a/lua/entities/gmod_track_signal/cl_init.lua +++ b/lua/entities/gmod_track_signal/cl_init.lua @@ -576,11 +576,22 @@ function ENT:Think() return true end -function ENT:Draw() +local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug") + +function ENT:Draw(flags) -- Draw model - self:DrawModel() + self:DrawModel(flags) + + if not C_SignalDebug:GetBool() then return end + if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end + if EyeVector():Dot(self:LocalToWorldAngles(Angle(0,90,90)):Forward()) > 0.1 then return end + + local pos = self:LocalToWorld(Vector(48,0,150)) + local ang = self:LocalToWorldAngles(Angle(0,180,90)) + cam.Start3D2D(pos, ang, 0.25) + self:DrawDebug() + cam.End3D2D() end -local debug = GetConVar("metrostroi_drawsignaldebug") local ars = { {"275 Hz", "0 KM/H"}, @@ -594,7 +605,6 @@ local ars = { {"75 Hz", "80 KM/H"}, } - local cols = { R = Color(200,0,0), Y = Color(200,200,0), @@ -602,127 +612,114 @@ local cols = { W = Color(200,200,200), B = Color(0,0,200), } -local function enableDebug() - if debug:GetBool() then - hook.Add("PreDrawEffects","MetrostroiSignalDebug",function() - for _,sig in pairs(ents.FindByClass("gmod_track_signal")) do - if IsValid(sig) and LocalPlayer():GetPos():DistToSqr(sig:GetPos()) < 147456 then - local pos = sig:LocalToWorld(Vector(48,0,150)) - local ang = sig:LocalToWorldAngles(Angle(0,180,90)) - cam.Start3D2D(pos, ang, 0.25) - if sig:GetNW2Bool("Debug",false) then - surface.SetDrawColor(sig.ARSOnly and 255 or 125, 125, 0, 255) - surface.DrawRect(0, -60, 364, 210) - if not sig.ARSOnly then - surface.DrawRect(0, 155, 240, 170) - surface.DrawRect(0, 330, 240, 190) - surface.SetDrawColor(0,0,0, 255) - surface.DrawRect(245, 155, 119, 365) - else - surface.DrawRect(0, 155, 364, 150) - surface.DrawRect(0, 310, 364, 190) - end +function ENT:DrawDebug() + surface.SetDrawColor(self.ARSOnly and 255 or 125, 125, 0, 255) + + if not self:GetNW2Bool("Debug",false) then + surface.DrawRect(0, 0, 364, 25) + draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0, 0, 0, 255)) + return + end - if sig.Name then - draw.DrawText(Format("Joint main info (%d)",sig:EntIndex()),"Trebuchet24",5,-60,Color(200,0,0,255)) - draw.DrawText("Signal name: "..sig.Name,"Trebuchet24", 15, -40,Color(0, 0, 0, 255)) - draw.DrawText("TrackID: "..sig:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0, 0, 0, 255)) - draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0, 0, 0, 255)) - draw.DrawText(Format("NextSignalName: %s",sig:GetNW2String("NextSignalName","N/A")),"Trebuchet24", 15, 0,Color(0, 0, 0, 255)) - draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("NextPosID",0)),"Trebuchet24", 25, 20,Color(0, 0, 0, 255)) - draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("NextPos",0)),"Trebuchet24", 135, 20,Color(0, 0, 0, 255)) - draw.DrawText(Format("Dist: %.02f",sig:GetNW2Float("DistanceToNext",0)),"Trebuchet24", 15, 40,Color(0, 0, 0, 255)) - draw.DrawText(Format("PrevSignalName: %s",sig:GetNW2String("PrevSignalName","N/A")),"Trebuchet24", 15, 60,Color(0, 0, 0, 255)) - draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("PrevPosID",0)),"Trebuchet24", 25, 80,Color(0, 0, 0, 255)) - draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("PrevPos",0)),"Trebuchet24", 135, 80,Color(0, 0, 0, 255)) - draw.DrawText(Format("DistPrev: %.02f",sig:GetNW2Float("DistanceToPrev",0)),"Trebuchet24", 15, 100,Color(0, 0, 0, 255)) - draw.DrawText(Format("Current route: %d",sig:GetNW2Int("CurrentRoute",-1)),"Trebuchet24", 15, 120,Color(0, 0, 0, 255)) + if not self.Name then + surface.DrawRect(0, 0, 364, 25) + draw.DrawText("No data...","Trebuchet24",5,0,Color(0, 0, 0, 255)) + return + end - draw.DrawText("AB info","Trebuchet24",5,160,Color(200,0,0,255)) - draw.DrawText(Format("Occupied: %s",sig:GetNW2Bool("Occupied",false) and "Y" or "N"),"Trebuchet24",5,180,Color(0, 0, 0, 255)) - draw.DrawText(Format("Linked to controller: %s",sig:GetNW2Bool("LinkedToController",false) and "Y" or "N"),"Trebuchet24",5,200,Color(0, 0, 0, 255)) - draw.DrawText(Format("Num: %d",sig:GetNW2Int("ControllersNumber",0)),"Trebuchet24",10,220,Color(0, 0, 0, 255)) - draw.DrawText(Format("Controller logic: %s",sig:GetNW2Bool("BlockedByController",false) and "Y" or "N"),"Trebuchet24",5,240,Color(0, 0, 0, 255)) - draw.DrawText(Format("Autostop: %s",not sig.ARSOnly and sig.AutostopPresent and (sig:GetNW2Bool("Autostop") and "Up" or "Down") or "No present"),"Trebuchet24",5,260,Color(0, 0, 0, 255)) - draw.DrawText(Format("2/6: %s",sig:GetNW2Bool("2/6",false) and "Y" or "N"),"Trebuchet24",5,280,Color(0, 0, 0, 255)) - draw.DrawText(Format("FreeBS: %d",sig:GetNW2Int("FreeBS")),"Trebuchet24",5,300,Color(0, 0, 0, 255)) + surface.DrawRect(0, -60, 364, 210) - draw.DrawText("ARS info","Trebuchet24",5,335,Color(200,0,0,255)) - local num = 0 - for i,tbl in pairs(ars) do - if not tbl then continue end - if sig:GetNW2Bool("CurrentARS"..(i-1),false) then - draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0,100,0,255)) - draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0,100,0,255)) - else - draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0, 0, 0, 255)) - draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255)) - end - num = num+1 - end - if sig:GetNW2Bool("CurrentARS325",false) or sig:GetNW2Bool("CurrentARS325_2",false) then - draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0,100,0,255)) - draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0,100,0,255)) - else - draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0, 0, 0, 255)) - draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255)) - end - - if not sig.ARSOnly then - draw.DrawText("Signal info","Trebuchet24",250,160,Color(200,0,0,255)) - local ID = 0 - local ID2 = 0 - local first = true - for _,v in ipairs(sig.LensesTBL) do - local data - if not sig.TrafficLightModels[sig.LightType][v] then - data = sig.TrafficLightModels[sig.LightType][#v-1] - else - data = sig.TrafficLightModels[sig.LightType][v] - end - if not data then continue end - - --sig.NamesOffset = sig.NamesOffset + Vector(0,0,data[1]) - if v ~= "M" then - for i = 1,#v do - ID2 = ID2 + 1 - local n = tonumber(sig.Sig[ID2]) - local State = n == 1 and "X" or (n == 2 and (RealTime() % 1.2 > 0.4)) and "B" or false - draw.DrawText(Format(v[i],sig:EntIndex()),"Trebuchet24",250,160 + ID*20 + ID2*20,cols[v[i]]) - if State then - draw.DrawText(State,"Trebuchet24",280,160 + ID*20 + ID2*20,cols[v[i]]) - end - end - else - ID2 = ID2 + 1 - draw.DrawText("M","Trebuchet24",250,160 + ID*20 + ID2*20,Color(200,200,200)) - draw.DrawText(sig.Num or "none","Trebuchet24",280,160 + ID*20 + ID2*20,Color(200,200,200)) - - --if Metrostroi.RoutePointer[sig.Num[1]] then sig.Models[1][sig.RouteNumber]:SetSkin(Metrostroi.RoutePointer[sig.Num[1]]) end - end - - ID = ID + 1 - end - end - else - draw.DrawText("No data...","Trebuchet24",5,0,Color(0, 0, 0, 255)) - end - else - surface.SetDrawColor(sig.ARSOnly and 255 or 125, 125, 0, 255) - surface.DrawRect(0, 0, 364, 25) - draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0, 0, 0, 255)) - end - cam.End3D2D() - end - end - end) + if not self.ARSOnly then + surface.DrawRect(0, 155, 240, 165) + surface.DrawRect(0, 325, 240, 190) + surface.SetDrawColor(0,0,0, 255) + surface.DrawRect(245, 155, 119, 365) else - hook.Remove("PreDrawEffects","MetrostroiSignalDebug") + surface.DrawRect(0, 155, 364, 165) + surface.DrawRect(0, 325, 364, 190) + end + + draw.DrawText(Format("Joint main info (%d)",self:EntIndex()),"Trebuchet24",5,-60,Color(200,0,0,255)) + draw.DrawText("Signal name: "..self.Name,"Trebuchet24", 5, -40,Color(0, 0, 0, 255)) + draw.DrawText("TrackID: "..self:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0, 0, 0, 255)) + draw.DrawText(Format("PosX: %.02f",self:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0, 0, 0, 255)) + draw.DrawText(Format("NextSignalName: %s",self:GetNW2String("NextSignalName","N/A")),"Trebuchet24", 5, 0,Color(0, 0, 0, 255)) + draw.DrawText(Format("TrackID: %s",self:GetNW2Int("NextPosID",0)),"Trebuchet24", 25, 20,Color(0, 0, 0, 255)) + draw.DrawText(Format("PosX: %.02f",self:GetNW2Float("NextPos",0)),"Trebuchet24", 135, 20,Color(0, 0, 0, 255)) + draw.DrawText(Format("Dist: %.02f",self:GetNW2Float("DistanceToNext",0)),"Trebuchet24", 5, 40,Color(0, 0, 0, 255)) + draw.DrawText(Format("PrevSignalName: %s",self:GetNW2String("PrevSignalName","N/A")),"Trebuchet24", 5, 60,Color(0, 0, 0, 255)) + draw.DrawText(Format("TrackID: %s",self:GetNW2Int("PrevPosID",0)),"Trebuchet24", 25, 80,Color(0, 0, 0, 255)) + draw.DrawText(Format("PosX: %.02f",self:GetNW2Float("PrevPos",0)),"Trebuchet24", 135, 80,Color(0, 0, 0, 255)) + draw.DrawText(Format("DistPrev: %.02f",self:GetNW2Float("DistanceToPrev",0)),"Trebuchet24", 5, 100,Color(0, 0, 0, 255)) + draw.DrawText(Format("Current route: %d",self:GetNW2Int("CurrentRoute",-1)),"Trebuchet24", 5, 120,Color(0, 0, 0, 255)) + + draw.DrawText("AB info","Trebuchet24",5,155,Color(200,0,0,255)) + draw.DrawText(Format("Occupied: %s",self:GetNW2Bool("Occupied",false) and "Y" or "N"),"Trebuchet24",5,175,Color(0, 0, 0, 255)) + draw.DrawText(Format("Linked to controller: %s",self:GetNW2Bool("LinkedToController",false) and "Y" or "N"),"Trebuchet24",5,195,Color(0, 0, 0, 255)) + draw.DrawText(Format("Num: %d",self:GetNW2Int("ControllersNumber",0)),"Trebuchet24",25,215,Color(0, 0, 0, 255)) + draw.DrawText(Format("Controller logic: %s",self:GetNW2Bool("BlockedByController",false) and "Y" or "N"),"Trebuchet24",5,235,Color(0, 0, 0, 255)) + draw.DrawText(Format("Autostop: %s",not self.ARSOnly and self.AutostopPresent and (self:GetNW2Bool("Autostop") and "Up" or "Down") or "No present"),"Trebuchet24",5,255,Color(0, 0, 0, 255)) + draw.DrawText(Format("2/6: %s",self:GetNW2Bool("2/6",false) and "Y" or "N"),"Trebuchet24",5,275,Color(0, 0, 0, 255)) + draw.DrawText(Format("FreeBS: %d",self:GetNW2Int("FreeBS")),"Trebuchet24",5,295,Color(0, 0, 0, 255)) + + draw.DrawText("ARS info","Trebuchet24",5,325,Color(200,0,0,255)) + local num = 0 + for i,tbl in pairs(ars) do + if not tbl then continue end + if self:GetNW2Bool("CurrentARS"..(i-1),false) then + draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,345+num*20,Color(0,100,0,255)) + draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,345+num*20,Color(0,100,0,255)) + else + draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,345+num*20,Color(0, 0, 0, 255)) + draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,345+num*20,Color(0, 0, 0, 255)) + end + num = num+1 + end + if self:GetNW2Bool("CurrentARS325",false) or self:GetNW2Bool("CurrentARS325_2",false) then + draw.DrawText("(325 Hz)","Trebuchet24",5,345+num*20,Color(0,100,0,255)) + draw.DrawText(Format("LN:%s Apr0:%s",self:GetNW2Bool("CurrentARS325",false) and "Y" or "N",self:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,345+num*20,Color(0,100,0,255)) + else + draw.DrawText("(325 Hz)","Trebuchet24",5,345+num*20,Color(0, 0, 0, 255)) + draw.DrawText(Format("LN:%s Apr0:%s",self:GetNW2Bool("CurrentARS325",false) and "Y" or "N",self:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,345+num*20,Color(0, 0, 0, 255)) + end + + if not self.ARSOnly then + draw.DrawText("Signal info","Trebuchet24",250,160,Color(200,0,0,255)) + local ID = 0 + local ID2 = 0 + local first = true + for _,v in ipairs(self.LensesTBL) do + local data + if not self.TrafficLightModels[self.LightType][v] then + data = self.TrafficLightModels[self.LightType][#v-1] + else + data = self.TrafficLightModels[self.LightType][v] + end + if not data then continue end + + --self.NamesOffset = self.NamesOffset + Vector(0,0,data[1]) + if v ~= "M" then + for i = 1,#v do + ID2 = ID2 + 1 + local n = tonumber(self.Sig[ID2]) + local State = n == 1 and "X" or (n == 2 and (RealTime() % 1.2 > 0.4)) and "B" or false + draw.DrawText(Format(v[i],self:EntIndex()),"Trebuchet24",250,160 + ID*20 + ID2*20,cols[v[i]]) + if State then + draw.DrawText(State,"Trebuchet24",280,160 + ID*20 + ID2*20,cols[v[i]]) + end + end + else + ID2 = ID2 + 1 + draw.DrawText("M","Trebuchet24",250,160 + ID*20 + ID2*20,Color(200,200,200)) + draw.DrawText(self.Num or "none","Trebuchet24",280,160 + ID*20 + ID2*20,Color(200,200,200)) + + --if Metrostroi.RoutePointer[self.Num[1]] then self.Models[1][self.RouteNumber]:SetSkin(Metrostroi.RoutePointer[self.Num[1]]) end + end + + ID = ID + 1 + end end end -hook.Remove("PreDrawEffects","MetrostroiSignalDebug") -cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug) -enableDebug() Metrostroi.OptimisationPatch() diff --git a/lua/entities/gmod_track_signs/cl_init.lua b/lua/entities/gmod_track_signs/cl_init.lua index 9af9037..661e289 100644 --- a/lua/entities/gmod_track_signs/cl_init.lua +++ b/lua/entities/gmod_track_signs/cl_init.lua @@ -1,28 +1,5 @@ include("shared.lua") -local debug = GetConVar("metrostroi_drawsignaldebug") -local function enableDebug() - if debug:GetBool() then - hook.Add("PostDrawTranslucentRenderables","MetrostroiSignDebug",function(bDrawingDepth,bDrawingSkybox) - for _,ent in pairs(ents.FindByClass("gmod_track_signs")) do - if bDrawingDepth and LocalPlayer():GetPos():DistToSqr(sig:GetPos()) < 262144 then - local pos = sig:LocalToWorld(Vector(0,0,0)) - local ang = sig:LocalToWorldAngles(Angle(0,90,90)) - cam.Start3D2D(pos, ang, 0.25) - surface.SetDrawColor(125, 125, 0, 255) - surface.DrawRect(-40, -20, 80, 20) - cam.End3D2D() - end - end - end) - else - hook.Remove("PostDrawTranslucentRenderables","MetrostroiSignDebug") - end -end -hook.Remove("PostDrawTranslucentRenderables","MetrostroiSignDebug") -cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug) -enableDebug() - function ENT:Initialize() --self.ModelProp = self:GetNWInt("Model") end @@ -53,11 +30,7 @@ function ENT:Think() self.Type = self:GetNWInt("Type") self.ModelProp = self.SignModels[self.Type-1] self.Left = self:GetNWBool("Left",false) - if self.Left then - self.Offset = self:GetNWVector("Offset") - else - self.Offset = self:GetNWVector("Offset") - end + self.Offset = self:GetNWVector("Offset") self:RemoveModels() end if not self.ModelProp then @@ -106,5 +79,26 @@ function ENT:Think() return true end -function ENT:Draw() +local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug") + +function ENT:Draw(flags) + if not C_SignalDebug:GetBool() then + self:SetNoDraw(true) + return + end + if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end + + local pos = self:LocalToWorld(Vector(0,0,0)) + local ang = self:LocalToWorldAngles(Angle(0,90,90)) + cam.Start3D2D(pos, ang, 0.25) + surface.SetDrawColor(125, 125, 0, 255) + surface.DrawRect(-40, -20, 80, 20) + cam.End3D2D() end + +cvars.AddChangeCallback("metrostroi_drawsignaldebug", function() + local noDraw = not C_SignalDebug:GetBool() + for _,ent in pairs(ents.FindByClass("gmod_track_signs")) do + ent:SetNoDraw(noDraw) + end +end) diff --git a/lua/entities/gmod_track_switch/cl_init.lua b/lua/entities/gmod_track_switch/cl_init.lua index 8ef1d0b..7c65dd8 100644 --- a/lua/entities/gmod_track_switch/cl_init.lua +++ b/lua/entities/gmod_track_switch/cl_init.lua @@ -1,26 +1,19 @@ include("shared.lua") -local debug = GetConVar("metrostroi_drawsignaldebug") -local function enableDebug() - if debug:GetBool() then - hook.Add("PreDrawEffects","MetrostroiSwitchDebug",function() - for _,ent in pairs(ents.FindByClass("gmod_track_switch")) do - if IsValid(ent) and LocalPlayer():GetPos():DistToSqr(ent:GetPos()) < 262144 then - local pos = ent:LocalToWorld(Vector(30,0,75)) - local ang = ent:LocalToWorldAngles(Angle(0,180,90)) - cam.Start3D2D(pos, ang, 0.25) - surface.SetDrawColor(125, 125, 0, 255) - surface.DrawRect(0, 0, 160, 24) +local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug") - draw.DrawText("SwitchID:"..ent:GetNW2String("ID"),"Trebuchet24",5,0,Color(0,0,0,255)) - cam.End3D2D() - end - end - end) - else - hook.Remove("PreDrawEffects","MetrostroiSwitchDebug") - end +function ENT:Draw(flags) + self:DrawModel(flags) + + if not C_SignalDebug:GetBool() then return end + if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end + + local pos = self:LocalToWorld(Vector(30,0,75)) + local ang = self:LocalToWorldAngles(Angle(0,180,90)) + cam.Start3D2D(pos, ang, 0.25) + surface.SetDrawColor(125, 125, 0, 255) + surface.DrawRect(0, 0, 160, 24) + + draw.DrawText("SwitchID:"..self:GetNW2String("ID"),"Trebuchet24",5,0,Color(0,0,0,255)) + cam.End3D2D() end -hook.Remove("PreDrawEffects","MetrostroiSwitchDebug") -cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug) -enableDebug() \ No newline at end of file diff --git a/lua/entities/gmod_train_autodrive_coil/cl_init.lua b/lua/entities/gmod_train_autodrive_coil/cl_init.lua index 4df00d7..02f9526 100644 --- a/lua/entities/gmod_train_autodrive_coil/cl_init.lua +++ b/lua/entities/gmod_train_autodrive_coil/cl_init.lua @@ -1,21 +1,31 @@ include("shared.lua") +local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug") + function ENT:Initialize() - self.CanDraw = GetConVar("metrostroi_drawsignaldebug"):GetInt()>0 + self:SetNoDraw(false) + self:DrawShadow(false) + self.CanDraw = C_SignalDebug:GetBool() + for k,v in pairs(self.ValidModels) do if v==self:GetModel() then self.CanDraw = true break end end - self:DrawShadow(false) end -function ENT:Draw() - if not self.CanDraw then return end - self:DrawModel() -end -cvars.AddChangeCallback("metrostroi_drawsignaldebug", function() - for k,auto in pairs(ents.FindByClass("gmod_train_autodrive_coil")) do - if auto.Initialize then auto:Initialize() end + +function ENT:Draw(flags) + if not self.CanDraw then + self:SetNoDraw(true) + return end -end,"AutodriveCoil") \ No newline at end of file + + self:DrawModel(flags) +end + +cvars.AddChangeCallback("metrostroi_drawsignaldebug", function() + for _,ent in pairs(ents.FindByClass("gmod_train_autodrive_coil")) do + ent:Initialize() + end +end) \ No newline at end of file