Skip to content

Commit 807542a

Browse files
committed
feat: display person role
1 parent 42a6231 commit 807542a

File tree

9 files changed

+104
-9
lines changed

9 files changed

+104
-9
lines changed

BangumiNet/App.axaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ResourceInclude Source="/Templates/InfoBadge.axaml"/>
1919
<ResourceInclude Source="/Templates/InfoItem.axaml"/>
2020
<ResourceInclude Source="/Templates/BBCode.axaml"/>
21+
<ResourceInclude Source="/Templates/HyperlinkButton.axaml"/>
2122
</ResourceDictionary.MergedDictionaries>
2223
</ResourceDictionary>
2324
<FontFamily x:Key="ContentControlThemeFontFamily">Microsoft YaHei UI, Noto Sans CJK SC, PingFang SC, sans-serif</FontFamily>
@@ -92,11 +93,6 @@
9293
<Setter Property="CornerRadius" Value="5"/>
9394
</Style>
9495
<Style Selector="HyperlinkButton">
95-
<Setter Property="ContentTemplate">
96-
<DataTemplate DataType="sys:String">
97-
<TextBlock Text="{Binding}" TextDecorations="{x:Null}" TextWrapping="Wrap"/>
98-
</DataTemplate>
99-
</Setter>
10096
<Setter Property="Padding" Value="0"/>
10197
<Setter Property="BorderThickness" Value="0"/>
10298
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
@@ -224,6 +220,12 @@
224220
<Style Selector="TextBlock.Sec, .Sec > TextBlock, SelectableTextBlock.Sec, .Sec > SelectableTextBlock">
225221
<Setter Property="Foreground" Value="{DynamicResource TextFillColorSecondaryBrush}"/>
226222
</Style>
223+
<Style Selector="Run.Pri">
224+
<Setter Property="Foreground" Value="{DynamicResource AccentTextFillColorPrimaryBrush}"/>
225+
</Style>
226+
<Style Selector="Run.Sec">
227+
<Setter Property="Foreground" Value="{DynamicResource TextFillColorSecondaryBrush}"/>
228+
</Style>
227229
<Style Selector="ItemsControl:empty">
228230
<Setter Property="IsVisible" Value="False"/>
229231
</Style>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!-- source: https://github.com/amwx/FluentAvalonia/blob/master/src/FluentAvalonia/Styling/ControlThemes/BasicControls/HyperlinkButtonStyles.axaml (modified) -->
2+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
5+
x:CompileBindings="True">
6+
<Design.PreviewWith>
7+
<Border Padding="50">
8+
<StackPanel Spacing="10">
9+
<HyperlinkButton Content="Hello" />
10+
<HyperlinkButton Content="Disabled" IsEnabled="False" />
11+
</StackPanel>
12+
</Border>
13+
</Design.PreviewWith>
14+
15+
16+
<ControlTheme x:Key="{x:Type HyperlinkButton}" TargetType="HyperlinkButton">
17+
<Setter Property="Background" Value="{DynamicResource HyperlinkButtonBackground}" />
18+
<Setter Property="Foreground" Value="{DynamicResource HyperlinkButtonForeground}" />
19+
<Setter Property="BorderBrush" Value="{DynamicResource HyperlinkButtonBorderBrush}" />
20+
<Setter Property="BorderThickness" Value="{DynamicResource HyperlinkButtonBorderThemeThickness}" />
21+
<Setter Property="Padding" Value="{DynamicResource ButtonPadding}" />
22+
<Setter Property="HorizontalAlignment" Value="Left" />
23+
<Setter Property="VerticalAlignment" Value="Center" />
24+
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
25+
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
26+
<Setter Property="Cursor" Value="Hand" />
27+
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
28+
<Setter Property="Template">
29+
<ControlTemplate>
30+
<ContentPresenter Name="ContentPresenter"
31+
Background="{TemplateBinding Background}"
32+
BorderBrush="{TemplateBinding BorderBrush}"
33+
BorderThickness="{TemplateBinding BorderThickness}"
34+
Content="{TemplateBinding Content}"
35+
ContentTemplate="{TemplateBinding ContentTemplate}"
36+
Padding="{TemplateBinding Padding}"
37+
CornerRadius="{TemplateBinding CornerRadius}"
38+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
39+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
40+
Foreground="{TemplateBinding Foreground}">
41+
<ContentPresenter.Styles>
42+
<Style Selector="TextBlock">
43+
<Setter Property="TextWrapping" Value="Wrap" />
44+
</Style>
45+
</ContentPresenter.Styles>
46+
</ContentPresenter>
47+
</ControlTemplate>
48+
</Setter>
49+
50+
<Style Selector="^:pointerover /template/ ContentPresenter#ContentPresenter">
51+
<Setter Property="Foreground" Value="{DynamicResource HyperlinkButtonForegroundPointerOver}" />
52+
<Setter Property="Background" Value="{DynamicResource HyperlinkButtonBackgroundPointerOver}" />
53+
<Setter Property="BorderBrush" Value="{DynamicResource HyperlinkButtonBorderBrushPointerOver}" />
54+
</Style>
55+
<Style Selector="^:pressed /template/ ContentPresenter#ContentPresenter">
56+
<Setter Property="Foreground" Value="{DynamicResource HyperlinkButtonForegroundPressed}" />
57+
<Setter Property="Background" Value="{DynamicResource HyperlinkButtonBackgroundPressed}" />
58+
<Setter Property="BorderBrush" Value="{DynamicResource HyperlinkButtonBorderBrushPressed}" />
59+
</Style>
60+
<Style Selector="^:disabled /template/ ContentPresenter#ContentPresenter">
61+
<Setter Property="Foreground" Value="{DynamicResource HyperlinkButtonForegroundDisabled}" />
62+
<Setter Property="Background" Value="{DynamicResource HyperlinkButtonBackgroundDisabled}" />
63+
<Setter Property="BorderBrush" Value="{DynamicResource HyperlinkButtonBorderBrushDisabled}" />
64+
</Style>
65+
</ControlTheme>
66+
67+
</ResourceDictionary>

BangumiNet/ViewModels/CharacterViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public CharacterViewModel(Api.P1.Models.Character character)
113113
public static CharacterViewModel Init(Api.P1.Models.SubjectCharacter subjectCharacter)
114114
=> new(subjectCharacter.Character!)
115115
{
116-
RelationItems = new() { SubjectViewModels = subjectCharacter.Actors?.Select<Api.P1.Models.SlimPerson, ViewModelBase>(x => new PersonViewModel(x)).ToObservableCollection() },
116+
RelationItems = new() { SubjectViewModels = subjectCharacter.Casts?.Select<Api.P1.Models.CharacterCast, ViewModelBase>(PersonViewModel.Init).ToObservableCollection() },
117117
Order = subjectCharacter.Order,
118118
Relation = ((CharacterRole?)subjectCharacter.Type)?.GetNameCn(),
119119
};

BangumiNet/ViewModels/PersonViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BangumiNet.Api.Interfaces;
55
using BangumiNet.Api.V0.Models;
66
using BangumiNet.Common;
7+
using BangumiNet.Common.Attributes;
78
using BangumiNet.Common.Extras;
89
using BangumiNet.Converters;
910
using BangumiNet.Models;
@@ -159,6 +160,11 @@ public static PersonViewModel Init(Api.P1.Models.SubjectStaff staff)
159160
{
160161
Relation = string.Join(' ', staff.Positions?.Select(x => x.Type?.ToLocalString()) ?? []),
161162
};
163+
public static PersonViewModel Init(Api.P1.Models.CharacterCast cast)
164+
=> new(cast.Person!)
165+
{
166+
Relation = $"{((PersonCharacterRelationType?)cast.Relation)?.GetNameCn()} {cast.Summary}".Trim(),
167+
};
162168

163169
protected override void Activate(CompositeDisposable disposables)
164170
{

BangumiNet/ViewModels/RelatedItemListViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public RelatedItemListViewModel(RelatedItemType type, ItemType parentType, int?
2222
ProceedPageCommand = ReactiveCommand.CreateFromTask(ProceedPageAsync, this.WhenAnyValue(x => x.IsFullyLoaded).Select(x => !x));
2323
}
2424

25+
public void Load(IEnumerable<ViewModelBase> items)
26+
{
27+
SubjectViewModels = [.. items];
28+
Total = Offset = SubjectViewModels.Count;
29+
}
30+
2531
public async Task LoadAsync(CancellationToken cancellationToken = default)
2632
{
2733
if (ParentId is not int id) return;

BangumiNet/ViewModels/SubjectViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ public static SubjectViewModel Init(Api.P1.Models.PersonWork work)
181181
public static SubjectViewModel Init(Api.P1.Models.CharacterSubject characterSubject)
182182
=> new(characterSubject.Subject!)
183183
{
184-
Relation = ((CharacterRole?)characterSubject.Type)?.GetNameCn() + "·" + string.Join('/', characterSubject.Actors?.Select(NameCnCvt.Convert) ?? []),
185-
RelationItems = new() { SubjectViewModels = characterSubject.Actors?.Select<Api.P1.Models.SlimPerson, ViewModelBase>(x => new PersonViewModel(x)).ToObservableCollection() }
184+
Relation = $"{((CharacterRole?)characterSubject.Type)?.GetNameCn()} {string.Join('/', characterSubject.Casts?.Select(x => NameCnCvt.Convert(x.Person)) ?? [])}",
185+
RelationItems = new() { SubjectViewModels = characterSubject.Casts?.Select<Api.P1.Models.CharacterCast, ViewModelBase>(PersonViewModel.Init).ToObservableCollection() }
186186
};
187187
public static SubjectViewModel Init(Api.P1.Models.SubjectRec rec)
188188
=> new(rec.Subject!)

BangumiNet/Views/Cards/PersonCardView.axaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
</MainImage>
1515

1616
<StackPanel Grid.Column="1">
17-
<HyperlinkButton Content="{Binding Converter={StaticResource NameCnCvt},Mode=OneWay}" Classes="Title" Command="{Binding OpenInNewWindowCommand}"/>
17+
<HyperlinkButton Classes="Title" Command="{Binding OpenInNewWindowCommand}">
18+
<TextBlock>
19+
<Run Text="{Binding Converter={StaticResource NameCnCvt},Mode=OneWay}"/>
20+
<Run Text="{Binding Relation}" Classes="Sec"/>
21+
</TextBlock>
22+
</HyperlinkButton>
1823
<WrapPanel Classes="InfoBar">
1924
<InfoItem Tip="收藏" Text="{Binding CollectionTotal}" Icon="Collections"/>
2025
<InfoItem Tip="评论数" Text="{Binding CommentCount}" Icon="Comment"/>

BangumiNet/Views/CharacterView.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
</StackPanel>
6161

6262
<bn:RelatedItemListView DataContext="{Binding SubjectBadgeListViewModel}"/>
63+
<bn:RelatedItemListView DataContext="{Binding PersonBadgeListViewModel}"/>
6364

6465
<Expander Header="吐槽箱" HorizontalAlignment="Stretch" IsExpanded="True">
6566
<bn:CommentListView DataContext="{Binding CommentListViewModel}"/>

BangumiNet/Views/CharacterView.axaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public CharacterView()
2626
.Subscribe(async vm =>
2727
{
2828
vm.IsLoaded = true;
29+
vm.SubjectBadgeListViewModel?.ProceedPageCommand.Subscribe(_ =>
30+
vm.PersonBadgeListViewModel?.Load(
31+
vm.SubjectBadgeListViewModel?.SubjectViewModels?
32+
.OfType<SubjectViewModel>()
33+
.SelectMany(x => x.RelationItems?.SubjectViewModels?.OfType<PersonViewModel>() ?? [])
34+
.DistinctBy(x => x.Id) ?? []
35+
)
36+
);
2937
vm.SubjectBadgeListViewModel?.ProceedPageCommand.Execute().Subscribe();
3038
vm.CommentListViewModel?.LoadPageCommand.Execute().Subscribe();
3139
vm.IndexCardListViewModel?.ProceedPageCommand.Execute().Subscribe();

0 commit comments

Comments
 (0)