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:
committed by
Matthias Mailänder
parent
ba763ac0f0
commit
e7dcbb3c2d
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
string siloUsageTooltip = "";
|
||||
|
||||
[TranslationReference("resources", "capacity")]
|
||||
[TranslationReference("usage", "capacity")]
|
||||
static readonly string SiloUsage = "silo-usage";
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
displayResources = playerResources.Cash + playerResources.Resources;
|
||||
|
||||
siloUsageTooltipCache = new CachedTransform<(int Resources, int Capacity), string>(x =>
|
||||
modData.Translation.GetString(SiloUsage, Translation.Arguments("resources", x.Resources, "capacity", x.Capacity)));
|
||||
modData.Translation.GetString(SiloUsage, Translation.Arguments("usage", x.Resources, "capacity", x.Capacity)));
|
||||
cashLabel = widget.Get<LabelWithTooltipWidget>("CASH");
|
||||
cashLabel.GetTooltipText = () => siloUsageTooltip;
|
||||
|
||||
|
||||
@@ -17,18 +17,32 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class IngamePowerBarLogic : ChromeLogic
|
||||
{
|
||||
[TranslationReference]
|
||||
[TranslationReference("usage", "capacity")]
|
||||
static readonly string PowerUsage = "power-usage";
|
||||
|
||||
[TranslationReference]
|
||||
static readonly string Infinite = "infinite-power";
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public IngamePowerBarLogic(Widget widget, ModData modData, World world)
|
||||
{
|
||||
var developerMode = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
|
||||
var powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
||||
var powerBar = widget.Get<ResourceBarWidget>("POWERBAR");
|
||||
|
||||
powerBar.GetProvided = () => powerManager.PowerProvided;
|
||||
powerBar.GetProvided = () => developerMode.UnlimitedPower ? -1 : powerManager.PowerProvided;
|
||||
powerBar.GetUsed = () => powerManager.PowerDrained;
|
||||
powerBar.TooltipFormat = modData.Translation.GetString(PowerUsage) + ": {0}/{1}";
|
||||
powerBar.TooltipTextCached = new CachedTransform<(float Current, float Capacity), string>(usage =>
|
||||
{
|
||||
var capacity = developerMode.UnlimitedPower ?
|
||||
modData.Translation.GetString(Infinite) :
|
||||
powerManager.PowerProvided.ToString();
|
||||
|
||||
return modData.Translation.GetString(
|
||||
PowerUsage,
|
||||
Translation.Arguments("usage", usage.Current, "capacity", capacity));
|
||||
});
|
||||
|
||||
powerBar.GetBarColor = () =>
|
||||
{
|
||||
if (powerManager.PowerState == PowerState.Critical)
|
||||
|
||||
@@ -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));
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class IngameSiloBarLogic : ChromeLogic
|
||||
{
|
||||
[TranslationReference]
|
||||
[TranslationReference("usage", "capacity")]
|
||||
static readonly string SiloUsage = "silo-usage";
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
@@ -28,7 +28,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
siloBar.GetProvided = () => playerResources.ResourceCapacity;
|
||||
siloBar.GetUsed = () => playerResources.Resources;
|
||||
siloBar.TooltipFormat = modData.Translation.GetString(SiloUsage) + ": {0}/{1}";
|
||||
siloBar.TooltipTextCached = new CachedTransform<(float Current, float Capacity), string>(usage =>
|
||||
{
|
||||
return modData.Translation.GetString(
|
||||
SiloUsage,
|
||||
Translation.Arguments("usage", usage.Current, "capacity", usage.Capacity));
|
||||
});
|
||||
siloBar.GetBarColor = () =>
|
||||
{
|
||||
if (playerResources.Resources == playerResources.ResourceCapacity)
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public readonly string TooltipContainer;
|
||||
readonly Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public string TooltipFormat = "";
|
||||
public CachedTransform<(float, float), string> TooltipTextCached;
|
||||
public ResourceBarOrientation Orientation = ResourceBarOrientation.Vertical;
|
||||
public string IndicatorCollection = "sidebar-bits";
|
||||
public string IndicatorImage = "indicator";
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
Func<string> getText = () => TooltipFormat.F(GetUsed(), GetProvided());
|
||||
Func<string> getText = () => TooltipTextCached.Update((GetUsed(), GetProvided()));
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() { { "getText", getText }, { "world", world } });
|
||||
}
|
||||
|
||||
|
||||
@@ -202,11 +202,12 @@ exit-map-editor-confirm = Exit
|
||||
|
||||
## IngamePowerBarLogic
|
||||
## IngamePowerCounterLogic
|
||||
power-usage = Power Usage
|
||||
power-usage = Power Usage: { $usage }/{ $capacity }
|
||||
infinite-power = Infinite
|
||||
|
||||
## IngameSiloBarLogic
|
||||
## IngameCashCounterLogic
|
||||
silo-usage = Silo Usage: { $resources }/{ $capacity }
|
||||
silo-usage = Silo Usage: { $usage }/{ $capacity }
|
||||
|
||||
## ObserverShroudSelectorLogic
|
||||
camera-option-all-players = All Players
|
||||
|
||||
Reference in New Issue
Block a user