Skip to content

Commit

Permalink
Cache some more strings in GameInfoStatsLogic
Browse files Browse the repository at this point in the history
  • Loading branch information
obrakmann committed Dec 20, 2018
1 parent fa41dbb commit 683017a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs
Expand Up @@ -94,17 +94,16 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager,
var nameFont = Game.Renderer.Fonts[nameLabel.Font];

var suffixLength = new CachedTransform<string, int>(s => nameFont.Measure(s).X);
var name = new CachedTransform<Pair<string, int>, string>(c =>
WidgetUtils.TruncateText(c.First, nameLabel.Bounds.Width - c.Second, nameFont));
var name = new CachedTransform<Pair<string, string>, 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)";
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;

Expand All @@ -121,7 +120,8 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager,
item.Get<LabelWidget>("FACTION").GetText = () => pp.DisplayFaction.Name;
}

item.Get<LabelWidget>("SCORE").GetText = () => (p.Second != null ? p.Second.Experience : 0).ToString();
var scoreCache = new CachedTransform<int, string>(s => s.ToString());
item.Get<LabelWidget>("SCORE").GetText = () => scoreCache.Update((p.Second != null ? p.Second.Experience : 0));

playerPanel.AddChild(item);
}
Expand Down

0 comments on commit 683017a

Please sign in to comment.