feat: implemented DialogueRenderer

This commit is contained in:
Andrey Terentev 2024-12-02 18:07:23 +07:00
parent 190194450f
commit 6ed96d082e

View File

@ -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
builder.append(
i % 2 == 0
? positions.answerText().leftLineX()
: positions.answerText().rightLineX(), line.toGlyphList(0, endWithDots, positions.answerText().textColor()));
: 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;