Added dynamic-size components

This commit is contained in:
Auxilor
2022-09-30 13:29:50 +01:00
parent 27d2b5c8a4
commit e1c063d5f4
4 changed files with 29 additions and 5 deletions

View File

@@ -25,6 +25,24 @@ public interface GUIComponent {
*/
int getColumns();
/**
* Initialize the component.
* <p>
* This is called before getRows / getColumns is queried,
* and allows for dynamically sized components.
* <p>
* getRows and getColumns can return values bigger than this,
* it will simply prevent the component from being added at
* this position (for minimum-sized components).
*
* @param maxRows The maximum number of rows.
* @param maxColumns The maximum number of columns.
*/
default void init(final int maxRows,
final int maxColumns) {
// Most components will not require initialization.
}
/**
* Get the slot at a certain position in the component.
* <p>

View File

@@ -161,7 +161,7 @@ public interface MenuBuilder extends PageBuilder {
* @param action The action.
* @return THe builder.
*/
default MenuBuilder onSignalReceive(@NotNull final SignalHandler action) {
default MenuBuilder onSignal(@NotNull final SignalHandler action) {
return this;
}

View File

@@ -142,9 +142,9 @@ fun MenuBuilder.addPage(page: Int, creation: PageBuilder.() -> Unit): MenuBuilde
return this.addPage(Page(page, builder.build()))
}
/** @see MenuBuilder.onSignalReceive */
inline fun <reified T : Signal> MenuBuilder.onSignalReceive(crossinline handler: (Player, Menu, T) -> Unit): MenuBuilder {
return this.onSignalReceive(object : SignalHandler<T>(T::class.java) {
/** @see MenuBuilder.onSignal */
inline fun <reified T : Signal> MenuBuilder.onSignal(crossinline handler: (Player, Menu, T) -> Unit): MenuBuilder {
return this.onSignal(object : SignalHandler<T>(T::class.java) {
override fun handle(player: Player, menu: Menu, signal: T) =
handler(player, menu, signal)
})