Add tooltip hook to SupportPowers; save some batches.
This commit is contained in:
@@ -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">
|
||||
|
||||
27
OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs
Normal file
27
OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ Container@INGAME_ROOT:
|
||||
Align:Center
|
||||
Font:Bold
|
||||
SupportPowers:
|
||||
TooltipContainer:TOOLTIP_CONTAINER
|
||||
X:10
|
||||
Y:10
|
||||
Background@SIDEBAR_BACKGROUND:
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user