diff --git a/lib/pages/live_room/superchat/superchat_card.dart b/lib/pages/live_room/superchat/superchat_card.dart index f90e51c26..5195c21a7 100644 --- a/lib/pages/live_room/superchat/superchat_card.dart +++ b/lib/pages/live_room/superchat/superchat_card.dart @@ -20,13 +20,13 @@ class SuperChatCard extends StatefulWidget { required this.item, this.onRemove, this.persistentSC = false, - required this.onReport, + this.onReport, }); final SuperChatItem item; final VoidCallback? onRemove; final bool persistentSC; - final VoidCallback onReport; + final VoidCallback? onReport; @override State createState() => _SuperChatCardState(); @@ -168,6 +168,7 @@ class _SuperChatCardState extends State { } return Column( + mainAxisSize: .min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ GestureDetector( diff --git a/lib/pages/live_room/view.dart b/lib/pages/live_room/view.dart index 8bc25bc84..24d83dcf7 100644 --- a/lib/pages/live_room/view.dart +++ b/lib/pages/live_room/view.dart @@ -46,6 +46,7 @@ import 'package:PiliPlus/utils/platform_utils.dart'; import 'package:PiliPlus/utils/share_utils.dart'; import 'package:PiliPlus/utils/storage.dart'; import 'package:PiliPlus/utils/storage_key.dart'; +import 'package:PiliPlus/utils/storage_pref.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:canvas_danmaku/canvas_danmaku.dart'; @@ -65,6 +66,7 @@ class LiveRoomPage extends StatefulWidget { class _LiveRoomPageState extends State with WidgetsBindingObserver, RouteAware, RouteAwareMixin { + late final fullScreenSCWidth = Pref.fullScreenSCWidth; final String heroTag = Utils.generateRandomString(6); late final LiveRoomController _liveRoomController; late final PlPlayerController plPlayerController; @@ -322,7 +324,7 @@ class _LiveRoomPageState extends State Positioned( left: padding.left + 25, bottom: 25, - width: 255, + width: fullScreenSCWidth, child: Obx(() { final item = _liveRoomController.fsSC.value; if (item == null) { diff --git a/lib/pages/setting/models/play_settings.dart b/lib/pages/setting/models/play_settings.dart index c21977fb3..c240ef005 100644 --- a/lib/pages/setting/models/play_settings.dart +++ b/lib/pages/setting/models/play_settings.dart @@ -5,6 +5,7 @@ import 'package:PiliPlus/models/common/super_chat_type.dart'; import 'package:PiliPlus/models/common/video/subtitle_pref_type.dart'; import 'package:PiliPlus/pages/main/controller.dart'; import 'package:PiliPlus/pages/setting/models/model.dart'; +import 'package:PiliPlus/pages/setting/pages/fullscreen_sc_size.dart'; import 'package:PiliPlus/pages/setting/widgets/select_dialog.dart'; import 'package:PiliPlus/plugin/pl_player/models/bottom_progress_behavior.dart'; import 'package:PiliPlus/plugin/pl_player/models/fullscreen_mode.dart'; @@ -145,6 +146,12 @@ List get playSettings => [ getSubtitle: () => '当前:「${Pref.superChatType.title}」', onTap: _showSuperChatDialog, ), + NormalModel( + title: '全屏 SC 大小', + subtitle: 'SuperChat (醒目留言) 大小设置', + leading: const Icon(Icons.open_in_full), + onTap: (_, _) => Get.to(const FullScreenScSize()), + ), const SwitchModel( title: '竖屏扩大展示', subtitle: '小屏竖屏视频宽高比由16:9扩大至1:1(不支持收起);横屏适配时,扩大至9:16', diff --git a/lib/pages/setting/pages/fullscreen_sc_size.dart b/lib/pages/setting/pages/fullscreen_sc_size.dart new file mode 100644 index 000000000..339efd1da --- /dev/null +++ b/lib/pages/setting/pages/fullscreen_sc_size.dart @@ -0,0 +1,141 @@ +import 'dart:io' show Platform; +import 'dart:math' as math; + +import 'package:PiliPlus/common/widgets/extra_hittest_stack.dart'; +import 'package:PiliPlus/models_new/live/live_superchat/item.dart'; +import 'package:PiliPlus/pages/live_room/superchat/superchat_card.dart'; +import 'package:PiliPlus/plugin/pl_player/utils/fullscreen.dart'; +import 'package:PiliPlus/utils/platform_utils.dart'; +import 'package:PiliPlus/utils/storage.dart'; +import 'package:PiliPlus/utils/storage_key.dart'; +import 'package:PiliPlus/utils/storage_pref.dart'; +import 'package:flutter/material.dart'; + +const kFullScreenSCWidth = 255.0; + +class FullScreenScSize extends StatefulWidget { + const FullScreenScSize({super.key}); + + @override + State createState() => _FullScreenScSizeState(); +} + +class _FullScreenScSizeState extends State { + double _width = Pref.fullScreenSCWidth; + final _randomSC = SuperChatItem.random; + late EdgeInsets _padding; + late ColorScheme _colorScheme; + + @override + void initState() { + super.initState(); + if (Platform.isAndroid) { + landscapeLeftMode(); + } else if (Platform.isIOS) { + landscapeRightMode(); + } + } + + @override + void dispose() { + if (PlatformUtils.isMobile) { + if (Pref.horizontalScreen) { + fullMode(); + } else { + portraitUpMode(); + } + } + super.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final padding = MediaQuery.viewPaddingOf(context); + _padding = .only( + right: padding.right + 17, + left: padding.left + 25, + bottom: padding.bottom + 25, + ); + _colorScheme = ColorScheme.of(context); + } + + void _onReset() { + _width = kFullScreenSCWidth; + GStorage.setting.delete(SettingBoxKey.fullScreenSCWidth); + setState(() {}); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: AppBar( + title: const Text('全屏 SC 大小设置'), + actions: [ + TextButton(onPressed: _onReset, child: const Text('重置')), + ], + ), + body: Padding(padding: _padding, child: _buildBody), + ); + } + + Widget get _buildBody { + return Align( + alignment: .bottomLeft, + child: ExtraHitTestStack( + clipBehavior: .none, + children: [ + SizedBox( + width: _width, + child: IgnorePointer( + child: SuperChatCard( + item: _randomSC, + persistentSC: true, + ), + ), + ), + Positioned( + top: 0, + bottom: 0, + right: -17, + width: 34, + child: MouseRegion( + cursor: SystemMouseCursors.resizeRight, + child: GestureDetector( + behavior: .opaque, + onHorizontalDragUpdate: _onHorizontalDragUpdate, + onHorizontalDragEnd: _onHorizontalDragEnd, + child: DecoratedBox( + decoration: BoxDecoration( + shape: .circle, + color: _colorScheme.secondaryContainer.withValues( + alpha: .8, + ), + ), + child: Transform.rotate( + angle: math.pi / 4, + child: Icon( + size: 18, + Icons.open_in_full, + color: _colorScheme.onSecondaryContainer, + ), + ), + ), + ), + ), + ), + ], + ), + ); + } + + void _onHorizontalDragUpdate(DragUpdateDetails details) { + _width = math.max(25.0, _width + details.delta.dx); + setState(() {}); + } + + void _onHorizontalDragEnd(DragEndDetails details) { + GStorage.setting.put(SettingBoxKey.fullScreenSCWidth, _width); + } +} diff --git a/lib/utils/storage_key.dart b/lib/utils/storage_key.dart index 227cba460..a67fb8522 100644 --- a/lib/utils/storage_key.dart +++ b/lib/utils/storage_key.dart @@ -23,6 +23,7 @@ abstract final class SettingBoxKey { enableAutoExit = 'enableAutoExit', enableOnlineTotal = 'enableOnlineTotal', superChatType = 'superChatType', + fullScreenSCWidth = 'fullScreenSCWidth', keyboardControl = 'keyboardControl', pauseOnMinimize = 'pauseOnMinimize', pgcSkipType = 'pgcSkipType', diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index b7337cefe..b3d44be75 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -25,6 +25,8 @@ import 'package:PiliPlus/models/common/video/video_decode_type.dart'; import 'package:PiliPlus/models/common/video/video_quality.dart'; import 'package:PiliPlus/models/user/danmaku_rule.dart'; import 'package:PiliPlus/models/user/info.dart'; +import 'package:PiliPlus/pages/setting/pages/fullscreen_sc_size.dart' + show kFullScreenSCWidth; import 'package:PiliPlus/plugin/pl_player/models/audio_output_type.dart'; import 'package:PiliPlus/plugin/pl_player/models/bottom_progress_behavior.dart'; import 'package:PiliPlus/plugin/pl_player/models/fullscreen_mode.dart'; @@ -892,6 +894,11 @@ abstract final class Pref { defaultValue: SuperChatType.valid.index, )]; + static double get fullScreenSCWidth => _setting.get( + SettingBoxKey.fullScreenSCWidth, + defaultValue: kFullScreenSCWidth, + ); + static bool get minimizeOnExit => _setting.get(SettingBoxKey.minimizeOnExit, defaultValue: true);