feat(fields): Fields-fanen som farvet liste med Start/Stop pr. række; klik åbner redigeringsvinduet
This commit is contained in:
@@ -104,13 +104,14 @@ function SmartPickupFrame:fieldCells(row)
|
||||
for _, assignment in ipairs(ADFieldJobs.assignmentsFor(info.id)) do
|
||||
table.insert(names, ADRuns.vehicleLabel(assignment.vehicle))
|
||||
end
|
||||
local name = string.format("%s%sF%d", info.id == self.selectedFieldId and "> " or "", info.markerId == nil and "! " or "", info.id)
|
||||
local name = string.format("%sF%d", info.markerId == nil and "! " or "", info.id)
|
||||
local crop = ADFieldView.cropText(info, function(key) return self.i18n:getText(key) end)
|
||||
return {
|
||||
name, crop, self:fieldPlanText(field, info),
|
||||
self.i18n:getText(field.plan.mode == "auto" and "spu_field_mode_auto" or "spu_field_mode_manual"),
|
||||
self:fieldStatusText(field, info, true),
|
||||
ADFlowView.joinCounted(names, ", ", "-"),
|
||||
self:fieldActionText(info.id),
|
||||
}
|
||||
end
|
||||
|
||||
@@ -133,32 +134,68 @@ function SmartPickupFrame:fillFieldRows(adEnv)
|
||||
if ADFieldJobs.state.fleetMode == "ticked" and next(ADFieldJobs.state.fleet or {}) == nil then
|
||||
self:addTextRow(i18n:getText("spu_field_fleetEmpty"))
|
||||
end
|
||||
self:addCellRow(self.fieldPrefab, {i18n:getText("spu_col_field"), i18n:getText("spu_col_crop"), i18n:getText("spu_col_plan"), i18n:getText("spu_col_mode"), i18n:getText("spu_col_status"), i18n:getText("spu_col_tractors")})
|
||||
self:addCellRow(self.fieldListPrefab, {i18n:getText("spu_col_field"), i18n:getText("spu_col_crop"), i18n:getText("spu_col_plan"), i18n:getText("spu_col_mode"), i18n:getText("spu_col_status"), i18n:getText("spu_col_tractors"), ""})
|
||||
for _, row in ipairs(ADFieldView.rows(infos, ADFieldJobs.state.fields)) do
|
||||
local cells = self:addCellRow(self.fieldPrefab, self:fieldCells(row))
|
||||
local cells = self:addCellRow(self.fieldListPrefab, self:fieldCells(row))
|
||||
local fieldId = row.info.id
|
||||
if cells[1] ~= nil and cells[1].parent ~= nil then
|
||||
local actionCell = cells[7]
|
||||
self:makeRowClickable(cells[1].parent, function(frame)
|
||||
frame.selectedFieldId = fieldId
|
||||
frame:requestRebuild()
|
||||
-- klik på [Start]/[Stop]-feltet = handling (kun denne mark); ellers åbn redigeringsvinduet
|
||||
if frame.lastClickX ~= nil and actionCell ~= nil and actionCell.absPosition ~= nil and frame.lastClickX >= actionCell.absPosition[1] then
|
||||
frame:toggleField(fieldId)
|
||||
else
|
||||
frame.selectedFieldId = fieldId
|
||||
frame:openEditPanel("field", fieldId)
|
||||
end
|
||||
end)
|
||||
end
|
||||
table.insert(self.fieldRows, {id = fieldId, cells = cells})
|
||||
end
|
||||
end
|
||||
local selected = self.selectedFieldId ~= nil and ADFields.getInfo(self.selectedFieldId) or nil
|
||||
if selected ~= nil then
|
||||
self:fillFieldOverview(adEnv, selected)
|
||||
self:refreshFieldLevels()
|
||||
end
|
||||
|
||||
-- Prik og statusfarve pr. mark i listen.
|
||||
function SmartPickupFrame:refreshFieldLevels()
|
||||
local unpackFn = table.unpack or unpack
|
||||
for _, entry in ipairs(self.fieldRows or {}) do
|
||||
local color = ADFlowView.LEVEL_COLORS[self:fieldLevel(entry.id)]
|
||||
local row = entry.cells[1] ~= nil and entry.cells[1].parent or nil
|
||||
local dot = row ~= nil and row:getDescendantByName("dot") or nil
|
||||
if dot ~= nil and dot.setImageColor ~= nil then dot:setImageColor(nil, unpackFn(color)) end
|
||||
if entry.cells[5] ~= nil and entry.cells[5].setTextColor ~= nil then entry.cells[5]:setTextColor(unpackFn(color)) end
|
||||
end
|
||||
end
|
||||
|
||||
function SmartPickupFrame:fieldLevel(id)
|
||||
local field, info = ADFieldJobs.getField(id), ADFields.getInfo(id)
|
||||
if field == nil or info == nil then return "stopped" end
|
||||
local reason = type(field.reason) == "table" and field.reason.key or nil
|
||||
return ADFieldView.fieldStatus({hasMarker = info.markerId ~= nil, working = ADFieldModel.isWorking(field),
|
||||
awaiting = ADFieldJobs.awaitingPlayer(id) ~= nil,
|
||||
startRequested = ADFieldJobs.isStartRequested ~= nil and ADFieldJobs.isStartRequested(id) or false,
|
||||
reasonKey = reason})
|
||||
end
|
||||
|
||||
-- forButton: knaplinjens tekst (Start/Stop) i stedet for listens [Start]/[Stop].
|
||||
function SmartPickupFrame:fieldActionText(id, forButton)
|
||||
local field = ADFieldJobs.getField(id)
|
||||
if ADFieldJobs.awaitingPlayer(id) ~= nil then return self.i18n:getText("spu_field_button_takeover") end
|
||||
local isWorking = field ~= nil and ADFieldModel.isWorking(field)
|
||||
if forButton then return self.i18n:getText(isWorking and "spu_field_button_stop" or "spu_field_button_start") end
|
||||
return self.i18n:getText(isWorking and "spu_flowList_stop" or "spu_flowList_start")
|
||||
end
|
||||
|
||||
-- Den valgte marks resumé: én klikbar linje pr. emne ([Ret] åbner kun det trin), hele status, markør og
|
||||
-- advarsel om marksilo der ikke tømmes hjem.
|
||||
function SmartPickupFrame:fillFieldOverview(adEnv, info)
|
||||
local i18n = self.i18n
|
||||
local field = ADFieldJobs.getField(info.id)
|
||||
local crop = ADFieldView.cropText(info, function(key) return i18n:getText(key) end)
|
||||
self:addTextRow(string.format(i18n:getText("spu_field_section"), info.id, crop))
|
||||
if not self.editPanelOpen then
|
||||
self:addTextRow(string.format(i18n:getText("spu_field_section"), info.id, crop))
|
||||
end
|
||||
self:addTextRow(" " .. i18n:getText("spu_guide_sum_hint"))
|
||||
local context = self:fieldGuideContext(adEnv, info, field.plan, field.plan.storeBuildingIds)
|
||||
local guide = ADFieldGuide.open(field, context)
|
||||
@@ -283,7 +320,7 @@ end
|
||||
-- ---- live ----
|
||||
|
||||
function SmartPickupFrame:refreshFieldRows(adEnv)
|
||||
if self:hasGuideOn(SmartPickupFrame.TAB_FIELDS) or self.fieldView == "fleet" then
|
||||
if (not self.editPanelOpen and self:hasGuideOn(SmartPickupFrame.TAB_FIELDS)) or self.fieldView == "fleet" then
|
||||
self:setStatusText(self.statusOverride or "")
|
||||
return
|
||||
end
|
||||
@@ -298,6 +335,7 @@ function SmartPickupFrame:refreshFieldRows(adEnv)
|
||||
if ADFieldModel.isWorking(row.field) then working = working + 1 end
|
||||
end
|
||||
end
|
||||
self:refreshFieldLevels()
|
||||
self:setStatusText(self.statusOverride or string.format(self.i18n:getText("spu_field_status"), working, total))
|
||||
local selected = self.selectedFieldId ~= nil and ADFieldJobs.getField(self.selectedFieldId) or nil
|
||||
local info = self.selectedFieldId ~= nil and ADFields.getInfo(self.selectedFieldId) or nil
|
||||
@@ -327,8 +365,12 @@ end
|
||||
|
||||
-- Start nu: pleje hvis marken trænger (og vokser), ellers hele kæden (høst/slå, eller klargøring på bar mark).
|
||||
function SmartPickupFrame:onClickFieldStartStop()
|
||||
self:toggleField(self.selectedFieldId)
|
||||
end
|
||||
|
||||
-- Start/Stop/Overtag for én mark (rækkens felt, vinduets knap og knaplinjen).
|
||||
function SmartPickupFrame:toggleField(id)
|
||||
self:safe(function(frame)
|
||||
local id = frame.selectedFieldId
|
||||
if id == nil then return end
|
||||
local field = ADFieldJobs.getField(id)
|
||||
if ADFieldJobs.awaitingPlayer(id) ~= nil then
|
||||
@@ -350,3 +392,24 @@ function SmartPickupFrame:onClickFieldStartStop()
|
||||
frame:requestRebuild()
|
||||
end)
|
||||
end
|
||||
|
||||
-- Redigeringsvinduet for en mark (gui/SmartPickupEditPanel.lua).
|
||||
SmartPickupFrame.EDIT_PANEL_KINDS = SmartPickupFrame.EDIT_PANEL_KINDS or {}
|
||||
SmartPickupFrame.EDIT_PANEL_KINDS.field = {
|
||||
canDelete = false,
|
||||
exists = function(frame, id) return ADFields.getInfo(id) ~= nil and ADFieldJobs.getField(id) ~= nil end,
|
||||
title = function(frame, id) return string.format(frame.i18n:getText("spu_panel_fieldTitle"), id) end,
|
||||
fill = function(frame, adEnv, id)
|
||||
frame:fillFieldOverview(adEnv, ADFields.getInfo(id))
|
||||
frame:addLinkRow(" " .. frame.i18n:getText("spu_guide_field_open"), function(f)
|
||||
f.selectedFieldId = id
|
||||
f:onClickFieldSetup()
|
||||
end)
|
||||
end,
|
||||
status = function(frame, adEnv, id)
|
||||
return {text = frame:fieldStatusText(ADFieldJobs.getField(id), ADFields.getInfo(id), true), level = frame:fieldLevel(id)}
|
||||
end,
|
||||
startStopText = function(frame, adEnv, id) return frame:fieldActionText(id, true) end,
|
||||
startStop = function(frame, id) frame:toggleField(id) end,
|
||||
delete = function() end,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user