Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. local component = require ('component')
  2. local gpu = component.gpu
  3. local pe = require ('event').pull
  4. local W, H = gpu.getResolution()
  5. local bColor, fColor = 0x000000, = 0xffffff
  6. local b_color, f_color = gpu.getBackground(), gpu.getForeground()
  7. local scr = {[1] = '577704fa-54af-4d4b-960d-77ed2c50229a', [2] = '8f607167-d55e-414d-a01e-996e17e629fb', [3] = '09764fde-13a6-48b4-a321-23bdbda184bf'}
  8.  
  9. -------------------------------------------------------------------------------------------------------------------------------------
  10.  
  11. local tButtons = {
  12. {
  13. visible = false, X = W-2, Y = 1, W = 3, H = 3, color = 0xff0000, textColor = 0xffffff, text = 'X',
  14. action = function()
  15. gpu.setBackground(b_color)
  16. gpu.setForeground(f_color)
  17. gpu.fill(1, 1, W, H, ' ')
  18. gpu.bind(scr[1])
  19. os.exit()
  20. end
  21. },
  22. {
  23. visible = false, X = 35, Y = 3, W = 10, H = 3, color = 0x00ff00, textColor = 0xffffff, text = 'Floor 1',
  24. action = function()
  25. gpu.setBackground(b_color)
  26. gpu.setForeground(f_color)
  27. gpu.fill(1, 1, W, H, ' ')
  28. end
  29. },
  30. {
  31. visible = false, X = 35, Y = 8, W = 10, H = 3, color = 0x00ff00, textColor = 0xffffff, text = 'Floor 2',
  32. action = function()
  33. gpu.setBackground(b_color)
  34. gpu.setForeground(f_color)
  35. gpu.fill(1, 1, W, H, ' ')
  36. end
  37. },
  38. }
  39.  
  40. -------------------------------------------------------------------------------------------------------------------------------------
  41.  
  42. local function drawButton(n)
  43. gpu.setBackground(tButtons[n].color)
  44. gpu.setForeground(tButtons[n].textColor)
  45. gpu.fill(tButtons[n].X, tButtons[n].Y, tButtons[n].W, tButtons[n].H, ' ')
  46. gpu.set(tButtons[n].X+(tButtons[n].W/2)-(#tButtons[n].text/2), tButtons[n].Y+(tButtons[n].H/2), tButtons[n].text)
  47. end
  48.  
  49. local function toggleVisible(n)
  50. if tButtons[n].visible then
  51. tButtons[n].visible = false
  52. gpu.setBackground(b_color)
  53. gpu.fill(tButtons[n].X, tButtons[n].Y, tButtons[n].W, tButtons[n].H, ' ')
  54. else
  55. tButtons[n].visible = true
  56. drawButton(n)
  57. end
  58. end
  59.  
  60. -------------------------------------------------------------------------------------------------------------------------------------
  61. gpu.bind(scr[2])
  62. for i = 1, #tButtons do
  63. toggleVisible(i)
  64. end
  65.  
  66. while true do
  67. local tEvent = {pe('touch')}
  68. for i = 1, #tButtons do
  69. if tButtons[i].visible then
  70. if tEvent[3] >= tButtons[i].X and tEvent[3] <= tButtons[i].X+tButtons[i].W and tEvent[4] >= tButtons[i].Y and tEvent[4] <= tButtons[i].Y+tButtons[i].H then
  71. tButtons[i].action()
  72. gpu.bind(scr[i])
  73. for i = 1, #tButtons do
  74. tButtons[i].visible = false
  75. toggleVisible(i)
  76. end
  77. break
  78. end
  79. end
  80. end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement