1
0
mirror of https://github.com/metrostroi-repo/MetrostroiAddon.git synced 2026-05-02 00:42:29 +00:00

Дебаг сигнализации.

Почистил мусор
Перенес всю отрисовку дебаг информации в ENT:Draw()
This commit is contained in:
kosmik641
2025-12-06 02:51:30 +03:00
parent e393387043
commit aca7d7aa0a
7 changed files with 245 additions and 243 deletions

View File

@@ -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))
local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug")
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(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
end)
else
hook.Remove("PostDrawTranslucentRenderables","MetrostroiAutoDebug")
end
end
hook.Remove("PostDrawTranslucentRenderables","MetrostroiAutoDebug")
cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug)
enableDebug()
function ENT:Initialize()
end
function ENT:OnRemove()
end
function ENT:RemoveModels()
end
function ENT:Draw()
self:DrawModel()
if false and self.SpeedDetectors then
cam.Start3D()
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
cam.End3D()
end
end

View File

@@ -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)

View File

@@ -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)
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)
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)
draw.DrawText(Format("[%d]/%d",self:GetNWInt("StationIndex"),self:GetNWInt("PlatformIndex")),"Trebuchet24",5,0,Color(0,0,0,255))
cam.End3D2D()
if not C_SignalDebug:GetBool() then
self:SetNoDraw(true)
return
end
local pos, ang
local stationIndex = self:GetNWInt("StationIndex")
local platformIndex = self:GetNWInt("PlatformIndex")
local platformStart = self:GetNW2Vector("PlatformStart")
local platformEnd = self:GetNW2Vector("PlatformEnd")
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()
-- 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)

View File

@@ -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,94 +612,99 @@ 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)
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 not self.Name then
surface.DrawRect(0, 0, 364, 25)
draw.DrawText("No data...","Trebuchet24",5,0,Color(0, 0, 0, 255))
return
end
surface.DrawRect(0, -60, 364, 210)
if not sig.ARSOnly then
surface.DrawRect(0, 155, 240, 170)
surface.DrawRect(0, 330, 240, 190)
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
surface.DrawRect(0, 155, 364, 150)
surface.DrawRect(0, 310, 364, 190)
surface.DrawRect(0, 155, 364, 165)
surface.DrawRect(0, 325, 364, 190)
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))
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,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))
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,335,Color(200,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 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))
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,355+num*20,Color(0, 0, 0, 255))
draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255))
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 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))
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,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))
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 sig.ARSOnly then
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(sig.LensesTBL) do
for _,v in ipairs(self.LensesTBL) do
local data
if not sig.TrafficLightModels[sig.LightType][v] then
data = sig.TrafficLightModels[sig.LightType][#v-1]
if not self.TrafficLightModels[self.LightType][v] then
data = self.TrafficLightModels[self.LightType][#v-1]
else
data = sig.TrafficLightModels[sig.LightType][v]
data = self.TrafficLightModels[self.LightType][v]
end
if not data then continue end
--sig.NamesOffset = sig.NamesOffset + Vector(0,0,data[1])
--self.NamesOffset = self.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 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],sig:EntIndex()),"Trebuchet24",250,160 + ID*20 + ID2*20,cols[v[i]])
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
@@ -697,32 +712,14 @@ local function enableDebug()
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))
draw.DrawText(self.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
--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
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
hook.Remove("PreDrawEffects","MetrostroiSignalDebug")
end
end
hook.Remove("PreDrawEffects","MetrostroiSignalDebug")
cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug)
enableDebug()
Metrostroi.OptimisationPatch()

View File

@@ -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: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)

View File

@@ -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))
local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug")
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:"..ent:GetNW2String("ID"),"Trebuchet24",5,0,Color(0,0,0,255))
draw.DrawText("SwitchID:"..self:GetNW2String("ID"),"Trebuchet24",5,0,Color(0,0,0,255))
cam.End3D2D()
end
end
end)
else
hook.Remove("PreDrawEffects","MetrostroiSwitchDebug")
end
end
hook.Remove("PreDrawEffects","MetrostroiSwitchDebug")
cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug)
enableDebug()

View File

@@ -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()
function ENT:Draw(flags)
if not self.CanDraw then
self:SetNoDraw(true)
return
end
self:DrawModel(flags)
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
for _,ent in pairs(ents.FindByClass("gmod_train_autodrive_coil")) do
ent:Initialize()
end
end,"AutodriveCoil")
end)