diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/HutaoStatisticsFactory.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/HutaoStatisticsFactory.cs index f7c0ddaa..397f65ee 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/HutaoStatisticsFactory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/Factory/HutaoStatisticsFactory.cs @@ -19,7 +19,7 @@ internal sealed class HutaoStatisticsFactory private readonly GachaEvent avatarEvent; private readonly GachaEvent avatarEvent2; private readonly GachaEvent weaponEvent; - private readonly GachaEvent chronicledEvent; + private readonly GachaEvent? chronicledEvent; public HutaoStatisticsFactory(in HutaoStatisticsFactoryMetadataContext context) { @@ -32,7 +32,7 @@ internal sealed class HutaoStatisticsFactory avatarEvent = context.GachaEvents.Single(g => g.From < now && g.To > now && g.Type == GachaType.ActivityAvatar); avatarEvent2 = context.GachaEvents.Single(g => g.From < now && g.To > now && g.Type == GachaType.SpecialActivityAvatar); weaponEvent = context.GachaEvents.Single(g => g.From < now && g.To > now && g.Type == GachaType.ActivityWeapon); - chronicledEvent = context.GachaEvents.Single(g => g.From < now && g.To > now && g.Type == GachaType.ActivityCity); + chronicledEvent = context.GachaEvents.SingleOrDefault(g => g.From < now && g.To > now && g.Type == GachaType.ActivityCity); } public HutaoStatistics Create(GachaEventStatistics raw) @@ -42,7 +42,7 @@ internal sealed class HutaoStatisticsFactory AvatarEvent = CreateWishSummary(avatarEvent, raw.AvatarEvent), AvatarEvent2 = CreateWishSummary(avatarEvent2, raw.AvatarEvent2), WeaponEvent = CreateWishSummary(weaponEvent, raw.WeaponEvent), - Chronicled = CreateWishSummary(chronicledEvent, raw.Chronicled), + Chronicled = chronicledEvent is null ? null : CreateWishSummary(chronicledEvent, raw.Chronicled), }; } diff --git a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj index 7f427d0c..04a6a060 100644 --- a/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj +++ b/src/Snap.Hutao/Snap.Hutao/Snap.Hutao.csproj @@ -35,11 +35,11 @@ Debug;Release true true @@ -52,7 +52,7 @@ - + @@ -153,6 +153,7 @@ + @@ -205,7 +206,7 @@ - + @@ -220,7 +221,7 @@ - + @@ -348,6 +349,10 @@ package has not yet been restored --> + + + MSBuild:Compile + @@ -389,37 +394,37 @@ MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile @@ -569,13 +574,13 @@ MSBuild:Compile - + MSBuild:Compile - + MSBuild:Compile @@ -617,7 +622,7 @@ MSBuild:Compile - + diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsPanel.xaml b/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsPanel.xaml new file mode 100644 index 00000000..0a0e99e9 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsPanel.xaml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsPanel.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsPanel.xaml.cs new file mode 100644 index 00000000..4dd8b5c1 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsPanel.xaml.cs @@ -0,0 +1,38 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Microsoft.UI.Xaml; +using Snap.Hutao.Control.Panel; +using Snap.Hutao.ViewModel.GachaLog; + +namespace Snap.Hutao.View.Control; + +[DependencyProperty("Statistics", typeof(HutaoStatistics), default, nameof(OnStatisticsChanged))] +internal sealed partial class HutaoStatisticsPanel : HorizontalEqualPanel +{ + public HutaoStatisticsPanel() + { + InitializeComponent(); + + if (DataContext is HutaoStatistics statistics && statistics.Chronicled is { } chronicled) + { + Children.Add(new HutaoStatisticsCard + { + DataContext = chronicled, + }); + } + } + + private static void OnStatisticsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) + { + HutaoStatisticsPanel panel = (HutaoStatisticsPanel)obj; + + if (args.NewValue is HutaoStatistics { Chronicled: { } chronicled }) + { + panel.Children.Add(new HutaoStatisticsCard + { + DataContext = chronicled, + }); + } + } +} diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/GachaLogPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/GachaLogPage.xaml index 84c93d6c..1147c210 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/GachaLogPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/GachaLogPage.xaml @@ -468,24 +468,15 @@ Margin="16" CornerRadius="{ThemeResource ControlCornerRadius}" IsLoading="{Binding HutaoCloudStatisticsViewModel.IsInitialized, Converter={StaticResource BoolNegationConverter}}"/> - - - - - - - - - - - - + diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/HutaoStatistics.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/HutaoStatistics.cs index 1602ff3f..5824c5a8 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/HutaoStatistics.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/HutaoStatistics.cs @@ -26,5 +26,5 @@ internal sealed class HutaoStatistics /// /// 集录祈愿 /// - public HutaoWishSummary Chronicled { get; set; } = default!; + public HutaoWishSummary? Chronicled { get; set; } } \ No newline at end of file