Add Checkbox/Dropdown to lobby options yaml fields.

This commit is contained in:
Paul Chote
2017-12-09 21:02:56 +00:00
committed by reaperrr
parent ea32c758eb
commit 36fccbc453
28 changed files with 333 additions and 226 deletions

View File

@@ -20,82 +20,82 @@ namespace OpenRA.Mods.Common.Traits
{
[Translate]
[Desc("Descriptive label for the short game checkbox in the lobby.")]
public readonly string ShortGameLabel = "Short Game";
public readonly string ShortGameCheckboxLabel = "Short Game";
[Translate]
[Desc("Tooltip description for the short game checkbox in the lobby.")]
public readonly string ShortGameDescription = "Players are defeated when their bases are destroyed";
public readonly string ShortGameCheckboxDescription = "Players are defeated when their bases are destroyed";
[Desc("Default value of the short game checkbox in the lobby.")]
public readonly bool ShortGameEnabled = true;
public readonly bool ShortGameCheckboxEnabled = true;
[Desc("Prevent the short game enabled state from being changed in the lobby.")]
public readonly bool ShortGameLocked = false;
public readonly bool ShortGameCheckboxLocked = false;
[Desc("Whether to display the short game checkbox in the lobby.")]
public readonly bool ShortGameVisible = true;
public readonly bool ShortGameCheckboxVisible = true;
[Desc("Display order for the short game checkbox in the lobby.")]
public readonly int ShortGameDisplayOrder = 0;
public readonly int ShortGameCheckboxDisplayOrder = 0;
[Translate]
[Desc("Descriptive label for the tech level option in the lobby.")]
public readonly string TechLevelLabel = "Tech Level";
public readonly string TechLevelDropdownLabel = "Tech Level";
[Translate]
[Desc("Tooltip description for the tech level option in the lobby.")]
public readonly string TechLevelDescription = "Change the units and abilities at your disposal";
public readonly string TechLevelDropdownDescription = "Change the units and abilities at your disposal";
[Desc("Default tech level.")]
public readonly string TechLevel = "unrestricted";
[Desc("Prevent the tech level from being changed in the lobby.")]
public readonly bool TechLevelLocked = false;
public readonly bool TechLevelDropdownLocked = false;
[Desc("Display the tech level option in the lobby.")]
public readonly bool TechLevelVisible = true;
public readonly bool TechLevelDropdownVisible = true;
[Desc("Display order for the tech level option in the lobby.")]
public readonly int TechLevelDisplayOrder = 0;
public readonly int TechLevelDropdownDisplayOrder = 0;
[Translate]
[Desc("Tooltip description for the game speed option in the lobby.")]
public readonly string GameSpeedLabel = "Game Speed";
public readonly string GameSpeedDropdownLabel = "Game Speed";
[Translate]
[Desc("Description of the game speed option in the lobby.")]
public readonly string GameSpeedDescription = "Change the rate at which time passes";
public readonly string GameSpeedDropdownDescription = "Change the rate at which time passes";
[Desc("Default game speed.")]
public readonly string GameSpeed = "default";
[Desc("Prevent the game speed from being changed in the lobby.")]
public readonly bool GameSpeedLocked = false;
public readonly bool GameSpeedDropdownLocked = false;
[Desc("Display the game speed option in the lobby.")]
public readonly bool GameSpeedVisible = true;
public readonly bool GameSpeedDropdownVisible = true;
[Desc("Display order for the game speed option in the lobby.")]
public readonly int GameSpeedDisplayOrder = 0;
public readonly int GameSpeedDropdownDisplayOrder = 0;
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
{
yield return new LobbyBooleanOption("shortgame", ShortGameLabel, ShortGameDescription,
ShortGameVisible, ShortGameDisplayOrder, ShortGameEnabled, ShortGameLocked);
yield return new LobbyBooleanOption("shortgame", ShortGameCheckboxLabel, ShortGameCheckboxDescription,
ShortGameCheckboxVisible, ShortGameCheckboxDisplayOrder, ShortGameCheckboxEnabled, ShortGameCheckboxLocked);
var techLevels = rules.Actors["player"].TraitInfos<ProvidesTechPrerequisiteInfo>()
.ToDictionary(t => t.Id, t => t.Name);
if (techLevels.Any())
yield return new LobbyOption("techlevel", TechLevelLabel, TechLevelDescription, TechLevelVisible, TechLevelDisplayOrder,
new ReadOnlyDictionary<string, string>(techLevels), TechLevel, TechLevelLocked);
yield return new LobbyOption("techlevel", TechLevelDropdownLabel, TechLevelDropdownDescription, TechLevelDropdownVisible, TechLevelDropdownDisplayOrder,
new ReadOnlyDictionary<string, string>(techLevels), TechLevel, TechLevelDropdownLocked);
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>().Speeds
.ToDictionary(s => s.Key, s => s.Value.Name);
// NOTE: The server hardcodes special-case logic for this option id
yield return new LobbyOption("gamespeed", GameSpeedLabel, GameSpeedDescription, GameSpeedVisible, GameSpeedDisplayOrder,
new ReadOnlyDictionary<string, string>(gameSpeeds), GameSpeed, GameSpeedLocked);
yield return new LobbyOption("gamespeed", GameSpeedDropdownLabel, GameSpeedDropdownDescription, GameSpeedDropdownVisible, GameSpeedDropdownDisplayOrder,
new ReadOnlyDictionary<string, string>(gameSpeeds), GameSpeed, GameSpeedDropdownLocked);
}
void IRulesetLoaded<ActorInfo>.RulesetLoaded(Ruleset rules, ActorInfo info)
@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self)
{
ShortGame = self.World.LobbyInfo.GlobalSettings
.OptionOrDefault("shortgame", info.ShortGameEnabled);
.OptionOrDefault("shortgame", info.ShortGameCheckboxEnabled);
TechLevel = self.World.LobbyInfo.GlobalSettings
.OptionOrDefault("techlevel", info.TechLevel);