feat(oversigt): Start/Stop alle flows + klik på flow hopper til redigering; palleskure viser paller af pladser (v1.20.0.0)
- ADRunsController.startAllRuns/stopAllRuns/hasActiveRuns (kørende flows røres ikke ved Start alle) - Oversigt: knapsæt Start alle / Stop alle / Nyt run, samlet status, klikbare rækker (hop via update) - Palleskur-statistik: kapacitet = (egne + ledige pladser) x indhold; 24/4000 paller 1 % i stedet for 600 % - Manualer da/en opdateret
This commit is contained in:
@@ -64,15 +64,45 @@ function SmartPickupFrame:flowCells(adEnv, run)
|
||||
return {name, products, from, to, string.format("%d/%d", row.running, row.total), status}
|
||||
end
|
||||
|
||||
-- Fanen Oversigt: alle flows som tabel, grupperet Ind/Ud efter navn.
|
||||
-- Hele rækken klikbar med musen (Bitmap-rækker har ingen onClick). Klikket gemmes kun som
|
||||
-- pendingJumpRunId; hoppet sker i update(), fordi genopbygningen sletter netop denne række.
|
||||
local MOUSE_LEFT = Input ~= nil and Input.MOUSE_BUTTON_LEFT or 1
|
||||
|
||||
local function isInside(element, posX, posY)
|
||||
local position, size = element.absPosition, element.absSize
|
||||
if position == nil or size == nil then return false end
|
||||
return posX >= position[1] and posX <= position[1] + size[1] and posY >= position[2] and posY <= position[2] + size[2]
|
||||
end
|
||||
|
||||
function SmartPickupFrame:makeRowClickable(row, runId)
|
||||
local frame = self
|
||||
local baseMouseEvent = row.mouseEvent
|
||||
row.mouseEvent = function(element, posX, posY, isDown, isUp, button, eventUsed)
|
||||
local used = baseMouseEvent(element, posX, posY, isDown, isUp, button, eventUsed)
|
||||
-- også inden for listens synlige udsnit: rækker scrollet ud af syne må ikke fange klik
|
||||
if not used and not eventUsed and isUp and button == MOUSE_LEFT and (element.getIsVisible == nil or element:getIsVisible())
|
||||
and isInside(element, posX, posY) and isInside(frame.boxLayout, posX, posY) then
|
||||
frame.pendingJumpRunId = runId
|
||||
return true
|
||||
end
|
||||
return used
|
||||
end
|
||||
end
|
||||
|
||||
-- Fanen Oversigt: alle flows som tabel, grupperet Ind/Ud efter navn. Klik på et flow = redigér det.
|
||||
function SmartPickupFrame:fillOverviewRows(adEnv)
|
||||
self.overviewRows = {}
|
||||
local i18n = self.i18n
|
||||
self:addTextRow(i18n:getText("spu_overview_hint"))
|
||||
self:addCellRow(self.flowPrefab, {i18n:getText("spu_col_flow"), i18n:getText("spu_col_goods"), i18n:getText("spu_col_from"), i18n:getText("spu_col_to"), i18n:getText("spu_col_tractors"), i18n:getText("spu_col_status")})
|
||||
for _, group in ipairs(ADFlowView.boardGroups(ADRunsController.store.runs)) do
|
||||
self:addTextRow(i18n:getText(group.kind == "outbound" and "spu_board_outbound" or "spu_board_supply"))
|
||||
for _, run in ipairs(group.runs) do
|
||||
table.insert(self.overviewRows, {runId = run.id, cells = self:addCellRow(self.flowPrefab, self:flowCells(adEnv, run))})
|
||||
local cells = self:addCellRow(self.flowPrefab, self:flowCells(adEnv, run))
|
||||
if cells[1] ~= nil and cells[1].parent ~= nil then
|
||||
self:makeRowClickable(cells[1].parent, run.id)
|
||||
end
|
||||
table.insert(self.overviewRows, {runId = run.id, cells = cells})
|
||||
end
|
||||
end
|
||||
if #ADRunsController.store.runs == 0 then
|
||||
|
||||
@@ -8,6 +8,7 @@ SmartPickupFrame._mt = Class(SmartPickupFrame, TabbedMenuFrameElement)
|
||||
|
||||
SmartPickupFrame.REFRESH_INTERVAL_MS = 1000
|
||||
SmartPickupFrame.STATUS_OVERRIDE_TICKS = 6
|
||||
SmartPickupFrame.MAX_STATUS_REASONS = 3
|
||||
SmartPickupFrame.LOG_PREFIX = "ADSmartPickup: "
|
||||
SmartPickupFrame.STATE_OFF, SmartPickupFrame.STATE_ON = 1, 2
|
||||
SmartPickupFrame.TAB_OVERVIEW, SmartPickupFrame.TAB_FLOWS = 1, 2
|
||||
@@ -45,8 +46,13 @@ function SmartPickupFrame.new(i18n, getAdEnv)
|
||||
self.newButtonInfo = {inputAction = InputAction.MENU_EXTRA_1, text = i18n:getText("spu_button_new"), callback = function() self:onClickNew() end}
|
||||
self.renameButtonInfo = {inputAction = InputAction.MENU_EXTRA_2, text = i18n:getText("spu_button_rename"), callback = function() self:onClickRename() end}
|
||||
self.deleteButtonInfo = {inputAction = InputAction.MENU_CANCEL, text = i18n:getText("spu_button_delete"), callback = function() self:onClickDelete() end}
|
||||
-- Oversigt: Start/Stop alle i stedet for knapperne der virker på ét valgt flow.
|
||||
self.startAllButtonInfo = {inputAction = InputAction.MENU_ACTIVATE, text = i18n:getText("spu_button_startAll"), callback = function() self:onClickStartAll() end}
|
||||
self.stopAllButtonInfo = {inputAction = InputAction.MENU_EXTRA_2, text = i18n:getText("spu_button_stopAll"), callback = function() self:onClickStopAll() end}
|
||||
self.flowButtons = {self.backButtonInfo, self.startButtonInfo, self.newButtonInfo, self.renameButtonInfo, self.deleteButtonInfo}
|
||||
self.overviewButtons = {self.backButtonInfo, self.startAllButtonInfo, self.stopAllButtonInfo, self.newButtonInfo}
|
||||
-- Egen reference til listen: fallback'en i refreshButtons skal kunne sende den igen.
|
||||
self.menuButtonInfo = {self.backButtonInfo, self.startButtonInfo, self.newButtonInfo, self.renameButtonInfo, self.deleteButtonInfo}
|
||||
self.menuButtonInfo = self.overviewButtons
|
||||
self:setMenuButtonInfo(self.menuButtonInfo)
|
||||
return self
|
||||
end
|
||||
@@ -195,7 +201,11 @@ end
|
||||
-- dets egen klik-håndtering, hopper værdien frem og tilbage og fokus ryger.
|
||||
function SmartPickupFrame:update(dt)
|
||||
SmartPickupFrame:superClass().update(self, dt)
|
||||
if self.pendingRebuild then
|
||||
if self.pendingJumpRunId ~= nil then
|
||||
local runId = self.pendingJumpRunId
|
||||
self.pendingJumpRunId = nil
|
||||
self:safe(function(frame) frame:openFlow(runId) end)
|
||||
elseif self.pendingRebuild then
|
||||
self.pendingRebuild = false
|
||||
self:safe(self.rebuild)
|
||||
end
|
||||
@@ -632,6 +642,11 @@ end
|
||||
-- setMenuButtonInfoDirty findes i FS22/25's TabbedMenuFrameElement; mangler den,
|
||||
-- sendes listen igen. Kaldes hvert sekund, så den må aldrig kaste.
|
||||
function SmartPickupFrame:refreshButtons()
|
||||
local wanted = self.currentTab == SmartPickupFrame.TAB_OVERVIEW and self.overviewButtons or self.flowButtons
|
||||
if self.menuButtonInfo ~= wanted then
|
||||
self.menuButtonInfo = wanted
|
||||
self:setMenuButtonInfo(wanted)
|
||||
end
|
||||
if self.setMenuButtonInfoDirty ~= nil then
|
||||
self:setMenuButtonInfoDirty()
|
||||
else
|
||||
@@ -647,12 +662,22 @@ function SmartPickupFrame:refreshLive()
|
||||
self:setStatusText(self.i18n:getText("spu_status_noAd"))
|
||||
return
|
||||
end
|
||||
if self.currentTab == SmartPickupFrame.TAB_OVERVIEW then
|
||||
local isOverview = self.currentTab == SmartPickupFrame.TAB_OVERVIEW
|
||||
if isOverview then
|
||||
self:refreshOverview(adEnv)
|
||||
end
|
||||
self:refreshStorageRows(adEnv)
|
||||
local isRunning = false
|
||||
if run ~= nil then
|
||||
if isOverview then
|
||||
local running, total, activeRuns = 0, 0, 0
|
||||
for _, anyRun in ipairs(ADRunsController.store.runs) do
|
||||
local status = ADRunsController.getRunStatus(adEnv, anyRun)
|
||||
running, total = running + status.running, total + status.total
|
||||
if status.running > 0 then activeRuns = activeRuns + 1 end
|
||||
end
|
||||
self:setStatusText(self.statusOverride or string.format(self.i18n:getText("spu_status_overview"), running, total, activeRuns, #ADRunsController.store.runs))
|
||||
self.stopAllButtonInfo.disabled = running == 0
|
||||
elseif run ~= nil then
|
||||
self:syncOptionsFromModel(adEnv, run)
|
||||
if run.kind == "outbound" then
|
||||
self:refreshOutboundRows(adEnv, run)
|
||||
@@ -766,30 +791,80 @@ function SmartPickupFrame:onClickStartStop()
|
||||
ADRunsController.stopRun(adEnv, run.id)
|
||||
frame.statusOverride = nil
|
||||
else
|
||||
local started, skipped, reasons = 0, 0, {}
|
||||
for _, result in ipairs(ADRunsController.startRun(adEnv, run.id)) do
|
||||
if result.ok then
|
||||
started = started + 1
|
||||
else
|
||||
skipped = skipped + 1
|
||||
local reasonText = frame.i18n:getText("spu_reason_" .. tostring(result.reason))
|
||||
if result.reason == "noMarker" and result.missingBuilding ~= nil then
|
||||
reasonText = string.format(reasonText, tostring(result.missingBuilding))
|
||||
end
|
||||
table.insert(reasons, string.format("%s: %s", tostring(ADRuns.vehicleLabel(result.vehicle)), reasonText))
|
||||
end
|
||||
end
|
||||
frame.statusOverride = string.format(frame.i18n:getText("spu_status_started"), started, skipped)
|
||||
if #reasons > 0 then
|
||||
frame.statusOverride = frame.statusOverride .. " — " .. table.concat(reasons, "; ")
|
||||
end
|
||||
frame.statusOverrideTicks = SmartPickupFrame.STATUS_OVERRIDE_TICKS
|
||||
local started, skipped, reasons = frame:summarizeStartResults(ADRunsController.startRun(adEnv, run.id))
|
||||
frame:showOverride(string.format(frame.i18n:getText("spu_status_started"), started, skipped), reasons)
|
||||
end
|
||||
ADRunsController.save()
|
||||
frame:requestRebuild()
|
||||
end)
|
||||
end
|
||||
|
||||
-- Start-resultater -> antal startet/sprunget over + "Traktor: grund"-liste til statuslinjen.
|
||||
function SmartPickupFrame:summarizeStartResults(results)
|
||||
local started, skipped, reasons = 0, 0, {}
|
||||
for _, result in ipairs(results) do
|
||||
if result.ok then
|
||||
started = started + 1
|
||||
else
|
||||
skipped = skipped + 1
|
||||
local reasonText = self.i18n:getText("spu_reason_" .. tostring(result.reason))
|
||||
if result.reason == "noMarker" and result.missingBuilding ~= nil then
|
||||
reasonText = string.format(reasonText, tostring(result.missingBuilding))
|
||||
end
|
||||
table.insert(reasons, string.format("%s: %s", tostring(ADRuns.vehicleLabel(result.vehicle)), reasonText))
|
||||
end
|
||||
end
|
||||
return started, skipped, reasons
|
||||
end
|
||||
|
||||
function SmartPickupFrame:showOverride(text, reasons)
|
||||
if reasons ~= nil and #reasons > 0 then
|
||||
-- én statuslinje: højst MAX_STATUS_REASONS grunde, resten står i log.txt
|
||||
local shown = {}
|
||||
for index = 1, math.min(#reasons, SmartPickupFrame.MAX_STATUS_REASONS) do shown[index] = reasons[index] end
|
||||
text = text .. " — " .. table.concat(shown, "; ")
|
||||
if #reasons > #shown then text = text .. string.format(" (+%d)", #reasons - #shown) end
|
||||
end
|
||||
self.statusOverride = text
|
||||
self.statusOverrideTicks = SmartPickupFrame.STATUS_OVERRIDE_TICKS
|
||||
self:setStatusText(text)
|
||||
end
|
||||
|
||||
function SmartPickupFrame:onClickStartAll()
|
||||
self:safe(function(frame)
|
||||
local adEnv = frame.getAdEnv()
|
||||
if adEnv == nil then return end
|
||||
local summary = ADRunsController.startAllRuns(adEnv)
|
||||
local _, skipped, reasons = frame:summarizeStartResults(summary.results)
|
||||
Logging.info(SmartPickupFrame.LOG_PREFIX .. "Start alle: %d flows startet (%d traktorer), %d kørte allerede, %d sprunget over",
|
||||
summary.runsStarted, summary.vehiclesStarted, summary.alreadyRunning, skipped)
|
||||
frame:showOverride(string.format(frame.i18n:getText("spu_status_startedAll"), summary.runsStarted, summary.vehiclesStarted, summary.alreadyRunning, skipped), reasons)
|
||||
ADRunsController.save()
|
||||
frame:requestRebuild()
|
||||
end)
|
||||
end
|
||||
|
||||
function SmartPickupFrame:onClickStopAll()
|
||||
self:safe(function(frame)
|
||||
local adEnv = frame.getAdEnv()
|
||||
if adEnv == nil then return end
|
||||
local stopped = ADRunsController.stopAllRuns(adEnv)
|
||||
Logging.info(SmartPickupFrame.LOG_PREFIX .. "Stop alle: %d traktorer stoppet", stopped)
|
||||
frame:showOverride(string.format(frame.i18n:getText("spu_status_stoppedAll"), stopped))
|
||||
ADRunsController.save()
|
||||
frame:requestRebuild()
|
||||
end)
|
||||
end
|
||||
|
||||
-- Klik på en række i Oversigt: vælg flowet og hop til fanen Flows (kaldes fra update, aldrig inde i
|
||||
-- rækkens eget mouseEvent — rækken slettes af genopbygningen).
|
||||
function SmartPickupFrame:openFlow(runId)
|
||||
if ADRuns.getRun(ADRunsController.store, runId) == nil then return end
|
||||
self.selectedRunId = runId
|
||||
self.statusOverride = nil
|
||||
self:switchTab(SmartPickupFrame.TAB_FLOWS)
|
||||
end
|
||||
|
||||
-- Nyt run: navnet vælges FØR run'et oprettes (annulleres dialogen, oprettes intet).
|
||||
-- Forslaget tæller efter antal runs, ikke efter løbenummeret, så "Run 2" kan genbruges.
|
||||
function SmartPickupFrame:onClickNew()
|
||||
|
||||
@@ -93,6 +93,9 @@ 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.count ~= nil and stat.slots ~= nil then
|
||||
here = string.format(i18n:getText("spu_stat_pallets"), stat.count, stat.slots)
|
||||
end
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user