From 630936a211e3c876a85f5e6157ae12581fbf852f Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 6 Jul 2018 20:51:00 +0100 Subject: [PATCH] Adjust lobby tooltip plumbing: - Pass Client instead of Client ID - Pass WorldRenderer and OrderManager to util helpers. --- .../Widgets/ClientTooltipRegionWidget.cs | 27 ++++++++++++++----- .../Logic/Lobby/LatencyTooltipLogic.cs | 5 ++-- .../Widgets/Logic/Lobby/LobbyLogic.cs | 22 ++++++++------- .../Widgets/Logic/Lobby/LobbyUtils.cs | 12 +++++---- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/ClientTooltipRegionWidget.cs b/OpenRA.Mods.Common/Widgets/ClientTooltipRegionWidget.cs index 9ae59e675f..9f78d5bbef 100644 --- a/OpenRA.Mods.Common/Widgets/ClientTooltipRegionWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ClientTooltipRegionWidget.cs @@ -10,6 +10,7 @@ #endregion using System; +using OpenRA.Graphics; using OpenRA.Network; using OpenRA.Widgets; @@ -17,11 +18,14 @@ namespace OpenRA.Mods.Common.Widgets { public class ClientTooltipRegionWidget : Widget { - public readonly string Template; public readonly string TooltipContainer; - Lazy tooltipContainer; + readonly Lazy tooltipContainer; + + public string Template; + OrderManager orderManager; - int clientIndex; + WorldRenderer worldRenderer; + Session.Client client; public ClientTooltipRegionWidget() { @@ -35,28 +39,37 @@ namespace OpenRA.Mods.Common.Widgets TooltipContainer = other.TooltipContainer; tooltipContainer = Exts.Lazy(() => Ui.Root.Get(TooltipContainer)); orderManager = other.orderManager; - clientIndex = other.clientIndex; + worldRenderer = other.worldRenderer; + client = other.client; } public override Widget Clone() { return new ClientTooltipRegionWidget(this); } - public void Bind(OrderManager orderManager, int clientIndex) + public void Bind(OrderManager orderManager, WorldRenderer worldRenderer, Session.Client client) { this.orderManager = orderManager; - this.clientIndex = clientIndex; + this.worldRenderer = worldRenderer; + this.client = client; } public override void MouseEntered() { if (TooltipContainer == null) return; - tooltipContainer.Value.SetTooltip(Template, new WidgetArgs() { { "orderManager", orderManager }, { "clientIndex", clientIndex } }); + + tooltipContainer.Value.SetTooltip(Template, new WidgetArgs() + { + { "orderManager", orderManager }, + { "worldRenderer", worldRenderer }, + { "client", client } + }); } public override void MouseExited() { if (TooltipContainer == null) return; + tooltipContainer.Value.RemoveTooltip(); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LatencyTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LatencyTooltipLogic.cs index c2a2118507..146734c956 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LatencyTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LatencyTooltipLogic.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public class LatencyTooltipLogic : ChromeLogic { [ObjectCreator.UseCtor] - public LatencyTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, OrderManager orderManager, int clientIndex) + public LatencyTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, OrderManager orderManager, Session.Client client) { var latencyPrefix = widget.Get("LATENCY_PREFIX"); var latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font]; @@ -29,14 +29,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic latency.Bounds.X = latencyPrefix.Bounds.X + latencyPrefixFont.Measure(latencyPrefix.Text + " ").X; - widget.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null; + widget.IsVisible = () => client != 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); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index b54342082c..ad2749ea0d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -29,6 +29,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Action onStart; readonly Action onExit; readonly OrderManager orderManager; + readonly WorldRenderer worldRenderer; readonly bool skirmishMode; readonly Ruleset modRules; readonly World shellmapWorld; @@ -100,6 +101,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic lobby = widget; this.modData = modData; this.orderManager = orderManager; + this.worldRenderer = worldRenderer; this.onStart = onStart; this.onExit = onExit; this.skirmishMode = skirmishMode; @@ -558,7 +560,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic template = emptySlotTemplate.Clone(); if (isHost) - LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map); + LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, worldRenderer, map); else LobbyUtils.SetupSlotWidget(template, slot, client); @@ -577,9 +579,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic LobbyUtils.SetupLatencyWidget(template, client, orderManager, client.Bot == null); if (client.Bot != null) - LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map); + LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, worldRenderer, map); else - LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager); + LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager, worldRenderer); LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, shellmapWorld, colorPreview); LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, factions); @@ -601,12 +603,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic { LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, map); LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map); - LobbyUtils.SetupPlayerActionWidget(template, slot, client, orderManager, lobby, - () => panel = PanelType.Kick, () => panel = PanelType.Players); + LobbyUtils.SetupPlayerActionWidget(template, slot, client, orderManager, worldRenderer, + lobby, () => panel = PanelType.Kick, () => panel = PanelType.Players); } else { - LobbyUtils.SetupNameWidget(template, slot, client); + LobbyUtils.SetupNameWidget(template, slot, client, orderManager, worldRenderer); LobbyUtils.SetupTeamWidget(template, slot, client); LobbyUtils.SetupSpawnWidget(template, slot, client); } @@ -640,7 +642,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (template == null || template.Id != editableSpectatorTemplate.Id) template = editableSpectatorTemplate.Clone(); - LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager); + LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager, worldRenderer); if (client.IsAdmin) LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager, map); @@ -652,10 +654,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic template = nonEditableSpectatorTemplate.Clone(); if (isHost) - LobbyUtils.SetupPlayerActionWidget(template, null, client, orderManager, lobby, - () => panel = PanelType.Kick, () => panel = PanelType.Players); + LobbyUtils.SetupPlayerActionWidget(template, null, client, orderManager, worldRenderer, + lobby, () => panel = PanelType.Kick, () => panel = PanelType.Players); else - LobbyUtils.SetupNameWidget(template, null, client); + LobbyUtils.SetupNameWidget(template, null, client, orderManager, worldRenderer); if (client.IsAdmin) LobbyUtils.SetupReadyWidget(template, null, client); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index d32c16a0a7..ab1cc01442 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -320,10 +320,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic var tooltip = parent.Get("LATENCY_REGION"); tooltip.IsVisible = () => c != null && visible; if (c != null) - tooltip.Bind(orderManager, c.Index); + tooltip.Bind(orderManager, null, c); } - public static void SetupEditableNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager) + public static void SetupEditableNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, WorldRenderer worldRenderer) { var name = parent.Get("NAME"); name.IsVisible = () => true; @@ -363,7 +363,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic HideChildWidget(parent, "SLOT_OPTIONS"); } - public static void SetupNameWidget(Widget parent, Session.Slot s, Session.Client c) + public static void SetupNameWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, WorldRenderer worldRenderer) { var name = parent.Get("NAME"); name.IsVisible = () => true; @@ -372,7 +372,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic name.GetText = () => label; } - public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map) + public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, + OrderManager orderManager, WorldRenderer worldRenderer, MapPreview map) { var slot = parent.Get("SLOT_OPTIONS"); slot.IsVisible = () => true; @@ -394,7 +395,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic HideChildWidget(parent, "SLOT_OPTIONS"); } - public static void SetupPlayerActionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, Widget lobby, Action before, Action after) + public static void SetupPlayerActionWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, + WorldRenderer worldRenderer, Widget lobby, Action before, Action after) { var slot = parent.Get("PLAYER_ACTION"); slot.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;