Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- component = require("component")
- dial = component.rftools_dialing_device
- event = require("event")
- gpu = component.gpu
- term = require("term")
- keyboard = require("keyboard")
- colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000, purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00, lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b, olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7, crimson = 0xaf002a, fuchsia = 0xfd3f92, folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c, englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a, lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
- blackListedDestinations = {"Mine"}
- destinations = {}
- origin = nil
- function init()
- if not component.isAvailable("gpu") then io.stderr:write("Program needs a GPU to run"); os.exit() end
- gpu.setResolution(gpu.maxResolution())
- maxWidth, maxHeight = gpu.getResolution()
- term.clear()
- getMachines()
- component.screen.setTouchModeInverted(true)
- end
- function getMachines()
- destinations = checkReceivers()
- origin = getHere()
- end
- function checkReceivers()
- local receivers = dial.getReceivers()
- for k,v in pairs(receivers) do
- if type(receivers[k]) ~= "table" then
- receivers[k] = nil
- end
- end
- for i = #receivers, 1, -1 do
- for j = 1, #blackListedDestinations do
- if receivers[i].name == blackListedDestinations[j] then
- table.remove(receivers, i)
- break
- end
- end
- end
- return receivers
- end
- function getHere()
- return dial.getTransmitters()[1].position
- end
- function display(destinationList)
- local headerText = "Possible destinations:\n"
- do --get optimal resolution
- widestWidth = string.len(headerText)
- for k,v in pairs(destinationList) do
- if string.len(v.name) > widestWidth then widestWidth = string.len(v.name) end
- end
- width = widestWidth + 2
- height = math.min(#destinationList + 2, maxHeight)
- gpu.setResolution(width, height)
- end
- term.clear()
- term.setCursor(1,1)
- io.stderr:write(headerText)
- for k,v in ipairs(destinationList) do
- io.stdout:write(v.name .. "\n")
- if k > height - 2 then break end
- end
- term.setCursor(1, height)
- term.write("[[Refresh]]")
- end
- function selectDestination(destinationList, number)
- dial.dial(origin, destinationList[number].position, 0, true)
- os.sleep(5)
- dial.interrupt(origin)
- end
- function debug(text)
- print(text); os.exit()
- end
- function checkClick(destinationList)
- local e, _, x, y, _, _ = event.pull(5, "touch")
- if e == nil then return end
- do --we pushed a screen
- local function hasPushedLine(line)
- if line == 0 then return false end
- return true
- end
- if hasPushedLine(y) then --we have pushed something ~= header
- if y == height then
- getMachines()
- display(destinations)
- else
- selectDestination(destinationList, y - 1)
- end
- end
- end
- end
- init()
- display(destinations)
- repeat
- checkClick(destinations)
- until keyboard.isControlDown()
- term.clear()
- gpu.setResolution(gpu.maxResolution())
- component.screen.setTouchModeInverted(false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement