mirror of https://github.com/axmolengine/axmol.git
143 lines
7.6 KiB
C++
143 lines
7.6 KiB
C++
/****************************************************************************
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
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 "editor-support/cocosbuilder/CCControlButtonLoader.h"
|
|
|
|
using namespace cocos2d;
|
|
using namespace cocos2d::extension;
|
|
|
|
namespace cocosbuilder {;
|
|
|
|
#define PROPERTY_ZOOMONTOUCHDOWN "zoomOnTouchDown"
|
|
#define PROPERTY_TITLE_NORMAL "title|1"
|
|
#define PROPERTY_TITLE_HIGHLIGHTED "title|2"
|
|
#define PROPERTY_TITLE_DISABLED "title|3"
|
|
#define PROPERTY_TITLECOLOR_NORMAL "titleColor|1"
|
|
#define PROPERTY_TITLECOLOR_HIGHLIGHTED "titleColor|2"
|
|
#define PROPERTY_TITLECOLOR_DISABLED "titleColor|3"
|
|
#define PROPERTY_TITLETTF_NORMAL "titleTTF|1"
|
|
#define PROPERTY_TITLETTF_HIGHLIGHTED "titleTTF|2"
|
|
#define PROPERTY_TITLETTF_DISABLED "titleTTF|3"
|
|
#define PROPERTY_TITLETTFSIZE_NORMAL "titleTTFSize|1"
|
|
#define PROPERTY_TITLETTFSIZE_HIGHLIGHTED "titleTTFSize|2"
|
|
#define PROPERTY_TITLETTFSIZE_DISABLED "titleTTFSize|3"
|
|
#define PROPERTY_LABELANCHORPOINT "labelAnchorPoint"
|
|
// TODO: Should be "preferredSize". This is a typo in cocos2d-iphone, cocos2d-x and CocosBuilder!
|
|
#define PROPERTY_PREFEREDSIZE "preferedSize"
|
|
#define PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL "backgroundSpriteFrame|1"
|
|
#define PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED "backgroundSpriteFrame|2"
|
|
#define PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED "backgroundSpriteFrame|3"
|
|
|
|
void ControlButtonLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char * pPropertyName, bool pCheck, CCBReader * ccbReader) {
|
|
if(strcmp(pPropertyName, PROPERTY_ZOOMONTOUCHDOWN) == 0) {
|
|
((ControlButton *)pNode)->setZoomOnTouchDown(pCheck);
|
|
} else {
|
|
ControlLoader::onHandlePropTypeCheck(pNode, pParent, pPropertyName, pCheck, ccbReader);
|
|
}
|
|
}
|
|
|
|
void ControlButtonLoader::onHandlePropTypeString(Node * pNode, Node * pParent, const char * pPropertyName, const char * pString, CCBReader * ccbReader) {
|
|
if(strcmp(pPropertyName, PROPERTY_TITLE_NORMAL) == 0) {
|
|
((ControlButton *)pNode)->setTitleForState(pString, Control::State::NORMAL);
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLE_HIGHLIGHTED) == 0) {
|
|
((ControlButton *)pNode)->setTitleForState(pString, Control::State::HIGH_LIGHTED);
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLE_DISABLED) == 0) {
|
|
((ControlButton *)pNode)->setTitleForState(pString, Control::State::DISABLED);
|
|
} else {
|
|
ControlLoader::onHandlePropTypeString(pNode, pParent, pPropertyName, pString, ccbReader);
|
|
}
|
|
}
|
|
|
|
void ControlButtonLoader::onHandlePropTypeFontTTF(Node * pNode, Node * pParent, const char * pPropertyName, const char * pFontTTF, CCBReader * ccbReader) {
|
|
if(strcmp(pPropertyName, PROPERTY_TITLETTF_NORMAL) == 0) {
|
|
((ControlButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::NORMAL);
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLETTF_HIGHLIGHTED) == 0) {
|
|
((ControlButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::HIGH_LIGHTED);
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLETTF_DISABLED) == 0) {
|
|
((ControlButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::DISABLED);
|
|
} else {
|
|
ControlLoader::onHandlePropTypeFontTTF(pNode, pParent, pPropertyName, pFontTTF, ccbReader);
|
|
}
|
|
}
|
|
|
|
void ControlButtonLoader::onHandlePropTypeFloatScale(Node * pNode, Node * pParent, const char * pPropertyName, float pFloatScale, CCBReader * ccbReader) {
|
|
if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_NORMAL) == 0) {
|
|
((ControlButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::NORMAL);
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_HIGHLIGHTED) == 0) {
|
|
((ControlButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::HIGH_LIGHTED);
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_DISABLED) == 0) {
|
|
((ControlButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::DISABLED);
|
|
} else {
|
|
ControlLoader::onHandlePropTypeFloatScale(pNode, pParent, pPropertyName, pFloatScale, ccbReader);
|
|
}
|
|
}
|
|
|
|
void ControlButtonLoader::onHandlePropTypePoint(Node * pNode, Node * pParent, const char * pPropertyName, Vec2 pPoint, CCBReader * ccbReader) {
|
|
if(strcmp(pPropertyName, PROPERTY_LABELANCHORPOINT) == 0) {
|
|
((ControlButton *)pNode)->setLabelAnchorPoint(pPoint);
|
|
} else {
|
|
ControlLoader::onHandlePropTypePoint(pNode, pParent, pPropertyName, pPoint, ccbReader);
|
|
}
|
|
}
|
|
|
|
void ControlButtonLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, const char * pPropertyName, Size pSize, CCBReader * ccbReader) {
|
|
if(strcmp(pPropertyName, PROPERTY_PREFEREDSIZE) == 0) {
|
|
((ControlButton *)pNode)->setPreferredSize(pSize);
|
|
} else {
|
|
ControlLoader::onHandlePropTypeSize(pNode, pParent, pPropertyName, pSize, ccbReader);
|
|
}
|
|
}
|
|
|
|
void ControlButtonLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
|
|
if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL) == 0) {
|
|
if(pSpriteFrame != nullptr) {
|
|
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::NORMAL);
|
|
}
|
|
} else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED) == 0) {
|
|
if(pSpriteFrame != nullptr) {
|
|
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::HIGH_LIGHTED);
|
|
}
|
|
} else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED) == 0) {
|
|
if(pSpriteFrame != nullptr) {
|
|
((ControlButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::DISABLED);
|
|
}
|
|
} else {
|
|
ControlLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pSpriteFrame, ccbReader);
|
|
}
|
|
}
|
|
|
|
void ControlButtonLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, const char * pPropertyName, Color3B pColor3B, CCBReader * ccbReader) {
|
|
if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_NORMAL) == 0) {
|
|
((ControlButton *)pNode)->setTitleColorForState(pColor3B, Control::State::NORMAL);
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_HIGHLIGHTED) == 0) {
|
|
((ControlButton *)pNode)->setTitleColorForState(pColor3B, Control::State::HIGH_LIGHTED);
|
|
} else if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_DISABLED) == 0) {
|
|
((ControlButton *)pNode)->setTitleColorForState(pColor3B, Control::State::DISABLED);
|
|
} else {
|
|
ControlLoader::onHandlePropTypeColor3(pNode, pParent, pPropertyName, pColor3B, ccbReader);
|
|
}
|
|
}
|
|
|
|
};
|