Skip to content

Commit 7db6e3a

Browse files
committed
subfaction side filtering
1 parent b2d8a04 commit 7db6e3a

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ protected override void TraitEnabled(Actor self)
6868
if (!allowSpawn)
6969
return;
7070

71+
if (!self.IsInWorld || self.Disposed)
72+
return;
73+
7174
allowSpawn = Info.AllowRespawn;
7275

7376
var td = new TypeDictionary

OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,32 @@ ScrollItemWidget SetupItem(string factionId, ScrollItemWidget itemTemplate)
237237
return item;
238238
}
239239

240-
var options = factions.Where(f => f.Value.Selectable).GroupBy(f => f.Value.Side)
240+
var selectableFactions = factions.Where(f => f.Value.Selectable).ToList();
241+
242+
string selectedSide = null;
243+
if (client != null && !string.IsNullOrEmpty(client.Faction))
244+
{
245+
if (!factions.TryGetValue(client.Faction, out var selectedFaction))
246+
{
247+
var fallback = factions.FirstOrDefault(f => string.Equals(f.Key, client.Faction, StringComparison.OrdinalIgnoreCase));
248+
selectedFaction = fallback.Value;
249+
}
250+
251+
selectedSide = selectedFaction?.Side;
252+
}
253+
254+
IEnumerable<KeyValuePair<string, LobbyFaction>> filteredFactions = selectableFactions;
255+
if (!string.IsNullOrEmpty(selectedSide) && !selectedSide.Equals("Random", StringComparison.OrdinalIgnoreCase))
256+
{
257+
var restricted = selectableFactions
258+
.Where(f => string.Equals(f.Value.Side, selectedSide, StringComparison.OrdinalIgnoreCase))
259+
.ToList();
260+
261+
if (restricted.Count > 0)
262+
filteredFactions = restricted;
263+
}
264+
265+
var options = filteredFactions.GroupBy(f => f.Value.Side)
241266
.ToDictionary(g => g.Key != null ? FluentProvider.GetMessage(g.Key) : "", g => g.Select(f => FluentProvider.GetMessage(f.Key)));
242267

243268
dropdown.ShowDropDown("FACTION_DROPDOWN_TEMPLATE", 154, options, SetupItem);

0 commit comments

Comments
 (0)