diff --git a/UndertaleModTool/MainWindow.xaml.cs b/UndertaleModTool/MainWindow.xaml.cs
index 6e59bcfbb..48addfb20 100644
--- a/UndertaleModTool/MainWindow.xaml.cs
+++ b/UndertaleModTool/MainWindow.xaml.cs
@@ -103,13 +103,13 @@ public object Selected
OnPropertyChanged();
OpenInTab(value);
}
- }
-
- ///
- /// Whether the currently-selected object is exportable to a project.
- ///
- public bool IsSelectedProjectExportable { get; private set; }
-
+ }
+
+ ///
+ /// Whether the currently-selected object is exportable to a project.
+ ///
+ public bool IsSelectedProjectExportable { get; private set; }
+
private static Visibility ToVisibility(bool visible) => visible ? Visibility.Visible : Visibility.Collapsed;
public Visibility IsGMS2 => (Data?.GeneralInfo?.Major ?? 0) >= 2 ? Visibility.Visible : Visibility.Collapsed;
@@ -300,9 +300,9 @@ public BitmapSource GetBitmapSourceForImage(GMImage image)
}
// If the image is of unknown format, it cannot be displayed. Use a placeholder texture...
- if (image.Format == GMImage.ImageFormat.Unknown)
- {
- image = new GMImage(1, 1);
+ if (image.Format == GMImage.ImageFormat.Unknown)
+ {
+ image = new GMImage(1, 1);
}
// If no source was found, then create a new one
@@ -493,11 +493,11 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
Environment.Exit(0);
}
string gameExePath = Paths.TryJoinVerifyWithinDirectory(Path.GetDirectoryName(FilePath), gameExeName + ".exe");
- if (gameExePath is null)
- {
+ if (gameExePath is null)
+ {
ScriptError("Failed to find valid game executable path; escaped directory");
- Environment.Exit(0);
- }
+ Environment.Exit(0);
+ }
if (!File.Exists(gameExePath))
{
ScriptError("Cannot find game executable path, expected: " + gameExePath);
@@ -544,11 +544,11 @@ public void OpenChildFile(string filename, string chunkName, int itemIndex)
string dir = Path.GetDirectoryName(FilePath);
string childFilePath = Paths.TryJoinVerifyWithinDirectory(dir, filename);
- if (childFilePath is null)
- {
- ScriptError("Failed to open child data file; escaped directory.");
- return;
- }
+ if (childFilePath is null)
+ {
+ ScriptError("Failed to open child data file; escaped directory.");
+ return;
+ }
Process.Start(new ProcessStartInfo(Environment.ProcessPath, [childFilePath, key]));
var server = new NamedPipeServerStream(key);
@@ -1128,20 +1128,20 @@ private async Task LoadFile(string filename, bool preventClose = false, bool onl
this.ShowWarning("This game is set to run with the GameMaker Studio debugger and the normal runtime will simply hang after loading if the debugger is not running. You can turn this off in General Info by checking the \"Disable Debugger\" box and saving.", "GMS Debugger");
}
}
- if (data.EmbeddedTextures is not null)
- {
- foreach (UndertaleEmbeddedTexture tex in data.EmbeddedTextures)
- {
- if (tex?.TextureData?.Image?.Format == GMImage.ImageFormat.Unknown)
- {
- this.ShowWarning("This game contains texture(s) with unknown or unsupported image formats. These will save/load, but will not display in editors, and many operations will fail regarding them. Proceed with caution.", "Unsupported textures");
- break;
- }
- }
- }
- if (Path.GetDirectoryName(FilePath) != Path.GetDirectoryName(filename))
+ if (data.EmbeddedTextures is not null)
+ {
+ foreach (UndertaleEmbeddedTexture tex in data.EmbeddedTextures)
+ {
+ if (tex?.TextureData?.Image?.Format == GMImage.ImageFormat.Unknown)
+ {
+ this.ShowWarning("This game contains texture(s) with unknown or unsupported image formats. These will save/load, but will not display in editors, and many operations will fail regarding them. Proceed with caution.", "Unsupported textures");
+ break;
+ }
+ }
+ }
+ if (Path.GetDirectoryName(FilePath) != Path.GetDirectoryName(filename))
{
- CloseChildFiles();
+ CloseChildFiles();
}
Data = data;
@@ -1190,46 +1190,46 @@ private async Task SaveFile(string filename, bool suppressDebug = false)
dialog.Owner = this;
FilePath = filename;
OnPropertyChanged("FilePath");
- if (Path.GetDirectoryName(FilePath) != Path.GetDirectoryName(filename))
- {
- CloseChildFiles();
+ if (Path.GetDirectoryName(FilePath) != Path.GetDirectoryName(filename))
+ {
+ CloseChildFiles();
}
DebugDataDialog.DebugDataMode debugMode = DebugDataDialog.DebugDataMode.NoDebug;
if (!suppressDebug && Data.GeneralInfo != null && !Data.GeneralInfo.IsDebuggerDisabled)
this.ShowWarning("You are saving the game in GameMaker Studio debug mode. Unless the debugger is running, the normal runtime will simply hang after loading. You can turn this off in General Info by checking the \"Disable Debugger\" box and saving.", "GMS Debugger");
Task t = Task.Run(() =>
- {
- // Recompile code sources before doing anything, if needed
- if (Settings.Instance.RecompileAllCodeSourcesOnProjectSave)
- {
- try
- {
- if (Project is not null)
- {
- FileMessageEvent?.Invoke("Recompiling GML code, please wait...");
- Project.RecompileAllCodeSources();
- FileMessageEvent?.Invoke("Saving data file, please wait...");
- }
- }
- catch (ProjectException e)
- {
- Dispatcher.Invoke(() =>
- {
- dialog.TryClose();
- this.ShowError(e.Message, "Recompile error");
- });
- return false;
- }
- catch (Exception e)
- {
- Dispatcher.Invoke(() =>
- {
- dialog.TryClose();
- this.ShowError("An error occurred while trying to recompile code sources:\n" + e.Message, "Recompile error");
- });
- return false;
- }
+ {
+ // Recompile code sources before doing anything, if needed
+ if (Settings.Instance.RecompileAllCodeSourcesOnProjectSave)
+ {
+ try
+ {
+ if (Project is not null)
+ {
+ FileMessageEvent?.Invoke("Recompiling GML code, please wait...");
+ Project.RecompileAllCodeSources();
+ FileMessageEvent?.Invoke("Saving data file, please wait...");
+ }
+ }
+ catch (ProjectException e)
+ {
+ Dispatcher.Invoke(() =>
+ {
+ dialog.TryClose();
+ this.ShowError(e.Message, "Recompile error");
+ });
+ return false;
+ }
+ catch (Exception e)
+ {
+ Dispatcher.Invoke(() =>
+ {
+ dialog.TryClose();
+ this.ShowError("An error occurred while trying to recompile code sources:\n" + e.Message, "Recompile error");
+ });
+ return false;
+ }
}
bool saveSucceeded = true;
@@ -1699,7 +1699,7 @@ private void MainTree_KeyDown(object sender, KeyEventArgs e)
if (Highlighted is UndertaleObject obj)
DeleteItem(obj);
}
- }
+ }
private async void CommandBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
@@ -1710,10 +1710,10 @@ private async void CommandBox_PreviewKeyDown(object sender, KeyEventArgs e)
CommandBox.IsEnabled = false;
object result;
try
- {
- if (!scriptSetupTask.IsCompleted)
- {
- await scriptSetupTask;
+ {
+ if (!scriptSetupTask.IsCompleted)
+ {
+ await scriptSetupTask;
}
ScriptPath = null;
@@ -2130,6 +2130,11 @@ public void HideProgressBar()
{
scriptDialog?.TryHide();
}
+ public void CloseProgressBar()
+ {
+ scriptDialog?.TryClose();
+ scriptDialog = null;
+ }
public void AddProgress(int amount)
{
@@ -2302,13 +2307,14 @@ public async Task RunScript(string path)
ScriptExecutionSuccess = true;
ScriptErrorMessage = "";
ScriptErrorType = "";
+
InitializeScriptDialog();
- this.IsEnabled = false; // Prevent interaction while the script is running.
+ this.IsEnabled = false; // Prevent interaction while the script is running.
await RunScriptNow(path); // Runs the script now.
- HideProgressBar(); // Hide the progress bar.
- scriptDialog = null;
- this.IsEnabled = true; // Allow interaction again.
+
+ CloseProgressBar(); // Closes the progress bar entirely.
+ this.IsEnabled = true; // Allow interaction again.
}
private async Task RunScriptNow(string path)
@@ -2317,10 +2323,10 @@ private async Task RunScriptNow(string path)
Dispatcher.Invoke(() => CommandBox.Text = "Running " + Path.GetFileName(path) + " ...");
try
- {
- if (!scriptSetupTask.IsCompleted)
- {
- await scriptSetupTask;
+ {
+ if (!scriptSetupTask.IsCompleted)
+ {
+ await scriptSetupTask;
}
ScriptPath = path;
@@ -2920,10 +2926,10 @@ private async void Command_Run(object sender, ExecutedRoutedEventArgs e)
// Project is loaded - try to find game EXE in save directory
saveDataFilePath = Project.SaveDataPath;
gameExePath = Paths.TryJoinVerifyWithinDirectory(Path.GetDirectoryName(saveDataFilePath), $"{gameExeName}.exe");
- if (gameExePath is null)
- {
- ScriptError("Failed to find valid game executable path; escaped directory");
- return;
+ if (gameExePath is null)
+ {
+ ScriptError("Failed to find valid game executable path; escaped directory");
+ return;
}
if (!File.Exists(gameExePath))
{
@@ -2950,10 +2956,10 @@ to save your changes. Closing UndertaleModTool
// Try to find game EXE
gameExePath = Paths.TryJoinVerifyWithinDirectory(Path.GetDirectoryName(FilePath), $"{gameExeName}.exe");
- if (gameExePath is null)
- {
- ScriptError("Failed to find valid game executable path; escaped directory");
- return;
+ if (gameExePath is null)
+ {
+ ScriptError("Failed to find valid game executable path; escaped directory");
+ return;
}
if (!File.Exists(gameExePath))
{
@@ -3029,9 +3035,9 @@ private async void Command_RunSpecial(object sender, ExecutedRoutedEventArgs e)
RuntimePicker picker = new RuntimePicker();
picker.Owner = this;
var runtime = picker.Pick(FilePath, Data);
- if (runtime is not null)
+ if (runtime is not null)
{
- Process.Start(new ProcessStartInfo(runtime.Path, ["-game", FilePath, "-debugoutput", Path.ChangeExtension(FilePath, ".gamelog.txt")]));
+ Process.Start(new ProcessStartInfo(runtime.Path, ["-game", FilePath, "-debugoutput", Path.ChangeExtension(FilePath, ".gamelog.txt")]));
}
}
}
@@ -3087,9 +3093,9 @@ private async void Command_RunDebug(object sender, ExecutedRoutedEventArgs e)
0
-");
-
- Process.Start(new ProcessStartInfo(runtime.Path, ["-game", FilePath, "-debugoutput", Path.ChangeExtension(FilePath, ".gamelog.txt")]));
+");
+
+ Process.Start(new ProcessStartInfo(runtime.Path, ["-game", FilePath, "-debugoutput", Path.ChangeExtension(FilePath, ".gamelog.txt")]));
Process.Start(runtime.DebuggerPath, "-d=\"" + Path.ChangeExtension(FilePath, ".yydebug") + "\" -t=\"127.0.0.1\" -tp=" + Data.GeneralInfo.DebuggerPort + " -p=\"" + tempProject + "\"");
}
Data.GeneralInfo.IsDebuggerDisabled = origDbg;
@@ -3109,16 +3115,16 @@ private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
public void UpdateObjectLabel(object obj)
{
- // Try to get index
+ // Try to get index
int foundIndex = obj is UndertaleResource res ? Data.IndexOf(res, false) : -1;
-
- // Determine ID
- string idString;
+
+ // Determine ID
+ string idString;
if (foundIndex == -2)
- {
+ {
idString = "None";
- }
- else if (foundIndex == -1)
+ }
+ else if (foundIndex == -1)
{
idString = "N/A";
}
@@ -3817,7 +3823,7 @@ private string ChooseProjectSaveFile(string sourceFilePath)
return null;
}
- // Check if the directories are the same and warn if so (note: not a fully exhaustive check, but decent)
+ // Check if the directories are the same and warn if so (note: not a fully exhaustive check, but decent)
string saveFilePath = saveDataDialog.FileName;
if (Path.GetFullPath(Path.GetDirectoryName(saveFilePath)).Equals(
Path.GetFullPath(Path.GetDirectoryName(sourceFilePath)), StringComparison.OrdinalIgnoreCase))
@@ -3857,25 +3863,25 @@ private async void Command_NewProject(object sender, ExecutedRoutedEventArgs e)
}
// If necessary, ask for a source data file
- if (Data is null || FilePath is null)
- {
- OpenFileDialog sourceDialog = new()
- {
- DefaultExt = "win",
- Filter = DataFileFilter,
- Title = "Choose source data file"
- };
- if (sourceDialog.ShowDialog(this) != true)
- {
- return;
- }
- await LoadFile(sourceDialog.FileName, true);
-
- // Upon load failure, exit
- if (Data is null || FilePath is null)
- {
- return;
- }
+ if (Data is null || FilePath is null)
+ {
+ OpenFileDialog sourceDialog = new()
+ {
+ DefaultExt = "win",
+ Filter = DataFileFilter,
+ Title = "Choose source data file"
+ };
+ if (sourceDialog.ShowDialog(this) != true)
+ {
+ return;
+ }
+ await LoadFile(sourceDialog.FileName, true);
+
+ // Upon load failure, exit
+ if (Data is null || FilePath is null)
+ {
+ return;
+ }
}
// Ask for name
@@ -3948,25 +3954,25 @@ private async void Command_OpenProject(object sender, ExecutedRoutedEventArgs e)
Title = "Open project file"
};
if (openProjectDialog.ShowDialog(this) != true)
- {
- return;
+ {
+ return;
}
// If necessary, ask for a source data file
string dataFilePathToLoad = null;
- if (Data is null || FilePath is null)
- {
- OpenFileDialog sourceDialog = new()
- {
- DefaultExt = "win",
- Filter = DataFileFilter,
- Title = "Choose source data file"
- };
- if (sourceDialog.ShowDialog(this) != true)
- {
- return;
- }
- dataFilePathToLoad = sourceDialog.FileName;
+ if (Data is null || FilePath is null)
+ {
+ OpenFileDialog sourceDialog = new()
+ {
+ DefaultExt = "win",
+ Filter = DataFileFilter,
+ Title = "Choose source data file"
+ };
+ if (sourceDialog.ShowDialog(this) != true)
+ {
+ return;
+ }
+ dataFilePathToLoad = sourceDialog.FileName;
}
// Ask for save file directory
@@ -3978,16 +3984,16 @@ private async void Command_OpenProject(object sender, ExecutedRoutedEventArgs e)
}
// Load data file if needed
- if (dataFilePathToLoad is not null)
- {
- await LoadFile(dataFilePathToLoad, true);
-
- // Upon load failure, exit
- if (Data is null || FilePath is null)
- {
- return;
- }
- }
+ if (dataFilePathToLoad is not null)
+ {
+ await LoadFile(dataFilePathToLoad, true);
+
+ // Upon load failure, exit
+ if (Data is null || FilePath is null)
+ {
+ return;
+ }
+ }
// Change main file path to the save data file path
string loadFilePath = FilePath;
diff --git a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs
index e6fd3fa27..379a95a41 100644
--- a/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs
+++ b/UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs
@@ -1732,7 +1732,7 @@ await Task.Run(() =>
finally
{
await mainWindow.StopProgressBarUpdater();
- mainWindow.HideProgressBar();
+ mainWindow.CloseProgressBar();
mainWindow.IsEnabled = true;
stringReferences = null;
diff --git a/UndertaleModTool/Windows/SearchInCodeWindow.xaml.cs b/UndertaleModTool/Windows/SearchInCodeWindow.xaml.cs
index c9d2ab994..b90ec25e2 100644
--- a/UndertaleModTool/Windows/SearchInCodeWindow.xaml.cs
+++ b/UndertaleModTool/Windows/SearchInCodeWindow.xaml.cs
@@ -41,7 +41,6 @@ public partial class SearchInCodeWindow : Window
private Regex keywordRegex, nameRegex;
private GlobalDecompileContext decompileContext;
- private LoaderDialog loaderDialog;
private UndertaleCodeEditor.CodeEditorTab editorTab;
public readonly record struct Result(string Code, int LineNumber, string LineText);
@@ -173,10 +172,7 @@ private async Task Search()
isSearchInProgress = true;
- loaderDialog = new("Searching...", null);
- loaderDialog.Owner = this;
- loaderDialog.PreventClose = true;
- loaderDialog.Show();
+ mainWindow.InitializeProgressDialog("Searching...", null);
Results.Clear();
@@ -192,22 +188,20 @@ private async Task Search()
decompileContext = new GlobalDecompileContext(mainWindow.Data);
}
- loaderDialog.SavedStatusText = "Code entries";
- loaderDialog.Update(null, "Code entries", 0, codeEntriesToSearch.Count);
+ mainWindow.SetProgressBar(null, "Code entries", 0, codeEntriesToSearch.Count);
+ mainWindow.StartProgressBarUpdater();
await Task.Run(() => Parallel.ForEach(codeEntriesToSearch, SearchInUndertaleCode));
await Task.Run(SortResults);
- loaderDialog.Maximum = null;
- loaderDialog.Update("Generating result list...");
+ await mainWindow.StopProgressBarUpdater();
+ mainWindow.UpdateProgressStatus("Generating result list...");
editorTab = isInAssembly ? UndertaleCodeEditor.CodeEditorTab.Disassembly : UndertaleCodeEditor.CodeEditorTab.Decompiled;
ShowResults();
- loaderDialog.PreventClose = false;
- loaderDialog.Close();
- loaderDialog = null;
+ mainWindow.CloseProgressBar();
mainWindow.IsEnabled = true;
this.IsEnabled = true;
@@ -246,7 +240,7 @@ private void SearchInUndertaleCode(UndertaleCode code)
}
Interlocked.Increment(ref progressCount);
- Dispatcher.Invoke(() => loaderDialog.ReportProgress(progressCount));
+ mainWindow.IncrementProgressParallel();
}
private void SearchInCodeText(string codeName, string codeText)
@@ -468,7 +462,7 @@ private void Window_IsVisibleChanged(object sender, DependencyPropertyChangedEve
private void Window_Closing(object sender, CancelEventArgs e)
{
- e.Cancel = (loaderDialog is not null);
+ e.Cancel = isSearchInProgress;
}
}
}