SpaceCompound now knows what GUIs currently use it
This commit is contained in:
@@ -16,6 +16,10 @@ class InventoryGUISpaceCompoundElement<T : ForInventory, E>(
|
|||||||
compound.onClickElement(clickEvent)
|
compound.onClickElement(clickEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun startUsing(gui: InventoryGUI<*>) = compound.registerGUI(gui)
|
||||||
|
|
||||||
|
override fun stopUsing(gui: InventoryGUI<*>) = compound.unregisterGUI(gui)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class InventoryGUISpaceCompound<T : ForInventory, E>(
|
class InventoryGUISpaceCompound<T : ForInventory, E>(
|
||||||
@@ -46,6 +50,8 @@ class InventoryGUISpaceCompound<T : ForInventory, E>(
|
|||||||
|
|
||||||
private var contentSort: () -> Unit = { }
|
private var contentSort: () -> Unit = { }
|
||||||
|
|
||||||
|
private val registeredGUIs = HashSet<InventoryGUI<*>>()
|
||||||
|
|
||||||
private fun translateSlot(slot: Int) = (scrolledLines * invType.dimensions.width) + slot
|
private fun translateSlot(slot: Int) = (scrolledLines * invType.dimensions.width) + slot
|
||||||
|
|
||||||
private fun contentAtSlot(slot: Int) = content.getOrNull(
|
private fun contentAtSlot(slot: Int) = content.getOrNull(
|
||||||
@@ -70,6 +76,14 @@ class InventoryGUISpaceCompound<T : ForInventory, E>(
|
|||||||
realInternalSlots.sort()
|
realInternalSlots.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun registerGUI(gui: InventoryGUI<*>) {
|
||||||
|
registeredGUIs += gui
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun unregisterGUI(gui: InventoryGUI<*>) {
|
||||||
|
registeredGUIs -= gui
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the sort behaviour which gets applied to the content
|
* Defines the sort behaviour which gets applied to the content
|
||||||
* automatically.
|
* automatically.
|
||||||
@@ -94,7 +108,7 @@ class InventoryGUISpaceCompound<T : ForInventory, E>(
|
|||||||
fun addContent(elements: Collection<E>) {
|
fun addContent(elements: Collection<E>) {
|
||||||
content += elements
|
content += elements
|
||||||
contentSort.invoke()
|
contentSort.invoke()
|
||||||
// TODO reload GUIs using this compound at this time
|
registeredGUIs.forEach { it.reloadCurrentPage() }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user