diff --git a/README.md b/README.md index f162a835d..b0465b7b6 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ ## feat +- [x] 高级弹幕 by @My-Responsitories - [x] 取消/置顶评论 - [x] 记笔记 - [x] 多账号支持 by @My-Responsitories diff --git a/lib/pages/danmaku/controller.dart b/lib/pages/danmaku/controller.dart index ff0f29c72..ed9d32ca9 100644 --- a/lib/pages/danmaku/controller.dart +++ b/lib/pages/danmaku/controller.dart @@ -38,7 +38,7 @@ class PlDanmakuController { if (result['status']) { if (result['data'].elems.isNotEmpty) { for (DanmakuElem element in result['data'].elems) { - if (element.mode == 7) { + if (element.mode == 7 && !plPlayerController.showSpecialDanmaku) { continue; } int pos = element.progress ~/ 100; //每0.1秒存储一次 diff --git a/lib/pages/danmaku/view.dart b/lib/pages/danmaku/view.dart index b38173141..3ba93ff13 100644 --- a/lib/pages/danmaku/view.dart +++ b/lib/pages/danmaku/view.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'package:PiliPlus/grpc/dm/v1/dm.pb.dart'; import 'package:PiliPlus/utils/extension.dart'; @@ -103,22 +104,32 @@ class _PlDanmakuState extends State { _plDanmakuController.getCurrentDanmaku(currentPosition); if (currentDanmakuList != null) { for (DanmakuElem e in currentDanmakuList) { - _controller!.addDanmaku( - DanmakuContentItem( - e.content, - color: playerController.blockTypes.contains(6) - ? Colors.white - : DmUtils.decimalToColor(e.color), - type: DmUtils.getPosition(e.mode), - isColorful: playerController.showVipDanmaku && - e.colorful == DmColorfulType.VipGradualColor - ? true - : null, - count: widget.playerController.mergeDanmaku && e.hasAttr() - ? e.attr - : null, - ), - ); + if (e.mode == 7) { + _controller!.addDanmaku( + SpecialDanmakuContentItem.fromList( + DmUtils.decimalToColor(e.color), + e.fontsize.toDouble(), + jsonDecode(e.content), + ), + ); + } else { + _controller!.addDanmaku( + DanmakuContentItem( + e.content, + color: playerController.blockTypes.contains(6) + ? Colors.white + : DmUtils.decimalToColor(e.color), + type: DmUtils.getPosition(e.mode), + isColorful: playerController.showVipDanmaku && + e.colorful == DmColorfulType.VipGradualColor + ? true + : null, + count: widget.playerController.mergeDanmaku && e.hasAttr() + ? e.attr + : null, + ), + ); + } } } } diff --git a/lib/pages/setting/widgets/model.dart b/lib/pages/setting/widgets/model.dart index d286bcede..b6207dba7 100644 --- a/lib/pages/setting/widgets/model.dart +++ b/lib/pages/setting/widgets/model.dart @@ -1837,6 +1837,13 @@ List get extraSettings => [ setKey: SettingBoxKey.showVipDanmaku, defaultVal: true, ), + SettingsModel( + settingsType: SettingsType.sw1tch, + title: '显示高级弹幕', + leading: Icon(MdiIcons.paletteAdvanced), + setKey: SettingBoxKey.showSpecialDanmaku, + defaultVal: true, + ), SettingsModel( settingsType: SettingsType.sw1tch, title: '合并弹幕', diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index c9844bbff..52bcfaa5b 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -287,6 +287,7 @@ class PlPlayerController { late int subtitlePaddingB = GStorage.subtitlePaddingB; late double subtitleBgOpaticy = GStorage.subtitleBgOpaticy; late bool showVipDanmaku = GStorage.showVipDanmaku; + late bool showSpecialDanmaku = GStorage.showSpecialDanmaku; late double subtitleStrokeWidth = GStorage.subtitleStrokeWidth; late int subtitleFontWeight = GStorage.subtitleFontWeight; diff --git a/lib/utils/danmaku.dart b/lib/utils/danmaku.dart index 56f1e6862..367e2fc31 100644 --- a/lib/utils/danmaku.dart +++ b/lib/utils/danmaku.dart @@ -12,14 +12,11 @@ class DmUtils { } static DanmakuItemType getPosition(int mode) { - DanmakuItemType type = DanmakuItemType.scroll; - if (mode >= 1 && mode <= 3) { - type = DanmakuItemType.scroll; - } else if (mode == 4) { - type = DanmakuItemType.bottom; - } else if (mode == 5) { - type = DanmakuItemType.top; - } - return type; + return switch (mode) { + 4 => DanmakuItemType.bottom, + 5 => DanmakuItemType.top, + 7 => DanmakuItemType.special, + _ => DanmakuItemType.scroll, + }; } } diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 5c8c37b71..1bbeda800 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -342,6 +342,9 @@ class GStorage { static bool get showVipDanmaku => GStorage.setting.get(SettingBoxKey.showVipDanmaku, defaultValue: true); + static bool get showSpecialDanmaku => GStorage.setting + .get(SettingBoxKey.showSpecialDanmaku, defaultValue: true); + static bool get mergeDanmaku => GStorage.setting.get(SettingBoxKey.mergeDanmaku, defaultValue: false); @@ -695,6 +698,7 @@ class SettingBoxKey { refreshDragPercentage = 'refreshDragPercentage', refreshDisplacement = 'refreshDisplacement', showVipDanmaku = 'showVipDanmaku', + showSpecialDanmaku = 'showSpecialDanmaku', mergeDanmaku = 'mergeDanmaku', showHotRcmd = 'showHotRcmd', audioNormalization = 'audioNormalization', diff --git a/pubspec.lock b/pubspec.lock index 30e27abfd..ae5d264ca 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -252,7 +252,7 @@ packages: description: path: "." ref: main - resolved-ref: "23269eb39f4374b7cbf7154e47918213e174373d" + resolved-ref: "233f3e2581cbe2dd4867effbd0c512ef6b340599" url: "https://github.com/bggRGjQaUbCoE/canvas_danmaku.git" source: git version: "0.2.6"