SHOW:
|
|
- or go back to the newest paste.
| 1 | local unicode = require('unicode')
| |
| 2 | local event = require('event')
| |
| 3 | local term = require('term')
| |
| 4 | local shell=require("shell")
| |
| 5 | local fs = require('filesystem')
| |
| 6 | local component = require('component')
| |
| 7 | local gpu = component.gpu | |
| 8 | - | local debug = component.debug |
| 8 | + | local net = component.modem |
| 9 | local running = true | |
| 10 | ||
| 11 | -- Colors | |
| 12 | - | local backcolor = 0x444444 |
| 12 | + | local backcolor = 0x000000 |
| 13 | local forecolor = 0xFFFFFF | |
| 14 | ||
| 15 | - | local buttonbg = 0x000000 |
| 15 | + | local buttonbg = 0x444444 |
| 16 | local buttonselectedbg = 0x626262 | |
| 17 | local buttontext = 0xC5C8C6 | |
| 18 | ||
| 19 | local selection = 0xF0544C | |
| 20 | ||
| 21 | local infocolor = 0x0066FF | |
| 22 | local errorcolor = 0xFF0000 | |
| 23 | ||
| 24 | ||
| 25 | -- Constants | |
| 26 | local myname = "XDjackieXD" | |
| 27 | ||
| 28 | - | -- Quickdial |
| 28 | + | |
| 29 | - | local qdPlayers = {"Ellpeck", "canitzp", "_Inari", "unascribed", "Vexatos", "Chocohead", "Aesen"}
|
| 29 | + | |
| 30 | - | local qdPos = {}
|
| 30 | + | |
| 31 | - | qdPos["MyBooth"] = {458, 44, -317}
|
| 31 | + | |
| 32 | - | qdPos["EllpeckBooth"] = {404, 44, -271}
|
| 32 | + | local width = 10 |
| 33 | local height = 20 | |
| 34 | local buttons = {}
| |
| 35 | ||
| 36 | gpu.setResolution(width, height) | |
| 37 | gpu.setForeground(forecolor) | |
| 38 | gpu.setBackground(backcolor) | |
| 39 | - | local width, height = gpu.maxResolution() |
| 39 | + | |
| 40 | local function addButton(x, y, wi, he, name, callback, colorbg, colortext) | |
| 41 | buttons[#buttons + 1] = {x, y, wi, he, name, callback, colorbg, colortext}
| |
| 42 | end | |
| 43 | ||
| 44 | local function drawButton(x, y, wi, he, text, buttonbgcolor, buttontextcolor) | |
| 45 | gpu.setBackground(buttonbgcolor) | |
| 46 | - | local function addButton(x, y, wi, he, name, callback) |
| 46 | + | gpu.setForeground(buttontextcolor) |
| 47 | - | buttons[#buttons + 1] = {x, y, wi, he, name, callback}
|
| 47 | + | |
| 48 | gpu.fill(x, y, wi, he, " ") | |
| 49 | gpu.set(x+(wi/2)-(string.len(text)/2) , y+(he/2), text) | |
| 50 | - | local function drawButton(x, y, wi, he, text) |
| 50 | + | |
| 51 | - | gpu.setBackground(buttonbg) |
| 51 | + | |
| 52 | - | gpu.setForeground(buttontext) |
| 52 | + | |
| 53 | end | |
| 54 | ||
| 55 | local function drawScreen() | |
| 56 | term.clear() | |
| 57 | for i=1, #buttons do | |
| 58 | drawButton(buttons[i][1], buttons[i][2], buttons[i][3], buttons[i][4], buttons[i][5], buttons[i][7], buttons[i][8]) | |
| 59 | end | |
| 60 | end | |
| 61 | ||
| 62 | local function clickCallback(x, y, player) | |
| 63 | for i=1, #buttons do | |
| 64 | - | drawButton(buttons[i][1], buttons[i][2], buttons[i][3], buttons[i][4], buttons[i][5]) |
| 64 | + | |
| 65 | if y >= buttons[i][2] and y < buttons[i][2]+buttons[i][4] then | |
| 66 | buttons[i][6](buttons[i], player) | |
| 67 | end | |
| 68 | end | |
| 69 | end | |
| 70 | end | |
| 71 | ||
| 72 | - | buttons[i][6](buttons[i][5], player) |
| 72 | + | |
| 73 | ||
| 74 | -- Callbacks | |
| 75 | local function touchCallback(name, address, x, y, button, player) | |
| 76 | clickCallback(x, y, player) | |
| 77 | end | |
| 78 | ||
| 79 | local function onCallback(button, player) | |
| 80 | net.broadcast(123, "on") | |
| 81 | drawButton(button[1], button[2], button[3], button[4], button[5], 0x9D0000, button[8]) | |
| 82 | os.sleep(0.5) | |
| 83 | drawScreen() | |
| 84 | end | |
| 85 | - | local function tabCompletionCallback(line, pos) |
| 85 | + | |
| 86 | - | local players = debug.getPlayers() |
| 86 | + | local function offCallback(button, player) |
| 87 | - | local matches = {}
|
| 87 | + | net.broadcast(123, "off") |
| 88 | - | for i=1, #players do |
| 88 | + | drawButton(button[1], button[2], button[3], button[4], button[5], 0x9D0000, button[8]) |
| 89 | - | if string.sub(players[i],1,string.len(line))==line then |
| 89 | + | os.sleep(0.5) |
| 90 | - | table.insert(matches, players[i]) |
| 90 | + | |
| 91 | end | |
| 92 | ||
| 93 | - | return matches |
| 93 | + | |
| 94 | -- Main Code | |
| 95 | ||
| 96 | - | local function exitCallback(name, player) |
| 96 | + | addButton(1, 1, 10, 9, "On", onCallback, buttonbg, buttontext) |
| 97 | - | event.ignore("touch", touchCallback)
|
| 97 | + | addButton(1, 12, 10, 9, "Off", offCallback, buttonbg, buttontext) |
| 98 | - | gpu.setBackground(oldbgcolor) |
| 98 | + | |
| 99 | - | gpu.setForeground(oldfgcolor) |
| 99 | + | net.open(123) |
| 100 | - | gpu.setResolution(oldwidth, oldheight) |
| 100 | + | |
| 101 | event.listen("touch", touchCallback)
| |
| 102 | - | running = false |
| 102 | + | drawScreen() |
| 103 | - | os.exit() |
| 103 | + | |
| 104 | while running do | |
| 105 | os.sleep(10) | |
| 106 | - | local function tpPlayerCallback(n2, n1) |
| 106 | + |