feat: moulconfig beta v4

This commit is contained in:
Linnea Gräf
2025-07-05 15:56:07 +02:00
parent 9b53b601c1
commit da0be52225
6 changed files with 64 additions and 70 deletions

View File

@@ -71,7 +71,7 @@ jarvis = "1.1.4"
nealisp = "1.1.0"
# Update from https://github.com/NotEnoughUpdates/MoulConfig/tags
moulconfig = "3.11.0"
moulconfig = "4.0.0-beta"
# Update from https://repo.nea.moe/#/releases/moe/nea/mc-auto-translations/moe.nea.mc-auto-translations.gradle.plugin
mcAutoTranslations = "0.3.0"

View File

@@ -113,11 +113,3 @@ class BarComponent(
fun Identifier.toMoulConfig(): MyResourceLocation {
return MyResourceLocation(this.namespace, this.path)
}
fun RenderContext.color(color: Color) {
color(color.red, color.green, color.blue, color.alpha)
}
fun RenderContext.color(red: Int, green: Int, blue: Int, alpha: Int) {
color(red / 255f, green / 255f, blue / 255f, alpha / 255f)
}

View File

@@ -74,7 +74,7 @@ open class FirmButtonComponent(
getBackground(context),
0f, 0f, context.width, context.height
)
context.renderContext.translate(insets.toFloat(), insets.toFloat(), 0f)
context.renderContext.translate(insets.toFloat(), insets.toFloat())
element.render(getChildContext(context))
context.renderContext.popMatrix()
}

View File

@@ -10,50 +10,50 @@ import kotlin.time.Duration
import moe.nea.firmament.util.TimeMark
class FirmHoverComponent(
val child: GuiComponent,
val hoverLines: Supplier<List<String>>,
val hoverDelay: Duration,
val child: GuiComponent,
val hoverLines: Supplier<List<String>>,
val hoverDelay: Duration,
) : GuiComponent() {
override fun getWidth(): Int {
return child.width
}
override fun getWidth(): Int {
return child.width
}
override fun getHeight(): Int {
return child.height
}
override fun getHeight(): Int {
return child.height
}
override fun <T : Any?> foldChildren(
initial: T,
visitor: BiFunction<GuiComponent, T, T>
): T {
return visitor.apply(child, initial)
}
override fun <T : Any?> foldChildren(
initial: T,
visitor: BiFunction<GuiComponent, T, T>
): T {
return visitor.apply(child, initial)
}
override fun render(context: GuiImmediateContext) {
if (context.isHovered && (permaHover || lastMouseMove.passedTime() > hoverDelay)) {
context.renderContext.scheduleDrawTooltip(hoverLines.get())
permaHover = true
} else {
permaHover = false
}
if (!context.isHovered) {
lastMouseMove = TimeMark.now()
}
child.render(context)
override fun render(context: GuiImmediateContext) {
if (context.isHovered && (permaHover || lastMouseMove.passedTime() > hoverDelay)) {
context.renderContext.scheduleDrawTooltip(context.mouseX, context.mouseY, hoverLines.get())
permaHover = true
} else {
permaHover = false
}
if (!context.isHovered) {
lastMouseMove = TimeMark.now()
}
child.render(context)
}
}
var permaHover = false
var lastMouseMove = TimeMark.farPast()
var permaHover = false
var lastMouseMove = TimeMark.farPast()
override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean {
if (mouseEvent is MouseEvent.Move) {
lastMouseMove = TimeMark.now()
}
return child.mouseEvent(mouseEvent, context)
}
override fun mouseEvent(mouseEvent: MouseEvent, context: GuiImmediateContext): Boolean {
if (mouseEvent is MouseEvent.Move) {
lastMouseMove = TimeMark.now()
}
return child.mouseEvent(mouseEvent, context)
}
override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean {
return child.keyboardEvent(event, context)
}
override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean {
return child.keyboardEvent(event, context)
}
}

View File

@@ -6,28 +6,30 @@ import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext
import java.util.function.Supplier
class ImageComponent(
private val width: Int,
private val height: Int,
val resourceLocation: Supplier<MyResourceLocation>,
val u1: Float,
val u2: Float,
val v1: Float,
val v2: Float,
private val width: Int,
private val height: Int,
val resourceLocation: Supplier<MyResourceLocation>,
val u1: Float,
val u2: Float,
val v1: Float,
val v2: Float,
) : GuiComponent() {
override fun getWidth(): Int {
return width
}
override fun getWidth(): Int {
return width
}
override fun getHeight(): Int {
return height
}
override fun getHeight(): Int {
return height
}
override fun render(context: GuiImmediateContext) {
context.renderContext.bindTexture(resourceLocation.get())
context.renderContext.drawTexturedRect(
0f, 0f,
context.width.toFloat(), context.height.toFloat(),
u1, v1, u2, v2
)
}
override fun render(context: GuiImmediateContext) {
context.renderContext.drawComplexTexture(
resourceLocation.get(),
0f, 0f,
context.width.toFloat(), context.height.toFloat(),
{
it.uv(u1, v1, u2, v2)
}
)
}
}

View File

@@ -35,7 +35,7 @@ class MoulConfigFragment(
m.translate(position.x.toFloat(), position.y.toFloat(), 0F)
context.root.render(ctx)
m.pop()
ctx.renderContext.doDrawTooltip()
ctx.renderContext.renderExtraLayers()
}
override fun close() {