SHOW:
|
|
- or go back to the newest paste.
1 | local mon = peripheral.wrap("monitor_1") | |
2 | local sg = peripheral.wrap("stargate_1") | |
3 | local buttonTable = {} | |
4 | local buttonName | |
5 | local irisState = true | |
6 | ||
7 | mon.setBackgroundColor(colors.black) | |
8 | mon.clear() | |
9 | term.clear() | |
10 | term.setCursorPos(1,1) | |
11 | w,h = mon.getSize() | |
12 | print("W: "..w , "H: "..h) | |
13 | ||
14 | function createButton(btnName, PosX, PosY, SizeX, SizeY, Name, Address, bkCol) | |
15 | buttonTable[btnName] = {} | |
16 | buttonTable[btnName]["rectangle"] = {} | |
17 | buttonTable[btnName]["PosX"] = PosX | |
18 | buttonTable[btnName]["PosY"] = PosY | |
19 | buttonTable[btnName]["SizeX"] = SizeX | |
20 | buttonTable[btnName]["SizeY"] = SizeY | |
21 | buttonTable[btnName]["Name"] = Name | |
22 | buttonTable[btnName]["Address"] = Address | |
23 | buttonTable[btnName]["bkCol"] = bkCol | |
24 | buttonTable[btnName]["state"] = {} | |
25 | ||
26 | end | |
27 | ||
28 | local function drawButton(btnName) | |
29 | i = 1 | |
30 | str = string.len(buttonTable[btnName]["Name"]) | |
31 | for y = 1,buttonTable[btnName]["SizeY"] do | |
32 | for x = 1, buttonTable[btnName]["SizeX"] do | |
33 | if btnName == "local_stargate" then | |
34 | mon.setTextColor(colors.lightGray) | |
35 | elseif btnName ~= nil and btnName ~= "local_stargate" then | |
36 | mon.setTextColor(colors.white) | |
37 | end | |
38 | mon.setBackgroundColor(buttonTable[btnName]["bkCol"]) | |
39 | mon.setCursorPos(buttonTable[btnName]["PosX"]+x, buttonTable[btnName]["PosY"]+y) | |
40 | mon.write(" ") | |
41 | buttonTable[btnName]["rectangle"][x..":"..y] = {} | |
42 | buttonTable[btnName]["rectangle"][x..":"..y] = buttonTable[btnName]["PosX"]+x ..":"..buttonTable[btnName]["PosY"]+y | |
43 | if y == (buttonTable[btnName]["SizeY"]) then | |
44 | textPosiX = buttonTable[btnName]["SizeX"]-str+2 | |
45 | textPosX = textPosiX/2 | |
46 | if y ~= 1 and y ~= 2 then | |
47 | mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"] + buttonTable[btnName]["SizeY"]-1)--(buttonTable[btnName]["SizeY"])) | |
48 | elseif y == 1 or y == 2 then | |
49 | mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"]+y) | |
50 | end | |
51 | mon.write(buttonTable[btnName]["Name"]) | |
52 | end | |
53 | i = i+1 | |
54 | end | |
55 | end | |
56 | sleep(0.2) | |
57 | end | |
58 | ||
59 | local function drawButtonPress(btnName) | |
60 | if btnName ~= nil then | |
61 | str = string.len(buttonTable[btnName]["Name"]) | |
62 | for y = 1,buttonTable[btnName]["SizeY"] do | |
63 | for x = 1, buttonTable[btnName]["SizeX"] do | |
64 | --print(x..","..y.." : "..buttonTable[btnName]["PosX"]+x-1) | |
65 | --print(x..","..y.." : "..buttonTable[btnName]["PosY"]+y-1) | |
66 | mon.setBackgroundColor(colors.red) | |
67 | mon.setCursorPos(buttonTable[btnName]["PosX"]+x, buttonTable[btnName]["PosY"]+y) | |
68 | mon.write(" ") | |
69 | ||
70 | --mon.setBackgroundColor(colors.gray) | |
71 | if y == buttonTable[btnName]["SizeY"] then | |
72 | textPosiX = buttonTable[btnName]["SizeX"]-str+2 | |
73 | textPosX = textPosiX/2 | |
74 | if y ~= 1 and y ~= 2 then | |
75 | mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"] + buttonTable[btnName]["SizeY"]-1)--(buttonTable[btnName]["SizeY"])) | |
76 | elseif y == 1 or y == 2 then | |
77 | mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"]+y) | |
78 | end | |
79 | mon.write(buttonTable[btnName]["Name"]) | |
80 | end | |
81 | i = i+1 | |
82 | end | |
83 | end | |
84 | else | |
85 | print("Looks like the button you requested is not available") | |
86 | end | |
87 | sleep(0.5) | |
88 | end | |
89 | ||
90 | local function testButtonPress(tPosX, tPosY) | |
91 | for k,v in pairs(buttonTable) do | |
92 | for a,b in pairs(buttonTable[k]["rectangle"]) do | |
93 | if b == tPosX..":"..tPosY then | |
94 | return k | |
95 | end | |
96 | end | |
97 | end | |
98 | end | |
99 | ||
100 | --createButton(registryName, Xmin, Ymin, Xmax, Ymax (ideally odd), displayName, stargate, color) | |
101 | --Dimensions | |
102 | createButton("Nether", 0,0,string.len("Nether")+2,3, "Nether", "PFER-7QN-9R", colors.orange) | |
103 | createButton("End", string.len("Nether")+2,0,string.len("End")+2,3,"End", "I454-OTE-QX", colors.purple) | |
104 | --Planets | |
105 | createButton("Moon", 0,9,string.len("Moon")+2,3,"Moon", "1FYB-81J-KE", colors.lightGray) | |
106 | createButton("Mars", 0,12,string.len("Mars")+2,3, "Mars", "PFS5-21P-6H", colors.orange) | |
107 | --POIs | |
108 | createButton("Mesa", 0,3,string.len("Mesa")+2,3,"Mesa", "TAGJ-YB8-GC", colors.yellow) | |
109 | --No touchs | |
110 | createButton("local_stargate", 39, 18, string.len(tostring(sg.localAddress()))+2, 1, sg.localAddress(), "", colors.gray) | |
111 | createButton("disconnect", 19, 16, string.len("disconnect")+4, 3, "Disconnect", "", colors.gray) | |
112 | createButton("iris", w-w,18,6,1, "Iris", "", colors.lime)--"RDJT-5IA-MU", colors.lime) | |
113 | createButton("modem", w-string.len("wifi")-string.len(tostring(sg.localAddress()))-4,18,string.len("WiFi")+2,1, "WiFi","",colors.lime) | |
114 | ||
115 | --spacer | |
116 | ||
117 | ||
118 | local function autoDrawBtn() | |
119 | for k,v in pairs(buttonTable) do | |
120 | drawButton(k) | |
121 | end | |
122 | end | |
123 | ||
124 | local function monitor_touch_event() | |
125 | event, side, xPos, yPos = os.pullEvent("monitor_touch") | |
126 | if event == "monitor_touch" then | |
127 | buttonName = testButtonPress(xPos, yPos) | |
128 | print(xPos, yPos) | |
129 | if buttonName == "disconnect" then | |
130 | print("Disconnecting") | |
131 | drawButtonPress(buttonName) | |
132 | drawButton(buttonName) | |
133 | drawButtonPress(buttonName) | |
134 | drawButton(buttonName) | |
135 | drawButtonPress(buttonName) | |
136 | sg.disconnect() | |
137 | elseif buttonTable[buttonName]["Address"] == "" then | |
138 | ||
139 | elseif buttonName ~= nil then | |
140 | drawButtonPress(buttonName) | |
141 | sg.dial(buttonTable[buttonName]["Address"]) | |
142 | end | |
143 | end | |
144 | drawButton(buttonName) | |
145 | end | |
146 | ||
147 | autoDrawBtn() | |
148 | ||
149 | while true do | |
150 | mon.setTextColor(colors.white) | |
151 | monitor_touch_event() | |
152 | ||
153 | end |