SHOW:
|
|
- or go back to the newest paste.
1 | local chat = peripheral.wrap("top") | |
2 | local mon = peripheral.wrap("monitor_0") | |
3 | local sg = peripheral.wrap("stargate_0") | |
4 | local buttonTable = {} | |
5 | local buttonName | |
6 | ||
7 | mon.setBackgroundColor(colors.black) | |
8 | mon.clear() | |
9 | chat.capture("^SG") | |
10 | ||
11 | function catchEntry() | |
12 | local _, message, pattern, player, uuid = os.pullEvent("chat_capture") | |
13 | if pattern == "^SG" then | |
14 | cutSG = string.gsub(message, "SG", "") | |
15 | chat.tell("[Stargate] Starting 'Stargate Protocol'!") | |
16 | end | |
17 | end | |
18 | ||
19 | ||
20 | ||
21 | function createButton(btnName, PosX, PosY, SizeX, SizeY, Name, Address, bkCol) | |
22 | buttonTable[btnName] = {} | |
23 | buttonTable[btnName]["rectangle"] = {} | |
24 | buttonTable[btnName]["PosX"] = PosX | |
25 | buttonTable[btnName]["PosY"] = PosY | |
26 | buttonTable[btnName]["SizeX"] = SizeX | |
27 | buttonTable[btnName]["SizeY"] = SizeY | |
28 | buttonTable[btnName]["Name"] = Name | |
29 | buttonTable[btnName]["Address"] = Address | |
30 | buttonTable[btnName]["bkCol"] = bkCol | |
31 | ||
32 | end | |
33 | ||
34 | local function drawButton(btnName) | |
35 | i = 1 | |
36 | str = string.len(buttonTable[btnName]["Name"]) | |
37 | for y = 1,buttonTable[btnName]["SizeY"] do | |
38 | for x = 1, buttonTable[btnName]["SizeX"] do | |
39 | --print(x..","..y.." : "..buttonTable[btnName]["PosX"]+x-1) | |
40 | --print(x..","..y.." : "..buttonTable[btnName]["PosY"]+y-1) | |
41 | mon.setBackgroundColor(buttonTable[btnName]["bkCol"]) | |
42 | mon.setCursorPos(buttonTable[btnName]["PosX"]+x-1, buttonTable[btnName]["PosY"]+y-1) | |
43 | mon.write(" ") | |
44 | ||
45 | --mon.setBackgroundColor(colors.gray) | |
46 | buttonTable[btnName]["rectangle"][x..":"..y] = {} | |
47 | buttonTable[btnName]["rectangle"][x..":"..y] = buttonTable[btnName]["PosX"]+x-1 ..":"..buttonTable[btnName]["PosY"]+y-1 | |
48 | if y == buttonTable[btnName]["SizeY"] then | |
49 | textPosiX = buttonTable[btnName]["SizeX"]-str | |
50 | textPosX = textPosiX/2 | |
51 | mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, math.floor(buttonTable[btnName]["PosY"]+y/buttonTable[btnName]["SizeY"])) | |
52 | mon.write(buttonTable[btnName]["Name"]) | |
53 | end | |
54 | i = i+1 | |
55 | end | |
56 | end | |
57 | --print(str) | |
58 | end | |
59 | ||
60 | local function drawButtonPress(btnName) | |
61 | if btnName ~= nil then | |
62 | str = string.len(buttonTable[btnName]["Name"]) | |
63 | for y = 1,buttonTable[btnName]["SizeY"] do | |
64 | for x = 1, buttonTable[btnName]["SizeX"] do | |
65 | --print(x..","..y.." : "..buttonTable[btnName]["PosX"]+x-1) | |
66 | --print(x..","..y.." : "..buttonTable[btnName]["PosY"]+y-1) | |
67 | mon.setBackgroundColor(colors.red) | |
68 | mon.setCursorPos(buttonTable[btnName]["PosX"]+x-1, buttonTable[btnName]["PosY"]+y-1) | |
69 | mon.write(" ") | |
70 | ||
71 | --mon.setBackgroundColor(colors.gray) | |
72 | if y == buttonTable[btnName]["SizeY"] then | |
73 | textPosiX = buttonTable[btnName]["SizeX"]-str | |
74 | textPosX = textPosiX/2 | |
75 | mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, math.floor(buttonTable[btnName]["PosY"]+y/buttonTable[btnName]["SizeY"])) | |
76 | mon.write(buttonTable[btnName]["Name"]) | |
77 | end | |
78 | i = i+1 | |
79 | end | |
80 | end | |
81 | else | |
82 | print("Looks like the button you requested is not available") | |
83 | end | |
84 | end | |
85 | ||
86 | local function testButtonPress(tPosX, tPosY) | |
87 | for k,v in pairs(buttonTable) do | |
88 | for a,b in pairs(buttonTable[k]["rectangle"]) do | |
89 | if b == tPosX..":"..tPosY then | |
90 | return k | |
91 | end | |
92 | end | |
93 | end | |
94 | end | |
95 | ||
96 | createButton("Nether", 1,1,10,3, "Nether", "RDJT-5IA-MU", colors.orange) | |
97 | createButton("Moon", 11,1,10,3,"Moon", "1FYB-81J-KE", colors.lightGray) | |
98 | --createButton("Asus", 17,1,8,3,"Asus", "123", colors.green) | |
99 | --createButton("test3", 9,4,8,3,"TestoX", "123", colors.blue) | |
100 | ||
101 | createButton("disconnect", 1, 17, 39,3, "Disconnect", "", colors.gray) | |
102 | ||
103 | ||
104 | local function autoDrawBtn() | |
105 | for k,v in pairs(buttonTable) do | |
106 | drawButton(k) | |
107 | end | |
108 | end | |
109 | ||
110 | local function monitor_touch_event() | |
111 | event, side, xPos, yPos = os.pullEvent("monitor_touch") | |
112 | if event == "monitor_touch" then | |
113 | buttonName = testButtonPress(xPos, yPos) | |
114 | drawButtonPress(buttonName) | |
115 | print(xPos, yPos) | |
116 | if buttonName == "disconnect" then | |
117 | print("Disconnecting") | |
118 | sg.disconnect() | |
119 | sleep(5) | |
120 | autoDrawBtn() | |
121 | elseif buttonName ~= nil then | |
122 | sg.dial(buttonTable[buttonName]["Address"]) | |
123 | sleep(5) | |
124 | autoDrawBtn() | |
125 | end | |
126 | end | |
127 | end | |
128 | ||
129 | autoDrawBtn() | |
130 | ||
131 | while true do | |
132 | monitor_touch_event() | |
133 | end |