add an in-game client tooltip without latency indicator
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user