Advertisement
supersniperguy

Untitled

Jun 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.41 KB | None | 0 0
  1. API = require("buttonAPI")
  2. local component = require("component")
  3. local sides = require("sides")
  4. local event = require("event")
  5. local keyboard = require("keyboard")
  6. local gpu = component.gpu
  7.  
  8. local colors = {
  9.   blue = 0x4286F4,
  10.   purple = 0xB673d6,
  11.   red = 0xC14141,
  12.   green = 0xDA841,
  13.   black = 0x000000,
  14.   white = 0xFFFFFF,
  15.   gray = 0x47494C,
  16.   lightGray = 0xBBBBBB
  17. }
  18.  
  19. -- Data
  20. local sections = {}
  21. local floors = {}
  22. local screens = {}
  23. local floorComponents = {}
  24. local buttons = {}
  25. local elevatorPosition = nil
  26.  
  27. function setSections()
  28.   sections["buttons"] = { x = 1, y = 1, width = 50, height = 20, title = "  CONTROLS  "}
  29.   sections["position"] = { x = 53, y = 1, width = 26, height = 20, title = "  POSITION  "}
  30. end
  31.  
  32. function setFloors()
  33.   floors["main"] = "c88"
  34.   floors["first"] = "495"
  35.   floors["second"] = "425"
  36. end
  37.  
  38. function setScreens()
  39.   screens["main"] = "749"
  40.   screens["first"] = "380"
  41.   screens["second"] = "39b"
  42. end
  43.  
  44. function setFloorComponents()
  45.   for k,v in pairs(floors) do
  46.     floorComponents[v] = component.redstone
  47.     floorComponents[v].address = component.proxy(component.get(v))
  48.   end
  49. end
  50.  
  51. function setButtons()
  52.   buttons["main"] = {x = 2, y = 2, width = 5, height = 5, title = "Main", callback = function() moveTo(floors.main) end}
  53. end
  54.  
  55. -- Screen functions
  56.  
  57. function clear()
  58.   maxWidth, maxHeight = component.gpu.maxResolution()
  59.   gpu.fill(1, 1, maxWidth, maxHeight, " ")
  60. end
  61.  
  62. function printButton(buttonName)
  63.   API.screen()
  64.   button = buttons[buttonName]
  65.   API.setTable(buttonName, button.callback, button.x, button.y, button.width, button.height, button.title, {
  66.     on = colors.green,
  67.     off = colors.green
  68.   })
  69. end
  70.  
  71. function printBorders(sectionName)
  72.   local s = sections[sectionName]
  73.  
  74.   gpu.setBackground(colors.gray)
  75.   gpu.fill(s.x, s.y, s.width, 1, " ")
  76.   gpu.fill(s.x, s.y, 1, s.height, " ")
  77.   gpu.fill(s.x, s.y + s.height, s.width, 1, " ")
  78.   gpu.fill(s.x + s.width, s.y, 1, s.height + 1, " ")
  79.    
  80.   -- set title
  81.   gpu.setBackground(colors.black)
  82.   gpu.set(s.x + 2, s.y, s.title)
  83. end
  84.  
  85. -- Movement functions
  86. function moveTo(floor)
  87.   floorComponents[floor].setOutput(sides.east, 15)
  88.   floorComponents[floor].setOutput(sides.east, 0)
  89.   elevatorPosition = floor
  90. end
  91.  
  92. function moveToMain()
  93.   moveTo(floors.main)
  94. end
  95.  
  96. function moveToFirst()
  97.   moveTo(floors.first)
  98. end
  99.  
  100. -- Initialize components and move to bottom floor
  101. function init()
  102.   API.screen()
  103.  
  104.   event.listen("touch", API.checkxy)
  105.   setFloorComponents()
  106.   setScreens()
  107.   setSections()
  108.   setButtons()
  109.  
  110.   for screen,address in pairs(screens) do
  111.     gpu.bind(component.get(address))
  112.     clear()
  113.  
  114.     for section,sectionSettings in pairs(sections) do
  115.       printBorders(section)
  116.     end
  117.  
  118.     for button,buttonSettings in pairs(buttons) do
  119.       printButton(button)
  120.     end
  121.   end
  122.   gpu.bind(component.get(screens.main))
  123. end
  124.  
  125. function draw()
  126.   for k,v in pairs(screens) do
  127.     gpu.bind(component.get(v))
  128.     y = 3
  129.     for floor,address in pairs(floors) do
  130.       gpu.set(54, y, floor)
  131.       y = y + 1
  132.     end
  133.   end
  134.   gpu.bind(component.get(screens.main))
  135. end
  136.  
  137. -- Program start
  138. init()
  139.  
  140. while event.pull(0.05, "interrupted") == nil do
  141.   local event, address, arg1, arg2, arg3 = event.pull(1)
  142.   if type(address) == "string" and component.isPrimary(address) then
  143.     if event == "key_down" and arg2 == keyboard.keys.q then    
  144.       os.exit(1)
  145.     end
  146.   end
  147.   draw()
  148.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement