Move SupportPowersWidget into RA and generalize.
This commit is contained in:
@@ -79,8 +79,6 @@
|
||||
<Compile Include="Widgets\Logic\CncConquestObjectivesLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncMainMenuLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
||||
<Compile Include="WithFire.cs" />
|
||||
<Compile Include="WithRoof.cs" />
|
||||
<Compile Include="Widgets\Logic\ProductionTabsLogic.cs" />
|
||||
|
||||
@@ -540,6 +540,9 @@
|
||||
<Compile Include="Widgets\Logic\Ingame\IngamePowerBarLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\IngameSiloBarLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\AddRaceSuffixLogic.cs" />
|
||||
<Compile Include="Widgets\SupportPowersWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\SupportPowerBinLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\LoadIngamePlayerOrObserverUILogic.cs" />
|
||||
<Compile Include="Widgets\MenuButtonWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\DebugMenuLogic.cs" />
|
||||
|
||||
72
OpenRA.Mods.RA/Widgets/Logic/SupportPowerBinLogic.cs
Normal file
72
OpenRA.Mods.RA/Widgets/Logic/SupportPowerBinLogic.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class SupportPowerBinLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public SupportPowerBinLogic(Widget widget, World world)
|
||||
{
|
||||
var palette = widget.Get<SupportPowersWidget>("SUPPORT_PALETTE");
|
||||
|
||||
var background = widget.GetOrNull("PALETTE_BACKGROUND");
|
||||
var foreground = widget.GetOrNull("PALETTE_FOREGROUND");
|
||||
if (background != null || foreground != null)
|
||||
{
|
||||
Widget backgroundTemplate = null;
|
||||
Widget foregroundTemplate = null;
|
||||
|
||||
if (background != null)
|
||||
backgroundTemplate = background.Get("ICON_TEMPLATE");
|
||||
|
||||
if (foreground != null)
|
||||
foregroundTemplate = foreground.Get("ICON_TEMPLATE");
|
||||
|
||||
Action<int, int> updateBackground = (_, icons) =>
|
||||
{
|
||||
var rowHeight = palette.IconSize.Y + palette.IconMargin;
|
||||
|
||||
if (background != null)
|
||||
{
|
||||
background.RemoveChildren();
|
||||
|
||||
for (var i = 0; i < icons; i++)
|
||||
{
|
||||
var row = backgroundTemplate.Clone();
|
||||
row.Bounds.Y += i * rowHeight;
|
||||
background.AddChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
if (foreground != null)
|
||||
{
|
||||
foreground.RemoveChildren();
|
||||
|
||||
for (var i = 0; i < icons; i++)
|
||||
{
|
||||
var row = foregroundTemplate.Clone();
|
||||
row.Bounds.Y += i * rowHeight;
|
||||
foreground.AddChild(row);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
palette.OnIconCountChanged += updateBackground;
|
||||
|
||||
// Set the initial palette state
|
||||
updateBackground(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -12,7 +12,7 @@ using System;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class SupportPowerTooltipLogic
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -16,17 +16,22 @@ using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class SupportPowersWidget : Widget
|
||||
{
|
||||
[Translate] public readonly string ReadyText = "";
|
||||
[Translate] public readonly string HoldText = "";
|
||||
|
||||
public readonly int2 IconSize = new int2(64, 48);
|
||||
public readonly int IconMargin = 10;
|
||||
public readonly int2 IconSpriteOffset = int2.Zero;
|
||||
|
||||
public readonly string TooltipContainer;
|
||||
public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP";
|
||||
|
||||
public int Spacing = 10;
|
||||
public int IconCount { get; private set; }
|
||||
public event Action<int, int> OnIconCountChanged = (a, b) => {};
|
||||
|
||||
readonly WorldRenderer worldRenderer;
|
||||
readonly SupportPowerManager spm;
|
||||
@@ -67,12 +72,15 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
icons = new Dictionary<Rectangle, SupportPowerIcon>();
|
||||
var powers = spm.Powers.Values.Where(p => !p.Disabled);
|
||||
|
||||
var i = 0;
|
||||
var oldIconCount = IconCount;
|
||||
IconCount = 0;
|
||||
|
||||
var rb = RenderBounds;
|
||||
foreach (var p in powers)
|
||||
{
|
||||
var rect = new Rectangle(rb.X + 1, rb.Y + i * (48 + Spacing) + 1, 64, 48);
|
||||
var rect = new Rectangle(rb.X, rb.Y + IconCount * (IconSize.Y + IconMargin), IconSize.X, IconSize.Y);
|
||||
icon.Play(p.Info.Icon);
|
||||
|
||||
var power = new SupportPowerIcon()
|
||||
{
|
||||
Power = p,
|
||||
@@ -81,26 +89,24 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
};
|
||||
|
||||
icons.Add(rect, power);
|
||||
i++;
|
||||
IconCount++;
|
||||
}
|
||||
|
||||
eventBounds = (icons.Count == 0) ? Rectangle.Empty : icons.Keys.Aggregate(Rectangle.Union);
|
||||
eventBounds = icons.Any() ? icons.Keys.Aggregate(Rectangle.Union) : Rectangle.Empty;
|
||||
|
||||
if (oldIconCount != IconCount)
|
||||
OnIconCountChanged(oldIconCount, IconCount);
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
var iconSize = new float2(64, 48);
|
||||
var iconOffset = 0.5f * iconSize;
|
||||
|
||||
var iconOffset = 0.5f * IconSize.ToFloat2() + IconSpriteOffset;
|
||||
overlayFont = Game.Renderer.Fonts["TinyBold"];
|
||||
|
||||
holdOffset = iconOffset - overlayFont.Measure(HoldText) / 2;
|
||||
readyOffset = iconOffset - overlayFont.Measure(ReadyText) / 2;
|
||||
timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
|
||||
|
||||
// Background
|
||||
foreach (var rect in icons.Keys)
|
||||
WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1, 1, 1, 1));
|
||||
|
||||
// Icons
|
||||
foreach (var p in icons.Values)
|
||||
{
|
||||
@@ -110,6 +116,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
clock.PlayFetchIndex("idle",
|
||||
() => (p.Power.TotalTime - p.Power.RemainingTime)
|
||||
* (clock.CurrentSequence.Length - 1) / p.Power.TotalTime);
|
||||
|
||||
clock.Tick();
|
||||
WidgetUtils.DrawSHPCentered(clock.Image, p.Pos + iconOffset, worldRenderer);
|
||||
}
|
||||
@@ -140,14 +147,18 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||
new WidgetArgs() { { "palette", this } });
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
@@ -157,7 +168,8 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
var icon = icons.Where(i => i.Key.Contains(mi.Location))
|
||||
.Select(i => i.Value).FirstOrDefault();
|
||||
TooltipPower = (icon != null) ? icon.Power : null;
|
||||
|
||||
TooltipPower = icon != null ? icon.Power : null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -171,6 +183,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
if (!clicked.Power.Active)
|
||||
Sound.PlayToPlayer(spm.self.Owner, clicked.Power.Info.InsufficientPowerSound);
|
||||
|
||||
spm.Target(clicked.Power.Info.OrderName);
|
||||
}
|
||||
|
||||
@@ -182,12 +182,24 @@ Container@PLAYER_WIDGETS:
|
||||
WorldCommand:
|
||||
Width: WINDOW_RIGHT
|
||||
Height: WINDOW_BOTTOM
|
||||
SupportPowers:
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
Container@SUPPORT_POWERS:
|
||||
Logic: SupportPowerBinLogic
|
||||
X: 10
|
||||
Y: 10
|
||||
ReadyText: Ready
|
||||
HoldText: On Hold
|
||||
Children:
|
||||
Container@PALETTE_BACKGROUND:
|
||||
Children:
|
||||
Background@ICON_TEMPLATE:
|
||||
Width: 66
|
||||
Height: 50
|
||||
ClickThrough: false
|
||||
Background: panel-black
|
||||
SupportPowers@SUPPORT_PALETTE:
|
||||
X: 1
|
||||
Y: 1
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
ReadyText: Ready
|
||||
HoldText: On Hold
|
||||
Background@SIDEBAR_BACKGROUND:
|
||||
Logic: OrderButtonsChromeLogic
|
||||
X: WINDOW_RIGHT - 204
|
||||
|
||||
Reference in New Issue
Block a user