Skip to content

Commit

Permalink
在设置中增加最大弹幕长度配置;修改弹幕窗最小宽度为300;在播放窗口右键菜单增加了弹幕窗口入口;给弹幕窗增加了标题名称方便识别;给兼容播放…
Browse files Browse the repository at this point in the history
…窗口增加了打开后是否自动打开弹幕窗口的配置
  • Loading branch information
CHKZL committed Feb 10, 2025
1 parent dd8a0d3 commit bf9d2ae
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 14 deletions.
45 changes: 45 additions & 0 deletions Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,51 @@ public bool _LocalHTTPMode
}
}

private static string MaximumLengthDanmu = "20";
/// <summary>
/// 弹幕最大长度(直播等级20以上可能会是30,用户自己配置)
/// 默认值:20
/// </summary>
public int _MaximumLengthDanmu
{
get
{
return int.Parse(MaximumLengthDanmu);
}
set
{
if (value.ToString() != MaximumLengthDanmu)
{
MaximumLengthDanmu = value.ToString();
OnPropertyChanged();
ModifyConfig(value);
}
}
}


private static string CompatibilityModeDefaultsToOpeningPopupWindow = "false";
/// <summary>
/// 打开兼容模式播放器时,是否默认打开弹幕窗口以方便弹幕查看和发送
/// 默认值:false
/// </summary>
public bool _CompatibilityModeDefaultsToOpeningPopupWindow
{
get
{
return bool.Parse(LocalHTTPMode);
}
set
{
if (value.ToString() != LocalHTTPMode)
{
LocalHTTPMode = value.ToString();
OnPropertyChanged();
ModifyConfig(value);
}
}
}

}
#endregion
}
Expand Down
67 changes: 61 additions & 6 deletions Desktop/Views/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0" Grid.Column="0" FontSize="16" FontTypography="Body" Text="播放窗设置" />
<ui:TextBlock Grid.Row="1" Grid.Column="0" FontSize="12" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" Text="在线播放功能相关设置" />
<ui:TextBlock Grid.Row="0" Grid.Column="0" FontSize="16" FontTypography="Body" Text="弹幕和播放窗设置" />
<ui:TextBlock Grid.Row="1" Grid.Column="0" FontSize="12" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" Text="弹幕窗口以及在线播放功能窗口相关设置" />
</Grid>
</ui:CardExpander.Header>
<StackPanel Margin="24,0,24,0">
Expand Down Expand Up @@ -699,7 +699,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0" Grid.Column="0" FontSize="16" FontTypography="Body" Text="播放窗弹幕" />
<ui:TextBlock Grid.Row="1" Grid.Column="0" FontSize="12" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" Text="针对标准播放窗口的弹幕相关设置内容" />
<ui:TextBlock Grid.Row="1" Grid.Column="0" FontSize="12" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" Text="针对标准播放窗口的弹幕显示相关设置内容" />
</Grid>

</Grid>
Expand Down Expand Up @@ -748,10 +748,65 @@
<Label Grid.Row="0" Margin="10,0,0,0" Content="弹幕速度是否跟随播放大小变化动态变化" />
<CheckBox Name="PlayWindowDanmaSpeed_CheckBox" Grid.Row="1" HorizontalAlignment="Left" Margin="10,0,0,0" Content="跟随" IsChecked="{Binding _PlayDanmaSpeed_Dynamically, Mode=OneWay}"/>
</Grid>




</Grid>
</StackPanel>
</ui:CardExpander>

<ui:CardExpander Icon="{ui:SymbolIcon TextWordCount20}">
<ui:CardExpander.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:TextBlock Grid.Row="0" Grid.Column="0" FontSize="16" FontTypography="Body" Text="弹幕发送设置" />
<ui:TextBlock Grid.Row="1" Grid.Column="0" FontSize="12" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}" Text="发送弹幕功能的设置" />
</Grid>

</Grid>
</ui:CardExpander.Header>
<StackPanel Margin="24,0.5,24,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Margin="10,0,0,0" Content="发送弹幕最大长度(默认为20,请根据自己账号等级修改)" />
<ui:NumberBox Name="MaximumLengthDanmu_InputBox" Grid.Row="1" Width="200" HorizontalAlignment="Left" Margin="10,0,0,0" PlaceholderText="15" Minimum="1" Maximum="100" Text="{Binding _MaximumLengthDanmu, Mode=OneWay}"/>
</Grid>
<Grid Grid.Row="0" Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Margin="10,0,0,0" Content="打开兼容播放器时,是否自动打开单独的弹幕窗口" />
<CheckBox Name="CompatibilityModeDefaultsToOpeningPopupWindow_CheckBox" Grid.Row="1" HorizontalAlignment="Left" Margin="10,0,0,0" Content="跟随" IsChecked="{Binding _CompatibilityModeDefaultsToOpeningPopupWindow, Mode=OneWay}"/>
</Grid>



</Grid>

</StackPanel>
</ui:CardExpander>

Expand Down
13 changes: 13 additions & 0 deletions Desktop/Views/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,19 @@ public async void SaveConfiguration()
}
#endregion

#region 弹幕发送设置
//弹幕最长字数设置
if (Config.Core_RunConfig._MaximumLengthDanmu != int.Parse(MaximumLengthDanmu_InputBox.Text))
{
Config.Core_RunConfig._MaximumLengthDanmu = int.Parse(MaximumLengthDanmu_InputBox.Text);
}
//打开兼容模式播放器时,是否默认打开弹幕窗口
if (Config.Core_RunConfig._CompatibilityModeDefaultsToOpeningPopupWindow != CompatibilityModeDefaultsToOpeningPopupWindow_CheckBox.IsChecked)
{
Config.Core_RunConfig._CompatibilityModeDefaultsToOpeningPopupWindow = (bool)CompatibilityModeDefaultsToOpeningPopupWindow_CheckBox.IsChecked;
}
#endregion

if (IsReboot)
{
MainWindow.SnackbarService.Show("保存成功", "多项配置需要重启后生效,5秒后自动重启DDTV", ControlAppearance.Caution, new SymbolIcon(SymbolRegular.SaveSync20), TimeSpan.FromSeconds(30));
Expand Down
2 changes: 1 addition & 1 deletion Desktop/Views/Windows/DanmaOnlyWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Desktop.Views.Windows"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
Title="DanmaOnlyWindow" Height="500" Width="450" MinWidth="450" Closing="FluentWindow_Closing">
Title="DanmaOnlyWindow" Height="500" Width="450" MinWidth="300" Closing="FluentWindow_Closing">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down
14 changes: 10 additions & 4 deletions Desktop/Views/Windows/DanmaOnlyWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public DanmaOnlyWindow(RoomCardClass Card)
Dispatcher.Invoke(() =>
{
UI_TitleBar.Title = $"{Card.Name}({Card.RoomId})";
this.Title = UI_TitleBar.Title;
DanmaCollection.Add(new DanmaOnly { Message = $"连接[{Card.Name}({Card.RoomId})]直播间弹幕长连" });
});

Expand Down Expand Up @@ -154,8 +155,9 @@ private void DanmaView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
private void Send_Danma_Button_Click(object sender, RoutedEventArgs e)
{
string T = DanmaOnly_DanmaInput.Text;
if (string.IsNullOrEmpty(T) && T.Length > 20)
if (string.IsNullOrEmpty(T) || T.Length > Core.Config.Core_RunConfig._MaximumLengthDanmu)
{
SetNotificatom("弹幕过长或为空", $"输入的弹幕长度为0或者超过最大长度限制,目前限制长度为{Core.Config.Core_RunConfig._MaximumLengthDanmu}");
return;
}
Danmu.SendDanmu(roomCard.RoomId.ToString(), T);
Expand All @@ -164,12 +166,16 @@ private void Send_Danma_Button_Click(object sender, RoutedEventArgs e)

private void DanmaOnly_DanmaInput_TextChanged(object sender, TextChangedEventArgs e)
{
//直接进行一个屏蔽,检查个屁,超过直接报错
//return;
//检测输入框长度,超过长度则截断
System.Windows.Controls.TextBox? textBox = sender as System.Windows.Controls.TextBox;
if (textBox != null && textBox.Text.Length > 20)
int maxlen = Core.Config.Core_RunConfig._MaximumLengthDanmu;
if (textBox != null && textBox.Text.Length > Core.Config.Core_RunConfig._MaximumLengthDanmu)
{
int selectionStart = textBox.SelectionStart;
textBox.Text = textBox.Text.Substring(0, 20);
textBox.SelectionStart = selectionStart > 20 ? 20 : selectionStart;
textBox.Text = textBox.Text.Substring(0, maxlen);
textBox.SelectionStart = selectionStart > maxlen ? maxlen : selectionStart;
}
}

Expand Down
1 change: 1 addition & 0 deletions Desktop/Views/Windows/VlcPlayWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<MenuItem Header="展示弹幕发送框" Icon="{ui:SymbolIcon News20}" Click="MenuItem_Switch_Danma_Send_Click"/>
<MenuItem Header="在浏览器打开直播间" Icon="{ui:SymbolIcon WebAsset20}" Click="MenuItem_OpenLiveUlr_Click"/>
<MenuItem Header="单独打开弹幕查看器" Icon="{ui:SymbolIcon TextWordCount20}" Click="MenuItem_DanmaOnly_Click"/>
<Separator/>

<MenuItem Header="关闭本窗口" Click="ExitWindow_MenuItem_Click" Icon="{ui:SymbolIcon ArrowExit20}"/>
Expand Down
13 changes: 10 additions & 3 deletions Desktop/Views/Windows/VlcPlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private void FluentWindow_KeyDown(object sender, System.Windows.Input.KeyEventAr
private void Send_Danma_Button_Click(object sender, RoutedEventArgs e)
{
string T = DanmaOnly_DanmaInput.Text;
if (string.IsNullOrEmpty(T) && T.Length > 20)
if (string.IsNullOrEmpty(T) && T.Length > Core.Config.Core_RunConfig._MaximumLengthDanmu)
{
return;
}
Expand All @@ -611,7 +611,8 @@ private void Send_Danma_Button_Click(object sender, RoutedEventArgs e)
private void DanmaOnly_DanmaInput_TextChanged(object sender, TextChangedEventArgs e)
{
System.Windows.Controls.TextBox? textBox = sender as System.Windows.Controls.TextBox;
if (textBox != null && textBox.Text.Length > 20)
int maxlen = Core.Config.Core_RunConfig._MaximumLengthDanmu;
if (textBox != null && textBox.Text.Length > Core.Config.Core_RunConfig._MaximumLengthDanmu)
{
int selectionStart = textBox.SelectionStart;
textBox.Text = textBox.Text.Substring(0, 20);
Expand Down Expand Up @@ -715,6 +716,12 @@ private void MenuItem_OpenLiveUlr_Click(object sender, RoutedEventArgs e)
Process.Start(psi);
}


private void MenuItem_DanmaOnly_Click(object sender, RoutedEventArgs e)
{
RoomCardClass roomCardClass = new();
_Room.GetCardForUID(roomCard.UID, ref roomCardClass);
Windows.DanmaOnlyWindow danmaOnlyWindow = new(roomCardClass);
danmaOnlyWindow.Show();
}
}
}
7 changes: 7 additions & 0 deletions Desktop/Views/Windows/WebPlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ public WebPlayWindow(long room_id)
});
});

if (Core.Config.Core_RunConfig._CompatibilityModeDefaultsToOpeningPopupWindow)
{

RoomCardClass roomCardClass = new();
_Room.GetCardForUID(_uid, ref roomCardClass);
Windows.DanmaOnlyWindow danmaOnlyWindow = new(roomCardClass);
danmaOnlyWindow.Show();
}

Log.Info(nameof(WebPlayWindow), $"房间号:[{room_id}],打开播放器");
}
Expand Down

0 comments on commit bf9d2ae

Please sign in to comment.