Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and a release's notes are its section. The procedure is in [`docs/RELEASING.md`]

## [Unreleased]

### Changed

- Trigger sets are made where rules are written. On F2, F3, F4 and F6, `s` opens a trigger sets screen: make a set
(the character in front uses it at once), rename it (every character's reference follows), describe it, delete it,
and tick which characters use it. Each set's heading now says who uses it, and a set nobody uses says so in the
warning colour, since its rules do nothing. Undo on the list screen covers changes made there. The window's
settings get the same: a *+ Set* button and a page per set on Triggers, Aliases, Keypad and Timers, a *Set…* link
from a rule to its set, and *+ New set* on a character's page. A character's own page (F5) still chooses its sets.

## [0.3.8] - 2026-11-24

### Added
Expand Down
331 changes: 314 additions & 17 deletions src/SharpMUTerm.Avalonia/ListEditorView.cs

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion src/SharpMUTerm.Avalonia/SettingsWindow.Worlds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ internal sealed partial class SettingsWindow
/// <summary>Each set's check box on a character's page, by set name, for a test.</summary>
internal Dictionary<string, CheckBox> SetBoxes { get; } = new(StringComparer.OrdinalIgnoreCase);

/// <summary>The character page's link that makes a new set used by that character, for a test.</summary>
internal Button? NewSetLink { get; private set; }

/// <summary>The server-information card's rows, as text, for a test.</summary>
internal List<string> ServerInfoLines { get; } = [];

Expand Down Expand Up @@ -1004,6 +1007,22 @@ private void FillSets(CharacterDefinition character)
heading.Children.Add(edit);
}

// A set is made where it is wanted: here it is made for this character, already ticked.
var make = LinkButton("+ New set", NativeTokens.PageSmall);
AutomationProperties.SetName(make, $"Make a new trigger set used by {character.Name}");
make.Margin = new Thickness(0, 0, NativeTokens.Space12, 0);
make.Click += (_, _) => _form.NewSet(character);
NewSetLink = make;
var links = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Right };
foreach (var link in heading.Children.OfType<Button>().ToList())
{
heading.Children.Remove(link);
links.Children.Add(link);
}

links.Children.Insert(0, make);
Grid.SetColumn(links, 1);
heading.Children.Add(links);
body.Children.Add(heading);
body.Children.Add(new TextBlock
{
Expand All @@ -1017,7 +1036,7 @@ private void FillSets(CharacterDefinition character)
var assignments = _form.Assignments(character);
if (assignments.Count == 0)
{
body.Children.Add(new TextBlock { Text = "There is no trigger set yet. Make one on the Triggers page.", Foreground = DimInk, Margin = new Thickness(0, 0, 0, NativeTokens.Space12) });
body.Children.Add(new TextBlock { Text = "There is no trigger set yet. Make one with + New set; it starts ticked for this character.", Foreground = DimInk, Margin = new Thickness(0, 0, 0, NativeTokens.Space12) });
return;
}

Expand Down
126 changes: 126 additions & 0 deletions src/SharpMUTerm.Client/Settings/SettingsForm.Sets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using SharpMUTerm.Core.Configuration;

namespace SharpMUTerm.Client.Settings;

/// <summary>
/// The trigger sets themselves, as the list pages (F2, F3, F4, F6) manage them: make one, name it, describe it, choose
/// who uses it, delete it. Every change goes through the funnel like any other edit, with a name for the undo history;
/// the operations are <see cref="TriggerSetEditing"/>'s, which the cell sets screen runs too.
/// </summary>
public sealed partial class SettingsForm
{
/// <summary>The character a set made here is used by from the start: the one the form was opened for.</summary>
public CharacterDefinition? SetOwner => _character;

/// <summary>Every character, with whether it uses <paramref name="set"/>.</summary>
public IReadOnlyList<SetUser> UsersOf(TriggerSet set) => TriggerSetEditing.Users(_config, set);

/// <summary>Who uses <paramref name="set"/>, as its heading says it (<c>used by Corvid</c>).</summary>
public string UsageOf(TriggerSet set)
{
ArgumentNullException.ThrowIfNull(set);
return TriggerSetEditing.Usage(_config.Worlds, set.Name);
}

/// <summary>Whether any character uses <paramref name="set"/>.</summary>
public bool IsUsed(TriggerSet set)
{
ArgumentNullException.ThrowIfNull(set);
return TriggerSetEditing.IsUsed(_config.Worlds, set.Name);
}

/// <summary>Whether <paramref name="set"/> is one of the player's own sets (not a package's), so it can be changed.</summary>
public bool IsOwnSet(TriggerSet set) => _config.TriggerSets.Contains(set);

/// <summary>
/// Makes a new empty set through the funnel, used by the character the form was opened for, and selects nothing in
/// it (it has no items yet). Returns the set, which is in the configuration once the commit lands.
/// </summary>
public TriggerSet NewSet() => NewSet(_character);

/// <summary>Makes a new empty set through the funnel, used by <paramref name="usedBy"/> when one is given.</summary>
public TriggerSet NewSet(CharacterDefinition? usedBy)
{
var owner = usedBy;
var set = new TriggerSet
{
Name = WorldEditing.Available(_config.TriggerSets.ToArray().Select(s => s.Name), TriggerSetEditing.NewSetName),
};
Commit(
() =>
{
// Named again as it lands: two sets made before either commit would otherwise share a name.
set.Name = WorldEditing.Available(_config.TriggerSets.ToArray().Select(s => s.Name), TriggerSetEditing.NewSetName);
_config.TriggerSets = [.. _config.TriggerSets, set];
if (owner is not null)
{
TriggerSetEditing.Use(owner, set.Name, on: true);
}
},
"making a set");
Comment thread
HarryCordewener marked this conversation as resolved.
Resolved
return set;
}

/// <summary>Renames <paramref name="set"/> and every reference to it; the reason when the name is refused, else null.</summary>
public string? RenameSet(TriggerSet set, string name)
{
ArgumentNullException.ThrowIfNull(set);
if (!IsOwnSet(set))
{
return ReadOnlyRefusal;
}

if (TriggerSetEditing.NameProblem(_config, set, name) is { } problem)
{
return problem;
}

if (string.Equals(set.Name, name.Trim(), StringComparison.Ordinal))
{
return null;
}

Commit(() => TriggerSetEditing.Rename(_config, set, name), "renaming a set");
return null;
}

/// <summary>Sets <paramref name="set"/>'s description (blank clears it); false for a package's set.</summary>
public bool DescribeSet(TriggerSet set, string? description)
{
ArgumentNullException.ThrowIfNull(set);
if (!IsOwnSet(set))
{
return false;
}

var text = string.IsNullOrWhiteSpace(description) ? null : description.Trim();
if (string.Equals(set.Description, text, StringComparison.Ordinal))
{
return true;
}

Commit(() => set.Description = text, "describing a set");
return true;
}

/// <summary>Deletes <paramref name="set"/> and every character's use of it; false for a package's set.</summary>
public bool DeleteSet(TriggerSet set)
{
ArgumentNullException.ThrowIfNull(set);
if (!IsOwnSet(set))
{
return false;
}

if (_item is not null && Sections.Any(s => s.Collection?.ItemsIn(set).Any(i => ReferenceEquals(i, _item)) == true))
{
_item = null;
}

Commit(() => TriggerSetEditing.Delete(_config, set), "deleting a set");
return true;
}

/// <summary>What deleting <paramref name="set"/> costs, in words, for the question asked first.</summary>
public string SetDeletion(TriggerSet set) => TriggerSetEditing.Deletion(_config.Worlds, set);
}
5 changes: 3 additions & 2 deletions src/SharpMUTerm.Client/Settings/SettingsForm.Worlds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,11 @@ public bool Assign(CharacterDefinition character, TriggerSet set, bool on)
return false;
}

var name = set.Name;
// The name is read when the change lands, so a rename queued ahead of it is the name written.
Commit(
() =>
{
var name = set.Name;
var names = character.TriggerSets.Where(n => !string.Equals(n, name, StringComparison.OrdinalIgnoreCase)).ToList();
if (on)
{
Expand All @@ -410,7 +411,7 @@ public bool Assign(CharacterDefinition character, TriggerSet set, bool on)

character.TriggerSets = names;
},
on ? $"using set {name}" : $"dropping set {name}");
on ? $"using set {set.Name}" : $"dropping set {set.Name}");
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/SharpMUTerm.Client/Settings/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ _item is Trigger trigger
? TriggerPreview.Run(_context.Lines, trigger.MatchType, pattern ?? trigger.Pattern, trigger.CaseSensitive, samples)
: null;

private bool IsPackageSet(TriggerSet set) => _config.Packages.Any(p => p.Sets.Contains(set));
/// <summary>Whether <paramref name="set"/> is an installed package's, which no edit may change.</summary>
public bool IsPackageSet(TriggerSet set) => _config.Packages.Any(p => p.Sets.Contains(set));

private static IEnumerable<object> ItemsOf(TriggerSet set) =>
set.Triggers.Cast<object>().Concat(set.Aliases).Concat(set.Timers).Concat(set.Macros);
Expand Down
Loading
Loading