100 lines
2.7 KiB
Lua
100 lines
2.7 KiB
Lua
local showUI = true
|
|
|
|
local function getTextY(line)
|
|
return 15 + 25 * line
|
|
end
|
|
|
|
local function addLineToTextBox(box, text, color)
|
|
color = color or {1, 1, 1}
|
|
box.lines = box.lines or {}
|
|
box.lines[#box.lines + 1] = {text=text, color=color}
|
|
|
|
local font = love.graphics.getFont()
|
|
local width = font:getWidth(text)
|
|
local boxWidth = box.width or 0
|
|
if width > boxWidth then
|
|
box.width = width
|
|
end
|
|
end
|
|
|
|
local function drawTextBox(box, x, y, margin, padding)
|
|
x = x or 0
|
|
y = y or 0
|
|
margin = margin or 10
|
|
padding = padding or 3
|
|
|
|
local font = love.graphics.getFont()
|
|
local lineHeight = font:getHeight() + padding
|
|
|
|
love.graphics.setColor(0, 0, 0, 0.5)
|
|
love.graphics.rectangle("fill", x, y, box.width + margin * 2, #box.lines * lineHeight - padding + margin * 2)
|
|
|
|
love.graphics.setColor(1, 1, 1)
|
|
for index, line in ipairs(box.lines) do
|
|
love.graphics.setColor(line.color)
|
|
love.graphics.print(line.text, x + margin, y + margin + (index - 1) * lineHeight)
|
|
end
|
|
end
|
|
|
|
function love.draw2()
|
|
local width, height = love.graphics.getDimensions()
|
|
|
|
-- Set background
|
|
love.graphics.setBackgroundColor(0, 0, 0)
|
|
love.graphics.setColor(1, 1, 1)
|
|
|
|
-- Draw camera feed
|
|
if BotState.camfeed then
|
|
local imageWidth = BotState.camfeed:getWidth()
|
|
local imageHeight = BotState.camfeed:getHeight()
|
|
|
|
local scaleWidth = width / imageWidth
|
|
local scaleHeight = height / imageHeight
|
|
local scale = math.min(scaleWidth, scaleHeight)
|
|
|
|
local scaledWidth = imageWidth * scale
|
|
local scaledHeight = imageHeight * scale
|
|
|
|
love.graphics.setShader(CamShader)
|
|
love.graphics.draw(BotState.camfeed,
|
|
(width - scaledWidth) / 2, (height - scaledHeight) / 2,
|
|
0,
|
|
scale, scale
|
|
)
|
|
love.graphics.setShader(nil)
|
|
end
|
|
|
|
local textbox = {}
|
|
|
|
if UIState.showUI then
|
|
-- Draw time
|
|
local time
|
|
if BotState.lastMessage == 0 then
|
|
time = "Never"
|
|
else
|
|
time = math.floor(love.timer.getTime() - BotState.lastMessage) .. "s ago"
|
|
end
|
|
addLineToTextBox(textbox, "Last message received: " .. time)
|
|
|
|
-- Draw cpu battery
|
|
local color = {1, 1, 1}
|
|
if BotState.cpuBatteryCorrected == nil or BotState.cpuBatteryCorrected <= 3 then
|
|
color = {1, 0, 0}
|
|
end
|
|
addLineToTextBox(textbox, "CPU Batt: ".. formatSafe("%.02f (%.02f) V", BotState.cpuBattery, BotState.cpuBatteryCorrected), color)
|
|
|
|
-- Draw servo battery
|
|
local color = {1, 1, 1}
|
|
if BotState.servoBatteryCorrected == nil or BotState.servoBatteryCorrected <= 3 then
|
|
color = {1, 0, 0}
|
|
end
|
|
addLineToTextBox(textbox, "Servo Batt: ".. formatSafe("%.02f (%.02f) V", BotState.servoBattery, BotState.servoBatteryCorrected), color)
|
|
|
|
-- Draw latency
|
|
love.graphics.setColor(1, 1, 1)
|
|
addLineToTextBox(textbox, "Latency: ".. Ping.latency)
|
|
|
|
drawTextBox(textbox)
|
|
end
|
|
end
|