TAStudio: don't rely on a broken instance of a tool form for macro saving/loading
This commit is contained in:
parent
5641757b98
commit
4d06fb1fde
|
@ -15,7 +15,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
[RequiredService]
|
[RequiredService]
|
||||||
private IEmulator Emulator { get; set; }
|
private IEmulator Emulator { get; set; }
|
||||||
|
|
||||||
private static readonly FilesystemFilterSet MacrosFSFilterSet = new FilesystemFilterSet(new FilesystemFilter("Movie Macros", new[] { "bk2m" }));
|
public static readonly FilesystemFilterSet MacrosFSFilterSet = new FilesystemFilterSet(new FilesystemFilter("Movie Macros", new[] { "bk2m" }));
|
||||||
|
|
||||||
private readonly List<MovieZone> _zones = new List<MovieZone>();
|
private readonly List<MovieZone> _zones = new List<MovieZone>();
|
||||||
private readonly List<int> _unsavedZones = new List<int>();
|
private readonly List<int> _unsavedZones = new List<int>();
|
||||||
|
@ -255,27 +255,28 @@ namespace BizHawk.Client.EmuHawk
|
||||||
ZonesList.Items.Add($"{loadZone.Name} - length: {loadZone.Length}");
|
ZonesList.Items.Add($"{loadZone.Name} - length: {loadZone.Length}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private string SuggestedFolder()
|
public static string SuggestedFolder(Config config, IGameInfo game = null)
|
||||||
{
|
{
|
||||||
return Config.PathEntries.AbsolutePathFor(Path.Combine(
|
return config.PathEntries.AbsolutePathFor(Path.Combine(
|
||||||
Config.PathEntries["Global", "Macros"].Path,
|
config.PathEntries["Global", "Macros"].Path,
|
||||||
Game.FilesystemSafeName()), null);
|
game?.FilesystemSafeName()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SaveMacroAs(MovieZone macro)
|
private bool SaveMacroAs(MovieZone macro)
|
||||||
{
|
{
|
||||||
|
string suggestedFolder = SuggestedFolder(Config, Game);
|
||||||
using var dialog = new SaveFileDialog
|
using var dialog = new SaveFileDialog
|
||||||
{
|
{
|
||||||
InitialDirectory = SuggestedFolder(),
|
InitialDirectory = suggestedFolder,
|
||||||
FileName = macro.Name,
|
FileName = macro.Name,
|
||||||
Filter = MacrosFSFilterSet.ToString()
|
Filter = MacrosFSFilterSet.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create directory?
|
// Create directory?
|
||||||
bool create = false;
|
bool create = false;
|
||||||
if (!Directory.Exists(SuggestedFolder()))
|
if (!Directory.Exists(suggestedFolder))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(SuggestedFolder());
|
Directory.CreateDirectory(suggestedFolder);
|
||||||
create = true;
|
create = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,11 +296,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovieZone LoadMacro(IEmulator emulator = null, ToolManager tools = null)
|
private MovieZone LoadMacro(IEmulator emulator = null, ToolManager tools = null)
|
||||||
{
|
{
|
||||||
using var dialog = new OpenFileDialog
|
using var dialog = new OpenFileDialog
|
||||||
{
|
{
|
||||||
InitialDirectory = SuggestedFolder(),
|
InitialDirectory = SuggestedFolder(Config),
|
||||||
Filter = MacrosFSFilterSet.ToString()
|
Filter = MacrosFSFilterSet.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -228,17 +228,26 @@ namespace BizHawk.Client.EmuHawk
|
||||||
TasView.SelectRow(CurrentTasMovie.InputLogLength, false);
|
TasView.SelectRow(CurrentTasMovie.InputLogLength, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var macro = new MovieZone(
|
var file = SaveFileDialog(
|
||||||
CurrentTasMovie,
|
null,
|
||||||
Emulator,
|
MacroInputTool.SuggestedFolder(Config, Game),
|
||||||
Tools,
|
MacroInputTool.MacrosFSFilterSet,
|
||||||
MovieSession,
|
this
|
||||||
TasView.FirstSelectedIndex ?? 0,
|
);
|
||||||
TasView.LastSelectedIndex ?? 0 - TasView.FirstSelectedIndex ?? 0 + 1);
|
|
||||||
|
|
||||||
//var macroTool = Tools.Load<MacroInputTool>(false);
|
if (file != null)
|
||||||
var macroTool = new MacroInputTool { Config = Config };
|
{
|
||||||
macroTool.SaveMacroAs(macro);
|
new MovieZone(
|
||||||
|
CurrentTasMovie,
|
||||||
|
Emulator,
|
||||||
|
Tools,
|
||||||
|
MovieSession,
|
||||||
|
TasView.FirstSelectedIndex ?? 0,
|
||||||
|
TasView.LastSelectedIndex ?? 0 - TasView.FirstSelectedIndex ?? 0 + 1)
|
||||||
|
.Save(file.FullName);
|
||||||
|
|
||||||
|
Config.RecentMacros.Add(file.FullName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlaceMacroAtSelectionMenuItem_Click(object sender, EventArgs e)
|
private void PlaceMacroAtSelectionMenuItem_Click(object sender, EventArgs e)
|
||||||
|
@ -248,13 +257,22 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//var macroTool = Tools.Load<MacroInputTool>(false);
|
var file = OpenFileDialog(
|
||||||
var macroTool = new MacroInputTool { Config = Config };
|
null,
|
||||||
var macro = macroTool.LoadMacro(Emulator, Tools);
|
MacroInputTool.SuggestedFolder(Config, Game),
|
||||||
if (macro != null)
|
MacroInputTool.MacrosFSFilterSet
|
||||||
|
);
|
||||||
|
|
||||||
|
if (file != null)
|
||||||
{
|
{
|
||||||
macro.Start = TasView.FirstSelectedIndex ?? 0;
|
var macro = new MovieZone(file.FullName, Emulator, MovieSession, Tools);
|
||||||
macro.PlaceZone(CurrentTasMovie, Config);
|
if (macro != null)
|
||||||
|
{
|
||||||
|
macro.Start = TasView.FirstSelectedIndex ?? 0;
|
||||||
|
macro.PlaceZone(CurrentTasMovie, Config);
|
||||||
|
|
||||||
|
Config.RecentMacros.Add(file.FullName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
@ -59,6 +60,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
protected virtual void FastUpdateAfter() { }
|
protected virtual void FastUpdateAfter() { }
|
||||||
|
|
||||||
public FileInfo OpenFileDialog(string currentFile, string path, string fileType, string fileExt)
|
public FileInfo OpenFileDialog(string currentFile, string path, string fileType, string fileExt)
|
||||||
|
{
|
||||||
|
return OpenFileDialog(currentFile, path, new FilesystemFilterSet(new FilesystemFilter(fileType, new[] { fileExt })));
|
||||||
|
}
|
||||||
|
public FileInfo OpenFileDialog(string currentFile, string path, FilesystemFilterSet filterSet)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
{
|
{
|
||||||
|
@ -69,9 +74,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
FileName = !string.IsNullOrWhiteSpace(currentFile)
|
FileName = !string.IsNullOrWhiteSpace(currentFile)
|
||||||
? Path.GetFileName(currentFile)
|
? Path.GetFileName(currentFile)
|
||||||
: $"{Game.FilesystemSafeName()}.{fileExt}",
|
: $"{Game.FilesystemSafeName()}.{filterSet.Filters.FirstOrDefault()?.Extensions.FirstOrDefault()}",
|
||||||
InitialDirectory = path,
|
InitialDirectory = path,
|
||||||
Filter = new FilesystemFilterSet(new FilesystemFilter(fileType, new[] { fileExt })).ToString(),
|
Filter = filterSet.ToString(),
|
||||||
RestoreDirectory = true
|
RestoreDirectory = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,6 +85,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileInfo SaveFileDialog(string currentFile, string path, string fileType, string fileExt, IDialogParent parent)
|
public static FileInfo SaveFileDialog(string currentFile, string path, string fileType, string fileExt, IDialogParent parent)
|
||||||
|
{
|
||||||
|
return SaveFileDialog(currentFile, path, new FilesystemFilterSet(new FilesystemFilter(fileType, new[] { fileExt })), parent);
|
||||||
|
}
|
||||||
|
public static FileInfo SaveFileDialog(string currentFile, string path, FilesystemFilterSet filterSet, IDialogParent parent)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
{
|
{
|
||||||
|
@ -90,7 +99,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
FileName = Path.GetFileName(currentFile),
|
FileName = Path.GetFileName(currentFile),
|
||||||
InitialDirectory = path,
|
InitialDirectory = path,
|
||||||
Filter = new FilesystemFilterSet(new FilesystemFilter(fileType, new[] { fileExt })).ToString(),
|
Filter = filterSet.ToString(),
|
||||||
RestoreDirectory = true
|
RestoreDirectory = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue