diff --git a/AUTHORS b/AUTHORS index b1bd3c3f03..410d8ab60c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -443,6 +443,7 @@ Developers: Explicitly initialising CCAcceleration structure. Add support to save/retrieve CCData into/from CCUserDefault. Text Shadows fix + Solving 'black screen' on android. MarcelBloemendaal Adding secureTextEntry property to CCTextFieldTTF. @@ -454,6 +455,7 @@ Developers: sunzhuoshi Adding support for javascript bytecode. + Fixing bad js constant names. ptekchand (Pranav Tekchand) Supporting negative node scales for CCScrollView. diff --git a/CocosDenshion/android/opensl/OpenSLEngine.cpp b/CocosDenshion/android/opensl/OpenSLEngine.cpp index 095d56bff4..680200e314 100644 --- a/CocosDenshion/android/opensl/OpenSLEngine.cpp +++ b/CocosDenshion/android/opensl/OpenSLEngine.cpp @@ -311,9 +311,8 @@ bool createAudioPlayerBySource(AudioPlayer* player) result = (*(player->fdPlayerObject))->GetInterface(player->fdPlayerObject, getInterfaceID("SL_IID_SEEK"), &(player->fdPlayerSeek)); assert(SL_RESULT_SUCCESS == result); - // get the playback rate interface - result = (*(player->fdPlayerObject))->GetInterface(player->fdPlayerObject, getInterfaceID("SL_IID_PLAYBACKRATE"), &(player->fdPlaybackRate)); - assert(SL_RESULT_SUCCESS == result); + // get the playback rate interface, if available + (*(player->fdPlayerObject))->GetInterface(player->fdPlayerObject, getInterfaceID("SL_IID_PLAYBACKRATE"), &(player->fdPlaybackRate)); return true; } diff --git a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 09c8f65300..7e2a12a92c 100644 --- a/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -08ecad70e8370c7af451fddea1c59d05e80ca696 \ No newline at end of file +1ab0fd6fdad74af8ce054c089d8571a05a7a04d8 \ No newline at end of file diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index f2ccf8a59b..2d2d776f74 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -87,7 +87,6 @@ Node::Node(void) , _ignoreAnchorPointForPosition(false) , _reorderChildDirty(false) , _isTransitionFinished(false) -, _scriptHandler(0) , _updateScriptHandler(0) , _componentContainer(NULL) { @@ -107,7 +106,6 @@ Node::~Node(void) { CCLOGINFO( "cocos2d: deallocing: %p", this ); - unregisterScriptHandler(); if (_updateScriptHandler) { ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_updateScriptHandler); @@ -987,23 +985,6 @@ void Node::onExit() arrayMakeObjectsPerformSelector(_children, onExit, Node*); } -void Node::registerScriptHandler(int nHandler) -{ - unregisterScriptHandler(); - _scriptHandler = nHandler; - LUALOG("[LUA] Add Node event handler: %d", _scriptHandler); -} - -void Node::unregisterScriptHandler(void) -{ - if (_scriptHandler) - { - ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_scriptHandler); - LUALOG("[LUA] Remove Node event handler: %d", _scriptHandler); - _scriptHandler = 0; - } -} - void Node::setActionManager(ActionManager* actionManager) { if( actionManager != _actionManager ) { diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index 74e4628cc0..b1a49b87a6 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -857,47 +857,6 @@ public: * @return Whether or not the node is running. */ virtual bool isRunning() const; - - - /// @{ - /// @name Script Bindings for lua - - /** - * Registers a script function that will be called in onEnter() & onExit() seires functions. - * - * This handler will be removed automatically after onExit() called. - * @code - * -- lua sample - * local function sceneEventHandler(eventType) - * if eventType == kNodeOnEnter then - * -- do something - * elseif evetType == kNodeOnExit then - * -- do something - * end - * end - * scene::registerScriptHandler(sceneEventHandler) - * @endcode - * - * @warning This method is for internal usage, don't call it manually. - * @todo Perhaps we should rename it to get/set/removeScriptHandler acoording to the function name style. - * - * @param handler A number that indicates a lua function. - */ - virtual void registerScriptHandler(int handler); - /** - * Unregisters a script function that will be called in onEnter() & onExit() series functions. - * - * @see registerScriptHandler(int) - */ - virtual void unregisterScriptHandler(void); - /** - * Gets script handler for onEnter/onExit event. - * This is an internal method. g - * @see registerScriptHandler(int) - * - * @return A number that indicates a lua function. - */ - inline int getScriptHandler() const { return _scriptHandler; }; /** * Schedules for lua script. diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index 3b7746ffb4..f04a61ee50 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -47,9 +47,6 @@ Layer::Layer() , _accelerometerEnabled(false) , _keyboardEnabled(false) , _keypadEnabled(false) -, _scriptTouchHandlerEntry(NULL) -, _scriptKeypadHandlerEntry(NULL) -, _scriptAccelerateHandlerEntry(NULL) , _touchPriority(0) , _touchMode(kTouchesAllAtOnce) { @@ -59,9 +56,7 @@ Layer::Layer() Layer::~Layer() { - unregisterScriptTouchHandler(); - unregisterScriptKeypadHandler(); - unregisterScriptAccelerateHandler(); + } bool Layer::init() @@ -101,51 +96,20 @@ void Layer::registerWithTouchDispatcher() { TouchDispatcher* pDispatcher = Director::getInstance()->getTouchDispatcher(); - // Using LuaBindings - if (_scriptTouchHandlerEntry) - { - if (_scriptTouchHandlerEntry->isMultiTouches()) - { - pDispatcher->addStandardDelegate(this, 0); - LUALOG("[LUA] Add multi-touches event handler: %d", _scriptTouchHandlerEntry->getHandler()); - } - else - { - pDispatcher->addTargetedDelegate(this, - _scriptTouchHandlerEntry->getPriority(), - _scriptTouchHandlerEntry->getSwallowsTouches()); - LUALOG("[LUA] Add touch event handler: %d", _scriptTouchHandlerEntry->getHandler()); - } - } - else - { - if( _touchMode == kTouchesAllAtOnce ) { - pDispatcher->addStandardDelegate(this, 0); - } else { - pDispatcher->addTargetedDelegate(this, _touchPriority, true); - } + if( _touchMode == kTouchesAllAtOnce ) { + pDispatcher->addStandardDelegate(this, 0); + } else { + pDispatcher->addTargetedDelegate(this, _touchPriority, true); } } -void Layer::registerScriptTouchHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches) -{ - unregisterScriptTouchHandler(); - _scriptTouchHandlerEntry = TouchScriptHandlerEntry::create(nHandler, bIsMultiTouches, nPriority, bSwallowsTouches); - _scriptTouchHandlerEntry->retain(); -} - -void Layer::unregisterScriptTouchHandler(void) -{ - CC_SAFE_RELEASE_NULL(_scriptTouchHandlerEntry); - } - int Layer::excuteScriptTouchHandler(int nEventType, Touch *pTouch) { if (kScriptTypeLua == _scriptType) { Set touches; touches.addObject((Object*)pTouch); - TouchesScriptData data(nEventType,kLayerTouches,(void*)this,&touches); + TouchesScriptData data(nEventType,(void*)this,&touches); ScriptEvent event(kTouchesEvent,&data); return ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event); } @@ -161,7 +125,7 @@ int Layer::excuteScriptTouchHandler(int nEventType, Set *pTouches) { if (kScriptTypeLua == _scriptType) { - TouchesScriptData data(nEventType,kLayerTouches,(void*)this,pTouches); + TouchesScriptData data(nEventType,(void*)this,pTouches); ScriptEvent event(kTouchesEvent,&data); return ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event); } @@ -291,18 +255,6 @@ void Layer::didAccelerate(Acceleration* pAccelerationValue) } } -void Layer::registerScriptAccelerateHandler(int nHandler) -{ - unregisterScriptAccelerateHandler(); - _scriptAccelerateHandlerEntry = ScriptHandlerEntry::create(nHandler); - _scriptAccelerateHandlerEntry->retain(); -} - -void Layer::unregisterScriptAccelerateHandler(void) -{ - CC_SAFE_RELEASE_NULL(_scriptAccelerateHandlerEntry); -} - /// isKeyboardEnabled getter bool Layer::isKeyboardEnabled() const { @@ -356,23 +308,11 @@ void Layer::setKeypadEnabled(bool enabled) } } -void Layer::registerScriptKeypadHandler(int nHandler) -{ - unregisterScriptKeypadHandler(); - _scriptKeypadHandlerEntry = ScriptHandlerEntry::create(nHandler); - _scriptKeypadHandlerEntry->retain(); -} - -void Layer::unregisterScriptKeypadHandler(void) -{ - CC_SAFE_RELEASE_NULL(_scriptKeypadHandlerEntry); -} - void Layer::keyBackClicked(void) { - if (NULL != _scriptKeypadHandlerEntry && 0 != _scriptKeypadHandlerEntry->getHandler()) + if (kScriptTypeLua == _scriptType) { - KeypadScriptData data(kTypeBackClicked,kLayerKeypad,(void*)this); + KeypadScriptData data(kTypeBackClicked,(void*)this); ScriptEvent event(kKeypadEvent,(void*)&data); ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event); } @@ -384,9 +324,9 @@ void Layer::keyBackClicked(void) void Layer::keyMenuClicked(void) { - if (NULL != _scriptKeypadHandlerEntry && 0 != _scriptKeypadHandlerEntry->getHandler()) + if (kScriptTypeLua == _scriptType) { - KeypadScriptData data(kTypeMenuClicked,kLayerKeypad,(void*)this); + KeypadScriptData data(kTypeMenuClicked,(void*)this); ScriptEvent event(kKeypadEvent,(void*)&data); ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event); } @@ -425,8 +365,6 @@ void Layer::onExit() if( _touchEnabled ) { pDirector->getTouchDispatcher()->removeDelegate(this); - // [lua]:don't unregister script touch handler, or the handler will be destroyed - // unregisterScriptTouchHandler(); } // remove this layer from the delegates who concern Accelerometer Sensor diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h index 9075005e8f..182d73c050 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.h @@ -83,8 +83,6 @@ public: virtual void ccTouchesCancelled(Set *pTouches, Event *pEvent); virtual void didAccelerate(Acceleration* pAccelerationValue); - void registerScriptAccelerateHandler(int nHandler); - void unregisterScriptAccelerateHandler(void); /** If isTouchEnabled, this method is called onEnter. Override it to change the way Layer receives touch events. @@ -97,11 +95,6 @@ public: @since v0.8.0 */ virtual void registerWithTouchDispatcher(void); - - /** Register script touch events handler */ - virtual void registerScriptTouchHandler(int nHandler, bool bIsMultiTouches = false, int nPriority = INT_MIN, bool bSwallowsTouches = false); - /** Unregister script touch events handler */ - virtual void unregisterScriptTouchHandler(void); /** whether or not it will receive Touch events. You can enable / disable touch events with this property. @@ -139,18 +132,8 @@ public: virtual bool isKeypadEnabled() const; virtual void setKeypadEnabled(bool value); - /** Register keypad events handler */ - void registerScriptKeypadHandler(int nHandler); - /** Unregister keypad events handler */ - void unregisterScriptKeypadHandler(void); - virtual void keyBackClicked(void); virtual void keyMenuClicked(void); - - inline TouchScriptHandlerEntry* getScriptTouchHandlerEntry() const { return _scriptTouchHandlerEntry; }; - inline ScriptHandlerEntry* getScriptKeypadHandlerEntry() const { return _scriptKeypadHandlerEntry; }; - inline ScriptHandlerEntry* getScriptAccelerateHandlerEntry() const { return _scriptAccelerateHandlerEntry; }; - // // Overrides // @@ -165,11 +148,6 @@ protected: bool _keypadEnabled; private: - // Script touch events handler - TouchScriptHandlerEntry* _scriptTouchHandlerEntry; - ScriptHandlerEntry* _scriptKeypadHandlerEntry; - ScriptHandlerEntry* _scriptAccelerateHandlerEntry; - int _touchPriority; ccTouchesMode _touchMode; diff --git a/cocos2dx/menu_nodes/CCMenuItem.cpp b/cocos2dx/menu_nodes/CCMenuItem.cpp index c433c17e1b..34cabb13cf 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.cpp +++ b/cocos2dx/menu_nodes/CCMenuItem.cpp @@ -91,8 +91,6 @@ bool MenuItem::initWithCallback(const ccMenuCallback& callback) MenuItem::~MenuItem() { CC_SAFE_RELEASE(_target); - - unregisterScriptTapHandler(); } void MenuItem::selected() @@ -105,23 +103,6 @@ void MenuItem::unselected() _selected = false; } -void MenuItem::registerScriptTapHandler(int nHandler) -{ - unregisterScriptTapHandler(); - _scriptTapHandler = nHandler; - LUALOG("[LUA] Add MenuItem script handler: %d", _scriptTapHandler); -} - -void MenuItem::unregisterScriptTapHandler(void) -{ - if (_scriptTapHandler) - { - ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_scriptTapHandler); - LUALOG("[LUA] Remove MenuItem script handler: %d", _scriptTapHandler); - _scriptTapHandler = 0; - } -} - void MenuItem::activate() { if (_enabled) diff --git a/cocos2dx/menu_nodes/CCMenuItem.h b/cocos2dx/menu_nodes/CCMenuItem.h index ec215e79fc..1905c58e4b 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.h +++ b/cocos2dx/menu_nodes/CCMenuItem.h @@ -62,7 +62,6 @@ public: MenuItem() : _selected(false) , _enabled(false) - , _scriptTapHandler(0) , _callback(nullptr) , _target(NULL) {} @@ -86,11 +85,6 @@ public: virtual void selected(); /** The item was unselected */ virtual void unselected(); - - /** Register menu handler script function */ - virtual void registerScriptTapHandler(int nHandler); - virtual void unregisterScriptTapHandler(void); - int getScriptTapHandler() const { return _scriptTapHandler; }; virtual bool isEnabled() const; //@note: It's 'setIsEnable' in cocos2d-iphone. @@ -105,7 +99,6 @@ public: protected: bool _selected; bool _enabled; - int _scriptTapHandler; // callback ccMenuCallback _callback; // If using the old API, the _target needs to be retained / released diff --git a/cocos2dx/platform/android/CCImage.cpp b/cocos2dx/platform/android/CCImage.cpp index f3dfbaa9a3..42878d1ae3 100644 --- a/cocos2dx/platform/android/CCImage.cpp +++ b/cocos2dx/platform/android/CCImage.cpp @@ -72,7 +72,7 @@ public: float shadowDeltaX = 0.0, float shadowDeltaY = 0.0, float shadowBlur = 0.0, - float shadowIntensity = 0.0, + float shadowOpacity = 0.0, bool stroke = false, float strokeColorR = 0.0, float strokeColorG = 0.0, @@ -81,7 +81,7 @@ public: { JniMethodInfo methodInfo; if (! JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxBitmap", "createTextBitmapShadowStroke", - "(Ljava/lang/String;Ljava/lang/String;IFFFIIIZFFFZFFFF)V")) + "(Ljava/lang/String;Ljava/lang/String;IFFFIIIZFFFFZFFFF)V")) { CCLOG("%s %d: error to get methodInfo", __FILE__, __LINE__); return false; @@ -110,7 +110,7 @@ public: jstring jstrFont = methodInfo.env->NewStringUTF(fullPathOrFontName.c_str()); methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, jstrText, - jstrFont, (int)fontSize, textTintR, textTintG, textTintB, eAlignMask, nWidth, nHeight, shadow, shadowDeltaX, -shadowDeltaY, shadowBlur, stroke, strokeColorR, strokeColorG, strokeColorB, strokeSize); + jstrFont, (int)fontSize, textTintR, textTintG, textTintB, eAlignMask, nWidth, nHeight, shadow, shadowDeltaX, -shadowDeltaY, shadowBlur, shadowOpacity, stroke, strokeColorR, strokeColorG, strokeColorB, strokeSize); methodInfo.env->DeleteLocalRef(jstrText); methodInfo.env->DeleteLocalRef(jstrFont); diff --git a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxBitmap.java b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxBitmap.java index 2a0a915a02..3df03cef47 100644 --- a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxBitmap.java +++ b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxBitmap.java @@ -96,7 +96,7 @@ public class Cocos2dxBitmap { // createTextBitmapShadowStroke( pString, pFontName, pFontSize, 1.0f, 1.0f, 1.0f, // text font and color pAlignment, pWidth, pHeight, // alignment and size - false, 0.0f, 0.0f, 0.0f, // no shadow + false, 0.0f, 0.0f, 0.0f, 0.0f, // no shadow false, 1.0f, 1.0f, 1.0f, 1.0f); // no stroke } @@ -104,7 +104,7 @@ public class Cocos2dxBitmap { public static void createTextBitmapShadowStroke(String pString, final String pFontName, final int pFontSize, final float fontTintR, final float fontTintG, final float fontTintB, final int pAlignment, final int pWidth, final int pHeight, final boolean shadow, - final float shadowDX, final float shadowDY, final float shadowBlur, final boolean stroke, + final float shadowDX, final float shadowDY, final float shadowBlur, final float shadowOpacity, final boolean stroke, final float strokeR, final float strokeG, final float strokeB, final float strokeSize) { @@ -128,7 +128,7 @@ public class Cocos2dxBitmap { if ( shadow ) { - int shadowColor = 0x54000000; + int shadowColor = ((int)(255 * shadowOpacity) & 0xff) << 24; paint.setShadowLayer(shadowBlur, shadowDX, shadowDY, shadowColor); bitmapPaddingX = Math.abs(shadowDX); diff --git a/cocos2dx/platform/ios/CCImage.mm b/cocos2dx/platform/ios/CCImage.mm index 0015e7ebf1..857c8160a0 100644 --- a/cocos2dx/platform/ios/CCImage.mm +++ b/cocos2dx/platform/ios/CCImage.mm @@ -279,12 +279,10 @@ static bool _initWithString(const char * pText, cocos2d::Image::ETextAlign eAlig 8, (int)(dim.width) * 4, colorSpace, - kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); - - CGColorSpaceRelease(colorSpace); - + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); if (!context) { + CGColorSpaceRelease(colorSpace); delete[] data; break; } @@ -319,9 +317,15 @@ static bool _initWithString(const char * pText, cocos2d::Image::ETextAlign eAlig CGSize offset; offset.height = pInfo->shadowOffset.height; offset.width = pInfo->shadowOffset.width; - CGContextSetShadow(context, offset, pInfo->shadowBlur); + CGFloat shadowColorValues[] = {0, 0, 0, pInfo->shadowOpacity}; + CGColorRef shadowColor = CGColorCreate (colorSpace, shadowColorValues); + + CGContextSetShadowWithColor(context, offset, pInfo->shadowBlur, shadowColor); + + CGColorRelease (shadowColor); } + CGColorSpaceRelease(colorSpace); // normal fonts diff --git a/cocos2dx/script_support/CCScriptSupport.h b/cocos2dx/script_support/CCScriptSupport.h index 9060b5dc8a..89d009aeba 100644 --- a/cocos2dx/script_support/CCScriptSupport.h +++ b/cocos2dx/script_support/CCScriptSupport.h @@ -166,19 +166,10 @@ enum ScriptEventType kTouchesEvent, kKeypadEvent, kAccelerometerEvent, + kControlEvent, kCommonEvent, }; -enum TouchesObjectType -{ - kLayerTouches = 0, -}; - -enum KeypadObjectType -{ - kLayerKeypad = 0, -}; - struct BasicScriptData { //nativeobject:to get handler for lua or to get jsobject for js @@ -209,12 +200,10 @@ struct SchedulerScriptData struct TouchesScriptData { int actionType; - int objectType; void* nativeObject; Set* touches; - TouchesScriptData(int inActionType,int inObjectType,void* inNativeObject,Set* inTouches) + TouchesScriptData(int inActionType,void* inNativeObject,Set* inTouches) :actionType(inActionType), - objectType(inObjectType), nativeObject(inNativeObject), touches(inTouches) { @@ -224,10 +213,9 @@ struct TouchesScriptData struct KeypadScriptData { int actionType; - int objectType; void* nativeObject; - KeypadScriptData(int inActionType,int inObjectType,void* inNativeObject) - :actionType(inActionType),objectType(inObjectType),nativeObject(inNativeObject) + KeypadScriptData(int inActionType,void* inNativeObject) + :actionType(inActionType),nativeObject(inNativeObject) { } }; @@ -285,7 +273,7 @@ public: virtual void removeScriptHandler(int nHandler) {}; /** Reallocate script function handler, only LuaEngine class need to implement this function. */ - virtual int reallocateScriptHandler(int nHandler) { return -1;} + virtual int reallocateScriptHandler(int nHandler) { return 0;} /** @brief Execute script code contained in the given string. diff --git a/cocos2dx/support/CCNotificationCenter.h b/cocos2dx/support/CCNotificationCenter.h index 5efbfe90eb..6563422e4f 100644 --- a/cocos2dx/support/CCNotificationCenter.h +++ b/cocos2dx/support/CCNotificationCenter.h @@ -30,8 +30,10 @@ THE SOFTWARE. NS_CC_BEGIN +class ScriptHandlerMgr; class CC_DLL NotificationCenter : public Object { + friend class ScriptHandlerMgr; public: /** NotificationCenter constructor */ NotificationCenter(); diff --git a/extensions/GUI/CCControlExtension/CCControl.cpp b/extensions/GUI/CCControlExtension/CCControl.cpp index d98f2fba87..5177029e4f 100644 --- a/extensions/GUI/CCControlExtension/CCControl.cpp +++ b/extensions/GUI/CCControlExtension/CCControl.cpp @@ -78,8 +78,6 @@ bool Control::init() this->setTouchPriority(1); // Initialise the tables _dispatchTable = new Dictionary(); - // Initialise the mapHandleOfControlEvents - _mapHandleOfControlEvent.clear(); return true; } @@ -128,15 +126,11 @@ void Control::sendActionsForControlEvents(ControlEvent controlEvents) invocation->invoke(this); } //Call ScriptFunc - if (kScriptTypeNone != _scriptType) + if (kScriptTypeLua == _scriptType) { - int nHandler = this->getHandleOfControlEvent(controlEvents); - if (0 != nHandler) - { - cocos2d::CommonScriptData data(nHandler, "",(Object*)this); - cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); - cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event); - } + cocos2d::BasicScriptData data((void*)this,(void*)&controlEvents); + cocos2d::ScriptEvent event(cocos2d::kControlEvent,(void*)&data); + cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event); } } } @@ -338,30 +332,4 @@ bool Control::hasVisibleParents() } return true; } - -void Control::addHandleOfControlEvent(int nFunID,ControlEvent controlEvent) -{ - _mapHandleOfControlEvent[controlEvent] = nFunID; -} - -void Control::removeHandleOfControlEvent(ControlEvent controlEvent) -{ - std::map::iterator Iter = _mapHandleOfControlEvent.find(controlEvent); - - if (_mapHandleOfControlEvent.end() != Iter) - { - _mapHandleOfControlEvent.erase(Iter); - } - -} - -int Control::getHandleOfControlEvent(ControlEvent controlEvent) -{ - std::map::iterator Iter = _mapHandleOfControlEvent.find(controlEvent); - - if (_mapHandleOfControlEvent.end() != Iter) - return Iter->second; - - return 0; -} NS_CC_EXT_END diff --git a/extensions/GUI/CCControlExtension/CCControl.h b/extensions/GUI/CCControlExtension/CCControl.h index 7b4326fa8a..9386888061 100644 --- a/extensions/GUI/CCControlExtension/CCControl.h +++ b/extensions/GUI/CCControlExtension/CCControl.h @@ -254,13 +254,6 @@ protected: void removeTargetWithActionForControlEvent(Object* target, SEL_CCControlHandler action, ControlEvent controlEvent); static Control* create(); -public: - void addHandleOfControlEvent(int nFunID,ControlEvent controlEvent); - void removeHandleOfControlEvent(ControlEvent controlEvent); -private: - int getHandleOfControlEvent(ControlEvent controlEvent); -private: - std::map _mapHandleOfControlEvent; }; // end of GUI group diff --git a/extensions/cocos-ext.h b/extensions/cocos-ext.h index a0d4334ecf..13e1c33e97 100644 --- a/extensions/cocos-ext.h +++ b/extensions/cocos-ext.h @@ -45,7 +45,7 @@ #include "physics_nodes/CCPhysicsDebugNode.h" #include "physics_nodes/CCPhysicsSprite.h" #endif - + #include "spine/spine-cocos2dx.h" #include "Components/CCComAttribute.h" diff --git a/samples/Lua/TestLua/Classes/AppDelegate.cpp b/samples/Lua/TestLua/Classes/AppDelegate.cpp index ebda987b1b..bfcfeffab4 100644 --- a/samples/Lua/TestLua/Classes/AppDelegate.cpp +++ b/samples/Lua/TestLua/Classes/AppDelegate.cpp @@ -9,6 +9,7 @@ #endif #include "LuaOpengl.h" #include "LuaScrollView.h" +#include "LuaScriptHandlerMgr.h" using namespace CocosDenshion; @@ -64,6 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching() #endif tolua_opengl_open(tolua_s); tolua_scroll_view_open(tolua_s); + tolua_script_handler_mgr_open(tolua_s); std::vector searchPaths = pFileUtils->getSearchPaths(); searchPaths.push_back("cocosbuilderRes"); @@ -74,8 +76,9 @@ bool AppDelegate::applicationDidFinishLaunching() #endif FileUtils::getInstance()->setSearchPaths(searchPaths); + pEngine->extendLuaObject(); pEngine->executeScriptFile("luaScript/controller.lua"); - + return true; } diff --git a/samples/Lua/TestLua/Resources/luaScript/ActionManagerTest/ActionManagerTest.lua b/samples/Lua/TestLua/Resources/luaScript/ActionManagerTest/ActionManagerTest.lua index ae27702f43..65b2c12063 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ActionManagerTest/ActionManagerTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ActionManagerTest/ActionManagerTest.lua @@ -29,8 +29,8 @@ local function CrashTest() ret:getParent():removeChild(ret, true) Helper.nextAction() end - - arr:addObject(CCCallFunc:create(removeThis)) + local callfunc = CCCallFunc:create(removeThis) + arr:addObject(callfunc) --After 1.5 second, self will be removed. ret:runAction( CCSequence:create(arr)) return ret @@ -56,7 +56,8 @@ local function LogicTest() node:runAction(CCScaleTo:create(2, 2)) end - arr:addObject(CCCallFuncN:create(bugMe)) + local callfunc = CCCallFunc:create(bugMe) + arr:addObject(callfunc) grossini:runAction( CCSequence:create(arr)); return ret end @@ -69,7 +70,6 @@ end local function PauseTest() local ret = createTestLayer("Pause Test") - local schedulerEntry = nil local function unpause(dt) scheduler:unscheduleScriptEntry(schedulerEntry) @@ -95,6 +95,7 @@ local function PauseTest() pDirector:getActionManager():addAction(action, grossini, true) schedulerEntry = scheduler:scheduleScriptFunc(unpause, 3.0, false) + elseif event == "exit" then if schedulerEntry ~= nil then scheduler:unscheduleScriptEntry(schedulerEntry) @@ -123,10 +124,10 @@ local function RemoveTest() pSprite:stopActionByTag(kTagSequence) end - local pCallback = CCCallFunc:create(stopAction) + local callfunc = CCCallFunc:create(stopAction) local arr = CCArray:create() arr:addObject(pMove) - arr:addObject(pCallback) + arr:addObject(callfunc) local pSequence = CCSequence:create(arr) pSequence:setTag(kTagSequence) diff --git a/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua b/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua index 335836eb2f..3b071732b2 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua @@ -582,25 +582,26 @@ local function ActionSequenceCallback3(sender) end local function ActionSequence2() - actionSequenceLayer = CCLayer:create() - initWithLayer(actionSequenceLayer) + actionSequenceLayer = CCLayer:create() + initWithLayer(actionSequenceLayer) - alignSpritesLeft(1) + alignSpritesLeft(1) - grossini:setVisible(false) - local array = CCArray:create() - array:addObject(CCPlace:create(ccp(200,200))) - array:addObject(CCShow:create()) - array:addObject(CCMoveBy:create(1, ccp(100,0))) - array:addObject(CCCallFunc:create(ActionSequenceCallback1)) - array:addObject(CCCallFuncN:create(ActionSequenceCallback2)) - array:addObject(CCCallFuncN:create(ActionSequenceCallback3)) - local action = CCSequence:create(array) + grossini:setVisible(false) + local array = CCArray:create() + array:addObject(CCPlace:create(ccp(200,200))) + array:addObject(CCShow:create()) + array:addObject(CCMoveBy:create(1, ccp(100,0))) + array:addObject(CCCallFunc:create(ActionSequenceCallback1)) + array:addObject(CCCallFunc:create(ActionSequenceCallback2)) + array:addObject(CCCallFunc:create(ActionSequenceCallback3)) + + local action = CCSequence:create(array) grossini:runAction(action) - Helper.subtitleLabel:setString("Sequence of InstantActions") - return actionSequenceLayer + Helper.subtitleLabel:setString("Sequence of InstantActions") + return actionSequenceLayer end -------------------------------------- @@ -703,7 +704,7 @@ local function ActionRepeatForever() local action = CCSequence:createWithTwoActions( CCDelayTime:create(1), - CCCallFuncN:create(repeatForever)) + CCCallFunc:create(repeatForever) ) grossini:runAction(action) @@ -796,18 +797,18 @@ local function ActionCallFunc() local action = CCSequence:createWithTwoActions( CCMoveBy:create(2, ccp(200,0)), - CCCallFunc:create(CallFucnCallback1)) + CCCallFunc:create(CallFucnCallback1) ) local array = CCArray:create() array:addObject(CCScaleBy:create(2, 2)) array:addObject(CCFadeOut:create(2)) - array:addObject(CCCallFuncN:create(CallFucnCallback2)) + array:addObject(CCCallFunc:create(CallFucnCallback2)) local action2 = CCSequence:create(array) local array2 = CCArray:create() array2:addObject(CCRotateBy:create(3 , 360)) array2:addObject(CCFadeOut:create(2)) - array2:addObject(CCCallFuncN:create(CallFucnCallback3)) + array2:addObject(CCCallFunc:create(CallFucnCallback3)) local action3 = CCSequence:create(array2) grossini:runAction(action) @@ -1087,7 +1088,7 @@ local function ActionIssue1305() centerSprites(0) spriteTmp = CCSprite:create("Images/grossini.png") - spriteTmp:runAction(CCCallFuncN:create(Issue1305_log)) + spriteTmp:runAction(CCCallFunc:create(Issue1305_log)) Issue1305_layer:registerScriptHandler(Issue1305_onEnterOrExit) @@ -1215,15 +1216,15 @@ local function ActionIssue1327() spr:setPosition(ccp(100, 100)) layer:addChild(spr) - local act1 = CCCallFuncN:create(logSprRotation) + local act1 = CCCallFunc:create(logSprRotation) local act2 = CCRotateBy:create(0.25, 45) - local act3 = CCCallFuncN:create(logSprRotation) + local act3 = CCCallFunc:create(logSprRotation) local act4 = CCRotateBy:create(0.25, 45) - local act5 = CCCallFuncN:create(logSprRotation) + local act5 = CCCallFunc:create(logSprRotation) local act6 = CCRotateBy:create(0.25, 45) - local act7 = CCCallFuncN:create(logSprRotation) + local act7 = CCCallFunc:create(logSprRotation) local act8 = CCRotateBy:create(0.25, 45) - local act9 = CCCallFuncN:create(logSprRotation) + local act9 = CCCallFunc:create(logSprRotation) local array = CCArray:create() array:addObject(act1) diff --git a/samples/Lua/TestLua/Resources/luaScript/ExtensionTest/ExtensionTest.lua b/samples/Lua/TestLua/Resources/luaScript/ExtensionTest/ExtensionTest.lua index 5027965c0e..76b7d8a237 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ExtensionTest/ExtensionTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ExtensionTest/ExtensionTest.lua @@ -128,7 +128,6 @@ local function runNotificationCenterTest() local function setIsConnectToSwitch(pLight,bConnect,nIdx) bConnectArray[nIdx] = bConnect - print("come in") if bConnect then CCNotificationCenter:sharedNotificationCenter():registerScriptObserver(pLight, switchStateChanged,NotificationCenterParam.MSG_SWITCH_STATE) else @@ -372,7 +371,7 @@ local function runCCControlTest() pDisplayValueLabel:setPosition(ccp(screenSize.width / 1.7, screenSize.height / 2.0)) pLayer:addChild(pDisplayValueLabel) - local function valueChanged(strEventName,pSender) + local function valueChanged(pSender) if nil == pSender or nil == pDisplayValueLabel then return end @@ -397,7 +396,7 @@ local function runCCControlTest() pSlider:setTag(1) --When the value of the slider will change, the given selector will be call - pSlider:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged) + pSlider:registerControlEventHandler(valueChanged, CCControlEventValueChanged) local pRestrictSlider = CCControlSlider:create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png") pRestrictSlider:setAnchorPoint(ccp(0.5, 1.0)) @@ -409,7 +408,7 @@ local function runCCControlTest() pRestrictSlider:setPosition(ccp(screenSize.width / 2.0, screenSize.height / 2.0 - 24)) pRestrictSlider:setTag(2) --same with restricted - pRestrictSlider:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged) + pRestrictSlider:registerControlEventHandler(valueChanged, CCControlEventValueChanged) pLayer:addChild(pSlider) pLayer:addChild(pRestrictSlider) end @@ -429,7 +428,7 @@ local function runCCControlTest() local dLayer_width = 0 --Create the colour picker,pStrEventName not use - local function colourValueChanged(pStrEventName,pSender) + local function colourValueChanged(pSender) if nil == pSender or nil == pColorLabel then return end @@ -441,7 +440,7 @@ local function runCCControlTest() local pColourPicker = CCControlColourPicker:create() pColourPicker:setColor(Color3B(37, 46, 252)) pColourPicker:setPosition(ccp (pColourPicker:getContentSize().width / 2, 0)) - pColourPicker:addHandleOfControlEvent(colourValueChanged, CCControlEventValueChanged) + pColourPicker:registerControlEventHandler(colourValueChanged, CCControlEventValueChanged) pNode:addChild(pColourPicker) dLayer_width = dLayer_width + pColourPicker:getContentSize().width @@ -463,7 +462,7 @@ local function runCCControlTest() pNode:setAnchorPoint(ccp (0.5, 0.5)) --Update the color text - colourValueChanged("", pColourPicker) + colourValueChanged(pColourPicker) end --SwitchTest @@ -494,7 +493,7 @@ local function runCCControlTest() pNode:addChild(pDisplayValueLabel) --Create the switch - local function valueChanged(strEventName,pSender) + local function valueChanged(pSender) if nil == pDisplayValueLabel or nil == pSender then return end @@ -516,14 +515,14 @@ local function runCCControlTest() ) pSwitchControl:setPosition(ccp (dLayer_width + 10 + pSwitchControl:getContentSize().width / 2, 0)) pNode:addChild(pSwitchControl) - pSwitchControl:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged) + pSwitchControl:registerControlEventHandler(valueChanged, CCControlEventValueChanged) --Set the layer size pNode:setContentSize(CCSizeMake(dLayer_width, 0)) pNode:setAnchorPoint(ccp (0.5, 0.5)) --Update the value label - valueChanged("", pSwitchControl) + valueChanged(pSwitchControl) end --Hvs:HelloVariableSize @@ -731,14 +730,14 @@ local function runCCControlTest() pControlButton:setTitleColorForState(Color3B(255, 255, 255), CCControlStateHighlighted) pControlButton:setAnchorPoint(ccp(0.5, 1)) pControlButton:setPosition(ccp(screenSize.width / 2.0, screenSize.height / 2.0)) - pControlButton:addHandleOfControlEvent(touchDownAction,CCControlEventTouchDown) - pControlButton:addHandleOfControlEvent(touchDragInsideAction,CCControlEventTouchDragInside) - pControlButton:addHandleOfControlEvent(touchDragOutsideAction,CCControlEventTouchDragOutside) - pControlButton:addHandleOfControlEvent(touchDragEnterAction,CCControlEventTouchDragEnter) - pControlButton:addHandleOfControlEvent(touchDragExitAction,CCControlEventTouchDragExit) - pControlButton:addHandleOfControlEvent(touchUpInsideAction,CCControlEventTouchUpInside) - pControlButton:addHandleOfControlEvent(touchUpOutsideAction,CCControlEventTouchUpOutside) - pControlButton:addHandleOfControlEvent(touchCancelAction,CCControlEventTouchCancel) + pControlButton:registerControlEventHandler(touchDownAction,CCControlEventTouchDown) + pControlButton:registerControlEventHandler(touchDragInsideAction,CCControlEventTouchDragInside) + pControlButton:registerControlEventHandler(touchDragOutsideAction,CCControlEventTouchDragOutside) + pControlButton:registerControlEventHandler(touchDragEnterAction,CCControlEventTouchDragEnter) + pControlButton:registerControlEventHandler(touchDragExitAction,CCControlEventTouchDragExit) + pControlButton:registerControlEventHandler(touchUpInsideAction,CCControlEventTouchUpInside) + pControlButton:registerControlEventHandler(touchUpOutsideAction,CCControlEventTouchUpOutside) + pControlButton:registerControlEventHandler(touchCancelAction,CCControlEventTouchCancel) pLayer:addChild(pControlButton, 1) --Add the black background @@ -774,7 +773,7 @@ local function runCCControlTest() pNode:addChild(pDisplayValueLabel) -- Add the slider - local function valueChanged(strEventName,pSender) + local function valueChanged(pSender) if nil == pSender then return end @@ -788,7 +787,7 @@ local function runCCControlTest() pPotentiometer:setPosition(ccp (dLayer_width + 10 + pPotentiometer:getContentSize().width / 2, 0)) -- When the value of the slider will change, the given selector will be call - pPotentiometer:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged) + pPotentiometer:registerControlEventHandler(valueChanged, CCControlEventValueChanged) pNode:addChild(pPotentiometer) @@ -799,7 +798,7 @@ local function runCCControlTest() pNode:setAnchorPoint(ccp (0.5, 0.5)) -- Update the value label - valueChanged("", pPotentiometer) + valueChanged(pPotentiometer) end local function InitStepperTest(pLayer) @@ -831,7 +830,7 @@ local function runCCControlTest() local minusSprite = CCSprite:create("extensions/stepper-minus.png") local plusSprite = CCSprite:create("extensions/stepper-plus.png") - local function valueChanged(strEventName,pSender) + local function valueChanged(pSender) if nil == pDisplayValueLabel or nil == pSender then return end @@ -842,7 +841,7 @@ local function runCCControlTest() end local stepper = CCControlStepper:create(minusSprite, plusSprite) stepper:setPosition(ccp (layer_width + 10 + stepper:getContentSize().width / 2, 0)) - stepper:addHandleOfControlEvent(valueChanged, CCControlEventValueChanged) + stepper:registerControlEventHandler(valueChanged, CCControlEventValueChanged) pNode:addChild(stepper) layer_width = layer_width + stepper:getContentSize().width @@ -852,7 +851,7 @@ local function runCCControlTest() pNode:setAnchorPoint(ccp (0.5, 0.5)) -- Update the value label - valueChanged("", stepper) + valueChanged(stepper) end local function InitSpecialSceneLayer(pLayer) diff --git a/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua b/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua index 1d8e26cd91..98403dec40 100644 --- a/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua @@ -313,7 +313,8 @@ local function shouldNotCrash(dt) explosion:setPosition(s.width / 2, s.height / 2) StressTest1_layer:setAnchorPoint(ccp(0, 0)) - StressTest1_layer:runAction(CCSequence:createWithTwoActions(CCRotateBy:create(2, 360), CCCallFuncN:create(removeMe))) + local callFunc = CCCallFunc:create(removeMe) + StressTest1_layer:runAction(CCSequence:createWithTwoActions(CCRotateBy:create(2, 360), callFunc)) StressTest1_layer:addChild(explosion) end diff --git a/samples/Lua/TestLua/Resources/luaScript/TileMapTest/TileMapTest.lua b/samples/Lua/TestLua/Resources/luaScript/TileMapTest/TileMapTest.lua index bb237d069a..adc21c0464 100644 --- a/samples/Lua/TestLua/Resources/luaScript/TileMapTest/TileMapTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/TileMapTest/TileMapTest.lua @@ -377,9 +377,12 @@ local function TMXReadWriteTest() local fadein = CCFadeIn:create(2) local scaleback = CCScaleTo:create(1, 1) - local function removeSprite(tag, sender) + local function removeSprite(sender) --------cclog("removing tile: %x", sender) - local node = tolua.cast(sender, "CCNode"); + local node = tolua.cast(sender, "CCNode") + if nil == node then + print("Errro node is nil") + end local p = node:getParent() if p ~= nil then @@ -388,8 +391,7 @@ local function TMXReadWriteTest() ----------cclog("atlas quantity: %d", p:textureAtlas():totalQuads()) end - - local finish = CCCallFuncN:create(removeSprite) + local finish = CCCallFunc:create(removeSprite) local arr = CCArray:create() arr:addObject(move) arr:addObject(rotate) diff --git a/samples/Lua/TestLua/Resources/luaScript/extern.lua b/samples/Lua/TestLua/Resources/luaScript/extern.lua index 68b498ac4a..60c03ba54a 100644 --- a/samples/Lua/TestLua/Resources/luaScript/extern.lua +++ b/samples/Lua/TestLua/Resources/luaScript/extern.lua @@ -61,8 +61,7 @@ end function schedule(node, callback, delay) local delay = CCDelayTime:create(delay) - local callfunc = CCCallFunc:create(callback) - local sequence = CCSequence:createWithTwoActions(delay, callfunc) + local sequence = CCSequence:createWithTwoActions(delay, CCCallFunc:create(callback)) local action = CCRepeatForever:create(sequence) node:runAction(action) return action @@ -70,8 +69,7 @@ end function performWithDelay(node, callback, delay) local delay = CCDelayTime:create(delay) - local callfunc = CCCallFunc:create(callback) - local sequence = CCSequence:createWithTwoActions(delay, callfunc) + local sequence = CCSequence:createWithTwoActions(delay, CCCallFunc:create(callback)) node:runAction(sequence) return sequence end diff --git a/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua b/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua index 37e2fe38c7..630be53cf5 100644 --- a/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua +++ b/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua @@ -45,51 +45,50 @@ local BeginPos = {x = 0, y = 0} local _allTests = { - { isSupported = true, name = "ActionsTest" , create_func = ActionsTest }, - { isSupported = true, name = "TransitionsTest" , create_func = TransitionsTest }, - { isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest }, - { isSupported = true, name = "EffectsTest" , create_func = EffectsTest }, - { isSupported = true, name = "ClickAndMoveTest" , create_func = ClickAndMoveTest }, - { isSupported = true, name = "RotateWorldTest" , create_func = RotateWorldTest }, - { isSupported = true, name = "ParticleTest" , create_func = ParticleTest }, - { isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest }, - { isSupported = true, name = "MotionStreakTest" , create_func = MotionStreakTest }, - { isSupported = false, name = "DrawPrimitivesTest" , create_func= DrawPrimitivesTest }, - { isSupported = true, name = "NodeTest" , create_func = CocosNodeTest }, - { isSupported = true, name = "TouchesTest" , create_func = TouchesTest }, - --Many tests in MenuTest will crash, so disable it. Should enable it after all crashes are resolved. - { isSupported = true, name = "MenuTest" , create_func = MenuTestMain }, + { isSupported = true, name = "Accelerometer" , create_func= AccelerometerMain }, { isSupported = true, name = "ActionManagerTest" , create_func = ActionManagerTestMain }, - { isSupported = true, name = "LayerTest" , create_func = LayerTestMain }, - { isSupported = true, name = "SceneTest" , create_func = SceneTestMain }, - { isSupported = true, name = "ParallaxTest" , create_func = ParallaxTestMain }, - { isSupported = true, name = "TileMapTest" , create_func = TileMapTestMain }, - { isSupported = true, name = "IntervalTest" , create_func = IntervalTestMain }, - { isSupported = false, name = "ChipmunkAccelTouchTest" , create_func= ChipmunkAccelTouchTestMain }, - { isSupported = true, name = "LabelTest" , create_func = LabelTest }, - { isSupported = false, name = "TextInputTest" , create_func= TextInputTestMain }, - { isSupported = true, name = "SpriteTest" , create_func = SpriteTest }, - { isSupported = false, name = "SchdulerTest" , create_func= SchdulerTestMain }, - { isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain }, - { isSupported = true, name = "Texture2DTest" , create_func = Texture2dTestMain }, + { isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest }, + { isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest }, + { isSupported = true, name = "ActionsTest" , create_func = ActionsTest }, { isSupported = false, name = "Box2dTest" , create_func= Box2dTestMain }, { isSupported = false, name = "Box2dTestBed" , create_func= Box2dTestBedMain }, - { isSupported = true, name = "EffectAdvancedTest" , create_func = EffectAdvancedTestMain }, - { isSupported = true, name = "Accelerometer" , create_func= AccelerometerMain }, - { isSupported = true, name = "KeypadTest" , create_func= KeypadTestMain }, - { isSupported = true, name = "CocosDenshionTest" , create_func = CocosDenshionTestMain }, - { isSupported = true, name = "PerformanceTest" , create_func= PerformanceTestMain }, - { isSupported = true, name = "ZwoptexTest" , create_func = ZwoptexTestMain }, - { isSupported = false, name = "CurlTest" , create_func= CurlTestMain }, - { isSupported = true, name = "UserDefaultTest" , create_func= UserDefaultTestMain }, { isSupported = true, name = "BugsTest" , create_func= BugsTestMain }, - { isSupported = true, name = "FontTest" , create_func = FontTestMain }, + { isSupported = false, name = "ChipmunkAccelTouchTest" , create_func= ChipmunkAccelTouchTestMain }, + { isSupported = true, name = "ClickAndMoveTest" , create_func = ClickAndMoveTest }, + { isSupported = true, name = "CocosDenshionTest" , create_func = CocosDenshionTestMain }, + { isSupported = false, name = "CurlTest" , create_func= CurlTestMain }, { isSupported = true, name = "CurrentLanguageTest" , create_func= CurrentLanguageTestMain }, - { isSupported = false, name = "TextureCacheTest" , create_func= TextureCacheTestMain }, + { isSupported = false, name = "DrawPrimitivesTest" , create_func= DrawPrimitivesTest }, + { isSupported = true, name = "EffectsTest" , create_func = EffectsTest }, + { isSupported = true, name = "EffectAdvancedTest" , create_func = EffectAdvancedTestMain }, { isSupported = true, name = "ExtensionsTest" , create_func= ExtensionsTestMain }, - { isSupported = false, name = "ShaderTest" , create_func= ShaderTestMain }, + { isSupported = true, name = "FontTest" , create_func = FontTestMain }, + { isSupported = true, name = "IntervalTest" , create_func = IntervalTestMain }, + { isSupported = true, name = "KeypadTest" , create_func= KeypadTestMain }, + { isSupported = true, name = "LabelTest" , create_func = LabelTest }, + { isSupported = true, name = "LayerTest" , create_func = LayerTestMain }, + { isSupported = true, name = "MenuTest" , create_func = MenuTestMain }, + { isSupported = true, name = "MotionStreakTest" , create_func = MotionStreakTest }, { isSupported = false, name = "MutiTouchTest" , create_func= MutiTouchTestMain }, - { isSupported = true, name = "OpenGLTest" , create_func= OpenGLTestMain } + { isSupported = true, name = "NodeTest" , create_func = CocosNodeTest }, + { isSupported = true, name = "OpenGLTest" , create_func= OpenGLTestMain }, + { isSupported = true, name = "ParallaxTest" , create_func = ParallaxTestMain }, + { isSupported = true, name = "ParticleTest" , create_func = ParticleTest }, + { isSupported = true, name = "PerformanceTest" , create_func= PerformanceTestMain }, + { isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain }, + { isSupported = true, name = "RotateWorldTest" , create_func = RotateWorldTest }, + { isSupported = true, name = "SceneTest" , create_func = SceneTestMain }, + { isSupported = false, name = "SchdulerTest" , create_func= SchdulerTestMain }, + { isSupported = false, name = "ShaderTest" , create_func= ShaderTestMain }, + { isSupported = true, name = "SpriteTest" , create_func = SpriteTest }, + { isSupported = false, name = "TextInputTest" , create_func= TextInputTestMain }, + { isSupported = true, name = "Texture2DTest" , create_func = Texture2dTestMain }, + { isSupported = false, name = "TextureCacheTest" , create_func= TextureCacheTestMain }, + { isSupported = true, name = "TileMapTest" , create_func = TileMapTestMain }, + { isSupported = true, name = "TouchesTest" , create_func = TouchesTest }, + { isSupported = true, name = "TransitionsTest" , create_func = TransitionsTest }, + { isSupported = true, name = "UserDefaultTest" , create_func= UserDefaultTestMain }, + { isSupported = true, name = "ZwoptexTest" , create_func = ZwoptexTestMain } } local TESTS_COUNT = table.getn(_allTests) diff --git a/scripting/javascript/bindings/generated b/scripting/javascript/bindings/generated index 47d7b831be..6f8b3fcb81 160000 --- a/scripting/javascript/bindings/generated +++ b/scripting/javascript/bindings/generated @@ -1 +1 @@ -Subproject commit 47d7b831bedde49e53d8daf8e619eea7932b2b79 +Subproject commit 6f8b3fcb81a96054903ab7361354a288f837b1a6 diff --git a/scripting/javascript/bindings/js/jsb_cocos2d_constants.js b/scripting/javascript/bindings/js/jsb_cocos2d_constants.js index de5f804e61..b3b8ba7db6 100644 --- a/scripting/javascript/bindings/js/jsb_cocos2d_constants.js +++ b/scripting/javascript/bindings/js/jsb_cocos2d_constants.js @@ -93,17 +93,17 @@ cc.TMX_TILE_VERTICAL_FLAG = 0x40000000; cc.TEXT_ALIGNMENT_CENTER = 0x1; cc.TEXT_ALIGNMENT_LEFT = 0x0; cc.TEXT_ALIGNMENT_RIGHT = 0x2; -cc.TEXTURE2_D_PIXEL_FORMAT_A8 = 0x3; -cc.TEXTURE2_D_PIXEL_FORMAT_A_I88 = 0x5; -cc.TEXTURE2_D_PIXEL_FORMAT_DEFAULT = 0x0; -cc.TEXTURE2_D_PIXEL_FORMAT_I8 = 0x4; -cc.TEXTURE2_D_PIXEL_FORMAT_PVRTC2 = 0x9; -cc.TEXTURE2_D_PIXEL_FORMAT_PVRTC4 = 0x8; -cc.TEXTURE2_D_PIXEL_FORMAT_RG_B565 = 0x2; -cc.TEXTURE2_D_PIXEL_FORMAT_RGB5_A1 = 0x7; -cc.TEXTURE2_D_PIXEL_FORMAT_RG_B888 = 0x1; -cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444 = 0x6; -cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888 = 0x0; +cc.TEXTURE_2D_PIXEL_FORMAT_A8 = 0x3; +cc.TEXTURE_2D_PIXEL_FORMAT_AI88 = 0x5; +cc.TEXTURE_2D_PIXEL_FORMAT_DEFAULT = 0x0; +cc.TEXTURE_2D_PIXEL_FORMAT_I8 = 0x4; +cc.TEXTURE_2D_PIXEL_FORMAT_PVRTC2 = 0x9; +cc.TEXTURE_2D_PIXEL_FORMAT_PVRTC4 = 0x8; +cc.TEXTURE_2D_PIXEL_FORMAT_RGB565 = 0x2; +cc.TEXTURE_2D_PIXEL_FORMAT_RGB5A1 = 0x7; +cc.TEXTURE_2D_PIXEL_FORMAT_RGB888 = 0x1; +cc.TEXTURE_2D_PIXEL_FORMAT_RGBA4444 = 0x6; +cc.TEXTURE_2D_PIXEL_FORMAT_RGBA8888 = 0x0; cc.TOUCHES_ALL_AT_ONCE = 0x0; cc.TOUCHES_ONE_BY_ONE = 0x1; cc.TRANSITION_ORIENTATION_DOWN_OVER = 0x1; diff --git a/scripting/lua/cocos2dx_support/CCBProxy.cpp b/scripting/lua/cocos2dx_support/CCBProxy.cpp index 2d284d58fe..60fe9677b2 100644 --- a/scripting/lua/cocos2dx_support/CCBProxy.cpp +++ b/scripting/lua/cocos2dx_support/CCBProxy.cpp @@ -23,6 +23,7 @@ ****************************************************************************/ #include "CCBProxy.h" +#include "LuaScriptHandlerMgr.h" CCBReader* CCBProxy::createCCBReader() { @@ -144,7 +145,7 @@ void CCBProxy::setCallback(Node* pNode,int nHandle) { MenuItem *pMenuItem = dynamic_cast(pNode); if (NULL != pMenuItem) { - pMenuItem->registerScriptTapHandler(nHandle); + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)pMenuItem, nHandle, ScriptHandlerMgr::kMenuClickHandler); } } else if (NULL != dynamic_cast(pNode)) @@ -152,10 +153,8 @@ void CCBProxy::setCallback(Node* pNode,int nHandle) ControlButton *pBtnItem = dynamic_cast(pNode); if (NULL != pBtnItem) { //UNOD,need Btn Pros to addHanldeOfControlEvent - pBtnItem->addHandleOfControlEvent(nHandle,ControlEventTouchUpInside); + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)pBtnItem, nHandle, ScriptHandlerMgr::kControlTouchUpInsideHandler); } } - - } diff --git a/scripting/lua/cocos2dx_support/CCLuaEngine.cpp b/scripting/lua/cocos2dx_support/CCLuaEngine.cpp index a2e39bc708..f40c296704 100644 --- a/scripting/lua/cocos2dx_support/CCLuaEngine.cpp +++ b/scripting/lua/cocos2dx_support/CCLuaEngine.cpp @@ -26,6 +26,8 @@ #include "cocos2d.h" #include "cocoa/CCArray.h" #include "CCScheduler.h" +#include "LuaScriptHandlerMgr.h" +#include "GUI/CCControlExtension/CCControl.h" NS_CC_BEGIN @@ -67,6 +69,7 @@ void LuaEngine::addLuaLoader(lua_CFunction func) void LuaEngine::removeScriptObjectByObject(Object* pObj) { _stack->removeScriptObjectByObject(pObj); + ScriptHandlerMgr::getInstance()->removeObjectAllHandlers(pObj); } void LuaEngine::removeScriptHandler(int nHandler) @@ -97,49 +100,12 @@ int LuaEngine::executeGlobalFunction(const char* functionName) int LuaEngine::executeNodeEvent(Node* pNode, int nAction) { - int nHandler = pNode->getScriptHandler(); - if (!nHandler) return 0; - - switch (nAction) - { - case kNodeOnEnter: - _stack->pushString("enter"); - break; - - case kNodeOnExit: - _stack->pushString("exit"); - break; - - case kNodeOnEnterTransitionDidFinish: - _stack->pushString("enterTransitionFinish"); - break; - - case kNodeOnExitTransitionDidStart: - _stack->pushString("exitTransitionStart"); - break; - - case kNodeOnCleanup: - _stack->pushString("cleanup"); - break; - - default: - return 0; - } - int ret = _stack->executeFunctionByHandler(nHandler, 1); - _stack->clean(); - return ret; + return 0; } int LuaEngine::executeMenuItemEvent(MenuItem* pMenuItem) { - int nHandler = pMenuItem->getScriptTapHandler(); - if (!nHandler) return 0; - - _stack->pushInt(pMenuItem->getTag()); - _stack->pushObject(pMenuItem, "CCMenuItem"); - int ret = _stack->executeFunctionByHandler(nHandler, 2); - _stack->clean(); - return ret; + return 0; } int LuaEngine::executeNotificationEvent(NotificationCenter* pNotificationCenter, const char* pszName) @@ -155,16 +121,7 @@ int LuaEngine::executeNotificationEvent(NotificationCenter* pNotificationCenter, int LuaEngine::executeCallFuncActionEvent(CallFunc* pAction, Object* pTarget/* = NULL*/) { - int nHandler = pAction->getScriptHandler(); - if (!nHandler) return 0; - - if (pTarget) - { - _stack->pushObject(pTarget, "CCNode"); - } - int ret = _stack->executeFunctionByHandler(nHandler, pTarget ? 1 : 0); - _stack->clean(); - return ret; + return 0; } int LuaEngine::executeSchedule(int nHandler, float dt, Node* pNode/* = NULL*/) @@ -178,131 +135,22 @@ int LuaEngine::executeSchedule(int nHandler, float dt, Node* pNode/* = NULL*/) int LuaEngine::executeLayerTouchEvent(Layer* pLayer, int eventType, Touch *pTouch) { - TouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry(); - if (!pScriptHandlerEntry) return 0; - int nHandler = pScriptHandlerEntry->getHandler(); - if (!nHandler) return 0; - - switch (eventType) - { - case CCTOUCHBEGAN: - _stack->pushString("began"); - break; - - case CCTOUCHMOVED: - _stack->pushString("moved"); - break; - - case CCTOUCHENDED: - _stack->pushString("ended"); - break; - - case CCTOUCHCANCELLED: - _stack->pushString("cancelled"); - break; - - default: - return 0; - } - - const Point pt = Director::getInstance()->convertToGL(pTouch->getLocationInView()); - _stack->pushFloat(pt.x); - _stack->pushFloat(pt.y); - int ret = _stack->executeFunctionByHandler(nHandler, 3); - _stack->clean(); - return ret; + return 0; } int LuaEngine::executeLayerTouchesEvent(Layer* pLayer, int eventType, Set *pTouches) { - TouchScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptTouchHandlerEntry(); - if (!pScriptHandlerEntry) return 0; - int nHandler = pScriptHandlerEntry->getHandler(); - if (!nHandler) return 0; - - switch (eventType) - { - case CCTOUCHBEGAN: - _stack->pushString("began"); - break; - - case CCTOUCHMOVED: - _stack->pushString("moved"); - break; - - case CCTOUCHENDED: - _stack->pushString("ended"); - break; - - case CCTOUCHCANCELLED: - _stack->pushString("cancelled"); - break; - - default: - return 0; - } - - Director* pDirector = Director::getInstance(); - lua_State *L = _stack->getLuaState(); - lua_newtable(L); - int i = 1; - for (SetIterator it = pTouches->begin(); it != pTouches->end(); ++it) - { - Touch* pTouch = (Touch*)*it; - Point pt = pDirector->convertToGL(pTouch->getLocationInView()); - lua_pushnumber(L, pt.x); - lua_rawseti(L, -2, i++); - lua_pushnumber(L, pt.y); - lua_rawseti(L, -2, i++); - lua_pushinteger(L, pTouch->getID()); - lua_rawseti(L, -2, i++); - } - int ret = _stack->executeFunctionByHandler(nHandler, 2); - _stack->clean(); - return ret; + return 0; } int LuaEngine::executeLayerKeypadEvent(Layer* pLayer, int eventType) { - ScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptKeypadHandlerEntry(); - if (!pScriptHandlerEntry) - return 0; - int nHandler = pScriptHandlerEntry->getHandler(); - if (!nHandler) return 0; - - switch (eventType) - { - case kTypeBackClicked: - _stack->pushString("backClicked"); - break; - - case kTypeMenuClicked: - _stack->pushString("menuClicked"); - break; - - default: - return 0; - } - int ret = _stack->executeFunctionByHandler(nHandler, 1); - _stack->clean(); - return ret; + return 0; } int LuaEngine::executeAccelerometerEvent(Layer* pLayer, Acceleration* pAccelerationValue) { - ScriptHandlerEntry* pScriptHandlerEntry = pLayer->getScriptAccelerateHandlerEntry(); - if (!pScriptHandlerEntry) - return 0; - int nHandler = pScriptHandlerEntry->getHandler(); - if (!nHandler) return 0; - - _stack->pushFloat(pAccelerationValue->x); - _stack->pushFloat(pAccelerationValue->y); - _stack->pushFloat(pAccelerationValue->z); - _stack->pushFloat(pAccelerationValue->timestamp); - int ret = _stack->executeFunctionByHandler(nHandler, 4); - _stack->clean(); - return ret; + return 0; } int LuaEngine::executeEvent(int nHandler, const char* pEventName, Object* pEventSource /* = NULL*/, const char* pEventSourceClassName /* = NULL*/) @@ -382,6 +230,11 @@ int LuaEngine::sendEvent(ScriptEvent* message) return handleCommonEvent(message->data); } break; + case kControlEvent: + { + return handlerControlEvent(message->data); + } + break; default: break; } @@ -398,9 +251,8 @@ int LuaEngine::handleNodeEvent(void* data) if (NULL == basicScriptData->nativeObject || NULL == basicScriptData->value) return 0; - Node* node = (Node*)(basicScriptData->nativeObject); + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler(basicScriptData->nativeObject, ScriptHandlerMgr::kNodeHandler); - int handler = node->getScriptHandler(); if (0 == handler) return 0; @@ -446,7 +298,7 @@ int LuaEngine::handleMenuClickedEvent(void* data) MenuItem* menuItem = (MenuItem*)(basicScriptData->nativeObject); - int handler = menuItem->getScriptTapHandler(); + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)menuItem, ScriptHandlerMgr::kMenuClickHandler); if (0 == handler) return 0; @@ -487,9 +339,12 @@ int LuaEngine::handleCallFuncActionEvent(void* data) BasicScriptData* basicScriptData = (BasicScriptData*)(data); if (NULL == basicScriptData->nativeObject) return 0; + + int handler =ScriptHandlerMgr::getInstance()->getObjectHandler(basicScriptData->nativeObject, ScriptHandlerMgr::kCallFuncHandler); + + if (0 == handler) + return 0; - CallFunc* callFunc = (CallFunc*)(basicScriptData->nativeObject); - int handler = callFunc->getScriptHandler(); Object* target = (Object*)(basicScriptData->value); if (NULL != target) { @@ -523,20 +378,29 @@ int LuaEngine::handleKeypadEvent(void* data) if (NULL == keypadScriptData->nativeObject) return 0; - switch (keypadScriptData->objectType) + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)keypadScriptData->nativeObject, ScriptHandlerMgr::kKeypadHandler); + + if (0 == handler) + return 0; + + int action = keypadScriptData->actionType; + + switch (action) { - case kLayerKeypad: - { - Layer* layer = (Layer*)(keypadScriptData->nativeObject); - return handleLayerKeypadEvent(layer, keypadScriptData->actionType); - } - break; + case kTypeBackClicked: + _stack->pushString("backClicked"); + break; + + case kTypeMenuClicked: + _stack->pushString("menuClicked"); + break; default: - break; + return 0; } - - return 0; + int ret = _stack->executeFunctionByHandler(handler, 1); + _stack->clean(); + return ret; } int LuaEngine::handleAccelerometerEvent(void* data) @@ -548,10 +412,8 @@ int LuaEngine::handleAccelerometerEvent(void* data) if (NULL == basicScriptData->nativeObject || NULL == basicScriptData->value) return 0; - Layer* layer = (Layer*)(basicScriptData->nativeObject); - - ScriptHandlerEntry* scriptHandlerEntry = layer->getScriptAccelerateHandlerEntry(); - if (NULL == scriptHandlerEntry || 0 == scriptHandlerEntry->getHandler()) + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler(basicScriptData->nativeObject, ScriptHandlerMgr::kAccelerometerHandler); + if (0 == handler) return 0; Acceleration* accelerationValue = (Acceleration*)(basicScriptData->value); @@ -559,7 +421,7 @@ int LuaEngine::handleAccelerometerEvent(void* data) _stack->pushFloat(accelerationValue->y); _stack->pushFloat(accelerationValue->z); _stack->pushFloat(accelerationValue->timestamp); - int ret = _stack->executeFunctionByHandler(scriptHandlerEntry->getHandler(), 4); + int ret = _stack->executeFunctionByHandler(handler, 4); _stack->clean(); return ret; } @@ -599,32 +461,12 @@ int LuaEngine::handleTouchesEvent(void* data) if (NULL == touchesScriptData->nativeObject || NULL == touchesScriptData->touches) return 0; - switch (touchesScriptData->objectType) - { - case kLayerTouches: - { - Layer* layer = (Layer*)(touchesScriptData->nativeObject); - return handleLayerTouchesEvent(layer, touchesScriptData->actionType, touchesScriptData->touches); - } - break; - - default: - break; - } - - return 0; -} - -int LuaEngine::handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches) -{ - if (NULL == layer || NULL == touches) + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)touchesScriptData->nativeObject, ScriptHandlerMgr::kTouchesHandler); + + if (0 == handler) return 0; - TouchScriptHandlerEntry* scriptHandlerEntry = layer->getScriptTouchHandlerEntry(); - if (NULL == scriptHandlerEntry || 0 == scriptHandlerEntry->getHandler()) - return 0; - - switch (actionType) + switch (touchesScriptData->actionType) { case CCTOUCHBEGAN: _stack->pushString("began"); @@ -648,23 +490,23 @@ int LuaEngine::handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches) Director* pDirector = Director::getInstance(); lua_State *L = _stack->getLuaState(); - int count = touches->count(); + int count = touchesScriptData->touches->count(); int ret = 0; if (count == 1) { - Touch* touch = (Touch*)*(touches->begin()); + Touch* touch = (Touch*)*(touchesScriptData->touches->begin()); if (NULL != touch) { const Point pt = Director::getInstance()->convertToGL(touch->getLocationInView()); _stack->pushFloat(pt.x); _stack->pushFloat(pt.y); - ret = _stack->executeFunctionByHandler(scriptHandlerEntry->getHandler(), 3); + ret = _stack->executeFunctionByHandler(handler, 3); } } else if(count > 1) { lua_newtable(L); int i = 1; - for (SetIterator it = touches->begin(); it != touches->end(); ++it) + for (SetIterator it = touchesScriptData->touches->begin(); it != touchesScriptData->touches->end(); ++it) { Touch* pTouch = (Touch*)*it; Point pt = pDirector->convertToGL(pTouch->getLocationInView()); @@ -675,36 +517,139 @@ int LuaEngine::handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches) lua_pushinteger(L, pTouch->getID()); lua_rawseti(L, -2, i++); } - ret = _stack->executeFunctionByHandler(scriptHandlerEntry->getHandler(), 2); + ret = _stack->executeFunctionByHandler(handler, 2); } _stack->clean(); return ret; } -int LuaEngine::handleLayerKeypadEvent(Layer* layer,int actionType) +int LuaEngine::handlerControlEvent(void* data) { - if (NULL == layer) + if ( NULL == data ) return 0; - ScriptHandlerEntry* pScriptHandlerEntry = layer->getScriptKeypadHandlerEntry(); + BasicScriptData* basicScriptData = (BasicScriptData*)data; + if (NULL == basicScriptData->nativeObject) + return 0; - int action = actionType; + int controlEvents = *((int*)(basicScriptData->value)); - switch (action) + int handler = 0; + int ret = 0; + + for (int i = 0; i < kControlEventTotalNumber; i++) { - case kTypeBackClicked: - _stack->pushString("backClicked"); - break; + if ((controlEvents & (1 << i))) + { + handler = ScriptHandlerMgr::getInstance()->getObjectHandler(basicScriptData->nativeObject, ScriptHandlerMgr::kControlTouchDownHandler + i); - case kTypeMenuClicked: - _stack->pushString("menuClicked"); - break; - - default: - return 0; + if (0 != handler) + { + _stack->pushObject((Object*)basicScriptData->nativeObject, "CCObject"); + ret = _stack->executeFunctionByHandler(handler, 1); + _stack->clean(); + } + } } - int ret = _stack->executeFunctionByHandler(pScriptHandlerEntry->getHandler(), 1); + + return ret; +} + +void LuaEngine::extendLuaObject() +{ + if ( NULL == _stack || NULL == _stack->getLuaState()) + return; + + lua_State* lua_S = _stack->getLuaState(); + extendNode(lua_S); + extendMenuItem(lua_S); + extendLayer(lua_S); + extendControl(lua_S); + _stack->clean(); - return ret; +} + +void LuaEngine::extendNode(lua_State* lua_S) +{ + if(NULL == lua_S) + return; + + lua_pushstring(lua_S,"CCNode"); + lua_rawget(lua_S,LUA_REGISTRYINDEX); + if (lua_istable(lua_S,-1)) + { + lua_pushstring(lua_S,"registerScriptHandler"); + lua_pushcfunction(lua_S,tolua_Cocos2d_registerScriptHandler00); + lua_rawset(lua_S,-3); + lua_pushstring(lua_S,"unregisterScriptHandler"); + lua_pushcfunction(lua_S,tolua_Cocos2d_unregisterScriptHandler00); + lua_rawset(lua_S, -3); + } +} + +void LuaEngine::extendMenuItem(lua_State* lua_S) +{ + if (NULL == lua_S) + return; + + lua_pushstring(lua_S,"CCMenuItem"); + lua_rawget(lua_S,LUA_REGISTRYINDEX); + if (lua_istable(lua_S,-1)) + { + lua_pushstring(lua_S,"registerScriptTapHandler"); + lua_pushcfunction(lua_S,tolua_Cocos2d_registerScriptTapHandler00); + lua_rawset(lua_S,-3); + lua_pushstring(lua_S, "unregisterScriptTapHandler"); + lua_pushcfunction(lua_S,tolua_Cocos2d_unregisterScriptTapHandler00); + lua_rawset(lua_S, -3); + } +} + +void LuaEngine::extendLayer(lua_State* lua_S) +{ + if (NULL == lua_S) + return; + + lua_pushstring(lua_S,"CCLayer"); + lua_rawget(lua_S,LUA_REGISTRYINDEX); + if (lua_istable(lua_S,-1)) + { + lua_pushstring(lua_S,"registerScriptTouchHandler"); + lua_pushcfunction(lua_S,tolua_Cocos2d_registerScriptTouchHandler00); + lua_rawset(lua_S,-3); + lua_pushstring(lua_S, "unregisterScriptTouchHandler"); + lua_pushcfunction(lua_S,tolua_Cocos2d_unregisterScriptTouchHandler00); + lua_rawset(lua_S, -3); + lua_pushstring(lua_S, "registerScriptKeypadHandler"); + lua_pushcfunction(lua_S, tolua_Cocos2d_registerScriptKeypadHandler00); + lua_rawset(lua_S, -3); + lua_pushstring(lua_S, "unregisterScriptKeypadHandler"); + lua_pushcfunction(lua_S, tolua_Cocos2d_unregisterScriptKeypadHandler00); + lua_rawset(lua_S, -3); + lua_pushstring(lua_S, "registerScriptAccelerateHandler"); + lua_pushcfunction(lua_S, tolua_Cocos2d_registerScriptAccelerateHandler00); + lua_rawset(lua_S, -3); + lua_pushstring(lua_S, "unregisterScriptAccelerateHandler"); + lua_pushcfunction(lua_S, tolua_Cocos2d_unregisterScriptAccelerateHandler00); + lua_rawset(lua_S, -3); + } +} + +void LuaEngine::extendControl(lua_State* lua_S) +{ + if (NULL == lua_S) + return; + + lua_pushstring(lua_S,"CCControl"); + lua_rawget(lua_S,LUA_REGISTRYINDEX); + if (lua_istable(lua_S,-1)) + { + lua_pushstring(lua_S,"registerControlEventHandler"); + lua_pushcfunction(lua_S,tolua_Cocos2d_registerControlEventHandler00); + lua_rawset(lua_S,-3); + lua_pushstring(lua_S,"unregisterControlEventHandler"); + lua_pushcfunction(lua_S,tolua_Cocos2d_unregisterControlEventHandler00); + lua_rawset(lua_S,-3); + } } NS_CC_END diff --git a/scripting/lua/cocos2dx_support/CCLuaEngine.h b/scripting/lua/cocos2dx_support/CCLuaEngine.h index b24e1a16ec..4fedd35233 100644 --- a/scripting/lua/cocos2dx_support/CCLuaEngine.h +++ b/scripting/lua/cocos2dx_support/CCLuaEngine.h @@ -119,6 +119,7 @@ public: virtual bool handleAssert(const char *msg); virtual int sendEvent(ScriptEvent* message); + void extendLuaObject(); private: int handleNodeEvent(void* data); int handleMenuClickedEvent(void* data); @@ -129,8 +130,11 @@ private: int handleAccelerometerEvent(void* data); int handleCommonEvent(void* data); int handleTouchesEvent(void* data); - int handleLayerTouchesEvent(Layer* layer,int actionType,Set* touches); - int handleLayerKeypadEvent(Layer* layer,int actionType); + int handlerControlEvent(void* data); + void extendNode(lua_State* lua_S); + void extendMenuItem(lua_State* lua_S); + void extendLayer(lua_State* lua_S); + void extendControl(lua_State* lua_S); private: LuaEngine(void) : _stack(NULL) diff --git a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id index 16582a4598..00135a60b3 100644 --- a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id @@ -1 +1 @@ -dcb1aae4641e4e318fc42f8d740bebe21c4277ca \ No newline at end of file +ecb6191757f5eb70142d6767d49edf46074a2db4 \ No newline at end of file diff --git a/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id index 24259265d5..c2c49c47a7 100644 --- a/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaOpengl.cpp.REMOVED.git-id @@ -1 +1 @@ -d0b231fcad3b4e35d4f2a998dce1b7437ae689ab \ No newline at end of file +9fac9e19f8a57d40eb90b02c0be6e9f8e20e0d22 \ No newline at end of file diff --git a/scripting/lua/cocos2dx_support/LuaScriptHandlerMgr.cpp b/scripting/lua/cocos2dx_support/LuaScriptHandlerMgr.cpp new file mode 100644 index 0000000000..44fae6f12a --- /dev/null +++ b/scripting/lua/cocos2dx_support/LuaScriptHandlerMgr.cpp @@ -0,0 +1,610 @@ +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua_fix.h" +#ifdef __cplusplus +} +#endif + +#include +#include +#include "LuaScriptHandlerMgr.h" +#include "cocos2d.h" +#include "cocos-ext.h" +#include "CCLuaStack.h" +#include "CCLuaValue.h" +#include "CCLuaEngine.h" + +using namespace cocos2d; +using namespace cocos2d::extension; + +NS_CC_BEGIN + +ScheduleHandlerDelegate* ScheduleHandlerDelegate::create() +{ + ScheduleHandlerDelegate *ret = new ScheduleHandlerDelegate(); + if (NULL != ret ) + { + ret->autorelease(); + return ret; + } + else + { + CC_SAFE_DELETE(ret); + return NULL; + } +} + +void ScheduleHandlerDelegate::scheduleFunc(float elapse) +{ + +} + +void ScheduleHandlerDelegate::update(float elapse) +{ + +} + + +LuaCallFunc * LuaCallFunc::create(int nHandler) +{ + LuaCallFunc *ret = new LuaCallFunc(); + if (NULL != ret ) + { + ret->autorelease(); + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)ret, nHandler, ScriptHandlerMgr::kCallFuncHandler); + return ret; + } + else + { + CC_SAFE_DELETE(ret); + return NULL; + } +} +void LuaCallFunc::execute() +{ + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr:: kCallFuncHandler); + + if (0 == handler) + return ; + + BasicScriptData data((void*)this,(void*)_target); + ScriptEvent event(kCallFuncEvent,(void*)&data); + ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event); +} + +LuaCallFunc* LuaCallFunc::clone() const +{ + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr:: kCallFuncHandler); + + if (0 == handler) + return NULL; + + auto ret = new LuaCallFunc(); + + int newscriptHandler = cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine()->reallocateScriptHandler(handler); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)ret, newscriptHandler, ScriptHandlerMgr::kCallFuncHandler); + + ret->autorelease(); + + return ret; +} + +ScriptHandlerMgr* ScriptHandlerMgr::_scriptHandlerMgr = NULL; + +ScriptHandlerMgr::ScriptHandlerMgr() +{ + +} +ScriptHandlerMgr::~ScriptHandlerMgr() +{ + CC_SAFE_DELETE(_scriptHandlerMgr); +} +ScriptHandlerMgr* ScriptHandlerMgr::getInstance() +{ + if (NULL == _scriptHandlerMgr) + { + _scriptHandlerMgr = new ScriptHandlerMgr(); + _scriptHandlerMgr->init(); + } + return _scriptHandlerMgr; +} + +void ScriptHandlerMgr::init() +{ + _mapObjectHandlers.clear(); +} + +void ScriptHandlerMgr::addObjectHandler(void* object,int handler,int eventType) +{ + if (NULL == object) + return; + + //may be not need + removeObjectHandler(object,eventType); + + auto iter = _mapObjectHandlers.find(object); + VecEventHandlers vecHandlers; + vecHandlers.clear(); + if (_mapObjectHandlers.end() != iter) + { + vecHandlers = iter->second; + } + + PairEventHandler eventHanler = std::make_pair(eventType, handler); + vecHandlers.push_back(eventHanler); + _mapObjectHandlers[object] = vecHandlers; +} +void ScriptHandlerMgr::removeObjectHandler(void* object,int eventType) +{ + if (NULL == object || _mapObjectHandlers.empty()) + return; + + auto iterMap = _mapObjectHandlers.find(object); + if (_mapObjectHandlers.end() == iterMap) + return; + + if (iterMap->second.empty()) + return; + + auto iterVec = iterMap->second.begin(); + bool exist = false; + for (; iterVec != iterMap->second.end(); iterVec++) + { + if (iterVec->first == eventType) + { + exist = true; + break; + } + } + + if (exist) + { + iterMap->second.erase(iterVec); + } + +} +int ScriptHandlerMgr::getObjectHandler(void* object,int eventType) +{ + if (NULL == object || _mapObjectHandlers.empty() ) + return 0; + + auto iter = _mapObjectHandlers.find(object); + + if (_mapObjectHandlers.end() != iter) + { + auto iterVec = (iter->second).begin(); + for (; iterVec != (iter->second).end(); iterVec++) + { + if (iterVec->first == eventType) + { + return iterVec->second; + } + } + } + + return 0; +} +void ScriptHandlerMgr::removeObjectAllHandlers(void* object) +{ + if (NULL == object || _mapObjectHandlers.empty()) + return; + + auto iter = _mapObjectHandlers.find(object); + + if (_mapObjectHandlers.end() != iter) + { + (iter->second).clear(); + _mapObjectHandlers.erase(iter); + } +} + +NS_CC_END + +int tolua_Cocos2d_registerScriptHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"CCNode",0,&tolua_err) || + !toluafix_isfunction(tolua_S, 2, "LUA_FUNCTION", 0, &tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Node* node = (Node*)tolua_tousertype(tolua_S,1,0); + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)node, handler, ScriptHandlerMgr::kNodeHandler); + return 0; + } +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_unregisterScriptHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"CCNode",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Node* node = (Node*)tolua_tousertype(tolua_S,1,0); + ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)node, ScriptHandlerMgr::kNodeHandler); + return 0; + } +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_registerScriptTapHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"CCMenuItem",0,&tolua_err) || + !toluafix_isfunction(tolua_S, 2, "LUA_FUNCTION", 0, &tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + MenuItem* menuItem = (MenuItem*)tolua_tousertype(tolua_S,1,0); + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)menuItem, handler, ScriptHandlerMgr::kMenuClickHandler); + return 0; + } +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_unregisterScriptTapHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"CCMenuItem",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + MenuItem* menuItem = (MenuItem*)tolua_tousertype(tolua_S,1,0); + ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)menuItem, ScriptHandlerMgr::kMenuClickHandler); + return 0; + } +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_registerScriptTouchHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) || + !tolua_isboolean(tolua_S,3,1,&tolua_err) || + !tolua_isnumber(tolua_S,4,1,&tolua_err) || + !tolua_isboolean(tolua_S,5,1,&tolua_err) || + !tolua_isnoobj(tolua_S,6,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Layer* self = (Layer*) tolua_tousertype(tolua_S,1,0); + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); + bool isMultiTouches = ((bool) tolua_toboolean(tolua_S,3,false)); + int priority = ((int) tolua_tonumber(tolua_S,4,0)); + bool swallowsTouches = ((bool) tolua_toboolean(tolua_S,5,false)); + ccTouchesMode touchesMode = kTouchesAllAtOnce; + if (!isMultiTouches) + touchesMode = kTouchesOneByOne; + self->setTouchMode(touchesMode); + self->setTouchPriority(priority); + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::kTouchesHandler); + } + return 0; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptTouchHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_unregisterScriptTouchHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Layer* layer = (Layer*) tolua_tousertype(tolua_S,1,0); + ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)layer, ScriptHandlerMgr::kTouchesHandler); + return 0; + } +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptTouchHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_registerScriptKeypadHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Layer* layer = (Layer*) tolua_tousertype(tolua_S,1,0); + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)layer, handler, ScriptHandlerMgr::kKeypadHandler); + } + return 0; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptKeypadHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_unregisterScriptKeypadHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Layer* layer = (Layer*) tolua_tousertype(tolua_S,1,0); + + ScriptHandlerMgr::getInstance()->removeObjectHandler(layer, ScriptHandlerMgr::kKeypadHandler); + } + return 0; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'unregisterScriptKeypadHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_registerScriptAccelerateHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Layer* layer = (Layer*) tolua_tousertype(tolua_S,1,0); + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)layer, handler, ScriptHandlerMgr::kAccelerometerHandler); + } + return 0; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptAccelerateHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_unregisterScriptAccelerateHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"CCLayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Layer* layer = (Layer*) tolua_tousertype(tolua_S,1,0); + ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)layer, ScriptHandlerMgr::kAccelerometerHandler); + } + return 0; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'unregisterScriptAccelerateHandler'.",&tolua_err); + return 0; +#endif +} + +int tolua_Cocos2d_registerControlEventHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"CCControl",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) || + !tolua_isnumber(tolua_S, 3, 0, &tolua_err)|| + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Control* control = (Control*) tolua_tousertype(tolua_S,1,0); + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); + int controlevent = ((ControlEvent) (int) tolua_tonumber(tolua_S,3,0)); + for (int i = 0; i < kControlEventTotalNumber; i++) + { + if ((controlevent & (1 << i))) + { + int handlerevent = ScriptHandlerMgr::kControlTouchDownHandler + i; + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)control, handler, handlerevent); + break; + } + } + } + return 0; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerControlEventHandler'.",&tolua_err); + return 0; +#endif +} +int tolua_Cocos2d_unregisterControlEventHandler00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"CCControl",0,&tolua_err) || + !tolua_isnumber(tolua_S, 2, 0, &tolua_err)|| + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Control* control = (Control*) tolua_tousertype(tolua_S,1,0); + int handlerEvent = (int)tolua_tonumber(tolua_S,2,0); + ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)control,handlerEvent); + } + return 0; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerControlEventHandler'.",&tolua_err); + return 0; +#endif +} + +static void tolua_reg_script_handler_mgr_type(lua_State* tolua_S) +{ + tolua_usertype(tolua_S, "CCCallFunc"); + tolua_usertype(tolua_S, "ScheduleHandlerDelegate"); + tolua_usertype(tolua_S, "ScriptHandlerMgr"); +} + +/* method: create of class LuaCallFunc */ +#ifndef TOLUA_DISABLE_tolua_Cocos2d_LuaCallFunc_create00 +static int tolua_Cocos2d_LuaCallFunc_create00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"CCCallFunc",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + LUA_FUNCTION funcID = ( toluafix_ref_function(tolua_S,2,0)); + { + LuaCallFunc* tolua_ret = (LuaCallFunc*) LuaCallFunc::create(funcID); + int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; + int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"CCCallFunc"); + } + } + return 1; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: getInstance of class ScriptHandlerMgr */ +#ifndef TOLUA_DISABLE_tolua_Cocos2d_ScriptHandlerMgr_getInstance00 +static int tolua_Cocos2d_ScriptHandlerMgr_getInstance00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!tolua_isusertable(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) ) + goto tolua_lerror; + else +#endif + { + ScriptHandlerMgr* tolua_ret = (ScriptHandlerMgr*) ScriptHandlerMgr::getInstance(); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"ScriptHandlerMgr"); + } + return 1; +#ifndef TOLUA_RELEASE +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'getInstance'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + + +TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S) +{ + tolua_open(tolua_S); + tolua_reg_script_handler_mgr_type(tolua_S); + tolua_module(tolua_S, NULL,0); + tolua_beginmodule(tolua_S, NULL); + tolua_cclass(tolua_S, "CCCallFunc", "CCCallFunc","CCActionInstant",NULL); + tolua_beginmodule(tolua_S, "CCCallFunc"); + tolua_function(tolua_S, "create", tolua_Cocos2d_LuaCallFunc_create00); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"ScriptHandlerMgr","ScriptHandlerMgr","",NULL); + tolua_beginmodule(tolua_S, "ScriptHandlerMgr"); + tolua_constant(tolua_S,"kNormalHandler",ScriptHandlerMgr::kNodeHandler); + tolua_constant(tolua_S,"kMenuClickHandler",ScriptHandlerMgr::kMenuClickHandler); + tolua_constant(tolua_S,"kNotificationHandler",ScriptHandlerMgr::kNotificationHandler); + tolua_constant(tolua_S,"kCallFuncHandler",ScriptHandlerMgr::kCallFuncHandler); + tolua_constant(tolua_S,"kScheduleHandler",ScriptHandlerMgr::kScheduleHandler); + tolua_constant(tolua_S,"kTouchesHandler",ScriptHandlerMgr::kTouchesHandler); + tolua_constant(tolua_S,"kKeypadHandler",ScriptHandlerMgr::kKeypadHandler); + tolua_constant(tolua_S,"kAccelerometerHandler",ScriptHandlerMgr::kAccelerometerHandler); + tolua_constant(tolua_S,"kControlTouchDownHandler",ScriptHandlerMgr::kControlTouchDownHandler); + tolua_constant(tolua_S,"kControlTouchDragInsideHandler",ScriptHandlerMgr::kControlTouchDragInsideHandler); + tolua_constant(tolua_S,"kControlTouchDragOutsideHandler",ScriptHandlerMgr::kControlTouchDragOutsideHandler); + tolua_constant(tolua_S,"kControlTouchDragEnterHandler",ScriptHandlerMgr::kControlTouchDragEnterHandler); + tolua_constant(tolua_S,"kControlTouchDragExitHandler",ScriptHandlerMgr::kControlTouchDragExitHandler); + tolua_constant(tolua_S,"kControlTouchUpInsideHandler",ScriptHandlerMgr::kControlTouchUpInsideHandler); + tolua_constant(tolua_S,"kControlTouchUpOutsideHandler",ScriptHandlerMgr::kControlTouchUpOutsideHandler); + tolua_constant(tolua_S,"kControlTouchCancelHandler",ScriptHandlerMgr::kControlTouchCancelHandler); + tolua_constant(tolua_S,"kControlValueChangedHandler",ScriptHandlerMgr::kControlValueChangedHandler); + tolua_function(tolua_S, "getInstance", tolua_Cocos2d_ScriptHandlerMgr_getInstance00); + tolua_endmodule(tolua_S); + tolua_endmodule(tolua_S); + return 1; +} diff --git a/scripting/lua/cocos2dx_support/LuaScriptHandlerMgr.h b/scripting/lua/cocos2dx_support/LuaScriptHandlerMgr.h new file mode 100644 index 0000000000..a64d96d221 --- /dev/null +++ b/scripting/lua/cocos2dx_support/LuaScriptHandlerMgr.h @@ -0,0 +1,124 @@ +#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 +#include + +NS_CC_BEGIN + +class ScheduleHandlerDelegate; + +typedef int EventType; +typedef int EventHandler; +typedef std::pair PairEventHandler; +typedef std::vector VecEventHandlers; +typedef std::map MapObjectHandlers; +typedef std::vector VecShedule; +typedef std::map 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; +}; + +class LuaCallFunc:public cocos2d::CallFuncN +{ +public: + LuaCallFunc() + {} + virtual ~LuaCallFunc() + {} + + static LuaCallFunc * create(int nHandler); + virtual void execute(); + virtual LuaCallFunc* clone() const; +}; + +class ScriptHandlerMgr +{ +public: + ScriptHandlerMgr(void); + virtual ~ScriptHandlerMgr(void); + static ScriptHandlerMgr* getInstance(void); + + void addObjectHandler(void* object,int handler,int eventType); + void removeObjectHandler(void* object,int eventType); + int getObjectHandler(void* object,int eventType); + void removeObjectAllHandlers(void* object); + + enum HandlerEventType + { + kNodeHandler = 0, + kMenuClickHandler, + kNotificationHandler, + kCallFuncHandler, + kScheduleHandler, + kTouchesHandler, + kKeypadHandler, + kAccelerometerHandler, + + kControlTouchDownHandler, + kControlTouchDragInsideHandler, + kControlTouchDragOutsideHandler, + kControlTouchDragEnterHandler, + kControlTouchDragExitHandler, + kControlTouchUpInsideHandler, + kControlTouchUpOutsideHandler, + kControlTouchCancelHandler, + kControlValueChangedHandler, + }; + + +private: + void init(void); + static ScriptHandlerMgr* _scriptHandlerMgr; + MapObjectHandlers _mapObjectHandlers; +}; + +NS_CC_END + +TOLUA_API int tolua_Cocos2d_registerScriptHandler00(lua_State* tolua_S); +TOLUA_API int tolua_Cocos2d_unregisterScriptHandler00(lua_State* tolua_S); + +TOLUA_API int tolua_Cocos2d_registerScriptTapHandler00(lua_State* tolua_S); +TOLUA_API int tolua_Cocos2d_unregisterScriptTapHandler00(lua_State* tolua_S); + +TOLUA_API int tolua_Cocos2d_registerScriptTouchHandler00(lua_State* tolua_S); +TOLUA_API int tolua_Cocos2d_unregisterScriptTouchHandler00(lua_State* tolua_S); + +TOLUA_API int tolua_Cocos2d_registerScriptKeypadHandler00(lua_State* tolua_S); +TOLUA_API int tolua_Cocos2d_unregisterScriptKeypadHandler00(lua_State* tolua_S); + +TOLUA_API int tolua_Cocos2d_registerScriptAccelerateHandler00(lua_State* tolua_S); +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); + +TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S); + +#endif //__LUA_SCRIPT_HANDLER_MGR_H__ diff --git a/scripting/lua/proj.android/Android.mk b/scripting/lua/proj.android/Android.mk index 6d23dc0806..34ee333ad3 100644 --- a/scripting/lua/proj.android/Android.mk +++ b/scripting/lua/proj.android/Android.mk @@ -16,6 +16,7 @@ LOCAL_SRC_FILES := ../cocos2dx_support/CCLuaBridge.cpp \ ../cocos2dx_support/Lua_web_socket.cpp \ ../cocos2dx_support/LuaOpengl.cpp \ ../cocos2dx_support/LuaScrollView.cpp \ + ../cocos2dx_support/LuaScriptHandlerMgr.cpp \ ../tolua/tolua_event.c \ ../tolua/tolua_is.c \ ../tolua/tolua_map.c \ diff --git a/scripting/lua/proj.emscripten/Makefile b/scripting/lua/proj.emscripten/Makefile index 815417cd21..794d1ee6bb 100644 --- a/scripting/lua/proj.emscripten/Makefile +++ b/scripting/lua/proj.emscripten/Makefile @@ -48,7 +48,8 @@ SOURCES = ../lua/lapi.o \ ../cocos2dx_support/CCBProxy.cpp \ ../cocos2dx_support/Lua_extensions_CCB.cpp \ ../cocos2dx_support/LuaOpengl.cpp \ - ../cocos2dx_support/LuaScrollView.cpp + ../cocos2dx_support/LuaScrollView.cpp \ + ../cocos2dx_support/LuaScriptHandlerMgr.cpp include ../../../cocos2dx/proj.emscripten/cocos2dx.mk diff --git a/scripting/lua/proj.linux/Makefile b/scripting/lua/proj.linux/Makefile index 78403e5296..d1d9149d53 100644 --- a/scripting/lua/proj.linux/Makefile +++ b/scripting/lua/proj.linux/Makefile @@ -48,7 +48,8 @@ SOURCES = ../lua/lapi.o \ ../cocos2dx_support/CCBProxy.cpp \ ../cocos2dx_support/Lua_extensions_CCB.cpp \ ../cocos2dx_support/LuaOpengl.cpp \ - ../cocos2dx_support/LuaScrollView.cpp + ../cocos2dx_support/LuaScrollView.cpp \ + ../cocos2dx_support/LuaScriptHandlerMgr.cpp include ../../../cocos2dx/proj.linux/cocos2dx.mk diff --git a/scripting/lua/proj.marmalade/lua.mkf b/scripting/lua/proj.marmalade/lua.mkf index 8878021557..b4e3a26f30 100644 --- a/scripting/lua/proj.marmalade/lua.mkf +++ b/scripting/lua/proj.marmalade/lua.mkf @@ -42,4 +42,6 @@ files "LuaOpengl.h" "LuaScrollView.cpp" "LuaScrollView.h" + "LuaScriptHandlerMgr.cpp" + "LuaScriptHandlerMgr.h" } diff --git a/scripting/lua/proj.win32/liblua.vcxproj b/scripting/lua/proj.win32/liblua.vcxproj index 68973385de..bd49613e75 100644 --- a/scripting/lua/proj.win32/liblua.vcxproj +++ b/scripting/lua/proj.win32/liblua.vcxproj @@ -130,6 +130,7 @@ xcopy /Y /Q "$(ProjectDir)..\luajit\win32\*.*" "$(OutDir)" + @@ -149,6 +150,7 @@ xcopy /Y /Q "$(ProjectDir)..\luajit\win32\*.*" "$(OutDir)" + diff --git a/scripting/lua/proj.win32/liblua.vcxproj.filters b/scripting/lua/proj.win32/liblua.vcxproj.filters index 3234300db0..9a30acb82f 100644 --- a/scripting/lua/proj.win32/liblua.vcxproj.filters +++ b/scripting/lua/proj.win32/liblua.vcxproj.filters @@ -66,6 +66,9 @@ cocos2dx_support + + cocos2dx_support + @@ -122,5 +125,8 @@ cocos2dx_support + + cocos2dx_support + \ No newline at end of file diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index f22ec5e205..85b0435fc6 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -43,9 +43,9 @@ skip = Node::[^setPosition$ getGrid setGLServerState description getUserObject . ParticleBatchNode::[getBlendFunc setBlendFunc], LayerColor::[getBlendFunc setBlendFunc], ParticleSystem::[getBlendFunc setBlendFunc], - DrawNode::[getBlendFunc setBlendFunc drawPolygon], + DrawNode::[getBlendFunc setBlendFunc drawPolygon listenBackToForeground], Director::[getAccelerometer (g|s)et.*Dispatcher getOpenGLView getProjection getClassTypeInfo], - Layer.*::[didAccelerate (g|s)etBlendFunc keyPressed keyReleased unregisterScriptKeypadHandler], + Layer.*::[didAccelerate (g|s)etBlendFunc keyPressed keyReleased], Menu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns], MenuItem.*::[create setCallback initWithCallback], Copying::[*], diff --git a/tools/tolua++/CCAction.pkg b/tools/tolua++/CCAction.pkg index 0104a2b1b0..6dd2c41a7d 100644 --- a/tools/tolua++/CCAction.pkg +++ b/tools/tolua++/CCAction.pkg @@ -295,13 +295,3 @@ class CCPlace : public CCActionInstant // { static CCPlace* create(CCPoint pos); }; - -class CCCallFunc : public CCActionInstant -{ - static CCCallFunc* create(LUA_FUNCTION funcID); -}; - -class CCCallFuncN : public CCCallFunc -{ - static CCCallFuncN* create(LUA_FUNCTION funcID); -}; diff --git a/tools/tolua++/CCControl.pkg b/tools/tolua++/CCControl.pkg index 829a3fcbcc..bb749d8334 100644 --- a/tools/tolua++/CCControl.pkg +++ b/tools/tolua++/CCControl.pkg @@ -59,7 +59,4 @@ class CCControl:public CCLayerRGBA virtual CCPoint getTouchLocation(CCTouch* touch); virtual bool isTouchInside(CCTouch * touch); - - void addHandleOfControlEvent(LUA_FUNCTION nFunID,CCControlEvent controlEvents); - void removeHandleOfControlEvent(CCControlEvent controlEvents); }; diff --git a/tools/tolua++/CCLayer.pkg b/tools/tolua++/CCLayer.pkg index ad24591efc..62e8233b61 100644 --- a/tools/tolua++/CCLayer.pkg +++ b/tools/tolua++/CCLayer.pkg @@ -19,18 +19,6 @@ class CCLayer : public CCNode virtual void setTouchPriority(int priority); virtual int getTouchPriority() const; - void registerScriptTouchHandler(LUA_FUNCTION nHandler, - bool bIsMultiTouches = false, - int nPriority = 0, - bool bSwallowsTouches = false); - void unregisterScriptTouchHandler(); - - void registerScriptKeypadHandler(LUA_FUNCTION nHandler); - void unregisterScriptKeypadHandler(void); - - void registerScriptAccelerateHandler(LUA_FUNCTION nHandler); - void unregisterScriptAccelerateHandler(void); - static CCLayer *create(void); }; diff --git a/tools/tolua++/CCMenuItem.pkg b/tools/tolua++/CCMenuItem.pkg index cca5f247ad..577cc379dc 100644 --- a/tools/tolua++/CCMenuItem.pkg +++ b/tools/tolua++/CCMenuItem.pkg @@ -8,9 +8,6 @@ class CCMenuItem : public CCNodeRGBA void setEnabled(bool enabled); bool isEnabled() const; bool isSelected() const; - - void registerScriptTapHandler(LUA_FUNCTION funcID); - void unregisterScriptTapHandler(void); }; class CCMenuItemLabel : public CCMenuItem diff --git a/tools/tolua++/CCNode.pkg b/tools/tolua++/CCNode.pkg index 7490742f7f..71e9628c74 100644 --- a/tools/tolua++/CCNode.pkg +++ b/tools/tolua++/CCNode.pkg @@ -117,9 +117,6 @@ class CCNode : public CCObject void scheduleUpdateWithPriorityLua(LUA_FUNCTION nHandler, int priority); void unscheduleUpdate(void); - void registerScriptHandler(LUA_FUNCTION funcID); - void unregisterScriptHandler(void); - static CCNode * create(void); }; diff --git a/tools/tolua++/basic.lua b/tools/tolua++/basic.lua index e818ca73e2..8529054c90 100644 --- a/tools/tolua++/basic.lua +++ b/tools/tolua++/basic.lua @@ -11,8 +11,6 @@ local CCObjectTypes = { "CCImage", "CCFiniteTimeAction", "CCActionInstant", - "CCCallFunc", - "CCCallFuncN", "CCFlipX", "CCFlipY", "CCHide",