Move SupportPowerInstance out of SupportPowerManager

This commit is contained in:
ScottNZ
2013-07-14 20:31:24 +12:00
parent fc458d191d
commit 8bec40eb9b
4 changed files with 68 additions and 68 deletions

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var baseHeight = widget.Bounds.Height; var baseHeight = widget.Bounds.Height;
var timeOffset = timeLabel.Bounds.X; var timeOffset = timeLabel.Bounds.X;
SupportPowerManager.SupportPowerInstance lastPower = null; SupportPowerInstance lastPower = null;
tooltipContainer.BeforeRender = () => tooltipContainer.BeforeRender = () =>
{ {
var sp = palette.TooltipPower; var sp = palette.TooltipPower;

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public readonly string TooltipContainer; public readonly string TooltipContainer;
public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP"; public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP";
public SupportPowerManager.SupportPowerInstance TooltipPower { get; private set; } public SupportPowerInstance TooltipPower { get; private set; }
Lazy<TooltipContainerWidget> tooltipContainer; Lazy<TooltipContainerWidget> tooltipContainer;
Rectangle eventBounds; Rectangle eventBounds;
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public class SupportPowerIcon public class SupportPowerIcon
{ {
public SupportPowerManager.SupportPowerInstance Power; public SupportPowerInstance Power;
public float2 Pos; public float2 Pos;
public Sprite Sprite; public Sprite Sprite;
} }

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self) public void Tick(Actor self)
{ {
foreach(var power in Powers.Values) foreach (var power in Powers.Values)
power.Tick(); power.Tick();
} }
@@ -100,7 +100,7 @@ namespace OpenRA.Mods.RA
Powers[key].Target(); Powers[key].Target();
} }
static readonly SupportPowerInstance[] NoInstances = {}; static readonly SupportPowerInstance[] NoInstances = { };
public IEnumerable<SupportPowerInstance> GetPowersForActor(Actor a) public IEnumerable<SupportPowerInstance> GetPowersForActor(Actor a)
{ {
@@ -110,85 +110,85 @@ namespace OpenRA.Mods.RA
return a.TraitsImplementing<SupportPower>() return a.TraitsImplementing<SupportPower>()
.Select(t => Powers[MakeKey(t)]); .Select(t => Powers[MakeKey(t)]);
} }
}
public class SupportPowerInstance public class SupportPowerInstance
{
readonly SupportPowerManager Manager;
readonly string Key;
public List<SupportPower> 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; Manager = manager;
readonly string Key; Key = key;
}
public List<SupportPower> Instances; static bool InstanceDisabled(SupportPower sp)
public int RemainingTime; {
public int TotalTime; return sp.self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
public bool Active { get; private set; } }
public bool Disabled { get; private set; }
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } } bool notifiedCharging;
public bool Ready { get { return Active && RemainingTime == 0; } } 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; var power = Instances.First();
Key = key; if (Manager.devMode.FastCharge && RemainingTime > 25)
} RemainingTime = 25;
static bool InstanceDisabled(SupportPower sp) if (RemainingTime > 0) --RemainingTime;
{ if (!notifiedCharging)
return sp.self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
}
bool notifiedCharging;
bool notifiedReady;
public void Tick()
{
Active = !Disabled && Instances.Any(i => !i.self.IsDisabled());
if (!Active)
return;
if (Active)
{ {
var power = Instances.First(); power.Charging(power.self, Key);
if (Manager.devMode.FastCharge && RemainingTime > 25) notifiedCharging = true;
RemainingTime = 25; }
if (RemainingTime > 0) --RemainingTime; if (RemainingTime == 0
if (!notifiedCharging) && !notifiedReady)
{ {
power.Charging(power.self, Key); power.Charged(power.self, Key);
notifiedCharging = true; notifiedReady = true;
}
if (RemainingTime == 0
&& !notifiedReady)
{
power.Charged(power.self, Key);
notifiedReady = true;
}
} }
} }
}
public void Target() public void Target()
{ {
if (!Ready) if (!Ready)
return; return;
Manager.self.World.OrderGenerator = Instances.First().OrderGenerator(Key, Manager); Manager.self.World.OrderGenerator = Instances.First().OrderGenerator(Key, Manager);
} }
public void Activate(Order order) public void Activate(Order order)
{ {
if (!Ready) if (!Ready)
return; return;
var power = Instances.First(i => !InstanceDisabled(i)); var power = Instances.First(i => !InstanceDisabled(i));
// Note: order.Subject is the *player* actor // Note: order.Subject is the *player* actor
power.Activate(power.self, order); power.Activate(power.self, order);
RemainingTime = TotalTime; RemainingTime = TotalTime;
notifiedCharging = notifiedReady = false; notifiedCharging = notifiedReady = false;
if (Info.OneShot) if (Info.OneShot)
Disabled = true; Disabled = true;
}
} }
} }

View File

@@ -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.Disabled) return "ON HOLD";
if (item.Ready) return "READY"; if (item.Ready) return "READY";