feat: Smart Pickup-fane — behovsrække (hvad hentes, målets niveauer), felter synkes fra modellen, run-ændringer logges (v1.9.4.0)
This commit is contained in:
@@ -22,6 +22,7 @@ function SmartPickupFrame.new(i18n, getAdEnv)
|
||||
self.refreshTimer = 0
|
||||
self.statusOverride = nil
|
||||
self.statusRow = nil -- Text-elementet i den klonede statusrække
|
||||
self.needsRow = nil
|
||||
self.pendingRebuild = false
|
||||
self.frameOpen = false
|
||||
self.focusLost = false
|
||||
@@ -174,6 +175,7 @@ function SmartPickupFrame:clearRows()
|
||||
end
|
||||
self.clonedRows, self.rowData = {}, {}
|
||||
self.statusRow = nil
|
||||
self.needsRow = nil
|
||||
end
|
||||
|
||||
function SmartPickupFrame:addRow(prefab, data)
|
||||
@@ -229,6 +231,7 @@ function SmartPickupFrame:rebuild()
|
||||
self:fillTargetOption(adEnv, run)
|
||||
self.ingredientModeOption:setState(run.ingredientMode == "manual" and SmartPickupFrame.STATE_ON or SmartPickupFrame.STATE_OFF, false)
|
||||
self:fillIngredientRows(adEnv, run)
|
||||
self.needsRow = self:addTextRow(self:describeNeeds(adEnv, run))
|
||||
self:fillWaitPoolOption(adEnv, run)
|
||||
self.loopsOption:setState(run.loops + 1, false)
|
||||
self:addTextRow(self.i18n:getText("spu_vehicles"))
|
||||
@@ -362,6 +365,68 @@ function SmartPickupFrame:describeCarriable(adEnv, run, vehicle, carriable)
|
||||
return string.format(self.i18n:getText("spu_canCarry"), table.concat(titles, ", "))
|
||||
end
|
||||
|
||||
-- Felterne følger modellen: når et klik ikke er nået ind i run'et, springer feltet tilbage,
|
||||
-- og loggen ("run '…': waitPoolGroup=…") viser om klikket blev registreret.
|
||||
function SmartPickupFrame:syncOptionsFromModel(adEnv, run)
|
||||
local function sync(option, wantedIndex)
|
||||
if option ~= nil and wantedIndex ~= nil and SmartPickupFrame.getOptionState(option) ~= wantedIndex then
|
||||
option:setState(wantedIndex, false)
|
||||
end
|
||||
end
|
||||
local targetIndex = 1
|
||||
for index, id in ipairs(self.targetIds) do
|
||||
if id == run.targetWayPointId then targetIndex = index end
|
||||
end
|
||||
sync(self.targetOption, targetIndex)
|
||||
sync(self.ingredientModeOption, run.ingredientMode == "manual" and SmartPickupFrame.STATE_ON or SmartPickupFrame.STATE_OFF)
|
||||
local poolIndex = 1
|
||||
for index, group in ipairs(self.poolGroups) do
|
||||
if group == run.waitPoolGroup then poolIndex = index end
|
||||
end
|
||||
sync(self.waitPoolOption, poolIndex)
|
||||
sync(self.loopsOption, run.loops + 1)
|
||||
end
|
||||
|
||||
-- "Hentes (mest trængende først): Forage 0/33.750 l · Silage 0/33.750 l · Straw 21.375/21.375 l"
|
||||
function SmartPickupFrame:describeNeeds(adEnv, run)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local target = run.targetWayPointId ~= nil and ADSmartPickup.getUnloadStationAtWayPointId(adEnv, run.targetWayPointId, farmId) or nil
|
||||
if target == nil then
|
||||
return self.i18n:getText("spu_needs_noTarget")
|
||||
end
|
||||
local fillTypes = {}
|
||||
if run.ingredientMode == "manual" then
|
||||
for _, name in ipairs(run.ingredients) do
|
||||
local index = g_fillTypeManager:getFillTypeIndexByName(name)
|
||||
if index ~= nil then table.insert(fillTypes, index) end
|
||||
end
|
||||
else
|
||||
for _, fillType in ipairs(ADRunsController.getTargetAcceptedFillTypes(adEnv, run)) do
|
||||
table.insert(fillTypes, fillType.index)
|
||||
end
|
||||
end
|
||||
local needs = {}
|
||||
for _, fillType in ipairs(fillTypes) do
|
||||
local level, capacity = ADSmartPickup.getStationLevelAndCapacity(target, fillType, farmId)
|
||||
if level ~= nil then
|
||||
table.insert(needs, {fillType = fillType, level = level, capacity = capacity, free = capacity - level})
|
||||
end
|
||||
end
|
||||
table.sort(needs, function(a, b)
|
||||
if a.free ~= b.free then return a.free > b.free end
|
||||
return a.fillType < b.fillType
|
||||
end)
|
||||
local parts = {}
|
||||
for _, need in ipairs(needs) do
|
||||
local title = g_fillTypeManager.getFillTypeTitleByIndex ~= nil and g_fillTypeManager:getFillTypeTitleByIndex(need.fillType) or g_fillTypeManager:getFillTypeNameByIndex(need.fillType)
|
||||
table.insert(parts, string.format("%s %s/%s l", tostring(title), g_i18n:formatNumber(need.level, 0), g_i18n:formatNumber(need.capacity, 0)))
|
||||
end
|
||||
if #parts == 0 then
|
||||
return self.i18n:getText("spu_needs_none")
|
||||
end
|
||||
return string.format(self.i18n:getText("spu_needs"), table.concat(parts, " · "))
|
||||
end
|
||||
|
||||
function SmartPickupFrame:fillPoolRows(adEnv)
|
||||
if adEnv == nil then
|
||||
return
|
||||
@@ -405,6 +470,10 @@ function SmartPickupFrame:refreshLive()
|
||||
end
|
||||
local isRunning = false
|
||||
if run ~= nil then
|
||||
self:syncOptionsFromModel(adEnv, run)
|
||||
if self.needsRow ~= nil then
|
||||
self.needsRow:setText(self:describeNeeds(adEnv, run))
|
||||
end
|
||||
local status = ADRunsController.getRunStatus(adEnv, run)
|
||||
isRunning = status.running > 0
|
||||
local text = isRunning and string.format(self.i18n:getText("spu_status_running"), status.running, status.total)
|
||||
|
||||
Reference in New Issue
Block a user