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\SimpleTooltipLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
<Compile Include="Widgets\Logic\WorldTooltipLogic.cs" />
|
||||||
<Compile Include="Widgets\CncWorldInteractionControllerWidget.cs" />
|
<Compile Include="Widgets\CncWorldInteractionControllerWidget.cs" />
|
||||||
|
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ProductionTooltipLogic([ObjectCreator.Param] Widget widget,
|
public ProductionTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||||
[ObjectCreator.Param] ProductionPaletteWidget palette)
|
[ObjectCreator.Param] ProductionPaletteWidget palette)
|
||||||
{
|
{
|
||||||
widget.IsVisible = () => palette.TooltipActor != null;
|
widget.IsVisible = () => palette.TooltipActor != null;
|
||||||
widget.GetWidget<LabelWidget>("NAME").GetText = () => palette.TooltipActor;
|
widget.GetWidget<LabelWidget>("NAME").GetText = () => palette.TooltipActor;
|
||||||
|
|||||||
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 TabClick = "button.aud";
|
||||||
public readonly string TooltipContainer;
|
public readonly string TooltipContainer;
|
||||||
public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP";
|
public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP";
|
||||||
public string TooltipActor { get; private set; }
|
|
||||||
|
|
||||||
|
public string TooltipActor { get; private set; }
|
||||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
ProductionQueue currentQueue;
|
ProductionQueue currentQueue;
|
||||||
public ProductionQueue CurrentQueue
|
public ProductionQueue CurrentQueue
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ using OpenRA.Mods.RA;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets
|
namespace OpenRA.Mods.Cnc.Widgets
|
||||||
{
|
{
|
||||||
class SupportPowersWidget : Widget
|
public class SupportPowersWidget : Widget
|
||||||
{
|
{
|
||||||
public int Spacing = 10;
|
public int Spacing = 10;
|
||||||
|
|
||||||
@@ -27,6 +27,11 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
Animation clock;
|
Animation clock;
|
||||||
Dictionary<Rectangle, string> Icons = new Dictionary<Rectangle, string>();
|
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;
|
Rectangle eventBounds;
|
||||||
public override Rectangle EventBounds { get { return eventBounds; } }
|
public override Rectangle EventBounds { get { return eventBounds; } }
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
@@ -34,10 +39,12 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public SupportPowersWidget([ObjectCreator.Param] World world,
|
public SupportPowersWidget([ObjectCreator.Param] World world,
|
||||||
[ObjectCreator.Param] WorldRenderer worldRenderer)
|
[ObjectCreator.Param] WorldRenderer worldRenderer)
|
||||||
{
|
{
|
||||||
this.worldRenderer = worldRenderer;
|
this.worldRenderer = worldRenderer;
|
||||||
spm = world.LocalPlayer.PlayerActor.Trait<SupportPowerManager>();
|
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>() )
|
iconSprites = Rules.Info.Values.SelectMany( u => u.Traits.WithInterface<SupportPowerInfo>() )
|
||||||
.Select(u => u.Image).Distinct()
|
.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 holdOffset = new float2(32,24) - overlayFont.Measure("On Hold") / 2;
|
||||||
var readyOffset = new float2(32,24) - overlayFont.Measure("Ready") / 2;
|
var readyOffset = new float2(32,24) - overlayFont.Measure("Ready") / 2;
|
||||||
|
|
||||||
|
// Background
|
||||||
foreach (var kv in Icons)
|
foreach (var kv in Icons)
|
||||||
WidgetUtils.DrawPanel("panel-black", kv.Key.InflateBy(1,1,1,1));
|
WidgetUtils.DrawPanel("panel-black", kv.Key.InflateBy(1,1,1,1));
|
||||||
|
|
||||||
|
// Icons
|
||||||
foreach (var kv in Icons)
|
foreach (var kv in Icons)
|
||||||
{
|
{
|
||||||
var rect = kv.Key;
|
var rect = kv.Key;
|
||||||
@@ -87,6 +96,13 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
* (clock.CurrentSequence.Length - 1) / power.TotalTime);
|
* (clock.CurrentSequence.Length - 1) / power.TotalTime);
|
||||||
clock.Tick();
|
clock.Tick();
|
||||||
WidgetUtils.DrawSHP(clock.Image, drawPos, worldRenderer);
|
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)
|
if (power.Ready)
|
||||||
overlayFont.DrawTextWithContrast("Ready",
|
overlayFont.DrawTextWithContrast("Ready",
|
||||||
@@ -104,8 +120,30 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
RefreshIcons();
|
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)
|
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)
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ Container@INGAME_ROOT:
|
|||||||
Align:Center
|
Align:Center
|
||||||
Font:Bold
|
Font:Bold
|
||||||
SupportPowers:
|
SupportPowers:
|
||||||
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
X:10
|
X:10
|
||||||
Y:10
|
Y:10
|
||||||
Background@SIDEBAR_BACKGROUND:
|
Background@SIDEBAR_BACKGROUND:
|
||||||
|
|||||||
@@ -53,3 +53,17 @@ Background@PRODUCTION_TOOLTIP:
|
|||||||
Width:PARENT_RIGHT-10
|
Width:PARENT_RIGHT-10
|
||||||
Height:23
|
Height:23
|
||||||
Font:Bold
|
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