Skip to content

Commit

Permalink
Fixed an issue with DialogBox not adjusting to Minimum Length, Polish…
Browse files Browse the repository at this point in the history
…ed Success DialogBox
  • Loading branch information
HerpDerpinstine committed Nov 22, 2024
1 parent c05e4a9 commit 919fb64
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion MelonLoader.Installer/Views/DetailsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Name="VersionCombobox" Grid.Row="10" Margin="5" HorizontalAlignment="Center"
SelectedIndex="0" MaxDropDownHeight="150" />
<TextBlock Grid.Row="11" Tapped="SelectZipHandler" HorizontalAlignment="Center" IsEnabled="{Binding EnableSettings}"
Foreground="Gray" TextDecorations="Underline" FontSize="13" Cursor="Hand">Or select a
Foreground="Gray" TextDecorations="Underline" FontSize="13" Cursor="Hand">Or add a
zipped version</TextBlock>
<StackPanel Grid.Row="12" IsEnabled="{Binding !Installing}">
<CheckBox Name="NightlyCheck" IsEnabled="{Binding EnableSettings}"
Expand Down
36 changes: 27 additions & 9 deletions MelonLoader.Installer/Views/DetailsView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void InstallHandler(object sender, RoutedEventArgs args)
_ = MLManager.InstallAsync(Path.GetDirectoryName(Model.Game.Path)!, Model.Game.MLInstalled && !KeepFilesCheck.IsChecked!.Value,
(MLVersion)VersionCombobox.SelectedItem!, Model.Game.IsLinux, Model.Game.Is32Bit,
(progress, newStatus) => Dispatcher.UIThread.Post(() => OnInstallProgress(progress, newStatus)),
(errorMessage) => Dispatcher.UIThread.Post(() => OnInstallFinished(errorMessage)));
(errorMessage) => Dispatcher.UIThread.Post(() => OnOperationFinished(errorMessage)));
}

private void OnInstallProgress(double progress, string? newStatus)
Expand All @@ -153,14 +153,14 @@ private void OnInstallProgress(double progress, string? newStatus)
MelonIcon.Opacity = progress * 0.7 + 0.3;
}

private void OnInstallFinished(string? errorMessage, bool showConfirmation = true)
private void OnOperationFinished(string? errorMessage, bool addedLocalBuild = false)
{
if (Model == null)
return;

var wasReinstall = Model.Game.MLInstalled;
Model.Game.ValidateGame();
var currentMLVersion = Model.Game.MLVersion;

Model.Game.ValidateGame();
Model.Installing = false;

#if LINUX
Expand All @@ -173,8 +173,26 @@ private void OnInstallFinished(string? errorMessage, bool showConfirmation = tru
return;
}

if (showConfirmation)
DialogBox.ShowNotice("Success!", $"Successfully {(Model.Game.MLInstalled ? (wasReinstall ? "reinstalled" : "installed") : "uninstalled")} MelonLoader!");
if (addedLocalBuild)
return;

bool isReinstall = false;
string operationType = Model.Game.MLInstalled ? "Installed" : "Uninstalled";
if (Model.Game.MLInstalled
&& (Model.Game.MLVersion != null)
&& (currentMLVersion != null))
{
var comp = Model.Game.MLVersion.CompareSortOrderTo(currentMLVersion);
isReinstall = comp == 0;
operationType = comp switch
{
> 0 => "Upgraded",
0 => "Reinstalled",
< 0 => "Downgraded"
};
}

DialogBox.ShowNotice("Success!", $"Successfully {operationType}{((!Model.Game.MLInstalled || isReinstall) ? string.Empty : " to")}\nMelonLoader{(Model.Game.MLInstalled ? $" v{Model.Game.MLVersion}" : string.Empty)}");
}

private void OpenDirHandler(object sender, RoutedEventArgs args)
Expand All @@ -197,8 +215,8 @@ private void UninstallHandler(object sender, RoutedEventArgs args)
return;

var error = MLManager.Uninstall(Model.Game.Dir, !KeepFilesCheck.IsChecked!.Value);
OnInstallFinished(error);

OnOperationFinished(error);
}

private async void SelectZipHandler(object sender, TappedEventArgs args)
Expand Down Expand Up @@ -241,7 +259,7 @@ private async void SelectZipHandler(object sender, TappedEventArgs args)
}
}

OnInstallFinished(errorMessage, false);
OnOperationFinished(errorMessage, true);
UpdateVersionList();
})));
}
Expand Down
6 changes: 3 additions & 3 deletions MelonLoader.Installer/Views/DialogBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
Height="100"
SizeToContent="WidthAndHeight"
RenderOptions.BitmapInterpolationMode="HighQuality">
<Grid ColumnDefinitions="auto" RowDefinitions="60, auto, auto">
<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" />
<Grid ColumnDefinitions="200" RowDefinitions="60, auto, auto">
<Image IsVisible="{Binding !IsError}" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Width="60" Height="60" Source="/Assets/icon.ico" />
<Image IsVisible="{Binding IsError}" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Width="60" Height="60" Source="/Assets/error.png" />
<TextBlock Grid.Column="0" Grid.Row="1" Margin="0 10" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="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>
Expand Down

0 comments on commit 919fb64

Please sign in to comment.