Lay the band panel out the way N1MM lays it out, and colour it
N1MM's band panel is a row per band and a column per mode the contest runs, with every cell painted by what the callsign being typed would be worth there: red for one new multiplier, green for more than one, blue for points, grey for a station already worked on that band and mode. With nothing typed every cell is grey. That is the panel's point — it says where a station is still needed without working the bands one at a time — and this had only the frame. BandPanel holds the rule and is unit-tested without a window. The bands are the six contest bands, with 30, 17 and 12 metres added for general logging: in N1MM that is the one entry of the hundred and thirty-five that shows the WARC bands, so Contest.ShowsWarcBands says so and GeneralLogging overrides it. The columns are the modes the contest runs, so CQ WW CW has one column and IARU has two, rather than always showing CW and phone. A digital entry gets one DIG column where N1MM has RTTY and PSK: dupes and points here go by mode category, and those two are the same category. The labels are N1MM's: the metres alone up to 10, then the unit from 6m up. The band the radio is on is ringed rather than filled, as N1MM rings it, so the ring does not hide the colour underneath. The cells are labels with a click handler rather than buttons, so the theme cannot paint over the colour under the pointer. Text on a filled cell is black or white by N1MM's rule: light is the three channels adding up to more than 384. Looked at under Xvfb in CQ WW CW: one CW column, six bands, grey with nothing typed, and with a JA typed red on every band but 20, where the zone and country are already claimed, and which carries the ring. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD
This commit is contained in:
@@ -1,62 +1,122 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Nonemm.App.Theming;
|
||||
using Nonemm.Contests;
|
||||
using Nonemm.Core;
|
||||
using Nonemm.Session;
|
||||
|
||||
namespace Nonemm.App.Windows;
|
||||
|
||||
/// The band buttons down the left of the window, CW in one column and phone in
|
||||
/// the other, as N1MM has them. A button puts the radio where the operator left
|
||||
/// that band, or at the start of that part of it.
|
||||
/// The band panel down the left of the window, laid out as N1MM lays it out: a
|
||||
/// column per mode the contest runs, a row per band, and each cell painted with
|
||||
/// what the callsign being typed would be worth there. Clicking a cell puts the
|
||||
/// radio where the operator left that band, or at the start of that part of it.
|
||||
public sealed partial class EntryWindow
|
||||
{
|
||||
private static readonly IReadOnlyList<Band> BandColumn =
|
||||
[
|
||||
Bands.Band160M, Bands.Band80M, Bands.Band40M, Bands.Band30M, Bands.Band20M,
|
||||
Bands.Band17M, Bands.Band15M, Bands.Band12M, Bands.Band10M, Bands.Band6M,
|
||||
];
|
||||
/// From here up a band is named with its unit — 6m, 2m, 70cm — and below it
|
||||
/// with the metres alone.
|
||||
private const double VhfFromMegahertz = 50;
|
||||
|
||||
private readonly List<(Band Band, ModeCategory Mode, Button Button)> bandButtons = [];
|
||||
private readonly List<BandCell> bandCells = [];
|
||||
private string bandsBuiltFor = "";
|
||||
|
||||
private void BuildBandButtons()
|
||||
private sealed record BandCell(Band Band, ModeCategory Mode, Border Fill, Border Ring, TextBlock Label);
|
||||
|
||||
private void BuildBandCells(BandPanel panel)
|
||||
{
|
||||
string wanted = string.Join(
|
||||
'|',
|
||||
[.. panel.Bands.Select(b => b.Name), .. panel.Modes.Select(m => m.ToString())]);
|
||||
if (wanted == bandsBuiltFor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bandsBuiltFor = wanted;
|
||||
BandButtons.Children.Clear();
|
||||
BandButtons.RowDefinitions.Clear();
|
||||
bandButtons.Clear();
|
||||
BandButtons.ColumnDefinitions.Clear();
|
||||
bandCells.Clear();
|
||||
foreach (ModeCategory _ in panel.Modes)
|
||||
{
|
||||
BandButtons.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
|
||||
}
|
||||
BandButtons.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
|
||||
Heading("CW", 0);
|
||||
Heading("PH", 1);
|
||||
for (int at = 0; at < BandColumn.Count; at++)
|
||||
for (int column = 0; column < panel.Modes.Count; column++)
|
||||
{
|
||||
AddHeading(HeadingFor(panel.Modes[column]), column);
|
||||
}
|
||||
for (int row = 0; row < panel.Bands.Count; row++)
|
||||
{
|
||||
BandButtons.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
|
||||
Add(BandColumn[at], ModeCategory.Cw, at + 1, column: 0);
|
||||
Add(BandColumn[at], ModeCategory.Phone, at + 1, column: 1);
|
||||
for (int column = 0; column < panel.Modes.Count; column++)
|
||||
{
|
||||
AddCell(panel.Bands[row], panel.Modes[column], row + 1, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Heading(string text, int column)
|
||||
private void AddHeading(string text, int column)
|
||||
{
|
||||
TextBlock heading = new()
|
||||
{
|
||||
Text = text,
|
||||
FontSize = 10,
|
||||
Opacity = 0.7,
|
||||
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
|
||||
Margin = new Avalonia.Thickness(0, 0, 2, 2),
|
||||
FontWeight = FontWeight.Bold,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
Margin = new Thickness(0, 0, 2, 2),
|
||||
};
|
||||
Grid.SetColumn(heading, column);
|
||||
BandButtons.Children.Add(heading);
|
||||
}
|
||||
|
||||
private void Add(Band band, ModeCategory mode, int row, int column)
|
||||
private void AddCell(Band band, ModeCategory mode, int row, int column)
|
||||
{
|
||||
Button button = new() { Content = band.MegahertzLabel.ToString("0.###") };
|
||||
button.Classes.Add("band");
|
||||
button.Click += (_, _) => MoveToBand(band, mode);
|
||||
Grid.SetRow(button, row);
|
||||
Grid.SetColumn(button, column);
|
||||
BandButtons.Children.Add(button);
|
||||
bandButtons.Add((band, mode, button));
|
||||
TextBlock label = new()
|
||||
{
|
||||
Text = LabelFor(band),
|
||||
FontSize = 11,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
};
|
||||
Border ring = new()
|
||||
{
|
||||
CornerRadius = new CornerRadius(10),
|
||||
BorderThickness = new Thickness(1),
|
||||
BorderBrush = Brushes.Transparent,
|
||||
Padding = new Thickness(6, 1),
|
||||
Margin = new Thickness(2),
|
||||
Child = label,
|
||||
};
|
||||
Border fill = new()
|
||||
{
|
||||
Margin = new Thickness(0, 0, 2, 0),
|
||||
MinWidth = 34,
|
||||
Cursor = new Cursor(StandardCursorType.Hand),
|
||||
Child = ring,
|
||||
};
|
||||
fill.PointerPressed += (_, _) => MoveToBand(band, mode);
|
||||
Grid.SetRow(fill, row);
|
||||
Grid.SetColumn(fill, column);
|
||||
BandButtons.Children.Add(fill);
|
||||
bandCells.Add(new BandCell(band, mode, fill, ring, label));
|
||||
}
|
||||
|
||||
/// N1MM names the HF bands with the metres alone and the VHF bands with the
|
||||
/// unit: 160, 80, 40 … then 6m, 2m, 70cm.
|
||||
private static string LabelFor(Band band) =>
|
||||
band.MegahertzLabel < VhfFromMegahertz
|
||||
? band.Name[..^1]
|
||||
: band.Name.ToLowerInvariant();
|
||||
|
||||
private static string HeadingFor(ModeCategory mode) => mode switch
|
||||
{
|
||||
ModeCategory.Phone => "PH",
|
||||
ModeCategory.Digital => "DIG",
|
||||
_ => "CW",
|
||||
};
|
||||
|
||||
private void MoveToBand(Band band, ModeCategory mode)
|
||||
{
|
||||
if (Logging is null)
|
||||
@@ -64,15 +124,22 @@ public sealed partial class EntryWindow
|
||||
return;
|
||||
}
|
||||
Frequency where = session.BandMemory.Where(band, mode, session.BandPlan);
|
||||
Mode wanted = mode == ModeCategory.Phone ? Modes.ForSideband(where) : Modes.Cw;
|
||||
Mode wanted = mode switch
|
||||
{
|
||||
ModeCategory.Phone => Modes.ForSideband(where),
|
||||
ModeCategory.Digital => Modes.Rtty,
|
||||
_ => Modes.Cw,
|
||||
};
|
||||
Logging.Tune(where, wanted);
|
||||
_ = session.Radio?.TuneAsync(where);
|
||||
boxes[0].Focus();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
/// The button for the band and mode the radio is on is marked, and the
|
||||
/// frequency is kept so the button goes back to it.
|
||||
/// Each cell says what the call being typed would be worth on that band and
|
||||
/// mode. With nothing typed N1MM paints every cell as a station already
|
||||
/// worked. The band the radio is on is ringed rather than filled, so the
|
||||
/// ring does not hide what the cell is saying.
|
||||
private void ShowBandButtons()
|
||||
{
|
||||
if (Logging is null)
|
||||
@@ -80,10 +147,21 @@ public sealed partial class EntryWindow
|
||||
return;
|
||||
}
|
||||
session.BandMemory.Remember(Logging.Frequency, Logging.Mode);
|
||||
BandPanel panel = new(Logging);
|
||||
BuildBandCells(panel);
|
||||
Band? here = Bands.ForFrequency(Logging.Frequency);
|
||||
foreach ((Band band, ModeCategory mode, Button button) in bandButtons)
|
||||
foreach (BandCell cell in bandCells)
|
||||
{
|
||||
button.Classes.Set("here", band == here && mode == Logging.Mode.Category);
|
||||
Verdict? worth = panel.Worth(cell.Band, cell.Mode);
|
||||
Color background = worth is null
|
||||
? Themes.Current.DupeBackground
|
||||
: Verdicts.BackgroundColour(worth);
|
||||
IBrush text = Themes.TextOn(background);
|
||||
cell.Fill.Background = Themes.Brush(background);
|
||||
cell.Label.Foreground = text;
|
||||
cell.Ring.BorderBrush = cell.Band == here && cell.Mode == Logging.Mode.Category
|
||||
? text
|
||||
: Brushes.Transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,20 +32,6 @@
|
||||
<Style Selector="Button.mode.here:pointerover /template/ ContentPresenter">
|
||||
<Setter Property="Background" Value="#3498DB" />
|
||||
</Style>
|
||||
<Style Selector="Button.band">
|
||||
<Setter Property="FontSize" Value="11" />
|
||||
<Setter Property="Padding" Value="4,1" />
|
||||
<Setter Property="Margin" Value="0,0,2,2" />
|
||||
<Setter Property="MinWidth" Value="34" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
||||
</Style>
|
||||
<Style Selector="Button.band.here">
|
||||
<Setter Property="Background" Value="#2980B9" />
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
</Style>
|
||||
<Style Selector="Button.band.here:pointerover /template/ ContentPresenter">
|
||||
<Setter Property="Background" Value="#3498DB" />
|
||||
</Style>
|
||||
<Style Selector="Button.fkey">
|
||||
<Setter Property="FontSize" Value="11" />
|
||||
<Setter Property="Padding" Value="6,3" />
|
||||
|
||||
@@ -39,7 +39,6 @@ public sealed partial class EntryWindow : Window
|
||||
this.radioNumber = radioNumber;
|
||||
InitializeComponent();
|
||||
BuildFunctionKeys();
|
||||
BuildBandButtons();
|
||||
session.Changed += (_, _) => Dispatcher.UIThread.Post(Refresh);
|
||||
session.ContestChanged += (_, _) => Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user