This commit is contained in:
2022-12-12 10:55:02 -08:00
parent a2ee1e139d
commit 8bbf05dcf0
13 changed files with 165 additions and 13 deletions

View File

@ -10,8 +10,6 @@ using namespace Dawn;
VisualNovelManager::VisualNovelManager(SceneItem *item) :
SceneItemComponent(item)
{
this->uiCanvas = nullptr;
this->textBox = nullptr;
}
void VisualNovelManager::onStart() {
@ -21,7 +19,10 @@ void VisualNovelManager::onStart() {
assertNotNull(this->uiCanvas);
this->textBox = this->uiCanvas->findElement<VisualNovelTextbox>();
this->fader = this->uiCanvas->findElement<VisualNovelFader>();
assertNotNull(this->textBox);
assertNotNull(this->fader);
this->getScene()->eventSceneUnpausedUpdate.addListener(this, &VisualNovelManager::onUnpausedUpdate);
}

View File

@ -6,22 +6,23 @@
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "visualnovel/ui/VisualNovelTextbox.hpp"
#include "visualnovel/ui/VisualNovelFader.hpp"
namespace Dawn {
class IVisualNovelEvent;
class VisualNovelManager : public SceneItemComponent {
private:
UICanvas *uiCanvas;
IVisualNovelEvent* currentEvent = nullptr;
public:
UICanvas *uiCanvas = nullptr;
VisualNovelTextbox *textBox = nullptr;
VisualNovelFader *fader = nullptr;
/** Event listener for unpaused scene updates. */
void onUnpausedUpdate();
VisualNovelTextbox *textBox;
/**
* Constructs a visual novel manager, scene item component.
*

View File

@ -0,0 +1,34 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/VisualNovelManager.hpp"
#include "display/animation/Animation.hpp"
namespace Dawn {
class VisualNovelAnimationEvent : public IVisualNovelEvent {
protected:
void onStart(IVisualNovelEvent *previous) override {
}
bool_t onUpdate() override {
this->animation->tick(this->manager->getGame()->timeManager.delta);
return this->animation->finished;
}
void onEnd() override {
}
public:
struct Animation *animation;
VisualNovelAnimationEvent(VisualNovelManager *manager) :
IVisualNovelEvent(manager)
{
}
};
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "VisualNovelSimpleAnimationEvent.hpp"
namespace Dawn {
class VisualNovelFadeEvent :
public VisualNovelSimpleAnimationEvent<float_t>
{
protected:
struct Color color;
bool_t fadeIn;
float_t duration;
void onStart(IVisualNovelEvent *previous) override {
VisualNovelSimpleAnimationEvent::onStart(previous);
this->simpleAnimation = SimpleAnimation<float_t>(&this->manager->fader->color.a);
this->manager->fader->color = this->color;
this->manager->fader->color.a = this->fadeIn ? 0.0f : 1.0f;
this->simpleAnimation.addKeyframe(
0.0f, this->fadeIn ? 0.0f : 1.0f
);
this->simpleAnimation.addKeyframe(
this->duration, this->fadeIn ? 1.0f : 0.0f
);
}
public:
VisualNovelFadeEvent(
VisualNovelManager *man,
struct Color color,
bool_t fadeIn,
easefunction_t *ease,
float_t duration
) : VisualNovelSimpleAnimationEvent(man, &duration) {
this->color = color;
this->fadeIn = fadeIn;
this->duration = duration;
this->simpleAnimation.easing = ease;
}
};
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "VisualNovelAnimationEvent.hpp"
#include "display/animation/SimpleAnimation.hpp"
namespace Dawn {
template<typename T>
class VisualNovelSimpleAnimationEvent : public VisualNovelAnimationEvent {
public:
struct SimpleAnimation<T> simpleAnimation;
VisualNovelSimpleAnimationEvent(
VisualNovelManager *man,
T *modifies
) :
VisualNovelAnimationEvent(man),
simpleAnimation(modifies)
{
this->animation = &this->simpleAnimation;
}
};
}

View File

@ -0,0 +1,29 @@
// 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/UIEmpty.hpp"
namespace Dawn {
class VisualNovelFader : public UISprite {
private:
public:
static VisualNovelFader * create(UICanvas *canvas) {
assertNotNull(canvas);
auto item = canvas->addElement<VisualNovelFader>();
item->setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
glm::vec4(0, 0, 0, 0),
0.0f
);
return item;
}
VisualNovelFader(UICanvas *canvas) : UISprite(canvas) {
}
};
}