2013-07-10 15:04:00 +08:00
|
|
|
#ifndef __LUA_SCRIPT_HANDLER_MGR_H__
|
|
|
|
#define __LUA_SCRIPT_HANDLER_MGR_H__
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "tolua++.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-16 17:19:02 +08:00
|
|
|
#include "CCObject.h"
|
2013-07-10 15:04:00 +08:00
|
|
|
#include "ccMacros.h"
|
2013-10-16 17:19:02 +08:00
|
|
|
#include "CCActionInstant.h"
|
2013-07-10 15:04:00 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
|
2013-07-11 13:38:25 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-07-10 15:04:00 +08:00
|
|
|
class ScheduleHandlerDelegate;
|
|
|
|
|
2013-09-04 22:17:26 +08:00
|
|
|
|
2013-07-10 15:04:00 +08:00
|
|
|
typedef std::vector<ScheduleHandlerDelegate*> VecShedule;
|
|
|
|
typedef std::map<cocos2d::Node*,VecShedule> MapNodeSchedules;
|
|
|
|
|
|
|
|
class ScheduleHandlerDelegate:public cocos2d::Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScheduleHandlerDelegate():_isUpdateSchedule(false)
|
|
|
|
{}
|
|
|
|
virtual ~ScheduleHandlerDelegate()
|
|
|
|
{}
|
|
|
|
|
|
|
|
static ScheduleHandlerDelegate* create();
|
|
|
|
|
|
|
|
void scheduleFunc(float elapse);
|
|
|
|
|
|
|
|
virtual void update(float elapse);
|
|
|
|
|
|
|
|
void setUpdateSchedule(bool isUpdateSchedule){ _isUpdateSchedule = isUpdateSchedule; }
|
|
|
|
bool isUpdateSchedule(){ return _isUpdateSchedule; }
|
|
|
|
private:
|
|
|
|
bool _isUpdateSchedule;
|
|
|
|
};
|
|
|
|
|
2013-07-15 10:38:16 +08:00
|
|
|
class LuaCallFunc:public cocos2d::CallFuncN
|
2013-07-10 15:04:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-22 11:51:07 +08:00
|
|
|
LuaCallFunc():_functionLua(nullptr)
|
2013-07-10 15:04:00 +08:00
|
|
|
{}
|
2013-07-15 10:38:16 +08:00
|
|
|
virtual ~LuaCallFunc()
|
2013-07-10 15:04:00 +08:00
|
|
|
{}
|
|
|
|
|
2013-11-22 11:51:07 +08:00
|
|
|
static LuaCallFunc* create(const std::function<void(void* self,Node*)>& func);
|
|
|
|
bool initWithFunction(const std::function<void(void* self,Node*)>& func);
|
2013-07-15 10:38:16 +08:00
|
|
|
virtual LuaCallFunc* clone() const;
|
2013-11-22 11:51:07 +08:00
|
|
|
virtual void execute() override;
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
std::function<void(void* self,Node*)> _functionLua;
|
|
|
|
|
2013-07-10 15:04:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ScriptHandlerMgr
|
|
|
|
{
|
|
|
|
public:
|
2013-09-04 22:17:26 +08:00
|
|
|
enum class HandlerType: int
|
2013-07-10 15:04:00 +08:00
|
|
|
{
|
2013-09-04 22:17:26 +08:00
|
|
|
NODE = 0,
|
|
|
|
MENU_CLICKED,
|
|
|
|
NOTIFICATION,
|
|
|
|
CALLFUNC,
|
|
|
|
SCHEDULE,
|
|
|
|
TOUCHES,
|
|
|
|
KEYPAD,
|
|
|
|
ACCELEROMETER,
|
2013-07-17 10:15:25 +08:00
|
|
|
|
2013-09-04 22:17:26 +08:00
|
|
|
CONTROL_TOUCH_DOWN,
|
|
|
|
CONTROL_TOUCH_DRAG_INSIDE,
|
|
|
|
CONTROL_TOUCH_DRAG_OUTSIDE,
|
|
|
|
CONTROL_TOUCH_DRAG_ENTER,
|
|
|
|
CONTROL_TOUCH_DRAG_EXIT,
|
|
|
|
CONTROL_TOUCH_UP_INSIDE,
|
|
|
|
CONTROL_TOUCH_UP_OUTSIDE,
|
|
|
|
CONTROL_TOUCH_UP_CANCEL,
|
|
|
|
CONTROL_VALUE_CHANGED,
|
2013-07-17 10:15:25 +08:00
|
|
|
|
2013-09-04 22:17:26 +08:00
|
|
|
WEBSOCKET_OPEN,
|
|
|
|
WEBSOCKET_MESSAGE,
|
|
|
|
WEBSOCKET_CLOSE,
|
|
|
|
WEBSOCKET_ERROR,
|
|
|
|
|
|
|
|
GL_NODE_DRAW,
|
|
|
|
|
|
|
|
SCROLLVIEW_SCROLL,
|
|
|
|
SCROLLVIEW_ZOOM,
|
|
|
|
|
|
|
|
TABLECELL_TOUCHED,
|
|
|
|
TABLECELL_HIGHLIGHT,
|
|
|
|
TABLECELL_UNHIGHLIGHT,
|
|
|
|
TABLECELL_WILL_RECYCLE,
|
|
|
|
TABLECELL_SIZE_FOR_INDEX,
|
|
|
|
TABLECELL_AT_INDEX,
|
|
|
|
TABLEVIEW_NUMS_OF_CELLS,
|
2013-10-22 16:14:49 +08:00
|
|
|
|
2013-10-29 11:40:41 +08:00
|
|
|
XMLHTTPREQUEST_READY_STATE_CHANGE,
|
2013-11-01 17:17:21 +08:00
|
|
|
|
2013-10-22 16:14:49 +08:00
|
|
|
ASSETSMANAGER_PROGRESS,
|
|
|
|
ASSETSMANAGER_SUCCESS,
|
|
|
|
ASSETSMANAGER_ERROR,
|
2013-11-07 23:22:11 +08:00
|
|
|
|
|
|
|
EVENT_LISTENER,
|
2013-11-09 22:58:40 +08:00
|
|
|
ARMATURE_EVENT,
|
2013-07-10 15:04:00 +08:00
|
|
|
};
|
|
|
|
|
2013-09-04 22:17:26 +08:00
|
|
|
typedef int Handler;
|
|
|
|
typedef std::pair<HandlerType, Handler> HandlerPair;
|
|
|
|
typedef std::vector<HandlerPair> VecHandlerPairs;
|
|
|
|
typedef std::map<void*,VecHandlerPairs> MapObjectHandlers;
|
|
|
|
|
|
|
|
ScriptHandlerMgr(void);
|
|
|
|
virtual ~ScriptHandlerMgr(void);
|
|
|
|
static ScriptHandlerMgr* getInstance(void);
|
|
|
|
|
|
|
|
void addObjectHandler(void* object,int handler,ScriptHandlerMgr::HandlerType handlerType);
|
|
|
|
void removeObjectHandler(void* object,ScriptHandlerMgr::HandlerType handlerType);
|
|
|
|
int getObjectHandler(void* object,ScriptHandlerMgr::HandlerType handlerType);
|
|
|
|
void removeObjectAllHandlers(void* object);
|
2013-07-10 15:04:00 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void init(void);
|
|
|
|
static ScriptHandlerMgr* _scriptHandlerMgr;
|
|
|
|
MapObjectHandlers _mapObjectHandlers;
|
|
|
|
};
|
|
|
|
|
2013-07-11 13:38:25 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2013-07-17 16:40:31 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
2013-07-17 10:15:25 +08:00
|
|
|
TOLUA_API int tolua_Cocos2d_WebSocket_registerScriptHandler00(lua_State* tolua_S);
|
|
|
|
TOLUA_API int tolua_Cocos2d_WebSocket_unregisterScriptHandler00(lua_State* tolua_S);
|
2013-07-17 16:40:31 +08:00
|
|
|
#endif
|
2013-07-17 10:15:25 +08:00
|
|
|
|
|
|
|
TOLUA_API int tolua_Cocos2d_GLNode_registerScriptDrawHandler00(lua_State* tolua_S);
|
|
|
|
TOLUA_API int tolua_Cocos2d_GLNode_unregisterScriptDrawHandler00(lua_State* tolua_S);
|
|
|
|
|
2013-07-10 15:04:00 +08:00
|
|
|
TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S);
|
|
|
|
|
|
|
|
#endif //__LUA_SCRIPT_HANDLER_MGR_H__
|