This commit is contained in:
2509_92447106 committed 2026-11-07 16:09:06 +08:00
1 parent 60113ab76e
commit 153ea88f4f
2 files changed
+398 -92

No files matched your search

+10 -3
View File
@@ -257,8 +257,17 @@ public class CelestialView : Control
var dx = p.X - _dragLast.X; var dx = p.X - _dragLast.X;
_dragLast = p; _dragLast = p;
DragBy(dx, p.Y - _dragLast.Y + (p.Y - _dragLast.Y));
e.Handled = true;
}
// 只驱动地球自身的角度;视角俯仰、轨道平面、经纬网平面一律不动 /// <summary>
/// 手动转动地球。只接受水平分量:竖直分量在任何情况下都不会改变相机俯仰角,
/// 因此轨道面、经纬网、地轴所在的平面始终固定。
/// </summary>
public void DragBy(double dx, double dy)
{
_ = dy;
if (View == SceneView.Revolution) if (View == SceneView.Revolution)
{ {
_orbitDeg = Wrap360(_orbitDeg + dx * 0.32); _orbitDeg = Wrap360(_orbitDeg + dx * 0.32);
@@ -269,10 +278,8 @@ public class CelestialView : Control
_spinDeg = Wrap360(_spinDeg + dx * 0.42); _spinDeg = Wrap360(_spinDeg + dx * 0.42);
_spinVelocity = dx * 0.42 * 55; _spinVelocity = dx * 0.42 * 55;
} }
AnglesChanged?.Invoke(); AnglesChanged?.Invoke();
InvalidateVisual(); InvalidateVisual();
e.Handled = true;
} }
protected override void OnPointerReleased(PointerReleasedEventArgs e) protected override void OnPointerReleased(PointerReleasedEventArgs e)
+388 -89
View File
@@ -14,8 +14,8 @@ using EarthModelStudio.ModelSdk;
namespace NeoRF.EarthModels; namespace NeoRF.EarthModels;
/// <summary> /// <summary>
/// 模型自己的界面:画布 + 工具栏 + 速度条 + 教学要点。 /// 模型自己的界面:画布 + 触控友好工具栏 + 课堂演示卡 + 节气定格与步进。
/// 带过渡动画、缩放控件与「暂停后可拖动」提示;启动器只负责开窗口。 /// 启动器只负责下载、开窗口和进度条,不参与任何模型渲染或教学交互。
/// </summary> /// </summary>
public sealed class EarthModelView : UserControl public sealed class EarthModelView : UserControl
{ {
@@ -27,6 +27,7 @@ public sealed class EarthModelView : UserControl
private static readonly IBrush MutedBrush = new SolidColorBrush(Color.Parse("#7E93B8")); private static readonly IBrush MutedBrush = new SolidColorBrush(Color.Parse("#7E93B8"));
private static readonly IBrush FaintBrush = new SolidColorBrush(Color.Parse("#61779C")); private static readonly IBrush FaintBrush = new SolidColorBrush(Color.Parse("#61779C"));
private static readonly IBrush BodyBrush = new SolidColorBrush(Color.Parse("#8CA0C4")); private static readonly IBrush BodyBrush = new SolidColorBrush(Color.Parse("#8CA0C4"));
private static readonly IBrush WarmBrush = new SolidColorBrush(Color.Parse("#FFC46B"));
private static readonly TimeSpan HoverDuration = TimeSpan.FromMilliseconds(120); private static readonly TimeSpan HoverDuration = TimeSpan.FromMilliseconds(120);
private static readonly TimeSpan PanelDuration = TimeSpan.FromMilliseconds(190); private static readonly TimeSpan PanelDuration = TimeSpan.FromMilliseconds(190);
@@ -37,12 +38,22 @@ public sealed class EarthModelView : UserControl
private readonly List<string> _views; private readonly List<string> _views;
private readonly List<ModelButton> _viewButtons = new(); private readonly List<ModelButton> _viewButtons = new();
private readonly CelestialView _canvas; private readonly CelestialView _canvas;
private readonly CelestialView _closeup;
private readonly DispatcherTimer _uiTimer;
private Border? _viewSwitch; private Border? _viewSwitch;
private StackPanel? _seasonPanel; private StackPanel? _seasonPanel;
private Border? _lessons; private Border? _lessons;
private Border? _closeupHost;
private ModelButton? _playButton; private ModelButton? _playButton;
private ModelButton? _overheadButton;
private ModelButton? _closeupButton;
private TextBlock? _zoomText; private TextBlock? _zoomText;
private TextBlock? _cardState;
private TextBlock? _cardTitle;
private TextBlock? _cardDate;
private TextBlock? _cardDirect;
private TextBlock? _cardNote;
private bool _playing = true; private bool _playing = true;
private bool _labels = true; private bool _labels = true;
@@ -50,6 +61,9 @@ public sealed class EarthModelView : UserControl
private bool _grid = true; private bool _grid = true;
private bool _tilt; private bool _tilt;
private bool _showLessons = true; private bool _showLessons = true;
private bool _showCloseup = true;
private bool _overhead;
private double _lastDeclination = double.NaN;
public EarthModelView(IModelContext context, SceneRuntime runtime) public EarthModelView(IModelContext context, SceneRuntime runtime)
{ {
@@ -67,6 +81,7 @@ public sealed class EarthModelView : UserControl
ShowLabels = true, ShowLabels = true,
ShowOrbit = true, ShowOrbit = true,
ShowGraticule = true, ShowGraticule = true,
ShowKeyLatitudes = true,
FrameRate = 60, FrameRate = 60,
View = IsRevolution ? SceneView.Revolution : SceneView.Rotation View = IsRevolution ? SceneView.Revolution : SceneView.Rotation
}; };
@@ -77,26 +92,52 @@ public sealed class EarthModelView : UserControl
if (_zoomText != null) _zoomText.Text = $"{zoom * 100:0}%"; if (_zoomText != null) _zoomText.Text = $"{zoom * 100:0}%";
}; };
var root = new Grid { RowDefinitions = new RowDefinitions("Auto,*,Auto") }; // 课堂特写:同一套渲染器,把当前直射纬度放大给全班看
_closeup = new CelestialView
{
Scene = runtime,
Texts = _texts,
View = SceneView.Rotation,
IsPlaying = false,
ShowHud = false,
ShowLabels = true,
ShowGraticule = false,
ShowKeyLatitudes = true,
InsetMode = true,
Width = 240,
Height = 240
};
_closeup.JumpToSpin(20);
_uiTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(140),
DispatcherPriority.Render, (_, _) => RefreshTeaching());
var root = new Grid { RowDefinitions = new RowDefinitions("Auto,Auto,*,Auto") };
var top = BuildTopBar(); var top = BuildTopBar();
root.Children.Add(top); root.Children.Add(top);
var options = BuildOptionsBar();
Grid.SetRow(options, 1);
root.Children.Add(options);
var stage = new Grid(); var stage = new Grid();
stage.Children.Add(_canvas); stage.Children.Add(_canvas);
_lessons = BuildLessonsPanel(); stage.Children.Add(BuildZoomPad());
_lessons = BuildClassroomCard();
stage.Children.Add(_lessons); stage.Children.Add(_lessons);
Grid.SetRow(stage, 1); Grid.SetRow(stage, 2);
root.Children.Add(stage); root.Children.Add(stage);
var bottom = BuildBottomBar(); var bottom = BuildBottomBar();
Grid.SetRow(bottom, 2); Grid.SetRow(bottom, 3);
root.Children.Add(bottom); root.Children.Add(bottom);
Content = root; Content = root;
ApplyVisibility(); ApplyVisibility();
RefreshTeaching();
// 打开时整窗淡入,避免“啪”地出现 // 打开时整窗淡入,避免「啪」地出现
Opacity = 0; Opacity = 0;
Transitions = new Transitions Transitions = new Transitions
{ {
@@ -107,16 +148,24 @@ public sealed class EarthModelView : UserControl
Easing = new CubicEaseOut() Easing = new CubicEaseOut()
} }
}; };
AttachedToVisualTree += (_, _) => Opacity = 1; AttachedToVisualTree += (_, _) =>
{
Opacity = 1;
_uiTimer.Start();
if (TopLevel.GetTopLevel(this) is Window window) window.KeyDown += OnKeyDown;
};
DetachedFromVisualTree += (_, _) =>
{
_uiTimer.Stop();
if (TopLevel.GetTopLevel(this) is Window window) window.KeyDown -= OnKeyDown;
};
} }
private string CurrentView { get; set; } = "rotation"; private string CurrentView { get; set; } = "rotation";
private double StartAngle => IsRevolution ? 60 : 0; private double StartAngle => IsRevolution ? 60 : 0;
private bool IsRevolution => string.Equals(CurrentView, "revolution", StringComparison.OrdinalIgnoreCase); private bool IsRevolution => string.Equals(CurrentView, "revolution", StringComparison.OrdinalIgnoreCase);
private bool HasViewSwitch => _views.Count > 1; private bool HasViewSwitch => _views.Count > 1;
private List<SeasonPoint> Seasons => _runtime.Scene.Orbit.Seasons;
private static string NormalizeView(string? view) private static string NormalizeView(string? view)
=> string.Equals(view, "revolution", StringComparison.OrdinalIgnoreCase) ? "revolution" : "rotation"; => string.Equals(view, "revolution", StringComparison.OrdinalIgnoreCase) ? "revolution" : "rotation";
@@ -134,7 +183,7 @@ public sealed class EarthModelView : UserControl
return list; return list;
} }
// ---------------------------------------------------------------- 顶部 // ---------------------------------------------------------------- 顶部主工具栏
private Control BuildTopBar() private Control BuildTopBar()
{ {
var close = MakeButton(_texts["close"], () => _context.RequestClose()); var close = MakeButton(_texts["close"], () => _context.RequestClose());
@@ -144,7 +193,7 @@ public sealed class EarthModelView : UserControl
{ {
Text = _texts.Pick(_runtime.Scene.NameI18n, _texts["title"]), Text = _texts.Pick(_runtime.Scene.NameI18n, _texts["title"]),
Foreground = TitleBrush, Foreground = TitleBrush,
FontSize = 13, FontSize = 14,
FontWeight = FontWeight.SemiBold FontWeight = FontWeight.SemiBold
}); });
title.Children.Add(new TextBlock title.Children.Add(new TextBlock
@@ -172,42 +221,22 @@ public sealed class EarthModelView : UserControl
var actions = new StackPanel var actions = new StackPanel
{ {
Orientation = Orientation.Horizontal, Orientation = Orientation.Horizontal,
Spacing = 7, Spacing = 8,
VerticalAlignment = VerticalAlignment.Center VerticalAlignment = VerticalAlignment.Center
}; };
// 缩放:− / 百分比 / + / 复位
actions.Children.Add(MakeButton("−", () => _canvas.ZoomBy(1 / 1.25), compact: true));
_zoomText = new TextBlock
{
Text = "100%",
Foreground = TextBrush,
FontSize = 11,
Width = 38,
VerticalAlignment = VerticalAlignment.Center,
TextAlignment = TextAlignment.Center
};
actions.Children.Add(_zoomText);
actions.Children.Add(MakeButton("+", () => _canvas.ZoomBy(1.25), compact: true));
actions.Children.Add(MakeButton("⟲", () =>
{
_canvas.ResetView();
_canvas.JumpToOrbit(StartAngle);
_canvas.JumpToSpin(20);
}, compact: true));
_playButton = MakeButton(_texts["pause"], TogglePlay); _playButton = MakeButton(_texts["pause"], TogglePlay);
_playButton.MinWidth = 74;
actions.Children.Add(_playButton); actions.Children.Add(_playButton);
actions.Children.Add(MakeButton(_texts["reset"], () => actions.Children.Add(MakeButton(_texts["reset"], () =>
{ {
_canvas.ResetAnimation(); _canvas.ResetAnimation();
_canvas.JumpToOrbit(StartAngle); _canvas.JumpToOrbit(StartAngle);
RefreshTeaching();
})); }));
actions.Children.Add(MakeToggle(_texts["labels"], _labels, on => { _labels = on; _canvas.ShowLabels = on; })); actions.Children.Add(MakeButton("◀", () => Step(-5), large: true));
actions.Children.Add(MakeToggle(_texts["orbit"], _orbit, on => { _orbit = on; _canvas.ShowOrbit = on; })); actions.Children.Add(MakeButton("▶", () => Step(5), large: true));
actions.Children.Add(MakeToggle(_texts["grid"], _grid, on => { _grid = on; _canvas.ShowGraticule = on; })); actions.Children.Add(MakeButton(_texts["classroom"], () => SetLessonsVisible(!_showLessons)));
actions.Children.Add(MakeToggle(_texts["tilt"], _tilt, on => { _tilt = on; _canvas.ExaggerateTilt = on; })); actions.Children.Add(MakeButton("⛶", ToggleFullScreen, large: true));
actions.Children.Add(MakeButton(_texts["lessons"], () => SetLessonsVisible(!_showLessons)));
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto,*,Auto") }; var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto,*,Auto") };
grid.Children.Add(close); grid.Children.Add(close);
@@ -219,7 +248,55 @@ public sealed class EarthModelView : UserControl
Grid.SetColumn(actions, 4); Grid.SetColumn(actions, 4);
grid.Children.Add(actions); grid.Children.Add(actions);
return new Border { Background = PanelBg, Padding = new Thickness(16, 11), Child = grid }; return new Border { Background = PanelBg, Padding = new Thickness(16, 9), Child = grid };
}
// ---------------------------------------------------------------- 显示选项行
private Control BuildOptionsBar()
{
var row = new StackPanel
{
Orientation = Orientation.Horizontal,
Spacing = 7,
VerticalAlignment = VerticalAlignment.Center
};
row.Children.Add(MakeToggle(_texts["labels"], _labels, on => { _labels = on; _canvas.ShowLabels = on; }));
row.Children.Add(MakeToggle(_texts["orbit"], _orbit, on => { _orbit = on; _canvas.ShowOrbit = on; }));
row.Children.Add(MakeToggle(_texts["grid"], _grid, on => { _grid = on; _canvas.ShowGraticule = on; }));
row.Children.Add(MakeToggle(_texts["tilt"], _tilt, on => { _tilt = on; _canvas.ExaggerateTilt = on; }));
_closeupButton = MakeToggle(_texts["closeup"], _showCloseup, on =>
{
_showCloseup = on;
ApplyVisibility();
});
row.Children.Add(_closeupButton);
_overheadButton = MakeToggle(_texts["overhead"], _overhead, on =>
{
_overhead = on;
// 视角只由这个显式控件改变;拖动永远不会碰它
_canvas.CameraElevation = on ? (IsRevolution ? 74 : 62) : double.NaN;
});
row.Children.Add(_overheadButton);
var shortcut = new TextBlock
{
Text = _texts["shortcutHint"],
Foreground = FaintBrush,
FontSize = 10.5,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(12, 0, 0, 0)
};
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*") };
grid.Children.Add(row);
Grid.SetColumn(shortcut, 1);
grid.Children.Add(shortcut);
return new Border
{
Background = new SolidColorBrush(Color.Parse("#A00A1020")),
Padding = new Thickness(16, 7),
Child = grid
};
} }
private ModelButton MakeViewButton(string view, string label) private ModelButton MakeViewButton(string view, string label)
@@ -251,11 +328,63 @@ public sealed class EarthModelView : UserControl
CurrentView = NormalizeView(view); CurrentView = NormalizeView(view);
_canvas.View = IsRevolution ? SceneView.Revolution : SceneView.Rotation; _canvas.View = IsRevolution ? SceneView.Revolution : SceneView.Rotation;
_canvas.JumpToOrbit(StartAngle); _canvas.JumpToOrbit(StartAngle);
_canvas.CameraElevation = _overhead ? (IsRevolution ? 74 : 62) : double.NaN;
foreach (var button in _viewButtons) foreach (var button in _viewButtons)
button.SetBase(string.Equals(button.Tag as string, CurrentView, StringComparison.OrdinalIgnoreCase) button.SetBase(string.Equals(button.Tag as string, CurrentView, StringComparison.OrdinalIgnoreCase)
? Accent ? Accent
: ControlBg); : ControlBg);
ApplyVisibility(); ApplyVisibility();
RefreshTeaching();
}
// ---------------------------------------------------------------- 画布浮动缩放板(触控大按钮)
private Control BuildZoomPad()
{
var plus = MakeButton("+", () => _canvas.ZoomBy(1.25), large: true);
var minus = MakeButton("-", () => _canvas.ZoomBy(1 / 1.25), large: true);
var reset = MakeButton("⟲", () => _canvas.ResetView(), large: true);
foreach (var b in new[] { plus, minus, reset })
{
b.MinWidth = 62;
b.MinHeight = 48;
b.HorizontalAlignment = HorizontalAlignment.Stretch;
}
_zoomText = new TextBlock
{
Text = "100%",
Foreground = TextBrush,
FontSize = 13,
FontWeight = FontWeight.SemiBold,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 2, 0, 2)
};
var stack = new StackPanel { Spacing = 6, Width = 62 };
stack.Children.Add(new TextBlock
{
Text = _texts["zoom"],
Foreground = MutedBrush,
FontSize = 10.5,
TextAlignment = TextAlignment.Center
});
stack.Children.Add(plus);
stack.Children.Add(_zoomText);
stack.Children.Add(minus);
stack.Children.Add(reset);
return new Border
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Bottom,
Margin = new Thickness(16, 0, 0, 16),
Background = new SolidColorBrush(Color.Parse("#C00B1226")),
BorderBrush = new SolidColorBrush(Color.Parse("#26374F")),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(14),
Padding = new Thickness(10),
Child = stack
};
} }
// ---------------------------------------------------------------- 底部 // ---------------------------------------------------------------- 底部
@@ -274,7 +403,8 @@ public sealed class EarthModelView : UserControl
Maximum = 4, Maximum = 4,
Value = 1, Value = 1,
Margin = new Thickness(12, 0, 0, 0), Margin = new Thickness(12, 0, 0, 0),
Width = 180 Width = 180,
Height = 38
}; };
var speedText = new TextBlock var speedText = new TextBlock
{ {
@@ -296,14 +426,14 @@ public sealed class EarthModelView : UserControl
Foreground = FaintBrush, Foreground = FaintBrush,
FontSize = 10.5, FontSize = 10.5,
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(22, 0, 0, 0), Margin = new Thickness(20, 0, 0, 0),
TextTrimming = TextTrimming.CharacterEllipsis TextTrimming = TextTrimming.CharacterEllipsis
}; };
_seasonPanel = new StackPanel _seasonPanel = new StackPanel
{ {
Orientation = Orientation.Horizontal, Orientation = Orientation.Horizontal,
Spacing = 6, Spacing = 7,
VerticalAlignment = VerticalAlignment.Center VerticalAlignment = VerticalAlignment.Center
}; };
_seasonPanel.Children.Add(new TextBlock _seasonPanel.Children.Add(new TextBlock
@@ -313,10 +443,7 @@ public sealed class EarthModelView : UserControl
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0, 0, 6, 0) Margin = new Thickness(0, 0, 6, 0)
}); });
_seasonPanel.Children.Add(MakeSeasonButton(0)); foreach (var season in Seasons) _seasonPanel.Children.Add(MakeSeasonButton(season));
_seasonPanel.Children.Add(MakeSeasonButton(90));
_seasonPanel.Children.Add(MakeSeasonButton(180));
_seasonPanel.Children.Add(MakeSeasonButton(270));
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto,*,Auto") }; var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto,*,Auto") };
grid.Children.Add(speedLabel); grid.Children.Add(speedLabel);
@@ -329,35 +456,27 @@ public sealed class EarthModelView : UserControl
Grid.SetColumn(_seasonPanel, 4); Grid.SetColumn(_seasonPanel, 4);
grid.Children.Add(_seasonPanel); grid.Children.Add(_seasonPanel);
return new Border { Background = PanelBg, Padding = new Thickness(16, 10), Child = grid }; return new Border { Background = PanelBg, Padding = new Thickness(16, 8), Child = grid };
} }
private ModelButton MakeSeasonButton(double angle) private ModelButton MakeSeasonButton(SeasonPoint season)
{ {
var key = angle switch var captured = season;
{ var button = MakeButton(_texts[season.Key], () => JumpToSeason(captured));
0 => "season.springEquinox", button.MinHeight = 44;
90 => "season.summerSolstice", return button;
180 => "season.autumnEquinox",
_ => "season.winterSolstice"
};
return MakeButton(_texts[key], () =>
{
if (!IsRevolution) SwitchView("revolution");
_canvas.JumpToOrbit(angle);
});
} }
// ---------------------------------------------------------------- 教学要点 // ---------------------------------------------------------------- 课堂演示卡
private Border BuildLessonsPanel() private Border BuildClassroomCard()
{ {
var header = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") }; var header = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") };
header.Children.Add(new TextBlock header.Children.Add(new TextBlock
{ {
Text = _texts["lessons"], Text = _texts["classroom"],
Foreground = TitleBrush, Foreground = TitleBrush,
FontWeight = FontWeight.SemiBold, FontWeight = FontWeight.SemiBold,
FontSize = 12.5, FontSize = 13,
VerticalAlignment = VerticalAlignment.Center VerticalAlignment = VerticalAlignment.Center
}); });
var close = MakeButton("✕", () => SetLessonsVisible(false)); var close = MakeButton("✕", () => SetLessonsVisible(false));
@@ -365,6 +484,66 @@ public sealed class EarthModelView : UserControl
Grid.SetColumn(close, 1); Grid.SetColumn(close, 1);
header.Children.Add(close); header.Children.Add(close);
_cardState = new TextBlock
{
Text = _texts["running"],
Foreground = MutedBrush,
FontSize = 11,
Margin = new Thickness(0, 6, 0, 0)
};
_cardTitle = new TextBlock
{
Foreground = TitleBrush,
FontSize = 20,
FontWeight = FontWeight.Bold
};
_cardDate = new TextBlock { Foreground = MutedBrush, FontSize = 12 };
_cardDirect = new TextBlock
{
Foreground = WarmBrush,
FontSize = 27,
FontWeight = FontWeight.Bold
};
_cardNote = new TextBlock
{
Foreground = BodyBrush,
FontSize = 12,
TextWrapping = TextWrapping.Wrap,
LineHeight = 18
};
_closeupHost = new Border
{
CornerRadius = new CornerRadius(10),
BorderBrush = new SolidColorBrush(Color.Parse("#26374F")),
BorderThickness = new Thickness(1),
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, 4, 0, 2),
Child = _closeup
};
var readouts = new StackPanel { Spacing = 2 };
readouts.Children.Add(_cardState);
readouts.Children.Add(_cardTitle);
readouts.Children.Add(_cardDate);
readouts.Children.Add(new TextBlock
{
Text = _texts["directPoint"],
Foreground = MutedBrush,
FontSize = 11,
Margin = new Thickness(0, 8, 0, 0)
});
readouts.Children.Add(_cardDirect);
readouts.Children.Add(_cardNote);
readouts.Children.Add(new TextBlock
{
Text = _texts["closeup"],
Foreground = MutedBrush,
FontSize = 11,
Margin = new Thickness(0, 6, 0, 0)
});
readouts.Children.Add(_closeupHost);
var list = new StackPanel { Spacing = 2 }; var list = new StackPanel { Spacing = 2 };
foreach (var lesson in _runtime.Scene.Lessons) foreach (var lesson in _runtime.Scene.Lessons)
{ {
@@ -394,8 +573,9 @@ public sealed class EarthModelView : UserControl
BorderThickness = new Thickness(0), BorderThickness = new Thickness(0),
HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalContentAlignment = HorizontalAlignment.Left, HorizontalContentAlignment = HorizontalAlignment.Left,
Padding = new Thickness(8, 7), Padding = new Thickness(8, 9),
Margin = new Thickness(0, 1), Margin = new Thickness(0, 1),
MinHeight = 44,
Cursor = new Cursor(StandardCursorType.Hand), Cursor = new Cursor(StandardCursorType.Hand),
Transitions = new Transitions Transitions = new Transitions
{ {
@@ -410,26 +590,39 @@ public sealed class EarthModelView : UserControl
} }
var content = new StackPanel { Spacing = 8 }; var content = new StackPanel { Spacing = 8 };
content.Children.Add(header); content.Children.Add(readouts);
content.Children.Add(new ScrollViewer content.Children.Add(new TextBlock
{ {
Content = list, Text = _texts["lessons"],
MaxHeight = 380, Foreground = TitleBrush,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto FontWeight = FontWeight.SemiBold,
FontSize = 12.5
}); });
content.Children.Add(list);
var bodyGrid = new Grid { RowDefinitions = new RowDefinitions("Auto,*") };
bodyGrid.Children.Add(header);
var scroller = new ScrollViewer
{
Content = content,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
Margin = new Thickness(0, 8, 0, 0)
};
Grid.SetRow(scroller, 1);
bodyGrid.Children.Add(scroller);
var panel = new Border var panel = new Border
{ {
HorizontalAlignment = HorizontalAlignment.Right, HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Stretch,
Width = 272, Width = 296,
Margin = new Thickness(0, 58, 16, 80), Margin = new Thickness(0, 12, 16, 12),
Background = new SolidColorBrush(Color.Parse("#D00B1226")), Background = new SolidColorBrush(Color.Parse("#D00B1226")),
CornerRadius = new CornerRadius(14), CornerRadius = new CornerRadius(14),
Padding = new Thickness(13), Padding = new Thickness(13),
BorderBrush = new SolidColorBrush(Color.Parse("#26374F")), BorderBrush = new SolidColorBrush(Color.Parse("#26374F")),
BorderThickness = new Thickness(1), BorderThickness = new Thickness(1),
Child = content, Child = bodyGrid,
RenderTransform = new TranslateTransform(0, 0) RenderTransform = new TranslateTransform(0, 0)
}; };
panel.Transitions = new Transitions panel.Transitions = new Transitions
@@ -470,6 +663,38 @@ public sealed class EarthModelView : UserControl
timer.Start(); timer.Start();
} }
/// <summary>课堂卡与地球特写跟随当前轨道位置刷新(播放时每 140ms 更新一次)。</summary>
private void RefreshTeaching()
{
if (_cardTitle == null) return;
var season = IsRevolution ? _canvas.NearestSeason(6) : null;
var decl = _canvas.SubsolarLatitude;
_cardState!.Text = _playing ? _texts["running"] : _texts["frozen"];
_cardState.Foreground = _playing ? MutedBrush : WarmBrush;
_cardTitle.Text = season != null
? _texts[season.Key]
: (IsRevolution ? _texts["seasons"] : _texts.Pick(_runtime.Scene.NameI18n, _texts["title"]));
_cardDate!.Text = _canvas.CurrentDate + (season?.Date != null ? " · " + season.Date : "");
_cardDirect!.Text = season?.DeclinationDeg.HasValue == true
? FormatDeclination(season.DeclinationDeg.Value)
: _canvas.DeclinationLabel;
_cardNote!.Text = season != null
? _texts.Pick(season.TeachingI18n, _texts["orbitTeach"])
: _texts["orbitTeach"];
if (_showCloseup && (double.IsNaN(_lastDeclination) || Math.Abs(_lastDeclination - decl) > 0.04))
{
_closeup.DeclinationDeg = decl;
_lastDeclination = decl;
}
}
private string FormatDeclination(double d)
=> Math.Abs(d) < 0.05
? "0° " + _texts["lat.equator"]
: $"{Math.Abs(d):0.0}°" + (d > 0 ? _texts["northShort"] : _texts["southShort"]);
private void ApplyLesson(Lesson lesson) private void ApplyLesson(Lesson lesson)
{ {
if (!string.IsNullOrWhiteSpace(lesson.View)) if (!string.IsNullOrWhiteSpace(lesson.View))
@@ -477,20 +702,101 @@ public sealed class EarthModelView : UserControl
var view = NormalizeView(lesson.View); var view = NormalizeView(lesson.View);
if (!string.Equals(view, CurrentView, StringComparison.OrdinalIgnoreCase)) SwitchView(view); if (!string.Equals(view, CurrentView, StringComparison.OrdinalIgnoreCase)) SwitchView(view);
} }
// 讲要点时自动定格,读数不再跳动,方便指读板书
SetPlaying(false);
if (lesson.AngleDeg.HasValue) _canvas.JumpToOrbit(lesson.AngleDeg.Value); if (lesson.AngleDeg.HasValue) _canvas.JumpToOrbit(lesson.AngleDeg.Value);
RefreshTeaching();
}
// ---------------------------------------------------------------- 教学操作
private void SetPlaying(bool play)
{
_playing = play;
_canvas.IsPlaying = play;
if (_playButton?.Content is TextBlock block)
block.Text = play ? _texts["pause"] : _texts["play"];
RefreshTeaching();
}
private void TogglePlay() => SetPlaying(!_playing);
private void Step(double deltaDeg)
{
SetPlaying(false);
if (IsRevolution) _canvas.StepOrbit(deltaDeg);
else _canvas.StepSpin(deltaDeg);
RefreshTeaching();
}
private void JumpToSeason(SeasonPoint season)
{
if (!IsRevolution) SwitchView("revolution");
SetPlaying(false);
_canvas.JumpToOrbit(season.AngleDeg);
RefreshTeaching();
}
private void JumpToSeasonIndex(int index)
{
if (index < 0 || index >= Seasons.Count) return;
JumpToSeason(Seasons[index]);
}
private void ToggleFullScreen()
{
try
{
if (TopLevel.GetTopLevel(this) is Window window)
window.WindowState = window.WindowState == WindowState.FullScreen
? WindowState.Normal
: WindowState.FullScreen;
}
catch (Exception ex)
{
_context.Log("全屏切换失败: " + ex.Message);
}
}
private void OnKeyDown(object? sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Space:
TogglePlay();
e.Handled = true;
break;
case Key.Left:
Step(-5);
e.Handled = true;
break;
case Key.Right:
Step(5);
e.Handled = true;
break;
case Key.D1: JumpToSeasonIndex(0); e.Handled = true; break;
case Key.D2: JumpToSeasonIndex(1); e.Handled = true; break;
case Key.D3: JumpToSeasonIndex(2); e.Handled = true; break;
case Key.D4: JumpToSeasonIndex(3); e.Handled = true; break;
case Key.F: ToggleFullScreen(); e.Handled = true; break;
case Key.Add: _canvas.ZoomBy(1.25); e.Handled = true; break;
case Key.Subtract: _canvas.ZoomBy(1 / 1.25); e.Handled = true; break;
case Key.D0: _canvas.ResetView(); e.Handled = true; break;
}
} }
// ---------------------------------------------------------------- 工具 // ---------------------------------------------------------------- 工具
private ModelButton MakeButton(string text, Action onClick, bool compact = false) private ModelButton MakeButton(string text, Action onClick, bool large = false)
{ {
var button = new ModelButton var button = new ModelButton
{ {
Content = new TextBlock { Text = text, FontSize = 11.5 }, Content = new TextBlock { Text = text, FontSize = large ? 20 : 12.5 },
Foreground = TextBrush, Foreground = TextBrush,
BorderThickness = new Thickness(0), BorderThickness = new Thickness(0),
CornerRadius = new CornerRadius(8), CornerRadius = new CornerRadius(9),
Padding = compact ? new Thickness(8, 4) : new Thickness(9, 5), Padding = large ? new Thickness(10, 8) : new Thickness(13, 9),
MinWidth = compact ? 26 : 0, MinWidth = large ? 46 : 44,
MinHeight = 40,
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
Cursor = new Cursor(StandardCursorType.Hand) Cursor = new Cursor(StandardCursorType.Hand)
}; };
@@ -499,19 +805,12 @@ public sealed class EarthModelView : UserControl
return button; return button;
} }
private void TogglePlay()
{
_playing = !_playing;
_canvas.IsPlaying = _playing;
if (_playButton?.Content is TextBlock block)
block.Text = _playing ? _texts["pause"] : _texts["play"];
}
private void ApplyVisibility() private void ApplyVisibility()
{ {
if (_viewSwitch != null) _viewSwitch.IsVisible = HasViewSwitch; if (_viewSwitch != null) _viewSwitch.IsVisible = HasViewSwitch;
if (_lessons != null) _lessons.IsVisible = _showLessons; if (_lessons != null) _lessons.IsVisible = _showLessons;
if (_seasonPanel != null) _seasonPanel.IsVisible = IsRevolution; if (_seasonPanel != null) _seasonPanel.IsVisible = IsRevolution;
if (_closeupHost != null) _closeupHost.IsVisible = _showCloseup;
} }
/// <summary>带悬停过渡的按钮:本地基础色 + 悬停提亮。</summary> /// <summary>带悬停过渡的按钮:本地基础色 + 悬停提亮。</summary>