Add a button to reset lobby options to default.
This commit is contained in:
@@ -177,6 +177,7 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
{ "slot_bot", SlotBot },
|
{ "slot_bot", SlotBot },
|
||||||
{ "map", Map },
|
{ "map", Map },
|
||||||
{ "option", Option },
|
{ "option", Option },
|
||||||
|
{ "reset_options", ResetOptions },
|
||||||
{ "assignteams", AssignTeams },
|
{ "assignteams", AssignTeams },
|
||||||
{ "kick", Kick },
|
{ "kick", Kick },
|
||||||
{ "vote_kick", VoteKick },
|
{ "vote_kick", VoteKick },
|
||||||
@@ -744,6 +745,49 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ResetOptions(S server, Connection conn, Session.Client client, string s)
|
||||||
|
{
|
||||||
|
lock (server.LobbyInfo)
|
||||||
|
{
|
||||||
|
if (!client.IsAdmin)
|
||||||
|
{
|
||||||
|
server.SendLocalizedMessageTo(conn, NotAdmin);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var allOptions = server.Map.PlayerActorInfo.TraitInfos<ILobbyOptions>()
|
||||||
|
.Concat(server.Map.WorldActorInfo.TraitInfos<ILobbyOptions>())
|
||||||
|
.SelectMany(t => t.LobbyOptions(server.Map));
|
||||||
|
|
||||||
|
var options = new Dictionary<string, Session.LobbyOptionState>();
|
||||||
|
foreach (var o in allOptions)
|
||||||
|
{
|
||||||
|
if (o.DefaultValue != server.LobbyInfo.GlobalSettings.LobbyOptions[o.Id].Value)
|
||||||
|
server.SendLocalizedMessage(ValueChanged, Translation.Arguments(
|
||||||
|
"player", client.Name,
|
||||||
|
"name", o.Name,
|
||||||
|
"value", o.Label(o.DefaultValue)));
|
||||||
|
|
||||||
|
options[o.Id] = new Session.LobbyOptionState
|
||||||
|
{
|
||||||
|
IsLocked = o.IsLocked,
|
||||||
|
Value = o.DefaultValue,
|
||||||
|
PreferredValue = o.DefaultValue
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
server.LobbyInfo.GlobalSettings.LobbyOptions = options;
|
||||||
|
server.SyncLobbyGlobalSettings();
|
||||||
|
|
||||||
|
foreach (var c in server.LobbyInfo.Clients)
|
||||||
|
c.State = Session.ClientState.NotReady;
|
||||||
|
|
||||||
|
server.SyncLobbyClients();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool AssignTeams(S server, Connection conn, Session.Client client, string raw)
|
static bool AssignTeams(S server, Connection conn, Session.Client client, string raw)
|
||||||
{
|
{
|
||||||
lock (server.LobbyInfo)
|
lock (server.LobbyInfo)
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
bool insufficientPlayerSpawns;
|
bool insufficientPlayerSpawns;
|
||||||
bool teamChat;
|
bool teamChat;
|
||||||
bool updateDiscordStatus = true;
|
bool updateDiscordStatus = true;
|
||||||
|
bool resetOptionsButtonEnabled;
|
||||||
Dictionary<int, SpawnOccupant> spawnOccupants = new();
|
Dictionary<int, SpawnOccupant> spawnOccupants = new();
|
||||||
|
|
||||||
readonly string chatLineSound;
|
readonly string chatLineSound;
|
||||||
@@ -167,6 +168,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||||
Game.LobbyInfoChanged += UpdateDiscordStatus;
|
Game.LobbyInfoChanged += UpdateDiscordStatus;
|
||||||
Game.LobbyInfoChanged += UpdateSpawnOccupants;
|
Game.LobbyInfoChanged += UpdateSpawnOccupants;
|
||||||
|
Game.LobbyInfoChanged += UpdateOptions;
|
||||||
Game.BeforeGameStart += OnGameStart;
|
Game.BeforeGameStart += OnGameStart;
|
||||||
Game.ConnectionStateChanged += ConnectionStateChanged;
|
Game.ConnectionStateChanged += ConnectionStateChanged;
|
||||||
|
|
||||||
@@ -263,7 +265,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
|
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
|
||||||
if (slotsButton != null)
|
if (slotsButton != null)
|
||||||
{
|
{
|
||||||
slotsButton.IsVisible = () => panel != PanelType.Servers;
|
slotsButton.IsVisible = () => panel != PanelType.Servers && panel != PanelType.Options;
|
||||||
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
|
slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players ||
|
||||||
(orderManager.LobbyInfo.Slots.Values.All(s => !s.AllowBots) &&
|
(orderManager.LobbyInfo.Slots.Values.All(s => !s.AllowBots) &&
|
||||||
!orderManager.LobbyInfo.Slots.Any(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null));
|
!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()
|
var optionsBin = Ui.LoadWidget("LOBBY_OPTIONS_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()
|
||||||
{
|
{
|
||||||
{ "orderManager", orderManager },
|
{ "orderManager", orderManager },
|
||||||
@@ -910,6 +920,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
.ToDictionary(c => c.SpawnPoint, c => new SpawnOccupant(c));
|
.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()
|
void OnGameStart()
|
||||||
{
|
{
|
||||||
Ui.CloseWindow();
|
Ui.CloseWindow();
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ Container@SERVER_LOBBY:
|
|||||||
Width: 211
|
Width: 211
|
||||||
Height: 25
|
Height: 25
|
||||||
Text: dropdownbutton-bg-slots
|
Text: dropdownbutton-bg-slots
|
||||||
|
Button@RESET_OPTIONS_BUTTON:
|
||||||
|
X: 15
|
||||||
|
Y: 254
|
||||||
|
Width: 211
|
||||||
|
Height: 25
|
||||||
|
Text: button-bg-reset-options
|
||||||
Container@SKIRMISH_TABS:
|
Container@SKIRMISH_TABS:
|
||||||
X: 697 - WIDTH
|
X: 697 - WIDTH
|
||||||
Width: 465
|
Width: 465
|
||||||
|
|||||||
@@ -409,6 +409,7 @@ dropdownbutton-lobby-servers-bin-filters = Filter Games
|
|||||||
|
|
||||||
## lobby.yaml
|
## lobby.yaml
|
||||||
dropdownbutton-bg-slots = Slot Admin
|
dropdownbutton-bg-slots = Slot Admin
|
||||||
|
button-bg-reset-options = Reset Defaults
|
||||||
button-skirmish-tabs-players-tab = Players
|
button-skirmish-tabs-players-tab = Players
|
||||||
button-skirmish-tabs-options-tab = Options
|
button-skirmish-tabs-options-tab = Options
|
||||||
button-skirmish-tabs-music-tab = Music
|
button-skirmish-tabs-music-tab = Music
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ Background@SERVER_LOBBY:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Text: dropdownbutton-server-lobby-slots
|
Text: dropdownbutton-server-lobby-slots
|
||||||
|
Button@RESET_OPTIONS_BUTTON:
|
||||||
|
X: 20
|
||||||
|
Y: 291
|
||||||
|
Width: 185
|
||||||
|
Height: 25
|
||||||
|
Font: Bold
|
||||||
|
Text: button-server-lobby-reset-options
|
||||||
Container@SKIRMISH_TABS:
|
Container@SKIRMISH_TABS:
|
||||||
X: 695 - WIDTH
|
X: 695 - WIDTH
|
||||||
Width: 486
|
Width: 486
|
||||||
|
|||||||
@@ -260,6 +260,7 @@ label-notice-container-playtest-available = A preview of the next OpenRA release
|
|||||||
|
|
||||||
## lobby.yaml
|
## lobby.yaml
|
||||||
dropdownbutton-server-lobby-slots = Slot Admin
|
dropdownbutton-server-lobby-slots = Slot Admin
|
||||||
|
button-server-lobby-reset-options = Reset Defaults
|
||||||
button-skirmish-tabs-players-tab = Players
|
button-skirmish-tabs-players-tab = Players
|
||||||
button-skirmish-tabs-options-tab = Options
|
button-skirmish-tabs-options-tab = Options
|
||||||
button-skirmish-tabs-music-tab = Music
|
button-skirmish-tabs-music-tab = Music
|
||||||
|
|||||||
Reference in New Issue
Block a user