Magic_Game/core/base/ActionTween.h

449 lines
9.3 KiB
C++
Raw Blame History

// Copyright (c) 2016-2018 Easy2D - Nomango
//
// 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.
#pragma once
#include "Action.hpp"
#include "logs.h"
namespace easy2d
{
enum class EaseFunc
{
Linear, // 窟昑
EaseIn, // 譚찹긴우
EaseOut, // 譚우긴찹
EaseInOut, // 譚찹긴우, 疼譚우긴찹
EaseExponentialIn, // 譚찹긴섐우
EaseExponentialOut, // 譚섐우긴찹
EaseExponentialInOut, // 譚찹逞섐우, 疼譚섐우긋찹
EaseSineIn, // 譚우긴찹, 꽃痰攣菊긴뻣醵똑
EaseSineOut, // 譚찹긴우, 꽃痰攣菊긴뻣醵똑
EaseSineInOut // 譚찹逞우, 疼譚우逞찹, 꽃痰攣菊긴뻣醵똑
};
class Tween
: public Action
{
public:
Tween();
explicit Tween(
Duration const& duration,
EaseFunc func
);
// <20>零醵똑긴뺏혓窟
void SetEaseFunction(
EaseFunc func
);
// 菱땍屢醵똑긴뺏혓窟
void SetEaseFunction(
std::function<float(float)> func
);
virtual void Reset() override;
Duration const& GetDuration() const;
void SetDuration(Duration const& duration);
protected:
virtual void Init(Node* target) override;
virtual void Update(Node* target, Duration const& dt) override;
virtual void UpdateStep(Node* target, float step) = 0;
protected:
Duration duration_;
Duration elapsed_;
EaseFunc ease_type_;
std::function<float(float)> ease_func_;
};
// 宮뚤貫盧땡鱗
class MoveBy
: public Tween
{
public:
explicit MoveBy(
Duration const& duration, /* 넣崎珂낀 */
Point const& vector, /* 盧땡약잼 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override;
protected:
virtual void Init(Node* target) override;
virtual void UpdateStep(Node* target, float step) override;
protected:
Point start_pos_;
Point prev_pos_;
Point delta_pos_;
};
// 貫盧땡鱗
class MoveTo
: public MoveBy
{
public:
explicit MoveTo(
Duration const& duration, /* 넣崎珂낀 */
Point const& pos, /* 커돨麟깃 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override
{
logs::Errorln("Reverse() not supported in MoveTo");
return nullptr;
}
protected:
virtual void Init(Node* target) override;
protected:
Point end_pos_;
};
// 宮뚤契禿땡鱗
class JumpBy
: public Tween
{
public:
explicit JumpBy(
Duration const& duration, /* 넣崎珂낀 */
Point const& vec, /* 契禿약잼 */
float height, /* 契禿멕똑 */
int jumps = 1, /* 契禿늴鑒 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override;
protected:
virtual void Init(Node* target) override;
virtual void UpdateStep(Node* target, float step) override;
protected:
Point start_pos_;
Point delta_pos_;
float height_;
int jumps_;
Point prev_pos_;
};
// 契禿땡鱗
class JumpTo
: public JumpBy
{
public:
explicit JumpTo(
Duration const& duration, /* 넣崎珂낀 */
Point const& pos, /* 커돨麟깃 */
float height, /* 契禿멕똑 */
int jumps = 1, /* 契禿늴鑒 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override
{
logs::Errorln("Reverse() not supported in JumpTo");
return nullptr;
}
protected:
virtual void Init(Node* target) override;
protected:
Point end_pos_;
};
// 宮뚤鍵렴땡鱗
class ScaleBy
: public Tween
{
public:
explicit ScaleBy(
Duration const& duration, /* 넣崎珂낀 */
float scale, /* 宮뚤긴뺏令 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
explicit ScaleBy(
Duration const& duration, /* 넣崎珂낀 */
float scale_x, /* 뷘蕨鍵렴宮뚤긴뺏令 */
float scale_y, /* 李蕨鍵렴宮뚤긴뺏令 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override;
protected:
virtual void Init(Node* target) override;
virtual void UpdateStep(Node* target, float step) override;
protected:
float start_scale_x_;
float start_scale_y_;
float delta_x_;
float delta_y_;
};
// 鍵렴땡鱗
class ScaleTo
: public ScaleBy
{
public:
explicit ScaleTo(
Duration const& duration, /* 넣崎珂낀 */
float scale, /* 커깃令 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
explicit ScaleTo(
Duration const& duration, /* 넣崎珂낀 */
float scale_x, /* 뷘蕨鍵렴커깃令 */
float scale_y, /* 李蕨鍵렴커깃令 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override
{
logs::Errorln("Reverse() not supported in ScaleTo");
return nullptr;
}
protected:
virtual void Init(Node* target) override;
protected:
float end_scale_x_;
float end_scale_y_;
};
// 拷츠똑宮뚤쉈긴땡鱗
class OpacityBy
: public Tween
{
public:
explicit OpacityBy(
Duration const& duration, /* 넣崎珂낀 */
float opacity, /* 宮뚤긴뺏令 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override;
protected:
virtual void Init(Node* target) override;
virtual void UpdateStep(Node* target, float step) override;
protected:
float start_val_;
float delta_val_;
};
// 拷츠똑쉈긴땡鱗
class OpacityTo
: public OpacityBy
{
public:
explicit OpacityTo(
Duration const& duration, /* 넣崎珂낀 */
float opacity, /* 커깃令 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override
{
logs::Errorln("Reverse() not supported in OpacityTo");
return nullptr;
}
protected:
virtual void Init(Node* target) override;
protected:
float end_val_;
};
// 뎅흙땡鱗
class FadeIn
: public OpacityTo
{
public:
// 눼쉔뎅흙땡鱗
explicit FadeIn(
Duration const& duration, /* 넣崎珂낀 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
};
// 뎅놔땡鱗
class FadeOut
: public OpacityTo
{
public:
// 눼쉔뎅놔땡鱗
explicit FadeOut(
Duration const& duration, /* 넣崎珂낀 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
};
// 宮뚤旗瘻땡鱗
class RotateBy
: public Tween
{
public:
explicit RotateBy(
Duration const& duration, /* 넣崎珂낀 */
float rotation, /* 宮뚤긴뺏令 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override;
protected:
virtual void Init(Node* target) override;
virtual void UpdateStep(Node* target, float step) override;
protected:
float start_val_;
float delta_val_;
};
// 旗瘻땡鱗
class RotateTo
: public RotateBy
{
public:
explicit RotateTo(
Duration const& duration, /* 넣崎珂낀 */
float rotation, /* 커깃令 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override
{
logs::Errorln("Reverse() not supported in RotateTo");
return nullptr;
}
protected:
virtual void Init(Node* target) override;
protected:
float end_val_;
};
// 쨌쓺땡鱗
class PathAction
: public Tween
{
public:
explicit PathAction(
Duration const& duration, /* 넣崎珂낀 */
spGeometry const& geo, /* 섯부暠近 */
bool rotating = false, /* 懶쨌쓺학窟렘蕨旗瘻 */
float start = 0.f, /* 폅듐 */
float end = 1.f, /* 老듐 */
EaseFunc func = EaseFunc::Linear /* 醵똑긴뺏 */
);
// 삿혤맡땡鱗돨옙굔뚤蹶
virtual spAction Clone() const override;
// 삿혤맡땡鱗돨돌瘻
virtual spAction Reverse() const override;
protected:
virtual void UpdateStep(Node* target, float step) override;
protected:
bool rotating_;
float start_;
float end_;
spGeometry geo_;
};
}