diff --git a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt index 0d93b5e..92fd293 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt @@ -3,25 +3,24 @@ package fr.username404.snowygui import fr.username404.snowygui.gui.Element import fr.username404.snowygui.gui.SnowyScreen import fr.username404.snowygui.gui.elements.ClickBox -import fr.username404.snowygui.gui.elements.ClickButton +import fr.username404.snowygui.misc.addComponents import net.minecraft.network.chat.TranslatableComponent +private var baseXAxis: Double = 4.0 +internal fun newBox(translationKey: String): ClickBox { + val result = ClickBox(baseXAxis, 4.0, TranslatableComponent(translationKey)) + baseXAxis += 86 + return result +} + object ClickGui: SnowyScreen() { private var GuiDragging: Boolean = false - override val components: MutableSet = mutableSetOf( - ClickBox(4.0, 4.0, TranslatableComponent("snowy.clickbox.misc"), mutableListOf( - ClickButton(color = 0x6C9E9D, Title = "Fullbright"), - ClickButton(color = 0x6C9E9D) - )), - ClickBox(90.0, 4.0, TranslatableComponent("snowy.clickbox.rendering"), mutableListOf( - ClickButton(color = 0x6C9E9D), - ClickButton(color = 0x6C9E9D) - )) - ) + override val components = mutableSetOf() + fun addComps(vararg toAdd: Element) { components.addAll(toAdd) } private inline fun boxContext(args: (ClickBox) -> Unit) = components.filterIsInstance().forEach(args) - override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { boxContext { it.buttons.forEach { elem -> elem.mouseClicked(d, e, i) } }; return false } - override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { boxContext { it.buttons.forEach { elem -> elem.mouseReleased(d, e, i) } }; return false } + override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { boxContext { it.buttons.values.forEach { elem -> elem.mouseClicked(d, e, i) } }; return false } + override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { boxContext { it.buttons.values.forEach { elem -> elem.mouseReleased(d, e, i) } }; return false } override fun mouseScrolled(d: Double, e: Double, f: Double): Boolean { boxContext { it.scrollBar.height // TODO Implement scrolling @@ -40,4 +39,5 @@ object ClickGui: SnowyScreen() { } return super.mouseDragged(d, e, i, f, g) } + init { addComponents() } } \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt index 923724d..f54b76c 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt @@ -6,7 +6,7 @@ import net.minecraft.network.chat.TranslatableComponent import kotlin.properties.Delegates abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) { - open val components: MutableSet by Delegates.notNull() + protected open val components: MutableSet by Delegates.notNull() override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) { if (poseStack != null) { components.forEach { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index 6a51e95..bde5ebc 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -18,6 +18,14 @@ class ClickBox( private val name: TranslatableComponent? = null ): ColoredElement(x, y, 80, 10, 0x6C9E9D, 0.5F) { val buttons = mutableMapOf() + fun addButtons(vararg collect: Pair Unit>, color: Int = 0x6C9E9D): ClickBox { + buttons.putAll( + collect.map { + it.first to ClickButton(Title = it.first, action = it.second, color = color) + } + ) + return this + } @JvmField val scrollBar: ColoredElement = object: ColoredElement( (x + width), y + height + 3, diff --git a/common/src/main/kotlin/fr/username404/snowygui/misc/addComponents.kt b/common/src/main/kotlin/fr/username404/snowygui/misc/addComponents.kt new file mode 100644 index 0000000..da5060d --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/misc/addComponents.kt @@ -0,0 +1,15 @@ +package fr.username404.snowygui.misc + +import fr.username404.snowygui.ClickGui +import fr.username404.snowygui.newBox + +fun ClickGui.addComponents() { + addComps( + newBox("snowy.clickbox.misc").addButtons( + "Fullbright" to { + // TODO Fullbright + } + ), + newBox("snowy.clickbox.rendering").addButtons() + ) +} \ No newline at end of file