From 38781c9807306e4cef036873c3d759c256397145 Mon Sep 17 00:00:00 2001 From: chenmoyuan1214 Date: Sat, 21 Nov 2026 20:45:25 +0800 Subject: [PATCH 1/4] =?UTF-8?q?refactor(ui):=20=E5=88=A0=E9=99=A4=E7=99=BE?= =?UTF-8?q?=E5=AE=9D=E7=AE=B1=E9=A1=B5=EF=BC=9B=E8=AE=BE=E7=BD=AE=E9=A1=B5?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=BB=E9=A2=98=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 pages/treasure.dart 与侧栏「百宝箱」入口,用户页从 index 6 前移到 5 - 清理 pages.dart 导出与 i18n 里的 nav.treasure / treasure.* 键 - 设置页移除主题色色板、自定义颜色入口与 _applyAccent 等实现 - 强调色改由用户账号的 theme_color 决定: · controller._applySettings 不再应用 settings.accentColor · 启动后 _applyUserTheme() 拉一次 /api/user/me 并按 theme_color 上色 · 退出登录回落到 GcPalette.defaultAccent - 清理 i18n 中的 set.accent.* 键与 settings.dart 无用的 dart:async 导入 --- GC-UI/frontend/lib/controller.dart | 17 ++- GC-UI/frontend/lib/i18n.dart | 12 -- GC-UI/frontend/lib/pages.dart | 1 - GC-UI/frontend/lib/pages/settings.dart | 137 -------------------- GC-UI/frontend/lib/pages/treasure.dart | 163 ------------------------ GC-UI/frontend/lib/pages/user_page.dart | 2 +- GC-UI/frontend/lib/shell.dart | 3 - 7 files changed, 17 insertions(+), 318 deletions(-) delete mode 100644 GC-UI/frontend/lib/pages/treasure.dart diff --git a/GC-UI/frontend/lib/controller.dart b/GC-UI/frontend/lib/controller.dart index 57ff40f..5658c13 100644 --- a/GC-UI/frontend/lib/controller.dart +++ b/GC-UI/frontend/lib/controller.dart @@ -67,6 +67,8 @@ class ShellController extends ChangeNotifier { if (settingsResult != null) { settings = settingsResult; _applySettings(settingsResult!); + // 主题色现在归用户账号所有(设置页不再提供),启动时按当前用户恢复 + unawaited(_applyUserTheme()); } if (firstError != null && settingsResult == null) { @@ -97,10 +99,23 @@ class ShellController extends ChangeNotifier { void _applySettings(SettingsInfo value) { I18n.setLanguage(value.language); - GcPalette.apply(value.accentColor); + // 强调色不再来自设置:由用户账号的 theme_color 决定(见 _applyUserTheme) GcPalette.applyTheme(value.theme); } + /// 按当前登录用户的 theme_color 应用强调色;未登录时保持默认。 + Future applyUserTheme() => _applyUserTheme(); + + Future _applyUserTheme() async { + try { + final resp = await api.me(); + final hex = resp?['theme_color'] as String?; + if (hex != null && hex.isNotEmpty) GcPalette.apply('#$hex'); + } catch (_) { + // 后端没起来或未登录:保持当前颜色即可 + } + } + void goTo(int value) { if (index == value) return; index = value; diff --git a/GC-UI/frontend/lib/i18n.dart b/GC-UI/frontend/lib/i18n.dart index b0b9b0c..e5a7d7e 100644 --- a/GC-UI/frontend/lib/i18n.dart +++ b/GC-UI/frontend/lib/i18n.dart @@ -17,7 +17,6 @@ class I18n { 'nav.download': '下载', 'nav.settings': '设置', 'nav.about': '关于', - 'nav.treasure': '百宝箱', 'nav.user': '用户', 'home.title': '模型库', 'home.subtitle': '选择模型,用可交互的三维演示讲清自转、公转与四季成因。', @@ -76,11 +75,6 @@ class I18n { 'set.theme.dark': '深色', 'set.theme.light': '浅色', 'set.theme.system': '跟随系统', - 'set.accent': '主题颜色', - 'set.accent.desc': '选择启动器的主色调,按钮、滑块与高亮会同步换色。', - 'set.accent.custom': '自定义颜色', - 'set.accent.hexHint': '格式 #RRGGBB,例如 #8FB6FF', - 'set.accent.invalid': '颜色格式无效,请使用 #RRGGBB', 'set.language': '界面语言', 'set.language.auto': '跟随系统', 'set.fps': '渲染帧率', @@ -218,7 +212,6 @@ class I18n { 'nav.download': 'Download', 'nav.settings': 'Settings', 'nav.about': 'About', - 'nav.treasure': 'Treasure', 'nav.user': 'User', 'home.title': 'Model library', 'home.subtitle': 'Pick a model and explain rotation, revolution and the seasons with an interactive 3D scene.', @@ -277,11 +270,6 @@ class I18n { 'set.theme.dark': 'Dark', 'set.theme.light': 'Light', 'set.theme.system': 'System', - 'set.accent': 'Theme color', - 'set.accent.desc': 'Pick the launcher accent color; buttons, sliders and highlights follow it.', - 'set.accent.custom': 'Custom color', - 'set.accent.hexHint': 'Format #RRGGBB, e.g. #8FB6FF', - 'set.accent.invalid': 'Invalid color, use #RRGGBB', 'set.language': 'Language', 'set.language.auto': 'System', 'set.fps': 'Render frame rate', diff --git a/GC-UI/frontend/lib/pages.dart b/GC-UI/frontend/lib/pages.dart index 4fffaea..12bab19 100644 --- a/GC-UI/frontend/lib/pages.dart +++ b/GC-UI/frontend/lib/pages.dart @@ -6,5 +6,4 @@ export 'pages/courseware.dart'; export 'pages/download.dart'; export 'pages/settings.dart'; export 'pages/about.dart'; -export 'pages/treasure.dart'; export 'pages/user_page.dart'; diff --git a/GC-UI/frontend/lib/pages/settings.dart b/GC-UI/frontend/lib/pages/settings.dart index 111a0ff..1c98a21 100644 --- a/GC-UI/frontend/lib/pages/settings.dart +++ b/GC-UI/frontend/lib/pages/settings.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:flutter/material.dart'; import '../api_client.dart'; @@ -248,8 +246,6 @@ class _SettingsPageViewState extends State { } Widget _appearanceCard(SettingsInfo settings) { - final current = - GcPalette.parseHex(settings.accentColor) ?? GcPalette.defaultAccent; return GcCard( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -287,144 +283,11 @@ class _SettingsPageViewState extends State { if (mounted) setState(() => _status = T('common.applied')); }, ), - const SizedBox(height: GcSpace.xl), - GcHint(T('set.accent.desc')), - const SizedBox(height: GcSpace.md + 2), - Wrap( - spacing: GcSpace.sm + 2, - runSpacing: GcSpace.sm + 2, - children: [ - for (final color in GcPalette.presets) - _accentSwatch(color, current), - _customAccentChip(), - ], - ), - const SizedBox(height: GcSpace.md), - Text( - '${T('set.accent')}: ${GcPalette.toHex(current)}', - style: TextStyle( - fontSize: 11.5, - height: 1.4, - color: GcColors.faint, - ), - ), ], ), ); } - Widget _accentSwatch(Color color, Color current) { - final selected = color.value == current.value; - return Tooltip( - message: GcPalette.toHex(color), - child: GestureDetector( - onTap: () => _applyAccent(GcPalette.toHex(color)), - child: Container( - width: 34, - height: 34, - decoration: BoxDecoration( - color: color, - borderRadius: BorderRadius.circular(GcRadius.control), - border: Border.all( - color: selected ? GcColors.ink : Colors.transparent, - width: 2, - ), - ), - child: selected - ? Icon( - Icons.check_rounded, - size: 18, - color: color.computeLuminance() > 0.42 - ? const Color(0xFF0A1226) - : Colors.white, - ) - : null, - ), - ), - ); - } - - Widget _customAccentChip() { - return MouseRegion( - cursor: SystemMouseCursors.click, - child: GestureDetector( - onTap: _pickCustomAccent, - child: Container( - height: 34, - padding: const EdgeInsets.symmetric(horizontal: GcSpace.md), - decoration: BoxDecoration( - color: GcColors.surfaceAlt, - borderRadius: BorderRadius.circular(GcRadius.control), - border: Border.all(color: GcColors.line), - ), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Icon(Icons.colorize_rounded, size: 16, color: GcColors.faint), - const SizedBox(width: GcSpace.xs + 2), - Text( - T('set.accent.custom'), - style: TextStyle( - fontSize: 12, - height: 1.3, - color: GcColors.muted, - ), - ), - ], - ), - ), - ), - ); - } - - Future _pickCustomAccent() async { - final controller = TextEditingController( - text: GcPalette.toHex(GcPalette.accent.value), - ); - final hex = await showDialog( - context: context, - builder: (context) => AlertDialog( - backgroundColor: GcColors.surface, - title: Text(T('set.accent.custom')), - content: TextField( - controller: controller, - autofocus: true, - style: Theme.of(context).textTheme.bodyLarge!.copyWith(fontSize: 13), - decoration: InputDecoration( - hintText: '#8FB6FF', - helperText: T('set.accent.hexHint'), - ), - onSubmitted: (value) => Navigator.of(context).pop(value), - ), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: Text(T('common.cancel')), - ), - FilledButton( - onPressed: () => Navigator.of(context).pop(controller.text), - child: Text(T('common.confirm')), - ), - ], - ), - ); - controller.dispose(); - if (hex != null) await _applyAccent(hex); - } - - Future _applyAccent(String hex) async { - final parsed = GcPalette.parseHex(hex); - if (parsed == null) { - if (mounted) setState(() => _status = T('set.accent.invalid')); - return; - } - final normalized = GcPalette.toHex(parsed); - GcPalette.apply(normalized); // 立即预览 - await widget.controller - .saveSettings(SettingsPatch(accentColor: normalized)); - if (mounted) setState(() => _status = T('common.applied')); - } - Widget _memoryCard(SettingsInfo settings) { return GcCard( child: Column( diff --git a/GC-UI/frontend/lib/pages/treasure.dart b/GC-UI/frontend/lib/pages/treasure.dart deleted file mode 100644 index 3df2818..0000000 --- a/GC-UI/frontend/lib/pages/treasure.dart +++ /dev/null @@ -1,163 +0,0 @@ -import 'dart:math'; - -import 'package:flutter/material.dart'; - -import '../controller.dart'; -import '../theme.dart'; -import '../i18n.dart'; - -/// 百宝箱页:今日人品、随机运势等小玩意。 -class TreasurePage extends StatefulWidget { - const TreasurePage({super.key, required this.controller}); - - final ShellController controller; - - @override - State createState() => _TreasurePageState(); -} - -class _TreasurePageState extends State { - String _fortune = ''; - String _luckyColor = ''; - String _luckyNumber = ''; - bool _loading = false; - final Random _rand = Random(); - - @override - void initState() { - super.initState(); - _refresh(); - } - - void _refresh() { - setState(() => _loading = true); - // 模拟计算延迟 - Future.delayed(const Duration(milliseconds: 400), () { - if (!mounted) return; - final fortunes = [ - '今日宜:尝试新事物,突破舒适区。', - '运气不错,适合做重要的决定。', - '财运旺盛,可能会有意外收获。', - '人际和谐,适合合作与沟通。', - '专注当下,好运自然来。', - '保持乐观,今天会有好消息。', - '灵感涌现,适合创作和思考。', - '脚踏实地,一步一个脚印。', - '贵人运旺,多与他人交流。', - '健康第一,注意休息和锻炼。', - ]; - final colors = [ - '红色', '蓝色', '绿色', '金色', '紫色', '橙色', '粉色', '青色', - ]; - setState(() { - _fortune = fortunes[_rand.nextInt(fortunes.length)]; - _luckyColor = colors[_rand.nextInt(colors.length)]; - _luckyNumber = '${(_rand.nextInt(99)) + 1}'; - _loading = false; - }); - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - backgroundColor: GcColors.appBg, - body: _loading - ? const Center(child: CircularProgressIndicator()) - : Center( - child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 480), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - // 今日人品卡片 - GcCard( - padding: const EdgeInsets.all(GcSpace.xxl), - child: Column( - children: [ - Icon( - Icons.star_rounded, - size: 48, - color: GcColors.accent, - ), - const SizedBox(height: GcSpace.lg), - Text( - T('treasure.fortuneTitle'), - style: const TextStyle( - fontSize: 20, - fontWeight: FontWeight.w700, - ), - ), - const SizedBox(height: GcSpace.md), - Text( - _fortune, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 15, - height: 1.5, - color: GcColors.muted, - ), - ), - ], - ), - ), - const SizedBox(height: GcSpace.lg), - // 幸运信息 - Wrap( - spacing: GcSpace.md, - runSpacing: GcSpace.md, - children: [ - _buildStatCard( - icon: Icons.check_circle_outline_rounded, - label: T('treasure.luckyColor'), - value: _luckyColor, - ), - _buildStatCard( - icon: Icons.numbers_rounded, - label: T('treasure.luckyNumber'), - value: _luckyNumber, - ), - ], - ), - const SizedBox(height: GcSpace.xl), - // 刷新按钮 - FilledButton.icon( - onPressed: _refresh, - icon: const Icon(Icons.refresh_rounded, size: 18), - label: Text(T('treasure.refresh')), - ), - ], - ), - ), - ), - ); - } - - Widget _buildStatCard({ - required IconData icon, - required String label, - required String value, - }) { - return GcCard( - padding: const EdgeInsets.all(GcSpace.lg), - child: Column( - children: [ - Icon(icon, size: 28, color: GcColors.accent), - const SizedBox(height: GcSpace.sm), - Text( - label, - style: TextStyle(fontSize: 12, color: GcColors.muted), - ), - const SizedBox(height: GcSpace.xs), - Text( - value, - style: const TextStyle( - fontSize: 20, - fontWeight: FontWeight.w700, - ), - ), - ], - ), - ); - } -} diff --git a/GC-UI/frontend/lib/pages/user_page.dart b/GC-UI/frontend/lib/pages/user_page.dart index a5f95dc..02ed444 100644 --- a/GC-UI/frontend/lib/pages/user_page.dart +++ b/GC-UI/frontend/lib/pages/user_page.dart @@ -169,7 +169,7 @@ class _UserPageState extends State { _user = null; _fortune = null; }); - GcPalette.apply('#${ThemeColor.defaultHex}'); + GcPalette.accent.value = GcPalette.defaultAccent; _toast(T('user.logoutDone')); } diff --git a/GC-UI/frontend/lib/shell.dart b/GC-UI/frontend/lib/shell.dart index ced70f5..120a3fc 100644 --- a/GC-UI/frontend/lib/shell.dart +++ b/GC-UI/frontend/lib/shell.dart @@ -20,7 +20,6 @@ const List<_NavItem> _navItems = <_NavItem>[ _NavItem(Icons.download_rounded, 'nav.download'), _NavItem(Icons.tune_rounded, 'nav.settings'), _NavItem(Icons.info_outline_rounded, 'nav.about'), - _NavItem(Icons.auto_awesome_rounded, 'nav.treasure'), _NavItem(Icons.person_rounded, 'nav.user'), ]; @@ -148,8 +147,6 @@ class _ShellPageState extends State { case 4: return AboutPageView(controller: controller); case 5: - return TreasurePage(controller: controller); - case 6: return UserPage(controller: controller); default: return HomePageView(controller: controller); -- 2.54.0 From cfd68097145fbf9efee4ce8f1d4a28b06e781e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9C=E5=BD=B1=E7=A7=91=E6=8A=80?= Date: Sat, 21 Nov 2026 21:51:34 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E6=A8=A1=E5=9E=8B=E5=9B=9E?= =?UTF-8?q?=E9=80=80=20Avalonia=20=E7=8B=AC=E7=AB=8B=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=EF=BC=9B=E7=A7=AF=E5=88=86=E7=B2=BE=E7=A1=AE=E5=88=B0=200.01?= =?UTF-8?q?=EF=BC=9B=E4=BA=BA=E5=93=81=E5=80=BC/=E4=BA=8C=E9=80=89?= =?UTF-8?q?=E4=B8=80=E6=8E=A5=E5=85=A5=E5=90=8E=E7=AB=AF=E8=AE=A1=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 模型(回退 Flutter 内嵌 → Avalonia): - 恢复 model/_sdk、5 个模型 src/、GC-DRAW/PlayerWindow、ModelHost/AvaloniaHost(源自 5b62897) - FlutterShell 主线程承载 Avalonia 事件循环,根治 1.1.1 的 AppKit 崩溃 - /api/models/{id}/launch 由后端开独立 Avalonia 窗口 - 前端删除 Flutter 模型实现与 ModelViewPage 死代码(13 个文件) 积分: - Points/ThemePaid int → decimal,精确到 0.01;pw.yaml 兼容旧整数格式 - 主题色退款保留 2 位小数;前端新增 formatPoints 显示 人品值/二选一计费(原前端本地免费随机 → 后端计费): - 新增 POST /api/user/fortune、/api/user/pick,随机数与扣费都在服务端 - 人品值阶梯:当日免费 1 次 → 0.1×5 → 0.2×5 → 0.5×15 → 1.0 起 - 二选一:当日免费 1 次 → 0.5/次;计数按 UTC 日期持久化,跨天清零 - 前端两个功能需登录,扣费后提示本次消耗 附 RELEASE-1.1.2.md 更新日志。 --- .workbuddy/memory/2026-11-21.md | 53 + Directory.Build.props | 4 + GC-BOOT/FlutterShell.cs | 34 +- GC-DRAW/PlayerWindow.cs | 642 ++++++++++ GC-UI/backend/GC.UI.Server/ApiModels.cs | 3 + GC-UI/backend/GC.UI.Server/AvaloniaHost.cs | 180 +++ GC-UI/backend/GC.UI.Server/BackendServer.cs | 77 +- GC-UI/backend/GC.UI.Server/UserService.cs | 177 ++- GC-UI/frontend/lib/api_client.dart | 13 + GC-UI/frontend/lib/controller.dart | 20 +- GC-UI/frontend/lib/models/base.dart | 11 - .../frontend/lib/models/contour_flutter.dart | 378 ------ GC-UI/frontend/lib/models/contour_model.dart | 27 - .../lib/models/geography_flutter.dart | 376 ------ .../frontend/lib/models/geography_model.dart | 67 - GC-UI/frontend/lib/models/lookup.dart | 25 - GC-UI/frontend/lib/models/registry.dart | 37 - .../lib/models/revolution_flutter.dart | 252 ---- .../frontend/lib/models/revolution_model.dart | 39 - .../frontend/lib/models/rotation_flutter.dart | 330 ----- GC-UI/frontend/lib/models/scale_flutter.dart | 217 ---- GC-UI/frontend/lib/models/scale_model.dart | 27 - GC-UI/frontend/lib/models/user.dart | 18 +- GC-UI/frontend/lib/pages/home.dart | 2 + GC-UI/frontend/lib/pages/model_view.dart | 119 -- GC-UI/frontend/lib/pages/user_page.dart | 54 +- GC/src/GC.Core.csproj | 13 +- GC/src/Services/AppServices.cs | 3 + GC/src/Services/ModelHost.cs | 300 +++++ RELEASE-1.1.2.md | 158 +++ model/_sdk/GC.ModelSdk/GC.ModelSdk.csproj | 17 + model/_sdk/GC.ModelSdk/IModelContracts.cs | 77 ++ model/contour-map/src/ContourMapModel.csproj | 23 + model/contour-map/src/ContourMapRuntime.cs | 96 ++ model/contour-map/src/ContourPage.cs | 721 +++++++++++ model/contour-map/src/ContourView.cs | 1130 +++++++++++++++++ model/contour-map/src/DefaultTexts.cs | 225 ++++ model/contour-map/src/TerrainAnalyzer.cs | 194 +++ model/contour-map/src/TerrainField.cs | 707 +++++++++++ .../src/EarthGeographyModel.csproj | 29 + model/earth-geography/src/GeoModels.cs | 96 ++ model/earth-geography/src/GeographyRuntime.cs | 270 ++++ model/earth-geography/src/GeographyView.cs | 916 +++++++++++++ .../src/EarthRevolutionModel.csproj | 28 + .../src/RevolutionModelFactory.cs | 11 + .../src/EarthRotationModel.csproj | 28 + .../src/RotationModelFactory.cs | 11 + model/scale-calculator/src/DefaultTexts.cs | 251 ++++ .../src/ScaleCalculatorFactory.cs | 10 + .../src/ScaleCalculatorModel.csproj | 24 + .../src/ScaleCalculatorRuntime.cs | 78 ++ .../src/ScaleCalculatorView.Layout.cs | 489 +++++++ .../src/ScaleCalculatorView.Logic.cs | 312 +++++ .../src/ScaleCalculatorView.cs | 141 ++ model/scale-calculator/src/ScaleData.cs | 88 ++ model/scale-calculator/src/ScaleMath.cs | 291 +++++ model/scale-calculator/src/ScaleRuler.cs | 347 +++++ 57 files changed, 8300 insertions(+), 1966 deletions(-) create mode 100644 GC-DRAW/PlayerWindow.cs create mode 100644 GC-UI/backend/GC.UI.Server/AvaloniaHost.cs delete mode 100644 GC-UI/frontend/lib/models/base.dart delete mode 100644 GC-UI/frontend/lib/models/contour_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/contour_model.dart delete mode 100644 GC-UI/frontend/lib/models/geography_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/geography_model.dart delete mode 100644 GC-UI/frontend/lib/models/lookup.dart delete mode 100644 GC-UI/frontend/lib/models/registry.dart delete mode 100644 GC-UI/frontend/lib/models/revolution_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/revolution_model.dart delete mode 100644 GC-UI/frontend/lib/models/rotation_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/scale_flutter.dart delete mode 100644 GC-UI/frontend/lib/models/scale_model.dart delete mode 100644 GC-UI/frontend/lib/pages/model_view.dart create mode 100644 GC/src/Services/ModelHost.cs create mode 100644 RELEASE-1.1.2.md create mode 100644 model/_sdk/GC.ModelSdk/GC.ModelSdk.csproj create mode 100644 model/_sdk/GC.ModelSdk/IModelContracts.cs create mode 100644 model/contour-map/src/ContourMapModel.csproj create mode 100644 model/contour-map/src/ContourMapRuntime.cs create mode 100644 model/contour-map/src/ContourPage.cs create mode 100644 model/contour-map/src/ContourView.cs create mode 100644 model/contour-map/src/DefaultTexts.cs create mode 100644 model/contour-map/src/TerrainAnalyzer.cs create mode 100644 model/contour-map/src/TerrainField.cs create mode 100644 model/earth-geography/src/EarthGeographyModel.csproj create mode 100644 model/earth-geography/src/GeoModels.cs create mode 100644 model/earth-geography/src/GeographyRuntime.cs create mode 100644 model/earth-geography/src/GeographyView.cs create mode 100644 model/earth-revolution/src/EarthRevolutionModel.csproj create mode 100644 model/earth-revolution/src/RevolutionModelFactory.cs create mode 100644 model/earth-rotation/src/EarthRotationModel.csproj create mode 100644 model/earth-rotation/src/RotationModelFactory.cs create mode 100644 model/scale-calculator/src/DefaultTexts.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorFactory.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorModel.csproj create mode 100644 model/scale-calculator/src/ScaleCalculatorRuntime.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorView.Layout.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorView.Logic.cs create mode 100644 model/scale-calculator/src/ScaleCalculatorView.cs create mode 100644 model/scale-calculator/src/ScaleData.cs create mode 100644 model/scale-calculator/src/ScaleMath.cs create mode 100644 model/scale-calculator/src/ScaleRuler.cs diff --git a/.workbuddy/memory/2026-11-21.md b/.workbuddy/memory/2026-11-21.md index 7fe8705..5f10f5b 100644 --- a/.workbuddy/memory/2026-11-21.md +++ b/.workbuddy/memory/2026-11-21.md @@ -264,3 +264,56 @@ mingw-w64 14.0.0_3 携带 GCC 16.2,与 Flutter 插件(flutter_inappwebview_w ### 修正(19:17) - 夜间构建 tag 改为 **`nightly`**(concurrency 组 `release-nightly`); `@build-bot` 手动触发仍是 **`ip-prerelease`**(组 `release-ip-prerelease`)。两个 tag 互不覆盖。 + +## 用户系统重做(20:30) +分支 `feat/user-system`,提交 ecb71ad。GitHub 直接推 main,XHGit 开 PR #39。 + +### 存储 +- `.GC/user/<用户名>/pw.yaml`:username / pw_hash(sha512+salt) / points / last_sign_in / consecutive_days / theme_color / theme_paid / theme_paid_at +- `.GC/user/user.yaml`:username + session_token,后端启动自动登录(前端不需要自己找 .GC) +- 旧 `.GC/user/<用户名>.yaml` 启动时自动迁移 + +### 关键实现 +- 验证码:`_captchas` 内存字典,算术题 5 分钟、一次性(TryRemove) +- 签到奖励:1-6:10 / 7:30 / 8-13:15 / 14:40 / 15-20:20 / 21:50 / 22-27:25 / 28:60 / 29:40 / 30:100 +- 主题色:ThemeCost() 服务端算价(默认蓝 0 / 预置 50 / 其它 150);1 小时内换色退 floor(theme_paid*0.8) +- 前端:GcPalette.apply('#hex') 应用用户主题色;人品值纯客户端随机,不限次 + +### 踩坑 +- `flutter build macos` 没有 --no-codesign(iOS 才有),已从 flutter.sh 与两个 workflow 移除 +- `GcColors.appBg` 是 getter,不能放进 const Widget +- CaptchaInfo 在 api_client.dart,user_page 需要单独 import + +## 删百宝箱 + 设置页去主题色(20:47,提交 38781c9) +- 删除 `pages/treasure.dart`、侧栏 `nav.treasure` 入口、`pages.dart` 导出、i18n 的 treasure.* 键 +- 侧栏索引变化:user 从 6 → 5(download=2 / settings=3 不受影响,home.dart 里的 goTo 无需改) +- `settings.dart`:删掉主题色色板、自定义颜色对话、`_accentSwatch` / `_customAccentChip` / `_pickCustomAccent` / `_applyAccent`,以及 i18n 的 set.accent.* +- 强调色唯一来源改为用户账号:`controller._applySettings` 不再用 `settings.accentColor`; + 启动 `_applyUserTheme()` 拉 `/api/user/me` 上色;退出登录回落 `GcPalette.defaultAccent` +- 注意:后端 SettingsInfo 仍保留 accentColor 字段(未删,避免破坏旧配置与 API 兼容) + +## 模型回退 Avalonia + 积分计费改造(21:05–21:35) + +### 1. 模型从 Flutter 回退 Avalonia(方案 B) +- 恢复源:5b62897(Flutter 重写前最后的 Avalonia 模型版本)→ `model/_sdk`、5 个模型的 `src/`、`GC-DRAW/PlayerWindow.cs`、`ModelHost.cs`、`AvaloniaHost.cs` +- `FlutterShell.cs`:主线程跑 Avalonia 事件循环(`uiHost.RunOnCurrentThread()`),修复 1.1.1 的 AppKit 主线程崩溃 +- `BackendServer.cs`:`/api/models/{id}/launch` 走 `host.LaunchAsync(package)` 开 Avalonia 窗口 +- `GC.Core.csproj` 重新引用 Avalonia/MVVM/GC.ModelSdk;`Directory.Build.props` 加 AvaloniaVersion +- 前端清理死代码:删 `pages/model_view.dart` + `lib/models/` 12 个 Flutter 模型文件(保留 user.dart),controller 删 `activeModelId/openModel/closeModel` +- GC.sln 全量编译通过;flutter analyze 0 error + +### 2. 积分精确到 0.01 +- `UserRecord.Points/ThemePaid`:int → decimal;pw.yaml 用 `ToString("0.##")` 写,decimal.TryParse 读(兼容旧整数) +- 主题色退款改 `Math.Floor(paid * 0.8 * 100) / 100` 保 2 位 +- 前端 `points/themePaid` int → double,新增顶层 `formatPoints()`(整数不带小数、去尾零) + +### 3. 人品值 / 二选一 后端计费(原先前端本地随机免费) +- pw.yaml 新增 `fortune_date/fortune_count/pick_date/pick_count`(UTC 日期跨天清零) +- 阶梯(按当日已付费次数):免费1次 → 0.1×5 → 0.2×5 → 0.5×15 → 1.0 起;二选一免费1次 → 0.5/次 +- 端点 `POST /api/user/fortune`、`POST /api/user/pick`(服务端随机数);FortuneComment 评语后端生成 +- 前端 `_rollFortune/_pickRandom` 改走 API,需登录,toast 显示本次消耗 + +### 端到端验证(GC_UI_PORT=18999) +- 注册→签到(10分)→连摇27次:费用 0/0.1×5/0.2×5/0.5×15/1.0,余额始终精确到 0.01,10 分花到 0 +- 二选一首免、余额不足报「积分不足,本次需要 0.5 积分」(400) +- 重启进程后 user.yaml 自动登录 + 当日计数持久化生效;测试账号 billtest 已删 diff --git a/Directory.Build.props b/Directory.Build.props index 6f7eb39..2cafea2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,6 +14,10 @@ enable disable 8.2.2 + + 11.3.9 1.1.2 Morris GC diff --git a/GC-BOOT/FlutterShell.cs b/GC-BOOT/FlutterShell.cs index 7f65921..8437717 100644 --- a/GC-BOOT/FlutterShell.cs +++ b/GC-BOOT/FlutterShell.cs @@ -54,6 +54,7 @@ internal static class FlutterShell Environment.SetEnvironmentVariable(Services.GcUiContract.TokenEnvVar, token); var port = Port; + AvaloniaHost? uiHost = null; // 用户可能重复启动:只有当端口上已有一个「持有同一令牌」的后端时才复用。 // 同机其他程序即便占端口并返回 200,也没有令牌,会被 IsHealthy 拒绝, @@ -67,13 +68,14 @@ internal static class FlutterShell for (var candidate = start; candidate < start + Services.GcUiContract.PortScanRange; candidate++) { - var app = TryStartBackend(args, candidate); + var app = TryStartBackend(args, candidate, out var host); if (app == null) continue; if (WaitHealthy(candidate, token, TimeSpan.FromSeconds(25))) { port = candidate; _backend = app; + uiHost = host; break; } @@ -93,9 +95,27 @@ internal static class FlutterShell return false; } - // 前端窗口已拉起。这里不再需要 AppKit 事件循环:模型已经全部在 Flutter 里渲染, - // 后端只是纯 HTTP 服务,主线程阻塞等它退出即可。 + // 前端窗口已拉起。模型窗口由 Avalonia 承载,而 macOS 的 AppKit 要求 + // NSApplication 必须在**主线程**——所以事件循环要跑在这里(当前正是主线程), + // 不能丢到副线程,否则一点「启动模型」就会把整个后端带崩。 ui.EnableRaisingEvents = true; + var closed = 0; + void RequestClose() + { + if (Interlocked.Exchange(ref closed, 1) == 1) return; + uiHost?.Shutdown(); + } + + ui.Exited += (_, _) => RequestClose(); + if (ui.HasExited) RequestClose(); + + if (!ui.HasExited && uiHost != null) + { + // 阻塞直到界面退出(或图形环境初始化失败)。 + uiHost.RunOnCurrentThread(); + } + + // Avalonia 起不来(无桌面会话)时仍要等界面退出,避免后端被提前收掉。 if (!ui.HasExited) ui.WaitForExit(); StopBackend(_backend); @@ -158,16 +178,20 @@ internal static class FlutterShell // ---------------------------------------------------------------- 进程管理 /// 在本进程内启动后端;端口被占用等失败情况返回 null。 - private static WebApplication? TryStartBackend(string[] args, int port) + /// 成功时交出模型窗口宿主,由调用方在主线程跑事件循环。 + private static WebApplication? TryStartBackend(string[] args, int port, out AvaloniaHost? uiHost) { + uiHost = null; try { - var app = BackendServer.Start(args, port); + var app = BackendServer.Start(args, port, out var host); + uiHost = host; app.StartAsync().GetAwaiter().GetResult(); return app; } catch (Exception ex) { + uiHost = null; Console.Error.WriteLine($"[shell] 后端启动失败(端口 {port}): {ex.Message}"); return null; } diff --git a/GC-DRAW/PlayerWindow.cs b/GC-DRAW/PlayerWindow.cs new file mode 100644 index 0000000..c3f8139 --- /dev/null +++ b/GC-DRAW/PlayerWindow.cs @@ -0,0 +1,642 @@ +using System; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.Json; +using Avalonia; +using Avalonia.Animation; +using Avalonia.Animation.Easings; +using Avalonia.Controls; +using Avalonia.Input; +using Avalonia.Layout; +using Avalonia.Media; +using Shapes = Avalonia.Controls.Shapes; +using Avalonia.VisualTree; +using GC.Models; +using GC.Services; + +namespace GC.Views; + +/// +/// 模型窗口:**只做窗口宿主**。 +/// 内容完全来自模型程序集(),启动器不渲染任何东西。 +/// 快捷键:Esc 关闭窗口,F11 全屏。 +/// +public sealed class PlayerWindow : Window +{ + private LoadedModel? _model; + private bool _closing; + private Button? _maximizeButton; + private Border? _frame; + private TextBlock? _titleText; + private Border? _titleBar; + private readonly List