2012-05-03 14:43:27 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2012 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-05-07 17:05:17 +08:00
|
|
|
#ifndef _CC_CUSTOM_CLASS_H_
|
|
|
|
#define _CC_CUSTOM_CLASS_H_
|
2012-05-03 11:58:53 +08:00
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2012-05-07 17:05:17 +08:00
|
|
|
#include <map>
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-05-07 17:05:17 +08:00
|
|
|
NS_CC_EXT_BEGIN
|
|
|
|
|
2012-05-07 18:14:15 +08:00
|
|
|
/**
|
|
|
|
@brief This is a simple reflection implement for custom classes in CocosBuilder
|
|
|
|
|
|
|
|
You should declare your custom class like:
|
|
|
|
class MyCustomLayer : public CCBCustomClass, public CCLayer
|
|
|
|
CCBCustomClass is a pure virtual class. It doesn't inherit CCObject to prevent dead-diamond.
|
|
|
|
*/
|
2012-05-08 11:30:08 +08:00
|
|
|
class CCBCustomClassProtocol
|
2012-05-03 11:58:53 +08:00
|
|
|
{
|
2012-05-07 17:05:17 +08:00
|
|
|
public:
|
2012-05-07 18:14:15 +08:00
|
|
|
/** You should implement this static function in your custom class, and return a valid object */
|
2012-05-08 11:30:08 +08:00
|
|
|
static CCBCustomClassProtocol* createInstance() { return NULL; }; // cannot create virual class here
|
2012-05-07 17:05:17 +08:00
|
|
|
|
2012-05-08 11:30:08 +08:00
|
|
|
CCBCustomClassProtocol() {};
|
|
|
|
virtual ~CCBCustomClassProtocol() {};
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-05-07 18:14:15 +08:00
|
|
|
/** This pure virtual methods should be implemented in your custom class
|
|
|
|
please refer to tests/ExtensionsTest/CocosBuilderTest as a sample */
|
2012-05-07 17:05:17 +08:00
|
|
|
virtual bool callbackSetChildren(const char* name, cocos2d::CCObject* node) = 0;
|
2012-05-07 18:14:15 +08:00
|
|
|
|
|
|
|
/** This pure virtual methods should be implemented in your custom class
|
|
|
|
please refer to tests/ExtensionsTest/CocosBuilderTest as a sample */
|
|
|
|
virtual cocos2d::SEL_MenuHandler callbackGetSelectors(const char* selectorName) = 0;
|
|
|
|
|
|
|
|
/** This pure virtual methods should be implemented in your custom class
|
|
|
|
please refer to tests/ExtensionsTest/CocosBuilderTest as a sample */
|
2012-05-07 17:05:17 +08:00
|
|
|
virtual void callbackAfterCCBLoaded() = 0;
|
|
|
|
};
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-05-07 18:14:15 +08:00
|
|
|
/**
|
|
|
|
@brief CCBCustomClass should be registed into this factory, then CCBReader can create your custom class via its name string.
|
|
|
|
|
|
|
|
See tests/Extensionstest/CocosBuilderTest/CocosBuilderTest.cpp as the reference
|
|
|
|
*/
|
2012-05-08 11:30:08 +08:00
|
|
|
class CC_DLL CCBCustomClassFactory
|
2012-05-07 17:05:17 +08:00
|
|
|
{
|
2012-05-08 11:30:08 +08:00
|
|
|
private:
|
|
|
|
/// a function pointer for CCCustomClassProtocol::createInstance
|
|
|
|
typedef CCBCustomClassProtocol* (*FUNC_CUSTON_CLASS_CREATOR)();
|
|
|
|
typedef std::map<std::string, FUNC_CUSTON_CLASS_CREATOR> CUSTOM_CLASS_MAP;
|
|
|
|
CUSTOM_CLASS_MAP* m_pCustomCreatorsMap;
|
|
|
|
|
|
|
|
public:
|
2012-05-07 17:05:17 +08:00
|
|
|
CCBCustomClassFactory();
|
|
|
|
virtual ~CCBCustomClassFactory();
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-05-07 18:14:15 +08:00
|
|
|
/** get the singleton */
|
2012-05-07 17:05:17 +08:00
|
|
|
static CCBCustomClassFactory* sharedFactory();
|
|
|
|
|
2012-05-07 18:14:15 +08:00
|
|
|
/** Note that you should regist custom class before invoke CCBReader::nodeGraphFromFile
|
|
|
|
For example:
|
|
|
|
CCBCustomClassFactory::sharedFactory()->registCustomClass("HelloCocosBuilder",
|
|
|
|
HelloCocosBuilder::createInstance);
|
|
|
|
*/
|
2012-05-08 11:30:08 +08:00
|
|
|
bool registCustomClass(const char* name, FUNC_CUSTON_CLASS_CREATOR pfnCreator);
|
2012-05-07 18:14:15 +08:00
|
|
|
|
|
|
|
/** This function is only used in CCBReader. Developers don't need to know it */
|
2012-05-08 11:30:08 +08:00
|
|
|
CCBCustomClassProtocol* createCustomClassWithName(const char* name);
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-05-08 11:30:08 +08:00
|
|
|
|
2012-05-07 17:05:17 +08:00
|
|
|
};
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-05-07 17:05:17 +08:00
|
|
|
NS_CC_EXT_END;
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-05-07 17:05:17 +08:00
|
|
|
#endif // _CC_CUSTOM_CLASS_H_
|