diff --git a/spritebuilder/CCBAnimationManager.cpp b/spritebuilder/CCBAnimationManager.cpp index 8da4fcd..9969698 100644 --- a/spritebuilder/CCBAnimationManager.cpp +++ b/spritebuilder/CCBAnimationManager.cpp @@ -361,7 +361,7 @@ ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyfr return Sequence::createWithTwoActions(DelayTime::create(duration), Hide::create()); } } - else if (propName == "displayFrame") + else if (propName == "displayFrame" || propName == "spriteFrame") { return Sequence::createWithTwoActions(DelayTime::create(duration), CCBSetSpriteFrame::create(static_cast(pKeyframe1->getObject()))); @@ -503,7 +503,7 @@ void CCBAnimationManager::setAnimatedProperty(const std::string& propName, Node unsigned char opacity = value.asFloat() * 255.0f;//value.asByte(); pNode->setOpacity(opacity); } - else if (propName == "displayFrame") + else if (propName == "displayFrame" || propName == "spriteFrame") { static_cast(pNode)->setSpriteFrame(static_cast(obj)); } diff --git a/spritebuilder/CCBReader.cpp b/spritebuilder/CCBReader.cpp index c6ff23b..bc9de1d 100755 --- a/spritebuilder/CCBReader.cpp +++ b/spritebuilder/CCBReader.cpp @@ -68,10 +68,14 @@ float CCBReader::getPTMRatio() { void CCBReader::setupSpriteBuilder(const char* resourcePath, float ptmRatio) { _ptmRatio = ptmRatio; + std::vector searchPath; searchPath.push_back("Published-iOS"); FileUtils::getInstance()->setSearchPaths(searchPath); -// FileUtils::getInstance()->addSearchPath("Published-iOS") + char docPath[256] = {0}; + sprintf(docPath, "%s/Published-iOS", FileUtils::getInstance()->getWritablePath().c_str()); + FileUtils::getInstance()->addSearchPath(docPath, true); + FileUtils::getInstance()->addSearchResolutionsOrder(resourcePath); FileUtils::getInstance()->loadFilenameLookupDictionaryFromFile("fileLookup.plist"); @@ -1409,8 +1413,9 @@ CCBKeyframe* CCBReader::readKeyframe(PropertyType type) std::string spriteFile = readCachedString(); //std::string spriteSheet = readCachedString(); - SpriteFrame* spriteFrame; + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFile); //if (spriteSheet.length() == 0) + if (spriteFrame == nullptr) { spriteFile = _CCBRootPath + spriteFile; @@ -1435,6 +1440,9 @@ CCBKeyframe* CCBReader::readKeyframe(PropertyType type) spriteFrame = frameCache->getSpriteFrameByName(spriteFile.c_str()); } */ + + keyframe->setObject(spriteFrame); + } else { CCASSERT(false, "Unknown keyframe type!"); } diff --git a/spritebuilder/CCButton.cpp b/spritebuilder/CCButton.cpp new file mode 100755 index 0000000..a6af83a --- /dev/null +++ b/spritebuilder/CCButton.cpp @@ -0,0 +1,650 @@ +#include "CCButton.h" + +namespace spritebuilder { + +enum +{ + kZoomActionTag = 0xCCCB0001, +}; + +CCButton::CCButton() +: _isPushed(false) +, _parentInited(false) +, _currentTitleColor(Color3B::WHITE) +, _titleLabel(nullptr) +, _backgroundSprite(nullptr) +, _zoomOnTouchDown(false) +, m_bMoved(false) +, m_pOldPos(Point()) +, m_moveThreshold(kMoveThreshold) +, onTouchUpInside(nullptr) +{ + +} + +CCButton::~CCButton() +{ + CC_SAFE_RELEASE(_titleLabel); + CC_SAFE_RELEASE(_backgroundSprite); +} + +//initialisers + +bool CCButton::init() +{ + return this->initWithLabelAndBackgroundSprite(Label::createWithSystemFont("", "Helvetica", 12), Sprite::create()); +} + +bool CCButton::initWithLabelAndBackgroundSprite(Node* node, Sprite* backgroundSprite) +{ + if (Control::init()) + { + CCASSERT(node != nullptr, "node must not be nil."); + LabelProtocol* label = dynamic_cast(node); + CCASSERT(backgroundSprite != nullptr, "Background sprite must not be nil."); + CCASSERT(label != nullptr, "label must not be nil."); + + _parentInited = true; + + _isPushed = false; + + // Zooming button by default + _zoomOnTouchDown = true; + _scaleRatio = 1.1f; + + // Set the default anchor point + ignoreAnchorPointForPosition(false); + setAnchorPoint(Vec2::ANCHOR_MIDDLE); + + // Set the nodes + setTitleLabel(node); + setBackgroundSprite(backgroundSprite); + + // Set the default color and opacity + setColor(Color3B::WHITE); + setOpacity(255.0f); + setOpacityModifyRGB(true); + + // Initialize the dispatch table + + setTitleForState(label->getString(), Control::State::NORMAL); + setTitleColorForState(node->getColor(), Control::State::NORMAL); + setTitleLabelForState(node, Control::State::NORMAL); + setBackgroundSpriteForState(backgroundSprite, Control::State::NORMAL); + + setLabelAnchorPoint(Vec2::ANCHOR_MIDDLE); + + // Layout update + needsLayout(); + + return true; + } + //couldn't init the Control + else + { + return false; + } +} + +CCButton* CCButton::create(Node* label, Sprite* backgroundSprite) +{ + CCButton *pRet = new CCButton(); + pRet->initWithLabelAndBackgroundSprite(label, backgroundSprite); + pRet->autorelease(); + return pRet; +} + +bool CCButton::initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize) +{ + return initWithLabelAndBackgroundSprite(Label::createWithSystemFont(title, fontName, fontSize), Sprite::create()); +} + +CCButton* CCButton::create(const std::string& title, const std::string& fontName, float fontSize) +{ + CCButton *pRet = new CCButton(); + pRet->initWithTitleAndFontNameAndFontSize(title, fontName, fontSize); + pRet->autorelease(); + return pRet; +} + +bool CCButton::initWithBackgroundSprite(Sprite* sprite) +{ + Label *label = Label::createWithSystemFont("", "Arial", 30);// + return initWithLabelAndBackgroundSprite(label, sprite); +} + +CCButton* CCButton::create(Sprite* sprite) +{ + CCButton *pRet = new CCButton(); + pRet->initWithBackgroundSprite(sprite); + pRet->autorelease(); + return pRet; +} + +void CCButton::setEnabled(bool enabled) +{ + Control::setEnabled(enabled); + needsLayout(); +} + +void CCButton::setSelected(bool enabled) +{ + Control::setSelected(enabled); + needsLayout(); +} + +void CCButton::setHighlighted(bool enabled) +{ + if (enabled == true) + { + _state = Control::State::HIGH_LIGHTED; + } + else + { + _state = Control::State::NORMAL; + } + + Control::setHighlighted(enabled); + + Action *action = getActionByTag(kZoomActionTag); + if (action) + { + stopAction(action); + } + needsLayout(); + if( _zoomOnTouchDown ) + { + float scaleValue = (isHighlighted() && isEnabled() && !isSelected()) ? _scaleRatio : 1.0f; + Action *zoomAction = ScaleTo::create(0.05f, scaleValue); + zoomAction->setTag(kZoomActionTag); + runAction(zoomAction); + } +} + +void CCButton::setZoomOnTouchDown(bool zoomOnTouchDown) +{ + _zoomOnTouchDown = zoomOnTouchDown; +} + +bool CCButton::getZoomOnTouchDown() +{ + return _zoomOnTouchDown; +} + +void CCButton::setPreferredSize(const Size& size) +{ + _preferredSize = size; + needsLayout(); +} + +const Size& CCButton::getPreferredSize() const +{ + return _preferredSize; +} + +const Vec2& CCButton::getLabelAnchorPoint() const +{ + return this->_labelAnchorPoint; +} + +void CCButton::setLabelAnchorPoint(const Vec2& labelAnchorPoint) +{ + this->_labelAnchorPoint = labelAnchorPoint; + if (_titleLabel != nullptr) + { + this->_titleLabel->setAnchorPoint(labelAnchorPoint); + } +} + +std::string CCButton::getTitleForState(State state) +{ + auto iter = _titleDispatchTable.find((int)state); + if (iter != _titleDispatchTable.end()) + { + return iter->second; + } + + iter = _titleDispatchTable.find((int)Control::State::NORMAL); + + return iter != _titleDispatchTable.end() ? iter->second : ""; +} + +void CCButton::setTitleForState(const std::string& title, State state) +{ + _titleDispatchTable.erase((int)state); + + if (!title.empty()) + { + _titleDispatchTable[(int)state] = title; + } + + // If the current state if equal to the given state we update the layout + if (getState() == state) + { + needsLayout(); + } +} + + +Color3B CCButton::getTitleColorForState(State state) const +{ + Color3B returnColor = Color3B::WHITE; + + auto iter = _titleColorDispatchTable.find((int)state); + if (iter != _titleColorDispatchTable.end()) + { + returnColor = iter->second; + } + else + { + iter = _titleColorDispatchTable.find((int)Control::State::NORMAL); + if (iter != _titleColorDispatchTable.end()) + { + returnColor = iter->second; + } + } + + return returnColor; +} + +void CCButton::setTitleColorForState(const Color3B& color, State state) +{ + _titleColorDispatchTable.erase((int)state); + _titleColorDispatchTable[(int)state] = color; + + // If the current state if equal to the given state we update the layout + if (getState() == state) + { + needsLayout(); + } +} + +Node* CCButton::getTitleLabelForState(State state) +{ + Node* titleLabel = _titleLabelDispatchTable.at((int)state); + if (titleLabel) + { + return titleLabel; + } + return _titleLabelDispatchTable.at((int)Control::State::NORMAL); +} + +void CCButton::setTitleLabelForState(Node* titleLabel, State state) +{ + Node* previousLabel = _titleLabelDispatchTable.at((int)state); + if (previousLabel) + { + removeChild(previousLabel, true); + _titleLabelDispatchTable.erase((int)state); + } + + _titleLabelDispatchTable.insert((int)state, titleLabel); + titleLabel->setVisible(false); + titleLabel->setAnchorPoint(Vec2(0.5f, 0.5f)); + addChild(titleLabel, 1); + + // If the current state if equal to the given state we update the layout + if (getState() == state) + { + needsLayout(); + } +} + +void CCButton::setTitleTTFForState(const std::string& fontName, State state) +{ + this->setTitleLabelForState(Label::createWithSystemFont(getTitleForState(state), fontName, 12), state); +} + +const std::string& CCButton::getTitleTTFForState(State state) +{ + LabelProtocol* label = dynamic_cast(this->getTitleLabelForState(state)); + Label* labelTTF = dynamic_cast(label); + if(labelTTF != 0) + { + return labelTTF->getSystemFontName(); + } + + static std::string ret(""); + return ret; +} + +void CCButton::setTitleTTFSizeForState(float size, State state) +{ + LabelProtocol* label = dynamic_cast(this->getTitleLabelForState(state)); + if(label) + { + Label* labelTTF = dynamic_cast(label); + if(labelTTF != 0) + { + return labelTTF->setSystemFontSize(size); + } + } +} + +float CCButton::getTitleTTFSizeForState(State state) +{ + LabelProtocol* label = dynamic_cast(this->getTitleLabelForState(state)); + Label* labelTTF = dynamic_cast(label); + if(labelTTF != 0) + { + return labelTTF->getSystemFontSize(); + } + else + { + return 0; + } +} + +void CCButton::setTitleBMFontForState(const std::string& fntFile, State state) +{ + std::string title = this->getTitleForState(state); + this->setTitleLabelForState(Label::createWithBMFont(fntFile, title), state); +} + +const std::string& CCButton::getTitleBMFontForState(State state) +{ + LabelProtocol* label = dynamic_cast(this->getTitleLabelForState(state)); + auto labelBMFont = dynamic_cast(label); + if(labelBMFont != 0) + { + return labelBMFont->getBMFontFilePath(); + } + + static std::string ret(""); + return ret; +} + + +Sprite* CCButton::getBackgroundSpriteForState(State state) +{ + auto backgroundSprite = _backgroundSpriteDispatchTable.at((int)state); + if (backgroundSprite) + { + return backgroundSprite; + } + return _backgroundSpriteDispatchTable.at((int)Control::State::NORMAL); +} + + +void CCButton::setBackgroundSpriteForState(Sprite* sprite, State state) +{ + auto previousBackgroundSprite = _backgroundSpriteDispatchTable.at((int)state); + if (previousBackgroundSprite) + { + removeChild(previousBackgroundSprite, true); + _backgroundSpriteDispatchTable.erase((int)state); + } + + _backgroundSpriteDispatchTable.insert((int)state, sprite); + sprite->setVisible(false); + sprite->setAnchorPoint(Vec2(0.5f, 0.5f)); + addChild(sprite); + + // If the current state if equal to the given state we update the layout + if (getState() == state) + { + needsLayout(); + } +} + +void CCButton::setBackgroundSpriteFrameForState(SpriteFrame * spriteFrame, State state) +{ + Sprite * sprite = Sprite::createWithSpriteFrame(spriteFrame); + this->setBackgroundSpriteForState(sprite, state); +} + + +void CCButton::needsLayout() +{ + if (!_parentInited) { + return; + } + // Hide the background and the label + if (_titleLabel != nullptr) { + _titleLabel->setVisible(false); + } + if (_backgroundSprite) { + _backgroundSprite->setVisible(false); + } + // Update anchor of all labels + this->setLabelAnchorPoint(this->_labelAnchorPoint); + + // Update the label to match with the current state + _currentTitle = getTitleForState(_state); + + _currentTitleColor = getTitleColorForState(_state); + + this->setTitleLabel(getTitleLabelForState(_state)); + + LabelProtocol* label = dynamic_cast(_titleLabel); + if (label && !_currentTitle.empty()) + { + label->setString(_currentTitle); + } + + if (_titleLabel) + { + _titleLabel->setColor(_currentTitleColor); + } + if (_titleLabel != nullptr) + { + _titleLabel->setPosition(Vec2 (getContentSize().width / 2, getContentSize().height / 2)); + } + + // Update the background sprite + this->setBackgroundSprite(this->getBackgroundSpriteForState(_state)); + if (_backgroundSprite != nullptr) + { + _backgroundSprite->setPosition(Vec2 (getContentSize().width / 2, getContentSize().height / 2)); + } + + // Get the title label size + Size titleLabelSize; + if (_titleLabel != nullptr) + { + titleLabelSize = _titleLabel->getBoundingBox().size; + } + + // Set the content size + Rect rectTitle; + if (_titleLabel != nullptr) + { + rectTitle = _titleLabel->getBoundingBox(); + } + Rect rectBackground; + if (_backgroundSprite != nullptr) + { + rectBackground = _backgroundSprite->getBoundingBox(); + } + + Rect maxRect = ControlUtils::RectUnion(rectTitle, rectBackground); + maxRect = ControlUtils::RectUnion(Rect(0, 0, _preferredSize.width, _preferredSize.height), maxRect); + setContentSize(Size(maxRect.size.width, maxRect.size.height)); + + if (_titleLabel != nullptr) + { + _titleLabel->setPosition(Vec2(getContentSize().width/2, getContentSize().height/2)); + // Make visible the background and the label + _titleLabel->setVisible(true); + } + + if (_backgroundSprite != nullptr) + { + _backgroundSprite->setPosition(Vec2(getContentSize().width/2, getContentSize().height/2)); + _backgroundSprite->setVisible(true); + } +} + +bool CCButton::onTouchBegan(Touch *pTouch, Event *pEvent) +{ + if (!isTouchInside(pTouch) || !isEnabled() || !isVisible() || !hasVisibleParents() ) + { + return false; + } + + for (Node *c = this->_parent; c != nullptr; c = c->getParent()) + { + if (c->isVisible() == false) + { + return false; + } + } + + _isPushed = true; + this->setHighlighted(true); + sendActionsForControlEvents(Control::EventType::TOUCH_DOWN); + + //TODO: parent is null + m_pOldPos = getParent()->convertToWorldSpace(this->getPosition()); + m_bMoved = false; + + return true; +} + +void CCButton::onTouchMoved(Touch *pTouch, Event *pEvent) +{ + if (!isEnabled() || !isPushed() || isSelected()) + { + if (isHighlighted()) + { + setHighlighted(false); + } + return; + } + + //TODO: parent is null + Point p = getParent()->convertToWorldSpace(getPosition()); + if(fabsf(p.x - m_pOldPos.x) > m_moveThreshold || + fabsf(p.y - m_pOldPos.y) > m_moveThreshold) { + m_bMoved = true; + } + + bool isTouchMoveInside = isTouchInside(pTouch); + if (isTouchMoveInside && !isHighlighted()) + { + setHighlighted(true); + sendActionsForControlEvents(Control::EventType::DRAG_ENTER); + } + else if (isTouchMoveInside && isHighlighted()) + { + sendActionsForControlEvents(Control::EventType::DRAG_INSIDE); + } + else if (!isTouchMoveInside && isHighlighted()) + { + setHighlighted(false); + + sendActionsForControlEvents(Control::EventType::DRAG_EXIT); + } + else if (!isTouchMoveInside && !isHighlighted()) + { + sendActionsForControlEvents(Control::EventType::DRAG_OUTSIDE); + } +} +void CCButton::onTouchEnded(Touch *pTouch, Event *pEvent) +{ + _isPushed = false; + setHighlighted(false); + + if (m_bMoved) { + //send CCControlEventValueChanged for replace + sendActionsForControlEvents(Control::EventType::VALUE_CHANGED); + m_bMoved = false; + return; + } + m_bMoved = false; + + if (isTouchInside(pTouch)) + { + if (onTouchUpInside) { + onTouchUpInside(this); + }else { + sendActionsForControlEvents(Control::EventType::TOUCH_UP_INSIDE); + } + } + else + { + sendActionsForControlEvents(Control::EventType::TOUCH_UP_OUTSIDE); + } +} + +void CCButton::setOpacity(GLubyte opacity) +{ + Control::setOpacity(opacity); + + for (auto iter = _backgroundSpriteDispatchTable.begin(); iter != _backgroundSpriteDispatchTable.end(); ++iter) + { + iter->second->setOpacity(opacity); + } + + for (auto iter = _titleLabelDispatchTable.begin(); iter != _titleLabelDispatchTable.end(); ++iter) + { + iter->second->setOpacity(opacity); + } +} + +void CCButton::updateDisplayedOpacity(GLubyte parentOpacity) +{ + Control::updateDisplayedOpacity(parentOpacity); + + for (auto iter = _backgroundSpriteDispatchTable.begin(); iter != _backgroundSpriteDispatchTable.end(); ++iter) + { + iter->second->updateDisplayedOpacity(parentOpacity); + } + + for (auto iter = _titleLabelDispatchTable.begin(); iter != _titleLabelDispatchTable.end(); ++iter) + { + iter->second->updateDisplayedOpacity(parentOpacity); + } +} + +void CCButton::setColor(const Color3B & color) +{ + Control::setColor(color); + + for (auto iter = _backgroundSpriteDispatchTable.begin(); iter != _backgroundSpriteDispatchTable.end(); ++iter) + { + iter->second->setColor(color); + } + + for (auto iter = _titleLabelDispatchTable.begin(); iter != _titleLabelDispatchTable.end(); ++iter) + { + iter->second->setColor(color); + } +} + +void CCButton::updateDisplayedColor(const Color3B& parentColor) +{ + Control::updateDisplayedColor(parentColor); + + for (auto iter = _backgroundSpriteDispatchTable.begin(); iter != _backgroundSpriteDispatchTable.end(); ++iter) + { + iter->second->updateDisplayedColor(parentColor); + } + + for (auto iter = _titleLabelDispatchTable.begin(); iter != _titleLabelDispatchTable.end(); ++iter) + { + iter->second->updateDisplayedColor(parentColor); + } +} + +void CCButton::onTouchCancelled(Touch *pTouch, Event *pEvent) +{ + _isPushed = false; + setHighlighted(false); + sendActionsForControlEvents(Control::EventType::TOUCH_CANCEL); +} + +CCButton* CCButton::create() +{ + CCButton *pCCButton = new CCButton(); + if (pCCButton && pCCButton->init()) + { + pCCButton->autorelease(); + return pCCButton; + } + CC_SAFE_DELETE(pCCButton); + return nullptr; +} + +} + diff --git a/spritebuilder/CCButton.h b/spritebuilder/CCButton.h new file mode 100755 index 0000000..2f8946d --- /dev/null +++ b/spritebuilder/CCButton.h @@ -0,0 +1,211 @@ +#ifndef __CCBUTTON_H__ +#define __CCBUTTON_H__ + +#include "cocos2d.h" +#include "cocos-ext.h" +#include "base/CCMap.h" + +USING_NS_CC; +USING_NS_CC_EXT; +using namespace std; + +namespace spritebuilder { + +/* Define the button move threshold for cancel actions */ +#define kMoveThreshold 20.0 + +class CCButton : public Control +{ +public: + static CCButton* create(); + static CCButton* create(Sprite* sprite); + static CCButton* create(Node* label, Sprite* backgroundSprite); + static CCButton* create(const std::string& title, const std::string& fontName, float fontSize); + + virtual void needsLayout(void); + + virtual void setEnabled(bool enabled); + virtual void setSelected(bool enabled); + virtual void setHighlighted(bool enabled); + + bool isPushed() const { return _isPushed; } + + /** + * Returns the title used for a state. + * + * @param state The state that uses the title. Possible values are described in + * "CCControlState". + * + * @return The title for the specified state. + */ + virtual std::string getTitleForState(State state); + + /** + * Sets the title string to use for the specified state. + * If a property is not specified for a state, the default is to use + * the ButtonStateNormal value. + * + * @param title The title string to use for the specified state. + * @param state The state that uses the specified title. The values are described + * in "CCControlState". + */ + virtual void setTitleForState(const std::string& title, State state); + + /** + * Returns the title color used for a state. + * + * @param state The state that uses the specified color. The values are described + * in "CCControlState". + * + * @return The color of the title for the specified state. + */ + + virtual Color3B getTitleColorForState(State state) const; + + /** + * Sets the color of the title to use for the specified state. + * + * @param color The color of the title to use for the specified state. + * @param state The state that uses the specified color. The values are described + * in "CCControlState". + */ + virtual void setTitleColorForState(const Color3B& color, State state); + + /** + * Returns the title label used for a state. + * + * @param state The state that uses the title label. Possible values are described + * in "CCControlState". + */ + virtual Node* getTitleLabelForState(State state); + + /** + * Sets the title label to use for the specified state. + * If a property is not specified for a state, the default is to use + * the ButtonStateNormal value. + * + * @param label The title label to use for the specified state. + * @param state The state that uses the specified title. The values are described + * in "CCControlState". + */ + virtual void setTitleLabelForState(Node* label, State state); + + virtual void setTitleTTFForState(const std::string& fntFile, State state); + virtual const std::string& getTitleTTFForState(State state); + + virtual void setTitleTTFSizeForState(float size, State state); + virtual float getTitleTTFSizeForState(State state); + + /** + * Sets the font of the label, changes the label to a BMFont if neccessary. + * @param fntFile The name of the font to change to + * @param state The state that uses the specified fntFile. The values are described + * in "CCControlState". + */ + virtual void setTitleBMFontForState(const std::string& fntFile, State state); + virtual const std::string& getTitleBMFontForState(State state); + + /** + * Returns the background sprite used for a state. + * + * @param state The state that uses the background sprite. Possible values are + * described in "CCControlState". + */ + virtual Sprite* getBackgroundSpriteForState(State state); + + /** + * Sets the background sprite to use for the specified button state. + * + * @param sprite The background sprite to use for the specified state. + * @param state The state that uses the specified image. The values are described + * in "CCControlState". + */ + virtual void setBackgroundSpriteForState(Sprite* sprite, State state); + + /** + * Sets the background spriteFrame to use for the specified button state. + * + * @param spriteFrame The background spriteFrame to use for the specified state. + * @param state The state that uses the specified image. The values are described + * in "CCControlState". + */ + virtual void setBackgroundSpriteFrameForState(SpriteFrame * spriteFrame, State state); + + // Overrides + virtual bool onTouchBegan(Touch *touch, Event *event) override; + virtual void onTouchMoved(Touch *touch, Event *event) override; + virtual void onTouchEnded(Touch *touch, Event *event) override; + virtual void onTouchCancelled(Touch *touch, Event *event) override; + + virtual void setOpacity(GLubyte var) override; + virtual void updateDisplayedOpacity(GLubyte parentOpacity) override; + virtual void setColor(const Color3B&) override; + virtual void updateDisplayedColor(const Color3B& parentColor) override; + + const std::string& getCurrentTitle() const { return _currentTitle; }; + std::string getCurrentTitle() { return _currentTitle; }; + +CC_CONSTRUCTOR_ACCESS: + /** + * @js ctor + */ + CCButton(); + /** + * @js NA + * @lua NA + */ + virtual ~CCButton(); + + virtual bool init() override; + virtual bool initWithLabelAndBackgroundSprite(Node* label, Sprite* backgroundSprite); + virtual bool initWithBackgroundSprite(Sprite* sprite); + virtual bool initWithTitleAndFontNameAndFontSize(const std::string& title, const std::string& fontName, float fontSize); + +protected: + bool _isPushed; + bool _parentInited; + + Point m_pOldPos; + bool m_bMoved; + CC_SYNTHESIZE_PASS_BY_REF(float, m_moveThreshold, MoveThreshold); + + /** The current title that is displayed on the button. */ + std::string _currentTitle; + + /** The current color used to display the title. */ + CC_SYNTHESIZE_READONLY_PASS_BY_REF(Color3B, _currentTitleColor, CurrentTitleColor); + + /** The current title label. */ + CC_SYNTHESIZE_RETAIN(Node*, _titleLabel, TitleLabel); + + /** The current background sprite. */ + CC_SYNTHESIZE_RETAIN(Sprite*, _backgroundSprite, BackgroundSprite); + + /** The prefered size of the button, if label is larger it will be expanded. */ + CC_PROPERTY_PASS_BY_REF(Size, _preferredSize, PreferredSize); + + /** Adjust the button zooming on touchdown. Default value is YES. */ + CC_PROPERTY(bool, _zoomOnTouchDown, ZoomOnTouchDown); + /** Scale ratio button on touchdown. Default value 1.1f */ + CC_SYNTHESIZE(float, _scaleRatio, ScaleRatio); + + CC_PROPERTY_PASS_BY_REF(Vec2, _labelAnchorPoint, LabelAnchorPoint); + + std::unordered_map _titleDispatchTable; + std::unordered_map _titleColorDispatchTable; + + Map _titleLabelDispatchTable; + Map _backgroundSpriteDispatchTable; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(CCButton); + +public: + std::function onTouchUpInside; // high pirority than [sendActionsForControlEvents(Control::EventType::TOUCH_UP_INSIDE)] + +}; + + +} + +#endif \ No newline at end of file diff --git a/spritebuilder/CCButtonLoader.cpp b/spritebuilder/CCButtonLoader.cpp new file mode 100644 index 0000000..08e0c44 --- /dev/null +++ b/spritebuilder/CCButtonLoader.cpp @@ -0,0 +1,216 @@ +// +// CCButtonLoader.cpp +// cocos2d_libs +// +// Created by LiuHuanMing on 8/1/14. +// +// + +#include "CCButtonLoader.h" + +using namespace cocos2d; +using namespace cocos2d::extension; + +namespace spritebuilder { + +#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" +#define PROPERTY_PREFEREDSIZE "preferredSize" // TODO Should be "preferredSize". This is a typo in cocos2d-iphone, cocos2d-x and CocosBuilder! +#define PROPERTY_TITLE_FONTNAME "fontName" +#define PROPERTY_TITLE_FONTSIZE "fontSize" +#define PROPERTY_HORIZONTAL_PADDING "horizontalPadding" +#define PROPERTY_VERTICAL_PADDING "verticalPadding" + +#define PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL "backgroundSpriteFrame|Normal" +#define PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED "backgroundSpriteFrame|Highlighted" +#define PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED "backgroundSpriteFrame|Disabled" +#define PROPERTY_BACKGROUNDSPRITEFRAME_SELECTED "backgroundSpriteFrame|Selected" + +#define PROPERTY_LABELCOLOR_NORMAL "labelColor|Normal" +#define PROPERTY_LABELCOLOR_HIGHLIGHTED "labelColor|Highlighted" +#define PROPERTY_LABELCOLOR_DISABLED "labelColor|Disabled" + +#define PROPERTY_LABELCOLOR "labelColor" +#define PROPERTY_OUTLINE_COLOR "outlineColor" +#define PROPERTY_FONT_COLOR "fontColor" +#define PROPERTY_OUTLINE_WIDTH "outlineWidth" +#define PROPERTY_SHADOW_COLOR "shadowColor" + +#define PROPERTY_SHADOW_BLUR_RADIUS "shadowBlurRadius" + +#define PROPERTY_SHADOW_OFFSET "shadowOffset" +#define PROPERTY_TITLE "title" + +#define PROPERTY_MAXSIZE "maxSize" + +CCButton * CCButtonLoader::createNode(cocos2d::Node * pParent, CCBReader * ccbReader) { + auto pRet = CCButton::create(); + return pRet; +} + +void CCButtonLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char * pPropertyName, bool pCheck, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_ZOOMONTOUCHDOWN) == 0) { + ((CCButton *)pNode)->setZoomOnTouchDown(pCheck); + } else { + ControlLoader::onHandlePropTypeCheck(pNode, pParent, pPropertyName, pCheck, ccbReader); + } +} + +void CCButtonLoader::onHandlePropTypeString(Node * pNode, Node * pParent, const char * pPropertyName, const char * pString, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_TITLE_NORMAL) == 0) { + ((CCButton *)pNode)->setTitleForState(pString, Control::State::NORMAL); + } else if(strcmp(pPropertyName, PROPERTY_TITLE_HIGHLIGHTED) == 0) { + ((CCButton *)pNode)->setTitleForState(pString, Control::State::HIGH_LIGHTED); + } else if(strcmp(pPropertyName, PROPERTY_TITLE_DISABLED) == 0) { + ((CCButton *)pNode)->setTitleForState(pString, Control::State::DISABLED); + } else if(strcmp(pPropertyName, PROPERTY_TITLE) == 0) { + ((CCButton *)pNode)->setTitleForState(pString, Control::State::NORMAL); + ((CCButton *)pNode)->setTitleForState(pString, Control::State::HIGH_LIGHTED); + ((CCButton *)pNode)->setTitleForState(pString, Control::State::DISABLED); + } else { + ControlLoader::onHandlePropTypeString(pNode, pParent, pPropertyName, pString, ccbReader); + } +} + +void CCButtonLoader::onHandlePropTypeFontTTF(Node * pNode, Node * pParent, const char * pPropertyName, const char * pFontTTF, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_TITLETTF_NORMAL) == 0) { + ((CCButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::NORMAL); + } else if(strcmp(pPropertyName, PROPERTY_TITLETTF_HIGHLIGHTED) == 0) { + ((CCButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::HIGH_LIGHTED); + } else if(strcmp(pPropertyName, PROPERTY_TITLETTF_DISABLED) == 0) { + ((CCButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::DISABLED); + + } else if(strcmp(pPropertyName, PROPERTY_TITLE_FONTNAME) == 0) { + ((CCButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::NORMAL); + ((CCButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::HIGH_LIGHTED); + ((CCButton *)pNode)->setTitleTTFForState(pFontTTF, Control::State::DISABLED); + } else { + ControlLoader::onHandlePropTypeFontTTF(pNode, pParent, pPropertyName, pFontTTF, ccbReader); + } +} + +void CCButtonLoader::onHandlePropTypeFloatScale(Node * pNode, Node * pParent, const char * pPropertyName, float pFloatScale, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_NORMAL) == 0) { + ((CCButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::NORMAL); + } else if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_HIGHLIGHTED) == 0) { + ((CCButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::HIGH_LIGHTED); + } else if(strcmp(pPropertyName, PROPERTY_TITLETTFSIZE_DISABLED) == 0) { + ((CCButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::DISABLED); + } else if(strcmp(pPropertyName, PROPERTY_TITLE_FONTSIZE) == 0) { + ((CCButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::NORMAL); + ((CCButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::HIGH_LIGHTED); + ((CCButton *)pNode)->setTitleTTFSizeForState(pFloatScale, Control::State::DISABLED); + } else if(strcmp(pPropertyName, PROPERTY_HORIZONTAL_PADDING) == 0) { +// ((CCButton *)pNode)->setHorizonPadding(pFloatScale); + } else if(strcmp(pPropertyName, PROPERTY_VERTICAL_PADDING) == 0) { +// ((CCButton *)pNode)->setVerticalPadding(pFloatScale); + } else if(strcmp(pPropertyName, PROPERTY_OUTLINE_WIDTH) == 0) { + _outlineWidth = pFloatScale; + } else if(strcmp(pPropertyName, PROPERTY_SHADOW_BLUR_RADIUS) == 0) { + _shadowBlurRadius = pFloatScale; + } else { + ControlLoader::onHandlePropTypeFloatScale(pNode, pParent, pPropertyName, pFloatScale, ccbReader); + } +} + +void CCButtonLoader::onHandlePropTypePosition(cocos2d::Node * pNode,cocos2d:: Node * pParent, const char* pPropertyName, cocos2d::Point pPosition, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_SHADOW_OFFSET) == 0) { + _shadowOffset = pPosition; + } else { + ControlLoader::onHandlePropTypePosition(pNode, pParent, pPropertyName, pPosition, ccbReader); + } +} +void CCButtonLoader::onHandlePropTypePoint(Node * pNode, Node * pParent, const char * pPropertyName, Point pPoint, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_LABELANCHORPOINT) == 0) { + ((CCButton *)pNode)->setLabelAnchorPoint(pPoint); + } else { + ControlLoader::onHandlePropTypePoint(pNode, pParent, pPropertyName, pPoint, ccbReader); + } +} + +void CCButtonLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, const char * pPropertyName, Size pSize, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_PREFEREDSIZE) == 0) { + ((CCButton *)pNode)->setPreferredSize(pSize); + } else if(strcmp(pPropertyName, PROPERTY_MAXSIZE) == 0) { +// ((CCButton *)pNode)->setMaxSize(pSize); + } else { + ControlLoader::onHandlePropTypeSize(pNode, pParent, pPropertyName, pSize, ccbReader); + } +} + +void CCButtonLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL) == 0) { + if(pSpriteFrame != NULL) { + ((CCButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::NORMAL); + } + } else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED) == 0) { + if(pSpriteFrame != NULL) { + ((CCButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::HIGH_LIGHTED); + } + } else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED) == 0) { + if(pSpriteFrame != NULL) { + ((CCButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::DISABLED); + } + } else if(strcmp(pPropertyName, PROPERTY_BACKGROUNDSPRITEFRAME_SELECTED) == 0) { + if(pSpriteFrame != NULL) { + ((CCButton *)pNode)->setBackgroundSpriteFrameForState(pSpriteFrame, Control::State::SELECTED); + } + } else { + ControlLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pSpriteFrame, ccbReader); + } +} + +void CCButtonLoader::onHandlePropTypeColor4(Node * pNode, Node * pParent, const char * pPropertyName, Color4F pColor4F, CCBReader * ccbReader) { + if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_NORMAL) == 0) { + ((CCButton *)pNode)->setTitleColorForState(COLOR4F_TO_COLOR3B(pColor4F), Control::State::NORMAL); + } else if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_HIGHLIGHTED) == 0) { + ((CCButton *)pNode)->setTitleColorForState(COLOR4F_TO_COLOR3B(pColor4F), Control::State::HIGH_LIGHTED); + } else if(strcmp(pPropertyName, PROPERTY_TITLECOLOR_DISABLED) == 0) { + ((CCButton *)pNode)->setTitleColorForState(COLOR4F_TO_COLOR3B(pColor4F), Control::State::DISABLED); + + } else if(strcmp(pPropertyName, PROPERTY_LABELCOLOR_NORMAL) == 0) { + ((CCButton *)pNode)-> setTitleColorForState(COLOR4F_TO_COLOR3B(pColor4F), Control::State::NORMAL); + } else if(strcmp(pPropertyName, PROPERTY_LABELCOLOR_HIGHLIGHTED) == 0) { + ((CCButton *)pNode)-> setTitleColorForState(COLOR4F_TO_COLOR3B(pColor4F), Control::State::HIGH_LIGHTED); + } else if(strcmp(pPropertyName, PROPERTY_LABELCOLOR_DISABLED) == 0) { + ((CCButton *)pNode)-> setTitleColorForState(COLOR4F_TO_COLOR3B(pColor4F), Control::State::DISABLED); + } else if(strcmp(pPropertyName, PROPERTY_LABELCOLOR) == 0) { + ((CCButton *)pNode)->getTitleLabel()->setColor(COLOR4F_TO_COLOR3B(pColor4F)); + } else if(strcmp(pPropertyName, PROPERTY_OUTLINE_COLOR) == 0) { + _outlineColor = pColor4F; + } else if(strcmp(pPropertyName, PROPERTY_FONT_COLOR) == 0) { + ((CCButton *)pNode)->setTitleColorForState(Color3B(pColor4F.r, pColor4F.g, pColor4F.b), Control::State::NORMAL); + ((CCButton *)pNode)->setTitleColorForState(Color3B(pColor4F.r, pColor4F.g, pColor4F.b), Control::State::HIGH_LIGHTED); + ((CCButton *)pNode)->setTitleColorForState(Color3B(pColor4F.r, pColor4F.g, pColor4F.b), Control::State::DISABLED); + } else if(strcmp(pPropertyName, PROPERTY_SHADOW_COLOR) == 0) { + _shadowColor = pColor4F; + } else { + ControlLoader::onHandlePropTypeColor4(pNode, pParent, pPropertyName, pColor4F, ccbReader); + } +} + +void CCButtonLoader::onHandlePropTypeIntegerLabeled(Node * pNode, Node * pParent, const char* pPropertyName, int pIntegerLabeled, CCBReader * ccbReader) +{ + if (strcmp(pPropertyName, "horizontalAlignment") == 0) { + + } else if (strcmp(pPropertyName, "verticalAlignment") == 0) { + + } else { + ControlLoader::onHandlePropTypeIntegerLabeled(pNode, pParent, pPropertyName, pIntegerLabeled, ccbReader); + }; +} + +} + diff --git a/spritebuilder/CCButtonLoader.h b/spritebuilder/CCButtonLoader.h new file mode 100644 index 0000000..1ccb27a --- /dev/null +++ b/spritebuilder/CCButtonLoader.h @@ -0,0 +1,56 @@ +// +// CCButtonLoader.h +// cocos2d_libs +// +// Created by LiuHuanMing on 8/1/14. +// +// + +#ifndef __cocos2d_libs__CCButtonLoader__ +#define __cocos2d_libs__CCButtonLoader__ + +#include "CCControlLoader.h" +#include "extensions//GUI/CCControlExtension/CCControlButton.h" +#include "spritebuilder/CCButton.h" + +namespace spritebuilder { + +class CCButtonLoader : public ControlLoader { +public: + /** + * @js NA + * @lua NA + */ + virtual ~CCButtonLoader() {}; + /** + * @js NA + * @lua NA + */ + SB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(CCButtonLoader, loader); + +protected: + + virtual CCButton * createNode(cocos2d::Node * pParent, CCBReader * ccbReader); + + virtual void onHandlePropTypeCheck(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, bool pCheck, CCBReader * ccbReader); + virtual void onHandlePropTypeString(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, const char * pString, CCBReader * ccbReader); + virtual void onHandlePropTypeFontTTF(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, const char * pFontTTF, CCBReader * ccbReader); + virtual void onHandlePropTypeFloatScale(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, float pFloatScale, CCBReader * ccbReader); + virtual void onHandlePropTypePoint(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, cocos2d::Point pPoint, CCBReader * ccbReader); + virtual void onHandlePropTypeSize(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, cocos2d::Size pSize, CCBReader * ccbReader); + virtual void onHandlePropTypeSpriteFrame(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, cocos2d::SpriteFrame * pSpriteFrame, CCBReader * ccbReader); + virtual void onHandlePropTypeColor4(cocos2d::Node * pNode, cocos2d::Node * pParent, const char * pPropertyName, cocos2d::Color4F pColor4F, CCBReader * ccbReader); + virtual void onHandlePropTypePosition(cocos2d::Node * pNode,cocos2d:: Node * pParent, const char* pPropertyName, cocos2d::Point pPosition, CCBReader * ccbReader); + virtual void onHandlePropTypeIntegerLabeled(Node * pNode, Node * pParent, const char* pPropertyName, int pIntegerLabeled, CCBReader * ccbReader); + +protected: + float _outlineWidth; + float _shadowBlurRadius; + cocos2d::Point _shadowOffset; + cocos2d::Color4F _outlineColor; + cocos2d::Color4F _shadowColor; +}; + +} + +#endif /* defined(__cocos2d_libs__CCButtonLoader__) */ diff --git a/spritebuilder/CCNodeLoader.cpp b/spritebuilder/CCNodeLoader.cpp index 97fdae2..1a26aff 100644 --- a/spritebuilder/CCNodeLoader.cpp +++ b/spritebuilder/CCNodeLoader.cpp @@ -62,7 +62,19 @@ void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbRe // Skip properties that doesn't have a value to override CCSet* extraPropsNames = (CCSet*)pNode->getUserObject(); - setProp &= extraPropsNames->containsObject(CCString::create(propertyName)); + bool foundProperty = false; + __SetIterator it; + for( it = extraPropsNames->begin(); it != extraPropsNames->end(); ++it) { + __String *propName = (__String*)*it; + if (strcmp(propertyName.c_str(), propName->getCString()) == 0) { + foundProperty = true; + break; + } + } + + setProp &= foundProperty; + +// setProp &= extraPropsNames->containsObject(CCString::create(propertyName)); } } else if (isExtraProp && pNode == ccbReader->getAnimationManager()->getRootNode()) @@ -127,10 +139,10 @@ void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbRe } else if (isExtraProp && pNode == ccbReader->getAnimationManager()->getRootNode()) { - __Array *extraPropsNames = static_cast<__Array*>(pNode->getUserObject()); + CCSet *extraPropsNames = static_cast(pNode->getUserObject()); if (! extraPropsNames) { - extraPropsNames = Array::create(); + extraPropsNames = CCSet::create(); pNode->setUserObject(extraPropsNames); } @@ -1293,8 +1305,16 @@ void NodeLoader::onHandlePropTypeFntFile(Node * pNode, Node * pParent, const cha void NodeLoader::onHandlePropTypeString(Node * pNode, Node * pParent, const char* pPropertyName, const char * pString, CCBReader * ccbReader) { // ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName); - // It may be a custom property, add it to custom property dictionary. - _customProperties[pPropertyName] = Value(pString); + if(strcmp(pPropertyName, PROPERTY_NAME) == 0) { +#if COCOS2D_VERSION >= 0x030200 + pNode->setName(pString); +#else + CCLOG("NOT supported setName() on current cocos2d version"); +#endif + }else { + // It may be a custom property, add it to custom property dictionary. + _customProperties[pPropertyName] = Value(pString); + } } void NodeLoader::onHandlePropTypeText(Node * pNode, Node * pParent, const char* pPropertyName, const char * pText, CCBReader * ccbReader) { diff --git a/spritebuilder/CCNodeLoader.h b/spritebuilder/CCNodeLoader.h index 8604c4b..2478f0d 100644 --- a/spritebuilder/CCNodeLoader.h +++ b/spritebuilder/CCNodeLoader.h @@ -19,6 +19,7 @@ namespace spritebuilder { #define PROPERTY_TAG "tag" #define PROPERTY_IGNOREANCHORPOINTFORPOSITION "ignoreAnchorPointForPosition" #define PROPERTY_VISIBLE "visible" +#define PROPERTY_NAME "name" #define ASSERT_FAIL_UNEXPECTED_PROPERTY(PROPERTY) cocos2d::log("Unexpected property: '%s'!\n", PROPERTY); assert(false) #define ASSERT_FAIL_UNEXPECTED_PROPERTYTYPE(PROPERTYTYPE) cocos2d::log("Unexpected property type: '%d'!\n", PROPERTYTYPE); assert(false) diff --git a/spritebuilder/CCNodeLoaderLibrary.cpp b/spritebuilder/CCNodeLoaderLibrary.cpp index 1166995..d5a81b7 100644 --- a/spritebuilder/CCNodeLoaderLibrary.cpp +++ b/spritebuilder/CCNodeLoaderLibrary.cpp @@ -18,6 +18,7 @@ #include "CCLayoutBoxLoader.h" #include "CCSliderLoader.h" #include "CCTextFieldLoader.h" +#include "CCButtonLoader.h" using namespace cocos2d; @@ -55,7 +56,8 @@ void NodeLoaderLibrary::registerDefaultNodeLoaders() { this->registerNodeLoader("CCNodeGradient", LayerGradientLoader::loader()); this->registerNodeLoader("CCNodeColor", LayerColorLoader::loader()); - this->registerNodeLoader("CCButton", ControlButtonLoader::loader()); + this->registerNodeLoader("CCButton", CCButtonLoader::loader()); +// this->registerNodeLoader("CCButton", ControlButtonLoader::loader()); this->registerNodeLoader("CCPhysicsNode", PhysicsNodeLoader::loader()); this->registerNodeLoader("CCLayoutBox", LayoutBoxLoader::loader()); diff --git a/spritebuilder/SpriteBuilder.h b/spritebuilder/SpriteBuilder.h index e085968..54520a4 100644 --- a/spritebuilder/SpriteBuilder.h +++ b/spritebuilder/SpriteBuilder.h @@ -30,5 +30,6 @@ #include "spritebuilder/CCBLocalizationManager.h" #include "spritebuilder/CCPhysicsNode.h" #include "spritebuilder/CCBPhysicsBody.h" +#include "spritebuilder/CCButton.h" #endif // __EDITOR_SUPPORT_SPRITEBUILDER_H__