2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2009 On-Core
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-01-04 12:36:20 +08:00
|
|
|
https://adxeproject.github.io/
|
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:
|
|
|
|
|
|
|
|
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 __ACTION_CCGRID_ACTION_H__
|
|
|
|
#define __ACTION_CCGRID_ACTION_H__
|
|
|
|
|
|
|
|
#include "2d/CCActionInterval.h"
|
|
|
|
#include "2d/CCActionInstant.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class GridBase;
|
|
|
|
class NodeGrid;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup actions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@class GridAction
|
|
|
|
@brief Base class for Grid actions.
|
|
|
|
@details Grid actions are the actions take effect on GridBase.
|
|
|
|
*/
|
|
|
|
class CC_DLL GridAction : public ActionInterval
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Get the pointer of GridBase.
|
|
|
|
@return The pointer of GridBase.
|
|
|
|
*/
|
|
|
|
virtual GridBase* getGrid();
|
|
|
|
|
|
|
|
// overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual GridAction* clone() const override
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
CC_ASSERT(0);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual GridAction* reverse() const override;
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void startWithTarget(Node* target) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
GridAction() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~GridAction() {}
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @brief Initializes the action with size and duration.
|
|
|
|
* @param duration The duration of the GridAction. It's a value in seconds.
|
|
|
|
* @param gridSize The size of the GridAction should be.
|
|
|
|
* @return Return true when the initialization success, otherwise return false.
|
|
|
|
*/
|
2021-10-23 23:27:14 +08:00
|
|
|
bool initWithDuration(float duration, const Vec2& gridSize);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 _gridSize;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
NodeGrid* _gridNodeTarget;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void cacheTargetAsGridNode();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(GridAction);
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Base class for Grid3D actions.
|
|
|
|
@details Grid3D actions can modify a non-tiled grid.
|
|
|
|
*/
|
|
|
|
class CC_DLL Grid3DAction : public GridAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual GridBase* getGrid() override;
|
|
|
|
/**
|
|
|
|
* @brief Get the vertex that belongs to certain position in the grid.
|
|
|
|
* @param position The position of the grid.
|
|
|
|
* @return Return a pointer of vertex.
|
|
|
|
* @js vertex
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
Vec3 getVertex(const Vec2& position) const;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @brief Get the non-transformed vertex that belongs to certain position in the grid.
|
|
|
|
* @param position The position of the grid.
|
|
|
|
* @return Return a pointer of vertex.
|
|
|
|
* @js originalVertex
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
Vec3 getOriginalVertex(const Vec2& position) const;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @brief Set a new vertex to a certain position of the grid.
|
|
|
|
* @param position The position of the grid.
|
|
|
|
* @param vertex The vertex will be used on the certain position of grid.
|
|
|
|
* @js setVertex
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void setVertex(const Vec2& position, const Vec3& vertex);
|
|
|
|
|
|
|
|
// Overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual Grid3DAction* clone() const override
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
CC_ASSERT(0);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Get the effect grid rect.
|
|
|
|
* @return Return the effect grid rect.
|
|
|
|
*/
|
|
|
|
Rect getGridRect() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Base class for TiledGrid3D actions.
|
|
|
|
*/
|
|
|
|
class CC_DLL TiledGrid3DAction : public GridAction
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @brief Create the action with size and duration.
|
|
|
|
* @param duration The duration of the action. It's a value in seconds.
|
|
|
|
* @param gridSize Specify the grid size of the action.
|
|
|
|
* @return A pointer of TiledGrid3DAction. If creation failed, return nil.
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2021-10-23 23:27:14 +08:00
|
|
|
static TiledGrid3DAction* create(float duration, const Vec2& gridSize);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @brief Get the tile that belongs to a certain position of the grid.
|
|
|
|
* @param position The position of the tile want to get.
|
2021-12-25 10:04:45 +08:00
|
|
|
* @return A quadrilateral of the tile.
|
2019-11-23 20:27:39 +08:00
|
|
|
* @js tile
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
Quad3 getTile(const Vec2& position) const;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @brief Get the non-transformed tile that belongs to a certain position of the grid.
|
|
|
|
* @param position The position of the tile want to get.
|
2021-12-25 10:04:45 +08:00
|
|
|
* @return A quadrilateral of the tile.
|
2019-11-23 20:27:39 +08:00
|
|
|
* @js originalTile
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
Quad3 getOriginalTile(const Vec2& position) const;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
* @brief Set a new tile to a certain position of the grid.
|
|
|
|
* @param position The position of the tile.
|
|
|
|
* @param coords The quadrilateral of the new tile.
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
void setTile(const Vec2& position, const Quad3& coords);
|
|
|
|
|
|
|
|
/** returns the grid */
|
|
|
|
virtual GridBase* getGrid() override;
|
|
|
|
|
|
|
|
// Override
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual TiledGrid3DAction* clone() const override
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
CC_ASSERT(0);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief AccelDeccelAmplitude action.
|
|
|
|
@js NA
|
|
|
|
*/
|
|
|
|
class CC_DLL AccelDeccelAmplitude : public ActionInterval
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
@brief Create the action with an inner action that has the amplitude property, and a duration time.
|
|
|
|
@param action A pointer of the inner action.
|
|
|
|
@param duration Specify the duration of the AccelDeccelAmplitude action.
|
|
|
|
@return Return a pointer of AccelDeccelAmplitude action. When the creation failed, return nil.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static AccelDeccelAmplitude* create(Action* action, float duration);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Get the value of amplitude rate.
|
|
|
|
@return the value of amplitude rate.
|
|
|
|
*/
|
|
|
|
float getRate() const { return _rate; }
|
|
|
|
/**
|
|
|
|
@brief Set the value of amplitude rate.
|
|
|
|
@param rate Specify the value of amplitude rate.
|
|
|
|
*/
|
|
|
|
void setRate(float rate) { _rate = rate; }
|
|
|
|
|
|
|
|
// Overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void startWithTarget(Node* target) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float time) override;
|
|
|
|
virtual AccelDeccelAmplitude* clone() const override;
|
|
|
|
virtual AccelDeccelAmplitude* reverse() const override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
AccelDeccelAmplitude() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~AccelDeccelAmplitude();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Initializes the action with an inner action that has the amplitude property, and a duration time.
|
|
|
|
@param action A pointer of the inner action.
|
|
|
|
@param duration Specify the duration of the AccelDeccelAmplitude action.
|
|
|
|
@return If the initialization success, return true; otherwise, return false.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool initWithAction(Action* action, float duration);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
float _rate;
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionInterval* _other;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(AccelDeccelAmplitude);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief AccelAmplitude action.
|
|
|
|
@js NA
|
|
|
|
*/
|
|
|
|
class CC_DLL AccelAmplitude : public ActionInterval
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Create the action with an inner action that has the amplitude property, and a duration time.
|
|
|
|
@param action A pointer of the inner action.
|
|
|
|
@param duration Specify the duration of the AccelAmplitude action.
|
|
|
|
@return Return a pointer of AccelAmplitude action. When the creation failed, return nil.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static AccelAmplitude* create(Action* action, float duration);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Get the value of amplitude rate.
|
|
|
|
@return The value of amplitude rate.
|
|
|
|
*/
|
|
|
|
float getRate() const { return _rate; }
|
|
|
|
/**
|
|
|
|
@brief Set the value of amplitude rate.
|
|
|
|
@param rate Specify the value of amplitude rate.
|
|
|
|
*/
|
|
|
|
void setRate(float rate) { _rate = rate; }
|
|
|
|
|
|
|
|
// Overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void startWithTarget(Node* target) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float time) override;
|
|
|
|
virtual AccelAmplitude* clone() const override;
|
|
|
|
virtual AccelAmplitude* reverse() const override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
AccelAmplitude() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~AccelAmplitude();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool initWithAction(Action* action, float duration);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
float _rate;
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionInterval* _other;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(AccelAmplitude);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief DeccelAmplitude action.
|
|
|
|
@js NA
|
|
|
|
*/
|
|
|
|
class CC_DLL DeccelAmplitude : public ActionInterval
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Creates the action with an inner action that has the amplitude property, and a duration time.
|
|
|
|
@param action A pointer of the inner action.
|
|
|
|
@param duration Specify the duration of the DeccelAmplitude action.
|
|
|
|
@return Return a pointer of DeccelAmplitude. When the creation failed, return nil.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static DeccelAmplitude* create(Action* action, float duration);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Get the value of amplitude rate.
|
|
|
|
@return The value of amplitude rate.
|
|
|
|
*/
|
|
|
|
float getRate() const { return _rate; }
|
|
|
|
/**
|
|
|
|
@brief Set the value of amplitude rate.
|
|
|
|
@param rate Specify the value.
|
|
|
|
*/
|
|
|
|
void setRate(float rate) { _rate = rate; }
|
|
|
|
|
|
|
|
// overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void startWithTarget(Node* target) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float time) override;
|
|
|
|
virtual DeccelAmplitude* clone() const override;
|
|
|
|
virtual DeccelAmplitude* reverse() const override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
DeccelAmplitude() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~DeccelAmplitude();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Initializes the action with an inner action that has the amplitude property, and a duration time.
|
|
|
|
@param action The pointer of inner action.
|
|
|
|
@param duration The duration of the DeccelAmplitude action.
|
|
|
|
@return If the initialization success, return true; otherwise, return false.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool initWithAction(Action* action, float duration);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
float _rate;
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionInterval* _other;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(DeccelAmplitude);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief StopGrid action.
|
|
|
|
@warning Don't call this action if another grid action is active.
|
|
|
|
Call if you want to remove the grid effect. Example:
|
|
|
|
@code
|
|
|
|
Sequence::create(Lens3D::create(...), StopGrid::create(), nullptr);
|
|
|
|
@endcode
|
|
|
|
*/
|
|
|
|
class CC_DLL StopGrid : public ActionInstant
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Create a StopGrid Action.
|
|
|
|
@return Return a pointer of StopGrid. When the creation failed, return nil.
|
|
|
|
*/
|
|
|
|
static StopGrid* create();
|
|
|
|
|
|
|
|
// Overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void startWithTarget(Node* target) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual StopGrid* clone() const override;
|
|
|
|
virtual StopGrid* reverse() const override;
|
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
StopGrid() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~StopGrid() {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
|
|
|
NodeGrid* _gridNodeTarget;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void cacheTargetAsGridNode();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(StopGrid);
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief ReuseGrid action.
|
|
|
|
*/
|
|
|
|
class CC_DLL ReuseGrid : public ActionInstant
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Create an action with the number of times that the current grid will be reused.
|
|
|
|
@param times Specify times the grid will be reused.
|
|
|
|
@return Return a pointer of ReuseGrid. When the creation failed, return nil.
|
|
|
|
*/
|
|
|
|
static ReuseGrid* create(int times);
|
|
|
|
|
|
|
|
// Override
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void startWithTarget(Node* target) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ReuseGrid* clone() const override;
|
|
|
|
virtual ReuseGrid* reverse() const override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
ReuseGrid() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~ReuseGrid() {}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2019-11-23 20:27:39 +08:00
|
|
|
@brief Initializes an action with the number of times that the current grid will be reused.
|
|
|
|
@param times Specify times the grid will be reused.
|
|
|
|
@return If the initialization success, return true; otherwise, return false.
|
|
|
|
*/
|
|
|
|
bool initWithTimes(int times);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
NodeGrid* _gridNodeTarget;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void cacheTargetAsGridNode();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
int _times;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(ReuseGrid);
|
|
|
|
};
|
|
|
|
|
|
|
|
// end of actions group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __ACTION_CCGRID_ACTION_H__
|