Overhaul the lobby faction dropdown for ra
This commit is contained in:
@@ -49,7 +49,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
readonly Widget chatTemplate;
|
||||
|
||||
readonly ScrollPanelWidget players;
|
||||
readonly Dictionary<string, string> countryNames;
|
||||
|
||||
readonly Dictionary<string, LobbyCountry> countries = new Dictionary<string, LobbyCountry>();
|
||||
|
||||
readonly ColorPreviewManagerWidget colorPreview;
|
||||
|
||||
@@ -142,10 +143,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER");
|
||||
colorPreview.Color = Game.Settings.Player.Color;
|
||||
|
||||
countryNames = modRules.Actors["world"].Traits.WithInterface<CountryInfo>()
|
||||
.Where(c => c.Selectable)
|
||||
.ToDictionary(a => a.Race, a => a.Name);
|
||||
countryNames.Add("random", "Any");
|
||||
countries.Add("random", new LobbyCountry { Name = "Any" });
|
||||
foreach (var c in modRules.Actors["world"].Traits.WithInterface<CountryInfo>().Where(c => c.Selectable))
|
||||
countries.Add(c.Race, new LobbyCountry { Name = c.Name, Side = c.Side, Description = c.Description });
|
||||
|
||||
var gameStarting = false;
|
||||
Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting ||
|
||||
@@ -691,7 +691,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
|
||||
|
||||
LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, colorPreview);
|
||||
LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, countryNames);
|
||||
LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, countries);
|
||||
LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map);
|
||||
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, Map);
|
||||
LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, Map);
|
||||
@@ -707,7 +707,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
LobbyUtils.SetupKickWidget(template, slot, client, orderManager, lobby,
|
||||
() => panel = PanelType.Kick, () => panel = PanelType.Players);
|
||||
LobbyUtils.SetupColorWidget(template, slot, client);
|
||||
LobbyUtils.SetupFactionWidget(template, slot, client, countryNames);
|
||||
LobbyUtils.SetupFactionWidget(template, slot, client, countries);
|
||||
LobbyUtils.SetupTeamWidget(template, slot, client);
|
||||
LobbyUtils.SetupSpawnWidget(template, slot, client);
|
||||
LobbyUtils.SetupReadyWidget(template, slot, client);
|
||||
@@ -810,4 +810,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
public Action OnClick;
|
||||
}
|
||||
}
|
||||
|
||||
public class LobbyCountry
|
||||
{
|
||||
public string Name;
|
||||
public string Description;
|
||||
public string Side;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,21 +105,25 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
}
|
||||
|
||||
public static void ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client,
|
||||
OrderManager orderManager, Dictionary<string, string> countryNames)
|
||||
OrderManager orderManager, Dictionary<string, LobbyCountry> countries)
|
||||
{
|
||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (race, itemTemplate) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(itemTemplate,
|
||||
() => client.Country == race,
|
||||
() => orderManager.IssueOrder(Order.Command("race {0} {1}".F(client.Index, race))));
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => countryNames[race];
|
||||
var country = countries[race];
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => country.Name;
|
||||
var flag = item.Get<ImageWidget>("FLAG");
|
||||
flag.GetImageCollection = () => "flags";
|
||||
flag.GetImageName = () => race;
|
||||
item.GetTooltipText = () => country.Description;
|
||||
return item;
|
||||
};
|
||||
|
||||
dropdown.ShowDropDown("RACE_DROPDOWN_TEMPLATE", 150, countryNames.Keys, setupItem);
|
||||
var options = countries.GroupBy(c => c.Value.Side).ToDictionary(g => g.Key ?? "", g => g.Select(c => c.Key));
|
||||
|
||||
dropdown.ShowDropDown("RACE_DROPDOWN_TEMPLATE", 150, options, setupItem);
|
||||
}
|
||||
|
||||
public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client,
|
||||
@@ -389,21 +393,25 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
color.GetColor = () => c.Color.RGB;
|
||||
}
|
||||
|
||||
public static void SetupEditableFactionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, Dictionary<string,string> countryNames)
|
||||
public static void SetupEditableFactionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager,
|
||||
Dictionary<string, LobbyCountry> countries)
|
||||
{
|
||||
var dropdown = parent.Get<DropDownButtonWidget>("FACTION");
|
||||
dropdown.IsDisabled = () => s.LockRace || orderManager.LocalClient.IsReady;
|
||||
dropdown.OnMouseDown = _ => ShowRaceDropDown(dropdown, c, orderManager, countryNames);
|
||||
SetupFactionWidget(dropdown, s, c, countryNames);
|
||||
dropdown.OnMouseDown = _ => ShowRaceDropDown(dropdown, c, orderManager, countries);
|
||||
var factionDescription = countries[c.Country].Description;
|
||||
dropdown.GetTooltipText = () => factionDescription;
|
||||
SetupFactionWidget(dropdown, s, c, countries);
|
||||
}
|
||||
|
||||
public static void SetupFactionWidget(Widget parent, Session.Slot s, Session.Client c, Dictionary<string,string> countryNames)
|
||||
public static void SetupFactionWidget(Widget parent, Session.Slot s, Session.Client c,
|
||||
Dictionary<string, LobbyCountry> countries)
|
||||
{
|
||||
var factionname = parent.Get<LabelWidget>("FACTIONNAME");
|
||||
factionname.GetText = () => countryNames[c.Country];
|
||||
var factionflag = parent.Get<ImageWidget>("FACTIONFLAG");
|
||||
factionflag.GetImageName = () => c.Country;
|
||||
factionflag.GetImageCollection = () => "flags";
|
||||
var factionName = parent.Get<LabelWidget>("FACTIONNAME");
|
||||
factionName.GetText = () => countries[c.Country].Name;
|
||||
var factionFlag = parent.Get<ImageWidget>("FACTIONFLAG");
|
||||
factionFlag.GetImageName = () => c.Country;
|
||||
factionFlag.GetImageCollection = () => "flags";
|
||||
}
|
||||
|
||||
public static void SetupEditableTeamWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
|
||||
|
||||
Reference in New Issue
Block a user