Prefabs not working
This commit is contained in:
@ -11,6 +11,10 @@
|
||||
|
||||
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
|
||||
@ -19,7 +23,10 @@ namespace Dawn {
|
||||
* @param man Asset Manager to retreive the assets from.
|
||||
* @return List of required assets, includes sibling/child assets.
|
||||
*/
|
||||
static virtual std::vector<Asset*> getAssets(AssetManager *man) = 0;
|
||||
template<class T>
|
||||
static std::vector<Asset*> getAssets(AssetManager *man) {
|
||||
return T::prefabAssets(man);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a scene item from this prefab.
|
||||
@ -27,23 +34,30 @@ namespace Dawn {
|
||||
* @param scene Scene to add the item to.
|
||||
* @return The created scene item for this prefab.
|
||||
*/
|
||||
static virtual SceneItem * create(Scene *scene) = 0;
|
||||
template<class T>
|
||||
static SceneItem * create(Scene *scene) {
|
||||
return T::prefabItem(scene);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class UIPrefab : public Prefab {
|
||||
public:
|
||||
protected:
|
||||
/** @deprecated */
|
||||
static SceneItem * create(Scene *scene) override {
|
||||
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) = 0;
|
||||
static virtual void uiApply(T *existing) {
|
||||
V::prefabUIApply(existing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a UI Item from this prefab.
|
||||
@ -53,7 +67,7 @@ namespace Dawn {
|
||||
*/
|
||||
static virtual T * uiCreate(UICanvas *canvas) {
|
||||
auto item = canvas->addElement<T>();
|
||||
uiApply(item);
|
||||
V::uiApply(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Dawn {
|
||||
class VisualNovelTextboxPrefab : public UIPrefab<VisualNovelTextbox> {
|
||||
public:
|
||||
static std::vector<Asset*> getAssets(AssetManager *man) {
|
||||
static std::vector<Asset*> prefabAssets(AssetManager *man) {
|
||||
std::vector<Asset*> assets{
|
||||
man->get<TrueTypeAsset>("truetype_ark")
|
||||
};
|
||||
@ -18,7 +18,7 @@ namespace Dawn {
|
||||
return assets;
|
||||
}
|
||||
|
||||
static void uiApply(VisualNovelTextbox *textbox) override {
|
||||
static void prefabUIApply(VisualNovelTextbox *textbox) override {
|
||||
assertNotNull(textbox);
|
||||
|
||||
auto assetFont = textbox->getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
|
||||
|
Reference in New Issue
Block a user