Skip to content

Commit

Permalink
Add some docs; Tweak refresh delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Jul 18, 2024
1 parent dca1ee5 commit ff9c12c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
6 changes: 3 additions & 3 deletions ComponentSelectorAdditions/DefaultConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace ComponentSelectorAdditions
/// </summary>
public sealed class DefaultConfig : ConfigSection
{
private static readonly DefiningConfigKey<float> _directButtonHeight = new("DirectButtonHeight", "The height of a button that is the direct child of the current category, in canvas units. Default is 32.", () => 32)
private static readonly DefiningConfigKey<float> _directButtonHeight = new("DirectButtonHeight", "The height of a button that is targeting the direct child of the current category, in canvas units. The default value is 32.", () => 32)
{
new ConfigKeyRange<float>(32, 64)
};

private static readonly DefiningConfigKey<float> _indirectButtonHeight = new("IndirectButtonHeight", "The height of a button that is not a direct child of the current category and has to fit a category path as well, in canvas units. Default is 48.", () => 48)
private static readonly DefiningConfigKey<float> _indirectButtonHeight = new("IndirectButtonHeight", "The height of a button that is not targeting a direct child of the current category and has to fit a category path as well, in canvas units. The default value is 48.", () => 48)
{
new ConfigKeyRange<float>(32, 96)
new ConfigKeyRange<float>(32, 64)
};

/// <summary>
Expand Down
41 changes: 34 additions & 7 deletions ComponentSelectorAdditions/DefaultHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

namespace ComponentSelectorAdditions
{
/// <summary>
/// Handles the default behavior for the <see cref="Injector"/> events.
/// </summary>
public sealed class DefaultHandler : ConfiguredResoniteMonkey<DefaultHandler, DefaultConfig>,
ICancelableEventHandler<EnumerateCategoriesEvent>, ICancelableEventHandler<EnumerateComponentsEvent>,
ICancelableEventHandler<BuildCategoryButtonEvent>, ICancelableEventHandler<BuildGroupButtonEvent>, ICancelableEventHandler<BuildComponentButtonEvent>,
Expand All @@ -26,6 +29,15 @@ public sealed class DefaultHandler : ConfiguredResoniteMonkey<DefaultHandler, De
/// <inheritdoc/>
public bool SkipCanceled => true;

/// <summary>
/// Formats the path from the <paramref name="rootCategory"/> to the <paramref name="subCategory"/>
/// or to its root prettily with the <paramref name="delimiter"/>.
/// </summary>
/// <typeparam name="T">The type of the <see cref="CategoryNode{T}"/>s.</typeparam>
/// <param name="subCategory">The category the path leads to.</param>
/// <param name="rootCategory">The root that the path starts from.</param>
/// <param name="delimiter">The string between the category names.</param>
/// <returns>The trimmed, path-like string.</returns>
public static string? GetPrettyPath<T>(CategoryNode<T>? subCategory, CategoryNode<T>? rootCategory = null, string delimiter = " > ")
{
var segments = EnumerateParents(subCategory, rootCategory);
Expand All @@ -36,6 +48,14 @@ public sealed class DefaultHandler : ConfiguredResoniteMonkey<DefaultHandler, De
return segments.Reverse().Join(delimiter: delimiter) + delimiter.TrimEnd();
}

/// <summary>
/// Creates a labeled text field as a generic argument input.
/// </summary>
/// <param name="ui">The <see cref="UIBuilder"/> to use for the construction.</param>
/// <param name="component">The type that the generic argument input is for.</param>
/// <param name="genericArgument">The generic argument "type".</param>
/// <param name="genericArgumentPrefiller">The <see cref="ComponentSelector.GenericArgumentPrefiller"/> target.</param>
/// <returns>The labeled <see cref="TextField"/> that was created.</returns>
public static TextField MakeGenericArgumentInput(UIBuilder ui, Type component, Type genericArgument, GenericArgumentPrefiller? genericArgumentPrefiller = null)
{
var textField = ui.HorizontalElementWithLabel(genericArgument.Name, .05f, () =>
Expand All @@ -54,7 +74,16 @@ public static TextField MakeGenericArgumentInput(UIBuilder ui, Type component, T
return textField;
}

public static void MakePermanentButton(UIBuilder ui, string? category, LocaleString name, colorX tint, ButtonEventHandler<string> callback, string argument)
/// <summary>
/// Creates a labeled button that can optionally show a category path as well.
/// </summary>
/// <param name="ui">The <see cref="UIBuilder"/> to use for the construction.</param>
/// <param name="name">The label on the button.</param>
/// <param name="tint">The background color of the button.</param>
/// <param name="callback">The <see cref="ButtonEventHandler{T}"/> to call when the button is pressed.</param>
/// <param name="argument">The argument for the <paramref name="callback"/>.</param>
/// <param name="category">The optional category path to show.</param>
public static void MakePermanentButton(UIBuilder ui, LocaleString name, colorX tint, ButtonEventHandler<string> callback, string argument, string? category = null)
{
ui.PushStyle();
ui.Style.MinHeight = category is not null ? ConfigSection.IndirectButtonHeight : ConfigSection.DirectButtonHeight;
Expand All @@ -79,8 +108,7 @@ public static void MakePermanentButton(UIBuilder ui, string? category, LocaleStr
buttonLabel.RectTransform.OffsetMax.Value = float2.Zero;

ui.NestInto(header);
var text = ui.Text(category, parseRTF: false);
//text.Color.Value = RadiantUI_Constants.Neutrals.LIGHT;
ui.Text(category, parseRTF: false);
}

ui.PopStyle();
Expand Down Expand Up @@ -113,7 +141,7 @@ void ICancelableEventHandler<BuildGroupButtonEvent>.Handle(BuildGroupButtonEvent
var tint = RadiantUI_Constants.Sub.PURPLE;
var argument = $"{eventData.ItemCategory.GetPath()}:{eventData.Group}";

MakePermanentButton(eventData.UI, category, eventData.GroupName, tint, selector.OpenGroupPressed, argument);
MakePermanentButton(eventData.UI, eventData.GroupName, tint, selector.OpenGroupPressed, argument, category);

eventData.Canceled = true;
}
Expand Down Expand Up @@ -154,15 +182,14 @@ void ICancelableEventHandler<BuildComponentButtonEvent>.Handle(BuildComponentBut
ButtonEventHandler<string> callback = component.IsGeneric ? selector.OpenGenericTypesPressed : selector.OnAddComponentPressed;
var argument = $"{(component.IsGeneric ? $"{path.Path}/{component.Type.AssemblyQualifiedName}" : selector.World.Types.EncodeType(component.Type))}{(component.IsGeneric && path.HasGroup ? $"?{path.Group}" : "")}";

MakePermanentButton(eventData.UI, category, component.NiceName, tint, callback, argument);
MakePermanentButton(eventData.UI, component.NiceName, tint, callback, argument, category);

eventData.Canceled = true;
}

void ICancelableEventHandler<BuildCategoryButtonEvent>.Handle(BuildCategoryButtonEvent eventData)
{
MakePermanentButton(eventData.UI, null,
GetPrettyPath(eventData.ItemCategory, eventData.RootCategory),
MakePermanentButton(eventData.UI, GetPrettyPath(eventData.ItemCategory, eventData.RootCategory),
RadiantUI_Constants.Sub.YELLOW,
eventData.Selector.OnOpenCategoryPressed,
eventData.ItemCategory.GetPath());
Expand Down
3 changes: 3 additions & 0 deletions ComponentSelectorAdditions/Locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"ComponentSelectorAdditions.RecentsCategories.Description": "Fügt 'Recents' Kategorien zu den Wurzelkategorien von Komponenten-Selektoren und ProtoFlux Nodebrowsern hinzu, welche die zuletzt Genutzten auflisten.",
"ComponentSelectorAdditions.SearchBar.Description": "Fügt eine Suchleiste zu Komponenten-Selektoren hinzu, welche es erlaubt Komponenten und ProtoFlux Nodes zu suchen.",

"ComponentSelectorAdditions.Defaults.DirectButtonHeight.Description": "Die Höhe eines Buttons, der ein direktes Kind der aktuellen Kategorie als Ziel hat, in Canvas-Einheiten. Der Standardwert ist 32.",
"ComponentSelectorAdditions.Defaults.IndirectButtonHeight.Description": "Die Höhe eines Buttons, der kein direktes Kind der aktuellen Kategorie als Ziel hat und auch Platz für einen Kategoriepfad braucht, in Canvas-Einheiten. Der Standardwert ist 48.",

"ComponentSelectorAdditions.Favorites.SortFavoriteCategoriesToTop.Description": "Sortiere favorisierte Kategorien über unfavorisierten.",
"ComponentSelectorAdditions.Favorites.SortFavoriteComponentsToTop.Description": "Sortiere favorisierte Komponenten / Nodes über unfavorisierten.",
"ComponentSelectorAdditions.Favorites.SortFavoriteConcreteGenericsToTop.Description": "Sortiere favorisierte konkrete Versionen von generischen Komponenten / Nodes über unfavorisierten.",
Expand Down
2 changes: 1 addition & 1 deletion ComponentSelectorAdditions/SearchConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class SearchConfig : ConfigSection
new ConfigKeyRange<int>(1, 128)
};

private static readonly DefiningConfigKey<float> _searchRefreshDelay = new("SearchRefreshDelay", "Time to wait after search input change before refreshing the results. 0 to always refresh.", () => .5f)
private static readonly DefiningConfigKey<float> _searchRefreshDelay = new("SearchRefreshDelay", "Time to wait after search input change before refreshing the results. 0 to always refresh.", () => .4f)
{
new ConfigKeyQuantity<float, Time>(new UnitConfiguration("s", "0", " ", new [] {"s", "ms"}), null, 0, 2)
};
Expand Down

0 comments on commit ff9c12c

Please sign in to comment.