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
|
|
|
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-08-22 10:16:57 +08:00
|
|
|
return "LabelTTF";
|
2013-06-07 19:49:22 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<LabelBMFont*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "LabelBMFont";
|
2013-06-07 19:49:22 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<Sprite*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "Sprite";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<ControlButton*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "ControlButton";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<LayerGradient*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "LayerGradient";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<LayerColor*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "LayerColor";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<Scale9Sprite*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "LayerGradient";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<Menu*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "Menu";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemAtlasFont*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "MenuItemAtlasFont";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemFont*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "MenuItemFont";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemLabel*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "MenuItemLabel";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemImage*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "MenuItemImage";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemToggle*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "MenuItemToggle";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItemSprite*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "MenuItemSprite";
|
2013-06-07 19:49:22 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<MenuItem*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "MenuItem";
|
2013-06-07 19:49:22 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<Layer*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "Layer";
|
2013-06-07 19:49:22 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<String*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "String";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:33:59 +08:00
|
|
|
if (NULL != dynamic_cast<ParticleSystemQuad*>(pNode)) {
|
2013-08-22 10:16:57 +08:00
|
|
|
return "ParticleSystemQuad";
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return "No Support";
|
|
|
|
}
|
|
|
|
|
2013-08-22 10:16:57 +08:00
|
|
|
void CCBProxy::setCallback(Node* node,int handle, int controlEvents)
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
2013-08-22 10:16:57 +08:00
|
|
|
if (nullptr == node) {
|
2013-06-03 13:47:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-22 10:16:57 +08:00
|
|
|
if (nullptr != dynamic_cast<MenuItem*>(node))
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
2013-08-22 10:16:57 +08:00
|
|
|
MenuItem *menuItem = dynamic_cast<MenuItem*>(node);
|
|
|
|
if (nullptr != menuItem) {
|
2013-09-04 22:17:26 +08:00
|
|
|
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)menuItem, handle, ScriptHandlerMgr::HandlerType::MENU_CLICKED);
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
}
|
2013-08-22 10:16:57 +08:00
|
|
|
else if (NULL != dynamic_cast<Control*>(node))
|
2013-06-03 13:47:12 +08:00
|
|
|
{
|
2013-08-22 10:16:57 +08:00
|
|
|
Control* control = dynamic_cast<Control*>(node);
|
|
|
|
if (nullptr != control)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < kControlEventTotalNumber; i++)
|
|
|
|
{
|
|
|
|
if ((controlEvents & (1 << i)))
|
|
|
|
{
|
2013-09-04 22:17:26 +08:00
|
|
|
ScriptHandlerMgr::HandlerType handlerType = ScriptHandlerMgr::HandlerType((int)ScriptHandlerMgr::HandlerType::CONTROL_TOUCH_DOWN + i);
|
|
|
|
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)control, handle, handlerType);
|
2013-08-22 10:16:57 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-03 13:47:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|