Example Poker VN Scene
This commit is contained in:
@ -6,5 +6,6 @@
|
|||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
VisualNovelFader.cpp
|
||||||
VisualNovelTextbox.cpp
|
VisualNovelTextbox.cpp
|
||||||
)
|
)
|
25
src/dawn/visualnovel/ui/VisualNovelFader.cpp
Normal file
25
src/dawn/visualnovel/ui/VisualNovelFader.cpp
Normal 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;
|
||||||
|
}
|
@ -12,18 +12,21 @@ namespace Dawn {
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static VisualNovelFader * create(UICanvas *canvas) {
|
/**
|
||||||
assertNotNull(canvas);
|
* Quickly create a visual novel fader.
|
||||||
auto item = canvas->addElement<VisualNovelFader>();
|
*
|
||||||
item->setTransform(
|
* @param canvas Canvas the fader belongs to.
|
||||||
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH,
|
* @return Created VN Fader.
|
||||||
glm::vec4(0, 0, 0, 0),
|
*/
|
||||||
0.0f
|
static VisualNovelFader * create(UICanvas *canvas);
|
||||||
);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -7,4 +7,5 @@
|
|||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
SimpleVNScene.cpp
|
SimpleVNScene.cpp
|
||||||
|
PokerVNScene.cpp
|
||||||
)
|
)
|
40
src/dawnpokergame/scenes/PokerVNScene.cpp
Normal file
40
src/dawnpokergame/scenes/PokerVNScene.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
33
src/dawnpokergame/scenes/PokerVNScene.hpp
Normal file
33
src/dawnpokergame/scenes/PokerVNScene.hpp
Normal 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);
|
||||||
|
};
|
||||||
|
}
|
@ -14,13 +14,7 @@ SimpleVNScene::SimpleVNScene(DawnGame *game) : Scene(game) {
|
|||||||
|
|
||||||
std::vector<Asset*> SimpleVNScene::getRequiredAssets() {
|
std::vector<Asset*> SimpleVNScene::getRequiredAssets() {
|
||||||
auto assMan = &this->game->assetManager;
|
auto assMan = &this->game->assetManager;
|
||||||
std::vector<Asset*> assets;
|
return PokerGameTextbox::getAssets(assMan);
|
||||||
|
|
||||||
vectorAppend(&assets, &PokerGameTextbox::getAssets(assMan));
|
|
||||||
vectorAppend(&assets, &PokerPlayerDisplay::getAssets(assMan));
|
|
||||||
vectorAppend(&assets, &VNPenny::getAssets(assMan));
|
|
||||||
|
|
||||||
return assets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleVNScene::stage() {
|
void SimpleVNScene::stage() {
|
||||||
|
@ -14,11 +14,6 @@
|
|||||||
#include "visualnovel/events/VisualNovelPauseEvent.hpp"
|
#include "visualnovel/events/VisualNovelPauseEvent.hpp"
|
||||||
#include "visualnovel/events/VisualNovelFadeEvent.hpp"
|
#include "visualnovel/events/VisualNovelFadeEvent.hpp"
|
||||||
#include "visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.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 {
|
namespace Dawn {
|
||||||
class SimpleVNScene : public Scene {
|
class SimpleVNScene : public Scene {
|
||||||
|
@ -4,27 +4,33 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "SimpleVNScene.hpp"
|
#include "PokerVNScene.hpp"
|
||||||
|
#include "prefabs/VNPenny.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class TestScene : public SimpleVNScene {
|
class TestScene : public PokerVNScene {
|
||||||
protected:
|
protected:
|
||||||
|
SceneItem *penny;
|
||||||
|
SceneItem *julie;
|
||||||
|
SceneItem *sammy;
|
||||||
|
SceneItem *lucy;
|
||||||
|
|
||||||
void vnStage() override {
|
void vnStage() override {
|
||||||
SimpleVNScene::vnStage();
|
penny = VNPenny::create(this);
|
||||||
|
julie = VNPenny::create(this);
|
||||||
|
sammy = VNPenny::create(this);
|
||||||
|
lucy = VNPenny::create(this);
|
||||||
|
|
||||||
// Poker Test
|
PokerVNScene::vnStage();
|
||||||
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>());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
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 {
|
IVisualNovelEvent * getVNEvent() override {
|
||||||
@ -35,10 +41,6 @@ namespace Dawn {
|
|||||||
);
|
);
|
||||||
|
|
||||||
start
|
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 VisualNovelTextboxEvent(vnManager, "Starting Game"))
|
||||||
->then(new PokerNewGameEvent(vnManager))
|
->then(new PokerNewGameEvent(vnManager))
|
||||||
->then(new VisualNovelTextboxEvent(vnManager, "Game Started"))
|
->then(new VisualNovelTextboxEvent(vnManager, "Game Started"))
|
||||||
@ -49,14 +51,15 @@ namespace Dawn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestScene(DawnGame *game) : SimpleVNScene(game) {
|
TestScene(DawnGame *game) : PokerVNScene(game) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Asset*> getRequiredAssets() override {
|
std::vector<Asset*> getRequiredAssets() override {
|
||||||
auto assMan = &this->game->assetManager;
|
auto assMan = &this->game->assetManager;
|
||||||
std::vector<Asset*> assets;
|
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"));
|
assets.push_back(assMan->get<TextureAsset>("texture_tavern_night"));
|
||||||
return assets;
|
return assets;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user