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; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 4af9cf8755..cfe9f0ae20 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -474,14 +474,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic else flag.GetImageName = () => player.Faction.InternalName; - var playerName = template.Get("PLAYER"); 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 == Network.Session.ClientState.Disconnected) - return player.PlayerName + " (Gone)"; - return player.PlayerName + (player.WinState == WinState.Undefined ? "" : " (" + player.WinState + ")"); + suffix = " (Gone)"; + + var sl = suffixLength.Update(suffix); + return name.Update(Pair.New(player.PlayerName, sl)) + suffix; }; + playerName.GetColor = () => player.Color.RGB; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 90962f3d5c..d9f59f403f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -639,7 +639,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic var item = ScrollItemWidget.Setup(playerTemplate, () => false, () => { }); var label = item.Get("LABEL"); - label.GetText = () => o.Name; + var font = Game.Renderer.Fonts[label.Font]; + var name = WidgetUtils.TruncateText(o.Name, label.Bounds.Width, font); + label.GetText = () => name; label.GetColor = () => color; var flag = item.Get("FLAG"); diff --git a/mods/cnc/chrome/replaybrowser.yaml b/mods/cnc/chrome/replaybrowser.yaml index 714ae37607..99fa564515 100644 --- a/mods/cnc/chrome/replaybrowser.yaml +++ b/mods/cnc/chrome/replaybrowser.yaml @@ -273,7 +273,7 @@ Container@REPLAYBROWSER_PANEL: Height: 16 Label@LABEL: X: 40 - Width: 60 + Width: PARENT_RIGHT-50 Height: 25 Label@NOFLAG_LABEL: X: 5 diff --git a/mods/ra/chrome/replaybrowser.yaml b/mods/ra/chrome/replaybrowser.yaml index f664e5313e..866500b337 100644 --- a/mods/ra/chrome/replaybrowser.yaml +++ b/mods/ra/chrome/replaybrowser.yaml @@ -262,7 +262,7 @@ Background@REPLAYBROWSER_PANEL: Height: 16 Label@LABEL: X: 40 - Width: 60 + Width: PARENT_RIGHT-50 Height: 25 Label@NOFLAG_LABEL: X: 5