feat: 多语言 初步引入

This commit is contained in:
2024-03-15 00:01:06 +08:00
parent eae02be2af
commit b2c13a8a6f
45 changed files with 525 additions and 446 deletions

View File

@ -30,9 +30,10 @@ class HomePerformanceUI extends HookConsumerWidget {
children: [
if (state.showGraphicsPerformanceTip)
InfoBar(
title: const Text("图形优化提示"),
content: const Text(
"该功能对优化显卡瓶颈有很大帮助,但对 CPU 瓶颈可能起反效果,如果您显卡性能强劲,可以尝试使用更好的画质来获得更高的显卡利用率。",
title: Text(
S.current.performance_info_graphic_optimization_hint),
content: Text(
S.current.performance_info_graphic_optimization_warning,
),
onClose: () => model.closeTip(),
),
@ -44,15 +45,15 @@ class HomePerformanceUI extends HookConsumerWidget {
style: const TextStyle(fontSize: 18),
),
const SizedBox(width: 32),
const Text(
"预设:",
style: TextStyle(fontSize: 18),
Text(
S.current.performance_action_preset,
style: const TextStyle(fontSize: 18),
),
for (final item in const {
"low": "",
"medium": "",
"high": "",
"ultra": "超级"
for (final item in {
"low": S.current.performance_action_low,
"medium": S.current.performance_action_medium,
"high": S.current.performance_action_high,
"ultra": S.current.performance_action_super
}.entries)
Padding(
padding: const EdgeInsets.only(left: 6, right: 6),
@ -65,7 +66,8 @@ class HomePerformanceUI extends HookConsumerWidget {
onPressed: () =>
model.onChangePreProfile(item.key)),
),
const Text("(预设只修改图形设置)"),
Text(
S.current.performance_action_info_preset_only_changes_graphics),
const Spacer(),
Button(
onPressed: () => model.refresh(),
@ -76,23 +78,23 @@ class HomePerformanceUI extends HookConsumerWidget {
),
const SizedBox(width: 12),
Button(
child: const Text(
" 恢复默认 ",
style: TextStyle(fontSize: 16),
child: Text(
S.current.performance_action_reset_to_default,
style: const TextStyle(fontSize: 16),
),
onPressed: () => model.clean(context)),
const SizedBox(width: 24),
Button(
child: const Text(
"应用",
style: TextStyle(fontSize: 16),
child: Text(
S.current.performance_action_apply,
style: const TextStyle(fontSize: 16),
),
onPressed: () => model.applyProfile(false)),
const SizedBox(width: 6),
Button(
child: const Text(
"应用并清理着色器(推荐)",
style: TextStyle(fontSize: 16),
child: Text(
S.current.performance_action_apply_and_clear_shaders,
style: const TextStyle(fontSize: 16),
),
onPressed: () => model.applyProfile(true)),
],

View File

@ -11,6 +11,7 @@ import 'package:starcitizen_doctor/api/analytics.dart';
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
import 'package:starcitizen_doctor/data/game_performance_data.dart';
import 'package:starcitizen_doctor/generated/l10n.dart';
import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
part 'performance_ui_model.freezed.dart';
@ -19,7 +20,7 @@ part 'performance_ui_model.g.dart';
@freezed
class HomePerformanceUIState with _$HomePerformanceUIState {
const factory HomePerformanceUIState({
factory HomePerformanceUIState({
@Default(true) bool showGraphicsPerformanceTip,
@Default(false) bool enabled,
Map<String, List<GamePerformanceData>>? performanceMap,
@ -41,7 +42,7 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
@override
HomePerformanceUIState build() {
state = const HomePerformanceUIState();
state = HomePerformanceUIState();
_init();
return state;
}
@ -111,7 +112,7 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
switch (key) {
case "low":
state.performanceMap?.forEach((key, v) {
if (key.contains("图形")) {
if (key.contains(S.current.performance_info_graphics)) {
for (var element in v) {
element.value = element.min;
}
@ -120,7 +121,7 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
break;
case "medium":
state.performanceMap?.forEach((key, v) {
if (key.contains("图形")) {
if (key.contains(S.current.performance_info_graphics)) {
for (var element in v) {
element.value = ((element.max ?? 0) ~/ 2);
}
@ -129,7 +130,7 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
break;
case "high":
state.performanceMap?.forEach((key, v) {
if (key.contains("图形")) {
if (key.contains(S.current.performance_info_graphics)) {
for (var element in v) {
element.value = ((element.max ?? 0) / 1.5).ceil();
}
@ -138,7 +139,7 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
break;
case "ultra":
state.performanceMap?.forEach((key, v) {
if (key.contains("图形")) {
if (key.contains(S.current.performance_info_graphics)) {
for (var element in v) {
element.value = element.max;
}
@ -154,14 +155,14 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
}
clean(BuildContext context) async {
state = state.copyWith(workingString: "删除配置文件...");
state = state.copyWith(workingString: S.current.performance_info_delete_config_file);
if (await confFile.exists()) {
await confFile.delete(recursive: true);
}
state = state.copyWith(workingString: "清理着色器");
state = state.copyWith(workingString: S.current.performance_action_clear_shaders);
if (!context.mounted) return;
await cleanShaderCache(context);
state = state.copyWith(workingString: "完成...");
state = state.copyWith(workingString: S.current.performance_info_done);
await await Future.delayed(const Duration(milliseconds: 300));
await _init();
state = state.copyWith(workingString: "");
@ -180,14 +181,14 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
}
await Future.delayed(const Duration(milliseconds: 300));
if (context != null && context.mounted) {
showToast(context, "清理着色器后首次进入游戏可能会出现卡顿,请耐心等待游戏初始化完毕。");
showToast(context, S.current.performance_info_shader_clearing_warning);
}
}
applyProfile(bool cleanShader) async {
if (state.performanceMap == null) return;
AnalyticsApi.touch("performance_apply");
state = state.copyWith(workingString: "生成配置文件");
state = state.copyWith(workingString: S.current.performance_info_generate_config_file);
String conf = "";
for (var v in state.performanceMap!.entries) {
for (var c in v.value) {
@ -206,23 +207,23 @@ class HomePerformanceUIModel extends _$HomePerformanceUIModel {
}
}
}
state = state.copyWith(workingString: "写出配置文件");
state = state.copyWith(workingString: S.current.performance_info_write_out_config_file);
if (await confFile.exists()) {
await confFile.delete();
}
await confFile.create();
await confFile.writeAsString(conf);
if (cleanShader) {
state = state.copyWith(workingString: "清理着色器");
state = state.copyWith(workingString: S.current.performance_action_clear_shaders);
await cleanShaderCache(null);
}
state = state.copyWith(workingString: "完成...");
state = state.copyWith(workingString: S.current.performance_info_done);
await await Future.delayed(const Duration(milliseconds: 300));
await _init();
state = state.copyWith(workingString: "清理着色器");
state = state.copyWith(workingString: S.current.performance_action_clear_shaders);
}
updateState() {
state = state.copyWith();
}
}
}

View File

@ -138,7 +138,7 @@ class __$$HomePerformanceUIStateImplCopyWithImpl<$Res>
/// @nodoc
class _$HomePerformanceUIStateImpl implements _HomePerformanceUIState {
const _$HomePerformanceUIStateImpl(
_$HomePerformanceUIStateImpl(
{this.showGraphicsPerformanceTip = true,
this.enabled = false,
final Map<String, List<GamePerformanceData>>? performanceMap,
@ -203,7 +203,7 @@ class _$HomePerformanceUIStateImpl implements _HomePerformanceUIState {
}
abstract class _HomePerformanceUIState implements HomePerformanceUIState {
const factory _HomePerformanceUIState(
factory _HomePerformanceUIState(
{final bool showGraphicsPerformanceTip,
final bool enabled,
final Map<String, List<GamePerformanceData>>? performanceMap,

View File

@ -7,7 +7,7 @@ part of 'performance_ui_model.dart';
// **************************************************************************
String _$homePerformanceUIModelHash() =>
r'85e3390e954b35ffeb7cbacf85619b5a61f866bb';
r'0519b95b68b4bffcd940513fa800654c81da2502';
/// See also [HomePerformanceUIModel].
@ProviderFor(HomePerformanceUIModel)