Advertisement
Guest User

testing

a guest
Apr 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2.  
  3. mouseHeight = 0
  4. mouseWidth = 0
  5.  
  6. local buttons = 3
  7.  
  8. button={}
  9.  
  10. button[1] = {2,2,2}
  11. button[2] = {2,6,10}
  12. button[3] = {"Lamp","Spawner","lanterns"}
  13. button[4] = {colors.lime}
  14. button[5] = {colors.red}
  15. button[6] = {0,0,0}
  16.  
  17.  
  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.  
  65.  
  66.  
  67.  
  68.  
  69. -- button clicks
  70.  
  71. function CP(amount)
  72.   for i = 1,amount do
  73.  
  74.   if mouseWidth > button[1][i] - 1 and mouseWidth < string.len(button[3][i]) + 4 and mouseHeight > button[2][i] - 1 and mouseHeight < button[2][i] + 3 then
  75.   button[6][i] = button[6][i] + 1
  76.       if button[6][i] >= 2 then
  77.       button[6][i] = 0
  78.       end  
  79.      
  80.        
  81.    fill(buttons)
  82.  
  83.   end
  84.  end
  85. end
  86.  
  87. repeat
  88.  
  89.  event,p1,p2,p3 = os.pullEvent()
  90.  
  91.   if event == "monitor_touch" then
  92.    mouseWidth = p2
  93.    mouseHeight = p3
  94.   CP(buttons)
  95.  
  96.  end
  97.  
  98. until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement