VN textbox event

This commit is contained in:
2023-05-21 15:11:51 -07:00
parent a64df032e2
commit a6ecdfd84d
11 changed files with 42 additions and 35 deletions

View File

@ -22,17 +22,21 @@ void VNTextboxScroller::onStart() {
this->timeCharacter = 0;
this->label->startQuad = 0;
this->label->quadCount = 0;
this->readyToClose = false;
};
x();
useEvent(x, this->label->eventTextChanged);
useEvent([&](float_t delta){
auto game = this->getGame();
this->timeCharacter += delta;
if(this->hasRevealedAllCurrentCharacters()) {
if(this->hasRevealedAllCharacters()) {
if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
std::cout << "HIDE" << std::endl;
if(!this->readyToClose) {
this->readyToClose = true;
this->eventReadyToClose.invoke();
}
} else {
if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
@ -43,21 +47,6 @@ void VNTextboxScroller::onStart() {
}
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
// ),
// 5.0f
// );
// this->eventNewPage.invoke();
}
}
@ -71,8 +60,10 @@ void VNTextboxScroller::onStart() {
this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED;
}
auto newCount = mathFloor<int32_t>(this->timeCharacter);
if(newCount == this->label->quadCount) return;
this->label->quadCount = mathFloor<int32_t>(this->timeCharacter);
// this->eventCharacterRevealed.invoke();
this->eventCharacterRevealed.invoke();
}, getScene()->eventSceneUpdate);
}

View File

@ -13,17 +13,19 @@
namespace Dawn {
class VNTextboxScroller : public SceneItemComponent {
protected:
public:
// @optional
StateProperty<UILabel*> label;
StateEvent<> eventReadyToClose;
StateEvent<> eventCharacterRevealed;
bool_t readyToClose = false;
size_t lineCurrent = 0;
float_t timeCharacter = 0.0f;
VNTextboxScroller(SceneItem *item);
virtual void onStart() override;
/**

View File

@ -5,6 +5,8 @@
#pragma once
#include "VNEvent.hpp"
#include "scene/Scene.hpp"
#include "games/vn/components/VNTextboxScroller.hpp"
namespace Dawn {
class VNTextEvent : public VNEvent {
@ -12,8 +14,19 @@ namespace Dawn {
std::string text;
protected:
VNTextboxScroller *scroller = nullptr;
void onStart() override {
std::cout << "TEXT: " << text << std::endl;
scroller = this->getScene()->findComponent<VNTextboxScroller>();
assertNotNull(scroller);
scroller->label->text = text;
useEvent([&](inputbind_t bind){
if(bind != INPUT_BIND_ACCEPT) return;
if(!scroller->readyToClose) return;
this->next();
}, this->getScene()->game->inputManager.eventBindPressed);
}
};
}

View File

@ -12,7 +12,7 @@
namespace Dawn {
class SceneItemComponent;
class SceneItem {
class SceneItem : public StateOwner {
private:
std::vector<SceneItemComponent*> components;

View File

@ -111,6 +111,10 @@ void UILabel::onStart() {
alignmentNeedsUpdating = true;
}, { &fontSize, &font, &text, &maxWidth, &startQuad, &quadCount });
useEffect([&]{
eventTextChanged.invoke();
}, text);
useEffect([&]{
needsRebuffering = true;
}, alignmentNeedsUpdating);

View File

@ -45,6 +45,7 @@ namespace Dawn {
StateProperty<int32_t> quadCount;
StateEvent<> eventFontRebuffered;
StateEvent<> eventTextChanged;
struct FontMeasure measure;