VN Textbox Scroll initial version

This commit is contained in:
2023-05-20 22:13:22 -07:00
parent 8df72dace1
commit c69352cf9c
17 changed files with 351 additions and 73 deletions

View File

@ -7,4 +7,5 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
VNManager.cpp
VNTextboxScroller.cpp
)

View File

@ -0,0 +1,110 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "VNTextboxScroller.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
VNTextboxScroller::VNTextboxScroller(SceneItem *item) :
SceneItemComponent(item),
label(nullptr)
{
}
void VNTextboxScroller::onStart() {
assertNotNull(label);
std::function<void()> x = [&]{
this->lineCurrent = 0;
this->timeCharacter = 0;
this->label->startQuad = 0;
this->label->quadCount = 0;
};
x();
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;
}
} 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;
// 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();
}
}
return;
}
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->quadCount = mathFloor<int32_t>(this->timeCharacter);
// this->eventCharacterRevealed.invoke();
}, getScene()->eventSceneUpdate);
}
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();
}
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;
}
bool_t VNTextboxScroller::hasRevealedAllCharacters() {
return (
this->lineCurrent + this->getCountOfVisibleLines() >=
this->label->measure.getLineCount()
);
}

View File

@ -0,0 +1,53 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "scene/components/ui/UILabel.hpp"
#include "input/InputManager.hpp"
#define VN_TEXTBOX_SPEED 25.0f
#define VN_TEXTBOX_SPEED_FASTER 40.0f
namespace Dawn {
class VNTextboxScroller : public SceneItemComponent {
protected:
public:
// @optional
StateProperty<UILabel*> label;
size_t lineCurrent = 0;
float_t timeCharacter = 0.0f;
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.
*
* @return True if above statement is met.
*/
bool_t hasRevealedAllCurrentCharacters();
/**
* Returns true only when every character passed previously in setText
* has been revealed by scrolling.
*
* @return True if above statement is true.
*/
bool_t hasRevealedAllCharacters();
};
}

View File

@ -14,13 +14,6 @@ namespace Dawn {
protected:
void onStart() override {
std::cout << "TEXT: " << text << std::endl;
useEvent([&](float_t delta) {
if(getScene()->game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
std::cout << "Text Advance" << std::endl;
this->next();
}
}, getScene()->eventSceneUpdate);
}
};
}