-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/net/mcbrawls/sgui/callback/ParentedOpenGuiClickCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.mcbrawls.sgui.callback | ||
|
||
import eu.pb4.sgui.api.ClickType | ||
import eu.pb4.sgui.api.elements.GuiElementInterface.ClickCallback | ||
import eu.pb4.sgui.api.gui.GuiInterface | ||
import eu.pb4.sgui.api.gui.SlotGuiInterface | ||
import net.mcbrawls.sgui.openGui | ||
import net.mcbrawls.sgui.openParentedGui | ||
import net.minecraft.screen.slot.SlotActionType | ||
import net.minecraft.server.network.ServerPlayerEntity | ||
|
||
/** | ||
* A click callback to open a GUI. | ||
*/ | ||
data class ParentedOpenGuiClickCallback( | ||
/** | ||
* The factory to create the new GUI. | ||
*/ | ||
val factory: (ServerPlayerEntity) -> GuiInterface, | ||
|
||
/** | ||
* The parent of the opened GUI. | ||
*/ | ||
val parent: GuiInterface? = null | ||
) : ClickCallback { | ||
override fun click(index: Int, type: ClickType, action: SlotActionType, gui: SlotGuiInterface) { | ||
val player = gui.player | ||
val parent = parent | ||
if (parent != null) { | ||
player.openParentedGui(parent, factory) | ||
} else { | ||
player.openGui(factory) | ||
} | ||
} | ||
} |