refa: danmaku & feat: scroll fixed velocity (#1791)

This commit is contained in:
My-Responsitories
2025-12-29 21:03:24 +08:00
committed by GitHub
parent 0a40d11133
commit 49b7ea14c3
15 changed files with 721 additions and 770 deletions

View File

@@ -321,7 +321,7 @@ class PlPlayerController {
}
}
/// 弹幕权重
// 弹幕相关配置
late final enableTapDm = PlatformUtils.isMobile && Pref.enableTapDm;
late int danmakuWeight = Pref.danmakuWeight;
late RuleFilter filters = Pref.danmakuFilterRule;
@@ -334,26 +334,16 @@ class PlPlayerController {
ascii.encode(Accounts.main.mid.toString()),
0,
).toRadixString(16);
// 弹幕相关配置
late Set<int> blockTypes = Pref.danmakuBlockType;
late bool blockColorful = blockTypes.contains(6);
late double showArea = Pref.danmakuShowArea;
late RxDouble danmakuOpacity = Pref.danmakuOpacity.obs;
late double danmakuFontScale = Pref.danmakuFontScale;
late double danmakuFontScaleFS = Pref.danmakuFontScaleFS;
late double danmakuStrokeWidth = Pref.strokeWidth;
late int danmakuFontWeight = Pref.fontWeight;
late bool massiveMode = Pref.danmakuMassiveMode;
late double danmakuDuration = Pref.danmakuDuration;
late double danmakuStaticDuration = Pref.danmakuStaticDuration;
late final RxDouble danmakuOpacity = Pref.danmakuOpacity.obs;
late List<double> speedList = Pref.speedList;
late bool enableAutoLongPressSpeed = Pref.enableAutoLongPressSpeed;
late final showControlDuration = Pref.enableLongShowControl
? const Duration(seconds: 30)
: const Duration(seconds: 3);
// 字幕
late double subtitleFontScale = Pref.subtitleFontScale;
late double subtitleFontScaleFS = Pref.subtitleFontScaleFS;
late double danmakuLineHeight = Pref.danmakuLineHeight;
late int subtitlePaddingH = Pref.subtitlePaddingH;
late int subtitlePaddingB = Pref.subtitlePaddingB;
late double subtitleBgOpacity = Pref.subtitleBgOpacity;
@@ -1676,22 +1666,6 @@ class PlPlayerController {
video.put(VideoBoxKey.playRepeat, type.index);
}
void putDanmakuSettings() {
setting.putAll({
SettingBoxKey.danmakuWeight: danmakuWeight,
SettingBoxKey.danmakuBlockType: blockTypes.toList(),
SettingBoxKey.danmakuShowArea: showArea,
SettingBoxKey.danmakuOpacity: danmakuOpacity.value,
SettingBoxKey.danmakuFontScale: danmakuFontScale,
SettingBoxKey.danmakuFontScaleFS: danmakuFontScaleFS,
SettingBoxKey.danmakuDuration: danmakuDuration,
SettingBoxKey.danmakuStaticDuration: danmakuStaticDuration,
SettingBoxKey.strokeWidth: danmakuStrokeWidth,
SettingBoxKey.fontWeight: danmakuFontWeight,
SettingBoxKey.danmakuLineHeight: danmakuLineHeight,
});
}
void putSubtitleSettings() {
setting.putAll({
SettingBoxKey.subtitleFontScale: subtitleFontScale,

View File

@@ -0,0 +1,58 @@
import 'package:PiliPlus/utils/extension/box_ext.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_key.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:canvas_danmaku/canvas_danmaku.dart';
abstract final class DanmakuOptions {
static final Set<int> blockTypes = Pref.danmakuBlockType;
static bool blockColorful = blockTypes.contains(6);
static double danmakuFontScaleFS = Pref.danmakuFontScaleFS;
static double danmakuFontScale = Pref.danmakuFontScale;
static int danmakuFontWeight = Pref.fontWeight;
static double danmakuShowArea = Pref.danmakuShowArea;
static double danmakuDuration = Pref.danmakuDuration;
static double danmakuStaticDuration = Pref.danmakuStaticDuration;
static double danmakuStrokeWidth = Pref.strokeWidth;
static bool scrollFixedVelocity = Pref.danmakuFixedV;
static bool massiveMode = Pref.danmakuMassiveMode;
static double danmakuLineHeight = Pref.danmakuLineHeight;
static DanmakuOption get({
required bool notFullscreen,
double speed = 1.0,
}) {
return DanmakuOption(
fontSize: notFullscreen ? danmakuFontScaleFS : danmakuFontScale,
fontWeight: danmakuFontWeight,
area: danmakuShowArea,
duration: danmakuDuration / speed,
staticDuration: danmakuStaticDuration / speed,
hideBottom: blockTypes.contains(5),
hideScroll: blockTypes.contains(2),
hideTop: blockTypes.contains(4),
hideSpecial: blockTypes.contains(7),
strokeWidth: danmakuStrokeWidth,
scrollFixedVelocity: scrollFixedVelocity,
massiveMode: massiveMode,
static2Scroll: true,
safeArea: true,
lineHeight: danmakuLineHeight,
);
}
static Future<void>? save() {
return GStorage.setting.putAllNE({
SettingBoxKey.danmakuBlockType: blockTypes.toList(),
SettingBoxKey.danmakuShowArea: danmakuShowArea,
SettingBoxKey.danmakuFontScale: danmakuFontScale,
SettingBoxKey.danmakuFontScaleFS: danmakuFontScaleFS,
SettingBoxKey.danmakuDuration: danmakuDuration,
SettingBoxKey.danmakuStaticDuration: danmakuStaticDuration,
SettingBoxKey.strokeWidth: danmakuStrokeWidth,
SettingBoxKey.fontWeight: danmakuFontWeight,
SettingBoxKey.danmakuLineHeight: danmakuLineHeight,
});
}
}

View File

@@ -1200,17 +1200,21 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
final ctr = plPlayerController.danmakuController;
if (ctr != null) {
final pos = details.localPosition;
final item = ctr.findSingleDanmaku(pos);
if (item == null) {
final res = ctr.findSingleDanmaku(pos);
if (res != null) {
final (dy, item) = res;
if (item != _suspendedDm) {
_suspendedDm?.suspend = false;
if (item.content.extra == null) {
_dmOffset.value = null;
return;
}
_suspendedDm = item..suspend = true;
this.dy = dy;
}
} else {
_suspendedDm?.suspend = false;
_dmOffset.value = null;
} else if (item != _suspendedDm) {
_suspendedDm?.suspend = false;
if (item.content.extra == null) {
_dmOffset.value = null;
return;
}
_suspendedDm = item..suspend = true;
}
}
}
@@ -2269,6 +2273,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
static const _actionItemHeight = 35.0 - _triangleHeight;
DanmakuItem<DanmakuExtra>? _suspendedDm;
double dy = 0;
late final Rxn<Offset> _dmOffset = Rxn<Offset>();
void _removeDmAction() {
@@ -2327,9 +2332,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
final overlayWidth = _actionItemWidth * (seekOffset == null ? 3 : 4);
final dy = item.content.type == DanmakuItemType.bottom
? maxHeight - item.yPosition - item.height
: item.yPosition;
final top = dy + item.height + _triangleHeight + 2;
final realLeft = dx + overlayWidth / 2;