diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index f4d07e01b4..5e35070136 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -4,8 +4,9 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2011 Zynga Inc. Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org +Copyright (c) 2021 Bytedance Inc. + +https://adxe.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -53,14 +54,6 @@ NS_CC_BEGIN // Layer Layer::Layer() -: _touchEnabled(false) -, _accelerometerEnabled(false) -, _keyboardEnabled(false) -, _touchListener(nullptr) -, _keyboardListener(nullptr) -, _accelerationListener(nullptr) -, _touchMode(Touch::DispatchMode::ALL_AT_ONCE) -, _swallowsTouches(true) { _ignoreAnchorPointForPosition = true; setAnchorPoint(Vec2(0.5f, 0.5f)); @@ -92,145 +85,6 @@ Layer *Layer::create() } } -int Layer::executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch, Event* event) -{ -#if CC_ENABLE_SCRIPT_BINDING - TouchScriptData data(eventType, this, touch, event); - ScriptEvent scriptEvent(kTouchEvent, &data); - return ScriptEngineManager::sendEventToLua(scriptEvent); -#else - CC_UNUSED_PARAM(eventType); - CC_UNUSED_PARAM(touch); - CC_UNUSED_PARAM(event); - return 0; -#endif -} - -int Layer::executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector& touches, Event* event) -{ -#if CC_ENABLE_SCRIPT_BINDING - TouchesScriptData data(eventType, this, touches, event); - ScriptEvent scriptEvent(kTouchesEvent, &data); - return ScriptEngineManager::sendEventToLua(scriptEvent); -#else - CC_UNUSED_PARAM(eventType); - CC_UNUSED_PARAM(touches); - CC_UNUSED_PARAM(event); - return 0; -#endif -} - - -void Layer::onAcceleration(Acceleration* acc, Event* /*unused_event*/) -{ -#if CC_ENABLE_SCRIPT_BINDING - BasicScriptData data(this,(void*)acc); - ScriptEvent event(kAccelerometerEvent,&data); - ScriptEngineManager::sendEventToLua(event); -#else - CC_UNUSED_PARAM(acc); -#endif -} - -void Layer::onKeyPressed(EventKeyboard::KeyCode /*keyCode*/, Event* /*unused_event*/) -{ -} - -void Layer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* /*unused_event*/) -{ -#if CC_ENABLE_SCRIPT_BINDING - KeypadScriptData data(keyCode, this); - ScriptEvent event(kKeypadEvent,&data); - ScriptEngineManager::sendEventToLua(event); -#else - CC_UNUSED_PARAM(keyCode); -#endif -} - -/// Callbacks - -bool Layer::onTouchBegan(Touch *touch, Event *event) -{ -#if CC_ENABLE_SCRIPT_BINDING - return executeScriptTouchHandler(EventTouch::EventCode::BEGAN, touch, event) == 0 ? false : true; -#else - CC_UNUSED_PARAM(touch); - CC_UNUSED_PARAM(event); - CCASSERT(false, "Layer#ccTouchBegan override me"); - return true; -#endif -} - -void Layer::onTouchMoved(Touch *touch, Event *event) -{ -#if CC_ENABLE_SCRIPT_BINDING - executeScriptTouchHandler(EventTouch::EventCode::MOVED, touch, event); -#else - CC_UNUSED_PARAM(touch); - CC_UNUSED_PARAM(event); -#endif -} - -void Layer::onTouchEnded(Touch *touch, Event *event) -{ -#if CC_ENABLE_SCRIPT_BINDING - executeScriptTouchHandler(EventTouch::EventCode::ENDED, touch, event); -#else - CC_UNUSED_PARAM(touch); - CC_UNUSED_PARAM(event); -#endif -} - -void Layer::onTouchCancelled(Touch *touch, Event *event) -{ -#if CC_ENABLE_SCRIPT_BINDING - executeScriptTouchHandler(EventTouch::EventCode::CANCELLED, touch, event); -#else - CC_UNUSED_PARAM(touch); - CC_UNUSED_PARAM(event); -#endif -} - -void Layer::onTouchesBegan(const std::vector& touches, Event *event) -{ -#if CC_ENABLE_SCRIPT_BINDING - executeScriptTouchesHandler(EventTouch::EventCode::BEGAN, touches, event); -#else - CC_UNUSED_PARAM(touches); - CC_UNUSED_PARAM(event); -#endif -} - -void Layer::onTouchesMoved(const std::vector& touches, Event *event) -{ -#if CC_ENABLE_SCRIPT_BINDING - executeScriptTouchesHandler(EventTouch::EventCode::MOVED, touches, event); -#else - CC_UNUSED_PARAM(touches); - CC_UNUSED_PARAM(event); -#endif -} - -void Layer::onTouchesEnded(const std::vector& touches, Event *event) -{ -#if CC_ENABLE_SCRIPT_BINDING - executeScriptTouchesHandler(EventTouch::EventCode::ENDED, touches, event); -#else - CC_UNUSED_PARAM(touches); - CC_UNUSED_PARAM(event); -#endif -} - -void Layer::onTouchesCancelled(const std::vector& touches, Event *event) -{ -#if CC_ENABLE_SCRIPT_BINDING - executeScriptTouchesHandler(EventTouch::EventCode::CANCELLED, touches, event); -#else - CC_UNUSED_PARAM(touches); - CC_UNUSED_PARAM(event); -#endif -} - std::string Layer::getDescription() const { return StringUtils::format("", _tag); diff --git a/cocos/2d/CCLayer.h b/cocos/2d/CCLayer.h index 7ff96b2122..22ee35064f 100644 --- a/cocos/2d/CCLayer.h +++ b/cocos/2d/CCLayer.h @@ -4,8 +4,9 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2011 Zynga Inc. Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2021 Bytedance Inc. -http://www.cocos2d-x.org +https://adxe.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -68,95 +69,6 @@ public: */ static Layer *create(); - /* Callback function should not be deprecated, it will generate lots of warnings. - Since 'setTouchEnabled' was deprecated, it will make warnings if developer overrides onTouchXXX and invokes setTouchEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX. - */ - /** Callback function for touch began. - * - * @param touch Touch information. - * @param unused_event Event information. - * @return if return false, onTouchMoved, onTouchEnded, onTouchCancelled will never called. - * @js NA - */ - virtual bool onTouchBegan(Touch *touch, Event *unused_event); - /** Callback function for touch moved. - * - * @param touch Touch information. - * @param unused_event Event information. - * @js NA - */ - virtual void onTouchMoved(Touch *touch, Event *unused_event); - /** Callback function for touch ended. - * - * @param touch Touch information. - * @param unused_event Event information. - * @js NA - */ - virtual void onTouchEnded(Touch *touch, Event *unused_event); - /** Callback function for touch cancelled. - * - * @param touch Touch information. - * @param unused_event Event information. - * @js NA - */ - virtual void onTouchCancelled(Touch *touch, Event *unused_event); - - /** Callback function for multiple touches began. - * - * @param touches Touches information. - * @param unused_event Event information. - * @js NA - */ - virtual void onTouchesBegan(const std::vector& touches, Event *unused_event); - /** Callback function for multiple touches moved. - * - * @param touches Touches information. - * @param unused_event Event information. - * @js NA - */ - virtual void onTouchesMoved(const std::vector& touches, Event *unused_event); - /** Callback function for multiple touches ended. - * - * @param touches Touches information. - * @param unused_event Event information. - * @js NA - */ - virtual void onTouchesEnded(const std::vector& touches, Event *unused_event); - /** Callback function for multiple touches cancelled. - * - * @param touches Touches information. - * @param unused_event Event information. - * @js NA - */ - virtual void onTouchesCancelled(const std::vector&touches, Event *unused_event); - - /* Callback function should not be deprecated, it will generate lots of warnings. - Since 'setAccelerometerEnabled' was deprecated, it will make warnings if developer overrides onAcceleration and invokes setAccelerometerEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX. - */ - /** Callback function for acceleration. - * @param acc Acceleration information. - * @param unused_event Event information. - * @js NA - */ - virtual void onAcceleration(Acceleration* acc, Event* unused_event); - - - /* Callback function should not be deprecated, it will generate lots of warnings. - Since 'setKeyboardEnabled' was deprecated, it will make warnings if developer overrides onKeyXXX and invokes setKeyboardEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX. - */ - /** Callback function for key pressed. - * @param keyCode KeyCode information. - * @param event Event information. - * @js NA - */ - virtual void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event); - /** Callback function for key released. - * @param keyCode KeyCode information. - * @param event Event information. - * @js NA - */ - virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event); - // Overrides virtual std::string getDescription() const override; @@ -166,21 +78,6 @@ CC_CONSTRUCTOR_ACCESS: virtual bool init() override; -protected: - - int executeScriptTouchHandler(EventTouch::EventCode eventType, Touch* touch, Event* event); - int executeScriptTouchesHandler(EventTouch::EventCode eventType, const std::vector& touches, Event* event); - - bool _touchEnabled; - bool _accelerometerEnabled; - bool _keyboardEnabled; - EventListener* _touchListener; - EventListenerKeyboard* _keyboardListener; - EventListenerAcceleration* _accelerationListener; - - Touch::DispatchMode _touchMode; - bool _swallowsTouches; - private: CC_DISALLOW_COPY_AND_ASSIGN(Layer);