From 8bec40eb9b3102f95c0c46d1b5a2048c0bda1cc7 Mon Sep 17 00:00:00 2001 From: ScottNZ Date: Sun, 14 Jul 2013 20:31:24 +1200 Subject: [PATCH] Move SupportPowerInstance out of SupportPowerManager --- .../Widgets/Logic/SupportPowerTooltipLogic.cs | 2 +- .../Widgets/SupportPowersWidget.cs | 4 +- .../SupportPowers/SupportPowerManager.cs | 128 +++++++++--------- .../ObserverSupportPowerIconsWidget.cs | 2 +- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs index e54cf36e36..85060a45a3 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/SupportPowerTooltipLogic.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic var baseHeight = widget.Bounds.Height; var timeOffset = timeLabel.Bounds.X; - SupportPowerManager.SupportPowerInstance lastPower = null; + SupportPowerInstance lastPower = null; tooltipContainer.BeforeRender = () => { var sp = palette.TooltipPower; diff --git a/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs b/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs index 375ec3ee97..3f6b20a2a4 100755 --- a/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/SupportPowersWidget.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Widgets public readonly string TooltipContainer; public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP"; - public SupportPowerManager.SupportPowerInstance TooltipPower { get; private set; } + public SupportPowerInstance TooltipPower { get; private set; } Lazy tooltipContainer; Rectangle eventBounds; @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Cnc.Widgets public class SupportPowerIcon { - public SupportPowerManager.SupportPowerInstance Power; + public SupportPowerInstance Power; public float2 Pos; public Sprite Sprite; } diff --git a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs index c3c34b4f2c..bb9ba10718 100755 --- a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs @@ -83,7 +83,7 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { - foreach(var power in Powers.Values) + foreach (var power in Powers.Values) power.Tick(); } @@ -100,7 +100,7 @@ namespace OpenRA.Mods.RA Powers[key].Target(); } - static readonly SupportPowerInstance[] NoInstances = {}; + static readonly SupportPowerInstance[] NoInstances = { }; public IEnumerable GetPowersForActor(Actor a) { @@ -110,85 +110,85 @@ namespace OpenRA.Mods.RA return a.TraitsImplementing() .Select(t => Powers[MakeKey(t)]); } + } - public class SupportPowerInstance + public class SupportPowerInstance + { + readonly SupportPowerManager Manager; + readonly string Key; + + public List Instances; + public int RemainingTime; + public int TotalTime; + public bool Active { get; private set; } + public bool Disabled { get; private set; } + + public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } } + public bool Ready { get { return Active && RemainingTime == 0; } } + + public SupportPowerInstance(string key, SupportPowerManager manager) { - readonly SupportPowerManager Manager; - readonly string Key; + Manager = manager; + Key = key; + } - public List Instances; - public int RemainingTime; - public int TotalTime; - public bool Active { get; private set; } - public bool Disabled { get; private set; } + static bool InstanceDisabled(SupportPower sp) + { + return sp.self.TraitsImplementing().Any(d => d.Disabled); + } - public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } } - public bool Ready { get { return Active && RemainingTime == 0; } } + bool notifiedCharging; + bool notifiedReady; + public void Tick() + { + Active = !Disabled && Instances.Any(i => !i.self.IsDisabled()); + if (!Active) + return; - public SupportPowerInstance(string key, SupportPowerManager manager) + if (Active) { - Manager = manager; - Key = key; - } + var power = Instances.First(); + if (Manager.devMode.FastCharge && RemainingTime > 25) + RemainingTime = 25; - static bool InstanceDisabled(SupportPower sp) - { - return sp.self.TraitsImplementing().Any(d => d.Disabled); - } - - bool notifiedCharging; - bool notifiedReady; - public void Tick() - { - Active = !Disabled && Instances.Any(i => !i.self.IsDisabled()); - if (!Active) - return; - - if (Active) + if (RemainingTime > 0) --RemainingTime; + if (!notifiedCharging) { - var power = Instances.First(); - if (Manager.devMode.FastCharge && RemainingTime > 25) - RemainingTime = 25; + power.Charging(power.self, Key); + notifiedCharging = true; + } - if (RemainingTime > 0) --RemainingTime; - if (!notifiedCharging) - { - power.Charging(power.self, Key); - notifiedCharging = true; - } - - if (RemainingTime == 0 - && !notifiedReady) - { - power.Charged(power.self, Key); - notifiedReady = true; - } + if (RemainingTime == 0 + && !notifiedReady) + { + power.Charged(power.self, Key); + notifiedReady = true; } } + } - public void Target() - { - if (!Ready) - return; + public void Target() + { + if (!Ready) + return; - Manager.self.World.OrderGenerator = Instances.First().OrderGenerator(Key, Manager); - } + Manager.self.World.OrderGenerator = Instances.First().OrderGenerator(Key, Manager); + } - public void Activate(Order order) - { - if (!Ready) - return; + public void Activate(Order order) + { + if (!Ready) + return; - var power = Instances.First(i => !InstanceDisabled(i)); + var power = Instances.First(i => !InstanceDisabled(i)); - // Note: order.Subject is the *player* actor - power.Activate(power.self, order); - RemainingTime = TotalTime; - notifiedCharging = notifiedReady = false; + // Note: order.Subject is the *player* actor + power.Activate(power.self, order); + RemainingTime = TotalTime; + notifiedCharging = notifiedReady = false; - if (Info.OneShot) - Disabled = true; - } + if (Info.OneShot) + Disabled = true; } } diff --git a/OpenRA.Mods.RA/Widgets/ObserverSupportPowerIconsWidget.cs b/OpenRA.Mods.RA/Widgets/ObserverSupportPowerIconsWidget.cs index a95cd6756b..5b1a03aca7 100644 --- a/OpenRA.Mods.RA/Widgets/ObserverSupportPowerIconsWidget.cs +++ b/OpenRA.Mods.RA/Widgets/ObserverSupportPowerIconsWidget.cs @@ -90,7 +90,7 @@ namespace OpenRA.Mods.RA.Widgets } } - static string GetOverlayForItem(SupportPowerManager.SupportPowerInstance item) + static string GetOverlayForItem(SupportPowerInstance item) { if (item.Disabled) return "ON HOLD"; if (item.Ready) return "READY";