SHOW:
|
|
- or go back to the newest paste.
1 | mon = peripheral.wrap("back") | |
2 | lx,ly = mon.getSize() | |
3 | mon.setBackgroundColor(colors.blue) | |
4 | mon.clear() | |
5 | mon.setTextScale(2) | |
6 | mon.setCursorPos(lx/2-3,1) | |
7 | mon.setTextColor(colors.yellow) | |
8 | mon.write("SPAWNERS") | |
9 | ||
10 | sp1_side = "right" -- Cursed Earth | |
11 | sp2_side = "front" | |
12 | sp3_side = "left" | |
13 | ||
14 | rs.setOutput(sp1_side, true) | |
15 | rs.setOutput(sp2_side, true) | |
16 | rs.setOutput(sp3_side, true) | |
17 | ||
18 | --fonctions | |
19 | ||
20 | function switch_signal(side) | |
21 | ||
22 | if rs.getInput(side) == true then | |
23 | rs.setOutput(side, false) | |
24 | else | |
25 | rs.setOutput(side, true) | |
26 | end | |
27 | ||
28 | end | |
29 | ||
30 | function boutons() | |
31 | - | create_button(math.floor(0.05*lx)+1,math.floor(0.3*lx)+1,(ly/3),(ly/3)+2,colors.red,"SPA1 OFF",colors.orange) |
31 | + | create_button(math.floor(0.05*lx)+1,math.floor(0.3*lx)+1,(ly/3),(ly/3)+2,colors.red,"SQUE OFF",colors.orange) |
32 | - | create_button(math.floor(0.35*lx)+1,math.floor(0.65*lx)+1,(ly/3),(ly/3)+2,colors.red,"SPA2 OFF",colors.orange) |
32 | + | create_button(math.floor(0.35*lx)+1,math.floor(0.65*lx)+1,(ly/3),(ly/3)+2,colors.red,"SORC OFF",colors.orange) |
33 | - | create_button(math.floor(0.7*lx)+1,math.floor(0.95*lx)+1,(ly/3),(ly/3)+2,colors.red,"SPA3 OFF",colors.orange) |
33 | + | create_button(math.floor(0.7*lx)+1,math.floor(0.95*lx)+1,(ly/3),(ly/3)+2,colors.red,"ENDER OFF",colors.orange) |
34 | ||
35 | - | create_button(math.floor(0.05*lx)+1,math.floor(0.3*lx)+1,((ly/3)*2),((ly/3)*2)+2,colors.green,"SPA1 ON",colors.black) |
35 | + | create_button(math.floor(0.05*lx)+1,math.floor(0.3*lx)+1,((ly/3)*2),((ly/3)*2)+2,colors.green,"SQUE ON",colors.black) |
36 | - | create_button(math.floor(0.35*lx)+1,math.floor(0.65*lx)+1,((ly/3)*2),((ly/3)*2)+2,colors.green,"SPA2 ON",colors.black) |
36 | + | create_button(math.floor(0.35*lx)+1,math.floor(0.65*lx)+1,((ly/3)*2),((ly/3)*2)+2,colors.green,"SORC ON",colors.black) |
37 | - | create_button(math.floor(0.7*lx)+1,math.floor(0.95*lx)+1,((ly/3)*2),((ly/3)*2)+2,colors.green,"SPA3 ON",colors.black) |
37 | + | create_button(math.floor(0.7*lx)+1,math.floor(0.95*lx)+1,((ly/3)*2),((ly/3)*2)+2,colors.green,"ENDER ON",colors.black) |
38 | end | |
39 | ||
40 | function create_button(xmin, xmax, ymin, ymax, color, text, tcolor) | |
41 | ||
42 | local aire = 0 | |
43 | local xtemp, ytemp = xmin, ymin | |
44 | ||
45 | while aire < (((xmax-xmin)+1)*((ymax-ymin)+1)) do | |
46 | mon.setBackgroundColor(color) | |
47 | mon.setCursorPos(xtemp,ytemp) | |
48 | mon.write(" ") | |
49 | ||
50 | if xtemp == xmax then | |
51 | xtemp = xmin | |
52 | ytemp = ytemp + 1 | |
53 | else | |
54 | xtemp = xtemp + 1 | |
55 | end | |
56 | aire = aire + 1 | |
57 | end | |
58 | ||
59 | mon.setTextColor(tcolor) | |
60 | mon.setCursorPos((xmin+xmax)/2 - (string.len(text)/2) + 1, (ymax+ymin)/2) | |
61 | mon.write(text) | |
62 | mon.setBackgroundColor(colors.blue) | |
63 | end | |
64 | ||
65 | function touch_detect(lx, ly) | |
66 | local tevent, cote, x, y = os.pullEvent("monitor_touch") | |
67 | mon.setTextColor(colors.yellow) | |
68 | if y <=ly/2 then | |
69 | if x < lx/3 then | |
70 | rs.setOutput(sp1_side, true) | |
71 | elseif x>lx/3 and x<(lx/3)*2 then | |
72 | rs.setOutput(sp2_side, true) | |
73 | else | |
74 | rs.setOutput(sp3_side, true) | |
75 | end | |
76 | else | |
77 | if x < lx/3 then | |
78 | rs.setOutput(sp1_side, false) | |
79 | elseif x>lx/3 and x<(lx/3)*2 then | |
80 | rs.setOutput(sp2_side, false) | |
81 | else | |
82 | rs.setOutput(sp3_side, false) | |
83 | end | |
84 | end | |
85 | end | |
86 | ||
87 | function status_set(side) | |
88 | mon.setCursorPos(0.25*lx,0.9*ly) | |
89 | if rs.getInput(sp1_side) == false then | |
90 | mon.write("ON ")else mon.write("OFF") | |
91 | end | |
92 | mon.setCursorPos(0.6*lx,0.9*ly) | |
93 | if rs.getInput(sp2_side) == false then | |
94 | mon.write("ON ")else mon.write("OFF") | |
95 | end | |
96 | mon.setCursorPos(0.92*lx,0.9*ly) | |
97 | if rs.getInput(sp3_side) == false then | |
98 | mon.write("ON ")else mon.write("OFF") | |
99 | end | |
100 | end | |
101 | ||
102 | function set_status() | |
103 | mon.setTextColor(colors.yellow) | |
104 | mon.setCursorPos((lx/20)*1.5,0.9*ly) | |
105 | mon.write("Status:") | |
106 | mon.setCursorPos((lx/20)*8,0.9*ly) | |
107 | mon.write("Status:") | |
108 | mon.setCursorPos((lx/20)*14.5,0.9*ly) | |
109 | mon.write("Status:") | |
110 | end | |
111 | ||
112 | function stat_off()--mep | |
113 | mon.setCursorPos(0.25*lx,0.9*ly) | |
114 | mon.write("OFF") | |
115 | mon.setCursorPos(0.6*lx,0.9*ly) | |
116 | mon.write("OFF") | |
117 | mon.setCursorPos(0.92*lx,0.9*ly) | |
118 | mon.write("OFF") | |
119 | end | |
120 | ||
121 | function spawn() | |
122 | mon.setCursorPos(lx/2-3,1) | |
123 | mon.setTextColor(colors.yellow) | |
124 | mon.write("SPAWNERS") | |
125 | end | |
126 | ||
127 | --main | |
128 | stat_off() | |
129 | while true do | |
130 | mon.clear() | |
131 | set_status() | |
132 | spawn() | |
133 | boutons() | |
134 | status_set() | |
135 | touch_detect(lx,ly) | |
136 | end | |
137 | ||
138 | --code par appollon41, version OpenSource |