BizHawk/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs

120 lines
3.3 KiB
C#
Raw Normal View History

2014-10-17 17:58:48 +00:00
using System.Linq;
using System.IO;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class TAStudio
{
/// <summary>
/// Only goes to go to the frame if it is an event before current emulation, otherwise it is just a future event that can freely be edited
/// </summary>
private void GoToLastEmulatedFrameIfNecessary(int frame)
{
if (frame != Emulator.Frame) // Don't go to a frame if you are already on it!
2014-10-17 17:58:48 +00:00
{
int restoreFrame = Emulator.Frame;
2014-10-17 17:58:48 +00:00
if (frame <= Emulator.Frame)
2014-10-17 17:58:48 +00:00
{
GoToFrame(frame);
}
if (!_autoRestoreFrame.HasValue || _autoRestoreFrame.Value < restoreFrame)
_autoRestoreFrame = restoreFrame;
2014-10-17 17:58:48 +00:00
}
}
// SuuperW: I changed this to public so that it could be used by MarkerControl.cs
public void GoToFrame(int frame)
2014-10-17 17:58:48 +00:00
{
// If seeking to a frame before or at the end of the movie, use StartAtNearestFrameAndEmulate
// Otherwise, load the latest state (if not already there) and seek while recording.
2014-10-17 17:58:48 +00:00
if (frame <= CurrentTasMovie.InputLogLength)
2014-10-17 17:58:48 +00:00
{
// Get as close as we can then emulate there
StartAtNearestFrameAndEmulate(frame);
MaybeFollowCursor();
2014-10-17 17:58:48 +00:00
}
else // Emulate to a future frame
{
if (frame == Emulator.Frame + 1) // We are at the end of the movie and advancing one frame, therefore we are recording, simply emulate a frame
2014-10-17 17:58:48 +00:00
{
2015-03-23 20:15:35 +00:00
bool wasPaused = GlobalWin.MainForm.EmulatorPaused;
GlobalWin.MainForm.FrameAdvance();
2015-03-23 20:15:35 +00:00
if (!wasPaused)
GlobalWin.MainForm.UnpauseEmulator();
2014-10-17 17:58:48 +00:00
}
else
2014-10-17 17:58:48 +00:00
{
CurrentTasMovie.SwitchToPlay();
int lastState = CurrentTasMovie.TasStateManager.GetStateClosestToFrame(frame).Key; // Simply getting the last state doesn't work if that state is the frame. [dispaly isn't saved in the state, need to emulate to frame]
if (lastState > Emulator.Frame)
LoadState(CurrentTasMovie.TasStateManager[lastState]); // STATE ACCESS
StartSeeking(frame);
2014-10-17 17:58:48 +00:00
}
}
RefreshDialog();
UpdateOtherTools();
}
public void GoToPreviousFrame()
{
if (Emulator.Frame > 0)
2014-10-17 17:58:48 +00:00
{
GoToFrame(Emulator.Frame - 1);
2014-10-17 17:58:48 +00:00
}
}
public void GoToNextFrame()
{
GoToFrame(Emulator.Frame + 1);
2014-10-17 17:58:48 +00:00
}
public void GoToPreviousMarker()
{
if (Emulator.Frame > 0)
2014-10-17 17:58:48 +00:00
{
var prevMarker = CurrentTasMovie.Markers.Previous(Emulator.Frame);
2014-10-17 17:58:48 +00:00
var prev = prevMarker != null ? prevMarker.Frame : 0;
GoToFrame(prev);
}
}
public void GoToNextMarker()
{
var nextMarker = CurrentTasMovie.Markers.Next(Emulator.Frame);
var next = nextMarker != null ? nextMarker.Frame : CurrentTasMovie.InputLogLength - 1;
2014-10-17 17:58:48 +00:00
GoToFrame(next);
}
public void GoToMarker(TasMovieMarker marker)
{
GoToFrame(marker.Frame);
}
/// <summary>
/// Makes the given frame visible. If no frame is given, makes the current frame visible.
/// </summary>
public void SetVisibleIndex(int? indexThatMustBeVisible = null)
{
if (!indexThatMustBeVisible.HasValue)
indexThatMustBeVisible = Emulator.Frame;
TasView.ScrollToIndex(indexThatMustBeVisible.Value);
}
private void MaybeFollowCursor()
{
if (TasPlaybackBox.FollowCursor && !mouseButtonHeld)
SetVisibleIndex();
}
}
2014-10-17 17:58:48 +00:00
}