Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. local event = require("event")
  2. local component = require("component")
  3. local Button = require("button")
  4. local gpu = component.gpu
  5. gpu.setResolution(160, 50)
  6. -- gpu.setResolution(80,25)
  7. local w, h = gpu.getResolution()
  8. local backgroundColor = 0x696969
  9. local s = {}
  10. local buttons = {}
  11.  
  12. function fillBackground(color)
  13.   gpu.setForeground(0x000000)
  14.   gpu.setBackground(color)
  15.   gpu.fill(1, 1, w, h, " ")
  16. end
  17.  
  18. function calculateSize()
  19.  s.buttonWidth = math.floor(w/3)
  20.  s.buttonHeight = math.floor(h/5)
  21.  s.buttonColumnGap = math.floor(w/8)
  22.  s.buttonRowGap = math.floor(h/15)
  23. end
  24.  
  25. --only on startup
  26. function start()
  27.   fillBackground(backgroundColor)
  28.   calculateSize()
  29.   table.insert(buttons, Button:new{x=s.buttonColumnGap, y=s.buttonRowGap, width=s.buttonWidth, height=s.buttonHeight,
  30.     borderColor=0x4b4b4b, fillColor=0x5a5a5a, text="Gravel"}
  31.   )
  32.   table.insert(buttons, Button:new{x=s.buttonColumnGap, y=s.buttonRowGap*2+s.buttonHeight, width=s.buttonWidth, height=s.buttonHeight,
  33.     borderColor=0xffff80, fillColor=0xffffc0, text="Sand"}
  34.   )
  35.   table.insert(buttons, Button:new{x=s.buttonColumnGap, y=s.buttonRowGap*3+s.buttonHeight*2, width=s.buttonWidth, height=s.buttonHeight,
  36.     borderColor=0xffffc0, fillColor=0xf0f0f0, text="Dust"}
  37.   )
  38.   table.insert(buttons, Button:new{x=w-s.buttonColumnGap-s.buttonWidth, y=s.buttonRowGap, width=s.buttonWidth, height=s.buttonHeight,
  39.     borderColor=0x330000, fillColor=0x332400, text="Soulsand"}
  40.   )
  41.   table.insert(buttons, Button:new{x=w-s.buttonColumnGap-s.buttonWidth, y=s.buttonRowGap*2+s.buttonHeight, height=s.buttonHeight,
  42.     borderColor=0x660000, fillColor=0x990000, text="Netherrack"}
  43.   )
  44.   table.insert(buttons, Button:new{x=w-s.buttonColumnGap-s.buttonWidth, y=s.buttonRowGap*3+s.buttonHeight*2, height=s.buttonHeight,
  45.     borderColor=0xccc0ff, fillColor=0xccc0db, text="Endstone"}
  46.   )
  47.  
  48.   for i = 1, #buttons do
  49.     buttons[i]:draw()
  50.   end
  51. end
  52.  
  53. --actions when running
  54. function update()
  55.   repeat
  56.     local ev, _, x, y, user = event.pull()
  57.     if ev == "touch" then
  58.      
  59.       print(buttons[1]:checkClick(x, y))
  60.     end    
  61.   until false
  62. end
  63.  
  64.  
  65. start()
  66. update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement