Add suffix to player name in shroud selector
This commit is contained in:
committed by
Paul Chote
parent
7a213338a2
commit
31a965b29a
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
LobbyUtils.SetupProfileWidget(item, client, orderManager, worldRenderer);
|
LobbyUtils.SetupProfileWidget(item, client, orderManager, worldRenderer);
|
||||||
|
|
||||||
var nameLabel = item.Get<LabelWidget>("NAME");
|
var nameLabel = item.Get<LabelWidget>("NAME");
|
||||||
WidgetUtils.AddSuffixToPlayerNameLabel(nameLabel, pp);
|
WidgetUtils.BindPlayerNameAndStatus(nameLabel, pp);
|
||||||
nameLabel.GetColor = () => pp.Color;
|
nameLabel.GetColor = () => pp.Color;
|
||||||
|
|
||||||
var flag = item.Get<ImageWidget>("FACTIONFLAG");
|
var flag = item.Get<ImageWidget>("FACTIONFLAG");
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
readonly World world;
|
readonly World world;
|
||||||
|
|
||||||
CameraOption selected;
|
CameraOption selected;
|
||||||
|
LabelWidget shroudLabel;
|
||||||
|
|
||||||
class CameraOption
|
class CameraOption
|
||||||
{
|
{
|
||||||
@@ -50,7 +51,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Color = p.Color;
|
Color = p.Color;
|
||||||
Faction = p.Faction.InternalName;
|
Faction = p.Faction.InternalName;
|
||||||
IsSelected = () => p.World.RenderPlayer == p;
|
IsSelected = () => p.World.RenderPlayer == p;
|
||||||
OnClick = () => { p.World.RenderPlayer = p; logic.selected = this; p.World.Selection.Clear(); };
|
OnClick = () =>
|
||||||
|
{
|
||||||
|
p.World.RenderPlayer = p;
|
||||||
|
logic.selected = this;
|
||||||
|
p.World.Selection.Clear();
|
||||||
|
WidgetUtils.BindPlayerNameAndStatus(logic.shroudLabel, p);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public CameraOption(ObserverShroudSelectorLogic logic, World w, string label, Player p)
|
public CameraOption(ObserverShroudSelectorLogic logic, World w, string label, Player p)
|
||||||
@@ -107,9 +114,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var label = item.Get<LabelWidget>("LABEL");
|
var label = item.Get<LabelWidget>("LABEL");
|
||||||
label.IsVisible = () => showFlag;
|
label.IsVisible = () => showFlag;
|
||||||
label.GetText = () => option.Label;
|
|
||||||
label.GetColor = () => option.Color;
|
label.GetColor = () => option.Color;
|
||||||
|
|
||||||
|
if (showFlag)
|
||||||
|
WidgetUtils.BindPlayerNameAndStatus(label, option.Player);
|
||||||
|
else
|
||||||
|
label.GetText = () => option.Label;
|
||||||
|
|
||||||
var flag = item.Get<ImageWidget>("FLAG");
|
var flag = item.Get<ImageWidget>("FLAG");
|
||||||
flag.IsVisible = () => showFlag;
|
flag.IsVisible = () => showFlag;
|
||||||
flag.GetImageCollection = () => "flags";
|
flag.GetImageCollection = () => "flags";
|
||||||
@@ -126,7 +137,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
shroudSelector.ShowDropDown("SPECTATOR_DROPDOWN_TEMPLATE", 400, groups, setupItem);
|
shroudSelector.ShowDropDown("SPECTATOR_DROPDOWN_TEMPLATE", 400, groups, setupItem);
|
||||||
};
|
};
|
||||||
|
|
||||||
var shroudLabel = shroudSelector.Get<LabelWidget>("LABEL");
|
shroudLabel = shroudSelector.Get<LabelWidget>("LABEL");
|
||||||
shroudLabel.IsVisible = () => selected.Faction != null;
|
shroudLabel.IsVisible = () => selected.Faction != null;
|
||||||
shroudLabel.GetText = () => selected.Label;
|
shroudLabel.GetText = () => selected.Label;
|
||||||
shroudLabel.GetColor = () => selected.Color;
|
shroudLabel.GetColor = () => selected.Color;
|
||||||
|
|||||||
@@ -526,7 +526,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
flag.GetImageName = () => player.Faction.InternalName;
|
flag.GetImageName = () => player.Faction.InternalName;
|
||||||
|
|
||||||
var playerName = template.Get<LabelWidget>("PLAYER");
|
var playerName = template.Get<LabelWidget>("PLAYER");
|
||||||
WidgetUtils.AddSuffixToPlayerNameLabel(playerName, player);
|
WidgetUtils.BindPlayerNameAndStatus(playerName, player);
|
||||||
|
|
||||||
playerName.GetColor = () => player.Color;
|
playerName.GetColor = () => player.Color;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,21 +272,23 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
button.GetTooltipText = null;
|
button.GetTooltipText = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddSuffixToPlayerNameLabel(LabelWidget label, Player p)
|
public static void BindPlayerNameAndStatus(LabelWidget label, Player p)
|
||||||
{
|
{
|
||||||
var client = p.World.LobbyInfo.ClientWithIndex(p.ClientIndex);
|
var client = p.World.LobbyInfo.ClientWithIndex(p.ClientIndex);
|
||||||
var playerNameFont = Game.Renderer.Fonts[label.Font];
|
var nameFont = Game.Renderer.Fonts[label.Font];
|
||||||
var suffixLength = new CachedTransform<string, int>(s => playerNameFont.Measure(s).X);
|
var name = new CachedTransform<Tuple<string, WinState, Session.ClientState>, string>(c =>
|
||||||
var name = new CachedTransform<Pair<string, string>, string>(c =>
|
{
|
||||||
WidgetUtils.TruncateText(c.First, label.Bounds.Width - suffixLength.Update(c.Second), playerNameFont));
|
var suffix = c.Item2 == WinState.Undefined ? "" : " (" + c.Item2 + ")";
|
||||||
|
if (c.Item3 == Session.ClientState.Disconnected)
|
||||||
|
suffix = " (Gone)";
|
||||||
|
|
||||||
|
return TruncateText(c.Item1, label.Bounds.Width - nameFont.Measure(suffix).X, nameFont) + suffix;
|
||||||
|
});
|
||||||
|
|
||||||
label.GetText = () =>
|
label.GetText = () =>
|
||||||
{
|
{
|
||||||
var suffix = p.WinState == WinState.Undefined ? "" : " (" + p.WinState + ")";
|
var clientState = client != null ? client.State : Session.ClientState.Ready;
|
||||||
if (client != null && client.State == Session.ClientState.Disconnected)
|
return name.Update(Tuple.Create(p.PlayerName, p.WinState, clientState));
|
||||||
suffix = " (Gone)";
|
|
||||||
|
|
||||||
return name.Update(Pair.New(p.PlayerName, suffix)) + suffix;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE:
|
|||||||
Height: 16
|
Height: 16
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 40
|
X: 40
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Height: 16
|
Height: 16
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 40
|
X: 40
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE:
|
|||||||
Height: 16
|
Height: 16
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 40
|
X: 40
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Y: 2
|
Y: 2
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 34
|
X: 34
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE:
|
|||||||
Y: 2
|
Y: 2
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 34
|
X: 34
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Y: 2
|
Y: 2
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 34
|
X: 34
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Height: 16
|
Height: 16
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 40
|
X: 40
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ ScrollPanel@SPECTATOR_DROPDOWN_TEMPLATE:
|
|||||||
Height: 16
|
Height: 16
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 40
|
X: 40
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Y: 5
|
Y: 5
|
||||||
Label@LABEL:
|
Label@LABEL:
|
||||||
X: 34
|
X: 34
|
||||||
Width: 60
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Shadow: True
|
Shadow: True
|
||||||
Label@NOFLAG_LABEL:
|
Label@NOFLAG_LABEL:
|
||||||
|
|||||||
Reference in New Issue
Block a user