From fa41dbb2f59d1503528efccc57b0336e4d189b7b Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Sun, 11 Nov 2018 16:42:38 +0100 Subject: [PATCH 1/2] Fix player score not updating while game info screen is visible --- .../Widgets/Logic/Ingame/GameInfoStatsLogic.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index c123d78f65a9..8e5a79e5c0cb 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -77,7 +77,8 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, var teamHeader = ScrollItemWidget.Setup(teamTemplate, () => true, () => { }); teamHeader.Get("TEAM").GetText = () => t.Key == 0 ? "No Team" : "Team {0}".F(t.Key); var teamRating = teamHeader.Get("TEAM_SCORE"); - teamRating.GetText = () => t.Sum(gg => gg.Second != null ? gg.Second.Experience : 0).ToString(); + var scoreCache = new CachedTransform(s => s.ToString()); + teamRating.GetText = () => scoreCache.Update(t.Sum(gg => gg.Second != null ? gg.Second.Experience : 0)); playerPanel.AddChild(teamHeader); } @@ -120,8 +121,7 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, item.Get("FACTION").GetText = () => pp.DisplayFaction.Name; } - var experience = p.Second != null ? p.Second.Experience : 0; - item.Get("SCORE").GetText = () => experience.ToString(); + item.Get("SCORE").GetText = () => (p.Second != null ? p.Second.Experience : 0).ToString(); playerPanel.AddChild(item); } From a17345c4bfff23b1a4d6456c549496c7f54bd21b Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Thu, 20 Dec 2018 03:09:09 +0100 Subject: [PATCH 2/2] Cache some more strings in GameInfoStatsLogic --- .../Logic/Ingame/GameInfoStatsLogic.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 8e5a79e5c0cb..b71e0ebac599 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -78,7 +78,8 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, teamHeader.Get("TEAM").GetText = () => t.Key == 0 ? "No Team" : "Team {0}".F(t.Key); var teamRating = teamHeader.Get("TEAM_SCORE"); var scoreCache = new CachedTransform(s => s.ToString()); - teamRating.GetText = () => scoreCache.Update(t.Sum(gg => gg.Second != null ? gg.Second.Experience : 0)); + var teamMemberScores = t.Select(tt => tt.Second).Where(s => s != null).ToArray().Select(s => s.Experience); + teamRating.GetText = () => scoreCache.Update(teamMemberScores.Sum()); playerPanel.AddChild(teamHeader); } @@ -94,8 +95,8 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, 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)); + var name = new CachedTransform, string>(c => + WidgetUtils.TruncateText(c.First, nameLabel.Bounds.Width - suffixLength.Update(c.Second), nameFont) + c.Second); nameLabel.GetText = () => { @@ -103,8 +104,7 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, if (client != null && client.State == Session.ClientState.Disconnected) suffix = " (Gone)"; - var sl = suffixLength.Update(suffix); - return name.Update(Pair.New(pp.PlayerName, sl)) + suffix; + return name.Update(Pair.New(pp.PlayerName, suffix)); }; nameLabel.GetColor = () => pp.Color.RGB; @@ -121,7 +121,8 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, item.Get("FACTION").GetText = () => pp.DisplayFaction.Name; } - item.Get("SCORE").GetText = () => (p.Second != null ? p.Second.Experience : 0).ToString(); + var scoreCache = new CachedTransform(s => s.ToString()); + item.Get("SCORE").GetText = () => scoreCache.Update(p.Second != null ? p.Second.Experience : 0); playerPanel.AddChild(item); } @@ -144,14 +145,13 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, 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)); + var name = new CachedTransform, string>(c => + WidgetUtils.TruncateText(c.First, nameLabel.Bounds.Width - suffixLength.Update(c.Second), nameFont) + c.Second); nameLabel.GetText = () => { var suffix = client.State == Session.ClientState.Disconnected ? " (Gone)" : ""; - var sl = suffixLength.Update(suffix); - return name.Update(Pair.New(client.Name, sl)) + suffix; + return name.Update(Pair.New(client.Name, suffix)); }; item.Get("FACTIONFLAG").IsVisible = () => false;