mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: 新增弹幕按等级云屏蔽功能
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import 'package:PiliPalaX/http/danmaku.dart';
|
||||
import 'package:PiliPalaX/models/danmaku/dm.pb.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class PlDanmakuController {
|
||||
PlDanmakuController(this.cid);
|
||||
PlDanmakuController(this.cid, this.danmakuWeightNotifier);
|
||||
final int cid;
|
||||
final ValueNotifier<int> danmakuWeightNotifier;
|
||||
int danmakuWeight = 0;
|
||||
Map<int, List<DanmakuElem>> dmSegMap = {};
|
||||
// 已请求的段落标记
|
||||
List<bool> requestedSeg = [];
|
||||
@@ -16,6 +19,11 @@ class PlDanmakuController {
|
||||
if (videoDuration <= 0) {
|
||||
return;
|
||||
}
|
||||
danmakuWeightNotifier.addListener(() {
|
||||
print(
|
||||
"danmakuWeight changed from $danmakuWeight to ${danmakuWeightNotifier.value}");
|
||||
danmakuWeight = danmakuWeightNotifier.value;
|
||||
});
|
||||
if (requestedSeg.isEmpty) {
|
||||
int segCount = (videoDuration / segmentLength).ceil();
|
||||
requestedSeg = List<bool>.generate(segCount, (index) => false);
|
||||
@@ -59,6 +67,13 @@ class PlDanmakuController {
|
||||
if (!requestedSeg[segmentIndex]) {
|
||||
queryDanmaku(segmentIndex);
|
||||
}
|
||||
return dmSegMap[progress ~/ 100];
|
||||
if (danmakuWeight == 0) {
|
||||
return dmSegMap[progress ~/ 100];
|
||||
} else {
|
||||
//using filter
|
||||
return dmSegMap[progress ~/ 100]
|
||||
?.where((element) => element.weight >= danmakuWeight)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
super.initState();
|
||||
enableShowDanmaku =
|
||||
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
|
||||
_plDanmakuController = PlDanmakuController(widget.cid);
|
||||
_plDanmakuController = PlDanmakuController(
|
||||
widget.cid, widget.playerController.danmakuWeight);
|
||||
if (mounted) {
|
||||
playerController = widget.playerController;
|
||||
if (enableShowDanmaku || playerController.isOpenDanmu.value) {
|
||||
@@ -136,8 +137,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
hideTop: blockTypes.contains(5),
|
||||
hideScroll: blockTypes.contains(2),
|
||||
hideBottom: blockTypes.contains(4),
|
||||
duration:
|
||||
danmakuDurationVal / playerController.playbackSpeed,
|
||||
duration: danmakuDurationVal / playerController.playbackSpeed,
|
||||
strokeWidth: strokeWidth,
|
||||
// initDuration /
|
||||
// (danmakuSpeedVal * widget.playerController.playbackSpeed),
|
||||
|
||||
Reference in New Issue
Block a user