Added CCMenuLoader, CCMenuItemLoader and CCMenuItemImageLoader.

This commit is contained in:
Nicolas Gramlich 2012-05-31 17:07:02 -07:00
parent 40f1ffe5fb
commit 62e0c1cda0
7 changed files with 120 additions and 0 deletions

View File

@ -9,6 +9,9 @@
#include "CCSpriteLoader.h"
#include "CCScale9SpriteLoader.h"
#include "CCBFileLoader.h"
#include "CCMenuLoader.h"
#include "CCMenuItemLoader.h"
#include "CCMenuItemImageLoader.h"
using namespace cocos2d;
using namespace cocos2d::extension;
@ -23,6 +26,8 @@ CCBReader::CCBReader() {
this->registerCCNodeLoader("CCLabelTTF", new CCLabelTTFLoader());
this->registerCCNodeLoader("CCScale9Sprite", new CCScale9SpriteLoader());
this->registerCCNodeLoader("CCBFile", new CCBFileLoader());
this->registerCCNodeLoader("CCMenu", new CCMenuLoader());
this->registerCCNodeLoader("CCMenuItemImage", new CCMenuItemImageLoader());
}
CCBReader::~CCBReader() {

View File

@ -0,0 +1,24 @@
#import "CCMenuItemImageLoader.h"
using namespace cocos2d;
using namespace cocos2d::extension;
#define PROPERTY_NORMALDISPLAYFRAME "normalSpriteFrame"
#define PROPERTY_SELECTEDDISPLAYFRAME "selectedSpriteFrame"
#define PROPERTY_DISABLEDDISPLAYFRAME "disabledSpriteFrame"
CCMenuItemImage * CCMenuItemImageLoader::createCCNode(CCNode * pParent, CCBReader * pCCBReader) {
return CCMenuItemImage::node();
}
void CCMenuItemImageLoader::onHandlePropTypeSpriteFrame(CCNode * pNode, CCNode * pParent, std::string pPropertyName, CCSpriteFrame * pCCSpriteFrame, CCBReader * pCCBReader) {
if(pPropertyName.compare(PROPERTY_NORMALDISPLAYFRAME) == 0) {
((CCMenuItemImage *)pNode)->setNormalSpriteFrame(pCCSpriteFrame);
} else if(pPropertyName.compare(PROPERTY_SELECTEDDISPLAYFRAME) == 0) {
((CCMenuItemImage *)pNode)->setSelectedSpriteFrame(pCCSpriteFrame);
} else if(pPropertyName.compare(PROPERTY_DISABLEDDISPLAYFRAME) == 0) {
((CCMenuItemImage *)pNode)->setDisabledSpriteFrame(pCCSpriteFrame);
} else {
CCMenuItemLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pCCSpriteFrame, pCCBReader);
}
}

View File

@ -0,0 +1,20 @@
#ifndef _CCMENUITEMIMAGE_LOADER_H_
#define _CCMENUITEMIMAGE_LOADER_H_
#include "CCMenuItemLoader.h"
NS_CC_EXT_BEGIN
/* Forward declaration. */
class CCBReader;
class CCMenuItemImageLoader : public CCMenuItemLoader {
protected:
virtual CCMenuItemImage * createCCNode(CCNode *, CCBReader *);
virtual void onHandlePropTypeSpriteFrame(CCNode *, CCNode *, std::string, CCSpriteFrame *, CCBReader *);
};
NS_CC_EXT_END
#endif

View File

@ -0,0 +1,23 @@
#import "CCMenuItemLoader.h"
using namespace cocos2d;
using namespace cocos2d::extension;
#define PROPERTY_BLOCK "block"
#define PROPERTY_ISENABLED "isEnabled"
void CCMenuItemLoader::onHandlePropTypeBlock(CCNode * pNode, CCNode * pParent, std::string pPropertyName, void * pBlock, CCBReader * pCCBReader) {
if(pPropertyName.compare(PROPERTY_BLOCK) == 0) {
// ((CCMenuItem *)pNode)->setTarget(???, ???);
} else {
CCNodeLoader::onHandlePropTypeBlock(pNode, pParent, pPropertyName, pBlock, pCCBReader);
}
}
void CCMenuItemLoader::onHandlePropTypeCheck(CCNode * pNode, CCNode * pParent, std::string pPropertyName, bool pCheck, CCBReader * pCCBReader) {
if(pPropertyName.compare(PROPERTY_ISENABLED) == 0) {
((CCMenuItem *)pNode)->setIsEnabled(pCheck);
} else {
CCNodeLoader::onHandlePropTypeCheck(pNode, pParent, pPropertyName, pCheck, pCCBReader);
}
}

View File

@ -0,0 +1,21 @@
#ifndef _CCMENUITEM_LOADER_H_
#define _CCMENUITEM_LOADER_H_
#include "CCLayerLoader.h"
NS_CC_EXT_BEGIN
/* Forward declaration. */
class CCBReader;
class CCMenuItemLoader : public CCNodeLoader {
protected:
virtual CCMenuItem * createCCNode(CCNode *, CCBReader *) = 0;
virtual void onHandlePropTypeBlock(CCNode *, CCNode *, std::string, void *, CCBReader *);
virtual void onHandlePropTypeCheck(CCNode *, CCNode *, std::string, bool, CCBReader *);
};
NS_CC_EXT_END
#endif

View File

@ -0,0 +1,9 @@
#import "CCMenuLoader.h"
using namespace cocos2d;
using namespace cocos2d::extension;
CCMenu * CCMenuLoader::createCCNode(CCNode * pParent, CCBReader * pCCBReader) {
return CCMenu::node();
}

View File

@ -0,0 +1,18 @@
#ifndef _CCMENU_LOADER_H_
#define _CCMENU_LOADER_H_
#include "CCLayerLoader.h"
NS_CC_EXT_BEGIN
/* Forward declaration. */
class CCBReader;
class CCMenuLoader : public CCLayerLoader {
protected:
virtual CCMenu * createCCNode(CCNode *, CCBReader *);
};
NS_CC_EXT_END
#endif