Adjust lobby tooltip plumbing:

- Pass Client instead of Client ID
- Pass WorldRenderer and OrderManager to util helpers.
This commit is contained in:
Paul Chote
2018-07-06 20:51:00 +01:00
committed by abcdefg30
parent 97c03b00f2
commit 630936a211
4 changed files with 41 additions and 25 deletions

View File

@@ -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<TooltipContainerWidget> tooltipContainer;
readonly Lazy<TooltipContainerWidget> 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<TooltipContainerWidget>(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();
}
}

View File

@@ -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<LabelWidget>("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);

View File

@@ -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);

View File

@@ -320,10 +320,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var tooltip = parent.Get<ClientTooltipRegionWidget>("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<TextFieldWidget>("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<LabelWidget>("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<DropDownButtonWidget>("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<DropDownButtonWidget>("PLAYER_ACTION");
slot.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;