2014-03-24 15:25:44 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Valentin Milea
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CPROTECTEDCNODE_H__
|
|
|
|
#define __CPROTECTEDCNODE_H__
|
|
|
|
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCNode.h"
|
2014-03-24 15:25:44 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
2014-07-21 17:45:56 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup _2d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*@brief A inner node type mainly used for UI module.
|
|
|
|
* It is useful for composing complex node type and it's children are protected.
|
|
|
|
*/
|
2014-07-31 16:38:55 +08:00
|
|
|
class CC_DLL ProtectedNode : public Node
|
2014-03-24 15:25:44 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Creates a ProtectedNode with no argument.
|
|
|
|
*@return A instance of ProtectedNode.
|
|
|
|
*/
|
2014-03-24 15:25:44 +08:00
|
|
|
static ProtectedNode * create(void);
|
|
|
|
|
|
|
|
/// @{
|
|
|
|
/// @name Children and Parent
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a child to the container with z-order as 0.
|
|
|
|
*
|
|
|
|
* If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
|
|
|
|
*
|
|
|
|
* @param child A child node
|
|
|
|
*/
|
|
|
|
virtual void addProtectedChild(Node * child);
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Adds a child to the container with a local z-order.
|
2014-03-24 15:25:44 +08:00
|
|
|
*
|
|
|
|
* If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
|
|
|
|
*
|
|
|
|
* @param child A child node
|
|
|
|
* @param zOrder Z order for drawing priority. Please refer to `setLocalZOrder(int)`
|
|
|
|
*/
|
|
|
|
virtual void addProtectedChild(Node * child, int localZOrder);
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Adds a child to the container with z order and tag.
|
2014-03-24 15:25:44 +08:00
|
|
|
*
|
|
|
|
* If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
|
|
|
|
*
|
|
|
|
* @param child A child node
|
|
|
|
* @param zOrder Z order for drawing priority. Please refer to `setLocalZOrder(int)`
|
|
|
|
* @param tag An integer to identify the node easily. Please refer to `setTag(int)`
|
|
|
|
*/
|
|
|
|
virtual void addProtectedChild(Node* child, int localZOrder, int tag);
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Gets a child from the container with its tag.
|
2014-03-24 15:25:44 +08:00
|
|
|
*
|
|
|
|
* @param tag An identifier to find the child node.
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return a Node object whose tag equals to the input parameter.
|
2014-03-24 15:25:44 +08:00
|
|
|
*/
|
|
|
|
virtual Node * getProtectedChildByTag(int tag);
|
|
|
|
|
|
|
|
////// REMOVES //////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
|
|
|
|
*
|
|
|
|
* @param child The child node which will be removed.
|
|
|
|
* @param cleanup true if all running actions and callbacks on the child node will be cleanup, false otherwise.
|
|
|
|
*/
|
|
|
|
virtual void removeProtectedChild(Node* child, bool cleanup = true);
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter.
|
2014-03-24 15:25:44 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param tag An interger number that identifies a child node.
|
2014-03-24 15:25:44 +08:00
|
|
|
* @param cleanup true if all running actions and callbacks on the child node will be cleanup, false otherwise.
|
|
|
|
*/
|
|
|
|
virtual void removeProtectedChildByTag(int tag, bool cleanup = true);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-03-24 15:25:44 +08:00
|
|
|
/**
|
|
|
|
* Removes all children from the container with a cleanup.
|
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @see `removeAllChildrenWithCleanup(bool)`.
|
2014-03-24 15:25:44 +08:00
|
|
|
*/
|
|
|
|
virtual void removeAllProtectedChildren();
|
|
|
|
/**
|
|
|
|
* Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter.
|
|
|
|
*
|
|
|
|
* @param cleanup true if all running actions on all children nodes should be cleanup, false oterwise.
|
|
|
|
* @js removeAllChildren
|
|
|
|
* @lua removeAllChildren
|
|
|
|
*/
|
|
|
|
virtual void removeAllProtectedChildrenWithCleanup(bool cleanup);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reorders a child according to a new z value.
|
|
|
|
*
|
|
|
|
* @param child An already added child node. It MUST be already added.
|
|
|
|
* @param localZOrder Z order for drawing priority. Please refer to setLocalZOrder(int)
|
|
|
|
*/
|
|
|
|
virtual void reorderProtectedChild(Node * child, int localZOrder);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sorts the children array once before drawing, instead of every time when a child is added or reordered.
|
|
|
|
* This appraoch can improves the performance massively.
|
|
|
|
* @note Don't call this manually unless a child added needs to be removed in the same frame
|
|
|
|
*/
|
|
|
|
virtual void sortAllProtectedChildren();
|
|
|
|
|
|
|
|
/// @} end of Children and Parent
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
2014-03-24 15:25:44 +08:00
|
|
|
|
|
|
|
virtual void cleanup() override;
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
|
|
|
|
/** Event callback that is invoked when the Node enters in the 'stage'.
|
|
|
|
* If the Node enters the 'stage' with a transition, this event is called when the transition finishes.
|
|
|
|
* If you override onEnterTransitionDidFinish, you shall call its parent's one, e.g. Node::onEnterTransitionDidFinish()
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void onEnterTransitionDidFinish() override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event callback that is invoked every time the Node leaves the 'stage'.
|
|
|
|
* If the Node leaves the 'stage' with a transition, this event is called when the transition finishes.
|
|
|
|
* During onExit you can't access a sibling node.
|
|
|
|
* If you override onExit, you shall call its parent's one, e.g., Node::onExit().
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void onExit() override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event callback that is called every time the Node leaves the 'stage'.
|
|
|
|
* If the Node leaves the 'stage' with a transition, this callback is called when the transition starts.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void onExitTransitionDidStart() override;
|
|
|
|
|
|
|
|
virtual void updateDisplayedOpacity(GLubyte parentOpacity) override;
|
|
|
|
virtual void updateDisplayedColor(const Color3B& parentColor) override;
|
|
|
|
virtual void disableCascadeColor() override;
|
2014-08-22 11:49:39 +08:00
|
|
|
virtual void disableCascadeOpacity()override;
|
2015-02-12 09:24:04 +08:00
|
|
|
virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override;
|
2014-03-27 14:27:30 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2014-03-24 15:25:44 +08:00
|
|
|
ProtectedNode();
|
|
|
|
virtual ~ProtectedNode();
|
2014-03-27 14:27:30 +08:00
|
|
|
|
|
|
|
protected:
|
2014-03-24 15:25:44 +08:00
|
|
|
|
|
|
|
/// helper that reorder a child
|
|
|
|
void insertProtectedChild(Node* child, int z);
|
|
|
|
|
|
|
|
Vector<Node*> _protectedChildren; ///< array of children nodes
|
|
|
|
bool _reorderProtectedChildDirty;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(ProtectedNode);
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of 2d group
|
|
|
|
/// @}
|
2014-03-24 15:25:44 +08:00
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2014-06-19 19:45:49 +08:00
|
|
|
#endif // __CPROTECTEDCNODE_H__
|