From 6ed96d082ebbec83900dbfcc9b19ac68e4276409 Mon Sep 17 00:00:00 2001 From: ScarletRedMan Date: Mon, 2 Dec 2024 18:07:23 +0700 Subject: [PATCH] feat: implemented DialogueRenderer --- .../api/talk/dialogue/DialogueRenderer.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/ru/dragonestia/msb3/api/talk/dialogue/DialogueRenderer.java b/api/src/main/java/ru/dragonestia/msb3/api/talk/dialogue/DialogueRenderer.java index 819340f..75970da 100644 --- a/api/src/main/java/ru/dragonestia/msb3/api/talk/dialogue/DialogueRenderer.java +++ b/api/src/main/java/ru/dragonestia/msb3/api/talk/dialogue/DialogueRenderer.java @@ -277,7 +277,7 @@ public class DialogueRenderer { // Answers - var answers = List.of("Hello world!", "I am a teapot", "I love pizza", "msb3 is top!"); + var answers = List.of("Hello world!", "I am a teapot", "I love pizza\nMamma mia\nPeperoni\nPapa carlo\nZaebumba\nPidoraso ebanino", "msb3 is top!"); for (int i = 0; i < 4; i++) { if (true) { //TODO: checking answer exists builder.append(i % 2 == 0 @@ -305,25 +305,23 @@ public class DialogueRenderer { var lines = breakIntoLines( answers.get(i), i < 2 - ? new TextureProperties(positions.answerText().fontHeight(), - positions.answerText().topFirstLineAscent()) - : new TextureProperties( - positions.answerText().fontHeight(), - positions.answerText().bottomFirstLineAscent()), + ? new TextureProperties(positions.answerText().fontHeight(), positions.answerText().topFirstLineAscent()) + : new TextureProperties(positions.answerText().fontHeight(), positions.answerText().bottomFirstLineAscent()), positions.answerText().fontHeight(), positions.answerText().lineWidth()); - for (int lineIdx = 0; - lineIdx < Math.min(lines.size(), positions.answerText().maxLines()); - lineIdx++) { - + for (int lineIdx = 0; lineIdx < Math.min(lines.size(), positions.answerText().maxLines()); lineIdx++) { boolean endWithDots = lineIdx + 1 == positions.answerText().maxLines() && lineIdx + 1 != lines.size(); var line = lines.get(lineIdx); - builder.append(i % 2 == 0 - ? positions.answerText().leftLineX() - : positions.answerText().rightLineX(), line.toGlyphList(0, endWithDots, positions.answerText().textColor())); + + builder.append( + i % 2 == 0 + ? positions.answerText().leftLineX() + : positions.answerText().rightLineX(), + line.toGlyphList(line.textureProperties(), 0, endWithDots, positions.answerText().textColor()) + ); } } else { builder.append(i % 2 == 0 @@ -360,7 +358,8 @@ public class DialogueRenderer { for (int lineIdx = 0; lineIdx < lines.length; lineIdx++) { var text = lines[lineIdx]; - textLines.add(new TextLine(text, new TextureProperties(firstLineProperties.height(), firstLineProperties.ascent() - lineIdx * (fontHeight + 1)))); + var properties = new TextureProperties(firstLineProperties.height(), firstLineProperties.ascent() - lineIdx * (fontHeight + 1)); + textLines.add(new TextLine(text, properties)); } return textLines; } @@ -377,7 +376,8 @@ public class DialogueRenderer { for (int lineIdx = shift; (lineIdx - shift) < Math.min(textLines.size() - shift, positions.phraseText().maxLines()); lineIdx++) { var line = textLines.get(lineIdx); builder.append(positions.phraseText().lineX(), line.toGlyphList( - -lineIdx + shift, + line.textureProperties(), + shift, textLines.size() - lineIdx > 0 && lineIdx - shift == positions.phraseText().maxLines() - 1, positions.phraseText().textColor() )); @@ -418,12 +418,12 @@ public class DialogueRenderer { private record TextLine(Component text, TextureProperties textureProperties) { - public List<@NotNull AppendableGlyph> toGlyphList(int lineShift, boolean cutEnding, TextColor color) { + public List<@NotNull AppendableGlyph> toGlyphList(TextureProperties parentProperties, int lineShift, boolean cutEnding, TextColor color) { var positions = DialogGlyphPositions.DEFAULT; var properties = new TextureProperties( - positions.phraseText().firstLineProperties().height(), - positions.phraseText().firstLineProperties().ascent() + lineShift * (textureProperties().height() + 1) + parentProperties.height(), + parentProperties.ascent() + lineShift * (textureProperties().height() + 1) ); Component text = this.text;