Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m = peripheral.wrap("back")
- w,h = m.getSize()
- w = w+1
- h = h+1
- page = 1
- col = { ["white"]=1, ["orange"]=2, ["magenta"]=4, ["lightblue"]=8, ["yellow"]=16, ["lime"]=32, ["pink"]=64, ["gray"]=128, ["lightgray"]=256, ["cyan"]=512, ["purple"]=1024, ["blue"]=2048, ["brown"]=4096, ["green"]=8192, ["red"]=16384, ["black"]=32768 }
- rednet.open("top")
- mobfarmsname = { [1]="ZombiePig Farm", [2]="Blaze Farm", }
- mobfarmscode = { [1]="zombiepig", [2]="blaze", }
- mobfarmsactive = { [1]=false, [2]=false, }
- mobfarmsbutton = {}
- function swrite(str,x,y,color)
- m.setCursorPos(x,y)
- m.setTextColor(col[color])
- m.write(str)
- end
- function drawbox(str,x1,x2,y1,y2,strcol,color)
- m.setCursorPos(x1,y1)
- m.setBackgroundColor(col[color])
- m.setTextColor(col[strcol])
- local bw = x2-x1
- local bh = y2-y1
- local bstr = " "
- while #bstr < bw do
- bstr = bstr.." "
- end
- for i=1,bh do
- m.setCursorPos(x1,y1+i-1)
- m.write(bstr)
- end
- m.setCursorPos(x1+bw/2-#str/2,y1+bh/2)
- m.write(str)
- m.setBackgroundColor(col["black"])
- return { [1]=x1, [2]=x2, [3]=y1, [4]=y2 }
- end
- function press(but)
- if event == "monitor_touch" then
- if pr2 >= but[1] and pr2 < but[2] and pr3 >= but[3] and pr3 < but[4] then
- return true
- else
- return false
- end
- end
- end
- function drawbackground(str,strcol,color)
- drawbox("",1,w,1,h,strcol,color)
- drawbox("",2,w-1,2,h-1,"black","black")
- drawbox(str,1,w,1,2,strcol,color)
- end
- function drawmenu()
- m.clear()
- drawbackground("Mob Farms","black","white")
- if page > 1 then
- back = drawbox("Back",4,w/2-2,h-5,h-2,"white","red")
- end
- for i=1,3 do
- if mobfarmsname[i+(page-1)*3] == nil then
- mobfarmsbutton[i+(page-1)*3] = drawbox("",w+4,w+6,4,4,"black","black")
- else
- if mobfarmsactive[i+(page-1)*3] then color = "green" else color = "red" end
- mobfarmsbutton[i+(page-1)*3] = textutils.serialize(drawbox(mobfarmsname[i+(page-1)*3],4,w-3,4*i-1,4*i+2,"white",color))
- end
- if i == 3 and mobfarmsname[i+(page-1)*3+1] ~= nil then
- next = drawbox("Next",w/2+2,w-3,h-5,h-2,"white","green")
- else
- next = drawbox("Next",w/2+2,w-3,h+5,h+2,"white","green")
- end
- end
- end
- function updatemobfarms()
- for i=1,#mobfarmsactive do
- if mobfarmsactive[i] then
- rednet.broadcast(mobfarmscode[i].."on")
- else
- rednet.broadcast(mobfarmscode[i].."off")
- end
- end
- drawmenu()
- end
- drawmenu()
- updatemobfarms()
- while true do
- event,pr1,pr2,pr3 = os.pullEvent()
- for i=1,3 do
- if mobfarmsname[i+(page-1)*3] ~= nil then
- if press(textutils.unserialize(mobfarmsbutton[i+(page-1)*3])) then
- mobfarmsactive[i+(page-1)*3] = not mobfarmsactive[i+(page-1)*3]
- updatemobfarms()
- end
- end
- end
- if page > 1 then
- if press(back) then
- page = page - 1
- drawmenu()
- end
- end
- if press(next) then
- page = page + 1
- drawmenu()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment