aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-06-12 12:49:20 +0200
committerGitHub <noreply@github.com>2023-06-12 12:49:20 +0200
commit56c5f9fc485731f2a33a2b61fa8b7d81193c207c (patch)
tree501b76594f2afa2057b1e45e402aa4c7f109dd12 /src/main/java/at/hannibal2/skyhanni/utils
parentf7b36cc696105948a31a871f493a515c3be658cd (diff)
downloadskyhanni-56c5f9fc485731f2a33a2b61fa8b7d81193c207c.tar.gz
skyhanni-56c5f9fc485731f2a33a2b61fa8b7d81193c207c.tar.bz2
skyhanni-56c5f9fc485731f2a33a2b61fa8b7d81193c207c.zip
Quick Mod Menu Switch (#232)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ModsJson.java25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt38
2 files changed, 49 insertions, 14 deletions
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<String, Mod> mods = new HashMap<>();
+
+ public class Mod {
+ @Expose
+ public List<String> description = new ArrayList<>();
+
+ @Expose
+ public String command = "";
+
+ @Expose
+ public List<String> 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<String>, onClick: () -> Unit): Renderable {
- return clickable(hoverTips(text, tips), onClick)
+ fun clickAndHover(text: String, tips: List<String>, 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<String>, condition: () -> Boolean = { true }): Renderable {
+ fun hoverTips(text: String, tips: List<String>, 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<String>, 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)