diff --git a/Common/src/main/java/at/petrak/hexcasting/api/spell/iota/IotaType.java b/Common/src/main/java/at/petrak/hexcasting/api/spell/iota/IotaType.java index f1ccb6a9..f40f024c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/spell/iota/IotaType.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/spell/iota/IotaType.java @@ -1,15 +1,12 @@ package at.petrak.hexcasting.api.spell.iota; import at.petrak.hexcasting.common.lib.hex.HexIotaTypes; -import net.minecraft.client.gui.Font; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextColor; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.FormattedCharSequence; import javax.annotation.Nullable; -import java.util.List; // Take notes from ForgeRegistryEntry public abstract class IotaType { @@ -31,15 +28,6 @@ public abstract class IotaType { */ public abstract Component display(Tag tag); - /** - * Get a display of this datum from the {@code data} tag, with a maximum width. - * This is for use on the client. - */ - public List displayWithWidth(Tag tag, int maxWidth, Font font) { - var display = this.display(tag); - return font.split(display, maxWidth); - } - /** * Get the color associated with this datum type. */ diff --git a/Common/src/main/java/at/petrak/hexcasting/api/spell/iota/ListIota.java b/Common/src/main/java/at/petrak/hexcasting/api/spell/iota/ListIota.java index 4b742dae..69f7f3a4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/spell/iota/ListIota.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/spell/iota/ListIota.java @@ -4,14 +4,11 @@ import at.petrak.hexcasting.api.spell.SpellList; import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.common.lib.hex.HexIotaTypes; import net.minecraft.ChatFormatting; -import net.minecraft.client.gui.Font; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -112,55 +109,6 @@ public class ListIota extends Iota { return Component.translatable("hexcasting.tooltip.list_contents", out).withStyle(ChatFormatting.DARK_PURPLE); } - @Override - public List displayWithWidth(Tag tag, int maxWidth, Font font) { - // We aim to not break one iota between lines - var listTag = HexUtils.downcast(tag, ListTag.TYPE); - - var start = FormattedCharSequence.forward(listTag.isEmpty() ? "[]" : "[", - Style.EMPTY.withColor(ChatFormatting.DARK_PURPLE)); - var cursor = font.width(start); - var currentLine = new ArrayList<>(List.of(start)); - var out = new ArrayList(); - - for (int i = 0; i < listTag.size(); i++) { - Tag subtag = listTag.get(i); - var cSubtag = HexUtils.downcast(subtag, CompoundTag.TYPE); - var translation = HexIotaTypes.getDisplay(cSubtag); - var currentElement = translation.getVisualOrderText(); - String addl; - if (i < listTag.size() - 1) { - addl = ", "; - } else { - // Last go-around, so add the closing bracket - addl = "]"; - } - currentElement = FormattedCharSequence.composite(currentElement, - FormattedCharSequence.forward(addl, Style.EMPTY.withColor(ChatFormatting.DARK_PURPLE))); - - var width = font.width(currentElement); - - if (cursor + width > maxWidth) { - out.add(FormattedCharSequence.composite(currentLine)); - currentLine = new ArrayList<>(); - // Indent further lines by two spaces - var indentation = FormattedCharSequence.forward(" ", Style.EMPTY); - var lineStart = FormattedCharSequence.composite(indentation, currentElement); - currentLine.add(lineStart); - cursor = font.width(lineStart); - } else { - currentLine.add(currentElement); - cursor += width; - } - } - - if (!currentLine.isEmpty()) { - out.add(FormattedCharSequence.composite(currentLine)); - } - - return out; - } - @Override public int color() { return 0xff_aa00aa; diff --git a/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt b/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt index 539a5928..13aa080e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt +++ b/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt @@ -11,12 +11,11 @@ import at.petrak.hexcasting.api.spell.math.HexCoord import at.petrak.hexcasting.api.spell.math.HexDir import at.petrak.hexcasting.api.spell.math.HexPattern import at.petrak.hexcasting.api.utils.asTranslatedComponent -import at.petrak.hexcasting.api.utils.gold import at.petrak.hexcasting.client.* import at.petrak.hexcasting.client.ktxt.accumulatedScroll import at.petrak.hexcasting.client.sound.GridSoundInstance -import at.petrak.hexcasting.common.lib.hex.HexIotaTypes import at.petrak.hexcasting.common.lib.HexSounds +import at.petrak.hexcasting.common.lib.hex.HexIotaTypes import at.petrak.hexcasting.common.network.MsgNewSpellPatternSyn import at.petrak.hexcasting.xplat.IClientXplatAbstractions import com.mojang.blaze3d.systems.RenderSystem @@ -44,7 +43,7 @@ class GuiSpellcasting constructor( ) : Screen("gui.hexcasting.spellcasting".asTranslatedComponent) { private var stackDescs: List = listOf() private var parenDescs: List = listOf() - private var ravenmind: List? = null + private var ravenmind: FormattedCharSequence? = null private var drawState: PatternDrawState = PatternDrawState.BetweenPatterns private val usedSpots: MutableSet = HashSet() @@ -76,14 +75,15 @@ class GuiSpellcasting constructor( val mc = Minecraft.getInstance() val width = (this.width * LHS_IOTAS_ALLOCATION).toInt() this.stackDescs = - this.cachedStack.flatMap { HexIotaTypes.getDisplayWithMaxWidth(it, width, mc.font).asReversed() } + this.cachedStack.map { HexIotaTypes.getDisplayWithMaxWidth(it, width, mc.font) } .asReversed() - this.parenDescs = if (this.cachedParens.isNotEmpty()) - this.cachedParens.flatMap { HexIotaTypes.getDisplayWithMaxWidth(it, width, mc.font) } - else if (this.parenCount > 0) - listOf("...".gold.visualOrderText) - else - emptyList() +// this.parenDescs = if (this.cachedParens.isNotEmpty()) +// this.cachedParens.flatMap { HexIotaTypes.getDisplayWithMaxWidth(it, width, mc.font) } +// else if (this.parenCount > 0) +// listOf("...".gold.visualOrderText) +// else +// emptyList() + this.parenDescs = emptyList() this.ravenmind = this.cachedRavenmind?.let { HexIotaTypes.getDisplayWithMaxWidth( @@ -383,23 +383,23 @@ class GuiSpellcasting constructor( ps.pushPose() ps.translate(10.0, 10.0, 0.0) - if (this.parenCount > 0) { - val boxHeight = (this.parenDescs.size + 1f) * 10f - RenderSystem.setShader(GameRenderer::getPositionColorShader) - RenderSystem.defaultBlendFunc() - drawBox(ps, 0f, 0f, (this.width * LHS_IOTAS_ALLOCATION + 5).toFloat(), boxHeight, 7.5f) - ps.translate(0.0, 0.0, 1.0) - - val time = ClientTickCounter.getTotal() * 0.16f - val opacity = (Mth.map(cos(time), -1f, 1f, 200f, 255f)).toInt() - val color = 0x00_ffffff or (opacity shl 24) - RenderSystem.setShader { prevShader } - for (desc in this.parenDescs) { - font.draw(ps, desc, 10f, 7f, color) - ps.translate(0.0, 10.0, 0.0) - } - ps.translate(0.0, 15.0, 0.0) - } +// if (this.parenCount > 0) { +// val boxHeight = (this.parenDescs.size + 1f) * 10f +// RenderSystem.setShader(GameRenderer::getPositionColorShader) +// RenderSystem.defaultBlendFunc() +// drawBox(ps, 0f, 0f, (this.width * LHS_IOTAS_ALLOCATION + 5).toFloat(), boxHeight, 7.5f) +// ps.translate(0.0, 0.0, 1.0) +// +// val time = ClientTickCounter.getTotal() * 0.16f +// val opacity = (Mth.map(cos(time), -1f, 1f, 200f, 255f)).toInt() +// val color = 0x00_ffffff or (opacity shl 24) +// RenderSystem.setShader { prevShader } +// for (desc in this.parenDescs) { +// font.draw(ps, desc, 10f, 7f, color) +// ps.translate(0.0, 10.0, 0.0) +// } +// ps.translate(0.0, 15.0, 0.0) +// } if (this.stackDescs.isNotEmpty()) { val boxHeight = (this.stackDescs.size + 1f) * 10f @@ -415,30 +415,27 @@ class GuiSpellcasting constructor( } ps.popPose() - if (!this.ravenmind.isNullOrEmpty()) { + if (this.ravenmind != null) { val kotlinBad = this.ravenmind!! ps.pushPose() - ps.translate(this.width * 0.8, 10.0, 0.0) - val boxHeight = (kotlinBad.size + 0.5f) * 10f + val boxHeight = 15f val addlScale = 1.5f + ps.translate(this.width * (1.0 - RHS_IOTAS_ALLOCATION * addlScale) - 10, 10.0, 0.0) RenderSystem.setShader(GameRenderer::getPositionColorShader) RenderSystem.enableBlend() drawBox( ps, 0f, 0f, - ((this.width * RHS_IOTAS_ALLOCATION + 5) * addlScale).toFloat(), boxHeight * addlScale, + (this.width * RHS_IOTAS_ALLOCATION * addlScale).toFloat(), boxHeight * addlScale, ) ps.translate(5.0, 5.0, 1.0) ps.scale(addlScale, addlScale, 1f) - val time = ClientTickCounter.getTotal() * 0.42f + val time = ClientTickCounter.getTotal() * 0.2f val opacity = (Mth.map(sin(time), -1f, 1f, 150f, 255f)).toInt() val color = 0x00_ffffff or (opacity shl 24) RenderSystem.setShader { prevShader } - for (desc in kotlinBad) { - font.draw(ps, desc, 0f, 0f, color) - ps.translate(0.0, 10.0, 0.0) - } + font.draw(ps, kotlinBad, 0f, 0f, color) ps.popPose() } @@ -479,7 +476,7 @@ class GuiSpellcasting constructor( companion object { const val LHS_IOTAS_ALLOCATION = 0.7 - const val RHS_IOTAS_ALLOCATION = 0.1 + const val RHS_IOTAS_ALLOCATION = 0.15 fun drawBox(ps: PoseStack, x: Float, y: Float, w: Float, h: Float, leftMargin: Float = 2.5f) { RenderSystem.setShader(GameRenderer::getPositionColorShader) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexIotaTypes.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexIotaTypes.java index 67e767a6..ba4bfcf3 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexIotaTypes.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/hex/HexIotaTypes.java @@ -150,16 +150,26 @@ public class HexIotaTypes { return type.display(data); } - public static List getDisplayWithMaxWidth(CompoundTag tag, int maxWidth, Font font) { + public static FormattedCharSequence getDisplayWithMaxWidth(CompoundTag tag, int maxWidth, Font font) { var type = getTypeFromTag(tag); if (type == null) { - return font.split(brokenIota(), maxWidth); + return brokenIota().getVisualOrderText(); } var data = tag.get(KEY_DATA); if (data == null) { - return font.split(brokenIota(), maxWidth); + return brokenIota().getVisualOrderText(); + } + var display = type.display(data); + var splitted = font.split(display, maxWidth - font.width("...")); + if (splitted.isEmpty()) + return FormattedCharSequence.EMPTY; + else if (splitted.size() == 1) + return splitted.get(0); + else { + var first = splitted.get(0); + return FormattedCharSequence.fromPair(first, + Component.literal("...").withStyle(ChatFormatting.GRAY).getVisualOrderText()); } - return type.displayWithWidth(data, maxWidth, font); } public static int getColor(CompoundTag tag) {