SHARE
TWEET

Resonant Cell Control (OpenComputers)

Armander May 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Tylko monitor w=5, h=3 (width, height)
  2. API = require("buttonAPI")
  3. local component = require("component")
  4. local term = require("term")
  5. local event = require("event")
  6. local keyboard = require("keyboard")
  7. local sides = require("sides")
  8. local computer = require("computer")
  9. term.clear() --Czyszczenie napisow wstepnych
  10.  
  11. local kolor = { pomaranczowy = 0xEBB329, zielony = 0x008000, czerwony = 0xFF0000, czarny = 0x000000, bialy = 0xFFFFFF, niebieski = 0x0000FF, szary = 0x808080, morski = 0x008080, zolty = 0xFFFF00, fioletowy = 0x800080, cyjan = 0x00FFFF, fuksja = 0xFF00FF, limonka = 0x00FF00, wisniowy = 0x800000, granatowy = 0x000080, oliwkowy = 0x808000, srebrny = 0xC0C0C0}
  12.  
  13. --Zmienne urzadzen
  14. local screen = component.proxy(component.list("screen")())
  15. local gpu = component.proxy(component.list("gpu")())
  16. local rs = component.proxy(component.list("redstone")())
  17.  
  18. --Pojemniki na energie
  19. local acell = component.proxy("cea06e0f-4403-4059-9c63-b044ba6c11ca")
  20. local bcell = component.proxy("5ea0c33b-49b6-463c-ae08-ec9b2ed3a5ca")
  21. local ccell = component.proxy("ccb99ddc-d82c-4e79-9fd1-0921004880f3")
  22. local dcell = component.proxy("ea95d063-e8b1-4344-b6c1-c477547ee9da")
  23. local ecell = component.proxy("eab4e092-6d51-4304-b1ca-648a5da03e39")
  24.  
  25. local aredstone = component.proxy("baf998e6-968c-4089-b7ea-6e9c247ebfda")
  26. local bredstone = component.proxy("c7c26a9b-0f69-4fe0-a32b-de00d94467da")
  27. local credstone = component.proxy("bf1cdb44-d497-46fc-9ba5-80a3678868df")
  28. local dredstone = component.proxy("d6e88e76-bafa-44da-83ac-c6d7d45dd34b")
  29. local eredstone = component.proxy("47516274-8453-43a3-98b3-84371b276da9")
  30.  
  31. function round(val, decimal)
  32.     if (decimal) then
  33.         return math.floor((val*10^decimal)+0.5)/(10^decimal)
  34.     else
  35.         return math.floor(val+0.5)
  36.     end
  37. end
  38.  
  39. function adjustUnit(value) --Funkcja do wyzszych jednostek
  40.     if value >= 1000000000000 then
  41.         return tostring(round(value/1000000000000, 2) .. " TRF")
  42.     elseif value >= 1000000000 then
  43.         return tostring(round(value/1000000000, 2) .. " GRF")
  44.     elseif value >= 1000000 then
  45.         return tostring(round(value/1000000, 2) .. " MRF")
  46.     elseif value >= 1000 then
  47.         return tostring(round(value/1000, 2) .. " kRF")
  48.     else
  49.     return tostring(round(value) .. " RF")
  50.   end
  51. end
  52.  
  53. function hBar(x, y, size, val, maxval) --Pasek postepu (poziomy)
  54.     val = tonumber(val)
  55.     maxval = tonumber(maxval)
  56.  
  57.     if val < 0 then val = 0 end
  58.     if val > maxval then val = maxval end
  59.  
  60.     local pct = round((val/maxval)*100, 1)
  61.     local scale = 100/size
  62.     local fill = pct/scale
  63.     local spos = math.floor(fill)
  64.  
  65.     for i = 1, spos do
  66.         gpu.setBackground(kolor.czerwony) -- Kolor wypelnienia wartosci
  67.         gpu.set(x+i, y, " ")
  68.         gpu.setBackground(kolor.czarny)
  69.     end
  70.  
  71.     for i = spos + 1, size do
  72.         gpu.setBackground(kolor.szary) -- Kolor wypelnienia reszty
  73.         gpu.set(x + i, y, " ")
  74.         gpu.setBackground(kolor.czarny)
  75.     end
  76.     gpu.set(x + size + 1, y, string.rep(" ", 4 - string.len(pct)) .. string.format(pct) .. "%")
  77. end
  78.  
  79. function drawScreen() --Ramka na dane
  80.     gpu.setResolution(104, 30)
  81.     gpu.setBackground(kolor.szary)
  82.     x, y = gpu.getResolution()
  83.  
  84.     for i = 1, x do
  85.         gpu.set(i, 1, " ")
  86.     end
  87.     for i = 1, y do
  88.         gpu.set(1, i, " ")
  89.     end
  90.     for i = 1, x do
  91.         gpu.set(i, y, " ")
  92.     end
  93.     for i = 1, y do
  94.         gpu.set(x, i, " ")
  95.     end
  96.     for i = 1, y do
  97.         gpu.set(math.floor(x/3), i, " ")
  98.     end
  99.     for i = 1,y do
  100.         gpu.set(math.floor(x/1.5), i, " ")
  101.     end
  102.     for i = 1,x do
  103.         gpu.set(i, math.floor(y/2), " ")
  104.     end
  105. end
  106.  
  107. function aredstoneOn() --Wlaczanie przesylu energii
  108.     aredstone.setOutput(sides.bottom, 15)
  109. end
  110.  
  111. function bredstoneOn()
  112.     bredstone.setOutput(sides.bottom, 15)
  113. end
  114.  
  115. function credstoneOn()
  116.     credstone.setOutput(sides.bottom, 15)
  117. end
  118.  
  119. function dredstoneOn()
  120.     dredstone.setOutput(sides.bottom, 15)
  121. end
  122.  
  123. function eredstoneOn()
  124.     eredstone.setOutput(sides.bottom, 15)
  125. end
  126.  
  127. function aredstoneOff() --Wylaczanie przesylu energii
  128.     aredstone.setOutput(sides.bottom, 0)
  129. end
  130.  
  131. function bredstoneOff()
  132.     bredstone.setOutput(sides.bottom, 0)
  133. end
  134.  
  135. function credstoneOff()
  136.     credstone.setOutput(sides.bottom, 0)
  137. end
  138.  
  139. function dredstoneOff()
  140.     dredstone.setOutput(sides.bottom, 0)
  141. end
  142.  
  143. function eredstoneOff()
  144.     eredstone.setOutput(sides.bottom, 0)
  145. end
  146.  
  147. function allredstoneOn()
  148.     aredstone.setOutput(sides.bottom, 15)
  149.     bredstone.setOutput(sides.bottom, 15)
  150.     credstone.setOutput(sides.bottom, 15)
  151.     dredstone.setOutput(sides.bottom, 15)
  152.     eredstone.setOutput(sides.bottom, 15)
  153. end
  154.  
  155. function allredstoneOff()
  156.     aredstone.setOutput(sides.bottom, 0)
  157.     bredstone.setOutput(sides.bottom, 0)
  158.     credstone.setOutput(sides.bottom, 0)
  159.     dredstone.setOutput(sides.bottom, 0)
  160.     eredstone.setOutput(sides.bottom, 0)
  161. end
  162.  
  163. function setButtons() --Funkcja do wyswietlania przyciskow
  164.     API.setTable("aredstoneOn", aredstoneOn, 3, 11, 15, 13,"ON", {on = kolor.zielony, off = kolor.zielony})
  165.     API.setTable("aredstoneOff", aredstoneOff, 20, 11, 32, 13,"OFF", {on = kolor.czerwony, off = kolor.czerwony})
  166.     API.setTable("bredstoneOn", bredstoneOn, 36, 11, 49, 13,"ON", {on = kolor.zielony, off = kolor.zielony})
  167.     API.setTable("bredstoneOff", bredstoneOff, 54, 11, 67, 13,"OFF", {on = kolor.czerwony, off = kolor.czerwony})
  168.     API.setTable("credstoneOn", credstoneOn, 71, 11, 84, 13,"ON", {on = kolor.zielony, off = kolor.zielony})
  169.     API.setTable("credstoneOff", credstoneOff, 89, 11, 102, 13,"OFF", {on = kolor.czerwony, off = kolor.czerwony})
  170.     API.setTable("dredstoneOn", dredstoneOn, 3, 26, 15, 28,"ON", {on = kolor.zielony, off = kolor.zielony})
  171.     API.setTable("dredstoneOff", dredstoneOff, 20, 26, 32, 28,"OFF", {on = kolor.czerwony, off = kolor.czerwony})
  172.     API.setTable("eredstoneOn", eredstoneOn, 36, 26, 49, 28,"ON", {on = kolor.zielony, off = kolor.zielony})
  173.     API.setTable("eredstoneOff", eredstoneOff, 54, 26, 67, 28,"OFF", {on = kolor.czerwony, off = kolor.czerwony})
  174.     API.setTable("allredstoneOn", allredstoneOn, 71, 26, 84, 28,"ON", {on = kolor.zielony, off = kolor.zielony})
  175.     API.setTable("allredstoneOff", allredstoneOff, 89, 26, 102, 28,"OFF", {on = kolor.czerwony, off = kolor.czerwony})
  176. end
  177.  
  178. function drawData() --Wyƛwietlanie danych
  179.  
  180. gpu.setBackground(kolor.czarny)
  181.  
  182. local astorage = acell.getEnergyStored()
  183. local amstorage = acell.getMaxEnergyStored()
  184.  
  185. local bstorage = bcell.getEnergyStored()
  186. local bmstorage = bcell.getMaxEnergyStored()
  187.  
  188. local cstorage = ccell.getEnergyStored()
  189. local cmstorage = ccell.getMaxEnergyStored()
  190.  
  191. local dstorage = dcell.getEnergyStored()
  192. local dmstorage = dcell.getMaxEnergyStored()
  193.  
  194. local estorage = ecell.getEnergyStored()
  195. local emstorage = ecell.getMaxEnergyStored()
  196.  
  197. local sumstorage = math.floor(astorage+bstorage+cstorage+dstorage+estorage)
  198. local summstorage = math.floor(amstorage+bmstorage+cmstorage+dmstorage+emstorage)
  199.  
  200. --Tekst z danymi
  201.     gpu.set(10, 2, "BANK ENERGII #1")
  202.     gpu.set(43, 2, "BANK ENERGII #2")
  203.     gpu.set(79, 2, "BANK ENERGII #3")
  204.     gpu.set(10, 16, "BANK ENERGII #4")
  205.     gpu.set(43, 16, "BANK ENERGII #5")
  206.     gpu.set(75, 16, "WSZYSTKIE BANKI ENERGII")
  207.  
  208.     gpu.set(4, 5, "POJEMNOSC: ".. string.rep(" ", 9 - string.len(adjustUnit(astorage)))..adjustUnit(astorage))
  209.     gpu.set(37, 5, "POJEMNOSC: ".. string.rep(" ", 9 - string.len(adjustUnit(bstorage)))..adjustUnit(bstorage))
  210.     gpu.set(72, 5, "POJEMNOSC: ".. string.rep(" ", 9 - string.len(adjustUnit(cstorage)))..adjustUnit(cstorage))
  211.     gpu.set(4, 19, "POJEMNOSC: ".. string.rep(" ", 9 - string.len(adjustUnit(dstorage)))..adjustUnit(dstorage))
  212.     gpu.set(37, 19, "POJEMNOSC: ".. string.rep(" ", 9 - string.len(adjustUnit(estorage)))..adjustUnit(estorage))
  213.  
  214.     gpu.set(4, 7, "MAKS. POJEMNOSC: "..adjustUnit(amstorage))
  215.     gpu.set(37, 7, "MAKS. POJEMNOSC: "..adjustUnit(bmstorage))
  216.     gpu.set(72, 7, "MAKS. POJEMNOSC: "..adjustUnit(cmstorage))
  217.     gpu.set(4, 21, "MAKS. POJEMNOSC: "..adjustUnit(dmstorage))
  218.     gpu.set(37, 21, "MAKS. POJEMNOSC: "..adjustUnit(emstorage))
  219.  
  220.     gpu.set(72, 19, "POJEMNOSC: ".. string.rep(" ", 9 - string.len(sumstorage))..adjustUnit(sumstorage))
  221.     gpu.set(72, 21, "MAKS. POJEMNOSC: "..adjustUnit(summstorage))
  222.  
  223.     hBar(4, 9, 20, astorage, amstorage)
  224.     hBar(37, 9, 20, bstorage, bmstorage)
  225.     hBar(72, 9, 20, cstorage, cmstorage)
  226.     hBar(4, 23, 20, dstorage, dmstorage)
  227.     hBar(37, 23, 20, estorage, emstorage)
  228.  
  229.     hBar(72, 23, 20, sumstorage, summstorage)
  230. end
  231.  
  232. while true do --Petla wyswietlajaca
  233.     drawScreen()
  234.     setButtons()
  235.     API.screen()
  236.     event.listen("touch", API.checkxy)
  237.     drawData()
  238.  
  239.     local event, address, arg1, arg2, arg3 = event.pull(1) --Wyjscie z programu za pomoca "Q"
  240.     if type(address) == "string" and component.isPrimary(address) then
  241.     if event == "key_down" and arg2 == keyboard.keys.q then
  242.             term.clear()
  243.             os.exit()
  244.         end
  245.     end
  246. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top