Extract translation strings.

This commit is contained in:
Matthias Mailänder
2022-08-10 22:43:22 +02:00
committed by teinarss
parent 8201a57b10
commit cc58fe1a0f
17 changed files with 314 additions and 73 deletions

View File

@@ -18,8 +18,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public class GameTimerLogic : ChromeLogic
{
[TranslationReference]
static readonly string Paused = "paused";
[TranslationReference]
static readonly string MaxSpeed = "max-speed";
[TranslationReference("percentage")]
static readonly string Speed = "speed";
[TranslationReference("percentage")]
static readonly string Complete = "complete";
[ObjectCreator.UseCtor]
public GameTimerLogic(Widget widget, OrderManager orderManager, World world)
public GameTimerLogic(Widget widget, ModData modData, OrderManager orderManager, World world)
{
var timer = widget.GetOrNull<LabelWidget>("GAME_TIMER");
var status = widget.GetOrNull<LabelWidget>("GAME_TIMER_STATUS");
@@ -31,12 +43,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Func<bool> paused = () => world.Paused || world.ReplayTimestep == 0;
var pausedText = modData.Translation.GetString(Paused);
var maxSpeedText = modData.Translation.GetString(MaxSpeed);
var speedText = new CachedTransform<int, string>(p =>
modData.Translation.GetString(Speed, Translation.Arguments("percentage", p)));
if (timer != null)
{
timer.GetText = () =>
{
if (status == null && paused() && shouldShowStatus())
return "Paused";
return pausedText;
var timeLimit = tlm?.TimeLimit ?? 0;
var displayTick = timeLimit > 0 ? timeLimit - world.WorldTick : world.WorldTick;
@@ -51,22 +68,24 @@ namespace OpenRA.Mods.Common.Widgets.Logic
status.GetText = () =>
{
if (paused())
return "Paused";
return pausedText;
if (world.ReplayTimestep == 1)
return "Max Speed";
return maxSpeedText;
return $"{world.Timestep * 100 / world.ReplayTimestep}% Speed";
return speedText.Update(world.Timestep * 100 / world.ReplayTimestep);
};
}
var timerText = new CachedTransform<int, string>(p =>
modData.Translation.GetString(Complete, Translation.Arguments("percentage", p)));
if (timer is LabelWithTooltipWidget timerTooltip)
{
var connection = orderManager.Connection as ReplayConnection;
if (connection != null && connection.FinalGameTick != 0)
timerTooltip.GetTooltipText = () => $"{world.WorldTick * 100 / connection.FinalGameTick}% complete";
timerTooltip.GetTooltipText = () => timerText.Update(world.WorldTick * 100 / connection.FinalGameTick);
else if (connection != null && connection.TickCount != 0)
timerTooltip.GetTooltipText = () => $"{orderManager.NetFrameNumber * 100 / connection.TickCount}% complete";
timerTooltip.GetTooltipText = () => timerText.Update(orderManager.NetFrameNumber * 100 / connection.TickCount);
else
timerTooltip.GetTooltipText = null;
}