Finally finished VN textbox

This commit is contained in:
2023-06-17 07:59:22 -07:00
parent 4cbff34034
commit f766f675ce
5 changed files with 120 additions and 86 deletions

View File

@ -10,95 +10,83 @@ using namespace Dawn;
VNTextboxScroller::VNTextboxScroller(SceneItem *item) :
SceneItemComponent(item),
label(nullptr)
label(nullptr),
visibleLines(4)
{
}
void VNTextboxScroller::onStart() {
// assertNotNull(label);
assertNotNull(label);
// std::function<void()> x = [&]{
// this->lineCurrent = 0;
// this->timeCharacter = 0;
// this->label->startQuad = 0;
// this->label->quadCount = 0;
// this->readyToClose = false;
// };
// x();
std::function<void()> x = [&]{
this->lineCurrent = 0;
this->timeCharacter = 0;
this->label->quadStart = 0;
this->label->quadCount = 0;
this->readyToClose = false;
};
// useEvent(x, this->label->eventTextChanged);
useEvent(x, this->label->eventTextChanged);
useEffect(x, visibleLines)();
// useEvent([&](float_t delta){
// auto game = this->getGame();
useEvent([&](float_t delta){
auto game = this->getGame();
// this->timeCharacter += delta;
// if(this->hasRevealedAllCurrentCharacters()) {
// if(this->hasRevealedAllCharacters()) {
// if(!this->readyToClose) {
// this->readyToClose = true;
// this->eventReadyToClose.invoke();
// }
// } else {
// if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
// this->lineCurrent += this->getCountOfVisibleLines();
// 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;
// }
// }
// return;
// }
this->timeCharacter += delta;
if(this->hasRevealedAllCurrentCharacters()) {
if(this->hasRevealedAllCharacters()) {
if(!this->readyToClose) {
this->readyToClose = true;
this->eventReadyToClose.invoke();
}
} else {
if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
this->lineCurrent += this->visibleLines;
this->label->quadStart = this->label->lines[this->lineCurrent].quadStart;
this->label->quadCount = 0;
this->timeCharacter = 0.0f;
// auto lastTimeCharacter = mathFloor<int32_t>(this->timeCharacter);
// if(game->inputManager.isDown(INPUT_BIND_ACCEPT)) {
// this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED_FASTER;
// } else {
// this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED;
// }
this->label->textOffset = (
-this->label->lines[this->lineCurrent].position
);
}
}
return;
}
// auto newCount = mathFloor<int32_t>(this->timeCharacter);
// if(newCount == this->label->quadCount) return;
// this->label->quadCount = mathFloor<int32_t>(this->timeCharacter);
// this->eventCharacterRevealed.invoke();
// }, getScene()->eventSceneUpdate);
assertUnreachable();
}
auto lastTimeCharacter = mathFloor<int32_t>(this->timeCharacter);
if(game->inputManager.isDown(INPUT_BIND_ACCEPT)) {
this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED_FASTER;
} else {
this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED;
}
size_t VNTextboxScroller::getCountOfVisibleLines() {
// float_t y = this->label->getHeight();
// size_t i = 1;
// for(i = this->label->measure.getLineCount(); i > 0; --i) {
// if(y >= this->label->measure.getHeightOfLineCount(i)) {
// return i;
// }
// }
// return this->label->measure.getLineCount();
assertUnreachable();
auto newCount = mathFloor<int32_t>(this->timeCharacter);
if(newCount == this->label->quadCount) return;
this->label->quadCount = mathFloor<int32_t>(this->timeCharacter);
this->eventCharacterRevealed.invoke();
}, getScene()->eventSceneUpdate);
}
bool_t VNTextboxScroller::hasRevealedAllCurrentCharacters() {
// int32_t quadsTotal = 0;
// for(
// size_t i = this->lineCurrent;
// i < mathMin<size_t>(
// this->label->measure.getLineCount(),
// this->lineCurrent + this->getCountOfVisibleLines()
// );
// i++
// ) {
// quadsTotal += this->label->measure.getQuadsOnLine(i);
// }
// return mathFloor<int32_t>(this->timeCharacter) >= quadsTotal;
assertUnreachable();
int32_t quadsTotal = 0;
for(
size_t i = this->lineCurrent;
i < mathMin<size_t>(
this->label->lines.size(),
this->lineCurrent + this->visibleLines
);
i++
) {
quadsTotal += this->label->lines[i].quadCount;
}
return mathFloor<int32_t>(this->timeCharacter) >= quadsTotal;
}
bool_t VNTextboxScroller::hasRevealedAllCharacters() {
// return (
// this->lineCurrent + this->getCountOfVisibleLines() >=
// this->label->measure.getLineCount()
// );
return (
this->lineCurrent + this->visibleLines >=
this->label->lines.size()
);
assertUnreachable();
}

View File

@ -17,6 +17,9 @@ namespace Dawn {
// @optional
StateProperty<UILabel*> label;
// @optional
StateProperty<int32_t> visibleLines;
StateEvent<> eventReadyToClose;
StateEvent<> eventCharacterRevealed;
@ -28,14 +31,6 @@ namespace Dawn {
VNTextboxScroller(SceneItem *item);
virtual void onStart() override;
/**
* Returns the count of visible lines within the textbox. Mostly used for
* when we need to decide how to wrap.
*
* @return The count of visible lines.
*/
size_t getCountOfVisibleLines();
/**
* Returns true if all of the characters that can be made visible for the
* current textbox size have finished revealing, or false if not.