feat(gui): fanen Marksiloer — til/fra, maks. vogne, mindste mængde, gårdlagre, status pr. silo (v1.36.0.0)
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
-- Smart Pickup — fanen Marksiloer
|
||||
-- Opsætning (til/fra, maks. vogne, mindste mængde, gårdlagre) og status for marksilo-flowet.
|
||||
-- Klik går til onClickFieldSiloRow; reglerne ligger i ADFieldSilos/ADFieldSiloPlanner.
|
||||
|
||||
SmartPickupFrame.FIELDSILO_ROW_KINDS = {fsEnabled = true, fsMaxVehicles = true, fsMinLiters = true, fsStore = true}
|
||||
|
||||
local function numberTexts(from, to)
|
||||
local texts = {}
|
||||
for n = from, to do table.insert(texts, tostring(n)) end
|
||||
return texts
|
||||
end
|
||||
|
||||
local function literTexts()
|
||||
local texts = {}
|
||||
for _, liters in ipairs(ADFieldSiloConfig.MIN_LITERS_CHOICES) do table.insert(texts, string.format("%d l", liters)) end
|
||||
return texts
|
||||
end
|
||||
|
||||
local function indexOf(list, value)
|
||||
for index, entry in ipairs(list) do if entry == value then return index end end
|
||||
return 1
|
||||
end
|
||||
|
||||
function SmartPickupFrame:fillFieldSiloRows(adEnv)
|
||||
local i18n, cfg = self.i18n, ADFieldSilos.config
|
||||
local onOff = {i18n:getText("ui_no"), i18n:getText("ui_yes")}
|
||||
self:addToggleRow("fsEnabled", i18n:getText("spu_fs_enabled"), onOff, cfg.enabled)
|
||||
local maxOption = self:addToggleRow("fsMaxVehicles", i18n:getText("spu_fs_maxVehicles"), numberTexts(1, ADFieldSiloConfig.MAX_VEHICLES), false)
|
||||
maxOption:setState(cfg.maxVehicles, false)
|
||||
local minOption = self:addToggleRow("fsMinLiters", i18n:getText("spu_fs_minLiters"), literTexts(), false)
|
||||
minOption:setState(indexOf(ADFieldSiloConfig.MIN_LITERS_CHOICES, cfg.minLiters), false)
|
||||
|
||||
local plan = ADFieldSilos.lastPlan
|
||||
local waiting = 0
|
||||
for _, entry in ipairs(plan ~= nil and plan.status or {}) do if entry.state == "ok" then waiting = waiting + 1 end end
|
||||
self:addTextRow(string.format(i18n:getText("spu_fs_status"), ADFieldSilos.loanCount(), cfg.maxVehicles, waiting))
|
||||
if #cfg.storeIds == 0 then self:addTextRow(i18n:getText("spu_fs_noStores")) end
|
||||
|
||||
self:addTextRow(i18n:getText("spu_fs_silosTitle"))
|
||||
if plan == nil or #plan.status == 0 then
|
||||
self:addTextRow(" " .. i18n:getText("spu_fs_nothing"))
|
||||
else
|
||||
self:addCellRow(self.fieldPrefab, {i18n:getText("spu_fs_col_silo"), i18n:getText("spu_col_crop"), i18n:getText("spu_fs_col_liters"),
|
||||
i18n:getText("spu_fs_col_onWay"), i18n:getText("spu_fs_col_state"), ""})
|
||||
for _, entry in ipairs(plan.status) do
|
||||
local desc = g_fillTypeManager:getFillTypeByIndex(entry.fillType)
|
||||
local title = desc ~= nil and (desc.title or desc.name) or tostring(entry.fillType)
|
||||
local state = i18n:getText("spu_fs_state_" .. entry.state)
|
||||
if entry.state == "noFarmStore" then state = string.format(state, title) end
|
||||
self:addCellRow(self.fieldPrefab, {tostring(entry.siloName), title, string.format("%d", math.floor(entry.liters)),
|
||||
string.format("%d", math.floor(entry.onWay)), state, ""})
|
||||
end
|
||||
end
|
||||
|
||||
self:addTextRow(i18n:getText("spu_fs_storesTitle"))
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, farmId)) do
|
||||
if building.kind == "silo" then
|
||||
local option = self:addToggleRow("fsStore", tostring(building.name), onOff, ADFieldSiloConfig.hasStore(cfg, building.id))
|
||||
self.rowData[option] = {kind = "fsStore", buildingId = building.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SmartPickupFrame:onClickFieldSiloRow(state, data)
|
||||
self:safe(function(frame)
|
||||
local cfg = ADFieldSilos.config
|
||||
if data.kind == "fsEnabled" then
|
||||
cfg = ADFieldSiloConfig.with(cfg, {enabled = state == SmartPickupFrame.STATE_ON})
|
||||
elseif data.kind == "fsMaxVehicles" then
|
||||
cfg = ADFieldSiloConfig.with(cfg, {maxVehicles = state})
|
||||
elseif data.kind == "fsMinLiters" then
|
||||
cfg = ADFieldSiloConfig.with(cfg, {minLiters = ADFieldSiloConfig.MIN_LITERS_CHOICES[state]})
|
||||
elseif data.kind == "fsStore" then
|
||||
cfg = ADFieldSiloConfig.toggleStore(cfg, data.buildingId)
|
||||
end
|
||||
ADFieldSilos.setConfig(cfg)
|
||||
pcall(ADFieldSilos.save)
|
||||
local adEnv = frame.getAdEnv()
|
||||
if adEnv ~= nil then pcall(ADFieldSilos.planNow, adEnv) end
|
||||
frame:requestRebuild()
|
||||
end)
|
||||
end
|
||||
Reference in New Issue
Block a user