Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("top")
- mon.setTextScale(1)
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- buttons={}
- function setButton(name, x,y,func)
- buttons[name]={}
- buttons[name]["x"]=x
- buttons[name]["y"]=y
- buttons[name]["func"]=func
- buttons[name]["active"]=false
- end
- function drawButton(text, color, data)
- mon.setBackgroundColor(color)
- mon.setCursorPos(data["x"],data["y"])
- mon.write(text)
- mon.setBackgroundColor(colors.black)
- end
- function screen()
- local currColor
- for name, data in pairs(buttons) do
- local on=data["active"]
- if on==true then currColor=colors.lime else currColor=colors.red end
- drawButton(name, currColor, data)
- end
- end
- function toggleButton(name)
- buttons[name]["active"]= not buttons[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(buttons) do
- local xmax= data["x"]+string.len(name)
- if y==data["y"] then
- if x>=data["x"] and x<xmax then
- data["func"]()
- return true
- end
- end
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement