diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 13f440d4b6..26b7def067 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -93,20 +93,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic LobbyUtils.SetupProfileWidget(item, client, orderManager, worldRenderer); var nameLabel = item.Get("NAME"); - var nameFont = Game.Renderer.Fonts[nameLabel.Font]; - - var suffixLength = new CachedTransform(s => nameFont.Measure(s).X); - var name = new CachedTransform, string>(c => - WidgetUtils.TruncateText(c.First, nameLabel.Bounds.Width - suffixLength.Update(c.Second), nameFont) + c.Second); - - nameLabel.GetText = () => - { - var suffix = pp.WinState == WinState.Undefined ? "" : " (" + pp.WinState + ")"; - if (client != null && client.State == Session.ClientState.Disconnected) - suffix = " (Gone)"; - - return name.Update(Pair.New(pp.PlayerName, suffix)); - }; + WidgetUtils.AddSuffixToPlayerNameLabel(nameLabel, pp); nameLabel.GetColor = () => pp.Color; var flag = item.Get("FACTIONFLAG"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs index 49061965e8..34edc08101 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs @@ -525,22 +525,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic flag.GetImageCollection = () => "flags"; flag.GetImageName = () => player.Faction.InternalName; - var client = player.World.LobbyInfo.ClientWithIndex(player.ClientIndex); var playerName = template.Get("PLAYER"); - var playerNameFont = Game.Renderer.Fonts[playerName.Font]; - var suffixLength = new CachedTransform(s => playerNameFont.Measure(s).X); - var name = new CachedTransform, string>(c => - WidgetUtils.TruncateText(c.First, playerName.Bounds.Width - c.Second, playerNameFont)); - - playerName.GetText = () => - { - var suffix = player.WinState == WinState.Undefined ? "" : " (" + player.WinState + ")"; - if (client != null && client.State == Session.ClientState.Disconnected) - suffix = " (Gone)"; - - var sl = suffixLength.Update(suffix); - return name.Update(Pair.New(player.PlayerName, sl)) + suffix; - }; + WidgetUtils.AddSuffixToPlayerNameLabel(playerName, player); playerName.GetColor = () => player.Color; } diff --git a/OpenRA.Mods.Common/Widgets/WidgetUtils.cs b/OpenRA.Mods.Common/Widgets/WidgetUtils.cs index 8043e6cf28..a9eadd0c9e 100644 --- a/OpenRA.Mods.Common/Widgets/WidgetUtils.cs +++ b/OpenRA.Mods.Common/Widgets/WidgetUtils.cs @@ -12,6 +12,7 @@ using System; using System.Linq; using OpenRA.Graphics; +using OpenRA.Network; using OpenRA.Primitives; namespace OpenRA.Mods.Common.Widgets @@ -270,6 +271,24 @@ namespace OpenRA.Mods.Common.Widgets else button.GetTooltipText = null; } + + public static void AddSuffixToPlayerNameLabel(LabelWidget label, Player p) + { + var client = p.World.LobbyInfo.ClientWithIndex(p.ClientIndex); + var playerNameFont = Game.Renderer.Fonts[label.Font]; + var suffixLength = new CachedTransform(s => playerNameFont.Measure(s).X); + var name = new CachedTransform, string>(c => + WidgetUtils.TruncateText(c.First, label.Bounds.Width - suffixLength.Update(c.Second), playerNameFont)); + + label.GetText = () => + { + var suffix = p.WinState == WinState.Undefined ? "" : " (" + p.WinState + ")"; + if (client != null && client.State == Session.ClientState.Disconnected) + suffix = " (Gone)"; + + return name.Update(Pair.New(p.PlayerName, suffix)) + suffix; + }; + } } public class CachedTransform