mirror of
https://github.com/willox/gmod-keypad.git
synced 2025-03-04 03:13:31 -05:00
VGUI Element system
This commit is contained in:
parent
fb2a285fee
commit
766c12cf9b
@ -1,15 +1,14 @@
|
||||
include "sh_init.lua"
|
||||
|
||||
local debug = CreateConVar("keypad_debug", "0")
|
||||
surface.CreateFont("KeypadAbort", {font = "Trebuchet", size = 80, weight = 900})
|
||||
surface.CreateFont("KeypadOK", {font = "Trebuchet", size = 100, weight = 900})
|
||||
surface.CreateFont("KeypadNumber", {font = "Trebuchet", size = 140, weight = 900})
|
||||
|
||||
local mat = CreateMaterial("keypad_aaaaaaaaaaaaaaaaaaaaabaaaaaaaaaasaae", "VertexLitGeneric", {
|
||||
local mat = CreateMaterial("keypad_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaasaae", "VertexLitGeneric", {
|
||||
["$basetexture"] = "white",
|
||||
["$color"] = "{ 42 42 42 }",
|
||||
["$color"] = "{ 35 35 35 }",
|
||||
})
|
||||
|
||||
local VECTOR_X = Vector(1, 0, 0)
|
||||
local VECTOR_Y = Vector(0, 1, 0)
|
||||
local VECTOR_Z = Vector(0, 0, 1)
|
||||
|
||||
function ENT:Draw()
|
||||
render.SetMaterial(mat)
|
||||
@ -21,39 +20,92 @@ function ENT:Draw()
|
||||
pos:Add(self:GetRight() * self.Maxs.y) -- Translate to left
|
||||
pos:Add(self:GetUp() * self.Maxs.z) -- Translate to top
|
||||
|
||||
pos:Add(self:GetForward() * 0.01) -- Pop out of front to stop culling
|
||||
pos:Add(self:GetRight() * -0.03) -- Left margin
|
||||
pos:Add(self:GetUp() * -0.03) -- Top margin
|
||||
pos:Add(self:GetForward() * 0.05) -- Pop out of front to stop culling
|
||||
|
||||
local ang = self:GetAngles()
|
||||
ang:RotateAroundAxis(ang:Right(), -90)
|
||||
ang:RotateAroundAxis(ang:Up(), 90)
|
||||
ang:RotateAroundAxis(ang:Up(), 90)
|
||||
|
||||
local w, h = 130, 230 -- :(
|
||||
local w, h = self.Maxs.y - self.Mins.y, self.Maxs.z - self.Mins.z
|
||||
|
||||
local ply = LocalPlayer()
|
||||
local scale = 0.01
|
||||
|
||||
if not IsValid(ply) then
|
||||
return
|
||||
end
|
||||
|
||||
local intersect = util.IntersectRayWithPlane(ply:EyePos(), ply:GetAimVector(), pos, (ply:EyePos() - pos):GetNormal())
|
||||
print(intersect)
|
||||
|
||||
cam.Start3D2D(pos, ang, 0.05)
|
||||
self:Paint(w, h, intersect.x, intersect.y)
|
||||
cam.Start3D2D(pos, ang, scale)
|
||||
self:Paint(math.floor(w / scale), math.floor(h / scale))
|
||||
cam.End3D2D()
|
||||
end
|
||||
|
||||
if debug:GetBool() then
|
||||
render.SetBlend(0.05)
|
||||
cam.IgnoreZ(true)
|
||||
self:DrawModel()
|
||||
cam.IgnoreZ(false)
|
||||
render.SetBlend(1)
|
||||
local elements = {
|
||||
{ -- Screen
|
||||
x = 0.075,
|
||||
y = 0.04,
|
||||
w = 0.85,
|
||||
h = 0.25,
|
||||
color = Color(50, 75, 50, 255),
|
||||
},
|
||||
{ -- ABORT
|
||||
x = 0.075,
|
||||
y = 0.04 + 0.25 + 0.03,
|
||||
w = 0.85 / 2 - 0.04 / 2 + 0.05,
|
||||
h = 0.125,
|
||||
color = Color(120, 25, 25),
|
||||
text = "ABORT",
|
||||
font = "KeypadAbort"
|
||||
},
|
||||
{ -- OK
|
||||
x = 0.5 + 0.04 / 2 + 0.05,
|
||||
y = 0.04 + 0.25 + 0.03,
|
||||
w = 0.85 / 2 - 0.04 / 2 - 0.05,
|
||||
h = 0.125,
|
||||
color = Color(25, 120, 25),
|
||||
text = "OK",
|
||||
font = "KeypadOK"
|
||||
}
|
||||
}
|
||||
|
||||
do -- Create numbers
|
||||
for i = 1, 9 do
|
||||
local column = (i - 1) % 3
|
||||
|
||||
local row = math.floor((i - 1) / 3)
|
||||
|
||||
local element = {
|
||||
x = 0.075 + (0.3 * column),
|
||||
y = 0.175 + 0.25 + 0.05 + ((0.5 / 3) * row),
|
||||
w = 0.25,
|
||||
h = 0.13,
|
||||
color = Color(120, 120, 120),
|
||||
text = tostring(i)
|
||||
}
|
||||
|
||||
table.insert(elements, element)
|
||||
|
||||
print(i, column, row)
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:Paint(w, h, x, y)
|
||||
surface.SetDrawColor(Color(255, 255, 255, 10))
|
||||
surface.DrawRect(0, 0, w, h * 0.2)
|
||||
-- surface.SetDrawColor(Color(50, 75, 50, 255))
|
||||
-- surface.DrawRect(40, 40, w - 80, h * 0.25)
|
||||
|
||||
for k, element in ipairs(elements) do
|
||||
surface.SetDrawColor(element.color)
|
||||
surface.DrawRect(
|
||||
w * element.x,
|
||||
h * element.y,
|
||||
w * element.w,
|
||||
h * element.h
|
||||
)
|
||||
|
||||
if element.text then
|
||||
surface.SetFont(element.font or "KeypadNumber")
|
||||
|
||||
local textw, texth = surface.GetTextSize(element.text)
|
||||
|
||||
surface.SetTextColor(color_black)
|
||||
surface.SetTextPos(w * element.x + (w * element.w / 2) - textw / 2, h * element.y + (h * element.h / 2) - texth / 2)
|
||||
surface.DrawText(element.text)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user