Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local unicode = require('unicode')
- local event = require('event')
- local term = require('term')
- local shell=require("shell")
- local fs = require('filesystem')
- local component = require('component')
- local gpu = component.gpu
- local debug = component.debug
- local running = true
- -- Colors
- local backcolor = 0x444444
- local forecolor = 0xFFFFFF
- local buttonbg = 0x000000
- local buttonselectedbg = 0x626262
- local buttontext = 0xC5C8C6
- local selection = 0xF0544C
- local infocolor = 0x0066FF
- local errorcolor = 0xFF0000
- -- Constants
- local myname = "XDjackieXD"
- -- Quickdial
- local qdPlayers = {"Ellpeck", "canitzp", "_Inari", "unascribed", "Vexatos", "Chocohead", "Aesen"}
- local qdPos = {}
- qdPos["MyBooth"] = {458, 44, -317}
- qdPos["EllpeckBooth"] = {404, 44, -271}
- -- Gui
- local oldwidth, oldheight = gpu.getResolution()
- local oldbgcolor = gpu.getBackground()
- local oldfgcolor = gpu.getForeground()
- local width, height = gpu.maxResolution()
- local buttons = {}
- gpu.setResolution(width, height)
- gpu.setForeground(forecolor)
- gpu.setBackground(backcolor)
- local function addButton(x, y, wi, he, name, callback)
- buttons[#buttons + 1] = {x, y, wi, he, name, callback}
- end
- local function drawButton(x, y, wi, he, text)
- gpu.setBackground(buttonbg)
- gpu.setForeground(buttontext)
- gpu.fill(x, y, wi, he, " ")
- gpu.set(x+(wi/2)-(string.len(text)/2) , y+(he/2), text)
- gpu.setBackground(backcolor)
- gpu.setForeground(forecolor)
- end
- local function drawScreen()
- term.clear()
- for i=1, #buttons do
- drawButton(buttons[i][1], buttons[i][2], buttons[i][3], buttons[i][4], buttons[i][5])
- end
- end
- local function clickCallback(x, y, player)
- for i=1, #buttons do
- if x >= buttons[i][1] and x < buttons[i][1]+buttons[i][3] then
- if y >= buttons[i][2] and y < buttons[i][2]+buttons[i][4] then
- buttons[i][6](buttons[i][5], player)
- end
- end
- end
- end
- -- Callbacks
- local function touchCallback(name, address, x, y, button, player)
- clickCallback(x, y, player)
- end
- local function tabCompletionCallback(line, pos)
- local players = debug.getPlayers()
- local matches = {}
- for i=1, #players do
- if string.sub(players[i],1,string.len(line))==line then
- table.insert(matches, players[i])
- end
- end
- return matches
- end
- local function exitCallback(name, player)
- event.ignore("touch", touchCallback)
- gpu.setBackground(oldbgcolor)
- gpu.setForeground(oldfgcolor)
- gpu.setResolution(oldwidth, oldheight)
- term.clear()
- running = false
- os.exit()
- end
- local function tpPlayerCallback(n2, n1)
- if n1 ~= nil and n2 ~= nil then
- local p1 = debug.getPlayer(n1)
- local p2 = debug.getPlayer(n2)
- local players = debug.getPlayers()
- local f1, f2 = false, false
- for i, v in ipairs(players) do
- if v == n1 then f1 = true end
- if v == n2 then f2 = true end
- end
- if f1 and f2 then
- local posX, posY, posZ = p2.getPosition()
- p1.setPosition(posX, posY, posZ)
- else
- gpu.setForeground(errorcolor)
- local xpos, ypos = term.getCursor()
- term.setCursor(width-18, height)
- term.write("Player not found!")
- term.setCursor(xpos, ypos)
- gpu.setForeground(forecolor)
- end
- end
- end
- local function tpPosCallback(name, player)
- if qdPos[name] ~= nil then
- local p1 = debug.getPlayer(player)
- p1.setPosition(qdPos[name][1], qdPos[name][2], qdPos[name][3])
- end
- end
- -- Main Code
- local maxlength = 0
- for i=1, #qdPlayers do
- if string.len(qdPlayers[i]) > maxlength then
- maxlength = string.len(qdPlayers[i])
- end
- end
- for k, v in pairs(qdPos) do
- if string.len(k) > maxlength then
- maxlength = string.len(k)
- end
- end
- maxlength = maxlength+2
- local row = 0
- local col = 0
- for i=1, #qdPlayers do
- addButton(2+(col*(maxlength+1)), 2+(row*4), maxlength, 3, qdPlayers[i], tpPlayerCallback)
- col = col+1
- if 2+(col*(maxlength+2)) > width then
- col = 0
- row = row+1
- end
- end
- for k,v in pairs(qdPos) do
- addButton(2+(col*(maxlength+1)), 2+(row*4), maxlength, 3, k, tpPosCallback)
- col = col+1
- if 2+(col*(maxlength+2)) > width then
- col = 0
- row = row+1
- end
- end
- --addButton(2, 2, maxlength, 3, "Exit", exitCallback)
- event.listen("touch", touchCallback)
- while running do
- drawScreen()
- term.setCursor(1, height)
- term.clearLine()
- term.write(">")
- player = string.sub(term.read({}, false, tabCompletionCallback), 1, -2)
- if player == "exit" then
- exitCallback("", "")
- else
- tpPlayerCallback(player, myname)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement