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