Add tooltips to the password icon and player count.

This commit is contained in:
Paul Chote
2017-12-27 18:47:37 +00:00
committed by reaperrr
parent 0eaec5d861
commit ef680dbbfe
4 changed files with 49 additions and 9 deletions

View File

@@ -635,7 +635,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
password.GetImageName = () => canJoin ? "protected" : "protected-disabled"; password.GetImageName = () => canJoin ? "protected" : "protected-disabled";
} }
var players = item.GetOrNull<LabelWidget>("PLAYERS"); var players = item.GetOrNull<LabelWithTooltipWidget>("PLAYERS");
if (players != null) if (players != null)
{ {
var label = "{0} / {1}".F(game.Players + game.Bots, game.MaxPlayers + game.Bots) var label = "{0} / {1}".F(game.Players + game.Bots, game.MaxPlayers + game.Bots)
@@ -644,6 +644,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var color = canJoin ? players.TextColor : incompatibleGameColor; var color = canJoin ? players.TextColor : incompatibleGameColor;
players.GetText = () => label; players.GetText = () => label;
players.GetColor = () => color; players.GetColor = () => color;
if (game.Clients.Any())
{
var displayClients = game.Clients.Select(c => c.Name);
if (game.Clients.Length > 10)
displayClients = displayClients
.Take(9)
.Append("+ {0} other players".F(game.Clients.Length - 9));
var tooltip = displayClients.JoinWith("\n");
players.GetTooltipText = () => tooltip;
}
else
players.GetTooltipText = null;
} }
var state = item.GetOrNull<LabelWidget>("STATUS"); var state = item.GetOrNull<LabelWidget>("STATUS");

View File

@@ -16,8 +16,9 @@ namespace OpenRA.Mods.Common.Widgets
{ {
public class ScrollItemWidget : ButtonWidget public class ScrollItemWidget : ButtonWidget
{ {
public readonly string BaseName = "scrollitem";
public readonly bool EnableChildMouseOver = false;
public string ItemKey; public string ItemKey;
public string BaseName = "scrollitem";
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ScrollItemWidget(ModData modData) public ScrollItemWidget(ModData modData)
@@ -25,7 +26,6 @@ namespace OpenRA.Mods.Common.Widgets
{ {
IsVisible = () => false; IsVisible = () => false;
VisualHeight = 0; VisualHeight = 0;
IgnoreChildMouseOver = true;
} }
protected ScrollItemWidget(ScrollItemWidget other) protected ScrollItemWidget(ScrollItemWidget other)
@@ -33,17 +33,31 @@ namespace OpenRA.Mods.Common.Widgets
{ {
IsVisible = () => false; IsVisible = () => false;
VisualHeight = 0; VisualHeight = 0;
IgnoreChildMouseOver = true;
Key = other.Key; Key = other.Key;
BaseName = other.BaseName; BaseName = other.BaseName;
EnableChildMouseOver = other.EnableChildMouseOver;
}
public override void Initialize(WidgetArgs args)
{
base.Initialize(args);
// HACK: We want to default IgnoreChildMouseOver to true in this widget
// but still allow it to be disabled
IgnoreChildMouseOver = !EnableChildMouseOver;
} }
public Func<bool> IsSelected = () => false; public Func<bool> IsSelected = () => false;
public override void Draw() public override void Draw()
{ {
// PERF: Only check for ourself or our direct children
var isHover = Ui.MouseOverWidget == this;
if (!IgnoreChildMouseOver && !isHover)
isHover = Children.Contains(Ui.MouseOverWidget);
var state = IsSelected() ? BaseName + "-selected" : var state = IsSelected() ? BaseName + "-selected" :
Ui.MouseOverWidget == this ? BaseName + "-hover" : isHover ? BaseName + "-hover" :
null; null;
if (state != null) if (state != null)

View File

@@ -103,6 +103,7 @@ Container@MULTIPLAYER_PANEL:
Width: PARENT_RIGHT - 27 Width: PARENT_RIGHT - 27
Height: 25 Height: 25
X: 2 X: 2
EnableChildMouseOver: True
Children: Children:
Label@TITLE: Label@TITLE:
X: 5 X: 5
@@ -114,10 +115,15 @@ Container@MULTIPLAYER_PANEL:
Width: 8 Width: 8
Height: 10 Height: 10
ImageCollection: lobby-bits ImageCollection: lobby-bits
Label@PLAYERS: TooltipContainer: TOOLTIP_CONTAINER
TooltipTemplate: SIMPLE_TOOLTIP
TooltipText: Requires Password
LabelWithTooltip@PLAYERS:
X: 290 X: 290
Width: 85 Width: 85
Height: 25 Height: 25
TooltipContainer: TOOLTIP_CONTAINER
TooltipTemplate: SIMPLE_TOOLTIP
Label@LOCATION: Label@LOCATION:
X: 380 X: 380
Width: 110 Width: 110

View File

@@ -95,6 +95,7 @@ Background@MULTIPLAYER_PANEL:
X: 2 X: 2
Width: PARENT_RIGHT - 27 Width: PARENT_RIGHT - 27
Height: 25 Height: 25
EnableChildMouseOver: True
Children: Children:
Label@TITLE: Label@TITLE:
X: 5 X: 5
@@ -103,13 +104,18 @@ Background@MULTIPLAYER_PANEL:
Image@PASSWORD_PROTECTED: Image@PASSWORD_PROTECTED:
X: 272 X: 272
Y: 6 Y: 6
Width: 8 Width: 10
Height: 10 Height: 12
ImageCollection: lobby-bits ImageCollection: lobby-bits
Label@PLAYERS: TooltipContainer: TOOLTIP_CONTAINER
TooltipTemplate: SIMPLE_TOOLTIP
TooltipText: Requires Password
LabelWithTooltip@PLAYERS:
X: 290 X: 290
Width: 85 Width: 85
Height: 25 Height: 25
TooltipContainer: TOOLTIP_CONTAINER
TooltipTemplate: SIMPLE_TOOLTIP
Label@LOCATION: Label@LOCATION:
X: 380 X: 380
Width: 110 Width: 110