Advertisement
Guest User

testing

a guest
Apr 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. mon = peripheral.wrap("monitor_0")
  2.  
  3. mouseHeight = 0
  4. mouseWidth = 0
  5.  
  6. local buttons = 5
  7.  
  8. button={}
  9.  
  10. button[1] = {2,9,19,30,37}
  11. button[2] = {2,2,2,2,2}
  12. button[3] = {"Lamp","Spawner","lanterns","Door","Lock"}
  13. button[4] = {colors.lime}
  14. button[5] = {colors.red}
  15. button[6] = {0,0,0,0,0}
  16. button[7] = {colors.white,colors.orange,colors.magenta,colors.yellow,colors.lime}
  17. button[8] = {"back", "back", "back", "back", "back"}
  18.  
  19.  
  20. function clear()
  21. mon.setBackgroundColor(colors.black)
  22. mon.clear()
  23. end
  24.  
  25.  
  26. -- xmin,ymin,text,bgc,tbgc,state
  27. function DrawButton(x,y,text,bgc,tbgc,state)
  28.  
  29. -- setting the background colour
  30.   if state == 1 then
  31.   mon.setBackgroundColor(bgc)
  32.   else
  33.   mon.setBackgroundColor(tbgc)
  34.   end
  35.  
  36. -- setting the position to write the text
  37.   mon.setCursorPos(x,y)    
  38.     mon.write(string.rep(" ", string.len(text) + 2))
  39.  
  40.   mon.setCursorPos(x,y + 1)
  41.     mon.write(" ")
  42.     mon.write(text)
  43.     mon.write(" ")
  44.  
  45.   mon.setCursorPos(x,y+2)
  46.     mon.write(string.rep(" ", string.len(text) + 2))
  47.  
  48. end
  49.  
  50. clear()
  51.  
  52. function fill(amount)
  53.  
  54.    for i = 1,amount do
  55.       DrawButton(button[1][i],button[2][i],button[3][i],button[4][1],button[5][1],button[6][i])
  56.    end  
  57.  
  58. end
  59.  
  60. -- filling the screen with buttons
  61. fill(buttons)
  62.  
  63.  
  64. function active(amount)
  65.   for i = 1,amount do
  66.     if button[6][i] == 1 then
  67.       rs.setBundledOutput(button[8][i],colors.combine(rs.getBundledOutput(button[8][i]),button[7][i]))
  68.    elseif button[6][i] == 0 then
  69.      rs.setBundledOutput(button[8][i],colors.subtract(rs.getBundledOutput(button[8][i]),button[7][i]))
  70.    end
  71.   end
  72. end
  73.  
  74. -- button clicks
  75.  
  76. function CP(amount)
  77.   for i = 1,amount do
  78.  
  79.   if mouseWidth > button[1][i] - 1 and mouseWidth < string.len(button[3][i]) + button[1][i] + 2 and mouseHeight > button[2][i] - 1 and mouseHeight < button[2][i] + 3 then
  80.   button[6][i] = button[6][i] + 1
  81.       if button[6][i] >= 2 then
  82.       button[6][i] = 0
  83.       end  
  84.  
  85.    active(amount)    
  86.        
  87.    fill(buttons)
  88.  
  89.   end
  90.  end
  91. end
  92.  
  93. repeat
  94.  
  95.  event,p1,p2,p3 = os.pullEvent()
  96.  
  97.   if event == "monitor_touch" then
  98.    mouseWidth = p2
  99.    mouseHeight = p3
  100.   CP(buttons)
  101.  end
  102.  
  103. until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement