diff options
Diffstat (limited to 'src')
4 files changed, 70 insertions, 8 deletions
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 000000000..6144dddf2 --- /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 000000000..504171ac4 --- /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 000000000..541edc49b --- /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 9f2d2ac59..2fbbc395d 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 @@ -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,9 +67,9 @@ class GuiOptionEditorUpdateCheck(option: ProcessedOption) : GuiOptionEditor(opti } override fun mouseInput(x: Int, y: Int, width: Int, mouseX: Int, mouseY: Int): Boolean { - val width = width - 20 + val adjustedWidth = width - 20 if (Mouse.getEventButtonState() && - (mouseX - getButtonPosition(width) - x) in (0..button.width) && + (mouseX - getButtonPosition(adjustedWidth) - x) in (0..button.width) && (mouseY - 10 - y) in (0..button.height) ) { when (UpdateManager.updateState) { |