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]
|
||||
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<int> _unsavedZones = new List<int>();
|
||||
|
@ -255,27 +255,28 @@ namespace BizHawk.Client.EmuHawk
|
|||
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(
|
||||
Config.PathEntries["Global", "Macros"].Path,
|
||||
Game.FilesystemSafeName()), null);
|
||||
return config.PathEntries.AbsolutePathFor(Path.Combine(
|
||||
config.PathEntries["Global", "Macros"].Path,
|
||||
game?.FilesystemSafeName()), null);
|
||||
}
|
||||
|
||||
public bool SaveMacroAs(MovieZone macro)
|
||||
private bool SaveMacroAs(MovieZone macro)
|
||||
{
|
||||
string suggestedFolder = SuggestedFolder(Config, Game);
|
||||
using var dialog = new SaveFileDialog
|
||||
{
|
||||
InitialDirectory = SuggestedFolder(),
|
||||
InitialDirectory = suggestedFolder,
|
||||
FileName = macro.Name,
|
||||
Filter = MacrosFSFilterSet.ToString()
|
||||
};
|
||||
|
||||
// Create directory?
|
||||
bool create = false;
|
||||
if (!Directory.Exists(SuggestedFolder()))
|
||||
if (!Directory.Exists(suggestedFolder))
|
||||
{
|
||||
Directory.CreateDirectory(SuggestedFolder());
|
||||
Directory.CreateDirectory(suggestedFolder);
|
||||
create = true;
|
||||
}
|
||||
|
||||
|
@ -295,11 +296,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
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
|
||||
{
|
||||
InitialDirectory = SuggestedFolder(),
|
||||
InitialDirectory = SuggestedFolder(Config),
|
||||
Filter = MacrosFSFilterSet.ToString()
|
||||
};
|
||||
|
||||
|
|
|
@ -228,17 +228,26 @@ namespace BizHawk.Client.EmuHawk
|
|||
TasView.SelectRow(CurrentTasMovie.InputLogLength, false);
|
||||
}
|
||||
|
||||
var macro = new MovieZone(
|
||||
CurrentTasMovie,
|
||||
Emulator,
|
||||
Tools,
|
||||
MovieSession,
|
||||
TasView.FirstSelectedIndex ?? 0,
|
||||
TasView.LastSelectedIndex ?? 0 - TasView.FirstSelectedIndex ?? 0 + 1);
|
||||
var file = SaveFileDialog(
|
||||
null,
|
||||
MacroInputTool.SuggestedFolder(Config, Game),
|
||||
MacroInputTool.MacrosFSFilterSet,
|
||||
this
|
||||
);
|
||||
|
||||
//var macroTool = Tools.Load<MacroInputTool>(false);
|
||||
var macroTool = new MacroInputTool { Config = Config };
|
||||
macroTool.SaveMacroAs(macro);
|
||||
if (file != null)
|
||||
{
|
||||
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)
|
||||
|
@ -248,13 +257,22 @@ namespace BizHawk.Client.EmuHawk
|
|||
return;
|
||||
}
|
||||
|
||||
//var macroTool = Tools.Load<MacroInputTool>(false);
|
||||
var macroTool = new MacroInputTool { Config = Config };
|
||||
var macro = macroTool.LoadMacro(Emulator, Tools);
|
||||
if (macro != null)
|
||||
var file = OpenFileDialog(
|
||||
null,
|
||||
MacroInputTool.SuggestedFolder(Config, Game),
|
||||
MacroInputTool.MacrosFSFilterSet
|
||||
);
|
||||
|
||||
if (file != null)
|
||||
{
|
||||
macro.Start = TasView.FirstSelectedIndex ?? 0;
|
||||
macro.PlaceZone(CurrentTasMovie, Config);
|
||||
var macro = new MovieZone(file.FullName, Emulator, MovieSession, Tools);
|
||||
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.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
@ -59,6 +60,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
protected virtual void FastUpdateAfter() { }
|
||||
|
||||
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))
|
||||
{
|
||||
|
@ -69,9 +74,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
FileName = !string.IsNullOrWhiteSpace(currentFile)
|
||||
? Path.GetFileName(currentFile)
|
||||
: $"{Game.FilesystemSafeName()}.{fileExt}",
|
||||
: $"{Game.FilesystemSafeName()}.{filterSet.Filters.FirstOrDefault()?.Extensions.FirstOrDefault()}",
|
||||
InitialDirectory = path,
|
||||
Filter = new FilesystemFilterSet(new FilesystemFilter(fileType, new[] { fileExt })).ToString(),
|
||||
Filter = filterSet.ToString(),
|
||||
RestoreDirectory = true
|
||||
};
|
||||
|
||||
|
@ -80,6 +85,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
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))
|
||||
{
|
||||
|
@ -90,7 +99,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
FileName = Path.GetFileName(currentFile),
|
||||
InitialDirectory = path,
|
||||
Filter = new FilesystemFilterSet(new FilesystemFilter(fileType, new[] { fileExt })).ToString(),
|
||||
Filter = filterSet.ToString(),
|
||||
RestoreDirectory = true
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue