code style

This commit is contained in:
Lightczx
2024-05-07 14:23:54 +08:00
parent a57933388d
commit 77067d27d0
5 changed files with 102 additions and 58 deletions

View File

@@ -5,6 +5,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using Snap.Hutao.Core.Abstraction;
using Snap.Hutao.Model.Entity.Abstraction;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.ViewModel.DailyNote;
using Snap.Hutao.ViewModel.User;
using Snap.Hutao.Web.Hoyolab.Takumi.Binding;
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.DailyNote;
@@ -55,50 +56,7 @@ internal sealed class DailyNoteEntry : ObservableObject, IMappingFrom<DailyNoteE
public DailyNote? DailyNote { get; set; }
[NotMapped]
public List<ChapterId> ArchonQuestIds { get; set; } = default!;
[NotMapped]
public int ArchonQuestStatusValue
{
get
{
if (DailyNote is { ArchonQuestProgress.List: { Count: > 0 } list })
{
return ArchonQuestIds.IndexOf(list.Single().Id);
}
return ArchonQuestIds.Count;
}
}
[NotMapped]
public string ArchonQuestStatusFormatted
{
get
{
if (DailyNote is { ArchonQuestProgress.List: { Count: > 0 } list })
{
return list.Single().Status.GetLocalizedDescription();
}
return SH.WebDailyNoteArchonQuestStatusFinished;
}
}
[NotMapped]
public string ArchonQuestChapterFormatted
{
get
{
if (DailyNote is { ArchonQuestProgress.List: { Count: > 0 } list })
{
ArchonQuest quest = list.Single();
return $"{quest.ChapterNum} {quest.ChapterTitle}";
}
return SH.WebDailyNoteArchonQuestChapterFinished;
}
}
public DailyNoteArchonQuestView ArchonQuestView { get; set; } = default!;
/// <summary>
/// 刷新时间

View File

@@ -9,6 +9,7 @@ using Snap.Hutao.Service.Abstraction;
using Snap.Hutao.Service.Metadata;
using Snap.Hutao.Service.Metadata.ContextAbstraction;
using Snap.Hutao.Service.User;
using Snap.Hutao.ViewModel.DailyNote;
using Snap.Hutao.ViewModel.User;
using Snap.Hutao.Web.Hoyolab;
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord;
@@ -94,10 +95,7 @@ internal sealed partial class DailyNoteService : IDailyNoteService, IRecipient<U
entryList.ForEach(entry =>
{
entry.UserGameRole = userService.GetUserGameRoleByUid(entry.Uid);
entry.ArchonQuestIds = context.Chapters
.Where(chapter => chapter.QuestType is Model.Intrinsic.QuestType.AQ)
.Select(chapter => chapter.Id)
.ToList();
entry.ArchonQuestView = DailyNoteArchonQuestView.Create(entry.DailyNote, context.Chapters);
});
entries = entryList.ToObservableCollection();
}

View File

@@ -13,6 +13,7 @@
xmlns:shch="using:Snap.Hutao.Control.Helper"
xmlns:shci="using:Snap.Hutao.Control.Image"
xmlns:shcm="using:Snap.Hutao.Control.Markup"
xmlns:shme="using:Snap.Hutao.Model.Entity"
xmlns:shvc="using:Snap.Hutao.View.Control"
xmlns:shvcp="using:Snap.Hutao.View.Card.Primitive"
xmlns:shvd="using:Snap.Hutao.ViewModel.DailyNote"
@@ -32,11 +33,10 @@
FalseValue="{StaticResource UI_MarkQuest_Events_Start}"
TrueValue="{StaticResource UI_MarkQuest_Events_Proce}"/>
<cwconv:DoubleToObjectConverter
<cwconv:BoolToObjectConverter
x:Name="ArchonQuestIconConverter"
FalseValue="{StaticResource UI_MarkQuest_Main_Proce}"
GreaterThan="0"
TrueValue="{StaticResource UI_MarkQuest_Main_Start}"/>
FalseValue="{StaticResource UI_MarkQuest_Main_Start}"
TrueValue="{StaticResource UI_MarkQuest_Main_Proce}"/>
<DataTemplate x:Key="UserAndUidTemplate">
<Grid Padding="0,0,0,16">
@@ -55,7 +55,7 @@
</Grid>
</DataTemplate>
<DataTemplate x:Key="DailyNoteEntryTemplate">
<DataTemplate x:Key="DailyNoteEntryTemplate" x:DataType="shme:DailyNoteEntry">
<ItemContainer cw:Effects.Shadow="{ThemeResource CompatCardShadow}">
<ItemContainer.Resources>
<SolidColorBrush x:Key="ItemContainerPointerOverBackground" Color="Transparent"/>
@@ -131,28 +131,28 @@
MinHeight="48"
Background="{x:Null}"
CornerRadius="{ThemeResource ControlCornerRadius}"
Maximum="{Binding ArchonQuestIds.Count, Mode=OneWay}"
Maximum="{Binding ArchonQuestView.Ids.Count, Mode=OneWay}"
Opacity="{StaticResource LargeBackgroundProgressBarOpacity}"
Value="{Binding ArchonQuestStatusValue, Mode=OneWay}"/>
Value="{Binding ArchonQuestView.ProgressValue, Mode=OneWay}"/>
<shci:CachedImage
Grid.Column="0"
Margin="4"
VerticalAlignment="Center"
shch:FrameworkElementHelper.SquareLength="32"
Source="{Binding DailyNote.ArchonQuestProgress.List.Count, Converter={StaticResource ArchonQuestIconConverter}}"/>
Source="{Binding DailyNote.IsArchonQuestFinished, Converter={StaticResource ArchonQuestIconConverter}}"/>
<StackPanel
Grid.Column="1"
Margin="8,0,0,0"
VerticalAlignment="Center">
<TextBlock
Style="{StaticResource SubtitleTextBlockStyle}"
Text="{Binding ArchonQuestStatusFormatted, Mode=OneWay}"
Text="{Binding ArchonQuestView.ProgressFormatted, Mode=OneWay}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"/>
<TextBlock
Opacity="0.6"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding ArchonQuestChapterFormatted, Mode=OneWay}"
Text="{Binding ArchonQuestView.ChapterFormatted, Mode=OneWay}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap"/>
</StackPanel>

View File

@@ -0,0 +1,82 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.DailyNote;
using WebDailyNote = Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.DailyNote.DailyNote;
namespace Snap.Hutao.ViewModel.DailyNote;
internal sealed class DailyNoteArchonQuestView
{
private readonly WebDailyNote? dailyNote;
private DailyNoteArchonQuestView(WebDailyNote? dailyNote, List<Chapter> chapters)
{
this.dailyNote = dailyNote;
Ids = chapters
.Where(chapter => chapter.QuestType is QuestType.AQ)
.Select(chapter => chapter.Id)
.ToList();
}
public List<ChapterId> Ids { get; set; } = default!;
public int ProgressValue
{
get
{
if (TryGetFirstArchonQuest(out ArchonQuest? quest))
{
return Ids.IndexOf(quest.Id);
}
return Ids.Count;
}
}
public string ProgressFormatted
{
get
{
if (TryGetFirstArchonQuest(out ArchonQuest? quest))
{
return quest.Status.GetLocalizedDescription();
}
return SH.WebDailyNoteArchonQuestStatusFinished;
}
}
public string ChapterFormatted
{
get
{
if (TryGetFirstArchonQuest(out ArchonQuest? quest))
{
return $"{quest.ChapterNum} {quest.ChapterTitle}";
}
return SH.WebDailyNoteArchonQuestChapterFinished;
}
}
public static DailyNoteArchonQuestView Create(WebDailyNote? dailyNote, List<Chapter> chapters)
{
return new(dailyNote, chapters);
}
private bool TryGetFirstArchonQuest([NotNullWhen(true)] out ArchonQuest? archonQuest)
{
if (dailyNote is { ArchonQuestProgress.List: [{ } target, ..] })
{
archonQuest = target;
return true;
}
archonQuest = default;
return false;
}
}

View File

@@ -132,4 +132,10 @@ internal sealed class DailyNote : DailyNoteCommon
[JsonPropertyName("archon_quest_progress")]
public ArchonQuestProgress ArchonQuestProgress { get; set; } = default!;
[JsonIgnore]
public bool IsArchonQuestFinished
{
get => ArchonQuestProgress.List.Count == 0;
}
}