mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-30 23:58:13 +08:00
mod: show live danmaku emote
This commit is contained in:
@@ -87,7 +87,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
right: 0,
|
right: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: 0.8,
|
opacity: 0.6,
|
||||||
child: Image.asset(
|
child: Image.asset(
|
||||||
'assets/images/live/default_bg.webp',
|
'assets/images/live/default_bg.webp',
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
@@ -108,7 +108,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
.roomInfoH5.value.roomInfo?.appBackground !=
|
.roomInfoH5.value.roomInfo?.appBackground !=
|
||||||
null
|
null
|
||||||
? Opacity(
|
? Opacity(
|
||||||
opacity: 0.8,
|
opacity: 0.6,
|
||||||
child: NetworkImgLayer(
|
child: NetworkImgLayer(
|
||||||
width: Get.width,
|
width: Get.width,
|
||||||
height: Get.height,
|
height: Get.height,
|
||||||
@@ -231,13 +231,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
child: videoPlayerPanel,
|
child: videoPlayerPanel,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Expanded(
|
||||||
height: MediaQuery.of(context).orientation ==
|
|
||||||
Orientation.landscape
|
|
||||||
? Get.size.height
|
|
||||||
: Get.size.height - (Get.size.width * 9 / 16) - 100,
|
|
||||||
color: const Color(0x10000000),
|
|
||||||
width: Get.size.width,
|
|
||||||
child: LiveRoomChat(
|
child: LiveRoomChat(
|
||||||
roomId: int.parse(Get.parameters['roomid']!)))
|
roomId: int.parse(Get.parameters['roomid']!)))
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
|
import 'package:PiliPalaX/common/widgets/network_img_layer.dart';
|
||||||
import 'package:PiliPalaX/http/live.dart';
|
import 'package:PiliPalaX/http/live.dart';
|
||||||
import 'package:PiliPalaX/models/live/danmu_info.dart';
|
import 'package:PiliPalaX/models/live/danmu_info.dart';
|
||||||
import 'package:PiliPalaX/services/loggeer.dart';
|
import 'package:PiliPalaX/services/loggeer.dart';
|
||||||
@@ -17,18 +17,25 @@ class LiveRoomChat extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LiveRoomChatState extends State<LiveRoomChat> {
|
class _LiveRoomChatState extends State<LiveRoomChat> {
|
||||||
String dm = "Danmaku Area";
|
|
||||||
final List<Widget> _items = [];
|
final List<Widget> _items = [];
|
||||||
late LiveMessageStream msgStream;
|
late LiveMessageStream msgStream;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView.builder(
|
return Container(
|
||||||
itemCount: _items.length,
|
width: double.infinity,
|
||||||
itemBuilder: (ctx, i) {
|
padding: EdgeInsets.only(
|
||||||
return _items[i];
|
left: 10,
|
||||||
},
|
right: 10,
|
||||||
); //Center(child: Text(dm,style: const TextStyle(color: Colors.red),),);
|
bottom: MediaQuery.of(context).padding.bottom,
|
||||||
|
),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: _items,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -38,44 +45,35 @@ class _LiveRoomChatState extends State<LiveRoomChat> {
|
|||||||
LiveDanmakuInfo info = v['data'];
|
LiveDanmakuInfo info = v['data'];
|
||||||
// logger.d("info => $info");
|
// logger.d("info => $info");
|
||||||
msgStream = LiveMessageStream(
|
msgStream = LiveMessageStream(
|
||||||
streamToken: info.data.token,
|
streamToken: info.data.token,
|
||||||
roomId: widget.roomId,
|
roomId: widget.roomId,
|
||||||
uid: GStorage.userInfo.get('userInfoCache').mid ?? 0,
|
uid: GStorage.userInfo.get('userInfoCache').mid ?? 0,
|
||||||
host: info.data.hostList[0].host,
|
host: info.data.hostList[0].host,
|
||||||
port: info.data.hostList[0].port);
|
port: info.data.hostList[0].port,
|
||||||
|
);
|
||||||
msgStream.addEventListener((obj) {
|
msgStream.addEventListener((obj) {
|
||||||
if (obj['cmd'] == 'DANMU_MSG') {
|
if (obj['cmd'] == 'DANMU_MSG') {
|
||||||
// logger.i(' 原始弹幕消息 ======> ${jsonEncode(obj)}');
|
// logger.i(' 原始弹幕消息 ======> ${jsonEncode(obj)}');
|
||||||
setState(() {
|
setState(() {
|
||||||
var widget = Container(
|
var widget = GestureDetector(
|
||||||
decoration: const BoxDecoration(
|
onTap: () {
|
||||||
borderRadius: BorderRadius.all(Radius.circular(100))),
|
// showDialog(
|
||||||
child: ListTile(
|
// context: context,
|
||||||
dense: true,
|
// builder: (_) => AlertDialog(
|
||||||
leading: obj['info'][0][15]['user']['medal'] != null
|
// content: SelectableText(
|
||||||
? IntrinsicWidth(
|
// '${jsonDecode(obj['info'][0][15]['extra'])['emots']}'),
|
||||||
child: Container(
|
// ),
|
||||||
// width: 70,
|
// );
|
||||||
height: 20,
|
},
|
||||||
padding: const EdgeInsets.symmetric(
|
child: Container(
|
||||||
horizontal: 5,
|
margin: const EdgeInsets.only(top: 5),
|
||||||
),
|
padding:
|
||||||
color: Color((0xff000000 +
|
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||||
obj['info'][0][15]['user']['medal']
|
decoration: const BoxDecoration(
|
||||||
['color']) as int),
|
color: Color(0x15FFFFFF),
|
||||||
child: Center(
|
borderRadius: BorderRadius.all(Radius.circular(18)),
|
||||||
child: Text(
|
),
|
||||||
'${obj['info'][0][15]['user']['medal']['name']} '
|
child: Text.rich(
|
||||||
'lv${obj['info'][0][15]['user']['medal']['level']}',
|
|
||||||
style:
|
|
||||||
const TextStyle(color: Color(0xffdddddd)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
style: ListTileStyle.list,
|
|
||||||
title: Text.rich(
|
|
||||||
TextSpan(
|
TextSpan(
|
||||||
children: [
|
children: [
|
||||||
TextSpan(
|
TextSpan(
|
||||||
@@ -86,20 +84,14 @@ class _LiveRoomChatState extends State<LiveRoomChat> {
|
|||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextSpan(
|
_buildMsg(obj),
|
||||||
text: obj['info'][1],
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Color(0xFFFFFFFF),
|
|
||||||
fontSize: 14,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
_items.add(widget);
|
_items.add(widget);
|
||||||
if (_items.length >= 20) {
|
if (_items.length >= 50) {
|
||||||
_items.removeAt(0);
|
_items.removeAt(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -116,6 +108,58 @@ class _LiveRoomChatState extends State<LiveRoomChat> {
|
|||||||
msgStream.close();
|
msgStream.close();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextSpan _buildMsg(obj) {
|
||||||
|
dynamic emots = jsonDecode(obj['info'][0][15]['extra'])['emots'];
|
||||||
|
if (emots != null) {
|
||||||
|
List list = emots.keys.map((e) {
|
||||||
|
return e.replaceAllMapped(
|
||||||
|
RegExp(r'\[(.*?)\]'),
|
||||||
|
(match) => r'\[' + match.group(1)! + r'\]',
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
RegExp regExp = RegExp(list.join('|'));
|
||||||
|
final List<InlineSpan> spanChildren = <InlineSpan>[];
|
||||||
|
(obj['info'][1] as String).splitMapJoin(
|
||||||
|
regExp,
|
||||||
|
onMatch: (Match match) {
|
||||||
|
String key = match[0]!;
|
||||||
|
spanChildren.add(WidgetSpan(
|
||||||
|
child: ExcludeSemantics(
|
||||||
|
child: NetworkImgLayer(
|
||||||
|
src: emots[key]['url'],
|
||||||
|
type: 'emote',
|
||||||
|
width: emots[key]['width'].toDouble(),
|
||||||
|
height: emots[key]['height'].toDouble(),
|
||||||
|
semanticsLabel: key,
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
onNonMatch: (String nonMatchStr) {
|
||||||
|
spanChildren.add(
|
||||||
|
TextSpan(
|
||||||
|
text: nonMatchStr,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Color(0xFFFFFFFF),
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return TextSpan(children: spanChildren);
|
||||||
|
} else {
|
||||||
|
return TextSpan(
|
||||||
|
text: obj['info'][1],
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Color(0xFFFFFFFF),
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final PiliLogger logger = getLogger();
|
final PiliLogger logger = getLogger();
|
||||||
|
|||||||
Reference in New Issue
Block a user