2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +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.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2019-10-11 21:55:29 +08:00
|
|
|
|
#include <kiwano/2d/include-forwards.h>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-08-13 21:16:38 +08:00
|
|
|
|
using ActionCallback = Function<void()>;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
class ActionManager;
|
|
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
class KGE_API Action
|
2019-08-18 10:23:54 +08:00
|
|
|
|
: public ObjectBase
|
2019-10-30 23:12:18 +08:00
|
|
|
|
, protected IntrusiveListItem<ActionPtr>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
friend class ActionManager;
|
|
|
|
|
|
friend class ActionGroup;
|
2019-10-30 23:12:18 +08:00
|
|
|
|
friend IntrusiveList<ActionPtr>;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
Action();
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~Action();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void Resume();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void Pause();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void Stop();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD>ʱ
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void SetDelay(Duration delay);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (-1 Ϊ<><CEAA><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>)
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void SetLoops(int loops);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-12 18:30:42 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ƴ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>ɫ
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void RemoveTargetWhenDone();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void SetDoneCallback(ActionCallback const& cb);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
2019-11-07 18:16:28 +08:00
|
|
|
|
void SetLoopDoneCallback(ActionCallback const& cb);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
|
|
|
|
|
|
virtual ActionPtr Clone() const = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ת
|
|
|
|
|
|
virtual ActionPtr Reverse() const = 0;
|
|
|
|
|
|
|
2019-11-07 18:16:28 +08:00
|
|
|
|
bool IsRunning() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-11-07 18:16:28 +08:00
|
|
|
|
int GetLoops() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-11-07 18:16:28 +08:00
|
|
|
|
Duration GetDelay() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-11-07 18:16:28 +08:00
|
|
|
|
ActionCallback GetDoneCallback() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-11-07 18:16:28 +08:00
|
|
|
|
ActionCallback GetLoopDoneCallback() const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
protected:
|
2019-08-12 18:30:42 +08:00
|
|
|
|
virtual void Init(ActorPtr target);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-12 18:30:42 +08:00
|
|
|
|
virtual void Update(ActorPtr target, Duration dt);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-12 18:30:42 +08:00
|
|
|
|
void UpdateStep(ActorPtr target, Duration dt);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-12 18:30:42 +08:00
|
|
|
|
void Complete(ActorPtr target);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-12 18:30:42 +08:00
|
|
|
|
void Restart(ActorPtr target);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-11-07 18:16:28 +08:00
|
|
|
|
enum class Status
|
|
|
|
|
|
{
|
|
|
|
|
|
NotStarted,
|
|
|
|
|
|
Delayed,
|
|
|
|
|
|
Started,
|
|
|
|
|
|
Done,
|
|
|
|
|
|
Removeable
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Status GetStatus() const;
|
|
|
|
|
|
|
|
|
|
|
|
Duration GetElapsed() const;
|
|
|
|
|
|
|
|
|
|
|
|
int GetLoopsDone() const;
|
|
|
|
|
|
|
|
|
|
|
|
void Done();
|
|
|
|
|
|
|
|
|
|
|
|
bool IsDone() const;
|
|
|
|
|
|
|
|
|
|
|
|
bool IsRemoveable() const;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2019-03-31 01:37:06 +08:00
|
|
|
|
Status status_;
|
|
|
|
|
|
bool running_;
|
|
|
|
|
|
bool detach_target_;
|
2019-09-29 22:23:13 +08:00
|
|
|
|
int loops_;
|
|
|
|
|
|
int loops_done_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
Duration delay_;
|
|
|
|
|
|
Duration elapsed_;
|
|
|
|
|
|
ActionCallback cb_done_;
|
|
|
|
|
|
ActionCallback cb_loop_done_;
|
|
|
|
|
|
};
|
2019-11-07 18:16:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::Resume()
|
|
|
|
|
|
{
|
|
|
|
|
|
running_ = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::Pause()
|
|
|
|
|
|
{
|
|
|
|
|
|
running_ = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::Stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
Done();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::SetDelay(Duration delay)
|
|
|
|
|
|
{
|
|
|
|
|
|
delay_ = delay;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::SetLoops(int loops)
|
|
|
|
|
|
{
|
|
|
|
|
|
loops_ = loops;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::RemoveTargetWhenDone()
|
|
|
|
|
|
{
|
|
|
|
|
|
detach_target_ = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::SetDoneCallback(ActionCallback const& cb)
|
|
|
|
|
|
{
|
|
|
|
|
|
cb_done_ = cb;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::SetLoopDoneCallback(ActionCallback const& cb)
|
|
|
|
|
|
{
|
|
|
|
|
|
cb_loop_done_ = cb;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Action::Done()
|
|
|
|
|
|
{
|
|
|
|
|
|
status_ = Status::Done;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Action::Status Action::GetStatus() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return status_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Action::IsRunning() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return running_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Action::IsDone() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return status_ == Status::Done || status_ == Status::Removeable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Action::IsRemoveable() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return status_ == Status::Removeable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int Action::GetLoops() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return loops_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Duration Action::GetDelay() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return delay_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Duration Action::GetElapsed() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return elapsed_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int Action::GetLoopsDone() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return loops_done_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline ActionCallback Action::GetDoneCallback() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return cb_done_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline ActionCallback Action::GetLoopDoneCallback() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return cb_loop_done_;
|
|
|
|
|
|
}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
}
|