Skip to content

Commit

Permalink
Merge pull request #23 from slxdy/Cleanup
Browse files Browse the repository at this point in the history
Final Cleanup
  • Loading branch information
HerpDerpinstine authored Nov 16, 2024
2 parents df4d6ac + cbdb698 commit e73bab8
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 77 deletions.
16 changes: 1 addition & 15 deletions MelonLoader.Installer/ViewModels/DetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class DetailsViewModel(GameModel game) : ViewModelBase
{
private bool _installing;
private bool _confirmation;
private bool _offline;

public GameModel Game => game;
Expand All @@ -15,33 +14,20 @@ public bool Installing
{
_installing = value;
OnPropertyChanged();
OnPropertyChanged(nameof(CanInstall));
OnPropertyChanged(nameof(EnableSettings));
}
}

public bool Confirmation
{
get => _confirmation;
set
{
_confirmation = value;
OnPropertyChanged();
OnPropertyChanged(nameof(CanInstall));
}
}

public bool Offline
{
get => _offline;
set
{
_offline = value;
OnPropertyChanged(nameof(Confirmation));
OnPropertyChanged();
OnPropertyChanged(nameof(EnableSettings));
}
}

public bool CanInstall => !Installing && !Confirmation;
public bool EnableSettings => !Offline && !Installing;
}
10 changes: 10 additions & 0 deletions MelonLoader.Installer/ViewModels/DialogBoxModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MelonLoader.Installer.ViewModels;

public class DialogBoxModel : ViewModelBase
{
public required string Message { get; init; }
public string ConfirmText { get; init; } = "YES";
public string CancelText { get; init; } = "NO";
public bool IsError { get; init; }
public bool IsConfirmation { get; init; }
}
4 changes: 2 additions & 2 deletions MelonLoader.Installer/Views/DetailsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
IsVisible="{Binding Game.MLInstalled}" IsChecked="True">Keep mods and settings</CheckBox>
</StackPanel>
<Grid Grid.Row="13" Margin="10" Width="300" HorizontalAlignment="Center">
<Grid IsVisible="{Binding CanInstall}" ColumnDefinitions="*, auto">
<Grid IsVisible="{Binding !Installing}" ColumnDefinitions="*, auto">
<Button Click="InstallHandler" IsEnabled="{Binding !Offline}" Name="InstallButton" Grid.Column="0"
HorizontalAlignment="Stretch" Background="#383" Height="40"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
Expand All @@ -50,7 +50,7 @@
Background="#833" Height="40" HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" FontSize="18">Uninstall</Button>
</Grid>
<Grid IsVisible="{Binding !CanInstall}">
<Grid IsVisible="{Binding Installing}">
<ProgressBar Name="Progress" Height="40" Background="#4383" Foreground="#383" />
<TextBlock Name="InstallStatus" HorizontalAlignment="Center"
VerticalAlignment="Center" Opacity="0.7" FontSize="14" />
Expand Down
8 changes: 3 additions & 5 deletions MelonLoader.Installer/Views/DetailsView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ public void UpdateVersionInfo()
if (Model == null || VersionCombobox.SelectedItem == null)
return;

Model.Confirmation = false;

MelonIcon.Opacity = Model.Game.MLInstalled ? 1 : 0.3;

if (Model.Game.MLVersion == null)
Expand Down Expand Up @@ -139,7 +137,7 @@ private void OnInstallFinished(string? errorMessage)
if (Model == null)
return;

bool wasReinstall = Model.Game.MLInstalled;
var wasReinstall = Model.Game.MLInstalled;
Model.Game.ValidateGame();

Model.Installing = false;
Expand All @@ -152,7 +150,7 @@ private void OnInstallFinished(string? errorMessage)
return;
}

DialogBox.ShowNotice("SUCCESS!", $"{(wasReinstall ? "Reinstall" : "Install")} was Successful!");
DialogBox.ShowNotice("Success!", $"{(wasReinstall ? "Reinstall" : "Install")} was Successful!");
}

private void OpenDirHandler(object sender, RoutedEventArgs args)
Expand Down Expand Up @@ -182,7 +180,7 @@ private void UninstallHandler(object sender, RoutedEventArgs args)
}

Model.Game.ValidateGame();
DialogBox.ShowNotice("SUCCESS!", "Uninstall was Successful!");
DialogBox.ShowNotice("Success!", "Uninstall was Successful!");
}

private async void SelectZipHandler(object sender, TappedEventArgs args)
Expand Down
17 changes: 10 additions & 7 deletions MelonLoader.Installer/Views/DialogBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
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"
xmlns:vm="clr-namespace:MelonLoader.Installer.ViewModels"
mc:Ignorable="d"
x:Class="MelonLoader.Installer.Views.DialogBox"
x:DataType="vm:DialogBoxModel"
Title="NOTICE"
Icon="/Assets/icon.ico"
WindowStartupLocation="CenterScreen"
Expand All @@ -14,14 +16,15 @@
SizeToContent="WidthAndHeight"
RenderOptions.BitmapInterpolationMode="HighQuality">
<Grid ColumnDefinitions="auto" RowDefinitions="60, 30, auto">
<Image Name="HeaderImage" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Source="/Assets/icon.ico" />
<TextBlock Name="Message" Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="15" Text="The quick brown fox jumps over the lazy dog" />
<Grid Name="NoticeGrid" Grid.Column="0" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Center" ColumnDefinitions="60, 60, 60" RowDefinitions="60">
<Button Name="OkButton" Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Click="ConfirmHandler">OK</Button>
<Image IsVisible="{Binding !IsError}" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Source="/Assets/icon.ico" />
<Image IsVisible="{Binding IsError}" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Source="/Assets/error.png" />
<TextBlock Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="15" Text="{Binding Message}" />
<Grid IsVisible="{Binding !IsConfirmation}" Grid.Column="0" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Center" ColumnDefinitions="60, 60, 60" RowDefinitions="60">
<Button Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Click="ConfirmHandler">OK</Button>
</Grid>
<Grid Name="ConfirmationGrid" Grid.Column="0" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Center" ColumnDefinitions="60, 60" RowDefinitions="60" IsVisible="false">
<Button Name="CancelButton" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Click="CancelHandler">NO</Button>
<Button Name="ConfirmButton" Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Click="ConfirmHandler">YES</Button>
<Grid IsVisible="{Binding IsConfirmation}" Grid.Column="0" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Center" ColumnDefinitions="60, 60" RowDefinitions="60">
<Button Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Click="CancelHandler" Content="{Binding CancelText}"/>
<Button Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Click="ConfirmHandler" Content="{Binding ConfirmText}"/>
</Grid>
</Grid>
</Window>
95 changes: 48 additions & 47 deletions MelonLoader.Installer/Views/DialogBox.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using MelonLoader.Installer.ViewModels;

namespace MelonLoader.Installer.Views;

public partial class DialogBox : Window
{
public delegate void dCallback(object sender, RoutedEventArgs args);
private dCallback? OnConfirm;
private dCallback? OnCancel;

private static Bitmap? ErrorIcon = new Bitmap(AssetLoader.Open(new("avares://" + typeof(GameControl).Assembly.GetName().Name + "/Assets/error.png")));
private Action? OnConfirm;
private Action? OnCancel;

public DialogBox()
=> InitializeComponent();

public static void ShowError(string message)
{
DialogBox dialogBox = new DialogBox();
dialogBox.Title = "ERROR";
dialogBox.Message.Text = message;
dialogBox.HeaderImage.Source = ErrorIcon;
dialogBox.Open();
new DialogBox
{
Title = "Error",
DataContext = new DialogBoxModel
{
Message = message,
IsError = true
}
}.Open();
}

public static void ShowNotice(string message)
=> ShowNotice("NOTICE", message);
=> ShowNotice("Notice", message);

public static void ShowNotice(string title, string message)
{
DialogBox dialogBox = new DialogBox();
dialogBox.Title = title;
dialogBox.Message.Text = message;
dialogBox.Open();
new DialogBox
{
Title = title,
DataContext = new DialogBoxModel
{
Message = message
}
}.Open();
}

public static void ShowConfirmation(
string message,
dCallback? onConfirm = null,
dCallback? onCancel = null,
string message,
Action? onConfirm = null,
Action? onCancel = null,
string confirmText = "YES",
string cancelText = "NO")
=> ShowConfirmation("CONFIRMATION",
message,
onConfirm,
onCancel,
confirmText,
=> ShowConfirmation("CONFIRMATION",
message,
onConfirm,
onCancel,
confirmText,
cancelText);

public static void ShowConfirmation(
string title,
string message,
dCallback? onConfirm = null,
dCallback? onCancel = null,
string message,
Action? onConfirm = null,
Action? onCancel = null,
string confirmText = "YES",
string cancelText = "NO")
{
DialogBox dialogBox = new DialogBox();

dialogBox.Title = title;
dialogBox.Message.Text = message;

dialogBox.ConfirmButton.Content = confirmText;

dialogBox.CancelButton.IsVisible = true;
dialogBox.CancelButton.Content = cancelText;

dialogBox.OnConfirm = onConfirm;
dialogBox.OnCancel = onCancel;

dialogBox.NoticeGrid.IsVisible = false;
dialogBox.ConfirmationGrid.IsVisible = true;

dialogBox.Open();
new DialogBox
{
Title = title,
DataContext = new DialogBoxModel
{
Message = message,
IsConfirmation = true,
ConfirmText = confirmText,
CancelText = cancelText
},
OnConfirm = onConfirm,
OnCancel = onCancel
}.Open();
}

private void Open()
Expand All @@ -96,12 +97,12 @@ private void BringToFront()
private void ConfirmHandler(object sender, RoutedEventArgs args)
{
Close();
OnConfirm?.Invoke(sender, args);
OnConfirm?.Invoke();
}

private void CancelHandler(object sender, RoutedEventArgs args)
{
Close();
OnCancel?.Invoke(sender, args);
OnCancel?.Invoke();
}
}
2 changes: 1 addition & 1 deletion MelonLoader.Installer/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void OnActivation(object? sender, EventArgs e)
{
if (sender is not Window window)
return;

window.Topmost = true;
window.Topmost = false;
Program.GrabAttention();
Expand Down

0 comments on commit e73bab8

Please sign in to comment.