Add client tooltips showing Admin/IP/Latency.

This commit is contained in:
Paul Chote
2013-04-25 13:34:18 +12:00
parent 91115d5ba3
commit 45ff0645ba
11 changed files with 273 additions and 4 deletions

View File

@@ -223,6 +223,7 @@
<Compile Include="Widgets\TooltipContainerWidget.cs" />
<Compile Include="Traits\DebugPauseState.cs" />
<Compile Include="Network\UPnP.cs" />
<Compile Include="Widgets\ClientTooltipRegionWidget.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -0,0 +1,67 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Network;
namespace OpenRA.Widgets
{
public class ClientTooltipRegionWidget : Widget
{
public readonly string Template;
public readonly string TooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer;
OrderManager orderManager;
int clientIndex;
public ClientTooltipRegionWidget() : base()
{
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
protected ClientTooltipRegionWidget(ClientTooltipRegionWidget other)
: base(other)
{
Template = other.Template;
TooltipContainer = other.TooltipContainer;
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
orderManager = other.orderManager;
clientIndex = other.clientIndex;
}
public override Widget Clone() { return new ClientTooltipRegionWidget(this); }
public void Bind(OrderManager orderManager, int clientIndex)
{
this.orderManager = orderManager;
this.clientIndex = clientIndex;
}
public override void MouseEntered()
{
if (TooltipContainer == null)
return;
tooltipContainer.Value.SetTooltip(Template, new WidgetArgs() {{"orderManager", orderManager}, {"clientIndex", clientIndex}});
}
public override void MouseExited()
{
if (TooltipContainer == null)
return;
tooltipContainer.Value.RemoveTooltip();
}
}
}

View File

@@ -431,6 +431,7 @@
<Compile Include="Lint\CheckSequences.cs" />
<Compile Include="ServerTraits\PlayerPinger.cs" />
<Compile Include="Widgets\Logic\SpawnSelectorTooltipLogic.cs" />
<Compile Include="Widgets\Logic\ClientTooltipLogic.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -0,0 +1,64 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Widgets;
using OpenRA.Network;
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ClientTooltipLogic
{
[ObjectCreator.UseCtor]
public ClientTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, OrderManager orderManager, int clientIndex)
{
var admin = widget.Get<LabelWidget>("ADMIN");
var adminFont = Game.Renderer.Fonts[admin.Font];
var latency = widget.Get<LabelWidget>("LATENCY");
var latencyFont = Game.Renderer.Fonts[latency.Font];
var ip = widget.Get<LabelWidget>("IP");
var ipFont = Game.Renderer.Fonts[ip.Font];
var ipOffset = ip.Bounds.Y;
var latencyOffset = latency.Bounds.Y;
var tooltipHeight = widget.Bounds.Height;
var margin = widget.Bounds.Width;
tooltipContainer.BeforeRender = () =>
{
var width = Math.Max(adminFont.Measure(admin.GetText()).X, Math.Max(ipFont.Measure(ip.GetText()).X, latencyFont.Measure(latency.GetText()).X));
widget.Bounds.Width = width + 2*margin;
latency.Bounds.Width = widget.Bounds.Width;
ip.Bounds.Width = widget.Bounds.Width;
admin.Bounds.Width = widget.Bounds.Width;
ip.Bounds.Y = ipOffset;
latency.Bounds.Y = latencyOffset;
widget.Bounds.Height = tooltipHeight;
if (admin.IsVisible())
{
ip.Bounds.Y += admin.Bounds.Height;
latency.Bounds.Y += admin.Bounds.Height;
widget.Bounds.Height += admin.Bounds.Height;
}
};
admin.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin;
latency.GetText = () => "Latency: {0}".F(LobbyUtils.LatencyDescription(orderManager.LobbyInfo.ClientWithIndex(clientIndex).Latency));
ip.GetText = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress;
}
}
}

View File

@@ -158,7 +158,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
}
}
static Color LatencyColor(int latency)
public static Color LatencyColor(int latency)
{
// Levels set relative to the default order lag of 3 net ticks (360ms)
// TODO: Adjust this once dynamic lag is implemented
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return Color.Red;
}
static string LatencyDescription(int latency)
public static string LatencyDescription(int latency)
{
if (latency < 0)
return "Unknown";
@@ -190,6 +190,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (visible)
block.Get<ColorBlockWidget>("LATENCY_COLOR").GetColor = () => LatencyColor(c.Latency);
var tooltip = parent.Get<ClientTooltipRegionWidget>("CLIENT_REGION");
tooltip.IsVisible = () => visible;
tooltip.Bind(orderManager, c.Index);
}
public static void SetupEditableNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager)

View File

@@ -86,6 +86,11 @@ Container@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
TextField@NAME:
Text:Name
X:15
@@ -174,6 +179,11 @@ Container@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
Label@NAME:
Text:Name
Width:185
@@ -276,6 +286,11 @@ Container@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
TextField@NAME:
Text:Name
X:15
@@ -332,6 +347,11 @@ Container@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
Label@NAME:
Text:Name
Width:185

View File

@@ -123,3 +123,27 @@ Background@SPAWN_TOOLTIP:
Height:15
Font:TinyBold
Align:center
Background@CLIENT_TOOLTIP:
Logic:ClientTooltipLogic
Background:panel-black
Height:35
Width:5
Children:
Label@ADMIN:
Y:2
Height:18
Font:Bold
Text:Game Admin
Align:Center
Label@IP:
Y:5
Width:5
Height:10
Font:TinyBold
Align:Center
Label@LATENCY:
Y:17
Height:10
Font:TinyBold
Align:Center

View File

@@ -66,6 +66,11 @@ Background@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
TextField@NAME:
Text:Name
X:15
@@ -152,6 +157,11 @@ Background@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
Label@NAME:
Text:Name
Width:130
@@ -252,6 +262,11 @@ Background@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
TextField@NAME:
Text:Name
X:15
@@ -314,6 +329,11 @@ Background@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
Label@NAME:
Text:Name
Width:130

View File

@@ -20,4 +20,28 @@ Background@SPAWN_TOOLTIP:
Y:28
Height:15
Font:TinyBold
Align:center
Align:center
Background@CLIENT_TOOLTIP:
Logic:ClientTooltipLogic
Background:dialog3
Height:39
Width:7
Children:
Label@ADMIN:
Y:4
Height:18
Font:Bold
Text:Game Admin
Align:Center
Label@IP:
Y:7
Width:5
Height:10
Font:TinyBold
Align:Center
Label@LATENCY:
Y:19
Height:10
Font:TinyBold
Align:Center

View File

@@ -66,6 +66,11 @@ Background@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
TextField@NAME:
Text:Name
X:15
@@ -152,6 +157,11 @@ Background@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
Label@NAME:
Text:Name
Width:130
@@ -252,6 +262,11 @@ Background@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
TextField@NAME:
Text:Name
X:15
@@ -314,6 +329,11 @@ Background@SERVER_LOBBY:
Y:2
Width:PARENT_RIGHT-4
Height:PARENT_BOTTOM-4
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer:TOOLTIP_CONTAINER
Template:CLIENT_TOOLTIP
Width:11
Height:25
Label@NAME:
Text:Name
Width:130

View File

@@ -20,4 +20,28 @@ Background@SPAWN_TOOLTIP:
Y:23
Height:15
Font:TinyBold
Align:center
Align:center
Background@CLIENT_TOOLTIP:
Logic:ClientTooltipLogic
Background:dialog4
Height:39
Width:7
Children:
Label@ADMIN:
Y:4
Height:18
Font:Bold
Text:Game Admin
Align:Center
Label@IP:
Y:7
Width:5
Height:10
Font:TinyBold
Align:Center
Label@LATENCY:
Y:19
Height:10
Font:TinyBold
Align:Center