| 1 | using Avalonia; |
| 2 | using Avalonia.Controls; |
| 3 | using Avalonia.LogicalTree; |
| 4 | |
| 5 | namespace CascadeIDE.Features.UiChrome; |
| 6 | |
| 7 | /// <summary> |
| 8 | /// Контейнер <strong>пространственного якоря</strong> (лобовое / PFD / MFD): один канонический <see cref="AttentionZone"/>, |
| 9 | /// без путаницы с именами вроде PrimaryFlightDisplay. Канал EICAS (оповещения) по ADR — отдельный контур, |
| 10 | /// не «четвёртая колонка»; UI — <c>EicasAlertsBarView</c> / <c>eicas_alerts_bar</c>, не обязательно этот контроль. |
| 11 | /// </summary> |
| 12 | public sealed class AttentionZoneContainer : ContentControl |
| 13 | { |
| 14 | public static readonly StyledProperty<AttentionZone> ZoneProperty = |
| 15 | AvaloniaProperty.Register<AttentionZoneContainer, AttentionZone>(nameof(Zone)); |
| 16 | |
| 17 | static AttentionZoneContainer() |
| 18 | { |
| 19 | ZoneProperty.Changed.AddClassHandler<AttentionZoneContainer>((c, _) => c.SyncZoneClasses()); |
| 20 | } |
| 21 | |
| 22 | /// <summary>Начальная зона <see cref="AttentionZone.Forward"/> не даёт <c>ZoneProperty.Changed</c>; без синхронизации классы пусты до логического дерева.</summary> |
| 23 | public AttentionZoneContainer() => SyncZoneClasses(); |
| 24 | |
| 25 | public AttentionZone Zone |
| 26 | { |
| 27 | get => GetValue(ZoneProperty); |
| 28 | set => SetValue(ZoneProperty, value); |
| 29 | } |
| 30 | |
| 31 | /// <summary>Каноническая строка для TOML/MCP (например <c>pfd</c>).</summary> |
| 32 | public string CanonicalZoneId => Zone.ToCanonicalId(); |
| 33 | |
| 34 | protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) |
| 35 | { |
| 36 | base.OnAttachedToLogicalTree(e); |
| 37 | SyncZoneClasses(); |
| 38 | } |
| 39 | |
| 40 | private void SyncZoneClasses() |
| 41 | { |
| 42 | foreach (var token in ZoneClassTokens) |
| 43 | Classes.Remove(token); |
| 44 | |
| 45 | // Три якоря — общий маркер attention-zone + суффикс. EICAS/HUD по ADR не «зоны-якоря». |
| 46 | switch (Zone) |
| 47 | { |
| 48 | case AttentionZone.Eicas: |
| 49 | Classes.Add("attention-channel-eicas"); |
| 50 | return; |
| 51 | case AttentionZone.Hud: |
| 52 | Classes.Add("attention-layer-hud"); |
| 53 | return; |
| 54 | case AttentionZone.Forward: |
| 55 | Classes.Add("attention-zone"); |
| 56 | Classes.Add("attention-zone-forward"); |
| 57 | return; |
| 58 | case AttentionZone.Pfd: |
| 59 | Classes.Add("attention-zone"); |
| 60 | Classes.Add("attention-zone-pfd"); |
| 61 | return; |
| 62 | case AttentionZone.Mfd: |
| 63 | Classes.Add("attention-zone"); |
| 64 | Classes.Add("attention-zone-mfd"); |
| 65 | return; |
| 66 | default: |
| 67 | Classes.Add("attention-zone"); |
| 68 | Classes.Add("attention-zone-forward"); |
| 69 | return; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | private static readonly string[] ZoneClassTokens = |
| 74 | [ |
| 75 | "attention-zone", |
| 76 | "attention-zone-forward", |
| 77 | "attention-zone-pfd", |
| 78 | "attention-zone-mfd", |
| 79 | "attention-channel-eicas", |
| 80 | "attention-layer-hud", |
| 81 | ]; |
| 82 | } |
| 83 | |