Rename *Time to *Ticks and increase internal resolution.
This commit is contained in:
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
if (viewer != null && !Info.DisplayStances.HasStance(self.Owner.Stances[viewer]))
|
||||
return 0;
|
||||
|
||||
return 1 - (float)power.RemainingTime / power.TotalTime;
|
||||
return 1 - (float)power.RemainingTicks / power.TotalTicks;
|
||||
}
|
||||
|
||||
Color ISelectionBar.GetColor() { return Info.Color; }
|
||||
|
||||
@@ -153,13 +153,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly string Key;
|
||||
|
||||
public readonly List<SupportPower> Instances = new List<SupportPower>();
|
||||
public readonly int TotalTime;
|
||||
public int RemainingTime { get; private set; }
|
||||
public readonly int TotalTicks;
|
||||
|
||||
protected int remainingSubTicks;
|
||||
public int RemainingTicks { get { return remainingSubTicks / 100; } }
|
||||
public bool Active { get; private set; }
|
||||
public bool Disabled { get { return (!prereqsAvailable && !Manager.DevMode.AllTech) || !instancesEnabled || oneShotFired; } }
|
||||
|
||||
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
|
||||
public bool Ready { get { return Active && RemainingTime == 0; } }
|
||||
public bool Ready { get { return Active && RemainingTicks == 0; } }
|
||||
|
||||
bool instancesEnabled;
|
||||
bool prereqsAvailable = true;
|
||||
@@ -170,8 +172,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public SupportPowerInstance(string key, SupportPowerInfo info, SupportPowerManager manager)
|
||||
{
|
||||
Key = key;
|
||||
TotalTime = info.ChargeInterval;
|
||||
RemainingTime = info.StartFullyCharged ? 0 : info.ChargeInterval;
|
||||
TotalTicks = info.ChargeInterval;
|
||||
remainingSubTicks = info.StartFullyCharged ? 0 : TotalTicks * 100;
|
||||
|
||||
Manager = manager;
|
||||
}
|
||||
@@ -181,14 +183,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
prereqsAvailable = available;
|
||||
|
||||
if (!available)
|
||||
RemainingTime = TotalTime;
|
||||
remainingSubTicks = TotalTicks * 100;
|
||||
}
|
||||
|
||||
public virtual void Tick()
|
||||
{
|
||||
instancesEnabled = Instances.Any(i => !i.IsTraitDisabled);
|
||||
if (!instancesEnabled)
|
||||
RemainingTime = TotalTime;
|
||||
remainingSubTicks = TotalTicks * 100;
|
||||
|
||||
Active = !Disabled && Instances.Any(i => !i.IsTraitPaused);
|
||||
if (!Active)
|
||||
@@ -197,18 +199,19 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Active)
|
||||
{
|
||||
var power = Instances.First();
|
||||
if (Manager.DevMode.FastCharge && RemainingTime > 25)
|
||||
RemainingTime = 25;
|
||||
if (Manager.DevMode.FastCharge && remainingSubTicks > 2500)
|
||||
remainingSubTicks = 2500;
|
||||
|
||||
if (remainingSubTicks > 0)
|
||||
remainingSubTicks = (remainingSubTicks - 100).Clamp(0, TotalTicks * 100);
|
||||
|
||||
if (RemainingTime > 0)
|
||||
--RemainingTime;
|
||||
if (!notifiedCharging)
|
||||
{
|
||||
power.Charging(power.Self, Key);
|
||||
notifiedCharging = true;
|
||||
}
|
||||
|
||||
if (RemainingTime == 0
|
||||
if (RemainingTicks == 0
|
||||
&& !notifiedReady)
|
||||
{
|
||||
power.Charged(power.Self, Key);
|
||||
@@ -248,7 +251,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Note: order.Subject is the *player* actor
|
||||
power.Activate(power.Self, order, Manager);
|
||||
RemainingTime = TotalTime;
|
||||
remainingSubTicks = TotalTicks * 100;
|
||||
notifiedCharging = notifiedReady = false;
|
||||
|
||||
if (Info.OneShot)
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
// HACK: This abuses knowledge of the internals of WidgetUtils.FormatTime
|
||||
// to efficiently work when the label is going to change, requiring a panel relayout
|
||||
var remainingSeconds = (int)Math.Ceiling(sp.RemainingTime * world.Timestep / 1000f);
|
||||
var remainingSeconds = (int)Math.Ceiling(sp.RemainingTicks * world.Timestep / 1000f);
|
||||
|
||||
var hotkey = icon.Hotkey != null ? icon.Hotkey.GetValue() : Hotkey.Invalid;
|
||||
if (sp == lastPower && hotkey == lastHotkey && lastRemainingSeconds == remainingSeconds)
|
||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
descLabel.Text = sp.Info.LongDesc.Replace("\\n", "\n");
|
||||
var descSize = descFont.Measure(descLabel.Text);
|
||||
|
||||
var remaining = WidgetUtils.FormatTime(sp.RemainingTime, world.Timestep);
|
||||
var remaining = WidgetUtils.FormatTime(sp.RemainingTicks, world.Timestep);
|
||||
var total = WidgetUtils.FormatTime(sp.Info.ChargeInterval, world.Timestep);
|
||||
timeLabel.Text = "{0} / {1}".F(remaining, total);
|
||||
var timeSize = timeFont.Measure(timeLabel.Text);
|
||||
|
||||
@@ -132,8 +132,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
var clock = clocks[power.a.Key];
|
||||
clock.PlayFetchIndex(ClockSequence,
|
||||
() => item.TotalTime == 0 ? 0 : ((item.TotalTime - item.RemainingTime)
|
||||
* (clock.CurrentSequence.Length - 1) / item.TotalTime));
|
||||
() => item.TotalTicks == 0 ? 0 : ((item.TotalTicks - item.RemainingTicks)
|
||||
* (clock.CurrentSequence.Length - 1) / item.TotalTicks));
|
||||
clock.Tick();
|
||||
WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer.Palette(ClockPalette), 0.5f);
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
if (item.Disabled) return "ON HOLD";
|
||||
if (item.Ready) return "READY";
|
||||
return WidgetUtils.FormatTime(item.RemainingTime, timestep);
|
||||
return WidgetUtils.FormatTime(item.RemainingTicks, timestep);
|
||||
}
|
||||
|
||||
public override Widget Clone()
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
texts = displayedPowers.Select(p =>
|
||||
{
|
||||
var time = WidgetUtils.FormatTime(p.RemainingTime, false, timestep);
|
||||
var time = WidgetUtils.FormatTime(p.RemainingTicks, false, timestep);
|
||||
var text = Format.F(p.Info.Description, time);
|
||||
var self = p.Instances[0].Self;
|
||||
var playerColor = self.Owner.Color;
|
||||
|
||||
@@ -205,8 +205,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
// Charge progress
|
||||
var sp = p.Power;
|
||||
clock.PlayFetchIndex(ClockSequence,
|
||||
() => sp.TotalTime == 0 ? clock.CurrentSequence.Length - 1 : (sp.TotalTime - sp.RemainingTime)
|
||||
* (clock.CurrentSequence.Length - 1) / sp.TotalTime);
|
||||
() => sp.TotalTicks == 0 ? clock.CurrentSequence.Length - 1 : (sp.TotalTicks - sp.RemainingTicks)
|
||||
* (clock.CurrentSequence.Length - 1) / sp.TotalTicks);
|
||||
|
||||
clock.Tick();
|
||||
WidgetUtils.DrawSHPCentered(clock.Image, p.Pos + iconOffset, p.IconClockPalette);
|
||||
@@ -224,7 +224,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
p.Pos + holdOffset,
|
||||
Color.White, Color.Black, 1);
|
||||
else
|
||||
overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(p.Power.RemainingTime, worldRenderer.World.Timestep),
|
||||
overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(p.Power.RemainingTicks, worldRenderer.World.Timestep),
|
||||
p.Pos + timeOffset,
|
||||
Color.White, Color.Black, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user