Merge pull request #10067 from Mailaender/ingame-client-tooltip

Added an in-game client tooltip with IP and country
This commit is contained in:
Oliver Brakmann
2015-12-11 21:09:05 +01:00
10 changed files with 136 additions and 25 deletions

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
class GameInfoStatsLogic : ChromeLogic class GameInfoStatsLogic : ChromeLogic
{ {
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public GameInfoStatsLogic(Widget widget, World world) public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager)
{ {
var lp = world.LocalPlayer; var lp = world.LocalPlayer;
@@ -52,6 +52,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var pp = p; var pp = p;
var client = world.LobbyInfo.ClientWithIndex(pp.ClientIndex); var client = world.LobbyInfo.ClientWithIndex(pp.ClientIndex);
var item = playerTemplate.Clone(); var item = playerTemplate.Clone();
LobbyUtils.SetupClientWidget(item, client, orderManager, client.Bot == null);
var nameLabel = item.Get<LabelWidget>("NAME"); var nameLabel = item.Get<LabelWidget>("NAME");
var nameFont = Game.Renderer.Fonts[nameLabel.Font]; var nameFont = Game.Renderer.Fonts[nameLabel.Font];

View File

@@ -10,6 +10,7 @@
using System; using System;
using System.Net; using System.Net;
using OpenRA.Graphics;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Widgets; using OpenRA.Widgets;
@@ -17,17 +18,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
public class ClientTooltipLogic : ChromeLogic public class ClientTooltipLogic : ChromeLogic
{ {
SpriteFont latencyFont;
SpriteFont latencyPrefixFont;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ClientTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, OrderManager orderManager, int clientIndex) public ClientTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, OrderManager orderManager, int clientIndex)
{ {
var admin = widget.Get<LabelWidget>("ADMIN"); var admin = widget.Get<LabelWidget>("ADMIN");
var adminFont = Game.Renderer.Fonts[admin.Font]; var adminFont = Game.Renderer.Fonts[admin.Font];
var latency = widget.Get<LabelWidget>("LATENCY"); var latency = widget.GetOrNull<LabelWidget>("LATENCY");
var latencyFont = Game.Renderer.Fonts[latency.Font]; if (latency != null)
latencyFont = Game.Renderer.Fonts[latency.Font];
var latencyPrefix = widget.Get<LabelWidget>("LATENCY_PREFIX"); var latencyPrefix = widget.GetOrNull<LabelWidget>("LATENCY_PREFIX");
var latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font]; if (latencyPrefix != null)
latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font];
var ip = widget.Get<LabelWidget>("IP"); var ip = widget.Get<LabelWidget>("IP");
var addressFont = Game.Renderer.Fonts[ip.Font]; var addressFont = Game.Renderer.Fonts[ip.Font];
@@ -37,7 +43,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var locationOffset = location.Bounds.Y; var locationOffset = location.Bounds.Y;
var addressOffset = ip.Bounds.Y; var addressOffset = ip.Bounds.Y;
var latencyOffset = latency.Bounds.Y; var latencyOffset = latency == null ? 0 : latency.Bounds.Y;
var tooltipHeight = widget.Bounds.Height; var tooltipHeight = widget.Bounds.Height;
var margin = widget.Bounds.Width; var margin = widget.Bounds.Width;
@@ -45,19 +51,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
tooltipContainer.IsVisible = () => (orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null); tooltipContainer.IsVisible = () => (orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null);
tooltipContainer.BeforeRender = () => tooltipContainer.BeforeRender = () =>
{ {
var latencyPrefixSize = latencyPrefix.Bounds.X + latencyPrefixFont.Measure(latencyPrefix.GetText() + " ").X; var latencyPrefixSize = latencyPrefix == null ? 0 : latencyPrefix.Bounds.X + latencyPrefixFont.Measure(latencyPrefix.GetText() + " ").X;
var locationWidth = locationFont.Measure(location.GetText()).X; var locationWidth = locationFont.Measure(location.GetText()).X;
var adminWidth = adminFont.Measure(admin.GetText()).X; var adminWidth = adminFont.Measure(admin.GetText()).X;
var addressWidth = addressFont.Measure(ip.GetText()).X; var addressWidth = addressFont.Measure(ip.GetText()).X;
var latencyWidth = latencyPrefixSize + latencyFont.Measure(latency.GetText()).X; var latencyWidth = latencyFont == null ? 0 : latencyPrefixSize + latencyFont.Measure(latency.GetText()).X;
var width = Math.Max(locationWidth, Math.Max(adminWidth, Math.Max(addressWidth, latencyWidth))); var width = Math.Max(locationWidth, Math.Max(adminWidth, Math.Max(addressWidth, latencyWidth)));
widget.Bounds.Width = width + 2 * margin; widget.Bounds.Width = width + 2 * margin;
if (latency != null)
latency.Bounds.Width = widget.Bounds.Width; latency.Bounds.Width = widget.Bounds.Width;
ip.Bounds.Width = widget.Bounds.Width; ip.Bounds.Width = widget.Bounds.Width;
admin.Bounds.Width = widget.Bounds.Width; admin.Bounds.Width = widget.Bounds.Width;
location.Bounds.Width = widget.Bounds.Width; location.Bounds.Width = widget.Bounds.Width;
ip.Bounds.Y = addressOffset; ip.Bounds.Y = addressOffset;
if (latency != null)
latency.Bounds.Y = latencyOffset; latency.Bounds.Y = latencyOffset;
location.Bounds.Y = locationOffset; location.Bounds.Y = locationOffset;
widget.Bounds.Height = tooltipHeight; widget.Bounds.Height = tooltipHeight;
@@ -65,20 +73,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (admin.IsVisible()) if (admin.IsVisible())
{ {
ip.Bounds.Y += admin.Bounds.Height; ip.Bounds.Y += admin.Bounds.Height;
if (latency != null)
latency.Bounds.Y += admin.Bounds.Height; latency.Bounds.Y += admin.Bounds.Height;
location.Bounds.Y += admin.Bounds.Height; location.Bounds.Y += admin.Bounds.Height;
widget.Bounds.Height += admin.Bounds.Height; widget.Bounds.Height += admin.Bounds.Height;
} }
if (latencyPrefix != null)
latencyPrefix.Bounds.Y = latency.Bounds.Y; latencyPrefix.Bounds.Y = latency.Bounds.Y;
if (latency != null)
latency.Bounds.X = latencyPrefixSize; latency.Bounds.X = latencyPrefixSize;
}; };
admin.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin; admin.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin;
var client = orderManager.LobbyInfo.ClientWithIndex(clientIndex); var client = orderManager.LobbyInfo.ClientWithIndex(clientIndex);
var ping = orderManager.LobbyInfo.PingFromClient(client); var ping = orderManager.LobbyInfo.PingFromClient(client);
if (latency != null)
{
latency.GetText = () => LobbyUtils.LatencyDescription(ping); latency.GetText = () => LobbyUtils.LatencyDescription(ping);
latency.GetColor = () => LobbyUtils.LatencyColor(ping); latency.GetColor = () => LobbyUtils.LatencyColor(ping);
}
var address = LobbyUtils.GetExternalIP(clientIndex, orderManager); var address = LobbyUtils.GetExternalIP(clientIndex, orderManager);
var cachedDescriptiveIP = LobbyUtils.DescriptiveIpAddress(address); var cachedDescriptiveIP = LobbyUtils.DescriptiveIpAddress(address);

View File

@@ -810,7 +810,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (template == null || template.Id != editablePlayerTemplate.Id) if (template == null || template.Id != editablePlayerTemplate.Id)
template = editablePlayerTemplate.Clone(); template = editablePlayerTemplate.Clone();
LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null); LobbyUtils.SetupClientWidget(template, client, orderManager, client.Bot == null);
if (client.Bot != null) if (client.Bot != null)
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, modRules); LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, modRules);
@@ -829,7 +829,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (template == null || template.Id != nonEditablePlayerTemplate.Id) if (template == null || template.Id != nonEditablePlayerTemplate.Id)
template = nonEditablePlayerTemplate.Clone(); template = nonEditablePlayerTemplate.Clone();
LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null); LobbyUtils.SetupClientWidget(template, client, orderManager, client.Bot == null);
LobbyUtils.SetupNameWidget(template, slot, client); LobbyUtils.SetupNameWidget(template, slot, client);
LobbyUtils.SetupKickWidget(template, slot, client, orderManager, lobby, LobbyUtils.SetupKickWidget(template, slot, client, orderManager, lobby,
() => panel = PanelType.Kick, () => panel = PanelType.Players); () => panel = PanelType.Kick, () => panel = PanelType.Players);
@@ -879,7 +879,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
() => panel = PanelType.Kick, () => panel = PanelType.Players); () => panel = PanelType.Kick, () => panel = PanelType.Players);
} }
LobbyUtils.SetupClientWidget(template, null, c, orderManager, true); LobbyUtils.SetupClientWidget(template, c, orderManager, true);
template.IsVisible = () => true; template.IsVisible = () => true;
if (idx >= players.Children.Count) if (idx >= players.Children.Count)

View File

@@ -235,15 +235,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return ip; return ip;
} }
public static void SetupClientWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible) public static void SetupClientWidget(Widget parent, Session.Client c, OrderManager orderManager, bool visible)
{
var adminIndicator = parent.GetOrNull("ADMIN_INDICATOR");
if (adminIndicator != null)
adminIndicator.IsVisible = () => c.IsAdmin;
var block = parent.GetOrNull("LATENCY");
if (block != null)
{ {
parent.Get("ADMIN_INDICATOR").IsVisible = () => c.IsAdmin;
var block = parent.Get("LATENCY");
block.IsVisible = () => visible; block.IsVisible = () => visible;
if (visible) if (visible)
block.Get<ColorBlockWidget>("LATENCY_COLOR").GetColor = () => LatencyColor( block.Get<ColorBlockWidget>("LATENCY_COLOR").GetColor = () => LatencyColor(
orderManager.LobbyInfo.PingFromClient(c)); orderManager.LobbyInfo.PingFromClient(c));
}
var tooltip = parent.Get<ClientTooltipRegionWidget>("CLIENT_REGION"); var tooltip = parent.Get<ClientTooltipRegionWidget>("CLIENT_REGION");
tooltip.IsVisible = () => visible; tooltip.IsVisible = () => visible;

View File

@@ -82,6 +82,12 @@ Container@SKIRMISH_STATS:
X: 10 X: 10
Width: 150 Width: 150
Height: 25 Height: 25
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer: TOOLTIP_CONTAINER
Template: INGAME_CLIENT_TOOLTIP
X: 10
Width: 150
Height: 25
Image@FACTIONFLAG: Image@FACTIONFLAG:
X: 159 X: 159
Y: 6 Y: 6

View File

@@ -204,6 +204,30 @@ Background@CLIENT_TOOLTIP:
Height: 10 Height: 10
Font: TinyBold Font: TinyBold
Background@INGAME_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@LOCATION:
Y: 17
Height: 10
Font: TinyBold
Align: Center
Background@FACTION_DESCRIPTION_TOOLTIP: Background@FACTION_DESCRIPTION_TOOLTIP:
Logic: FactionTooltipLogic Logic: FactionTooltipLogic
Background: panel-black Background: panel-black

View File

@@ -82,6 +82,12 @@ Container@SKIRMISH_STATS:
X: 10 X: 10
Width: 150 Width: 150
Height: 25 Height: 25
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer: TOOLTIP_CONTAINER
Template: INGAME_CLIENT_TOOLTIP
X: 10
Width: 150
Height: 25
Image@FACTIONFLAG: Image@FACTIONFLAG:
X: 159 X: 159
Y: 3 Y: 3

View File

@@ -130,6 +130,30 @@ Background@CLIENT_TOOLTIP:
Height: 10 Height: 10
Font: TinyBold Font: TinyBold
Background@INGAME_CLIENT_TOOLTIP:
Logic: ClientTooltipLogic
Background: dialog4
Height: 41
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@LOCATION:
Y: 19
Height: 10
Font: TinyBold
Align: Center
Background@PRODUCTION_TOOLTIP: Background@PRODUCTION_TOOLTIP:
Logic: ProductionTooltipLogic Logic: ProductionTooltipLogic
Background: dialog3 Background: dialog3

View File

@@ -82,6 +82,12 @@ Container@SKIRMISH_STATS:
X: 10 X: 10
Width: 150 Width: 150
Height: 25 Height: 25
ClientTooltipRegion@CLIENT_REGION:
TooltipContainer: TOOLTIP_CONTAINER
Template: INGAME_CLIENT_TOOLTIP
X: 10
Width: 150
Height: 25
Image@FACTIONFLAG: Image@FACTIONFLAG:
X: 159 X: 159
Y: 6 Y: 6

View File

@@ -130,6 +130,30 @@ Background@CLIENT_TOOLTIP:
Height: 10 Height: 10
Font: TinyBold Font: TinyBold
Background@INGAME_CLIENT_TOOLTIP:
Logic: ClientTooltipLogic
Background: dialog4
Height: 41
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@LOCATION:
Y: 19
Height: 10
Font: TinyBold
Align: Center
Background@PRODUCTION_TOOLTIP: Background@PRODUCTION_TOOLTIP:
Logic: ProductionTooltipLogic Logic: ProductionTooltipLogic
Background: dialog4 Background: dialog4