2012-06-13 02:59:49 +08:00
|
|
|
#include "CCControlButtonLoader.h"
|
2012-06-02 06:14:18 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
|
|
|
using namespace cocos2d::extension;
|
2012-09-24 11:47:33 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocosbuilder {;
|
2012-06-02 06:14:18 +08:00
|
|
|
|
|
|
|
#define PROPERTY_ZOOMONTOUCHDOWN "zoomOnTouchDown"
|
|
|
|
#define PROPERTY_TITLE_NORMAL "title|1"
|
|
|
|
#define PROPERTY_TITLE_HIGHLIGHTED "title|2"
|
2012-09-17 14:27:17 +08:00
|
|
|
#define PROPERTY_TITLE_DISABLED "title|3"
|
2012-06-02 06:14:18 +08:00
|
|
|
#define PROPERTY_TITLECOLOR_NORMAL "titleColor|1"
|
|
|
|
#define PROPERTY_TITLECOLOR_HIGHLIGHTED "titleColor|2"
|
2012-09-17 14:27:17 +08:00
|
|
|
#define PROPERTY_TITLECOLOR_DISABLED "titleColor|3"
|
2012-06-02 06:14:18 +08:00
|
|
|
#define PROPERTY_TITLETTF_NORMAL "titleTTF|1"
|
|
|
|
#define PROPERTY_TITLETTF_HIGHLIGHTED "titleTTF|2"
|
2012-09-17 14:27:17 +08:00
|
|
|
#define PROPERTY_TITLETTF_DISABLED "titleTTF|3"
|
2012-06-02 06:14:18 +08:00
|
|
|
#define PROPERTY_TITLETTFSIZE_NORMAL "titleTTFSize|1"
|
|
|
|
#define PROPERTY_TITLETTFSIZE_HIGHLIGHTED "titleTTFSize|2"
|
2012-09-17 14:27:17 +08:00
|
|
|
#define PROPERTY_TITLETTFSIZE_DISABLED "titleTTFSize|3"
|
2012-06-02 06:14:18 +08:00
|
|
|
#define PROPERTY_LABELANCHORPOINT "labelAnchorPoint"
|
|
|
|
#define PROPERTY_PREFEREDSIZE "preferedSize" // TODO Should be "preferredSize". This is a typo in cocos2d-iphone, cocos2d-x and CocosBuilder!
|
|
|
|
#define PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL "backgroundSpriteFrame|1"
|
|
|
|
#define PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED "backgroundSpriteFrame|2"
|
2012-09-17 14:27:17 +08:00
|
|
|
#define PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED "backgroundSpriteFrame|3"
|
2012-06-02 06:14:18 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void ControlButtonLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char * pPropertyName, bool pCheck, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_ZOOMONTOUCHDOWN) == 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
((ControlButton *)pNode)->setZoomOnTouchDown(pCheck);
|
2012-06-02 06:14:18 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
ControlLoader::onHandlePropTypeCheck(pNode, pParent, pPropertyName, pCheck, ccbReader);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void ControlButtonLoader::onHandlePropTypeString(Node * pNode, Node * pParent, const char * pPropertyName, const char * pString, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_TITLE_NORMAL) == 0) {
|
2013-12-18 15:40:31 +08:00
|
|
|
((ControlButton *)pNode)->setTitleForState(pString, Control::State::NORMAL);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLE_HIGHLIGHTED) == 0) {
|
2013-12-18 15:40:31 +08:00
|
|
|
((ControlButton *)pNode)->setTitleForState(pString, Control::State::HIGH_LIGHTED);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLE_DISABLED) == 0) {
|
2013-12-18 15:40:31 +08:00
|
|
|
((ControlButton *)pNode)->setTitleForState(pString, Control::State::DISABLED);
|
2012-06-02 06:14:18 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
ControlLoader::onHandlePropTypeString(pNode, pParent, pPropertyName, pString, ccbReader);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void ControlButtonLoader::onHandlePropTypeFontTTF(Node * pNode, Node * pParent, const char * pPropertyName, const char * pFontTTF, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_TITLETTF_NORMAL) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::NORMAL);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLETTF_HIGHLIGHTED) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::HIGH_LIGHTED);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLETTF_DISABLED) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::DISABLED);
|
2012-06-02 06:14:18 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
ControlLoader::onHandlePropTypeFontTTF(pNode, pParent, pPropertyName, pFontTTF, ccbReader);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void ControlButtonLoader::onHandlePropTypeFloatScale(Node * pNode, Node * pParent, const char * pPropertyName, float pFloatScale, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_NORMAL) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::NORMAL);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_HIGHLIGHTED) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::HIGH_LIGHTED);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_DISABLED) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::DISABLED);
|
2012-06-02 06:14:18 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
ControlLoader::onHandlePropTypeFloatScale(pNode, pParent, pPropertyName, pFloatScale, ccbReader);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ControlButtonLoader::onHandlePropTypePoint(Node * pNode, Node * pParent, const char * pPropertyName, Vec2 pPoint, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_LABELANCHORPOINT) == 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
((ControlButton *)pNode)->setLabelAnchorPoint(pPoint);
|
2012-06-02 06:14:18 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
ControlLoader::onHandlePropTypePoint(pNode, pParent, pPropertyName, pPoint, ccbReader);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void ControlButtonLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, const char * pPropertyName, Size pSize, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_PREFEREDSIZE) == 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
((ControlButton *)pNode)->setPreferredSize(pSize);
|
2012-06-02 06:14:18 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
ControlLoader::onHandlePropTypeSize(pNode, pParent, pPropertyName, pSize, ccbReader);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void ControlButtonLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL) == 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
if(pSpriteFrame != NULL) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::NORMAL);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED) == 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
if(pSpriteFrame != NULL) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::HIGH_LIGHTED);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED) == 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
if(pSpriteFrame != NULL) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::DISABLED);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
ControlLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pSpriteFrame, ccbReader);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void ControlButtonLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, const char * pPropertyName, Color3B pColor3B, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_NORMAL) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleColorForState(pColor3B, Control::State::NORMAL);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_HIGHLIGHTED) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleColorForState(pColor3B, Control::State::HIGH_LIGHTED);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_DISABLED) == 0) {
|
2013-07-26 14:37:26 +08:00
|
|
|
((ControlButton *)pNode)->setTitleColorForState(pColor3B, Control::State::DISABLED);
|
2012-06-02 06:14:18 +08:00
|
|
|
} else {
|
2013-07-27 21:44:49 +08:00
|
|
|
ControlLoader::onHandlePropTypeColor3(pNode, pParent, pPropertyName, pColor3B, ccbReader);
|
2012-06-02 06:14:18 +08:00
|
|
|
}
|
2012-07-19 17:22:36 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
};
|