Add helper method to add suffix to player name label

This commit is contained in:
Ivaylo Draganov
2020-05-18 17:53:04 +03:00
committed by Paul Chote
parent fb27a25e52
commit 7a213338a2
3 changed files with 21 additions and 29 deletions

View File

@@ -93,20 +93,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
LobbyUtils.SetupProfileWidget(item, client, orderManager, worldRenderer);
var nameLabel = item.Get<LabelWidget>("NAME");
var nameFont = Game.Renderer.Fonts[nameLabel.Font];
var suffixLength = new CachedTransform<string, int>(s => nameFont.Measure(s).X);
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)";
return name.Update(Pair.New(pp.PlayerName, suffix));
};
WidgetUtils.AddSuffixToPlayerNameLabel(nameLabel, pp);
nameLabel.GetColor = () => pp.Color;
var flag = item.Get<ImageWidget>("FACTIONFLAG");