Added simple compounds

This commit is contained in:
bluefireoly
2020-10-30 15:39:05 +01:00
parent 5ce269dab3
commit f9b46fc0e3
2 changed files with 43 additions and 3 deletions

View File

@@ -179,6 +179,14 @@ class GUIPageBuilder<T : ForInventory>(
)
)
/**
* Creates a new compound, holding simple compound elements.
*/
fun createSimpleCompound() = createCompound<GUICompoundElement<T>>(
iconGenerator = { it.icon },
onClick = { clickEvent, element -> element.onClick?.invoke(clickEvent) }
)
/**
* Creates a new compound, holding data which can be displayed
* in any compound space.
@@ -204,8 +212,28 @@ class GUIPageBuilder<T : ForInventory>(
}
/**
* Creates a new compound, holding data which can be displayed
* in any compound space.
* Creates a new compound, holding simple compound elements.
* This compound is strictly a rectangle.
* The space is automatically defined.
*
* This method sets the element type to
* [GUICompoundElement]. The iconGenerator and onClick callback
* are automatically defined.
*/
fun createSimpleRectCompound(
fromSlot: SingleInventorySlot<out T>,
toSlot: SingleInventorySlot<out T>
) = createRectCompound<GUICompoundElement<T>>(
fromSlot, toSlot,
iconGenerator = { it.icon },
onClick = { clickEvent, element -> element.onClick?.invoke(clickEvent) }
)
/**
* Creates a new compound, holding custom element data.
* This compound is strictly a rectangle.
* The space is automatically defined.
*/

View File

@@ -163,4 +163,16 @@ abstract class AbstractGUISpaceCompound<T : ForInventory, E> internal constructo
}
}
}
/**
* A simple compound element, covering the most common
* compound use cases.
*
* @see GUIPageBuilder.createSimpleCompound
* @see GUIPageBuilder.createSimpleRectCompound
*/
class GUICompoundElement<T : ForInventory>(
internal val icon: ItemStack,
internal val onClick: ((GUIClickEvent<T>) -> Unit)? = null
)