From 686d2bd3b8f5f2e17c6bd21078ecb7bd0274e8b4 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Wed, 30 Aug 2023 14:34:44 +0800 Subject: [PATCH] attempt to fix cultivation selection --- .../Automation/ConstructorGenerator.cs | 7 ++++++ .../Helper/FrameworkElementHelper.cs | 4 ++-- .../Snap.Hutao/Control/Media/Bgra32.cs | 1 + .../Snap.Hutao/Control/SegmentedBar.cs | 23 +++++++++++++++++++ .../Cultivation/CultivationDbService.cs | 10 ++++++++ .../CultivationService.Collection.cs | 7 +----- .../Cultivation/ICultivationDbService.cs | 3 +++ .../Service/DailyNote/DailyNoteOptions.cs | 15 +++--------- .../Snap.Hutao/View/Card/DailyNoteCard.xaml | 20 ++++++++-------- .../View/Control/HutaoStatisticsCard.xaml | 5 ++-- .../Snap.Hutao/View/Control/ItemIcon.xaml | 4 ++-- .../Snap.Hutao/View/Control/SkillPivot.xaml | 4 ++-- .../View/Control/StatisticsCard.xaml | 10 ++++---- .../Dialog/GachaLogRefreshProgressDialog.xaml | 4 ++-- .../Snap.Hutao/View/Page/AchievementPage.xaml | 4 ++-- .../Snap.Hutao/View/Page/DailyNotePage.xaml | 18 +++++++-------- 16 files changed, 84 insertions(+), 55 deletions(-) rename src/Snap.Hutao/Snap.Hutao/{View => Control}/Helper/FrameworkElementHelper.cs (89%) create mode 100644 src/Snap.Hutao/Snap.Hutao/Control/SegmentedBar.cs diff --git a/src/Snap.Hutao/Snap.Hutao.SourceGeneration/Automation/ConstructorGenerator.cs b/src/Snap.Hutao/Snap.Hutao.SourceGeneration/Automation/ConstructorGenerator.cs index cc6535c1..0d005188 100644 --- a/src/Snap.Hutao/Snap.Hutao.SourceGeneration/Automation/ConstructorGenerator.cs +++ b/src/Snap.Hutao/Snap.Hutao.SourceGeneration/Automation/ConstructorGenerator.cs @@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Snap.Hutao.SourceGeneration.Primitive; +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -16,6 +17,7 @@ namespace Snap.Hutao.SourceGeneration.Automation; internal sealed class ConstructorGenerator : IIncrementalGenerator { private const string AttributeName = "Snap.Hutao.Core.Annotation.ConstructorGeneratedAttribute"; + private const string CompilerGenerated = "System.Runtime.CompilerServices.CompilerGeneratedAttribute"; //private static readonly DiagnosticDescriptor genericTypeNotSupportedDescriptor = new("SH102", "Generic type is not supported to generate .ctor", "Type [{0}] is not supported", "Quality", DiagnosticSeverity.Error, true); @@ -98,6 +100,11 @@ internal sealed class ConstructorGenerator : IIncrementalGenerator foreach (IFieldSymbol fieldSymbol in fields) { + if (fieldSymbol.Name.AsSpan()[0] is '<') + { + continue; + } + bool shoudSkip = false; foreach (SyntaxReference syntaxReference in fieldSymbol.DeclaringSyntaxReferences) { diff --git a/src/Snap.Hutao/Snap.Hutao/View/Helper/FrameworkElementHelper.cs b/src/Snap.Hutao/Snap.Hutao/Control/Helper/FrameworkElementHelper.cs similarity index 89% rename from src/Snap.Hutao/Snap.Hutao/View/Helper/FrameworkElementHelper.cs rename to src/Snap.Hutao/Snap.Hutao/Control/Helper/FrameworkElementHelper.cs index db88a48e..9b001414 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Helper/FrameworkElementHelper.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/Helper/FrameworkElementHelper.cs @@ -3,10 +3,10 @@ using Microsoft.UI.Xaml; -namespace Snap.Hutao.View.Helper; +namespace Snap.Hutao.Control.Helper; [SuppressMessage("", "SH001")] -[DependencyProperty("SquareLength", typeof(double), 0D, nameof(OnSquareLengthChanged), IsAttached = true, AttachedType = typeof(Microsoft.UI.Xaml.FrameworkElement))] +[DependencyProperty("SquareLength", typeof(double), 0D, nameof(OnSquareLengthChanged), IsAttached = true, AttachedType = typeof(FrameworkElement))] public sealed partial class FrameworkElementHelper { private static void OnSquareLengthChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e) diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Media/Bgra32.cs b/src/Snap.Hutao/Snap.Hutao/Control/Media/Bgra32.cs index eda7c14c..50d2da48 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Media/Bgra32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/Media/Bgra32.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Microsoft.UI.Xaml.Media; using System.Buffers.Binary; using System.Runtime.CompilerServices; using Windows.UI; diff --git a/src/Snap.Hutao/Snap.Hutao/Control/SegmentedBar.cs b/src/Snap.Hutao/Snap.Hutao/Control/SegmentedBar.cs new file mode 100644 index 00000000..6e0c3a17 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Control/SegmentedBar.cs @@ -0,0 +1,23 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Shapes; + +namespace Snap.Hutao.Control; + +[DependencyProperty("Source", typeof(GradientStopCollection))] +internal sealed partial class SegmentedBar : ContentControl +{ + private readonly LinearGradientBrush brush = new(); + + public SegmentedBar() + { + Content = new Rectangle() + { + Fill = brush, + }; + } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationDbService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationDbService.cs index a0016390..ef54f882 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationDbService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationDbService.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using Snap.Hutao.Core.Database; using Snap.Hutao.Model.Entity; using Snap.Hutao.Model.Entity.Database; +using System.Collections.ObjectModel; namespace Snap.Hutao.Service.Cultivation; @@ -153,4 +154,13 @@ internal sealed partial class CultivationDbService : ICultivationDbService .ConfigureAwait(false); } } + + public ObservableCollection GetCultivateProjectCollection() + { + using (IServiceScope scope = serviceProvider.CreateScope()) + { + AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); + return appDbContext.CultivateProjects.AsNoTracking().ToObservableCollection(); + } + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.Collection.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.Collection.cs index 6f79bd5d..4291d8de 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.Collection.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.Collection.cs @@ -29,12 +29,7 @@ internal sealed partial class CultivationService { if (projects is null) { - using (IServiceScope scope = serviceProvider.CreateScope()) - { - AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService(); - projects = appDbContext.CultivateProjects.ToObservableCollection(); - } - + projects = cultivationDbService.GetCultivateProjectCollection(); Current ??= projects.SelectedOrDefault(); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/ICultivationDbService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/ICultivationDbService.cs index 22239f7e..f6ba87b0 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/ICultivationDbService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/ICultivationDbService.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using Snap.Hutao.Model.Entity; +using System.Collections.ObjectModel; namespace Snap.Hutao.Service.Cultivation; @@ -21,6 +22,8 @@ internal interface ICultivationDbService ValueTask> GetCultivateItemListByEntryIdAsync(Guid entryId); + ObservableCollection GetCultivateProjectCollection(); + List GetInventoryItemListByProjectId(Guid projectId); ValueTask> GetInventoryItemListByProjectIdAsync(Guid projectId); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteOptions.cs index c76cc61e..843bec74 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/DailyNote/DailyNoteOptions.cs @@ -8,14 +8,16 @@ using Snap.Hutao.Model.Entity; using Snap.Hutao.Service.Abstraction; using Snap.Hutao.Service.Notification; using System.Globalization; +using System.Runtime.CompilerServices; namespace Snap.Hutao.Service.DailyNote; /// /// 实时便笺选项 /// +[ConstructorGenerated(CallBaseConstructor = true)] [Injection(InjectAs.Singleton)] -internal sealed class DailyNoteOptions : DbStoreOptions +internal sealed partial class DailyNoteOptions : DbStoreOptions { private const int OneMinute = 60; @@ -27,17 +29,6 @@ internal sealed class DailyNoteOptions : DbStoreOptions private bool? isReminderNotification; private bool? isSilentWhenPlayingGame; - /// - /// 构造一个新的实时便笺选项 - /// - /// 服务提供器 - public DailyNoteOptions(IServiceProvider serviceProvider) - : base(serviceProvider) - { - scheduleTaskInterop = serviceProvider.GetRequiredService(); - this.serviceProvider = serviceProvider; - } - /// /// 刷新时间 /// diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/DailyNoteCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/DailyNoteCard.xaml index 001788db..2c1d1eb7 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/DailyNoteCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/DailyNoteCard.xaml @@ -6,10 +6,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mxi="using:Microsoft.Xaml.Interactivity" xmlns:shcb="using:Snap.Hutao.Control.Behavior" + xmlns:shch="using:Snap.Hutao.Control.Helper" xmlns:shci="using:Snap.Hutao.Control.Image" xmlns:shvc="using:Snap.Hutao.View.Control" xmlns:shvd="using:Snap.Hutao.ViewModel.DailyNote" - xmlns:shvh="using:Snap.Hutao.View.Helper" Padding="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" @@ -64,7 +64,7 @@ - + @@ -92,7 +92,7 @@ - + - + @@ -138,7 +138,7 @@ - + - + diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsCard.xaml index a8fa5e8f..c1955f8e 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/HutaoStatisticsCard.xaml @@ -2,15 +2,14 @@ x:Class="Snap.Hutao.View.Control.HutaoStatisticsCard" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:cwucont="using:CommunityToolkit.WinUI.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:shch="using:Snap.Hutao.Control.Helper" xmlns:shci="using:Snap.Hutao.Control.Image" xmlns:shcm="using:Snap.Hutao.Control.Markup" xmlns:shcp="using:Snap.Hutao.Control.Panel" xmlns:shvcont="using:Snap.Hutao.View.Control" xmlns:shvg="using:Snap.Hutao.ViewModel.GachaLog" - xmlns:shvh="using:Snap.Hutao.View.Helper" d:DataContext="{d:DesignInstance shvg:HutaoWishSummary}" mc:Ignorable="d"> @@ -22,7 +21,7 @@ Style="{StaticResource BorderCardStyle}"> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/SkillPivot.xaml b/src/Snap.Hutao/Snap.Hutao/View/Control/SkillPivot.xaml index 54b8166d..837d7558 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Control/SkillPivot.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/SkillPivot.xaml @@ -4,9 +4,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:shch="using:Snap.Hutao.Control.Helper" xmlns:shci="using:Snap.Hutao.Control.Image" xmlns:shmmc="using:Snap.Hutao.Model.Metadata.Converter" - xmlns:shvh="using:Snap.Hutao.View.Helper" mc:Ignorable="d"> @@ -26,7 +26,7 @@ - + @@ -39,7 +39,7 @@ @@ -236,10 +236,10 @@ @@ -15,7 +15,7 @@ diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/AchievementPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/AchievementPage.xaml index e7d52467..ac333887 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/AchievementPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/AchievementPage.xaml @@ -9,11 +9,11 @@ xmlns:mxic="using:Microsoft.Xaml.Interactions.Core" xmlns:shc="using:Snap.Hutao.Control" xmlns:shcb="using:Snap.Hutao.Control.Behavior" + xmlns:shch="using:Snap.Hutao.Control.Helper" xmlns:shci="using:Snap.Hutao.Control.Image" xmlns:shcm="using:Snap.Hutao.Control.Markup" xmlns:shcp="using:Snap.Hutao.Control.Panel" xmlns:shva="using:Snap.Hutao.ViewModel.Achievement" - xmlns:shvh="using:Snap.Hutao.View.Helper" d:DataContext="{d:DesignInstance shva:AchievementViewModel}" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" mc:Ignorable="d"> @@ -236,7 +236,7 @@ Visibility="{Binding IsChecked, Converter={StaticResource BoolToVisibilityConverter}}"/> @@ -255,7 +255,7 @@ Margin="8,0,0,0" HorizontalAlignment="Right" VerticalAlignment="Stretch" - shvh:FrameworkElementHelper.SquareLength="40" + shch:FrameworkElementHelper.SquareLength="40" Background="Transparent" BorderBrush="{x:Null}" BorderThickness="0" @@ -267,7 +267,7 @@