Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Created by:
- Fredyman_95 aka Carters Toaster]]
- -- Declarations
- local component = require("component")
- local computer = require("computer")
- local event = require("event")
- local term = require("term")
- local sides = require("sides")
- local unicode = require("unicode")
- local gpu = component.gpu
- local screen = component.screen
- local mainloop = true
- local ActiveButtons = {}
- local buttons = {}
- local logo = [[
- ____ ____ _ _
- | _ \/ ___| ___ ___ _ __ | |_ _ __ ___ | | ___ _ __
- | |_) \___ \ / __/ _ \| '_ \| __| '__/ _ \| |/ _ \ '__|
- | _ < ___) | | (_| (_) | | | | |_| | | (_) | | __/ |
- |_| \_\____/ \___\___/|_| |_|\__|_| \___/|_|\___|_|]]
- -- Requirements check -------------------
- if gpu.maxResolution() < 100 then
- io.stderr:write("Tier 3 GPU and Screen Required")
- computer.beep()
- os.sleep(0.2)
- computer.beep()
- os.exit(1)
- end
- if not component.isAvailable("redstone") then
- io.stderr:write("No RedstoneIO Connected.")
- computer.beep()
- os.sleep(0.2)
- computer.beep()
- os.sleep(0.2)
- computer.beep()
- os.exit(1)
- else
- redstone = component.redstone
- end
- -- End of Requirements check ------------
- -- Prepare GUI ---
- local function colorText(plainText, colorCode, posX, posY)
- gpu.setForeground(colorCode)
- term.setCursor(posX, posY)
- print(plainText)
- gpu.setForeground(0xFFFFFF)
- end
- local function setupRedstoneIO()
- a = 0
- for i, v in pairs(redstone.getInput()) do
- if a == 0 then if v > 0 then buttonCondition0 = true; colorText("ON ", 0x00FF00, 15, 50) else buttonCondition0 = false; colorText("OFF", 0xFF0000, 15, 50) end end
- if a == 1 then if v > 0 then buttonCondition1 = true; colorText("ON ", 0x00FF00, 15, 51) else buttonCondition1 = false; colorText("OFF", 0xFF0000, 15, 51) end end
- if a == 2 then if v > 0 then buttonCondition2 = true; colorText("ON ", 0x00FF00, 15, 52) else buttonCondition2 = false; colorText("OFF", 0xFF0000, 15, 52) end end
- if a == 3 then if v > 0 then buttonCondition3 = true; colorText("ON ", 0x00FF00, 35 ,50) else buttonCondition3 = false; colorText("OFF", 0xFF0000, 35, 50) end end
- if a == 4 then if v > 0 then buttonCondition4 = true; colorText("ON ", 0x00FF00, 35, 51) else buttonCondition4 = false; colorText("OFF", 0xFF0000, 35, 51) end end
- if a == 5 then if v > 0 then buttonCondition5 = true; colorText("ON ", 0x00FF00, 35, 52) else buttonCondition5 = false; colorText("OFF", 0xFF0000, 35, 52) end end
- a = a + 1
- end
- end
- local function InfoBoard()
- term.setCursor(4, 46)
- for i=4, 54 do
- print("─")
- posx = i + 1
- term.setCursor(posx, 46)
- end
- colorText("STATUS:", 0x006DFF, 26, 48)
- term.setCursor(4, 50)
- print("RS Bottom:")
- term.setCursor(4, 51)
- print("RS Top:")
- term.setCursor(4, 52)
- print("RS North:")
- term.setCursor(25,50)
- print("RS South:")
- term.setCursor(25,51)
- print("RS West:")
- term.setCursor(25,52)
- print("RS East:")
- end
- gpu.setResolution(59,57)
- term.clear()
- colorText(logo, 0xFF0000, 1, 1)
- setupRedstoneIO()
- InfoBoard()
- -- End of preprare GUI ---
- -- Buttons Objects ---------------
- local Button = {}
- Button.__index = Button
- function Button.new(xPos, yPos, width, height, label, func, border)
- local self = setmetatable({}, Button)
- if xPos < 1 or xPos > term.window.width then xPos = 1 end
- if yPos < 1 or yPos > term.window.height then yPos = 1 end
- if (width-2) < unicode.len(label) then width = unicode.len(label)+2 end
- if height < 3 then height = 3 end
- if border == nil then
- self.border = true
- else
- self.border = border
- end
- self.xPos = xPos
- self.yPos = yPos
- self.width = width
- self.height = height
- self.label = label
- self.func = func
- self.visible = false
- self.disabled = false
- return self
- end
- function Button.display(self, x, y)
- table.insert(ActiveButtons, 1, self)
- if (self.width-2) < unicode.len(self.label) then self.width = unicode.len(self.label)+2 end
- if x ~= nil and y ~= nil then
- self.xPos = x
- self.yPos = y
- end
- if self.border then
- gpu.fill(self.xPos+1, self.yPos, self.width-2, 1, "─")
- gpu.fill(self.xPos+1, self.yPos+self.height-1, self.width-2, 1, "─")
- gpu.fill(self.xPos, self.yPos+1, 1, self.height-2, "│")
- gpu.fill(self.xPos+self.width-1, self.yPos+1, 1, self.height-2, "│")
- gpu.set(self.xPos, self.yPos, "┌")
- gpu.set(self.xPos+self.width-1, self.yPos, "┐")
- gpu.set(self.xPos, self.yPos+self.height-1, "└")
- gpu.set(self.xPos+self.width-1, self.yPos+self.height-1, "┘")
- end
- gpu.set(self.xPos+1, self.yPos+1, self.label)
- self.visible = true
- end
- function Button.hide(self)
- self.visible = false
- for i,v in ipairs(ActiveButtons) do
- if v == self then table.remove(ActiveButtons, i) end
- end
- if self.border then
- gpu.fill(self.xPos, self.yPos, self.width, self.height, " ")
- else
- gpu.fill(self.xPos+1, self.yPos+1, self.width-2, 1, " ")
- end
- end
- function Button.disable(self, bool)
- if bool == nil then
- self.disabled = false
- else
- self.disabled = bool
- end
- if self.disabled then gpu.setForeground(0x0F0F0F) end
- if self.visible then self:display() end
- gpu.setForeground(0xFFFFFF)
- end
- function Button.touch(self, x, y)
- local wasTouched = false
- if self.visible and not self.disabled then
- if self.border then
- if x >= self.xPos and x <= (self.xPos+self.width-1) and y >= self.yPos and y <= (self.yPos+self.height-1) then wasTouched = true end
- else
- if x >= self.xPos+1 and x <= (self.xPos+self.width-2) and y >= self.yPos+1 and y <= (self.yPos+self.height-2) then wasTouched = true end
- end
- end
- if wasTouched then
- gpu.setBackground(0x878787)
- gpu.set(self.xPos+1, self.yPos+1, self.label)
- gpu.setBackground(0x000000)
- if self.visible then gpu.set(self.xPos+1, self.yPos+1, self.label) end
- self.func()
- end
- return wasTouched
- end
- function Button.forceTouch(self)
- self:touch(self.xPos+1, self.yPos+1)
- end
- -- end of Buttons Objects --------
- -- Events -------------------------------------------------
- local Events = {}
- Events.interrupted = event.listen("interrupted", function()
- mainloop = false
- end)
- Events.touch = event.listen("touch", function(_, screenAddress, x, y, button, playerName)
- local success, msg = xpcall(function()
- if button == 0 then
- for i,v in ipairs(ActiveButtons) do
- if v:touch(x,y) then break end
- end
- end
- end, debug.traceback)
- if not success then
- ErrorMessage = msg
- mainloop = false
- end
- end)
- -- end of Events ------------------------------------------
- -- buttons -----------------------------------------
- buttons = {
- Button0 = Button.new(4, 10, 51, 5, "Button - RS Bottom", function()
- computer.beep(300)
- if not buttonCondition0 then
- redstone.setOutput(sides.bottom, 16)
- buttonCondition0 = not buttonCondition0
- colorText("ON ", 0x00FF00, 15, 50)
- os.sleep(1)
- else
- redstone.setOutput(sides.bottom, 0)
- buttonCondition0 = not buttonCondition0
- colorText("OFF", 0xFF0000, 15, 50)
- os.sleep(1)
- end
- end),
- Button1 = Button.new(4, 16, 51, 5, "Button - RS Top", function()
- computer.beep(600)
- if not buttonCondition1 then
- redstone.setOutput(sides.top, 16)
- buttonCondition1 = not buttonCondition1
- colorText("ON ", 0x00FF00, 15, 51)
- os.sleep(1)
- else
- redstone.setOutput(sides.top, 0)
- buttonCondition1 = not buttonCondition1
- colorText("OFF", 0xFF0000, 15, 51)
- os.sleep(1)
- end
- end),
- Button2 = Button.new(4, 22, 51, 5, "Button - RS North", function()
- computer.beep(900)
- if not buttonCondition2 then
- redstone.setOutput(sides.north, 16)
- buttonCondition2 = not buttonCondition2
- colorText("ON ", 0x00FF00, 15, 52)
- os.sleep(1)
- else
- redstone.setOutput(sides.north, 0)
- buttonCondition2 = not buttonCondition2
- colorText("OFF", 0xFF0000, 15, 52)
- os.sleep(1)
- end
- end),
- Button3 = Button.new(4, 28, 51, 5, "Button - RS South", function()
- computer.beep(1200)
- if not buttonCondition3 then
- redstone.setOutput(sides.south, 16)
- buttonCondition3 = not buttonCondition3
- colorText("ON ", 0x00FF00, 35 ,50)
- os.sleep(1)
- else
- redstone.setOutput(sides.south, 0)
- buttonCondition3 = not buttonCondition3
- colorText("OFF", 0xFF0000, 35, 50)
- os.sleep(1)
- end
- end),
- Button4 = Button.new(4, 34, 51, 5, "Button - RS West", function()
- computer.beep(1500)
- if not buttonCondition4 then
- redstone.setOutput(sides.west, 16)
- buttonCondition4 = not buttonCondition4
- colorText("ON ", 0x00FF00, 35, 51)
- os.sleep(1)
- else
- redstone.setOutput(sides.west, 0)
- buttonCondition4 = not buttonCondition4
- colorText("OFF", 0xFF0000, 35, 51)
- os.sleep(1)
- end
- end),
- Button5 = Button.new(4, 40, 51, 5, "Button - RS East", function()
- computer.beep(1800)
- if not buttonCondition5 then
- redstone.setOutput(sides.east, 16)
- buttonCondition5 = not buttonCondition5
- colorText("ON ", 0x00FF00, 35, 52)
- os.sleep(1)
- else
- redstone.setOutput(sides.east, 0)
- buttonCondition5 = not buttonCondition5
- colorText("OFF", 0xFF0000, 35, 52)
- os.sleep(1)
- end
- end),
- Button6 = Button.new(4, 54, 23, 1, " Turn Off ALL", function()
- computer.beep()
- redstone.setOutput(sides.bottom, 0); buttonCondition0 = false; colorText("OFF", 0xFF0000, 15, 50)
- redstone.setOutput(sides.top, 0); buttonCondition1 = false; colorText("OFF", 0xFF0000, 15, 51)
- redstone.setOutput(sides.north, 0); buttonCondition2 = false; colorText("OFF", 0xFF0000, 15, 52)
- redstone.setOutput(sides.south, 0); buttonCondition3 = false; colorText("OFF", 0xFF0000, 35, 50)
- redstone.setOutput(sides.west, 0); buttonCondition4 = false; colorText("OFF", 0xFF0000, 35, 51)
- redstone.setOutput(sides.east, 0); buttonCondition5 = false; colorText("OFF", 0xFF0000, 35, 52)
- os.sleep(1)
- end),
- Button7 = Button.new(32, 54, 23, 1, " Turn On ALL", function()
- computer.beep()
- redstone.setOutput(sides.bottom, 16); buttonCondition0 = true; colorText("ON ", 0x00FF00, 15, 50)
- redstone.setOutput(sides.top, 16); buttonCondition1 = true; colorText("ON ", 0x00FF00, 15, 51)
- redstone.setOutput(sides.north, 16); buttonCondition2 = true; colorText("ON ", 0x00FF00, 15, 52)
- redstone.setOutput(sides.south, 16); buttonCondition3 = true; colorText("ON ", 0x00FF00, 35 ,50)
- redstone.setOutput(sides.west, 16); buttonCondition4 = true; colorText("ON ", 0x00FF00, 35, 51)
- redstone.setOutput(sides.east, 16); buttonCondition5 = true; colorText("ON ", 0x00FF00, 35, 52)
- os.sleep(1)
- end),
- ExitButton = Button.new(45, 50, 10, 1, " Exit", function()
- computer.beep(2000)
- mainloop = false
- end),
- }
- -- End of buttons -----------------------------------------
- -- Functions ----------------------------------------------
- local function showButtons()
- buttons.Button0:display()
- buttons.Button0:disable(false)
- buttons.Button1:display()
- buttons.Button1:disable(false)
- buttons.Button2:display()
- buttons.Button2:disable(false)
- buttons.Button3:display()
- buttons.Button3:disable(false)
- buttons.Button4:display()
- buttons.Button4:disable(false)
- buttons.Button5:display()
- buttons.Button5:disable(false)
- buttons.Button6:display()
- buttons.Button6:disable(false)
- buttons.Button7:display()
- buttons.Button7:disable(false)
- buttons.ExitButton:display()
- buttons.ExitButton:disable(false)
- end
- local function hideAllButtons()
- buttons.Button0:hide()
- buttons.Button0:disable(true)
- buttons.Button1:hide()
- buttons.Button1:disable(true)
- buttons.Button2:hide()
- buttons.Button2:disable(true)
- buttons.Button3:hide()
- buttons.Button3:disable(true)
- buttons.Button4:hide()
- buttons.Button4:disable(true)
- buttons.Button5:hide()
- buttons.Button5:disable(true)
- buttons.Button6:hide()
- buttons.Button6:disable(true)
- buttons.Button7:hide()
- buttons.Button7:disable(true)
- buttons.ExitButton:hide()
- buttons.ExitButton:disable(true)
- end
- -- end of Functions ---------------------------------------
- showButtons()
- screen.setTouchModeInverted(true)
- while mainloop do
- os.sleep(0.1)
- end
- screen.setTouchModeInverted(false)
- hideAllButtons()
- term.clear()
- gpu.setResolution(160,50)
- print("All buttons disabled!")
- for k,v in pairs(Events) do
- print("Canceling Event Listener: "..k) -- For debug
- event.cancel(v)
- end
- -- End of program -----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement