Skip to content

Add piece filter functionality to character creation system #429

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class CharacterCreationComponent : Component, IDisposable

public List<Color> Swatches = [Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black, Colors.Black];

public string PieceFilter = string.Empty;

public CharacterCreationComponent()
{
Background = Assets.Load<Texture>("textures/backgrounds/character_creation_1.qoi");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class CharacterCreationSystem : Walgelijk.System
private static readonly MenuCharacterRenderer menuCharacterRenderer = new();

private const float ButtonBarHeight = 50;
private const float FilterBoxHeight = 42;

public override void Render()
{
Expand Down Expand Up @@ -427,20 +428,33 @@ private bool PieceGrid<T>(CharacterComponent character, Registry<T> registry, re

float padding = Onion.Tree.CurrentNode!.GetInstance().Theme.Padding;

if (!Scene.FindAnyComponent<CharacterCreationComponent>(out var data))
return false;

// Add filter controls
Ui.Layout.FitWidth().Scale(-32, 0).Height(32).StickTop().StickLeft().Move(0, 5);
Ui.StringInputBox(ref data.PieceFilter, new TextBoxOptions(Localisation.Get("experiment-filter")));

Ui.Layout.Size(32, 32).StickRight().StickTop().Move(0, 5);
if (Ui.ImageButton(Textures.UserInterface.SmallExitClose.Value, ImageContainmentMode.Center))
data.PieceFilter = string.Empty;

bool returnValue = false;
Ui.Layout.FitContainer(1, 1, false).StickLeft(false).StickBottom(false).VerticalLayout().Overflow(false, true);
// Offset filter box height
Ui.Layout.FitContainer(1, 1, false).StickLeft(false).StickBottom(false).Scale(0, -FilterBoxHeight).Move(0, FilterBoxHeight).VerticalLayout().Overflow(false, true);
Ui.Theme.ScrollbarWidth(24).ForegroundColor(Colors.Black).Once();
Ui.StartScrollView(false, identity: callsite);
{
float w = Onion.Tree.CurrentNode!.GetInstance().Rects.GetInnerContentRect().Width - padding;
int i = 0;
float x = 0;
float rowHeight = (w) / preferredColumns;
foreach (var piece in registry.GetAllValues().OrderBy(static p => p.DisplayName).OrderBy(static p => p.Order))
foreach (var piece in registry.GetAllValues()
.Where(p => !p.Hidden && (string.IsNullOrEmpty(data.PieceFilter) ||
p.DisplayName.Contains(data.PieceFilter, StringComparison.InvariantCultureIgnoreCase)))
.OrderBy(static p => p.DisplayName)
.OrderBy(static p => p.Order))
{
if (piece.Hidden)
continue;

if (x > w || i == 0)
{
x = rowHeight;
Expand Down Expand Up @@ -471,7 +485,8 @@ private bool PieceGrid<T>(CharacterComponent character, Registry<T> registry, re
x += rowHeight;
}

Ui.End(); // end the last row
if (i > 0) // Only end the last row if we actually created any rows
Ui.End();
}
Ui.End();

Expand Down