Add a button to reset lobby options to default.

This commit is contained in:
Paul Chote
2023-11-11 22:56:21 +00:00
committed by Gustas
parent 9a3c39878d
commit 9d174cd87d
6 changed files with 86 additions and 1 deletions

View File

@@ -103,6 +103,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
bool insufficientPlayerSpawns;
bool teamChat;
bool updateDiscordStatus = true;
bool resetOptionsButtonEnabled;
Dictionary<int, SpawnOccupant> spawnOccupants = new();
readonly string chatLineSound;
@@ -167,6 +168,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.LobbyInfoChanged += UpdatePlayerList;
Game.LobbyInfoChanged += UpdateDiscordStatus;
Game.LobbyInfoChanged += UpdateSpawnOccupants;
Game.LobbyInfoChanged += UpdateOptions;
Game.BeforeGameStart += OnGameStart;
Game.ConnectionStateChanged += ConnectionStateChanged;
@@ -263,7 +265,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
if (slotsButton != null)
{
slotsButton.IsVisible = () => panel != PanelType.Servers;
slotsButton.IsVisible = () => panel != PanelType.Servers && panel != PanelType.Options;
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
(orderManager.LobbyInfo.Slots.Values.All(s => !s.AllowBots) &&
!orderManager.LobbyInfo.Slots.Any(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null));
@@ -357,6 +359,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
};
}
var resetOptionsButton = lobby.GetOrNull<ButtonWidget>("RESET_OPTIONS_BUTTON");
if (resetOptionsButton != null)
{
resetOptionsButton.IsVisible = () => panel == PanelType.Options;
resetOptionsButton.IsDisabled = () => configurationDisabled() || !resetOptionsButtonEnabled;
resetOptionsButton.OnMouseDown = _ => orderManager.IssueOrder(Order.Command("reset_options"));
}
var optionsBin = Ui.LoadWidget("LOBBY_OPTIONS_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()
{
{ "orderManager", orderManager },
@@ -910,6 +920,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
.ToDictionary(c => c.SpawnPoint, c => new SpawnOccupant(c));
}
void UpdateOptions()
{
if (map == null || map.WorldActorInfo == null)
return;
var serverOptions = orderManager.LobbyInfo.GlobalSettings.LobbyOptions;
var mapOptions = map.PlayerActorInfo.TraitInfos<ILobbyOptions>()
.Concat(map.WorldActorInfo.TraitInfos<ILobbyOptions>())
.SelectMany(t => t.LobbyOptions(map))
.Where(o => o.IsVisible)
.OrderBy(o => o.DisplayOrder)
.ToArray();
resetOptionsButtonEnabled = mapOptions.Any(o => o.DefaultValue != serverOptions[o.Id].Value);
}
void OnGameStart()
{
Ui.CloseWindow();