Add tooltip hook to SupportPowers; save some batches.

This commit is contained in:
Paul Chote
2011-07-05 22:29:36 +12:00
parent ca77f20f19
commit 7c72c1564e
7 changed files with 85 additions and 4 deletions

View File

@@ -103,6 +103,7 @@
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
<Compile Include="Widgets\CncWorldInteractionControllerWidget.cs" />
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -0,0 +1,27 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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 OpenRA.Support;
using OpenRA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets.Logic
{
public class SupportPowerTooltipLogic
{
[ObjectCreator.UseCtor]
public SupportPowerTooltipLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] SupportPowersWidget palette)
{
widget.IsVisible = () => palette.TooltipPower != null;
widget.GetWidget<LabelWidget>("NAME").GetText = () => palette.TooltipPower;
}
}
}

View File

@@ -35,8 +35,8 @@ namespace OpenRA.Mods.Cnc.Widgets
public readonly string TabClick = "button.aud";
public readonly string TooltipContainer;
public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP";
public string TooltipActor { get; private set; }
public string TooltipActor { get; private set; }
Lazy<TooltipContainerWidget> tooltipContainer;
ProductionQueue currentQueue;
public ProductionQueue CurrentQueue

View File

@@ -19,7 +19,7 @@ using OpenRA.Mods.RA;
namespace OpenRA.Mods.Cnc.Widgets
{
class SupportPowersWidget : Widget
public class SupportPowersWidget : Widget
{
public int Spacing = 10;
@@ -27,6 +27,11 @@ namespace OpenRA.Mods.Cnc.Widgets
Animation clock;
Dictionary<Rectangle, string> Icons = new Dictionary<Rectangle, string>();
public readonly string TooltipContainer;
public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP";
public string TooltipPower { get; private set; }
Lazy<TooltipContainerWidget> tooltipContainer;
Rectangle eventBounds;
public override Rectangle EventBounds { get { return eventBounds; } }
readonly WorldRenderer worldRenderer;
@@ -38,6 +43,8 @@ namespace OpenRA.Mods.Cnc.Widgets
{
this.worldRenderer = worldRenderer;
spm = world.LocalPlayer.PlayerActor.Trait<SupportPowerManager>();
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
iconSprites = Rules.Info.Values.SelectMany( u => u.Traits.WithInterface<SupportPowerInfo>() )
.Select(u => u.Image).Distinct()
@@ -71,9 +78,11 @@ namespace OpenRA.Mods.Cnc.Widgets
var holdOffset = new float2(32,24) - overlayFont.Measure("On Hold") / 2;
var readyOffset = new float2(32,24) - overlayFont.Measure("Ready") / 2;
// Background
foreach (var kv in Icons)
WidgetUtils.DrawPanel("panel-black", kv.Key.InflateBy(1,1,1,1));
// Icons
foreach (var kv in Icons)
{
var rect = kv.Key;
@@ -87,6 +96,13 @@ namespace OpenRA.Mods.Cnc.Widgets
* (clock.CurrentSequence.Length - 1) / power.TotalTime);
clock.Tick();
WidgetUtils.DrawSHP(clock.Image, drawPos, worldRenderer);
}
// Overlays
foreach (var kv in Icons)
{
var power = spm.Powers[kv.Value];
var drawPos = new float2(kv.Key.Location);
if (power.Ready)
overlayFont.DrawTextWithContrast("Ready",
@@ -104,8 +120,30 @@ namespace OpenRA.Mods.Cnc.Widgets
RefreshIcons();
}
public override void MouseEntered()
{
if (TooltipContainer == null)
return;
var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "palette", this }});
tooltipContainer.Value.SetTooltip(panel);
}
public override void MouseExited()
{
if (TooltipContainer == null) return;
tooltipContainer.Value.RemoveTooltip();
}
public override bool HandleMouseInput(MouseInput mi)
{
if (mi.Event == MouseInputEvent.Move)
{
TooltipPower = Icons.Where(i => i.Key.Contains(mi.Location))
.Select(i => i.Value).FirstOrDefault();
return false;
}
if (mi.Event != MouseInputEvent.Down)
return false;

View File

@@ -80,6 +80,7 @@ Container@INGAME_ROOT:
Align:Center
Font:Bold
SupportPowers:
TooltipContainer:TOOLTIP_CONTAINER
X:10
Y:10
Background@SIDEBAR_BACKGROUND:

View File

@@ -53,3 +53,17 @@ Background@PRODUCTION_TOOLTIP:
Width:PARENT_RIGHT-10
Height:23
Font:Bold
Background@SUPPORT_POWER_TOOLTIP:
Id:SUPPORT_POWER_TOOLTIP
Logic:SupportPowerTooltipLogic
Background:panel-black
Width:200
Height:25
Children:
Label@NAME:
Id:NAME
X:5
Width:PARENT_RIGHT-10
Height:23
Font:Bold