2019-11-23 20:27:39 +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-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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__
|
|
|
|
|
|
|
|
#include "2d/CCNode.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +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.
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_DLL ProtectedNode : public Node
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a ProtectedNode with no argument.
|
|
|
|
*@return A instance of ProtectedNode.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static ProtectedNode* create();
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/// @{
|
|
|
|
/// @name Children and Parent
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Adds a child to the container with z-order as 0.
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
* If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called
|
|
|
|
* immediately.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param child A child node
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void addProtectedChild(Node* child);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Adds a child to the container with a local z-order.
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
* If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called
|
|
|
|
* immediately.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param child A child node
|
|
|
|
* @param localZOrder Z order for drawing priority. Please refer to `setLocalZOrder(int)`
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void addProtectedChild(Node* child, int localZOrder);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Adds a child to the container with z order and tag.
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
* If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called
|
|
|
|
* immediately.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param child A child node
|
|
|
|
* @param localZOrder 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);
|
|
|
|
/**
|
|
|
|
* Gets a child from the container with its tag.
|
|
|
|
*
|
|
|
|
* @param tag An identifier to find the child node.
|
|
|
|
*
|
|
|
|
* @return a Node object whose tag equals to the input parameter.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual Node* getProtectedChildByTag(int tag);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
////// REMOVES //////
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* 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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Removes a child from the container by tag value. It will also cleanup all running actions depending on the
|
|
|
|
* cleanup parameter.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param tag An integer number that identifies a child node.
|
|
|
|
* @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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Removes all children from the container with a cleanup.
|
|
|
|
*
|
|
|
|
* @see `removeAllChildrenWithCleanup(bool)`.
|
|
|
|
*/
|
|
|
|
virtual void removeAllProtectedChildren();
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Removes all children from the container, and do a cleanup to all running actions depending on the cleanup
|
|
|
|
* parameter.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param cleanup true if all running actions on all children nodes should be cleanup, false otherwise.
|
|
|
|
* @js removeAllChildren
|
|
|
|
* @lua removeAllChildren
|
|
|
|
*/
|
|
|
|
virtual void removeAllProtectedChildrenWithCleanup(bool cleanup);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void reorderProtectedChild(Node* child, int localZOrder);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Sorts the children array once before drawing, instead of every time when a child is added or reordered.
|
|
|
|
* This approach 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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/// @} end of Children and Parent
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags) override;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void cleanup() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void onEnter() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** 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.
|
2021-12-25 10:04:45 +08:00
|
|
|
* If you override onEnterTransitionDidFinish, you shall call its parent's one, e.g.
|
|
|
|
* Node::onEnterTransitionDidFinish()
|
2019-11-23 20:27:39 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void onEnterTransitionDidFinish() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* 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;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* 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(uint8_t parentOpacity) override;
|
|
|
|
virtual void updateDisplayedColor(const Color3B& parentColor) override;
|
|
|
|
virtual void disableCascadeColor() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void disableCascadeOpacity() override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override;
|
|
|
|
virtual void setGlobalZOrder(float globalZOrder) override;
|
2022-03-18 21:46:07 +08:00
|
|
|
ProtectedNode();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~ProtectedNode();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
|
|
|
/// helper that reorder a child
|
|
|
|
void insertProtectedChild(Node* child, int z);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Vector<Node*> _protectedChildren; ///< array of children nodes
|
2019-11-23 20:27:39 +08:00
|
|
|
bool _reorderProtectedChildDirty;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DISALLOW_COPY_AND_ASSIGN(ProtectedNode);
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// end of 2d group
|
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __CPROTECTEDCNODE_H__
|