Nike622000

IC2 Reactor buttons

Oct 27th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. local monSide = "top"
  2. local bunSide = "back"
  3.  
  4. local m = peripheral.wrap(monSide)
  5.  
  6. local xMax,yMax = m.getSize()
  7.  
  8. --xStart,yStart,xEnd,yEnd,txt,displayColor,cableColor,stat
  9. local button = {}
  10. button[1]    = {37,16,53,20,_,_,colors.white}
  11.  
  12. function drawField(xStart,yStart,xEnd,yEnd,col)
  13.     m.setBackgroundColor(col)
  14.     for yP = yStart,yEnd do
  15.         m.setCursorPos(xStart,yP)
  16.         for xP = xStart,xEnd do
  17.             m.write(" ")
  18.         end
  19.     end
  20. end
  21.  
  22. function drawButton(arr)
  23.     for i = 1,#arr do
  24.         drawField(arr[i][1],arr[i][2],arr[i][3],arr[i][4],arr[i][6])
  25.         m.setCursorPos(arr[i][1]+.5+((arr[i][3]-arr[i][1])/2-#arr[i][5]/2),arr[i][2]+(arr[i][4]-arr[i][2])/2)
  26.         m.write(arr[i][5])
  27.     end
  28. end
  29.  
  30. function checkButton(arr,xP,yP)
  31.     for i = 1,#arr do
  32.         if xP >= arr[i][1] and xP <= arr[i][3] and yP >= arr[i][2] and yP <= arr[i][4] then
  33.             if arr[i][8] then
  34.                 arr[i][8] = false
  35.             else
  36.                 arr[i][8] = true
  37.             end
  38.             return i
  39.         end
  40.     end
  41. end
  42.  
  43. while true do
  44.     button[1][8] = colors.test(rs.getBundledInput(bunSide),colors.white)
  45.     if button[1][8] then
  46.         button[1][5] = "Reaktor stoppen"
  47.         button[1][6] = colors.red
  48.     else
  49.         button[1][5] = "Reaktor starten"
  50.         button[1][6] = colors.lime
  51.     end
  52.     drawButton(button)
  53.     local event,_,xP,yP = os.pullEvent("monitor_touch")
  54.     if checkButton(button,xP,yP) == 1 then
  55.         rs.setBundledOutput(bunSide,colors.gray)
  56.         sleep(.5)
  57.         rs.setBundledOutput(bunSide,0)
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment