Advertisement
Guest User

a

a guest
Aug 1st, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. c = peripheral.wrap("top")
  2. m = peripheral.wrap("monitor_3")
  3. os.loadAPI("buttons")
  4. sStart = 1
  5. yStart = 2
  6.  
  7. x,y = m.getSize()
  8. x2 = x - 4
  9. x1 = 5
  10. sSize = (y-yStart)/2-2
  11.  
  12. function getSize()
  13.   c.condenseItems()
  14.   for i = 1,c.getInventorySize() do
  15.     if c.getStackInSlot(i) == nil then
  16.       return i
  17.     end
  18.   end
  19.   return c.getInventorySize()+1
  20. end
  21.  
  22. function centerM(message)
  23.   m.clear()
  24.   m.setCursorPos((x-string.len(message))/2,y/2)
  25.   m.write(message)
  26. end
  27.  
  28. function screen()
  29.   local name
  30.   if sStart+sSize>size then
  31.     i2 = size
  32.   else
  33.     i2 = sStart+sSize
  34.   end
  35.   j = 0
  36.   for i = sStart, i2 do
  37.     j = j + 1
  38.     if c.getStackInSlot(i) ~= nil then
  39.       name = c.getStackInSlot(i).destination
  40.       buttons.setTable(name,moveItem,i,x1,x2,j+1*j+yStart,j+1*j+yStart)
  41.     end
  42.   end
  43.   scroll()
  44.   m.clear()
  45.   buttons.heading("Portal Hub")
  46.   buttons.screen()
  47. end
  48.  
  49. function scroll()
  50.   if sStart > 1 then
  51.     buttons.setTable("< Prev",prev,0,x1,(x/2)-1,y,y)
  52.   end
  53.   if sStart+sSize < size then
  54.     buttons.setTable("Next >",next,0,(x/2)+1,x2,y,y)
  55.   end
  56. end
  57.  
  58. function prev(i)
  59.   sStart = sStart-sSize-1
  60. end
  61.  
  62. function next(i)
  63.   sStart = sStart+sSize+1
  64. end
  65.  
  66. function moveItem(slot)
  67.   c.pullItem("west",1,1,1)
  68.   c.pushItem("west",slot,1,1)
  69. end
  70.  
  71. function starter()
  72.   size = getSize()
  73.   c.condenseItems()
  74.   buttons.clearTable()
  75.   screen()
  76. end
  77.  
  78. while true do
  79.   starter()
  80.   event,p1,p2,p3 = os.pullEvent("monitor_touch")
  81.   centerM("Loading...")
  82.   buttons.checkxy(p2,p3)
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement