Fixed some bugs with AI
This commit is contained in:
@ -29,14 +29,9 @@ void VisualNovelManager::onStart() {
|
||||
void VisualNovelManager::onUnpausedUpdate() {
|
||||
if(this->currentEvent == nullptr) return;
|
||||
|
||||
if(!this->currentEvent->hasStarted) {
|
||||
this->currentEvent->start();
|
||||
}
|
||||
|
||||
if(!this->currentEvent->hasStarted) this->currentEvent->start(nullptr);
|
||||
if(this->currentEvent->update()) return;
|
||||
auto oldCurrent = this->currentEvent;
|
||||
this->currentEvent = this->currentEvent->end();
|
||||
delete oldCurrent;
|
||||
this->setEvent(this->currentEvent->end());
|
||||
}
|
||||
|
||||
VisualNovelManager::~VisualNovelManager() {
|
||||
@ -46,15 +41,18 @@ VisualNovelManager::~VisualNovelManager() {
|
||||
this->getScene()->eventSceneUnpausedUpdate.removeListener(this, &VisualNovelManager::onUnpausedUpdate);
|
||||
}
|
||||
|
||||
// Visual Novel Event
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
|
||||
IVisualNovelEvent::IVisualNovelEvent(VisualNovelManager *man) {
|
||||
assertNotNull(man);
|
||||
this->manager = man;
|
||||
}
|
||||
|
||||
void IVisualNovelEvent::start() {
|
||||
this->onStart();
|
||||
void IVisualNovelEvent::start(IVisualNovelEvent *previous) {
|
||||
this->hasStarted = true;
|
||||
this->onStart(previous);
|
||||
}
|
||||
|
||||
bool_t IVisualNovelEvent::update() {
|
||||
@ -64,14 +62,18 @@ bool_t IVisualNovelEvent::update() {
|
||||
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->hasStarted && this->doNext != nullptr) {
|
||||
delete this->doNext;
|
||||
}
|
||||
if(this->doNext != nullptr) delete this->doNext;
|
||||
}
|
@ -15,10 +15,12 @@ namespace Dawn {
|
||||
UICanvas *uiCanvas;
|
||||
IVisualNovelEvent* currentEvent = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
/** Event listener for unpaused scene updates. */
|
||||
void onUnpausedUpdate();
|
||||
|
||||
public:
|
||||
|
||||
VisualNovelTextbox *textBox;
|
||||
/**
|
||||
* Constructs a visual novel manager, scene item component.
|
||||
@ -35,8 +37,10 @@ namespace Dawn {
|
||||
*/
|
||||
template <class T>
|
||||
T * setEvent(T *event) {
|
||||
assertNotNull(event);
|
||||
auto oldCurrent = this->currentEvent;
|
||||
this->currentEvent = event;
|
||||
if(event != nullptr) this->currentEvent->start(oldCurrent);
|
||||
delete oldCurrent;
|
||||
return event;
|
||||
}
|
||||
|
||||
@ -60,26 +64,22 @@ namespace Dawn {
|
||||
protected:
|
||||
VisualNovelManager *manager;
|
||||
IVisualNovelEvent *doNext = nullptr;
|
||||
bool_t hasStarted;
|
||||
bool_t hasStarted = false;
|
||||
|
||||
virtual void onStart() = 0;
|
||||
virtual void onStart(IVisualNovelEvent *previous) = 0;
|
||||
virtual bool_t onUpdate() = 0;
|
||||
virtual void onEnd() = 0;
|
||||
|
||||
public:
|
||||
IVisualNovelEvent *previous = nullptr;
|
||||
|
||||
IVisualNovelEvent(VisualNovelManager *manager);
|
||||
|
||||
template<class T>
|
||||
T * then(T *next) {
|
||||
assertNotNull(next);
|
||||
this->doNext = next;
|
||||
next->previous = this;
|
||||
return next;
|
||||
}
|
||||
|
||||
void start();
|
||||
void start(IVisualNovelEvent *previous);
|
||||
bool_t update();
|
||||
IVisualNovelEvent * end();
|
||||
|
||||
|
31
src/dawn/visualnovel/events/SimpleLoopEvent.hpp
Normal file
31
src/dawn/visualnovel/events/SimpleLoopEvent.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "visualnovel/VisualNovelManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleLoopEvent : public IVisualNovelEvent {
|
||||
protected:
|
||||
std::string text;
|
||||
|
||||
void onStart(IVisualNovelEvent *previous) override {
|
||||
this->then(new SimpleLoopEvent(this->manager));
|
||||
}
|
||||
|
||||
bool_t onUpdate() override {
|
||||
return false;
|
||||
}
|
||||
|
||||
void onEnd() override {
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
SimpleLoopEvent(VisualNovelManager *man) : IVisualNovelEvent(man) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
@ -14,12 +14,23 @@ VisualNovelTextboxEvent::VisualNovelTextboxEvent(
|
||||
this->text = text;
|
||||
}
|
||||
|
||||
void VisualNovelTextboxEvent::onStart() {
|
||||
void VisualNovelTextboxEvent::onStart(IVisualNovelEvent *previous) {
|
||||
if(this->manager->textBox == nullptr) return;
|
||||
|
||||
this->manager->textBox->setText(this->text);
|
||||
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->text);
|
||||
this->manager->textBox->show();
|
||||
this->hasSetText = true;
|
||||
}
|
||||
|
||||
return this->manager->textBox->isVisible();
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,9 @@ namespace Dawn {
|
||||
class VisualNovelTextboxEvent : public IVisualNovelEvent {
|
||||
protected:
|
||||
std::string text;
|
||||
bool_t hasSetText = false;
|
||||
|
||||
void onStart() override;
|
||||
void onStart(IVisualNovelEvent *previous) override;
|
||||
bool_t onUpdate() override;
|
||||
void onEnd() override;
|
||||
|
||||
|
Reference in New Issue
Block a user