View difference between Paste ID: 7HWebjuz and 5a5CwKVD
SHOW: | | - or go back to the newest paste.
1-
os.loadAPI("button")
1+
local mon = peripheral.wrap("top")
2-
local m = peripheral.wrap("monitor_0")
2+
mon.setTextScale(1)
3-
 
3+
mon.setTextColor(colors.white)
4
local button={}
5-
Bottom = Grinder
5+
mon.setBackgroundColor(colors.black)
6-
Top = Lights
6+
     
7-
Left = MobSpawner
7+
function clearTable()
8-
 
8+
button={}
9-
 
9+
10-
 
10+
11-
local function default()
11+
12-
rs.setOutput("left", true)
12+
function setTable(name, func, xmin, xmax, ymin, ymax)
13-
 
13+
   button[name] = {}
14-
rs.setOutput("bottom", false)
14+
   button[name]["func"] = func
15-
button.toggleButton("Grinder")
15+
   button[name]["active"] = false
16-
 
16+
   button[name]["xmin"] = xmin
17-
rs.setOutput("top", false)
17+
   button[name]["ymin"] = ymin
18
   button[name]["xmax"] = xmax
19-
 
19+
   button[name]["ymax"] = ymax
20-
 function menu()
20+
21-
m.clear()
21+
22-
 button.setTable("Lights", lights, 4,26 ,2,6)
22+
function funcName()
23-
 button.setTable("Grinder", grinder, 4,26 ,8,12)
23+
   print("You clicked buttonText")
24-
 button.setTable("Spawner", spawner, 4,26 ,14,17)
24+
25-
 button.setTable("Reboot", reboot, 2,28, 19,20)
25+
        
26-
button.screen()
26+
function fillTable()
27-
default()
27+
   setTable("ButtonText", funcName, 5, 25, 4, 8)
28
end     
29-
 
29+
30-
function reboot()
30+
function fill(text, color, bData)
31-
os.reboot()
31+
   mon.setBackgroundColor(color)
32
   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
33-
 
33+
   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
34-
function grinder()
34+
   for j = bData["ymin"], bData["ymax"] do
35-
if  rs.getOutput("bottom")
35+
      mon.setCursorPos(bData["xmin"], j)
36-
 then grinderOn() else grinderOff()
36+
      if j == yspot then
37
         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
38
            if k == xspot then
39-
 
39+
               mon.write(text)
40-
function spawner()
40+
            else
41-
if  rs.getOutput("left")
41+
               mon.write(" ")
42-
 then spawnerOn() else spawnerOff()
42+
            end
43
         end
44
      else
45-
 
45+
         for i = bData["xmin"], bData["xmax"] do
46-
function lights()
46+
            mon.write(" ")
47-
if rs.getOutput("top") then
47+
         end
48-
 lightsOn() else lightsOff()
48+
      end
49
   end
50
   mon.setBackgroundColor(colors.black)
51-
 
51+
52-
 
52+
     
53-
function lightsOn()
53+
function screen()
54-
rs.setOutput("top", false)
54+
   local currColor
55-
button.toggleButton("Lights")
55+
   for name,data in pairs(button) do
56
      local on = data["active"]
57-
 
57+
      if on == true then currColor = colors.lime else currColor = colors.red end
58-
function lightsOff()
58+
      fill(name, currColor, data)
59-
rs.setOutput("top", true)
59+
60-
button.toggleButton("Lights")
60+
61
62-
 
62+
function toggleButton(name)
63-
 
63+
   button[name]["active"] = not button[name]["active"]
64-
function grinderOn()
64+
   screen()
65-
rs.setOutput("bottom", false)
65+
end     
66-
button.toggleButton("Grinder")
66+
67
function flash(name)
68-
 
68+
   toggleButton(name)
69-
function grinderOff()
69+
   screen()
70-
rs.setOutput("bottom", true)
70+
   sleep(0.15)
71-
button.toggleButton("Grinder")
71+
   toggleButton(name)
72
   screen()
73-
 
73+
74-
 
74+
                                             
75-
function spawnerOn()
75+
function checkxy(x, y)
76-
rs.setOutput("left", false)
76+
   for name, data in pairs(button) do
77-
button.toggleButton("Spawner")
77+
      if y>=data["ymin"] and  y <= data["ymax"] then
78-
activatorOn()
78+
         if x>=data["xmin"] and x<= data["xmax"] then
79
            data["func"]()
80-
 
80+
            return true
81-
function spawnerOff()
81+
            --data["active"] = not data["active"]
82-
rs.setOutput("left", true)
82+
            --print(name)
83-
button.toggleButton("Spawner")
83+
         end
84-
activatorOff()
84+
      end
85
   end
86-
 
86+
   return false
87-
 
87+
88-
function getClick()
88+
     
89-
   local event,side,x,y = os.pullEvent()
89+
function heading(text)
90-
   if event=="monitor_touch" then
90+
   w, h = mon.getSize()
91-
     button.checkxy(x,y)
91+
   mon.setCursorPos((w-string.len(text))/2+1, 1)
92
   mon.write(text)
93
end
94-
 
94+
     
95-
 
95+
function label(w, h, text)
96-
menu()
96+
   mon.setCursorPos(w, h)
97-
 
97+
   mon.write(text)
98-
while true do
98+
99-
   getClick()
99+
100
function centerText(text)
101
x, y = mon.getSize()
102
b, m = mon.getCursorPos()
103
mon.setCursorPos((x-string.len(text))/2+b, m)
104
mon.write(text)
105
end