New spawn selector tooltip for C&C.

This commit is contained in:
Paul Chote
2013-04-06 14:49:13 +13:00
parent 0fb8878273
commit 2cb634b8f5
9 changed files with 144 additions and 14 deletions

View File

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