View difference between Paste ID: qc4QeDgu and 3Fp9pfQy
SHOW: | | - or go back to the newest paste.
1-
monitors = {peripheral.find("monitor")}
1+
os.loadAPI("config")
2-
local mon = {}
2+
local mon = peripheral.wrap(config.monitorId)
3-
for funcName,_ in pairs(monitors[1]) do
3+
4-
	mon[funcName] = function(...)
4+
5-
		for i=1,#monitors-1 do monitors[i][funcName](unpack(arg)) end
5+
6-
		return monitors[#monitors][funcName](unpack(arg))
6+
7-
	end
7+
8
function clearTable()
9
   button = {}
10
   mon.clear()
11
end
12
               
13
function setTable(name, func, xmin, xmax, ymin, ymax)
14
   button[name] = {}
15
   button[name]["func"] = func
16
   button[name]["active"] = false
17
   button[name]["xmin"] = xmin
18
   button[name]["ymin"] = ymin
19-
function setButton(name, buttonOn)
19+
20-
   print(name)
20+
21-
   print(button[name]["active"])
21+
22-
   button[name]["active"] = buttonOn
22+
23
function funcName()
24
   print("You clicked buttonText")
25
end
26-
function setTable(name, func, param, xmin, xmax, ymin, ymax)
26+
27
function fillTable()
28
   setTable("ButtonText", funcName, 5, 25, 4, 8)
29
end     
30-
   button[name]["param"] = param
30+
31
function fill(text, color, bData)
32
   mon.setBackgroundColor(color)
33
   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
34
   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
35
   for j = bData["ymin"], bData["ymax"] do
36
      mon.setCursorPos(bData["xmin"], j)
37
      if j == yspot then
38
         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
39
            if k == xspot then
40
               mon.write(text)
41
            else
42
               mon.write(" ")
43
            end
44
         end
45
      else
46
         for i = bData["xmin"], bData["xmax"] do
47
            mon.write(" ")
48
         end
49
      end
50
   end
51
   mon.setBackgroundColor(colors.black)
52
end
53
     
54
function screen()
55
   local currColor
56
   for name,data in pairs(button) do
57
      local on = data["active"]
58
      if on == true then currColor = colors.lime else currColor = colors.red end
59
      fill(name, currColor, data)
60
   end
61
end
62
63
function toggleButton(name)
64
   button[name]["active"] = not button[name]["active"]
65
   screen()
66
end     
67
68
function flash(name)
69
   toggleButton(name)
70
   screen()
71
   sleep(0.15)
72
   toggleButton(name)
73
   screen()
74
end
75
                                             
76
function checkxy(x, y)
77
   for name, data in pairs(button) do
78
      if y>=data["ymin"] and  y <= data["ymax"] then
79
         if x>=data["xmin"] and x<= data["xmax"] then
80
            data["func"]()
81
            return true
82
            --data["active"] = not data["active"]
83
            --print(name)
84
         end
85
      end
86
   end
87
   return false
88
end
89
     
90
function heading(text)
91
   w, h = mon.getSize()
92
   mon.setCursorPos((w-string.len(text))/2+1, 1)
93
   mon.write(text)
94-
            if data["param"] == "" then
94+
95-
              data["func"]()
95+
96
function label(w, h, text)
97-
              data["func"](data["param"])
97+
98
   mon.write(text)
99
end