mirror of
https://github.com/u0u0/Cocos2d-Lua-Community.git
synced 2026-05-31 21:20:56 +08:00
脚本事件去垃圾。
This commit is contained in:
@@ -105,21 +105,6 @@ int LuaEngine::executeGlobalFunction(const char* functionName)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::executeNodeEvent(Node* pNode, int nAction)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::executeMenuItemEvent(MenuItem* pMenuItem)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::executeCallFuncActionEvent(CallFunc* pAction, Ref* pTarget/* = NULL*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::executeSchedule(int nHandler, float dt, Node* pNode/* = NULL*/)
|
||||
{
|
||||
if (!nHandler) return 0;
|
||||
@@ -129,21 +114,6 @@ int LuaEngine::executeSchedule(int nHandler, float dt, Node* pNode/* = NULL*/)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::executeLayerTouchEvent(Layer* pLayer, int eventType, Touch *pTouch)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::executeLayerKeypadEvent(Layer* pLayer, int eventType)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::executeAccelerometerEvent(Layer* pLayer, Acceleration* pAccelerationValue)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::executeEvent(int nHandler, const char* pEventName, Ref* pEventSource /* = NULL*/, const char* pEventSourceClassName /* = NULL*/)
|
||||
{
|
||||
_stack->pushString(pEventName);
|
||||
@@ -208,26 +178,6 @@ int LuaEngine::sendEvent(ScriptEvent* evt)
|
||||
return handleScheduler(evt->data);
|
||||
}
|
||||
break;
|
||||
case kTouchEvent:
|
||||
{
|
||||
return handleTouchEvent(evt->data);
|
||||
}
|
||||
break;
|
||||
case kTouchesEvent:
|
||||
{
|
||||
return handleTouchesEvent(evt->data);
|
||||
}
|
||||
break;
|
||||
case kKeypadEvent:
|
||||
{
|
||||
return handleKeypadEvent(evt->data);
|
||||
}
|
||||
break;
|
||||
case kAccelerometerEvent:
|
||||
{
|
||||
return handleAccelerometerEvent(evt->data);
|
||||
}
|
||||
break;
|
||||
case kCommonEvent:
|
||||
{
|
||||
return handleCommonEvent(evt->data);
|
||||
@@ -323,62 +273,6 @@ int LuaEngine::handleScheduler(void* data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleKeypadEvent(void* data)
|
||||
{
|
||||
if (NULL == data)
|
||||
return 0;
|
||||
|
||||
KeypadScriptData* keypadScriptData = static_cast<KeypadScriptData*>(data);
|
||||
if (NULL == keypadScriptData->nativeObject)
|
||||
return 0;
|
||||
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler(keypadScriptData->nativeObject, ScriptHandlerMgr::HandlerType::KEYPAD);
|
||||
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
EventKeyboard::KeyCode action = keypadScriptData->actionType;
|
||||
|
||||
switch(action)
|
||||
{
|
||||
case EventKeyboard::KeyCode::KEY_ESCAPE:
|
||||
_stack->pushString("backClicked");
|
||||
break;
|
||||
case EventKeyboard::KeyCode::KEY_MENU:
|
||||
_stack->pushString("menuClicked");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
int ret = _stack->executeFunctionByHandler(handler, 1);
|
||||
_stack->clean();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleAccelerometerEvent(void* data)
|
||||
{
|
||||
if (NULL == data)
|
||||
return 0;
|
||||
|
||||
BasicScriptData* basicScriptData = static_cast<BasicScriptData*>(data);
|
||||
if (NULL == basicScriptData->nativeObject || NULL == basicScriptData->value)
|
||||
return 0;
|
||||
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler(basicScriptData->nativeObject, ScriptHandlerMgr::HandlerType::ACCELEROMETER);
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
Acceleration* accelerationValue = static_cast<Acceleration*>(basicScriptData->value);
|
||||
_stack->pushFloat(float(accelerationValue->x));
|
||||
_stack->pushFloat(float(accelerationValue->y));
|
||||
_stack->pushFloat(float(accelerationValue->z));
|
||||
_stack->pushFloat(float(accelerationValue->timestamp));
|
||||
int ret = _stack->executeFunctionByHandler(handler, 4);
|
||||
_stack->clean();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleCommonEvent(void* data)
|
||||
{
|
||||
if (NULL == data)
|
||||
@@ -405,113 +299,6 @@ int LuaEngine::handleCommonEvent(void* data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleTouchEvent(void* data)
|
||||
{
|
||||
if (NULL == data)
|
||||
return 0;
|
||||
|
||||
TouchScriptData* touchScriptData = static_cast<TouchScriptData*>(data);
|
||||
if (NULL == touchScriptData->nativeObject || NULL == touchScriptData->touch)
|
||||
return 0;
|
||||
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)touchScriptData->nativeObject, ScriptHandlerMgr::HandlerType::TOUCHES);
|
||||
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
switch (touchScriptData->actionType)
|
||||
{
|
||||
case EventTouch::EventCode::BEGAN:
|
||||
_stack->pushString("began");
|
||||
break;
|
||||
|
||||
case EventTouch::EventCode::MOVED:
|
||||
_stack->pushString("moved");
|
||||
break;
|
||||
|
||||
case EventTouch::EventCode::ENDED:
|
||||
_stack->pushString("ended");
|
||||
break;
|
||||
|
||||
case EventTouch::EventCode::CANCELLED:
|
||||
_stack->pushString("cancelled");
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
|
||||
Touch* touch = touchScriptData->touch;
|
||||
if (NULL != touch) {
|
||||
const cocos2d::Vec2 pt = Director::getInstance()->convertToGL(touch->getLocationInView());
|
||||
_stack->pushFloat(pt.x);
|
||||
_stack->pushFloat(pt.y);
|
||||
ret = _stack->executeFunctionByHandler(handler, 3);
|
||||
}
|
||||
_stack->clean();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleTouchesEvent(void* data)
|
||||
{
|
||||
if (NULL == data)
|
||||
return 0;
|
||||
|
||||
TouchesScriptData* touchesScriptData = static_cast<TouchesScriptData*>(data);
|
||||
if (NULL == touchesScriptData->nativeObject || touchesScriptData->touches.size() == 0)
|
||||
return 0;
|
||||
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)touchesScriptData->nativeObject, ScriptHandlerMgr::HandlerType::TOUCHES);
|
||||
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
switch (touchesScriptData->actionType)
|
||||
{
|
||||
case EventTouch::EventCode::BEGAN:
|
||||
_stack->pushString("began");
|
||||
break;
|
||||
|
||||
case EventTouch::EventCode::MOVED:
|
||||
_stack->pushString("moved");
|
||||
break;
|
||||
|
||||
case EventTouch::EventCode::ENDED:
|
||||
_stack->pushString("ended");
|
||||
break;
|
||||
|
||||
case EventTouch::EventCode::CANCELLED:
|
||||
_stack->pushString("cancelled");
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
Director* pDirector = Director::getInstance();
|
||||
lua_State *L = _stack->getLuaState();
|
||||
int ret = 0;
|
||||
|
||||
lua_newtable(L);
|
||||
int i = 1;
|
||||
for (auto& touch : touchesScriptData->touches)
|
||||
{
|
||||
cocos2d::Vec2 pt = pDirector->convertToGL(touch->getLocationInView());
|
||||
lua_pushnumber(L, pt.x);
|
||||
lua_rawseti(L, -2, i++);
|
||||
lua_pushnumber(L, pt.y);
|
||||
lua_rawseti(L, -2, i++);
|
||||
lua_pushinteger(L, touch->getID());
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
ret = _stack->executeFunctionByHandler(handler, 2);
|
||||
|
||||
_stack->clean();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleEventAcc(void* data)
|
||||
{
|
||||
if (nullptr == data)
|
||||
@@ -681,23 +468,6 @@ int LuaEngine::handleEvent(ScriptHandlerMgr::HandlerType type,void* data)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL:
|
||||
case ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM:
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED:
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT:
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT:
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE:
|
||||
{
|
||||
return handleTableViewEvent(type, data);
|
||||
}
|
||||
break;
|
||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS:
|
||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR:
|
||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS:
|
||||
{
|
||||
return handleAssetsManagerEvent(type, data);
|
||||
}
|
||||
break;
|
||||
case ScriptHandlerMgr::HandlerType::ARMATURE_EVENT:
|
||||
{
|
||||
return handleArmatureWrapper(type, data);
|
||||
@@ -750,164 +520,6 @@ int LuaEngine::handleEvent(ScriptHandlerMgr::HandlerType type,void* data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::handleEvent(ScriptHandlerMgr::HandlerType type, void* data, int numResults, const std::function<void(lua_State*,int)>& func)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX:
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX:
|
||||
case ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS:
|
||||
{
|
||||
return handleTableViewEvent(type, data, numResults,func);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::handleTableViewEvent(ScriptHandlerMgr::HandlerType type,void* data)
|
||||
{
|
||||
if (nullptr == data)
|
||||
return 0;
|
||||
|
||||
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
||||
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||
return 0;
|
||||
|
||||
LuaTableViewEventData* tableViewData = static_cast<LuaTableViewEventData*>(eventData->value);
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, type);
|
||||
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
Ref* obj = static_cast<Ref*>(eventData->nativeObject);
|
||||
if (nullptr == obj)
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
switch (type)
|
||||
{
|
||||
case ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL:
|
||||
case ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM:
|
||||
{
|
||||
toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView");
|
||||
ret = _stack->executeFunctionByHandler(handler, 1);
|
||||
}
|
||||
break;
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED:
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT:
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT:
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE:
|
||||
{
|
||||
Ref* cellObject = static_cast<Ref*>(tableViewData->value);
|
||||
if (nullptr == cellObject) {
|
||||
break;
|
||||
}
|
||||
toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView");
|
||||
toluafix_pushusertype_ccobject(_stack->getLuaState(), cellObject->_ID, &(cellObject->_luaID), (void*)(cellObject),"cc.TableViewCell");
|
||||
ret = _stack->executeFunctionByHandler(handler, 2);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int LuaEngine::handleTableViewEvent(ScriptHandlerMgr::HandlerType handlerType,void* data, int numResults, const std::function<void(lua_State*,int)>& func)
|
||||
{
|
||||
if (nullptr == data || numResults <= 0)
|
||||
return 0;
|
||||
|
||||
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
||||
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||
return 0;
|
||||
|
||||
LuaTableViewEventData* tableViewData = static_cast<LuaTableViewEventData*>(eventData->value);
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, handlerType);
|
||||
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
Ref* obj = static_cast<Ref*>(eventData->nativeObject);
|
||||
if (nullptr == obj)
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
switch (handlerType)
|
||||
{
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX:
|
||||
{
|
||||
toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView");
|
||||
_stack->pushLong(*((ssize_t*)tableViewData->value));
|
||||
ret = _stack->executeFunction(handler, 2, 2, func);
|
||||
}
|
||||
break;
|
||||
case ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX:
|
||||
{
|
||||
toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView");
|
||||
_stack->pushLong(*((ssize_t*)tableViewData->value));
|
||||
ret = _stack->executeFunction(handler, 2, 1, func);
|
||||
}
|
||||
break;
|
||||
case ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS:
|
||||
{
|
||||
toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView");
|
||||
ret = _stack->executeFunction(handler, 1, 1, func);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleAssetsManagerEvent(ScriptHandlerMgr::HandlerType type,void* data)
|
||||
{
|
||||
if (nullptr == data)
|
||||
return 0;
|
||||
|
||||
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
||||
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||
return 0;
|
||||
|
||||
LuaAssetsManagerEventData* assetsManagerData = static_cast<LuaAssetsManagerEventData*>(eventData->value);
|
||||
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, type);
|
||||
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
switch (type)
|
||||
{
|
||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS:
|
||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR:
|
||||
{
|
||||
_stack->pushInt(assetsManagerData->value);
|
||||
ret = _stack->executeFunctionByHandler(handler, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS:
|
||||
{
|
||||
ret = _stack->executeFunctionByHandler(handler, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleArmatureWrapper(ScriptHandlerMgr::HandlerType type,void* data)
|
||||
{
|
||||
if (nullptr == data)
|
||||
|
||||
Reference in New Issue
Block a user