Pass EmuClientApi instance to MainForm when restarting in ToolManager
This commit is contained in:
parent
87a4f1186e
commit
781976f18e
|
@ -821,12 +821,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
GlobalWin.Emulator = value;
|
GlobalWin.Emulator = value;
|
||||||
if (GlobalWin.ClientApi != null) GlobalWin.ClientApi.Emulator = value; // first call to this setter is in the ctor, before the APIs have been registered by the ToolManager ctor
|
if (EmuClient != null) EmuClient.Emulator = value; // first call to this setter is in the ctor, before the APIs have been registered by the ToolManager ctor
|
||||||
_currentVideoProvider = GlobalWin.Emulator.AsVideoProviderOrDefault();
|
_currentVideoProvider = GlobalWin.Emulator.AsVideoProviderOrDefault();
|
||||||
_currentSoundProvider = GlobalWin.Emulator.AsSoundProviderOrDefault();
|
_currentSoundProvider = GlobalWin.Emulator.AsSoundProviderOrDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EmuClientApi EmuClient { get; set; }
|
||||||
|
|
||||||
private InputManager InputManager => GlobalWin.InputManager;
|
private InputManager InputManager => GlobalWin.InputManager;
|
||||||
private OSDManager OSD => GlobalWin.OSD;
|
private OSDManager OSD => GlobalWin.OSD;
|
||||||
|
|
||||||
|
@ -3602,7 +3604,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var oldGame = GlobalWin.Game;
|
var oldGame = GlobalWin.Game;
|
||||||
var result = loader.LoadRom(path, nextComm, ioaRetro?.CorePath);
|
var result = loader.LoadRom(path, nextComm, ioaRetro?.CorePath);
|
||||||
|
|
||||||
GlobalWin.ClientApi.Game = GlobalWin.Game = result ? loader.Game : oldGame;
|
EmuClient.Game = GlobalWin.Game = result ? loader.Game : oldGame;
|
||||||
|
|
||||||
// we need to replace the path in the OpenAdvanced with the canonical one the user chose.
|
// we need to replace the path in the OpenAdvanced with the canonical one the user chose.
|
||||||
// It can't be done until loader.LoadRom happens (for CanonicalFullPath)
|
// It can't be done until loader.LoadRom happens (for CanonicalFullPath)
|
||||||
|
@ -3762,20 +3764,20 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientApi.OnRomLoaded(Emulator);
|
EmuClient.OnRomLoaded(Emulator);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (Emulator.IsNull())
|
else if (Emulator.IsNull())
|
||||||
{
|
{
|
||||||
// This shows up if there's a problem
|
// This shows up if there's a problem
|
||||||
ClientApi.UpdateEmulatorAndVP(Emulator);
|
EmuClient.UpdateEmulatorAndVP(Emulator);
|
||||||
OnRomChanged();
|
OnRomChanged();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The ROM has been loaded by a recursive invocation of the LoadROM method.
|
// The ROM has been loaded by a recursive invocation of the LoadROM method.
|
||||||
ClientApi.OnRomLoaded(Emulator);
|
EmuClient.OnRomLoaded(Emulator);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3863,7 +3865,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
CheatList.SaveOnClose();
|
CheatList.SaveOnClose();
|
||||||
Emulator.Dispose();
|
Emulator.Dispose();
|
||||||
Emulator = new NullEmulator();
|
Emulator = new NullEmulator();
|
||||||
ClientApi.UpdateEmulatorAndVP(Emulator);
|
EmuClient.UpdateEmulatorAndVP(Emulator);
|
||||||
InputManager.ActiveController = new Controller(NullController.Instance.Definition);
|
InputManager.ActiveController = new Controller(NullController.Instance.Definition);
|
||||||
InputManager.AutoFireController = _autofireNullControls;
|
InputManager.AutoFireController = _autofireNullControls;
|
||||||
RewireSound();
|
RewireSound();
|
||||||
|
@ -3881,7 +3883,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
CloseGame(clearSram);
|
CloseGame(clearSram);
|
||||||
Emulator = new NullEmulator();
|
Emulator = new NullEmulator();
|
||||||
GlobalWin.ClientApi.Game = GlobalWin.Game = GameInfo.NullInstance;
|
EmuClient.Game = GlobalWin.Game = GameInfo.NullInstance;
|
||||||
CreateRewinder();
|
CreateRewinder();
|
||||||
Tools.Restart(Emulator, Game);
|
Tools.Restart(Emulator, Game);
|
||||||
RewireSound();
|
RewireSound();
|
||||||
|
@ -3992,7 +3994,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
if (new SavestateFile(Emulator, MovieSession, GlobalWin.UserBag).Load(path))
|
if (new SavestateFile(Emulator, MovieSession, GlobalWin.UserBag).Load(path))
|
||||||
{
|
{
|
||||||
OSD.ClearGuiText();
|
OSD.ClearGuiText();
|
||||||
ClientApi.OnStateLoaded(this, userFriendlyStateName);
|
EmuClient.OnStateLoaded(this, userFriendlyStateName);
|
||||||
|
|
||||||
if (Tools.Has<LuaConsole>())
|
if (Tools.Has<LuaConsole>())
|
||||||
{
|
{
|
||||||
|
@ -4030,7 +4032,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientApi.OnBeforeQuickLoad(this, quickSlotName, out var handled);
|
EmuClient.OnBeforeQuickLoad(this, quickSlotName, out var handled);
|
||||||
if (handled)
|
if (handled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -4070,7 +4072,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
new SavestateFile(Emulator, MovieSession, GlobalWin.UserBag).Create(path, Config.Savestates);
|
new SavestateFile(Emulator, MovieSession, GlobalWin.UserBag).Create(path, Config.Savestates);
|
||||||
|
|
||||||
ClientApi.OnStateSaved(this, userFriendlyStateName);
|
EmuClient.OnStateSaved(this, userFriendlyStateName);
|
||||||
|
|
||||||
if (!suppressOSD)
|
if (!suppressOSD)
|
||||||
{
|
{
|
||||||
|
@ -4096,7 +4098,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientApi.OnBeforeQuickSave(this, quickSlotName, out var handled);
|
EmuClient.OnBeforeQuickSave(this, quickSlotName, out var handled);
|
||||||
if (handled)
|
if (handled)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -31,6 +31,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
// Also a UsesRam, and similar method
|
// Also a UsesRam, and similar method
|
||||||
private readonly List<IToolForm> _tools = new List<IToolForm>();
|
private readonly List<IToolForm> _tools = new List<IToolForm>();
|
||||||
|
|
||||||
|
private IExternalApiProvider ApiProvider
|
||||||
|
{
|
||||||
|
get => _apiProvider;
|
||||||
|
set => _owner.EmuClient = (EmuClientApi) (_apiProvider = value).GetApi<IEmuClientApi>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ToolManager"/> class.
|
/// Initializes a new instance of the <see cref="ToolManager"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -48,7 +54,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_emulator = emulator;
|
_emulator = emulator;
|
||||||
_movieSession = movieSession;
|
_movieSession = movieSession;
|
||||||
_game = game;
|
_game = game;
|
||||||
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, GlobalWin.DisplayManager, _inputManager, _config, _emulator, _game);
|
ApiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, GlobalWin.DisplayManager, _inputManager, _config, _emulator, _game);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -165,7 +171,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var newTool = (IExternalToolForm) CreateInstance(typeof(IExternalToolForm), toolPath, customFormTypeName, skipExtToolWarning: skipExtToolWarning);
|
var newTool = (IExternalToolForm) CreateInstance(typeof(IExternalToolForm), toolPath, customFormTypeName, skipExtToolWarning: skipExtToolWarning);
|
||||||
if (newTool == null) return null;
|
if (newTool == null) return null;
|
||||||
if (newTool is Form form) form.Owner = _owner;
|
if (newTool is Form form) form.Owner = _owner;
|
||||||
ApiInjector.UpdateApis(_apiProvider, newTool);
|
ApiInjector.UpdateApis(ApiProvider, newTool);
|
||||||
ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
|
ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
|
||||||
SetBaseProperties(newTool);
|
SetBaseProperties(newTool);
|
||||||
// auto settings
|
// auto settings
|
||||||
|
@ -499,7 +505,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
_emulator = emulator;
|
_emulator = emulator;
|
||||||
_game = game;
|
_game = game;
|
||||||
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, GlobalWin.DisplayManager, _inputManager, _config, _emulator, _game);
|
ApiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, GlobalWin.DisplayManager, _inputManager, _config, _emulator, _game);
|
||||||
// If Cheat tool is loaded, restarting will restart the list too anyway
|
// If Cheat tool is loaded, restarting will restart the list too anyway
|
||||||
if (!Has<Cheats>())
|
if (!Has<Cheats>())
|
||||||
{
|
{
|
||||||
|
@ -518,7 +524,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch) // Hack for RAM Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic
|
if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch) // Hack for RAM Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic
|
||||||
{
|
{
|
||||||
if (tool is IExternalToolForm)
|
if (tool is IExternalToolForm)
|
||||||
ApiInjector.UpdateApis(_apiProvider, tool);
|
ApiInjector.UpdateApis(ApiProvider, tool);
|
||||||
tool.Restart();
|
tool.Restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue