The entry window had a fixed set of boxes with a Name and Comment box beside the exchange. N1MM lays out one row of boxes per contest and nothing else, so this does the same: general logging keeps Name and Comment, and a contest gets the boxes it exchanges. Two new members on `Contest` carry the cases where the boxes and the log columns are not the same list: - `FromExchange1` spreads what was typed in one box across the log columns. Where the other station sends a serial or a district code depending on where it is, N1MM gives it one box and sorts the value into the number, section or zone column from there, so the score and the Cabrillo file read it from the same column N1MM does. - `LogFieldsFor` gives the log window its own column list. Sweepstakes takes the whole exchange in one box and logs it in four columns; `SweepstakesExchange` parses `72 A 74 SCV` in any order, reading from the last word back as N1MM does. The sent serial is now marked as not required and space steps over it along with the two report boxes, because nobody types the number going out. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015NZkFxHde1iifAQemFTHxf
107 lines
2.8 KiB
C#
107 lines
2.8 KiB
C#
using Nonemm.Contests;
|
|
|
|
namespace Nonemm.Session;
|
|
|
|
/// What the operator has typed: the callsign, a value per exchange box, and
|
|
/// which box the cursor is in. The callsign box is field 0.
|
|
public sealed class EntryFields
|
|
{
|
|
private readonly List<string> values;
|
|
|
|
public EntryFields(IReadOnlyList<ExchangeField> exchange)
|
|
{
|
|
Exchange = exchange;
|
|
values = [.. Enumerable.Repeat("", exchange.Count)];
|
|
}
|
|
|
|
public IReadOnlyList<ExchangeField> Exchange { get; }
|
|
|
|
public string Call { get; set; } = "";
|
|
|
|
/// 0 is the callsign box; 1 and up are the exchange boxes in order.
|
|
public int Focus { get; private set; }
|
|
|
|
public int FieldCount => Exchange.Count + 1;
|
|
|
|
public string this[int field]
|
|
{
|
|
get => field == 0 ? Call : values[field - 1];
|
|
set
|
|
{
|
|
if (field == 0)
|
|
{
|
|
Call = value;
|
|
}
|
|
else
|
|
{
|
|
values[field - 1] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string ValueOf(ExchangeSlot slot)
|
|
{
|
|
for (int at = 0; at < Exchange.Count; at++)
|
|
{
|
|
if (Exchange[at].Slot == slot)
|
|
{
|
|
return values[at];
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public void Set(ExchangeSlot slot, string value)
|
|
{
|
|
for (int at = 0; at < Exchange.Count; at++)
|
|
{
|
|
if (Exchange[at].Slot == slot)
|
|
{
|
|
values[at] = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void FocusOn(int field) => Focus = Math.Clamp(field, 0, FieldCount - 1);
|
|
|
|
/// What space and tab do: move to the next box the operator types in, and
|
|
/// round to the callsign again from the last one. The report boxes and the
|
|
/// sent serial are stepped over, because nobody types 599 or the number
|
|
/// they are sending — N1MM steps over the same three and fills them in.
|
|
public void Advance() => Focus = Next(1);
|
|
|
|
public void Retreat() => Focus = Next(-1);
|
|
|
|
private int Next(int by)
|
|
{
|
|
int at = Focus;
|
|
for (int step = 0; step < FieldCount; step++)
|
|
{
|
|
at = (at + by + FieldCount) % FieldCount;
|
|
if (at == 0 || !IsFilledIn(Exchange[at - 1]))
|
|
{
|
|
return at;
|
|
}
|
|
}
|
|
return Focus;
|
|
}
|
|
|
|
private static bool IsFilledIn(ExchangeField field) =>
|
|
field.IsSent || field.Kind == ExchangeFieldKind.Report;
|
|
|
|
/// True when everything the contest asks for has been typed.
|
|
public bool IsComplete =>
|
|
Call.Trim().Length > 0 &&
|
|
Exchange.Where((f, at) => f.IsRequired && values[at].Trim().Length == 0).Any() == false;
|
|
|
|
public void Clear()
|
|
{
|
|
Call = "";
|
|
for (int at = 0; at < values.Count; at++)
|
|
{
|
|
values[at] = "";
|
|
}
|
|
Focus = 0;
|
|
}
|
|
}
|