Skip to content

Commit

Permalink
Replaced Material MessageBox with Homebrew Solution
Browse files Browse the repository at this point in the history
MaterialMessageBox has too many bugs that can affect opening and closing of the patcher.
  • Loading branch information
Piranha91 committed Dec 5, 2023
1 parent 7cbce3b commit 8078bc1
Show file tree
Hide file tree
Showing 46 changed files with 349 additions and 238 deletions.
2 changes: 1 addition & 1 deletion BatchConfigUpdater/VM_BatchConfigUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
13 changes: 1 addition & 12 deletions SynthEBD/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ public int StandaloneOpen()
var navPanel = container.Resolve<VM_NavPanel>();
navPanel.GoToMainMenu();

var customMessages = container.Resolve<CustomMessageBox>();
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;
}

Expand All @@ -98,9 +90,6 @@ public int OpenForSettings(IOpenForSettingsState state)
mainVM.Init();
window.Show();

var customMessages = container.Resolve<CustomMessageBox>();
customMessages.AllowMessageDisplay();

return 0;
}

Expand Down Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions SynthEBD/Classes_Aux/ViewModels/VM_AssetDistributionSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}


Expand All @@ -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);
});
}

Expand Down
2 changes: 1 addition & 1 deletion SynthEBD/Classes_Aux/ViewModels/VM_AttributeGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions SynthEBD/Classes_Aux/ViewModels/VM_BodySlideExchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public bool Export()
JSONhandler<BodySlideExchange>.SaveJSONFile(exchange, savePath, out bool success, out string exception);
if (!success)
{
CustomMessageBox.DisplayNotificationOK("Export Failed", exception);
MessageWindow.DisplayNotificationOK("Export Failed", exception);
closeWindow = false;
}
}
Expand Down Expand Up @@ -215,19 +215,19 @@ public bool Import()
var exchange = JSONhandler<BodySlideExchange>.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"))
{
JSONhandler<Settings_OBody>.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;
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion SynthEBD/Classes_Aux/ViewModels/VM_FilePathReplacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion SynthEBD/Classes_Aux/ViewModels/VM_HeadPartImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion SynthEBD/Classes_Aux/ViewModels/VM_HeadPartList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public VM_HeadPartList(ObservableCollection<VM_RaceGrouping> 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())
{
Expand Down
119 changes: 119 additions & 0 deletions SynthEBD/Classes_Aux/ViewModels/VM_MessageWindow.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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<string> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
26 changes: 26 additions & 0 deletions SynthEBD/Classes_Aux/Views/Window_MessageWindowOK.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Window x:Class="SynthEBD.Window_MessageWindowOK"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DataContext="{d:DesignInstance Type=local:VM_MessageWindowOK}"
xmlns:local="clr-namespace:SynthEBD"
mc:Ignorable="d"
Title="{Binding Header}" Height="450" Width="800">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>

<ScrollViewer Grid.Row="0">
<TextBox Text="{Binding Path=Text, Mode=OneWay}" Foreground="White" Background="Transparent" BorderThickness="0" IsReadOnly="True" TextWrapping="Wrap" FontSize="12"/>
</ScrollViewer>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Foreground="Green" Content="OK" Command="{Binding OkCommand}" FontSize="18"/>
<Button Foreground="White" FontSize="18" Content="Copy Message" Command="{Binding CopyTextCommand}" Margin="15 0 0 0"/>
</StackPanel>
</Grid>
</Grid>
</Window>
27 changes: 27 additions & 0 deletions SynthEBD/Classes_Aux/Views/Window_MessageWindowOK.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SynthEBD
{
/// <summary>
/// Interaction logic for Window_MessageWindowOK.xaml
/// </summary>
public partial class Window_MessageWindowOK : Window
{
public Window_MessageWindowOK()
{
InitializeComponent();
}
}
}
27 changes: 27 additions & 0 deletions SynthEBD/Classes_Aux/Views/Window_MessageWindowYesNo.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Window x:Class="SynthEBD.Window_MessageWindowYesNo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DataContext="{d:DesignInstance Type=local:VM_MessageWindowYesNo}"
xmlns:local="clr-namespace:SynthEBD"
mc:Ignorable="d"
Title="{Binding Header}" Height="450" Width="800">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>

<ScrollViewer Grid.Row="0">
<TextBox Text="{Binding Path=Text, Mode=OneWay}" Foreground="White" Background="Transparent" BorderThickness="0" IsReadOnly="True" TextWrapping="Wrap" FontSize="12"/>
</ScrollViewer>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Foreground="Green" FontSize="18" Content="Yes" Command="{Binding YesCommand}"/>
<Button Foreground="Firebrick" FontSize="18" Content="No" Command="{Binding NoCommand}" Margin="15 0 0 0"/>
<Button Foreground="White" FontSize="18" Content="Copy Message" Command="{Binding CopyTextCommand}" Margin="15 0 0 0"/>
</StackPanel>
</Grid>
</Grid>
</Window>
Loading

0 comments on commit 8078bc1

Please sign in to comment.