fix(kæde): pausede kæder kan genoptages, træet folder ud og teksten passer i cellerne

This commit is contained in:
2026-09-30 14:07:37 +02:00
parent f0b8df8ae3
commit b77bda5334
5 changed files with 263 additions and 109 deletions
+43 -17
View File
@@ -26,21 +26,46 @@ function SmartPickupFrame:chainTitle(last, name)
return title or self:fruitTitle(name)
end
-- Klik på en kæde-knap: udfør, evaluér straks (ny visning) og genopbyg.
-- Klik på en kæde-knap: udfør, evaluér straks (ny visning) og genopbyg. Et forslag der ikke længere findes
-- (approve/dismiss -> false) meldes i statuslinjen som i "Kræver handling".
function SmartPickupFrame:onChainAction(action)
local ok = true
if action.kind == "approve" then
ADChain.approve(action.fieldId)
ok = ADChain.approve(action.fieldId)
elseif action.kind == "dismiss" then
ADChain.dismiss(action.fieldId)
ok = ADChain.dismiss(action.fieldId)
elseif action.kind == "pause" or action.kind == "resume" then
ADChain.setPaused(action.rootKey, action.kind == "pause")
end
if ok == false then
local text = self.i18n:getText("spu_chain_gone")
self.statusOverride, self.statusOverrideTicks = text, SmartPickupFrame.STATUS_OVERRIDE_TICKS
if ADFieldJobs ~= nil and ADFieldJobs.notify ~= nil then ADFieldJobs.notify(text, false) end
end
local adEnv = self.getAdEnv()
if adEnv ~= nil then self:chainLast(adEnv, true) end
self:requestRebuild()
end
-- Række med prik + c1..c5 (flowListPrefab); knappen er c5 (klik i c5 = handling, som Flows-listen).
-- Klik på rodens linje uden for knappen: fold ud/sammen (huskes kun mens spillet kører).
function SmartPickupFrame:toggleChainRoot(rootKey)
self.chainExpanded = self.chainExpanded or {}
self.chainExpanded[rootKey] = not self.chainExpanded[rootKey] or nil
self:requestRebuild()
end
-- Hvilken celle blev der klikket i? Højeste celle hvis venstre kant ligger til venstre for klikket.
local function clickedCell(frame, cells)
if frame.lastClickX == nil then return nil end
for index = #cells, 1, -1 do
local cell = cells[index]
if cell ~= nil and cell.absPosition ~= nil and frame.lastClickX >= cell.absPosition[1] then return index end
end
return nil
end
-- Række med prik + c1..c5 (flowListPrefab). Knapper er celler (entry.actions[celle], som [Start]/[Stop] i
-- Flows-listen); et klik andetsteds på en rodlinje folder den ud/sammen.
function SmartPickupFrame:addChainRow(entry)
local unpackFn = table.unpack or unpack
local row = self:addRow(self.flowListPrefab, {kind = "chainRow"})
@@ -48,21 +73,22 @@ function SmartPickupFrame:addChainRow(entry)
for index = 1, 5 do cells[index] = row:getDescendantByName("c" .. index) end
SmartPickupFrame.setCells(cells, entry.cells)
local dot = row:getDescendantByName("dot")
local color = ADFlowView.LEVEL_COLORS[entry.level or "running"]
if dot ~= nil and dot.setImageColor ~= nil and color ~= nil then
dot:setImageColor(nil, unpackFn(color))
-- rækker uden egen status (forslag/afvis/auto) får ingen prik — kun rod og noder har status
if entry.kind ~= "root" and entry.kind ~= "node" and dot.setVisible ~= nil then dot:setVisible(false) end
end
if cells[4] ~= nil and cells[4].setTextColor ~= nil and color ~= nil and entry.level ~= "running" then
local color = entry.level ~= nil and ADFlowView.LEVEL_COLORS[entry.level] or nil
if dot ~= nil and dot.setImageColor ~= nil and color ~= nil then dot:setImageColor(nil, unpackFn(color)) end
-- kun rod og varer har en status-prik (overskrift, forslag og auto-skift har ingen)
if dot ~= nil and dot.setVisible ~= nil and entry.kind ~= "root" and entry.kind ~= "node" then dot:setVisible(false) end
if cells[4] ~= nil and cells[4].setTextColor ~= nil and color ~= nil and entry.level ~= "running" and entry.kind ~= "suggest" then
cells[4]:setTextColor(unpackFn(color))
end
if entry.action ~= nil then
local action, actionCell = entry.action, cells[5]
local actions, toggle = entry.actions or {}, entry.toggle
if next(actions) ~= nil or toggle ~= nil then
self:makeRowClickable(row, function(frame)
local onButton = frame.lastClickX == nil or actionCell == nil or actionCell.absPosition == nil
or frame.lastClickX >= actionCell.absPosition[1]
if onButton then frame:onChainAction(action) end
local action = actions[clickedCell(frame, cells) or 0]
if action ~= nil then
frame:onChainAction(action)
elseif toggle ~= nil then
frame:toggleChainRoot(toggle)
end
end)
end
return row
@@ -72,7 +98,7 @@ function SmartPickupFrame:fillChainRows(adEnv)
local i18n = self.i18n
local last = self:chainLast(adEnv, false)
local rows = ADChainView.rows(last, function(name) return self:chainTitle(last, name) end,
SmartPickupFrame.formatCompact, function(key) return i18n:getText(key) end)
SmartPickupFrame.formatCompact, function(key) return i18n:getText(key) end, self.chainExpanded or {})
for _, entry in ipairs(rows) do
if entry.kind == "info" or entry.kind == "empty" then
self:addTextRow(entry.text)
@@ -473,6 +473,7 @@ function SmartPickupFrame:rebuild()
if adEnv ~= nil then
self:fillChainRows(adEnv)
end
self.statusRow = self:addTextRow(self.statusOverride or "")
self.monthRebuildTicks = SmartPickupFrame.CHAIN_REBUILD_TICKS
self:colorRows()
self.boxLayout:invalidateLayout()
@@ -653,6 +654,12 @@ function SmartPickupFrame:refreshLive()
end
if self.currentTab == SmartPickupFrame.TAB_MONTH or self.currentTab == SmartPickupFrame.TAB_FIELDSILOS
or self.currentTab == SmartPickupFrame.TAB_CHAINS then
if self.currentTab == SmartPickupFrame.TAB_CHAINS then
-- "forslaget gælder ikke længere" står STATUS_OVERRIDE_TICKS sekunder
self.statusOverrideTicks = (self.statusOverrideTicks or 0) - 1
if self.statusOverrideTicks <= 0 then self.statusOverride = nil end
self:setStatusText(self.statusOverride or "")
end
self.monthRebuildTicks = (self.monthRebuildTicks or 0) - 1
if self.monthRebuildTicks <= 0 then self:requestRebuild() end
self:refreshButtons()