diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 757a60997a..f1a774b000 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -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("NAME"); var nameFont = Game.Renderer.Fonts[nameLabel.Font]; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs index c371b210bb..824c018121 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs @@ -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("ADMIN"); var adminFont = Game.Renderer.Fonts[admin.Font]; - var latency = widget.Get("LATENCY"); - var latencyFont = Game.Renderer.Fonts[latency.Font]; + var latency = widget.GetOrNull("LATENCY"); + if (latency != null) + latencyFont = Game.Renderer.Fonts[latency.Font]; - var latencyPrefix = widget.Get("LATENCY_PREFIX"); - var latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font]; + var latencyPrefix = widget.GetOrNull("LATENCY_PREFIX"); + if (latencyPrefix != null) + latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font]; var ip = widget.Get("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); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 988ecd6867..9db7f06e24 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -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) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 6fa7b03f36..2032b5178b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -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("LATENCY_COLOR").GetColor = () => LatencyColor( - orderManager.LobbyInfo.PingFromClient(c)); + var block = parent.GetOrNull("LATENCY"); + if (block != null) + { + block.IsVisible = () => visible; + + if (visible) + block.Get("LATENCY_COLOR").GetColor = () => LatencyColor( + orderManager.LobbyInfo.PingFromClient(c)); + } var tooltip = parent.Get("CLIENT_REGION"); tooltip.IsVisible = () => visible; diff --git a/mods/cnc/chrome/ingame-infostats.yaml b/mods/cnc/chrome/ingame-infostats.yaml index 84935afb94..0c6f13ecd1 100644 --- a/mods/cnc/chrome/ingame-infostats.yaml +++ b/mods/cnc/chrome/ingame-infostats.yaml @@ -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 diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index 8d4d470f6a..42ee7a806f 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -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 diff --git a/mods/d2k/chrome/ingame-infostats.yaml b/mods/d2k/chrome/ingame-infostats.yaml index d2d3c84bde..1d0fa2b666 100644 --- a/mods/d2k/chrome/ingame-infostats.yaml +++ b/mods/d2k/chrome/ingame-infostats.yaml @@ -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 diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml index 1417d3b3af..b658de7b69 100644 --- a/mods/d2k/chrome/tooltips.yaml +++ b/mods/d2k/chrome/tooltips.yaml @@ -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 diff --git a/mods/ra/chrome/ingame-infostats.yaml b/mods/ra/chrome/ingame-infostats.yaml index 8262c4a8b6..993cff768d 100644 --- a/mods/ra/chrome/ingame-infostats.yaml +++ b/mods/ra/chrome/ingame-infostats.yaml @@ -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 diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml index ba039de479..fa1cef3332 100644 --- a/mods/ra/chrome/tooltips.yaml +++ b/mods/ra/chrome/tooltips.yaml @@ -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