Adding VN Character interface
This commit is contained in:
@ -7,4 +7,5 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
SimpleVisualNovelBackground.cpp
|
||||
VisualNovelCharacter.cpp
|
||||
)
|
14
src/dawn/visualnovel/components/VisualNovelCharacter.cpp
Normal file
14
src/dawn/visualnovel/components/VisualNovelCharacter.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VisualNovelCharacter.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
VisualNovelCharacter::VisualNovelCharacter(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
|
||||
}
|
22
src/dawn/visualnovel/components/VisualNovelCharacter.hpp
Normal file
22
src/dawn/visualnovel/components/VisualNovelCharacter.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelCharacter : public SceneItemComponent {
|
||||
public:
|
||||
std::string nameKey = "character.unknown";
|
||||
|
||||
/**
|
||||
* Visual Novel Character Component. Mostly logic-less but provides nice
|
||||
* interfaces for sibling components.
|
||||
*
|
||||
* @param item Item that this component belongs to.
|
||||
*/
|
||||
VisualNovelCharacter(SceneItem *item);
|
||||
};
|
||||
}
|
@ -8,16 +8,19 @@
|
||||
using namespace Dawn;
|
||||
|
||||
VisualNovelTextboxEvent::VisualNovelTextboxEvent(
|
||||
VisualNovelManager *manager,
|
||||
std::string key
|
||||
VisualNovelManager *manager,
|
||||
VisualNovelCharacter *character,
|
||||
std::string languageKey
|
||||
) : IVisualNovelEvent(manager) {
|
||||
this->key = key;
|
||||
this->character = character;
|
||||
this->languageKey = languageKey;
|
||||
}
|
||||
|
||||
void VisualNovelTextboxEvent::onStart(IVisualNovelEvent *previous) {
|
||||
if(this->manager->textBox == nullptr) return;
|
||||
|
||||
this->manager->textBox->setText(this->key);
|
||||
this->manager->textBox->setText(this->languageKey);
|
||||
this->manager->textBox->setCharacter(this->character);
|
||||
this->manager->textBox->show();
|
||||
this->hasSetText = true;
|
||||
}
|
||||
@ -26,7 +29,8 @@ bool_t VisualNovelTextboxEvent::onUpdate() {
|
||||
if(this->manager->textBox == nullptr) return true;
|
||||
|
||||
if(!this->hasSetText) {
|
||||
this->manager->textBox->setText(this->key);
|
||||
this->manager->textBox->setText(this->languageKey);
|
||||
this->manager->textBox->setCharacter(this->character);
|
||||
this->manager->textBox->show();
|
||||
this->hasSetText = true;
|
||||
}
|
||||
|
@ -5,11 +5,13 @@
|
||||
|
||||
#pragma once
|
||||
#include "visualnovel/VisualNovelManager.hpp"
|
||||
#include "visualnovel/components/VisualNovelCharacter.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelTextboxEvent : public IVisualNovelEvent {
|
||||
protected:
|
||||
std::string key;
|
||||
std::string languageKey;
|
||||
VisualNovelCharacter *character;
|
||||
bool_t hasSetText = false;
|
||||
|
||||
void onStart(IVisualNovelEvent *previous) override;
|
||||
@ -17,9 +19,18 @@ namespace Dawn {
|
||||
void onEnd() override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a new Textbox Event. This will queue a conversation item for the
|
||||
* textbox to display.
|
||||
*
|
||||
* @param manager Visual Novel Manager instance for this event.
|
||||
* @param character Character that is intended to be speaking.
|
||||
* @param languageKey Language Key to talk.
|
||||
*/
|
||||
VisualNovelTextboxEvent(
|
||||
VisualNovelManager *manager,
|
||||
std::string text
|
||||
VisualNovelCharacter *character,
|
||||
std::string languageKey
|
||||
);
|
||||
};
|
||||
}
|
@ -153,6 +153,10 @@ void VisualNovelTextbox::setText(std::string key, float_t fontSize) {
|
||||
this->label.updateMesh();
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::setCharacter(VisualNovelCharacter *character) {
|
||||
this->character = character;
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::setText(std::string key) {
|
||||
this->label.setText(key);
|
||||
this->label.updateMesh();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "ui/UILabel.hpp"
|
||||
#include "ui/UIEmpty.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
#include "visualnovel/components/VisualNovelCharacter.hpp"
|
||||
|
||||
#define VISUAL_NOVEL_TEXTBOX_SPEED 25.0f
|
||||
#define VISUAL_NOVEL_TEXTBOX_SPEED_FASTER 40.0f
|
||||
@ -21,6 +22,7 @@ namespace Dawn {
|
||||
UIEmpty selfParent;
|
||||
float_t timeCharacter = 0.0f;
|
||||
bool_t visible = false;
|
||||
VisualNovelCharacter *character = nullptr;
|
||||
|
||||
void updatePositions() override;
|
||||
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
|
||||
@ -82,6 +84,13 @@ namespace Dawn {
|
||||
*/
|
||||
void setText(std::string key);
|
||||
|
||||
/**
|
||||
* Sets the VN Character for this text.
|
||||
*
|
||||
* @param character Character to set.
|
||||
*/
|
||||
void setCharacter(VisualNovelCharacter *character);
|
||||
|
||||
/**
|
||||
* Sets the font size to use.
|
||||
*
|
||||
|
Reference in New Issue
Block a user