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:
@@ -81,8 +81,16 @@ function ADRunsController.deleteRun(runId)
|
||||
ADRunsController.store = ADRuns.deleteRun(ADRunsController.store, runId)
|
||||
end
|
||||
|
||||
-- Hver ændring logges, så et klik der ikke når modellen kan ses i log.txt.
|
||||
function ADRunsController.updateRun(runId, changes)
|
||||
ADRunsController.store = ADRuns.updateRun(ADRunsController.store, runId, changes)
|
||||
local run = ADRuns.getRun(ADRunsController.store, runId)
|
||||
local parts = {}
|
||||
for key, value in pairs(changes) do
|
||||
table.insert(parts, string.format("%s=%s", tostring(key), type(value) == "table" and table.concat(value, " ") or tostring(value)))
|
||||
end
|
||||
table.sort(parts)
|
||||
Logging.info(ADRunsController.LOG_PREFIX .. "run '%s': %s", run ~= nil and tostring(run.name) or tostring(runId), table.concat(parts, ", "))
|
||||
end
|
||||
|
||||
function ADRunsController.assignVehicle(runId, vehicle)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
<text name="spu_renameTitle" text="Navn på run"/>
|
||||
<text name="spu_deleteConfirm" text="Slet run '%s'? Traktorerne stoppes ikke."/>
|
||||
<text name="spu_capacity" text="%s l"/>
|
||||
<text name="spu_needs" text="Hentes (mest trængende først): %s"/>
|
||||
<text name="spu_needs_noTarget" text="(vælg et mål for at se behov)"/>
|
||||
<text name="spu_needs_none" text="Målet tager ingen af run'ets varer"/>
|
||||
<text name="spu_canCarry" text="kan bære: %s"/>
|
||||
</texts>
|
||||
</l10n>
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
<text name="spu_renameTitle" text="Run name"/>
|
||||
<text name="spu_deleteConfirm" text="Delete run '%s'? Tractors are not stopped."/>
|
||||
<text name="spu_capacity" text="%s l"/>
|
||||
<text name="spu_needs" text="To fetch (neediest first): %s"/>
|
||||
<text name="spu_needs_noTarget" text="(choose a target to see needs)"/>
|
||||
<text name="spu_needs_none" text="The target accepts none of the run's goods"/>
|
||||
<text name="spu_canCarry" text="can carry: %s"/>
|
||||
</texts>
|
||||
</l10n>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.9.3.0</version>
|
||||
<version>1.9.4.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user