diff options
| author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-09 00:37:17 +0200 |
|---|---|---|
| committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-09 00:37:17 +0200 |
| commit | 5f592670446d0dfc5458a962e893cf1b19e1bfa7 (patch) | |
| tree | becfa9afb79190031c159f5d5d302d9599e451d6 /src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt | |
| parent | 38b53ed9d8aabaf80fe92aa4acecc9e77c14f2c0 (diff) | |
| download | SkyHanni-5f592670446d0dfc5458a962e893cf1b19e1bfa7.tar.gz SkyHanni-5f592670446d0dfc5458a962e893cf1b19e1bfa7.tar.bz2 SkyHanni-5f592670446d0dfc5458a962e893cf1b19e1bfa7.zip | |
adding a button on pause menu
Diffstat (limited to 'src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt')
| -rw-r--r-- | src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt b/src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt new file mode 100644 index 000000000..9fe540ae9 --- /dev/null +++ b/src/main/java/at/lorenz/mod/misc/ButtonOnPause.kt @@ -0,0 +1,42 @@ +package at.lorenz.mod.misc + +import at.lorenz.mod.LorenzMod +import com.thatgravyboat.skyblockhud_2.config.SBHConfigEditor +import com.thatgravyboat.skyblockhud_2.core.GuiScreenElementWrapper +import net.minecraft.client.gui.GuiButton +import net.minecraft.client.gui.GuiIngameMenu +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ButtonOnPause { + private val buttonId = System.nanoTime().toInt() + + @SubscribeEvent + fun onGuiAction(event: GuiScreenEvent.ActionPerformedEvent.Post) { + if (LorenzMod.feature.misc.configButtonOnPause && event.gui is GuiIngameMenu && event.button.id == buttonId) { + LorenzMod.screenToOpen = GuiScreenElementWrapper(SBHConfigEditor(LorenzMod.feature)) + } + } + + @SubscribeEvent + fun onGuiInitPost(event: GuiScreenEvent.InitGuiEvent.Post) { + if (LorenzMod.feature.misc.configButtonOnPause && event.gui is GuiIngameMenu) { + val x = event.gui.width - 105 + val x2 = x + 100 + var y = event.gui.height - 22 + var y2 = y + 20 + val sorted = event.buttonList.sortedWith { a, b -> b.yPosition + b.height - a.yPosition + a.height } + for (button in sorted) { + val otherX = button.xPosition + val otherX2 = button.xPosition + button.width + val otherY = button.yPosition + val otherY2 = button.yPosition + button.height + if (otherX2 > x && otherX < x2 && otherY2 > y && otherY < y2) { + y = otherY - 20 - 2 + y2 = y + 20 + } + } + event.buttonList.add(GuiButton(buttonId, x, 0.coerceAtLeast(y), 100, 20, "Lorenz Mod")) + } + } +}
\ No newline at end of file |
