Working on time and input
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VisualNovelTextbox.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -12,10 +13,58 @@ VisualNovelTextbox::VisualNovelTextbox(UICanvas &canvas) :
|
||||
border(canvas),
|
||||
label(canvas)
|
||||
{
|
||||
// Border
|
||||
this->addChild(&this->border);
|
||||
|
||||
// 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->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->border.setTransform(
|
||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
|
||||
glm::vec4(0, 0, 0, 0),
|
||||
0.0f
|
||||
);
|
||||
|
||||
this->label.setTransform(
|
||||
UI_COMPONENT_ALIGN_STRETCH,
|
||||
UI_COMPONENT_ALIGN_STRETCH,
|
||||
glm::vec4(
|
||||
this->border.getBorderSize() + this->labelPadding,
|
||||
this->border.getBorderSize() + this->labelPadding
|
||||
),
|
||||
1.0f
|
||||
);
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::drawSelf(UIShader &shader, glm::mat4 self) {
|
||||
|
||||
}
|
||||
|
||||
VisualNovelTextbox::~VisualNovelTextbox() {
|
||||
this->canvas.getScene().eventSceneUnpausedUpdate.removeListener(
|
||||
this, &VisualNovelTextbox::textboxOnSceneUpdate
|
||||
);
|
||||
}
|
@ -7,16 +7,28 @@
|
||||
#include "ui/UISprite.hpp"
|
||||
#include "ui/UIBorder.hpp"
|
||||
#include "ui/UILabel.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
|
||||
#define VISUAL_NOVEL_TEXTBOX_SPEED 25.0f
|
||||
#define VISUAL_NOVEL_TEXTBOX_SPEED_FASTER 40.0f
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelTextbox : public UIComponent {
|
||||
private:
|
||||
UIBorder border;
|
||||
UILabel label;
|
||||
glm::vec2 labelPadding = glm::vec2(0, 0);
|
||||
|
||||
void updatePositions() override;
|
||||
|
||||
void textboxOnSceneUpdate();
|
||||
|
||||
public:
|
||||
float_t timeCharacter = 0.0f;
|
||||
UIBorder border;
|
||||
UILabel label;
|
||||
|
||||
VisualNovelTextbox(UICanvas &canvas);
|
||||
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
|
||||
|
||||
~VisualNovelTextbox();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user