diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 6addf8cd..68560058 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -126,8 +126,12 @@ void RenderPipeline::renderUI( // Clear / Bind / Update the render target. renderTarget->bind(); + renderTarget->clear( + RENDER_TARGET_CLEAR_FLAG_DEPTH | + RENDER_TARGET_CLEAR_FLAG_COLOR + ); this->renderManager->setRenderFlags( - RENDER_MANAGER_RENDER_FLAG_BLEND + RENDER_MANAGER_RENDER_FLAG_BLEND ); // Prepare the UI Shader @@ -138,7 +142,7 @@ void RenderPipeline::renderUI( shader->setUICamera(transform, projection); // Render the children - glm::mat4 rootMatrix = canvas->transform->getWorldTransform(); + glm::mat4 rootMatrix = canvas->transform->getWorldTransform(); auto it = canvas->children.begin(); while(it != canvas->children.end()) { (*it)->draw(shader, rootMatrix); diff --git a/src/dawn/visualnovel/CMakeLists.txt b/src/dawn/visualnovel/CMakeLists.txt index 36ed345f..6bbff3d2 100644 --- a/src/dawn/visualnovel/CMakeLists.txt +++ b/src/dawn/visualnovel/CMakeLists.txt @@ -10,5 +10,6 @@ target_sources(${DAWN_TARGET_NAME} ) # Subdirs +add_subdirectory(components) add_subdirectory(events) add_subdirectory(ui) \ No newline at end of file diff --git a/src/dawn/visualnovel/VisualNovelManager.cpp b/src/dawn/visualnovel/VisualNovelManager.cpp index 78e06cbb..d70bfe34 100644 --- a/src/dawn/visualnovel/VisualNovelManager.cpp +++ b/src/dawn/visualnovel/VisualNovelManager.cpp @@ -25,6 +25,8 @@ void VisualNovelManager::onStart() { assertNotNull(this->fader); this->getScene()->eventSceneUnpausedUpdate.addListener(this, &VisualNovelManager::onUnpausedUpdate); + + if(this->currentEvent != nullptr) this->currentEvent->start(nullptr); } void VisualNovelManager::onUnpausedUpdate() { diff --git a/src/dawn/visualnovel/VisualNovelManager.hpp b/src/dawn/visualnovel/VisualNovelManager.hpp index b6cf0fa7..6560186b 100644 --- a/src/dawn/visualnovel/VisualNovelManager.hpp +++ b/src/dawn/visualnovel/VisualNovelManager.hpp @@ -40,7 +40,7 @@ namespace Dawn { T * setEvent(T *event) { auto oldCurrent = this->currentEvent; this->currentEvent = event; - if(event != nullptr) this->currentEvent->start(oldCurrent); + if(this->hasInitialized && event != nullptr) event->start(oldCurrent); delete oldCurrent; return event; } @@ -74,16 +74,46 @@ namespace Dawn { public: IVisualNovelEvent(VisualNovelManager *manager); + /** + * Chains an event to be executed after this event has finished. + * + * @param next Event to process next. + * @return Whatever you pass in to next. + */ template T * then(T *next) { this->doNext = next; return next; } + /** + * Begins this visual novel event, internally updates some flags and + * calls the event to do its own start logic. + * + * @param previous Previous event, this is for doing logic based chains. + */ void start(IVisualNovelEvent *previous); + + /** + * Performs a tick on this event. The event can then decide whether or not + * it has finished processing. + * + * @return True if the event is still active, otherwise false. + */ bool_t update(); + + /** + * End this current event. Returns the "next event" to process. Most of + * the events can handle this with the simple ->then() chaining, but some + * events may chose to do complex if-style logic. + * + * @return Event to run next. + */ IVisualNovelEvent * end(); + /** + * Dispose the VN event. + */ virtual ~IVisualNovelEvent(); friend class VisualNovelManager; diff --git a/src/dawn/visualnovel/components/CMakeLists.txt b/src/dawn/visualnovel/components/CMakeLists.txt new file mode 100644 index 00000000..87f857a7 --- /dev/null +++ b/src/dawn/visualnovel/components/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + SimpleVisualNovelBackground.cpp +) \ No newline at end of file diff --git a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp new file mode 100644 index 00000000..0c3ae206 --- /dev/null +++ b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "SimpleVisualNovelBackground.hpp" + +using namespace Dawn; + +SimpleVisualNovelBackground::SimpleVisualNovelBackground(SceneItem *item) : + SceneItemComponent(item) +{ + +} + +std::vector SimpleVisualNovelBackground::getDependencies(){ + return std::vector{ + this->meshHost = this->item->getComponent(), + this->material = this->item->getComponent() + }; +} + +void SimpleVisualNovelBackground::onStart() { + +} \ No newline at end of file diff --git a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp new file mode 100644 index 00000000..c178dfbb --- /dev/null +++ b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "scene/components/Components.hpp" + +namespace Dawn { + class SimpleVisualNovelBackground : public SceneItemComponent { + public: + Material *material; + MeshHost *meshHost; + + SimpleVisualNovelBackground(SceneItem *item); + std::vector getDependencies() override; + void onStart() override; + }; +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/CMakeLists.txt b/src/dawn/visualnovel/events/CMakeLists.txt index 5389d80d..c9f8045a 100644 --- a/src/dawn/visualnovel/events/CMakeLists.txt +++ b/src/dawn/visualnovel/events/CMakeLists.txt @@ -6,5 +6,8 @@ # Sources target_sources(${DAWN_TARGET_NAME} PRIVATE + VisualNovelAnimationEvent.cpp + VisualNovelFadeEvent.cpp + VisualNovelPauseEvent.cpp VisualNovelTextboxEvent.cpp ) \ No newline at end of file diff --git a/src/dawn/visualnovel/events/SimpleLoopEvent.hpp b/src/dawn/visualnovel/events/SimpleLoopEvent.hpp deleted file mode 100644 index 54a7fbaa..00000000 --- a/src/dawn/visualnovel/events/SimpleLoopEvent.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// 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) { - - } - }; -} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp b/src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp new file mode 100644 index 00000000..90fe2ac7 --- /dev/null +++ b/src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "VisualNovelAnimationEvent.hpp" + +using namespace Dawn; + +VisualNovelAnimationEvent::VisualNovelAnimationEvent( + VisualNovelManager *manager +) : IVisualNovelEvent(manager) { +} + +void VisualNovelAnimationEvent::onStart(IVisualNovelEvent *previous) { + +} + +bool_t VisualNovelAnimationEvent::onUpdate() { + this->animation->tick(this->manager->getGame()->timeManager.delta); + return !this->animation->finished; +} + +void VisualNovelAnimationEvent::onEnd() { + +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelAnimationEvent.hpp b/src/dawn/visualnovel/events/VisualNovelAnimationEvent.hpp index 948fd744..36ecc495 100644 --- a/src/dawn/visualnovel/events/VisualNovelAnimationEvent.hpp +++ b/src/dawn/visualnovel/events/VisualNovelAnimationEvent.hpp @@ -10,25 +10,13 @@ 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) - { - } + void onStart(IVisualNovelEvent *previous) override; + bool_t onUpdate() override; + void onEnd() override; + + public: + VisualNovelAnimationEvent(VisualNovelManager *manager); }; } \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp b/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp new file mode 100644 index 00000000..48ed4139 --- /dev/null +++ b/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp @@ -0,0 +1,20 @@ +// 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 VisualNovelChangeSimpleBackgroundEvent : public IVisualNovelEvent { + protected: + Texture *texture; + + public: + VisualNovelChangeSimpleBackgroundEvent( + VisualNovelManager *manager, + Texture *texture + ); + }; +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelFadeEvent.cpp b/src/dawn/visualnovel/events/VisualNovelFadeEvent.cpp new file mode 100644 index 00000000..defae717 --- /dev/null +++ b/src/dawn/visualnovel/events/VisualNovelFadeEvent.cpp @@ -0,0 +1,35 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "VisualNovelFadeEvent.hpp" + +using namespace Dawn; + +VisualNovelFadeEvent::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; +} + +void VisualNovelFadeEvent::onStart(IVisualNovelEvent *previous) { + VisualNovelSimpleAnimationEvent::onStart(previous); + + this->simpleAnimation = SimpleAnimation(&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 + ); +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelFadeEvent.hpp b/src/dawn/visualnovel/events/VisualNovelFadeEvent.hpp index d0b14588..b6a57800 100644 --- a/src/dawn/visualnovel/events/VisualNovelFadeEvent.hpp +++ b/src/dawn/visualnovel/events/VisualNovelFadeEvent.hpp @@ -7,40 +7,30 @@ #include "VisualNovelSimpleAnimationEvent.hpp" namespace Dawn { - class VisualNovelFadeEvent : - public VisualNovelSimpleAnimationEvent - { + class VisualNovelFadeEvent : public VisualNovelSimpleAnimationEvent { protected: struct Color color; bool_t fadeIn; float_t duration; - void onStart(IVisualNovelEvent *previous) override { - VisualNovelSimpleAnimationEvent::onStart(previous); - - this->simpleAnimation = SimpleAnimation(&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 - ); - } + void onStart(IVisualNovelEvent *previous) override; public: + /** + * Create a new visual novel event for fading the screen in/out. + * + * @param man Manager that this VN event belongs to. + * @param color Color to fade to/from. + * @param fadeIn True to make the color go from 0 to 1 opacity. + * @param ease Easing function to use. + * @param duration How long does the fade take. + */ 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; - } + ); }; } \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp b/src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp new file mode 100644 index 00000000..f136a705 --- /dev/null +++ b/src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "VisualNovelPauseEvent.hpp" + +using namespace Dawn; + +VisualNovelPauseEvent::VisualNovelPauseEvent( + VisualNovelManager *manager, float_t duration +) : IVisualNovelEvent(manager) { + this->duration = duration; +} + +void VisualNovelPauseEvent::onStart(IVisualNovelEvent *prev) { + this->time = 0; +} + +bool_t VisualNovelPauseEvent::onUpdate() { + this->time += this->manager->getGame()->timeManager.delta; + return this->time < this->duration; +} + +void VisualNovelPauseEvent::onEnd() { + +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelPauseEvent.hpp b/src/dawn/visualnovel/events/VisualNovelPauseEvent.hpp new file mode 100644 index 00000000..439e9e22 --- /dev/null +++ b/src/dawn/visualnovel/events/VisualNovelPauseEvent.hpp @@ -0,0 +1,28 @@ +// 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 VisualNovelPauseEvent : public IVisualNovelEvent { + protected: + float_t time; + float_t duration; + + void onStart(IVisualNovelEvent *previous) override; + bool_t onUpdate() override; + void onEnd() override; + + public: + /** + * Create a new Visual Novel Pause Event. + * + * @param manager Manager this event belongs to. + * @param duration Duration to pause for. + */ + VisualNovelPauseEvent(VisualNovelManager *manager, float_t duration); + }; +} \ No newline at end of file diff --git a/src/dawnpokergame/scenes/TestScene.hpp b/src/dawnpokergame/scenes/TestScene.hpp index b16d8f10..d13bdf8d 100644 --- a/src/dawnpokergame/scenes/TestScene.hpp +++ b/src/dawnpokergame/scenes/TestScene.hpp @@ -11,11 +11,11 @@ #include "ui/PokerGameTextbox.hpp" #include "visualnovel/VisualNovelManager.hpp" #include "visualnovel/events/VisualNovelTextboxEvent.hpp" +#include "visualnovel/events/VisualNovelPauseEvent.hpp" #include "visualnovel/events/VisualNovelFadeEvent.hpp" #include "poker/PokerGame.hpp" #include "visualnovel/events/PokerBetLoopEvent.hpp" #include "visualnovel/events/PokerInitialEvent.hpp" -#include "visualnovel/events/SimpleLoopEvent.hpp" #include "ui/PokerPlayerDisplay.hpp" #include "prefabs/VNPenny.hpp" @@ -45,7 +45,6 @@ namespace Dawn { // UI auto canvas = UICanvas::createCanvas(this); auto textbox = PokerGameTextbox::create(canvas); - auto vnFader = VisualNovelFader::create(canvas); // VN Manager auto vnManagerItem = this->createSceneItem(); @@ -62,10 +61,16 @@ namespace Dawn { uiPlayer->setTransform(UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START, glm::vec4(i * 220, 0, 220, 200), 0); uiPlayer->setPlayer(player->getComponent()); } + + auto vnFader = VisualNovelFader::create(canvas); auto betting = vnManager ->setEvent(new VisualNovelFadeEvent( - vnManager, COLOR_BLACK, true, &easeOutCubic, 5.0f + vnManager, COLOR_BLACK, true, &easeOutCubic, 0.0f + )) + ->then(new VisualNovelPauseEvent(vnManager, 1.0f)) + ->then(new VisualNovelFadeEvent( + vnManager, COLOR_BLACK, false, &easeOutCubic, 1.0f )) ->then(new VisualNovelTextboxEvent(vnManager, "Starting Game")) ->then(new PokerNewGameEvent(vnManager)) diff --git a/src/dawnpokergame/ui/PokerPlayerDisplay.cpp b/src/dawnpokergame/ui/PokerPlayerDisplay.cpp index a28897c0..87110f95 100644 --- a/src/dawnpokergame/ui/PokerPlayerDisplay.cpp +++ b/src/dawnpokergame/ui/PokerPlayerDisplay.cpp @@ -24,7 +24,7 @@ PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) : this->border.setTransform( UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, glm::vec4(0, 0, 0, 0), - -0.0f + 0.0f ); // Border Inner