Improve mod import notification

This commit is contained in:
Exter-N 2026-01-27 07:02:29 +01:00
parent 582a4d61a9
commit 754fad24e0
2 changed files with 33 additions and 16 deletions

View file

@ -18,22 +18,40 @@ public partial class TexToolsImporter
private string _currentOptionName = string.Empty; private string _currentOptionName = string.Empty;
private string _currentFileName = string.Empty; private string _currentFileName = string.Empty;
public (string Text, float Progress, bool Ended, bool Successful) ComputeNotificationData() public (string Title, string Text, float Progress, bool Ended, bool Successful) ComputeNotificationData()
{ {
if (_modPackCount is 0) if (_modPackCount is 0)
return ("Nothing to extract.", 1.0f, true, true); return ("No mods to import", "Nothing to extract.", 1.0f, true, true);
if (_modPackCount == _currentModPackIdx) if (_modPackCount == _currentModPackIdx)
{ {
var success = ExtractedMods.Count(t => t.Error == null); var success = ExtractedMods.Count(t => t.Error == null);
string title;
if (success == ExtractedMods.Count)
{
title = ExtractedMods.Count switch
{
1 => $"Successfully imported {_currentModName}",
_ => "Successfully imported mods",
};
}
else
{
title = ExtractedMods.Count switch
{
1 => $"Failed to import {(string.IsNullOrEmpty(_currentModName) ? ExtractedMods[0].File.Name : _currentModName)}",
_ => "Failed to import some mods",
};
}
return ($"Successfully extracted {success} / {ExtractedMods.Count} files.", 1.0f, true, success == ExtractedMods.Count); return (title, $"Successfully extracted {success} / {ExtractedMods.Count} files.", 1.0f, true, success == ExtractedMods.Count);
} }
if (State is ImporterState.DeduplicatingFiles) if (State is ImporterState.DeduplicatingFiles)
return ($"Deduplicating {_currentModName}...", 1.0f, false, true); return ($"Installing {_currentModName}", "Deduplicating Files...", 1.0f, false, true);
return ($"Extracting {_currentModName}...", _currentNumFiles > 0 ? _currentFileIdx / (float)_currentNumFiles : 0.0f, false, true); return ($"Installing {_currentModName}", $"Extracting File {_currentFileName}...",
_currentNumFiles > 0 ? _currentFileIdx / (float)_currentNumFiles : 0.0f, false, true);
} }
public bool DrawProgressInfo(Vector2 size) public bool DrawProgressInfo(Vector2 size)

View file

@ -19,6 +19,7 @@ public sealed class ImportPopup : Window, INotificationAwareMessage
private static readonly Vector2 OneHalf = Vector2.One / 2; private static readonly Vector2 OneHalf = Vector2.One / 2;
private IActiveNotification? _notification; private IActiveNotification? _notification;
private string _notificationTitle = string.Empty;
private string _notificationMessage = string.Empty; private string _notificationMessage = string.Empty;
private float _notificationProgress = 1.0f; private float _notificationProgress = 1.0f;
private bool _notificationEnded = true; private bool _notificationEnded = true;
@ -74,11 +75,13 @@ public sealed class ImportPopup : Window, INotificationAwareMessage
if (!_modImportManager.IsImporting(out var import)) if (!_modImportManager.IsImporting(out var import))
return; return;
(_notificationMessage, _notificationProgress, _notificationEnded, _notificationSuccessful) = import.ComputeNotificationData(); (_notificationTitle, _notificationMessage, _notificationProgress, _notificationEnded, _notificationSuccessful) =
import.ComputeNotificationData();
_notification?.Title = NotificationTitle; _notification?.Title = _notificationTitle;
_notification?.Type = NotificationType; _notification?.Type = NotificationType;
_notification?.Content = _notificationMessage; _notification?.Content = _notificationMessage;
_notification?.MinimizedText = NotificationMinimizedText;
_notification?.Progress = _notificationProgress; _notification?.Progress = _notificationProgress;
_notification?.UserDismissable = _notificationEnded; _notification?.UserDismissable = _notificationEnded;
@ -137,13 +140,8 @@ public sealed class ImportPopup : Window, INotificationAwareMessage
(true, false) => NotificationType.Error, (true, false) => NotificationType.Error,
}; };
private string NotificationTitle private string NotificationMinimizedText
=> (_notificationEnded, _notificationSuccessful) switch => _notificationEnded ? _notificationMessage : _notificationTitle;
{
(false, _) => "Importing mods",
(true, true) => "Successfully imported mods",
(true, false) => "Failed to import some mods",
};
NotificationType IMessage.NotificationType NotificationType IMessage.NotificationType
=> NotificationType; => NotificationType;
@ -155,7 +153,7 @@ public sealed class ImportPopup : Window, INotificationAwareMessage
=> TimeSpan.MaxValue; => TimeSpan.MaxValue;
string IMessage.NotificationTitle string IMessage.NotificationTitle
=> NotificationTitle; => _notificationTitle;
string IMessage.LogMessage string IMessage.LogMessage
=> string.Empty; => string.Empty;
@ -201,6 +199,7 @@ public sealed class ImportPopup : Window, INotificationAwareMessage
var previousNotification = _notification; var previousNotification = _notification;
_notification = notification; _notification = notification;
previousNotification?.DismissNow(); previousNotification?.DismissNow();
notification.MinimizedText = NotificationMinimizedText;
notification.Progress = _notificationProgress; notification.Progress = _notificationProgress;
notification.UserDismissable = _notificationEnded; notification.UserDismissable = _notificationEnded;
notification.Dismiss += OnNotificationDismissed; notification.Dismiss += OnNotificationDismissed;