diff --git a/BatchConfigUpdater/VM_BatchConfigUpdater.cs b/BatchConfigUpdater/VM_BatchConfigUpdater.cs index 5d394b9e..ff0d4247 100644 --- a/BatchConfigUpdater/VM_BatchConfigUpdater.cs +++ b/BatchConfigUpdater/VM_BatchConfigUpdater.cs @@ -24,7 +24,7 @@ public VM_BatchConfigUpdater() if (errors.Any()) { - CustomMessageBox.DisplayNotificationOK("Errors", String.Join(Environment.NewLine, errors)); + MessageWindow.DisplayNotificationOK("Errors", String.Join(Environment.NewLine, errors)); } } } diff --git a/SynthEBD/App.xaml.cs b/SynthEBD/App.xaml.cs index e2bb62ea..475f8a15 100644 --- a/SynthEBD/App.xaml.cs +++ b/SynthEBD/App.xaml.cs @@ -65,14 +65,6 @@ public int StandaloneOpen() var navPanel = container.Resolve(); navPanel.GoToMainMenu(); - var customMessages = container.Resolve(); - customMessages.AllowMessageDisplay(); - - //special case - MaterialMessageBox causes main window to close if it's called before window.Show(), so have to call these functions now - //update 2023 08 09 - it looks like MaterialMessageBox is fine as long as it's called after the window is declared, not when window.Show() is called. Not changing the function calls below because they work fine, but - // for future reference it's fine to call MaterialMessageBox any time after the window is declared -- currently used by mainVM.Init() - //update 2023 08 21 - Moved these functions to ViewModelLoader now that they're ok to call before window.Show() - return 0; } @@ -98,9 +90,6 @@ public int OpenForSettings(IOpenForSettingsState state) mainVM.Init(); window.Show(); - var customMessages = container.Resolve(); - customMessages.AllowMessageDisplay(); - return 0; } @@ -253,7 +242,7 @@ private void Application_DispatcherUnhandledException(object sender, System.Wind } var errorMessage = sb.ToString(); - CustomMessageBox.DisplayNotificationOK("SynthEBD has crashed.", errorMessage); + MessageWindow.DisplayNotificationOK("SynthEBD has crashed.", errorMessage); var path = Path.Combine(_settingsSourceProvider.DefaultSettingsRootPath, "Logs", "Crash Logs", DateTime.Now.ToString("yyyy-MM-dd-HH-mm", System.Globalization.CultureInfo.InvariantCulture) + ".txt"); diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_AssetDistributionSimulator.cs b/SynthEBD/Classes_Aux/ViewModels/VM_AssetDistributionSimulator.cs index 15122a3a..bd498cae 100644 --- a/SynthEBD/Classes_Aux/ViewModels/VM_AssetDistributionSimulator.cs +++ b/SynthEBD/Classes_Aux/ViewModels/VM_AssetDistributionSimulator.cs @@ -115,11 +115,11 @@ public bool SimulatePrimaryDistribution() { Clear(); if (PrimaryAPs is null || !PrimaryAPs.Any()) { - CustomMessageBox.DisplayNotificationOK("Cannot Simulate Distribution", "No Primary Config Files are selected in the Active Config Files list"); + MessageWindow.DisplayNotificationOK("Cannot Simulate Distribution", "No Primary Config Files are selected in the Active Config Files list"); return false; } if (NPCformKey.IsNull) { - CustomMessageBox.DisplayNotificationOK("Cannot Simulate Distribution", "No NPC is selected"); + MessageWindow.DisplayNotificationOK("Cannot Simulate Distribution", "No NPC is selected"); return false; } @@ -129,7 +129,7 @@ public bool SimulatePrimaryDistribution() if (!flattenedAssetPacks.Any()) { - CustomMessageBox.DisplayNotificationOK("Cannot Simulate Distribution", "No Primary Config Files with the same gender as " + _logger.GetNPCLogNameString(NPCgetter) + " are selected in the Active Config Files list"); + MessageWindow.DisplayNotificationOK("Cannot Simulate Distribution", "No Primary Config Files with the same gender as " + _logger.GetNPCLogNameString(NPCgetter) + " are selected in the Active Config Files list"); return false; } @@ -247,7 +247,7 @@ public void DislpayFullReportPopup(NPCInfo npcInfo) output.Add(npcInfo.Report.RootElement); var outputStr = Logger.FormatLogStringIndents(output.ToString()); - CustomMessageBox.DisplayNotificationOK("Copy this to a text editor: Notepad++ is recommended", outputStr); + MessageWindow.DisplayNotificationOK("Copy this to a text editor: Notepad++ is recommended", outputStr); } @@ -270,7 +270,7 @@ public VM_ReportCountableStringWrapper(CountableString str) ReferencedStr = str; ExplainCommand = new RelayCommand(canExecute: _ => true, execute: _ => { - CustomMessageBox.DisplayNotificationOK("Explanation", ExplainStr); + MessageWindow.DisplayNotificationOK("Explanation", ExplainStr); }); } diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_AttributeGroup.cs b/SynthEBD/Classes_Aux/ViewModels/VM_AttributeGroup.cs index 219814ce..8d86abfe 100644 --- a/SynthEBD/Classes_Aux/ViewModels/VM_AttributeGroup.cs +++ b/SynthEBD/Classes_Aux/ViewModels/VM_AttributeGroup.cs @@ -85,7 +85,7 @@ public void CheckGroupForCircularReferences() { if (CheckMemberForCircularReference(attribute, circularRefs, ParentMenu.Groups)) { - CustomMessageBox.DisplayNotificationOK("Attribute Group Error", "Circular reference detected: " + string.Join(" -> ", circularRefs)); + MessageWindow.DisplayNotificationOK("Attribute Group Error", "Circular reference detected: " + string.Join(" -> ", circularRefs)); var groupAttribute = attribute.MostRecentlyEditedShell.Attribute as VM_NPCAttributeGroup; if (groupAttribute != null) { diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_BodySlideExchange.cs b/SynthEBD/Classes_Aux/ViewModels/VM_BodySlideExchange.cs index d6d23770..25ae106e 100644 --- a/SynthEBD/Classes_Aux/ViewModels/VM_BodySlideExchange.cs +++ b/SynthEBD/Classes_Aux/ViewModels/VM_BodySlideExchange.cs @@ -98,7 +98,7 @@ public bool Export() JSONhandler.SaveJSONFile(exchange, savePath, out bool success, out string exception); if (!success) { - CustomMessageBox.DisplayNotificationOK("Export Failed", exception); + MessageWindow.DisplayNotificationOK("Export Failed", exception); closeWindow = false; } } @@ -215,11 +215,11 @@ public bool Import() var exchange = JSONhandler.LoadJSONFile(loadPath, out bool success, out string exception); if (!success) { - CustomMessageBox.DisplayNotificationOK("Import Failed", exception); + MessageWindow.DisplayNotificationOK("Import Failed", exception); return false; } - if (CustomMessageBox.DisplayNotificationYesNo("Settings Backup", "Back up your current BodySlide settings before importing?")) + if (MessageWindow.DisplayNotificationYesNo("Settings Backup", "Back up your current BodySlide settings before importing?")) { var currentSettings = _oBodyUI.DumpViewModelToModel(); if (currentSettings != null && IO_Aux.SelectFileSave("", "Bodyslide Settings files (.json|*.json", ".json", "Save BodySlide Settings", out string savePath, "OBodySettings.json")) @@ -227,7 +227,7 @@ public bool Import() JSONhandler.SaveJSONFile(currentSettings, savePath, out bool succes, out string saveException); if (!succes) { - CustomMessageBox.DisplayNotificationOK("Failed to save settings", "Settings could not be saved. Error: " + Environment.NewLine + Environment.NewLine + saveException); + MessageWindow.DisplayNotificationOK("Failed to save settings", "Settings could not be saved. Error: " + Environment.NewLine + Environment.NewLine + saveException); return false; } } @@ -261,7 +261,7 @@ public bool Import() _oBodyUI.DescriptorUI.MergeInMissingModels(exchange.TemplateDescriptors, DescriptorMergeMode, mergedDescriptors); if (mergedDescriptors.Any()) { - CustomMessageBox.DisplayNotificationOK("Descriptor Merge", "The following already existing Descriptors were merged from the imported file. Please check their associated distribution rules to make sure the merged product is consistent with your preferences." + Environment.NewLine + string.Join(Environment.NewLine, mergedDescriptors)); + MessageWindow.DisplayNotificationOK("Descriptor Merge", "The following already existing Descriptors were merged from the imported file. Please check their associated distribution rules to make sure the merged product is consistent with your preferences." + Environment.NewLine + string.Join(Environment.NewLine, mergedDescriptors)); } List<(string, int, int)> multiplexWarnings = new(); @@ -277,7 +277,7 @@ public bool Import() } string dispStr = "Could not import annotations for the following BodySlides because the number of existing entries in your BodySlide Settings does not match the number of annotations in the exchange file. Either adjust the number of your entries to match by copying/deleting the existing one(s), or delete all but one, and then try importing again." + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine + Environment.NewLine, warnStrs); - CustomMessageBox.DisplayNotificationOK("Import Warnings", dispStr); + MessageWindow.DisplayNotificationOK("Import Warnings", dispStr); } return true; diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_FilePathReplacement.cs b/SynthEBD/Classes_Aux/ViewModels/VM_FilePathReplacement.cs index 656fd33b..f6500e8e 100644 --- a/SynthEBD/Classes_Aux/ViewModels/VM_FilePathReplacement.cs +++ b/SynthEBD/Classes_Aux/ViewModels/VM_FilePathReplacement.cs @@ -71,7 +71,7 @@ public VM_FilePathReplacement(VM_FilePathReplacementMenu parentMenu, IEnvironmen } else { - CustomMessageBox.DisplayNotificationOK("Parsing Error", "Cannot figure out where the Data folder is within the supplied path. You will need to edit the path so that it starts one folder beneath the Data folder."); + MessageWindow.DisplayNotificationOK("Parsing Error", "Cannot figure out where the Data folder is within the supplied path. You will need to edit the path so that it starts one folder beneath the Data folder."); Source = dialog.FileName; } diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_HeadPartImport.cs b/SynthEBD/Classes_Aux/ViewModels/VM_HeadPartImport.cs index 07eecad1..76ea31d1 100644 --- a/SynthEBD/Classes_Aux/ViewModels/VM_HeadPartImport.cs +++ b/SynthEBD/Classes_Aux/ViewModels/VM_HeadPartImport.cs @@ -217,7 +217,7 @@ public void ImportSelections() if (skippedImports.Any()) { - CustomMessageBox.DisplayNotificationOK("Duplicate Imports", "The following head parts were previously imported and will be skipped: " + Environment.NewLine + String.Join(Environment.NewLine, skippedImports)); + MessageWindow.DisplayNotificationOK("Duplicate Imports", "The following head parts were previously imported and will be skipped: " + Environment.NewLine + String.Join(Environment.NewLine, skippedImports)); } _logger.CallTimedNotifyStatusUpdateAsync("Imported " + importCount + " head parts.", 5); diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_HeadPartList.cs b/SynthEBD/Classes_Aux/ViewModels/VM_HeadPartList.cs index 512ffcbf..88a68c87 100644 --- a/SynthEBD/Classes_Aux/ViewModels/VM_HeadPartList.cs +++ b/SynthEBD/Classes_Aux/ViewModels/VM_HeadPartList.cs @@ -74,7 +74,7 @@ public VM_HeadPartList(ObservableCollection raceGroupingVMs, DeleteAll = new RelayCommand( canExecute: _ => true, execute: _ => { - if (CustomMessageBox.DisplayNotificationYesNo("Batch Deletion", "Are you sure you want to delete all headparts in this list?")) + if (MessageWindow.DisplayNotificationYesNo("Batch Deletion", "Are you sure you want to delete all headparts in this list?")) { foreach (var hp in DisplayedList.ToArray()) { diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_MessageWindow.cs b/SynthEBD/Classes_Aux/ViewModels/VM_MessageWindow.cs new file mode 100644 index 00000000..26772611 --- /dev/null +++ b/SynthEBD/Classes_Aux/ViewModels/VM_MessageWindow.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace SynthEBD +{ + public class MessageWindow + { + public static void DisplayNotificationOK(string header, string text) + { + var box = new VM_MessageWindowOK(header, text); + box.Show(); + } + public static void DisplayNotificationOK(string header, ICollection text, string separator) + { + var box = new VM_MessageWindowOK(header, string.Join(separator, text)); + box.Show(); + } + public static bool DisplayNotificationYesNo(string header, string text) + { + var box = new VM_MessageWindowYesNo(header, text); + box.Show(); + + return box.Result; + } + public static bool DisplayNotificationYesNo(string header, ICollection text, string separator) + { + var box = new VM_MessageWindowYesNo(header, string.Join(separator, text)); + box.Show(); + + return box.Result; + } + } + + public class VM_MessageWindowOK : VM + { + public VM_MessageWindowOK(string header, string text) + { + Header = header; + Text = text; + _window = new(); + + OkCommand = new RelayCommand( + canExecute: _ => true, + execute: _ => + { + _window.Close(); + }); + + CopyTextCommand = new RelayCommand( + canExecute: _ => true, + execute: _ => + { + Clipboard.SetText(Text); + }); + } + + public string Header { get; set; } + public string Text { get; set; } + private Window_MessageWindowOK _window { get; } + public RelayCommand OkCommand { get; } + public RelayCommand CopyTextCommand { get; } + + public void Show() + { + _window.DataContext = this; + _window.ShowDialog(); + } + } + + public class VM_MessageWindowYesNo : VM + { + public VM_MessageWindowYesNo(string header, string text) + { + Header = header; + Text = text; + _window = new(); + + YesCommand = new RelayCommand( + canExecute: _ => true, + execute: _ => + { + Result = true; + _window.Close(); + }); + + NoCommand = new RelayCommand( + canExecute: _ => true, + execute: _ => + { + Result = false; + _window.Close(); + }); + + CopyTextCommand = new RelayCommand( + canExecute: _ => true, + execute: _ => + { + Clipboard.SetText(Text); + }); + } + + public string Header { get; set; } + public string Text { get; set; } + public bool Result { get; set; } + private Window_MessageWindowYesNo _window { get; } + public RelayCommand YesCommand { get; } + public RelayCommand NoCommand { get; } + public RelayCommand CopyTextCommand { get; } + public void Show() + { + _window.DataContext = this; + _window.ShowDialog(); + } + } +} diff --git a/SynthEBD/Classes_Aux/ViewModels/VM_PositionalSubgroupContainerCollection.cs b/SynthEBD/Classes_Aux/ViewModels/VM_PositionalSubgroupContainerCollection.cs index db7d5111..90228ec6 100644 --- a/SynthEBD/Classes_Aux/ViewModels/VM_PositionalSubgroupContainerCollection.cs +++ b/SynthEBD/Classes_Aux/ViewModels/VM_PositionalSubgroupContainerCollection.cs @@ -127,7 +127,7 @@ public void Drop(IDropInfo dropInfo) { if (collectionViewModel.ContainsSubgroup(draggedSubgroup)) { - CustomMessageBox.DisplayNotificationOK("Invalid Operation", "This list already contains subgroup " + draggedSubgroup.ID + ": " + draggedSubgroup.Name); + MessageWindow.DisplayNotificationOK("Invalid Operation", "This list already contains subgroup " + draggedSubgroup.ID + ": " + draggedSubgroup.Name); } else { diff --git a/SynthEBD/Classes_Aux/Views/Window_MessageWindowOK.xaml b/SynthEBD/Classes_Aux/Views/Window_MessageWindowOK.xaml new file mode 100644 index 00000000..50e9ca84 --- /dev/null +++ b/SynthEBD/Classes_Aux/Views/Window_MessageWindowOK.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + +