Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function boot_logo()
- term.clear()
- local boot = {
- }
- for i = 1, #boot do
- while false do
- print(" ")
- break
- end
- end
- print("Loading DevilLabs, please wait...")
- term.setCursorPos(1,19)
- term.setTextColour(colours.white)
- textutils.slowPrint("LOADING...")
- sleep(1)
- end
- boot_logo()
- local buttons = {
- [1] = {
- x = 10,
- y = 10,
- on_state = "Door Closed",
- off_state = "Door Open",
- current_state = true, -- Initially the button is off
- onClick = function(state) -- Open of close the door
- if state then -- Currently on, closing
- --rednet.open("back")
- term.setCursorPos(1,18)
- term.setTextColour(colours.white)
- textutils.slowPrint("Pocessing...")
- term.setCursorPos(1,19)
- term.setTextColour(colours.blue)
- textutils.slowPrint("Complete!")
- --rednet.broadcast("Closed")
- --rednet.close("back")
- sleep(1)
- os.reboot()
- -- The current state is off: Open The Door
- else
- --rednet.open(back")
- term.setCursorPos(1,18)
- term.setTextColour(colours.lime)
- textutils.slowPrint("Pocessing...")
- term.setCursorPos(1,19)
- term.setTextColour(colours.blue)
- textutils.slowPrint("Complete!")
- --rednet.broadcast("Open")
- --rednet.close("back")
- sleep(1)
- os.reboot()
- -- The current state is off: Close The Door
- end
- end
- }
- }
- local function drawButton(button)
- term.setCursorPos(button.x, button.y)
- if button.current_state then -- If it’s on, our button is green
- term.setBackgroundColor(colors.green)
- else -- Otherwise it’s red
- term.setBackgroundColor(colors.red)
- end
- term.setTextColor(colors.white)
- local button_text -- We’ll store what text we want to write here
- if button.current_state then
- button_text = button.on_state
- --rednet.broadcast("Close")
- else
- button_text = button.off_state
- --rednet.broadcast("Open")
- end
- local button_length = #button.on_state -- How long is our button?
- if #button.off_state > #button.on_state then -- We want the longest it ever gets
- button_length = #button.off_state
- end
- term.write(string.rep(" ", 2 + button_length)) -- Give it a little space on each side
- term.setCursorPos(button.x + 1 + button_length / 2 -
- #button_text / 2, button.y) -- Nothing too complicated here: just centering the text inside of the button
- term.write(button_text) -- Draw our text
- end
- local function checkClick(x, y)
- for index, button in pairs(buttons) do
- local button_length = #button.on_state + 4
- if #button.off_state > #button.on_state then
- button_length = #button.off_state + 4
- end
- if button.y == y and
- x >= button.x and
- x <= button.x + button_length then
- -- Yep, we clicked this button
- button.onClick(button.current_state)
- button.current_state = not button.current_state
- end
- end
- end
- local width, height = term.getSize()
- while true do
- term.setBackgroundColor(colors.black)
- term.clear()
- for index, button in pairs(buttons) do drawButton(button) end
- local e = {os.pullEvent("mouse_click")} -- Change to "monitor_touch" if you’re working with a monitor
- checkClick(e[3], e[4])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement