feat(lagre): tabel med kolonner for bygningsstatistik + gitter for gårdens beholdning, egen tooltip; brugermanual på dansk og engelsk (v1.15.2.0)

This commit is contained in:
2026-09-24 02:11:45 +02:00
parent 31168b895a
commit a11c8e46df
12 changed files with 714 additions and 57 deletions
+25
View File
@@ -65,3 +65,28 @@ function ADStorageStats.splitTroughConsumption(perDay, levels, weights)
if best ~= nil then result[best] = perDay end
return result
end
-- Deler en liste i rækker á `size` celler (gitter i fanen Lagre). Tom liste giver én tom række,
-- så bygningen stadig får sin navnerække.
function ADStorageStats.chunk(list, size)
local rows, current = {}, {}
for _, value in ipairs(list or {}) do
table.insert(current, value)
if #current == size then
table.insert(rows, current)
current = {}
end
end
if #current > 0 or #rows == 0 then
table.insert(rows, current)
end
return rows
end
-- "-14.4k +3.6k": forbrug med minus, produktion med plus pr. døgn; intet = "-".
function ADStorageStats.rateText(consumption, production, format)
local parts = {}
if (consumption or 0) > 0 then table.insert(parts, "-" .. format(consumption)) end
if (production or 0) > 0 then table.insert(parts, "+" .. format(production)) end
return #parts > 0 and table.concat(parts, " ") or "-"
end
+1 -1
View File
@@ -56,7 +56,7 @@ end
-- Prefabs skal ud af layoutet før de klones, ellers vises de selv som rækker.
function SmartPickupFrame:initialize()
for _, name in ipairs({"ingredientPrefab", "vehiclePrefab", "textPrefab", "productPrefab"}) do
for _, name in ipairs({"ingredientPrefab", "vehiclePrefab", "textPrefab", "productPrefab", "statPrefab", "gridPrefab"}) do
local prefab = self[name]
if prefab ~= nil then
prefab:unlinkElement()
@@ -72,6 +72,23 @@
<Bitmap profile="fs25_multiTextOptionContainer" id="textPrefab">
<Text profile="spuInfoText" name="title"/>
</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"/>
</Bitmap>
<!-- Lagre: gårdens beholdning som gitter (bygning · 3 varer pr. række) -->
<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"/>
</Bitmap>
<!-- udkørsel: én række pr. vare med politik Fra/Lager/Salg/Salg, ellers lager -->
<Bitmap profile="fs25_multiTextOptionContainer" id="productPrefab">
<MultiTextOption profile="fs25_settingsMultiTextOption" onClick="onClickProduct" name="option">
@@ -3,20 +3,48 @@
-- 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", item.isOutput and "*" or "", tostring(item.title), amount))
SmartPickupFrame.GRID_CELLS = 3
-- Én celle i gitteret: "*Ensilage 1.7M/20.0M" eller "Kurve 12 paller" (* = fabrikkens output).
function SmartPickupFrame:describeInventoryItem(item)
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
return string.format("%s%s %s", item.isOutput and "*" or "", tostring(item.title), amount)
end
-- Gitterlinjer for en bygning: {{navn, celle, celle, celle}, {"", celle, ...}, ...}.
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))
return string.format("%s (%s): %s", tostring(entry.name), kindText, table.concat(parts, " · "))
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 ""}
for cell = 1, SmartPickupFrame.GRID_CELLS do line[cell + 1] = chunk[cell] or "" end
table.insert(lines, line)
end
return lines
end
-- Kloner en tabelrække og sætter cellerne c1..cN; returnerer celle-elementerne.
function SmartPickupFrame:addCellRow(prefab, texts)
local row = self:addRow(prefab, {kind = "text"})
local cells = {}
for index = 1, #texts do
cells[index] = row:getDescendantByName("c" .. index)
end
SmartPickupFrame.setCells(cells, texts)
return cells
end
function SmartPickupFrame.setCells(cells, texts)
for index, cell in ipairs(cells) do
if cell ~= nil then cell:setText(tostring(texts[index] or "")) end
end
end
function SmartPickupFrame:getInventory(adEnv)
@@ -55,27 +83,29 @@ function SmartPickupFrame:computeBuildingStats(adEnv, entry, inventory)
return stats
end
-- "Sukker — 150.0k/180.0k (83 %) · nu 240.300 kr · top 300.400 kr · gården 412.0k = 3.2 døgn · forbrug 130.0k/døgn · prod. 48.0k/døgn"
function SmartPickupFrame:describeStat(stat)
-- Tabelkolonner: vare · i bygningen · værdi nu · ved toppris · gården · rækker til · forbrug/prod. pr. døgn
function SmartPickupFrame:statHeader()
local i18n = self.i18n
local fc = SmartPickupFrame.formatCompact
local parts = {string.format("%s — %s/%s%s", self:fillTypeTitle(stat.fillType), fc(stat.level), fc(stat.capacity), stat.percent ~= nil and string.format(" (%d %%)", stat.percent) or "")}
if stat.valueNow ~= nil then
table.insert(parts, string.format(i18n:getText("spu_stat_now"), SmartPickupFrame.formatMoney(stat.valueNow)))
table.insert(parts, string.format(i18n:getText("spu_stat_top"), SmartPickupFrame.formatMoney(stat.valueTop)))
else
table.insert(parts, i18n:getText("spu_stat_noSell"))
end
local days = stat.days ~= nil and string.format(i18n:getText("spu_stat_days"), stat.days) or i18n:getText("spu_stat_noUse")
table.insert(parts, string.format(i18n:getText("spu_stat_farm"), fc(stat.farmTotal), days))
if stat.consumption > 0 then table.insert(parts, string.format(i18n:getText("spu_stat_use"), fc(stat.consumption))) end
if stat.production > 0 then table.insert(parts, string.format(i18n:getText("spu_stat_prod"), fc(stat.production))) end
return " " .. table.concat(parts, " · ")
return {i18n:getText("spu_col_item"), i18n:getText("spu_col_here"), i18n:getText("spu_col_now"), i18n:getText("spu_col_top"),
i18n:getText("spu_col_farm"), i18n:getText("spu_col_lasts"), i18n:getText("spu_col_rate")}
end
function SmartPickupFrame:describeStatTotals(stats)
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
local now, top = i18n:getText("spu_stat_noSell"), ""
if stat.valueNow ~= nil then
now, top = SmartPickupFrame.formatMoney(stat.valueNow), SmartPickupFrame.formatMoney(stat.valueTop)
end
local days = stat.days ~= nil and string.format(i18n:getText("spu_stat_days"), stat.days) or "-"
return {self:fillTypeTitle(stat.fillType), here, now, top, fc(stat.farmTotal), days, ADStorageStats.rateText(stat.consumption, stat.production, fc)}
end
function SmartPickupFrame:statTotalCells(stats)
local totals = ADStorageStats.buildingTotals(stats)
return string.format(" " .. self.i18n:getText("spu_stat_total"), SmartPickupFrame.formatMoney(totals.valueNow), SmartPickupFrame.formatMoney(totals.valueTop))
return {self.i18n:getText("spu_stat_total"), "", SmartPickupFrame.formatMoney(totals.valueNow), SmartPickupFrame.formatMoney(totals.valueTop), "", "", ""}
end
-- Navne til vælgeren; ens navne (40 Farma-siloer) får løbenummer.
@@ -102,11 +132,16 @@ function SmartPickupFrame:fillStorageDetail(adEnv, inventory)
row:getDescendantByName("title"):setText(self.i18n:getText("spu_storage_select"))
local entry = inventory[self.storageIndex]
self.storageDetailPlaceable = entry.placeable
local tooltip = option:getDescendantByName("ignore")
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)
self:addCellRow(self.statPrefab, self:statHeader())
for _, stat in ipairs(stats) do
table.insert(self.storageDetailRows, self:addTextRow(self:describeStat(stat)))
table.insert(self.storageDetailRows, self:addCellRow(self.statPrefab, self:statCells(stat)))
end
table.insert(self.storageDetailRows, self:addTextRow(self:describeStatTotals(stats)))
table.insert(self.storageDetailRows, self:addCellRow(self.statPrefab, self:statTotalCells(stats)))
end
function SmartPickupFrame:refreshStorageDetail(adEnv, inventory)
@@ -119,9 +154,9 @@ function SmartPickupFrame:refreshStorageDetail(adEnv, inventory)
end
local stats = self:computeBuildingStats(adEnv, entry, inventory)
for index, stat in ipairs(stats) do
self.storageDetailRows[index]:setText(self:describeStat(stat))
SmartPickupFrame.setCells(self.storageDetailRows[index], self:statCells(stat))
end
self.storageDetailRows[#stats + 1]:setText(self:describeStatTotals(stats))
SmartPickupFrame.setCells(self.storageDetailRows[#stats + 1], self:statTotalCells(stats))
end
function SmartPickupFrame:onClickStorageBuilding(state)
@@ -135,7 +170,11 @@ function SmartPickupFrame:fillStorageRows(adEnv)
self:fillStorageDetail(adEnv, inventory)
self:addTextRow(self.i18n:getText("spu_section_storage"))
for _, entry in ipairs(inventory) do
table.insert(self.storageRows, {placeable = entry.placeable, title = self:addTextRow(self:describeInventory(entry))})
local rows = {}
for _, line in ipairs(self:inventoryLines(entry)) do
table.insert(rows, self:addCellRow(self.gridPrefab, line))
end
table.insert(self.storageRows, {placeable = entry.placeable, rows = rows})
end
if #inventory == 0 then
self:addTextRow(self.i18n:getText("spu_storage_empty"))
@@ -154,8 +193,10 @@ function SmartPickupFrame:refreshStorageRows(adEnv)
pcall(self.refreshStorageDetail, self, adEnv, inventory)
for _, row in ipairs(self.storageRows) do
local entry = byPlaceable[row.placeable]
if entry ~= nil then
row.title:setText(self:describeInventory(entry))
local lines = entry ~= nil and self:inventoryLines(entry) or nil
-- flere/færre linjer end ved opbygningen (ny vare) vises ved næste genopbygning
if lines ~= nil and #lines == #row.rows then
for index, line in ipairs(lines) do SmartPickupFrame.setCells(row.rows[index], line) end
end
end
end
+8
View File
@@ -11,4 +11,12 @@
<textBold value="false"/>
<size value="1400px 40px"/>
</Profile>
<!-- Tabel-celler i fanen Lagre: position og bredde sættes pr. celle i SmartPickupFrame.xml. -->
<Profile name="spuCell" extends="fs25_settingsMultiTextOptionTitle">
<textBold value="false"/>
<textAlignment value="left"/>
</Profile>
<Profile name="spuCellBold" extends="spuCell">
<textBold value="true"/>
</Profile>
</GUIProfiles>
+9 -1
View File
@@ -133,6 +133,14 @@
<text name="spu_stat_farm" text="gården %s = %s"/>
<text name="spu_stat_use" text="forbrug %s/døgn"/>
<text name="spu_stat_prod" text="prod. %s/døgn"/>
<text name="spu_stat_total" text="Bygningens værdi: nu %s · ved toppris %s"/>
<text name="spu_stat_total" text="Bygningen i alt"/>
<text name="spu_col_item" text="Vare"/>
<text name="spu_col_here" text="I bygningen"/>
<text name="spu_col_now" text="Værdi nu"/>
<text name="spu_col_top" text="Ved toppris"/>
<text name="spu_col_farm" text="Gården"/>
<text name="spu_col_lasts" text="Rækker til"/>
<text name="spu_col_rate" text="Forbrug/prod. døgn"/>
<text name="spu_storage_select_tooltip" text="Vælg en bygning for at se værdi, gårdens samlede beholdning og forbrug og produktion pr. døgn for hver vare."/>
</texts>
</l10n>
+9 -1
View File
@@ -133,6 +133,14 @@
<text name="spu_stat_farm" text="farm %s = %s"/>
<text name="spu_stat_use" text="use %s/day"/>
<text name="spu_stat_prod" text="prod. %s/day"/>
<text name="spu_stat_total" text="Building value: now %s · at top price %s"/>
<text name="spu_stat_total" text="Building total"/>
<text name="spu_col_item" text="Item"/>
<text name="spu_col_here" text="In building"/>
<text name="spu_col_now" text="Value now"/>
<text name="spu_col_top" text="At top price"/>
<text name="spu_col_farm" text="Farm"/>
<text name="spu_col_lasts" text="Lasts"/>
<text name="spu_col_rate" text="Use/prod. per day"/>
<text name="spu_storage_select_tooltip" text="Pick a building to see value, the farm total and daily use and production for each item."/>
</texts>
</l10n>
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.15.1.0</version>
<version>1.15.2.0</version>
<title>
<en>AD Smart Pickup</en>
</title>