diff --git a/Task.lua b/Task.lua
index f7c0fc1..95e0cfd 100644
--- a/Task.lua
+++ b/Task.lua
@@ -214,6 +214,9 @@ function Task:readStream(streamId, connection)
self.shouldRecur = streamReadBool(streamId)
self.recurMode = streamReadInt32(streamId)
self.nextN = streamReadInt32(streamId)
+ if self.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS and self.nextN ~= 0 then
+ self.nextN = TaskListUtils.normalizePeriod(self.nextN)
+ end
self.n = streamReadInt32(streamId)
self.effort = streamReadInt32(streamId)
self.type = streamReadInt32(streamId)
@@ -265,6 +268,9 @@ function Task:loadFromXMLFile(xmlFile, key)
self.shouldRecur = getXMLBool(xmlFile, key .. "#shouldRecur")
self.nextN = getXMLInt(xmlFile, key .. "#nextN")
self.n = getXMLInt(xmlFile, key .. "#n")
+ if self.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS and self.nextN ~= 0 then
+ self.nextN = TaskListUtils.normalizePeriod(self.nextN)
+ end
self.effort = getXMLInt(xmlFile, key .. "#effort") or 1
self.type = getXMLInt(xmlFile, key .. "#type") or Task.TASK_TYPE.Standard
self.husbandryFood = getXMLString(xmlFile, key .. "#husbandryFood") or ""
diff --git a/TaskListUtils.lua b/TaskListUtils.lua
index 767b931..d4918c7 100644
--- a/TaskListUtils.lua
+++ b/TaskListUtils.lua
@@ -32,6 +32,21 @@ function TaskListUtils.convertPeriodToMonthNumber(period)
return period
end
+--- Folds a game period or month slot into 1..12 (e.g. after adding N-month intervals, including N > 12).
+function TaskListUtils.normalizePeriod(period)
+ if period == nil then
+ return 1
+ end
+ local p = math.floor(tonumber(period) or 1)
+ while p > 12 do
+ p = p - 12
+ end
+ while p < 1 do
+ p = p + 12
+ end
+ return p
+end
+
function TaskListUtils.formatPeriodFullMonthName(period)
if period == 1 then
return g_i18n:getText("ui_month3")
diff --git a/gui/EditTaskFrame.lua b/gui/EditTaskFrame.lua
new file mode 100644
index 0000000..549e3be
--- /dev/null
+++ b/gui/EditTaskFrame.lua
@@ -0,0 +1,950 @@
+EditTaskFrame = {}
+EditTaskFrame._params = nil
+
+--- Row height in form layout (matches editTaskFormRow profile).
+local EDIT_TASK_ROW_H = 52
+
+local function trimWhitespace(str)
+ return string.gsub(str or "", '^%s*(.-)%s*$', '%1')
+end
+
+--- Match TextInputElement / savegame limits (UTF-8 aware when engine helpers exist).
+local function limitTaskDetailLength(str, maxLen)
+ str = trimWhitespace(str)
+ if str == "" then
+ return ""
+ end
+ if type(utf8Strlen) == "function" and type(utf8Substr) == "function" then
+ if utf8Strlen(str) > maxLen then
+ return utf8Substr(str, 0, maxLen)
+ end
+ return str
+ end
+ if string.len(str) > maxLen then
+ return string.sub(str, 1, maxLen)
+ end
+ return str
+end
+
+local EditTaskFrame_mt = Class(EditTaskFrame, MessageDialog)
+
+--- @param elem GuiElement|nil
+local function editTaskRowVisible(elem)
+ if elem == nil then
+ return false
+ end
+ if elem.getIsVisible ~= nil then
+ return elem:getIsVisible()
+ end
+ return elem.isVisible ~= false
+end
+
+--- @param elem GuiElement|nil
+--- @param y number Y offset in pixels (negative stacks downward in this dialog)
+local function editTaskSetRowY(elem, y)
+ if elem == nil or elem.setPosition == nil then
+ return
+ end
+ elem:setPosition("0px", string.format("%dpx", y))
+end
+
+function EditTaskFrame:_optionCallbacksSuppressed()
+ return (self._optionCallbackSuppressDepth or 0) > 0
+end
+
+--- Batch MultiTextOption setState/setTexts without treating engine-spurious onClick as user input.
+function EditTaskFrame:withSuppressedOptionCallbacks(fn)
+ self._optionCallbackSuppressDepth = (self._optionCallbackSuppressDepth or 0) + 1
+ fn()
+ self._optionCallbackSuppressDepth = math.max(0, (self._optionCallbackSuppressDepth or 1) - 1)
+end
+
+function EditTaskFrame.new(target, custom_mt)
+ local self = MessageDialog.new(target, custom_mt or EditTaskFrame_mt)
+ self.i18n = g_i18n
+ return self
+end
+
+function EditTaskFrame.open(groupId, group, task, isEdit)
+ local working = task
+ if isEdit then
+ working = Task.new()
+ working:copyValuesFromTask(task, true)
+ end
+ EditTaskFrame._params = {
+ groupId = groupId,
+ group = group,
+ task = working,
+ isEdit = isEdit
+ }
+ g_gui:showDialog("editTaskFrame")
+end
+
+function EditTaskFrame:onCreate()
+ EditTaskFrame:superClass().onCreate(self)
+end
+
+function EditTaskFrame:onGuiSetupFinished()
+ EditTaskFrame:superClass().onGuiSetupFinished(self)
+ self._standardRows = {
+ self.standardDetailRow,
+ self.standardEffortRow,
+ self.standardPriorityRow,
+ self.standardRecurToggleRow,
+ self.recurModeRow,
+ self.recurNRow,
+ self.startPeriodRow,
+ self.periodRow
+ }
+ self._foodRows = { self.foodTypeRow, self.foodLevelRow }
+ self._conditionRows = { self.conditionTypeRow, self.conditionEvalRow, self.conditionLevelRow }
+ self._productionRows = {
+ self.productionPickRow,
+ self.productionIoRow,
+ self.productionFillRow,
+ self.productionEvalRow,
+ self.productionLevelRow
+ }
+end
+
+--- Stack visible rows inside a section; returns next Y cursor (negative) inside that section.
+function EditTaskFrame:layoutRowStack(rows, startY)
+ local y = startY
+ for _, row in ipairs(rows) do
+ if editTaskRowVisible(row) then
+ editTaskSetRowY(row, y)
+ y = y - EDIT_TASK_ROW_H
+ end
+ end
+ return y
+end
+
+--- Position a block and stack its rows; returns next Y cursor relative to the same parent as the block.
+function EditTaskFrame:layoutBlockAtY(block, innerRows, yCursor)
+ if not editTaskRowVisible(block) then
+ return yCursor
+ end
+ editTaskSetRowY(block, yCursor)
+ local inner = 0
+ for _, row in ipairs(innerRows) do
+ if editTaskRowVisible(row) then
+ editTaskSetRowY(row, inner)
+ inner = inner - EDIT_TASK_ROW_H
+ end
+ end
+ return yCursor + inner
+end
+
+--- Repack form rows so hidden fields leave no empty gaps.
+function EditTaskFrame:relayoutForm()
+ if self.formRoot == nil then
+ return
+ end
+ if self._standardRows == nil then
+ self._standardRows = {
+ self.standardDetailRow,
+ self.standardEffortRow,
+ self.standardPriorityRow,
+ self.standardRecurToggleRow,
+ self.recurModeRow,
+ self.recurNRow,
+ self.startPeriodRow,
+ self.periodRow
+ }
+ self._foodRows = { self.foodTypeRow, self.foodLevelRow }
+ self._conditionRows = { self.conditionTypeRow, self.conditionEvalRow, self.conditionLevelRow }
+ self._productionRows = {
+ self.productionPickRow,
+ self.productionIoRow,
+ self.productionFillRow,
+ self.productionEvalRow,
+ self.productionLevelRow
+ }
+ end
+
+ local sectionStart = 0
+ if editTaskRowVisible(self.taskTypeRow) then
+ editTaskSetRowY(self.taskTypeRow, 0)
+ sectionStart = -EDIT_TASK_ROW_H
+ end
+
+ if editTaskRowVisible(self.standardSection) then
+ self.standardSection:setPosition("0px", string.format("%dpx", sectionStart))
+ self:layoutRowStack(self._standardRows or {}, 0)
+ elseif editTaskRowVisible(self.linkedSection) then
+ self.linkedSection:setPosition("0px", string.format("%dpx", sectionStart))
+ local y2 = 0
+ if editTaskRowVisible(self.husbandryPickRow) then
+ editTaskSetRowY(self.husbandryPickRow, y2)
+ y2 = y2 - EDIT_TASK_ROW_H
+ end
+ if editTaskRowVisible(self.foodBlock) then
+ y2 = self:layoutBlockAtY(self.foodBlock, self._foodRows or {}, y2)
+ elseif editTaskRowVisible(self.conditionBlock) then
+ y2 = self:layoutBlockAtY(self.conditionBlock, self._conditionRows or {}, y2)
+ elseif editTaskRowVisible(self.productionBlock) then
+ y2 = self:layoutBlockAtY(self.productionBlock, self._productionRows or {}, y2)
+ end
+ end
+end
+
+function EditTaskFrame:linkedObjectCounts()
+ local husbandryCount = 0
+ for _ in pairs(g_currentMission.taskList:getHusbandries()) do
+ husbandryCount = husbandryCount + 1
+ end
+ local productionCount = 0
+ for _ in pairs(g_currentMission.taskList:getProductions()) do
+ productionCount = productionCount + 1
+ end
+ return husbandryCount, productionCount, husbandryCount + productionCount
+end
+
+function EditTaskFrame:shouldShowTaskType()
+ local _, _, total = self:linkedObjectCounts()
+ return self.group.type ~= TaskGroup.GROUP_TYPE.Template and total > 0
+end
+
+function EditTaskFrame:monthNameTexts()
+ return {
+ g_i18n:getText("ui_month1"),
+ g_i18n:getText("ui_month2"),
+ g_i18n:getText("ui_month3"),
+ g_i18n:getText("ui_month4"),
+ g_i18n:getText("ui_month5"),
+ g_i18n:getText("ui_month6"),
+ g_i18n:getText("ui_month7"),
+ g_i18n:getText("ui_month8"),
+ g_i18n:getText("ui_month9"),
+ g_i18n:getText("ui_month10"),
+ g_i18n:getText("ui_month11"),
+ g_i18n:getText("ui_month12")
+ }
+end
+
+function EditTaskFrame:buildLevelOptionTexts(capacity)
+ return {
+ g_i18n:getText("ui_task_level_empty"),
+ string.format("10%% (%s)", g_i18n:formatVolume(capacity * 0.10, 0)),
+ string.format("20%% (%s)", g_i18n:formatVolume(capacity * 0.20, 0)),
+ string.format("30%% (%s)", g_i18n:formatVolume(capacity * 0.30, 0)),
+ string.format("40%% (%s)", g_i18n:formatVolume(capacity * 0.40, 0)),
+ string.format("50%% (%s)", g_i18n:formatVolume(capacity * 0.50, 0)),
+ string.format("60%% (%s)", g_i18n:formatVolume(capacity * 0.60, 0)),
+ string.format("70%% (%s)", g_i18n:formatVolume(capacity * 0.70, 0)),
+ string.format("80%% (%s)", g_i18n:formatVolume(capacity * 0.80, 0)),
+ string.format("90%% (%s)", g_i18n:formatVolume(capacity * 0.90, 0))
+ }
+end
+
+function EditTaskFrame:levelStateForStoredLevel(level, capacity)
+ if capacity == nil or capacity <= 0 then
+ return 1
+ end
+ if level == 0 then
+ return 1
+ end
+ local idx = math.floor((level / capacity) * 10) + 1
+ if idx < 1 then idx = 1 end
+ if idx > 10 then idx = 10 end
+ return idx
+end
+
+function EditTaskFrame:applyLevelFromState(idx, capacity)
+ if idx <= 1 or capacity == nil or capacity <= 0 then
+ return 0
+ end
+ return (idx - 1) * 0.10 * capacity
+end
+
+function EditTaskFrame:populateTaskTypeOption()
+ self._taskTypeOrder = {}
+ local options = {}
+ table.insert(options, g_i18n:getText("ui_type_standard"))
+ table.insert(self._taskTypeOrder, Task.TASK_TYPE.Standard)
+
+ local husbandryCount = 0
+ for _ in pairs(g_currentMission.taskList:getHusbandries()) do husbandryCount = husbandryCount + 1 end
+ if husbandryCount > 0 then
+ table.insert(options, g_i18n:getText("ui_type_husbandry_food"))
+ table.insert(self._taskTypeOrder, Task.TASK_TYPE.HusbandryFood)
+ table.insert(options, g_i18n:getText("ui_type_husbandry_conditions"))
+ table.insert(self._taskTypeOrder, Task.TASK_TYPE.HusbandryConditions)
+ end
+
+ local productionCount = 0
+ for _ in pairs(g_currentMission.taskList:getProductions()) do productionCount = productionCount + 1 end
+ if productionCount > 0 then
+ table.insert(options, g_i18n:getText("ui_type_production"))
+ table.insert(self._taskTypeOrder, Task.TASK_TYPE.Production)
+ end
+
+ self.taskTypeOption:setTexts(options)
+ local state = 1
+ for i, t in ipairs(self._taskTypeOrder) do
+ if t == self.task.type then
+ state = i
+ break
+ end
+ end
+ self.taskTypeOption:setState(state, false)
+end
+
+function EditTaskFrame:populateHusbandryOptions()
+ self._husbandryList = {}
+ self._husbandryLookup = {}
+ local options = {}
+ for _, husbandry in pairs(g_currentMission.taskList:getHusbandries()) do
+ if self.task.type == Task.TASK_TYPE.HusbandryConditions then
+ local conditionCount = 0
+ for _ in pairs(husbandry.conditionInfos) do conditionCount = conditionCount + 1 end
+ if conditionCount == 0 then
+ -- skip husbandries with no conditions
+ else
+ table.insert(options, husbandry.name)
+ table.insert(self._husbandryList, husbandry)
+ self._husbandryLookup[husbandry.name] = husbandry
+ end
+ else
+ table.insert(options, husbandry.name)
+ table.insert(self._husbandryList, husbandry)
+ self._husbandryLookup[husbandry.name] = husbandry
+ end
+ end
+ self.husbandryOption:setTexts(options)
+ local default = 1
+ for i, h in ipairs(self._husbandryList) do
+ if self.task:getObjectId() == h.id then
+ default = i
+ break
+ end
+ end
+ if #options == 0 then
+ self.husbandryOption:setState(1, false)
+ return
+ end
+ self.husbandryOption:setState(default, false)
+ local h = self._husbandryList[default]
+ if h ~= nil then
+ self.task.objectId = h.id
+ end
+end
+
+function EditTaskFrame:populateFoodOptions()
+ local husbandry = g_currentMission.taskList:getHusbandries()[self.task:getObjectId()]
+ if husbandry == nil then
+ self.foodTypeOption:setTexts({})
+ self.foodLevelOption:setTexts({})
+ return
+ end
+ local options = { g_i18n:getText("ui_husbandry_food_total") }
+ self._foodKeys = { Task.TOTAL_FOOD_KEY }
+ for _, foodInfo in pairs(husbandry.keys) do
+ table.insert(options, foodInfo.title)
+ table.insert(self._foodKeys, foodInfo.key)
+ end
+ self.foodTypeOption:setTexts(options)
+ local fstate = 1
+ for i, key in ipairs(self._foodKeys) do
+ if self.task.husbandryFood == key then
+ fstate = i
+ break
+ end
+ end
+ self.foodTypeOption:setState(fstate, false)
+
+ local levelTexts = self:buildLevelOptionTexts(husbandry.foodCapacity)
+ self.foodLevelOption:setTexts(levelTexts)
+ self.foodLevelOption:setState(self:levelStateForStoredLevel(self.task.husbandryLevel, husbandry.foodCapacity), false)
+end
+
+function EditTaskFrame:populateConditionOptions()
+ local husbandry = g_currentMission.taskList:getHusbandries()[self.task:getObjectId()]
+ if husbandry == nil then
+ self.conditionTypeOption:setTexts({})
+ self.conditionLevelOption:setTexts({})
+ return
+ end
+ local options = {}
+ self._conditionKeys = {}
+ for _, conditionInfo in pairs(husbandry.conditionInfos) do
+ table.insert(options, conditionInfo.title)
+ table.insert(self._conditionKeys, conditionInfo.key)
+ end
+ self.conditionTypeOption:setTexts(options)
+ local cstate = 1
+ for i, key in ipairs(self._conditionKeys) do
+ if self.task.husbandryCondition == key then
+ cstate = i
+ break
+ end
+ end
+ if #options > 0 then
+ self.conditionTypeOption:setState(cstate, false)
+ local key = self._conditionKeys[cstate]
+ if key ~= nil then
+ self.task.husbandryCondition = key
+ end
+ end
+
+ local evalTexts = {
+ g_i18n:getText("ui_task_condition_evaluator_less_than"),
+ g_i18n:getText("ui_task_condition_evaluator_greater_than")
+ }
+ self.conditionEvalOption:setTexts(evalTexts)
+ self.conditionEvalOption:setState(self.task.evaluator, false)
+
+ local conditionInfo = husbandry.conditionInfos[self.task.husbandryCondition]
+ if conditionInfo == nil then
+ self.conditionLevelOption:setTexts(self:buildLevelOptionTexts(1))
+ self.conditionLevelOption:setState(1, false)
+ return
+ end
+ self.conditionLevelOption:setTexts(self:buildLevelOptionTexts(conditionInfo.capacity))
+ self.conditionLevelOption:setState(self:levelStateForStoredLevel(self.task.husbandryLevel, conditionInfo.capacity), false)
+end
+
+function EditTaskFrame:populateProductionOptions()
+ self._productionList = {}
+ local options = {}
+ for _, production in pairs(g_currentMission.taskList:getProductions()) do
+ table.insert(options, production.name)
+ table.insert(self._productionList, production)
+ end
+ self.productionOption:setTexts(options)
+ local pstate = 1
+ for i, p in ipairs(self._productionList) do
+ if self.task:getObjectId() == p.id then
+ pstate = i
+ break
+ end
+ end
+ if #options > 0 then
+ self.productionOption:setState(pstate, false)
+ local p = self._productionList[pstate]
+ if p ~= nil then
+ self.task.objectId = p.id
+ end
+ end
+
+ local ioTexts = {
+ g_i18n:getText("ui_task_production_input"),
+ g_i18n:getText("ui_task_production_output")
+ }
+ self.productionIoOption:setTexts(ioTexts)
+ self.productionIoOption:setState(self.task.productionType, false)
+
+ self:populateProductionFillAndLevel()
+end
+
+function EditTaskFrame:populateProductionFillAndLevel()
+ local production = g_currentMission.taskList:getProductions()[self.task:getObjectId()]
+ if production == nil then
+ self.productionFillOption:setTexts({})
+ self.productionLevelOption:setTexts({})
+ return
+ end
+ local fillTypes = production.inputs
+ if self.task.productionType == Task.PRODUCTION_TYPE.OUTPUT then
+ fillTypes = production.outputs
+ end
+ local options = {}
+ self._fillKeys = {}
+ for _, fillInfo in pairs(fillTypes) do
+ table.insert(options, fillInfo.title)
+ table.insert(self._fillKeys, fillInfo.key)
+ end
+ self.productionFillOption:setTexts(options)
+ local fstate = 1
+ for i, key in ipairs(self._fillKeys) do
+ if self.task.productionFillType == key then
+ fstate = i
+ break
+ end
+ end
+ if #options > 0 then
+ self.productionFillOption:setState(fstate, false)
+ local key = self._fillKeys[fstate]
+ if key ~= nil then
+ self.task.productionFillType = key
+ end
+ end
+
+ local evalTexts = {
+ g_i18n:getText("ui_task_condition_evaluator_less_than"),
+ g_i18n:getText("ui_task_condition_evaluator_greater_than")
+ }
+ self.productionEvalOption:setTexts(evalTexts)
+ self.productionEvalOption:setState(self.task.evaluator, false)
+
+ local fillInfo = nil
+ if self.task.productionType == Task.PRODUCTION_TYPE.INPUT then
+ fillInfo = production.inputs[self.task.productionFillType]
+ else
+ fillInfo = production.outputs[self.task.productionFillType]
+ end
+ if fillInfo == nil then
+ self.productionLevelOption:setTexts(self:buildLevelOptionTexts(1))
+ self.productionLevelOption:setState(1, false)
+ return
+ end
+ self.productionLevelOption:setTexts(self:buildLevelOptionTexts(fillInfo.capacity))
+ self.productionLevelOption:setState(self:levelStateForStoredLevel(self.task.productionLevel, fillInfo.capacity), false)
+end
+
+function EditTaskFrame:populateRecurNOption()
+ local mode = self.recurModeOption:getState()
+ local texts = {}
+ self._recurNValues = {}
+ if mode == Task.RECUR_MODE.EVERY_N_MONTHS then
+ self.recurNLabel:setText(g_i18n:getText("ui_set_task_n_months"))
+ for v = 1, 12 do
+ table.insert(texts, tostring(v))
+ table.insert(self._recurNValues, v)
+ end
+ table.insert(texts, "24")
+ table.insert(self._recurNValues, 24)
+ table.insert(texts, "36")
+ table.insert(self._recurNValues, 36)
+ elseif mode == Task.RECUR_MODE.EVERY_N_DAYS then
+ self.recurNLabel:setText(g_i18n:getText("ui_set_task_n_days"))
+ for v = 1, 12 do
+ table.insert(texts, tostring(v))
+ table.insert(self._recurNValues, v)
+ end
+ else
+ self.recurNOption:setTexts({ "-" })
+ self._recurNValues = {}
+ self.recurNOption:setState(1, false)
+ return
+ end
+ self.recurNOption:setTexts(texts)
+ local want = self.task.n
+ if want == 0 then want = 1 end
+ local state = 1
+ for i, n in ipairs(self._recurNValues) do
+ if n == want then
+ state = i
+ break
+ end
+ end
+ self.recurNOption:setState(state, false)
+end
+
+function EditTaskFrame:syncStandardWidgetsFromTask()
+ self:setTaskDetailInputText(self.task.detail or "")
+
+ local effortTexts = { "1", "2", "3", "4", "5" }
+ self.effortOption:setTexts(effortTexts)
+ self.effortOption:setState(math.max(1, math.min(5, self.task.effort or 1)), false)
+
+ local priTexts = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }
+ self.priorityOption:setTexts(priTexts)
+ self.priorityOption:setState(math.max(1, math.min(10, self.task.priority or 1)), false)
+
+ local yn = { g_i18n:getText("ui_yes"), g_i18n:getText("ui_no") }
+ self.shouldRecurOption:setTexts(yn)
+ self.shouldRecurOption:setState(self.task.shouldRecur and 1 or 2, false)
+
+ local recurTexts = {
+ g_i18n:getText("ui_set_task_recur_mode_monthly"),
+ g_i18n:getText("ui_task_due_daily"),
+ g_i18n:getText("ui_set_task_recur_mode_n_months"),
+ g_i18n:getText("ui_set_task_recur_mode_n_days")
+ }
+ self.recurModeOption:setTexts(recurTexts)
+ local rm = self.task.recurMode
+ if rm == nil or rm == Task.RECUR_MODE.NONE then
+ rm = Task.RECUR_MODE.MONTHLY
+ end
+ self.recurModeOption:setState(rm, false)
+
+ self:populateRecurNOption()
+
+ local months = self:monthNameTexts()
+ self.startPeriodOption:setTexts(months)
+ local startDef = TaskListUtils.convertPeriodToMonthNumber(g_currentMission.environment.currentPeriod)
+ if self.task.nextN ~= 0 then
+ startDef = TaskListUtils.convertPeriodToMonthNumber(self.task.nextN)
+ end
+ self.startPeriodOption:setState(startDef, false)
+
+ self.periodOption:setTexts(months)
+ local perDef = TaskListUtils.convertPeriodToMonthNumber(g_currentMission.environment.currentPeriod)
+ if self.task.period ~= 1 then
+ perDef = TaskListUtils.convertPeriodToMonthNumber(self.task.period)
+ end
+ self.periodOption:setState(perDef, false)
+end
+
+function EditTaskFrame:populateLinkedForCurrentType()
+ local t = self.task.type
+ if t == Task.TASK_TYPE.HusbandryFood or t == Task.TASK_TYPE.HusbandryConditions then
+ self:populateHusbandryOptions()
+ end
+ if t == Task.TASK_TYPE.HusbandryFood then
+ self:populateFoodOptions()
+ elseif t == Task.TASK_TYPE.HusbandryConditions then
+ self:populateConditionOptions()
+ elseif t == Task.TASK_TYPE.Production then
+ self:populateProductionOptions()
+ end
+end
+
+function EditTaskFrame:updateVisibility()
+ local showType = self:shouldShowTaskType()
+ self.taskTypeRow:setVisible(showType)
+ if not showType then
+ self.task.type = Task.TASK_TYPE.Standard
+ end
+ if self.task.type ~= Task.TASK_TYPE.Standard
+ and self.task.type ~= Task.TASK_TYPE.HusbandryFood
+ and self.task.type ~= Task.TASK_TYPE.HusbandryConditions
+ and self.task.type ~= Task.TASK_TYPE.Production then
+ self.task.type = Task.TASK_TYPE.Standard
+ end
+
+ local std = self.task.type == Task.TASK_TYPE.Standard
+ self.standardSection:setVisible(std)
+ self.linkedSection:setVisible(not std)
+
+ local food = self.task.type == Task.TASK_TYPE.HusbandryFood
+ local cond = self.task.type == Task.TASK_TYPE.HusbandryConditions
+ local prod = self.task.type == Task.TASK_TYPE.Production
+
+ self.husbandryPickRow:setVisible(food or cond)
+ self.foodBlock:setVisible(food)
+ self.conditionBlock:setVisible(cond)
+ self.productionBlock:setVisible(prod)
+
+ local recurOn = std and self.shouldRecurOption:getState() == 1
+ local mode = self.recurModeOption:getState()
+ local needN = std and recurOn and (mode == Task.RECUR_MODE.EVERY_N_MONTHS or mode == Task.RECUR_MODE.EVERY_N_DAYS)
+ local needStart = std and recurOn and mode == Task.RECUR_MODE.EVERY_N_MONTHS
+ local needPeriod = std and ((not recurOn) or mode == Task.RECUR_MODE.MONTHLY)
+
+ self.recurModeRow:setVisible(std and recurOn)
+ self.recurNRow:setVisible(needN)
+ self.startPeriodRow:setVisible(needStart)
+ self.periodRow:setVisible(needPeriod)
+
+ if self.recurNOption ~= nil and self.recurNOption.setDisabled ~= nil then
+ self.recurNOption:setDisabled(not needN)
+ end
+ if self.startPeriodOption ~= nil and self.startPeriodOption.setDisabled ~= nil then
+ self.startPeriodOption:setDisabled(not needStart)
+ end
+
+ self:relayoutForm()
+end
+
+function EditTaskFrame:onOpen()
+ EditTaskFrame:superClass().onOpen(self)
+ local p = EditTaskFrame._params
+ EditTaskFrame._params = nil
+ if p == nil then
+ self:close()
+ return
+ end
+ self.groupId = p.groupId
+ self.group = p.group
+ self.task = p.task
+ self.isEdit = p.isEdit
+
+ if self.isEdit then
+ self.titleText:setText(g_i18n:getText("ui_edit_task"))
+ else
+ self.titleText:setText(g_i18n:getText("ui_add_task"))
+ end
+
+ self:withSuppressedOptionCallbacks(function()
+ if self:shouldShowTaskType() then
+ self:populateTaskTypeOption()
+ else
+ self.task.type = Task.TASK_TYPE.Standard
+ end
+ self:syncStandardWidgetsFromTask()
+ self:populateLinkedForCurrentType()
+ end)
+ self:updateVisibility()
+end
+
+function EditTaskFrame:onClose()
+ EditTaskFrame:superClass().onClose(self)
+ self.groupId = nil
+ self.group = nil
+ self.task = nil
+ self._optionCallbackSuppressDepth = 0
+end
+
+function EditTaskFrame:onTaskTypeChange(index)
+ if self:_optionCallbacksSuppressed() then
+ return
+ end
+ if self.task.type == Task.TASK_TYPE.Standard then
+ self:readDetailFromUi()
+ end
+ self.task.type = self._taskTypeOrder[index] or Task.TASK_TYPE.Standard
+ self:withSuppressedOptionCallbacks(function()
+ self:populateLinkedForCurrentType()
+ end)
+ self:updateVisibility()
+ if self.task.type == Task.TASK_TYPE.Standard then
+ self:withSuppressedOptionCallbacks(function()
+ self:syncStandardWidgetsFromTask()
+ end)
+ self:updateVisibility()
+ end
+end
+
+function EditTaskFrame:onEffortChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+function EditTaskFrame:onPriorityChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+function EditTaskFrame:onShouldRecurChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+ self:withSuppressedOptionCallbacks(function()
+ self:populateRecurNOption()
+ end)
+ self:updateVisibility()
+end
+function EditTaskFrame:onRecurModeChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+ self:withSuppressedOptionCallbacks(function()
+ self:populateRecurNOption()
+ end)
+ self:updateVisibility()
+end
+function EditTaskFrame:onRecurNChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+function EditTaskFrame:onStartPeriodChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+function EditTaskFrame:onPeriodChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+
+function EditTaskFrame:onHusbandryChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+ local h = self._husbandryList[index]
+ if h ~= nil then
+ self.task.objectId = h.id
+ end
+ if self.task.type == Task.TASK_TYPE.HusbandryFood then
+ self:withSuppressedOptionCallbacks(function()
+ self:populateFoodOptions()
+ end)
+ elseif self.task.type == Task.TASK_TYPE.HusbandryConditions then
+ self:withSuppressedOptionCallbacks(function()
+ self:populateConditionOptions()
+ end)
+ end
+end
+
+function EditTaskFrame:onFoodTypeChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+function EditTaskFrame:onFoodLevelChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+function EditTaskFrame:onConditionTypeChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+ local key = self._conditionKeys[index]
+ if key ~= nil then
+ self.task.husbandryCondition = key
+ end
+ self:withSuppressedOptionCallbacks(function()
+ self:populateConditionOptions()
+ end)
+end
+function EditTaskFrame:onConditionEvalChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+function EditTaskFrame:onConditionLevelChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+
+function EditTaskFrame:onProductionChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+ local pr = self._productionList[index]
+ if pr ~= nil then
+ self.task.objectId = pr.id
+ end
+ self:withSuppressedOptionCallbacks(function()
+ self:populateProductionFillAndLevel()
+ end)
+end
+
+function EditTaskFrame:onProductionIoChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+ self.task.productionType = index
+ self:withSuppressedOptionCallbacks(function()
+ self:populateProductionFillAndLevel()
+ end)
+end
+
+function EditTaskFrame:onProductionFillChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+ local key = self._fillKeys[index]
+ if key ~= nil then
+ self.task.productionFillType = key
+ end
+ self:withSuppressedOptionCallbacks(function()
+ self:populateProductionFillAndLevel()
+ end)
+end
+
+function EditTaskFrame:onProductionEvalChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+function EditTaskFrame:onProductionLevelChange(index)
+ if self:_optionCallbacksSuppressed() then return end
+end
+
+function EditTaskFrame:getTaskDetailInputText()
+ if self.taskDetailInput == nil then
+ return ""
+ end
+ if self.taskDetailInput.getText ~= nil then
+ return self.taskDetailInput:getText() or ""
+ end
+ return self.taskDetailInput.text or ""
+end
+
+function EditTaskFrame:setTaskDetailInputText(text)
+ if self.taskDetailInput ~= nil and self.taskDetailInput.setText ~= nil then
+ self.taskDetailInput:setText(text or "")
+ end
+end
+
+function EditTaskFrame:readDetailFromUi()
+ self.task.detail = limitTaskDetailLength(self:getTaskDetailInputText(), Task.MAX_DETAIL_LENGTH)
+end
+
+function EditTaskFrame:readStandardFromUi()
+ self:readDetailFromUi()
+ self.task.effort = self.effortOption:getState()
+ self.task.priority = self.priorityOption:getState()
+ self.task.shouldRecur = self.shouldRecurOption:getState() == 1
+ if self.task.shouldRecur then
+ self.task.recurMode = self.recurModeOption:getState()
+ if self.task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS or self.task.recurMode == Task.RECUR_MODE.EVERY_N_DAYS then
+ local nv = self._recurNValues[self.recurNOption:getState()]
+ self.task.n = nv or 1
+ else
+ self.task.n = 0
+ end
+ if self.task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS then
+ self.task.nextN = TaskListUtils.convertMonthNumberToPeriod(self.startPeriodOption:getState())
+ elseif self.task.recurMode == Task.RECUR_MODE.EVERY_N_DAYS then
+ self.task.nextN = g_currentMission.environment.currentDay
+ else
+ self.task.nextN = 0
+ end
+ if self.task.recurMode == Task.RECUR_MODE.MONTHLY then
+ self.task.period = TaskListUtils.convertMonthNumberToPeriod(self.periodOption:getState())
+ end
+ else
+ self.task.recurMode = Task.RECUR_MODE.NONE
+ self.task.n = 0
+ self.task.nextN = 0
+ self.task.period = TaskListUtils.convertMonthNumberToPeriod(self.periodOption:getState())
+ end
+end
+
+function EditTaskFrame:readLinkedFromUi()
+ local t = self.task.type
+ if t == Task.TASK_TYPE.HusbandryFood then
+ local h = self._husbandryList[self.husbandryOption:getState()]
+ if h ~= nil then
+ self.task.objectId = h.id
+ end
+ if self._foodKeys ~= nil then
+ local fk = self._foodKeys[self.foodTypeOption:getState()]
+ if fk ~= nil then
+ self.task.husbandryFood = fk
+ end
+ end
+ local husbandry = g_currentMission.taskList:getHusbandries()[self.task:getObjectId()]
+ if husbandry ~= nil then
+ local idx = self.foodLevelOption:getState()
+ self.task.husbandryLevel = self:applyLevelFromState(idx, husbandry.foodCapacity)
+ end
+ elseif t == Task.TASK_TYPE.HusbandryConditions then
+ local h = self._husbandryList[self.husbandryOption:getState()]
+ if h ~= nil then
+ self.task.objectId = h.id
+ end
+ if self._conditionKeys ~= nil then
+ local ck = self._conditionKeys[self.conditionTypeOption:getState()]
+ if ck ~= nil then
+ self.task.husbandryCondition = ck
+ end
+ end
+ self.task.evaluator = self.conditionEvalOption:getState()
+ local husbandry = g_currentMission.taskList:getHusbandries()[self.task:getObjectId()]
+ if husbandry ~= nil then
+ local ci = husbandry.conditionInfos[self.task.husbandryCondition]
+ if ci ~= nil then
+ self.task.husbandryLevel = self:applyLevelFromState(self.conditionLevelOption:getState(), ci.capacity)
+ end
+ end
+ elseif t == Task.TASK_TYPE.Production then
+ local pr = self._productionList[self.productionOption:getState()]
+ if pr ~= nil then
+ self.task.objectId = pr.id
+ end
+ self.task.productionType = self.productionIoOption:getState()
+ if self._fillKeys ~= nil then
+ local fk = self._fillKeys[self.productionFillOption:getState()]
+ if fk ~= nil then
+ self.task.productionFillType = fk
+ end
+ end
+ self.task.evaluator = self.productionEvalOption:getState()
+ local production = g_currentMission.taskList:getProductions()[self.task:getObjectId()]
+ if production ~= nil then
+ local fillInfo = nil
+ if self.task.productionType == Task.PRODUCTION_TYPE.INPUT then
+ fillInfo = production.inputs[self.task.productionFillType]
+ else
+ fillInfo = production.outputs[self.task.productionFillType]
+ end
+ if fillInfo ~= nil then
+ self.task.productionLevel = self:applyLevelFromState(self.productionLevelOption:getState(), fillInfo.capacity)
+ end
+ end
+ end
+end
+
+function EditTaskFrame:onClickSave()
+ if self:shouldShowTaskType() then
+ self.task.type = self._taskTypeOrder[self.taskTypeOption:getState()] or Task.TASK_TYPE.Standard
+ else
+ self.task.type = Task.TASK_TYPE.Standard
+ end
+
+ if self.task.type == Task.TASK_TYPE.Standard then
+ self:readStandardFromUi()
+ if self.task.detail == "" then
+ InfoDialog.show(g_i18n:getText("ui_no_detail_specified_error"))
+ return
+ end
+ else
+ self:readLinkedFromUi()
+ if not self.task:isValid() then
+ InfoDialog.show(g_i18n:getText("ui_task_form_incomplete"))
+ return
+ end
+ end
+
+ g_currentMission.taskList:addTask(self.groupId, self.task, self.isEdit)
+ self:close()
+end
+
+function EditTaskFrame:onClickCancel()
+ self:close()
+end
diff --git a/gui/EditTaskFrame.xml b/gui/EditTaskFrame.xml
new file mode 100644
index 0000000..133d4f9
--- /dev/null
+++ b/gui/EditTaskFrame.xml
@@ -0,0 +1,154 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/gui/ManageTasksFrame.lua b/gui/ManageTasksFrame.lua
index 87d20ce..e8befa2 100644
--- a/gui/ManageTasksFrame.lua
+++ b/gui/ManageTasksFrame.lua
@@ -8,7 +8,6 @@ function ManageTasksFrame.new(target, custom_mt)
self.i18n = g_i18n
self.selectedTaskIndex = -1
self.currentGroupId = -1
- self.isEdit = false
return self
end
@@ -123,16 +122,16 @@ function ManageTasksFrame:onClickBack(sender)
self:close()
end
--- New Task Step
function ManageTasksFrame:onClickAdd(sender)
if self.currentGroupId == -1 then
InfoDialog.show(g_i18n:getText("ui_no_group_selected"))
return
end
- local newTask = Task.new()
- self.isEdit = false
- self:onAddEditTaskRequestType(newTask, false)
+ local groupId = self.currentGroupId
+ local group = self.currentGroup
+ self:close()
+ EditTaskFrame.open(groupId, group, Task.new(), false)
end
function ManageTasksFrame:onClickEdit(sender)
@@ -146,718 +145,10 @@ function ManageTasksFrame:onClickEdit(sender)
InfoDialog.show(g_i18n:getText("ui_no_task_selected"))
return
end
- self.isEdit = true
- self:onAddEditTaskRequestType(task, false)
-end
-
-function ManageTasksFrame:onAddEditTaskRequestType(task, isGoingBack)
- local husbandryCount = 0
- for _ in pairs(g_currentMission.taskList:getHusbandries()) do husbandryCount = husbandryCount + 1 end
- local productionCount = 0
- for _ in pairs(g_currentMission.taskList:getProductions()) do productionCount = productionCount + 1 end
- local totalCount = husbandryCount + productionCount
-
- if self.currentGroup.type == TaskGroup.GROUP_TYPE.Template or totalCount == 0 then
- -- If we're here after going back, the sequence should end
- if isGoingBack == false then
- self:onAddEditTaskRequestDetail(task)
- end
- else
- local allowedValues = {}
- local lookup = {}
- table.insert(allowedValues, g_i18n:getText("ui_type_standard"))
- lookup[g_i18n:getText("ui_type_standard")] = Task.TASK_TYPE.Standard
-
- if husbandryCount > 0 then
- table.insert(allowedValues, g_i18n:getText("ui_type_husbandry_food"))
- lookup[g_i18n:getText("ui_type_husbandry_food")] = Task.TASK_TYPE.HusbandryFood
- table.insert(allowedValues, g_i18n:getText("ui_type_husbandry_conditions"))
- lookup[g_i18n:getText("ui_type_husbandry_conditions")] = Task.TASK_TYPE.HusbandryConditions
- end
-
- if productionCount > 0 then
- table.insert(allowedValues, g_i18n:getText("ui_type_production"))
- lookup[g_i18n:getText("ui_type_production")] = Task.TASK_TYPE.Production
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_type_description"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = task.type,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local value = allowedValues[index]
- task.type = lookup[value]
-
- if task.type == Task.TASK_TYPE.Standard then
- self:onAddEditTaskRequestDetail(task)
- elseif task.type == Task.TASK_TYPE.HusbandryFood or task.type == Task.TASK_TYPE.HusbandryConditions then
- self:onAddEditRequestHusbandry(task)
- elseif task.type == Task.TASK_TYPE.Production then
- self:onAddEditRequestProduction(task)
- end
- end
- end
- })
- end
-end
-
-function ManageTasksFrame:onAddEditRequestProduction(task)
- local allowedValues = {}
- local lookup = {}
- local default = 1
-
- for _, production in pairs(g_currentMission.taskList:getProductions()) do
- table.insert(allowedValues, production.name)
- lookup[production.name] = production
- if task:getObjectId() == production.id then
- default = #allowedValues
- end
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_production"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local value = allowedValues[index]
- local production = lookup[value]
- task.objectId = production.id
- self:onAddEditRequestProductionType(task)
- else
- -- Go back
- self:onAddEditTaskRequestType(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditRequestProductionType(task)
- local allowedValues = {
- g_i18n:getText("ui_task_production_input"),
- g_i18n:getText("ui_task_production_output")
- }
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_production_type"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = task.productionType,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- task.productionType = index
- self:onAddEditRequestProductionFillType(task)
- else
- -- Go back
- self:onAddEditRequestProduction(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditRequestProductionFillType(task)
- local production = g_currentMission.taskList:getProductions()[task:getObjectId()]
- local allowedValues = {}
- local lookup = {}
- local default = 1
-
- local fillTypes = production.inputs
- if task.productionType == Task.PRODUCTION_TYPE.OUTPUT then
- fillTypes = production.outputs
- end
-
- for _, fillInfo in pairs(fillTypes) do
- table.insert(allowedValues, fillInfo.title)
- lookup[fillInfo.title] = fillInfo.key
- if task.productionFillType == fillInfo.key then
- default = #allowedValues
- end
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_production_fill_type"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- task.productionFillType = lookup[allowedValues[index]]
- self:onAddEditRequestConditionEvaluator(task)
- else
- -- Go back
- self:onAddEditRequestProductionType(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditRequestProductionLevel(task)
- local production = g_currentMission.taskList:getProductions()[task:getObjectId()]
- local fillInfo = nil
- if task.productionType == Task.PRODUCTION_TYPE.INPUT then
- fillInfo = production.inputs[task.productionFillType]
- else
- fillInfo = production.outputs[task.productionFillType]
- end
-
- local allowedValues = {
- g_i18n:getText("ui_task_level_empty"),
- string.format("10%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.10, 0)),
- string.format("20%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.20, 0)),
- string.format("30%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.30, 0)),
- string.format("40%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.40, 0)),
- string.format("50%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.50, 0)),
- string.format("60%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.60, 0)),
- string.format("70%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.70, 0)),
- string.format("80%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.80, 0)),
- string.format("90%% (%s)", g_i18n:formatVolume(fillInfo.capacity * 0.90, 0))
- }
- local default = 1
- if task.productionLevel ~= 0 then
- default = math.floor((task.productionLevel / fillInfo.capacity) * 10) + 1
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_production_level"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local capacity = (index - 1) * 0.10
- task.productionLevel = capacity * fillInfo.capacity
- self:onAddEditTaskJourneyComplete(task)
- else
- -- Go back
- self:onAddEditRequestConditionEvaluator(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditRequestHusbandry(task)
- local allowedValues = {}
- local lookup = {}
- local default = 1
-
- for _, husbandry in pairs(g_currentMission.taskList:getHusbandries()) do
- local conditionCount = 0
- for _ in pairs(husbandry.conditionInfos) do conditionCount = conditionCount + 1 end
- if task.type == Task.TASK_TYPE.HusbandryConditions and conditionCount == 0 then
- continue
- end
-
- table.insert(allowedValues, husbandry.name)
- lookup[husbandry.name] = husbandry
- if task:getObjectId() == husbandry.id then
- default = #allowedValues
- end
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_husbandry"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local value = allowedValues[index]
- local husbandry = lookup[value]
- task.objectId = husbandry.id
- if task.type == Task.TASK_TYPE.HusbandryFood then
- self:onAddEditRequestFoodType(task)
- elseif task.type == Task.TASK_TYPE.HusbandryConditions then
- self:OnAddEditRequestConditionType(task)
- end
- else
- -- Go back
- self:onAddEditTaskRequestType(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditRequestFoodType(task)
- local husbandry = g_currentMission.taskList:getHusbandries()[task:getObjectId()]
- local allowedValues = { g_i18n:getText("ui_husbandry_food_total") }
- local lookup = {}
- local default = 1
- local defaultMatch = 2
- for _, foodInfo in pairs(husbandry.keys) do
- table.insert(allowedValues, foodInfo.title)
- lookup[foodInfo.title] = foodInfo.key
- if task.husbandryFood == foodInfo.key then
- default = defaultMatch
- end
- defaultMatch = defaultMatch + 1
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_food_type"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- if index == 1 then
- task.husbandryFood = Task.TOTAL_FOOD_KEY
- else
- task.husbandryFood = lookup[allowedValues[index]]
- end
- self:onAddEditRequestFoodLevel(task)
- else
- -- Go back
- self:onAddEditRequestHusbandry(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditRequestFoodLevel(task)
- local husbandry = g_currentMission.taskList:getHusbandries()[task:getObjectId()]
- local allowedValues = {
- g_i18n:getText("ui_task_level_empty"),
- string.format("10%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.10, 0)),
- string.format("20%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.20, 0)),
- string.format("30%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.30, 0)),
- string.format("40%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.40, 0)),
- string.format("50%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.50, 0)),
- string.format("60%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.60, 0)),
- string.format("70%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.70, 0)),
- string.format("80%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.80, 0)),
- string.format("90%% (%s)", g_i18n:formatVolume(husbandry.foodCapacity * 0.90, 0))
- }
- local default = 1
- if task.husbandryLevel ~= 0 then
- default = math.floor((task.husbandryLevel / husbandry.foodCapacity) * 10) + 1
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_food_level"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local capacity = (index - 1) * 0.10
- task.husbandryLevel = capacity * husbandry.foodCapacity
- self:onAddEditTaskJourneyComplete(task)
- else
- -- Go back
- self:onAddEditRequestFoodType(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:OnAddEditRequestConditionType(task)
- local husbandry = g_currentMission.taskList:getHusbandries()[task:getObjectId()]
- local allowedValues = {}
- local lookup = {}
- local default = 1
- for _, conditionInfo in pairs(husbandry.conditionInfos) do
- table.insert(allowedValues, conditionInfo.title)
- lookup[conditionInfo.title] = conditionInfo.key
- if task.husbandryCondition == conditionInfo.key then
- default = #allowedValues
- end
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_condition_type"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- task.husbandryCondition = lookup[allowedValues[index]]
- self:onAddEditRequestConditionEvaluator(task)
- else
- -- Go back
- self:onAddEditRequestHusbandry(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditRequestConditionEvaluator(task)
- local allowedValues = {
- g_i18n:getText("ui_task_condition_evaluator_less_than"),
- g_i18n:getText("ui_task_condition_evaluator_greater_than")
- }
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_condition_evaluator"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = task.evaluator,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- task.evaluator = index
- if task.type == Task.TASK_TYPE.HusbandryConditions then
- self:onAddEditRequestConditionLevel(task)
- elseif task.type == Task.TASK_TYPE.Production then
- self:onAddEditRequestProductionLevel(task)
- end
- else
- -- Go back
- if task.type == Task.TASK_TYPE.HusbandryConditions then
- self:OnAddEditRequestConditionType(task)
- elseif task.type == Task.TASK_TYPE.Production then
- self:onAddEditRequestProductionFillType(task)
- end
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditRequestConditionLevel(task)
- local husbandry = g_currentMission.taskList:getHusbandries()[task:getObjectId()]
- local conditionInfo = husbandry.conditionInfos[task.husbandryCondition]
- local allowedValues = {
- g_i18n:getText("ui_task_level_empty"),
- string.format("10%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.10, 0)),
- string.format("20%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.20, 0)),
- string.format("30%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.30, 0)),
- string.format("40%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.40, 0)),
- string.format("50%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.50, 0)),
- string.format("60%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.60, 0)),
- string.format("70%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.70, 0)),
- string.format("80%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.80, 0)),
- string.format("90%% (%s)", g_i18n:formatVolume(conditionInfo.capacity * 0.90, 0))
- }
- local default = 1
- if task.husbandryLevel ~= 0 then
- default = math.floor((task.husbandryLevel / conditionInfo.capacity) * 10) + 1
- end
-
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_task_request_condition_level"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local capacity = (index - 1) * 0.10
- task.husbandryLevel = capacity * conditionInfo.capacity
- self:onAddEditTaskJourneyComplete(task)
- else
- -- Go back
- self:onAddEditRequestConditionEvaluator(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditTaskRequestDetail(task)
- TextInputDialog.show(
- function(self, value, clickOk)
- if clickOk then
- local detail = string.gsub(value, '^%s*(.-)%s*$', '%1')
- if detail == "" then
- InfoDialog.show(g_i18n:getText("ui_no_detail_specified_error"))
- return
- end
-
- task.detail = detail
- self:onAddEditTaskEffort(task)
- else
- -- Go back
- self:onAddEditTaskRequestType(task, true)
- end
- end, self,
- task.detail,
- g_i18n:getText("ui_set_task_detail"),
- nil, Task.MAX_DETAIL_LENGTH, g_i18n:getText("ui_btn_ok"), nil, nil, false)
-end
-
-function ManageTasksFrame:onAddEditTaskEffort(task)
- local allowedValues = { "1", "2", "3", "4", "5" }
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_set_task_effort"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = task.effort,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local value = allowedValues[index]
- task.effort = tonumber(value)
- self:onAddEditTaskRequestPriority(task)
- else
- -- Go back
- self:onAddEditTaskRequestDetail(task)
- end
- end
- })
-end
-
--- New Task Step
-function ManageTasksFrame:onAddEditTaskRequestPriority(task)
- local allowedValues = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_set_task_priority"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = task.priority,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local value = allowedValues[index]
- task.priority = tonumber(value)
- self:onAddEditTaskRequestShouldRecur(task)
- else
- -- Go back
- self:onAddEditTaskEffort(task)
- end
- end
- })
-end
-
--- New Task Step
-function ManageTasksFrame:onAddEditTaskRequestShouldRecur(task)
- local allowedValues = { g_i18n:getText("ui_yes"), g_i18n:getText("ui_no") }
- local default = 1
- if task.shouldRecur == false then
- default = 2
- end
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_set_task_should_recur"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- task.shouldRecur = index == 1
- if task.shouldRecur then
- self:onAddEditTaskRequestRecurMode(task)
- else
- self:onAddEditTaskRequestPeriod(task)
- end
- else
- -- Go back
- self:onAddEditTaskRequestPriority(task)
- end
- end
- })
-end
-
--- New Task Step
-function ManageTasksFrame:onAddEditTaskRequestRecurMode(task)
- local allowedValues = {
- g_i18n:getText("ui_set_task_recur_mode_monthly"),
- g_i18n:getText("ui_task_due_daily"),
- g_i18n:getText("ui_set_task_recur_mode_n_months"),
- g_i18n:getText("ui_set_task_recur_mode_n_days")
- }
-
- local default = 1
- if task.recurMode ~= Task.RECUR_MODE.NONE then
- default = task.recurMode
- end
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_set_task_recur_mode"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- task.recurMode = index
-
- if task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS or task.recurMode == Task.RECUR_MODE.EVERY_N_DAYS then
- self:onAddEditTaskRequestN(task)
- return
- end
-
- task.n = 0
- task.nextN = 0
- if task.recurMode == Task.RECUR_MODE.MONTHLY then
- self:onAddEditTaskRequestPeriod(task)
- elseif task.recurMode == Task.RECUR_MODE.DAILY then
- self:onAddEditTaskJourneyComplete(task)
- end
- else
- -- Go back
- self:onAddEditTaskRequestShouldRecur(task)
- end
- end
- })
-end
-
-function ManageTasksFrame:onAddEditTaskRequestN(task)
- local allowedValues = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}
- local default = 1
- if task.n ~= 0 then
- default = task.n
- end
-
- local text = ""
- if task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS then
- text = g_i18n:getText("ui_set_task_n_months")
- table.insert(allowedValues, "24")
- table.insert(allowedValues, "36")
- elseif task.recurMode == Task.RECUR_MODE.EVERY_N_DAYS then
- text = g_i18n:getText("ui_set_task_n_days")
- end
-
- TaskListUtils.showOptionDialog({
- text = text,
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- local increment = tonumber(allowedValues[index])
- task.n = increment
- if task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS then
- self:onAddEditTaskRequestStartPeriod(task)
- elseif task.recurMode == Task.RECUR_MODE.EVERY_N_DAYS then
- task.nextN = g_currentMission.environment.currentDay
- self:onAddEditTaskJourneyComplete(task)
- end
- else
- self:onAddEditTaskRequestRecurMode(task)
- end
- end
- })
-end
-
--- New Task Step for Start Period
-function ManageTasksFrame:onAddEditTaskRequestStartPeriod(task)
- local allowedValues = {
- g_i18n:getText("ui_month1"),
- g_i18n:getText("ui_month2"),
- g_i18n:getText("ui_month3"),
- g_i18n:getText("ui_month4"),
- g_i18n:getText("ui_month5"),
- g_i18n:getText("ui_month6"),
- g_i18n:getText("ui_month7"),
- g_i18n:getText("ui_month8"),
- g_i18n:getText("ui_month9"),
- g_i18n:getText("ui_month10"),
- g_i18n:getText("ui_month11"),
- g_i18n:getText("ui_month12")
- }
- local default = TaskListUtils.convertPeriodToMonthNumber(g_currentMission.environment.currentPeriod)
- if task.nextN ~= 0 then
- default = TaskListUtils.convertPeriodToMonthNumber(task.nextN)
- end
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_set_task_start_period"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- task.nextN = TaskListUtils.convertMonthNumberToPeriod(index)
- self:onAddEditTaskJourneyComplete(task)
- else
- -- Go back
- self:onAddEditTaskRequestN(task)
- end
- end
- })
-end
-
--- New Task Step
-function ManageTasksFrame:onAddEditTaskRequestPeriod(task)
- local allowedValues = {
- g_i18n:getText("ui_month1"),
- g_i18n:getText("ui_month2"),
- g_i18n:getText("ui_month3"),
- g_i18n:getText("ui_month4"),
- g_i18n:getText("ui_month5"),
- g_i18n:getText("ui_month6"),
- g_i18n:getText("ui_month7"),
- g_i18n:getText("ui_month8"),
- g_i18n:getText("ui_month9"),
- g_i18n:getText("ui_month10"),
- g_i18n:getText("ui_month11"),
- g_i18n:getText("ui_month12")
- }
- local default = TaskListUtils.convertPeriodToMonthNumber(g_currentMission.environment.currentPeriod)
- if task.period ~= 1 then
- default = TaskListUtils.convertPeriodToMonthNumber(task.period)
- end
- TaskListUtils.showOptionDialog({
- text = g_i18n:getText("ui_set_task_period"),
- title = "",
- defaultText = "",
- options = allowedValues,
- defaultOption = default,
- target = self,
- args = {},
- callback = function(_, index)
- if index > 0 then
- task.period = TaskListUtils.convertMonthNumberToPeriod(index)
- self:onAddEditTaskJourneyComplete(task)
- else
- if task.shouldRecur then
- self:onAddEditTaskRequestRecurMode(task)
- else
- self:onAddEditTaskRequestShouldRecur(task)
- end
- end
- end
- })
-end
-
--- New Task Final Step
-function ManageTasksFrame:onAddEditTaskJourneyComplete(task)
- g_currentMission.taskList:addTask(self.currentGroup.id, task, self.isEdit)
- self.isEdit = false
+ local groupId = self.currentGroupId
+ local group = self.currentGroup
+ self:close()
+ EditTaskFrame.open(groupId, group, task, true)
end
function ManageTasksFrame:onClickDelete(sender)
diff --git a/gui/MenuTaskList.lua b/gui/MenuTaskList.lua
index 8754aa6..34716d7 100644
--- a/gui/MenuTaskList.lua
+++ b/gui/MenuTaskList.lua
@@ -303,13 +303,21 @@ function MenuTaskList:populateCellForItemInSection(list, section, index, cell)
local currentPeriod = g_currentMission.environment.currentPeriod
local currentDay = g_currentMission.environment.currentDay
- local overdue = task.period ~= currentPeriod
+ local overdue
if task.recurMode == Task.RECUR_MODE.DAILY then
overdue = false
elseif task.recurMode == Task.RECUR_MODE.EVERY_N_DAYS then
overdue = currentDay ~= taskInfo.createdMarker
elseif task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS then
- overdue = currentPeriod ~= taskInfo.createdMarker
+ -- Active list = current occurrence; show overdue only after leaving the spawn period (valid marker).
+ local marker = taskInfo.createdMarker
+ if marker ~= nil and marker >= 1 and marker <= 12 then
+ overdue = currentPeriod ~= marker
+ else
+ overdue = false
+ end
+ else
+ overdue = task.period ~= currentPeriod
end
if task.type == Task.TASK_TYPE.HusbandryFood then overdue = true end
diff --git a/gui/guiProfiles.xml b/gui/guiProfiles.xml
index ad87501..3347dfe 100644
--- a/gui/guiProfiles.xml
+++ b/gui/guiProfiles.xml
@@ -58,4 +58,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/languages/l10n_de.xml b/languages/l10n_de.xml
index 00a1c8a..250d2e4 100644
--- a/languages/l10n_de.xml
+++ b/languages/l10n_de.xml
@@ -25,11 +25,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -37,11 +39,14 @@
-
-
+
+
+
+
+
@@ -54,7 +59,7 @@
-
+
@@ -76,10 +81,10 @@
-
-
+
+
-
+
@@ -87,18 +92,18 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
+
\ No newline at end of file
diff --git a/languages/l10n_en.xml b/languages/l10n_en.xml
index 292e041..9d385db 100644
--- a/languages/l10n_en.xml
+++ b/languages/l10n_en.xml
@@ -25,11 +25,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -37,11 +39,14 @@
-
-
+
+
+
+
+
@@ -54,7 +59,7 @@
-
+
@@ -76,10 +81,10 @@
-
-
+
+
-
+
@@ -87,18 +92,18 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
+
\ No newline at end of file
diff --git a/languages/l10n_es.xml b/languages/l10n_es.xml
index 79b8ea4..71ac0e1 100644
--- a/languages/l10n_es.xml
+++ b/languages/l10n_es.xml
@@ -25,11 +25,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -37,11 +39,14 @@
-
-
+
+
+
+
+
@@ -54,7 +59,7 @@
-
+
@@ -76,10 +81,10 @@
-
-
+
+
-
+
@@ -87,18 +92,18 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
+
\ No newline at end of file
diff --git a/languages/l10n_fr.xml b/languages/l10n_fr.xml
index e0860d3..513db70 100644
--- a/languages/l10n_fr.xml
+++ b/languages/l10n_fr.xml
@@ -25,11 +25,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -37,11 +39,14 @@
-
-
+
+
+
+
+
@@ -54,7 +59,7 @@
-
+
@@ -76,10 +81,10 @@
-
-
+
+
-
+
@@ -87,18 +92,18 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
+
\ No newline at end of file
diff --git a/languages/l10n_it.xml b/languages/l10n_it.xml
index 83e8c69..4a8a8ef 100644
--- a/languages/l10n_it.xml
+++ b/languages/l10n_it.xml
@@ -25,11 +25,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -37,11 +39,14 @@
-
-
+
+
+
+
+
@@ -54,7 +59,7 @@
-
+
@@ -76,10 +81,10 @@
-
-
+
+
-
+
@@ -87,18 +92,18 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
+
\ No newline at end of file
diff --git a/languages/l10n_nl.xml b/languages/l10n_nl.xml
index fa212cb..b400f56 100644
--- a/languages/l10n_nl.xml
+++ b/languages/l10n_nl.xml
@@ -25,11 +25,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -37,11 +39,14 @@
-
-
+
+
+
+
+
@@ -54,7 +59,7 @@
-
+
@@ -76,10 +81,10 @@
-
-
+
+
-
+
@@ -87,18 +92,18 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
+
\ No newline at end of file
diff --git a/languages/l10n_ru.xml b/languages/l10n_ru.xml
index b4512c4..01fed1c 100644
--- a/languages/l10n_ru.xml
+++ b/languages/l10n_ru.xml
@@ -25,11 +25,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -37,11 +39,14 @@
-
-
+
+
+
+
+
@@ -54,7 +59,7 @@
-
+
@@ -76,10 +81,10 @@
-
-
+
+
-
+
@@ -87,18 +92,18 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
+
\ No newline at end of file
diff --git a/languages/l10n_tr.xml b/languages/l10n_tr.xml
index e462465..729b47d 100644
--- a/languages/l10n_tr.xml
+++ b/languages/l10n_tr.xml
@@ -25,11 +25,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -37,11 +39,14 @@
-
-
+
+
+
+
+
@@ -54,7 +59,7 @@
-
+
@@ -76,10 +81,10 @@
-
-
+
+
-
+
@@ -87,18 +92,18 @@
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
+
\ No newline at end of file
diff --git a/main.lua b/main.lua
index 8478cc0..215fff7 100644
--- a/main.lua
+++ b/main.lua
@@ -20,6 +20,7 @@ source(TaskList.dir .. "TaskGroup.lua")
source(TaskList.dir .. "Task.lua")
source(TaskList.dir .. "gui/MenuTaskList.lua")
source(TaskList.dir .. "gui/ManageGroupsFrame.lua")
+source(TaskList.dir .. "gui/EditTaskFrame.lua")
source(TaskList.dir .. "gui/ManageTasksFrame.lua")
source(TaskList.dir .. "gui/tableRenderers/MonthlyTaskRenderer.lua")
source(TaskList.dir .. "events/InitialClientStateEvent.lua")
@@ -44,6 +45,9 @@ function TaskList:loadMap()
local manageGroupsFrame = ManageGroupsFrame.new(g_i18n)
g_gui:loadGui(TaskList.dir .. "gui/ManageGroupsFrame.xml", "manageGroupsFrame", manageGroupsFrame)
+ local editTaskFrame = EditTaskFrame.new(g_i18n)
+ g_gui:loadGui(TaskList.dir .. "gui/EditTaskFrame.xml", "editTaskFrame", editTaskFrame)
+
local manageTasksFrame = ManageTasksFrame.new(g_i18n)
g_gui:loadGui(TaskList.dir .. "gui/ManageTasksFrame.xml", "manageTasksFrame", manageTasksFrame)
@@ -140,7 +144,11 @@ function TaskList:loadFromXMLFile()
local groupId = getXMLString(xmlFile, activeTaskKey .. "#groupId")
local task = g_currentMission.taskList:addActiveTask(groupId, taskId)
if task ~= nil then
- task.createdMarker = getXMLInt(xmlFile, activeTaskKey .. "#createdMarker")
+ local marker = getXMLInt(xmlFile, activeTaskKey .. "#createdMarker")
+ if marker < 1 or marker > 12 then
+ marker = g_currentMission.environment.currentPeriod
+ end
+ task.createdMarker = marker
end
j = j + 1
end
@@ -508,6 +516,9 @@ function TaskList:currentMissionStarted()
-- self.activeTasks[activeTask.groupId .. "_" .. activeTask.id] = nil
-- end
-- end
+ g_currentMission.taskList:updateHusbandries()
+ g_currentMission.taskList:updateProductions()
+
g_currentMission.taskList:taskCleanup()
g_currentMission.taskList:addOrClearAutoTasks()
@@ -669,8 +680,8 @@ function TaskList:checkAndAddActiveTaskIfDue(group, task)
if task.recurMode == Task.RECUR_MODE.EVERY_N_DAYS or task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS then
if group.type == TaskGroup.GROUP_TYPE.Standard then
task.nextN = task.nextN + task.n
- if task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS and task.nextN > 12 then
- task.nextN = task.nextN - 12
+ if task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS then
+ task.nextN = TaskListUtils.normalizePeriod(task.nextN)
end
elseif group.type == TaskGroup.GROUP_TYPE.TemplateInstance then
if self.templateTasksAdded[group.templateGroupId] == nil then
@@ -690,8 +701,8 @@ function TaskList:updateTemplateAddedTasks()
for taskId, _ in pairs(tasks) do
local task = self.taskGroups[groupId].tasks[taskId]
task.nextN = task.nextN + task.n
- if task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS and task.nextN > 12 then
- task.nextN = task.nextN - 12
+ if task.recurMode == Task.RECUR_MODE.EVERY_N_MONTHS then
+ task.nextN = TaskListUtils.normalizePeriod(task.nextN)
end
end
end
@@ -791,10 +802,7 @@ function TaskList:getTasksForNextYear()
break
end
- local next = lastAdded + task.n
- if next > 12 then
- next = next - 12
- end
+ local next = TaskListUtils.normalizePeriod(lastAdded + task.n)
table.insert(result[next],
{ groupId = group.id, taskId = task.id, effort = effort, priority = task.priority })