Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- multishell.setTitle(multishell.getCurrent(), "gui")
- local m = peripheral.find("modem")
- local senderID = os.getComputerLabel() == nil and "ID:" .. os.getComputerID() or os.getComputerLabel()
- local channels = {
- ["stdout"] = 1000,
- ["stdin"] = 1001,
- ["witherout"] = 1010,
- ["witherin"] = 1011
- }
- local args = {...}
- local btns = {}
- local labels = {}
- local receiver = "^.*$"
- local function sendCmd(program, cmd, ...)
- m.transmit(channels.stdin, channels.stdout,
- {
- ["program"] = program,
- ["type"] = "cmd",
- ["cmd"] = cmd,
- ["text"] = {...},
- ["sender"] = senderID,
- ["receiver"] = receiver
- })
- end
- local function log(...)
- os.queueEvent("modem_message", "local", 1000, 1001, {
- ["program"] = "control",
- ["type"] = "info",
- ["text"] = {...},
- ["sender"] = senderID
- }, 0)
- end
- local function makeButton(text, x, y, w, h, action)
- local btn = window.create(term.current(), x, y, w, h)
- assert(type(text) == "string", "text is not a string")
- assert(type(x) == "number", "x is not a number")
- assert(type(y) == "number", "y is not a number")
- assert(type(w) == "number", "w is not a number")
- assert(type(h) == "number", "h is not a number")
- btn.x = x
- btn.y = y
- btn.w = w
- btn.h = h
- btn.text = string.sub(text, 1, w-2)
- if type(action) == "function" then
- btn.action = action
- end
- if h == 1 then
- btn.setCursorPos(1 + math.ceil(w/2-string.len(btn.text)/2), 1)
- btn.write(btn.text)
- btn.setCursorPos(1, 1)
- btn.write("[")
- btn.setCursorPos(w, 1)
- btn.write("]")
- elseif h == 2 then
- btn.setCursorPos(1, 1)
- btn.write("/")
- btn.setCursorPos(2, 1)
- btn.write("\\")
- btn.setCursorPos(1, w)
- btn.write("\\")
- btn.setCursorPos(2, w)
- btn.write("/")
- else
- btn.setCursorPos(1 + math.ceil(w/2-string.len(btn.text)/2), math.ceil(h/2))
- btn.write(btn.text)
- btn.setCursorPos(1, 1)
- btn.write("+")
- btn.setCursorPos(w, 1)
- btn.write("+")
- btn.setCursorPos(1, h)
- btn.write("+")
- btn.setCursorPos(w, h)
- btn.write("+")
- for i = 2, h - 1 do
- btn.setCursorPos(1, i)
- btn.write("|")
- btn.setCursorPos(w, i)
- btn.write("|")
- end
- for i = 2, w - 1 do
- btn.setCursorPos(i, 1)
- btn.write("-")
- btn.setCursorPos(i, h)
- btn.write("-")
- end
- end
- return btn
- end
- local function makeLabel(text, x, y)
- local label = window.create(term.current(), x, y, string.len(text), 1)
- label.text = text
- label.x = x
- label.y = y
- label.write(text)
- return label
- end
- local function handleClick(x, y)
- for name, btn in pairs(btns) do
- if x >= btn.x
- and x <= btn.x + btn.w - 1
- and y >= btn.y
- and y <= btn.y + btn.h - 1
- and type(btn.action) == "function" then
- btn.action()
- end
- end
- end
- local function redraw()
- term.clear()
- for name, btn in pairs(btns) do
- btn.redraw()
- end
- for name, label in pairs(labels) do
- label.redraw()
- end
- end
- btns.infinidig = makeButton("infinidig", 1, 1, 11, 1,
- function()
- log("Sending \"run infinidig\"")
- sendCmd("control", "run", "infinidig")
- end)
- btns.checkfuel = makeButton("checkfuel", 13, 1, 11, 1,
- function()
- log("Sending \"get fuel\"")
- sendCmd("control", "get", "fuel")
- end)
- btns.smine = makeButton("smine", 1, 2, 7, 1,
- function()
- log("Sending \"run smine\"")
- sendCmd("control", "run", "smine")
- end)
- btns.vquarry = makeButton("vquarry", 9, 2, 9, 1,
- function()
- end)
- btns.wither = makeButton("wither", 19, 2, 8, 1,
- function()
- end)
- btns.refuel = makeButton("refuel", 1, 3, 8, 1,
- function()
- log("Sending \"run refuel 64\"")
- sendCmd("control", "run", "refuel", "64")
- end)
- btns.stop = makeButton("STOP", 1, 5, 8, 3,
- function()
- log("Sending \"sigterm\" for 3 seconds")
- shell.switchTab(shell.openTab("sendstop", receiver))
- end)
- btns.setrecieve = makeButton("Set Receiver", 10, 5, 16, 3,
- function()
- term.clear()
- term.setCursorPos(1, 1)
- print("Type new receiver pattern")
- receiver = read()
- if receiver:sub(1, 1) ~= "^" then
- receiver = "^" .. receiver
- end
- if receiver:sub(-1, -1) ~= "$" then
- receiver = receiver .. "$"
- end
- labels.receiver = makeLabel("Rec:" .. receiver, 1, 8)
- redraw()
- end)
- btns.digon = makeButton("+", 6, 10, 3, 1,
- function()
- log("Sending \"set dig on\"")
- sendCmd("control", "set", "dig", "on")
- end)
- btns.digoff = makeButton("-", 10, 10, 3, 1,
- function()
- log("Sending \"set dig off\"")
- sendCmd("control", "set", "dig", "off")
- end)
- btns.digdownon = makeButton("+", 20, 10, 3, 1,
- function()
- log("Sending \"set digdown on\"")
- sendCmd("control", "set", "digdown", "on")
- end)
- btns.digdownoff = makeButton("-", 24, 10, 3, 1,
- function()
- log("Sending \"set digdown off\"")
- sendCmd("control", "set", "digdown", "off")
- end)
- btns.digupon = makeButton("+", 6, 11, 3, 1,
- function()
- log("Sending \"set digup on\"")
- sendCmd("control", "set", "digup", "on")
- end)
- btns.digupoff = makeButton("-", 10, 11, 3, 1,
- function()
- log("Sending \"set digup off\"")
- sendCmd("control", "set", "digup", "off")
- end)
- btns.persiston = makeButton("+", 20, 11, 3, 1,
- function()
- log("Sending \"set dig on\"")
- sendCmd("control", "set", "persist", "on")
- end)
- btns.persistoff = makeButton("-", 24, 11, 3, 1,
- function()
- log("Sending \"set dig on\"")
- sendCmd("control", "set", "persist", "off")
- end)
- btns.upx4 = makeButton("UP", 5, 13, 6, 1,
- function()
- log("Sending \"move up 4\"")
- sendCmd("control", "move", "up", 4)
- end)
- btns.upx2 = makeButton("UP", 5, 14, 6, 1,
- function()
- log("Sending \"move up 2\"")
- sendCmd("control", "move", "up", 2)
- end)
- btns.upx1 = makeButton("UP", 5, 15, 6, 1,
- function()
- log("Sending \"move up 1\"")
- sendCmd("control", "move", "up", 1)
- end)
- btns.downx1 = makeButton("DOWN", 5, 17, 6, 1,
- function()
- log("Sending \"move down 1\"")
- sendCmd("control", "move", "down", 1)
- end)
- btns.downx2 = makeButton("DOWN", 5, 18, 6, 1,
- function()
- log("Sending \"move down 2\"")
- sendCmd("control", "move", "down", 2)
- end)
- btns.downx4 = makeButton("DOWN", 5, 19, 6, 1,
- function()
- log("Sending \"move down 4\"")
- sendCmd("control", "move", "down", 4)
- end)
- btns.frwdx4 = makeButton("FRWD", 13, 13, 6, 1,
- function()
- log("Sending \"move frwd 4\"")
- sendCmd("control", "move", "frwd", 4)
- end)
- btns.frwdx2 = makeButton("FRWD", 13, 14, 6, 1,
- function()
- log("Sending \"move frwd 2\"")
- sendCmd("control", "move", "frwd", 2)
- end)
- btns.frwdx1 = makeButton("FRWD", 13, 15, 6, 1,
- function()
- log("Sending \"move frwd 1\"")
- sendCmd("control", "move", "frwd", 1)
- end)
- btns.backx1 = makeButton("BACK", 13, 17, 6, 1,
- function()
- log("Sending \"move back 1\"")
- sendCmd("control", "move", "back", 1)
- end)
- btns.backx2 = makeButton("BACK", 13, 18, 6, 1,
- function()
- log("Sending \"move back 2\"")
- sendCmd("control", "move", "back", 2)
- end)
- btns.backx4 = makeButton("BACK", 13, 19, 6, 1,
- function()
- log("Sending \"move back 4\"")
- sendCmd("control", "move", "back", 4)
- end)
- btns.left = makeButton("<", 21, 13, 5, 3,
- function()
- log("Sending \"move left\"")
- sendCmd("control", "move", "left")
- end)
- btns.right = makeButton(">", 21, 17, 5, 3,
- function()
- log("Sending \"move right\"")
- sendCmd("control", "move", "right")
- end)
- labels.receiver = makeLabel("Rec:" .. receiver, 1, 8)
- labels.dig = makeLabel("Dig:", 1, 10)
- labels.digdown = makeLabel("DDwn:", 14, 10)
- labels.digup = makeLabel("DUp:", 1, 11)
- labels.persist = makeLabel("Prst:", 14, 11)
- labels.plusx4 = makeLabel("x4", 1, 13)
- labels.plusx2 = makeLabel("x2", 1, 14)
- labels.plusx1 = makeLabel("x1", 1, 15)
- labels.minusx1 = makeLabel("x1", 1, 17)
- labels.minusx2 = makeLabel("x2", 1, 18)
- labels.minusx4 = makeLabel("x4", 1, 19)
- term.setCursorPos(1,1)
- term.clear()
- redraw()
- while true do
- evt, btn, x, y = os.pullEvent("mouse_click")
- handleClick(x, y)
- end
- --print("[infinidig] [checkfuel] ")
- --print("[smine] [vquarry] [wither]")
- --print("[refuel] ")
- --print(" ")
- --print("+------+ +--------------+")
- --print("| STOP | | Set receiver |")
- --print("+------+ +--------------+")
- --print("Rec: ")
- --print(" ")
- --print("Dig: [+] [-] DDwn: [+] [-]")
- --print("DUp: [+] [-] Prst: [+] [-]")
- --print(" ")
- --print("x4 [ UP ] [FRWD] +---+ ")
- --print("x2 [ UP ] [FRWD] | < | ")
- --print("x1 [ UP ] [FRWD] +---+ ")
- --print(" ")
- --print("x1 [DOWN] [BACK] +---+ ")
- --print("x2 [DOWN] [BACK] | > | ")
- --print("x4 [DOWN] [BACK] +---+ ")
Add Comment
Please, Sign In to add comment