Overhaul the replay sidebar.

This commit is contained in:
Paul Chote
2014-10-12 18:11:36 +13:00
parent 43f395b0c6
commit ad88378a0b
12 changed files with 660 additions and 276 deletions

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (world.Timestep == 1)
return "Max Speed";
return "{0:F1}x Speed".F(Game.Timestep * 1f / world.Timestep);
return "{0}% Speed".F(Game.Timestep * 100 / world.Timestep);
};
if (timer != null)
@@ -54,6 +54,16 @@ namespace OpenRA.Mods.RA.Widgets.Logic
status.IsVisible = shouldShowStatus;
status.GetText = statusText;
}
var percentage = widget.GetOrNull<LabelWidget>("GAME_TIMER_PERCENTAGE");
if (percentage != null)
{
var connection = orderManager.Connection as ReplayConnection;
if (connection != null && connection.TickCount != 0)
percentage.GetText = () => "({0}%)".F(orderManager.NetFrameNumber * 100 / connection.TickCount);
else
timer.Bounds.Width += percentage.Bounds.Width;
}
}
}
}

View File

@@ -8,41 +8,88 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Network;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ReplayControlBarLogic
{
enum PlaybackSpeed { Regular, Slow, Fast, Maximum }
readonly Dictionary<PlaybackSpeed, int> timesteps = new Dictionary<PlaybackSpeed, int>()
{
{ PlaybackSpeed.Regular, Game.Timestep },
{ PlaybackSpeed.Slow, Game.Timestep * 2 },
{ PlaybackSpeed.Fast, Game.Timestep / 2 },
{ PlaybackSpeed.Maximum, 1 },
};
[ObjectCreator.UseCtor]
public ReplayControlBarLogic(Widget widget, World world)
public ReplayControlBarLogic(Widget widget, World world, OrderManager orderManager)
{
if (world.IsReplay)
{
var container = widget.Get("REPLAY_PLAYER");
var connection = (ReplayConnection)orderManager.Connection;
var replayNetTicks = connection.TickCount;
var background = widget.Parent.GetOrNull("OBSERVER_CONTROL_BG");
if (background != null)
background.Bounds.Height += container.Bounds.Height;
container.Visible = true;
var speed = PlaybackSpeed.Regular;
var pauseButton = widget.Get<ButtonWidget>("BUTTON_PAUSE");
pauseButton.IsHighlighted = () => world.Timestep == 0;
pauseButton.IsVisible = () => world.Timestep != 0 && orderManager.NetFrameNumber < replayNetTicks;
pauseButton.OnClick = () => world.Timestep = 0;
var playButton = widget.Get<ButtonWidget>("BUTTON_PLAY");
playButton.IsVisible = () => world.Timestep == 0 || orderManager.NetFrameNumber >= replayNetTicks;
playButton.OnClick = () => world.Timestep = timesteps[speed];
playButton.IsDisabled = () => orderManager.NetFrameNumber >= replayNetTicks;
var slowButton = widget.Get<ButtonWidget>("BUTTON_SLOW");
slowButton.IsHighlighted = () => world.Timestep > Game.Timestep;
slowButton.OnClick = () => world.Timestep = Game.Timestep * 2;
slowButton.IsHighlighted = () => speed == PlaybackSpeed.Slow;
slowButton.IsDisabled = () => orderManager.NetFrameNumber >= replayNetTicks;
slowButton.OnClick = () =>
{
speed = PlaybackSpeed.Slow;
if (world.Timestep != 0)
world.Timestep = timesteps[speed];
};
var normalSpeedButton = widget.Get<ButtonWidget>("BUTTON_NORMALSPEED");
normalSpeedButton.IsHighlighted = () => world.Timestep == Game.Timestep;
normalSpeedButton.OnClick = () => world.Timestep = Game.Timestep;
var normalSpeedButton = widget.Get<ButtonWidget>("BUTTON_REGULAR");
normalSpeedButton.IsHighlighted = () => speed == PlaybackSpeed.Regular;
normalSpeedButton.IsDisabled = () => orderManager.NetFrameNumber >= replayNetTicks;
normalSpeedButton.OnClick = () =>
{
speed = PlaybackSpeed.Regular;
if (world.Timestep != 0)
world.Timestep = timesteps[speed];
};
var fastforwardButton = widget.Get<ButtonWidget>("BUTTON_FASTFORWARD");
fastforwardButton.IsHighlighted = () => world.Timestep == 1;
fastforwardButton.OnClick = () => world.Timestep = 1;
var fastButton = widget.Get<ButtonWidget>("BUTTON_FAST");
fastButton.IsHighlighted = () => speed == PlaybackSpeed.Fast;
fastButton.IsDisabled = () => orderManager.NetFrameNumber >= replayNetTicks;
fastButton.OnClick = () =>
{
speed = PlaybackSpeed.Fast;
if (world.Timestep != 0)
world.Timestep = timesteps[speed];
};
var maximumButton = widget.Get<ButtonWidget>("BUTTON_MAXIMUM");
maximumButton.IsHighlighted = () => speed == PlaybackSpeed.Maximum;
maximumButton.IsDisabled = () => orderManager.NetFrameNumber >= replayNetTicks;
maximumButton.OnClick = () =>
{
speed = PlaybackSpeed.Maximum;
if (world.Timestep != 0)
world.Timestep = timesteps[speed];
};
}
}
}