Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl achievement features #1972

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Model/Intrinsic/QuestType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal enum QuestType : uint
DQ,

/// <summary>
/// Indescribable Quest 不可描述的任务?
/// Interval Quest 间隔任务?
/// </summary>
IQ,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ internal sealed class Achievement
/// 版本
/// </summary>
public string Version { get; set; } = default!;

/// <summary>
/// 是否为委托成就
/// </summary>
public bool IsDailyQuest { get; set; }
}
3 changes: 3 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,9 @@
<data name="ViewPageAchievementExportLabel" xml:space="preserve">
<value>导出</value>
</data>
<data name="ViewPageAchievementFilterDailyQuestItems" xml:space="preserve">
<value>仅委托成就</value>
</data>
<data name="ViewPageAchievementImportFromClipboard" xml:space="preserve">
<value>从剪贴板导入</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@
Icon="{shuxm:FontIcon Glyph=&#xE8CB;}"
IsChecked="{Binding IsUncompletedItemsFirst, Mode=TwoWay}"
Label="{shuxm:ResourceString Name=ViewPageAchievementSortIncompletedItemsFirst}"/>
<AppBarToggleButton
Command="{Binding FilterDailyQuestSwitchCommand}"
Icon="{shuxm:FontIcon Glyph=&#xE8ED;}"
IsChecked="{Binding FilterDailyQuestItems, Mode=TwoWay}"
Label="{shuxm:ResourceString Name=ViewPageAchievementFilterDailyQuestItems}"/>
</CommandBar>
</Grid>
</Border>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ internal sealed partial class AchievementViewModel : Abstraction.ViewModel, INav
private IAdvancedDbCollectionView<EntityArchive>? archives;

private bool isUncompletedItemsFirst = true;
private bool filterDailyQuestItems;
private string searchText = string.Empty;
private string? finishDescription;

Expand Down Expand Up @@ -99,6 +100,12 @@ public bool IsUncompletedItemsFirst
set => SetProperty(ref isUncompletedItemsFirst, value);
}

public bool FilterDailyQuestItems
{
get => filterDailyQuestItems;
set => SetProperty(ref filterDailyQuestItems, value);
}

public string? FinishDescription
{
get => finishDescription;
Expand Down Expand Up @@ -374,28 +381,31 @@ private void UpdateAchievementsFilterByGoal(AchievementGoalView? goal)
[Command("SearchAchievementCommand")]
private void UpdateAchievementsFilterBySearch(string? search)
{
if (Achievements is null)
if (Achievements is null || AchievementGoals is null)
{
return;
}

AchievementGoals?.MoveCurrentTo(default);
AchievementGoals.MoveCurrentTo(default);

if (string.IsNullOrEmpty(search))
{
Achievements.Filter = default!;
AchievementGoals.Filter = default!;
return;
}

if (uint.TryParse(search, out uint achievementId))
{
Achievements.Filter = view => view.Inner.Id == achievementId;
AchievementGoals.Filter = goal => Achievements.View.FirstOrDefault(view => view.Inner.Goal == goal.Id) is not null;
return;
}

if (VersionRegex().IsMatch(search))
{
Achievements.Filter = view => view.Inner.Version == search;
AchievementGoals.Filter = goal => Achievements.View.FirstOrDefault(view => view.Inner.Goal == goal.Id) is not null;
return;
}

Expand All @@ -404,6 +414,7 @@ private void UpdateAchievementsFilterBySearch(string? search)
return view.Inner.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase)
|| view.Inner.Description.Contains(search, StringComparison.CurrentCultureIgnoreCase);
};
AchievementGoals.Filter = goal => Achievements.View.FirstOrDefault(view => view.Inner.Goal == goal.Id) is not null;
}

[Command("SaveAchievementCommand")]
Expand All @@ -417,4 +428,24 @@ private void SaveAchievement(AchievementView? achievement)
scopeContext.AchievementService.SaveAchievement(achievement);
AchievementFinishPercent.Update(this);
}

[Command("FilterDailyQuestSwitchCommand")]
private void UpdateAchievementsFilterByDailyQuest()
{
if (Achievements is null || AchievementGoals is null)
{
return;
}

if (FilterDailyQuestItems)
{
Achievements.Filter = (AchievementView view) => view.Inner.IsDailyQuest;
AchievementGoals.Filter = goal => Achievements.View.FirstOrDefault(view => view.Inner.Goal == goal.Id) is not null;
}
else
{
Achievements.Filter = default!;
AchievementGoals.Filter = default!;
}
}
}
Loading