Advertisement
danya201272

OPENCOMPUTERS GUI

Oct 30th, 2022 (edited)
1,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | Source Code | 0 0
  1. local component = require("component")
  2. local computer = require("computer")
  3. local event = require("event")
  4. local colors = require("colors")
  5. local gpu = component.gpu
  6. local rs = component.redstone
  7. local unicode = require("unicode")
  8. local term = require("term")
  9. local sides = require("sides")
  10. a = 0
  11. term.clear()
  12.  
  13.  
  14. function funcButton()
  15.  
  16. os.sleep(1)
  17. rs.setOutput(1, 255)
  18. rs.setOutput(2, 255)
  19. rs.setOutput(3, 255)
  20. rs.setOutput(4, 255)
  21. rs.setOutput(5, 255)
  22.  
  23. end
  24.  
  25. function funcButton1()
  26.  
  27. computer.beep(1000, 1)
  28. os.sleep(1)
  29. rs.setOutput(1, 0)
  30. rs.setOutput(2, 0)
  31. rs.setOutput(3, 0)
  32. rs.setOutput(4, 0)
  33. rs.setOutput(5, 0)
  34.  
  35. end
  36.  
  37. function funcButton2()
  38.  
  39. if buttons.button2.buttonPressed == true then
  40. rs.setOutput(0, 0)
  41. else
  42. rs.setOutput(0, 255)
  43. end
  44. end
  45.  
  46. function funcButton3()
  47. a = "EXIT"
  48. end
  49.  
  50. buttons = {button =  {x=35, y=7, text="ВКЛ_", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton, height=7, cFore = 0xFFFFFF, cBack = 0x00FF00},
  51.            button1 = {x=55, y=7, text="ВЫКЛ", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton1, height=7, cFore = 0xFFFFFF, cBack = 0xFF0000},
  52.            button2 = {x=35, y=17, text="AUTO", active=true, switchedButton = true, autoSwitch=false, buttonPressed = false, func = funcButton2, height=7, cFore = 0x000000, cBack = 0x00FF00, cFore1 = 0xFFFFFF, cBack1 = 0xFF0000},
  53.            button3 = {x=55, y=17, text="EXIT", active=true, switchedButton = false, autoSwitch=false, buttonPressed = false, func = funcButton3, height=7, cFore = 0xFFFFFF, cBack = 0x0000FF}}
  54.  
  55. function initButtons()
  56.  
  57. for k,v in pairs(buttons) do
  58. v.width = unicode.wlen(v.text) + 10
  59. end
  60.  
  61. end
  62.  
  63. initButtons()
  64.  
  65. function drawButtons()
  66.  
  67. for k,v in pairs(buttons) do
  68. if v.active then
  69. if not v.buttonPressed then -- если кнопка не нажата
  70. gpu.setForeground(v.cFore)
  71. gpu.setBackground(v.cBack)
  72. else                      -- в ином случае
  73. gpu.setForeground(v.cFore1)
  74. gpu.setBackground(v.cBack1)
  75. end
  76. gpu.fill(v.x, v.y, v.width, v.height, " ") -- фон для кнопки
  77. if v.height == 1 then         -- если высота кнопки равна 1
  78. gpu.set(v.x+4, v.y, v.text)
  79. elseif v.height%2 == 0 then   -- если высота кнопки равна четному числу
  80. gpu.set(v.x+4, v.y + (v.height/2 - 1), v.text)
  81. elseif v.height%2 == 1 then   -- если высота кнопки равна нечетному числу
  82. gpu.set(v.x+4, v.y + (math.ceil(v.height/2) - 1), v.text)
  83. end
  84. if v.autoSwitch == true and v.buttonPressed == true then
  85. v.buttonPressed = false
  86. os.sleep(4)
  87. drawButtons()
  88. end
  89. end
  90. end
  91. gpu.setForeground(0xFFFFFF)
  92. gpu.setBackground(0x000000)
  93.  
  94. end
  95.  
  96. function spam()
  97.  
  98. if component.redstone.getOutput(1) == 255 then
  99.     gpu.set(buttons.button.x + buttons.button.width - 30 - 4 , buttons.button.y, "РЕАКТОРЫ:ВКЛ_")
  100.     os.sleep(1)
  101.     else
  102.     gpu.set(buttons.button.x + buttons.button.width - 30 - 4 , buttons.button.y, "РЕАКТОРЫ:ВЫКЛ")
  103.     os.sleep(1)
  104. end
  105. end
  106.  
  107. function searchButton()
  108.  
  109. while true do
  110. spam()
  111. if a == "EXIT" then
  112.         term.clear()
  113.         break
  114.     end
  115. local _,_,x,y = event.pull("touch")
  116. for k,v in pairs(buttons) do
  117. if x >= v.x and x < v.x + v.width+2 and y >= v.y and y < v.y + v.height and v.active then
  118. if v.switchedButton == true then
  119. if not v.autoSwitch then
  120. if v.buttonPressed == false then
  121. v.buttonPressed = true
  122. else
  123. v.buttonPressed = false
  124. end
  125. else
  126. v.buttonPressed = true
  127. end
  128. term.clear()
  129. drawButtons()
  130. end
  131. v.func()
  132. end
  133. end
  134. end
  135. end
  136.  
  137. drawButtons()
  138. searchButton()
Tags: GTCE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement