From 3216ae7aac405f3ab38d9e80530f5ed7ae1f6005 Mon Sep 17 00:00:00 2001 From: Cal Date: Sat, 12 Oct 2024 16:05:42 +1100 Subject: [PATCH 1/2] rename variable --- .../misc/update/GuiOptionEditorUpdateCheck.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/update/GuiOptionEditorUpdateCheck.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/update/GuiOptionEditorUpdateCheck.kt index 84d86615da3d..c6929c258b2f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/update/GuiOptionEditorUpdateCheck.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/update/GuiOptionEditorUpdateCheck.kt @@ -20,7 +20,7 @@ class GuiOptionEditorUpdateCheck(option: ProcessedOption) : GuiOptionEditor(opti GlStateManager.pushMatrix() GlStateManager.translate(x.toFloat() + 10, y.toFloat(), 1F) - val width = width - 20 + val adjustedWidth = width - 20 val nextVersion = UpdateManager.getNextVersion() button.text = when (UpdateManager.updateState) { @@ -29,20 +29,20 @@ class GuiOptionEditorUpdateCheck(option: ProcessedOption) : GuiOptionEditor(opti UpdateManager.UpdateState.DOWNLOADED -> "Downloaded" UpdateManager.UpdateState.NONE -> if (nextVersion == null) "Check for Updates" else "Up to date" } - button.render(getButtonPosition(width), 10) + button.render(getButtonPosition(adjustedWidth), 10) if (UpdateManager.updateState == UpdateManager.UpdateState.DOWNLOADED) { TextRenderUtils.drawStringCentered( "${GREEN}The update will be installed after your next restart.", fr, - width / 2F, + adjustedWidth / 2F, 40F, true, - -1 + -1, ) } - val widthRemaining = width - button.width - 10 + val widthRemaining = adjustedWidth - button.width - 10 GlStateManager.scale(2F, 2F, 1F) val currentVersion = SkyHanniMod.version @@ -67,8 +67,8 @@ class GuiOptionEditorUpdateCheck(option: ProcessedOption) : GuiOptionEditor(opti } override fun mouseInput(x: Int, y: Int, width: Int, mouseX: Int, mouseY: Int): Boolean { - val width = width - 20 - if (Mouse.getEventButtonState() && (mouseX - getButtonPosition(width) - x) in (0..button.width) && (mouseY - 10 - y) in (0..button.height)) { + val adjustedWidth = width - 20 + if (Mouse.getEventButtonState() && (mouseX - getButtonPosition(adjustedWidth) - x) in (0..button.width) && (mouseY - 10 - y) in (0..button.height)) { when (UpdateManager.updateState) { UpdateManager.UpdateState.AVAILABLE -> UpdateManager.queueUpdate() UpdateManager.UpdateState.QUEUED -> {} From 6461aa456080633edf534fa2133716fa86453339 Mon Sep 17 00:00:00 2001 From: Cal Date: Sat, 12 Oct 2024 16:59:25 +1100 Subject: [PATCH 2/2] dont use neu button --- .../config/core/elements/GuiElement.kt | 19 ++++++++++++++++ .../config/core/elements/GuiElementButton.kt | 22 +++++++++++++++++++ .../config/core/elements/GuiElementText.kt | 21 ++++++++++++++++++ .../misc/update/GuiOptionEditorUpdateCheck.kt | 2 +- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElement.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElementButton.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElementText.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElement.kt b/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElement.kt new file mode 100644 index 000000000000..6144dddf295b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElement.kt @@ -0,0 +1,19 @@ +package at.hannibal2.skyhanni.config.core.elements + +import net.minecraft.client.gui.Gui + +abstract class GuiElement : Gui() { + abstract fun render(x: Int, y: Int) + + abstract val width: Int + + abstract val height: Int + + open fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) {} + + fun mouseClickMove(mouseX: Int, mouseY: Int, clickedMouseButton: Int, timeSinceLastClick: Long) {} + + fun otherComponentClick() {} + + fun keyTyped(typedChar: Char, keyCode: Int) {} +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElementButton.kt b/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElementButton.kt new file mode 100644 index 000000000000..504171ac418f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElementButton.kt @@ -0,0 +1,22 @@ +package at.hannibal2.skyhanni.config.core.elements + +import java.awt.Color + +class GuiElementButton(text: String, colour: Int, private val callback: Runnable) : GuiElementText(text, colour) { + + override val height: Int + get() = super.height + 5 + + override val width: Int + get() = super.width + 10 + + override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) { + callback.run() + } + + override fun render(x: Int, y: Int) { + drawRect(x, y, x + width, y + super.height, Color.WHITE.rgb) + drawRect(x + 1, y + 1, x + width - 1, y + super.height - 1, Color.BLACK.rgb) + super.render(x + 5, y - 1) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElementText.kt b/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElementText.kt new file mode 100644 index 000000000000..541edc49bf0d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/core/elements/GuiElementText.kt @@ -0,0 +1,21 @@ +package at.hannibal2.skyhanni.config.core.elements + +import net.minecraft.client.Minecraft + +open class GuiElementText(var text: String, private val colour: Int) : GuiElement() { + + override val height: Int + get() = 18 + + override val width: Int + get() { + val fr = Minecraft.getMinecraft().fontRendererObj + return fr.getStringWidth(text) + } + + override fun render(x: Int, y: Int) { + val fr = Minecraft.getMinecraft().fontRendererObj + + fr.drawString(text, x, y + 6, colour) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/update/GuiOptionEditorUpdateCheck.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/update/GuiOptionEditorUpdateCheck.kt index c6929c258b2f..a5be28b17209 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/update/GuiOptionEditorUpdateCheck.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/update/GuiOptionEditorUpdateCheck.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.features.misc.update import at.hannibal2.skyhanni.SkyHanniMod -import io.github.moulberry.notenoughupdates.itemeditor.GuiElementButton +import at.hannibal2.skyhanni.config.core.elements.GuiElementButton import io.github.notenoughupdates.moulconfig.gui.GuiOptionEditor import io.github.notenoughupdates.moulconfig.internal.TextRenderUtils import io.github.notenoughupdates.moulconfig.processor.ProcessedOption