Compare commits
3 Commits
43bfca07c6
...
40cf649c16
Author | SHA1 | Date | |
---|---|---|---|
![]() |
40cf649c16 | ||
![]() |
3a46e08f37 | ||
![]() |
9ac62319fd |
@ -4,6 +4,40 @@ local Element = require("gfx.element")
|
|||||||
|
|
||||||
local Container = Prop.attach(Element:new(), Children)
|
local Container = Prop.attach(Element:new(), Children)
|
||||||
|
|
||||||
|
function Container:getHeight()
|
||||||
|
if self:isStrict() then
|
||||||
|
return Element.getHeight(self)
|
||||||
|
end
|
||||||
|
local max = 0
|
||||||
|
for _,child in self:_iterateChildren() do
|
||||||
|
max = math.max(max, child:getY() + child:getHeight())
|
||||||
|
end
|
||||||
|
return max
|
||||||
|
end
|
||||||
|
|
||||||
|
function Container:getWidth()
|
||||||
|
if self:isStrict() then
|
||||||
|
return Element.getWidth(self)
|
||||||
|
end
|
||||||
|
local max = 0
|
||||||
|
for _,child in self:_iterateChildren() do
|
||||||
|
max = math.max(max, child:getX() + child:getWidth())
|
||||||
|
end
|
||||||
|
return max
|
||||||
|
end
|
||||||
|
|
||||||
|
function Container:isStrict()
|
||||||
|
return self.strict == true
|
||||||
|
end
|
||||||
|
|
||||||
|
function Container:setStrict(strict)
|
||||||
|
local needReload = (not not self.strict) ~= strict
|
||||||
|
self.strict = strict
|
||||||
|
if needReload then
|
||||||
|
self:_reload()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Container:_reload()
|
function Container:_reload()
|
||||||
Element._reload(self)
|
Element._reload(self)
|
||||||
|
|
||||||
|
@ -546,6 +546,21 @@ local PAGES = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local function paddedButton(label, width, height, parentHeight, parentWidth, onClick, bgColor, x, y)
|
||||||
|
local labelElement = Text:new{ text = label, bgColor = bgColor }
|
||||||
|
return Padding:new{
|
||||||
|
x = (parentWidth + (x or 1)) % parentWidth,
|
||||||
|
y = (parentHeight + (y or 1)) % parentHeight,
|
||||||
|
top = math.ceil((height - labelElement:getHeight()) / 2),
|
||||||
|
bottom = math.floor((height - labelElement:getHeight()) / 2),
|
||||||
|
left = math.ceil((width - labelElement:getWidth()) / 2),
|
||||||
|
right = math.floor((width - labelElement:getWidth()) / 2),
|
||||||
|
element = labelElement,
|
||||||
|
bgColor = bgColor,
|
||||||
|
onClick = onClick
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
local stuffContainer = List:new{
|
local stuffContainer = List:new{
|
||||||
[Orientation:getId()] = Orientation.VERTICAL,
|
[Orientation:getId()] = Orientation.VERTICAL,
|
||||||
[Children:getId()] = {
|
[Children:getId()] = {
|
||||||
@ -558,6 +573,53 @@ local PAGES = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local bottomBar = List:new{
|
||||||
|
[Orientation:getId()] = Orientation.HORIZONTAL,
|
||||||
|
[Children:getId()] = {
|
||||||
|
paddedButton(
|
||||||
|
"Fetch",
|
||||||
|
state.width / 2,
|
||||||
|
3,
|
||||||
|
state.height,
|
||||||
|
state.width,
|
||||||
|
function()
|
||||||
|
state:itemTransaction(function()
|
||||||
|
group:transferTo(state.node)
|
||||||
|
end)
|
||||||
|
state:setPage("Main")
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
colors.gray,
|
||||||
|
1,
|
||||||
|
-2
|
||||||
|
),
|
||||||
|
paddedButton(
|
||||||
|
"Back",
|
||||||
|
state.width / 2,
|
||||||
|
3,
|
||||||
|
state.height,
|
||||||
|
state.width,
|
||||||
|
function()
|
||||||
|
state:setPage("GROUP_DETAIL", group)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
colors.gray,
|
||||||
|
1,
|
||||||
|
-2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Anchored to (1,1)
|
||||||
|
local windowWrapper = Container:new{
|
||||||
|
[Children:getId()] = {
|
||||||
|
stuffContainer,
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- Set up event management
|
||||||
local function updateDisplayState()
|
local function updateDisplayState()
|
||||||
local dataRequestText = paddedRequestCount:findById("data_request")
|
local dataRequestText = paddedRequestCount:findById("data_request")
|
||||||
local dataDividerPad = paddedRequestCount:findById("data_divider")
|
local dataDividerPad = paddedRequestCount:findById("data_divider")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
local ItemStack = require("storage.itemstack")
|
local ItemStack = require("storage.itemstack")
|
||||||
|
local Sentinel = require("storage.sentinel")
|
||||||
|
|
||||||
local Chest = {}
|
local Chest = Sentinel.tag({}, Sentinel.CHEST)
|
||||||
Chest.__index = Chest
|
Chest.__index = Chest
|
||||||
|
|
||||||
-- Homogeneity allows chest scan to clone empty itemDetail slot to all empty slots in chest
|
-- Homogeneity allows chest scan to clone empty itemDetail slot to all empty slots in chest
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
local Chest = require("storage.chest")
|
local Chest = require("storage.chest")
|
||||||
local Storage = {}
|
local Sentinel = require("storage.sentinel")
|
||||||
|
|
||||||
|
local Storage = Sentinel.tag({}, Sentinel.STORAGE)
|
||||||
Storage.__index = Storage
|
Storage.__index = Storage
|
||||||
|
|
||||||
function Storage.assumeHomogeneous(names)
|
function Storage.assumeHomogeneous(names)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
local ItemGroup = {}
|
local Sentinel = require("storage.sentinel")
|
||||||
|
|
||||||
|
local ItemGroup = Sentinel.tag({}, Sentinel.ITEMGROUP)
|
||||||
ItemGroup.__index = ItemGroup
|
ItemGroup.__index = ItemGroup
|
||||||
|
|
||||||
--- Create a group of managed itemstacks
|
--- Create a group of managed itemstacks
|
||||||
@ -107,6 +109,52 @@ function ItemGroup:addStack(stack)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ItemGroup:transferTo(target, itemCount)
|
||||||
|
local targetGroup = nil
|
||||||
|
if Sentinel:is(target, Sentinel.CHEST) or Sentinel:is(target, Sentinel.STORAGE) then
|
||||||
|
local identity = self:_getIdentityStack()
|
||||||
|
local find = target:find(function(stack) return identity:canTransfer(stack) end)
|
||||||
|
if #find == 0 then
|
||||||
|
return itemCount == nil or itemCount == 0, 0
|
||||||
|
end
|
||||||
|
|
||||||
|
targetGroup = ItemGroup:from(find[1])
|
||||||
|
for i=2,#find do
|
||||||
|
targetGroup:_addStack(find[i])
|
||||||
|
end
|
||||||
|
elseif Sentinel:is(target, Sentinel.ITEMSTACK) then
|
||||||
|
targetGroup = ItemGroup:from(target)
|
||||||
|
elseif Sentinel:is(target, Sentinel.ITEMGROUP) then
|
||||||
|
targetGroup = target
|
||||||
|
end
|
||||||
|
|
||||||
|
if targetGroup == nil then
|
||||||
|
error("Unexpected transfer target for ItemGroup:transferTo")
|
||||||
|
end
|
||||||
|
|
||||||
|
local targetCap = 0
|
||||||
|
for _,stack in targetGroup:_iterateStacks() do
|
||||||
|
targetCap = targetCap + (stack:getMaxCount() - stack:getCount())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: Not efficient
|
||||||
|
local transferMax = math.min(itemCount or targetCap, targetCap, self:getItemCount())
|
||||||
|
local transfer = 0
|
||||||
|
for _,stack in targetGroup:_iterateStacks() do
|
||||||
|
local targetCount = math.min(target:getCount() + transferMax - transfer, stack:getMaxCount())
|
||||||
|
for _,from in self:_iterateStacks() do
|
||||||
|
if stack:getCount() == targetCount then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
local _, xfer = from:transferTo(stack)
|
||||||
|
transfer = transfer + xfer
|
||||||
|
end
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
|
||||||
|
return itemCount == nil or (itemCount == transfer), transfer
|
||||||
|
end
|
||||||
|
|
||||||
function ItemGroup:getItemCount()
|
function ItemGroup:getItemCount()
|
||||||
if self:_getIdentityStack():isEmpty() then
|
if self:_getIdentityStack():isEmpty() then
|
||||||
return 0
|
return 0
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
local Inventory = require("storage.inventory")
|
local Inventory = require("storage.inventory")
|
||||||
|
local Sentinel = require("storage.sentinel")
|
||||||
|
|
||||||
local ItemStack = {}
|
local ItemStack = Sentinel.tag({}, Sentinel.ITEMSTACK)
|
||||||
ItemStack.__index = ItemStack
|
ItemStack.__index = ItemStack
|
||||||
|
|
||||||
function ItemStack:fromDetail(inv, detail, slot)
|
function ItemStack:fromDetail(inv, detail, slot)
|
||||||
|
19
storage/sentinel.lua
Normal file
19
storage/sentinel.lua
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
local TABLE_KEY = "!__SENTINEL"
|
||||||
|
|
||||||
|
local Sentinel = {
|
||||||
|
CHEST = "CHEST",
|
||||||
|
ITEMSTACK = "ITEMSTACK",
|
||||||
|
ITEMGROUP = "ITEMGROUP",
|
||||||
|
STORAGE = "STORAGE"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Sentinel:tag(table, sentinel)
|
||||||
|
table[TABLE_KEY] = sentinel
|
||||||
|
return table
|
||||||
|
end
|
||||||
|
|
||||||
|
function Sentinel:is(table, sentinel)
|
||||||
|
return table[TABLE_KEY] == sentinel
|
||||||
|
end
|
||||||
|
|
||||||
|
return Sentinel
|
Loading…
x
Reference in New Issue
Block a user