diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 545d89beae..7d26d0e8e9 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -79,8 +79,6 @@ - - diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index e1fefcecba..34b5bdb132 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -540,6 +540,9 @@ + + + diff --git a/OpenRA.Mods.RA/Widgets/Logic/SupportPowerBinLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SupportPowerBinLogic.cs new file mode 100644 index 0000000000..17991847e5 --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/Logic/SupportPowerBinLogic.cs @@ -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("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 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); + } + } + } +} diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SupportPowerTooltipLogic.cs similarity index 95% rename from OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs rename to OpenRA.Mods.RA/Widgets/Logic/SupportPowerTooltipLogic.cs index 0d1bb46690..1dad90ff84 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SupportPowerTooltipLogic.cs @@ -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 { diff --git a/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs b/OpenRA.Mods.RA/Widgets/SupportPowersWidget.cs similarity index 82% rename from OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs rename to OpenRA.Mods.RA/Widgets/SupportPowersWidget.cs index 00d4c57b50..eba2f0e550 100644 --- a/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs +++ b/OpenRA.Mods.RA/Widgets/SupportPowersWidget.cs @@ -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 OnIconCountChanged = (a, b) => {}; readonly WorldRenderer worldRenderer; readonly SupportPowerManager spm; @@ -67,12 +72,15 @@ namespace OpenRA.Mods.Cnc.Widgets icons = new Dictionary(); 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); } diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index ec2f763e19..44f7598cd1 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -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