From 2f48f61e9aee33c80ac0f4237e822384359b3a1f Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 14 Dec 2022 08:35:50 -0800 Subject: [PATCH] Example Poker VN Scene --- src/dawn/visualnovel/ui/CMakeLists.txt | 1 + src/dawn/visualnovel/ui/VisualNovelFader.cpp | 25 +++++++++++ src/dawn/visualnovel/ui/VisualNovelFader.hpp | 27 ++++++------ src/dawnpokergame/scenes/CMakeLists.txt | 1 + src/dawnpokergame/scenes/PokerVNScene.cpp | 40 +++++++++++++++++ src/dawnpokergame/scenes/PokerVNScene.hpp | 33 ++++++++++++++ src/dawnpokergame/scenes/SimpleVNScene.cpp | 8 +--- src/dawnpokergame/scenes/SimpleVNScene.hpp | 5 --- src/dawnpokergame/scenes/TestScene.hpp | 45 +++++++++++--------- 9 files changed, 140 insertions(+), 45 deletions(-) create mode 100644 src/dawn/visualnovel/ui/VisualNovelFader.cpp create mode 100644 src/dawnpokergame/scenes/PokerVNScene.cpp create mode 100644 src/dawnpokergame/scenes/PokerVNScene.hpp diff --git a/src/dawn/visualnovel/ui/CMakeLists.txt b/src/dawn/visualnovel/ui/CMakeLists.txt index 4df3e017..79d3bf82 100644 --- a/src/dawn/visualnovel/ui/CMakeLists.txt +++ b/src/dawn/visualnovel/ui/CMakeLists.txt @@ -6,5 +6,6 @@ # Sources target_sources(${DAWN_TARGET_NAME} PRIVATE + VisualNovelFader.cpp VisualNovelTextbox.cpp ) \ No newline at end of file diff --git a/src/dawn/visualnovel/ui/VisualNovelFader.cpp b/src/dawn/visualnovel/ui/VisualNovelFader.cpp new file mode 100644 index 00000000..7127e814 --- /dev/null +++ b/src/dawn/visualnovel/ui/VisualNovelFader.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "VisualNovelFader.hpp" + +using namespace Dawn; + +VisualNovelFader::VisualNovelFader(UICanvas *canvas) : UISprite(canvas) { + +} + +VisualNovelFader * VisualNovelFader::create(UICanvas *canvas) { + assertNotNull(canvas); + + auto item = canvas->addElement(); + item->setTransform( + UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, + glm::vec4(0, 0, 0, 0), + 0.0f + ); + item->color = COLOR_BLACK_TRANSPARENT; + return item; +} \ No newline at end of file diff --git a/src/dawn/visualnovel/ui/VisualNovelFader.hpp b/src/dawn/visualnovel/ui/VisualNovelFader.hpp index 32b203f8..0b4f1d41 100644 --- a/src/dawn/visualnovel/ui/VisualNovelFader.hpp +++ b/src/dawn/visualnovel/ui/VisualNovelFader.hpp @@ -12,18 +12,21 @@ namespace Dawn { private: public: - static VisualNovelFader * create(UICanvas *canvas) { - assertNotNull(canvas); - auto item = canvas->addElement(); - item->setTransform( - UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, - glm::vec4(0, 0, 0, 0), - 0.0f - ); - return item; - } + /** + * Quickly create a visual novel fader. + * + * @param canvas Canvas the fader belongs to. + * @return Created VN Fader. + */ + static VisualNovelFader * create(UICanvas *canvas); - VisualNovelFader(UICanvas *canvas) : UISprite(canvas) { - } + /** + * Construct a new Visual Novel Fader. VN Fader is just a sprite that is + * easily found by the VN Manager for the purpose of adding transitions to + * a VN scene. + * + * @param canvas Canvas for this component. + */ + VisualNovelFader(UICanvas *canvas); }; } \ No newline at end of file diff --git a/src/dawnpokergame/scenes/CMakeLists.txt b/src/dawnpokergame/scenes/CMakeLists.txt index 7aa8a484..1af2b17d 100644 --- a/src/dawnpokergame/scenes/CMakeLists.txt +++ b/src/dawnpokergame/scenes/CMakeLists.txt @@ -7,4 +7,5 @@ target_sources(${DAWN_TARGET_NAME} PRIVATE SimpleVNScene.cpp + PokerVNScene.cpp ) \ No newline at end of file diff --git a/src/dawnpokergame/scenes/PokerVNScene.cpp b/src/dawnpokergame/scenes/PokerVNScene.cpp new file mode 100644 index 00000000..65219b9e --- /dev/null +++ b/src/dawnpokergame/scenes/PokerVNScene.cpp @@ -0,0 +1,40 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "PokerVNScene.hpp" + +using namespace Dawn; + +PokerVNScene::PokerVNScene(DawnGame *game) : SimpleVNScene(game) { + +} + +std::vector PokerVNScene::getRequiredAssets() { + auto assMan = &this->game->assetManager; + std::vector assets; + vectorAppend(&assets, &SimpleVNScene::getRequiredAssets()); + vectorAppend(&assets, &PokerPlayerDisplay::getAssets(assMan)); + return assets; +} + +void PokerVNScene::vnStage() { + SimpleVNScene::vnStage(); + + auto pokerGameItem = this->createSceneItem(); + this->pokerGame = pokerGameItem->addComponent(); + + this->pokerPlayers = this->getPokerPlayers(); + + auto it = this->pokerPlayers.begin(); + int32_t i = 0; + while(it != this->pokerPlayers.end()) { + auto player = *it; + auto uiPlayer = canvas->addElement(); + uiPlayer->setTransform(UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START, glm::vec4(i * 220, 0, 220, 200), 0); + uiPlayer->setPlayer(player); + ++it; + ++i; + } +} \ No newline at end of file diff --git a/src/dawnpokergame/scenes/PokerVNScene.hpp b/src/dawnpokergame/scenes/PokerVNScene.hpp new file mode 100644 index 00000000..3f17e179 --- /dev/null +++ b/src/dawnpokergame/scenes/PokerVNScene.hpp @@ -0,0 +1,33 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "SimpleVNScene.hpp" +#include "poker/PokerGame.hpp" +#include "visualnovel/events/PokerBetLoopEvent.hpp" +#include "visualnovel/events/PokerInitialEvent.hpp" +#include "ui/PokerPlayerDisplay.hpp" + +namespace Dawn { + class PokerVNScene : public SimpleVNScene { + protected: + virtual std::vector getPokerPlayers() = 0; + void vnStage() override; + std::vector getRequiredAssets() override; + + public: + PokerGame *pokerGame; + std::vector pokerPlayers; + std::map pokerPlayerDisplays; + + /** + * Create a simple Poker Visual Novel Scene. Simplifies some of the less + * interesting parts of a poker VN game. + * + * @param game Game that this poker scene belongs to. + */ + PokerVNScene(DawnGame *game); + }; +} \ No newline at end of file diff --git a/src/dawnpokergame/scenes/SimpleVNScene.cpp b/src/dawnpokergame/scenes/SimpleVNScene.cpp index c3b2549e..3680faf2 100644 --- a/src/dawnpokergame/scenes/SimpleVNScene.cpp +++ b/src/dawnpokergame/scenes/SimpleVNScene.cpp @@ -14,13 +14,7 @@ SimpleVNScene::SimpleVNScene(DawnGame *game) : Scene(game) { std::vector SimpleVNScene::getRequiredAssets() { auto assMan = &this->game->assetManager; - std::vector assets; - - vectorAppend(&assets, &PokerGameTextbox::getAssets(assMan)); - vectorAppend(&assets, &PokerPlayerDisplay::getAssets(assMan)); - vectorAppend(&assets, &VNPenny::getAssets(assMan)); - - return assets; + return PokerGameTextbox::getAssets(assMan); } void SimpleVNScene::stage() { diff --git a/src/dawnpokergame/scenes/SimpleVNScene.hpp b/src/dawnpokergame/scenes/SimpleVNScene.hpp index e1548c05..60d293e0 100644 --- a/src/dawnpokergame/scenes/SimpleVNScene.hpp +++ b/src/dawnpokergame/scenes/SimpleVNScene.hpp @@ -14,11 +14,6 @@ #include "visualnovel/events/VisualNovelPauseEvent.hpp" #include "visualnovel/events/VisualNovelFadeEvent.hpp" #include "visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp" -#include "poker/PokerGame.hpp" -#include "visualnovel/events/PokerBetLoopEvent.hpp" -#include "visualnovel/events/PokerInitialEvent.hpp" -#include "ui/PokerPlayerDisplay.hpp" -#include "prefabs/VNPenny.hpp" namespace Dawn { class SimpleVNScene : public Scene { diff --git a/src/dawnpokergame/scenes/TestScene.hpp b/src/dawnpokergame/scenes/TestScene.hpp index 1be66994..4fc53389 100644 --- a/src/dawnpokergame/scenes/TestScene.hpp +++ b/src/dawnpokergame/scenes/TestScene.hpp @@ -4,27 +4,33 @@ // https://opensource.org/licenses/MIT #pragma once -#include "SimpleVNScene.hpp" +#include "PokerVNScene.hpp" +#include "prefabs/VNPenny.hpp" namespace Dawn { - class TestScene : public SimpleVNScene { + class TestScene : public PokerVNScene { protected: + SceneItem *penny; + SceneItem *julie; + SceneItem *sammy; + SceneItem *lucy; + void vnStage() override { - SimpleVNScene::vnStage(); + penny = VNPenny::create(this); + julie = VNPenny::create(this); + sammy = VNPenny::create(this); + lucy = VNPenny::create(this); - // Poker Test - auto pokerGameItem = this->createSceneItem(); - auto pokerGame = pokerGameItem->addComponent(); - - for(int32_t i = 0; i < 5; i++) { - auto player = VNPenny::create(this); - - auto uiPlayer = canvas->addElement(); - uiPlayer->setTransform(UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START, glm::vec4(i * 220, 0, 220, 200), 0); - uiPlayer->setPlayer(player->getComponent()); - } - + PokerVNScene::vnStage(); + } + std::vector getPokerPlayers() override { + return std::vector{ + this->penny->getComponent(), + this->julie->getComponent(), + this->sammy->getComponent(), + this->lucy->getComponent() + }; } IVisualNovelEvent * getVNEvent() override { @@ -35,10 +41,6 @@ namespace Dawn { ); start - ->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)) ->then(new VisualNovelTextboxEvent(vnManager, "Game Started")) @@ -49,14 +51,15 @@ namespace Dawn { } public: - TestScene(DawnGame *game) : SimpleVNScene(game) { + TestScene(DawnGame *game) : PokerVNScene(game) { } std::vector getRequiredAssets() override { auto assMan = &this->game->assetManager; std::vector assets; - vectorAppend(&assets, &SimpleVNScene::getRequiredAssets()); + vectorAppend(&assets, &PokerVNScene::getRequiredAssets()); + vectorAppend(&assets, &VNPenny::getAssets(assMan)); assets.push_back(assMan->get("texture_tavern_night")); return assets; }