feat: v1.12.1.0 — prisregel via sæsonkurven, reserve til gårdens eget forbrug, paller til palleskur, fanen Lagre (idéer fra Distribution Redux)
This commit is contained in:
@@ -9,10 +9,10 @@ SmartPickupFrame._mt = Class(SmartPickupFrame, TabbedMenuFrameElement)
|
||||
SmartPickupFrame.REFRESH_INTERVAL_MS = 1000
|
||||
SmartPickupFrame.LOG_PREFIX = "ADSmartPickup: "
|
||||
SmartPickupFrame.STATE_OFF, SmartPickupFrame.STATE_ON = 1, 2
|
||||
SmartPickupFrame.TAB_OVERVIEW, SmartPickupFrame.TAB_SUPPLY, SmartPickupFrame.TAB_OUTBOUND = 1, 2, 3
|
||||
SmartPickupFrame.TAB_NAMES = {"spu_tab_overview", "spu_tab_supply", "spu_tab_outbound"}
|
||||
-- Hver fane viser kun runs af sin egen slags; Oversigt opretter forsynings-runs.
|
||||
SmartPickupFrame.TAB_KIND = {"supply", "supply", "outbound"}
|
||||
SmartPickupFrame.TAB_OVERVIEW, SmartPickupFrame.TAB_SUPPLY, SmartPickupFrame.TAB_OUTBOUND, SmartPickupFrame.TAB_STORAGE = 1, 2, 3, 4
|
||||
SmartPickupFrame.TAB_NAMES = {"spu_tab_overview", "spu_tab_supply", "spu_tab_outbound", "spu_tab_storage"}
|
||||
-- Hver fane viser kun runs af sin egen slags; Oversigt og Lagre opretter forsynings-runs.
|
||||
SmartPickupFrame.TAB_KIND = {"supply", "supply", "outbound", "supply"}
|
||||
SmartPickupFrame.POLICIES = {"off", "store", "sell", "sellElseStore"}
|
||||
|
||||
function SmartPickupFrame.new(i18n, getAdEnv)
|
||||
@@ -296,6 +296,7 @@ function SmartPickupFrame:clearRows()
|
||||
self.needsRows = {}
|
||||
self.overviewRows = {}
|
||||
self.productRows, self.outboundStatusRows = {}, {}
|
||||
self.storageRows = {}
|
||||
end
|
||||
|
||||
function SmartPickupFrame:addRow(prefab, data)
|
||||
@@ -345,6 +346,17 @@ function SmartPickupFrame:rebuild()
|
||||
self:clearRows()
|
||||
local isOverview = self.currentTab == SmartPickupFrame.TAB_OVERVIEW
|
||||
self:setStaticRowsVisible(self.currentTab)
|
||||
if self.currentTab == SmartPickupFrame.TAB_STORAGE then
|
||||
if adEnv ~= nil then
|
||||
self:fillStorageRows(adEnv)
|
||||
end
|
||||
self.statusRow = self:addTextRow("")
|
||||
self:colorRows()
|
||||
self.boxLayout:invalidateLayout()
|
||||
self:restoreFocusIfLost()
|
||||
self:refreshLive()
|
||||
return
|
||||
end
|
||||
if isOverview then
|
||||
if adEnv ~= nil then
|
||||
self:fillOverviewRows(adEnv)
|
||||
@@ -665,6 +677,7 @@ function SmartPickupFrame:refreshLive()
|
||||
return
|
||||
end
|
||||
self:refreshOverview(adEnv)
|
||||
self:refreshStorageRows(adEnv)
|
||||
local isRunning = false
|
||||
if run ~= nil then
|
||||
self:syncOptionsFromModel(adEnv, run)
|
||||
|
||||
@@ -43,11 +43,9 @@ function SmartPickupFrame:describeProduct(adEnv, product)
|
||||
return string.format(self.i18n:getText("spu_product_row"), tostring(product.title), SmartPickupFrame.formatCompact(product.available or 0), price)
|
||||
end
|
||||
|
||||
-- Paller kan ikke lagres i en silo: kun Fra/Salg for pallevarer.
|
||||
SmartPickupFrame.PALLET_POLICIES = {"off", "sell"}
|
||||
|
||||
-- Paller lagres i et palleskur (objektlager) i stedet for en silo — samme politikker som bulk.
|
||||
function SmartPickupFrame.getPoliciesFor(product)
|
||||
return product.isPallet and SmartPickupFrame.PALLET_POLICIES or SmartPickupFrame.POLICIES
|
||||
return SmartPickupFrame.POLICIES
|
||||
end
|
||||
|
||||
function SmartPickupFrame.getPolicyIndex(policies, policy)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
-- Smart Pickup — fanen Lagre
|
||||
-- Alt gården har liggende, pr. bygning: fabrikker (outputs først), stalde, palleskure, siloer.
|
||||
-- Kun bygninger med indhold vises; teksterne opdateres hvert sekund uden genopbygning.
|
||||
-- Funktionerne lægges på SmartPickupFrame (indlæses efter SmartPickupFrame.lua).
|
||||
|
||||
-- "Sugar mill (fabrik): Sukker 150.0k/180.0k ▸ · Roer 356.8k/360.0k" (▸ = output)
|
||||
function SmartPickupFrame:describeInventory(entry)
|
||||
local parts = {}
|
||||
for _, item in ipairs(entry.entries) do
|
||||
local amount
|
||||
if item.count ~= nil then
|
||||
amount = string.format(self.i18n:getText("spu_storage_pallets"), item.count)
|
||||
else
|
||||
amount = string.format("%s/%s", SmartPickupFrame.formatCompact(item.level or 0), SmartPickupFrame.formatCompact(item.capacity or 0))
|
||||
end
|
||||
table.insert(parts, string.format("%s %s%s", tostring(item.title), amount, item.isOutput and " ▸" or ""))
|
||||
end
|
||||
local kindText = self.i18n:getText("spu_source_kind_" .. tostring(entry.kind))
|
||||
return string.format("%s (%s): %s", tostring(entry.name), kindText, table.concat(parts, " · "))
|
||||
end
|
||||
|
||||
function SmartPickupFrame:getInventory(adEnv)
|
||||
if ADSources == nil or ADSources.getFarmInventory == nil then
|
||||
return {}
|
||||
end
|
||||
return ADSources.getFarmInventory(adEnv, g_currentMission:getFarmId())
|
||||
end
|
||||
|
||||
function SmartPickupFrame:fillStorageRows(adEnv)
|
||||
self.storageRows = {}
|
||||
self:addTextRow(self.i18n:getText("spu_section_storage"))
|
||||
local inventory = self:getInventory(adEnv)
|
||||
for _, entry in ipairs(inventory) do
|
||||
table.insert(self.storageRows, {placeable = entry.placeable, title = self:addTextRow(self:describeInventory(entry))})
|
||||
end
|
||||
if #inventory == 0 then
|
||||
self:addTextRow(self.i18n:getText("spu_storage_empty"))
|
||||
end
|
||||
end
|
||||
|
||||
function SmartPickupFrame:refreshStorageRows(adEnv)
|
||||
if self.currentTab ~= SmartPickupFrame.TAB_STORAGE or #(self.storageRows or {}) == 0 then
|
||||
return
|
||||
end
|
||||
local byPlaceable = {}
|
||||
for _, entry in ipairs(self:getInventory(adEnv)) do
|
||||
byPlaceable[entry.placeable] = entry
|
||||
end
|
||||
for _, row in ipairs(self.storageRows) do
|
||||
local entry = byPlaceable[row.placeable]
|
||||
if entry ~= nil then
|
||||
row.title:setText(self:describeInventory(entry))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user