Add a buttonsContext method to ClickGui.kt, and a WIP scroll function to ClickBox.kt
This commit is contained in:
parent
5c2d09abc1
commit
5d5ea4b5ea
|
@ -3,6 +3,7 @@ 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
|
||||
|
||||
|
@ -16,17 +17,13 @@ internal fun newBox(translationKey: String): ClickBox {
|
|||
object ClickGui: SnowyScreen() {
|
||||
private var GuiDragging: Boolean = false
|
||||
override val components = mutableSetOf<Element>()
|
||||
fun addComps(vararg toAdd: Element) { components.addAll(toAdd) }
|
||||
fun addComps(vararg toAdd: Element) = components.addAll(toAdd)
|
||||
|
||||
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.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 using the f argument
|
||||
}
|
||||
return false
|
||||
}
|
||||
private inline fun buttonsContext(args: (ClickButton) -> Unit) = boxContext { it.buttons.values.forEach(args) }
|
||||
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { buttonsContext { it.mouseClicked(d, e, i) }; return false }
|
||||
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { buttonsContext { it.mouseReleased(d, e, i) }; return false }
|
||||
override fun mouseScrolled(d: Double, e: Double, f: Double): Boolean { boxContext { it.scroll(f) }; return false }
|
||||
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
|
||||
if (i == 0) {
|
||||
components.forEach {
|
||||
|
|
|
@ -24,7 +24,7 @@ fun interface Renderable {
|
|||
|
||||
abstract class Element(
|
||||
@JvmField val xOrigin: Double, @JvmField val yOrigin: Double,
|
||||
val width: Int, val height: Int
|
||||
var width: Int, var height: Int
|
||||
): Renderable {
|
||||
open var x = xOrigin; open var y = yOrigin
|
||||
internal fun withinBounds(coordinateX: Double, coordinateY: Double): Boolean =
|
||||
|
@ -52,7 +52,10 @@ abstract class Element(
|
|||
var hidden: Boolean = false; protected set
|
||||
}
|
||||
|
||||
abstract class ColoredElement(x: Double, y: Double, width: Int, height: Int, protected open var color: Int, protected var opacity: Float) : Element(x, y, width, height) {
|
||||
abstract class ColoredElement(
|
||||
x: Double, y: Double, width: Int, height: Int,
|
||||
protected open var color: Int, protected var opacity: Float,
|
||||
) : Element(x, y, width, height) {
|
||||
companion object {
|
||||
const val TransparentColor: Int = -0x1
|
||||
@JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer {
|
||||
|
|
|
@ -18,7 +18,7 @@ class ClickBox(
|
|||
private val name: TranslatableComponent? = null
|
||||
): ColoredElement(x, y, 80, 10, 0x6C9E9D, 0.5F) {
|
||||
val buttons = mutableMapOf<String, ClickButton>()
|
||||
fun addButtons(vararg collect: Pair<String, () -> Unit>, color: Int = 0x6C9E9D): ClickBox {
|
||||
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)
|
||||
|
@ -41,6 +41,11 @@ class ClickBox(
|
|||
RenderSystem.enableTexture()
|
||||
}
|
||||
}
|
||||
fun scroll(supplied: Double) {
|
||||
with(scrollBar) {
|
||||
// TODO Implement scrolling
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val inclination: Double = 2.5
|
||||
|
|
Loading…
Reference in New Issue