feat: fanen Indstillinger (ADSettings globalt + pr. stald) (v1.62.140)
This commit is contained in:
@@ -10,7 +10,8 @@ ADSettings.LOG_PREFIX = "ADSmartPickup: indstilling: "
|
||||
|
||||
-- nøgle -> {default, min, max, text}. Nye indstillinger tilføjes her, så de får standardværdi, grænser og hjælpetekst.
|
||||
ADSettings.KEYS = {
|
||||
stableSiloRange = {default = 80, min = 10, max = 500, text = "m: en silo inden for denne afstand af en stald er staldens egen silo (forsyning henter der først)"},
|
||||
stableSiloRange = {default = 80, min = 10, max = 500, perBuilding = true, choices = {40, 60, 80, 100, 120, 150, 200, 300}, format = "%s m",
|
||||
text = "m: en silo inden for denne afstand af en stald er staldens egen silo (forsyning henter der først)"},
|
||||
}
|
||||
|
||||
local values = {global = {}, byBuilding = {}}
|
||||
@@ -51,6 +52,17 @@ function ADSettings.set(key, value, buildingId)
|
||||
return clamped
|
||||
end
|
||||
|
||||
-- Bygningens egen værdi (nil = ingen, så den globale gælder).
|
||||
function ADSettings.getOwn(key, buildingId)
|
||||
local own = buildingId ~= nil and values.byBuilding[buildingId] or nil
|
||||
return own ~= nil and own[key] or nil
|
||||
end
|
||||
|
||||
function ADSettings.clear(key, buildingId)
|
||||
if buildingId == nil then values.global[key] = nil
|
||||
elseif values.byBuilding[buildingId] ~= nil then values.byBuilding[buildingId][key] = nil end
|
||||
end
|
||||
|
||||
function ADSettings.snapshot() return values end
|
||||
function ADSettings.restore(snapshot) values = snapshot or {global = {}, byBuilding = {}} end
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ if ADSmartPickup.dir ~= nil and source ~= nil then
|
||||
source(ADSmartPickup.dir .. "gui/SmartPickupFieldTab.lua")
|
||||
source(ADSmartPickup.dir .. "gui/SmartPickupMonthTab.lua")
|
||||
source(ADSmartPickup.dir .. "gui/SmartPickupFieldSiloTab.lua")
|
||||
source(ADSmartPickup.dir .. "gui/SmartPickupSettingsTab.lua")
|
||||
source(ADSmartPickup.dir .. "gui/SmartPickupChainTab.lua")
|
||||
source(ADSmartPickup.dir .. "gui/SmartPickupGuide.lua")
|
||||
source(ADSmartPickup.dir .. "gui/SmartPickupFieldGuide.lua")
|
||||
|
||||
@@ -18,11 +18,12 @@ SmartPickupFrame.MONTH_REBUILD_TICKS = 5
|
||||
SmartPickupFrame.FIELDSILO_REBUILD_TICKS = 30
|
||||
-- Kæder-fanen (gui/SmartPickupChainTab.lua): klikbare forslag/pause, så genopbygning sjældent (som Marksiloer)
|
||||
SmartPickupFrame.TAB_CHAINS = 10
|
||||
SmartPickupFrame.TAB_SETTINGS = 11
|
||||
SmartPickupFrame.CHAIN_REBUILD_TICKS = 30
|
||||
-- Lagerfaner: én pr. bygningstype (indeks -> kind i ADSources.getFarmInventory)
|
||||
SmartPickupFrame.TAB_NAMES = {"spu_tab_overview", "spu_tab_flows", "spu_tab_fields", "spu_tab_month", "spu_tab_fieldsilos", "spu_tab_factories", "spu_tab_silos", "spu_tab_barns", "spu_tab_sheds", "spu_tab_chains"}
|
||||
SmartPickupFrame.TAB_NAMES = {"spu_tab_overview", "spu_tab_flows", "spu_tab_fields", "spu_tab_month", "spu_tab_fieldsilos", "spu_tab_factories", "spu_tab_silos", "spu_tab_barns", "spu_tab_sheds", "spu_tab_chains", "spu_tab_settings"}
|
||||
-- Visningsrækkefølge (fane-id'erne ovenfor er faste og bruges overalt): Kæder står efter Marker (in-game 30/9).
|
||||
SmartPickupFrame.TAB_DISPLAY = {1, 2, 3, 10, 4, 5, 6, 7, 8, 9}
|
||||
SmartPickupFrame.TAB_DISPLAY = {1, 2, 3, 10, 4, 5, 6, 7, 8, 9, 11}
|
||||
function SmartPickupFrame.tabPosition(tabId)
|
||||
for position, id in ipairs(SmartPickupFrame.TAB_DISPLAY) do
|
||||
if id == tabId then return position end
|
||||
@@ -474,6 +475,14 @@ function SmartPickupFrame:rebuild()
|
||||
self:restoreFocusIfLost()
|
||||
return
|
||||
end
|
||||
if self.currentTab == SmartPickupFrame.TAB_SETTINGS then
|
||||
if adEnv ~= nil then self:fillSettingsRows(adEnv) end
|
||||
self:colorRows()
|
||||
self.boxLayout:invalidateLayout()
|
||||
self:refreshButtons()
|
||||
self:restoreFocusIfLost()
|
||||
return
|
||||
end
|
||||
if self.currentTab == SmartPickupFrame.TAB_FIELDSILOS then
|
||||
if adEnv ~= nil then
|
||||
self:fillFieldSiloRows(adEnv)
|
||||
@@ -685,7 +694,7 @@ function SmartPickupFrame:refreshButtons()
|
||||
elseif self.currentTab == SmartPickupFrame.TAB_FIELDS then
|
||||
wanted = self:getFieldButtons()
|
||||
elseif self.currentTab == SmartPickupFrame.TAB_MONTH or self.currentTab == SmartPickupFrame.TAB_FIELDSILOS
|
||||
or self.currentTab == SmartPickupFrame.TAB_CHAINS then
|
||||
or self.currentTab == SmartPickupFrame.TAB_CHAINS or self.currentTab == SmartPickupFrame.TAB_SETTINGS then
|
||||
wanted = self.monthButtons
|
||||
elseif SmartPickupFrame.getTabKind(self.currentTab) ~= nil then
|
||||
wanted = self.storageButtons
|
||||
@@ -711,7 +720,7 @@ function SmartPickupFrame:refreshLive()
|
||||
return
|
||||
end
|
||||
if self.currentTab == SmartPickupFrame.TAB_MONTH or self.currentTab == SmartPickupFrame.TAB_FIELDSILOS
|
||||
or self.currentTab == SmartPickupFrame.TAB_CHAINS then
|
||||
or self.currentTab == SmartPickupFrame.TAB_CHAINS or self.currentTab == SmartPickupFrame.TAB_SETTINGS then
|
||||
if self.currentTab == SmartPickupFrame.TAB_CHAINS then
|
||||
-- "forslaget gælder ikke længere" står STATUS_OVERRIDE_TICKS sekunder
|
||||
self.statusOverrideTicks = (self.statusOverrideTicks or 0) - 1
|
||||
@@ -816,6 +825,8 @@ function SmartPickupFrame:onClickIngredient(state, element)
|
||||
return self:onClickGuideRow(state, data)
|
||||
elseif data ~= nil and SmartPickupFrame.FIELDSILO_ROW_KINDS ~= nil and SmartPickupFrame.FIELDSILO_ROW_KINDS[data.kind] then
|
||||
return self:onClickFieldSiloRow(state, data)
|
||||
elseif data ~= nil and SmartPickupFrame.SETTINGS_ROW_KINDS ~= nil and SmartPickupFrame.SETTINGS_ROW_KINDS[data.kind] then
|
||||
return self:onClickSettingsRow(state, data)
|
||||
elseif data ~= nil and SmartPickupFrame.FIELD_ROW_KINDS[data.kind] then
|
||||
return self:onClickFieldRow(state, data)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
-- Smart Pickup — fanen Indstillinger
|
||||
-- Moddens justeringer (ADSettings): én række pr. nøgle globalt, og pr. stald en række der kan afvige fra det globale
|
||||
-- ("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}
|
||||
|
||||
local function choiceTexts(spec, i18n, withGlobal)
|
||||
local texts = {}
|
||||
if withGlobal then table.insert(texts, i18n:getText("spu_set_asGlobal")) end
|
||||
for _, value in ipairs(spec.choices or {}) do
|
||||
table.insert(texts, string.format(spec.format or "%s", tostring(value)))
|
||||
end
|
||||
return texts
|
||||
end
|
||||
|
||||
local function choiceIndex(spec, value)
|
||||
local best, bestDiff = 1, math.huge
|
||||
for index, choice in ipairs(spec.choices or {}) do
|
||||
local diff = math.abs(choice - (value or spec.default))
|
||||
if diff < bestDiff then best, bestDiff = index, diff end
|
||||
end
|
||||
return best
|
||||
end
|
||||
|
||||
local function keyTitle(i18n, key)
|
||||
local text = i18n:getText("spu_set_" .. key)
|
||||
if text == nil or text == "" or text == ("spu_set_" .. key) then return key end
|
||||
return text
|
||||
end
|
||||
|
||||
local function sortedKeys()
|
||||
local keys = {}
|
||||
for key, spec in pairs(ADSettings.KEYS) do
|
||||
if spec.choices ~= nil then table.insert(keys, key) end
|
||||
end
|
||||
table.sort(keys)
|
||||
return keys
|
||||
end
|
||||
|
||||
function SmartPickupFrame:fillSettingsRows(adEnv)
|
||||
local i18n = self.i18n
|
||||
if ADSettings == nil then
|
||||
self:addTextRow("ADSettings mangler")
|
||||
return
|
||||
end
|
||||
local keys = sortedKeys()
|
||||
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}
|
||||
end
|
||||
self:addTextRow(i18n:getText("spu_set_globalHelp"))
|
||||
|
||||
-- pr. stald: kun nøgler med perBuilding = true
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local barns = {}
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, farmId) or {}) do
|
||||
if building.kind == "husbandry" then table.insert(barns, building) end
|
||||
end
|
||||
table.sort(barns, function(a, b) return tostring(a.name) < tostring(b.name) end)
|
||||
for _, key in ipairs(keys) do
|
||||
local spec = ADSettings.KEYS[key]
|
||||
if spec.perBuilding and #barns > 0 then
|
||||
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}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SmartPickupFrame:onClickSettingsRow(state, data)
|
||||
self:safe(function(frame)
|
||||
local spec = ADSettings.KEYS[data.key]
|
||||
if spec == nil then return end
|
||||
if data.kind == "setGlobal" then
|
||||
ADSettings.set(data.key, spec.choices[state], nil)
|
||||
elseif data.kind == "setBuilding" then
|
||||
if state == 1 then
|
||||
ADSettings.clear(data.key, data.buildingId)
|
||||
else
|
||||
ADSettings.set(data.key, spec.choices[state - 1], data.buildingId)
|
||||
end
|
||||
end
|
||||
pcall(ADSettings.save)
|
||||
frame:requestRebuild()
|
||||
end)
|
||||
end
|
||||
@@ -539,6 +539,12 @@
|
||||
<text name="spu_guide_flow_sumNoTractors" text="ingen"/>
|
||||
<text name="spu_guide_flow_sumTractors" text="%d traktorer"/>
|
||||
<text name="spu_tab_fieldsilos" text="Marksiloer"/>
|
||||
<text name="spu_tab_settings" text="Indstillinger"/>
|
||||
<text name="spu_set_globalTitle" text="Gælder hele gården"/>
|
||||
<text name="spu_set_globalHelp" text="Pr. stald nedenfor: "som globalt" bruger værdien ovenfor."/>
|
||||
<text name="spu_set_perBarnTitle" text="%s — pr. stald"/>
|
||||
<text name="spu_set_asGlobal" text="som globalt"/>
|
||||
<text name="spu_set_stableSiloRange" text="Stald-silo: afstand fra stald til egen silo"/>
|
||||
<text name="spu_fs_enabled" text="Hent marksiloer hjem automatisk"/>
|
||||
<text name="spu_fs_maxVehicles" text="Maks. vogne ude"/>
|
||||
<text name="spu_fs_minLiters" text="Mindste mængde pr. vare"/>
|
||||
|
||||
@@ -539,6 +539,12 @@
|
||||
<text name="spu_guide_flow_sumNoTractors" text="none"/>
|
||||
<text name="spu_guide_flow_sumTractors" text="%d tractors"/>
|
||||
<text name="spu_tab_fieldsilos" text="Field silos"/>
|
||||
<text name="spu_tab_settings" text="Settings"/>
|
||||
<text name="spu_set_globalTitle" text="Whole farm"/>
|
||||
<text name="spu_set_globalHelp" text="Per barn below: "as global" uses the value above."/>
|
||||
<text name="spu_set_perBarnTitle" text="%s — per barn"/>
|
||||
<text name="spu_set_asGlobal" text="as global"/>
|
||||
<text name="spu_set_stableSiloRange" text="Barn silo: distance from barn to its own silo"/>
|
||||
<text name="spu_fs_enabled" text="Bring field silos home automatically"/>
|
||||
<text name="spu_fs_maxVehicles" text="Max. vehicles out"/>
|
||||
<text name="spu_fs_minLiters" text="Minimum amount per product"/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.139.0</version>
|
||||
<version>1.62.140.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user