From efe135e38b4460809a2caec6b43914beae093a9b Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Thu, 13 Apr 2023 15:40:11 +0300 Subject: [PATCH] Add Translations to MapPreview --- OpenRA.Game/Map/Map.cs | 9 +++++---- OpenRA.Game/Map/MapPreview.cs | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index c25e7c108c..86f80c281d 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -167,11 +167,11 @@ namespace OpenRA new MapField("Bounds"), new MapField("Visibility"), new MapField("Categories"), - new MapField("Translations", required: false, ignoreIfValue: ""), new MapField("LockPreview", required: false, ignoreIfValue: "False"), new MapField("Players", "PlayerDefinitions"), new MapField("Actors", "ActorDefinitions"), new MapField("Rules", "RuleDefinitions", required: false), + new MapField("Translations", "TranslationDefinitions", required: false), new MapField("Sequences", "SequenceDefinitions", required: false), new MapField("ModelSequences", "ModelSequenceDefinitions", required: false), new MapField("Weapons", "WeaponDefinitions", required: false), @@ -193,7 +193,6 @@ namespace OpenRA public Rectangle Bounds; public MapVisibility Visibility = MapVisibility.Lobby; public string[] Categories = { "Conquest" }; - public string[] Translations; public int2 MapSize { get; private set; } @@ -203,6 +202,7 @@ namespace OpenRA // Custom map yaml. Public for access by the map importers and lint checks public readonly MiniYaml RuleDefinitions; + public readonly MiniYaml TranslationDefinitions; public readonly MiniYaml SequenceDefinitions; public readonly MiniYaml ModelSequenceDefinitions; public readonly MiniYaml WeaponDefinitions; @@ -450,7 +450,8 @@ namespace OpenRA } Sequences = new SequenceSet(this, modData, Tileset, SequenceDefinitions); - Translation = new Translation(Game.Settings.Player.Language, Translations, this); + Translation = TranslationDefinitions == null ? null + : new Translation(Game.Settings.Player.Language, FieldLoader.GetValue("value", TranslationDefinitions.Value), this); var tl = new MPos(0, 0).ToCPos(this); var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this); @@ -1412,7 +1413,7 @@ namespace OpenRA public string Translate(string key, IDictionary args = null) { - if (Translation.TryGetString(key, out var message, args)) + if (Translation != null && Translation.TryGetString(key, out var message, args)) return message; return modData.Translation.GetString(key, args); diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index 6c3ff528a6..a68ff11afd 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -90,6 +90,7 @@ namespace OpenRA public MiniYaml SequenceDefinitions; public MiniYaml ModelSequenceDefinitions; + public Translation Translation { get; private set; } public ActorInfo WorldActorInfo { get; private set; } public ActorInfo PlayerActorInfo { get; private set; } @@ -120,6 +121,10 @@ namespace OpenRA SequenceDefinitions = LoadRuleSection(yaml, "Sequences"); ModelSequenceDefinitions = LoadRuleSection(yaml, "ModelSequences"); + Translation = yaml.TryGetValue("Translations", out var node) && node != null + ? new Translation(Game.Settings.Player.Language, FieldLoader.GetValue("value", node.Value), fileSystem) + : null; + try { // PERF: Implement a minimal custom loader for custom world and player actors to minimize loading time @@ -293,6 +298,7 @@ namespace OpenRA innerData.SetCustomRules(modData, this, new Dictionary() { { "Rules", map.RuleDefinitions }, + { "Translations", map.TranslationDefinitions }, { "Weapons", map.WeaponDefinitions }, { "Voices", map.VoiceDefinitions }, { "Music", map.MusicDefinitions },