Expose hotkeys to localisation.

Allows the Settings > Hotkeys screen to be localised, including hotkey decriptions, groups and contexts.

The hotkey names are exposed to localisation via KeycodeExts. Hotkey modifiers are similarly exposed via ModifersExts.

The Settings > Input screen has a Zoom Modifier dropdown, which shows the localised modifier name.

The --check-yaml utility command is taught to recognise all hotkey translation, so it can validate their usage.
This commit is contained in:
RoosterDragon
2024-09-17 19:42:42 +01:00
committed by Gustas
parent 10856ccfd0
commit 6f6fb5b393
39 changed files with 1284 additions and 722 deletions

View File

@@ -21,6 +21,7 @@ using OpenRA.Mods.Common.Scripting;
using OpenRA.Mods.Common.Scripting.Global;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Mods.Common.Widgets.Logic;
using OpenRA.Scripting;
using OpenRA.Traits;
using OpenRA.Widgets;
@@ -249,7 +250,7 @@ namespace OpenRA.Mods.Common.Lint
testedFields.AddRange(
modData.ObjectCreator.GetTypes()
.Where(t => t.IsSubclassOf(typeof(TraitInfo)) || t.IsSubclassOf(typeof(Warhead)))
.SelectMany(t => t.GetFields().Where(f => f.HasAttribute<FluentReferenceAttribute>())));
.SelectMany(t => Utility.GetFields(t).Where(Utility.HasAttribute<FluentReferenceAttribute>)));
// TODO: linter does not work with LoadUsing
GetUsedTranslationKeysFromFieldsWithTranslationReferenceAttribute(
@@ -278,6 +279,36 @@ namespace OpenRA.Mods.Common.Lint
GetUsedTranslationKeysFromFieldsWithTranslationReferenceAttribute(
usedKeys, testedFields, Utility.GetFields(typeof(ModContent.ModPackage)), modContent.Packages.Values);
GetUsedTranslationKeysFromFieldsWithTranslationReferenceAttribute(
usedKeys, testedFields, Utility.GetFields(typeof(HotkeyDefinition)), modData.Hotkeys.Definitions);
// All keycodes and modifiers should be marked as used, as they can all be configured for use at hotkeys at runtime.
GetUsedTranslationKeysFromFieldsWithTranslationReferenceAttribute(
usedKeys, testedFields, Utility.GetFields(typeof(KeycodeExts)).Concat(Utility.GetFields(typeof(ModifiersExts))), new[] { (object)null });
foreach (var filename in modData.Manifest.ChromeLayout)
CheckHotkeysSettingsLogic(usedKeys, MiniYaml.FromStream(modData.DefaultFileSystem.Open(filename), filename));
static void CheckHotkeysSettingsLogic(Keys usedKeys, IEnumerable<MiniYamlNode> nodes)
{
foreach (var node in nodes)
{
if (node.Value.Nodes != null)
CheckHotkeysSettingsLogic(usedKeys, node.Value.Nodes);
if (node.Key != "Logic" || node?.Value.Value != "HotkeysSettingsLogic")
continue;
var hotkeyGroupsNode = node.Value.NodeWithKeyOrDefault("HotkeyGroups");
if (hotkeyGroupsNode == null)
continue;
var hotkeyGroupsKeys = hotkeyGroupsNode?.Value.Nodes.Select(n => n.Key);
foreach (var key in hotkeyGroupsKeys)
usedKeys.Add(key, new FluentReferenceAttribute(), $"`{nameof(HotkeysSettingsLogic)}.HotkeyGroups`");
}
}
return (usedKeys, testedFields);
}