Add components in another file called addComponents.kt
This commit is contained in:
parent
9dc097d32f
commit
1551d70e88
|
@ -3,25 +3,24 @@ package fr.username404.snowygui
|
||||||
import fr.username404.snowygui.gui.Element
|
import fr.username404.snowygui.gui.Element
|
||||||
import fr.username404.snowygui.gui.SnowyScreen
|
import fr.username404.snowygui.gui.SnowyScreen
|
||||||
import fr.username404.snowygui.gui.elements.ClickBox
|
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
|
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() {
|
object ClickGui: SnowyScreen() {
|
||||||
private var GuiDragging: Boolean = false
|
private var GuiDragging: Boolean = false
|
||||||
override val components: MutableSet<Element> = mutableSetOf(
|
override val components = mutableSetOf<Element>()
|
||||||
ClickBox(4.0, 4.0, TranslatableComponent("snowy.clickbox.misc"), mutableListOf(
|
fun addComps(vararg toAdd: Element) { components.addAll(toAdd) }
|
||||||
ClickButton(color = 0x6C9E9D, Title = "Fullbright"),
|
|
||||||
ClickButton(color = 0x6C9E9D)
|
|
||||||
)),
|
|
||||||
ClickBox(90.0, 4.0, TranslatableComponent("snowy.clickbox.rendering"), mutableListOf(
|
|
||||||
ClickButton(color = 0x6C9E9D),
|
|
||||||
ClickButton(color = 0x6C9E9D)
|
|
||||||
))
|
|
||||||
)
|
|
||||||
|
|
||||||
private inline fun boxContext(args: (ClickBox) -> Unit) = components.filterIsInstance<ClickBox>().forEach(args)
|
private inline fun boxContext(args: (ClickBox) -> Unit) = components.filterIsInstance<ClickBox>().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 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.forEach { elem -> elem.mouseReleased(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 {
|
override fun mouseScrolled(d: Double, e: Double, f: Double): Boolean {
|
||||||
boxContext {
|
boxContext {
|
||||||
it.scrollBar.height // TODO Implement scrolling
|
it.scrollBar.height // TODO Implement scrolling
|
||||||
|
@ -40,4 +39,5 @@ object ClickGui: SnowyScreen() {
|
||||||
}
|
}
|
||||||
return super.mouseDragged(d, e, i, f, g)
|
return super.mouseDragged(d, e, i, f, g)
|
||||||
}
|
}
|
||||||
|
init { addComponents() }
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ import net.minecraft.network.chat.TranslatableComponent
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) {
|
abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) {
|
||||||
open val components: MutableSet<Element> by Delegates.notNull()
|
protected open val components: MutableSet<Element> by Delegates.notNull()
|
||||||
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) {
|
||||||
if (poseStack != null) {
|
if (poseStack != null) {
|
||||||
components.forEach {
|
components.forEach {
|
||||||
|
|
|
@ -18,6 +18,14 @@ class ClickBox(
|
||||||
private val name: TranslatableComponent? = null
|
private val name: TranslatableComponent? = null
|
||||||
): ColoredElement(x, y, 80, 10, 0x6C9E9D, 0.5F) {
|
): ColoredElement(x, y, 80, 10, 0x6C9E9D, 0.5F) {
|
||||||
val buttons = mutableMapOf<String, ClickButton>()
|
val buttons = mutableMapOf<String, ClickButton>()
|
||||||
|
fun addButtons(vararg collect: Pair<String, () -> Unit>, color: Int = 0x6C9E9D): ClickBox {
|
||||||
|
buttons.putAll(
|
||||||
|
collect.map {
|
||||||
|
it.first to ClickButton(Title = it.first, action = it.second, color = color)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return this
|
||||||
|
}
|
||||||
@JvmField
|
@JvmField
|
||||||
val scrollBar: ColoredElement = object: ColoredElement(
|
val scrollBar: ColoredElement = object: ColoredElement(
|
||||||
(x + width), y + height + 3,
|
(x + width), y + height + 3,
|
||||||
|
|
|
@ -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()
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue