feat(gui): fanen Måned — marker i gang med fremdrift, næste trin og om høst-/såvinduet lukker ved månedsskiftet; dom 'du kan sove' + marker der kan sås nu (v1.35.0.0)
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
-- Smart Pickup — fanen Måned
|
||||
-- Hvad skal nås før månedsskiftet? Høst og såning har korte vinduer; fanen viser markerne med arbejde i
|
||||
-- gang, fremdrift, næste trin og om vinduet lukker. Kun visning — reglerne ligger i ADMonthView.
|
||||
|
||||
-- Periodens navn: spillets egen tekst (fx "Sen sommer") hvis den findes, ellers "Periode 6".
|
||||
-- Periode 1 = tidligt forår = marts (nordlig halvkugle) -> "(aug)".
|
||||
function SmartPickupFrame:monthPeriodText(period)
|
||||
local month = (period + 1) % 12 + 1
|
||||
local names = {}
|
||||
for name in string.gmatch(self.i18n:getText("spu_month_months"), "[^,]+") do table.insert(names, name) end
|
||||
local suffix = names[month] ~= nil and (" (" .. names[month] .. ")") or ""
|
||||
local ok, text = pcall(function() return g_i18n:formatPeriod(period, false) end)
|
||||
if ok and type(text) == "string" and text ~= "" then return text .. suffix end
|
||||
return string.format(self.i18n:getText("spu_month_period"), period) .. suffix
|
||||
end
|
||||
|
||||
-- {period, day, days, hour, minute}; nil hvis miljøet ikke kan læses.
|
||||
function SmartPickupFrame.monthClock()
|
||||
local ok, clock = pcall(function()
|
||||
local environment = g_currentMission.environment
|
||||
local dayTime = environment.dayTime or 0
|
||||
return {period = environment.currentPeriod, day = environment.currentDayInPeriod, days = environment.daysPerPeriod,
|
||||
hour = math.floor(dayTime / 3600000), minute = math.floor(dayTime / 60000) % 60}
|
||||
end)
|
||||
if ok and type(clock) == "table" and type(clock.period) == "number" then return clock end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Courseplays fremdrift for markens sæt (gennemsnit), nil hvis ingen melder noget.
|
||||
function SmartPickupFrame.monthCpProgress(fieldId)
|
||||
local sum, count = 0, 0
|
||||
for _, assignment in ipairs(ADFieldJobs.assignmentsFor(fieldId)) do
|
||||
local vehicle = assignment.vehicle
|
||||
if not assignment.helper and vehicle ~= nil and vehicle.getCpFieldWorkProgress ~= nil then
|
||||
local ok, progress = pcall(vehicle.getCpFieldWorkProgress, vehicle)
|
||||
if ok and type(progress) == "number" then
|
||||
sum, count = sum + progress, count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return count > 0 and sum / count or nil
|
||||
end
|
||||
|
||||
function SmartPickupFrame.monthContext(period)
|
||||
return {
|
||||
period = period,
|
||||
plantableIn = function(name, forPeriod)
|
||||
local fruit = g_fruitTypeManager ~= nil and g_fruitTypeManager:getFruitTypeByName(name) or nil
|
||||
return fruit ~= nil and ADCpBridge.isPlantableIn(fruit, forPeriod)
|
||||
end,
|
||||
withers = function(info, nextPeriod)
|
||||
local fruit = info.fruitIndex ~= nil and g_fruitTypeManager:getFruitTypeByIndex(info.fruitIndex) or nil
|
||||
local ok, result = pcall(ADMonthView.withersIn, fruit, nextPeriod, info.growthState)
|
||||
return ok and result == true
|
||||
end,
|
||||
cpProgress = SmartPickupFrame.monthCpProgress,
|
||||
}
|
||||
end
|
||||
|
||||
function SmartPickupFrame:monthStageText(stage)
|
||||
if stage == nil then return "–" end
|
||||
return self.i18n:getText("spu_field_stage_" .. tostring(stage))
|
||||
end
|
||||
|
||||
function SmartPickupFrame:monthCells(row)
|
||||
local crop = row.sowFruit ~= nil and self:fruitTitle(row.sowFruit) or (row.crop or "")
|
||||
return {"F" .. tostring(row.id), self:monthStageText(row.stage), crop, ADMonthView.percentText(row.progress),
|
||||
self:monthStageText(row.nextStage), self.i18n:getText("spu_month_window_" .. row.window)}
|
||||
end
|
||||
|
||||
function SmartPickupFrame:fillMonthRows(adEnv)
|
||||
local i18n = self.i18n
|
||||
local clock = SmartPickupFrame.monthClock()
|
||||
if clock == nil then
|
||||
self:addTextRow(i18n:getText("spu_month_noClock"))
|
||||
return
|
||||
end
|
||||
self:addTextRow(string.format(i18n:getText("spu_month_header"), self:monthPeriodText(clock.period),
|
||||
clock.day or 1, clock.days or 1, clock.hour, clock.minute))
|
||||
local infos = ADFields.list()
|
||||
if #infos == 0 then
|
||||
self:addTextRow(i18n:getText("spu_field_scanning"))
|
||||
return
|
||||
end
|
||||
local view = ADMonthView.build(infos, ADFieldJobs.state.fields, SmartPickupFrame.monthContext(clock.period))
|
||||
if view.critical > 0 then
|
||||
self:addTextRow(string.format(i18n:getText("spu_month_verdictUrgent"), view.critical))
|
||||
else
|
||||
self:addTextRow(i18n:getText("spu_month_verdictCalm"))
|
||||
end
|
||||
if #view.rows == 0 then
|
||||
self:addTextRow(i18n:getText("spu_month_noWork"))
|
||||
else
|
||||
self:addCellRow(self.fieldPrefab, {i18n:getText("spu_col_field"), i18n:getText("spu_month_col_work"), i18n:getText("spu_col_crop"),
|
||||
i18n:getText("spu_month_col_progress"), i18n:getText("spu_month_col_next"), i18n:getText("spu_month_col_window")})
|
||||
for _, row in ipairs(view.rows) do
|
||||
self:addCellRow(self.fieldPrefab, self:monthCells(row))
|
||||
end
|
||||
end
|
||||
if #view.upcoming > 0 then
|
||||
self:addTextRow(i18n:getText("spu_month_upcoming"))
|
||||
for _, entry in ipairs(view.upcoming) do
|
||||
local key = entry.closes and "spu_month_upcomingLast" or "spu_month_upcomingOpen"
|
||||
self:addTextRow(string.format(i18n:getText(key), entry.id, self:fruitTitle(entry.fruit)))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user