Skip to content

Commit f902c10

Browse files
committed
Refactor MainForm interfaces for LuaConsole
1 parent 2af42d9 commit f902c10

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed

src/BizHawk.Client.Common/IMainFormForApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface IMainFormForApi
2222
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>
2323
bool IsSeeking { get; }
2424

25-
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>
25+
/// <remarks>referenced from <see cref="EmuClientApi"/> and <c>LuaConsole</c></remarks>
2626
bool IsTurboing { get; }
2727

2828
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>
@@ -59,7 +59,7 @@ public interface IMainFormForApi
5959
void FrameAdvance(bool discardApiHawkSurfaces = true);
6060

6161
/// <param name="forceWindowResize">Override <see cref="Common.Config.ResizeWithFramebuffer"/></param>
62-
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>
62+
/// <remarks>referenced from <see cref="EmuClientApi"/> and <c>LuaConsole</c></remarks>
6363
void FrameBufferResized(bool forceWindowResize = false);
6464

6565
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>

src/BizHawk.Client.EmuHawk/Api/ApiManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static ApiManager()
3434
private static ApiContainer Register(
3535
IEmulatorServiceProvider serviceProvider,
3636
Action<string> logCallback,
37-
IMainFormForApi mainForm,
37+
IMainFormForApiInit mainForm,
3838
DisplayManagerBase displayManager,
3939
InputManager inputManager,
4040
IMovieSession movieSession,
@@ -47,7 +47,7 @@ private static ApiContainer Register(
4747
{
4848
[typeof(Action<string>)] = logCallback,
4949
[typeof(IMainFormForApi)] = mainForm,
50-
[typeof(IDialogController)] = ((MainForm) mainForm).DialogController,
50+
[typeof(IDialogController)] = mainForm.DialogController,
5151
[typeof(DisplayManagerBase)] = displayManager,
5252
[typeof(InputManager)] = inputManager,
5353
[typeof(IMovieSession)] = movieSession,
@@ -69,7 +69,7 @@ private static ApiContainer Register(
6969

7070
public static IExternalApiProvider Restart(
7171
IEmulatorServiceProvider serviceProvider,
72-
IMainFormForApi mainForm,
72+
IMainFormForApiInit mainForm,
7373
DisplayManagerBase displayManager,
7474
InputManager inputManager,
7575
IMovieSession movieSession,
@@ -86,7 +86,7 @@ public static IExternalApiProvider Restart(
8686
public static ApiContainer RestartLua(
8787
IEmulatorServiceProvider serviceProvider,
8888
Action<string> logCallback,
89-
IMainFormForApi mainForm,
89+
IMainFormForApiInit mainForm,
9090
DisplayManagerBase displayManager,
9191
InputManager inputManager,
9292
IMovieSession movieSession,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using BizHawk.Client.Common;
2+
3+
namespace BizHawk.Client.EmuHawk
4+
{
5+
public interface IMainFormForApiInit : IMainFormForApi, IDialogParent
6+
{
7+
IMovieSession MovieSession { get; }
8+
9+
ToolManager Tools { get; }
10+
}
11+
}

src/BizHawk.Client.EmuHawk/IMainFormForTools.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public interface IMainFormForTools : IDialogController
2727
/// <remarks>only referenced from <see cref="BasicBot"/></remarks>
2828
bool InvisibleEmulation { get; set; }
2929

30-
/// <remarks>only referenced from <see cref="LuaConsole"/></remarks>
31-
bool IsTurboing { get; }
32-
3330
/// <remarks>only referenced from <see cref="TAStudio"/></remarks>
3431
bool IsFastForwarding { get; }
3532

@@ -54,10 +51,6 @@ public interface IMainFormForTools : IDialogController
5451
/// <remarks>only referenced from <see cref="TAStudio"/></remarks>
5552
void FrameAdvance(bool discardApiHawkSurfaces = true);
5653

57-
/// <remarks>only referenced from <see cref="LuaConsole"/></remarks>
58-
/// <param name="forceWindowResize">Override <see cref="Common.Config.ResizeWithFramebuffer"/></param>
59-
void FrameBufferResized(bool forceWindowResize = false);
60-
6154
/// <remarks>only referenced from <see cref="BasicBot"/></remarks>
6255
bool LoadQuickSave(int slot, bool suppressOSD = false);
6356

src/BizHawk.Client.EmuHawk/MainForm.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444

4545
namespace BizHawk.Client.EmuHawk
4646
{
47-
public partial class MainForm : FormBase, IDialogParent, IMainFormForApi, IMainFormForTools, IMainFormForRetroAchievements
47+
public partial class MainForm : FormBase, IDialogParent,
48+
IMainFormForApiInit, IMainFormForRetroAchievements, IMainFormForTools
4849
{
4950
private const string FMT_STR_DUMP_STATUS_MENUITEM_LABEL = "Dump Status Report{0}...";
5051

@@ -1226,7 +1227,7 @@ private set
12261227

12271228
internal readonly ExternalToolManager ExtToolManager;
12281229

1229-
public readonly ToolManager Tools;
1230+
public ToolManager Tools { get; }
12301231

12311232
private IControlMainform ToolControllingSavestates => Tools.FirstOrNull<IControlMainform>(tool => tool.WantsToControlSavestates);
12321233
private IControlMainform ToolControllingRewind => Tools.FirstOrNull<IControlMainform>(tool => tool.WantsToControlRewind);

src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public sealed class FormsLuaLibrary : LuaLibraryBase
2727
public FormsLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, Action<string> logOutputCallback)
2828
: base(luaLibsImpl, apiContainer, logOutputCallback) {}
2929

30-
public Form MainForm { get; set; }
30+
public IDialogParent MainForm { get; set; }
3131

3232
public override string Name => "forms";
3333

@@ -295,7 +295,7 @@ public long NewForm(
295295
form.MaximizeBox = false;
296296
form.FormBorderStyle = FormBorderStyle.FixedDialog;
297297
form.Icon = SystemIcons.Application;
298-
form.Owner = MainForm;
298+
form.Owner = (Form) MainForm;
299299
form.Show();
300300

301301
form.FormClosed += (o, e) =>
@@ -325,7 +325,7 @@ public string OpenFile(
325325
string filter = null)
326326
{
327327
if (initialDirectory is null && fileName is not null) initialDirectory = Path.GetDirectoryName(fileName);
328-
var result = ((IDialogParent) MainForm).ShowFileOpenDialog(
328+
var result = MainForm.ShowFileOpenDialog(
329329
filterStr: filter ?? FilesystemFilter.AllFilesEntry,
330330
initDir: initialDirectory ?? PathEntries.LuaAbsolutePath(),
331331
initFileName: fileName);

src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public static Icon ToolIcon
5050

5151
public ToolDialogSettings.ColumnList Columns { get; set; }
5252

53+
[RequiredService]
54+
private new IMainFormForApiInit MainForm { get; set; }
55+
5356
public class LuaConsoleSettings
5457
{
5558
public LuaConsoleSettings()
@@ -214,7 +217,7 @@ public override void Restart()
214217
newScripts,
215218
registeredFuncList,
216219
Emulator.ServiceProvider,
217-
(MainForm) MainForm, //HACK
220+
MainForm,
218221
DisplayManager,
219222
InputManager,
220223
Config,

src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public LuaLibraries(
2323
LuaFileList scriptList,
2424
LuaFunctionList registeredFuncList,
2525
IEmulatorServiceProvider serviceProvider,
26-
MainForm mainForm,
26+
IMainFormForApiInit mainForm,
2727
DisplayManagerBase displayManager,
2828
InputManager inputManager,
2929
Config config,
@@ -165,7 +165,7 @@ void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
165165

166166
private readonly InputManager _inputManager;
167167

168-
private readonly MainForm _mainForm;
168+
private readonly IMainFormForApiInit _mainForm;
169169

170170
private Lua _lua = new();
171171
private LuaThread _currThread;

0 commit comments

Comments
 (0)