2021-12-31 12:12:40 +08:00
|
|
|
/****************************************************************************
|
2020-10-17 16:32:16 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.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 __TRIGGERMNG_H__
|
|
|
|
#define __TRIGGERMNG_H__
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CocoStudio.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
class EventDispatcher;
|
|
|
|
class EventListener;
|
2022-08-29 20:51:22 +08:00
|
|
|
NS_AX_END // namespace ax
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
class TriggerObj;
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
class CCS_DLL ArmatureMovementDispatcher : public ax::Ref
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureMovementDispatcher(void);
|
|
|
|
~ArmatureMovementDispatcher(void);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
2022-08-08 18:02:17 +08:00
|
|
|
void addAnimationEventCallBack(ax::Ref* pTarget, SEL_MovementEventCallFunc mecf);
|
|
|
|
void removeAnnimationEventCallBack(ax::Ref* pTarget, SEL_MovementEventCallFunc mecf);
|
2021-12-31 12:12:40 +08:00
|
|
|
void animationEvent(Armature* armature, MovementEventType movementType, std::string_view movementID);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
private:
|
2022-08-08 18:02:17 +08:00
|
|
|
std::unordered_map<ax::Ref*, SEL_MovementEventCallFunc>* _mapEventAnimation;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL TriggerMng
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2020-10-17 16:32:16 +08:00
|
|
|
TriggerMng(void);
|
|
|
|
virtual ~TriggerMng(void);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static TriggerMng* getInstance();
|
|
|
|
static void destroyInstance();
|
|
|
|
static const char* triggerMngVersion();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
void parse(const rapidjson::Value& root);
|
|
|
|
void parse(cocostudio::CocoLoader* pCocoLoader, cocostudio::stExpCocoNode* pCocoNode);
|
2020-10-17 16:32:16 +08:00
|
|
|
void removeAll(void);
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vector<TriggerObj*>* get(unsigned int event) const;
|
2019-11-23 20:27:39 +08:00
|
|
|
TriggerObj* getTriggerObj(unsigned int id) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
bool removeTriggerObj(TriggerObj* Obj);
|
2019-11-23 20:27:39 +08:00
|
|
|
bool removeTriggerObj(unsigned int id);
|
2020-10-17 16:32:16 +08:00
|
|
|
bool isEmpty(void) const;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void addArmatureMovementCallBack(Armature* pAr, ax::Ref* pTarget, SEL_MovementEventCallFunc mecf);
|
|
|
|
void removeArmatureMovementCallBack(Armature* pAr, ax::Ref* pTarget, SEL_MovementEventCallFunc mecf);
|
2021-12-25 10:04:45 +08:00
|
|
|
void removeArmatureAllMovementCallBack(Armature* pAr);
|
2019-11-23 20:27:39 +08:00
|
|
|
void removeAllArmatureMovementCallBack();
|
2022-08-08 18:02:17 +08:00
|
|
|
void dispatchEvent(ax::EventCustom* tEvent);
|
|
|
|
void removeEventListener(ax::EventListener* listener);
|
|
|
|
void addEventListenerWithFixedPriority(ax::EventListener* listener, int fixedPriority);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
2021-12-25 10:04:45 +08:00
|
|
|
void buildJson(rapidjson::Document& document,
|
|
|
|
cocostudio::CocoLoader* pCocoLoader,
|
|
|
|
cocostudio::stExpCocoNode* pCocoNode);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
private:
|
2021-12-25 10:04:45 +08:00
|
|
|
static TriggerMng* _sharedTriggerMng;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::unordered_map<unsigned int, TriggerObj*> _triggerObjs;
|
2021-12-25 10:04:45 +08:00
|
|
|
std::unordered_map<Armature*, ArmatureMovementDispatcher*>* _movementDispatches;
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::EventDispatcher* _eventDispatcher; ///< event dispatcher used to dispatch all kinds of events
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif
|