New spawn selector tooltip for C&C.
This commit is contained in:
@@ -217,6 +217,7 @@
|
||||
<Compile Include="World.cs" />
|
||||
<Compile Include="WorldUtils.cs" />
|
||||
<Compile Include="Network\ReplayRecorderConnection.cs" />
|
||||
<Compile Include="Widgets\TooltipContainerWidget.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -15,27 +15,39 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class MapPreviewWidget : Widget
|
||||
{
|
||||
public Func<Map> Map = () => null;
|
||||
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
||||
public Func<Dictionary<int2, Session.Client>> SpawnClients = () => new Dictionary<int2, Session.Client>();
|
||||
public Action<MouseInput> OnMouseDown = _ => {};
|
||||
public Action<int, int2> OnTooltip = (_, __) => { };
|
||||
public bool IgnoreMouseInput = false;
|
||||
public bool ShowSpawnPoints = true;
|
||||
|
||||
public MapPreviewWidget() : base() { }
|
||||
public readonly string TooltipContainer;
|
||||
public readonly string TooltipTemplate = "SPAWN_TOOLTIP";
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
public int TooltipSpawnIndex = -1;
|
||||
|
||||
public MapPreviewWidget() : base()
|
||||
{
|
||||
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
protected MapPreviewWidget(MapPreviewWidget other)
|
||||
: base(other)
|
||||
{
|
||||
lastMap = other.lastMap;
|
||||
Map = other.Map;
|
||||
SpawnColors = other.SpawnColors;
|
||||
SpawnClients = other.SpawnClients;
|
||||
ShowSpawnPoints = other.ShowSpawnPoints;
|
||||
TooltipTemplate = other.TooltipTemplate;
|
||||
TooltipContainer = other.TooltipContainer;
|
||||
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new MapPreviewWidget(this); }
|
||||
@@ -52,6 +64,18 @@ namespace OpenRA.Widgets
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "preview", this }});
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public int2 ConvertToPreview(int2 point)
|
||||
{
|
||||
var map = Map();
|
||||
@@ -104,9 +128,10 @@ namespace OpenRA.Widgets
|
||||
new float2(MapRect.Location),
|
||||
new float2(MapRect.Size));
|
||||
|
||||
TooltipSpawnIndex = -1;
|
||||
if (ShowSpawnPoints)
|
||||
{
|
||||
var colors = SpawnColors();
|
||||
var colors = SpawnClients().ToDictionary(c => c.Key, c => c.Value.ColorRamp.GetColor(0));
|
||||
|
||||
var spawnPoints = map.GetSpawnPoints().ToList();
|
||||
foreach (var p in spawnPoints)
|
||||
@@ -123,7 +148,11 @@ namespace OpenRA.Widgets
|
||||
|
||||
if ((pos - Viewport.LastMousePos).LengthSquared < 64)
|
||||
{
|
||||
OnTooltip(spawnPoints.IndexOf(p) + 1, pos);
|
||||
TooltipSpawnIndex = spawnPoints.IndexOf(p) + 1;
|
||||
|
||||
// Legacy tooltip behavior
|
||||
if (TooltipContainer == null)
|
||||
OnTooltip(TooltipSpawnIndex, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,10 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Widgets;
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
namespace OpenRA.Widgets
|
||||
{
|
||||
public class TooltipContainerWidget : Widget
|
||||
{
|
||||
@@ -111,10 +111,10 @@
|
||||
<Compile Include="Widgets\ProductionTabsWidget.cs" />
|
||||
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
||||
<Compile Include="Widgets\ToggleButtonWidget.cs" />
|
||||
<Compile Include="Widgets\TooltipContainerWidget.cs" />
|
||||
<Compile Include="WithFire.cs" />
|
||||
<Compile Include="WithRoof.cs" />
|
||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\SpawnSelectorTooltipLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
79
OpenRA.Mods.Cnc/Widgets/Logic/SpawnSelectorTooltipLogic.cs
Normal file
79
OpenRA.Mods.Cnc/Widgets/Logic/SpawnSelectorTooltipLogic.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Widgets;
|
||||
using OpenRA.Network;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class SpawnSelectorTooltipLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public SpawnSelectorTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, MapPreviewWidget preview)
|
||||
{
|
||||
widget.IsVisible = () => preview.TooltipSpawnIndex != -1;
|
||||
var label = widget.Get<LabelWidget>("LABEL");
|
||||
var flag = widget.Get<ImageWidget>("FLAG");
|
||||
var team = widget.Get<LabelWidget>("TEAM");
|
||||
|
||||
var ownerFont = Game.Renderer.Fonts[label.Font];
|
||||
var teamFont = Game.Renderer.Fonts[team.Font];
|
||||
var cachedWidth = 0;
|
||||
var labelText = "";
|
||||
string playerCountry = null;
|
||||
var playerTeam = -1;
|
||||
|
||||
tooltipContainer.BeforeRender = () =>
|
||||
{
|
||||
var client = preview.SpawnClients().Values.FirstOrDefault(c => c.SpawnPoint == preview.TooltipSpawnIndex);
|
||||
|
||||
var teamWidth = 0;
|
||||
if (client == null)
|
||||
{
|
||||
labelText = "Available spawn";
|
||||
playerCountry = null;
|
||||
playerTeam = 0;
|
||||
widget.Bounds.Height = 25;
|
||||
}
|
||||
else
|
||||
{
|
||||
labelText = client.Name;
|
||||
playerCountry = client.Country;
|
||||
playerTeam = client.Team;
|
||||
widget.Bounds.Height = playerTeam > 0 ? 40 : 25;
|
||||
teamWidth = teamFont.Measure(team.GetText()).X;
|
||||
}
|
||||
|
||||
label.Bounds.X = playerCountry != null ? flag.Bounds.Right + 5 : 5;
|
||||
|
||||
var textWidth = ownerFont.Measure(labelText).X;
|
||||
if (textWidth != cachedWidth)
|
||||
{
|
||||
label.Bounds.Width = textWidth;
|
||||
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
|
||||
}
|
||||
|
||||
widget.Bounds.Width = Math.Max(teamWidth + 10, label.Bounds.Right + 5);
|
||||
team.Bounds.Width = widget.Bounds.Width;
|
||||
};
|
||||
|
||||
label.GetText = () => labelText;
|
||||
flag.IsVisible = () => playerCountry != null;
|
||||
flag.GetImageCollection = () => "flags";
|
||||
flag.GetImageName = () => playerCountry;
|
||||
team.GetText = () => "Team {0}".F(playerTeam);
|
||||
team.IsVisible = () => playerTeam > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
mapPreview.Map = () => Map;
|
||||
mapPreview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint( orderManager, mapPreview, Map, mi );
|
||||
mapPreview.OnTooltip = (spawnPoint, pos) => LobbyUtils.ShowSpawnPointTooltip(orderManager, spawnPoint, pos);
|
||||
mapPreview.SpawnColors = () => LobbyUtils.GetSpawnColors(orderManager, Map);
|
||||
mapPreview.SpawnClients = () => LobbyUtils.GetSpawnClients(orderManager, Map);
|
||||
|
||||
var mapTitle = lobby.GetOrNull<LabelWidget>("MAP_TITLE");
|
||||
if (mapTitle != null)
|
||||
|
||||
@@ -149,14 +149,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
color.AttachPanel(colorChooser);
|
||||
}
|
||||
|
||||
public static Dictionary<int2, Color> GetSpawnColors(OrderManager orderManager, Map map)
|
||||
public static Dictionary<int2, Session.Client> GetSpawnClients(OrderManager orderManager, Map map)
|
||||
{
|
||||
var spawns = map.GetSpawnPoints();
|
||||
return orderManager.LobbyInfo.Clients
|
||||
.Where( c => c.SpawnPoint != 0)
|
||||
.ToDictionary(
|
||||
c => spawns[c.SpawnPoint - 1],
|
||||
c => c.ColorRamp.GetColor(0));
|
||||
.Where(c => c.SpawnPoint != 0)
|
||||
.ToDictionary(
|
||||
c => spawns[c.SpawnPoint - 1],
|
||||
c => c);
|
||||
}
|
||||
|
||||
public static void SelectSpawnPoint(OrderManager orderManager, MapPreviewWidget mapPreview, Map map, MouseInput mi)
|
||||
|
||||
@@ -32,6 +32,7 @@ Container@SERVER_LOBBY:
|
||||
Y:1
|
||||
Width:192
|
||||
Height:192
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
Label@MAP_TITLE:
|
||||
X:PARENT_RIGHT-15-WIDTH
|
||||
Y:227
|
||||
@@ -403,6 +404,7 @@ Container@SERVER_LOBBY:
|
||||
Height:25
|
||||
Align:Right
|
||||
Text:Chat:
|
||||
TooltipContainer@TOOLTIP_CONTAINER:
|
||||
Button@DISCONNECT_BUTTON:
|
||||
X:0
|
||||
Y:499
|
||||
|
||||
@@ -99,3 +99,23 @@ Background@SUPPORT_POWER_TOOLTIP:
|
||||
Y:20
|
||||
Font:TinyBold
|
||||
VAlign:Top
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic:SpawnSelectorTooltipLogic
|
||||
Background:panel-black
|
||||
Width:141
|
||||
Children:
|
||||
Label@LABEL:
|
||||
X:5
|
||||
Height:23
|
||||
Font:Bold
|
||||
Image@FLAG:
|
||||
X:5
|
||||
Y:5
|
||||
Width:32
|
||||
Height:16
|
||||
Label@TEAM:
|
||||
Y:21
|
||||
Height:15
|
||||
Font:TinyBold
|
||||
Align:center
|
||||
Reference in New Issue
Block a user