VN System improved.
This commit is contained in:
@ -37,6 +37,17 @@ namespace Dawn {
|
||||
struct FontMeasure *info
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Fonts need to be initialized before they can actually be used, but I
|
||||
* really want to keep things kind-of non-blocking, so for the time being
|
||||
* this hack works around it, fonts can decide to return false if they are
|
||||
* not "ready for buffering", and the item intending to use the font is
|
||||
* required to decide when it should actually request buffering.
|
||||
*
|
||||
* @return True if ready for buffering, otherwise false.
|
||||
*/
|
||||
virtual bool_t isReady() = 0;
|
||||
|
||||
/**
|
||||
* Returns the texture that is used for a given font.
|
||||
*
|
||||
|
@ -40,12 +40,56 @@ namespace Dawn {
|
||||
*/
|
||||
void addLine(int32_t start, int32_t length);
|
||||
|
||||
/**
|
||||
* Returns the width of this measured string.
|
||||
*
|
||||
* @return Width of the pre measured string.
|
||||
*/
|
||||
float_t getWidth();
|
||||
|
||||
/**
|
||||
* Returns the height of the measured string.
|
||||
*
|
||||
* @return Height of the pre measured string.
|
||||
*/
|
||||
float_t getHeight();
|
||||
|
||||
/**
|
||||
* Returns the count of quads on the given line.
|
||||
*
|
||||
* @param line Which line to get the count of quads for.
|
||||
* @return Count of quads on that line.
|
||||
*/
|
||||
int32_t getQuadsOnLine(int32_t line);
|
||||
|
||||
/**
|
||||
* Returns the index, of which quad is the first quad on the given line.
|
||||
*
|
||||
* @param line Line to get the quad index of.
|
||||
* @return The quad index of that line.
|
||||
*/
|
||||
int32_t getQuadIndexOnLine(int32_t line);
|
||||
|
||||
/**
|
||||
* Returns the height of the count of lines provided.
|
||||
*
|
||||
* @param lineCount Count of lines to get the height of.
|
||||
* @return Height of the given count of lines.
|
||||
*/
|
||||
float_t getHeightOfLineCount(int32_t lineCount);
|
||||
|
||||
/**
|
||||
* Returns the count of lines in this string.
|
||||
*
|
||||
* @return Count of lines.
|
||||
*/
|
||||
size_t getLineCount();
|
||||
|
||||
/**
|
||||
* Returns the count of quads in this string.
|
||||
*
|
||||
* @return Total count of quads.
|
||||
*/
|
||||
int32_t getQuadCount();
|
||||
};
|
||||
}
|
@ -56,6 +56,7 @@ void TrueTypeFont::buffer(
|
||||
assertNotNull(info);
|
||||
assertTrue(fontSize > 0);
|
||||
assertTrue(maxWidth == -1 || maxWidth > 0);
|
||||
assertTrue(this->isReady());
|
||||
|
||||
auto stringLength = text.length();
|
||||
if(stringLength == 0) {
|
||||
@ -189,6 +190,10 @@ void TrueTypeFont::buffer(
|
||||
delete quads;
|
||||
}
|
||||
|
||||
bool_t TrueTypeFont::isReady() {
|
||||
return this->texture.isReady();
|
||||
}
|
||||
|
||||
Texture * TrueTypeFont::getTexture() {
|
||||
return &this->texture;
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ namespace Dawn {
|
||||
Mesh *mesh,
|
||||
struct FontMeasure *info
|
||||
) override;
|
||||
bool_t isReady() override;
|
||||
Texture * getTexture() override;
|
||||
void draw(Mesh *mesh, int32_t startCharacter, int32_t length) override;
|
||||
float_t getLineHeight(float_t fontSize) override;
|
||||
|
@ -51,12 +51,18 @@ namespace Dawn {
|
||||
*/
|
||||
template<class T>
|
||||
T * findComponent() {
|
||||
auto it = this->items.begin();
|
||||
while(it != this->items.end()) {
|
||||
auto it = this->itemsNotInitialized.begin();
|
||||
while(it != this->itemsNotInitialized.end()) {
|
||||
auto component = it->second->getComponent<T>();
|
||||
if(component != nullptr) return component;
|
||||
++it;
|
||||
}
|
||||
auto it2 = this->items.begin();
|
||||
while(it2 != this->items.end()) {
|
||||
auto component = it2->second->getComponent<T>();
|
||||
if(component != nullptr) return component;
|
||||
++it2;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -70,12 +76,20 @@ namespace Dawn {
|
||||
template<class T>
|
||||
std::vector<T*> findComponents() {
|
||||
std::vector<T*> components;
|
||||
auto it = this->items.begin();
|
||||
while(it != this->items.end()) {
|
||||
|
||||
auto it = this->itemsNotInitialized.begin();
|
||||
while(it != this->itemsNotInitialized.end()) {
|
||||
auto component = it->second->getComponent<T>();
|
||||
if(component != nullptr) components.push_back(component);
|
||||
++it;
|
||||
}
|
||||
|
||||
auto it2 = this->items.begin();
|
||||
while(it2 != this->items.end()) {
|
||||
auto component = it2->second->getComponent<T>();
|
||||
if(component != nullptr) components.push_back(component);
|
||||
++it2;
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/components/display/Camera.hpp"
|
||||
#include "scene/components/display/MeshRenderer.hpp"
|
||||
#include "scene/components/display/Material.hpp"
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/components/display/Camera.hpp"
|
||||
#include "scene/components/display/MeshRenderer.hpp"
|
||||
#include "scene/components/display/Material.hpp"
|
||||
|
||||
#include "scene/components/ui/UICanvas.hpp"
|
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum CameraType {
|
||||
@ -20,6 +21,12 @@ namespace Dawn {
|
||||
void onRenderTargetResize(RenderTarget *target, float_t w, float_t h);
|
||||
|
||||
public:
|
||||
static Camera * create(Scene *scene) {
|
||||
auto item = scene->createSceneItem();
|
||||
auto cam = item->addComponent<Camera>();
|
||||
return cam;
|
||||
}
|
||||
|
||||
glm::mat4 projection;
|
||||
|
||||
// Perspective
|
||||
|
@ -57,6 +57,17 @@ namespace Dawn {
|
||||
this->children.push_back(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T * findElement() {
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
auto castedAs = dynamic_cast<T*>(*it);
|
||||
if(castedAs != nullptr) return castedAs;
|
||||
++it;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the root UI Canvas size. In future I may allow
|
||||
|
@ -1,13 +1,14 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UIBorder.cpp
|
||||
UIComponent.cpp
|
||||
UILabel.cpp
|
||||
UISprite.cpp
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UIBorder.cpp
|
||||
UIComponent.cpp
|
||||
UILabel.cpp
|
||||
UISprite.cpp
|
||||
UIEmpty.cpp
|
||||
)
|
@ -139,10 +139,11 @@ void UIComponent::addChild(UIComponent *child) {
|
||||
if(child->parent != nullptr) child->parent->removeChild(child);
|
||||
this->children.push_back(child);
|
||||
child->parent = this;
|
||||
this->updatePositions();
|
||||
}
|
||||
|
||||
void UIComponent::removeChild(UIComponent *child) {
|
||||
assertTrue(child->parent != this);
|
||||
assertTrue(child->parent == this);
|
||||
auto it = this->children.begin();
|
||||
while(it != this->children.end()) {
|
||||
if(*it == child) {
|
||||
@ -151,6 +152,7 @@ void UIComponent::removeChild(UIComponent *child) {
|
||||
}
|
||||
++it;
|
||||
}
|
||||
child->parent = nullptr;
|
||||
}
|
||||
|
||||
UIComponent::~UIComponent() {
|
||||
|
16
src/dawn/ui/UIEmpty.cpp
Normal file
16
src/dawn/ui/UIEmpty.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIEmpty.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
UIEmpty::UIEmpty(UICanvas *canvas) : UIComponent(canvas) {
|
||||
|
||||
}
|
||||
|
||||
void UIEmpty::drawSelf(UIShader *shader, glm::mat4 selfTrans) {
|
||||
|
||||
}
|
15
src/dawn/ui/UIEmpty.hpp
Normal file
15
src/dawn/ui/UIEmpty.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "UIComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIEmpty : public UIComponent {
|
||||
public:
|
||||
UIEmpty(UICanvas *canvas);
|
||||
void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) override;
|
||||
};
|
||||
}
|
@ -18,7 +18,7 @@ void UILabel::updatePositions() {
|
||||
|
||||
void UILabel::updateMesh() {
|
||||
if(!this->needsRebuffering) return;
|
||||
if(this->font == nullptr) return;
|
||||
if(this->font == nullptr || !this->font->isReady()) return;
|
||||
if(this->text.size() == 0) return;
|
||||
|
||||
float_t width = this->getWidth();
|
||||
|
@ -10,4 +10,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(events)
|
||||
add_subdirectory(ui)
|
@ -7,6 +7,72 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
VisualNovelManager::VisualNovelManager() {
|
||||
VisualNovelManager::VisualNovelManager(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
this->uiCanvas = nullptr;
|
||||
this->textBox = nullptr;
|
||||
}
|
||||
|
||||
void VisualNovelManager::onStart() {
|
||||
SceneItemComponent::onStart();
|
||||
|
||||
this->uiCanvas = getScene()->findComponent<UICanvas>();
|
||||
assertNotNull(this->uiCanvas);
|
||||
|
||||
this->textBox = this->uiCanvas->findElement<VisualNovelTextbox>();
|
||||
assertNotNull(this->textBox);
|
||||
|
||||
this->getScene()->eventSceneUnpausedUpdate.addListener(this, &VisualNovelManager::onUnpausedUpdate);
|
||||
}
|
||||
|
||||
void VisualNovelManager::onUnpausedUpdate() {
|
||||
if(this->currentEvent == nullptr) return;
|
||||
|
||||
if(!this->currentEvent->hasStarted) {
|
||||
this->currentEvent->start();
|
||||
}
|
||||
|
||||
if(this->currentEvent->update()) return;
|
||||
auto oldCurrent = this->currentEvent;
|
||||
this->currentEvent = this->currentEvent->end();
|
||||
delete oldCurrent;
|
||||
}
|
||||
|
||||
VisualNovelManager::~VisualNovelManager() {
|
||||
if(this->currentEvent != nullptr) {
|
||||
delete this->currentEvent;
|
||||
}
|
||||
this->getScene()->eventSceneUnpausedUpdate.removeListener(this, &VisualNovelManager::onUnpausedUpdate);
|
||||
}
|
||||
|
||||
// Visual Novel Event
|
||||
IVisualNovelEvent::IVisualNovelEvent(VisualNovelManager *man) {
|
||||
assertNotNull(man);
|
||||
this->manager = man;
|
||||
}
|
||||
|
||||
void IVisualNovelEvent::start() {
|
||||
this->onStart();
|
||||
this->hasStarted = true;
|
||||
}
|
||||
|
||||
bool_t IVisualNovelEvent::update() {
|
||||
return this->onUpdate();
|
||||
}
|
||||
|
||||
IVisualNovelEvent * IVisualNovelEvent::end() {
|
||||
this->onEnd();
|
||||
|
||||
if(this->doNext != nullptr) {
|
||||
auto next = this->doNext;
|
||||
this->doNext = nullptr;
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
||||
IVisualNovelEvent::~IVisualNovelEvent() {
|
||||
if(this->doNext != nullptr) {
|
||||
delete this->doNext;
|
||||
}
|
||||
}
|
@ -4,13 +4,84 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "visualnovel/ui/VisualNovelTextbox.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelManager {
|
||||
protected:
|
||||
class IVisualNovelEvent;
|
||||
|
||||
class VisualNovelManager : public SceneItemComponent {
|
||||
private:
|
||||
UICanvas *uiCanvas;
|
||||
IVisualNovelEvent* currentEvent = nullptr;
|
||||
|
||||
/** Event listener for unpaused scene updates. */
|
||||
void onUnpausedUpdate();
|
||||
|
||||
public:
|
||||
VisualNovelManager();
|
||||
VisualNovelTextbox *textBox;
|
||||
/**
|
||||
* Constructs a visual novel manager, scene item component.
|
||||
*
|
||||
* @param item Item that the VN manager belongs to.
|
||||
*/
|
||||
VisualNovelManager(SceneItem *item);
|
||||
|
||||
/**
|
||||
* Sets the currently active visual novel event. This is assumed to be
|
||||
* the only way to handle events (no multiples currently).
|
||||
*
|
||||
* @param event Event to set.
|
||||
*/
|
||||
template <class T>
|
||||
T * setEvent(T *event) {
|
||||
assertNotNull(event);
|
||||
this->currentEvent = event;
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to the SceneItemComponent on start event.
|
||||
*
|
||||
*/
|
||||
void onStart() override;
|
||||
|
||||
/**
|
||||
* Dispose / Cleanup the VN manager.
|
||||
*
|
||||
*/
|
||||
~VisualNovelManager();
|
||||
|
||||
friend class IVisualNovelEvent;
|
||||
};
|
||||
|
||||
|
||||
class IVisualNovelEvent {
|
||||
protected:
|
||||
VisualNovelManager *manager;
|
||||
IVisualNovelEvent *doNext = nullptr;
|
||||
bool_t hasStarted;
|
||||
|
||||
virtual void onStart() = 0;
|
||||
virtual bool_t onUpdate() = 0;
|
||||
virtual void onEnd() = 0;
|
||||
|
||||
public:
|
||||
IVisualNovelEvent(VisualNovelManager *manager);
|
||||
|
||||
template<class T>
|
||||
T * then(T *next) {
|
||||
assertNotNull(next);
|
||||
this->doNext = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
void start();
|
||||
bool_t update();
|
||||
IVisualNovelEvent * end();
|
||||
|
||||
virtual ~IVisualNovelEvent();
|
||||
|
||||
friend class VisualNovelManager;
|
||||
};
|
||||
}
|
10
src/dawn/visualnovel/events/CMakeLists.txt
Normal file
10
src/dawn/visualnovel/events/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
VisualNovelTextboxEvent.cpp
|
||||
)
|
28
src/dawn/visualnovel/events/VisualNovelTextboxEvent.cpp
Normal file
28
src/dawn/visualnovel/events/VisualNovelTextboxEvent.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VisualNovelTextboxEvent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
VisualNovelTextboxEvent::VisualNovelTextboxEvent(
|
||||
VisualNovelManager *manager,
|
||||
std::string text
|
||||
) : IVisualNovelEvent(manager) {
|
||||
this->text = text;
|
||||
}
|
||||
|
||||
void VisualNovelTextboxEvent::onStart() {
|
||||
this->manager->textBox->setText(this->text);
|
||||
this->manager->textBox->show();
|
||||
}
|
||||
|
||||
bool_t VisualNovelTextboxEvent::onUpdate() {
|
||||
return this->manager->textBox->isVisible();
|
||||
}
|
||||
|
||||
void VisualNovelTextboxEvent::onEnd() {
|
||||
|
||||
}
|
24
src/dawn/visualnovel/events/VisualNovelTextboxEvent.hpp
Normal file
24
src/dawn/visualnovel/events/VisualNovelTextboxEvent.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "visualnovel/VisualNovelManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelTextboxEvent : public IVisualNovelEvent {
|
||||
protected:
|
||||
std::string text;
|
||||
|
||||
void onStart() override;
|
||||
bool_t onUpdate() override;
|
||||
void onEnd() override;
|
||||
|
||||
public:
|
||||
VisualNovelTextboxEvent(
|
||||
VisualNovelManager *manager,
|
||||
std::string text
|
||||
);
|
||||
};
|
||||
}
|
@ -10,14 +10,27 @@ using namespace Dawn;
|
||||
|
||||
VisualNovelTextbox::VisualNovelTextbox(UICanvas *canvas) :
|
||||
UIComponent(canvas),
|
||||
selfParent(canvas),
|
||||
border(canvas),
|
||||
label(canvas)
|
||||
{
|
||||
// Self Parent
|
||||
this->selfParent.setTransform(
|
||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
|
||||
glm::vec4(0, 0, 0, 0),
|
||||
0.0f
|
||||
);
|
||||
|
||||
// Border
|
||||
this->addChild(&this->border);
|
||||
this->selfParent.addChild(&this->border);
|
||||
this->border.setTransform(
|
||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
|
||||
glm::vec4(0, 0, 0, 0),
|
||||
0.0f
|
||||
);
|
||||
|
||||
// Label
|
||||
this->addChild(&this->label);
|
||||
this->selfParent.addChild(&this->label);
|
||||
this->label.startQuad = 0;
|
||||
this->label.quadCount = 0;
|
||||
|
||||
@ -26,18 +39,30 @@ VisualNovelTextbox::VisualNovelTextbox(UICanvas *canvas) :
|
||||
);
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::show() {
|
||||
if(this->isVisible()) return;
|
||||
this->visible = true;
|
||||
this->addChild(&this->selfParent);
|
||||
std::cout << "Showing" << std::endl;
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::hide() {
|
||||
if(!this->isVisible()) return;
|
||||
this->visible = false;
|
||||
this->removeChild(&this->selfParent);
|
||||
this->eventHidden.invoke();
|
||||
}
|
||||
|
||||
bool_t VisualNovelTextbox::isVisible() {
|
||||
return this->visible;
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::updatePositions() {
|
||||
UIComponent::updatePositions();
|
||||
|
||||
this->lineCurrent = 0;
|
||||
this->timeCharacter = 0;
|
||||
|
||||
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,
|
||||
@ -58,7 +83,7 @@ void VisualNovelTextbox::textboxOnSceneUpdate() {
|
||||
if(this->hasRevealedAllCurrentCharacters()) {
|
||||
if(this->hasRevealedAllCharacters()) {
|
||||
if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
|
||||
this->eventClose.invoke();
|
||||
this->hide();
|
||||
}
|
||||
} else {
|
||||
if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
|
||||
@ -114,7 +139,9 @@ int32_t VisualNovelTextbox::getCountOfVisibleLines() {
|
||||
return this->label.measure.getLineCount();
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::drawSelf(UIShader *shader, glm::mat4 self) {}
|
||||
void VisualNovelTextbox::drawSelf(UIShader *shader, glm::mat4 self) {
|
||||
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::setBorder(Texture *texture, glm::vec2 dimensions) {
|
||||
this->border.texture = texture;
|
||||
@ -133,6 +160,21 @@ void VisualNovelTextbox::setText(std::string text, float_t fontSize) {
|
||||
this->label.updateMesh();
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::setText(std::string text) {
|
||||
this->label.setText(text);
|
||||
this->label.updateMesh();
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::setFontSize(float_t fontSize) {
|
||||
this->label.setFontSize(fontSize);
|
||||
this->label.updateMesh();
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::setLabelPadding(glm::vec2 padding) {
|
||||
this->labelPadding = padding;
|
||||
this->updatePositions();
|
||||
}
|
||||
|
||||
bool_t VisualNovelTextbox::hasRevealedAllCurrentCharacters() {
|
||||
int32_t quadsTotal = 0;
|
||||
for(
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "ui/UISprite.hpp"
|
||||
#include "ui/UIBorder.hpp"
|
||||
#include "ui/UILabel.hpp"
|
||||
#include "ui/UIEmpty.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
|
||||
#define VISUAL_NOVEL_TEXTBOX_SPEED 25.0f
|
||||
@ -17,9 +18,11 @@ namespace Dawn {
|
||||
private:
|
||||
int32_t lineCurrent = 0;
|
||||
glm::vec2 labelPadding = glm::vec2(0, 0);
|
||||
UIEmpty selfParent;
|
||||
UIBorder border;
|
||||
UILabel label;
|
||||
float_t timeCharacter = 0.0f;
|
||||
bool_t visible = false;
|
||||
|
||||
void updatePositions() override;
|
||||
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
|
||||
@ -42,7 +45,8 @@ namespace Dawn {
|
||||
Event<> eventCurrentCharactersRevealed;
|
||||
Event<> eventNewPage;
|
||||
Event<> eventAllCharactersRevealed;
|
||||
Event<> eventClose;
|
||||
Event<> eventHidden;
|
||||
Event<> eventVisible;
|
||||
|
||||
/**
|
||||
* Constructs a VN Textbox.
|
||||
@ -51,6 +55,10 @@ namespace Dawn {
|
||||
*/
|
||||
VisualNovelTextbox(UICanvas *canvas);
|
||||
|
||||
void show();
|
||||
void hide();
|
||||
bool_t isVisible();
|
||||
|
||||
/**
|
||||
* Sets the font for this vn textbox. Passed to the underlying label.
|
||||
*
|
||||
@ -74,6 +82,28 @@ namespace Dawn {
|
||||
*/
|
||||
void setText(std::string text, float_t fontSize);
|
||||
|
||||
/**
|
||||
* Sets the string (label) for this textbox.
|
||||
*
|
||||
* @param text Text to set.
|
||||
*/
|
||||
void setText(std::string text);
|
||||
|
||||
/**
|
||||
* Sets the font size to use.
|
||||
*
|
||||
* @param fontSize Font size to use.
|
||||
*/
|
||||
void setFontSize(float_t fontSize);
|
||||
|
||||
/**
|
||||
* Sets the padding of the label. This will increase the spacing between
|
||||
* the text and the border.
|
||||
*
|
||||
* @param padding Padding to set.
|
||||
*/
|
||||
void setLabelPadding(glm::vec2 padding);
|
||||
|
||||
/**
|
||||
* Returns true if all of the characters that can be made visible for the
|
||||
* current textbox size have finished revealing, or false if not.
|
||||
|
Reference in New Issue
Block a user