feat: slagtesalg pr. stald fordelt over måneder + fast traktor; ingen global dyre-indstilling
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
-- ("som globalt" = ingen egen værdi). Nye nøgler i ADSettings.KEYS (med choices) dukker op af sig selv.
|
||||
-- Klik går til onClickSettingsRow.
|
||||
|
||||
SmartPickupFrame.SETTINGS_ROW_KINDS = {setGlobal = true, setBuilding = true}
|
||||
SmartPickupFrame.SETTINGS_ROW_KINDS = {setGlobal = true, setBuilding = true, setBarnOnly = true, lockTractor = true}
|
||||
|
||||
local function choiceTexts(spec, i18n, withGlobal)
|
||||
local texts = {}
|
||||
@@ -50,8 +50,11 @@ function SmartPickupFrame:fillSettingsRows(adEnv)
|
||||
self:addTextRow(i18n:getText("spu_set_globalTitle"))
|
||||
for _, key in ipairs(keys) do
|
||||
local spec = ADSettings.KEYS[key]
|
||||
local option = self:addFieldSiloChoiceRow("setGlobal", keyTitle(i18n, key), choiceTexts(spec, i18n, false), choiceIndex(spec, ADSettings.get(key)))
|
||||
self.rowData[option] = {kind = "setGlobal", key = key}
|
||||
-- kun pr. stald (barnOnly): ingen global række
|
||||
if not spec.barnOnly then
|
||||
local option = self:addFieldSiloChoiceRow("setGlobal", keyTitle(i18n, key), choiceTexts(spec, i18n, false), choiceIndex(spec, ADSettings.get(key)))
|
||||
self.rowData[option] = {kind = "setGlobal", key = key}
|
||||
end
|
||||
end
|
||||
self:addTextRow(i18n:getText("spu_set_globalHelp"))
|
||||
|
||||
@@ -74,19 +77,72 @@ function SmartPickupFrame:fillSettingsRows(adEnv)
|
||||
self:addTextRow(string.format(i18n:getText("spu_set_perBarnTitle"), keyTitle(i18n, key)))
|
||||
for _, barn in ipairs(barns) do
|
||||
local own = ADSettings.getOwn(key, barn.id)
|
||||
local state = own ~= nil and (choiceIndex(spec, own) + 1) or 1
|
||||
local option = self:addFieldSiloChoiceRow("setBuilding", tostring(barn.name), choiceTexts(spec, i18n, true), state)
|
||||
self.rowData[option] = {kind = "setBuilding", key = key, buildingId = barn.id}
|
||||
if spec.barnOnly then
|
||||
-- kun staldens egen værdi (ingen "som global"): valgene direkte, intet valgt = standard (fra)
|
||||
local option = self:addFieldSiloChoiceRow("setBuilding", tostring(barn.name), choiceTexts(spec, i18n, false), choiceIndex(spec, own))
|
||||
self.rowData[option] = {kind = "setBarnOnly", key = key, buildingId = barn.id}
|
||||
else
|
||||
local state = own ~= nil and (choiceIndex(spec, own) + 1) or 1
|
||||
local option = self:addFieldSiloChoiceRow("setBuilding", tostring(barn.name), choiceTexts(spec, i18n, true), state)
|
||||
self.rowData[option] = {kind = "setBuilding", key = key, buildingId = barn.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self:fillLivestockTractorRows(adEnv, animalBarns)
|
||||
end
|
||||
|
||||
-- Fast traktor til slagtedyr pr. stald (kun stalde med salget slået til): "ledig traktor" eller en bestemt traktor
|
||||
function SmartPickupFrame:fillLivestockTractorRows(adEnv, animalBarns)
|
||||
if ADLivestock == nil or ADLivestock.setLock == nil then return end
|
||||
local i18n = self.i18n
|
||||
local selling = {}
|
||||
for _, barn in ipairs(animalBarns) do
|
||||
if ADSettings.getOwn("sellReadyAnimals", barn.id) == 1 then table.insert(selling, barn) end
|
||||
end
|
||||
if #selling == 0 then return end
|
||||
local tractors = {}
|
||||
for _, vehicle in ipairs(ADRunsController.getFarmVehicles(adEnv) or {}) do
|
||||
local id = ADRunsController.getVehicleId(vehicle)
|
||||
if id ~= nil and vehicle.spec_attacherJoints ~= nil and vehicle.spec_combine == nil and vehicle.spec_dischargeable == nil then
|
||||
table.insert(tractors, {id = id, name = tostring(ADRuns.vehicleLabel(vehicle))})
|
||||
end
|
||||
end
|
||||
table.sort(tractors, function(a, b) return a.name < b.name end)
|
||||
self:addTextRow(i18n:getText("spu_set_livestockTractorTitle"))
|
||||
for _, barn in ipairs(selling) do
|
||||
local texts, ids, state = {i18n:getText("spu_set_livestockTractorAny")}, {false}, 1
|
||||
local locked = ADLivestock.getLock(barn.id)
|
||||
for _, tractor in ipairs(tractors) do
|
||||
table.insert(texts, tractor.name)
|
||||
table.insert(ids, tractor.id)
|
||||
if tractor.id == locked then state = #texts end
|
||||
end
|
||||
-- låst traktor findes ikke længere (solgt/ukendt): vis det, så låsen kan ses og slås fra (review)
|
||||
if locked ~= nil and state == 1 then
|
||||
table.insert(texts, i18n:getText("spu_set_livestockTractorMissing"))
|
||||
table.insert(ids, locked)
|
||||
state = #texts
|
||||
end
|
||||
local option = self:addFieldSiloChoiceRow("setBuilding", tostring(barn.name), texts, state)
|
||||
self.rowData[option] = {kind = "lockTractor", buildingId = barn.id, ids = ids}
|
||||
end
|
||||
end
|
||||
|
||||
function SmartPickupFrame:onClickSettingsRow(state, data)
|
||||
self:safe(function(frame)
|
||||
if data.kind == "lockTractor" then
|
||||
local id = data.ids[state]
|
||||
ADLivestock.setLock(data.buildingId, id ~= false and id or nil)
|
||||
pcall(ADLivestock.save)
|
||||
frame:requestRebuild()
|
||||
return
|
||||
end
|
||||
local spec = ADSettings.KEYS[data.key]
|
||||
if spec == nil then return end
|
||||
if data.kind == "setGlobal" then
|
||||
if data.kind == "setBarnOnly" then
|
||||
ADSettings.set(data.key, spec.choices[state], data.buildingId)
|
||||
elseif data.kind == "setGlobal" then
|
||||
ADSettings.set(data.key, spec.choices[state], nil)
|
||||
elseif data.kind == "setBuilding" then
|
||||
if state == 1 then
|
||||
|
||||
Reference in New Issue
Block a user