Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.wrap("bottom")
- local reactorController = peripheral.wrap("right")
- local reactorCardData = {}
- local homeButtons = {}
- local backButton = {}
- local infoButton = {}
- local Page = 0
- local backgroundColor = colors.black
- local buttonPositions = {}
- local yieldTime
- local function yield()
- if yieldTime then
- if os.clock() - yieldTime > 2 then
- os.queueEvent("fakeEvent")
- os.pullEvent("fakeEvent")
- yieldTime = os.clock()
- end
- else
- yieldTime = os.clock()
- end
- end
- local function processTouch(x, y)
- click = Point.new(x, y)
- if (not (Page == -1)) and infoButton.isClicked(click) then
- Page = -1
- return
- end
- if Page == 0 then
- for i = 1, 9 do
- if not (homeButtons[i] == nil) then
- if homeButtons[i].isClicked(click) then
- Page = i
- end
- end
- yield()
- end
- elseif backButton.isClicked(click) then
- Page = 0
- end
- os.sleep(0.1)
- yield()
- end
- local function clearMonitor()
- monitor.setBackgroundColor(backgroundColor)
- local x, y = monitor.getSize()
- for i = 1, y do
- monitor.setCursorPos(1, i)
- for j = 1, x do
- monitor.write(" ")
- yield()
- end
- end
- end
- local function getreactorCardData()
- for i = 1, 9 do
- if not (reactorController.get(i) == nil) then
- reactorCardData[i] = {}
- local id, state, title, info = reactorController.get(i)
- reactorCardData[i].id = id
- reactorCardData[i].state = state
- reactorCardData[i].title = title
- reactorCardData[i].info = info
- else
- reactorCardData[i] = nil
- end
- yield()
- end
- end
- local function getHomeButtonColor(reactorData)
- if reactorData.info["timeLeft"] == 0 and reactorData.info["heat"] > 0 then
- return colors.blue
- end
- if reactorData.info["timeLeft"] == 0 and reactorData.info["heat"] == 0 then
- return colors.red
- end
- local heat = reactorData.info["heat"]
- local maxHeat = reactorData.info["maxHeat"]
- if heat > 0.9*maxHeat then
- return colors.orange
- end
- return colors.green
- end
- local function createButtons()
- for i = 1, 9 do
- if not (reactorCardData[i] == nil) then
- color = getHomeButtonColor(reactorCardData[i])
- homeButtons[i] = Button.new(buttonPositions[i].pos, buttonPositions[i].size, reactorCardData[i].title .. "|" .. reactorCardData[i].info["timeLeft"], color, function() switchPage(i) end)
- else
- homeButtons[i] = nil
- end
- yield()
- end
- end
- local function refreshMonitor()
- getreactorCardData()
- clearMonitor()
- if Page == 0 then
- createButtons()
- for i = 1, 9 do
- if not (homeButtons[i] == nil) then
- homeButtons[i].render(monitor)
- end
- yield()
- end
- infoButton.render(monitor)
- elseif Page == -1 then
- monitor.setCursorPos(1,1)
- monitor.write("Tiles on home page change")
- monitor.setCursorPos(1,2)
- monitor.write("color to represent state:")
- monitor.setCursorPos(1,3)
- monitor.write("Red = Off")
- monitor.setCursorPos(1,4)
- monitor.write("Blue = Off(cooling)")
- monitor.setCursorPos(1,5)
- monitor.write("Green = Running")
- monitor.setCursorPos(1,6)
- monitor.write("Orange = Overheating")
- monitor.setCursorPos(1,8)
- monitor.write("Tile text contains the title")
- monitor.setCursorPos(1,9)
- monitor.write("on the first line and then")
- monitor.setCursorPos(1,10)
- monitor.write("time remaining on the second.")
- monitor.setCursorPos(1,12)
- monitor.write("PS. I have it set up to")
- monitor.setCursorPos(1,13)
- monitor.write("autopull updates on restart.")
- backButton.render(monitor)
- else
- local line = 1
- for tag, data in pairs(reactorCardData[Page].info) do
- monitor.setCursorPos(1,line)
- monitor.write(tag .. " : " .. tostring(data))
- line = line + 1
- end
- backButton.render(monitor)
- infoButton.render(monitor)
- end
- yield()
- os.sleep(1)
- end
- local function startMonitor()
- while true do
- local timeout = os.startTimer(1)
- event = {os.pullEvent()}
- if event[1] == "monitor_touch" then
- processTouch(event[3], event[4])
- end
- refreshMonitor()
- yield()
- end
- end
- buttonPositions[1] = { pos = Point.new(1,1); size = Point.new(9,6) }
- buttonPositions[2] = { pos = Point.new(11,1); size = Point.new(9,6) }
- buttonPositions[3] = { pos = Point.new(21,1); size = Point.new(9,6) }
- buttonPositions[4] = { pos = Point.new(1,8); size = Point.new(9,5) }
- buttonPositions[5] = { pos = Point.new(11,8); size = Point.new(9,5) }
- buttonPositions[6] = { pos = Point.new(21,8); size = Point.new(9,5) }
- buttonPositions[7] = { pos = Point.new(1,14); size = Point.new(9,6) }
- buttonPositions[8] = { pos = Point.new(11,14); size = Point.new(9,6) }
- buttonPositions[9] = { pos = Point.new(21,14); size = Point.new(9,6) }
- backButton = Button.new(buttonPositions[9].pos, buttonPositions[9].size, "Back", colors.blue, function() switchPage(0) end)
- infoButton = Button.new(Point.new(29, 19), Point.new(1,1), "i", colors.blue, function() switchPage(0) end)
- monitor.setCursorBlink(false)
- refreshMonitor()
- startMonitor()
Advertisement
Add Comment
Please, Sign In to add comment