Fix uses of LabelWidget.Text and ButtonWidget.Text to use GetText instead.

The Text element of these widgets was changed from display text to a translation key as part of adding translation support. Functions interested in the display text need to invoke GetText instead. Lots of functions have not been updated, resulting in symptoms such as measuring the font size of the translation key rather than the display text and resizing a widget to the wrong size.

Update all callers to use GetText when getting or setting display text. This ensure their existing functionality that was intended to work in terms of the display text and not the translation key works as expected.
This commit is contained in:
RoosterDragon
2024-01-13 13:23:27 +00:00
committed by Gustas
parent ead78bc3a3
commit 2fde98a0d1
27 changed files with 115 additions and 84 deletions

View File

@@ -296,8 +296,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void ShowMessage(string title, string message)
{
visible = Mode.Message;
titleLabel.Text = title;
messageLabel.Text = message;
titleLabel.GetText = () => title;
messageLabel.GetText = () => message;
primaryButton.Bounds.Y += messageContainer.Bounds.Height - panel.Bounds.Height;
secondaryButton.Bounds.Y += messageContainer.Bounds.Height - panel.Bounds.Height;
@@ -308,7 +308,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void ShowProgressbar(string title, Func<string> getMessage)
{
visible = Mode.Progress;
titleLabel.Text = title;
titleLabel.GetText = () => title;
progressBar.IsIndeterminate = () => true;
var font = Game.Renderer.Fonts[progressLabel.Font];
@@ -324,8 +324,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void ShowList(ModContent.ModSource source, string message)
{
visible = Mode.List;
titleLabel.Text = source.Title;
listLabel.Text = message;
var titleText = source.Title;
titleLabel.GetText = () => titleText;
listLabel.GetText = () => message;
listPanel.RemoveChildren();
foreach (var package in availablePackages)
@@ -357,8 +358,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void ShowList(string title, string message, Dictionary<string, IEnumerable<string>> groups)
{
visible = Mode.List;
titleLabel.Text = title;
listLabel.Text = message;
titleLabel.GetText = () => title;
listLabel.GetText = () => message;
listPanel.RemoveChildren();
@@ -391,11 +392,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void ShowContinueCancel(Action continueAction)
{
primaryButton.OnClick = continueAction;
primaryButton.Text = TranslationProvider.GetString(Continue);
var primaryButtonText = TranslationProvider.GetString(Continue);
primaryButton.GetText = () => primaryButtonText;
primaryButton.Visible = true;
secondaryButton.OnClick = Ui.CloseWindow;
secondaryButton.Text = TranslationProvider.GetString(Cancel);
var secondaryButtonText = TranslationProvider.GetString(Cancel);
secondaryButton.GetText = () => secondaryButtonText;
secondaryButton.Visible = true;
secondaryButton.Disabled = false;
Game.RunAfterTick(Ui.ResetTooltips);
@@ -404,11 +407,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void ShowBackRetry(Action retryAction)
{
primaryButton.OnClick = retryAction;
primaryButton.Text = TranslationProvider.GetString(Retry);
var primaryButtonText = TranslationProvider.GetString(Retry);
primaryButton.GetText = () => primaryButtonText;
primaryButton.Visible = true;
secondaryButton.OnClick = Ui.CloseWindow;
secondaryButton.Text = TranslationProvider.GetString(Back);
var secondaryButtonText = TranslationProvider.GetString(Back);
secondaryButton.GetText = () => secondaryButtonText;
secondaryButton.Visible = true;
secondaryButton.Disabled = false;
Game.RunAfterTick(Ui.ResetTooltips);