diff --git a/model/contour-map/contour-map.json b/model/contour-map/contour-map.json index f88deb2..c40cc46 100644 --- a/model/contour-map/contour-map.json +++ b/model/contour-map/contour-map.json @@ -25,6 +25,6 @@ "button": "#9FB4D4", "frame": "#0A1524" }, - "updatedAt": "2026-11-14T01:23:14Z", - "build": "e7f837d0ef" + "updatedAt": "2026-11-14T01:56:57Z", + "build": "2baf95e031" } diff --git a/model/contour-map/contour-map.model/ContourMapModel.dll b/model/contour-map/contour-map.model/ContourMapModel.dll index 9ed368d..e8e7e87 100644 Binary files a/model/contour-map/contour-map.model/ContourMapModel.dll and b/model/contour-map/contour-map.model/ContourMapModel.dll differ diff --git a/model/contour-map/contour-map.model/help.json b/model/contour-map/contour-map.model/help.json new file mode 100644 index 0000000..aabf688 --- /dev/null +++ b/model/contour-map/contour-map.model/help.json @@ -0,0 +1,110 @@ +{ + "zh-CN": { + "title": "如何使用 · 等高线地形图", + "sections": [ + { + "h": "开始使用(跟着做)", + "lines": [ + "第 1 步:顶部选一种地形(山地 / 盆地 / 丘陵 / 高原 / 平原),画面会换成对应的等高线图。", + "第 2 步:把鼠标移到图上任意位置,底部会显示该点的海拔、相对高度和地形部位。", + "第 3 步:观察左边的立体地形与右边的等高线图,找出同一个山峰,看它在两张图上分别长什么样。", + "第 4 步:点右下角「取消上色」,只留等高线;再点一次恢复分层设色,对比哪种更便于判读。", + "第 5 步:对着右侧的判读要点,依次在图上找出一个山峰、一条山脊、一条山谷、一处鞍部和一处陡崖。" + ] + }, + { + "h": "等高线是什么", + "lines": [ + "在地图上,把海拔相同的点用线连起来,这条线就叫等高线。", + "相邻两条等高线之间的高差叫等高距:本图山地、高原、盆地用 100 米,丘陵用 10 米,平原用 5 米。", + "等高线的闭合圈,数值由中心向四周递减的是山峰;四周高中间低的是盆地。", + "等高线向海拔低处凸出的是山脊(分水线);向海拔高处凸出的是山谷(集水线)。", + "两个山峰之间低下去的地方叫鞍部;等高线重叠或挤成一团的地方是陡崖。", + "等高线越密,坡度越陡;越疏,坡度越缓。", + "每 5 条等高线加粗一条叫计曲线,上面标着海拔,方便读数。" + ] + }, + { + "h": "海拔与相对高度", + "lines": [ + "海拔:地面某一点高出海平面的垂直距离。", + "相对高度:两个地点海拔的差值,也就是图上两点的落差。", + "底部读数里的「相对高度」是本图最低点到该点的高差。" + ] + }, + { + "h": "五种地体的等高线特征", + "lines": [ + "山地:海拔高、起伏大,等高线密集且数值跨度大。", + "盆地:四周高、中间低,等高线由外向内数值递减,常有河流发育。", + "丘陵:海拔不高、坡度和缓,等高线稀疏弯曲。", + "高原:海拔高而顶面平坦,等高线中部稀疏、边缘密集。", + "平原:海拔低、地面平坦,等高线很少甚至没有。" + ] + }, + { + "h": "容易出错的地方", + "lines": [ + "把「等高线密集 = 陡」记反:密集是陡,稀疏是缓。", + "把山脊和山谷看反:看凸出的方向 —— 凸向低处是山脊,凸向高处是山谷。", + "忽视等高距:等高距变了,同样的等高线密度代表的坡度就不同。", + "把计曲线当成普通等高线:计曲线加粗并标了数值,读高程要看它。" + ] + } + ] + }, + "en": { + "title": "How to use · Contour Map", + "sections": [ + { + "h": "Getting started (follow along)", + "lines": [ + "Step 1: pick a terrain type at the top (mountains / basin / hills / plateau / plain) — the map switches to its contour map.", + "Step 2: move the pointer anywhere on the map; the footer shows elevation, relative height and the terrain feature.", + "Step 3: compare the 3D block on the left with the contour map on the right — find the same peak in both.", + "Step 4: click “No colour” at the bottom right to keep only the contour lines; click again to restore the colour fill.", + "Step 5: using the panel on the right, find one peak, one ridge, one valley, one saddle and one cliff." + ] + }, + { + "h": "What contour lines are", + "lines": [ + "Connect points of equal elevation on a map and you get a contour line.", + "The height gap between neighbouring contours is the contour interval: 100 m for mountains, plateau and basin; 10 m for hills; 5 m for plain.", + "A closed loop whose values decrease outward is a peak; high ground around a low centre is a basin.", + "Contours bulging toward lower ground form a ridge (watershed); bulging toward higher ground form a valley (drainage).", + "The low ground between two peaks is a saddle; overlapping or tightly crowded contours mark a cliff.", + "The closer the contours, the steeper the slope; the wider apart, the gentler.", + "Every 5th contour is bolded as an index contour and labelled with its elevation." + ] + }, + { + "h": "Elevation and relative height", + "lines": [ + "Elevation is the vertical height of a point above sea level.", + "Relative height is the difference between two elevations — the drop between two points on the map.", + "The relative height in the footer is measured from the lowest point of this map." + ] + }, + { + "h": "Contour patterns of the five terrains", + "lines": [ + "Mountains: high elevation, large relief, dense contours over a wide value range.", + "Basin: high rim, low centre; values decrease inward, often with a river.", + "Hills: low elevation, gentle slopes, sparse winding contours.", + "Plateau: high but flat on top — contours sparse in the middle and crowded at the edges.", + "Plain: low and flat — few or no contour lines at all." + ] + }, + { + "h": "Common mistakes", + "lines": [ + "Reversing dense and sparse: dense means steep, sparse means gentle.", + "Mixing up ridge and valley — look which way the bulge points: toward lower ground is a ridge, toward higher ground is a valley.", + "Ignoring the contour interval: change it and the same spacing means a different slope.", + "Treating index contours as ordinary ones — they are bold and labelled, so read elevations off them." + ] + } + ] + } +} diff --git a/model/contour-map/contour-map.model/preview.png b/model/contour-map/contour-map.model/preview.png index 1d7545e..687f635 100644 Binary files a/model/contour-map/contour-map.model/preview.png and b/model/contour-map/contour-map.model/preview.png differ diff --git a/model/contour-map/src/ContourMapRuntime.cs b/model/contour-map/src/ContourMapRuntime.cs index 38697d9..72769b6 100644 --- a/model/contour-map/src/ContourMapRuntime.cs +++ b/model/contour-map/src/ContourMapRuntime.cs @@ -28,21 +28,21 @@ public sealed class ContourMapRuntime : IModelRuntime public void Prepare(IModelContext context) { context.ReportProgress(0.15, "生成地形高度场"); - _field = new TerrainField(192); + _field = new TerrainField(TerrainKind.Mountain, 192); context.ReportProgress(0.70, "提取等高线"); _texts = LoadTexts(context.DataDirectory, context.Language); context.ReportProgress(0.92, "准备界面"); context.Log($"[contour-map] 地形 {_field.Size}×{_field.Size}," + - $"海拔 {_field.MinHeight:0}~{_field.MaxHeight:0} m,等高距 {_field.Interval:0} m"); + $"海拔 {_field.MinHeight:0}~{_field.MaxHeight:0} m,等高距 {_field.EffectiveInterval:0} m"); } public Control CreateView(IModelContext context) { - _field ??= new TerrainField(192); _texts ??= LoadTexts(context.DataDirectory, context.Language); - return new ContourPage(_field, _texts).Build(); + // 五种地体都在界面里现场生成(切换很快,不必预先生成全部) + return new ContourPage(_texts).Build(); } public void Dispose() diff --git a/model/contour-map/src/ContourPage.cs b/model/contour-map/src/ContourPage.cs index 7d68335..3418bab 100644 --- a/model/contour-map/src/ContourPage.cs +++ b/model/contour-map/src/ContourPage.cs @@ -20,16 +20,31 @@ public sealed class ContourPage private static readonly Color CWarn = Color.Parse("#FFB454"); private static readonly Color CGood = Color.Parse("#5FD69B"); - private readonly TerrainField _field; + private TerrainField _field; private readonly Dictionary _texts; + private readonly Dictionary _cache = new(); + private Border? _colorBtn; + private TextBlock? _colorBtnText; + private TerrainKind _kind = TerrainKind.Mountain; private ContourView? _view; private TextBlock? _readout; private TextBlock? _featureText; - public ContourPage(TerrainField field, Dictionary texts) + public ContourPage(Dictionary texts) { - _field = field; _texts = texts; + _field = GetField(TerrainKind.Mountain); + } + + /// 取(并缓存)某类地体的高度场,切换时不重复计算。 + private TerrainField GetField(TerrainKind kind) + { + if (!_cache.TryGetValue(kind, out var f)) + { + f = new TerrainField(kind, 192); + _cache[kind] = f; + } + return f; } private string T(string key) => _texts.TryGetValue(key, out var v) ? v : key; @@ -95,16 +110,84 @@ public sealed class ContourPage stack.Children.Add(title); stack.Children.Add(sub); + // 地体类型选择:教科书里的五种基本地形 + var kinds = new (TerrainKind Kind, string Key)[] + { + (TerrainKind.Mountain, "kind.mountain"), + (TerrainKind.Basin, "kind.basin"), + (TerrainKind.Hill, "kind.hill"), + (TerrainKind.Plateau, "kind.plateau"), + (TerrainKind.Plain, "kind.plain"), + }; + + var tabs = new StackPanel + { + Orientation = Orientation.Horizontal, + Spacing = 6, + Margin = new Thickness(0, 9, 0, 0) + }; + foreach (var (kind, key) in kinds) + { + var btn = MakeKindTab(kind, T(key)); + tabs.Children.Add(btn); + } + + var header = new StackPanel(); + header.Children.Add(stack); + header.Children.Add(tabs); + return new Border { Background = B(CPanel), BorderBrush = B(CLine), BorderThickness = new Thickness(0, 0, 0, 1), - Padding = new Thickness(18, 11), - Child = stack + Padding = new Thickness(18, 11, 18, 12), + Child = header }; } + /// 地体类型按钮:选中高亮。 + private Button MakeKindTab(TerrainKind kind, string label) + { + var b = new Button + { + Content = label, + FontSize = 11.5, + Padding = new Thickness(13, 5), + CornerRadius = new CornerRadius(8), + BorderThickness = new Thickness(1), + Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand), + Tag = kind + }; + + void Style() + { + var on = _kind == kind; + b.Background = B(on ? CAccent : Color.Parse("#16263C")); + b.BorderBrush = B(on ? CAccent : Color.Parse("#263A56")); + b.Foreground = B(on ? Colors.White : CInkDim); + } + Style(); + + b.Click += (_, _) => + { + _kind = kind; + _field = GetField(kind); + _view?.SetField(_field); + // 重新刷新所有 tab 的选中态 + if (b.Parent is StackPanel sp) + foreach (var c in sp.Children) + if (c is Button sib && sib.Tag is TerrainKind) + { + var on = (TerrainKind)sib.Tag == _kind; + sib.Background = B(on ? CAccent : Color.Parse("#16263C")); + sib.BorderBrush = B(on ? CAccent : Color.Parse("#263A56")); + sib.Foreground = B(on ? Colors.White : CInkDim); + } + }; + return b; + } + private Control BuildSidePanel() { var panel = new StackPanel { Spacing = 10, Margin = new Thickness(12, 0, 0, 0) }; @@ -203,8 +286,31 @@ public sealed class ContourPage HorizontalAlignment = HorizontalAlignment.Right }; + // 右下角「上色」开关:点击一次去掉分层设色,只显示线稿,再点恢复 + _colorBtnText = new TextBlock + { + Text = T("btn.color"), + FontSize = 11.5, + Foreground = B(Colors.White) + }; + _colorBtn = new Border + { + Background = B(CAccent), + CornerRadius = new CornerRadius(8), + Padding = new Thickness(13, 6), + Margin = new Thickness(0, 0, 12, 0), + Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand), + Child = _colorBtnText + }; + _colorBtn.PointerPressed += (_, _) => ToggleColor(); + + var left = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") }; + left.Children.Add(_readout); + Grid.SetColumn(_colorBtn, 1); + left.Children.Add(_colorBtn); + var row = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") }; - row.Children.Add(_readout); + row.Children.Add(left); Grid.SetColumn(_featureText, 1); row.Children.Add(_featureText); @@ -218,6 +324,17 @@ public sealed class ContourPage }; } + /// 切换分层设色。 + private void ToggleColor() + { + if (_view == null) return; + _view.Colored = !_view.Colored; + if (_colorBtn != null) + _colorBtn.Background = B(_view.Colored ? CAccent : Color.Parse("#2A3B55")); + if (_colorBtnText != null) + _colorBtnText.Text = _view.Colored ? T("btn.colorOn") : T("btn.color"); + } + private void OnHover(double u, double v, float height, TerrainFeature feature) { if (_readout == null || _featureText == null) return; diff --git a/model/contour-map/src/ContourView.cs b/model/contour-map/src/ContourView.cs index 8a2b7b4..4d49e2e 100644 --- a/model/contour-map/src/ContourView.cs +++ b/model/contour-map/src/ContourView.cs @@ -27,7 +27,18 @@ public sealed class ContourView : Control private static readonly Typeface Font = new("Noto Sans CJK SC, Microsoft YaHei, Arial"); - public TerrainField Field { get; } + public TerrainField Field { get; private set; } + + /// 切换到另一块地形(重新提取等高线)。 + public void SetField(TerrainField field) + { + Field = field; + _levels = Field.ContourLevels(); + _contours.Clear(); + foreach (var lv in _levels) + _contours.Add((lv, Field.ExtractContour(lv))); + InvalidateVisual(); + } /// 等高线缓存:level -> 折线集合。 private readonly List<(float Level, List> Lines)> _contours = new(); @@ -42,6 +53,7 @@ public sealed class ContourView : Control private bool _showContours = true; private bool _showLabels = true; private bool _showSlope = true; + private bool _colored = true; public bool ShowContours { @@ -61,6 +73,13 @@ public sealed class ContourView : Control set => SetFlag(ref _showSlope, value); } + /// 是否分层设色(关闭后只看线稿,便于观察等高线本身)。 + public bool Colored + { + get => _colored; + set => SetFlag(ref _colored, value); + } + private void SetFlag(ref bool slot, bool value) { if (slot == value) return; @@ -234,7 +253,9 @@ public sealed class ContourView : Control var u = (i + 0.5) / N; var v = (j + 0.5) / N; var h = Field.SampleSmooth(u, v); var (cr, cg, cb) = TerrainAnalyzer.ColorForHeight(h, Field.MinHeight, Field.MaxHeight); - var brush = new SolidColorBrush(Color.FromRgb(cr, cg, cb)); + var brush = _colored + ? new SolidColorBrush(Color.FromRgb(cr, cg, cb)) + : new SolidColorBrush(Color.Parse("#F3F0E6")); dc.FillRectangle(brush, new Rect( r.X + r.Width * i / N, r.Y + r.Height * j / N, diff --git a/model/contour-map/src/DefaultTexts.cs b/model/contour-map/src/DefaultTexts.cs index cda4054..067fea2 100644 --- a/model/contour-map/src/DefaultTexts.cs +++ b/model/contour-map/src/DefaultTexts.cs @@ -10,6 +10,14 @@ internal static class DefaultTexts ["app.title"] = "等高线地形图", ["app.subtitle"] = "七年级上册 · 地形图的判读:从立体地形到平面等高线", + ["kind.mountain"] = "山地", + ["kind.basin"] = "盆地", + ["kind.hill"] = "丘陵", + ["kind.plateau"] = "高原", + ["kind.plain"] = "平原", + ["btn.color"] = "上色", + ["btn.colorOn"] = "取消上色", + ["side.features"] = "五种地形部位", ["feature.peak"] = "山峰", ["feature.peakDesc"] = "等高线闭合,数值由中心向四周递减。", @@ -38,6 +46,14 @@ internal static class DefaultTexts ["app.title"] = "Contour Map", ["app.subtitle"] = "Grade 7 · Reading terrain maps: from 3D relief to contour lines", + ["kind.mountain"] = "Mountains", + ["kind.basin"] = "Basin", + ["kind.hill"] = "Hills", + ["kind.plateau"] = "Plateau", + ["kind.plain"] = "Plain", + ["btn.color"] = "Colour", + ["btn.colorOn"] = "No colour", + ["side.features"] = "Five terrain features", ["feature.peak"] = "Peak", ["feature.peakDesc"] = "Closed contours; values decrease outward from the centre.", diff --git a/model/contour-map/src/TerrainField.cs b/model/contour-map/src/TerrainField.cs index 7790b88..53624b6 100644 --- a/model/contour-map/src/TerrainField.cs +++ b/model/contour-map/src/TerrainField.cs @@ -3,6 +3,16 @@ using System.Collections.Generic; namespace NeoRF.ContourMap; +/// 五种基本地形类型(教科书分类)。 +public enum TerrainKind +{ + Mountain, // 山地:海拔高、起伏大 + Basin, // 盆地:四周高、中间低 + Hill, // 丘陵:海拔较低、坡度和缓 + Plateau, // 高原:海拔高、地面平坦、边缘陡 + Plain // 平原:海拔低、地面平坦 +} + /// /// 地形高度场(等高线模型的数据核心)。 /// @@ -29,13 +39,25 @@ public sealed class TerrainField /// 等高距(米):教学图常用 100 m。 public float Interval { get; init; } = 100f; - public TerrainField(int size = 192) + /// 这块地形属于哪种类型(决定界面标题与说明)。 + public TerrainKind Kind { get; } + + public TerrainField(TerrainKind kind = TerrainKind.Mountain, int size = 192) { Size = size; + Kind = kind; Heights = new float[size, size]; - Build(); + Build(kind); } + /// 该类型对应的等高距:平原/丘陵用 20m,山地/高原/盆地用 100m。 + public float EffectiveInterval => Kind switch + { + TerrainKind.Plain => 5f, // 平原起伏小,等高距要小才画得出线 + TerrainKind.Hill => 10f, // 丘陵相对高差约 150 m + _ => 100f + }; + /// 归一化坐标 (u,v) ∈ [0,1],u 向东、v 向南。 public float HeightAt(double u, double v) { @@ -61,7 +83,19 @@ public sealed class TerrainField return (float)(a * (1 - ty) + b * ty); } - private void Build() + private void Build(TerrainKind kind) + { + switch (kind) + { + case TerrainKind.Mountain: BuildMountain(); break; + case TerrainKind.Basin: BuildBasin(); break; + case TerrainKind.Hill: BuildHill(); break; + case TerrainKind.Plateau: BuildPlateau(); break; + case TerrainKind.Plain: BuildPlain(); break; + } + } + + private void BuildMountain() { // 各山体参数:中心(u,v)、高度、东西半径、南北半径 var peaks = new (double U, double V, double H, double RU, double RV)[] @@ -116,6 +150,121 @@ public sealed class TerrainField MaxHeight = max; } + /// 盆地:四周高、中间低,等高线由外向内递减。 + private void BuildBasin() + { + var min = float.MaxValue; var max = float.MinValue; + for (var y = 0; y < Size; y++) + { + for (var x = 0; x < Size; x++) + { + var u = (double)x / (Size - 1); + var v = (double)y / (Size - 1); + var du = u - 0.5; var dv = v - 0.5; + var r = Math.Sqrt(du * du + dv * dv) * 2.0; // 0=中心 1=边缘 + + // 边缘抬升、中心下沉,形成碗状 + double h = 160 + 900 * Math.Pow(Math.Clamp(r, 0, 1.15), 2.2); + // 一侧开个缺口(山口),让盆地向外开口 + var gap = Math.Abs(Math.Atan2(dv, du) - 0.5); + if (gap < 0.35) h -= 320 * (1 - gap / 0.35) * (1 - Math.Clamp(r, 0, 1)); + + h += 14 * Math.Sin(u * 7.3) * Math.Cos(v * 6.1); + var hf = (float)Math.Max(0, h); + Heights[y, x] = hf; + if (hf < min) min = hf; + if (hf > max) max = hf; + } + } + MinHeight = min; MaxHeight = max; + } + + /// 丘陵:起伏和缓、海拔不高,等高线稀疏而弯曲。 + private void BuildHill() + { + var bumps = new (double U, double V, double H, double R)[] + { + (0.30, 0.32, 120, 0.20), (0.66, 0.28, 95, 0.17), + (0.52, 0.62, 140, 0.22), (0.22, 0.72, 88, 0.16), + (0.78, 0.70, 110, 0.18), + }; + var min = float.MaxValue; var max = float.MinValue; + for (var y = 0; y < Size; y++) + { + for (var x = 0; x < Size; x++) + { + var u = (double)x / (Size - 1); + var v = (double)y / (Size - 1); + double h = 60; + foreach (var b in bumps) + { + var du = (u - b.U) / b.R; var dv = (v - b.V) / b.R; + h += b.H * Math.Exp(-(du * du + dv * dv) * 1.3); + } + h += 10 * Math.Sin(u * 11.0) * Math.Cos(v * 9.0); + var hf = (float)Math.Max(0, h); + Heights[y, x] = hf; + if (hf < min) min = hf; + if (hf > max) max = hf; + } + } + MinHeight = min; MaxHeight = max; + } + + /// 高原:顶部平坦、边缘陡峭(等高线在中部稀疏、边缘密集)。 + private void BuildPlateau() + { + var min = float.MaxValue; var max = float.MinValue; + for (var y = 0; y < Size; y++) + { + for (var x = 0; x < Size; x++) + { + var u = (double)x / (Size - 1); + var v = (double)y / (Size - 1); + + // 到中心的距离,做平台 + 陡降 + var du = (u - 0.5); var dv = (v - 0.5); + var r = Math.Sqrt(du * du + dv * dv) * 2.0; + + double h; + if (r < 0.55) h = 1250; // 平坦顶面 + else h = 1250 - 1000 * SmoothStep(0.55, 0.78, r); // 边缘陡降 + + // 顶面轻微起伏,避免完全平板 + if (r < 0.55) h += 25 * Math.Sin(u * 6.0) * Math.Cos(v * 5.0); + h += 30 * (1 - Math.Clamp(r, 0, 1)); + + var hf = (float)Math.Max(0, h); + Heights[y, x] = hf; + if (hf < min) min = hf; + if (hf > max) max = hf; + } + } + MinHeight = min; MaxHeight = max; + } + + /// 平原:地面低平、起伏极小,等高线很少。 + private void BuildPlain() + { + var min = float.MaxValue; var max = float.MinValue; + for (var y = 0; y < Size; y++) + { + for (var x = 0; x < Size; x++) + { + var u = (double)x / (Size - 1); + var v = (double)y / (Size - 1); + + // 整体微倾 + 极缓的起伏 + double h = 40 + 22 * u + 8 * Math.Sin(u * 4.2) * Math.Cos(v * 3.6); + var hf = (float)Math.Max(0, h); + Heights[y, x] = hf; + if (hf < min) min = hf; + if (hf > max) max = hf; + } + } + MinHeight = min; MaxHeight = max; + } + private static double SmoothStep(double a, double b, double x) { var t = Math.Clamp((x - a) / (b - a), 0, 1); @@ -151,9 +300,10 @@ public sealed class TerrainField public List ContourLevels() { var levels = new List(); - var top = (float)(Math.Floor(MaxHeight / Interval) * Interval); - var bottom = (float)(Math.Ceiling(MinHeight / Interval) * Interval); - for (var h = bottom; h <= top + 0.01f; h += Interval) + var iv = EffectiveInterval; + var top = (float)(Math.Floor(MaxHeight / iv) * iv); + var bottom = (float)(Math.Ceiling(MinHeight / iv) * iv); + for (var h = bottom; h <= top + 0.01f; h += iv) levels.Add(h); levels.Sort(); return levels; diff --git a/model/earth-geography/earth-geography.json b/model/earth-geography/earth-geography.json index 1a502f1..59a8a9e 100644 --- a/model/earth-geography/earth-geography.json +++ b/model/earth-geography/earth-geography.json @@ -18,7 +18,7 @@ ], "dataDir": "earth-geography.model", "version": "1.8", - "updatedAt": "2026-11-14T01:23:14Z", + "updatedAt": "2026-11-14T01:56:57Z", "chrome": { "titleBar": "#0C1828", "titleBorder": "#1B2740", @@ -26,5 +26,5 @@ "button": "#9FB4D4", "frame": "#0A1524" }, - "build": "143e56bed8" + "build": "def7ac1a55" } diff --git a/model/earth-revolution/earth-revolution.json b/model/earth-revolution/earth-revolution.json index 9779c5d..6425000 100644 --- a/model/earth-revolution/earth-revolution.json +++ b/model/earth-revolution/earth-revolution.json @@ -24,7 +24,7 @@ "preview": "preview.png", "apiVersion": 1, "version": "1.6", - "updatedAt": "2026-11-14T01:23:14Z", + "updatedAt": "2026-11-14T01:56:57Z", "chrome": { "titleBar": "#0C1828", "titleBorder": "#1B2740", @@ -32,5 +32,5 @@ "button": "#9FB4D4", "frame": "#0A1524" }, - "build": "26a2bd8f68" + "build": "d53a3ed8d0" } diff --git a/model/earth-rotation/earth-rotation.json b/model/earth-rotation/earth-rotation.json index d6c921f..1c52e36 100644 --- a/model/earth-rotation/earth-rotation.json +++ b/model/earth-rotation/earth-rotation.json @@ -24,7 +24,7 @@ "preview": "preview.png", "apiVersion": 1, "version": "1.6", - "updatedAt": "2026-11-14T01:23:14Z", + "updatedAt": "2026-11-14T01:56:57Z", "chrome": { "titleBar": "#0C1828", "titleBorder": "#1B2740", @@ -32,5 +32,5 @@ "button": "#9FB4D4", "frame": "#0A1524" }, - "build": "1a81492baa" + "build": "ea44c4934b" } diff --git a/model/scale-calculator/scale-calculator.json b/model/scale-calculator/scale-calculator.json index 1292c58..11d01c3 100644 --- a/model/scale-calculator/scale-calculator.json +++ b/model/scale-calculator/scale-calculator.json @@ -25,7 +25,7 @@ "preview": "preview.png", "apiVersion": 1, "version": "1.5", - "updatedAt": "2026-11-14T01:23:14Z", + "updatedAt": "2026-11-14T01:56:57Z", "chrome": { "titleBar": "#FFFFFF", "titleBorder": "#E3E8F3", @@ -33,5 +33,5 @@ "button": "#5B6A86", "frame": "#F4F6FB" }, - "build": "79711a44a8" + "build": "c6d584422f" } diff --git a/model/scale-calculator/scale-calculator.model/preview.png b/model/scale-calculator/scale-calculator.model/preview.png index 16ef000..ccbe6a1 100644 Binary files a/model/scale-calculator/scale-calculator.model/preview.png and b/model/scale-calculator/scale-calculator.model/preview.png differ diff --git a/model/version.json b/model/version.json index 452ea3b..8b10331 100644 --- a/model/version.json +++ b/model/version.json @@ -1,12 +1,12 @@ { "schema": 1, - "generated": "2026-11-14T01:23:14Z", + "generated": "2026-11-14T01:56:57Z", "repository": "https://gitcode.com/2509_92447106/GC", "branch": "main", "modelDir": "model", "launcher": { "version": "1.0.6", - "revision": "98cff12092", + "revision": "e1d82a059c", "packages": { "win-x64": { "path": "dist/GC-win-x64.zip", @@ -34,31 +34,31 @@ { "id": "contour-map", "version": "1.0", - "build": "e7f837d0ef", + "build": "2baf95e031", "dir": "model/contour-map" }, { "id": "earth-geography", "version": "1.8", - "build": "143e56bed8", + "build": "def7ac1a55", "dir": "model/earth-geography" }, { "id": "earth-revolution", "version": "1.6", - "build": "26a2bd8f68", + "build": "d53a3ed8d0", "dir": "model/earth-revolution" }, { "id": "earth-rotation", "version": "1.6", - "build": "1a81492baa", + "build": "ea44c4934b", "dir": "model/earth-rotation" }, { "id": "scale-calculator", "version": "1.5", - "build": "79711a44a8", + "build": "c6d584422f", "dir": "model/scale-calculator" } ] diff --git a/src/main/dotnet/EarthModelStudio/App.axaml.cs b/src/main/dotnet/EarthModelStudio/App.axaml.cs index 5aaa32d..55fa637 100644 --- a/src/main/dotnet/EarthModelStudio/App.axaml.cs +++ b/src/main/dotnet/EarthModelStudio/App.axaml.cs @@ -29,9 +29,47 @@ public partial class App : Application return; } - var vm = new MainViewModel(services); - var window = new MainWindow { DataContext = vm }; + // 启动加速:先建空窗口并显示,再在首帧之后构造 ViewModel。 + // MainViewModel 会扫描模型、加载封面、读设置,同步做会让 + // 「双击到看见窗口」明显变慢;先出窗口,内容随后填充。 + var window = new MainWindow(); + window.Show(); + MainViewModel vm = null!; + window.Opened += (_, _) => + { + Avalonia.Threading.Dispatcher.UIThread.Post(() => + { + vm = new MainViewModel(services); + window.DataContext = vm; + WireMainViewModel(vm, window, services, desktop); + }, Avalonia.Threading.DispatcherPriority.Background); + }; + + // 应用图标不依赖 ViewModel,先设好让窗口一出现就有图标 + try + { + using var iconStream = Avalonia.Platform.AssetLoader.Open( + new Uri("avares://EarthModelStudio/Assets/icon.png")); + window.Icon = new Avalonia.Controls.WindowIcon(iconStream); + } + catch { /* 图标缺失不影响启动 */ } + + desktop.MainWindow = window; + desktop.ShutdownMode = ShutdownMode.OnMainWindowClose; + } + + base.OnFrameworkInitializationCompleted(); + } + + /// + /// 主窗口显示后再接上 ViewModel:绑定对话框、启动后台更新检查。 + /// 拆出来是为了让窗口先出现,模型扫描不影响「双击到出窗口」。 + /// + private static void WireMainViewModel(MainViewModel vm, MainWindow window, + AppServices services, IClassicDesktopStyleApplicationLifetime desktop) + { + _ = desktop; vm.ConfirmHandler = async message => { var dialog = new ConfirmWindow(message); @@ -51,28 +89,13 @@ public partial class App : Application return await dialog.ShowDialog(window); }; - // 应用图标:窗口标题栏与任务栏也使用同一图标 - try - { - using var iconStream = Avalonia.Platform.AssetLoader.Open( - new Uri("avares://EarthModelStudio/Assets/icon.png")); - window.Icon = new Avalonia.Controls.WindowIcon(iconStream); - } - catch { /* 图标缺失不影响启动 */ } - - desktop.MainWindow = window; - desktop.ShutdownMode = ShutdownMode.OnMainWindowClose; - - // 主窗口已建好,后台检查模型 / 启动器更新,不阻塞界面 - if (Environment.GetEnvironmentVariable("EMS_NO_UPDATE") != "1") - { - Avalonia.Threading.Dispatcher.UIThread.Post( - () => _ = vm.RunStartupUpdateAsync(), - Avalonia.Threading.DispatcherPriority.Background); - } + // 主窗口已显示,后台检查模型 / 启动器更新,不阻塞界面 + if (Environment.GetEnvironmentVariable("EMS_NO_UPDATE") != "1") + { + Avalonia.Threading.Dispatcher.UIThread.Post( + () => _ = vm.RunStartupUpdateAsync(), + Avalonia.Threading.DispatcherPriority.Background); } - - base.OnFrameworkInitializationCompleted(); } /// 逐个加载模型,打印结果;返回退出码(0 = 全部成功)。 diff --git a/src/main/dotnet/EarthModelStudio/Services/AppPaths.cs b/src/main/dotnet/EarthModelStudio/Services/AppPaths.cs index 6e71768..001ce37 100644 --- a/src/main/dotnet/EarthModelStudio/Services/AppPaths.cs +++ b/src/main/dotnet/EarthModelStudio/Services/AppPaths.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using System.IO; namespace EarthModelStudio.Services; @@ -244,16 +245,21 @@ public sealed class AppPaths Directory.CreateDirectory(ModelRoot); Directory.CreateDirectory(UpdateRoot); - // 开发态:让 .GC/model 与仓库里的模型保持一致(只同步清单 + 数据,不含 src 源码) + // 开发态:让 .GC/model 与仓库里的模型保持一致(只同步清单 + 数据,不含 src 源码)。 + // 放到后台线程:这一步要复制 coastline.json 等大文件,同步做会拖慢启动。 if (IsDevelopment && string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("EMS_MODELS"))) - SyncDevelopmentModels(); + { + var root = HomeRoot; + var source = Path.Combine(AppRoot, "model"); + if (Directory.Exists(source)) + Task.Run(() => SyncDevelopmentModels(root, source)); + } } - private void SyncDevelopmentModels() + private static void SyncDevelopmentModels(string modelRoot, string source) { try { - var source = Path.Combine(AppRoot, "model"); if (!Directory.Exists(source)) return; foreach (var dir in Directory.GetDirectories(source)) { @@ -262,7 +268,7 @@ public sealed class AppPaths var manifest = Path.Combine(dir, id + ".json"); var data = Path.Combine(dir, id + ".model"); if (!File.Exists(manifest) || !Directory.Exists(data)) continue; - var dest = Path.Combine(ModelRoot, id); + var dest = Path.Combine(modelRoot, id); Directory.CreateDirectory(dest); File.Copy(manifest, Path.Combine(dest, id + ".json"), true); CopyTree(data, Path.Combine(dest, id + ".model")); diff --git a/src/main/dotnet/EarthModelStudio/Views/PlayerWindow.cs b/src/main/dotnet/EarthModelStudio/Views/PlayerWindow.cs index c2889af..42f2193 100644 --- a/src/main/dotnet/EarthModelStudio/Views/PlayerWindow.cs +++ b/src/main/dotnet/EarthModelStudio/Views/PlayerWindow.cs @@ -1,9 +1,12 @@ 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; @@ -23,6 +26,7 @@ namespace EarthModelStudio.Views; public sealed class PlayerWindow : Window { private LoadedModel? _model; + private bool _closing; private Button? _maximizeButton; private Border? _frame; private TextBlock? _titleText; @@ -167,7 +171,7 @@ public sealed class PlayerWindow : Window minimizeButton.Click += (_, _) => WindowState = WindowState.Minimized; maximizeButton.Click += (_, _) => ToggleMaximize(); - closeButton.Click += (_, _) => Close(); + closeButton.Click += (_, _) => _ = CloseWithAnimationAsync(); _maximizeGlyph = maxBadge.Icon; _restoreGlyph = maxBadge.Icon; _maxRestorePath = "M2.6,3.6 L7.4,3.6 L7.4,8.4 L2.6,8.4 Z M2.6,3.6 L2.6,1.6 L7.4,1.6 L7.4,6.4"; @@ -394,37 +398,23 @@ public sealed class PlayerWindow : Window } // ── 帮助窗口自建标题栏(带 ✕),与模型窗口同款配色 ── - // 关闭键也用品红卡通圆底 + 矢量 ✕:文字符号在中文字体下常被裁切或基线偏移 - var helpBadgeShape = new Shapes.Ellipse - { - Width = 18, Height = 18, - Fill = new SolidColorBrush(Color.Parse("#FF7B7B")), - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center - }; + // 纯矢量图标,无彩色圆底(与三个窗口按钮保持一致) var helpCross = new Shapes.Path { Data = Geometry.Parse("M2,2 L8,8 M8,2 L2,8"), - Stroke = new SolidColorBrush(Color.Parse("#7A1F1F")), - StrokeThickness = 1.7, + Stroke = new SolidColorBrush(btnText), + StrokeThickness = 1.5, StrokeLineCap = PenLineCap.Round, Fill = null, Stretch = Stretch.None, - Width = 9, Height = 9, + Width = 10, Height = 10, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; - var helpCrossLayer = new Grid - { - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center - }; - helpCrossLayer.Children.Add(helpBadgeShape); - helpCrossLayer.Children.Add(helpCross); var helpClose = new Button { - Content = helpCrossLayer, + Content = helpCross, Width = 34, Height = 26, Background = Brushes.Transparent, @@ -438,14 +428,14 @@ public sealed class PlayerWindow : Window }; helpClose.PointerEntered += (_, _) => { - helpBadgeShape.Fill = new SolidColorBrush(Color.Parse("#FF9B9B")); helpClose.Background = new SolidColorBrush(IsLight(frameBg) ? Color.Parse("#EEF1F7") : Color.Parse("#1E2C46")); + helpCross.Stroke = new SolidColorBrush(Colors.White); }; helpClose.PointerExited += (_, _) => { - helpBadgeShape.Fill = new SolidColorBrush(Color.Parse("#FF7B7B")); helpClose.Background = Brushes.Transparent; + helpCross.Stroke = new SolidColorBrush(btnText); }; var helpTitle = new TextBlock @@ -555,7 +545,7 @@ public sealed class PlayerWindow : Window switch (e.Key) { case Key.Escape: - Close(); + _ = CloseWithAnimationAsync(); e.Handled = true; break; case Key.F11: @@ -567,6 +557,30 @@ public sealed class PlayerWindow : Window } } + /// + /// 关闭动画:淡出 + 轻微缩小,动画结束后再真正关闭窗口。 + /// 与主窗口的关闭动画保持同一节奏(180ms)。 + /// + private async Task CloseWithAnimationAsync() + { + if (_closing) return; + _closing = true; + + Transitions = new Transitions + { + new DoubleTransition + { + Property = OpacityProperty, + Duration = TimeSpan.FromMilliseconds(180), + Easing = new CubicEaseIn() + } + }; + Opacity = 0; + + await Task.Delay(190); + Close(); + } + private void OnClosed(object? sender, EventArgs e) { Content = null; diff --git a/version.json b/version.json index 452ea3b..8b10331 100644 --- a/version.json +++ b/version.json @@ -1,12 +1,12 @@ { "schema": 1, - "generated": "2026-11-14T01:23:14Z", + "generated": "2026-11-14T01:56:57Z", "repository": "https://gitcode.com/2509_92447106/GC", "branch": "main", "modelDir": "model", "launcher": { "version": "1.0.6", - "revision": "98cff12092", + "revision": "e1d82a059c", "packages": { "win-x64": { "path": "dist/GC-win-x64.zip", @@ -34,31 +34,31 @@ { "id": "contour-map", "version": "1.0", - "build": "e7f837d0ef", + "build": "2baf95e031", "dir": "model/contour-map" }, { "id": "earth-geography", "version": "1.8", - "build": "143e56bed8", + "build": "def7ac1a55", "dir": "model/earth-geography" }, { "id": "earth-revolution", "version": "1.6", - "build": "26a2bd8f68", + "build": "d53a3ed8d0", "dir": "model/earth-revolution" }, { "id": "earth-rotation", "version": "1.6", - "build": "1a81492baa", + "build": "ea44c4934b", "dir": "model/earth-rotation" }, { "id": "scale-calculator", "version": "1.5", - "build": "79711a44a8", + "build": "c6d584422f", "dir": "model/scale-calculator" } ]