feat(lagre): faner pr. bygningstype (Fabrikker/Siloer/Stalde/Palleskure), kolonner tilpasset rækkebredden, statistik tæller kun kørende produktioner × tidsjustering (v1.16.0.0)
This commit is contained in:
@@ -10,8 +10,14 @@ SmartPickupFrame.REFRESH_INTERVAL_MS = 1000
|
||||
SmartPickupFrame.STATUS_OVERRIDE_TICKS = 6
|
||||
SmartPickupFrame.LOG_PREFIX = "ADSmartPickup: "
|
||||
SmartPickupFrame.STATE_OFF, SmartPickupFrame.STATE_ON = 1, 2
|
||||
SmartPickupFrame.TAB_FLOWS, SmartPickupFrame.TAB_STORAGE = 1, 2
|
||||
SmartPickupFrame.TAB_NAMES = {"spu_tab_flows", "spu_tab_storage"}
|
||||
SmartPickupFrame.TAB_FLOWS = 1
|
||||
-- Lagerfaner: én pr. bygningstype (indeks -> kind i ADSources.getFarmInventory)
|
||||
SmartPickupFrame.TAB_NAMES = {"spu_tab_flows", "spu_tab_factories", "spu_tab_silos", "spu_tab_barns", "spu_tab_sheds"}
|
||||
SmartPickupFrame.TAB_KINDS = {[2] = "factory", [3] = "silo", [4] = "husbandry", [5] = "objectStorage"}
|
||||
|
||||
function SmartPickupFrame.getTabKind(tab)
|
||||
return SmartPickupFrame.TAB_KINDS[tab]
|
||||
end
|
||||
SmartPickupFrame.POLICIES = {"off", "store", "sell", "sellElseStore"}
|
||||
-- Afvisningsgrunde der handler om VOGNEN (ikke run'ets opsætning): traktoren kan ikke vælges.
|
||||
SmartPickupFrame.VEHICLE_BLOCKING_REASONS = {noTrailer = true, cannotCarry = true, needsAutoload = true}
|
||||
@@ -349,7 +355,7 @@ function SmartPickupFrame:rebuild()
|
||||
self:clearRows()
|
||||
local run = self:getRun()
|
||||
self:setStaticRowsVisible(self.currentTab, run)
|
||||
if self.currentTab == SmartPickupFrame.TAB_STORAGE then
|
||||
if SmartPickupFrame.getTabKind(self.currentTab) ~= nil then
|
||||
if adEnv ~= nil then
|
||||
self:fillStorageRows(adEnv)
|
||||
end
|
||||
|
||||
@@ -74,20 +74,19 @@
|
||||
</Bitmap>
|
||||
<!-- Lagre: statistik-tabel (vare · i bygningen · værdi nu · ved toppris · gården · rækker til · forbrug/prod.) -->
|
||||
<Bitmap profile="fs25_multiTextOptionContainer" id="statPrefab">
|
||||
<Text profile="spuCellBold" name="c1" position="25px 0px" size="220px 40px"/>
|
||||
<Text profile="spuCell" name="c2" position="245px 0px" size="190px 40px"/>
|
||||
<Text profile="spuCell" name="c3" position="435px 0px" size="140px 40px"/>
|
||||
<Text profile="spuCell" name="c4" position="575px 0px" size="140px 40px"/>
|
||||
<Text profile="spuCell" name="c5" position="715px 0px" size="110px 40px"/>
|
||||
<Text profile="spuCell" name="c6" position="825px 0px" size="110px 40px"/>
|
||||
<Text profile="spuCell" name="c7" position="935px 0px" size="170px 40px"/>
|
||||
<Text profile="spuCellBold" name="c1" position="20px 0px" size="145px 40px"/>
|
||||
<Text profile="spuCell" name="c2" position="165px 0px" size="135px 40px"/>
|
||||
<Text profile="spuCell" name="c3" position="300px 0px" size="200px 40px"/>
|
||||
<Text profile="spuCell" name="c4" position="400px 0px" size="100px 40px"/>
|
||||
<Text profile="spuCell" name="c5" position="500px 0px" size="70px 40px"/>
|
||||
<Text profile="spuCell" name="c6" position="570px 0px" size="85px 40px"/>
|
||||
<Text profile="spuCell" name="c7" position="655px 0px" size="155px 40px"/>
|
||||
</Bitmap>
|
||||
<!-- Lagre: gårdens beholdning som gitter (bygning · 3 varer pr. række) -->
|
||||
<!-- Lagre: gårdens beholdning som gitter (bygning · 2 varer pr. række). Rækken er ~815 px bred. -->
|
||||
<Bitmap profile="fs25_multiTextOptionContainer" id="gridPrefab">
|
||||
<Text profile="spuCellBold" name="c1" position="25px 0px" size="300px 40px"/>
|
||||
<Text profile="spuCell" name="c2" position="330px 0px" size="255px 40px"/>
|
||||
<Text profile="spuCell" name="c3" position="585px 0px" size="255px 40px"/>
|
||||
<Text profile="spuCell" name="c4" position="840px 0px" size="255px 40px"/>
|
||||
<Text profile="spuCellBold" name="c1" position="20px 0px" size="270px 40px"/>
|
||||
<Text profile="spuCell" name="c2" position="290px 0px" size="260px 40px"/>
|
||||
<Text profile="spuCell" name="c3" position="550px 0px" size="260px 40px"/>
|
||||
</Bitmap>
|
||||
<!-- udkørsel: én række pr. vare med politik Fra/Lager/Salg/Salg, ellers lager -->
|
||||
<Bitmap profile="fs25_multiTextOptionContainer" id="productPrefab">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
-- Kun bygninger med indhold vises; teksterne opdateres hvert sekund uden genopbygning.
|
||||
-- Funktionerne lægges på SmartPickupFrame (indlæses efter SmartPickupFrame.lua).
|
||||
|
||||
SmartPickupFrame.GRID_CELLS = 3
|
||||
SmartPickupFrame.GRID_CELLS = 2
|
||||
|
||||
-- Én celle i gitteret: "*Ensilage 1.7M/20.0M" eller "Kurve 12 paller" (* = fabrikkens output).
|
||||
function SmartPickupFrame:describeInventoryItem(item)
|
||||
@@ -16,14 +16,13 @@ function SmartPickupFrame:describeInventoryItem(item)
|
||||
return string.format("%s%s %s", item.isOutput and "*" or "", tostring(item.title), amount)
|
||||
end
|
||||
|
||||
-- Gitterlinjer for en bygning: {{navn, celle, celle, celle}, {"", celle, ...}, ...}.
|
||||
-- Gitterlinjer for en bygning: {{navn, celle, celle}, {"", celle, ...}, ...} (fanen giver typen).
|
||||
function SmartPickupFrame:inventoryLines(entry)
|
||||
local cells = {}
|
||||
for _, item in ipairs(entry.entries) do table.insert(cells, self:describeInventoryItem(item)) end
|
||||
local kindText = self.i18n:getText("spu_source_kind_" .. tostring(entry.kind))
|
||||
local lines = {}
|
||||
for index, chunk in ipairs(ADStorageStats.chunk(cells, SmartPickupFrame.GRID_CELLS)) do
|
||||
local line = {index == 1 and string.format("%s (%s)", tostring(entry.name), kindText) or ""}
|
||||
local line = {index == 1 and tostring(entry.name) or ""}
|
||||
for cell = 1, SmartPickupFrame.GRID_CELLS do line[cell + 1] = chunk[cell] or "" end
|
||||
table.insert(lines, line)
|
||||
end
|
||||
@@ -94,7 +93,7 @@ function SmartPickupFrame:statCells(stat)
|
||||
local i18n = self.i18n
|
||||
local fc = SmartPickupFrame.formatCompact
|
||||
local here = string.format("%s/%s", fc(stat.level), fc(stat.capacity))
|
||||
if stat.percent ~= nil then here = here .. string.format(" %d %%", stat.percent) end
|
||||
if stat.percent ~= nil then here = here .. string.format(" %d %%", stat.percent) end
|
||||
local now, top = i18n:getText("spu_stat_noSell"), ""
|
||||
if stat.valueNow ~= nil then
|
||||
now, top = SmartPickupFrame.formatMoney(stat.valueNow), SmartPickupFrame.formatMoney(stat.valueTop)
|
||||
@@ -119,12 +118,13 @@ function SmartPickupFrame:storageLabels(inventory)
|
||||
return labels
|
||||
end
|
||||
|
||||
function SmartPickupFrame:fillStorageDetail(adEnv, inventory)
|
||||
function SmartPickupFrame:fillStorageDetail(adEnv, inventory, fullInventory)
|
||||
self.storageDetailRows = {}
|
||||
if #inventory == 0 then
|
||||
return
|
||||
end
|
||||
self.storageIndex = math.max(1, math.min(self.storageIndex or 1, #inventory))
|
||||
self.storageIndexByTab = self.storageIndexByTab or {}
|
||||
self.storageIndex = math.max(1, math.min(self.storageIndexByTab[self.currentTab] or 1, #inventory))
|
||||
local row = self:addRow(self.productPrefab, {kind = "storageBuilding"})
|
||||
local option = row:getDescendantByName("option")
|
||||
option:setTexts(self:storageLabels(inventory))
|
||||
@@ -136,7 +136,7 @@ function SmartPickupFrame:fillStorageDetail(adEnv, inventory)
|
||||
local tooltipText = self.i18n:getText("spu_storage_select_tooltip")
|
||||
if tooltip ~= nil then tooltip:setText(tooltipText) end
|
||||
option.toolTipText = tooltipText
|
||||
local stats = self:computeBuildingStats(adEnv, entry, inventory)
|
||||
local stats = self:computeBuildingStats(adEnv, entry, fullInventory)
|
||||
self:addCellRow(self.statPrefab, self:statHeader())
|
||||
for _, stat in ipairs(stats) do
|
||||
table.insert(self.storageDetailRows, self:addCellRow(self.statPrefab, self:statCells(stat)))
|
||||
@@ -144,7 +144,7 @@ function SmartPickupFrame:fillStorageDetail(adEnv, inventory)
|
||||
table.insert(self.storageDetailRows, self:addCellRow(self.statPrefab, self:statTotalCells(stats)))
|
||||
end
|
||||
|
||||
function SmartPickupFrame:refreshStorageDetail(adEnv, inventory)
|
||||
function SmartPickupFrame:refreshStorageDetail(adEnv, inventory, fullInventory)
|
||||
local entry = nil
|
||||
for _, candidate in ipairs(inventory) do
|
||||
if candidate.placeable == self.storageDetailPlaceable then entry = candidate end
|
||||
@@ -152,7 +152,7 @@ function SmartPickupFrame:refreshStorageDetail(adEnv, inventory)
|
||||
if entry == nil or #(self.storageDetailRows or {}) ~= #entry.entries + 1 then
|
||||
return
|
||||
end
|
||||
local stats = self:computeBuildingStats(adEnv, entry, inventory)
|
||||
local stats = self:computeBuildingStats(adEnv, entry, fullInventory)
|
||||
for index, stat in ipairs(stats) do
|
||||
SmartPickupFrame.setCells(self.storageDetailRows[index], self:statCells(stat))
|
||||
end
|
||||
@@ -160,15 +160,17 @@ function SmartPickupFrame:refreshStorageDetail(adEnv, inventory)
|
||||
end
|
||||
|
||||
function SmartPickupFrame:onClickStorageBuilding(state)
|
||||
self.storageIndex = state
|
||||
self.storageIndexByTab = self.storageIndexByTab or {}
|
||||
self.storageIndexByTab[self.currentTab] = state
|
||||
self:requestRebuild()
|
||||
end
|
||||
|
||||
function SmartPickupFrame:fillStorageRows(adEnv)
|
||||
self.storageRows = {}
|
||||
local inventory = self:getInventory(adEnv)
|
||||
self:fillStorageDetail(adEnv, inventory)
|
||||
self:addTextRow(self.i18n:getText("spu_section_storage"))
|
||||
local fullInventory = self:getInventory(adEnv)
|
||||
local inventory = ADStorageStats.filterKind(fullInventory, SmartPickupFrame.getTabKind(self.currentTab))
|
||||
self:fillStorageDetail(adEnv, inventory, fullInventory)
|
||||
self:addTextRow(self.i18n:getText("spu_section_storage_" .. tostring(SmartPickupFrame.getTabKind(self.currentTab))))
|
||||
for _, entry in ipairs(inventory) do
|
||||
local rows = {}
|
||||
for _, line in ipairs(self:inventoryLines(entry)) do
|
||||
@@ -182,15 +184,17 @@ function SmartPickupFrame:fillStorageRows(adEnv)
|
||||
end
|
||||
|
||||
function SmartPickupFrame:refreshStorageRows(adEnv)
|
||||
if self.currentTab ~= SmartPickupFrame.TAB_STORAGE or #(self.storageRows or {}) == 0 then
|
||||
local kind = SmartPickupFrame.getTabKind(self.currentTab)
|
||||
if kind == nil or #(self.storageRows or {}) == 0 then
|
||||
return
|
||||
end
|
||||
local inventory = self:getInventory(adEnv)
|
||||
local fullInventory = self:getInventory(adEnv)
|
||||
local inventory = ADStorageStats.filterKind(fullInventory, kind)
|
||||
local byPlaceable = {}
|
||||
for _, entry in ipairs(inventory) do
|
||||
byPlaceable[entry.placeable] = entry
|
||||
end
|
||||
pcall(self.refreshStorageDetail, self, adEnv, inventory)
|
||||
pcall(self.refreshStorageDetail, self, adEnv, inventory, fullInventory)
|
||||
for _, row in ipairs(self.storageRows) do
|
||||
local entry = byPlaceable[row.placeable]
|
||||
local lines = entry ~= nil and self:inventoryLines(entry) or nil
|
||||
|
||||
Reference in New Issue
Block a user