You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/invui2/window.md
+105-1Lines changed: 105 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -479,10 +479,114 @@ The smithing window can be created using `#!kotlin SmithingWindow.builder()`. It
479
479
480
480
### Stonecutter Window
481
481
482
-
The stonecutter window can be created using `#!kotlin StonecutterWindow.builder()`. It consists of a `2x1` upper gui, a `4xN` buttons gui, where `N` can be any number, and a `9x4` lower gui. You can use the scroll bar to scroll through the buttons. A button can be selected and deselected by both the server and the player. You can register a selection handler via `addSelectedSlotChangeHandler`.
482
+
The stonecutter window can be created using `#!kotlin StonecutterWindow.builder()`. It consists of a `2x1` upper gui, a `4xN` buttons gui, where `N` can be any number, and a `9x4` lower gui. You can use the scroll bar to scroll through the buttons. A button can be selected and deselected by both the server and the player. You can register a selection handler via `addSelectedSlotChangeHandler`. Clicking a button also fires the click handlers of the corresponding item.
483
483
484
484
{width=500}
485
485
486
+
??? example "Example: Using the buttons as tabs"
487
+
488
+
=== "Kotlin"
489
+
```kotlin
490
+
val woolTypes = Tag.ITEMS_WOOL.values.sortedBy { it.ordinal }
val buttonsGui = Gui.empty(4, Math.ceilDiv(woolTypes.size, 4))
504
+
for (i in woolTypes.indices) {
505
+
buttonsGui[i] = Item.builder()
506
+
.setItemProvider(ItemStack.of(woolTypes[i]))
507
+
.addClickHandler { lowerGui.tab = i }
508
+
.build()
509
+
}
510
+
511
+
StonecutterWindow.builder()
512
+
.setButtonsGui(buttonsGui)
513
+
.setLowerGui(lowerGui)
514
+
.setSelectedSlot(0) // (1)!
515
+
.open(player)
516
+
```
517
+
518
+
1. By default, no button is selected initially. However, since the default tab is `0`, having button `0` selected initially makes sense in this case.
519
+
520
+
=== "Kotlin (DSL)"
521
+
!!! warning "Experimental, see [Declarative Menus](declarative-menus.md)"
522
+
523
+
```kotlin
524
+
stonecutterWindow(player) {
525
+
val woolTypes = Tag.ITEMS_WOOL.values.sortedBy { it.ordinal }
526
+
lowerGui by tabGui(
527
+
"x x x x x x x x x",
528
+
"x x x x x x x x x",
529
+
"x x x x x x x x x",
530
+
"x x x x x x x x x"
531
+
) {
532
+
'x' by Markers.CONTENT_LIST_SLOT_HORIZONTAL
533
+
tabs by woolTypes.map { Gui.of(9, 4, Item.simple(ItemStack.of(it))) }
534
+
tab by selectedSlot // (1)!
535
+
}
536
+
buttonsGui by Gui.empty(4, Math.ceilDiv(woolTypes.size, 4)).also { gui ->
537
+
for (i in woolTypes.indices) {
538
+
gui[i] = Item.simple(ItemStack.of(woolTypes[i]))
539
+
}
540
+
}
541
+
}.open()
542
+
```
543
+
544
+
1. This combines the tab- and selected slot properties such that selecting a button automatically switches the tab and switching the tab automatically selects the corresponding button.
545
+
546
+
=== "Java"
547
+
```java
548
+
var woolTypes = Tag.ITEMS_WOOL.getValues().stream()
??? example "Example: Using the buttons as an inventory"
487
591
488
592
The following example embeds a `VirtualInventory` into the buttons gui. Note that updating the buttons resets the scroll bar to the top, so this is not a practical use case.
0 commit comments