Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MONITOR = peripheral.find("monitor")
- term.redirect(MONITOR)
- MONITOR.setTextScale(1)
- term.setCursorBlink(false)
- local WINDOW_WIDTH, WINDOW_HEIGHT = term.getSize()
- local BACKGROUND_COLOR = colors.gray
- local TEXT_COLOR = colors.cyan
- term.setBackgroundColor(BACKGROUND_COLOR)
- term.setTextColor(TEXT_COLOR)
- term.clear()
- local NUKE_INPUT_SIDE = "left"
- local NUKE_OUTPUT_SIDE = "right"
- local NUKE_STATE = false
- local NUKE_STATE_TRANS = {[true] = "RUNNING.", [false] = "OFF."}
- local NUKE_BATTERY_STATE = false --FALSE if battery NOT FULL. TRUE if battery FULL
- local NUKE_BATTERY_TRANS ={[false] = "FILLING.", [true] = "FULL."}
- local REDSTONE_OVERRIDE = false
- rs.setOutput(NUKE_OUTPUT_SIDE, NUKE_STATE)
- local BUTTONS = {} --[[Table containing all BUTTON objects. BUTTON objects are tables containing the bounds of a button, structured as so:
- {
- xPos (left border)
- yPos (top border)
- xPosD (right border)
- yPosD (bottom border)
- func (button function that will fire when clicked or touched)
- }
- ]]--
- function drawButton(xPos, yPos, text, f, textC, backC) --draws a button at xPos and yPos, that displays string text, with text color textC, and background color backC, and executes function f
- term.setCursorPos(xPos, yPos)
- term.setTextColor(textC)
- term.setBackgroundColor(backC)
- term.write(text)
- term.setTextColor(TEXT_COLOR)
- term.setBackgroundColor(BACKGROUND_COLOR)
- local xPosD, yPosD = term.getCursorPos()
- local buttonBounds = {xPos, yPos, xPosD, yPosD, f}
- table.insert(BUTTONS, buttonBounds)
- end
- function drawLabel(xPos, yPos, text, textC, backC) --draws a label at xPos and yPos, that displays string text, with text color textC, with background color backC
- term.setCursorPos(xPos, yPos)
- term.setTextColor(textC)
- term.setBackgroundColor(backC)
- term.write(text)
- term.setTextColor(TEXT_COLOR)
- term.setBackgroundColor(BACKGROUND_COLOR)
- end
- function checkTouchPos(touchX, touchY) --checks if coordinates are within bounds of a button in table BUTTONS and runs function f if true. returns false if no button found
- for _, v in pairs(BUTTONS) do
- if touchX >= v[1] and touchX <= v[3] and touchY >= v[4] and touchY <= v[2] then
- v[5]()
- end
- end
- return false
- end
- function setNukeState(newState) --Will set nuke to new state, returns true if swap was successful or false if swap was unnecessary
- local isBool = {[true] = true, [false] = true}
- if not isBool[newState] then
- error("Input to setNukeState must be type BOOLEAN")
- end
- if NUKE_STATE == newState then
- return false
- else
- NUKE_STATE = newState
- rs.setOutput(NUKE_OUTPUT_SIDE, NUKE_STATE)
- end
- end
- function eNuke() --Defined to pass to drawButton and prevent multiple anonymous functions entering the heap
- setNukeState(true)
- end
- function dNuke() --See eNuke
- setNukeState(false)
- end
- function drawScreen() --Updates render screen
- local RunningCoords = {x = 1, y = WINDOW_HEIGHT * .2}
- local BatteryCoords = {x = 1, y = WINDOW_HEIGHT * .4}
- local ToggleCoords = {x = 1, y = WINDOW_HEIGHT * .8}
- local ManualCoords = {x = 1, y = WINDOW_HEIGHT * .6}
- term.clear()
- drawLabel(RunningCoords.x, RunningCoords.y, "Nuke is " .. NUKE_STATE_TRANS[NUKE_STATE], TEXT_COLOR, BACKGROUND_COLOR) --Draw nuke operational status
- drawLabel(BatteryCoords.x, BatteryCoords.y, "Nuke battery is " .. NUKE_BATTERY_TRANS[NUKE_BATTERY_STATE], TEXT_COLOR, BACKGROUND_COLOR) --Draw nuke battery status
- drawLabel(ManualCoords.x, ManualCoords.y, "Redstone override is" .. tostring(REDSTONE_OVERRIDE), TEXT_COLOR, BACKGROUND_COLOR)
- if not NUKE_STATE and not NUKE_BATTERY_STATE then --Draw nuke enable button if nuke disabled, and battery not full
- drawButton(ToggleCoords.x, ToggleCoords.y, "DISABLE NUKE", eNuke, colors.red, colors.green)
- elseif not NUKE_STATE and NUKE_BATTERY_STATE then --Draw battery full indicator
- drawLabel(ToggleCoords.x, ToggleCoords.y, "BATTERY FULL; NUKE DISABLED", TEXT_COLOR, BACKGROUND_COLOR)
- elseif NUKE_STATE then --Draw nuke disable button if nuke enabled
- drawButton(ToggleCoords.x, ToggleCoords.y, "SCRAM", dNuke, colors.green, colors.red)
- end
- end
- while true do
- drawScreen()
- local eventData = {os.pullEvent()}
- local event = eventData[1]
- if event == "monitor_touch" then
- touchX = eventData[3]
- touchY = eventData[4]
- checkTouchPos(touchX, touchY)
- REDSTONE_OVERRIDE = not REDSTONE_OVERRIDE
- elseif event == "redstone" then
- NUKE_BATTERY_STATE = rs.getInput(NUKE_INPUT_SIDE)
- if not NUKE_BATTERY_STATE and not REDSTONE_OVERRIDE then
- setNukeState(not NUKE_BATTERY_STATE)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment