Debugger: Lua - Add option to auto-restart scripts after power cycling or reloading the rom

This commit is contained in:
Sour 2020-05-03 13:06:54 -04:00
parent a3f2e36fdf
commit 6b4fe28e59
3 changed files with 18 additions and 2 deletions

View file

@ -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)

View file

@ -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;
}
}

View file

@ -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);