Move events from `EmuClientApi` to `MainForm`
the `event` members remain, but the triggering is now delegated back to `MainForm`, and the additional processing has been moved there too
This commit is contained in:
parent
1909950742
commit
40b17b59c4
|
@ -40,6 +40,12 @@ namespace BizHawk.Client.Common
|
|||
_logCallback = logCallback;
|
||||
_mainForm = mainForm;
|
||||
VideoProvider = Emulator.AsVideoProviderOrDefault();
|
||||
|
||||
_mainForm.QuicksaveLoad += CallBeforeQuickLoad;
|
||||
_mainForm.QuicksaveSave += CallBeforeQuickSave;
|
||||
_mainForm.RomLoaded += CallRomLoaded;
|
||||
_mainForm.SavestateLoaded += CallStateLoaded;
|
||||
_mainForm.SavestateSaved += CallStateSaved;
|
||||
}
|
||||
|
||||
public int BorderHeight() => _displayManager.TransformPoint(new Point(0, 0)).Y;
|
||||
|
@ -50,6 +56,21 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public int BufferWidth() => VideoProvider.BufferWidth;
|
||||
|
||||
private void CallBeforeQuickLoad(object sender, BeforeQuickLoadEventArgs args)
|
||||
=> BeforeQuickLoad?.Invoke(sender, args);
|
||||
|
||||
private void CallBeforeQuickSave(object sender, BeforeQuickSaveEventArgs args)
|
||||
=> BeforeQuickSave?.Invoke(sender, args);
|
||||
|
||||
private void CallRomLoaded(object sender, EventArgs args)
|
||||
=> RomLoaded?.Invoke(sender, args);
|
||||
|
||||
private void CallStateLoaded(object sender, StateLoadedEventArgs args)
|
||||
=> StateLoaded?.Invoke(sender, args);
|
||||
|
||||
private void CallStateSaved(object sender, StateSavedEventArgs args)
|
||||
=> StateSaved?.Invoke(sender, args);
|
||||
|
||||
public void ClearAutohold() => _mainForm.ClearHolds();
|
||||
|
||||
public void CloseEmulator(int? exitCode = null) => _mainForm.CloseEmulator(exitCode);
|
||||
|
@ -58,6 +79,15 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void DisplayMessages(bool value) => _config.DisplayMessages = value;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_mainForm.QuicksaveLoad -= CallBeforeQuickLoad;
|
||||
_mainForm.QuicksaveSave -= CallBeforeQuickSave;
|
||||
_mainForm.RomLoaded -= CallRomLoaded;
|
||||
_mainForm.SavestateLoaded -= CallStateLoaded;
|
||||
_mainForm.SavestateSaved -= CallStateSaved;
|
||||
}
|
||||
|
||||
public void DoFrameAdvance()
|
||||
{
|
||||
_mainForm.FrameAdvance();
|
||||
|
@ -107,39 +137,6 @@ namespace BizHawk.Client.Common
|
|||
userFriendlyStateName: name,
|
||||
suppressOSD: false);
|
||||
|
||||
public void OnBeforeQuickLoad(object sender, string quickSaveSlotName, out bool eventHandled)
|
||||
{
|
||||
if (BeforeQuickLoad == null)
|
||||
{
|
||||
eventHandled = false;
|
||||
return;
|
||||
}
|
||||
var e = new BeforeQuickLoadEventArgs(quickSaveSlotName);
|
||||
BeforeQuickLoad(sender, e);
|
||||
eventHandled = e.Handled;
|
||||
}
|
||||
|
||||
public void OnBeforeQuickSave(object sender, string quickSaveSlotName, out bool eventHandled)
|
||||
{
|
||||
if (BeforeQuickSave == null)
|
||||
{
|
||||
eventHandled = false;
|
||||
return;
|
||||
}
|
||||
var e = new BeforeQuickSaveEventArgs(quickSaveSlotName);
|
||||
BeforeQuickSave(sender, e);
|
||||
eventHandled = e.Handled;
|
||||
}
|
||||
|
||||
public void OnRomLoaded()
|
||||
{
|
||||
RomLoaded?.Invoke(null, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void OnStateLoaded(object sender, string stateName) => StateLoaded?.Invoke(sender, new StateLoadedEventArgs(stateName));
|
||||
|
||||
public void OnStateSaved(object sender, string stateName) => StateSaved?.Invoke(sender, new StateSavedEventArgs(stateName));
|
||||
|
||||
public bool OpenRom(string path)
|
||||
=> _mainForm.LoadRom(path, new LoadRomArgs { OpenAdvanced = OpenAdvancedSerializer.ParseWithLegacy(path) });
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Drawing;
|
|||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public interface IEmuClientApi : IExternalApi
|
||||
public interface IEmuClientApi : IDisposable, IExternalApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Occurs before a quickload is done (just after user has pressed the shortcut button
|
||||
|
@ -91,41 +91,6 @@ namespace BizHawk.Client.Common
|
|||
/// <returns><see langword="true"/> iff succeeded</returns>
|
||||
bool LoadState(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Raised before a quickload is done (just after pressing shortcut button)
|
||||
/// </summary>
|
||||
/// <param name="sender">Object who raised the event</param>
|
||||
/// <param name="quickSaveSlotName">Slot used for quickload</param>
|
||||
/// <param name="eventHandled">A boolean that can be set if users want to handle save themselves; if so, BizHawk won't do anything</param>
|
||||
void OnBeforeQuickLoad(object sender, string quickSaveSlotName, out bool eventHandled);
|
||||
|
||||
/// <summary>
|
||||
/// Raised before a quicksave is done (just after pressing shortcut button)
|
||||
/// </summary>
|
||||
/// <param name="sender">Object who raised the event</param>
|
||||
/// <param name="quickSaveSlotName">Slot used for quicksave</param>
|
||||
/// <param name="eventHandled">A boolean that can be set if users want to handle save themselves; if so, BizHawk won't do anything</param>
|
||||
void OnBeforeQuickSave(object sender, string quickSaveSlotName, out bool eventHandled);
|
||||
|
||||
/// <summary>
|
||||
/// Raise when a rom is successfully Loaded
|
||||
/// </summary>
|
||||
void OnRomLoaded();
|
||||
|
||||
/// <summary>
|
||||
/// Raise when a state is loaded
|
||||
/// </summary>
|
||||
/// <param name="sender">Object who raised the event</param>
|
||||
/// <param name="stateName">User friendly name for saved state</param>
|
||||
void OnStateLoaded(object sender, string stateName);
|
||||
|
||||
/// <summary>
|
||||
/// Raise when a state is saved
|
||||
/// </summary>
|
||||
/// <param name="sender">Object who raised the event</param>
|
||||
/// <param name="stateName">User friendly name for saved state</param>
|
||||
void OnStateSaved(object sender, string stateName);
|
||||
|
||||
bool OpenRom(string path);
|
||||
|
||||
void Pause();
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
@ -117,5 +118,15 @@ namespace BizHawk.Client.Common
|
|||
void ToggleSound();
|
||||
|
||||
void UnpauseEmulator();
|
||||
|
||||
event BeforeQuickLoadEventHandler QuicksaveLoad;
|
||||
|
||||
event BeforeQuickSaveEventHandler QuicksaveSave;
|
||||
|
||||
event EventHandler RomLoaded;
|
||||
|
||||
event StateLoadedEventHandler SavestateLoaded;
|
||||
|
||||
event StateSavedEventHandler SavestateSaved;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1014,6 +1014,16 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public EmuClientApi EmuClient { get; set; }
|
||||
|
||||
public event BeforeQuickLoadEventHandler QuicksaveLoad;
|
||||
|
||||
public event BeforeQuickSaveEventHandler QuicksaveSave;
|
||||
|
||||
public event EventHandler RomLoaded;
|
||||
|
||||
public event StateLoadedEventHandler SavestateLoaded;
|
||||
|
||||
public event StateSavedEventHandler SavestateSaved;
|
||||
|
||||
private readonly InputManager InputManager;
|
||||
|
||||
private IVideoProvider _currentVideoProvider = NullVideo.Instance;
|
||||
|
@ -4013,7 +4023,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
ExtToolManager.BuildToolStrip();
|
||||
|
||||
EmuClient.OnRomLoaded();
|
||||
RomLoaded?.Invoke(null, EventArgs.Empty);
|
||||
return true;
|
||||
}
|
||||
else if (Emulator.IsNull())
|
||||
|
@ -4027,7 +4037,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
else
|
||||
{
|
||||
// The ROM has been loaded by a recursive invocation of the LoadROM method.
|
||||
EmuClient.OnRomLoaded();
|
||||
RomLoaded?.Invoke(null, EventArgs.Empty);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4254,7 +4264,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
OSD.ClearGuiText();
|
||||
EmuClient.OnStateLoaded(this, userFriendlyStateName);
|
||||
if (SavestateLoaded is not null)
|
||||
{
|
||||
StateLoadedEventArgs args = new(userFriendlyStateName);
|
||||
SavestateLoaded(this, args);
|
||||
}
|
||||
RA?.OnLoadState(path);
|
||||
|
||||
if (Tools.Has<LuaConsole>())
|
||||
|
@ -4287,7 +4301,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (!Emulator.HasSavestates()) return false;
|
||||
|
||||
var quickSlotName = $"QuickSave{slot % 10}";
|
||||
EmuClient.OnBeforeQuickLoad(this, quickSlotName, out var handled);
|
||||
var handled = false;
|
||||
if (QuicksaveLoad is not null)
|
||||
{
|
||||
BeforeQuickLoadEventArgs args = new(quickSlotName);
|
||||
QuicksaveLoad(this, args);
|
||||
handled = args.Handled;
|
||||
}
|
||||
if (handled) return true; // not sure
|
||||
|
||||
if (IsSavestateSlave) return Master.LoadQuickSave(SlotToInt(quickSlotName));
|
||||
|
@ -4319,7 +4339,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
new SavestateFile(Emulator, MovieSession, MovieSession.UserBag).Create(path, Config.Savestates);
|
||||
|
||||
EmuClient.OnStateSaved(this, userFriendlyStateName);
|
||||
if (SavestateSaved is not null)
|
||||
{
|
||||
StateSavedEventArgs args = new(userFriendlyStateName);
|
||||
SavestateSaved(this, args);
|
||||
}
|
||||
RA?.OnSaveState(path);
|
||||
|
||||
if (!suppressOSD)
|
||||
|
@ -4346,7 +4370,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
var quickSlotName = $"QuickSave{slot % 10}";
|
||||
EmuClient.OnBeforeQuickSave(this, quickSlotName, out var handled);
|
||||
var handled = false;
|
||||
if (QuicksaveSave is not null)
|
||||
{
|
||||
BeforeQuickSaveEventArgs args = new(quickSlotName);
|
||||
QuicksaveSave(this, args);
|
||||
handled = args.Handled;
|
||||
}
|
||||
if (handled)
|
||||
{
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue