Advertisement
Guest User

startup

a guest
May 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. --Look throughout the code for comments like this. They explain what to do to change things.
  2.  
  3. --What side the monitor will be on (change this if needed)
  4. side = "back"
  5.  
  6.  
  7.  
  8. m = peripheral.wrap(side)
  9.  
  10.  
  11. --button on/off color
  12. bactive = colors.cyan
  13. binactive=colors.gray
  14. --text on/off color
  15. tactive=colors.white
  16. tinactive=colors.black
  17. --Background color
  18. bgcolor = colors.black
  19.  
  20.  
  21. buttons = {}
  22.      
  23.      
  24.  
  25.       function newButton(id,xmin,xmax,ymin,ymax,text,func)
  26.         buttons[id] = {}
  27.         buttons[id]["xmin"] = xmin
  28.         buttons[id]["xmax"] = xmax
  29.         buttons[id]["ymin"] = ymin
  30.         buttons[id]["ymax"] = ymax
  31.         buttons[id]["active"] = false
  32.         buttons[id]["text"] = text
  33.         buttons[id]["func"] = func
  34.        
  35.       end
  36.       ---------------------------------------------------------------------------------
  37.       function printButton(id)
  38.         ymin = buttons[id]["ymin"]
  39.         ymax = buttons[id]["ymax"]
  40.         xmin = buttons[id]["xmin"]
  41.         xmax = buttons[id]["xmax"]
  42.         text = buttons[id]["text"]
  43.         ia = buttons[id]["active"]
  44.  
  45.        
  46.  
  47.             width = xmax - xmin
  48.             height = ymax - ymin
  49.            
  50.             m.setBackgroundColor(bactive)
  51.             m.setTextColor(tactive)
  52.             for j = ymin,ymax do
  53.              m.setCursorPos(xmin,j)
  54.               for i = xmin,xmax do
  55.  
  56.                 m.write(" ")
  57.  
  58.              end
  59.  
  60.            end
  61.  
  62.          
  63.         m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2)
  64.  
  65.        m.write(text)
  66.        m.setBackgroundColor(bgcolor)
  67.        
  68.       end
  69.       ----------------------------------------------------------------------------------
  70.       function refreshButtons()
  71.         for i = 1,#buttons do
  72.           printButton(i)
  73.         end
  74.       end
  75.     function checkxy( x,y )
  76.         for i = 1, #buttons do
  77.           if y >= buttons[i]["ymin"] and y <= buttons[i]["ymax"] then
  78.             if x >= buttons[i]["xmin"] and x <= buttons[i]["xmax"] then
  79.  
  80.              
  81.               buttons[i]["active"] = not buttons[i]["active"]
  82.               clicked = i
  83.               if buttons[i]["func"] ~= nil then
  84.  
  85.                 buttons[i]["func"]()
  86.  
  87.                
  88.               end
  89.             end
  90.           end
  91.         end
  92.       end
  93.  
  94.  
  95. bool1 = false
  96. bool2 = false
  97. bool3 = false
  98. rs.setBundledOutput("back",0)
  99.  
  100.  
  101.  
  102.  
  103. --White is pigman, Orange is witch, purple is wither skele (Bundled cable)
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. function rain()
  111.   bool1 = true
  112.   bool2 = false
  113.    rs.setOutput("front", bool1)
  114.    sleep(1)
  115.    rs.setOutput("front", bool2)
  116. end
  117.  
  118. --You can add more buttons and also change the size of them. The format is startingx,startingy,endingx,endingy,text,function
  119.  
  120. --The buttons
  121. newButton(1, 2,38,2,11,"Pluie OFF",rain)
  122. ------------------------------------------------
  123.  
  124.  
  125.  
  126. m.clear()
  127. refreshButtons()
  128.  
  129.  
  130. --main loop
  131. while true do
  132.     e,side,x,y = os.pullEvent("monitor_touch")
  133.     checkxy(x,y)
  134.  
  135.     refreshButtons()
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement