feat: implemented DialogueRenderer
This commit is contained in:
parent
190194450f
commit
6ed96d082e
@ -277,7 +277,7 @@ public class DialogueRenderer {
|
|||||||
|
|
||||||
// Answers
|
// 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++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (true) { //TODO: checking answer exists
|
if (true) { //TODO: checking answer exists
|
||||||
builder.append(i % 2 == 0
|
builder.append(i % 2 == 0
|
||||||
@ -305,25 +305,23 @@ public class DialogueRenderer {
|
|||||||
var lines = breakIntoLines(
|
var lines = breakIntoLines(
|
||||||
answers.get(i),
|
answers.get(i),
|
||||||
i < 2
|
i < 2
|
||||||
? new TextureProperties(positions.answerText().fontHeight(),
|
? new TextureProperties(positions.answerText().fontHeight(), positions.answerText().topFirstLineAscent())
|
||||||
positions.answerText().topFirstLineAscent())
|
: new TextureProperties(positions.answerText().fontHeight(), positions.answerText().bottomFirstLineAscent()),
|
||||||
: new TextureProperties(
|
|
||||||
positions.answerText().fontHeight(),
|
|
||||||
positions.answerText().bottomFirstLineAscent()),
|
|
||||||
positions.answerText().fontHeight(),
|
positions.answerText().fontHeight(),
|
||||||
positions.answerText().lineWidth());
|
positions.answerText().lineWidth());
|
||||||
|
|
||||||
for (int lineIdx = 0;
|
for (int lineIdx = 0; lineIdx < Math.min(lines.size(), positions.answerText().maxLines()); lineIdx++) {
|
||||||
lineIdx < Math.min(lines.size(), positions.answerText().maxLines());
|
|
||||||
lineIdx++) {
|
|
||||||
|
|
||||||
boolean endWithDots = lineIdx + 1 == positions.answerText().maxLines()
|
boolean endWithDots = lineIdx + 1 == positions.answerText().maxLines()
|
||||||
&& lineIdx + 1 != lines.size();
|
&& lineIdx + 1 != lines.size();
|
||||||
|
|
||||||
var line = lines.get(lineIdx);
|
var line = lines.get(lineIdx);
|
||||||
builder.append(i % 2 == 0
|
|
||||||
|
builder.append(
|
||||||
|
i % 2 == 0
|
||||||
? positions.answerText().leftLineX()
|
? 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 {
|
} else {
|
||||||
builder.append(i % 2 == 0
|
builder.append(i % 2 == 0
|
||||||
@ -360,7 +358,8 @@ public class DialogueRenderer {
|
|||||||
for (int lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
for (int lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
||||||
var text = lines[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;
|
return textLines;
|
||||||
}
|
}
|
||||||
@ -377,7 +376,8 @@ public class DialogueRenderer {
|
|||||||
for (int lineIdx = shift; (lineIdx - shift) < Math.min(textLines.size() - shift, positions.phraseText().maxLines()); lineIdx++) {
|
for (int lineIdx = shift; (lineIdx - shift) < Math.min(textLines.size() - shift, positions.phraseText().maxLines()); lineIdx++) {
|
||||||
var line = textLines.get(lineIdx);
|
var line = textLines.get(lineIdx);
|
||||||
builder.append(positions.phraseText().lineX(), line.toGlyphList(
|
builder.append(positions.phraseText().lineX(), line.toGlyphList(
|
||||||
-lineIdx + shift,
|
line.textureProperties(),
|
||||||
|
shift,
|
||||||
textLines.size() - lineIdx > 0 && lineIdx - shift == positions.phraseText().maxLines() - 1,
|
textLines.size() - lineIdx > 0 && lineIdx - shift == positions.phraseText().maxLines() - 1,
|
||||||
positions.phraseText().textColor()
|
positions.phraseText().textColor()
|
||||||
));
|
));
|
||||||
@ -418,12 +418,12 @@ public class DialogueRenderer {
|
|||||||
|
|
||||||
private record TextLine(Component text, TextureProperties textureProperties) {
|
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 positions = DialogGlyphPositions.DEFAULT;
|
||||||
|
|
||||||
var properties = new TextureProperties(
|
var properties = new TextureProperties(
|
||||||
positions.phraseText().firstLineProperties().height(),
|
parentProperties.height(),
|
||||||
positions.phraseText().firstLineProperties().ascent() + lineShift * (textureProperties().height() + 1)
|
parentProperties.ascent() + lineShift * (textureProperties().height() + 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
Component text = this.text;
|
Component text = this.text;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user