77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
// Copyright (c) 2022 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "VisualNovelManager.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
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;
|
|
return next;
|
|
}
|
|
}
|
|
|
|
IVisualNovelEvent::~IVisualNovelEvent() {
|
|
if(!this->hasStarted && this->doNext != nullptr) {
|
|
delete this->doNext;
|
|
}
|
|
} |