Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- API = require("buttonAPI")
- local component = require("component")
- local sides = require("sides")
- local event = require("event")
- local keyboard = require("keyboard")
- local gpu = component.gpu
- local colors = {
- blue = 0x4286F4,
- purple = 0xB673d6,
- red = 0xC14141,
- green = 0xDA841,
- black = 0x000000,
- white = 0xFFFFFF,
- gray = 0x47494C,
- lightGray = 0xBBBBBB
- }
- -- Data
- local sections = {}
- local floors = {}
- local screens = {}
- local floorComponents = {}
- local buttons = {}
- local elevatorPosition = nil
- function setSections()
- sections["buttons"] = { x = 1, y = 1, width = 50, height = 20, title = " CONTROLS "}
- sections["position"] = { x = 53, y = 1, width = 26, height = 20, title = " POSITION "}
- end
- function setFloors()
- floors["main"] = "c88"
- floors["first"] = "495"
- floors["second"] = "425"
- end
- function setScreens()
- screens["main"] = "749"
- screens["first"] = "380"
- screens["second"] = "39b"
- end
- function setFloorComponents()
- for k,v in pairs(floors) do
- floorComponents[v] = component.redstone
- floorComponents[v].address = component.proxy(component.get(v))
- end
- end
- function setButtons()
- buttons["main"] = {x = 2, y = 2, width = 5, height = 5, title = "Main", callback = function() moveTo(floors.main) end}
- end
- -- Screen functions
- function clear()
- maxWidth, maxHeight = component.gpu.maxResolution()
- gpu.fill(1, 1, maxWidth, maxHeight, " ")
- end
- function printButton(buttonName)
- API.screen()
- button = buttons[buttonName]
- API.setTable(buttonName, button.callback, button.x, button.y, button.width, button.height, button.title, {
- on = colors.green,
- off = colors.green
- })
- end
- function printBorders(sectionName)
- local s = sections[sectionName]
- gpu.setBackground(colors.gray)
- gpu.fill(s.x, s.y, s.width, 1, " ")
- gpu.fill(s.x, s.y, 1, s.height, " ")
- gpu.fill(s.x, s.y + s.height, s.width, 1, " ")
- gpu.fill(s.x + s.width, s.y, 1, s.height + 1, " ")
- -- set title
- gpu.setBackground(colors.black)
- gpu.set(s.x + 2, s.y, s.title)
- end
- -- Movement functions
- function moveTo(floor)
- floorComponents[floor].setOutput(sides.east, 15)
- floorComponents[floor].setOutput(sides.east, 0)
- elevatorPosition = floor
- end
- function moveToMain()
- moveTo(floors.main)
- end
- function moveToFirst()
- moveTo(floors.first)
- end
- -- Initialize components and move to bottom floor
- function init()
- API.screen()
- event.listen("touch", API.checkxy)
- setFloorComponents()
- setScreens()
- setSections()
- setButtons()
- for screen,address in pairs(screens) do
- gpu.bind(component.get(address))
- clear()
- for section,sectionSettings in pairs(sections) do
- printBorders(section)
- end
- for button,buttonSettings in pairs(buttons) do
- printButton(button)
- end
- end
- gpu.bind(component.get(screens.main))
- end
- function draw()
- for k,v in pairs(screens) do
- gpu.bind(component.get(v))
- y = 3
- for floor,address in pairs(floors) do
- gpu.set(54, y, floor)
- y = y + 1
- end
- end
- gpu.bind(component.get(screens.main))
- end
- -- Program start
- init()
- while event.pull(0.05, "interrupted") == nil do
- local event, address, arg1, arg2, arg3 = event.pull(1)
- if type(address) == "string" and component.isPrimary(address) then
- if event == "key_down" and arg2 == keyboard.keys.q then
- os.exit(1)
- end
- end
- draw()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement