Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("buttons")
- m = peripheral.wrap("top")
- rednet.open("bottom")
- bookNames = {}
- stargateName = "STARGATE SG-1"
- stargateNameSize = 1
- stargateNameColor = colors.black
- x,y = m.getSize()
- col = 3 --How many columns for buttons
- row = 3 --How many rows for buttons
- yHead = 1 --Amount of space for header
- yDown = 3 --Spaces between buttons and bottom
- --!! REQUIRED FOR THE PREV.&NEXT BUTTONS !!--
- y = y - 0 --Make room on the bottom
- x = x - 0 --For making room on the sides
- sStart = 0 --Global var to keep track of current book
- rcid = 66 --Remote chest ID
- function split(inputstr, sep)
- if sep == nil then sep = "%s" end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function printTable(t)
- --For testing purposes
- for k,v in pairs(t) do
- print("key: "..tostring(k).." value: "..tostring(v))
- end
- end
- function createButton()
- local xmin,xmax,ymin,ymax
- local j = sStart
- for i1 = 1,col do
- for i2 = 1,row do
- j = j + 1
- if n[j] == nil then break end
- xcol = math.floor(x/col)
- if (xcol*col) > x then xcol = xcol - 1 end
- yrow = math.floor((y-yHead-yDown)/row)
- if (yrow*row+yHead+yDown) > y then yrow = yrow - 1 end
- xmin = (xcol*i1+1)-(xcol-1)
- xmax = (xcol*(i1+1)-1)-(xcol-1)
- ymin = (yrow*i2+1)-(yrow-1)+yHead
- ymax = (yrow*(i2+1)-1)-(yrow-1)+yHead
- buttons.setTable(n[j],moveItem,keys[n[j]],xmin,xmax,ymin,ymax)
- end
- end
- end
- function prev(i)
- sStart = sStart - row * col
- refresh()
- end
- function next(i)
- sStart = sStart + row * col
- refresh()
- end
- function getBookNames()
- message = "name/"
- rednet.send(rcid,message)
- event, id, message = os.pullEvent("rednet_message")
- return split(message,"/")
- end
- function moveItem(slot,name)
- message = "move/"..slot
- rednet.send(rcid,message)
- --event, id, message = os.pullEvent("rednet_message")
- end
- function getClick()
- cont = false
- while not cont do
- event,p1,p2,p3 = os.pullEvent("monitor_touch")
- cont = buttons.checkxy(p2,p3)
- end
- end
- function createBottom()
- xcol = math.floor(x/col)
- if xcol*col > x then xcol = xcol - 1 end
- if sStart > 0 then
- buttons.setTable("< Prev",prev,0,2,xcol-1,y-1,y-1)
- end
- if #n > sStart+col*row then
- buttons.setTable("Next >",next,0,xcol+1,xcol*2-1,y-1,y-1)
- end
- end
- function starter()
- n = getBookNames()
- keys = {}
- for k,v in pairs(n) do
- keys[v] = k
- end
- table.sort(n, function(a,b) return string.lower(a)<string.lower(b) end)
- sleep(0.5)
- refresh()
- end
- function refresh()
- buttons.clearTable()
- buttons.loadingScreen("Loading",1)
- buttons.heading(stargateName,stargateNameColor,stargateNameSize)
- createButton()
- createBottom()
- buttons.screen()
- end
- starter()
- while true do
- getClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment