From 1e7ff89341448d9c5623e5e16ae016b48f440374 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 1 Jan 2025 13:26:45 +0800 Subject: [PATCH] feat: custom subtitle bg opacity Closes #78 Signed-off-by: bggRGjQaUbCoE --- .../video/detail/widgets/header_control.dart | 36 ++++++++++++++++++- lib/plugin/pl_player/controller.dart | 4 ++- lib/utils/storage.dart | 4 +++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/pages/video/detail/widgets/header_control.dart b/lib/pages/video/detail/widgets/header_control.dart index a3f77430..d37eec5f 100644 --- a/lib/pages/video/detail/widgets/header_control.dart +++ b/lib/pages/video/detail/widgets/header_control.dart @@ -1024,6 +1024,7 @@ class _HeaderControlState extends State { bool massiveMode = widget.controller.massiveMode; int subtitlePaddingH = widget.controller.subtitlePaddingH; int subtitlePaddingB = widget.controller.subtitlePaddingB; + double subtitleBgOpaticy = widget.controller.subtitleBgOpaticy; final DanmakuController? danmakuController = widget.controller.danmakuController; @@ -1457,7 +1458,7 @@ class _HeaderControlState extends State { min: 1.0, max: 3.0, value: danmakuLineHeight, - label: '$danmakuLineHeight', + // label: '$danmakuLineHeight', onChanged: (double val) { danmakuLineHeight = val.toPrecision(1); widget.controller @@ -1615,6 +1616,39 @@ class _HeaderControlState extends State { ), ), ), + Text('字幕背景不透明度 ${(subtitleBgOpaticy * 100).toInt()}%'), + Padding( + padding: const EdgeInsets.only( + top: 0, + bottom: 6, + left: 10, + right: 10, + ), + child: SliderTheme( + data: SliderThemeData( + trackShape: MSliderTrackShape(), + thumbColor: Theme.of(context).colorScheme.primary, + activeTrackColor: Theme.of(context).colorScheme.primary, + trackHeight: 10, + thumbShape: const RoundSliderThumbShape( + enabledThumbRadius: 6.0), + ), + child: Slider( + min: 0, + max: 1, + value: subtitleBgOpaticy, + // label: '${(subtitleBgOpaticy * 100).toInt()}%', + onChanged: (double val) { + subtitleBgOpaticy = val.toPrecision(2); + widget.controller + ..subtitleBgOpaticy = subtitleBgOpaticy + ..updateSubtitleStyle() + ..putDanmakuSettings(); + setState(() {}); + }, + ), + ), + ), ], ), ), diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 886e860c..38dc6cc6 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -256,6 +256,7 @@ class PlPlayerController { late double danmakuLineHeight = GStorage.danmakuLineHeight; late int subtitlePaddingH = GStorage.subtitlePaddingH; late int subtitlePaddingB = GStorage.subtitlePaddingB; + late double subtitleBgOpaticy = GStorage.subtitleBgOpaticy; // 播放顺序相关 PlayRepeat playRepeat = PlayRepeat.pause; @@ -270,7 +271,7 @@ class PlPlayerController { wordSpacing: 0.1, color: Colors.white, fontWeight: FontWeight.normal, - backgroundColor: Color(0xaa000000), + backgroundColor: Colors.black.withOpacity(subtitleBgOpaticy), ); void updateSubtitleStyle([double? value]) { @@ -1322,6 +1323,7 @@ class PlPlayerController { setting.put(SettingBoxKey.danmakuLineHeight, danmakuLineHeight); setting.put(SettingBoxKey.subtitlePaddingH, subtitlePaddingH); setting.put(SettingBoxKey.subtitlePaddingB, subtitlePaddingB); + setting.put(SettingBoxKey.subtitleBgOpaticy, subtitleBgOpaticy); } Future dispose({String type = 'single'}) async { diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 78fb9836..ae6bb732 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -157,6 +157,9 @@ class GStorage { static int get subtitlePaddingB => setting.get(SettingBoxKey.subtitlePaddingB, defaultValue: 24); + static double get subtitleBgOpaticy => + setting.get(SettingBoxKey.subtitleBgOpaticy, defaultValue: 0.67); + static List get dynamicDetailRatio => List.from(setting .get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0])); @@ -362,6 +365,7 @@ class SettingBoxKey { reverseFromFirst = 'reverseFromFirst', subtitlePaddingH = 'subtitlePaddingH', subtitlePaddingB = 'subtitlePaddingB', + subtitleBgOpaticy = 'subtitleBgOpaticy', // Sponsor Block enableSponsorBlock = 'enableSponsorBlock',