diff --git a/lib/pages/danmaku/view.dart b/lib/pages/danmaku/view.dart index 56b00d14..e2125217 100644 --- a/lib/pages/danmaku/view.dart +++ b/lib/pages/danmaku/view.dart @@ -140,7 +140,7 @@ class _PlDanmakuState extends State { opacity: playerController.isOpenDanmu.value ? 1 : 0, duration: const Duration(milliseconds: 100), child: DanmakuScreen( - createdController: (DanmakuController e) async { + createdController: (DanmakuController e) { playerController.danmakuController = _controller = e; }, option: DanmakuOption( @@ -154,6 +154,7 @@ class _PlDanmakuState extends State { duration: playerController.danmakuDurationVal ~/ playerController.playbackSpeed, strokeWidth: playerController.strokeWidth, + lineHeight: playerController.danmakuLineHeight, ), ), ), diff --git a/lib/pages/live_room/view.dart b/lib/pages/live_room/view.dart index 9e22616d..6fb1e25d 100644 --- a/lib/pages/live_room/view.dart +++ b/lib/pages/live_room/view.dart @@ -143,7 +143,7 @@ class _LiveRoomPageState extends State opacity: plPlayerController.isOpenDanmu.value ? 1 : 0, duration: const Duration(milliseconds: 100), child: DanmakuScreen( - createdController: (DanmakuController e) async { + createdController: (DanmakuController e) { plPlayerController.danmakuController = _liveRoomController.controller = e; }, @@ -159,6 +159,7 @@ class _LiveRoomPageState extends State duration: plPlayerController.danmakuDurationVal ~/ plPlayerController.playbackSpeed, strokeWidth: plPlayerController.strokeWidth, + lineHeight: plPlayerController.danmakuLineHeight, ), ), ), diff --git a/lib/pages/setting/extra_setting.dart b/lib/pages/setting/extra_setting.dart index ddb97436..c237af89 100644 --- a/lib/pages/setting/extra_setting.dart +++ b/lib/pages/setting/extra_setting.dart @@ -33,6 +33,7 @@ class _ExtraSettingState extends State { late dynamic enableSystemProxy; late String defaultSystemProxyHost; late String defaultSystemProxyPort; + late double danmakuLineHeight = GStorage.danmakuLineHeight; bool userLogin = false; Box get setting => GStorage.setting; @@ -336,6 +337,64 @@ class _ExtraSettingState extends State { ); }, ), + ListTile( + title: Text('弹幕行高', style: titleStyle), + subtitle: Text('默认1.6', style: subTitleStyle), + leading: const Icon(Icons.subtitles_outlined), + trailing: Text( + danmakuLineHeight.toString(), + style: Theme.of(context).textTheme.titleSmall, + ), + onTap: () { + String danmakuLineHeight = this.danmakuLineHeight.toString(); + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text('弹幕行高', style: TextStyle(fontSize: 18)), + content: TextFormField( + autofocus: true, + initialValue: danmakuLineHeight, + keyboardType: + TextInputType.numberWithOptions(decimal: true), + onChanged: (value) { + danmakuLineHeight = value; + }, + inputFormatters: [ + FilteringTextInputFormatter.allow(RegExp(r'[\d\.]+')), + ], + ), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '取消', + style: TextStyle( + color: Theme.of(context).colorScheme.outline, + ), + ), + ), + TextButton( + onPressed: () async { + Get.back(); + this.danmakuLineHeight = max( + 1.0, + double.tryParse(danmakuLineHeight) ?? 1.6, + ); + await setting.put( + SettingBoxKey.danmakuLineHeight, + this.danmakuLineHeight, + ); + setState(() {}); + }, + child: Text('确定'), + ) + ], + ); + }, + ); + }, + ), Obx( () => ListTile( enableFeedback: true, diff --git a/lib/pages/video/detail/widgets/header_control.dart b/lib/pages/video/detail/widgets/header_control.dart index 06c64158..ccd43ad1 100644 --- a/lib/pages/video/detail/widgets/header_control.dart +++ b/lib/pages/video/detail/widgets/header_control.dart @@ -1056,6 +1056,7 @@ class _HeaderControlState extends State { double fontSizeFSVal = widget.controller!.fontSizeFSVal; double subtitleFontScale = widget.controller!.subtitleFontScale.value; double subtitleFontScaleFS = widget.controller!.subtitleFontScaleFS.value; + double danmakuLineHeight = widget.controller!.danmakuLineHeight; // 弹幕速度 double danmakuDurationVal = widget.controller!.danmakuDurationVal; // 弹幕描边 @@ -1467,6 +1468,46 @@ class _HeaderControlState extends State { ), ), ), + Text('弹幕行高 $danmakuLineHeight'), + 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: 1.0, + max: 3.0, + value: danmakuLineHeight, + label: '$danmakuLineHeight', + onChanged: (double val) { + danmakuLineHeight = + double.parse(val.toStringAsFixed(1)); + widget.controller!.danmakuLineHeight = + danmakuLineHeight; + widget.controller?.putDanmakuSettings(); + setState(() {}); + try { + danmakuController.updateOption( + danmakuController.option.copyWith( + lineHeight: danmakuLineHeight, + ), + ); + } catch (_) {} + }, + ), + ), + ), Text( '字幕字体大小 ${(subtitleFontScale * 100).toStringAsFixed(1)}%'), Padding( diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index ca9a2eb6..75352f49 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -255,6 +255,7 @@ class PlPlayerController { late bool enableLongShowControl; RxDouble subtitleFontScale = (1.0).obs; RxDouble subtitleFontScaleFS = (1.5).obs; + late double danmakuLineHeight = GStorage.danmakuLineHeight; // 播放顺序相关 PlayRepeat playRepeat = PlayRepeat.pause; @@ -1281,6 +1282,7 @@ class PlPlayerController { setting.put(SettingBoxKey.danmakuDuration, danmakuDurationVal); setting.put(SettingBoxKey.strokeWidth, strokeWidth); setting.put(SettingBoxKey.fontWeight, fontWeight); + setting.put(SettingBoxKey.danmakuLineHeight, danmakuLineHeight); } Future dispose({String type = 'single'}) async { diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 8e90e059..20572e6a 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -142,6 +142,9 @@ class GStorage { static int get defaultPicQa => setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); + static double get danmakuLineHeight => + setting.get(SettingBoxKey.danmakuLineHeight, defaultValue: 1.6); + static List get dynamicDetailRatio => setting.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]); @@ -363,6 +366,7 @@ class SettingBoxKey { danmakuFontScaleFS = 'danmakuFontScaleFS', danmakuDuration = 'danmakuDuration', danmakuMassiveMode = 'danmakuMassiveMode', + danmakuLineHeight = 'danmakuLineHeight', strokeWidth = 'strokeWidth', fontWeight = 'fontWeight', memberTab = 'memberTab', diff --git a/pubspec.lock b/pubspec.lock index aba0ffae..d265f052 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -252,7 +252,7 @@ packages: description: path: "." ref: main - resolved-ref: cfa1b7cc7fbd7276d58307ea515533af3807ac7d + resolved-ref: "97d835d54086adddc2666d916f8f63d9e6f64a4d" url: "https://github.com/bggRGjQaUbCoE/canvas_danmaku.git" source: git version: "0.2.5"