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:
@@ -167,30 +167,36 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
if (advertiseOnline)
|
||||
{
|
||||
noticesLabelA.Text = TranslationProvider.GetString(InternetServerNatA) + " ";
|
||||
var aWidth = Game.Renderer.Fonts[noticesLabelA.Font].Measure(noticesLabelA.Text).X;
|
||||
var noticesLabelAText = TranslationProvider.GetString(InternetServerNatA) + " ";
|
||||
noticesLabelA.GetText = () => noticesLabelAText;
|
||||
var aWidth = Game.Renderer.Fonts[noticesLabelA.Font].Measure(noticesLabelAText).X;
|
||||
noticesLabelA.Bounds.Width = aWidth;
|
||||
|
||||
noticesLabelB.Text = Nat.Status == NatStatus.Enabled ? TranslationProvider.GetString(InternetServerNatBenabled) :
|
||||
Nat.Status == NatStatus.NotSupported ? TranslationProvider.GetString(InternetServerNatBnotSupported)
|
||||
: TranslationProvider.GetString(InternetServerNatBdisabled);
|
||||
var noticesLabelBText =
|
||||
Nat.Status == NatStatus.Enabled ? TranslationProvider.GetString(InternetServerNatBenabled) :
|
||||
Nat.Status == NatStatus.NotSupported ? TranslationProvider.GetString(InternetServerNatBnotSupported) :
|
||||
TranslationProvider.GetString(InternetServerNatBdisabled);
|
||||
noticesLabelB.GetText = () => noticesLabelBText;
|
||||
|
||||
noticesLabelB.TextColor = Nat.Status == NatStatus.Enabled ? ChromeMetrics.Get<Color>("NoticeSuccessColor") :
|
||||
noticesLabelB.TextColor =
|
||||
Nat.Status == NatStatus.Enabled ? ChromeMetrics.Get<Color>("NoticeSuccessColor") :
|
||||
Nat.Status == NatStatus.NotSupported ? ChromeMetrics.Get<Color>("NoticeErrorColor") :
|
||||
ChromeMetrics.Get<Color>("NoticeInfoColor");
|
||||
|
||||
var bWidth = Game.Renderer.Fonts[noticesLabelB.Font].Measure(noticesLabelB.Text).X;
|
||||
var bWidth = Game.Renderer.Fonts[noticesLabelB.Font].Measure(noticesLabelBText).X;
|
||||
noticesLabelB.Bounds.X = noticesLabelA.Bounds.Right;
|
||||
noticesLabelB.Bounds.Width = bWidth;
|
||||
noticesLabelB.Visible = true;
|
||||
|
||||
noticesLabelC.Text = TranslationProvider.GetString(InternetServerNatC);
|
||||
var noticesLabelCText = TranslationProvider.GetString(InternetServerNatC);
|
||||
noticesLabelC.GetText = () => noticesLabelCText;
|
||||
noticesLabelC.Bounds.X = noticesLabelB.Bounds.Right;
|
||||
noticesLabelC.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
noticesLabelA.Text = TranslationProvider.GetString(LocalServer);
|
||||
var noticesLabelAText = TranslationProvider.GetString(LocalServer);
|
||||
noticesLabelA.GetText = () => noticesLabelAText;
|
||||
noticesLabelB.Visible = false;
|
||||
noticesLabelC.Visible = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user