Working on assets
This commit is contained in:
@ -50,7 +50,6 @@ static inline void assertTrue(bool_t x) {}
|
|||||||
* Asserts a function as being deprecated.
|
* Asserts a function as being deprecated.
|
||||||
*/
|
*/
|
||||||
void assertDeprecated();
|
void assertDeprecated();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define assertTrue assert
|
#define assertTrue assert
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawnlibs.hpp"
|
||||||
#include "assert/assert.hpp"
|
#include "assert/assert.hpp"
|
||||||
|
#include "event/Event.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class AssetManager;
|
class AssetManager;
|
||||||
@ -16,6 +17,7 @@ namespace Dawn {
|
|||||||
std::string name;
|
std::string name;
|
||||||
uint8_t state = 0x00;
|
uint8_t state = 0x00;
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
|
Event<> eventLoaded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an abstract Asset object.
|
* Create an abstract Asset object.
|
||||||
|
@ -15,26 +15,72 @@ void AssetManager::init() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::update() {
|
void AssetManager::queueLoad(std::vector<Asset*> assets) {
|
||||||
auto it = this->assetsNotLoaded.begin();
|
vectorAppend(&this->assetsToLoad, &assets);
|
||||||
while(it != this->assetsNotLoaded.end()) {
|
}
|
||||||
auto asset = it->second;
|
|
||||||
|
void AssetManager::queueUnload(std::vector<Asset*> assets) {
|
||||||
|
vectorAppend(&this->assetsToUnload, &assets);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetManager::queueSwap(
|
||||||
|
std::vector<Asset*> newAssets,
|
||||||
|
std::vector<Asset*> oldAssets
|
||||||
|
) {
|
||||||
|
std::vector<Asset*> unload;
|
||||||
|
std::vector<Asset*> load;
|
||||||
|
|
||||||
|
// Determine assets to unload.
|
||||||
|
auto itUnload = oldAssets.begin();
|
||||||
|
while(itUnload != oldAssets.end()) {
|
||||||
|
auto inNewAssets = std::find(newAssets.begin(), newAssets.end(), *itUnload);
|
||||||
|
if(inNewAssets == oldAssets.end()) unload.push_back(*itUnload);
|
||||||
|
++itUnload;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine assets to load
|
||||||
|
auto itLoad = newAssets.begin();
|
||||||
|
while(itLoad != newAssets.end()) {
|
||||||
|
auto inOldAssets = std::find(oldAssets.begin(), oldAssets.end(), *itLoad);
|
||||||
|
if(inOldAssets == oldAssets.end()) load.push_back(*itLoad);
|
||||||
|
++itLoad;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->queueUnload(unload);
|
||||||
|
this->queueLoad(load);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetManager::syncTick() {
|
||||||
|
auto it = this->assetsToLoad.begin();
|
||||||
|
// auto it = this->assetsNotLoaded.begin();
|
||||||
|
while(it != this->assetsToLoad.end()) {
|
||||||
|
auto asset = *it;
|
||||||
if(asset->loaded) {
|
if(asset->loaded) {
|
||||||
it = this->assetsNotLoaded.erase(it);
|
it = this->assetsToLoad.erase(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
asset->updateSync();
|
asset->updateSync();
|
||||||
asset->updateAsync();
|
asset->updateAsync();//TODO: Make Async
|
||||||
|
|
||||||
if(asset->loaded) {
|
if(asset->loaded) {
|
||||||
it = this->assetsNotLoaded.erase(it);
|
it = this->assetsToLoad.erase(it);
|
||||||
this->assets[asset->name] = asset;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// auto it2 = this->assetsToUnload.begin();
|
||||||
|
// while(it2 != this->assetsToUnload.end()) {
|
||||||
|
// ++it2;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetManager::syncLoad() {
|
||||||
|
while(this->assetsToLoad.size() > 0) {
|
||||||
|
this->syncTick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetManager::~AssetManager() {
|
AssetManager::~AssetManager() {
|
||||||
@ -43,10 +89,4 @@ AssetManager::~AssetManager() {
|
|||||||
delete it->second;
|
delete it->second;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it2 = this->assetsNotLoaded.begin();
|
|
||||||
while(it2 != this->assetsNotLoaded.end()) {
|
|
||||||
delete it2->second;
|
|
||||||
++it2;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -5,13 +5,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Asset.hpp"
|
#include "Asset.hpp"
|
||||||
|
#include "util/array.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class AssetManager {
|
class AssetManager {
|
||||||
private:
|
private:
|
||||||
/** List of pointers to assets, mapped by their asset key. */
|
/** List of pointers to assets, mapped by their asset key. */
|
||||||
std::map<std::string, Asset*> assets;
|
std::map<std::string, Asset*> assets;
|
||||||
std::map<std::string, Asset*> assetsNotLoaded;
|
std::vector<Asset*> assetsToLoad;
|
||||||
|
std::vector<Asset*> assetsToUnload;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -20,9 +22,41 @@ namespace Dawn {
|
|||||||
void init();
|
void init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ticks the asset manager for a single frame, synchronously.
|
* Queue a loading of a list of assets. Does not actually begin loading.
|
||||||
|
*
|
||||||
|
* @param assets Assets to load.
|
||||||
*/
|
*/
|
||||||
void update();
|
void queueLoad(std::vector<Asset*> assets);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a list of lists to queue to unload. Does not immediately unload.
|
||||||
|
*
|
||||||
|
* @param assets Assets to unload.
|
||||||
|
*/
|
||||||
|
void queueUnload(std::vector<Asset*> assets);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queues load and unload based on the difference between two sets of
|
||||||
|
* assets. This is mostly used to perform a scene change.
|
||||||
|
*
|
||||||
|
* @param newAssets New list of assets to maintain.
|
||||||
|
* @param oldAssets Old list of assets to no longer maintain.
|
||||||
|
*/
|
||||||
|
void queueSwap(
|
||||||
|
std::vector<Asset*> newAssets,
|
||||||
|
std::vector<Asset*> oldAssets
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ticks the asset manager, synchronously.
|
||||||
|
*/
|
||||||
|
void syncTick();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads everything that isn't loaded, blocks the current thread until
|
||||||
|
* that has finished.
|
||||||
|
*/
|
||||||
|
void syncLoad();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and queue an asset to load.
|
* Creates and queue an asset to load.
|
||||||
@ -31,7 +65,7 @@ namespace Dawn {
|
|||||||
* @return The asset element to be loaded.
|
* @return The asset element to be loaded.
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
T * load(std::string name) {
|
T * get(std::string name) {
|
||||||
assertTrue(name.size() > 0);
|
assertTrue(name.size() > 0);
|
||||||
|
|
||||||
auto existing = this->assets.find(name);
|
auto existing = this->assets.find(name);
|
||||||
@ -40,7 +74,6 @@ namespace Dawn {
|
|||||||
}
|
}
|
||||||
auto asset = new T(this, name);
|
auto asset = new T(this, name);
|
||||||
this->assets[name] = asset;
|
this->assets[name] = asset;
|
||||||
this->assetsNotLoaded[name] = asset;
|
|
||||||
return asset;
|
return asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ void TextureAsset::updateSync() {
|
|||||||
this->texture.buffer(this->colors);
|
this->texture.buffer(this->colors);
|
||||||
this->state = 0x05;
|
this->state = 0x05;
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
|
this->eventLoaded.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAsset::updateAsync() {
|
void TextureAsset::updateAsync() {
|
||||||
|
@ -29,6 +29,7 @@ void TrueTypeAsset::updateSync() {
|
|||||||
|
|
||||||
this->state = 0x05;
|
this->state = 0x05;
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
|
this->eventLoaded.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrueTypeAsset::updateAsync() {
|
void TrueTypeAsset::updateAsync() {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "SceneItem.hpp"
|
#include "SceneItem.hpp"
|
||||||
#include "event/Event.hpp"
|
#include "event/Event.hpp"
|
||||||
|
#include "asset/Asset.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class DawnGame;
|
class DawnGame;
|
||||||
@ -41,6 +42,21 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
SceneItem * createSceneItem();
|
SceneItem * createSceneItem();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the required assets for this scene. Assets required are meant
|
||||||
|
* to be referenced back to the loader so that special loading actions can
|
||||||
|
* be performed against them.
|
||||||
|
*
|
||||||
|
* @return List of assets required by this scene.
|
||||||
|
*/
|
||||||
|
virtual std::vector<Asset*> getRequiredAssets() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to begin the actual staging of the scene, typically called after
|
||||||
|
* the scene has finished loading.
|
||||||
|
*/
|
||||||
|
virtual void stage() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds an existing component on the scene (Root Level Only) that has a
|
* Finds an existing component on the scene (Root Level Only) that has a
|
||||||
* component matching the given component type. Returns nullptr if no item
|
* component matching the given component type. Returns nullptr if no item
|
||||||
|
@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
|
|||||||
UILabel.cpp
|
UILabel.cpp
|
||||||
UISprite.cpp
|
UISprite.cpp
|
||||||
UIEmpty.cpp
|
UIEmpty.cpp
|
||||||
|
UIGrid.cpp
|
||||||
)
|
)
|
35
src/dawn/ui/UIGrid.cpp
Normal file
35
src/dawn/ui/UIGrid.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "UIGrid.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
UIGrid::UIGrid(UICanvas *canvas) : UIComponent(canvas) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIGrid::setSize(int32_t rows, int32_t columns) {
|
||||||
|
this->gridArea.clear();
|
||||||
|
|
||||||
|
this->rows = rows;
|
||||||
|
this->columns = columns;
|
||||||
|
|
||||||
|
int32_t i, l;
|
||||||
|
l = rows * columns;
|
||||||
|
for(i = 0; i < l; i++) {
|
||||||
|
struct GridArea area;
|
||||||
|
area.uiComponent = nullptr;
|
||||||
|
this->gridArea.push_back(area);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIGrid::setItem(int32_t x, int32_t y, UIComponent *comp) {
|
||||||
|
auto item = &this->gridArea[(y * this->rows) + x];
|
||||||
|
|
||||||
|
//Too lazy to support re setting. Need to mod setSize too
|
||||||
|
assertNull(item->uiComponent);
|
||||||
|
|
||||||
|
item->uiComponent = comp;
|
||||||
|
}
|
41
src/dawn/ui/UIGrid.hpp
Normal file
41
src/dawn/ui/UIGrid.hpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "UIComponent.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
enum GridAlign {
|
||||||
|
ALIGN_GROW,
|
||||||
|
ALIGN_CONTENT,
|
||||||
|
ALIGN_FIXED
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GridArea {
|
||||||
|
enum GridAlignment xAlign;
|
||||||
|
enum GridAlignment yAlign;
|
||||||
|
float_t width, height;
|
||||||
|
float_t x, y;
|
||||||
|
UIComponent *uiComponent;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UIGrid : public UIComponent {
|
||||||
|
protected:
|
||||||
|
void alignChildren();
|
||||||
|
|
||||||
|
public:
|
||||||
|
glm::vec2 cellPadding;
|
||||||
|
glm::vec2 cellMargin;
|
||||||
|
int32_t rows = 1;
|
||||||
|
int32_t columns = 1;
|
||||||
|
std::vector<struct GridArea> gridArea;
|
||||||
|
|
||||||
|
UIGrid(UICanvas *canvas);
|
||||||
|
|
||||||
|
void setSize(int32_t rows, int32_t columns);
|
||||||
|
|
||||||
|
void setItem(int32_t row, int32_t col, UIComponent *comp);
|
||||||
|
};
|
||||||
|
}
|
22
src/dawn/util/array.hpp
Normal file
22
src/dawn/util/array.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawnlibs.hpp"
|
||||||
|
#include "assert/assert.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
template<typename T>
|
||||||
|
void vectorAppend(std::vector<T> *list, std::vector<T> *append) {
|
||||||
|
assertNotNull(list);
|
||||||
|
assertNotNull(append);
|
||||||
|
|
||||||
|
auto it = append->begin();
|
||||||
|
while(it != append->end()) {
|
||||||
|
list->push_back(*it);
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -65,6 +65,14 @@ int32_t DawnHost::init(DawnGame *game) {
|
|||||||
auto result = game->init();
|
auto result = game->init();
|
||||||
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
|
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
|
||||||
|
|
||||||
|
// Hard-Load the first scene assets.
|
||||||
|
if(game->scene != nullptr) {
|
||||||
|
auto assets = game->scene->getRequiredAssets();
|
||||||
|
game->assetManager.queueLoad(assets);
|
||||||
|
game->assetManager.syncLoad();
|
||||||
|
game->scene->stage();
|
||||||
|
}
|
||||||
|
|
||||||
// Set up event listeners
|
// Set up event listeners
|
||||||
glfwSetWindowSizeCallback(this->data->window, &glfwOnResize);
|
glfwSetWindowSizeCallback(this->data->window, &glfwOnResize);
|
||||||
glfwSetKeyCallback(this->data->window, &glfwOnKey);
|
glfwSetKeyCallback(this->data->window, &glfwOnKey);
|
||||||
|
@ -22,13 +22,12 @@ int32_t DawnGame::init() {
|
|||||||
this->assetManager.init();
|
this->assetManager.init();
|
||||||
this->renderManager.init();
|
this->renderManager.init();
|
||||||
|
|
||||||
this->scene = TestScene::create(this);
|
this->scene = new TestScene(this);
|
||||||
|
|
||||||
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t DawnGame::update(float_t delta) {
|
int32_t DawnGame::update(float_t delta) {
|
||||||
this->assetManager.update();
|
|
||||||
this->inputManager.update();
|
this->inputManager.update();
|
||||||
this->timeManager.update(delta);
|
this->timeManager.update(delta);
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "scene/Scene.hpp"
|
#include "scene/Scene.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
|
#include "util/array.hpp"
|
||||||
#include "scene/components/Components.hpp"
|
#include "scene/components/Components.hpp"
|
||||||
#include "ui/PokerGameTextbox.hpp"
|
#include "ui/PokerGameTextbox.hpp"
|
||||||
#include "visualnovel/VisualNovelManager.hpp"
|
#include "visualnovel/VisualNovelManager.hpp"
|
||||||
@ -14,34 +15,48 @@
|
|||||||
#include "visualnovel/events/PokerBetLoopEvent.hpp"
|
#include "visualnovel/events/PokerBetLoopEvent.hpp"
|
||||||
#include "visualnovel/events/PokerInitialEvent.hpp"
|
#include "visualnovel/events/PokerInitialEvent.hpp"
|
||||||
#include "visualnovel/events/SimpleLoopEvent.hpp"
|
#include "visualnovel/events/SimpleLoopEvent.hpp"
|
||||||
|
#include "ui/PokerPlayerDisplay.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class TestScene {
|
class TestScene : public Scene {
|
||||||
public:
|
public:
|
||||||
static Scene * create(DawnGame *game) {
|
TestScene(DawnGame *game) : Scene(game) {
|
||||||
Scene *scene;
|
|
||||||
|
|
||||||
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
|
// Camera
|
||||||
auto camera = Camera::create(scene);
|
auto camera = Camera::create(this);
|
||||||
camera->transform->lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0));
|
camera->transform->lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0));
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
auto canvas = UICanvas::createCanvas(scene);
|
auto canvas = UICanvas::createCanvas(this);
|
||||||
auto textbox = PokerGameTextbox::create(canvas);
|
auto textbox = PokerGameTextbox::create(canvas);
|
||||||
|
|
||||||
// VN Manager
|
// VN Manager
|
||||||
auto vnManagerItem = scene->createSceneItem();
|
auto vnManagerItem = this->createSceneItem();
|
||||||
auto vnManager = vnManagerItem->addComponent<VisualNovelManager>();
|
auto vnManager = vnManagerItem->addComponent<VisualNovelManager>();
|
||||||
|
|
||||||
// Poker Test
|
// Poker Test
|
||||||
auto pokerGameItem = scene->createSceneItem();
|
auto pokerGameItem = this->createSceneItem();
|
||||||
auto pokerGame = pokerGameItem->addComponent<PokerGame>();
|
auto pokerGame = pokerGameItem->addComponent<PokerGame>();
|
||||||
|
|
||||||
for(int32_t i = 0; i < 4; i++) {
|
for(int32_t i = 0; i < 4; i++) {
|
||||||
auto pokerPlayerInstance = scene->createSceneItem();
|
auto pokerPlayerInstance = this->createSceneItem();
|
||||||
auto pokerPlayer = pokerPlayerInstance->addComponent<PokerPlayer>();
|
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
|
auto betting = vnManager
|
||||||
@ -50,8 +65,6 @@ namespace Dawn {
|
|||||||
->then(new VisualNovelTextboxEvent(vnManager, "Game Started"))
|
->then(new VisualNovelTextboxEvent(vnManager, "Game Started"))
|
||||||
->then(new PokerInitialEvent(vnManager))
|
->then(new PokerInitialEvent(vnManager))
|
||||||
;
|
;
|
||||||
|
|
||||||
return scene;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -4,7 +4,7 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
# target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
# PRIVATE
|
PRIVATE
|
||||||
# PokerGameTextbox.cpp
|
PokerPlayerDisplay.cpp
|
||||||
# )
|
)
|
@ -11,12 +11,20 @@
|
|||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class PokerGameTextbox {
|
class PokerGameTextbox {
|
||||||
public:
|
public:
|
||||||
static VisualNovelTextbox * create(UICanvas *canvas) {
|
static std::vector<Asset*> getAssets(AssetManager *man) {
|
||||||
auto textbox = canvas->addElement<VisualNovelTextbox>();
|
return std::vector<Asset*>{
|
||||||
|
man->get<TrueTypeAsset>("truetype_ark"),
|
||||||
auto assetFont = canvas->getGame()->assetManager.load<TrueTypeAsset>("truetype_ark");
|
man->get<TextureAsset>("texture_test")
|
||||||
auto assetTexture = canvas->getGame()->assetManager.load<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->setBorder(&assetTexture->texture, glm::vec2(16, 16));
|
||||||
textbox->setFont(&assetFont->font);
|
textbox->setFont(&assetFont->font);
|
||||||
textbox->setFontSize(40);
|
textbox->setFontSize(40);
|
||||||
|
62
src/dawnpokergame/ui/PokerPlayerDisplay.cpp
Normal file
62
src/dawnpokergame/ui/PokerPlayerDisplay.cpp
Normal 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);
|
||||||
|
}
|
32
src/dawnpokergame/ui/PokerPlayerDisplay.hpp
Normal file
32
src/dawnpokergame/ui/PokerPlayerDisplay.hpp
Normal 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();
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user