Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttonMap = {}
- local function drawButtons(monitor, nodes)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Mob Farm Controller")
- buttonMap = {}
- local sortedKeys = {}
- for key in pairs(nodes) do table.insert(sortedKeys, key) end
- table.sort(sortedKeys)
- local x, y = 2, 2
- for _, hostName in ipairs(sortedKeys) do
- local node = nodes[hostName]
- local label = string.format("%s FARM %d (%s)", node.type, node.id, node.status)
- monitor.setCursorPos(x, y)
- monitor.write(label)
- -- Toggle button
- table.insert(buttonMap, {
- x1 = x + #label + 2,
- y1 = y,
- x2 = x + #label + 6,
- y2 = y,
- action = function()
- print("Toggling node: " .. hostName)
- rednet.send(nodeIDs[hostName], { type = "toggle" }, PROTOCOL)
- node.status = "PENDING"
- end
- })
- y = y + 2
- end
- end
- local function handleMouseClicks()
- while true do
- local _, _, x, y = os.pullEvent("monitor_touch")
- for _, button in ipairs(buttonMap) do
- if x >= button.x1 and x <= button.x2 and y >= button.y1 and y <= button.y2 then
- button.action()
- break
- end
- end
- end
- end
- return {
- drawButtons = drawButtons,
- handleMouseClicks = handleMouseClicks,
- }
Advertisement
Add Comment
Please, Sign In to add comment