Improve mod import notification
Some checks failed
.NET Build / build (push) Has been cancelled

This commit is contained in:
Exter-N 2026-01-27 07:02:29 +01:00 committed by Ottermandias
parent 34234927d8
commit 3143530112
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 _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)
return ("Nothing to extract.", 1.0f, true, true);
return ("No mods to import", "Nothing to extract.", 1.0f, true, true);
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)
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)

View file

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