aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/gui/CheckboxComponent.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-27 17:26:42 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-27 17:26:42 +0100
commit8df225399f1932b8824d2fc44f4c964bc47fc6aa (patch)
treea2f1d7f64f68242aaaa5b97df2c15665eb7d12ce /src/main/kotlin/gui/CheckboxComponent.kt
parentccb5c556def69ea16a52c00b3fbfe3a224f51ac2 (diff)
downloadFirmament-8df225399f1932b8824d2fc44f4c964bc47fc6aa.tar.gz
Firmament-8df225399f1932b8824d2fc44f4c964bc47fc6aa.tar.bz2
Firmament-8df225399f1932b8824d2fc44f4c964bc47fc6aa.zip
feat: Add pickobulus blocker on private island
Diffstat (limited to 'src/main/kotlin/gui/CheckboxComponent.kt')
-rw-r--r--src/main/kotlin/gui/CheckboxComponent.kt56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main/kotlin/gui/CheckboxComponent.kt b/src/main/kotlin/gui/CheckboxComponent.kt
new file mode 100644
index 0000000..761c086
--- /dev/null
+++ b/src/main/kotlin/gui/CheckboxComponent.kt
@@ -0,0 +1,56 @@
+package moe.nea.firmament.gui
+
+import io.github.notenoughupdates.moulconfig.gui.GuiComponent
+import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext
+import io.github.notenoughupdates.moulconfig.gui.MouseEvent
+import io.github.notenoughupdates.moulconfig.observer.GetSetter
+import io.github.notenoughupdates.moulconfig.platform.ModernRenderContext
+import net.minecraft.client.render.RenderLayer
+import moe.nea.firmament.Firmament
+
+class CheckboxComponent<T>(
+ val state: GetSetter<T>,
+ val value: T,
+) : GuiComponent() {
+ override fun getWidth(): Int {
+ return 16
+ }
+
+ override fun getHeight(): Int {
+ return 16
+ }
+
+ fun isEnabled(): Boolean {
+ return state.get() == value
+ }
+
+ override fun render(context: GuiImmediateContext) {
+ val ctx = (context.renderContext as ModernRenderContext).drawContext
+ ctx.drawGuiTexture(
+ RenderLayer::getGuiTextured,
+ if (isEnabled()) Firmament.identifier("firmament:widget/checkbox_checked")
+ else Firmament.identifier("firmament:widget/checkbox_unchecked"),
+ 0, 0,
+ 16, 16
+ )
+ }
+
+ var isClicking = false
+
+ override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean {
+ if (mouseEvent is MouseEvent.Click) {
+ if (isClicking && !mouseEvent.mouseState && mouseEvent.mouseButton == 0) {
+ isClicking = false
+ if (context.isHovered)
+ state.set(value)
+ return true
+ }
+ if (mouseEvent.mouseState && mouseEvent.mouseButton == 0 && context.isHovered) {
+ requestFocus()
+ isClicking = true
+ return true
+ }
+ }
+ return false
+ }
+}