Adjust lobby tooltip plumbing:
- Pass Client instead of Client ID - Pass WorldRenderer and OrderManager to util helpers.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
@@ -17,11 +18,14 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
public class ClientTooltipRegionWidget : Widget
|
public class ClientTooltipRegionWidget : Widget
|
||||||
{
|
{
|
||||||
public readonly string Template;
|
|
||||||
public readonly string TooltipContainer;
|
public readonly string TooltipContainer;
|
||||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
readonly Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
|
|
||||||
|
public string Template;
|
||||||
|
|
||||||
OrderManager orderManager;
|
OrderManager orderManager;
|
||||||
int clientIndex;
|
WorldRenderer worldRenderer;
|
||||||
|
Session.Client client;
|
||||||
|
|
||||||
public ClientTooltipRegionWidget()
|
public ClientTooltipRegionWidget()
|
||||||
{
|
{
|
||||||
@@ -35,28 +39,37 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
TooltipContainer = other.TooltipContainer;
|
TooltipContainer = other.TooltipContainer;
|
||||||
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
tooltipContainer = Exts.Lazy(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
orderManager = other.orderManager;
|
orderManager = other.orderManager;
|
||||||
clientIndex = other.clientIndex;
|
worldRenderer = other.worldRenderer;
|
||||||
|
client = other.client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone() { return new ClientTooltipRegionWidget(this); }
|
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.orderManager = orderManager;
|
||||||
this.clientIndex = clientIndex;
|
this.worldRenderer = worldRenderer;
|
||||||
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseEntered()
|
public override void MouseEntered()
|
||||||
{
|
{
|
||||||
if (TooltipContainer == null)
|
if (TooltipContainer == null)
|
||||||
return;
|
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()
|
public override void MouseExited()
|
||||||
{
|
{
|
||||||
if (TooltipContainer == null)
|
if (TooltipContainer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tooltipContainer.Value.RemoveTooltip();
|
tooltipContainer.Value.RemoveTooltip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
public class LatencyTooltipLogic : ChromeLogic
|
public class LatencyTooltipLogic : ChromeLogic
|
||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[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 latencyPrefix = widget.Get<LabelWidget>("LATENCY_PREFIX");
|
||||||
var latencyPrefixFont = Game.Renderer.Fonts[latencyPrefix.Font];
|
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;
|
latency.Bounds.X = latencyPrefix.Bounds.X + latencyPrefixFont.Measure(latencyPrefix.Text + " ").X;
|
||||||
|
|
||||||
widget.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null;
|
widget.IsVisible = () => client != null;
|
||||||
tooltipContainer.BeforeRender = () =>
|
tooltipContainer.BeforeRender = () =>
|
||||||
{
|
{
|
||||||
if (widget.IsVisible())
|
if (widget.IsVisible())
|
||||||
widget.Bounds.Width = latency.Bounds.X + latencyFont.Measure(latency.GetText()).X + rightMargin;
|
widget.Bounds.Width = latency.Bounds.X + latencyFont.Measure(latency.GetText()).X + rightMargin;
|
||||||
};
|
};
|
||||||
|
|
||||||
var client = orderManager.LobbyInfo.ClientWithIndex(clientIndex);
|
|
||||||
var ping = orderManager.LobbyInfo.PingFromClient(client);
|
var ping = orderManager.LobbyInfo.PingFromClient(client);
|
||||||
latency.GetText = () => LobbyUtils.LatencyDescription(ping);
|
latency.GetText = () => LobbyUtils.LatencyDescription(ping);
|
||||||
latency.GetColor = () => LobbyUtils.LatencyColor(ping);
|
latency.GetColor = () => LobbyUtils.LatencyColor(ping);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
readonly Action onStart;
|
readonly Action onStart;
|
||||||
readonly Action onExit;
|
readonly Action onExit;
|
||||||
readonly OrderManager orderManager;
|
readonly OrderManager orderManager;
|
||||||
|
readonly WorldRenderer worldRenderer;
|
||||||
readonly bool skirmishMode;
|
readonly bool skirmishMode;
|
||||||
readonly Ruleset modRules;
|
readonly Ruleset modRules;
|
||||||
readonly World shellmapWorld;
|
readonly World shellmapWorld;
|
||||||
@@ -100,6 +101,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
lobby = widget;
|
lobby = widget;
|
||||||
this.modData = modData;
|
this.modData = modData;
|
||||||
this.orderManager = orderManager;
|
this.orderManager = orderManager;
|
||||||
|
this.worldRenderer = worldRenderer;
|
||||||
this.onStart = onStart;
|
this.onStart = onStart;
|
||||||
this.onExit = onExit;
|
this.onExit = onExit;
|
||||||
this.skirmishMode = skirmishMode;
|
this.skirmishMode = skirmishMode;
|
||||||
@@ -558,7 +560,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
template = emptySlotTemplate.Clone();
|
template = emptySlotTemplate.Clone();
|
||||||
|
|
||||||
if (isHost)
|
if (isHost)
|
||||||
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map);
|
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, worldRenderer, map);
|
||||||
else
|
else
|
||||||
LobbyUtils.SetupSlotWidget(template, slot, client);
|
LobbyUtils.SetupSlotWidget(template, slot, client);
|
||||||
|
|
||||||
@@ -577,9 +579,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
LobbyUtils.SetupLatencyWidget(template, client, orderManager, client.Bot == null);
|
LobbyUtils.SetupLatencyWidget(template, client, orderManager, client.Bot == null);
|
||||||
|
|
||||||
if (client.Bot != null)
|
if (client.Bot != null)
|
||||||
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map);
|
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, worldRenderer, map);
|
||||||
else
|
else
|
||||||
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
|
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager, worldRenderer);
|
||||||
|
|
||||||
LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, shellmapWorld, colorPreview);
|
LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, shellmapWorld, colorPreview);
|
||||||
LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, factions);
|
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.SetupEditableTeamWidget(template, slot, client, orderManager, map);
|
||||||
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map);
|
LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map);
|
||||||
LobbyUtils.SetupPlayerActionWidget(template, slot, client, orderManager, lobby,
|
LobbyUtils.SetupPlayerActionWidget(template, slot, client, orderManager, worldRenderer,
|
||||||
() => panel = PanelType.Kick, () => panel = PanelType.Players);
|
lobby, () => panel = PanelType.Kick, () => panel = PanelType.Players);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LobbyUtils.SetupNameWidget(template, slot, client);
|
LobbyUtils.SetupNameWidget(template, slot, client, orderManager, worldRenderer);
|
||||||
LobbyUtils.SetupTeamWidget(template, slot, client);
|
LobbyUtils.SetupTeamWidget(template, slot, client);
|
||||||
LobbyUtils.SetupSpawnWidget(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)
|
if (template == null || template.Id != editableSpectatorTemplate.Id)
|
||||||
template = editableSpectatorTemplate.Clone();
|
template = editableSpectatorTemplate.Clone();
|
||||||
|
|
||||||
LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager);
|
LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager, worldRenderer);
|
||||||
|
|
||||||
if (client.IsAdmin)
|
if (client.IsAdmin)
|
||||||
LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager, map);
|
LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager, map);
|
||||||
@@ -652,10 +654,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
template = nonEditableSpectatorTemplate.Clone();
|
template = nonEditableSpectatorTemplate.Clone();
|
||||||
|
|
||||||
if (isHost)
|
if (isHost)
|
||||||
LobbyUtils.SetupPlayerActionWidget(template, null, client, orderManager, lobby,
|
LobbyUtils.SetupPlayerActionWidget(template, null, client, orderManager, worldRenderer,
|
||||||
() => panel = PanelType.Kick, () => panel = PanelType.Players);
|
lobby, () => panel = PanelType.Kick, () => panel = PanelType.Players);
|
||||||
else
|
else
|
||||||
LobbyUtils.SetupNameWidget(template, null, client);
|
LobbyUtils.SetupNameWidget(template, null, client, orderManager, worldRenderer);
|
||||||
|
|
||||||
if (client.IsAdmin)
|
if (client.IsAdmin)
|
||||||
LobbyUtils.SetupReadyWidget(template, null, client);
|
LobbyUtils.SetupReadyWidget(template, null, client);
|
||||||
|
|||||||
@@ -320,10 +320,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var tooltip = parent.Get<ClientTooltipRegionWidget>("LATENCY_REGION");
|
var tooltip = parent.Get<ClientTooltipRegionWidget>("LATENCY_REGION");
|
||||||
tooltip.IsVisible = () => c != null && visible;
|
tooltip.IsVisible = () => c != null && visible;
|
||||||
if (c != null)
|
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");
|
var name = parent.Get<TextFieldWidget>("NAME");
|
||||||
name.IsVisible = () => true;
|
name.IsVisible = () => true;
|
||||||
@@ -363,7 +363,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
HideChildWidget(parent, "SLOT_OPTIONS");
|
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");
|
var name = parent.Get<LabelWidget>("NAME");
|
||||||
name.IsVisible = () => true;
|
name.IsVisible = () => true;
|
||||||
@@ -372,7 +372,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
name.GetText = () => label;
|
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");
|
var slot = parent.Get<DropDownButtonWidget>("SLOT_OPTIONS");
|
||||||
slot.IsVisible = () => true;
|
slot.IsVisible = () => true;
|
||||||
@@ -394,7 +395,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
HideChildWidget(parent, "SLOT_OPTIONS");
|
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");
|
var slot = parent.Get<DropDownButtonWidget>("PLAYER_ACTION");
|
||||||
slot.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
|
slot.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
|
||||||
|
|||||||
Reference in New Issue
Block a user