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

View File

@@ -10,6 +10,7 @@
using System;
using System.Net;
using OpenRA.Graphics;
using OpenRA.Network;
using OpenRA.Widgets;
@@ -17,17 +18,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public class ClientTooltipLogic : ChromeLogic
{
SpriteFont latencyFont;
SpriteFont latencyPrefixFont;
[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 latency = widget.GetOrNull<LabelWidget>("LATENCY");
if (latency != null)
latencyFont = Game.Renderer.Fonts[latency.Font];
var latencyPrefix = widget.Get<LabelWidget>("LATENCY_PREFIX");
var latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font];
var latencyPrefix = widget.GetOrNull<LabelWidget>("LATENCY_PREFIX");
if (latencyPrefix != null)
latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font];
var ip = widget.Get<LabelWidget>("IP");
var addressFont = Game.Renderer.Fonts[ip.Font];
@@ -37,7 +43,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var locationOffset = location.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 margin = widget.Bounds.Width;
@@ -45,40 +51,48 @@ namespace OpenRA.Mods.Common.Widgets.Logic
tooltipContainer.IsVisible = () => (orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null);
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 adminWidth = adminFont.Measure(admin.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)));
widget.Bounds.Width = width + 2 * margin;
latency.Bounds.Width = widget.Bounds.Width;
if (latency != null)
latency.Bounds.Width = widget.Bounds.Width;
ip.Bounds.Width = widget.Bounds.Width;
admin.Bounds.Width = widget.Bounds.Width;
location.Bounds.Width = widget.Bounds.Width;
ip.Bounds.Y = addressOffset;
latency.Bounds.Y = latencyOffset;
if (latency != null)
latency.Bounds.Y = latencyOffset;
location.Bounds.Y = locationOffset;
widget.Bounds.Height = tooltipHeight;
if (admin.IsVisible())
{
ip.Bounds.Y += admin.Bounds.Height;
latency.Bounds.Y += admin.Bounds.Height;
if (latency != null)
latency.Bounds.Y += admin.Bounds.Height;
location.Bounds.Y += admin.Bounds.Height;
widget.Bounds.Height += admin.Bounds.Height;
}
latencyPrefix.Bounds.Y = latency.Bounds.Y;
latency.Bounds.X = latencyPrefixSize;
if (latencyPrefix != null)
latencyPrefix.Bounds.Y = latency.Bounds.Y;
if (latency != null)
latency.Bounds.X = latencyPrefixSize;
};
admin.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin;
var client = orderManager.LobbyInfo.ClientWithIndex(clientIndex);
var ping = orderManager.LobbyInfo.PingFromClient(client);
latency.GetText = () => LobbyUtils.LatencyDescription(ping);
latency.GetColor = () => LobbyUtils.LatencyColor(ping);
if (latency != null)
{
latency.GetText = () => LobbyUtils.LatencyDescription(ping);
latency.GetColor = () => LobbyUtils.LatencyColor(ping);
}
var address = LobbyUtils.GetExternalIP(clientIndex, orderManager);
var cachedDescriptiveIP = LobbyUtils.DescriptiveIpAddress(address);

View File

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

View File

@@ -235,15 +235,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
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)
{
parent.Get("ADMIN_INDICATOR").IsVisible = () => c.IsAdmin;
var block = parent.Get("LATENCY");
block.IsVisible = () => visible;
var adminIndicator = parent.GetOrNull("ADMIN_INDICATOR");
if (adminIndicator != null)
adminIndicator.IsVisible = () => c.IsAdmin;
if (visible)
block.Get<ColorBlockWidget>("LATENCY_COLOR").GetColor = () => LatencyColor(
orderManager.LobbyInfo.PingFromClient(c));
var block = parent.GetOrNull("LATENCY");
if (block != null)
{
block.IsVisible = () => visible;
if (visible)
block.Get<ColorBlockWidget>("LATENCY_COLOR").GetColor = () => LatencyColor(
orderManager.LobbyInfo.PingFromClient(c));
}
var tooltip = parent.Get<ClientTooltipRegionWidget>("CLIENT_REGION");
tooltip.IsVisible = () => visible;

View File

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

View File

@@ -204,6 +204,30 @@ Background@CLIENT_TOOLTIP:
Height: 10
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:
Logic: FactionTooltipLogic
Background: panel-black

View File

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

View File

@@ -130,6 +130,30 @@ Background@CLIENT_TOOLTIP:
Height: 10
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:
Logic: ProductionTooltipLogic
Background: dialog3

View File

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

View File

@@ -130,6 +130,30 @@ Background@CLIENT_TOOLTIP:
Height: 10
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:
Logic: ProductionTooltipLogic
Background: dialog4