diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementFinishPercent.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementFinishPercent.cs index a590b01d93..0521c43eb9 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementFinishPercent.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementFinishPercent.cs @@ -30,7 +30,7 @@ public static void Update(AchievementViewModel viewModel) throw HutaoException.InvalidCast, List>("AchievementViewModel.Achievements.SourceCollection"); } - Dictionary counter = achievementGoals.ToDictionary(x => x.Id, AchievementGoalStatistics.From); + Dictionary counter = achievementGoals.SourceCollection.ToDictionary(x => x.Id, AchievementGoalStatistics.From); foreach (ref readonly AchievementView achievementView in CollectionsMarshal.AsSpan(list)) { diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementView.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementView.cs index d35b851e9f..c4211eb51a 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementView.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementView.cs @@ -43,6 +43,8 @@ public AchievementView(Model.Entity.Achievement entity, Model.Metadata.Achieveme /// public Model.Metadata.Achievement.Achievement Inner { get; } + public uint Order => Inner.Order; + /// /// 是否选中 /// diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementViewModel.cs index 4373e60095..de4f3cf2c1 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Achievement/AchievementViewModel.cs @@ -28,13 +28,17 @@ namespace Snap.Hutao.ViewModel.Achievement; [Injection(InjectAs.Scoped)] internal sealed partial class AchievementViewModel : Abstraction.ViewModel, INavigationRecipient { - private readonly SortDescription uncompletedItemsFirstSortDescription = new(nameof(AchievementView.IsChecked), SortDirection.Ascending); - private readonly SortDescription completionTimeSortDescription = new(nameof(AchievementView.Time), SortDirection.Descending); + private readonly SortDescription achievementUncompletedItemsFirstSortDescription = new(nameof(AchievementView.IsChecked), SortDirection.Ascending); + private readonly SortDescription achievementCompletionTimeSortDescription = new(nameof(AchievementView.Time), SortDirection.Descending); + private readonly SortDescription achievementGoalUncompletedItemsFirstSortDescription = new(nameof(AchievementGoalView.FinishPercent), SortDirection.Ascending); + + private readonly SortDescription achievementDefaultSortDescription = new(nameof(AchievementView.Order), SortDirection.Ascending); + private readonly SortDescription achievementGoalDefaultSortDescription = new(nameof(AchievementGoalView.Order), SortDirection.Ascending); private readonly AchievementViewModelDependencies dependencies; private AdvancedCollectionView? achievements; - private List? achievementGoals; + private AdvancedCollectionView? achievementGoals; private AchievementGoalView? selectedAchievementGoal; private ObservableCollection? archives; private EntityAchievementArchive? selectedArchive; @@ -67,7 +71,7 @@ public AdvancedCollectionView? Achievements set => SetProperty(ref achievements, value); } - public List? AchievementGoals + public AdvancedCollectionView? AchievementGoals { get => achievementGoals; set => SetProperty(ref achievementGoals, value); @@ -141,7 +145,7 @@ protected override async ValueTask InitializeUIAsync() await dependencies.TaskContext.SwitchToMainThreadAsync(); - AchievementGoals = sortedGoals; + AchievementGoals = new(sortedGoals, true); Archives = archives; SelectedArchive = dependencies.AchievementService.CurrentArchive; return true; @@ -299,20 +303,23 @@ private bool TryGetAchievements(EntityAchievementArchive archive, AchievementSer [Command("SortUncompletedSwitchCommand")] private void UpdateAchievementsSort() { - if (Achievements is null) + if (Achievements is null || AchievementGoals is null) { return; } + Achievements.SortDescriptions.Clear(); + AchievementGoals.SortDescriptions.Clear(); + if (IsUncompletedItemsFirst) { - Achievements.SortDescriptions.Add(uncompletedItemsFirstSortDescription); - Achievements.SortDescriptions.Add(completionTimeSortDescription); - } - else - { - Achievements.SortDescriptions.Clear(); + Achievements.SortDescriptions.Add(achievementUncompletedItemsFirstSortDescription); + Achievements.SortDescriptions.Add(achievementCompletionTimeSortDescription); + AchievementGoals.SortDescriptions.Add(achievementGoalUncompletedItemsFirstSortDescription); } + + Achievements.SortDescriptions.Add(achievementDefaultSortDescription); + AchievementGoals.SortDescriptions.Add(achievementGoalDefaultSortDescription); } private void UpdateAchievementsFilterByGoal(AchievementGoalView? goal)