Sync replay support timers to original game time.

This commit is contained in:
Paul Chote
2016-01-10 23:52:12 +00:00
parent 652f38ff66
commit 353837e37b
2 changed files with 28 additions and 9 deletions

View File

@@ -20,11 +20,11 @@ namespace OpenRA.Mods.Common.Widgets
{ {
public class ObserverSupportPowerIconsWidget : Widget public class ObserverSupportPowerIconsWidget : Widget
{ {
public Func<Player> GetPlayer; readonly Animation icon;
Animation icon; readonly World world;
World world; readonly WorldRenderer worldRenderer;
WorldRenderer worldRenderer; readonly Dictionary<string, Animation> clocks;
Dictionary<string, Animation> clocks; readonly int timestep;
public int IconWidth = 32; public int IconWidth = 32;
public int IconHeight = 24; public int IconHeight = 24;
@@ -33,6 +33,7 @@ namespace OpenRA.Mods.Common.Widgets
public string ClockAnimation = "clock"; public string ClockAnimation = "clock";
public string ClockSequence = "idle"; public string ClockSequence = "idle";
public string ClockPalette = "chrome"; public string ClockPalette = "chrome";
public Func<Player> GetPlayer;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ObserverSupportPowerIconsWidget(World world, WorldRenderer worldRenderer) public ObserverSupportPowerIconsWidget(World world, WorldRenderer worldRenderer)
@@ -41,6 +42,14 @@ namespace OpenRA.Mods.Common.Widgets
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
clocks = new Dictionary<string, Animation>(); clocks = new Dictionary<string, Animation>();
icon = new Animation(world, "icon"); icon = new Animation(world, "icon");
// Timers should be synced to the effective game time, not the playback time.
GameSpeed speed;
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
if (gameSpeeds.Speeds.TryGetValue(world.LobbyInfo.GlobalSettings.GameSpeedType, out speed))
timestep = speed.Timestep;
else
timestep = world.Timestep;
} }
protected ObserverSupportPowerIconsWidget(ObserverSupportPowerIconsWidget other) protected ObserverSupportPowerIconsWidget(ObserverSupportPowerIconsWidget other)
@@ -51,6 +60,7 @@ namespace OpenRA.Mods.Common.Widgets
world = other.world; world = other.world;
worldRenderer = other.worldRenderer; worldRenderer = other.worldRenderer;
clocks = other.clocks; clocks = other.clocks;
timestep = other.timestep;
IconWidth = other.IconWidth; IconWidth = other.IconWidth;
IconHeight = other.IconHeight; IconHeight = other.IconHeight;
@@ -94,7 +104,7 @@ namespace OpenRA.Mods.Common.Widgets
WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer.Palette(ClockPalette), 0.5f); WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer.Palette(ClockPalette), 0.5f);
var tiny = Game.Renderer.Fonts["Tiny"]; var tiny = Game.Renderer.Fonts["Tiny"];
var text = GetOverlayForItem(item, world.Timestep); var text = GetOverlayForItem(item, timestep);
tiny.DrawTextWithContrast(text, tiny.DrawTextWithContrast(text,
location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0), location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0),
Color.White, Color.Black, 1); Color.White, Color.Black, 1);

View File

@@ -23,25 +23,34 @@ namespace OpenRA.Mods.Common.Widgets
public readonly string Format = "{0}: {1}"; public readonly string Format = "{0}: {1}";
public readonly TimerOrder Order = TimerOrder.Descending; public readonly TimerOrder Order = TimerOrder.Descending;
readonly World world; readonly int timestep;
readonly IEnumerable<SupportPowerInstance> powers; readonly IEnumerable<SupportPowerInstance> powers;
Pair<string, Color>[] texts; Pair<string, Color>[] texts;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public SupportPowerTimerWidget(World world) public SupportPowerTimerWidget(World world)
{ {
this.world = world;
powers = world.ActorsWithTrait<SupportPowerManager>() powers = world.ActorsWithTrait<SupportPowerManager>()
.Where(p => !p.Actor.IsDead && !p.Actor.Owner.NonCombatant) .Where(p => !p.Actor.IsDead && !p.Actor.Owner.NonCombatant)
.SelectMany(s => s.Trait.Powers.Values) .SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimer && !p.Disabled); .Where(p => p.Instances.Any() && p.Info.DisplayTimer && !p.Disabled);
// Timers in replays should be synced to the effective game time, not the playback time.
timestep = world.Timestep;
if (world.IsReplay)
{
GameSpeed speed;
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
if (gameSpeeds.Speeds.TryGetValue(world.LobbyInfo.GlobalSettings.GameSpeedType, out speed))
timestep = speed.Timestep;
}
} }
public override void Tick() public override void Tick()
{ {
texts = powers.Select(p => texts = powers.Select(p =>
{ {
var time = WidgetUtils.FormatTime(p.RemainingTime, false, world.Timestep); var time = WidgetUtils.FormatTime(p.RemainingTime, false, timestep);
var text = Format.F(p.Info.Description, time); var text = Format.F(p.Info.Description, time);
var color = !p.Ready || Game.LocalTick % 50 < 25 ? p.Instances[0].Self.Owner.Color.RGB : Color.White; var color = !p.Ready || Game.LocalTick % 50 < 25 ? p.Instances[0].Self.Owner.Color.RGB : Color.White;
return Pair.New(text, color); return Pair.New(text, color);