ToolManager - inject common things like config, mainform, and the tool manager itself to tools that inherit ToolFormBase
This commit is contained in:
parent
f8ed9f49eb
commit
77c04412d2
|
@ -92,15 +92,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
public bool Rewind()
|
||||
{
|
||||
// copy pasted from TasView_MouseWheel(), just without notch logic
|
||||
if (Mainform.IsSeeking && !Mainform.EmulatorPaused)
|
||||
if (MainForm.IsSeeking && !MainForm.EmulatorPaused)
|
||||
{
|
||||
Mainform.PauseOnFrame--;
|
||||
MainForm.PauseOnFrame--;
|
||||
|
||||
// that's a weird condition here, but for whatever reason it works best
|
||||
if (Emulator.Frame >= Mainform.PauseOnFrame)
|
||||
if (Emulator.Frame >= MainForm.PauseOnFrame)
|
||||
{
|
||||
Mainform.PauseEmulator();
|
||||
Mainform.PauseOnFrame = null;
|
||||
MainForm.PauseEmulator();
|
||||
MainForm.PauseOnFrame = null;
|
||||
StopSeeking();
|
||||
GoToPreviousFrame();
|
||||
}
|
||||
|
|
|
@ -81,19 +81,19 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (!fromMiddleClick)
|
||||
{
|
||||
if (Mainform.PauseOnFrame != null)
|
||||
if (MainForm.PauseOnFrame != null)
|
||||
{
|
||||
StopSeeking(true); // don't restore rec mode just yet, as with heavy editing checkbox updating causes lag
|
||||
}
|
||||
_seekStartFrame = Emulator.Frame;
|
||||
}
|
||||
|
||||
Mainform.PauseOnFrame = frame.Value;
|
||||
int? diff = Mainform.PauseOnFrame - _seekStartFrame;
|
||||
MainForm.PauseOnFrame = frame.Value;
|
||||
int? diff = MainForm.PauseOnFrame - _seekStartFrame;
|
||||
|
||||
WasRecording = CurrentTasMovie.IsRecording() || WasRecording;
|
||||
TastudioPlayMode(); // suspend rec mode until seek ends, to allow mouse editing
|
||||
Mainform.UnpauseEmulator();
|
||||
MainForm.UnpauseEmulator();
|
||||
|
||||
if (!_seekBackgroundWorker.IsBusy && diff > TasView.VisibleRows)
|
||||
{
|
||||
|
@ -110,10 +110,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
WasRecording = false;
|
||||
}
|
||||
|
||||
Mainform.PauseOnFrame = null;
|
||||
MainForm.PauseOnFrame = null;
|
||||
if (_unpauseAfterSeeking)
|
||||
{
|
||||
Mainform.UnpauseEmulator();
|
||||
MainForm.UnpauseEmulator();
|
||||
_unpauseAfterSeeking = false;
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
offsetY = 5;
|
||||
}
|
||||
|
||||
if (index == Emulator.Frame && index == Mainform.PauseOnFrame)
|
||||
if (index == Emulator.Frame && index == MainForm.PauseOnFrame)
|
||||
{
|
||||
bitmap = TasView.HorizontalOrientation ?
|
||||
ts_v_arrow_green_blue :
|
||||
|
@ -262,11 +262,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
TasMovieRecord record = CurrentTasMovie[index];
|
||||
|
||||
if (Mainform.IsSeeking && Mainform.PauseOnFrame == index)
|
||||
if (MainForm.IsSeeking && MainForm.PauseOnFrame == index)
|
||||
{
|
||||
color = CurrentFrame_InputLog;
|
||||
}
|
||||
else if (!Mainform.IsSeeking && Emulator.Frame == index)
|
||||
else if (!MainForm.IsSeeking && Emulator.Frame == index)
|
||||
{
|
||||
color = CurrentFrame_InputLog;
|
||||
}
|
||||
|
@ -514,7 +514,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (e.Button == MouseButtons.Middle)
|
||||
{
|
||||
if (Mainform.EmulatorPaused)
|
||||
if (MainForm.EmulatorPaused)
|
||||
{
|
||||
TasMovieRecord record = CurrentTasMovie[LastPositionFrame];
|
||||
if (!record.Lagged.HasValue && LastPositionFrame > Emulator.Frame)
|
||||
|
@ -523,12 +523,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else
|
||||
{
|
||||
Mainform.UnpauseEmulator();
|
||||
MainForm.UnpauseEmulator();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Mainform.PauseEmulator();
|
||||
MainForm.PauseEmulator();
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -604,7 +604,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else if (TasView.CurrentCell.Column.Type != ColumnType.Text) // User changed input
|
||||
{
|
||||
bool wasPaused = Mainform.EmulatorPaused;
|
||||
bool wasPaused = MainForm.EmulatorPaused;
|
||||
|
||||
if (ControllerType.BoolButtons.Contains(buttonName))
|
||||
{
|
||||
|
@ -713,7 +713,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
// taseditor behavior
|
||||
if (!wasPaused)
|
||||
{
|
||||
Mainform.UnpauseEmulator();
|
||||
MainForm.UnpauseEmulator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -877,15 +877,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
// warning: tastudio rewind hotkey/button logic is copy pasted from here!
|
||||
if (Mainform.IsSeeking && !Mainform.EmulatorPaused)
|
||||
if (MainForm.IsSeeking && !MainForm.EmulatorPaused)
|
||||
{
|
||||
Mainform.PauseOnFrame -= notch;
|
||||
MainForm.PauseOnFrame -= notch;
|
||||
|
||||
// that's a weird condition here, but for whatever reason it works best
|
||||
if (notch > 0 && Emulator.Frame >= Mainform.PauseOnFrame)
|
||||
if (notch > 0 && Emulator.Frame >= MainForm.PauseOnFrame)
|
||||
{
|
||||
Mainform.PauseEmulator();
|
||||
Mainform.PauseOnFrame = null;
|
||||
MainForm.PauseEmulator();
|
||||
MainForm.PauseOnFrame = null;
|
||||
StopSeeking();
|
||||
GoToFrame(Emulator.Frame - notch);
|
||||
}
|
||||
|
@ -976,7 +976,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
if (_startCursorDrag && !Mainform.IsSeeking)
|
||||
if (_startCursorDrag && !MainForm.IsSeeking)
|
||||
{
|
||||
GoToFrame(e.NewCell.RowIndex.Value);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void NewTasMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Mainform.GameIsClosing)
|
||||
if (!MainForm.GameIsClosing)
|
||||
{
|
||||
StartNewTasMovie();
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var result1 = MessageBox.Show("This is a regular movie, a new project must be created from it, in order to use in TAStudio\nProceed?", "Convert movie", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
||||
if (result1 == DialogResult.OK)
|
||||
{
|
||||
Mainform.StartNewMovie(MovieService.Get(ofd.FileName), false);
|
||||
MainForm.StartNewMovie(MovieService.Get(ofd.FileName), false);
|
||||
ConvertCurrentMovieToTasproj();
|
||||
StartNewMovieWrapper(false);
|
||||
SetUpColumns();
|
||||
|
@ -168,7 +168,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
_autosaveTimer.Start();
|
||||
}
|
||||
|
||||
Mainform.SetWindowText();
|
||||
MainForm.SetWindowText();
|
||||
GlobalWin.Sound.StartSound();
|
||||
}
|
||||
|
||||
|
@ -865,7 +865,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
int goToFrame = CurrentTasMovie.LastStatedFrame;
|
||||
do
|
||||
{
|
||||
Mainform.FrameAdvance();
|
||||
MainForm.FrameAdvance();
|
||||
|
||||
if (CurrentTasMovie.TasStateManager.HasState(Emulator.Frame))
|
||||
{
|
||||
|
@ -1488,7 +1488,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
StartFromNowSeparator.Visible = StartNewProjectFromNowMenuItem.Visible || StartANewProjectFromSaveRamMenuItem.Visible;
|
||||
RemoveMarkersContextMenuItem.Enabled = CurrentTasMovie.Markers.Any(m => TasView.SelectedRows.Contains(m.Frame)); // Disable the option to remove markers if no markers are selected (FCEUX does this).
|
||||
CancelSeekContextMenuItem.Enabled = Mainform.PauseOnFrame.HasValue;
|
||||
CancelSeekContextMenuItem.Enabled = MainForm.PauseOnFrame.HasValue;
|
||||
BranchContextMenuItem.Visible = TasView.CurrentCell?.RowIndex == Emulator.Frame;
|
||||
|
||||
SelectBetweenMarkersContextMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Sel. bet. Markers"].Bindings;
|
||||
|
@ -1501,7 +1501,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void CancelSeekContextMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Mainform.PauseOnFrame = null;
|
||||
MainForm.PauseOnFrame = null;
|
||||
RefreshTasView();
|
||||
}
|
||||
|
||||
|
@ -1519,7 +1519,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
TasMovie newProject = CurrentTasMovie.ConvertToSavestateAnchoredMovie(
|
||||
index, (byte[])StatableEmulator.SaveStateBinary().Clone());
|
||||
|
||||
Mainform.PauseEmulator();
|
||||
MainForm.PauseEmulator();
|
||||
LoadFile(new FileInfo(newProject.Filename), true);
|
||||
}
|
||||
}
|
||||
|
@ -1539,7 +1539,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
GoToFrame(index);
|
||||
TasMovie newProject = CurrentTasMovie.ConvertToSaveRamAnchoredMovie(
|
||||
SaveRamEmulator.CloneSaveRam());
|
||||
Mainform.PauseEmulator();
|
||||
MainForm.PauseEmulator();
|
||||
LoadFile(new FileInfo(newProject.Filename), true);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (frame <= Emulator.Frame)
|
||||
{
|
||||
if ((Mainform.EmulatorPaused || !Mainform.IsSeeking)
|
||||
if ((MainForm.EmulatorPaused || !MainForm.IsSeeking)
|
||||
&& !CurrentTasMovie.LastPositionStable)
|
||||
{
|
||||
LastPositionFrame = Emulator.Frame;
|
||||
|
@ -42,11 +42,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
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
|
||||
{
|
||||
bool wasPaused = Mainform.EmulatorPaused;
|
||||
Mainform.FrameAdvance();
|
||||
bool wasPaused = MainForm.EmulatorPaused;
|
||||
MainForm.FrameAdvance();
|
||||
if (!wasPaused)
|
||||
{
|
||||
Mainform.UnpauseEmulator();
|
||||
MainForm.UnpauseEmulator();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -21,7 +21,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
// TODO: UI flow that conveniently allows to start from savestate
|
||||
public TasMovie CurrentTasMovie => Global.MovieSession.Movie as TasMovie;
|
||||
private MainForm Mainform => GlobalWin.MainForm;
|
||||
|
||||
public bool IsInMenuLoop { get; private set; }
|
||||
public string StatesPath => PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global", "TAStudio states"].Path, null);
|
||||
|
@ -212,14 +211,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
this.Invoke(() => SavingProgressBar.Visible = true);
|
||||
for (;;)
|
||||
{
|
||||
if (_seekBackgroundWorker.CancellationPending || !IsHandleCreated || !Mainform.PauseOnFrame.HasValue)
|
||||
if (_seekBackgroundWorker.CancellationPending || !IsHandleCreated || !MainForm.PauseOnFrame.HasValue)
|
||||
{
|
||||
e.Cancel = true;
|
||||
break;
|
||||
}
|
||||
|
||||
int diff = Emulator.Frame - _seekStartFrame.Value;
|
||||
int unit = Mainform.PauseOnFrame.Value - _seekStartFrame.Value;
|
||||
int unit = MainForm.PauseOnFrame.Value - _seekStartFrame.Value;
|
||||
double progress = 0;
|
||||
|
||||
if (diff != 0 && unit != 0)
|
||||
|
@ -323,8 +322,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private bool InitializeOnLoad()
|
||||
{
|
||||
Mainform.PauseOnFrame = null;
|
||||
Mainform.PauseEmulator();
|
||||
MainForm.PauseOnFrame = null;
|
||||
MainForm.PauseEmulator();
|
||||
|
||||
// Start Scenario 0: core needs a nag
|
||||
// But do not nag if auto-loading
|
||||
|
@ -526,11 +525,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
GlobalWin.OSD.AddMessage("TAStudio engaged");
|
||||
SetTasMovieCallbacks();
|
||||
SetTextProperty();
|
||||
Mainform.RelinquishControl(this);
|
||||
MainForm.RelinquishControl(this);
|
||||
_originalEndAction = Global.Config.MovieEndAction;
|
||||
Mainform.ClearRewindData();
|
||||
MainForm.ClearRewindData();
|
||||
Global.Config.MovieEndAction = MovieEndAction.Record;
|
||||
Mainform.SetMainformMovieInfo();
|
||||
MainForm.SetMainformMovieInfo();
|
||||
Global.MovieSession.ReadOnly = true;
|
||||
SetSplicer();
|
||||
}
|
||||
|
@ -681,7 +680,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
SetTasMovieCallbacks(movie as TasMovie);
|
||||
|
||||
bool result = Mainform.StartNewMovie(movie, record);
|
||||
bool result = MainForm.StartNewMovie(movie, record);
|
||||
if (result)
|
||||
{
|
||||
CurrentTasMovie.TasStateManager.Capture(); // Capture frame 0 always.
|
||||
|
@ -744,17 +743,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void TastudioStopMovie()
|
||||
{
|
||||
Global.MovieSession.StopMovie(false);
|
||||
Mainform.SetMainformMovieInfo();
|
||||
MainForm.SetMainformMovieInfo();
|
||||
}
|
||||
|
||||
private void DisengageTastudio()
|
||||
{
|
||||
Mainform.PauseOnFrame = null;
|
||||
Mainform.AddOnScreenMessage("TAStudio disengaged");
|
||||
MainForm.PauseOnFrame = null;
|
||||
MainForm.AddOnScreenMessage("TAStudio disengaged");
|
||||
Global.MovieSession.Movie = MovieService.DefaultInstance;
|
||||
Mainform.TakeBackControl();
|
||||
MainForm.TakeBackControl();
|
||||
Global.Config.MovieEndAction = _originalEndAction;
|
||||
Mainform.SetMainformMovieInfo();
|
||||
MainForm.SetMainformMovieInfo();
|
||||
|
||||
// Do not keep TAStudio's disk save states.
|
||||
// if (Directory.Exists(statesPath)) Directory.Delete(statesPath, true);
|
||||
|
@ -849,7 +848,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (_autoRestorePaused.HasValue && !_autoRestorePaused.Value)
|
||||
{
|
||||
// this happens when we're holding the left button while unpaused - view scrolls down, new input gets drawn, seek pauses
|
||||
Mainform.UnpauseEmulator();
|
||||
MainForm.UnpauseEmulator();
|
||||
}
|
||||
|
||||
_autoRestorePaused = null;
|
||||
|
@ -863,7 +862,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
_unpauseAfterSeeking = (fromRewinding || WasRecording) && !Mainform.EmulatorPaused;
|
||||
_unpauseAfterSeeking = (fromRewinding || WasRecording) && !MainForm.EmulatorPaused;
|
||||
TastudioPlayMode();
|
||||
var closestState = CurrentTasMovie.TasStateManager.GetStateClosestToFrame(frame);
|
||||
if (closestState.Value.Length > 0 && (frame < Emulator.Frame || closestState.Key > Emulator.Frame))
|
||||
|
@ -873,24 +872,24 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (fromLua)
|
||||
{
|
||||
bool wasPaused = Mainform.EmulatorPaused;
|
||||
bool wasPaused = MainForm.EmulatorPaused;
|
||||
|
||||
// why not use this? because I'm not letting the form freely run. it all has to be under this loop.
|
||||
// i could use this and then poll StepRunLoop_Core() repeatedly, but.. that's basically what I'm doing
|
||||
// PauseOnFrame = frame;
|
||||
|
||||
// can't re-enter lua while doing this
|
||||
Mainform.SuppressLua = true;
|
||||
MainForm.SuppressLua = true;
|
||||
while (Emulator.Frame != frame)
|
||||
{
|
||||
Mainform.SeekFrameAdvance();
|
||||
MainForm.SeekFrameAdvance();
|
||||
}
|
||||
|
||||
Mainform.SuppressLua = false;
|
||||
MainForm.SuppressLua = false;
|
||||
|
||||
if (!wasPaused)
|
||||
{
|
||||
Mainform.UnpauseEmulator();
|
||||
MainForm.UnpauseEmulator();
|
||||
}
|
||||
|
||||
// lua botting users will want to re-activate record mode automatically -- it should be like nothing ever happened
|
||||
|
@ -906,7 +905,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (frame > Emulator.Frame)
|
||||
{
|
||||
// make seek frame keep up with emulation on fast scrolls
|
||||
if (Mainform.EmulatorPaused || Mainform.IsSeeking || fromRewinding || WasRecording)
|
||||
if (MainForm.EmulatorPaused || MainForm.IsSeeking || fromRewinding || WasRecording)
|
||||
{
|
||||
StartSeeking(frame);
|
||||
}
|
||||
|
@ -956,7 +955,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void TogglePause()
|
||||
{
|
||||
Mainform.TogglePause();
|
||||
MainForm.TogglePause();
|
||||
}
|
||||
|
||||
private void SetSplicer()
|
||||
|
|
|
@ -13,6 +13,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public class ToolFormBase : Form
|
||||
{
|
||||
public ToolManager Tools { get; set; }
|
||||
public Config Config { get; set; }
|
||||
public MainForm MainForm { get; set; }
|
||||
|
||||
public static FileInfo OpenFileDialog(string currentFile, string path, string fileType, string fileExt)
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
|
@ -92,10 +96,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public static void ViewInHexEditor(MemoryDomain domain, IEnumerable<long> addresses, WatchSize size)
|
||||
public void ViewInHexEditor(MemoryDomain domain, IEnumerable<long> addresses, WatchSize size)
|
||||
{
|
||||
GlobalWin.Tools.Load<HexEditor>();
|
||||
GlobalWin.Tools.HexEditor.SetToAddresses(addresses, domain, size);
|
||||
Tools.Load<HexEditor>();
|
||||
Tools.HexEditor.SetToAddresses(addresses, domain, size);
|
||||
}
|
||||
|
||||
protected void GenericDragEnter(object sender, DragEventArgs e)
|
||||
|
@ -110,7 +114,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
protected bool IsOnScreen(Point topLeft)
|
||||
{
|
||||
return ToolManager.IsOnScreen(topLeft);
|
||||
return Tools.IsOnScreen(topLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public class ToolManager
|
||||
{
|
||||
private readonly Form _owner;
|
||||
private readonly MainForm _owner;
|
||||
private readonly Config _config;
|
||||
private IExternalApiProvider _apiProvider;
|
||||
private IEmulator _emulator;
|
||||
|
@ -32,7 +32,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ToolManager"/> class.
|
||||
/// </summary>
|
||||
public ToolManager(Form owner, Config config, IEmulator emulator)
|
||||
public ToolManager(MainForm owner, Config config, IEmulator emulator)
|
||||
{
|
||||
_owner = owner;
|
||||
_config = config;
|
||||
|
@ -60,6 +60,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
return (IToolForm)method.Invoke(this, new object[] { focus });
|
||||
}
|
||||
|
||||
// If the form inherits ToolFormBase, it will set base properties such as Tools, Config, etc
|
||||
private void SetBaseProperties(IToolForm form)
|
||||
{
|
||||
if (form is ToolFormBase tool)
|
||||
{
|
||||
tool.Tools = this;
|
||||
tool.Config = _config;
|
||||
tool.MainForm = _owner;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the tool dialog T (T must implement <see cref="IToolForm"/>) , if it does not exist it will be created, if it is already open, it will be focused
|
||||
/// </summary>
|
||||
|
@ -135,6 +146,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
|
||||
SetBaseProperties(newTool);
|
||||
string toolType = typeof(T).ToString();
|
||||
|
||||
// auto settings
|
||||
|
@ -398,7 +410,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return false;
|
||||
}
|
||||
|
||||
public static bool IsOnScreen(Point topLeft)
|
||||
public bool IsOnScreen(Point topLeft)
|
||||
{
|
||||
return Screen.AllScreens.Any(
|
||||
screen => screen.WorkingArea.Contains(topLeft));
|
||||
|
|
Loading…
Reference in New Issue