From 6b4fe28e5963b4d5febcc594a78fb84765a77d14 Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 3 May 2020 13:06:54 -0400 Subject: [PATCH] Debugger: Lua - Add option to auto-restart scripts after power cycling or reloading the rom --- UI/Debugger/Config/ScriptWindowConfig.cs | 1 + UI/Debugger/Scripts/frmScript.Designer.cs | 13 +++++++++++-- UI/Debugger/Scripts/frmScript.cs | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/UI/Debugger/Config/ScriptWindowConfig.cs b/UI/Debugger/Config/ScriptWindowConfig.cs index a643dfa..7caad33 100644 --- a/UI/Debugger/Config/ScriptWindowConfig.cs +++ b/UI/Debugger/Config/ScriptWindowConfig.cs @@ -26,6 +26,7 @@ namespace Mesen.GUI.Config public ScriptStartupBehavior ScriptStartupBehavior = ScriptStartupBehavior.ShowTutorial; public bool SaveScriptBeforeRun = true; public bool AutoLoadLastScript = true; + public bool AutoRestartScript = true; public UInt32 ScriptTimeout = 1000; public void AddRecentScript(string scriptFile) diff --git a/UI/Debugger/Scripts/frmScript.Designer.cs b/UI/Debugger/Scripts/frmScript.Designer.cs index d196c11..8f0a28b 100644 --- a/UI/Debugger/Scripts/frmScript.Designer.cs +++ b/UI/Debugger/Scripts/frmScript.Designer.cs @@ -59,6 +59,7 @@ this.mnuSetScriptTimeout = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator(); this.mnuSaveBeforeRun = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuAutoRestart = new System.Windows.Forms.ToolStripMenuItem(); this.mnuAutoReload = new System.Windows.Forms.ToolStripMenuItem(); this.onStartupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mnuBlankWindow = new System.Windows.Forms.ToolStripMenuItem(); @@ -263,6 +264,7 @@ this.mnuSetScriptTimeout, this.toolStripMenuItem3, this.mnuSaveBeforeRun, + this.mnuAutoRestart, this.mnuAutoReload, this.onStartupToolStripMenuItem}); this.scriptToolStripMenuItem.Name = "scriptToolStripMenuItem"; @@ -313,6 +315,13 @@ this.mnuSaveBeforeRun.Size = new System.Drawing.Size(258, 22); this.mnuSaveBeforeRun.Text = "Auto-save before running"; // + // mnuAutoRestart + // + this.mnuAutoRestart.CheckOnClick = true; + this.mnuAutoRestart.Name = "mnuAutoRestart"; + this.mnuAutoRestart.Size = new System.Drawing.Size(258, 22); + this.mnuAutoRestart.Text = "Auto-restart after reload"; + // // mnuAutoReload // this.mnuAutoReload.CheckOnClick = true; @@ -404,7 +413,6 @@ this.txtScriptContent.Cursor = System.Windows.Forms.Cursors.IBeam; this.txtScriptContent.DisabledColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180))))); this.txtScriptContent.Dock = System.Windows.Forms.DockStyle.Fill; - this.txtScriptContent.Font = new System.Drawing.Font("Courier New", 9.75F); this.txtScriptContent.IsReplaceMode = false; this.txtScriptContent.Language = FastColoredTextBoxNS.Language.Lua; this.txtScriptContent.LeftBracket = '('; @@ -619,5 +627,6 @@ private System.Windows.Forms.ToolStripMenuItem mnuApiReference; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem7; private System.Windows.Forms.ToolStripMenuItem mnuSetScriptTimeout; - } + private System.Windows.Forms.ToolStripMenuItem mnuAutoRestart; + } } \ No newline at end of file diff --git a/UI/Debugger/Scripts/frmScript.cs b/UI/Debugger/Scripts/frmScript.cs index 86b8861..b198291 100644 --- a/UI/Debugger/Scripts/frmScript.cs +++ b/UI/Debugger/Scripts/frmScript.cs @@ -101,6 +101,7 @@ namespace Mesen.GUI.Debugger RestoreLocation(cfg.WindowLocation, cfg.WindowSize); mnuSaveBeforeRun.Checked = cfg.SaveScriptBeforeRun; + mnuAutoRestart.Checked = cfg.AutoRestartScript; if(cfg.CodeWindowHeight >= ctrlSplit.Panel1MinSize) { if(cfg.CodeWindowHeight == Int32.MaxValue) { @@ -147,9 +148,13 @@ namespace Mesen.GUI.Debugger switch(e.NotificationType) { case ConsoleNotificationType.BeforeGameUnload: case ConsoleNotificationType.GameLoaded: + bool wasRunning = this._scriptId >= 0; this._scriptId = -1; this.BeginInvoke((Action)(() => { lblScriptActive.Visible = false; + if(e.NotificationType == ConsoleNotificationType.GameLoaded && wasRunning && mnuAutoRestart.Checked) { + RunScript(); + } })); break; } @@ -183,6 +188,7 @@ namespace Mesen.GUI.Debugger cfg.FontStyle = txtScriptContent.OriginalFont.Style; cfg.FontSize = txtScriptContent.OriginalFont.Size; cfg.AutoLoadLastScript = mnuAutoLoadLastScript.Checked; + cfg.AutoRestartScript = mnuAutoRestart.Checked; ConfigManager.ApplyChanges(); base.OnClosing(e);