Skip to content

Commit

Permalink
add customize font weight support
Browse files Browse the repository at this point in the history
  • Loading branch information
Predidit committed Nov 11, 2024
1 parent e91b6a9 commit f0ad46f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 13 deletions.
3 changes: 3 additions & 0 deletions lib/pages/player/player_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class _PlayerItemState extends State<PlayerItem>
late bool _danmakuBiliBiliSource;
late bool _danmakuGamerSource;
late bool _danmakuDanDanSource;
late int _danmakuFontWeight;

// 过渡动画
late AnimationController _animationController;
Expand Down Expand Up @@ -725,6 +726,7 @@ class _PlayerItemState extends State<PlayerItem>
setting.get(SettingBoxKey.danmakuGamerSource, defaultValue: true);
_danmakuDanDanSource =
setting.get(SettingBoxKey.danmakuDanDanSource, defaultValue: true);
_danmakuFontWeight = setting.get(SettingBoxKey.danmakuFontWeight, defaultValue: 4);
haEnable = setting.get(SettingBoxKey.hAenable, defaultValue: true);
playerTimer = getPlayerTimer();
windowManager.addListener(this);
Expand Down Expand Up @@ -1219,6 +1221,7 @@ class _PlayerItemState extends State<PlayerItem>
fontSize: _fontSize,
duration: _duration.toInt(),
showStroke: _border,
fontWeight: _danmakuFontWeight,
massiveMode: _massiveMode,
),
),
Expand Down
77 changes: 74 additions & 3 deletions lib/pages/settings/danmaku/danmaku_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
late dynamic defaultDanmakuArea;
late dynamic defaultDanmakuOpacity;
late dynamic defaultDanmakuFontSize;
late int defaultDanmakuFontWeight;
final PopularController popularController = Modular.get<PopularController>();

@override
Expand All @@ -43,6 +44,8 @@ class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
setting.get(SettingBoxKey.danmakuOpacity, defaultValue: 1.0);
defaultDanmakuFontSize = setting.get(SettingBoxKey.danmakuFontSize,
defaultValue: (Utils.isCompact()) ? 16.0 : 25.0);
defaultDanmakuFontWeight =
setting.get(SettingBoxKey.danmakuFontWeight, defaultValue: 4);
}

void onBackPressed(BuildContext context) {
Expand Down Expand Up @@ -71,6 +74,13 @@ class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
});
}

void updateDanmakuFontWeight(int i) async {
await setting.put(SettingBoxKey.danmakuFontWeight, i);
setState(() {
defaultDanmakuFontWeight = i;
});
}

@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Expand Down Expand Up @@ -190,9 +200,7 @@ class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
TextButton(
onPressed: () async {
updateDanmakuFontSize(
(Utils.isCompact())
? 16.0
: 25.0);
(Utils.isCompact()) ? 16.0 : 25.0);
SmartDialog.dismiss();
},
child: const Text('默认设置'),
Expand All @@ -209,6 +217,69 @@ class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
.labelMedium!
.copyWith(color: Theme.of(context).colorScheme.outline)),
),
ListTile(
onTap: () async {
SmartDialog.show(
useAnimation: false,
builder: (context) {
return AlertDialog(
title: const Text('字体字重'),
content: StatefulBuilder(builder:
(BuildContext context, StateSetter setState) {
return Wrap(
spacing: 8,
runSpacing: 2,
children: [
for (final int i in danFontWeightList) ...<Widget>[
if (i == defaultDanmakuFontWeight) ...<Widget>[
FilledButton(
onPressed: () async {
updateDanmakuFontWeight(i);
SmartDialog.dismiss();
},
child: Text(i.toString()),
),
] else ...[
FilledButton.tonal(
onPressed: () async {
updateDanmakuFontWeight(i);
SmartDialog.dismiss();
},
child: Text(i.toString()),
),
]
]
],
);
}),
actions: <Widget>[
TextButton(
onPressed: () => SmartDialog.dismiss(),
child: Text(
'取消',
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
updateDanmakuFontWeight(4);
SmartDialog.dismiss();
},
child: const Text('默认设置'),
),
],
);
});
},
dense: false,
title: const Text('字体字重'),
subtitle: Text('$defaultDanmakuFontWeight',
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(color: Theme.of(context).colorScheme.outline)),
),
ListTile(
onTap: () async {
SmartDialog.show(
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ final List<double> danFontList = [
32.0,
];

// 可选弹幕字体字重
final List<int> danFontWeightList = [
1,
2,
3,
4,
5,
6,
7,
8,
9,
];

// 可选弹幕区域
const List<double> danAreaList = [
0.25,
Expand Down
1 change: 1 addition & 0 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class SettingBoxKey {
danmakuBiliBiliSource = 'danmakuBiliBiliSource',
danmakuGamerSource = 'danmakuGamerSource',
danmakuDanDanSource = 'danmakuDanDanSource',
danmakuFontWeight = 'danmakuFontWeight',
themeMode = 'themeMode',
themeColor = 'themeColor',
privateMode = 'privateMode',
Expand Down
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ packages:
dependency: "direct main"
description:
name: canvas_danmaku
sha256: e5eebd19588cae528123fa14c0ad080fdc96881c3018f944f910024988ddb67e
sha256: "539beee7dab73b0d01980194885730de11527ec0f96d9c4fa26ae4eac6699b7f"
url: "https://pub.dev"
source: hosted
version: "0.2.2"
version: "0.2.3"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -461,10 +461,10 @@ packages:
dependency: "direct main"
description:
name: flutter_smart_dialog
sha256: "7932ab58440379094c6a568efc329d322c6dd740e5a553080f2d56a71ed53752"
sha256: d7b915461fdc9bb8111d23a709b4ce910dbc4b9bef0fbd941655f74bf7de09a6
url: "https://pub.dev"
source: hosted
version: "4.9.8+3"
version: "4.9.8+5"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -495,10 +495,10 @@ packages:
dependency: "direct main"
description:
name: fvp
sha256: "439ff92c52349cb6c345f680dcbe7f7a40fcd524073030a1e93aec64f959d864"
sha256: "3dd245cac5dfba36311cbf5834d8f275ba1f3e49a5cdcb4a98e01cb41e9a21d8"
url: "https://pub.dev"
source: hosted
version: "0.27.0"
version: "0.28.0"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -1023,10 +1023,10 @@ packages:
dependency: transitive
description:
name: shared_preferences
sha256: "746e5369a43170c25816cc472ee016d3a66bc13fcf430c0bc41ad7b4b2922051"
sha256: "95f9997ca1fb9799d494d0cb2a780fd7be075818d59f00c43832ed112b158a82"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
version: "2.3.3"
shared_preferences_android:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dependencies:
flutter_smart_dialog: ^4.9.8
cached_network_image: ^3.4.1

fvp: ^0.27.0
fvp: ^0.28.0
video_player: ^2.9.1

flutter_volume_controller: ^1.3.2
Expand All @@ -68,7 +68,7 @@ dependencies:
xpath_selector: ^3.0.2
xpath_selector_html_parser: ^3.0.1
webview_flutter: ^4.9.0
canvas_danmaku: ^0.2.0
canvas_danmaku: ^0.2.3
webdav_client: ^1.2.2
tray_manager: ^0.2.3
dlna_dart: ^0.0.8
Expand Down

0 comments on commit f0ad46f

Please sign in to comment.