From dcc21aea41ee8f820aaa77ebd4eb870139da928a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 9 Nov 2015 18:35:16 +0000 Subject: [PATCH 1/3] Truncate player name in ingame menu stats. --- .../Widgets/Logic/Ingame/GameInfoStatsLogic.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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; From 6236b29fdea1ac83a370ce87d10c3b2715417740 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 9 Nov 2015 18:51:15 +0000 Subject: [PATCH 2/3] Truncate player name in observer stats and diplomacy panels. --- .../Widgets/Logic/Lobby/LobbyUtils.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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; } From 491e96466da6a722312bf11aeff9a1f21731dffa Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 9 Nov 2015 18:55:54 +0000 Subject: [PATCH 3/3] Truncate player name in replay browser. --- OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs | 4 +++- mods/cnc/chrome/replaybrowser.yaml | 2 +- mods/ra/chrome/replaybrowser.yaml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) 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