aboutsummaryrefslogtreecommitdiff
path: root/src/texturePacks/java/moe/nea/firmament/features
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-06-22 14:51:38 +0200
committerLinnea Gräf <nea@nea.moe>2025-06-22 14:54:02 +0200
commit4cfba87783a7280678312ac42373eb639c86a62a (patch)
treeb721e53fb8de4826c2f46ac98b75210d0e081af3 /src/texturePacks/java/moe/nea/firmament/features
parentdb0174ca8c391e0b46cd013c53602679f99af398 (diff)
downloadFirmament-4cfba87783a7280678312ac42373eb639c86a62a.tar.gz
Firmament-4cfba87783a7280678312ac42373eb639c86a62a.tar.bz2
Firmament-4cfba87783a7280678312ac42373eb639c86a62a.zip
feat: Add interactive component movers + fix: move coordinates
Diffstat (limited to 'src/texturePacks/java/moe/nea/firmament/features')
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt86
1 files changed, 54 insertions, 32 deletions
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt
index 76047b4..a68fb2a 100644
--- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt
@@ -2,7 +2,8 @@ package moe.nea.firmament.features.texturepack
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
-import net.minecraft.client.MinecraftClient
+import kotlinx.serialization.Transient
+import net.minecraft.client.font.TextRenderer
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.gui.screen.ingame.HandledScreen
@@ -17,7 +18,9 @@ import moe.nea.firmament.Firmament
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.FinalizeResourceManagerEvent
import moe.nea.firmament.events.ScreenChangeEvent
-import moe.nea.firmament.features.texturepack.CustomTextColors.cache
+import moe.nea.firmament.features.texturepack.CustomScreenLayouts.Alignment.CENTER
+import moe.nea.firmament.features.texturepack.CustomScreenLayouts.Alignment.LEFT
+import moe.nea.firmament.features.texturepack.CustomScreenLayouts.Alignment.RIGHT
import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
import moe.nea.firmament.util.ErrorUtil.intoCatch
import moe.nea.firmament.util.IdentifierSerializer
@@ -29,8 +32,18 @@ object CustomScreenLayouts : SinglePreparationResourceReloader<List<CustomScreen
val predicates: Preds,
val background: BackgroundReplacer? = null,
val slots: List<SlotReplacer> = listOf(),
- val playerTitle: TitleReplacer = TitleReplacer(),
- val containerTitle: TitleReplacer = TitleReplacer()
+ val playerTitle: TitleReplacer? = null,
+ val containerTitle: TitleReplacer? = null,
+ val repairCostTitle: TitleReplacer? = null,
+ val nameField: ComponentMover? = null,
+ )
+
+ @Serializable
+ data class ComponentMover(
+ val x: Int,
+ val y: Int,
+ val width: Int? = null,
+ val height: Int? = null,
)
@Serializable
@@ -97,49 +110,48 @@ object CustomScreenLayouts : SinglePreparationResourceReloader<List<CustomScreen
enum class Alignment {
@SerialName("left")
LEFT,
+
@SerialName("center")
CENTER,
+
@SerialName("right")
RIGHT
}
@Serializable
data class TitleReplacer(
- val x: Int = 0,
- val y: Int = 0,
+ val x: Int? = null,
+ val y: Int? = null,
val align: Alignment = Alignment.LEFT,
val replace: String? = null
- )
-
- fun alignText(text: Text, x: Int, width: Int): Int {
- var currentText = mapReplaceText(text)
- val align = if (currentText.string == "Inventory") activeScreenOverride?.playerTitle?.align ?: Alignment.LEFT
- else activeScreenOverride?.containerTitle?.align ?: Alignment.LEFT
-
- val textWidth = MinecraftClient.getInstance().textRenderer.getWidth(Text.literal(currentText.string))
-
+ ) {
+ @Transient
+ val replacedText: Text? = replace?.let(Text::literal)
- return when (align) {
- Alignment.LEFT -> x
- Alignment.CENTER -> x + (width - textWidth) / 2
- Alignment.RIGHT -> x + (width - textWidth)
+ fun replaceText(text: Text): Text {
+ if (replacedText != null) return replacedText
+ return text
}
- }
- fun mapReplaceText(text: Text): Text {
- val replaceText = if (text.string == "Inventory") activeScreenOverride?.playerTitle?.replace ?: null else activeScreenOverride?.containerTitle?.replace ?: null
- if (replaceText == null) return text
- return Text.literal(replaceText)
- }
+ fun replaceY(y: Int): Int {
+ return this.y ?: y
+ }
- fun mapTextToX(text: Text, x: Int): Int {
- return x + if (text.string == "Inventory") activeScreenOverride?.playerTitle?.x
- ?: 0 else activeScreenOverride?.containerTitle?.x ?: 0
- }
+ fun replaceX(font: TextRenderer, text: Text, x: Int): Int {
+ val baseX = this.x ?: x
+ return baseX + when (this.align) {
+ LEFT -> 0
+ CENTER -> -font.getWidth(text) / 2
+ RIGHT -> -font.getWidth(text)
+ }
+ }
- fun mapTextToY(text: Text, y: Int): Int {
- return y + if (text.string == "Inventory") activeScreenOverride?.playerTitle?.y
- ?: 0 else activeScreenOverride?.containerTitle?.y ?: 0
+ /**
+ * Not technically part of the package, but it does allow for us to later on seamlessly integrate a color option into this class as well
+ */
+ fun replaceColor(text: Text, color: Int): Int {
+ return CustomTextColors.mapTextColor(text, color)
+ }
}
@@ -175,6 +187,16 @@ object CustomScreenLayouts : SinglePreparationResourceReloader<List<CustomScreen
@get:JvmStatic
var activeScreenOverride = null as CustomScreenLayout?
+ val DO_NOTHING_TEXT_REPLACER = TitleReplacer()
+
+ @JvmStatic
+ fun <T>getMover(selector: (CustomScreenLayout)-> (T?)) =
+ activeScreenOverride?.let(selector)
+
+ @JvmStatic
+ fun getTextMover(selector: (CustomScreenLayout) -> (TitleReplacer?)) =
+ getMover(selector) ?: DO_NOTHING_TEXT_REPLACER
+
@Subscribe
fun onScreenOpen(event: ScreenChangeEvent) {
if (!CustomSkyBlockTextures.TConfig.allowLayoutChanges) {