Skip to content

Lay dialog buttons out in a grid: columns and button width - #3066

Merged
tastybento merged 1 commit into
developfrom
feature/dialog-grid-layout
Aug 15, 2026
Merged

Lay dialog buttons out in a grid: columns and button width#3066
tastybento merged 1 commit into
developfrom
feature/dialog-grid-layout

Conversation

@tastybento

Copy link
Copy Markdown
Member

DialogBuilder can only produce Paper's default two-wide list of buttons: it never passes a column count and never passes a button width. Anything grid-shaped — a map, a picker, a calendar, a seat chooser — has to skip the API and build a Paper dialog by hand. That is what ChunkBlock ended up doing for its territory map, where every chunk is a button and the grid has to be as wide as the map.

What's added

DialogBuilder#columns(int) — lays a multi-action dialog's buttons out in that many columns.

new DialogButton(label, tooltip, width, onClick) — a button of a given width, matching Paper's ActionButton.create parameter order. Plus DialogButton#withWidth(int), so a button made by DialogButton.of(user, key, handler) can still be sized, and DialogButton#width().

Width applies to confirmation buttons too — the client sizes those the same way.

DialogBuilder grid = new DialogBuilder().title(user, "mygame.map.title").columns(9);
for (Tile tile : tiles) {
    grid.button(new DialogButton(tile.glyph(), tile.tooltip(), 26, u -> select(u, tile)));
}
grid.build().show(user);

Behaviour when untouched

Nothing changes for existing callers, and deliberately not by re-stating today's defaults:

  • a dialog left at DEFAULT_COLUMNS is built without a column count
  • a button left at DEFAULT_WIDTH is built without a width

So the client keeps deciding, and this API does not pin whatever default Paper happens to use. The two constants are public because callers need to be able to say "leave it alone" explicitly.

Validation

Values the client would reject are rejected here first, with a message that says which value was wrong: columns < 1, and width outside Paper's documented 1–1024 range.

Tests

DialogBuilderTest gains six cases: default widths (constructor and locale factory), a width that sticks, withWidth copying everything else and leaving the original alone, out-of-range widths and both ends of the valid range, and columns being fluent and validated. Whole suite green — 3462 tests.

Note the limitation the test class already documents: build() needs the server's dialog registry provider, which MockBukkit does not supply, so the tests cover the builder's own logic rather than the finished Paper object. The two new values reach Paper through MultiActionType.Builder#columns and ActionButton.Builder#width; the grid itself has been exercised in game via ChunkBlock's map, which drives those same two Paper calls directly today and will switch to this API once it is released.

🤖 Generated with Claude Code

https://claude.ai/code/session_017EZEwab2kL4i1FNnBYvSmp

DialogBuilder could only produce Paper's default two-wide list of
buttons, because it never passed a column count and never passed a
button width. Anything grid-shaped — a map, a picker, a calendar — had
to skip the API and build a Paper dialog by hand.

Adds DialogBuilder#columns(int) for the layout and a DialogButton
constructor taking a width, plus withWidth() so a button made by the
locale factory can still be sized. Width applies to confirmation buttons
too, which the client also sizes.

Both keep the current behaviour when untouched: a dialog left at
DEFAULT_COLUMNS is built without stating a column count and a button
left at DEFAULT_WIDTH without stating a width, so the client goes on
deciding and this API does not pin whatever default Paper uses today.
Values outside what the client accepts (columns < 1, width outside
1-1024) are rejected here with a clear message rather than deeper in
Paper.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017EZEwab2kL4i1FNnBYvSmp
@sonarqubecloud

Copy link
Copy Markdown

@tastybento
tastybento merged commit f89e04f into develop Aug 15, 2026
3 checks passed
@tastybento tastybento mentioned this pull request Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant