Working on assets

This commit is contained in:
2022-12-01 22:37:42 -08:00
parent 535e2b2dc5
commit ba9881e39d
18 changed files with 355 additions and 42 deletions

View File

@ -22,13 +22,12 @@ int32_t DawnGame::init() {
this->assetManager.init();
this->renderManager.init();
this->scene = TestScene::create(this);
this->scene = new TestScene(this);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}
int32_t DawnGame::update(float_t delta) {
this->assetManager.update();
this->inputManager.update();
this->timeManager.update(delta);

View File

@ -6,6 +6,7 @@
#pragma once
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
#include "util/array.hpp"
#include "scene/components/Components.hpp"
#include "ui/PokerGameTextbox.hpp"
#include "visualnovel/VisualNovelManager.hpp"
@ -14,34 +15,48 @@
#include "visualnovel/events/PokerBetLoopEvent.hpp"
#include "visualnovel/events/PokerInitialEvent.hpp"
#include "visualnovel/events/SimpleLoopEvent.hpp"
#include "ui/PokerPlayerDisplay.hpp"
namespace Dawn {
class TestScene {
class TestScene : public Scene {
public:
static Scene * create(DawnGame *game) {
Scene *scene;
TestScene(DawnGame *game) : Scene(game) {
scene = new Scene(game);
}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, &PokerGameTextbox::getAssets(assMan));
return assets;
}
void stage() override {
// Camera
auto camera = Camera::create(scene);
auto camera = Camera::create(this);
camera->transform->lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0));
// UI
auto canvas = UICanvas::createCanvas(scene);
auto canvas = UICanvas::createCanvas(this);
auto textbox = PokerGameTextbox::create(canvas);
// VN Manager
auto vnManagerItem = scene->createSceneItem();
auto vnManagerItem = this->createSceneItem();
auto vnManager = vnManagerItem->addComponent<VisualNovelManager>();
// Poker Test
auto pokerGameItem = scene->createSceneItem();
auto pokerGameItem = this->createSceneItem();
auto pokerGame = pokerGameItem->addComponent<PokerGame>();
for(int32_t i = 0; i < 4; i++) {
auto pokerPlayerInstance = scene->createSceneItem();
auto pokerPlayerInstance = this->createSceneItem();
auto pokerPlayer = pokerPlayerInstance->addComponent<PokerPlayer>();
auto uiPlayer = canvas->addElement<PokerPlayerDisplay>();
uiPlayer->setTransform(UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_STRETCH, glm::vec4(0, 0, 0, 0), 0);
uiPlayer->setPlayer(pokerPlayer);
}
auto betting = vnManager
@ -50,8 +65,6 @@ namespace Dawn {
->then(new VisualNovelTextboxEvent(vnManager, "Game Started"))
->then(new PokerInitialEvent(vnManager))
;
return scene;
}
};
}

View File

@ -4,7 +4,7 @@
# https://opensource.org/licenses/MIT
# Sources
# target_sources(${DAWN_TARGET_NAME}
# PRIVATE
# PokerGameTextbox.cpp
# )
target_sources(${DAWN_TARGET_NAME}
PRIVATE
PokerPlayerDisplay.cpp
)

View File

@ -11,12 +11,20 @@
namespace Dawn {
class PokerGameTextbox {
public:
static VisualNovelTextbox * create(UICanvas *canvas) {
auto textbox = canvas->addElement<VisualNovelTextbox>();
auto assetFont = canvas->getGame()->assetManager.load<TrueTypeAsset>("truetype_ark");
auto assetTexture = canvas->getGame()->assetManager.load<TextureAsset>("texture_test");
static std::vector<Asset*> getAssets(AssetManager *man) {
return std::vector<Asset*>{
man->get<TrueTypeAsset>("truetype_ark"),
man->get<TextureAsset>("texture_test")
};
}
static VisualNovelTextbox * create(UICanvas *canvas) {
auto assMan = &canvas->getGame()->assetManager;
auto assetFont = assMan->get<TrueTypeAsset>("truetype_ark");
auto assetTexture = assMan->get<TextureAsset>("texture_test");
auto textbox = canvas->addElement<VisualNovelTextbox>();
textbox->setBorder(&assetTexture->texture, glm::vec2(16, 16));
textbox->setFont(&assetFont->font);
textbox->setFontSize(40);

View File

@ -0,0 +1,62 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PokerPlayerDisplay.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
void PokerPlayerDisplay::updatePositions() {
UIEmpty::updatePositions();
this->labelChips.setTransform(
UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START,
glm::vec4(0, this->labelName.getHeight(), 0, 0),
0
);
}
PokerPlayerDisplay::PokerPlayerDisplay(UICanvas *canvas) :
UIEmpty(canvas),
labelName(canvas),
labelChips(canvas)
{
this->font = canvas->getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
this->addChild(&this->labelName);
this->labelName.setFont(&this->font->font);
this->labelName.setFontSize(40);
this->labelName.setTransform(
UI_COMPONENT_ALIGN_START, UI_COMPONENT_ALIGN_START,
glm::vec4(0, 0, 0, 0),
0.0f
);
this->addChild(&this->labelChips);
this->labelChips.setFont(&this->font->font);
this->labelChips.setFontSize(40);
this->font->eventLoaded.addListener(this, &PokerPlayerDisplay::onFontLoaded);
}
void PokerPlayerDisplay::setPlayer(PokerPlayer *player) {
assertNull(this->player);
this->player = player;
this->labelName.setText("Player");
this->labelChips.setText("Chips");
this->updatePositions();
}
void PokerPlayerDisplay::onFontLoaded() {
this->labelName.setFont(&this->font->font);
this->labelChips.setFont(&this->font->font);
this->updatePositions();
}
PokerPlayerDisplay::~PokerPlayerDisplay() {
this->font->eventLoaded.removeListener(this, &PokerPlayerDisplay::onFontLoaded);
}

View File

@ -0,0 +1,32 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "ui/UILabel.hpp"
#include "ui/UIEmpty.hpp"
#include "poker/PokerPlayer.hpp"
#include "asset/assets/TrueTypeAsset.hpp"
namespace Dawn {
class PokerPlayerDisplay : public UIEmpty {
private:
void onFontLoaded();
protected:
PokerPlayer *player = nullptr;
UILabel labelName;
UILabel labelChips;
TrueTypeAsset *font;
void updatePositions() override;
public:
PokerPlayerDisplay(UICanvas *canvas);
void setPlayer(PokerPlayer *player);
~PokerPlayerDisplay();
};
}