@@ -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