Expose lobby options to localisation.

This commit is contained in:
Matthias Mailänder
2022-10-25 21:40:49 +02:00
committed by Gustas
parent aefa49a831
commit 8297fcff30
30 changed files with 287 additions and 96 deletions

View File

@@ -20,11 +20,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Attach this to the player actor.")]
public class DeveloperModeInfo : TraitInfo, ILobbyOptions
{
[TranslationReference]
[Desc("Descriptive label for the developer mode checkbox in the lobby.")]
public readonly string CheckboxLabel = "Debug Menu";
public readonly string CheckboxLabel = "debug-menu.label";
[TranslationReference]
[Desc("Tooltip description for the developer mode checkbox in the lobby.")]
public readonly string CheckboxDescription = "Enables cheats and developer commands";
public readonly string CheckboxDescription = "debug-menu.description";
[Desc("Default value of the developer mode checkbox in the lobby.")]
public readonly bool CheckboxEnabled = false;

View File

@@ -22,10 +22,12 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Internal id for this checkbox.")]
public readonly string ID = null;
[TranslationReference]
[FieldLoader.Require]
[Desc("Display name for this checkbox.")]
public readonly string Label = null;
[TranslationReference]
[Desc("Description name for this checkbox.")]
public readonly string Description = null;

View File

@@ -21,6 +21,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Internal id for this tech level.")]
public readonly string Id;
[TranslationReference]
[Desc("Name shown in the lobby options.")]
public readonly string Name;

View File

@@ -21,11 +21,13 @@ namespace OpenRA.Mods.Common.Traits
[TraitLocation(SystemActors.World)]
public class CrateSpawnerInfo : TraitInfo, ILobbyOptions
{
[TranslationReference]
[Desc("Descriptive label for the crates checkbox in the lobby.")]
public readonly string CheckboxLabel = "Crates";
public readonly string CheckboxLabel = "crates.label";
[TranslationReference]
[Desc("Tooltip description for the crates checkbox in the lobby.")]
public readonly string CheckboxDescription = "Collect crates with units to receive random bonuses or penalties";
public readonly string CheckboxDescription = "crates.description";
[Desc("Default value of the crates checkbox in the lobby.")]
public readonly bool CheckboxEnabled = true;

View File

@@ -18,11 +18,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Controls the build radius checkboxes in the lobby options.")]
public class MapBuildRadiusInfo : TraitInfo, ILobbyOptions
{
[TranslationReference]
[Desc("Descriptive label for the ally build radius checkbox in the lobby.")]
public readonly string AllyBuildRadiusCheckboxLabel = "Build off Allies";
public readonly string AllyBuildRadiusCheckboxLabel = "ally-build-radius.label";
[TranslationReference]
[Desc("Tooltip description for the ally build radius checkbox in the lobby.")]
public readonly string AllyBuildRadiusCheckboxDescription = "Allow allies to place structures inside your build area";
public readonly string AllyBuildRadiusCheckboxDescription = "ally-build-radius.description";
[Desc("Default value of the ally build radius checkbox in the lobby.")]
public readonly bool AllyBuildRadiusCheckboxEnabled = true;
@@ -36,11 +38,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Display order for the ally build radius checkbox in the lobby.")]
public readonly int AllyBuildRadiusCheckboxDisplayOrder = 0;
[TranslationReference]
[Desc("Tooltip description for the build radius checkbox in the lobby.")]
public readonly string BuildRadiusCheckboxLabel = "Limit Build Area";
public readonly string BuildRadiusCheckboxLabel = "build-radius.label";
[TranslationReference]
[Desc("Tooltip description for the build radius checkbox in the lobby.")]
public readonly string BuildRadiusCheckboxDescription = "Limits structure placement to areas around Construction Yards";
public readonly string BuildRadiusCheckboxDescription = "build-radius.description";
[Desc("Default value of the build radius checkbox in the lobby.")]
public readonly bool BuildRadiusCheckboxEnabled = true;

View File

@@ -18,11 +18,13 @@ namespace OpenRA.Mods.Common.Traits
[TraitLocation(SystemActors.World)]
public class MapCreepsInfo : TraitInfo, ILobbyOptions
{
[TranslationReference]
[Desc("Descriptive label for the creeps checkbox in the lobby.")]
public readonly string CheckboxLabel = "Creep Actors";
public readonly string CheckboxLabel = "map-creeps.label";
[TranslationReference]
[Desc("Tooltip description for the creeps checkbox in the lobby.")]
public readonly string CheckboxDescription = "Hostile forces spawn on the battlefield";
public readonly string CheckboxDescription = "map-creeps.description";
[Desc("Default value of the creeps checkbox in the lobby.")]
public readonly bool CheckboxEnabled = true;

View File

@@ -19,11 +19,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Controls the game speed, tech level, and short game lobby options.")]
public class MapOptionsInfo : TraitInfo, ILobbyOptions, IRulesetLoaded
{
[TranslationReference]
[Desc("Descriptive label for the short game checkbox in the lobby.")]
public readonly string ShortGameCheckboxLabel = "Short Game";
public readonly string ShortGameCheckboxLabel = "short-game.label";
[TranslationReference]
[Desc("Tooltip description for the short game checkbox in the lobby.")]
public readonly string ShortGameCheckboxDescription = "Players are defeated when their bases are destroyed";
public readonly string ShortGameCheckboxDescription = "short-game.description";
[Desc("Default value of the short game checkbox in the lobby.")]
public readonly bool ShortGameCheckboxEnabled = true;
@@ -37,11 +39,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Display order for the short game checkbox in the lobby.")]
public readonly int ShortGameCheckboxDisplayOrder = 0;
[TranslationReference]
[Desc("Descriptive label for the tech level option in the lobby.")]
public readonly string TechLevelDropdownLabel = "Tech Level";
public readonly string TechLevelDropdownLabel = "tech-level.label";
[TranslationReference]
[Desc("Tooltip description for the tech level option in the lobby.")]
public readonly string TechLevelDropdownDescription = "The units and abilities that players can use";
public readonly string TechLevelDropdownDescription = "tech-level.description";
[Desc("Default tech level.")]
public readonly string TechLevel = "unrestricted";
@@ -55,11 +59,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Display order for the tech level option in the lobby.")]
public readonly int TechLevelDropdownDisplayOrder = 0;
[TranslationReference]
[Desc("Tooltip description for the game speed option in the lobby.")]
public readonly string GameSpeedDropdownLabel = "Game Speed";
public readonly string GameSpeedDropdownLabel = "game-speed.label";
[TranslationReference]
[Desc("Description of the game speed option in the lobby.")]
public readonly string GameSpeedDropdownDescription = "The rate at which time passes";
public readonly string GameSpeedDropdownDescription = "game-speed.description";
[Desc("Default game speed (leave empty to use the default defined in mod.yaml).")]
public readonly string GameSpeed = null;
@@ -79,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
ShortGameCheckboxVisible, ShortGameCheckboxDisplayOrder, ShortGameCheckboxEnabled, ShortGameCheckboxLocked);
var techLevels = map.PlayerActorInfo.TraitInfos<ProvidesTechPrerequisiteInfo>()
.ToDictionary(t => t.Id, t => t.Name);
.ToDictionary(t => t.Id, t => Game.ModData.Translation.GetString(t.Name));
if (techLevels.Count > 0)
yield return new LobbyOption("techlevel", TechLevelDropdownLabel, TechLevelDropdownDescription, TechLevelDropdownVisible, TechLevelDropdownDisplayOrder,

View File

@@ -25,11 +25,13 @@ namespace OpenRA.Mods.Common.Traits
{
public readonly WDist InitialExploreRange = WDist.FromCells(5);
[TranslationReference]
[Desc("Descriptive label for the spawn positions checkbox in the lobby.")]
public readonly string SeparateTeamSpawnsCheckboxLabel = "Separate Team Spawns";
public readonly string SeparateTeamSpawnsCheckboxLabel = "separate-team-spawns.label";
[TranslationReference]
[Desc("Tooltip description for the spawn positions checkbox in the lobby.")]
public readonly string SeparateTeamSpawnsCheckboxDescription = "Players without assigned spawn points will start as far as possible from enemy players";
public readonly string SeparateTeamSpawnsCheckboxDescription = "separate-team-spawns.description";
[Desc("Default value of the spawn positions checkbox in the lobby.")]
public readonly bool SeparateTeamSpawnsCheckboxEnabled = true;

View File

@@ -22,6 +22,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Internal class ID.")]
public readonly string Class = "none";
[TranslationReference]
[Desc("Exposed via the UI to the player.")]
public readonly string ClassName = "Unlabeled";

View File

@@ -24,11 +24,13 @@ namespace OpenRA.Mods.Common.Traits
{
public readonly string StartingUnitsClass = "none";
[TranslationReference]
[Desc("Descriptive label for the starting units option in the lobby.")]
public readonly string DropdownLabel = "Starting Units";
public readonly string DropdownLabel = "starting-units.label";
[TranslationReference]
[Desc("Tooltip description for the starting units option in the lobby.")]
public readonly string DropdownDescription = "The units that players start the game with";
public readonly string DropdownDescription = "starting-units.description";
[Desc("Prevent the starting units option from being changed in the lobby.")]
public readonly bool DropdownLocked = false;
@@ -45,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
// Duplicate classes are defined for different race variants
foreach (var t in map.WorldActorInfo.TraitInfos<StartingUnitsInfo>())
startingUnits[t.Class] = t.ClassName;
startingUnits[t.Class] = Game.ModData.Translation.GetString(t.ClassName);
if (startingUnits.Count > 0)
yield return new LobbyOption("startingunits", DropdownLabel, DropdownDescription, DropdownVisible, DropdownDisplayOrder,

View File

@@ -21,11 +21,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("This trait allows setting a time limit on matches. Attach this to the World actor.")]
public class TimeLimitManagerInfo : TraitInfo, ILobbyOptions, IRulesetLoaded
{
[TranslationReference]
[Desc("Label that will be shown for the time limit option in the lobby.")]
public readonly string TimeLimitLabel = "Time Limit";
public readonly string TimeLimitLabel = "time-limit.label";
[TranslationReference]
[Desc("Tooltip description that will be shown for the time limit option in the lobby.")]
public readonly string TimeLimitDescription = "Player or team with the highest score after this time wins";
public readonly string TimeLimitDescription = "time-limit.description";
[Desc("Time Limit options that will be shown in the lobby dropdown. Values are in minutes.")]
public readonly int[] TimeLimitOptions = { 0, 10, 20, 30, 40, 60, 90 };
@@ -74,14 +76,20 @@ namespace OpenRA.Mods.Common.Traits
throw new YamlException("TimeLimitDefault must be a value from TimeLimitOptions");
}
[TranslationReference]
const string NoTimeLimit = "no-time-limit";
[TranslationReference("minutes")]
const string TimeLimitOption = "time-limit-options";
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(MapPreview map)
{
var timelimits = TimeLimitOptions.ToDictionary(c => c.ToString(), c =>
var timelimits = TimeLimitOptions.ToDictionary(m => m.ToString(), m =>
{
if (c == 0)
return "No limit";
if (m == 0)
return Game.ModData.Translation.GetString(NoTimeLimit);
else
return c.ToString() + $" minute{(c > 1 ? "s" : null)}";
return Game.ModData.Translation.GetString(TimeLimitOption, Translation.Arguments("minutes", m));
});
yield return new LobbyOption("timelimit", TimeLimitLabel, TimeLimitDescription, TimeLimitDropdownVisible, TimeLimitDisplayOrder,
@@ -93,6 +101,9 @@ namespace OpenRA.Mods.Common.Traits
public class TimeLimitManager : INotifyTimeLimit, ITick, IWorldLoaded
{
[TranslationReference]
const string TimeLimitExpired = "time-limit-expired";
readonly TimeLimitManagerInfo info;
readonly int ticksPerSecond;
LabelWidget countdownLabel;
@@ -170,7 +181,7 @@ namespace OpenRA.Mods.Common.Traits
countdownLabel.GetText = () => null;
if (!info.SkipTimerExpiredNotification)
TextNotificationsManager.AddSystemLine("Time limit has expired.");
TextNotificationsManager.AddSystemLine(Game.ModData.Translation.GetString(TimeLimitExpired));
}
}
}