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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user