aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-07-05 15:56:07 +0200
committerLinnea Gräf <nea@nea.moe>2025-07-05 15:56:10 +0200
commitda0be5222556797d332ab5a996a3cbd1140a2282 (patch)
treef77ff250420fc62cfba6642765299fb94e15f16c /src
parent9b53b601c1dd76fd6e368d68cf823706aac0bba6 (diff)
downloadFirmament-da0be5222556797d332ab5a996a3cbd1140a2282.tar.gz
Firmament-da0be5222556797d332ab5a996a3cbd1140a2282.tar.bz2
Firmament-da0be5222556797d332ab5a996a3cbd1140a2282.zip
feat: moulconfig beta v4
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/gui/BarComponent.kt8
-rw-r--r--src/main/kotlin/gui/FirmButtonComponent.kt2
-rw-r--r--src/main/kotlin/gui/FirmHoverComponent.kt90
-rw-r--r--src/main/kotlin/gui/ImageComponent.kt44
-rw-r--r--src/main/kotlin/util/MoulConfigFragment.kt2
5 files changed, 70 insertions, 76 deletions
diff --git a/src/main/kotlin/gui/BarComponent.kt b/src/main/kotlin/gui/BarComponent.kt
index b82c666..da781da 100644
--- a/src/main/kotlin/gui/BarComponent.kt
+++ b/src/main/kotlin/gui/BarComponent.kt
@@ -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)
-}
diff --git a/src/main/kotlin/gui/FirmButtonComponent.kt b/src/main/kotlin/gui/FirmButtonComponent.kt
index 82e5b05..fe9b476 100644
--- a/src/main/kotlin/gui/FirmButtonComponent.kt
+++ b/src/main/kotlin/gui/FirmButtonComponent.kt
@@ -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()
}
diff --git a/src/main/kotlin/gui/FirmHoverComponent.kt b/src/main/kotlin/gui/FirmHoverComponent.kt
index b1792ce..e38582a 100644
--- a/src/main/kotlin/gui/FirmHoverComponent.kt
+++ b/src/main/kotlin/gui/FirmHoverComponent.kt
@@ -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 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 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)
-
- }
-
- 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 keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean {
- return child.keyboardEvent(event, context)
- }
+ override fun getWidth(): Int {
+ return child.width
+ }
+
+ 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 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()
+
+ 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)
+ }
}
diff --git a/src/main/kotlin/gui/ImageComponent.kt b/src/main/kotlin/gui/ImageComponent.kt
index bba7dee..695c0ed 100644
--- a/src/main/kotlin/gui/ImageComponent.kt
+++ b/src/main/kotlin/gui/ImageComponent.kt
@@ -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)
+ }
+ )
+ }
}
diff --git a/src/main/kotlin/util/MoulConfigFragment.kt b/src/main/kotlin/util/MoulConfigFragment.kt
index 36132cd..28ccfd0 100644
--- a/src/main/kotlin/util/MoulConfigFragment.kt
+++ b/src/main/kotlin/util/MoulConfigFragment.kt
@@ -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() {