121 lines
3.2 KiB
C++
121 lines
3.2 KiB
C++
// Copyright (c) 2022 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#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
|
|
#define VISUAL_NOVEL_TEXTBOX_SPEED_FASTER 40.0f
|
|
|
|
namespace Dawn {
|
|
class VisualNovelTextbox : public UIComponent {
|
|
private:
|
|
int32_t lineCurrent = 0;
|
|
glm::vec2 labelPadding = glm::vec2(0, 0);
|
|
UIEmpty selfParent;
|
|
float_t timeCharacter = 0.0f;
|
|
bool_t visible = false;
|
|
|
|
void updatePositions() override;
|
|
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
|
|
|
|
/**
|
|
* Listens for scene updates.
|
|
*/
|
|
void textboxOnSceneUpdate();
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
int32_t getCountOfVisibleLines();
|
|
|
|
public:
|
|
UIBorder border;
|
|
UILabel label;
|
|
|
|
Event<> eventCharacterRevealed;
|
|
Event<> eventCurrentCharactersRevealed;
|
|
Event<> eventNewPage;
|
|
Event<> eventAllCharactersRevealed;
|
|
Event<> eventHidden;
|
|
Event<> eventVisible;
|
|
|
|
/**
|
|
* Constructs a VN Textbox.
|
|
*
|
|
* @param canvas Canvas that this textbox belongs to.
|
|
*/
|
|
VisualNovelTextbox(UICanvas *canvas);
|
|
|
|
void show();
|
|
void hide();
|
|
bool_t isVisible();
|
|
|
|
/**
|
|
* Sets the font for this vn textbox. Passed to the underlying label.
|
|
*
|
|
* @param font Font to set for this textbox.
|
|
*/
|
|
void setFont(Font *font);
|
|
|
|
/**
|
|
* Sets the string (label) for this textbox.
|
|
*
|
|
* @param text Text to set.
|
|
* @param fontSize Font size of the string.
|
|
*/
|
|
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.
|
|
*
|
|
* @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();
|
|
|
|
/**
|
|
* Cleans the VN Textbox.
|
|
*/
|
|
~VisualNovelTextbox();
|
|
};
|
|
} |