Convert lobby checkboxes to new options backend.

This commit is contained in:
Paul Chote
2016-04-20 08:08:38 +02:00
parent 3e92c1944a
commit eb884ca76f
14 changed files with 134 additions and 328 deletions

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Controls the map difficulty, tech level, and short game lobby options.")]
public class MapOptionsInfo : TraitInfo<MapOptions>
public class MapOptionsInfo : ITraitInfo, ILobbyOptions
{
[Desc("Default value of the short game checkbox in the lobby.")]
public readonly bool ShortGameEnabled = true;
@@ -37,15 +37,30 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Prevent the difficulty from being changed in the lobby.")]
public readonly bool DifficultyLocked = false;
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
{
yield return new LobbyBooleanOption("shortgame", "Short Game", ShortGameEnabled, ShortGameLocked);
}
public object Create(ActorInitializer init) { return new MapOptions(this); }
}
public class MapOptions : INotifyCreated
{
readonly MapOptionsInfo info;
public bool ShortGame { get; private set; }
public MapOptions(MapOptionsInfo info)
{
this.info = info;
}
void INotifyCreated.Created(Actor self)
{
ShortGame = self.World.LobbyInfo.GlobalSettings.ShortGame;
ShortGame = self.World.LobbyInfo.GlobalSettings
.OptionOrDefault("shortgame", info.ShortGameEnabled);
}
}
}