SHOW:
|
|
- or go back to the newest paste.
1 | - | local mon = peripheral.wrap("top") |
1 | + | local mon = peripheral.wrap("right") |
2 | local button={} | |
3 | ||
4 | mon.setTextScale(1) | |
5 | mon.setTextColor(colors.white) | |
6 | mon.setBackgroundColor(colors.black) | |
7 | - | function setTable(name, func, xmin, xmax, ymin, ymax) |
7 | + | |
8 | function setTable(name, func, xmin, xmax, ymin, ymax, switch) | |
9 | button[name] = {} | |
10 | button[name]["func"] = func | |
11 | button[name]["active"] = false | |
12 | button[name]["xmin"] = xmin | |
13 | button[name]["ymin"] = ymin | |
14 | button[name]["xmax"] = xmax | |
15 | button[name]["ymax"] = ymax | |
16 | button[name]["switch"] = switch | |
17 | end | |
18 | ||
19 | function funcName() | |
20 | print("You clicked buttonText") | |
21 | end | |
22 | ||
23 | function fillTable() | |
24 | setTable("ButtonText", funcName, 5, 25, 4, 8) | |
25 | end | |
26 | ||
27 | function fill(text, color, bData) | |
28 | local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2) | |
29 | - | for j = bData["ymin"], bData["ymax"] do |
29 | + | |
30 | ||
31 | - | if j == yspot then |
31 | + | |
32 | - | for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do |
32 | + | |
33 | - | if k == xspot then |
33 | + | for j = bData["ymin"], bData["ymax"] |
34 | do | |
35 | mon.setCursorPos(bData["xmin"], j) | |
36 | ||
37 | if (j == yspot) | |
38 | then | |
39 | for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 | |
40 | - | for i = bData["xmin"], bData["xmax"] do |
40 | + | do |
41 | if k == xspot | |
42 | then | |
43 | mon.write(text) | |
44 | else | |
45 | mon.write(" ") | |
46 | end | |
47 | end | |
48 | else | |
49 | for i = bData["xmin"], bData["xmax"] | |
50 | - | for name,data in pairs(button) do |
50 | + | do |
51 | mon.write(" ") | |
52 | - | if on == true then currColor = colors.lime else currColor = colors.red end |
52 | + | |
53 | end | |
54 | end | |
55 | mon.setBackgroundColor(colors.black) | |
56 | end | |
57 | ||
58 | function screen() | |
59 | local currColor | |
60 | ||
61 | for name,data in pairs(button) | |
62 | do | |
63 | local on = data["active"] | |
64 | ||
65 | if (on == true) | |
66 | then | |
67 | currColor = colors.lime | |
68 | else | |
69 | currColor = colors.red | |
70 | end | |
71 | - | for name, data in pairs(button) do |
71 | + | |
72 | - | if y>=data["ymin"] and y <= data["ymax"] then |
72 | + | |
73 | - | if x>=data["xmin"] and x<= data["xmax"] then |
73 | + | |
74 | end | |
75 | - | return true |
75 | + | |
76 | - | --data["active"] = not data["active"] |
76 | + | |
77 | button[name]["active"] = not button[name]["active"] | |
78 | screen() | |
79 | end | |
80 | ||
81 | function flash(name) | |
82 | toggleButton(name) | |
83 | screen() | |
84 | sleep(0.15) | |
85 | toggleButton(name) | |
86 | screen() | |
87 | end | |
88 | ||
89 | function checkxy(x, y) | |
90 | for name, data in pairs(button) | |
91 | do | |
92 | if (y>=data["ymin"] and y <= data["ymax"]) | |
93 | - | end |
93 | + | then |
94 | if (x>=data["xmin"] and x<= data["xmax"]) | |
95 | then | |
96 | data["func"]() | |
97 | ||
98 | if (data["switch"]) | |
99 | then | |
100 | toggleButton(name) | |
101 | else | |
102 | flash(name) | |
103 | end | |
104 | --print(name) | |
105 | return true | |
106 | end | |
107 | end | |
108 | end | |
109 | return false | |
110 | end | |
111 | ||
112 | function heading(text) | |
113 | w, h = mon.getSize() | |
114 | mon.setCursorPos((w-string.len(text))/2+1, 1) | |
115 | mon.write(text) | |
116 | end | |
117 | ||
118 | function label(w, h, text) | |
119 | mon.setCursorPos(w, h) | |
120 | mon.write(text) | |
121 | end | |
122 | ||
123 | function stop() | |
124 | mon.clear() | |
125 | end | |
126 | ||
127 | --original script by Direwolf20 | |
128 | --modified by SolidSnake96AS |