1
0
mirror of https://github.com/metrostroi-repo/MetrostroiAddon.git synced 2026-05-04 00:52:33 +00:00

Merge branch 'signaldbg-refactor' into unstable

This commit is contained in:
kosmik641
2025-12-10 09:11:15 +03:00
7 changed files with 245 additions and 243 deletions

View File

@@ -1,46 +1,26 @@
include("shared.lua") include("shared.lua")
local debug = GetConVar("metrostroi_drawsignaldebug") local C_SignalDebug = 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()
function ENT:Initialize() function ENT:Draw(flags)
end self:DrawModel(flags)
function ENT:OnRemove() if not C_SignalDebug:GetBool() then return end
end if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end
function ENT:RemoveModels()
end
function ENT:Draw() local pos = self:LocalToWorld(Vector(0,0,0))
self:DrawModel() local ang = self:LocalToWorldAngles(Angle(0,90,90))
if false and self.SpeedDetectors then cam.Start3D2D(pos, ang, 0.25)
cam.Start3D() surface.SetDrawColor(125, 125, 0, 255)
for i,dist in ipairs(self.SpeedDetectors) do surface.DrawRect(-40, -20, 80, 20)
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) cam.End3D2D()
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) if self.SpeedDetectors then
end for i,dist in ipairs(self.SpeedDetectors) do
cam.End3D() 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
end end
@@ -53,4 +33,4 @@ net.Receive("metrostroi_auodrive_coils",function()
table.insert(ent.SpeedDetectors,net.ReadFloat()) table.insert(ent.SpeedDetectors,net.ReadFloat())
end end
PrintTable(ent.SpeedDetectors) PrintTable(ent.SpeedDetectors)
end) end)

View File

@@ -7,6 +7,7 @@ function ENT:DrawTranslucent(flags)
self:SetNoDraw(true) self:SetNoDraw(true)
return return
end end
if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end
self:DrawModel(flags) self:DrawModel(flags)
@@ -19,7 +20,7 @@ function ENT:DrawTranslucent(flags)
cam.End3D() cam.End3D()
end end
cvars.AddChangeCallback("metrostroi_drawsignaldebug", function (name, oldValue, newValue) cvars.AddChangeCallback("metrostroi_drawsignaldebug", function()
local noDraw = not C_SignalDebug:GetBool() local noDraw = not C_SignalDebug:GetBool()
for _,ent in pairs(ents.FindByClass("gmod_track_pa_marker")) do for _,ent in pairs(ents.FindByClass("gmod_track_pa_marker")) do
ent:SetNoDraw(noDraw) ent:SetNoDraw(noDraw)

View File

@@ -378,32 +378,59 @@ function ENT:Think()
end end
end end
local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug")
--------------------------------------------------------------------------------
-- Make sure entity is not drawn
--------------------------------------------------------------------------------
function ENT:Draw() function ENT:Draw()
if GetConVar("metrostroi_drawsignaldebug"):GetInt() ~= 1 then return end if not C_SignalDebug:GetBool() then
local platformStart = self:GetNW2Vector("PlatformStart",false) self:SetNoDraw(true)
local platformEnd = self:GetNW2Vector("PlatformEnd",false) return
end
local pos = self:GetPos()+Vector(0,0,50) local pos, ang
--[[ if platformStart and platformEnd then local stationIndex = self:GetNWInt("StationIndex")
pos = platformStart + (platformEnd-platformStart)/2+Vector(0,0,50) local platformIndex = self:GetNWInt("PlatformIndex")
end--]] local platformStart = self:GetNW2Vector("PlatformStart")
--print(2) local platformEnd = self:GetNW2Vector("PlatformEnd")
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(Format("[%d]/%d",self:GetNWInt("StationIndex"),self:GetNWInt("PlatformIndex")),"Trebuchet24",5,0,Color(0,0,0,255)) for i=0,1 do
cam.End3D2D() -- gmod_track_platform
local ang = self:LocalToWorldAngles(Angle(0,0,90)) pos = self:LocalToWorld(Vector(0,0,50))
cam.Start3D2D(pos, ang, 0.25) ang = self:LocalToWorldAngles(Angle(0,i*180,90))
surface.SetDrawColor(125, 125, 0, 255) cam.Start3D2D(pos, ang, 0.25)
surface.DrawRect(0, 0, 160, 24) 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)) -- Start platform info_target
cam.End3D2D() 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 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)

View File

@@ -576,11 +576,22 @@ function ENT:Think()
return true return true
end end
function ENT:Draw() local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug")
function ENT:Draw(flags)
-- Draw model -- 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 end
local debug = GetConVar("metrostroi_drawsignaldebug")
local ars = { local ars = {
{"275 Hz", "0 KM/H"}, {"275 Hz", "0 KM/H"},
@@ -594,7 +605,6 @@ local ars = {
{"75 Hz", "80 KM/H"}, {"75 Hz", "80 KM/H"},
} }
local cols = { local cols = {
R = Color(200,0,0), R = Color(200,0,0),
Y = Color(200,200,0), Y = Color(200,200,0),
@@ -602,127 +612,114 @@ local cols = {
W = Color(200,200,200), W = Color(200,200,200),
B = Color(0,0,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 function ENT:DrawDebug()
surface.SetDrawColor(sig.ARSOnly and 255 or 125, 125, 0, 255) surface.SetDrawColor(self.ARSOnly and 255 or 125, 125, 0, 255)
surface.DrawRect(0, -60, 364, 210)
if not sig.ARSOnly then if not self:GetNW2Bool("Debug",false) then
surface.DrawRect(0, 155, 240, 170) surface.DrawRect(0, 0, 364, 25)
surface.DrawRect(0, 330, 240, 190) draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0, 0, 0, 255))
surface.SetDrawColor(0,0,0, 255) return
surface.DrawRect(245, 155, 119, 365) end
else
surface.DrawRect(0, 155, 364, 150)
surface.DrawRect(0, 310, 364, 190)
end
if sig.Name then if not self.Name then
draw.DrawText(Format("Joint main info (%d)",sig:EntIndex()),"Trebuchet24",5,-60,Color(200,0,0,255)) surface.DrawRect(0, 0, 364, 25)
draw.DrawText("Signal name: "..sig.Name,"Trebuchet24", 15, -40,Color(0, 0, 0, 255)) draw.DrawText("No data...","Trebuchet24",5,0,Color(0, 0, 0, 255))
draw.DrawText("TrackID: "..sig:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0, 0, 0, 255)) return
draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0, 0, 0, 255)) end
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))
draw.DrawText("AB info","Trebuchet24",5,160,Color(200,0,0,255)) surface.DrawRect(0, -60, 364, 210)
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))
draw.DrawText("ARS info","Trebuchet24",5,335,Color(200,0,0,255)) if not self.ARSOnly then
local num = 0 surface.DrawRect(0, 155, 240, 165)
for i,tbl in pairs(ars) do surface.DrawRect(0, 325, 240, 190)
if not tbl then continue end surface.SetDrawColor(0,0,0, 255)
if sig:GetNW2Bool("CurrentARS"..(i-1),false) then surface.DrawRect(245, 155, 119, 365)
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)
else 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
end end
hook.Remove("PreDrawEffects","MetrostroiSignalDebug")
cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug)
enableDebug()
Metrostroi.OptimisationPatch() Metrostroi.OptimisationPatch()

View File

@@ -1,28 +1,5 @@
include("shared.lua") 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() function ENT:Initialize()
--self.ModelProp = self:GetNWInt("Model") --self.ModelProp = self:GetNWInt("Model")
end end
@@ -53,11 +30,7 @@ function ENT:Think()
self.Type = self:GetNWInt("Type") self.Type = self:GetNWInt("Type")
self.ModelProp = self.SignModels[self.Type-1] self.ModelProp = self.SignModels[self.Type-1]
self.Left = self:GetNWBool("Left",false) self.Left = self:GetNWBool("Left",false)
if self.Left then self.Offset = self:GetNWVector("Offset")
self.Offset = self:GetNWVector("Offset")
else
self.Offset = self:GetNWVector("Offset")
end
self:RemoveModels() self:RemoveModels()
end end
if not self.ModelProp then if not self.ModelProp then
@@ -106,5 +79,26 @@ function ENT:Think()
return true return true
end 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 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)

View File

@@ -1,26 +1,19 @@
include("shared.lua") include("shared.lua")
local debug = GetConVar("metrostroi_drawsignaldebug") local C_SignalDebug = 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)
draw.DrawText("SwitchID:"..ent:GetNW2String("ID"),"Trebuchet24",5,0,Color(0,0,0,255)) function ENT:Draw(flags)
cam.End3D2D() self:DrawModel(flags)
end
end if not C_SignalDebug:GetBool() then return end
end) if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end
else
hook.Remove("PreDrawEffects","MetrostroiSwitchDebug") local pos = self:LocalToWorld(Vector(30,0,75))
end 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 end
hook.Remove("PreDrawEffects","MetrostroiSwitchDebug")
cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug)
enableDebug()

View File

@@ -1,21 +1,31 @@
include("shared.lua") include("shared.lua")
local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug")
function ENT:Initialize() 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 for k,v in pairs(self.ValidModels) do
if v==self:GetModel() then if v==self:GetModel() then
self.CanDraw = true self.CanDraw = true
break break
end end
end end
self:DrawShadow(false)
end end
function ENT:Draw()
if not self.CanDraw then return end function ENT:Draw(flags)
self:DrawModel() if not self.CanDraw then
end self:SetNoDraw(true)
cvars.AddChangeCallback("metrostroi_drawsignaldebug", function() return
for k,auto in pairs(ents.FindByClass("gmod_train_autodrive_coil")) do
if auto.Initialize then auto:Initialize() end
end end
end,"AutodriveCoil")
self:DrawModel(flags)
end
cvars.AddChangeCallback("metrostroi_drawsignaldebug", function()
for _,ent in pairs(ents.FindByClass("gmod_train_autodrive_coil")) do
ent:Initialize()
end
end)