From b28a3b6a5a09e415b335a642b4170e0750c5be3a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 29 Oct 2023 14:20:27 +0000 Subject: [PATCH] Fix lobby faction tooltip rendering. --- OpenRA.Mods.Common/Widgets/ButtonWidget.cs | 11 ++++++----- OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs | 2 +- OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs index 7d902ec7c8..43724700ce 100644 --- a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs @@ -77,8 +77,11 @@ namespace OpenRA.Mods.Common.Widgets { ModRules = modData.DefaultRules; - var tooltipCache = new CachedTransform(s => !string.IsNullOrEmpty(s) ? TranslationProvider.GetString(s) : ""); - GetText = () => tooltipCache.Update(Text); + var textCache = new CachedTransform(s => !string.IsNullOrEmpty(s) ? TranslationProvider.GetString(s) : ""); + var tooltipTextCache = new CachedTransform(s => !string.IsNullOrEmpty(s) ? TranslationProvider.GetString(s) : ""); + var tooltipDescCache = new CachedTransform(s => !string.IsNullOrEmpty(s) ? TranslationProvider.GetString(s) : ""); + + GetText = () => textCache.Update(Text); GetColor = () => TextColor; GetColorDisabled = () => TextColorDisabled; GetContrastColorDark = () => ContrastColorDark; @@ -86,9 +89,7 @@ namespace OpenRA.Mods.Common.Widgets OnMouseUp = _ => OnClick(); OnKeyPress = _ => OnClick(); IsHighlighted = () => Highlighted; - var tooltipDescCache = new CachedTransform(s => !string.IsNullOrEmpty(s) ? TranslationProvider.GetString(s) : ""); - GetTooltipText = () => tooltipDescCache.Update(TooltipText); - var textCache = new CachedTransform(s => !string.IsNullOrEmpty(s) ? TranslationProvider.GetString(s) : ""); + GetTooltipText = () => tooltipTextCache.Update(TooltipText); GetTooltipDesc = () => tooltipDescCache.Update(TooltipDesc); tooltipContainer = Exts.Lazy(() => Ui.Root.Get(TooltipContainer)); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index ff8e57a600..b9e9e0cc17 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -218,7 +218,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic colorManager = modRules.Actors[SystemActors.World].TraitInfo(); foreach (var f in modRules.Actors[SystemActors.World].TraitInfos()) - factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description }); + factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description?.Replace(@"\n", "\n") }); var gameStarting = false; Func configurationDisabled = () => !Game.IsHost || gameStarting || diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 4bc2ce5525..56cb1d1d0f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -200,7 +200,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } /// Splits a string into two parts on the first instance of a given token. - static (string First, string Second) SplitOnFirstToken(string input, string token = "\\n") + static (string First, string Second) SplitOnFirstToken(string input, string token = "\n") { if (string.IsNullOrEmpty(input)) return (null, null);