Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("monitor_1")
- local sg = peripheral.wrap("stargate_1")
- local buttonTable = {}
- local buttonName
- mon.setBackgroundColor(colors.black)
- mon.clear()
- term.clear()
- term.setCursorPos(1,1)
- w,h = mon.getSize()
- print("W: "..w , "H: "..h)
- local function createButton(btnName, PosX, PosY, SizeXadd, SizeY, Address, bkCol)
- buttonTable[btnName] = {}
- buttonTable[btnName]["rectangle"] = {}
- buttonTable[btnName]["PosX"] = PosX
- buttonTable[btnName]["PosY"] = PosY
- buttonTable[btnName]["SizeX"] = string.len(btnName)+SizeXadd
- buttonTable[btnName]["SizeY"] = SizeY
- --buttonTable[btnName]["Name"] = btnName
- buttonTable[btnName]["Address"] = Address
- buttonTable[btnName]["bkCol"] = bkCol
- buttonTable[btnName]["state"] = {}
- end
- --createButton(registryName, Xmin, Ymin, 2, Ymax (ideally odd), displayName, stargate, color)
- --Dimensions
- createButton("Nether", 0,0, 2,3, "PFER-7QN-9R", colors.orange)
- createButton("End", 8, 0, 2, 3, "I454-OTE-QX", colors.purple)
- --Planets
- createButton("Moon", 0, 9, 2, 3,"1FYB-81J-KE", colors.lightGray)
- createButton("Mars", 6, 9, 2, 3, "PFS5-21P-6H", colors.orange)
- --POIs
- createButton("Mesa", 0, 3, 2, 3, "TAGJ-YB8-GC", colors.yellow)
- --No touchs
- createButton(tostring(sg.localAddress()), 39, 18, 2, 1, "", colors.gray)
- createButton("Disconnect", 18, 16, 4, 3, "", colors.gray)
- createButton("EARTH", 0,16,2,3, "FFYO-FV6-0R", colors.lime)
- --tbd createButton("Iris", 0,18,6,1, "RDJT-5IA-MU", colors.lime)--"RDJT-5IA-MU", colors.lime)
- --tbd createButton("WiFi",39, 17, 7,1,"",colors.lime)
- local function drawButton(btnName)
- str = string.len(btnName)
- for y = 1,buttonTable[btnName]["SizeY"] do
- for x = 1, buttonTable[btnName]["SizeX"] do
- mon.setBackgroundColor(buttonTable[btnName]["bkCol"])
- mon.setCursorPos(buttonTable[btnName]["PosX"]+x, buttonTable[btnName]["PosY"]+y)
- mon.write(" ")
- buttonTable[btnName]["rectangle"][x..":"..y] = {}
- buttonTable[btnName]["rectangle"][x..":"..y] = buttonTable[btnName]["PosX"]+x ..":"..buttonTable[btnName]["PosY"]+y
- if y == (buttonTable[btnName]["SizeY"]) then
- textPosiX = buttonTable[btnName]["SizeX"]-str+2
- textPosX = textPosiX/2
- if y ~= 1 and y ~= 2 then
- mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"] + buttonTable[btnName]["SizeY"]-1)--(buttonTable[btnName]["SizeY"]))
- elseif y == 1 or y == 2 then
- mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"]+y)
- end
- mon.write(btnName)
- end
- end
- end
- sleep(0.1)
- end
- local function drawButtonPress(btnName)
- str = string.len(btnName)
- for y = 1,buttonTable[btnName]["SizeY"] do
- for x = 1, buttonTable[btnName]["SizeX"] do
- --print(x..","..y.." : "..buttonTable[btnName]["PosX"]+x-1)
- --print(x..","..y.." : "..buttonTable[btnName]["PosY"]+y-1)
- mon.setBackgroundColor(colors.red)
- mon.setCursorPos(buttonTable[btnName]["PosX"]+x, buttonTable[btnName]["PosY"]+y)
- mon.write(" ")
- --mon.setBackgroundColor(colors.gray)
- if y == buttonTable[btnName]["SizeY"] then
- textPosiX = buttonTable[btnName]["SizeX"]-str+2
- textPosX = textPosiX/2
- if y ~= 1 and y ~= 2 then
- mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"] + buttonTable[btnName]["SizeY"]-1)--(buttonTable[btnName]["SizeY"]))
- elseif y == 1 or y == 2 then
- mon.setCursorPos(buttonTable[btnName]["PosX"]+textPosX, buttonTable[btnName]["PosY"]+y)
- end
- mon.write(btnName)
- end
- end
- end
- sleep(0.2)
- end
- local function testButtonPress(tPosX, tPosY)
- for k,v in pairs(buttonTable) do
- for a,b in pairs(buttonTable[k]["rectangle"]) do
- if b == tPosX..":"..tPosY then
- return k
- end
- end
- end
- end
- local function autoDrawBtn()
- for k,v in pairs(buttonTable) do
- drawButton(k)
- end
- end
- local function monitor_touch_event()
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if event == "monitor_touch" then
- buttonName = testButtonPress(xPos, yPos)
- print(xPos, yPos)
- if buttonName ~= nil then
- if buttonName == "Disconnect" and buttonTable[buttonName]["Address"] == "" then
- print("Disconnecting")
- drawButtonPress(buttonName)
- drawButton(buttonName)
- drawButtonPress(buttonName)
- drawButton(buttonName)
- drawButtonPress(buttonName)
- sg.disconnect()
- elseif buttonTable[buttonName]["Address"] ~= "" then
- drawButtonPress(buttonName)
- sg.dial(buttonTable[buttonName]["Address"])
- print(os.time().." | Connecting to: "..buttonName.." @ "..buttonTable[buttonName]["Address"])
- else
- --drawButton(buttonName)
- end
- drawButton(buttonName)
- end
- end
- end
- --called once to set up all buttons
- autoDrawBtn()
- while true do
- mon.setTextColor(colors.white)
- monitor_touch_event()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement