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" nealisp = "1.1.0"
# Update from https://github.com/NotEnoughUpdates/MoulConfig/tags # 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 # Update from https://repo.nea.moe/#/releases/moe/nea/mc-auto-translations/moe.nea.mc-auto-translations.gradle.plugin
mcAutoTranslations = "0.3.0" mcAutoTranslations = "0.3.0"

View File

@@ -113,11 +113,3 @@ class BarComponent(
fun Identifier.toMoulConfig(): MyResourceLocation { fun Identifier.toMoulConfig(): MyResourceLocation {
return MyResourceLocation(this.namespace, this.path) 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), getBackground(context),
0f, 0f, context.width, context.height 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)) element.render(getChildContext(context))
context.renderContext.popMatrix() context.renderContext.popMatrix()
} }

View File

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

View File

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

View File

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