feat(gui): redigeringsvindue (overlay) med Luk/ESC, Start/Stop, Slet

This commit is contained in:
2026-09-29 17:42:35 +02:00
parent 0cfb983506
commit f068c910c7
8 changed files with 189 additions and 3 deletions
+1
View File
@@ -31,6 +31,7 @@ if ADSmartPickup.dir ~= nil and source ~= nil then
source(ADSmartPickup.dir .. "gui/SmartPickupGuide.lua")
source(ADSmartPickup.dir .. "gui/SmartPickupFieldGuide.lua")
source(ADSmartPickup.dir .. "gui/SmartPickupFlowGuide.lua")
source(ADSmartPickup.dir .. "gui/SmartPickupEditPanel.lua")
end
-- Markøren er dér hvor trækkerens næse stopper; læssetriggeren ligger et
@@ -0,0 +1,149 @@
-- Smart Pickup — redigeringsvindue (v1.58)
-- Klik på en række i Flows/Fields åbner et panel oven på listen. Indholdet tegnes af den eksisterende
-- resumé-/guide-kode i vinduets egen ScrollingLayout (SmartPickupFrame:withRowTarget). Knapper i bunden via
-- menuButtonInfo: Luk (MENU_BACK = ESC), Start/Stop, Slet. Hver art registrerer sig i EDIT_PANEL_KINDS[kind] =
-- {title, exists, fill, status, startStop, startStopText, canDelete, delete} (se Flows-/Fields-fanen).
-- Funktionerne lægges på SmartPickupFrame (indlæses efter SmartPickupFrame.lua).
SmartPickupFrame.EDIT_PANEL_KINDS = SmartPickupFrame.EDIT_PANEL_KINDS or {}
SmartPickupFrame.EDIT_PANEL_WIDTH, SmartPickupFrame.EDIT_PANEL_HEIGHT = 0.80, 0.90 -- andel af listens flade
SmartPickupFrame.EDIT_PANEL_HEADER_PX = 80
function SmartPickupFrame:initEditPanelButtons(i18n)
self.panelCloseButtonInfo = {inputAction = InputAction.MENU_BACK, text = i18n:getText("spu_panel_close"), callback = function() self:onClickPanelClose() end}
self.panelStartButtonInfo = {inputAction = InputAction.MENU_ACTIVATE, text = i18n:getText("spu_button_start"), callback = function() self:onClickPanelStartStop() end}
self.panelDeleteButtonInfo = {inputAction = InputAction.MENU_CANCEL, text = i18n:getText("spu_button_delete"), callback = function() self:onClickPanelDelete() end}
self.panelButtons = {self.panelCloseButtonInfo, self.panelStartButtonInfo, self.panelDeleteButtonInfo}
self.panelGuideButtonCache = setmetatable({}, {__mode = "k"})
end
function SmartPickupFrame:editPanelHooks()
return self.editPanelOpen and SmartPickupFrame.EDIT_PANEL_KINDS[self.editPanelKind] or nil
end
-- Guidens knapper i vinduet: Tilbage (ESC) lukker trinnet/vinduet i stedet for hele menuen.
function SmartPickupFrame:panelGuideButtons()
local source = self:getGuideButtons()
local cached = self.panelGuideButtonCache[source]
if cached == nil then
cached = {}
for index, info in ipairs(source) do
cached[index] = info == self.backButtonInfo and self.panelCloseButtonInfo or info
end
self.panelGuideButtonCache[source] = cached
end
return cached
end
-- Vinduet dækker listens flade; panelet er centreret i den (absolutte koordinater, y opad).
function SmartPickupFrame:layoutEditPanel()
local box = self.boxLayout
if box == nil or box.absPosition == nil or box.absSize == nil then return end
local x, y, w, h = box.absPosition[1], box.absPosition[2], box.absSize[1], box.absSize[2]
self.editBackdrop:setAbsolutePosition(x, y)
self.editBackdrop:setSize(w, h)
local pw, ph = w * SmartPickupFrame.EDIT_PANEL_WIDTH, h * SmartPickupFrame.EDIT_PANEL_HEIGHT
local px, py = x + (w - pw) / 2, y + (h - ph) / 2
self.editPanel:setAbsolutePosition(px, py)
self.editPanel:setSize(pw, ph)
local header = SmartPickupFrame.EDIT_PANEL_HEADER_PX * g_pixelSizeScaledY
local margin = 20 * g_pixelSizeScaledX
self.editTitle:setAbsolutePosition(px + margin, py + ph - header * 0.45)
self.editStatus:setAbsolutePosition(px + margin, py + ph - header * 0.85)
self.editLayout:setAbsolutePosition(px, py)
self.editLayout:setSize(pw, ph - header)
end
function SmartPickupFrame:openEditPanel(kind, id)
if SmartPickupFrame.EDIT_PANEL_KINDS[kind] == nil or self.editOverlay == nil then return end
self.editPanelOpen, self.editPanelKind, self.editPanelId = true, kind, id
self:closeGuide()
self.editOverlay:setVisible(true)
self:layoutEditPanel()
self:requestRebuild()
end
-- Lukker uden genopbygning (fanebyt, lukket menu, slettet post).
function SmartPickupFrame:hideEditPanel()
self.editPanelOpen, self.editPanelKind, self.editPanelId = false, nil, nil
self:clearPanelRows()
if self.editOverlay ~= nil then self.editOverlay:setVisible(false) end
end
function SmartPickupFrame:closeEditPanel()
if not self.editPanelOpen then return end
self:closeGuide()
self:hideEditPanel()
self:requestRebuild()
end
-- Kaldes fra rebuild (efter listen): vinduets rækker genopbygges i editLayout.
function SmartPickupFrame:fillEditPanel(adEnv)
self:clearPanelRows()
local hooks = self:editPanelHooks()
if hooks == nil then return end
if not hooks.exists(self, self.editPanelId) then
self.statusOverride = self.i18n:getText("spu_panel_gone")
self.statusOverrideTicks = SmartPickupFrame.STATUS_OVERRIDE_TICKS
self:closeGuide()
self:hideEditPanel()
return
end
self:layoutEditPanel()
self.editTitle:setText(hooks.title(self, self.editPanelId))
self:withRowTarget(self.editLayout, function(frame)
if frame.guide ~= nil then
frame:fillGuideRows(adEnv)
else
hooks.fill(frame, adEnv, frame.editPanelId)
end
end)
self:colorLayout(self.editLayout)
self.editLayout:invalidateLayout()
self:refreshEditPanel(adEnv)
end
-- Hvert sekund: status i niveaufarve + knaptekster.
function SmartPickupFrame:refreshEditPanel(adEnv)
local hooks = self:editPanelHooks()
if hooks == nil or adEnv == nil then return end
if not hooks.exists(self, self.editPanelId) then
self:closeEditPanel()
return
end
local status = hooks.status(self, adEnv, self.editPanelId)
self.editStatus:setText(tostring(status.text or ""))
local color = ADFlowView.LEVEL_COLORS[status.level] or ADFlowView.LEVEL_COLORS.stopped
if self.editStatus.setTextColor ~= nil then
self.editStatus:setTextColor(color[1], color[2], color[3], color[4])
end
self.panelStartButtonInfo.text = hooks.startStopText(self, adEnv, self.editPanelId)
self.panelDeleteButtonInfo.disabled = not hooks.canDelete
end
function SmartPickupFrame:onClickPanelClose()
self:safe(function(frame)
-- et åbent [Edit]-trin lukkes først (kladden kasseres som ved Annullér)
if frame.guide ~= nil then
frame:closeGuide()
frame:requestRebuild()
return
end
frame:closeEditPanel()
end)
end
function SmartPickupFrame:onClickPanelStartStop()
self:safe(function(frame)
local hooks = frame:editPanelHooks()
if hooks ~= nil then hooks.startStop(frame, frame.editPanelId) end
frame:requestRebuild()
end)
end
function SmartPickupFrame:onClickPanelDelete()
self:safe(function(frame)
local hooks = frame:editPanelHooks()
if hooks ~= nil and hooks.canDelete then hooks.delete(frame, frame.editPanelId) end
end)
end
@@ -118,7 +118,7 @@ end
function SmartPickupFrame:fillFieldRows(adEnv)
self.fieldRows = {}
if self:hasGuideOn(SmartPickupFrame.TAB_FIELDS) and self:fillGuideRows(adEnv) then return end
if not self.editPanelOpen and self:hasGuideOn(SmartPickupFrame.TAB_FIELDS) and self:fillGuideRows(adEnv) then return end
if self.fieldView == "fleet" then
self:fillFleetRows(adEnv)
return
+13 -2
View File
@@ -68,6 +68,7 @@ function SmartPickupFrame.new(i18n, getAdEnv)
self:initGuideButtons(i18n)
-- Flows: [Start/Stop] [Opsæt flow] [Nyt flow] [Slet] (gui/SmartPickupFlowGuide.lua)
self:initFlowButtons(i18n)
self:initEditPanelButtons(i18n)
-- Egen reference til listen: fallback'en i refreshButtons skal kunne sende den igen.
self.menuButtonInfo = self.overviewButtons
self:setMenuButtonInfo(self.menuButtonInfo)
@@ -211,7 +212,8 @@ end
function SmartPickupFrame:onFrameClose()
self.frameOpen = false
-- en åben guide kasseres (intet er gemt før [Gem])
-- et åbent redigeringsvindue og en åben guide kasseres (intet er gemt før [Gem])
self:hideEditPanel()
self:closeGuide()
SmartPickupFrame:superClass().onFrameClose(self)
end
@@ -259,6 +261,10 @@ function SmartPickupFrame:requestRebuild()
end
function SmartPickupFrame:switchTab(tabIndex)
if self.editPanelOpen then
self:closeGuide()
self:hideEditPanel()
end
if self.guide ~= nil and not self:hasGuideOn(tabIndex) then self:closeGuide() end
self.currentTab = tabIndex
for index, tab in ipairs(self.subCategoryTabs) do
@@ -440,6 +446,7 @@ function SmartPickupFrame:rebuild()
self.statusRow = self:addTextRow("")
self:colorRows()
self.boxLayout:invalidateLayout()
if self.editPanelOpen then self:fillEditPanel(adEnv) end
self:refreshLive()
self:restoreFocusIfLost()
return
@@ -485,6 +492,7 @@ function SmartPickupFrame:rebuild()
self.statusRow = self:addTextRow("")
self:colorRows()
self.boxLayout:invalidateLayout()
if self.editPanelOpen then self:fillEditPanel(adEnv) end
self:refreshLive()
self:restoreFocusIfLost()
end
@@ -591,7 +599,9 @@ end
-- sendes listen igen. Kaldes hvert sekund, så den må aldrig kaste.
function SmartPickupFrame:refreshButtons()
local wanted = self.flowButtons
if self:hasGuideOn(self.currentTab) then
if self.editPanelOpen then
wanted = self.guide ~= nil and self:panelGuideButtons() or self.panelButtons
elseif self:hasGuideOn(self.currentTab) then
wanted = self:getGuideButtons()
elseif self.currentTab == SmartPickupFrame.TAB_OVERVIEW then
wanted = self.overviewButtons
@@ -632,6 +642,7 @@ function SmartPickupFrame:refreshLive()
if isOverview then
self:refreshOverview(adEnv)
end
if self.editPanelOpen then self:refreshEditPanel(adEnv) end
if self.currentTab == SmartPickupFrame.TAB_FIELDS then
self:refreshFieldRows(adEnv)
self.statusOverrideTicks = (self.statusOverrideTicks or 0) - 1
@@ -57,6 +57,14 @@
<Text profile="fs25_settingsMultiTextOptionTitle" text="$l10n_spu_storeAbove"/>
</Bitmap>
</ScrollingLayout>
<!-- redigeringsvindue (v1.58): skjult; placering/størrelse sættes i gui/SmartPickupEditPanel.lua -->
<GuiElement profile="baseReference" id="editOverlay" visible="false">
<Bitmap profile="spuOverlayBackdrop" id="editBackdrop"/>
<Bitmap profile="spuOverlayPanel" id="editPanel"/>
<Text profile="spuPanelTitle" id="editTitle"/>
<Text profile="spuCell" id="editStatus" size="700px 30px" textMaxWidth="690px"/>
<ScrollingLayout profile="fs25_settingsLayout" id="editLayout"/>
</GuiElement>
<!-- prefabs: klones pr. vare / traktor / tekstlinje og fjernes fra layoutet ved initialize -->
<Bitmap profile="fs25_multiTextOptionContainer" id="ingredientPrefab">
+13
View File
@@ -53,4 +53,17 @@
<Profile name="spuCellDim" extends="spuCell">
<textColor value="0.75 0.75 0.75 1"/>
</Profile>
<!-- redigeringsvindue (v1.58): mørk flade + panel; størrelser/placering sættes i Lua ud fra boxLayout -->
<Profile name="spuOverlayBackdrop" extends="spuBar">
<imageColor value="0 0 0 0.65"/>
<size value="100px 100px"/>
</Profile>
<Profile name="spuOverlayPanel" extends="spuBar">
<imageColor value="0.09 0.09 0.09 0.97"/>
<size value="100px 100px"/>
</Profile>
<Profile name="spuPanelTitle" extends="spuCellBold">
<textSize value="20px"/>
<size value="700px 30px"/>
</Profile>
</GUIProfiles>
+2
View File
@@ -252,6 +252,8 @@
<text name="spu_flow_pickOther" text="Vælg et andet flow (tavlen med alle flows står i Oversigt)"/>
<text name="spu_button_rename" text="Omdøb"/>
<text name="spu_button_delete" text="Slet flow"/>
<text name="spu_panel_close" text="Luk"/>
<text name="spu_panel_gone" text="Posten findes ikke længere — vinduet er lukket"/>
<text name="spu_newRunName" text="Flow %d"/>
<text name="spu_renameTitle" text="Navn på flow"/>
<text name="spu_deleteConfirm" text="Slet run '%s'? Dets kørende traktorer stoppes. Kan ikke fortrydes."/>
+2
View File
@@ -252,6 +252,8 @@
<text name="spu_flow_pickOther" text="Pick another flow (the board with all flows is in Overview)"/>
<text name="spu_button_rename" text="Rename"/>
<text name="spu_button_delete" text="Delete flow"/>
<text name="spu_panel_close" text="Close"/>
<text name="spu_panel_gone" text="That item no longer exists — window closed"/>
<text name="spu_newRunName" text="Flow %d"/>
<text name="spu_renameTitle" text="Flow name"/>
<text name="spu_deleteConfirm" text="Delete run '%s'? Its running tractors will be stopped. This cannot be undone."/>