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 net = component.modem
- local running = true
- -- Colors
- local backcolor = 0x000000
- local forecolor = 0xFFFFFF
- local buttonbg = 0x444444
- local buttonselectedbg = 0x626262
- local buttontext = 0xC5C8C6
- local selection = 0xF0544C
- local infocolor = 0x0066FF
- local errorcolor = 0xFF0000
- -- Constants
- local myname = "XDjackieXD"
- -- Gui
- local oldwidth, oldheight = gpu.getResolution()
- local oldbgcolor = gpu.getBackground()
- local oldfgcolor = gpu.getForeground()
- local width = 10
- local height = 20
- local buttons = {}
- gpu.setResolution(width, height)
- gpu.setForeground(forecolor)
- gpu.setBackground(backcolor)
- local function addButton(x, y, wi, he, name, callback, colorbg, colortext)
- buttons[#buttons + 1] = {x, y, wi, he, name, callback, colorbg, colortext}
- end
- local function drawButton(x, y, wi, he, text, buttonbgcolor, buttontextcolor)
- gpu.setBackground(buttonbgcolor)
- gpu.setForeground(buttontextcolor)
- 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], buttons[i][7], buttons[i][8])
- 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], player)
- end
- end
- end
- end
- -- Callbacks
- local function touchCallback(name, address, x, y, button, player)
- clickCallback(x, y, player)
- end
- local function onCallback(button, player)
- net.broadcast(123, "on")
- drawButton(button[1], button[2], button[3], button[4], button[5], 0x9D0000, button[8])
- os.sleep(0.5)
- drawScreen()
- end
- local function offCallback(button, player)
- net.broadcast(123, "off")
- drawButton(button[1], button[2], button[3], button[4], button[5], 0x9D0000, button[8])
- os.sleep(0.5)
- drawScreen()
- end
- -- Main Code
- addButton(1, 1, 10, 9, "On", onCallback, buttonbg, buttontext)
- addButton(1, 12, 10, 9, "Off", offCallback, buttonbg, buttontext)
- net.open(123)
- event.listen("touch", touchCallback)
- drawScreen()
- while running do
- os.sleep(10)
- end
Add Comment
Please, Sign In to add comment