Advertisement
DarkSiders061

Untitled

Nov 12th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = "top"
  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.             if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive)
  51.             else m.setBackgroundColor(binactive) m.setTextColor(tinactive) end
  52.  
  53.             for j = ymin,ymax do
  54.              m.setCursorPos(xmin,j)
  55.               for i = xmin,xmax do
  56.  
  57.                 m.write(" ")
  58.  
  59.              end
  60.  
  61.            end
  62.  
  63.          
  64.         m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2)
  65.  
  66.        m.write(text)
  67.        m.setBackgroundColor(bgcolor)
  68.        
  69.       end
  70.       ----------------------------------------------------------------------------------
  71.       function refreshButtons()
  72.         for i = 1,#buttons do
  73.           printButton(i)
  74.         end
  75.       end
  76.     function checkxy( x,y )
  77.         for i = 1, #buttons do
  78.           if y >= buttons[i]["ymin"] and y <= buttons[i]["ymax"] then
  79.             if x >= buttons[i]["xmin"] and x <= buttons[i]["xmax"] then
  80.  
  81.              
  82.               buttons[i]["active"] = not buttons[i]["active"]
  83.               clicked = i
  84.               if buttons[i]["func"] ~= nil then
  85.  
  86.                 buttons[i]["func"]()
  87.  
  88.                
  89.               end
  90.             end
  91.           end
  92.         end
  93.       end
  94.  
  95.  
  96. bool1 = false
  97. bool2 = false
  98. bool3 = false
  99. bool4 = false
  100. rs.setBundledOutput("back",0)
  101.  
  102.  
  103.  
  104.  
  105. --White is pigman, Orange is witch, purple is wither skele (Bundled cable)
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. function IronGolem()
  113.   current = rs.getBundledOutput("back")
  114.     bool1 = not bool1
  115.   if bool1 then
  116.      rs.setBundledOutput("back",current+colors.white)
  117.   else
  118.     rs.setBundledOutput("back",current-colors.white)
  119.   end
  120. end
  121.  
  122. function GoldGolem()
  123.   current = rs.getBundledOutput("back")
  124.     bool4 = not bool4
  125.   if bool4 then
  126.      rs.setBundledOutput("back",current+colors.white)
  127.   else
  128.     rs.setBundledOutput("back",current-colors.white)
  129.   end
  130. end
  131.  
  132. function witch()
  133.   current = rs.getBundledOutput("back")
  134.     bool2 = not bool2
  135.     if bool2 then
  136.    rs.setBundledOutput("back",current+colors.orange)
  137.   else
  138.     rs.setBundledOutput("back",current-colors.orange)
  139.   end
  140. end
  141.  
  142. function wither()
  143.   current = rs.getBundledOutput("back")
  144.     bool3 = not bool3
  145.     if bool3 then
  146.    rs.setBundledOutput("back",current+colors.magenta)
  147.   else
  148.     rs.setBundledOutput("back",current-colors.magenta)
  149.   end
  150. end
  151.  
  152.  
  153. --You can add more buttons and also change the size of them. The format is startingx,startingy,endingx,endingy,text,function
  154.  
  155. --The buttons
  156. newButton(1, 2,11,2,8,"IronGolem",IronGolem)
  157. newButton(1, 2,11,2,8,"GoldGolem",GoldGolem)
  158. newButton(2, 13,22,2,8,"Witch",witch)
  159. newButton(3, 24,37,2,8,"Wither Skeleton",wither)
  160. ------------------------------------------------
  161.  
  162.  
  163.  
  164. m.clear()
  165. refreshButtons()
  166.  
  167.  
  168. --main loop
  169. while true do
  170.     e,side,x,y = os.pullEvent("monitor_touch")
  171.     checkxy(x,y)
  172.  
  173.     refreshButtons()
  174. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement