Localize the faction dropdown.

This commit is contained in:
Matthias Mailänder
2024-07-16 19:27:06 +02:00
committed by Gustas
parent 59f6a6a2c2
commit 5ddc7b1177
14 changed files with 229 additions and 63 deletions

View File

@@ -17,6 +17,7 @@ namespace OpenRA.Traits
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)] [TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
public class FactionInfo : TraitInfo<Faction> public class FactionInfo : TraitInfo<Faction>
{ {
[TranslationReference]
[Desc("This is the name exposed to the players.")] [Desc("This is the name exposed to the players.")]
public readonly string Name = null; public readonly string Name = null;
@@ -29,6 +30,8 @@ namespace OpenRA.Traits
[Desc("The side that the faction belongs to. For example, England belongs to the 'Allies' side.")] [Desc("The side that the faction belongs to. For example, England belongs to the 'Allies' side.")]
public readonly string Side = null; public readonly string Side = null;
[TranslationReference(optional: true)]
[Desc("This is shown in the lobby as a tooltip.")]
public readonly string Description = null; public readonly string Description = null;
public readonly bool Selectable = true; public readonly bool Selectable = true;

View File

@@ -110,8 +110,7 @@ namespace OpenRA.Mods.Common.Lint
if (translationReference == null) if (translationReference == null)
continue; continue;
var keys = LintExts.GetFieldValues(traitInfo, field, translationReference.DictionaryReference); foreach (var key in LintExts.GetFieldValues(traitInfo, field, translationReference.DictionaryReference))
foreach (var key in keys)
usedKeys.Add(key, translationReference, $"Actor `{actorInfo.Key}` trait `{traitType.Name[..^4]}.{field.Name}`"); usedKeys.Add(key, translationReference, $"Actor `{actorInfo.Key}` trait `{traitType.Name[..^4]}.{field.Name}`");
} }
} }

View File

@@ -255,7 +255,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (player == null || player.RelationshipWith(pp) == PlayerRelationship.Ally || player.WinState != WinState.Undefined) if (player == null || player.RelationshipWith(pp) == PlayerRelationship.Ally || player.WinState != WinState.Undefined)
{ {
flag.GetImageName = () => pp.Faction.InternalName; flag.GetImageName = () => pp.Faction.InternalName;
factionName = pp.Faction.Name != factionName ? $"{factionName} ({pp.Faction.Name})" : pp.Faction.Name; factionName = pp.Faction.Name != factionName
? $"{TranslationProvider.GetString(factionName)} ({TranslationProvider.GetString(pp.Faction.Name)})"
: TranslationProvider.GetString(pp.Faction.Name);
} }
else else
flag.GetImageName = () => pp.DisplayFaction.InternalName; flag.GetImageName = () => pp.DisplayFaction.InternalName;

View File

@@ -219,7 +219,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
colorManager = modRules.Actors[SystemActors.World].TraitInfo<IColorPickerManagerInfo>(); colorManager = modRules.Actors[SystemActors.World].TraitInfo<IColorPickerManagerInfo>();
foreach (var f in modRules.Actors[SystemActors.World].TraitInfos<FactionInfo>()) foreach (var f in modRules.Actors[SystemActors.World].TraitInfos<FactionInfo>())
factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description?.Replace(@"\n", "\n") }); factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description });
var gameStarting = false; var gameStarting = false;
Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting || Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting ||

View File

@@ -222,14 +222,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var faction = factions[factionId]; var faction = factions[factionId];
var label = item.Get<LabelWidget>("LABEL"); var label = item.Get<LabelWidget>("LABEL");
var labelText = WidgetUtils.TruncateText(faction.Name, label.Bounds.Width, Game.Renderer.Fonts[label.Font]); var labelText = WidgetUtils.TruncateText(TranslationProvider.GetString(faction.Name), label.Bounds.Width, Game.Renderer.Fonts[label.Font]);
label.GetText = () => labelText; label.GetText = () => labelText;
var flag = item.Get<ImageWidget>("FLAG"); var flag = item.Get<ImageWidget>("FLAG");
flag.GetImageCollection = () => "flags"; flag.GetImageCollection = () => "flags";
flag.GetImageName = () => factionId; flag.GetImageName = () => factionId;
var (text, desc) = SplitOnFirstToken(faction.Description); var description = faction.Description != null ? TranslationProvider.GetString(faction.Description) : null;
var (text, desc) = SplitOnFirstToken(description);
item.GetTooltipText = () => text; item.GetTooltipText = () => text;
item.GetTooltipDesc = () => desc; item.GetTooltipDesc = () => desc;
@@ -237,7 +238,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
} }
var options = factions.Where(f => f.Value.Selectable).GroupBy(f => f.Value.Side) var options = factions.Where(f => f.Value.Selectable).GroupBy(f => f.Value.Side)
.ToDictionary(g => g.Key ?? "", g => g.Select(f => f.Key)); .ToDictionary(g => g.Key != null ? TranslationProvider.GetString(g.Key) : "", g => g.Select(f => TranslationProvider.GetString(f.Key)));
dropdown.ShowDropDown("FACTION_DROPDOWN_TEMPLATE", 154, options, SetupItem); dropdown.ShowDropDown("FACTION_DROPDOWN_TEMPLATE", 154, options, SetupItem);
} }
@@ -551,7 +552,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
dropdown.IsDisabled = () => s.LockFaction || orderManager.LocalClient.IsReady; dropdown.IsDisabled = () => s.LockFaction || orderManager.LocalClient.IsReady;
dropdown.OnMouseDown = _ => ShowFactionDropDown(dropdown, c, orderManager, factions); dropdown.OnMouseDown = _ => ShowFactionDropDown(dropdown, c, orderManager, factions);
var (text, desc) = SplitOnFirstToken(factions[c.Faction].Description); var description = factions[c.Faction].Description != null ? TranslationProvider.GetString(factions[c.Faction].Description) : null;
var (text, desc) = SplitOnFirstToken(description);
dropdown.GetTooltipText = () => text; dropdown.GetTooltipText = () => text;
dropdown.GetTooltipDesc = () => desc; dropdown.GetTooltipDesc = () => desc;
@@ -563,7 +565,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var factionName = parent.Get<LabelWidget>("FACTIONNAME"); var factionName = parent.Get<LabelWidget>("FACTIONNAME");
var font = Game.Renderer.Fonts[factionName.Font]; var font = Game.Renderer.Fonts[factionName.Font];
var truncated = new CachedTransform<string, string>(clientFaction => var truncated = new CachedTransform<string, string>(clientFaction =>
WidgetUtils.TruncateText(factions[clientFaction].Name, factionName.Bounds.Width, font)); WidgetUtils.TruncateText(TranslationProvider.GetString(factions[clientFaction].Name), factionName.Bounds.Width, font));
factionName.GetText = () => truncated.Update(c.Faction); factionName.GetText = () => truncated.Update(c.Faction);
var factionFlag = parent.Get<ImageWidget>("FACTIONFLAG"); var factionFlag = parent.Get<ImageWidget>("FACTIONFLAG");

View File

@@ -443,7 +443,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
options.Insert(0, null); // no filter options.Insert(0, null); // no filter
var anyText = ddb.GetText(); var anyText = ddb.GetText();
ddb.GetText = () => string.IsNullOrEmpty(filter.Faction) ? anyText : filter.Faction; ddb.GetText = () => string.IsNullOrEmpty(filter.Faction) ? anyText : TranslationProvider.GetString(filter.Faction);
ddb.OnMouseDown = _ => ddb.OnMouseDown = _ =>
{ {
ScrollItemWidget SetupItem(string option, ScrollItemWidget tpl) ScrollItemWidget SetupItem(string option, ScrollItemWidget tpl)
@@ -452,7 +452,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
tpl, tpl,
() => string.Equals(filter.Faction, option, StringComparison.CurrentCultureIgnoreCase), () => string.Equals(filter.Faction, option, StringComparison.CurrentCultureIgnoreCase),
() => { filter.Faction = option; ApplyFilter(); }); () => { filter.Faction = option; ApplyFilter(); });
item.Get<LabelWidget>("LABEL").GetText = () => option ?? anyText; item.Get<LabelWidget>("LABEL").GetText = () => option != null ? TranslationProvider.GetString(option) : anyText;
return item; return item;
} }

View File

@@ -32,6 +32,25 @@ dropdown-map-creeps =
resource-tiberium = Tiberium resource-tiberium = Tiberium
faction-random =
.name = Any
.description = Random Faction
A random faction will be chosen when the game starts
faction-gdi =
.name = GDI
.description = Global Defense Initiative
The GDI is an international military branch of the United Nations tasked
with keeping world peace. Commanding the combined forces of the world's
most powerful nations, they possess an unmatched arsenal of high-tech weaponry.
faction-nod =
.name = Nod
.description = Brotherhood of Nod
The Brotherhood is a religious cult centered around their leader Kane
and the alien substance Tiberium. They utilize stealth technology
and guerilla tactics to defeat those who oppose them.
## defaults.yaml ## defaults.yaml
notification-unit-lost = Unit lost. notification-unit-lost = Unit lost.
notification-unit-promoted = Unit promoted. notification-unit-promoted = Unit promoted.
@@ -540,4 +559,3 @@ actor-truck =
Builds fast Builds fast
Unarmed Unarmed
.name = Supply Truck .name = Supply Truck

View File

@@ -125,18 +125,18 @@
BlueTiberium: 100 BlueTiberium: 100
Beach: 89 Beach: 89
Faction@Random: Faction@Random:
Name: Any Name: faction-random.name
InternalName: Random InternalName: Random
RandomFactionMembers: gdi, nod RandomFactionMembers: gdi, nod
Description: Random Faction\nA random faction will be chosen when the game starts. Description: faction-random.description
Faction@gdi: Faction@gdi:
Name: GDI Name: faction-gdi.name
InternalName: gdi InternalName: gdi
Description: Global Defense Initiative\nThe GDI is an international military branch of the United Nations tasked\nwith keeping world peace. Commanding the combined forces of the world's\nmost powerful nations, they possess an unmatched arsenal of high-tech weaponry. Description: faction-gdi.description
Faction@nod: Faction@nod:
Name: Nod Name: faction-nod.name
InternalName: nod InternalName: nod
Description: Brotherhood of Nod\nThe Brotherhood is a religious cult centered around their leader Kane\nand the alien substance Tiberium. They utilize stealth technology\nand guerilla tactics to defeat those who oppose them. Description: faction-nod.description
ResourceRenderer: ResourceRenderer:
ResourceTypes: ResourceTypes:
Tiberium: Tiberium:

View File

@@ -33,6 +33,77 @@ options-starting-units =
resource-spice = Spice resource-spice = Spice
faction-random =
.name = Any
.description = Random House
A random house will be chosen when the game starts.
faction-atreides =
.name = Atreides
.description = House Atreides
The noble Atreides, from the water world of Caladan,
rely on their ornithopters to ensure air superiority.
They have allied themselves with the Fremen, the fearsome
native warriors of Dune that can move undetected in battle.
Faction Variations:
- Combat tanks are balanced in terms of speed and durability
Special Units:
- Grenadier
- Fremen
- Sonic Tank
Superweapon:
- Airstrike
faction-harkonnen =
.name = Harkonnen
.description = House Harkonnen
The evil Harkonnen will stop at nothing to gain control of the spice.
They rely on brute force and atomic weapons to achieve their goals:
wealth, and the destruction of House Atreides.
Faction Variations:
- Combat Tanks are more durable but slower
Special Units:
- Sardaukar
- Devastator
Superweapon:
- Death Hand Missile
faction-ordos =
.name = Ordos
.description = House Ordos
The insidious Ordos of the icy planet Sigma Draconis IV
are known for their wealth, greed and treachery.
Relying heavily on mercenaries they often resort
to sabotage and forbidden Ixian technologies.
Faction Variations:
- Trikes are replaced by Raider Trikes
- Combat Tanks are faster but less durable
Special Units:
- Raider Trike
- Stealth Raider Trike
- Saboteur
- Deviator
faction-corrino =
.name = Corrino
faction-mercenaries =
.name = Mercenaries
faction-smugglers =
.name = Smugglers
faction-fremen =
.name = Fremen
## defaults.yaml ## defaults.yaml
notification-unit-lost = Unit lost. notification-unit-lost = Unit lost.
notification-unit-promoted = Unit promoted. notification-unit-promoted = Unit promoted.

View File

@@ -77,36 +77,36 @@
SpiceSand: 100 SpiceSand: 100
Spice: 100 Spice: 100
Faction@Random: Faction@Random:
Name: Any Name: faction-random.name
InternalName: Random InternalName: Random
RandomFactionMembers: atreides, harkonnen, ordos RandomFactionMembers: atreides, harkonnen, ordos
Description: Random House\nA random house will be chosen when the game starts. Description: faction-random.description
Faction@Atreides: Faction@Atreides:
Name: Atreides Name: faction-atreides.name
InternalName: atreides InternalName: atreides
Description: House Atreides\nThe noble Atreides, from the water world of Caladan,\nrely on their ornithopters to ensure air superiority.\nThey have allied themselves with the Fremen, the fearsome\nnative warriors of Dune that can move undetected in battle.\n\nFaction Variations:\n - Combat tanks are balanced in terms of speed and durability\n\nSpecial Units:\n - Grenadier\n - Fremen\n - Sonic Tank\n\nSuperweapon:\n - Airstrike Description: faction-atreides.description
Faction@Harkonnen: Faction@Harkonnen:
Name: Harkonnen Name: faction-harkonnen.name
InternalName: harkonnen InternalName: harkonnen
Description: House Harkonnen\nThe evil Harkonnen will stop at nothing to gain control of the spice.\nThey rely on brute force and atomic weapons to achieve their goals:\nwealth, and the destruction of House Atreides.\n\nFaction Variations:\n - Combat Tanks are more durable but slower \n\nSpecial Units:\n - Sardaukar\n - Devastator\n\nSuperweapon: \n - Death Hand Missile Description: faction-harkonnen.description
Faction@Ordos: Faction@Ordos:
Name: Ordos Name: faction-ordos.name
InternalName: ordos InternalName: ordos
Description: House Ordos\nThe insidious Ordos of the icy planet Sigma Draconis IV\nare known for their wealth, greed and treachery.\nRelying heavily on mercenaries they often resort\nto sabotage and forbidden Ixian technologies.\n\nFaction Variations: \n - Trikes are replaced by Raider Trikes\n - Combat Tanks are faster but less durable\n\nSpecial Units:\n - Raider Trike\n - Stealth Raider Trike\n - Saboteur\n - Deviator Description: faction-ordos.description
Faction@Corrino: Faction@Corrino:
Name: Corrino Name: faction-corrino.name
InternalName: corrino InternalName: corrino
Selectable: false Selectable: false
Faction@Mercenaries: Faction@Mercenaries:
Name: Mercenaries Name: faction-mercenaries.name
InternalName: mercenary InternalName: mercenary
Selectable: false Selectable: false
Faction@Smugglers: Faction@Smugglers:
Name: Smugglers Name: faction-smugglers.name
InternalName: smuggler InternalName: smuggler
Selectable: false Selectable: false
Faction@Fremen: Faction@Fremen:
Name: Fremen Name: faction-fremen.name
InternalName: fremen InternalName: fremen
Selectable: false Selectable: false
D2kResourceRenderer: D2kResourceRenderer:

View File

@@ -34,6 +34,58 @@ options-starting-units =
resource-minerals = Valuable Minerals resource-minerals = Valuable Minerals
## Faction
faction-allies =
.name = Allies
faction-england =
.name = England
.description = England: Counterintelligence
Special Unit: British Spy
Special Unit: Mobile Gap Generator
faction-france =
.name = France
.description = France: Deception
Special Ability: Can build fake structures
Special Unit: Phase Transport
faction-germany =
.name = Germany
.description = Germany: Technology
Special Ability: Advanced Chronoshift
Special Unit: Chrono Tank
faction-soviet =
.name = Soviet
faction-russia =
.name = Russia
.description = Russia: Tesla Weapons
Special Unit: Tesla Tank
Special Unit: Shock Trooper
faction-ukraine =
.name = Ukraine
.description = Ukraine: Demolitions
Special Ability: Parabombs
Special Unit: Demolition Truck
faction-random =
.name = Any
.description = Random Country
A random country will be chosen when the game starts.
faction-randomallies =
.name = Allies
.description = Random Allied Country
A random Allied country will be chosen when the game starts.
faction-randomsoviet =
.name = Soviet
.description = Random Soviet Country
A random Soviet country will be chosen when the game starts.
## aircraft.yaml ## aircraft.yaml
actor-badr-name = Badger actor-badr-name = Badger

View File

@@ -97,59 +97,59 @@
FogVariants: shroud FogVariants: shroud
Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255 Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255
UseExtendedIndex: true UseExtendedIndex: true
Faction@0: Faction@allies:
Name: Allies Name: faction-allies.name
InternalName: allies InternalName: allies
Side: Allies Side: Allies
Selectable: False Selectable: False
Faction@1: Faction@england:
Name: England Name: faction-england.name
InternalName: england InternalName: england
Side: Allies Side: Allies
Description: England: Counterintelligence\nSpecial Unit: British Spy\nSpecial Unit: Mobile Gap Generator Description: faction-england.description
Faction@2: Faction@france:
Name: France Name: faction-france.name
InternalName: france InternalName: france
Side: Allies Side: Allies
Description: France: Deception\nSpecial Ability: Can build fake structures\nSpecial Unit: Phase Transport Description: faction-france.description
Faction@3: Faction@germany:
Name: Germany Name: faction-germany.name
InternalName: germany InternalName: germany
Side: Allies Side: Allies
Description: Germany: Technology\nSpecial Ability: Advanced Chronoshift\nSpecial Unit: Chrono Tank Description: faction-germany.description
Faction@4: Faction@soviet:
Name: Soviet Name: faction-soviet.name
InternalName: soviet InternalName: soviet
Side: Soviet Side: Soviet
Selectable: False Selectable: False
Faction@5: Faction@russia:
Name: Russia Name: faction-russia.name
InternalName: russia InternalName: russia
Side: Soviet Side: Soviet
Description: Russia: Tesla Weapons\nSpecial Unit: Tesla Tank\nSpecial Unit: Shock Trooper Description: faction-russia.description
Faction@6: Faction@ukraine:
Name: Ukraine Name: faction-ukraine.name
InternalName: ukraine InternalName: ukraine
Side: Soviet Side: Soviet
Description: Ukraine: Demolitions\nSpecial Ability: Parabombs\nSpecial Unit: Demolition Truck Description: faction-ukraine.description
Faction@random: Faction@random:
Name: Any Name: faction-random.name
InternalName: Random InternalName: Random
RandomFactionMembers: RandomAllies, RandomSoviet RandomFactionMembers: RandomAllies, RandomSoviet
Side: Random Side: Random
Description: Random Country\nA random country will be chosen when the game starts. Description: faction-random.description
Faction@randomallies: Faction@randomallies:
Name: Allies Name: faction-randomallies.name
InternalName: RandomAllies InternalName: RandomAllies
RandomFactionMembers: england, france, germany RandomFactionMembers: england, france, germany
Side: Random Side: Random
Description: Random Allied Country\nA random Allied country will be chosen when the game starts. Description: faction-randomallies.description
Faction@randomsoviet: Faction@randomsoviet:
Name: Soviet Name: faction-randomsoviet.name
InternalName: RandomSoviet InternalName: RandomSoviet
RandomFactionMembers: russia, ukraine RandomFactionMembers: russia, ukraine
Side: Random Side: Random
Description: Random Soviet Country\nA random Soviet country will be chosen when the game starts. Description: faction-randomsoviet.description
ResourceRenderer: ResourceRenderer:
ResourceTypes: ResourceTypes:
Ore: Ore:

View File

@@ -32,6 +32,25 @@ dropdown-map-creeps =
resource-veins = Veins resource-veins = Veins
resource-tiberium = Tiberium resource-tiberium = Tiberium
faction-random =
.name = Any
.description = Random Faction
A random faction will be chosen when the game starts
faction-gdi =
.name = GDI
.description = Global Defense Initiative
The GDI is an international military branch of the United Nations tasked
with keeping world peace. Commanding the combined forces of the world's
most powerful nations, they possess an unmatched arsenal of high-tech weaponry.
faction-nod =
.name = Nod
.description = Brotherhood of Nod
The Brotherhood is a religious cult centered around their leader Kane
and the alien substance Tiberium. They utilize stealth technology
and guerilla tactics to defeat those who oppose them.
## Structures ## Structures
notification-construction-complete = Construction complete. notification-construction-complete = Construction complete.
notification-unit-ready = Unit ready. notification-unit-ready = Unit ready.

View File

@@ -189,18 +189,18 @@
Rail: 100 Rail: 100
Crushes: wall, crate, infantry Crushes: wall, crate, infantry
Faction@Random: Faction@Random:
Name: Any Name: faction-random.name
InternalName: Random InternalName: Random
RandomFactionMembers: gdi, nod RandomFactionMembers: gdi, nod
Description: Random Faction\nA random faction will be chosen when the game starts. Description: faction-random.description
Faction@0: Faction@gdi:
Name: GDI Name: faction-gdi.name
InternalName: gdi InternalName: gdi
Description: Global Defense Initiative\nThe GDI is an international military branch of the United Nations tasked\nwith keeping world peace. Commanding the combined forces of the world's\nmost powerful nations, they possess an unmatched arsenal of high-tech weaponry. Description: faction-gdi.description
Faction@1: Faction@nod:
Name: Nod Name: faction-nod.name
InternalName: nod InternalName: nod
Description: Brotherhood of Nod\nThe Brotherhood is a religious cult centered around their leader Kane\nand the alien substance Tiberium. They utilize stealth technology\nand guerilla tactics to defeat those who oppose them. Description: faction-nod.description
TerrainGeometryOverlay: TerrainGeometryOverlay:
DebugVisualizations: DebugVisualizations:
CliffBackImpassabilityLayer: CliffBackImpassabilityLayer: