Strip the client block down to latency only.
This commit is contained in:
@@ -87,7 +87,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var pp = p.First;
|
||||
var client = world.LobbyInfo.ClientWithIndex(pp.ClientIndex);
|
||||
var item = playerTemplate.Clone();
|
||||
LobbyUtils.SetupClientWidget(item, client, orderManager, client != null && client.Bot == null);
|
||||
var nameLabel = item.Get<LabelWidget>("NAME");
|
||||
var nameFont = Game.Renderer.Fonts[nameLabel.Font];
|
||||
|
||||
@@ -137,7 +136,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
foreach (var client in spectators)
|
||||
{
|
||||
var item = playerTemplate.Clone();
|
||||
LobbyUtils.SetupClientWidget(item, client, orderManager, client != null && client.Bot == null);
|
||||
var nameLabel = item.Get<LabelWidget>("NAME");
|
||||
var nameFont = Game.Renderer.Fonts[nameLabel.Font];
|
||||
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2018 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
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.GetOrNull<LabelWidget>("LATENCY");
|
||||
if (latency != null)
|
||||
latencyFont = Game.Renderer.Fonts[latency.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];
|
||||
|
||||
var location = widget.Get<LabelWidget>("LOCATION");
|
||||
var locationFont = Game.Renderer.Fonts[location.Font];
|
||||
|
||||
var locationOffset = location.Bounds.Y;
|
||||
var addressOffset = ip.Bounds.Y;
|
||||
var latencyOffset = latency == null ? 0 : latency.Bounds.Y;
|
||||
var tooltipHeight = widget.Bounds.Height;
|
||||
|
||||
var margin = widget.Bounds.Width;
|
||||
|
||||
widget.IsVisible = () => (orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null);
|
||||
tooltipContainer.BeforeRender = () =>
|
||||
{
|
||||
if (!widget.IsVisible())
|
||||
return;
|
||||
|
||||
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 = 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;
|
||||
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;
|
||||
if (latency != null)
|
||||
latency.Bounds.Y = latencyOffset;
|
||||
location.Bounds.Y = locationOffset;
|
||||
widget.Bounds.Height = tooltipHeight;
|
||||
|
||||
if (admin.IsVisible())
|
||||
{
|
||||
ip.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;
|
||||
}
|
||||
|
||||
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);
|
||||
if (latency != null)
|
||||
{
|
||||
latency.GetText = () => LobbyUtils.LatencyDescription(ping);
|
||||
latency.GetColor = () => LobbyUtils.LatencyColor(ping);
|
||||
}
|
||||
|
||||
var address = LobbyUtils.GetExternalIP(clientIndex, orderManager);
|
||||
var cachedDescriptiveIP = LobbyUtils.DescriptiveIpAddress(address);
|
||||
ip.GetText = () => cachedDescriptiveIP;
|
||||
var cachedCountryLookup = GeoIP.LookupCountry(address);
|
||||
location.GetText = () => cachedCountryLookup;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2018 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class LatencyTooltipLogic : ChromeLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public LatencyTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, OrderManager orderManager, int clientIndex)
|
||||
{
|
||||
var latencyPrefix = widget.Get<LabelWidget>("LATENCY_PREFIX");
|
||||
var latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font];
|
||||
var latency = widget.Get<LabelWidget>("LATENCY");
|
||||
var latencyFont = Game.Renderer.Fonts[latency.Font];
|
||||
var rightMargin = widget.Bounds.Width;
|
||||
|
||||
latency.Bounds.X = latencyPrefix.Bounds.X + latencyPrefixFont.Measure(latencyPrefix.Text + " ").X;
|
||||
|
||||
widget.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null;
|
||||
tooltipContainer.BeforeRender = () =>
|
||||
{
|
||||
if (widget.IsVisible())
|
||||
widget.Bounds.Width = latency.Bounds.X + latencyFont.Measure(latency.GetText()).X + rightMargin;
|
||||
};
|
||||
|
||||
var client = orderManager.LobbyInfo.ClientWithIndex(clientIndex);
|
||||
var ping = orderManager.LobbyInfo.PingFromClient(client);
|
||||
latency.GetText = () => LobbyUtils.LatencyDescription(ping);
|
||||
latency.GetColor = () => LobbyUtils.LatencyColor(ping);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -574,7 +574,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (template == null || template.Id != editablePlayerTemplate.Id)
|
||||
template = editablePlayerTemplate.Clone();
|
||||
|
||||
LobbyUtils.SetupClientWidget(template, client, orderManager, client.Bot == null);
|
||||
LobbyUtils.SetupLatencyWidget(template, client, orderManager, client.Bot == null);
|
||||
|
||||
if (client.Bot != null)
|
||||
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map);
|
||||
@@ -593,7 +593,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (template == null || template.Id != nonEditablePlayerTemplate.Id)
|
||||
template = nonEditablePlayerTemplate.Clone();
|
||||
|
||||
LobbyUtils.SetupClientWidget(template, client, orderManager, client.Bot == null);
|
||||
LobbyUtils.SetupLatencyWidget(template, client, orderManager, client.Bot == null);
|
||||
LobbyUtils.SetupColorWidget(template, slot, client);
|
||||
LobbyUtils.SetupFactionWidget(template, slot, client, factions);
|
||||
|
||||
@@ -661,7 +661,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
LobbyUtils.SetupReadyWidget(template, null, client);
|
||||
}
|
||||
|
||||
LobbyUtils.SetupClientWidget(template, c, orderManager, true);
|
||||
LobbyUtils.SetupLatencyWidget(template, c, orderManager, true);
|
||||
template.IsVisible = () => true;
|
||||
|
||||
if (idx >= players.Children.Count)
|
||||
|
||||
@@ -305,12 +305,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static void SetupClientWidget(Widget parent, Session.Client c, OrderManager orderManager, bool visible)
|
||||
public static void SetupLatencyWidget(Widget parent, Session.Client c, OrderManager orderManager, bool visible)
|
||||
{
|
||||
var adminIndicator = parent.GetOrNull("ADMIN_INDICATOR");
|
||||
if (adminIndicator != null)
|
||||
adminIndicator.IsVisible = () => c != null && c.IsAdmin;
|
||||
|
||||
var block = parent.GetOrNull("LATENCY");
|
||||
if (block != null)
|
||||
{
|
||||
@@ -321,7 +317,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
orderManager.LobbyInfo.PingFromClient(c));
|
||||
}
|
||||
|
||||
var tooltip = parent.Get<ClientTooltipRegionWidget>("CLIENT_REGION");
|
||||
var tooltip = parent.Get<ClientTooltipRegionWidget>("LATENCY_REGION");
|
||||
tooltip.IsVisible = () => c != null && visible;
|
||||
if (c != null)
|
||||
tooltip.Bind(orderManager, c.Index);
|
||||
|
||||
Reference in New Issue
Block a user