feat: Revamp dashboard display for Turtle Bridge with simplified header, compact turtle list, and enhanced activity log
This commit is contained in:
217
webbridge.lua
217
webbridge.lua
@@ -89,145 +89,102 @@ local function drawDashboard()
|
||||
monitor.setBackgroundColor(colors.black)
|
||||
monitor.clear()
|
||||
|
||||
-- Header (larger for vertical display)
|
||||
drawBox(1, 1, w, 4, colors.blue)
|
||||
centerText(2, "╔════════════════════════════════════════════════╗", colors.white, colors.blue)
|
||||
centerText(3, "║ TURTLE NETWORK BRIDGE CONTROL CENTER ║", colors.white, colors.blue)
|
||||
centerText(4, "╚════════════════════════════════════════════════╝", colors.white, colors.blue)
|
||||
|
||||
monitor.setCursorPos(2, 2)
|
||||
monitor.setTextColor(colors.lime)
|
||||
-- Simple header
|
||||
monitor.setBackgroundColor(colors.blue)
|
||||
monitor.write("\7 ONLINE")
|
||||
monitor.setTextColor(colors.white)
|
||||
monitor.setCursorPos(1, 1)
|
||||
monitor.clearLine()
|
||||
centerText(1, "TURTLE BRIDGE - " .. #turtles .. " TURTLES ONLINE", colors.white, colors.blue)
|
||||
|
||||
-- Stats box (left side, taller)
|
||||
local statsY = 6
|
||||
drawBox(2, statsY, 50, 20, colors.gray)
|
||||
drawBox(3, statsY + 1, 48, 18, colors.black)
|
||||
-- Status line
|
||||
monitor.setBackgroundColor(colors.gray)
|
||||
monitor.setCursorPos(1, 2)
|
||||
monitor.clearLine()
|
||||
monitor.setTextColor(colors.white)
|
||||
monitor.setCursorPos(2, 2)
|
||||
monitor.write("MSG: " .. stats.messagesReceived .. " | CMD: " .. stats.commandsSent .. " | ERR: " .. stats.errors)
|
||||
|
||||
monitor.setTextColor(colors.yellow)
|
||||
-- Turtle list - much larger, starts at line 4
|
||||
monitor.setBackgroundColor(colors.black)
|
||||
monitor.setCursorPos(4, statsY + 1)
|
||||
monitor.write("╔═══ SYSTEM STATISTICS ═══╗")
|
||||
local startY = 4
|
||||
|
||||
local statY = statsY + 3
|
||||
|
||||
-- Messages
|
||||
monitor.setTextColor(colors.lightGray)
|
||||
monitor.setCursorPos(5, statY)
|
||||
monitor.write("Messages Received:")
|
||||
monitor.setTextColor(colors.white)
|
||||
monitor.setCursorPos(38, statY)
|
||||
monitor.write(tostring(stats.messagesReceived))
|
||||
statY = statY + 2
|
||||
|
||||
-- Commands
|
||||
monitor.setTextColor(colors.lightGray)
|
||||
monitor.setCursorPos(5, statY)
|
||||
monitor.write("Commands Sent:")
|
||||
monitor.setTextColor(colors.lime)
|
||||
monitor.setCursorPos(38, statY)
|
||||
monitor.write(tostring(stats.commandsSent))
|
||||
statY = statY + 2
|
||||
|
||||
-- Server Updates
|
||||
monitor.setTextColor(colors.lightGray)
|
||||
monitor.setCursorPos(5, statY)
|
||||
monitor.write("Server Updates:")
|
||||
monitor.setTextColor(colors.lightBlue)
|
||||
monitor.setCursorPos(38, statY)
|
||||
monitor.write(tostring(stats.serverUpdates))
|
||||
statY = statY + 2
|
||||
|
||||
-- Errors
|
||||
monitor.setTextColor(colors.lightGray)
|
||||
monitor.setCursorPos(5, statY)
|
||||
monitor.write("Errors:")
|
||||
monitor.setTextColor(stats.errors > 0 and colors.red or colors.lime)
|
||||
monitor.setCursorPos(38, statY)
|
||||
monitor.write(tostring(stats.errors))
|
||||
statY = statY + 2
|
||||
|
||||
-- Uptime
|
||||
monitor.setTextColor(colors.lightGray)
|
||||
monitor.setCursorPos(5, statY)
|
||||
monitor.write("Uptime:")
|
||||
monitor.setTextColor(colors.white)
|
||||
monitor.setCursorPos(38, statY)
|
||||
monitor.write(formatTime(os.epoch("utc") - stats.startTime))
|
||||
statY = statY + 3
|
||||
|
||||
-- Connection info
|
||||
monitor.setTextColor(colors.gray)
|
||||
monitor.setCursorPos(5, statY)
|
||||
monitor.write("Server: " .. SERVER_URL:sub(8))
|
||||
statY = statY + 1
|
||||
monitor.setCursorPos(5, statY)
|
||||
monitor.write("Channels: " .. STATUS_CHANNEL .. "/" .. COMMAND_CHANNEL)
|
||||
|
||||
-- Turtle list (right side, much taller)
|
||||
local turtleX = 54
|
||||
local turtleWidth = w - turtleX - 1
|
||||
drawBox(turtleX, statsY, turtleWidth, 20, colors.gray)
|
||||
drawBox(turtleX + 1, statsY + 1, turtleWidth - 2, 18, colors.black)
|
||||
|
||||
monitor.setTextColor(colors.yellow)
|
||||
monitor.setCursorPos(turtleX + 2, statsY + 1)
|
||||
monitor.write("╔═══ ACTIVE TURTLES ═══╗")
|
||||
|
||||
local turtleY = statsY + 3
|
||||
local count = 0
|
||||
for id, turtle in pairs(turtles) do
|
||||
if count >= 15 then break end -- Show up to 15 turtles
|
||||
|
||||
local statusColor = getStatusColor(turtle)
|
||||
monitor.setCursorPos(turtleX + 2, turtleY)
|
||||
monitor.setTextColor(statusColor)
|
||||
monitor.write("\7")
|
||||
|
||||
monitor.setTextColor(colors.white)
|
||||
monitor.write(string.format(" T#%-2d", id))
|
||||
|
||||
monitor.setCursorPos(turtleX + 12, turtleY)
|
||||
monitor.setTextColor(colors.lightGray)
|
||||
if turtle.state then
|
||||
local state = turtle.state:upper()
|
||||
if #state > 10 then state = state:sub(1, 10) end
|
||||
monitor.write(state)
|
||||
else
|
||||
monitor.write("UNKNOWN")
|
||||
end
|
||||
|
||||
-- Show position if available
|
||||
if turtle.position then
|
||||
turtleY = turtleY + 1
|
||||
monitor.setCursorPos(turtleX + 4, turtleY)
|
||||
monitor.setTextColor(colors.gray)
|
||||
monitor.write(string.format("X:%d Y:%d Z:%d",
|
||||
turtle.position.x or 0,
|
||||
turtle.position.y or 0,
|
||||
turtle.position.z or 0))
|
||||
end
|
||||
|
||||
turtleY = turtleY + 2
|
||||
count = count + 1
|
||||
end
|
||||
|
||||
if count == 0 then
|
||||
monitor.setCursorPos(turtleX + 2, statsY + 5)
|
||||
if #turtles == 0 then
|
||||
monitor.setTextColor(colors.gray)
|
||||
monitor.write("No turtles detected")
|
||||
monitor.setCursorPos(turtleX + 2, statsY + 6)
|
||||
monitor.write("Waiting for signals...")
|
||||
monitor.setCursorPos(2, startY)
|
||||
monitor.write("No turtles connected. Waiting for signals...")
|
||||
else
|
||||
-- Show all turtles in a compact list
|
||||
local y = startY
|
||||
local count = 0
|
||||
for id, turtle in pairs(turtles) do
|
||||
if y >= h - 5 then break end -- Leave room for activity log
|
||||
|
||||
local statusColor = getStatusColor(turtle)
|
||||
local timeSince = math.floor((os.epoch("utc") - (turtle.lastSeen or 0)) / 1000)
|
||||
|
||||
monitor.setCursorPos(2, y)
|
||||
monitor.setTextColor(statusColor)
|
||||
monitor.write("\7")
|
||||
|
||||
monitor.setTextColor(colors.white)
|
||||
monitor.write(string.format(" Turtle #%-3d", id))
|
||||
|
||||
monitor.setTextColor(colors.lightGray)
|
||||
local state = (turtle.state or "IDLE"):upper()
|
||||
if #state > 12 then state = state:sub(1, 12) end
|
||||
monitor.write(" " .. state)
|
||||
|
||||
-- Position on same line
|
||||
if turtle.position then
|
||||
monitor.setTextColor(colors.gray)
|
||||
monitor.write(string.format(" [%d,%d,%d]",
|
||||
turtle.position.x or 0,
|
||||
turtle.position.y or 0,
|
||||
turtle.position.z or 0))
|
||||
end
|
||||
|
||||
-- Last seen
|
||||
monitor.setTextColor(colors.darkGray)
|
||||
monitor.write(string.format(" %ds", timeSince))
|
||||
|
||||
y = y + 1
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Activity log (bottom section, MUCH taller for vertical display)
|
||||
local logY = 28
|
||||
drawBox(2, logY, w - 2, h - logY - 1, colors.gray)
|
||||
drawBox(3, logY + 1, w - 4, h - logY - 3, colors.black)
|
||||
|
||||
-- Activity log (last 5 lines of screen)
|
||||
local logY = h - 4
|
||||
monitor.setBackgroundColor(colors.gray)
|
||||
monitor.setCursorPos(1, logY)
|
||||
monitor.clearLine()
|
||||
monitor.setTextColor(colors.yellow)
|
||||
monitor.setCursorPos(4, logY + 1)
|
||||
monitor.setCursorPos(2, logY)
|
||||
monitor.write("ACTIVITY LOG")
|
||||
|
||||
logY = logY + 1
|
||||
monitor.setBackgroundColor(colors.black)
|
||||
|
||||
-- Show last 3 log entries
|
||||
for i = 1, math.min(3, #activityLog) do
|
||||
local entry = activityLog[i]
|
||||
monitor.setCursorPos(1, logY)
|
||||
monitor.clearLine()
|
||||
|
||||
monitor.setTextColor(colors.darkGray)
|
||||
local time = os.date("%H:%M:%S", entry.time / 1000)
|
||||
monitor.write(time .. " ")
|
||||
|
||||
monitor.setTextColor(entry.color)
|
||||
local maxWidth = w - 10
|
||||
local text = entry.text
|
||||
if #text > maxWidth then
|
||||
text = text:sub(1, maxWidth - 3) .. "..."
|
||||
end
|
||||
monitor.write(text)
|
||||
|
||||
logY = logY + 1
|
||||
end
|
||||
end
|
||||
monitor.write("╔═══ ACTIVITY LOG ═══╗")
|
||||
|
||||
-- Calculate how many log lines we can show (huge vertical space!)
|
||||
|
||||
Reference in New Issue
Block a user