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
- local irisState = true
- mon.setBackgroundColor(colors.black)
- mon.clear()
- term.clear()
- term.setCursorPos(1,1)
- w,h = mon.getSize()
- print("W: "..w , "H: "..h)
- function createButton(btnName, PosX, PosY, SizeX, SizeY, Name, Address, bkCol)
- buttonTable[btnName] = {}
- buttonTable[btnName]["rectangle"] = {}
- buttonTable[btnName]["PosX"] = PosX
- buttonTable[btnName]["PosY"] = PosY
- buttonTable[btnName]["SizeX"] = SizeX
- buttonTable[btnName]["SizeY"] = SizeY
- buttonTable[btnName]["Name"] = Name
- buttonTable[btnName]["Address"] = Address
- buttonTable[btnName]["bkCol"] = bkCol
- buttonTable[btnName]["state"] = {}
- end
- local function drawButton(btnName)
- i = 1
- str = string.len(buttonTable[btnName]["Name"])
- for y = 1,buttonTable[btnName]["SizeY"] do
- for x = 1, buttonTable[btnName]["SizeX"] do
- if btnName == "local_stargate" then
- mon.setTextColor(colors.lightGray)
- elseif btnName ~= nil and btnName ~= "local_stargate" then
- mon.setTextColor(colors.white)
- end
- 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(buttonTable[btnName]["Name"])
- end
- i = i+1
- end
- end
- sleep(0.2)
- end
- local function drawButtonPress(btnName)
- if btnName ~= nil then
- str = string.len(buttonTable[btnName]["Name"])
- 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(buttonTable[btnName]["Name"])
- end
- i = i+1
- end
- end
- else
- print("Looks like the button you requested is not available")
- end
- sleep(0.5)
- 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
- --createButton(registryName, Xmin, Ymin, Xmax, Ymax (ideally odd), displayName, stargate, color)
- --Dimensions
- createButton("Nether", 0,0,string.len("Nether")+2,3, "Nether", "PFER-7QN-9R", colors.orange)
- createButton("End", string.len("Nether")+2,0,string.len("End")+2,3,"End", "I454-OTE-QX", colors.purple)
- --Planets
- createButton("Moon", 0,9,string.len("Moon")+2,3,"Moon", "1FYB-81J-KE", colors.lightGray)
- createButton("Mars", 0,12,string.len("Mars")+2,3, "Mars", "PFS5-21P-6H", colors.orange)
- --POIs
- createButton("Mesa", 0,3,string.len("Mesa")+2,3,"Mesa", "TAGJ-YB8-GC", colors.yellow)
- --No touchs
- createButton("local_stargate", 39, 18, string.len(tostring(sg.localAddress()))+2, 1, sg.localAddress(), "", colors.gray)
- createButton("disconnect", 19, 16, string.len("disconnect")+4, 3, "Disconnect", "", colors.gray)
- createButton("iris", w-w,18,6,1, "Iris", "", colors.lime)--"RDJT-5IA-MU", colors.lime)
- createButton("modem", w-string.len("wifi")-string.len(tostring(sg.localAddress()))-4,18,string.len("WiFi")+2,1, "WiFi","",colors.lime)
- --spacer
- 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 == "disconnect" then
- print("Disconnecting")
- drawButtonPress(buttonName)
- drawButton(buttonName)
- drawButtonPress(buttonName)
- drawButton(buttonName)
- drawButtonPress(buttonName)
- sg.disconnect()
- elseif buttonTable[buttonName]["Address"] == "" then
- elseif buttonName ~= nil then
- drawButtonPress(buttonName)
- sg.dial(buttonTable[buttonName]["Address"])
- end
- end
- drawButton(buttonName)
- end
- autoDrawBtn()
- while true do
- mon.setTextColor(colors.white)
- monitor_touch_event()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement