Added basic prefabs finally
This commit is contained in:
@ -23,6 +23,7 @@ add_subdirectory(display)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(poker)
|
||||
add_subdirectory(prefab)
|
||||
add_subdirectory(save)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(time)
|
||||
|
10
src/dawn/prefab/CMakeLists.txt
Normal file
10
src/dawn/prefab/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
# target_sources(${DAWN_TARGET_NAME}
|
||||
# PRIVATE
|
||||
# Prefab.cpp
|
||||
# )
|
24
src/dawn/prefab/Prefab.hpp
Normal file
24
src/dawn/prefab/Prefab.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "asset/AssetManager.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
template<class T>
|
||||
class Prefab {
|
||||
public:
|
||||
static std::vector<Asset*> getRequiredAssets() {
|
||||
return T::prefabAssets();
|
||||
}
|
||||
|
||||
static T * create(Scene *scene) {
|
||||
T *item = scene->createSceneItemOfType<T>();
|
||||
item->prefabInit();
|
||||
return item;
|
||||
}
|
||||
};
|
||||
}
|
27
src/dawn/prefab/SceneItemPrefab.hpp
Normal file
27
src/dawn/prefab/SceneItemPrefab.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Prefab.hpp"
|
||||
#include "scene/SceneItem.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
template<class T>
|
||||
class SceneItemPrefab :
|
||||
public SceneItem,
|
||||
public Prefab<T>
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
SceneItemPrefab(Scene *scene, sceneitemid_t id) :
|
||||
SceneItem(scene, id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void prefabInit() = 0;
|
||||
};
|
||||
}
|
43
src/dawn/prefabs/display/SimpleCubePrefab.hpp
Normal file
43
src/dawn/prefabs/display/SimpleCubePrefab.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "prefab/SceneItemPrefab.hpp"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "display/mesh/CubeMesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleCubePrefab : public SceneItemPrefab<SimpleCubePrefab> {
|
||||
public:
|
||||
MeshRenderer *renderer = nullptr;
|
||||
MeshHost *host = nullptr;
|
||||
Material *material = nullptr;
|
||||
|
||||
static std::vector<Asset*> prefabAssets() {
|
||||
return std::vector<Asset*>();
|
||||
}
|
||||
|
||||
SimpleCubePrefab(Scene *scene, sceneitemid_t id) :
|
||||
SceneItemPrefab(scene, id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void prefabInit() override {
|
||||
this->renderer = this->addComponent<MeshRenderer>();
|
||||
this->host = this->addComponent<MeshHost>();
|
||||
this->material = this->addComponent<Material>();
|
||||
|
||||
this->host->mesh.createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
|
||||
CubeMesh::buffer(&this->host->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0);
|
||||
|
||||
// auto param = material->getShader()->getParameterByName("u_Text");
|
||||
// this->material->textureValues[param] = nullptr;
|
||||
this->material->colorValues[material->getShader()->getParameterByName("u_Color")] = COLOR_RED;
|
||||
|
||||
std::cout << "Preab Init" << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SceneItem.hpp"
|
||||
#include "SceneItemComponent.hpp"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "util/array.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Prefab {
|
||||
protected:
|
||||
virtual std::vector<Asset*> prefabAssets(AssetManager *man) = 0;
|
||||
virtual SceneItem * prefabItem(Scene *scene) = 0;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns a list of assets that this prefab requires to be loaded for the
|
||||
* instanciation to work.
|
||||
*
|
||||
* @param man Asset Manager to retreive the assets from.
|
||||
* @return List of required assets, includes sibling/child assets.
|
||||
*/
|
||||
template<class T>
|
||||
static std::vector<Asset*> getAssets(AssetManager *man) {
|
||||
return T::prefabAssets(man);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a scene item from this prefab.
|
||||
*
|
||||
* @param scene Scene to add the item to.
|
||||
* @return The created scene item for this prefab.
|
||||
*/
|
||||
template<class T>
|
||||
static SceneItem * create(Scene *scene) {
|
||||
return T::prefabItem(scene);
|
||||
}
|
||||
};
|
||||
|
||||
class UIPrefab : public Prefab {
|
||||
protected:
|
||||
/** @deprecated */
|
||||
SceneItem * prefabItem(Scene *scene) override {
|
||||
assertUnreachable();
|
||||
}
|
||||
|
||||
virtual void prefabUIApply(T *existing) = 0;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Applies a UI Prefab styling to an existing UI Element.
|
||||
*
|
||||
* @param existing Existing item to apply styling to.
|
||||
*/
|
||||
static virtual void uiApply(T *existing) {
|
||||
V::prefabUIApply(existing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a UI Item from this prefab.
|
||||
*
|
||||
* @param canvas Canvas to create this item on to.
|
||||
* @return Pointer to the created UI Item.
|
||||
*/
|
||||
static virtual T * uiCreate(UICanvas *canvas) {
|
||||
auto item = canvas->addElement<T>();
|
||||
V::uiApply(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
@ -33,11 +33,7 @@ void Scene::update() {
|
||||
}
|
||||
|
||||
SceneItem * Scene::createSceneItem() {
|
||||
sceneitemid_t id = this->nextId++;
|
||||
auto item = new SceneItem(this, id);
|
||||
assertNotNull(item);
|
||||
this->itemsNotInitialized[id] = item;
|
||||
return item;
|
||||
return this->createSceneItemOfType<SceneItem>();
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
|
@ -35,6 +35,20 @@ namespace Dawn {
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Create a Scene Item object and add to the current scene.
|
||||
*
|
||||
* @return A shared pointer to the created SceneItem.
|
||||
*/
|
||||
template<class T>
|
||||
T * createSceneItemOfType() {
|
||||
sceneitemid_t id = this->nextId++;
|
||||
auto item = new T(this, id);
|
||||
assertNotNull(item);
|
||||
this->itemsNotInitialized[id] = item;
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Scene Item object and add to the current scene.
|
||||
*
|
||||
|
@ -11,5 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
UILabel.cpp
|
||||
UISprite.cpp
|
||||
UIEmpty.cpp
|
||||
UIGrid.cpp
|
||||
# UIGrid.cpp
|
||||
)
|
@ -12,4 +12,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
# Subdirs
|
||||
add_subdirectory(components)
|
||||
add_subdirectory(events)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(ui)
|
10
src/dawn/visualnovel/scene/CMakeLists.txt
Normal file
10
src/dawn/visualnovel/scene/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
SimpleVNScene.cpp
|
||||
)
|
@ -14,7 +14,8 @@ SimpleVNScene::SimpleVNScene(DawnGame *game) : Scene(game) {
|
||||
|
||||
std::vector<Asset*> SimpleVNScene::getRequiredAssets() {
|
||||
auto assMan = &this->game->assetManager;
|
||||
return PokerGameTextbox::getAssets(assMan);
|
||||
// return PokerGameTextbox::getAssets(assMan);
|
||||
return std::vector<Asset*>();
|
||||
}
|
||||
|
||||
void SimpleVNScene::stage() {
|
||||
@ -29,7 +30,7 @@ void SimpleVNScene::stage() {
|
||||
|
||||
// UI
|
||||
this->canvas = UICanvas::createCanvas(this);
|
||||
this->textbox = Prefab::create<VisualNovelTextboxPrefab>(this)->getComponent<VisualNovelTextbox>();
|
||||
// this->textbox = Prefab::create<VisualNovelTextboxPrefab>(this)->getComponent<VisualNovelTextbox>();
|
||||
this->background = SimpleVisualNovelBackground::create(this);
|
||||
|
||||
// VN Manager
|
||||
@ -44,8 +45,4 @@ void SimpleVNScene::stage() {
|
||||
|
||||
// Begin VN.
|
||||
this->vnManager->setEvent(this->getVNEvent());
|
||||
}
|
||||
|
||||
void SimpleVNScene::vnStage() {
|
||||
|
||||
}
|
@ -8,7 +8,6 @@
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "util/array.hpp"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "prefabs/VisualNovelTextboxPrefab.hpp"
|
||||
#include "visualnovel/VisualNovelManager.hpp"
|
||||
#include "visualnovel/events/VisualNovelTextboxEvent.hpp"
|
||||
#include "visualnovel/events/VisualNovelPauseEvent.hpp"
|
||||
@ -25,7 +24,7 @@ namespace Dawn {
|
||||
VisualNovelFader *vnFader = nullptr;
|
||||
VisualNovelManager *vnManager = nullptr;
|
||||
|
||||
virtual void vnStage();
|
||||
virtual void vnStage() = 0;
|
||||
virtual IVisualNovelEvent * getVNEvent() = 0;
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user