From 4d770ab0f3f10964f9922a8f605d96e6ef2a63ee Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 10 Dec 2013 02:13:50 +0000 Subject: [PATCH] TAStudio - implement recent menu and Open file, but it is currently pointless since the input log parsing isn't implemented --- BizHawk.Client.Common/config/Config.cs | 1 + .../tools/TAStudio/TAStudio.Designer.cs | 6 +-- .../tools/TAStudio/TAStudio.cs | 45 +++++++++++++++++++ BizHawk.Client.EmuHawk/tools/ToolHelpers.cs | 21 +++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index 574f88034b..71b3dd82da 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -482,6 +482,7 @@ namespace BizHawk.Client.Common public int TASWidth = -1; public int TASHeight = -1; public bool TAStudioDrawInput = true; + public RecentFiles RecentTas = new RecentFiles(8); // VirtualPad Dialog public bool VirtualPadsUpdatePads = true; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs index fded57ca2b..5685d0a243 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs @@ -154,11 +154,11 @@ namespace BizHawk.Client.EmuHawk // // OpenTASMenuItem // - this.OpenTASMenuItem.Enabled = false; this.OpenTASMenuItem.Name = "OpenTASMenuItem"; this.OpenTASMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); this.OpenTASMenuItem.Size = new System.Drawing.Size(186, 22); this.OpenTASMenuItem.Text = "&Open"; + this.OpenTASMenuItem.Click += new System.EventHandler(this.OpenTASMenuItem_Click); // // SaveTASMenuItem // @@ -181,16 +181,16 @@ namespace BizHawk.Client.EmuHawk // this.RecentSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripSeparator3}); - this.RecentSubMenu.Enabled = false; this.RecentSubMenu.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Recent; this.RecentSubMenu.Name = "RecentSubMenu"; this.RecentSubMenu.Size = new System.Drawing.Size(186, 22); this.RecentSubMenu.Text = "Recent"; + this.RecentSubMenu.DropDownOpened += new System.EventHandler(this.RecentSubMenu_DropDownOpened); // // toolStripSeparator3 // this.toolStripSeparator3.Name = "toolStripSeparator3"; - this.toolStripSeparator3.Size = new System.Drawing.Size(57, 6); + this.toolStripSeparator3.Size = new System.Drawing.Size(149, 6); // // toolStripSeparator1 // diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index b383937bb8..623a9c5edc 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -206,6 +206,30 @@ namespace BizHawk.Client.EmuHawk Global.Config.TASHeight = Bottom - Top; } + public void LoadFileFromRecent(string path) + { + var askResult = true; + if (_tas.Changes) + { + askResult = AskSave(); + } + + if (askResult) + { + _tas.Filename = path; + var loadResult = _tas.Load(); + if (!loadResult) + { + ToolHelpers.HandleLoadError(Global.Config.RecentTas, path); + } + else + { + Global.Config.RecentTas.Add(path); + TASView.ItemCount = _tas.InputLogLength; + } + } + } + #region Events #region File Menu @@ -215,6 +239,26 @@ namespace BizHawk.Client.EmuHawk SaveTASMenuItem.Enabled = !String.IsNullOrWhiteSpace(_tas.Filename); } + private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) + { + RecentSubMenu.DropDownItems.Clear(); + RecentSubMenu.DropDownItems.AddRange( + ToolHelpers.GenerateRecentMenu(Global.Config.RecentTas, LoadFileFromRecent) + ); + } + + private void OpenTASMenuItem_Click(object sender, EventArgs e) + { + var file = ToolHelpers.GetTasProjFileFromUser(_tas.Filename); + if (file != null) + { + _tas.Filename = file.FullName; + _tas.Load(); + Global.Config.RecentTas.Add(_tas.Filename); + // TOOD: message to the user + } + } + private void SaveTASMenuItem_Click(object sender, EventArgs e) { _tas.Save(); @@ -228,6 +272,7 @@ namespace BizHawk.Client.EmuHawk { _tas.Filename = file.FullName; _tas.Save(); + Global.Config.RecentTas.Add(_tas.Filename); // TODO: inform the user it happened somehow } } diff --git a/BizHawk.Client.EmuHawk/tools/ToolHelpers.cs b/BizHawk.Client.EmuHawk/tools/ToolHelpers.cs index d71b927d8f..8211ac2734 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolHelpers.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolHelpers.cs @@ -11,6 +11,27 @@ namespace BizHawk.Client.EmuHawk { public static class ToolHelpers { + public static FileInfo GetTasProjFileFromUser(string currentFile) + { + var ofd = new OpenFileDialog(); + if (!String.IsNullOrWhiteSpace(currentFile)) + { + ofd.FileName = Path.GetFileNameWithoutExtension(currentFile); + } + + ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPath, null); + ofd.Filter = "Tas Project Files (*.tasproj)|*.tasproj|All Files|*.*"; + ofd.RestoreDirectory = true; + + var result = ofd.ShowHawkDialog(); + if (result != DialogResult.OK) + { + return null; + } + + return new FileInfo(ofd.FileName); + } + public static FileInfo GetTasProjSaveFileFromUser(string currentFile) { var sfd = new SaveFileDialog();