Advertisement
serafim7

progress bar mfsu [OpenComputers]

Jun 11th, 2017
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. --[[opencomputers progress bar mfsu by serafim
  2.     pastebin.com/kyN49tte
  3.  
  4. Получить заряд МФСУ и вывести на экран.
  5. От 1-го до 5-ти mfsu подключенных к
  6. ПК с помощью адаптера.
  7. ]]--
  8.  
  9. local comp = require('component')
  10. local gpu = comp.gpu
  11.  
  12. if not comp.isAvailable("mfsu") then
  13.   print("Ошибка! >> mfsu не найден")
  14.   os.exit()
  15. end
  16.  
  17. local function getAllSpecificComponets(filter)
  18.   local tableObjects ={}
  19.   for address, componentType in comp.list(filter) do
  20.     table.insert(tableObjects, comp.proxy(address))
  21.   end
  22.   return tableObjects
  23. end
  24.  
  25. local mfsu = getAllSpecificComponets('mfsu')
  26. local capacity = mfsu[1].getCapacity
  27.  
  28. if #mfsu > 5 then
  29.   print("Ошибка! >> подключено больше 5 mfsu")
  30.   os.exit()
  31. end
  32.  
  33. local w, h = gpu.getResolution()
  34. gpu.fill(1, 1, w, h, " ")
  35. gpu.setBackground(0x000000)
  36. gpu.setForeground(0x669999)
  37. local a,b,c,d,e,f = 1,2,3,4,3,4
  38. for i = 1, #mfsu do
  39.   gpu.set(3, a, "MFSU "..i.." :")
  40.   gpu.set(1, b, " ┌────────────────────────────────────┐ ")
  41.   gpu.set(1, c, " │")                  gpu.set(39, e, "│ ")
  42.   gpu.set(1, d, " └────────────────────────────────────┘ ")
  43.   a=a+5 b=b+5 c=c+5 d=d+5 e=e+5
  44.   if i ~= #mfsu then f=f+5 end
  45. end
  46. gpu.setResolution(44, f)
  47. gpu.setForeground(0xFF9900)
  48.  
  49. local stored,procent,progress = 0,0,0
  50. local a,b,c,d = 1,3,3,4
  51. while true do
  52.   for i = 1, #mfsu do
  53.     stored = mfsu[i].getStored
  54.     procent = math.ceil(stored()/capacity()*100)
  55.     progress = math.ceil(procent/100*34)
  56.     gpu.set(14, a, stored().." Eu из "..capacity())
  57.     gpu.set(40, b, procent.."% ")
  58.     d = 4
  59.     for i = 1, progress do
  60.       if d < 38 then
  61.         gpu.set(d, c, "█ ")
  62.       end
  63.       d = d + 1
  64.     end
  65.     a=a+5 b=b+5 c=c+5
  66.     if i == #mfsu then a,b,c = 1,3,3 end
  67.   end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement