Improve translation of power/silo usage tooltip

- Fix an instance where "silo-usage" translation was used without
arguments
- Use the same translation reference for the "Power usage"
- Make the ResourceBarWidget accept a cached transform with the tooltip
text
so it won't have to build the string itself
- Display an infinity symbol when the infinite power cheat is used
- Removes a magic number that is no longer used (>1000000 to check for
unlimited power)
This commit is contained in:
Ivaylo Draganov
2022-09-13 14:26:09 +03:00
committed by Matthias Mailänder
parent ba763ac0f0
commit e7dcbb3c2d
6 changed files with 53 additions and 16 deletions

View File

@@ -17,22 +17,39 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public class IngamePowerCounterLogic : ChromeLogic
{
[TranslationReference]
[TranslationReference("usage", "capacity")]
static readonly string PowerUsage = "power-usage";
[TranslationReference]
static readonly string Infinite = "infinite-power";
[ObjectCreator.UseCtor]
public IngamePowerCounterLogic(Widget widget, ModData modData, World world)
{
var developerMode = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
var powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
var power = widget.Get<LabelWithTooltipWidget>("POWER");
var powerIcon = widget.Get<ImageWidget>("POWER_ICON");
var powerUsage = modData.Translation.GetString(PowerUsage);
var unlimitedCapacity = modData.Translation.GetString(Infinite);
powerIcon.GetImageName = () => powerManager.ExcessPower < 0 ? "power-critical" : "power-normal";
power.GetColor = () => powerManager.ExcessPower < 0 ? Color.Red : Color.White;
power.GetText = () => powerManager.PowerProvided == 1000000 ? "∞" : powerManager.ExcessPower.ToString();
power.GetTooltipText = () => powerUsage + ": " + powerManager.PowerDrained.ToString() +
(powerManager.PowerProvided != 1000000 ? "/" + powerManager.PowerProvided.ToString() : "");
power.GetText = () => developerMode.UnlimitedPower ? unlimitedCapacity : powerManager.ExcessPower.ToString();
var tooltipTextCached = new CachedTransform<(string, string), string>(((string usage, string capacity) args) =>
{
return modData.Translation.GetString(
PowerUsage,
Translation.Arguments("usage", args.usage, "capacity", args.capacity));
});
power.GetTooltipText = () =>
{
var capacity = developerMode.UnlimitedPower ? unlimitedCapacity : powerManager.PowerProvided.ToString();
return tooltipTextCached.Update((powerManager.PowerDrained.ToString(), capacity));
};
}
}
}