Skip to content

Commit d5aacaf

Browse files
authored
完善弹幕功能 (Richasy#45)
* 修正缩放 * 添加发送设置 * 添加位置选项 * 添加颜色选择 * 添加弹幕发送逻辑 * 修复弹幕样式 * 更新输入框样式 * 更新直播弹幕发送
1 parent cd6efeb commit d5aacaf

34 files changed

Lines changed: 587 additions & 123 deletions

src/App/App.csproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<Compile Include="Controls\App\TwoLineButton\TwoLineButton.cs" />
2727
<Compile Include="Controls\App\CenterPopup\CenterPopup.cs" />
2828
<Compile Include="Controls\App\CenterPopup\CenterPopup.Properties.cs" />
29+
<Compile Include="Controls\Danmaku\DanmakuSendOptions.xaml.cs">
30+
<DependentUpon>DanmakuSendOptions.xaml</DependentUpon>
31+
</Compile>
2932
<Compile Include="Controls\IRefreshPage.cs" />
3033
<Compile Include="Controls\Message\AtMessageView.xaml.cs">
3134
<DependentUpon>AtMessageView.xaml</DependentUpon>
@@ -113,7 +116,7 @@
113116
<Compile Include="Controls\Danmaku\DanmakuModel.cs" />
114117
<Compile Include="Controls\Danmaku\DanmakuView\DanmakuView.Methods.cs" />
115118
<Compile Include="Controls\Danmaku\DanmakuView\DanmakuView.Properties.cs" />
116-
<Compile Include="Controls\Player\DanmakuDisplayOptions.xaml.cs">
119+
<Compile Include="Controls\Danmaku\DanmakuDisplayOptions.xaml.cs">
117120
<DependentUpon>DanmakuDisplayOptions.xaml</DependentUpon>
118121
</Compile>
119122
<Compile Include="Controls\Player\BiliPlayerTransportControls\BiliPlayerTransportControls.cs" />
@@ -354,6 +357,7 @@
354357
<Compile Include="Properties\AssemblyInfo.cs" />
355358
<Compile Include="Resources\Converter\BoolToVisibilityConverter.cs" />
356359
<Compile Include="Resources\Converter\ColorConverter.cs" />
360+
<Compile Include="Resources\Converter\DanmakuLocationConverter.cs" />
357361
<Compile Include="Resources\Converter\DanmakuStyleConverter.cs" />
358362
<Compile Include="Resources\Converter\DurationConverter.cs" />
359363
<Compile Include="Resources\Converter\EpisodeCoverConverter.cs" />
@@ -495,6 +499,10 @@
495499
<SubType>Designer</SubType>
496500
<Generator>MSBuild:Compile</Generator>
497501
</Page>
502+
<Page Include="Controls\Danmaku\DanmakuSendOptions.xaml">
503+
<SubType>Designer</SubType>
504+
<Generator>MSBuild:Compile</Generator>
505+
</Page>
498506
<Page Include="Controls\Message\AtMessageView.xaml">
499507
<SubType>Designer</SubType>
500508
<Generator>MSBuild:Compile</Generator>
@@ -607,7 +615,7 @@
607615
<SubType>Designer</SubType>
608616
<Generator>MSBuild:Compile</Generator>
609617
</Page>
610-
<Page Include="Controls\Player\DanmakuDisplayOptions.xaml">
618+
<Page Include="Controls\Danmaku\DanmakuDisplayOptions.xaml">
611619
<SubType>Designer</SubType>
612620
<Generator>MSBuild:Compile</Generator>
613621
</Page>

src/App/App.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
<converter:EpisodeCoverConverter x:Key="EpisodeCoverConverter" />
3333
<converter:SeasonCoverConverter x:Key="SeasonCoverConverter" />
3434
<converter:DanmakuStyleConverter x:Key="DanmakuStyleConverter" />
35-
<converter:ColorConverter x:Key="ColorConverter" />
35+
<converter:ColorConverter x:Key="ColorConverter" IsBrush="False" />
3636
<converter:ColorConverter x:Key="BrushConverter" IsBrush="True" />
3737
<converter:FavoriteTypeConverter x:Key="FavoriteTypeConverter" />
38+
<converter:DanmakuLocationConverter x:Key="DanmakuLocationConverter" />
3839
</ResourceDictionary>
3940
</Application.Resources>
4041
</Application>

src/App/Controls/App/TrimTextBlock.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<Button.Flyout>
3737
<Flyout>
3838
<TextBlock
39-
MaxWidth="200"
39+
MaxWidth="320"
4040
LineHeight="24"
4141
Text="{x:Bind Text, Mode=OneWay}"
4242
TextWrapping="Wrap" />

src/App/Controls/Danmaku/DanmakuBox.xaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
<AutoSuggestBox
2929
x:Name="DanmakuInputBox"
3030
Grid.Column="1"
31-
Padding="8,6,8,4"
31+
Height="32"
32+
Padding="8,0"
3233
HorizontalAlignment="Stretch"
3334
PlaceholderText="{loc:LocaleLocator Name=DanmakuPlaceholder}"
3435
QuerySubmitted="OnDanmakuInputBoxSubmittedAsync" />
@@ -46,6 +47,11 @@
4647
BorderThickness="0"
4748
ToolTipService.ToolTip="{loc:LocaleLocator Name=DanmakuSendSettings}">
4849
<icons:RegularFluentIcon Symbol="TextEffects24" />
50+
<Button.Flyout>
51+
<Flyout FlyoutPresenterStyle="{StaticResource ThinPaddingFlyoutPresenterStyle}" Opened="OnSendFlyoutOpened">
52+
<local:DanmakuSendOptions x:Name="SendOptions" />
53+
</Flyout>
54+
</Button.Flyout>
4955
</Button>
5056
<Button
5157
x:Name="DanmakuOptionButton"

src/App/Controls/Danmaku/DanmakuBox.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ private async void OnDanmakuInputBoxSubmittedAsync(AutoSuggestBox sender, AutoSu
3838
}
3939
}
4040
}
41+
42+
private void OnSendFlyoutOpened(object sender, object e)
43+
{
44+
SendOptions.Initialize();
45+
}
4146
}
4247
}

src/App/Controls/Danmaku/DanmakuBuilder.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ public async Task<Grid> CreateStrokeDanmakuAsync()
134134
var container = new Grid();
135135
var device = CanvasDevice.GetSharedDevice();
136136
var format = new CanvasTextFormat() { FontSize = (float)size, WordWrapping = CanvasWordWrapping.NoWrap, FontFamily = _fontFamily };
137+
if (_isBold)
138+
{
139+
format.FontWeight = FontWeights.Bold;
140+
}
141+
137142
var holderBlock = new TextBlock()
138143
{
139144
Text = _model.Text,
@@ -204,7 +209,7 @@ public Grid CreateNoStrokeDanmaku()
204209
}
205210

206211
/// <summary>
207-
/// 创建无边框弹幕.
212+
/// 创建阴影弹幕.
208213
/// </summary>
209214
/// <returns>弹幕容器.</returns>
210215
public Grid CreateShadowDanmaku()
@@ -234,10 +239,10 @@ public Grid CreateShadowDanmaku()
234239
var grid = new Grid();
235240
var dropShadowPanel = new DropShadowPanel()
236241
{
237-
BlurRadius = 6,
238-
ShadowOpacity = 0.6,
239-
OffsetX = 0,
240-
OffsetY = 0,
242+
BlurRadius = 2,
243+
ShadowOpacity = 0.8,
244+
OffsetX = 1,
245+
OffsetY = 1,
241246
Color = _model.Color.R <= 80 ? Colors.White : Colors.Black,
242247
};
243248

File renamed without changes.

src/App/Controls/Player/DanmakuDisplayOptions.xaml.cs renamed to src/App/Controls/Danmaku/DanmakuDisplayOptions.xaml.cs

File renamed without changes.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<UserControl
2+
x:Class="Richasy.Bili.App.Controls.DanmakuSendOptions"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:app="using:Richasy.Bili.Models.Enums.App"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:loc="using:Richasy.Bili.Locator.Uwp"
8+
xmlns:local="using:Richasy.Bili.App.Controls"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
11+
d:DesignHeight="300"
12+
d:DesignWidth="400"
13+
mc:Ignorable="d">
14+
15+
<StackPanel
16+
Width="240"
17+
Padding="16,12"
18+
Spacing="12">
19+
<StackPanel Spacing="4">
20+
<TextBlock Text="{loc:LocaleLocator Name=FontSize}" />
21+
<StackPanel
22+
HorizontalAlignment="Left"
23+
Orientation="Horizontal"
24+
Spacing="16">
25+
<RadioButton
26+
x:Name="StandardItem"
27+
MinWidth="0"
28+
Content="{loc:LocaleLocator Name=Standard}" />
29+
<RadioButton
30+
x:Name="SmallItem"
31+
MinWidth="0"
32+
Content="{loc:LocaleLocator Name=Small}" />
33+
</StackPanel>
34+
</StackPanel>
35+
<ComboBox
36+
x:Name="DanmakuLocationComboBox"
37+
HorizontalAlignment="Stretch"
38+
Header="{loc:LocaleLocator Name=Location}"
39+
ItemsSource="{x:Bind ViewModel.LocationCollection, Mode=OneWay}"
40+
SelectedItem="{x:Bind ViewModel.Location, Mode=TwoWay}">
41+
<ComboBox.ItemTemplate>
42+
<DataTemplate x:DataType="app:DanmakuLocation">
43+
<TextBlock Text="{x:Bind Converter={StaticResource DanmakuLocationConverter}}" />
44+
</DataTemplate>
45+
</ComboBox.ItemTemplate>
46+
</ComboBox>
47+
<StackPanel Spacing="12">
48+
<TextBlock Text="{loc:LocaleLocator Name=Color}" />
49+
<Grid Margin="0,-4,0,0" ColumnSpacing="8">
50+
<Grid.ColumnDefinitions>
51+
<ColumnDefinition Width="*" />
52+
<ColumnDefinition Width="Auto" />
53+
</Grid.ColumnDefinitions>
54+
<TextBox
55+
HorizontalAlignment="Stretch"
56+
VerticalAlignment="Stretch"
57+
IsReadOnly="True"
58+
Text="{x:Bind ViewModel.Color, Mode=OneWay}" />
59+
<Rectangle
60+
Grid.Column="1"
61+
Width="80"
62+
Fill="{x:Bind ViewModel.Color, Mode=OneWay, Converter={StaticResource BrushConverter}}"
63+
RadiusX="4"
64+
RadiusY="4" />
65+
</Grid>
66+
<muxc:ItemsRepeater HorizontalAlignment="Stretch" ItemsSource="{x:Bind ViewModel.ColorCollection}">
67+
<muxc:ItemsRepeater.Layout>
68+
<muxc:UniformGridLayout
69+
ItemsStretch="Fill"
70+
MinColumnSpacing="8"
71+
MinItemHeight="32"
72+
MinItemWidth="32"
73+
MinRowSpacing="8" />
74+
</muxc:ItemsRepeater.Layout>
75+
<muxc:ItemsRepeater.ItemTemplate>
76+
<DataTemplate>
77+
<local:CardPanel
78+
AutomationProperties.Name="{Binding Key}"
79+
Background="{Binding Value, Converter={StaticResource BrushConverter}}"
80+
BorderThickness="0"
81+
Click="OnColorItemClick"
82+
IsEnableShadow="False"
83+
PointerOverBackground="{Binding Value, Converter={StaticResource BrushConverter}}"
84+
PressedBackground="{Binding Value, Converter={StaticResource BrushConverter}}"
85+
ToolTipService.ToolTip="{Binding Key}" />
86+
</DataTemplate>
87+
</muxc:ItemsRepeater.ItemTemplate>
88+
</muxc:ItemsRepeater>
89+
</StackPanel>
90+
</StackPanel>
91+
</UserControl>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) Richasy. All rights reserved.
2+
3+
using Richasy.Bili.Models.App.Other;
4+
using Richasy.Bili.ViewModels.Uwp.Common;
5+
using Windows.UI.Xaml;
6+
using Windows.UI.Xaml.Controls;
7+
8+
namespace Richasy.Bili.App.Controls
9+
{
10+
/// <summary>
11+
/// 弹幕发送设置.
12+
/// </summary>
13+
public sealed partial class DanmakuSendOptions : UserControl
14+
{
15+
/// <summary>
16+
/// <see cref="ViewModel"/>的视图模型.
17+
/// </summary>
18+
public static readonly DependencyProperty ViewModelProperty =
19+
DependencyProperty.Register(nameof(ViewModel), typeof(DanmakuViewModel), typeof(DanmakuSendOptions), new PropertyMetadata(DanmakuViewModel.Instance));
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="DanmakuSendOptions"/> class.
23+
/// </summary>
24+
public DanmakuSendOptions()
25+
{
26+
this.InitializeComponent();
27+
}
28+
29+
/// <summary>
30+
/// 视图模型.
31+
/// </summary>
32+
public DanmakuViewModel ViewModel
33+
{
34+
get { return (DanmakuViewModel)GetValue(ViewModelProperty); }
35+
set { SetValue(ViewModelProperty, value); }
36+
}
37+
38+
/// <summary>
39+
/// 初始化.
40+
/// </summary>
41+
public void Initialize()
42+
{
43+
if (ViewModel.IsStandardSize)
44+
{
45+
StandardItem.IsChecked = true;
46+
SmallItem.IsChecked = false;
47+
}
48+
else
49+
{
50+
StandardItem.IsChecked = false;
51+
SmallItem.IsChecked = true;
52+
}
53+
}
54+
55+
private void OnColorItemClick(object sender, RoutedEventArgs e)
56+
{
57+
var item = (sender as FrameworkElement).DataContext as KeyValue<string>;
58+
ViewModel.Color = item.Value;
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)