// 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) { } void VisualNovelManager::onStart() { SceneItemComponent::onStart(); this->uiCanvas = getScene()->findComponent(); assertNotNull(this->uiCanvas); this->textBox = this->uiCanvas->findElement(); this->fader = this->uiCanvas->findElement(); assertNotNull(this->textBox); assertNotNull(this->fader); this->getScene()->eventSceneUnpausedUpdate.addListener(this, &VisualNovelManager::onUnpausedUpdate); } void VisualNovelManager::onUnpausedUpdate() { if(this->currentEvent == nullptr) return; if(!this->currentEvent->hasStarted) this->currentEvent->start(nullptr); if(this->currentEvent->update()) return; this->setEvent(this->currentEvent->end()); } VisualNovelManager::~VisualNovelManager() { if(this->currentEvent != nullptr) { delete this->currentEvent; } this->getScene()->eventSceneUnpausedUpdate.removeListener(this, &VisualNovelManager::onUnpausedUpdate); } // // // // // // // // // // // // // // // // // // // // // // // // // // // IVisualNovelEvent::IVisualNovelEvent(VisualNovelManager *man) { assertNotNull(man); this->manager = man; } void IVisualNovelEvent::start(IVisualNovelEvent *previous) { this->hasStarted = true; this->onStart(previous); } bool_t IVisualNovelEvent::update() { return this->onUpdate(); } IVisualNovelEvent * IVisualNovelEvent::end() { this->onEnd(); std::cout << "End"; if(this->doNext != nullptr) { std::cout << " Nexter" << std::endl; auto next = this->doNext; this->doNext = nullptr; return next; } std::cout << " No nxt" << std::endl; return nullptr; } IVisualNovelEvent::~IVisualNovelEvent() { if(this->doNext != nullptr) delete this->doNext; }