LuucEarth

Ficsit Networks Alphabetized Storage Monitor 1.0

Sep 22nd, 2020 (edited)
1,285
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[===[
  2.     ***Setup***
  3. Computer case with cpu,2 ram, gpu, screen driver(optional if using external screen), disk mount, hard drive T1
  4. You will need str_utils.lua by ProgCat  on your "hard drive" available in the ficsit networks code node
  5. Containers should be nicknamed "storage ##"  where ## is a designator of location
  6. ]===]--
  7.  
  8.  
  9. fs = filesystem
  10. fs.initFileSystem("/dev")
  11. disk_id="C959EF53449A1EDBECA95BBB4752F0BE"
  12. fs.mount("/dev/"..disk_id, "/")
  13. fs.doFile("str_utils.lua")
  14.  
  15. containers=component.proxy(component.findComponent("storage"))
  16. gpu=computer.getGPUs()[1]
  17. screen=computer.getScreens()[1]
  18. gpu:bindScreen(screen)
  19. w=120
  20. h=30
  21. gpu:setSize(w,h)
  22. gpu:setBackground(0,0,0,0)
  23. gpu:fill(0,0,w,h," ")
  24. gpu:setForeground(0,1,0,1)
  25. event.listen(gpu)
  26. data={}
  27. newData={}
  28. names={}
  29.  
  30.  
  31. emptyColorStatusBar = {0.1, 0.1, 0.1, 1}  
  32. fillColorStatusBar = {0.08, 0.9, 0.04, 1}
  33.  
  34. local function isNotEmpty(objectToCheck)
  35.   return objectToCheck ~= nil
  36. end
  37.  
  38. function roundToInt(value)
  39.  if value % 1 < 0.5 then
  40.   return math.floor(value)
  41.  end
  42.  return math.ceil(value)
  43. end
  44.  
  45. function clearScreen()
  46.  gpu:setBackground(0,0,0,0)
  47.  gpu:fill(0,0,w,h," ")
  48. end
  49.  
  50. function drawTitle()
  51.  gpu:setForeground(1,1,1,1)
  52.  gpu:setText(0,0,"Item")
  53.  gpu:setText(25,0,"Total/Max")
  54.  gpu:setText(40,0,"Slot")
  55.  gpu:setText(45,0,"Percent Full")
  56. end
  57.  
  58. function drawButtons()
  59.  gpu:setBackground(0,1,0,0.4)
  60.  gpu:setForeground(0,0,0,1)
  61.  gpu:setText(0,15,"  Prev Page  ")
  62.  gpu:setText(25,15,"  Next Page  ")
  63.  gpu:setBackground(0,0,0,0)
  64.  gpu:setForeground(0,1,0,1)
  65. end
  66.  
  67. for a,b in pairs(containers) do
  68.   nick=b.nick
  69.   spltNick=str.split(nick," ")
  70.   slot=spltNick[2]
  71.   inv=b:getInventories()[1]
  72.   iName=inv:getStack(0).item
  73.   if iName ~= nil then
  74.     iName=iName.type:getName()
  75.     amount=inv.itemcount
  76.     conSize=inv.size
  77.     stackSize=inv:getStack(0).count
  78.     table.insert(data,{iName,amount,conSize,stackSize,slot})
  79.   else
  80.     table.insert(data,{"Empty",0,0,0,slot})
  81.   end
  82. end
  83.  
  84. for a,b in pairs(data) do
  85.    name=b[1]
  86.    table.insert(names,name)
  87. end
  88.  
  89. table.sort(names)
  90.  
  91. for _,b in pairs(names) do
  92.    computer.skip()
  93.    for _,c in pairs(data) do
  94.      if b==c[1] then
  95.       table.insert(newData,{c[1],c[2],c[3],c[4],c[5]})
  96.      end
  97.    end  
  98. end
  99.  
  100. iter=1
  101. page=1
  102. offset=0
  103.  
  104. for y,a in pairs(newData) do
  105.   computer.skip()
  106.   if iter<=12 then
  107.     table.insert(a,y-offset)
  108.     table.insert(a,page)
  109.    iter=iter+1
  110.  else
  111.    page=page+1
  112.    offset=offset+12
  113.    iter=1
  114.    table.insert(a,y-offset)
  115.    table.insert(a,page)
  116.    iter=iter+1
  117.  
  118.  end
  119. end
  120. maxpage=page
  121. page=1
  122. function drawPage(page)
  123.   for a,b in pairs(newData) do
  124.     if b[7]==page then
  125.      name=b[1]
  126.      total=b[2]
  127.      contSize=b[3]
  128.      stackSize=b[4]
  129.      conSlot=b[5]
  130.      line=b[6]
  131.      max=stackSize*contSize
  132.      perc = total/max
  133.      fillSize=w-45
  134.      if perc < 0.2 or perc > 1 then
  135.         gpu:setForeground(1,0,0,1)
  136.      elseif perc < 0.5 then
  137.         gpu:setForeground(1,0.2,0,1)
  138.      elseif perc > 0.9 then
  139.         gpu:setForeground(0,1,0,1)
  140.      else
  141.         gpu:setForeground(1,1,0,1)
  142.      end
  143.      gpu:setText(0,line,name)
  144.      gpu:setText(25,line,total.."/"..max)
  145.      gpu:setText(40,line,conSlot)
  146.      gpu:setBackground(emptyColorStatusBar[1],emptyColorStatusBar[2],emptyColorStatusBar[3],emptyColorStatusBar[4])
  147.      gpu:fill(45,line,fillSize,1," ")
  148.      gpu:setBackground(fillColorStatusBar[1],fillColorStatusBar[2],fillColorStatusBar[3],fillColorStatusBar[4])
  149.      gpu:fill(45,line,roundToInt(fillSize * perc),1," ")
  150.      gpu:setBackground(0,0,0,0)
  151.     end
  152.   end
  153. end
  154.  
  155. while true do
  156.    clearScreen()
  157.    drawTitle()
  158.    drawButtons()
  159.    drawPage(page)
  160.    gpu:flush()
  161.  
  162.  
  163. signal, sender, x, y = event.pull()
  164.  if signal == "OnMouseDown" then
  165.     if x>=0 and x<=13 and y==15 and page > 1 then
  166.       page=page-1
  167.     end
  168.    if x>=25 and x<=38 and y==15 and page < maxpage then
  169.         page=page+1
  170.    end
  171.  end
  172. end
RAW Paste Data