2013-06-03 13:47:12 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCBProxy.h"
|
2013-07-16 09:55:06 +08:00
|
|
|
#include "LuaScriptHandlerMgr.h"
|
2013-06-03 13:47:12 +08:00
|
|
|
|
2013-07-05 10:25:37 +08:00
|
|
|
CCBReader* CCBProxy::createCCBReader()
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
2013-07-25 15:25:11 +08:00
|
|
|
NodeLoaderLibrary *ccNodeLoaderLibrary = NodeLoaderLibrary::getInstance();
|
2013-06-03 13:47:12 +08:00
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
ccNodeLoaderLibrary->registerNodeLoader("", CCBLayerLoader::loader());
|
2013-06-03 13:47:12 +08:00
|
|
|
|
|
|
|
CCBReader * pCCBReader = new CCBReader(ccNodeLoaderLibrary);
|
|
|
|
pCCBReader->autorelease();
|
|
|
|
|
|
|
|
return pCCBReader;
|
|
|
|
}
|
2013-06-20 14:33:59 +08:00
|
|
|
Node* CCBProxy::readCCBFromFile(const char *pszFileName,CCBReader* pCCBReader,bool bSetOwner)
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
|
|
|
if (NULL == pCCBReader || NULL == pszFileName || 0 == strlen(pszFileName)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-20 14:33:59 +08:00
|
|
|
Node *pNode = NULL;
|
2013-06-03 13:47:12 +08:00
|
|
|
if (bSetOwner) {
|
|
|
|
pNode = pCCBReader->readNodeGraphFromFile(pszFileName,this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pNode = pCCBReader->readNodeGraphFromFile(pszFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return pNode;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
const char* CCBProxy::getNodeTypeName(Node* pNode)
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
|
|
|
if (NULL == pNode) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<LabelTTF*>(pNode)) {
|
2013-06-07 19:49:22 +08:00
|
|
|
return "CCLabelTTF";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<LabelBMFont*>(pNode)) {
|
2013-06-07 19:49:22 +08:00
|
|
|
return "CCLabelBMFont";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<Sprite*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCSprite";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<ControlButton*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCControlButton";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<LayerGradient*>(pNode)) {
|
2013-06-07 19:49:22 +08:00
|
|
|
return "CCLayerGradient";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<LayerColor*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCLayerColor";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<Scale9Sprite*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCLayerGradient";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<Menu*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCMenu";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemAtlasFont*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCMenuItemAtlasFont";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemFont*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCMenuItemFont";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemLabel*>(pNode)) {
|
2013-06-07 19:49:22 +08:00
|
|
|
return "CCMenuItemLabel";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemImage*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCMenuItemImage";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemToggle*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCMenuItemToggle";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemSprite*>(pNode)) {
|
2013-06-07 19:49:22 +08:00
|
|
|
return "CCMenuItemSprite";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItem*>(pNode)) {
|
2013-06-07 19:49:22 +08:00
|
|
|
return "CCMenuItem";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<Layer*>(pNode)) {
|
2013-06-07 19:49:22 +08:00
|
|
|
return "CCLayer";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<String*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCString";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<ParticleSystemQuad*>(pNode)) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return "CCParticleSystemQuad";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "No Support";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
void CCBProxy::setCallback(Node* pNode,int nHandle)
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
|
|
|
if (NULL == pNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItem*>(pNode))
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
2013-06-20 14:33:59 +08:00
|
|
|
MenuItem *pMenuItem = dynamic_cast<MenuItem*>(pNode);
|
2013-06-03 13:47:12 +08:00
|
|
|
if (NULL != pMenuItem) {
|
2013-07-16 09:55:06 +08:00
|
|
|
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)pMenuItem, nHandle, ScriptHandlerMgr::kMenuClickHandler);
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-20 14:33:59 +08:00
|
|
|
else if (NULL != dynamic_cast<ControlButton*>(pNode))
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
2013-06-20 14:33:59 +08:00
|
|
|
ControlButton *pBtnItem = dynamic_cast<ControlButton*>(pNode);
|
2013-06-03 13:47:12 +08:00
|
|
|
if (NULL != pBtnItem) {
|
|
|
|
//UNOD,need Btn Pros to addHanldeOfControlEvent
|
2013-07-16 09:55:06 +08:00
|
|
|
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)pBtnItem, nHandle, ScriptHandlerMgr::kControlTouchUpInsideHandler);
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|