diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 815f38a379..757a60997a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -10,7 +10,10 @@ using System.Drawing; using System.Linq; +using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; +using OpenRA.Network; +using OpenRA.Primitives; using OpenRA.Traits; using OpenRA.Widgets; @@ -50,11 +53,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic var client = world.LobbyInfo.ClientWithIndex(pp.ClientIndex); var item = playerTemplate.Clone(); 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 - c.Second, nameFont)); + nameLabel.GetText = () => { + var suffix = pp.WinState == WinState.Undefined ? "" : " (" + pp.WinState + ")"; if (client != null && client.State == Network.Session.ClientState.Disconnected) - return pp.PlayerName + " (Gone)"; - return pp.PlayerName + (pp.WinState == WinState.Undefined ? "" : " (" + pp.WinState + ")"); + suffix = " (Gone)"; + + var sl = suffixLength.Update(suffix); + return name.Update(Pair.New(pp.PlayerName, sl)) + suffix; }; nameLabel.GetColor = () => pp.Color.RGB;