Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --https://pastebin.com/CAUxJx2T
- --https://computercraft.ru/topic/1063-zhidkostnyy-monitor/?tab=comments#comment-14635
- --https://img-fotki.yandex.ru/get/5644/209058805.0/0_13ca71_74a86267_orig.png
- local fluids = {
- Water = 0x1c86ee;
- Lava = 0xee4000;
- Milk = 0xfdf5e6;
- }
- local name
- local comp = component or require "component"
- local computer = computer or require "computer"
- local table_insert, unpack, comp_list = table.insert, table.unpack, comp.list
- name = name or "Monitor"
- local color = 0x1c86ee
- local gpu = comp.proxy(comp.list("gpu")())
- gpu.bind(comp.list("screen")())
- local width, height = gpu.getResolution()
- gpu.fill(1, 1, width, height, " ")
- local cell_w
- local function drawBox(x, y, w, h)
- gpu.fill(x+1, y, w-2, 1, "═")
- gpu.set(x, y, "╔")
- gpu.set(x+w-1, y, "╗")
- for i=1, h-2 do
- gpu.set(x, y+i, "║")
- gpu.set(x+w-1, y+i, "║")
- end
- gpu.fill(x+1, y+h-1, w-2, 1, "═")
- gpu.set(x, y+h-1, "╚")
- gpu.set(x+w-1, y+h-1, "╝")
- end
- local meta = {
- __index = {
- update = function(self, n)
- local side, tank = unpack(self)
- local x, y = cell_w*(n-1)+3, 5
- local info = tank.getFluidInTank(side)[1]
- if not info.label then return end
- local k = info.amount/info.capacity
- gpu.set(x, y-1, ("═"):rep(cell_w-2))
- local name = (info.label or "Empty"):sub(1, cell_w-2)
- gpu.set(x-1+cell_w/2-#name/2, y-1, name)
- local k2 = 1 - k
- local color = fluids[info.label] or color
- local h = height-5
- gpu.setBackground(color)
- gpu.fill(x, y+h*k2, cell_w-2, h*k+0.85, "─")
- gpu.setBackground(0x000000)
- gpu.fill(x, y, cell_w-2, h*k2, " ")
- if k ~= 1 then
- if info.amount <= (info.capacity/h)*(h/2) then
- gpu.setBackground(0x000000)
- else
- gpu.setBackground(color)
- end
- gpu.set(x+cell_w/2-#tostring(info.amount)/2-2, y+h/2-1, info.amount.." mb")
- end
- gpu.setBackground(0x000000)
- gpu.set(x, y+h, ("max "..info.capacity.." mb"):sub(1, cell_w-2))
- end;
- draw = function(self, n)
- local side, tank = unpack(self)
- local x, y = cell_w*(n-1)+2, 4
- drawBox(x, y, cell_w, height-3)
- for i=1, height-5 do
- gpu.set(x, y+i, "╟")
- gpu.set(x+cell_w-1, y+i, "╢")
- end
- self:update(n)
- end;
- };
- }
- function find()
- local tank_list = { }
- for address, name in comp_list("tank_controller") do
- local comp = comp.proxy(address)
- for i=1, 5 do
- if comp.getTankCapacity(i) then
- table_insert(tank_list, setmetatable({i, comp, #tank_list+1}, meta))
- end
- end
- end
- return tank_list
- end
- local tank_list = find()
- local s = 0
- gpu.setBackground(0x000000)
- gpu.setForeground(0xffffff)
- drawBox(math.floor(width/2-name:len()/2), 1, #name+2, 3)
- gpu.set(math.floor(width/2-name:len()/2)+1, 2, name)
- function red()
- gpu.fill(1, 4, width, height-3, " ")
- cell_w = math.floor(width/(#tank_list)-1)
- cell_w = cell_w < 15 and 15 or cell_w
- for n, tank in ipairs(tank_list) do
- tank:draw(n-s)
- if n-s > width/cell_w then break end
- end
- end
- red()
- while true do
- local e = { computer.pullSignal(0.1) }
- local list = find()
- if #list ~= #tank_list then
- tank_list = list
- red()
- end
- for n, tank in ipairs(tank_list) do
- if n-s > width/cell_w+1 then break end
- pcall(tank.update,tank,n-s)
- end
- if cell_w == 15 then
- if e[1] == "touch" then
- if e[3] > width/2 then
- s = s >= #tank_list-width/cell_w and s or s+1
- else
- s = s == 0 and 0 or s-1
- end
- red()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement