-
Notifications
You must be signed in to change notification settings - Fork 5
Implement subpage generation #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2a96b32
Format code base
dplochcoder 6040260
Fix warnings
dplochcoder af083cc
Make LocalizedText hashable.
dplochcoder 655ad83
Use LocalizedText for menu screen titles.
dplochcoder a22565b
Sort config elements by key.
dplochcoder 49ebe33
Implement a Tree collection utility.
dplochcoder c618112
Implement automatic subpage generation API.
dplochcoder 7a0f761
Bump version.
dplochcoder 1c51529
Address PR comments
dplochcoder 3b943c4
Address more PR comments
dplochcoder 5a906e4
Merge branch 'main' into subpages
flibber-hk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Silksong.ModMenu.Internal; | ||
|
|
||
| /// <summary> | ||
| /// A recursive tree structure which supports lazy node creation and postfix traversal. | ||
| /// </summary> | ||
| internal class TreeNode<K, V> | ||
| where V : new() | ||
| { | ||
| private readonly Dictionary<K, TreeNode<K, V>> subtrees = []; | ||
|
|
||
| public V Value = new(); | ||
|
|
||
| public IReadOnlyDictionary<K, TreeNode<K, V>> Subtrees => subtrees; | ||
|
|
||
| public TreeNode<K, V> this[IEnumerable<K> keys] | ||
| { | ||
| get | ||
| { | ||
| TreeNode<K, V> tree = this; | ||
| foreach (var key in keys) | ||
| { | ||
| if (tree.subtrees.TryGetValue(key, out var subtree)) | ||
| tree = subtree; | ||
| else | ||
| { | ||
| subtree = new(); | ||
| tree.subtrees[key] = subtree; | ||
| tree = subtree; | ||
| } | ||
| } | ||
| return tree; | ||
| } | ||
| } | ||
|
|
||
| private void ForEachPostfixRecursive( | ||
| List<K> keys, | ||
| Action<IReadOnlyList<K>, TreeNode<K, V>> action | ||
| ) | ||
| { | ||
| foreach (var e in subtrees) | ||
| { | ||
| keys.Add(e.Key); | ||
| e.Value.ForEachPostfixRecursive(keys, action); | ||
| keys.RemoveAt(keys.Count - 1); | ||
| } | ||
| action(keys, this); | ||
| } | ||
|
|
||
| public void ForEachPostfix(Action<IReadOnlyList<K>, TreeNode<K, V>> action) => | ||
| ForEachPostfixRecursive([], action); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Silksong.ModMenu.Elements; | ||
|
|
||
| namespace Silksong.ModMenu.Plugin; | ||
|
|
||
| /// <summary> | ||
| /// A config entry attribute that designates how this element should be organized into subpages hierarchically. | ||
| /// If present, this overrides the default hierarchy names generated (or not generated) by ConfigEntryFactory. | ||
| /// </summary> | ||
| public record ConfigEntrySubgroup | ||
| { | ||
| /// <summary> | ||
| /// Construct subgroup names from a list. | ||
| /// </summary> | ||
| public ConfigEntrySubgroup(IEnumerable<LocalizedText> subgroups) => Subgroups = [.. subgroups]; | ||
|
|
||
| /// <summary> | ||
| /// Construct subgroup names from explicit parameters. | ||
| /// </summary> | ||
| public ConfigEntrySubgroup(LocalizedText name1, params LocalizedText[] otherNames) => | ||
| Subgroups = [name1, .. otherNames]; | ||
|
|
||
| /// <summary> | ||
| /// The subgroup names that designate this config element's place in the subpage hierarchy. An empty list designates the root page. | ||
| /// | ||
| /// This can describe the page this entry belogs to, or the full path to the element itself explicitly. | ||
| /// Both will work for grouping purposes, but the choice must be consistent throughout the plugin. The default implementation generates full paths to each individual element. | ||
| /// </summary> | ||
| public readonly IReadOnlyList<LocalizedText> Subgroups; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace Silksong.ModMenu.Plugin; | ||
|
|
||
| /// <summary> | ||
| /// Marker interface for a mod menu that generates hierarchical submenus, based on config keys. | ||
| /// </summary> | ||
| public interface IModMenuNestedMenu : IModMenuInterface | ||
| { | ||
| /// <summary> | ||
| /// The minimum number of elements required in a subgroup to generate a screen for it. | ||
|
dplochcoder marked this conversation as resolved.
|
||
| /// If a sub-page has too few elements, it is flattened into its containing page. | ||
| /// </summary> | ||
| int MinSubgroupSize() => 2; | ||
| } | ||
|
dplochcoder marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.