Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Consts
- local NAME = 'Primary Reactor'
- local BTN_PADDING = 5
- local REDSTONE_SIDE = 'right'
- -- Data
- local loadTestRunning = false
- -- Peripherals
- local monitor = peripheral.find('monitor')
- if monitor == nil then
- print('Error: You need to connect a monitor!')
- return
- end
- -- Cached properties
- local monitorWidth, monitorHeight = monitor.getSize()
- local halfWidth = monitorWidth / 2
- -- Generic methods
- function resetMonitor()
- monitor.clear()
- monitor.setCursorPos(0, 0)
- end
- function drawButton(label, y, color, parent)
- local parentWidth = parent.getSize()
- local button = window.create(parent, BTN_PADDING, y, parentWidth - BTN_PADDING * 2, 3)
- button.setBackgroundColor(color)
- button.clear()
- local btnWidth = parentWidth - 10;
- button.setCursorPos(1, 2)
- local remainingWidth = btnWidth - label:len()
- button.write(string.rep(' ', remainingWidth / 2) .. label .. string.rep(' ', remainingWidth / 2))
- button.redraw();
- end
- -- Main logic
- function drawLoop()
- resetMonitor()
- --
- -- First half -> Reactor information
- --
- local leftHalf = window.create(monitor, 1, 1, halfWidth, monitorHeight)
- leftHalf.setBackgroundColor(colors.pink)
- leftHalf.clear()
- -- Draw the reactor name
- leftHalf.setTextColor(colors.black)
- leftHalf.setCursorPos(
- halfWidth / 2 - NAME:len() / 2,
- 2
- )
- leftHalf.write(NAME)
- if loadTestRunning then
- -- Draw a button to stop the load test
- drawButton('Stop load test', 5, colors.red, leftHalf)
- else
- -- Draw a button to start the load test
- drawButton('Start load test', 5, colors.green, leftHalf)
- end
- leftHalf.redraw()
- --
- -- Second half -> Generic base energy information (todo)
- --
- local rightHalf = window.create(monitor, halfWidth + 2, 1, halfWidth, monitorHeight)
- rightHalf.setBackgroundColor(colors.blue)
- rightHalf.clear()
- rightHalf.redraw()
- end
- function checkClick(x, y)
- -- Check if the click is the start / stop load test button
- if x >= BTN_PADDING and x < BTN_PADDING + halfWidth - BTN_PADDING * 2
- and y >= 5 and y < 8
- then
- if loadTestRunning then
- redstone.setOutput(REDSTONE_SIDE, false)
- loadTestRunning = false
- else
- redstone.setOutput(REDSTONE_SIDE, true)
- loadTestRunning = true
- end
- end
- end
- redstone.setOutput(REDSTONE_SIDE, false)
- while true do
- drawLoop()
- local _, _, x, y = os.pullEvent('monitor_touch')
- checkClick(x, y)
- end
Advertisement
Add Comment
Please, Sign In to add comment