local event = require("event")
local component = require("component")
local unicode = require("unicode")
local gpu = component.gpu
local red = component.isAvailable("restone") and component.redstone or error("Redstone component is unavailable")
local floor = math.floor
local TOP = 1
local BOTTOM = 0
local SignalTop, SignalBottom
local Buttons = {}
local function CreateButton(x, y, w, h, bgc, fgc, text, callback)
local obgc = gpu.getBackground()
local ofgc = gpu.getForeground()
gpu.setBackground(bgc)
gpu.setForeground(fgc)
gpu.fill(x, y, w, h, " ")
gpu.set(floor(x+(w/2)-unicode.len(text)/2), floor(y+h/2, text), text)
table.insert(Buttons, {
xmi = x,
ymi = y,
xma = x+w,
yma = y+h,
cb = callback
})
gpu.setBackground(obgc)
gpu.setForeground(ofgc)
end
local function CheckButtonPress(x, y)
for _, button in ipairs(Buttons) do
if (x>=button.xmi) and (x<=button.xma) then
if (y>=button.ymi) and (y<=button.yma) then
button.cb(x, y)
end
end
end
end
local ScrW, ScrH = gpu.getResolution()
CreateButton(floor(ScrW/6), floor(ScrH/2), 18, 3, 0x646464, 0xbebebe, "Top", function()
SignalTop = not SignalTop
red.setOutput(TOP, SignalTop and 15 or 0)
end)
CreateButton(ScrW - floor(ScrW/6) - 18, floor(ScrH/2), 18, 3, 0x646464, 0xbebebe, "Bottom", function()
SignalBottom = not SignalBottom
red.setOutput(BOTTOM, SignalBottom and 15 or 0)
end)
while true do
local _, _, x, y = event.pull("touch")
CheckButtonPress(x, y)
end
Нуу....
Должно работать, наверное...