feat(client/zoneCreator): display modes

add option to display zones as a wireframe, with solid walls, axis helper or both solid walls and axis helper
This commit is contained in:
DokaDoka
2022-09-15 21:19:10 +10:00
parent 18fa0b6391
commit d37324eeed

View File

@@ -4,6 +4,8 @@ local zoneType, step, xCoord, yCoord, zCoord, heading, height, width, length
local steps = {{0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 25, 50, 100}, {0.25, 0.5, 1, 2.5, 5, 15, 30, 45, 60, 90, 180}}
local points = {}
local format = 'array'
local displayModes = {'basic', 'walls', 'axes', 'both'}
local displayMode = 1
local function firstToUpper(str)
return (str:gsub("^%l", string.upper))
@@ -20,12 +22,14 @@ local function updateText()
if zoneType == 'poly' then
text[#text + 1] = ('Height [Shift + Scroll]: %s \n'):format(height)
text[#text + 1] = ('Cycle display mode [G]: %s \n'):format(firstToUpper(displayModes[displayMode]))
text[#text + 1] = 'Create new point - [Space] \n'
elseif zoneType == 'box' then
text[#text + 1] = ('Heading [Q/E]: %s° \n'):format(heading)
text[#text + 1] = ('Height [Shift + Scroll]: %s \n'):format(height)
text[#text + 1] = ('Width [Ctrl + Scroll]: %s \n'):format(width)
text[#text + 1] = ('Length [Alt + Scroll]: %s \n'):format(length)
text[#text + 1] = ('Cycle display mode [G]: %s \n'):format(firstToUpper(displayModes[displayMode]))
text[#text + 1] = 'Recenter - [Space] \n'
elseif zoneType == 'sphere' then
text[#text + 1] = ('Size [Shift + Scroll]: %s \n'):format(height)
@@ -81,8 +85,21 @@ local function closeCreator(cancel)
zoneType = nil
end
local function drawRectangle(rec)
DrawPoly(rec[1].x, rec[1].y, rec[1].z, rec[2].x, rec[2].y, rec[2].z, rec[3].x, rec[3].y, rec[3].z, 255, 42, 24, 100)
DrawPoly(rec[2].x, rec[2].y, rec[2].z, rec[1].x, rec[1].y, rec[1].z, rec[3].x, rec[3].y, rec[3].z, 255, 42, 24, 100)
DrawPoly(rec[1].x, rec[1].y, rec[1].z, rec[4].x, rec[4].y, rec[4].z, rec[3].x, rec[3].y, rec[3].z, 255, 42, 24, 100)
DrawPoly(rec[4].x, rec[4].y, rec[4].z, rec[1].x, rec[1].y, rec[1].z, rec[3].x, rec[3].y, rec[3].z, 255, 42, 24, 100)
end
local function drawLines()
local thickness = vec(0, 0, height / 2)
local activeA, activeB = vec(xCoord, yCoord, zCoord) + thickness, vec(xCoord, yCoord, zCoord) - thickness
if zoneType == 'poly' then
DrawLine(activeA.x, activeA.y, activeA.z, activeB.x, activeB.y, activeB.z, 255, 42, 24, 225)
end
for i = 1, #points do
points[i] = vec(points[i].x, points[i].y, zCoord)
local a = points[i] + thickness
@@ -91,10 +108,30 @@ local function drawLines()
local d = (points[i + 1] and vec(points[i + 1].x, points[i + 1].y, zCoord) or points[1]) - thickness
local e = points[i]
local f = (points[i + 1] and vec(points[i + 1].x, points[i + 1].y, zCoord) or points[1])
DrawLine(a.x, a.y, a.z, b.x, b.y, b.z, 255, 42, 24, 225)
DrawLine(a.x, a.y, a.z, c.x, c.y, c.z, 255, 42, 24, 225)
DrawLine(b.x, b.y, b.z, d.x, d.y, d.z, 255, 42, 24, 225)
DrawLine(e.x, e.y, e.z, f.x, f.y, f.z, 255, 42, 24, 225)
if i == #points and zoneType == 'poly' then
DrawLine(a.x, a.y, a.z, b.x, b.y, b.z, 255, 42, 24, 225)
DrawLine(activeA.x, activeA.y, activeA.z, c.x, c.y, c.z, 255, 42, 24, 225)
DrawLine(activeB.x, activeB.y, activeB.z, d.x, d.y, d.z, 255, 42, 24, 225)
DrawLine(a.x, a.y, a.z, activeA.x, activeA.y, activeA.z, 255, 42, 24, 225)
DrawLine(b.x, b.y, b.z, activeB.x, activeB.y, activeB.z, 255, 42, 24, 225)
DrawLine(xCoord, yCoord, zCoord, f.x, f.y, f.z, 255, 42, 24, 225)
DrawLine(e.x, e.y, e.z, xCoord, yCoord, zCoord, 255, 42, 24, 225)
else
DrawLine(a.x, a.y, a.z, b.x, b.y, b.z, 255, 42, 24, 225)
DrawLine(a.x, a.y, a.z, c.x, c.y, c.z, 255, 42, 24, 225)
DrawLine(b.x, b.y, b.z, d.x, d.y, d.z, 255, 42, 24, 225)
DrawLine(e.x, e.y, e.z, f.x, f.y, f.z, 255, 42, 24, 225)
end
if displayMode == 2 or displayMode == 4 then
if i == #points and zoneType == 'poly' then
drawRectangle({a, b, activeB, activeA})
drawRectangle({activeA, activeB, d, c})
else
drawRectangle({a, b, d, c})
end
end
end
end
@@ -125,9 +162,13 @@ local function startCreator(arg)
end
end
if zoneType == 'poly' then
DrawLine(xCoord, yCoord, zCoord + height / 2, xCoord, yCoord, zCoord - height / 2, 255, 42, 24, 225)
if displayMode == 3 or displayMode == 4 then
DrawLine(xCoord, yCoord, zCoord, xCoord + 2, yCoord, zCoord, 0, 0, 255, 225)
DrawLine(xCoord, yCoord, zCoord, xCoord, yCoord + 2, zCoord, 0, 0, 255, 225)
DrawLine(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord + 2, 0, 0, 255, 225)
end
if zoneType == 'poly' then
drawLines()
elseif zoneType == 'box' then
local rad = math.rad(heading)
@@ -218,6 +259,13 @@ local function startCreator(arg)
if heading < 0 then
heading += 360
end
elseif IsDisabledControlJustReleased(0, 47) then -- g
change = true
if displayMode == #displayModes then
displayMode = 1
else
displayMode += 1
end
elseif IsDisabledControlJustReleased(0, 22) then -- space
change = true
if zoneType == 'poly' then