Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Experement .net kinda
- by Big SHiny Toys
- ]]--
- local net = {}
- function net.newWindow()
- return {}
- end
- function net.run(tWin)
- local function draw()
- for k,v in pairs(tWin) do
- coroutine.resume(v,"redraw")
- end
- end
- local function checkForClick(clickX,clickY)
- for k,v in pairs(tWin) do
- local test,posX,posY,sizX,sizY = coroutine.resume(v,"box")
- if clickX >= posX and clickX < posX + sizX and clickY >= posY and clickY < posY + sizY then
- local test,func = coroutine.resume(v,"func")
- func()
- end
- end
- end
- draw()
- draw()
- while true do
- local event = {os.pullEvent()}
- if event[1] == "redraw" then
- draw()
- elseif event[1] == "mouse_click" then
- if event[2] == 1 then -- left click
- checkForClick(event[3],event[4])
- end
- end
- end
- end
- function net.button(windo,label,func,posX,posY,tCol,bCol)
- local myX,myY = posX,posY
- table.insert(windo,
- coroutine.create(
- function()
- local function draw()
- term.setCursorPos(myX,myY)
- term.setBackgroundColor(colors[tCol] or tCol)
- term.setTextColor(colors[bCol] or bCol)
- term.write(label)
- end
- local retdata = {}
- while true do
- local event = {coroutine.yield(unpack(retdata))}
- if event[1] == "redraw" then
- draw()
- retdata = {}
- elseif event[1] == "box" then
- retdata = {myX,myY,#label,1}
- elseif event[1] == "func" then
- retdata = {func}
- end
- end
- end
- )
- )
- end
- -- test
- local function x()
- print("X")
- error()
- end
- local function y()
- print("Y")
- error()
- end
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- local win = net.newWindow()
- net.button(win,"option1",x,3,3,"white","black")
- net.button(win,"option2",y,3,5,"white","black")
- net.run(win)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement