TAStudio - implement recent menu and Open file, but it is currently pointless since the input log parsing isn't implemented

This commit is contained in:
adelikat 2013-12-10 02:13:50 +00:00
parent fd149237ee
commit 4d770ab0f3
4 changed files with 70 additions and 3 deletions

View File

@ -482,6 +482,7 @@ namespace BizHawk.Client.Common
public int TASWidth = -1; public int TASWidth = -1;
public int TASHeight = -1; public int TASHeight = -1;
public bool TAStudioDrawInput = true; public bool TAStudioDrawInput = true;
public RecentFiles RecentTas = new RecentFiles(8);
// VirtualPad Dialog // VirtualPad Dialog
public bool VirtualPadsUpdatePads = true; public bool VirtualPadsUpdatePads = true;

View File

@ -154,11 +154,11 @@ namespace BizHawk.Client.EmuHawk
// //
// OpenTASMenuItem // OpenTASMenuItem
// //
this.OpenTASMenuItem.Enabled = false;
this.OpenTASMenuItem.Name = "OpenTASMenuItem"; this.OpenTASMenuItem.Name = "OpenTASMenuItem";
this.OpenTASMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); 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.Size = new System.Drawing.Size(186, 22);
this.OpenTASMenuItem.Text = "&Open"; this.OpenTASMenuItem.Text = "&Open";
this.OpenTASMenuItem.Click += new System.EventHandler(this.OpenTASMenuItem_Click);
// //
// SaveTASMenuItem // SaveTASMenuItem
// //
@ -181,16 +181,16 @@ namespace BizHawk.Client.EmuHawk
// //
this.RecentSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.RecentSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripSeparator3}); this.toolStripSeparator3});
this.RecentSubMenu.Enabled = false;
this.RecentSubMenu.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Recent; this.RecentSubMenu.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Recent;
this.RecentSubMenu.Name = "RecentSubMenu"; this.RecentSubMenu.Name = "RecentSubMenu";
this.RecentSubMenu.Size = new System.Drawing.Size(186, 22); this.RecentSubMenu.Size = new System.Drawing.Size(186, 22);
this.RecentSubMenu.Text = "Recent"; this.RecentSubMenu.Text = "Recent";
this.RecentSubMenu.DropDownOpened += new System.EventHandler(this.RecentSubMenu_DropDownOpened);
// //
// toolStripSeparator3 // toolStripSeparator3
// //
this.toolStripSeparator3.Name = "toolStripSeparator3"; this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(57, 6); this.toolStripSeparator3.Size = new System.Drawing.Size(149, 6);
// //
// toolStripSeparator1 // toolStripSeparator1
// //

View File

@ -206,6 +206,30 @@ namespace BizHawk.Client.EmuHawk
Global.Config.TASHeight = Bottom - Top; 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 Events
#region File Menu #region File Menu
@ -215,6 +239,26 @@ namespace BizHawk.Client.EmuHawk
SaveTASMenuItem.Enabled = !String.IsNullOrWhiteSpace(_tas.Filename); 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) private void SaveTASMenuItem_Click(object sender, EventArgs e)
{ {
_tas.Save(); _tas.Save();
@ -228,6 +272,7 @@ namespace BizHawk.Client.EmuHawk
{ {
_tas.Filename = file.FullName; _tas.Filename = file.FullName;
_tas.Save(); _tas.Save();
Global.Config.RecentTas.Add(_tas.Filename);
// TODO: inform the user it happened somehow // TODO: inform the user it happened somehow
} }
} }

View File

@ -11,6 +11,27 @@ namespace BizHawk.Client.EmuHawk
{ {
public static class ToolHelpers 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) public static FileInfo GetTasProjSaveFileFromUser(string currentFile)
{ {
var sfd = new SaveFileDialog(); var sfd = new SaveFileDialog();