Added talkey to texty
This commit is contained in:
@ -164,7 +164,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
|
||||
std::sort(
|
||||
shaderPassItems.begin(),
|
||||
shaderPassItems.end(),
|
||||
[](struct ShaderPassItem &a, struct ShaderPassItem &b){
|
||||
[](struct ShaderPassItem &a, struct ShaderPassItem &b) {
|
||||
if(a.priority == b.priority) {
|
||||
return a.w < b.w;
|
||||
}
|
||||
|
@ -24,6 +24,19 @@ namespace Dawn {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts internal keyframes by their time to make them conform correctly.
|
||||
*/
|
||||
void sortKeyframes() {
|
||||
std::sort(
|
||||
this->keyframes.begin(),
|
||||
this->keyframes.end(),
|
||||
[](struct SimpleKeyframe<T> &a, struct SimpleKeyframe<T> &b) {
|
||||
return a.time < b.time;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public:
|
||||
easefunction_t *easing = &easeLinear;
|
||||
T *modifies;
|
||||
@ -54,6 +67,8 @@ namespace Dawn {
|
||||
this->duration = mathMax<float_t>(this->duration, time);
|
||||
this->finished = false;
|
||||
this->keyframes.push_back(keyframe);
|
||||
|
||||
if(time < this->duration) this->sortKeyframes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,9 @@ namespace Dawn {
|
||||
UICanvas *uiCanvas = nullptr;
|
||||
VisualNovelTextbox *textBox = nullptr;
|
||||
VisualNovelFader *fader = nullptr;
|
||||
|
||||
AudioSource *audioBackground = nullptr;
|
||||
AudioSource *audioCharacter = nullptr;
|
||||
|
||||
/** Event listener for unpaused scene updates. */
|
||||
void onUnpausedUpdate();
|
||||
|
@ -14,10 +14,12 @@ VisualNovelCharacter::VisualNovelCharacter(SceneItem *item) :
|
||||
|
||||
std::vector<SceneItemComponent*> VisualNovelCharacter::getDependencies() {
|
||||
return std::vector<SceneItemComponent*>{
|
||||
(this->material = this->item->getComponent<SimpleTexturedMaterial>())
|
||||
(this->material = this->item->getComponent<SimpleTexturedMaterial>()),
|
||||
(this->tiledSprite = this->item->getComponent<TiledSprite>())
|
||||
};
|
||||
}
|
||||
|
||||
void VisualNovelCharacter::onStart() {
|
||||
assertNotNull(this->material);
|
||||
assertNotNull(this->tiledSprite);
|
||||
}
|
@ -5,13 +5,23 @@
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "asset/assets/AudioAsset.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
#include "scene/components/display/TiledSprite.hpp"
|
||||
#include "scene/components/audio/AudioSource.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct VisualNovelCharacterEmotion {
|
||||
int32_t tile = 0;
|
||||
AudioAsset *talkSound = nullptr;
|
||||
AudioAsset *emotionSound = nullptr;
|
||||
};
|
||||
|
||||
class VisualNovelCharacter : public SceneItemComponent {
|
||||
public:
|
||||
std::string nameKey = "character.unknown";
|
||||
SimpleTexturedMaterial *material = nullptr;
|
||||
TiledSprite *tiledSprite = nullptr;
|
||||
|
||||
/**
|
||||
* Visual Novel Character Component. Mostly logic-less but provides nice
|
||||
|
@ -8,12 +8,22 @@
|
||||
using namespace Dawn;
|
||||
|
||||
VisualNovelTextboxEvent::VisualNovelTextboxEvent(
|
||||
VisualNovelManager *manager,
|
||||
VisualNovelCharacter *character,
|
||||
std::string languageKey
|
||||
VisualNovelManager *manager,
|
||||
VisualNovelCharacter *character,
|
||||
struct VisualNovelCharacterEmotion emotion,
|
||||
std::string languageKey
|
||||
) : IVisualNovelEvent(manager) {
|
||||
this->character = character;
|
||||
this->languageKey = languageKey;
|
||||
this->emotion = emotion;
|
||||
}
|
||||
|
||||
VisualNovelTextboxEvent::VisualNovelTextboxEvent(
|
||||
VisualNovelManager *manager,
|
||||
std::string languageKey
|
||||
) : IVisualNovelEvent(manager) {
|
||||
this->character = nullptr;
|
||||
this->languageKey = languageKey;
|
||||
}
|
||||
|
||||
void VisualNovelTextboxEvent::onStart(IVisualNovelEvent *previous) {
|
||||
@ -21,20 +31,26 @@ void VisualNovelTextboxEvent::onStart(IVisualNovelEvent *previous) {
|
||||
|
||||
this->manager->textBox->setText(this->languageKey);
|
||||
this->manager->textBox->setCharacter(this->character);
|
||||
|
||||
if(this->character != nullptr) {
|
||||
this->character->tiledSprite->setTile(this->emotion.tile);
|
||||
}
|
||||
|
||||
if(this->emotion.emotionSound != nullptr) {
|
||||
if(this->manager->audioCharacter != nullptr) {
|
||||
this->manager->audioCharacter->stop();
|
||||
this->manager->audioCharacter->loop = false;
|
||||
this->manager->audioCharacter->setAudioData(this->emotion.emotionSound);
|
||||
this->manager->audioCharacter->play();
|
||||
}
|
||||
} else if(this->emotion.talkSound != nullptr) {
|
||||
this->manager->textBox->setTalkingSound(this->emotion.talkSound);
|
||||
}
|
||||
|
||||
this->manager->textBox->show();
|
||||
this->hasSetText = true;
|
||||
}
|
||||
|
||||
bool_t VisualNovelTextboxEvent::onUpdate() {
|
||||
if(this->manager->textBox == nullptr) return true;
|
||||
|
||||
if(!this->hasSetText) {
|
||||
this->manager->textBox->setText(this->languageKey);
|
||||
this->manager->textBox->setCharacter(this->character);
|
||||
this->manager->textBox->show();
|
||||
this->hasSetText = true;
|
||||
}
|
||||
|
||||
return this->manager->textBox->isVisible();
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace Dawn {
|
||||
protected:
|
||||
std::string languageKey;
|
||||
VisualNovelCharacter *character;
|
||||
bool_t hasSetText = false;
|
||||
struct VisualNovelCharacterEmotion emotion;
|
||||
|
||||
void onStart(IVisualNovelEvent *previous) override;
|
||||
bool_t onUpdate() override;
|
||||
@ -30,6 +30,12 @@ namespace Dawn {
|
||||
VisualNovelTextboxEvent(
|
||||
VisualNovelManager *manager,
|
||||
VisualNovelCharacter *character,
|
||||
struct VisualNovelCharacterEmotion emotion,
|
||||
std::string languageKey
|
||||
);
|
||||
|
||||
VisualNovelTextboxEvent(
|
||||
VisualNovelManager *manager,
|
||||
std::string languageKey
|
||||
);
|
||||
};
|
||||
|
@ -7,4 +7,5 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
VisualNovelFadeCharacterEvent.cpp
|
||||
VisualNovelTransformItemEvent.cpp
|
||||
)
|
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "visualnovel/events/animation/VisualNovelSimpleCallbackAnimationEvent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelTransformItemEvent :
|
||||
public VisualNovelSimpleCallbackAnimationEvent<glm::vec3, Transform>
|
||||
{
|
||||
protected:
|
||||
bool_t relative = false;
|
||||
SceneItem *item = nullptr;
|
||||
void onStart(IVisualNovelEvent *previous) override;
|
||||
|
||||
public:
|
||||
VisualNovelTransformItemEvent(
|
||||
VisualNovelManager *man,
|
||||
SceneItem *item,
|
||||
glm::vec3 start,
|
||||
glm::vec3 end,
|
||||
easefunction_t *ease,
|
||||
float_t duration
|
||||
);
|
||||
|
||||
VisualNovelTransformItemEvent(
|
||||
VisualNovelManager *man,
|
||||
SceneItem *item,
|
||||
glm::vec3 end,
|
||||
easefunction_t *ease,
|
||||
float_t duration
|
||||
);
|
||||
};
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VisualNovelTransformItemEvent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
VisualNovelTransformItemEvent::VisualNovelTransformItemEvent(
|
||||
VisualNovelManager *man,
|
||||
SceneItem *item,
|
||||
glm::vec3 start,
|
||||
glm::vec3 end,
|
||||
easefunction_t *ease,
|
||||
float_t duration
|
||||
) : VisualNovelSimpleCallbackAnimationEvent<glm::vec3, Transform>(man) {
|
||||
assertNotNull(item);
|
||||
this->item = item;
|
||||
|
||||
this->callbackAnimation.setCallback(
|
||||
&item->transform, &Transform::setLocalPosition
|
||||
);
|
||||
this->callbackAnimation.addKeyframe(0.0f, start);
|
||||
this->callbackAnimation.addKeyframe(duration, end);
|
||||
}
|
||||
|
||||
VisualNovelTransformItemEvent::VisualNovelTransformItemEvent(
|
||||
VisualNovelManager *man,
|
||||
SceneItem *item,
|
||||
glm::vec3 end,
|
||||
easefunction_t *ease,
|
||||
float_t duration
|
||||
) : VisualNovelSimpleCallbackAnimationEvent<glm::vec3, Transform>(man) {
|
||||
assertNotNull(item);
|
||||
this->item = item;
|
||||
|
||||
this->callbackAnimation.setCallback(
|
||||
&item->transform, &Transform::setLocalPosition
|
||||
);
|
||||
this->relative = true;
|
||||
this->callbackAnimation.addKeyframe(duration, end);
|
||||
}
|
||||
|
||||
void VisualNovelTransformItemEvent::onStart(IVisualNovelEvent *previous) {
|
||||
if(this->relative) {
|
||||
this->callbackAnimation.addKeyframe(0.0f, this->item->transform.getLocalPosition());
|
||||
}
|
||||
VisualNovelSimpleCallbackAnimationEvent::onStart(previous);
|
||||
}
|
@ -25,17 +25,12 @@ void SimpleVNScene::stage() {
|
||||
|
||||
// Camera
|
||||
this->camera = Camera::create(this);
|
||||
// this->camera->item->addComponent<AudioListener>();
|
||||
this->camera->transform->lookAtPixelPerfect(
|
||||
glm::vec3(0, 0, 0),
|
||||
glm::vec3(0, 0, 0),
|
||||
this->camera->getRenderTarget()->getHeight(),
|
||||
camera->fov
|
||||
);
|
||||
|
||||
// Audio
|
||||
auto listenerItem = this->createSceneItem();
|
||||
this->audioListener = listenerItem->addComponent<AudioListener>();
|
||||
|
||||
this->background = SimpleVisualNovelBackground::create(this);
|
||||
|
||||
@ -49,6 +44,16 @@ void SimpleVNScene::stage() {
|
||||
// VN Manager
|
||||
auto vnManagerItem = this->createSceneItem();
|
||||
this->vnManager = vnManagerItem->addComponent<VisualNovelManager>();
|
||||
|
||||
// Audio
|
||||
auto listenerItem = this->createSceneItem();
|
||||
this->audioListener = listenerItem->addComponent<AudioListener>();
|
||||
|
||||
auto audioBackgroundItem = this->createSceneItem();
|
||||
vnManager->audioBackground = audioBackgroundItem->addComponent<AudioSource>();
|
||||
|
||||
auto audioCharacterItem = this->createSceneItem();
|
||||
vnManager->audioCharacter = audioCharacterItem->addComponent<AudioSource>();
|
||||
|
||||
// Fader (Drawn over the top of everything else)
|
||||
this->vnFader = VisualNovelFader::create(canvas);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "VisualNovelTextbox.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "visualnovel/VisualNovelManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -43,10 +44,29 @@ void VisualNovelTextbox::show() {
|
||||
if(this->isVisible()) return;
|
||||
this->visible = true;
|
||||
this->addChild(&this->selfParent);
|
||||
|
||||
if(this->talkSound != nullptr) {
|
||||
auto vnManager = this->getVisualNovelManager();
|
||||
assertNotNull(vnManager);
|
||||
assertNotNull(vnManager->audioCharacter);
|
||||
|
||||
vnManager->audioCharacter->stop();
|
||||
vnManager->audioCharacter->setAudioData(this->talkSound);
|
||||
vnManager->audioCharacter->loop = true;
|
||||
vnManager->audioCharacter->play();
|
||||
}
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::hide() {
|
||||
if(!this->isVisible()) return;
|
||||
|
||||
if(this->talkSound != nullptr) {
|
||||
auto vnManager = this->getVisualNovelManager();
|
||||
assertNotNull(vnManager);
|
||||
assertNotNull(vnManager->audioCharacter);
|
||||
vnManager->audioCharacter->stop();
|
||||
}
|
||||
|
||||
this->visible = false;
|
||||
this->removeChild(&this->selfParent);
|
||||
this->eventHidden.invoke();
|
||||
@ -56,6 +76,10 @@ bool_t VisualNovelTextbox::isVisible() {
|
||||
return this->visible;
|
||||
}
|
||||
|
||||
VisualNovelManager * VisualNovelTextbox::getVisualNovelManager() {
|
||||
return this->getScene()->findComponent<VisualNovelManager>();
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::updatePositions() {
|
||||
UIComponent::updatePositions();
|
||||
|
||||
@ -110,6 +134,15 @@ void VisualNovelTextbox::textboxOnSceneUpdate() {
|
||||
this->eventNewPage.invoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(this->talkSound != nullptr) {
|
||||
auto vnManager = this->getVisualNovelManager();
|
||||
assertNotNull(vnManager);
|
||||
assertNotNull(vnManager->audioCharacter);
|
||||
vnManager->audioCharacter->stop();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -159,6 +192,11 @@ void VisualNovelTextbox::setText(std::string key, float_t fontSize) {
|
||||
|
||||
void VisualNovelTextbox::setCharacter(VisualNovelCharacter *character) {
|
||||
this->character = character;
|
||||
this->talkSound = nullptr;
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::setTalkingSound(AudioAsset *asset) {
|
||||
this->talkSound = asset;
|
||||
}
|
||||
|
||||
void VisualNovelTextbox::setText(std::string key) {
|
||||
|
@ -15,6 +15,8 @@
|
||||
#define VISUAL_NOVEL_TEXTBOX_SPEED_FASTER 40.0f
|
||||
|
||||
namespace Dawn {
|
||||
class VisualNovelManager;
|
||||
|
||||
class VisualNovelTextbox : public UIComponent {
|
||||
private:
|
||||
int32_t lineCurrent = 0;
|
||||
@ -23,6 +25,7 @@ namespace Dawn {
|
||||
float_t timeCharacter = 0.0f;
|
||||
bool_t visible = false;
|
||||
VisualNovelCharacter *character = nullptr;
|
||||
AudioAsset *talkSound = nullptr;
|
||||
|
||||
void updatePositions() override;
|
||||
|
||||
@ -67,6 +70,13 @@ namespace Dawn {
|
||||
void hide();
|
||||
bool_t isVisible();
|
||||
|
||||
/**
|
||||
* Returns the visual novel manager (if applicable).
|
||||
*
|
||||
* @return Visual Novel Manager instance.
|
||||
*/
|
||||
VisualNovelManager * getVisualNovelManager();
|
||||
|
||||
/**
|
||||
* Sets the font for this vn textbox. Passed to the underlying label.
|
||||
*
|
||||
@ -96,6 +106,14 @@ namespace Dawn {
|
||||
*/
|
||||
void setCharacter(VisualNovelCharacter *character);
|
||||
|
||||
/**
|
||||
* Set the sound to use whenever the text is scrolling to represent a
|
||||
* character talking.
|
||||
*
|
||||
* @param sound Sound asset to use.
|
||||
*/
|
||||
void setTalkingSound(AudioAsset *sound);
|
||||
|
||||
/**
|
||||
* Sets the font size to use.
|
||||
*
|
||||
|
Reference in New Issue
Block a user