Spoiler
local mon = peripheral.wrap("top")
mon.setTextScale(1)
mon.setTextColor(colors.white)
local button={}
mon.setBackgroundColor(colors.blue)
function clearTable()
button = {}
mon.clear()
end
function setTable(name, func, xmin, xmax, ymin, ymax, btnOff, btnOn)
button[name] = {}
button[name]["func"] = func
button[name]["active"] = false
button[name]["xmin"] = xmin
button[name]["ymin"] = ymin
button[name]["xmax"] = xmax
button[name]["ymax"] = ymax
button[name]["btnOff"] = btnOff
button[name]["btnOn"] = btnOn
end
function funcName()
print("You clicked buttonText")
end
function fillTable()
setTable("ButtonText", funcName, 5, 25, 4, 8)
end
function fill(text, color, bData)
mon.setBackgroundColor(color)
local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
for j = bData["ymin"], bData["ymax"] do
mon.setCursorPos(bData["xmin"], j)
if j == yspot then
for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
if k == xspot then
mon.write(text)
else
mon.write(" ")
end
end
else
for i = bData["xmin"], bData["xmax"] do
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.blue)
end
function screen()
local currColor
for name,data in pairs(button) do
local on = data["active"]
if on == true then currColor = data["btnOn"] else currColor = data["btnOff"] end
fill(name, currColor, data)
end
end
function toggleButton(name)
button[name]["active"] = not button[name]["active"]
screen()
end
function flash(name)
toggleButton(name)
screen()
sleep(0.15)
toggleButton(name)
screen()
end
function checkxy(x, y)
for name, data in pairs(button) do
if y>=data["ymin"] and y <= data["ymax"] then
if x>=data["xmin"] and x<= data["xmax"] then
data["func"]()
return true
--data["active"] = not data["active"]
--print(name)
end
end
end
return false
end
function heading(text)
w, h = mon.getSize()
mon.setCursorPos((w-string.len(text))/2+1, 1)
mon.write(text)
end
function label(w, h, text)
mon.setCursorPos(w, h)
mon.write(text)
end
I don't know is this posible but i think i must change function setTable and screen to this:
Spoiler
function setTable(name, func1, func2, xmin, xmax, ymin, ymax, btnOff, btnOn)
button[name] = {}
button[name]["func1"] = func1
button[name]["func2"] = func2
button[name]["active"] = false
button[name]["xmin"] = xmin
button[name]["ymin"] = ymin
button[name]["xmax"] = xmax
button[name]["ymax"] = ymax
button[name]["btnOff"] = btnOff
button[name]["btnOn"] = btnOn
end
function screen()
local currColor
local currFunc
for name,data in pairs(button) do
local on = data["active"]
if on == true then
currColor = data["btnOn"] and currFunc = data["func1"]
else
currColor = data["btnOff"] and currFunc = data["func2"]
end
fill(name, currColor, currFunc, data)
end
end
This is the one thing left to do in my project so if anybody can help me with my problem, I'll be really happy. I'm really sorry if this post is in non "english" form, but it's not my main language. I also search for any results on this forum and on google and youtube and i can't find anything what can help me in my problem