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-02-24 18:51:36 +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 __TRIGGERMNG_H__
|
|
|
|
#define __TRIGGERMNG_H__
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CocoStudio.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocos2d
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
class EventDispatcher;
|
|
|
|
class EventListener;
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocos2d
|
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;
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL ArmatureMovementDispatcher : public cocos2d::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:
|
2021-12-25 10:04:45 +08:00
|
|
|
void addAnimationEventCallBack(cocos2d::Ref* pTarget, SEL_MovementEventCallFunc mecf);
|
|
|
|
void removeAnnimationEventCallBack(cocos2d::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:
|
|
|
|
std::unordered_map<cocos2d::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);
|
2019-11-23 20:27:39 +08:00
|
|
|
cocos2d::Vector<TriggerObj*>* get(unsigned int event) const;
|
|
|
|
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
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void addArmatureMovementCallBack(Armature* pAr, cocos2d::Ref* pTarget, SEL_MovementEventCallFunc mecf);
|
|
|
|
void removeArmatureMovementCallBack(Armature* pAr, cocos2d::Ref* pTarget, SEL_MovementEventCallFunc mecf);
|
|
|
|
void removeArmatureAllMovementCallBack(Armature* pAr);
|
2019-11-23 20:27:39 +08:00
|
|
|
void removeAllArmatureMovementCallBack();
|
|
|
|
void dispatchEvent(cocos2d::EventCustom* tEvent);
|
|
|
|
void removeEventListener(cocos2d::EventListener* listener);
|
|
|
|
void addEventListenerWithFixedPriority(cocos2d::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;
|
2019-11-23 20:27:39 +08:00
|
|
|
cocos2d::EventDispatcher* _eventDispatcher; ///< event dispatcher used to dispatch all kinds of events
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif
|