include("shared.lua")

surface.CreateFont("mg_ent_font", {font = "Roboto", size = 42, weight = 500, blursize = 0, scanlines = 0, antialias = true})

function ENT:Draw()
	self:DrawModel()
end

local vector_1 = Vector(0, 0, 1)
local local_ply, pos
function ENT:DrawTranslucent()
	local_ply = local_ply or LocalPlayer()
	pos = self:GetPos()
	self:VisualCutoff(local_ply, pos)
	if self.Distance > 40000 then return end
	local angle = self:GetAngles()	
	local position = pos + (vector_1 * (self:OBBMaxs().z + math.sin(SysTime() * 2) * 2))
	local owner = self:Getowning_ent():IsPlayer() and self:Getowning_ent():Name() or "Niemand"
	angle:RotateAroundAxis(angle:Forward(), 90)
	angle:RotateAroundAxis(angle:Right(),-90)
	angle:RotateAroundAxis(angle:Up(), 0)
	cam.Start3D2D(position, Angle(0, EyeAngles().y - 90, 90), 0.05)
		draw.SimpleTextOutlined(self.PrintName, "mg_ent_font", 0, -250, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, color_black)
		draw.SimpleTextOutlined("Besitzer: "..owner, "mg_ent_font", 0, -200, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, color_black)
		draw.SimpleTextOutlined("Drücke ["..string.upper(input.LookupBinding("+speed") or "SHIFT").." + "..string.upper(input.LookupBinding("+use") or "E").."] zum Aufnehmen.", "mg_ent_font", 0, -150, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, color_black)
	cam.End3D2D()
end

function ENT:VisualCutoff(local_ply, pos)
	local cur_time = CurTime()
	if (self.LastDistanceCheck or 0) > cur_time then return end
	self.LastDistanceCheck = cur_time + 0.1
	self.Distance = pos:DistToSqr(local_ply:EyePos())
end