Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: No longer use neu gui elements in config #2725

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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) {}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand Down
Loading