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"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "cocoa/CCObject.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "actions/CCActionInstant.h"
|
|
|
|
#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;
|
|
|
|
|
|
|
|
typedef int EventType;
|
|
|
|
typedef int EventHandler;
|
|
|
|
typedef std::pair<EventType, EventHandler> PairEventHandler;
|
|
|
|
typedef std::vector<PairEventHandler> VecEventHandlers;
|
|
|
|
typedef std::map<void*,VecEventHandlers> MapObjectHandlers;
|
|
|
|
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-07-15 10:38:16 +08:00
|
|
|
LuaCallFunc()
|
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-07-15 10:38:16 +08:00
|
|
|
static LuaCallFunc * create(int nHandler);
|
|
|
|
virtual void execute();
|
|
|
|
virtual LuaCallFunc* clone() const;
|
2013-07-10 15:04:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ScriptHandlerMgr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScriptHandlerMgr(void);
|
|
|
|
virtual ~ScriptHandlerMgr(void);
|
|
|
|
static ScriptHandlerMgr* getInstance(void);
|
|
|
|
|
2013-07-15 10:38:16 +08:00
|
|
|
void addObjectHandler(void* object,int handler,int eventType);
|
|
|
|
void removeObjectHandler(void* object,int eventType);
|
|
|
|
int getObjectHandler(void* object,int eventType);
|
|
|
|
void removeObjectAllHandlers(void* object);
|
|
|
|
|
2013-07-10 15:04:00 +08:00
|
|
|
enum HandlerEventType
|
|
|
|
{
|
2013-07-15 10:38:16 +08:00
|
|
|
kNodeHandler = 0,
|
|
|
|
kMenuClickHandler,
|
2013-07-10 15:04:00 +08:00
|
|
|
kNotificationHandler,
|
|
|
|
kCallFuncHandler,
|
2013-07-15 10:38:16 +08:00
|
|
|
kScheduleHandler,
|
2013-07-10 15:04:00 +08:00
|
|
|
kTouchesHandler,
|
|
|
|
kKeypadHandler,
|
2013-07-15 10:38:16 +08:00
|
|
|
kAccelerometerHandler,
|
2013-07-16 09:55:06 +08:00
|
|
|
|
|
|
|
kControlTouchDownHandler,
|
|
|
|
kControlTouchDragInsideHandler,
|
|
|
|
kControlTouchDragOutsideHandler,
|
|
|
|
kControlTouchDragEnterHandler,
|
|
|
|
kControlTouchDragExitHandler,
|
|
|
|
kControlTouchUpInsideHandler,
|
|
|
|
kControlTouchUpOutsideHandler,
|
|
|
|
kControlTouchCancelHandler,
|
|
|
|
kControlValueChangedHandler,
|
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-15 10:38:16 +08:00
|
|
|
TOLUA_API int tolua_Cocos2d_registerScriptHandler00(lua_State* tolua_S);
|
2013-07-16 09:55:06 +08:00
|
|
|
TOLUA_API int tolua_Cocos2d_unregisterScriptHandler00(lua_State* tolua_S);
|
2013-07-15 10:38:16 +08:00
|
|
|
|
|
|
|
TOLUA_API int tolua_Cocos2d_registerScriptTapHandler00(lua_State* tolua_S);
|
2013-07-16 09:55:06 +08:00
|
|
|
TOLUA_API int tolua_Cocos2d_unregisterScriptTapHandler00(lua_State* tolua_S);
|
2013-07-15 10:38:16 +08:00
|
|
|
|
|
|
|
TOLUA_API int tolua_Cocos2d_registerScriptTouchHandler00(lua_State* tolua_S);
|
2013-07-16 09:55:06 +08:00
|
|
|
TOLUA_API int tolua_Cocos2d_unregisterScriptTouchHandler00(lua_State* tolua_S);
|
2013-07-15 10:38:16 +08:00
|
|
|
|
|
|
|
TOLUA_API int tolua_Cocos2d_registerScriptKeypadHandler00(lua_State* tolua_S);
|
2013-07-16 09:55:06 +08:00
|
|
|
TOLUA_API int tolua_Cocos2d_unregisterScriptKeypadHandler00(lua_State* tolua_S);
|
2013-07-15 10:38:16 +08:00
|
|
|
|
|
|
|
TOLUA_API int tolua_Cocos2d_registerScriptAccelerateHandler00(lua_State* tolua_S);
|
2013-07-16 09:55:06 +08:00
|
|
|
TOLUA_API int tolua_Cocos2d_unregisterScriptAccelerateHandler00(lua_State* tolua_S);
|
|
|
|
|
|
|
|
TOLUA_API int tolua_Cocos2d_registerControlEventHandler00(lua_State* tolua_S);
|
|
|
|
TOLUA_API int tolua_Cocos2d_unregisterControlEventHandler00(lua_State* tolua_S);
|
2013-07-15 10:38:16 +08:00
|
|
|
|
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__
|