From 56c5f9fc485731f2a33a2b61fa8b7d81193c207c Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Mon, 12 Jun 2023 12:49:20 +0200 Subject: Quick Mod Menu Switch (#232) --- .../skyhanni/utils/jsonobjects/ModsJson.java | 25 ++++++++++++++ .../skyhanni/utils/renderables/Renderable.kt | 38 ++++++++++++++-------- 2 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ModsJson.java (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ModsJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ModsJson.java new file mode 100644 index 000000000..d765f3e02 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ModsJson.java @@ -0,0 +1,25 @@ +package at.hannibal2.skyhanni.utils.jsonobjects; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ModsJson { + + @Expose + public Map mods = new HashMap<>(); + + public class Mod { + @Expose + public List description = new ArrayList<>(); + + @Expose + public String command = ""; + + @Expose + public List guiPath = new ArrayList<>(); + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt index 5047c4744..acd1085ba 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -40,19 +40,19 @@ interface Renderable { else -> null } - fun link(text: String, onClick: () -> Unit): Renderable = link(string(text), onClick) { true } - fun optionalLink(text: String, onClick: () -> Unit, condition: () -> Boolean = { true }): Renderable = - link(string(text), onClick, condition) + fun link(text: String, bypassChecks: Boolean = false, onClick: () -> Unit): Renderable = link(string(text), onClick, bypassChecks = bypassChecks) { true } + fun optionalLink(text: String, onClick: () -> Unit, bypassChecks: Boolean = false, condition: () -> Boolean = { true }): Renderable = + link(string(text), onClick, bypassChecks, condition) - fun link(renderable: Renderable, onClick: () -> Unit, condition: () -> Boolean = { true }): Renderable { - return clickable(hoverable(underlined(renderable), renderable, condition), onClick, 0, condition) + fun link(renderable: Renderable, onClick: () -> Unit, bypassChecks: Boolean = false, condition: () -> Boolean = { true }): Renderable { + return clickable(hoverable(underlined(renderable), renderable, bypassChecks, condition = condition), onClick, 0, bypassChecks, condition) } - fun clickAndHover(text: String, tips: List, onClick: () -> Unit): Renderable { - return clickable(hoverTips(text, tips), onClick) + fun clickAndHover(text: String, tips: List, bypassChecks: Boolean = false, onClick: () -> Unit): Renderable { + return clickable(hoverTips(text, tips, bypassChecks = bypassChecks), onClick, bypassChecks = bypassChecks) } - fun clickable(render: Renderable, onClick: () -> Unit, button: Int = 0, condition: () -> Boolean = { true }) = + fun clickable(render: Renderable, onClick: () -> Unit, button: Int = 0, bypassChecks: Boolean = false, condition: () -> Boolean = { true }) = object : Renderable { override val width: Int get() = render.width @@ -63,7 +63,7 @@ interface Renderable { override fun render(posX: Int, posY: Int) { val isDown = Mouse.isButtonDown(button) if (isDown > wasDown && isHovered(posX, posY)) { - if (condition() && shouldAllowLink(true)) { + if (condition() && shouldAllowLink(true, bypassChecks)) { onClick() } } @@ -72,7 +72,7 @@ interface Renderable { } } - fun hoverTips(text: String, tips: List, condition: () -> Boolean = { true }): Renderable { + fun hoverTips(text: String, tips: List, bypassChecks: Boolean = false, condition: () -> Boolean = { true }): Renderable { val render = string(text) return object : Renderable { override val width: Int @@ -82,7 +82,7 @@ interface Renderable { override fun render(posX: Int, posY: Int) { render.render(posX, posY) if (isHovered(posX, posY)) { - if (condition() && shouldAllowLink(true)) { + if (condition() && shouldAllowLink(true, bypassChecks)) { renderToolTips(posX, posY, tips) } } @@ -91,6 +91,11 @@ interface Renderable { } private fun renderToolTips(posX: Int, posY: Int, tips: List, border: Int = 1) { + GlStateManager.pushMatrix() +// GlStateManager.translate(0f, 0f, 2f) +// GuiRenderUtils.drawTooltip(tips, posX, posY, 0) +// GlStateManager.translate(0f, 0f, -2f) + val x = Utils.getMouseX() - posX + 10 val startY = Utils.getMouseY() - posY - 10 var maxX = 0 @@ -121,10 +126,15 @@ interface Renderable { LorenzColor.DARK_GRAY.toColor().rgb ) GlStateManager.translate(0f, 0f, -1f) + + GlStateManager.popMatrix() } - private fun shouldAllowLink(debug: Boolean = false): Boolean { + private fun shouldAllowLink(debug: Boolean = false, bypassChecks: Boolean): Boolean { val isGuiScreen = Minecraft.getMinecraft().currentScreen != null + if (bypassChecks) { + return isGuiScreen + } val isGuiPositionEditor = Minecraft.getMinecraft().currentScreen !is GuiPositionEditor val isNotInSignAndOnSlot = if (Minecraft.getMinecraft().currentScreen !is GuiEditSign) { ToolTipData.lastSlot == null @@ -161,14 +171,14 @@ interface Renderable { } } - fun hoverable(hovered: Renderable, unhovered: Renderable, condition: () -> Boolean = { true }) = + fun hoverable(hovered: Renderable, unhovered: Renderable, bypassChecks: Boolean = false, condition: () -> Boolean = { true }) = object : Renderable { override val width: Int get() = max(hovered.width, unhovered.width) override val height = 10 override fun render(posX: Int, posY: Int) { - if (isHovered(posX, posY) && condition() && shouldAllowLink()) + if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) hovered.render(posX, posY) else unhovered.render(posX, posY) -- cgit