From 97f32bde911115c8cd99a24c0576dbf47b903ef3 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 17 Mar 2012 21:59:56 +0000 Subject: [PATCH] Lua Console - implement recent session --- BizHawk.MultiClient/Config.cs | 3 +- .../tools/LuaConsole.Designer.cs | 1 + BizHawk.MultiClient/tools/LuaConsole.cs | 89 ++++++++++++++++++- 3 files changed, 91 insertions(+), 2 deletions(-) diff --git a/BizHawk.MultiClient/Config.cs b/BizHawk.MultiClient/Config.cs index 24e90a397d..c240b7e39f 100644 --- a/BizHawk.MultiClient/Config.cs +++ b/BizHawk.MultiClient/Config.cs @@ -143,7 +143,7 @@ namespace BizHawk.MultiClient public int SaveSlot = 0; //currently selected savestate slot public bool AutoLoadLastSaveSlot = false; public bool WIN32_CONSOLE = true; - public bool SkipLagFrame = false; + public bool SkipLagFrame = false; // Run-Control settings public int FrameProgressDelayMs = 500; //how long until a frame advance hold turns into a frame progress? @@ -205,6 +205,7 @@ namespace BizHawk.MultiClient // Lua Console public RecentFiles RecentLua = new RecentFiles(8); + public RecentFiles RecentLuaSession = new RecentFiles(8); public bool AutoLoadLua = false; public bool AutoLoadLuaConsole = false; public bool LuaConsoleSaveWindowPosition = true; diff --git a/BizHawk.MultiClient/tools/LuaConsole.Designer.cs b/BizHawk.MultiClient/tools/LuaConsole.Designer.cs index 7ef91617ab..abc0e0e04f 100644 --- a/BizHawk.MultiClient/tools/LuaConsole.Designer.cs +++ b/BizHawk.MultiClient/tools/LuaConsole.Designer.cs @@ -235,6 +235,7 @@ this.recentSessionsToolStripMenuItem.Name = "recentSessionsToolStripMenuItem"; this.recentSessionsToolStripMenuItem.Size = new System.Drawing.Size(237, 22); this.recentSessionsToolStripMenuItem.Text = "Recent Sessions"; + this.recentSessionsToolStripMenuItem.DropDownOpened += new System.EventHandler(this.recentSessionsToolStripMenuItem_DropDownOpened); // // noneToolStripMenuItem1 // diff --git a/BizHawk.MultiClient/tools/LuaConsole.cs b/BizHawk.MultiClient/tools/LuaConsole.cs index 15282ce531..bde53d2815 100644 --- a/BizHawk.MultiClient/tools/LuaConsole.cs +++ b/BizHawk.MultiClient/tools/LuaConsole.cs @@ -14,7 +14,6 @@ namespace BizHawk.MultiClient public partial class LuaConsole : Form { //track changes - //recent session //options - autoload session //options - disable scripts on load //TODO: remember column widths @@ -488,6 +487,13 @@ namespace BizHawk.MultiClient DisplayLuaList(); UpdateNumberOfScripts(); } + else if (Path.GetExtension(filePaths[0]) == (".luases")) + { + LoadLuaSession(filePaths[0]); + DisplayLuaList(); + UpdateNumberOfScripts(); + ClearOutput(); + } } private void LuaConsole_DragEnter(object sender, DragEventArgs e) @@ -643,6 +649,7 @@ namespace BizHawk.MultiClient luaList.Add(l); } } + Global.Config.RecentLuaSession.Add(path); return true; } @@ -786,5 +793,85 @@ namespace BizHawk.MultiClient saveToolStripMenuItem.Enabled = true; } } + + private void recentSessionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e) + { + //Clear out recent Cheats list + //repopulate it with an up to date list + recentSessionsToolStripMenuItem.DropDownItems.Clear(); + + if (Global.Config.RecentLuaSession.IsEmpty()) + { + var none = new ToolStripMenuItem(); + none.Enabled = false; + none.Text = "None"; + recentSessionsToolStripMenuItem.DropDownItems.Add(none); + } + else + { + for (int x = 0; x < Global.Config.RecentLuaSession.Length(); x++) + { + string path = Global.Config.RecentLuaSession.GetRecentFileByPosition(x); + var item = new ToolStripMenuItem(); + item.Text = path; + item.Click += (o, ev) => LoadSessionFromRecent(path); + recentSessionsToolStripMenuItem.DropDownItems.Add(item); + } + } + + recentSessionsToolStripMenuItem.DropDownItems.Add("-"); + + var clearitem = new ToolStripMenuItem(); + clearitem.Text = "&Clear"; + clearitem.Click += (o, ev) => Global.Config.RecentLuaSession.Clear(); + recentSessionsToolStripMenuItem.DropDownItems.Add(clearitem); + } + + public void LoadSessionFromRecent(string file) + { + bool z = true; + if (changes) z = AskSave(); + + if (z) + { + bool r = LoadLuaSession(file); + if (!r) + { + DialogResult result = MessageBox.Show("Could not open " + file + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error); + if (result == DialogResult.Yes) + Global.Config.RecentLuaSession.Remove(file); + } + RunLuaScripts(); + DisplayLuaList(); + UpdateNumberOfScripts(); + ClearOutput(); + changes = false; + } + } + + public bool AskSave() + { + if (changes) + { + Global.Sound.StopSound(); + DialogResult result = MessageBox.Show("Save changes to session?", "Lua Console", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3); + Global.Sound.StartSound(); + if (result == DialogResult.Yes) + { + if (string.Compare(currentSessionFile, "") == 0) + { + SaveAs(); + } + else + SaveSession(currentSessionFile); + return true; + } + else if (result == DialogResult.No) + return true; + else if (result == DialogResult.Cancel) + return false; + } + return true; + } } }