Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public ActorEditLogic(Widget widget, World world, WorldRenderer worldRenderer, D

actorIDErrorLabel = actorEditPanel.Get<LabelWidget>("ACTOR_ID_ERROR_LABEL");
actorIDErrorLabel.IsVisible = () => actorIDStatus != ActorIDStatus.Normal;
actorIDErrorLabel.GetText = () => actorIDStatus == ActorIDStatus.Duplicate ?
TranslationProvider.GetString(DuplicateActorId)
actorIDErrorLabel.GetText = () =>
actorIDStatus == ActorIDStatus.Duplicate || nextActorIDStatus == ActorIDStatus.Duplicate
? TranslationProvider.GetString(DuplicateActorId)
: TranslationProvider.GetString(EnterActorId);

if (logicArgs.TryGetValue("EditPanelPadding", out var yaml))
Expand Down Expand Up @@ -143,7 +144,6 @@ public ActorEditLogic(Widget widget, World world, WorldRenderer worldRenderer, D
if (!CurrentActor.ID.Equals(actorId, StringComparison.OrdinalIgnoreCase) && editorActorLayer[actorId] != null)
{
nextActorIDStatus = ActorIDStatus.Duplicate;
actorIDErrorLabel.Text = TranslationProvider.GetString(DuplicateActorId);
actorIDErrorLabel.Visible = true;
return;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ public override void Tick()

var font = Game.Renderer.Fonts[typeLabel.Font];
var truncatedType = WidgetUtils.TruncateText(actor.DescriptiveName, typeLabel.Bounds.Width, font);
typeLabel.Text = truncatedType;
typeLabel.GetText = () => truncatedType;

actorIDField.CursorPosition = actor.ID.Length;
nextActorIDStatus = ActorIDStatus.Normal;
Expand Down
6 changes: 4 additions & 2 deletions OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ ScrollItemWidget SetupItem(PlayerReference option, ScrollItemWidget template)
ownersDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, SetupItem);
};

ownersDropDown.Text = selectedOwner.Name;
var selectedOwnerName = selectedOwner.Name;
ownersDropDown.GetText = () => selectedOwnerName;
ownersDropDown.TextColor = selectedOwner.Color;

var tileSetId = world.Map.Rules.TerrainInfo.Id;
Expand Down Expand Up @@ -161,7 +162,8 @@ ScrollItemWidget SetupItem(PlayerReference option, ScrollItemWidget template)
void SelectOwner(PlayerReference option)
{
selectedOwner = option;
ownersDropDown.Text = option.Name;
var optionName = option.Name;
ownersDropDown.GetText = () => optionName;
ownersDropDown.TextColor = option.Color;
InitializePreviews();

Expand Down
9 changes: 5 additions & 4 deletions OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ public NewMapLogic(Action onExit, Action<string> onSelect, Widget widget, World
ScrollItemWidget SetupItem(string option, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template,
() => tilesetDropDown.Text == option,
() => tilesetDropDown.Text = option);
() => tilesetDropDown.GetText() == option,
() => tilesetDropDown.GetText = () => option);
item.Get<LabelWidget>("LABEL").GetText = () => option;
return item;
}

tilesetDropDown.Text = tilesets.First();
var firstTileset = tilesets.First();
tilesetDropDown.GetText = () => firstTileset;
tilesetDropDown.OnClick = () =>
tilesetDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, tilesets, SetupItem);

Expand All @@ -56,7 +57,7 @@ ScrollItemWidget SetupItem(string option, ScrollItemWidget template)
height = Math.Max(2, height);

var maxTerrainHeight = world.Map.Grid.MaximumTerrainHeight;
var tileset = modData.DefaultTerrainInfo[tilesetDropDown.Text];
var tileset = modData.DefaultTerrainInfo[tilesetDropDown.GetText()];
var map = new Map(Game.ModData, tileset, width + 2, height + maxTerrainHeight + 2);

var tl = new PPos(1, 1 + maxTerrainHeight);
Expand Down
5 changes: 3 additions & 2 deletions OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ ScrollItemWidget SetupItem(KeyValuePair<MapFileType, MapFileTypeInfo> option, Sc
{
var item = ScrollItemWidget.Setup(template,
() => fileType == option.Key,
() => { typeDropdown.Text = option.Value.UiLabel; fileType = option.Key; });
() => { var label = option.Value.UiLabel; typeDropdown.GetText = () => label; fileType = option.Key; });
item.Get<LabelWidget>("LABEL").GetText = () => option.Value.UiLabel;
return item;
}

typeDropdown.Text = fileTypes[fileType].UiLabel;
var label = fileTypes[fileType].UiLabel;
typeDropdown.GetText = () => label;

typeDropdown.OnClick = () =>
typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes, SetupItem);
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void SelectActor(ActorInfo actor)
text += WidgetUtils.WrapText(TranslationProvider.GetString(info.Description) + "\n\n", descriptionLabel.Bounds.Width, descriptionFont);

var height = descriptionFont.Measure(text).Y;
descriptionLabel.Text = text;
descriptionLabel.GetText = () => text;
descriptionLabel.Bounds.Height = height;
descriptionPanel.Layout.AdjustChildren();

Expand Down
5 changes: 2 additions & 3 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/ArmyTooltipLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ public ArmyTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer,
var name = tooltip != null ? TranslationProvider.GetString(tooltip.Name) : armyUnit.ActorInfo.Name;
var buildable = armyUnit.BuildableInfo;

nameLabel.Text = name;

nameLabel.GetText = () => name;
var nameSize = font.Measure(name);

var desc = string.IsNullOrEmpty(buildable.Description) ? "" : TranslationProvider.GetString(buildable.Description);
descLabel.Text = desc;
descLabel.GetText = () => desc;
var descSize = descFont.Measure(desc);
descLabel.Bounds.Width = descSize.X;
descLabel.Bounds.Height = descSize.Y + descLabelPadding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public GameInfoBriefingLogic(Widget widget, ModData modData, World world)
if (missionData != null)
{
var text = WidgetUtils.WrapText(missionData.Briefing?.Replace("\\n", "\n"), mapDescription.Bounds.Width, mapFont);
mapDescription.Text = text;
mapDescription.GetText = () => text;
mapDescription.Bounds.Height = mapFont.Measure(text).Y;
mapDescriptionPanel.ScrollToTop();
mapDescriptionPanel.Layout.AdjustChildren();
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public GameInfoLogic(Widget widget, ModData modData, World world, IngameInfoPane

if (tabButton != null)
{
tabButton.Text = TranslationProvider.GetString(label);
var tabButtonText = TranslationProvider.GetString(label);
tabButton.GetText = () => tabButtonText;
tabButton.OnClick = () =>
{
if (activePanel == IngameInfoPanel.Chat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public GameSaveLoadingLogic(Widget widget, ModData modData, World world)

var versionLabel = widget.GetOrNull<LabelWidget>("VERSION_LABEL");
if (versionLabel != null)
versionLabel.Text = modData.Manifest.Metadata.Version;
{
var versionText = modData.Manifest.Metadata.Version;
versionLabel.GetText = () => versionText;
}

var keyhandler = widget.Get<LogicKeyListenerWidget>("CANCEL_HANDLER");
keyhandler.AddHandler(e =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public override void Tick()
}

siloUsageTooltip = siloUsageTooltipCache.Update((playerResources.Resources, playerResources.ResourceCapacity));
cashLabel.Text = displayResources.ToString(CultureInfo.CurrentCulture);
var displayResourcesText = displayResources.ToString(CultureInfo.CurrentCulture);
cashLabel.GetText = () => displayResourcesText;
}
}
}
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public class IngameMenuLogic : ChromeLogic
mpe = world.WorldActor.TraitOrDefault<MenuPostProcessEffect>();
mpe?.Fade(mpe.Info.MenuEffect);

menu.Get<LabelWidget>("VERSION_LABEL").Text = modData.Manifest.Metadata.Version;
var versionText = modData.Manifest.Metadata.Version;
menu.Get<LabelWidget>("VERSION_LABEL").GetText = () => versionText;

buttonContainer = menu.Get("MENU_BUTTONS");
buttonTemplate = buttonContainer.Get<ButtonWidget>("BUTTON_TEMPLATE");
Expand Down
34 changes: 20 additions & 14 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipConta
cost = valued.Cost;
}

nameLabel.Text = name;
nameLabel.GetText = () => name;

var nameSize = font.Measure(name);
var hotkeyWidth = 0;
Expand All @@ -93,18 +93,21 @@ public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipConta
var hotkeyText = $"({hotkey.DisplayString()})";

hotkeyWidth = font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X;
hotkeyLabel.Text = hotkeyText;
hotkeyLabel.GetText = () => hotkeyText;
hotkeyLabel.Bounds.X = nameSize.X + 2 * nameLabel.Bounds.X;
}

var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a))
.Where(s => !s.StartsWith('~') && !s.StartsWith('!'));
var prereqs = buildable.Prerequisites
.Select(a => ActorName(mapRules, a))
.Where(s => !s.StartsWith('~') && !s.StartsWith('!'))
.ToList();

var requiresSize = int2.Zero;
if (prereqs.Any())
if (prereqs.Count > 0)
{
requiresLabel.Text = TranslationProvider.GetString(Requires, Translation.Arguments("prequisites", prereqs.JoinWith(", ")));
requiresSize = requiresFont.Measure(requiresLabel.Text);
var requiresText = TranslationProvider.GetString(Requires, Translation.Arguments("prequisites", prereqs.JoinWith(", ")));
requiresLabel.GetText = () => requiresText;
requiresSize = requiresFont.Measure(requiresText);
requiresLabel.Visible = true;
descLabel.Bounds.Y = descLabelY + requiresLabel.Bounds.Height;
}
Expand All @@ -118,27 +121,30 @@ public ProductionTooltipLogic(Widget widget, TooltipContainerWidget tooltipConta
if (pm != null)
{
var power = actor.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(i => i.Amount);
powerLabel.Text = power.ToString(NumberFormatInfo.CurrentInfo);
var powerText = power.ToString(NumberFormatInfo.CurrentInfo);
powerLabel.GetText = () => powerText;
powerLabel.GetColor = () => (pm.PowerProvided - pm.PowerDrained >= -power || power > 0)
? Color.White : Color.Red;
powerLabel.Visible = power != 0;
powerIcon.Visible = power != 0;
powerSize = font.Measure(powerLabel.Text);
powerSize = font.Measure(powerText);
}

var buildTime = tooltipIcon.ProductionQueue?.GetBuildTime(actor, buildable) ?? 0;
var timeModifier = pm != null && pm.PowerState != PowerState.Normal ? tooltipIcon.ProductionQueue.Info.LowPowerModifier : 100;

timeLabel.Text = formatBuildTime.Update(buildTime * timeModifier / 100);
var timeText = formatBuildTime.Update(buildTime * timeModifier / 100);
timeLabel.GetText = () => timeText;
timeLabel.TextColor = (pm != null && pm.PowerState != PowerState.Normal && tooltipIcon.ProductionQueue.Info.LowPowerModifier > 100) ? Color.Red : Color.White;
var timeSize = font.Measure(timeLabel.Text);
var timeSize = font.Measure(timeText);

costLabel.Text = cost.ToString(NumberFormatInfo.CurrentInfo);
var costText = cost.ToString(NumberFormatInfo.CurrentInfo);
costLabel.GetText = () => costText;
costLabel.GetColor = () => pr.GetCashAndResources() >= cost ? Color.White : Color.Red;
var costSize = font.Measure(costLabel.Text);
var costSize = font.Measure(costText);

var desc = string.IsNullOrEmpty(buildable.Description) ? "" : TranslationProvider.GetString(buildable.Description);
descLabel.Text = desc;
descLabel.GetText = () => desc;
var descSize = descFont.Measure(desc);
descLabel.Bounds.Width = descSize.X;
descLabel.Bounds.Height = descSize.Y + descLabelPadding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ScriptErrorLogic(Widget widget, World world)
var errorMessage = luaScript.Context.ErrorMessage.Replace("\r\n", "\n");

var text = WidgetUtils.WrapText(errorMessage, label.Bounds.Width, font);
label.Text = text;
label.GetText = () => text;
label.Bounds.Height = font.Measure(text).Y;
panel.ScrollToTop();
panel.Layout.AdjustChildren();
Expand Down
23 changes: 12 additions & 11 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,32 @@ public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipCon
if (sp == lastPower && hotkey == lastHotkey && lastRemainingSeconds == remainingSeconds)
return;

nameLabel.Text = sp.Info.Name;
var nameSize = nameFont.Measure(nameLabel.Text);
var nameText = sp.Info.Name;
nameLabel.GetText = () => nameText;
var nameSize = nameFont.Measure(nameText);

descLabel.Text = sp.Info.Description.Replace("\\n", "\n");
var descSize = descFont.Measure(descLabel.Text);
var descText = sp.Info.Description.Replace("\\n", "\n");
descLabel.GetText = () => descText;
var descSize = descFont.Measure(descText);

var customLabel = sp.TooltipTimeTextOverride();
if (customLabel == null)
var timeText = sp.TooltipTimeTextOverride();
if (timeText == null)
{
var remaining = WidgetUtils.FormatTime(sp.RemainingTicks, world.Timestep);
var total = WidgetUtils.FormatTime(sp.Info.ChargeInterval, world.Timestep);
timeLabel.Text = $"{remaining} / {total}";
timeText = $"{remaining} / {total}";
}
else
timeLabel.Text = customLabel;

var timeSize = timeFont.Measure(timeLabel.Text);
timeLabel.GetText = () => timeText;
var timeSize = timeFont.Measure(timeText);
var hotkeyWidth = 0;
hotkeyLabel.Visible = hotkey.IsValid();
if (hotkeyLabel.Visible)
{
var hotkeyText = $"({hotkey.DisplayString()})";

hotkeyWidth = hotkeyFont.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X;
hotkeyLabel.Text = hotkeyText;
hotkeyLabel.GetText = () => hotkeyText;
hotkeyLabel.Bounds.X = nameSize.X + 2 * nameLabel.Bounds.X;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public DownloadPackageLogic(Widget widget, ModData modData, ModContent.ModDownlo
statusLabel.GetText = () => status.Update(getStatusText());

var text = TranslationProvider.GetString(Downloading, Translation.Arguments("title", download.Title));
panel.Get<LabelWidget>("TITLE").Text = text;
panel.Get<LabelWidget>("TITLE").GetText = () => text;

ShowDownloadDialog();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ void RunSourceActions(MiniYamlNode contentPackageYaml)
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;
Expand All @@ -308,7 +308,7 @@ void ShowMessage(string title, string message)
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];
Expand All @@ -324,8 +324,9 @@ void ShowProgressbar(string title, Func<string> getMessage)
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)
Expand Down Expand Up @@ -357,8 +358,8 @@ void ShowList(ModContent.ModSource source, string message)
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();

Expand Down Expand Up @@ -391,11 +392,13 @@ void ShowList(string title, string message, Dictionary<string, IEnumerable<strin
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);
Expand All @@ -404,11 +407,13 @@ void ShowContinueCancel(Action continueAction)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ModContentSourceTooltipLogic(Widget widget, Func<string> getText)
var font = Game.Renderer.Fonts[template.Font];
var sourceTitles = getText().Split('\n');

var maxWidth = Game.Renderer.Fonts[desc.Font].Measure(desc.Text).X;
var maxWidth = Game.Renderer.Fonts[desc.Font].Measure(desc.GetText()).X;
var sideMargin = desc.Bounds.X;
var bottomMargin = sources.Bounds.Height;
foreach (var source in sourceTitles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public IntroductionPromptLogic(Widget widget, ModData modData, WorldRenderer wor
var zoomDescModifier = container.Get<LabelWidget>("DESC_ZOOM_MODIFIER");
zoomDescModifier.IsVisible = () => gs.ZoomModifier != Modifiers.None;

var zoomDescModifierTemplate = zoomDescModifier.Text;
var zoomDescModifierTemplate = zoomDescModifier.GetText();
var zoomDescModifierLabel = new CachedTransform<Modifiers, string>(
mod => zoomDescModifierTemplate.Replace("MODIFIER", mod.ToString()));
zoomDescModifier.GetText = () => zoomDescModifierLabel.Update(gs.ZoomModifier);
Expand Down