aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/gui
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-07-01 03:42:51 +0200
committerLinnea Gräf <nea@nea.moe>2024-07-03 21:05:51 +0200
commit5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e (patch)
treea5b0a6fbc8878ae62bb2c3a01dbb255388353fda /src/main/kotlin/moe/nea/firmament/gui
parentdff1f9c0e2b728dba902d72816104abccc61f511 (diff)
downloadFirmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.gz
Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.bz2
Firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.zip
[WIP] Remove LibGUI
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui')
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt31
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt32
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt10
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WBar.kt79
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt40
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WFixedPanel.kt32
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WSpacer.kt25
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WSplitPanel.kt29
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WTightScrollPanel.kt18
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt39
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/BooleanHandler.kt19
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/ClickHandler.kt14
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/DurationHandler.kt53
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt32
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/HudMetaHandler.kt21
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/IntegerHandler.kt55
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/KeyBindingHandler.kt115
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/ManagedConfig.kt68
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/ManagedOption.kt10
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/StringHandler.kt22
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/hud/MoulConfigHud.kt24
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt110
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfilePage.kt17
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt77
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt71
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt146
26 files changed, 290 insertions, 899 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt b/src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt
index 91b5735..38e898d 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/BarComponent.kt
@@ -7,8 +7,6 @@
package moe.nea.firmament.gui
import com.mojang.blaze3d.systems.RenderSystem
-import io.github.cottonmc.cotton.gui.client.ScreenDrawing
-import io.github.cottonmc.cotton.gui.widget.data.Texture
import io.github.notenoughupdates.moulconfig.common.MyResourceLocation
import io.github.notenoughupdates.moulconfig.common.RenderContext
import io.github.notenoughupdates.moulconfig.gui.GuiComponent
@@ -33,6 +31,24 @@ class BarComponent(
return 8
}
+ data class Texture(
+ val identifier: Identifier,
+ val u1: Float, val v1: Float,
+ val u2: Float, val v2: Float,
+ ) {
+ fun draw(context: DrawContext, x: Int, y: Int, width: Int, height: Int, color: Color) {
+ context.drawTexturedQuad(
+ identifier,
+ x, y, x + width, x + height, 0,
+ u1, u2, v1, v2,
+ color.red / 255F,
+ color.green / 255F,
+ color.blue / 255F,
+ color.alpha / 255F,
+ )
+ }
+ }
+
companion object {
val resource = Firmament.identifier("textures/gui/bar.png")
val left = Texture(resource, 0 / 64F, 0 / 64F, 4 / 64F, 8 / 64F)
@@ -51,20 +67,21 @@ class BarComponent(
sectionEnd: Double
) {
if (sectionEnd < progress.get() && width == 4) {
- ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, fillColor.color)
+ texture.draw(context, x, y, 4, 8, fillColor)
return
}
if (sectionStart > progress.get() && width == 4) {
- ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, emptyColor.color)
+ texture.draw(context, x, y, 4, 8, emptyColor)
return
}
val increasePerPixel = (sectionEnd - sectionStart) / width
var valueAtPixel = sectionStart
for (i in (0 until width)) {
- ScreenDrawing.texturedRect(
+ val newTex =
+ Texture(texture.identifier, texture.u1 + i / 64F, texture.v1, texture.u1 + (i + 1) / 64F, texture.v2)
+ newTex.draw(
context, x + i, y, 1, 8,
- texture.image, texture.u1 + i / 64F, texture.v1, texture.u1 + (i + 1) / 64F, texture.v2,
- if (valueAtPixel < progress.get()) fillColor.color else emptyColor.color
+ if (valueAtPixel < progress.get()) fillColor else emptyColor
)
valueAtPixel += increasePerPixel
}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt b/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt
index 30f280c..d1e223e 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/FirmButtonComponent.kt
@@ -15,24 +15,31 @@ import io.github.notenoughupdates.moulconfig.gui.component.PanelComponent
import io.github.notenoughupdates.moulconfig.observer.GetSetter
-class FirmButtonComponent(
+open class FirmButtonComponent(
child: GuiComponent,
+ val isEnabled: GetSetter<Boolean> = GetSetter.constant(true),
val action: Runnable,
- val isEnabled: GetSetter<Boolean> = GetSetter.constant(true)
) : PanelComponent(child) {
/* TODO: make use of vanillas built in nine slicer */
- val hoveredBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_highlighted.png"))
- .cornerSize(5)
- .cornerUv(5 / 200F, 5 / 20F)
- .mode(NinePatch.Mode.STRETCHING)
- .build()
+ val hoveredBg =
+ NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_highlighted.png"))
+ .cornerSize(5)
+ .cornerUv(5 / 200F, 5 / 20F)
+ .mode(NinePatch.Mode.STRETCHING)
+ .build()
val unhoveredBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button.png"))
.cornerSize(5)
.cornerUv(5 / 200F, 5 / 20F)
.mode(NinePatch.Mode.STRETCHING)
.build()
- val disabledBg = NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_disabled.png"))
+ val disabledBg =
+ NinePatch.builder(MyResourceLocation("minecraft", "textures/gui/sprites/widget/button_disabled.png"))
+ .cornerSize(5)
+ .cornerUv(5 / 200F, 5 / 20F)
+ .mode(NinePatch.Mode.STRETCHING)
+ .build()
+ val activeBg = NinePatch.builder(MyResourceLocation("firmament", "textures/gui/sprites/widget/button_active.png"))
.cornerSize(5)
.cornerUv(5 / 200F, 5 / 20F)
.mode(NinePatch.Mode.STRETCHING)
@@ -59,12 +66,15 @@ class FirmButtonComponent(
return false
}
+ open fun getBackground(context: GuiImmediateContext): NinePatch<MyResourceLocation> =
+ if (!isEnabled.get()) disabledBg
+ else if (context.isHovered || isClicking) hoveredBg
+ else unhoveredBg
+
override fun render(context: GuiImmediateContext) {
context.renderContext.pushMatrix()
context.renderContext.drawNinePatch(
- if (!isEnabled.get()) disabledBg
- else if (context.isHovered || isClicking) hoveredBg
- else unhoveredBg,
+ getBackground(context),
0f, 0f, context.width, context.height
)
context.renderContext.translate(insets.toFloat(), insets.toFloat(), 0f)
diff --git a/src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt b/src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt
index c98feda..15d6bfc 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/FixedComponent.kt
@@ -14,20 +14,20 @@ import io.github.notenoughupdates.moulconfig.observer.GetSetter
import java.util.function.BiFunction
class FixedComponent(
- val fixedWidth: GetSetter<Int>,
- val fixedHeight: GetSetter<Int>,
+ val fixedWidth: GetSetter<Int>?,
+ val fixedHeight: GetSetter<Int>?,
val component: GuiComponent,
) : GuiComponent() {
- override fun getWidth(): Int = fixedWidth.get()
+ override fun getWidth(): Int = fixedWidth?.get() ?: component.width
- override fun getHeight(): Int = fixedHeight.get()
+ override fun getHeight(): Int = fixedHeight?.get() ?: component.height
override fun <T : Any?> foldChildren(initial: T, visitor: BiFunction<GuiComponent, T, T>): T {
return visitor.apply(component, initial)
}
fun fixContext(context: GuiImmediateContext): GuiImmediateContext =
- context.translated(0, 0, fixedWidth.get(), fixedHeight.get())
+ context.translated(0, 0, width, height)
override fun render(context: GuiImmediateContext) {
component.render(fixContext(context))
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WBar.kt b/src/main/kotlin/moe/nea/firmament/gui/WBar.kt
deleted file mode 100644
index 5772aac..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/WBar.kt
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-package moe.nea.firmament.gui
-
-import com.mojang.blaze3d.systems.RenderSystem
-import io.github.cottonmc.cotton.gui.client.ScreenDrawing
-import io.github.cottonmc.cotton.gui.widget.WWidget
-import io.github.cottonmc.cotton.gui.widget.data.Texture
-import me.shedaniel.math.Color
-import net.minecraft.client.gui.DrawContext
-import moe.nea.firmament.Firmament
-
-open class WBar(
- var progress: Double,
- var total: Double,
- val fillColor: Color,
- val emptyColor: Color = fillColor.darker(2.0),
-) : WWidget() {
- companion object {
- val resource = Firmament.identifier("textures/gui/bar.png")
- val left = Texture(resource, 0 / 64F, 0 / 64F, 4 / 64F, 8 / 64F)
- val middle = Texture(resource, 4 / 64F, 0 / 64F, 8 / 64F, 8 / 64F)
- val right = Texture(resource, 8 / 64F, 0 / 64F, 12 / 64F, 8 / 64F)
- val segmentOverlay = Texture(resource, 12 / 64F, 0 / 64F, 15 / 64F, 8 / 64F)
- }
-
- override fun canResize(): Boolean {
- return true
- }
-
- private fun drawSection(
- context: DrawContext,
- texture: Texture,
- x: Int,
- y: Int,
- width: Int,
- sectionStart: Double,
- sectionEnd: Double
- ) {
- if (sectionEnd < progress && width == 4) {
- ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, fillColor.color)
- return
- }
- if (sectionStart > progress && width == 4) {
- ScreenDrawing.texturedRect(context, x, y, 4, 8, texture, emptyColor.color)
- return
- }
- val increasePerPixel = (sectionEnd - sectionStart / 4)
- var valueAtPixel = sectionStart
- for (i in (0 until width)) {
- ScreenDrawing.texturedRect(
- context, x + i, y, 1, 8,
- texture.image, texture.u1 + i / 64F, texture.v1, texture.u1 + (i + 1) / 64F, texture.v2,
- if (valueAtPixel < progress) fillColor.color else emptyColor.color
- )
- valueAtPixel += increasePerPixel
- }
- }
-
- override fun paint(context: DrawContext, x: Int, y: Int, mouseX: Int, mouseY: Int) {
- var i = 0
- while (i < width - 4) {
- drawSection(
- context,
- if (i == 0) left else middle,
- x + i, y,
- (width - (i + 4)).coerceAtMost(4),
- i * total / width, (i + 4) * total / width
- )
- i += 4
- }
- drawSection(context, right, x + width - 4, y, 4, (width - 4) * total / width, total)
- RenderSystem.setShaderColor(1F, 1F, 1F, 1F)
- }
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt b/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt
deleted file mode 100644
index 69a59f5..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/WCenteringPanel.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-package moe.nea.firmament.gui
-
-import io.github.cottonmc.cotton.gui.widget.WPanel
-import io.github.cottonmc.cotton.gui.widget.WWidget
-import io.github.cottonmc.cotton.gui.widget.data.Axis
-
-data class WCenteringPanel(
- val child: WWidget,
- val axis: Axis,
-) : WPanel() {
- init {
- child.parent = this
- }
-
- override fun setSize(x: Int, y: Int) {
- super.setSize(x, y)
- if (!child.canResize()) return
- if (axis == Axis.HORIZONTAL) {
- child.setSize(child.width, y)
- } else {
- child.setSize(x, child.height)
- }
- }
-
- override fun layout() {
- super.layout()
- child.setLocation(
- axis.choose((child.width + width) / 2, child.x),
- axis.choose(child.y, (child.height + height) / 2),
- )
- }
-
-
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WFixedPanel.kt b/src/main/kotlin/moe/nea/firmament/gui/WFixedPanel.kt
deleted file mode 100644
index 0fd724b..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/WFixedPanel.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-package moe.nea.firmament.gui
-
-import io.github.cottonmc.cotton.gui.widget.WPanel
-import io.github.cottonmc.cotton.gui.widget.WWidget
-
-class WFixedPanel() : WPanel() {
- var child: WWidget
- set(value) {
- children.clear()
- setSize(0, 0)
- value.parent = this
- children.add(value)
- }
- get() = children.single()
-
- constructor(child: WWidget) : this() {
- this.child = child
- }
-
- override fun layout() {
- setSize(0, 0)
- super.layout()
- }
-
- override fun canResize(): Boolean = false
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WSpacer.kt b/src/main/kotlin/moe/nea/firmament/gui/WSpacer.kt
deleted file mode 100644
index 8cdc4b8..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/WSpacer.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-package moe.nea.firmament.gui
-
-import io.github.cottonmc.cotton.gui.widget.WPanel
-import io.github.cottonmc.cotton.gui.widget.WWidget
-
-class WSpacer(val child: WWidget, val spaceLeft: Int) : WPanel() {
- init {
- children.add(child)
- child.setLocation(spaceLeft, 0)
- }
-
- override fun getWidth(): Int {
- return child.width + spaceLeft
- }
-
- override fun getHeight(): Int {
- return child.height
- }
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WSplitPanel.kt b/src/main/kotlin/moe/nea/firmament/gui/WSplitPanel.kt
deleted file mode 100644
index 1469880..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/WSplitPanel.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-package moe.nea.firmament.gui
-
-import io.github.cottonmc.cotton.gui.widget.WPanel
-import io.github.cottonmc.cotton.gui.widget.WPanelWithInsets
-import io.github.cottonmc.cotton.gui.widget.WWidget
-
-class WSplitPanel(val left: WWidget, val right: WWidget) : WPanelWithInsets() {
- init {
- left.parent = this
- right.parent = this
- children.add(left)
- children.add(right)
- }
-
- override fun layout() {
- expandToFit(left, insets)
- expandToFit(right, insets)
- (left as? WPanel)?.layout()
- (right as? WPanel)?.layout()
- left.setLocation(insets.left, insets.top)
- right.setLocation(width - insets.right - right.width, insets.top)
- }
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WTightScrollPanel.kt b/src/main/kotlin/moe/nea/firmament/gui/WTightScrollPanel.kt
deleted file mode 100644
index e4c3989..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/WTightScrollPanel.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-package moe.nea.firmament.gui
-
-import io.github.cottonmc.cotton.gui.widget.WPanel
-import io.github.cottonmc.cotton.gui.widget.WScrollPanel
-import io.github.cottonmc.cotton.gui.widget.WWidget
-
-class WTightScrollPanel(val widget: WWidget, val margin: Int = 3) : WScrollPanel(widget) {
- override fun setSize(x: Int, y: Int) {
- (widget as? WPanel)?.layout()
- super.setSize(widget.width + 8 + margin, y)
- }
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt b/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt
deleted file mode 100644
index a1d4d68..0000000
--- a/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
- * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-package moe.nea.firmament.gui
-
-import com.mojang.blaze3d.systems.RenderSystem
-import io.github.cottonmc.cotton.gui.client.BackgroundPainter
-import io.github.cottonmc.cotton.gui.widget.TooltipBuilder
-import io.github.cottonmc.cotton.gui.widget.WWidget
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.item.TooltipType
-import net.minecraft.item.ItemStack
-import net.minecraft.text.Text
-import moe.nea.firmament.util.MC
-
-open class WTitledItem(var stack: ItemStack, val countString: Text = Text.empty()) : WWidget() {
- var backgroundPainter: BackgroundPainter = BackgroundPainter.SLOT
- override fun canResize(): Boolean = true
- override fun paint(context: DrawContext, x: Int, y: Int, mouseX: Int, mouseY: Int) {
- backgroundPainter.paintBackground(context, x, y, this)
- context.matrices.push()
- context.matrices.translate(x.toFloat(), y.toFloat(), 0F)
- context.matrices.scale(width / 18F, height / 18F, 1F)
- RenderSystem.enableDepthTest()
- context.drawItemWithoutEntity(stack, 18 / 2 - 8, 18 / 2 - 8)
- context.matrices.translate(0F, 0F, 200F)
- context.drawText(MC.font, countString, 19 - 2 - MC.font.getWidth(countString), 6 + 3, 0xFFFFFF, true)
- context.matrices.pop()
- }
-
- override fun addTooltip(tooltip: TooltipBuilder) {
- tooltip.add(*stack.getTooltip(null, null, TooltipType.BASIC).toTypedArray())
- }
-
-}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/BooleanHandler.kt b/src/main/kotlin/moe/nea/firmament/gui/config/BooleanHandler.kt
index adbeeaf..85afeb4 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/config/BooleanHandler.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/config/BooleanHandler.kt
@@ -6,7 +6,9 @@
package moe.nea.firmament.gui.config
-import io.github.cottonmc.cotton.gui.widget.WToggleButton
+import io.github.notenoughupdates.moulconfig.gui.component.CenterComponent
+import io.github.notenoughupdates.moulconfig.gui.component.SwitchComponent
+import io.github.notenoughupdates.moulconfig.observer.GetSetter
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.boolean
@@ -24,13 +26,16 @@ class BooleanHandler(val config: ManagedConfig) : ManagedConfig.OptionHandler<Bo
override fun emitGuiElements(opt: ManagedOption<Boolean>, guiAppender: GuiAppender) {
guiAppender.appendLabeledRow(
opt.labelText,
- WToggleButton(opt.labelText).apply {
- guiAppender.onReload { toggle = opt.value }
- setOnToggle {
- opt.value = it
+ CenterComponent(SwitchComponent(object : GetSetter<Boolean> {
+ override fun get(): Boolean {
+ return opt.get()
+ }
+
+ override fun set(newValue: Boolean) {
+ opt.set(newValue)
config.save()
}
- }
- )
+ }, 200)
+ ))
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/ClickHandler.kt b/src/main/kotlin/moe/nea/firmament/gui/config/ClickHandler.kt
index 7fbad06..eef6559 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/config/ClickHandler.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/config/ClickHandler.kt
@@ -6,9 +6,9 @@
package moe.nea.firmament.gui.config
-import io.github.cottonmc.cotton.gui.widget.WButton
+import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
import kotlinx.serialization.json.JsonElement
-import net.minecraft.text.Text
+import moe.nea.firmament.gui.FirmButtonComponent
class ClickHandler(val config: ManagedConfig, val runnable: () -> Unit) : ManagedConfig.OptionHandler<Unit> {
override fun toJson(element: Unit): JsonElement? {
@@ -19,12 +19,10 @@ class ClickHandler(val config: ManagedConfig, val runnable: () -> Unit) : Manage
override fun emitGuiElements(opt: ManagedOption<Unit>, guiAppender: GuiAppender) {
guiAppender.appendLabeledRow(
- Text.translatable("firmament.config.${config.name}.${opt.propertyName}"),
- WButton(Text.translatable("firmament.config.${config.name}.${opt.propertyName}")).apply {
- setOnClick {
- runnable()
- }
- },
+ opt.labelText,
+ FirmButtonComponent(
+ TextComponent(opt.labelText.string),
+ action = runnable),
)
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/DurationHandler.kt b/src/main/kotlin/moe/nea/firmament/gui/config/DurationHandler.kt
index 29a8ed6..c4eac03 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/config/DurationHandler.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/config/DurationHandler.kt
@@ -6,18 +6,16 @@
package moe.nea.firmament.gui.config
-import io.github.cottonmc.cotton.gui.widget.WBox
-import io.github.cottonmc.cotton.gui.widget.WLabel
-import io.github.cottonmc.cotton.gui.widget.WSlider
-import io.github.cottonmc.cotton.gui.widget.data.Axis
-import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
-import java.util.function.IntConsumer
+import io.github.notenoughupdates.moulconfig.common.IMinecraft
+import io.github.notenoughupdates.moulconfig.gui.component.RowComponent
+import io.github.notenoughupdates.moulconfig.gui.component.SliderComponent
+import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
+import io.github.notenoughupdates.moulconfig.observer.GetSetter
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.long
import kotlin.time.Duration
-import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.DurationUnit
import kotlin.time.toDuration
import net.minecraft.text.Text
@@ -34,22 +32,31 @@ class DurationHandler(val config: ManagedConfig, val min: Duration, val max: Dur
}
override fun emitGuiElements(opt: ManagedOption<Duration>, guiAppender: GuiAppender) {
- val label =
- WLabel(Text.literal(FirmFormatters.formatTimespan(opt.value))).setVerticalAlignment(VerticalAlignment.CENTER)
- guiAppender.appendLabeledRow(opt.labelText, WBox(Axis.HORIZONTAL).also {
- it.add(label, 40, 18)
- it.add(WSlider(min.inWholeMilliseconds.toInt(), max.inWholeMilliseconds.toInt(), Axis.HORIZONTAL).apply {
- valueChangeListener = IntConsumer {
- opt.value = it.milliseconds
- label.text = Text.literal(FirmFormatters.formatTimespan(opt.value))
- config.save()
- }
- guiAppender.onReload {
- value = opt.value.inWholeMilliseconds.toInt()
- label.text = Text.literal(FirmFormatters.formatTimespan(opt.value))
- }
- }, 130, 18)
- })
+ guiAppender.appendLabeledRow(
+ opt.labelText,
+ RowComponent(
+ TextComponent(IMinecraft.instance.defaultFontRenderer,
+ { FirmFormatters.formatTimespan(opt.value) },
+ 40,
+ TextComponent.TextAlignment.CENTER,
+ true,
+ false),
+ SliderComponent(
+ object : GetSetter<Float> {
+ override fun get(): Float {
+ return opt.value.toDouble(DurationUnit.SECONDS).toFloat()
+ }
+
+ override fun set(newValue: Float) {
+ opt.value = newValue.toDouble().toDuration(DurationUnit.SECONDS)
+ }
+ },
+ min.toDouble(DurationUnit.SECONDS).toFloat(),
+ max.toDouble(DurationUnit.SECONDS).toFloat(),
+ 0.1F,
+ 130
+ )
+ ))
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt b/src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt
index 3c6e502..aabcd24 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/config/GuiAppender.kt
@@ -6,37 +6,39 @@
package moe.nea.firmament.gui.config
-import io.github.cottonmc.cotton.gui.widget.WBox
-import io.github.cottonmc.cotton.gui.widget.WLabel
-import io.github.cottonmc.cotton.gui.widget.WWidget
-import io.github.cottonmc.cotton.gui.widget.data.Axis
-import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
+import io.github.notenoughupdates.moulconfig.gui.GuiComponent
+import io.github.notenoughupdates.moulconfig.gui.component.RowComponent
+import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
+import io.github.notenoughupdates.moulconfig.observer.GetSetter
import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.Text
-import moe.nea.firmament.gui.WSplitPanel
+import moe.nea.firmament.gui.FixedComponent
class GuiAppender(val width: Int, val screenAccessor: () -> Screen) {
- val panel = WBox(Axis.VERTICAL).also {
- it.setSize(width, 200)
- }
+ val panel = mutableListOf<GuiComponent>()
internal val reloadables = mutableListOf<(() -> Unit)>()
fun onReload(reloadable: () -> Unit) {
reloadables.add(reloadable)
}
- fun appendLabeledRow(label: Text, right: WWidget) {
+ fun appendLabeledRow(label: Text, right: GuiComponent) {
appendSplitRow(
- WLabel(label).setVerticalAlignment(VerticalAlignment.CENTER),
+ TextComponent(label.string),
right
)
}
- fun appendSplitRow(left: WWidget, right: WWidget) {
- appendFullRow(WSplitPanel(left.also { it.setSize(width / 2, 18) }, right.also { it.setSize(width / 2, 18) }))
+ fun appendSplitRow(left: GuiComponent, right: GuiComponent) {
+ // TODO: make this more dynamic
+ // i could just make a component that allows for using half the available size
+ appendFullRow(RowComponent(
+ FixedComponent(GetSetter.constant(width / 2), null, left),
+ FixedComponent(GetSetter.constant(width / 2), null, right),
+ ))
}
- fun appendFullRow(widget: WWidget) {
- panel.add(widget, width, 18)
+ fun appendFullRow(widget: GuiComponent) {
+ panel.add(widget)
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/HudMetaHandler.kt b/src/main/kotlin/moe/nea/firmament/gui/config/HudMetaHandler.kt
index 7df98e3..a2147e8 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/config/HudMetaHandler.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/config/HudMetaHandler.kt
@@ -6,13 +6,14 @@
package moe.nea.firmament.gui.config
-import io.github.cottonmc.cotton.gui.widget.WButton
+import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.json.encodeToJsonElement
import net.minecraft.text.MutableText
import net.minecraft.text.Text
+import moe.n