VN Textbox updated

This commit is contained in:
2022-11-02 00:42:16 -07:00
parent f5e8dd9a8e
commit db90bd1476
8 changed files with 147 additions and 42 deletions

View File

@ -18,32 +18,24 @@ VisualNovelTextbox::VisualNovelTextbox(UICanvas &canvas) :
// Label
this->addChild(&this->label);
this->label.setText("The quick brown fox jumps over the lazy dog.");
this->label.startQuad = 0;
this->label.endQuad = 1;
this->updatePositions();
this->label.quadCount = 0;
this->updateSelfTransform();
this->canvas.getScene().eventSceneUnpausedUpdate.addListener(
this, &VisualNovelTextbox::textboxOnSceneUpdate
);
}
void VisualNovelTextbox::textboxOnSceneUpdate() {
DawnGame &game = this->canvas.getGame();
if(game.inputManager.isDown(INPUT_BIND_ACCEPT)) {
this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED_FASTER;
} else {
this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED;
}
this->label.endQuad = (int32_t)mathFloorFloat(this->timeCharacter);
}
void VisualNovelTextbox::updatePositions() {
UIComponent::updatePositions();
this->lineCurrent = 0;
this->timeCharacter = 0;
this->border.setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
glm::vec4(0, 0, 0, 0),
0.0f
);
@ -57,10 +49,108 @@ void VisualNovelTextbox::updatePositions() {
),
1.0f
);
this->label.startQuad = 0;
this->label.quadCount = 0;
}
void VisualNovelTextbox::drawSelf(UIShader &shader, glm::mat4 self) {
void VisualNovelTextbox::textboxOnSceneUpdate() {
DawnGame &game = this->canvas.getGame();
if(this->hasRevealedAllCurrentCharacters()) {
if(this->hasRevealedAllCharacters()) {
if(game.inputManager.isPressed(INPUT_BIND_ACCEPT)) {
std::cout << "Bruh" << std::endl;
}
} else {
if(game.inputManager.isPressed(INPUT_BIND_ACCEPT)) {
this->lineCurrent += VISUAL_NOVEL_TEXTBOX_LINES_MAX;
this->label.startQuad = 0;
for(int32_t i = 0; i < this->lineCurrent; i++) {
this->label.startQuad += this->label.measure.getQuadsOnLine(i);
}
this->label.quadCount = 0;
this->timeCharacter = 0.0f;
this->label.setTransform(
UI_COMPONENT_ALIGN_STRETCH,
UI_COMPONENT_ALIGN_STRETCH,
glm::vec4(
glm::vec2(
this->border.getBorderSize().x + this->labelPadding.x,
this->border.getBorderSize().y + this->labelPadding.y -
this->label.measure.getHeightOfLineCount(this->lineCurrent)
),
this->border.getBorderSize() + this->labelPadding
),
1.0f
);
}
}
return;
}
if(game.inputManager.isDown(INPUT_BIND_ACCEPT)) {
this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED_FASTER;
} else {
this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED;
}
this->label.quadCount = (int32_t)mathFloorFloat(this->timeCharacter);
}
void VisualNovelTextbox::updateSelfTransform() {
float_t height;
height = this->label.measure.getHeightOfLineCount(VISUAL_NOVEL_TEXTBOX_LINES_MAX);
this->setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_START,
glm::vec4(0, 0, 0, height + (this->border.getBorderSize().y * 2)),
0
);
}
void VisualNovelTextbox::drawSelf(UIShader &shader, glm::mat4 self) {}
void VisualNovelTextbox::setBorder(Texture *texture, glm::vec2 dimensions) {
this->border.texture = texture;
this->border.setBorderSize(dimensions);
this->updatePositions();
}
void VisualNovelTextbox::setFont(Font *font) {
this->label.setFont(font);
this->label.updateMesh();
this->updateSelfTransform();
}
void VisualNovelTextbox::setText(std::string text, float_t fontSize) {
this->label.setText(text);
this->label.setFontSize(fontSize);
this->label.updateMesh();
this->updateSelfTransform();
}
bool_t VisualNovelTextbox::hasRevealedAllCurrentCharacters() {
int32_t quadsTotal = 0;
for(
int32_t i = this->lineCurrent;
i < mathMin<int32_t>(
this->label.measure.getLineCount(),
this->lineCurrent + VISUAL_NOVEL_TEXTBOX_LINES_MAX
);
i++
) {
quadsTotal += this->label.measure.getQuadsOnLine(i);
}
return mathFloorFloat(this->timeCharacter) >= quadsTotal;
}
bool_t VisualNovelTextbox::hasRevealedAllCharacters() {
return (
this->lineCurrent + VISUAL_NOVEL_TEXTBOX_LINES_MAX >=
this->label.measure.getLineCount()
);
}
VisualNovelTextbox::~VisualNovelTextbox() {

View File

@ -11,24 +11,33 @@
#define VISUAL_NOVEL_TEXTBOX_SPEED 25.0f
#define VISUAL_NOVEL_TEXTBOX_SPEED_FASTER 40.0f
#define VISUAL_NOVEL_TEXTBOX_LINES_MAX 4
namespace Dawn {
class VisualNovelTextbox : public UIComponent {
private:
int32_t lineCurrent = 0;
glm::vec2 labelPadding = glm::vec2(0, 0);
void updatePositions() override;
void textboxOnSceneUpdate();
public:
float_t timeCharacter = 0.0f;
UIBorder border;
UILabel label;
float_t timeCharacter = 0.0f;
void updatePositions() override;
void textboxOnSceneUpdate();
void updateSelfTransform();
public:
VisualNovelTextbox(UICanvas &canvas);
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
void setFont(Font *font);
void setBorder(Texture *texture, glm::vec2 dimensions);
void setText(std::string text, float_t fontSize);
bool_t hasRevealedAllCurrentCharacters();
bool_t hasRevealedAllCharacters();
~VisualNovelTextbox();
};
}