Add a button to reset lobby options to default.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user