fix(gui): bygningsrækker i fast rækkefølge (navn, så markør) — et tryk flyttede valgte drops op i toppen; fjernet bygning vises som 'Fjernet bygning' i stedet for rå id (v1.28.4.0)
This commit is contained in:
@@ -101,18 +101,27 @@ end
|
||||
-- Bygninger: buildings = {{id, name, hasMarker}}, chosen = {[id] = true}. Valgte først; bygninger uden
|
||||
-- markør kun hvis valgte eller showAll (de kan alligevel ikke bruges før en markør er sat).
|
||||
function ADFlowView.buildingRows(buildings, chosen, showAll)
|
||||
local picked, withMarker, withoutMarker = {}, {}, {}
|
||||
local shown, withoutMarker = {}, {}
|
||||
for _, building in ipairs(buildings or {}) do
|
||||
if chosen ~= nil and chosen[building.id] then
|
||||
table.insert(picked, building)
|
||||
elseif building.hasMarker then
|
||||
table.insert(withMarker, building)
|
||||
if (chosen ~= nil and chosen[building.id]) or building.hasMarker then
|
||||
table.insert(shown, building)
|
||||
elseif showAll then
|
||||
table.insert(withoutMarker, building)
|
||||
end
|
||||
end
|
||||
-- fast rækkefølge: bygningsnavn, så markørnavn (label) — et tryk må ikke flytte rækken under markøren
|
||||
local function byNameThenLabel(list)
|
||||
local copy = {}
|
||||
for _, item in ipairs(list) do table.insert(copy, item) end
|
||||
table.sort(copy, function(a, b)
|
||||
if a.name ~= b.name then return ADFlowView.naturalLess(a.name, b.name) end
|
||||
if (a.label or "") ~= (b.label or "") then return ADFlowView.naturalLess(a.label or "", b.label or "") end
|
||||
return tostring(a.id) < tostring(b.id)
|
||||
end)
|
||||
return copy
|
||||
end
|
||||
local rows = {}
|
||||
for _, list in ipairs({sortedBy(picked, "name"), sortedBy(withMarker, "name"), sortedBy(withoutMarker, "name")}) do
|
||||
for _, list in ipairs({byNameThenLabel(shown), byNameThenLabel(withoutMarker)}) do
|
||||
for _, building in ipairs(list) do table.insert(rows, building) end
|
||||
end
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user