Skip to content

Commit

Permalink
Add Delete dialogs and proper error dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
TrinityDevelopers committed Apr 30, 2020
1 parent b2d4c83 commit fc5e4e5
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 25 deletions.
1 change: 0 additions & 1 deletion ZenovaLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Shell;
using ModernWpf.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down
19 changes: 19 additions & 0 deletions ZenovaLauncher/Dialogs/DeleteConfirmationDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<ui:ContentDialog x:Class="ZenovaLauncher.DeleteConfirmationDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ZenovaLauncher"
xmlns:ui="http://schemas.modernwpf.com/2019"
mc:Ignorable="d"
Style="{StaticResource ConfirmationContentDialog}"
PrimaryButtonText="Delete"
CloseButtonText="Cancel"
DefaultButton="Primary"
SecondaryButtonStyle="{DynamicResource LauncherDeleteButtonStyle}">

<ui:SimpleStackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Spacing="15">
<TextBlock HorizontalAlignment="Center" FontSize="15" Text="Are you sure you want to delete?" />
<TextBlock x:Name="DeleteItemName" FontSize="15" HorizontalAlignment="Center" FontStyle="Italic" />
</ui:SimpleStackPanel>
</ui:ContentDialog>
17 changes: 17 additions & 0 deletions ZenovaLauncher/Dialogs/DeleteConfirmationDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using ModernWpf.Controls;

namespace ZenovaLauncher
{
/// <summary>
/// Interaction logic for DeleteConfirmationDialog.xaml
/// </summary>
public partial class DeleteConfirmationDialog : ContentDialog
{
public DeleteConfirmationDialog(string nameToDelete)
{
InitializeComponent();

DeleteItemName.Text = nameToDelete;
}
}
}
21 changes: 21 additions & 0 deletions ZenovaLauncher/Dialogs/ErrorDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<ui:ContentDialog x:Class="ZenovaLauncher.ErrorDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ZenovaLauncher"
xmlns:ui="http://schemas.modernwpf.com/2019"
mc:Ignorable="d"
Style="{StaticResource ConfirmationContentDialog}"
CloseButtonText="Close"
SecondaryButtonStyle="{DynamicResource LauncherDefaultButtonStyle}">

<ui:SimpleStackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Spacing="15">
<ui:SimpleStackPanel Margin="20,0,20,0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBlock Text="ERROR" HorizontalAlignment="Center" FontSize="15" />
<TextBlock x:Name="ErrorTitle" HorizontalAlignment="Center" FontSize="22" FontWeight="Bold"/>
</ui:SimpleStackPanel>
<TextBlock Margin="20,0,20,0" x:Name="ErrorMessage" FontSize="14" TextAlignment="Center" TextWrapping="Wrap" />
<Separator Background="{DynamicResource AppBarSeparatorLowForeground}" />
</ui:SimpleStackPanel>
</ui:ContentDialog>
18 changes: 18 additions & 0 deletions ZenovaLauncher/Dialogs/ErrorDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using ModernWpf.Controls;

namespace ZenovaLauncher
{
/// <summary>
/// Interaction logic for DeleteConfirmationDialog.xaml
/// </summary>
public partial class ErrorDialog : ContentDialog
{
public ErrorDialog(string errorTitle, string errorMessage)
{
InitializeComponent();

ErrorTitle.Text = errorTitle;
ErrorMessage.Text = errorMessage;
}
}
}
2 changes: 2 additions & 0 deletions ZenovaLauncher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ private Uri GetNavigateUri(HamburgerMenuItemBase item)

private void MainWindowLoaded(object sender, RoutedEventArgs e)
{
Utils.WindowLoaded = true;
Utils.ShowErrorDialog();
ModManager.instance.WindowLoaded = true;
ModManager.instance.TryImportMods(new List<string>());
}
Expand Down
4 changes: 2 additions & 2 deletions ZenovaLauncher/Mods/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Mod LoadModFromDir(string modDir)
catch (Exception e)
{
Trace.WriteLine("Load Mod from directory Failed: " + e.ToString());
MessageBox.Show("Load Mod from directory Failed: " + e.ToString());
Utils.ShowErrorDialog("Failed to load mod", string.Format("Error occured while loading mod from directory:\n{0}\nMake sure directory exists and try again.", modDir));
}
return null;
}
Expand All @@ -82,7 +82,7 @@ public Mod LoadMod(string modText, string dirName)
catch (Exception e)
{
Trace.WriteLine("Mods JSON Deserialize Failed: " + e.ToString());
MessageBox.Show("Mods JSON Deserialize Failed: " + e.ToString());
Utils.ShowErrorDialog("Failed to load mod", string.Format("Error occured while parsing modinfo.json in directory:\n{0}\nMake sure modinfo.json exists and is formatted correctly.", dirName));
}
return null;
}
Expand Down
13 changes: 8 additions & 5 deletions ZenovaLauncher/Pages/ModsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Microsoft.Win32;
using ModernWpf.Controls;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -63,10 +61,15 @@ private void ModDetailsClick(object sender, RoutedEventArgs e)
ModDetails((sender as FrameworkElement).DataContext as Mod);
}

private void DeleteModClick(object sender, RoutedEventArgs e)
private async void DeleteModClick(object sender, RoutedEventArgs e)
{
ModManager.instance.RemoveMod((sender as FrameworkElement).DataContext as Mod);
RefreshMods();
DeleteConfirmationDialog deleteMod = new DeleteConfirmationDialog(((sender as FrameworkElement).DataContext as Mod).Name);
var result = await deleteMod.ShowAsync();
if (result == ContentDialogResult.Primary)
{
ModManager.instance.RemoveMod((sender as FrameworkElement).DataContext as Mod);
RefreshMods();
}
}

protected void SortModList(Mod.ModSortType sortType)
Expand Down
20 changes: 13 additions & 7 deletions ZenovaLauncher/Pages/ProfilesPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ModernWpf.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -45,7 +46,7 @@ private async void AddProfileClick(object sender, RoutedEventArgs e)
{
AddProfileDialog newProfile = new AddProfileDialog();
var result = await newProfile.ShowAsync();
if (result == ModernWpf.Controls.ContentDialogResult.Primary)
if (result == ContentDialogResult.Primary)
RefreshProfiles();
}

Expand All @@ -65,11 +66,16 @@ private void DuplicateProfileClick(object sender, RoutedEventArgs e)
SortProfileList(Preferences.instance.ProfileSorting);
}

private void DeleteProfileClick(object sender, RoutedEventArgs e)
private async void DeleteProfileClick(object sender, RoutedEventArgs e)
{
ProfileManager.instance.Remove((sender as FrameworkElement).DataContext as Profile);
VersionManager.instance.RemoveUnusedVersions();
RefreshProfiles();
DeleteConfirmationDialog deleteProfile = new DeleteConfirmationDialog(((sender as FrameworkElement).DataContext as Profile).Name);
var result = await deleteProfile.ShowAsync();
if (result == ContentDialogResult.Primary)
{
ProfileManager.instance.Remove((sender as FrameworkElement).DataContext as Profile);
VersionManager.instance.RemoveUnusedVersions();
RefreshProfiles();
}
}

private void ProfileSelected(object sender, MouseButtonEventArgs e)
Expand Down Expand Up @@ -122,7 +128,7 @@ protected async void EditProfile(Profile profile)
{
EditProfileDialog editProfile = new EditProfileDialog(profile);
var result = await editProfile.ShowAsync();
if (result == ModernWpf.Controls.ContentDialogResult.Primary)
if (result == ContentDialogResult.Primary)
RefreshProfiles();
}
}
Expand Down
8 changes: 4 additions & 4 deletions ZenovaLauncher/Profiles/ProfileLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private async Task<bool> Launch(Profile p)
catch (Exception e)
{
Trace.WriteLine("App re-register failed:\n" + e.ToString());
MessageBox.Show("App re-register failed:\n" + e.ToString());
Utils.ShowErrorDialog("Launch failed", "An error occured which prevented Zenova from re-registering Minecraft. Ensure that Developer Mode is enabled in Windows Settings.");
return false;
}

Expand All @@ -106,7 +106,7 @@ private async Task<bool> Launch(Profile p)
catch (Exception e)
{
Trace.WriteLine("App launch failed:\n" + e.ToString());
MessageBox.Show("App launch failed:\n" + e.ToString());
Utils.ShowErrorDialog("Launch failed", "An error occured which prevented Zenova from launching Minecraft.");
return false;
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ await downloader.Download(v.UUID, "1", dlPath, (current, total) =>
{
Trace.WriteLine("Download failed:\n" + e.ToString());
if (!(e is TaskCanceledException))
MessageBox.Show("Download failed:\n" + e.ToString());
Utils.ShowErrorDialog("Download failed", string.Format("An error occured while downloading Minecraft {0}. {1}", v.Name, v.Beta ? "Ensure the selected account is the one registered for beta versions in the Xbox Insider app." : ""));
return false;
}
try
Expand Down Expand Up @@ -290,7 +290,7 @@ await downloader.Download(v.UUID, "1", dlPath, (current, total) =>
catch (Exception e)
{
Trace.WriteLine("Extraction failed:\n" + e.ToString());
MessageBox.Show("Extraction failed:\n" + e.ToString());
Utils.ShowErrorDialog("Extraction failed", string.Format("An error occured during extraction to directory:\n{0}", v.GameDirectory));
return false;
}
v.UpdateInstallStatus();
Expand Down
2 changes: 1 addition & 1 deletion ZenovaLauncher/Profiles/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<Profile> LoadProfiles(string profileText)
catch (Exception e)
{
Trace.WriteLine("Profile JSON Deserialize Failed: " + e.ToString());
MessageBox.Show("Profile JSON Deserialize Failed: " + e.ToString());
Utils.ShowErrorDialog("Failed to load profile", "Error occured while parsing profiles.json. Make sure profiles.json is formatted correctly.");
}
return new List<Profile>();
}
Expand Down
49 changes: 49 additions & 0 deletions ZenovaLauncher/Styles/Button.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,53 @@
</Setter.Value>
</Setter>
</Style>

<Style x:Key="LauncherDeleteButtonStyle" TargetType="Button" BasedOn="{StaticResource LauncherAccentButtonStyle}">
<Setter Property="Background" Value="{DynamicResource DeleteButtonBackground}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border
x:Name="Background"
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding ui:ControlHelper.CornerRadius}"
SnapsToDevicePixels="True">
<Border
x:Name="Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
CornerRadius="{TemplateBinding ui:ControlHelper.CornerRadius}">
<ContentPresenter
MaxHeight="18"
x:Name="ContentPresenter"
TextElement.Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Focusable="False"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Background" Property="Background" Value="{DynamicResource DeleteButtonBackgroundPointerOver}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource AccentButtonBorderBrushPointerOver}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource AccentButtonForegroundPointerOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Background" Property="Background" Value="{DynamicResource DeleteButtonBackgroundPressed}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource LauncherButtonBorderBrushPressed}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource AccentButtonForegroundPressed}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Background" Property="Background" Value="{DynamicResource DeleteButtonBackgroundDisabled}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource AccentButtonBorderBrushDisabled}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource AccentButtonForegroundDisabled}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
8 changes: 4 additions & 4 deletions ZenovaLauncher/Styles/ContentDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Setter Property="IsTabStop" Value="False" />
<Setter Property="CornerRadius" Value="{DynamicResource OverlayCornerRadius}" />
<Setter Property="PrimaryButtonStyle" Value="{DynamicResource LauncherDefaultButtonStyle}" />
<Setter Property="SecondaryButtonStyle" Value="{DynamicResource LauncherDefaultButtonStyle}" />
<Setter Property="SecondaryButtonStyle" Value="{DynamicResource LauncherAccentButtonStyle}" />
<Setter Property="CloseButtonStyle" Value="{DynamicResource LauncherDefaultButtonStyle}" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
Expand Down Expand Up @@ -396,13 +396,13 @@
<Setter TargetName="Shdw" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="DefaultButton" Value="Primary">
<Setter TargetName="PrimaryButton" Property="Style" Value="{DynamicResource LauncherAccentButtonStyle}" />
<Setter TargetName="PrimaryButton" Property="Style" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SecondaryButtonStyle}" />
</Trigger>
<Trigger Property="DefaultButton" Value="Secondary">
<Setter TargetName="SecondaryButton" Property="Style" Value="{DynamicResource LauncherAccentButtonStyle}" />
<Setter TargetName="SecondaryButton" Property="Style" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SecondaryButtonStyle}" />
</Trigger>
<Trigger Property="DefaultButton" Value="Close">
<Setter TargetName="CloseButton" Property="Style" Value="{DynamicResource LauncherAccentButtonStyle}" />
<Setter TargetName="CloseButton" Property="Style" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SecondaryButtonStyle}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
13 changes: 13 additions & 0 deletions ZenovaLauncher/Styles/LauncherTheme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<Color x:Key="LauncherChromeMedium2Color">#FF262626</Color>
<Color x:Key="LauncherChromeMediumLowColor">#FF131313</Color>
<Color x:Key="LauncherChromeLowColor">#FF0E0E0E</Color>
<Color x:Key="LauncherDeleteHighColor">#FFE7643C</Color>
<Color x:Key="LauncherDeleteMediumColor">#FFD4441A</Color>
<Color x:Key="LauncherDeleteLowColor">#FFC0300A</Color>
<Color x:Key="LauncherDeleteDisabledColor">#FFC15E49</Color>

<SolidColorBrush x:Key="LauncherControlBackgroundDisabledBrush" Color="{ui:StaticColor LauncherChromeMediumColor}" />
<SolidColorBrush x:Key="LauncherControlForegroundBaseMediumBrush" Color="{ui:StaticColor LauncherBaseMediumColor}" />
Expand All @@ -29,6 +33,10 @@
<SolidColorBrush x:Key="LauncherControlHighlightListLowBrush" Color="{ui:StaticColor LauncherListLowColor}" />
<SolidColorBrush x:Key="LauncherControlAccentHoverBrush" Color="{ui:StaticColor LauncherAccentHoverColor}" />
<SolidColorBrush x:Key="LauncherControlAccentDisabledBrush" Color="{ui:StaticColor LauncherAccentDisabledColor}" />
<SolidColorBrush x:Key="LauncherControlDeleteBrush" Color="{ui:StaticColor LauncherDeleteMediumColor}" />
<SolidColorBrush x:Key="LauncherControlDeleteHoverBrush" Color="{ui:StaticColor LauncherDeleteHighColor}" />
<SolidColorBrush x:Key="LauncherControlDeletePressedBrush" Color="{ui:StaticColor LauncherDeleteLowColor}" />
<SolidColorBrush x:Key="LauncherControlDeleteDisabledBrush" Color="{ui:StaticColor LauncherDeleteDisabledColor}" />
<SolidColorBrush x:Key="LauncherControlTransientBackgroundBrush" Color="{ui:StaticColor LauncherChromeMediumLowColor}" />
<SolidColorBrush x:Key="LauncherControlTransientLowBackgroundBrush" Color="{ui:StaticColor LauncherChromeLowColor}" />

Expand Down Expand Up @@ -92,5 +100,10 @@
<ui:StaticResource x:Key="AccentButtonBackgroundPointerOver" ResourceKey="LauncherControlAccentHoverBrush" />
<ui:StaticResource x:Key="AccentButtonBackgroundDisabled" ResourceKey="LauncherControlAccentDisabledBrush" />

<ui:StaticResource x:Key="DeleteButtonBackground" ResourceKey="LauncherControlDeleteBrush" />
<ui:StaticResource x:Key="DeleteButtonBackgroundPointerOver" ResourceKey="LauncherControlDeleteHoverBrush" />
<ui:StaticResource x:Key="DeleteButtonBackgroundDisabled" ResourceKey="LauncherControlDeleteDisabledBrush" />
<ui:StaticResource x:Key="DeleteButtonBackgroundPressed" ResourceKey="LauncherControlDeletePressedBrush" />

<sys:Boolean x:Key="AutoHideScrollBars">True</sys:Boolean>
</ResourceDictionary>
3 changes: 2 additions & 1 deletion ZenovaLauncher/Utils/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static void LoadPreferences(string dataDir)
catch (Exception e)
{
Trace.WriteLine("Preferences JSON Deserialize Failed: " + e.ToString());
MessageBox.Show("Preferences JSON Deserialize Failed: " + e.ToString());
Utils.ShowErrorDialog("Failed to load Preferences", "An error occured when loading Preferences from preferences.json. Ensure the file is formatted correctly.");
instance = new Preferences();
}
}
else
Expand Down
Loading

0 comments on commit fc5e4e5

Please sign in to comment.