Example Poker VN Scene

This commit is contained in:
2022-12-14 08:35:50 -08:00
parent 6404f35b1c
commit 2f48f61e9a
9 changed files with 140 additions and 45 deletions

View File

@ -6,5 +6,6 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
VisualNovelFader.cpp
VisualNovelTextbox.cpp
)

View File

@ -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<VisualNovelFader>();
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;
}

View File

@ -12,18 +12,21 @@ namespace Dawn {
private:
public:
static VisualNovelFader * create(UICanvas *canvas) {
assertNotNull(canvas);
auto item = canvas->addElement<VisualNovelFader>();
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);
};
}

View File

@ -7,4 +7,5 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
SimpleVNScene.cpp
PokerVNScene.cpp
)

View File

@ -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<Asset*> PokerVNScene::getRequiredAssets() {
auto assMan = &this->game->assetManager;
std::vector<Asset*> 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<PokerGame>();
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<PokerPlayerDisplay>();
uiPlayer->setTransform(UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START, glm::vec4(i * 220, 0, 220, 200), 0);
uiPlayer->setPlayer(player);
++it;
++i;
}
}

View File

@ -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<PokerPlayer*> getPokerPlayers() = 0;
void vnStage() override;
std::vector<Asset*> getRequiredAssets() override;
public:
PokerGame *pokerGame;
std::vector<PokerPlayer*> pokerPlayers;
std::map<PokerPlayer*, PokerPlayerDisplay*> 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);
};
}

View File

@ -14,13 +14,7 @@ SimpleVNScene::SimpleVNScene(DawnGame *game) : Scene(game) {
std::vector<Asset*> SimpleVNScene::getRequiredAssets() {
auto assMan = &this->game->assetManager;
std::vector<Asset*> 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() {

View File

@ -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 {

View File

@ -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<PokerGame>();
for(int32_t i = 0; i < 5; i++) {
auto player = VNPenny::create(this);
auto uiPlayer = canvas->addElement<PokerPlayerDisplay>();
uiPlayer->setTransform(UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START, glm::vec4(i * 220, 0, 220, 200), 0);
uiPlayer->setPlayer(player->getComponent<PokerPlayer>());
}
PokerVNScene::vnStage();
}
std::vector<PokerPlayer *> getPokerPlayers() override {
return std::vector<PokerPlayer*>{
this->penny->getComponent<PokerPlayer>(),
this->julie->getComponent<PokerPlayer>(),
this->sammy->getComponent<PokerPlayer>(),
this->lucy->getComponent<PokerPlayer>()
};
}
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<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, &SimpleVNScene::getRequiredAssets());
vectorAppend(&assets, &PokerVNScene::getRequiredAssets());
vectorAppend(&assets, &VNPenny::getAssets(assMan));
assets.push_back(assMan->get<TextureAsset>("texture_tavern_night"));
return assets;
}