Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("right")
- local button={}
- mon.setTextScale(1)
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- redstone.setBundledOutput("left", 2)
- function setTable(name, func, xmin, xmax, ymin, ymax)
- 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
- end
- function fillTable()
- setTable("Spawn",spawn,1,7,1,5)
- setTable("Sort",sort,1,7,8,12)
- 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.black)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then currColor = colors.lime else currColor = colors.red end
- fill(name, currColor, data)
- end
- end
- function toggleButton(name)
- button[name]["active"] = not button[name]["active"]
- screen()
- end
- function flash(name)
- toggleButton(name)
- sleep(0.15)
- toggleButton(name)
- 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"]()
- end
- end
- end
- end
- function sort()
- os.startTimer(0.1)
- end
- function spawn()
- if button["Spawn"]["active"] then
- redstone.setBundledOutput("left", redstone.getBundledInput("left")+2)
- else
- redstone.setBundledOutput("left", redstone.getBundledInput("left")-2)
- end
- toggleButton(Spawn)
- end
- fillTable()
- while true do
- mon.clear()
- screen()
- local e,arg1,arg2,arg3 = os.pullEvent()
- if e == "monitor_touch" then
- checkxy(arg2,arg3)
- else
- redstone.setBundledOutput("left", redstone.getBundledInput("left")+4)
- os.sleep(0.2)
- redstone.setBundledOutput("left", redstone.getBundledInput("left")-4)
- os.startTimer(0.1)
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement