diff --git a/CHANGELOG b/CHANGELOG index 1e15fa39d9..8ea5abc716 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -32,6 +32,7 @@ cocos2d-x-3.2 ??? [FIX] UIListView: element position is changed a little when you click and up a list view without move [FIX] UIListView: element will respond to item_end event when end of scrolling a list view [FIX] UIVideo: crash when try to remove videoView(STATE_PLAYBACK_COMPLETED) on android + [FIX] WP8: crash of utils::captureScreen() cocos2d-x-3.2-alpha0 Jun.17 2014 [NEW] Console: add a command to show engine version diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 240bab5f60..a0905817e1 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -861,24 +861,25 @@ void Node::enumerateChildren(const std::string &name, std::function 3 && - name[length-3] == '/' && - name[length-2] == '.' && - name[length-1] == '.') - { - searchFromParent = true; - subStrlength -= 3; - } +// bool searchFromParent = false; +// if (length > 3 && +// name[length-3] == '/' && +// name[length-2] == '.' && +// name[length-1] == '.') +// { +// searchFromParent = true; +// subStrlength -= 3; +// } - // Remove '/', '//' and '/..' if exist + // Remove '/', '//' if exist std::string newName = name.substr(subStrStartPos, subStrlength); // If search from parent, then add * at first to make it match its children, which will do make - if (searchFromParent) - { - newName.insert(0, "[[:alnum:]]+/"); - } +// if (searchFromParent) +// { +// newName.insert(0, "[[:alnum:]]+/"); +// } if (searchFromRoot) { @@ -943,10 +944,14 @@ bool Node::doEnumerate(std::string name, std::function callback) needRecursive = true; } + std::hash h; + size_t hashOfName = h(searchName); bool ret = false; for (const auto& child : _children) { - if(std::regex_match(child->_name, std::regex(searchName))) + // TODO: regular expression support + // Android doesn't support c++ 11 regular expression well, may use external lib + if (hashOfName == child->_hashOfName && searchName.compare(child->_name) == 0) { if (!needRecursive) { diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 0a283154ce..55a26ec113 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -714,20 +714,17 @@ public: virtual Node* getChildByName(const std::string& name) const; /** Search the children of the receiving node to perform processing for nodes which share a name. * - * @param name The name to search for, support c++11 regular expression + * @param name The name to search for * Search syntax options: * `/` : When placed at the start of the search string, this indicates that the search should be performed on the tree's node. * `//`: Can only be placed at the begin of the search string. This indicates that the search should be performed on the tree's node * and be performed recursively across the entire node tree. - * `..`: The search should move up to the node's parent. Can only be placed at the end of string * `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children * * @code * enumerateChildren("/MyName", ...): This searches the root's children and matches any node with the name `MyName`. * enumerateChildren("//MyName", ...): This searches the root's children recursively and matches any node with the name `MyName`. - * enumerateChildren("[[:alnum:]]+", ...): This search string matches every node of its children. * enumerateChildren("/MyName", ...): This searches the node tree and matches the parent node of every node named `MyName`. - * enumerateChildren("A[[:digit:]]", ...): This searches the node's children and returns any child named `A0`, `A1`, ..., `A9` * enumerateChildren("Abby/Normal", ...): This searches the node's grandchildren and returns any node whose name is `Normal` * and whose parent is named `Abby`. * enumerateChildren("//Abby/Normal", ...): This searches the node tree and returns any node whose name is `Normal` and whose diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index da0996719a..5a025b25ec 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -72,19 +72,50 @@ void onCaptureScreen(const std::function& afterC } glPixelStorei(GL_PACK_ALIGNMENT, 1); + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) + // The frame buffer is always created with portrait orientation on WP8. + // So if the current device orientation is landscape, we need to rotate the frame buffer. + auto renderTargetSize = glView->getRenerTargetSize(); + CCASSERT(width * height == static_cast(renderTargetSize.width * renderTargetSize.height), "The frame size is not matched"); + glReadPixels(0, 0, (int)renderTargetSize.width, (int)renderTargetSize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get()); +#else glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get()); +#endif std::shared_ptr flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); }); if (!flippedBuffer) { break; } - + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) + if (width == static_cast(renderTargetSize.width)) + { + // The current device orientation is portrait. + for (int row = 0; row < height; ++row) + { + memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4); + } + } + else + { + // The current device orientation is landscape. + for (int row = 0; row < width; ++row) + { + for (int col = 0; col < height; ++col) + { + *(int*)(flippedBuffer.get() + (height - col - 1) * width * 4 + row * 4) = *(int*)(buffer.get() + row * height * 4 + col * 4); + } + } + } +#else for (int row = 0; row < height; ++row) { memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4); } - +#endif + std::shared_ptr image(new Image); if (image) { diff --git a/cocos/platform/android/ControllerDelegate/.classpath b/cocos/platform/android/ControllerAutoAdapter/.classpath similarity index 100% rename from cocos/platform/android/ControllerDelegate/.classpath rename to cocos/platform/android/ControllerAutoAdapter/.classpath diff --git a/cocos/platform/android/ControllerDelegate/.project b/cocos/platform/android/ControllerAutoAdapter/.project similarity index 95% rename from cocos/platform/android/ControllerDelegate/.project rename to cocos/platform/android/ControllerAutoAdapter/.project index 6711d455fd..c49a037939 100644 --- a/cocos/platform/android/ControllerDelegate/.project +++ b/cocos/platform/android/ControllerAutoAdapter/.project @@ -1,6 +1,6 @@ - libcontrollerdelegate + libControllerAutoAdapter diff --git a/cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs b/cocos/platform/android/ControllerAutoAdapter/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs rename to cocos/platform/android/ControllerAutoAdapter/.settings/org.eclipse.jdt.core.prefs diff --git a/cocos/platform/android/ControllerDelegate/AndroidManifest.xml b/cocos/platform/android/ControllerAutoAdapter/AndroidManifest.xml similarity index 100% rename from cocos/platform/android/ControllerDelegate/AndroidManifest.xml rename to cocos/platform/android/ControllerAutoAdapter/AndroidManifest.xml diff --git a/cocos/platform/android/ControllerDelegate/ant.properties b/cocos/platform/android/ControllerAutoAdapter/ant.properties similarity index 100% rename from cocos/platform/android/ControllerDelegate/ant.properties rename to cocos/platform/android/ControllerAutoAdapter/ant.properties diff --git a/cocos/platform/android/ControllerNibiru/build.xml b/cocos/platform/android/ControllerAutoAdapter/build.xml similarity index 98% rename from cocos/platform/android/ControllerNibiru/build.xml rename to cocos/platform/android/ControllerAutoAdapter/build.xml index 5e73af0ac0..413effd90c 100644 --- a/cocos/platform/android/ControllerNibiru/build.xml +++ b/cocos/platform/android/ControllerAutoAdapter/build.xml @@ -1,5 +1,5 @@ - + - - - - - - - - - - - - - - - - - - - diff --git a/cocos/platform/android/ControllerNibiru/.classpath b/cocos/platform/android/ControllerNibiru/.classpath deleted file mode 100644 index 51769745b2..0000000000 --- a/cocos/platform/android/ControllerNibiru/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/cocos/platform/android/ControllerNibiru/.project b/cocos/platform/android/ControllerNibiru/.project deleted file mode 100644 index c540b70b88..0000000000 --- a/cocos/platform/android/ControllerNibiru/.project +++ /dev/null @@ -1,33 +0,0 @@ - - - libcontrollernibiru - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff --git a/cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs b/cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b080d2ddc8..0000000000 --- a/cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/cocos/platform/android/ControllerNibiru/AndroidManifest.xml b/cocos/platform/android/ControllerNibiru/AndroidManifest.xml deleted file mode 100644 index d1f4a837d8..0000000000 --- a/cocos/platform/android/ControllerNibiru/AndroidManifest.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/cocos/platform/android/ControllerNibiru/ant.properties b/cocos/platform/android/ControllerNibiru/ant.properties deleted file mode 100644 index b0971e891e..0000000000 --- a/cocos/platform/android/ControllerNibiru/ant.properties +++ /dev/null @@ -1,17 +0,0 @@ -# This file is used to override default values used by the Ant build system. -# -# This file must be checked into Version Control Systems, as it is -# integral to the build system of your project. - -# This file is only used by the Ant script. - -# You can use this to override default values such as -# 'source.dir' for the location of your java source folder and -# 'out.dir' for the location of your output folder. - -# You can also use it define how the release builds are signed by declaring -# the following properties: -# 'key.store' for the location of your keystore and -# 'key.alias' for the name of the key to use. -# The password will be asked during the build when you use the 'release' target. - diff --git a/cocos/platform/android/ControllerNibiru/proguard-project.txt b/cocos/platform/android/ControllerNibiru/proguard-project.txt deleted file mode 100644 index f2fe1559a2..0000000000 --- a/cocos/platform/android/ControllerNibiru/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/cocos/platform/android/ControllerNibiru/res/.gitignore b/cocos/platform/android/ControllerNibiru/res/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/cocos/platform/android/ControllerOuya/.classpath b/cocos/platform/android/ControllerOuya/.classpath deleted file mode 100644 index 51769745b2..0000000000 --- a/cocos/platform/android/ControllerOuya/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs b/cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b080d2ddc8..0000000000 --- a/cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/cocos/platform/android/ControllerOuya/AndroidManifest.xml b/cocos/platform/android/ControllerOuya/AndroidManifest.xml deleted file mode 100644 index d1f4a837d8..0000000000 --- a/cocos/platform/android/ControllerOuya/AndroidManifest.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/cocos/platform/android/ControllerOuya/ant.properties b/cocos/platform/android/ControllerOuya/ant.properties deleted file mode 100644 index b0971e891e..0000000000 --- a/cocos/platform/android/ControllerOuya/ant.properties +++ /dev/null @@ -1,17 +0,0 @@ -# This file is used to override default values used by the Ant build system. -# -# This file must be checked into Version Control Systems, as it is -# integral to the build system of your project. - -# This file is only used by the Ant script. - -# You can use this to override default values such as -# 'source.dir' for the location of your java source folder and -# 'out.dir' for the location of your output folder. - -# You can also use it define how the release builds are signed by declaring -# the following properties: -# 'key.store' for the location of your keystore and -# 'key.alias' for the name of the key to use. -# The password will be asked during the build when you use the 'release' target. - diff --git a/cocos/platform/android/ControllerOuya/build.xml b/cocos/platform/android/ControllerOuya/build.xml deleted file mode 100644 index 7fc3634914..0000000000 --- a/cocos/platform/android/ControllerOuya/build.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cocos/platform/android/ControllerOuya/proguard-project.txt b/cocos/platform/android/ControllerOuya/proguard-project.txt deleted file mode 100644 index f2fe1559a2..0000000000 --- a/cocos/platform/android/ControllerOuya/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/cocos/platform/android/ControllerOuya/res/.gitignore b/cocos/platform/android/ControllerOuya/res/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/cocos/platform/android/java/project.properties b/cocos/platform/android/java/project.properties index 732c58e368..88ca83f9d0 100644 --- a/cocos/platform/android/java/project.properties +++ b/cocos/platform/android/java/project.properties @@ -12,5 +12,4 @@ android.library=true # Project target. -target=android-16 -android.library.reference.1=../ControllerDelegate +target=android-10 diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index 265387c29e..78929fb300 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -24,9 +24,6 @@ THE SOFTWARE. package org.cocos2dx.lib; import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener; -import org.cocos2dx.lib.GameControllerDelegate.ControllerEventListener; -import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat; -import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListener; import android.app.Activity; import android.content.Context; @@ -36,15 +33,12 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.os.Message; -import android.view.InputDevice; -import android.view.KeyEvent; -import android.view.MotionEvent; import android.view.ViewGroup; import android.util.Log; import android.widget.FrameLayout; import android.preference.PreferenceManager.OnActivityResultListener; -public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener, InputDeviceListener { +public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener { // =========================================================== // Constants // =========================================================== @@ -59,10 +53,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe private Cocos2dxHandler mHandler; private static Cocos2dxActivity sContext = null; private Cocos2dxVideoHelper mVideoHelper = null; - private InputManagerCompat mInputManager = null; - - protected GameControllerHelper mControllerHelper = null; - protected GameControllerDelegate mControllerDelegate = null; public static Context getContext() { return sContext; @@ -79,45 +69,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe } } - public void setGameControllerInstance(GameControllerDelegate controllerDelegate) { - if (mControllerDelegate != null) { - mControllerDelegate.onDestroy(); - mControllerDelegate = null; - } - mControllerDelegate = controllerDelegate; - mControllerDelegate.setControllerEventListener(mControllerEventListener); - mControllerDelegate.onCreate(this); - } - - public GameControllerDelegate getGameControllerInstance(){ - return mControllerDelegate; - } - - ControllerEventListener mControllerEventListener = new ControllerEventListener() { - - @Override - public void onButtonEvent(String vendorName, int controller, int button, - boolean isPressed, float value, boolean isAnalog) { - GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog); - } - - @Override - public void onAxisEvent(String vendorName, int controller, int axisID, - float value, boolean isAnalog) { - GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog); - } - - @Override - public void onConnected(String vendorName, int controller) { - GameControllerAdapter.onConnected(vendorName, controller); - } - - @Override - public void onDisconnected(String vendorName, int controller) { - GameControllerAdapter.onDisconnected(vendorName, controller); - } - }; - // =========================================================== // Constructors // =========================================================== @@ -137,16 +88,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe if (mVideoHelper == null) { mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout); } - - mInputManager = InputManagerCompat.Factory.getInputManager(this); - mInputManager.registerInputDeviceListener(this, null); - - if (mControllerDelegate != null) { - mControllerDelegate.onCreate(this); - } - if (mControllerHelper == null) { - mControllerHelper = new GameControllerHelper(this); - } } // =========================================================== @@ -157,96 +98,16 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe // Methods for/from SuperClass/Interfaces // =========================================================== - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - boolean handled = false; - if (mControllerDelegate != null) { - handled = mControllerDelegate.dispatchKeyEvent(event); - } - else { - handled = mControllerHelper.dispatchKeyEvent(event); - } - return handled || super.dispatchKeyEvent(event); - } - - @Override - public boolean dispatchGenericMotionEvent(MotionEvent event) { - boolean handled = false; - if (mControllerDelegate != null) { - handled = mControllerDelegate.dispatchGenericMotionEvent(event); - }else { - handled = mControllerHelper.dispatchGenericMotionEvent(event); - } - return handled || super.dispatchGenericMotionEvent(event); - } - - @Override - public void onInputDeviceAdded(int deviceId) { - - Log.d(TAG,"onInputDeviceAdded:" + deviceId); - - InputDevice device = InputDevice.getDevice(deviceId); - int deviceSource = device.getSources(); - - if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) - { - GameControllerAdapter.onConnected("Standard", deviceId); - } - } - /* - * This is an unusual case. Input devices don't typically change, but they - * certainly can --- for example a device may have different modes. We use - * this to make sure that the ship has an up-to-date InputDevice. - * - * @see - * com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener - * #onInputDeviceChanged(int) - */ - @Override - public void onInputDeviceChanged(int deviceId) { - Log.d(TAG,"onInputDeviceChanged:" + deviceId); - } - - /* - * Remove any ship associated with the ID. - * - * @see - * com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener - * #onInputDeviceRemoved(int) - */ - @Override - public void onInputDeviceRemoved(int deviceId) { - Log.d(TAG,"onInputDeviceRemoved:" + deviceId); - - InputDevice device = InputDevice.getDevice(deviceId); - int deviceSource = device.getSources(); - - if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) - { - GameControllerAdapter.onDisconnected("Standard", deviceId); - } - } - @Override protected void onResume() { super.onResume(); Cocos2dxHelper.onResume(); this.mGLSurfaceView.onResume(); - - if (mControllerDelegate != null) { - mControllerDelegate.onResume(); - } } @Override protected void onPause() { - if (mControllerDelegate != null) { - mControllerDelegate.onPause(); - } - super.onPause(); Cocos2dxHelper.onPause(); @@ -255,11 +116,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe @Override protected void onDestroy() { - if (mControllerDelegate != null) { - mControllerDelegate.onDestroy(); - } - mControllerHelper.destrory(); - super.onDestroy(); } diff --git a/cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java b/cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java similarity index 100% rename from cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java rename to cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java diff --git a/cocos/platform/wp8/CCGLView.h b/cocos/platform/wp8/CCGLView.h index 422d003122..e9d7410c6e 100644 --- a/cocos/platform/wp8/CCGLView.h +++ b/cocos/platform/wp8/CCGLView.h @@ -65,6 +65,7 @@ public: const Mat4& getReverseOrientationMatrix () const {return m_reverseOrientationMatrix;}; Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() {return m_orientation;}; + Size getRenerTargetSize() const { return Size(m_width, m_height); } virtual void setIMEKeyboardState(bool bOpen); void ShowKeyboard(Windows::Foundation::Rect r); diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index f33591a81c..cf3f8acc7d 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -1104,7 +1104,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget)const return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2)); } -float Layout::caculateNearestDistance(Widget* baseWidget) +float Layout::calculateNearestDistance(Widget* baseWidget) { float distance = FLT_MAX; @@ -1114,7 +1114,7 @@ float Layout::caculateNearestDistance(Widget* baseWidget) Layout *layout = dynamic_cast(node); int length; if (layout) { - length = layout->caculateNearestDistance(baseWidget); + length = layout->calculateNearestDistance(baseWidget); } else { @@ -1137,7 +1137,7 @@ float Layout::caculateNearestDistance(Widget* baseWidget) return distance; } -float Layout::caculateFarestDistance(cocos2d::ui::Widget *baseWidget) +float Layout::calculateFarestDistance(cocos2d::ui::Widget *baseWidget) { float distance = -FLT_MAX; @@ -1147,7 +1147,7 @@ float Layout::caculateFarestDistance(cocos2d::ui::Widget *baseWidget) Layout *layout = dynamic_cast(node); int length; if (layout) { - length = layout->caculateFarestDistance(baseWidget); + length = layout->calculateFarestDistance(baseWidget); } else { @@ -1194,7 +1194,8 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi float distance = FLT_MAX; int found = 0; - if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT) + if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT || + direction == FocusDirection::DOWN || direction == FocusDirection::UP) { Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget); while (index < count) @@ -1207,7 +1208,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi Layout *layout = dynamic_cast(w); if (layout) { - length = layout->caculateNearestDistance(baseWidget); + length = layout->calculateNearestDistance(baseWidget); } else { @@ -1225,39 +1226,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi return found; } - index = 0; - found = 0; - distance = FLT_MAX; - if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) { - Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget); - while (index < count) - { - Widget *w = dynamic_cast(this->getChildren().at(index)); - if (w && w->isFocusEnabled()) - { - Vec2 wPosition = this->getWorldCenterPoint(w); - float length; - Layout *layout = dynamic_cast(w); - if (layout) - { - length = layout->caculateNearestDistance(baseWidget); - } - else - { - length = (wPosition - widgetPosition).getLength(); - } - - if (length < distance) - { - found = index; - distance = length; - } - - } - index++; - } - return found; - } + CCASSERT(0, "invalid focus direction!!!"); return 0; } @@ -1273,7 +1242,8 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi float distance = -FLT_MAX; int found = 0; - if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT) + if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT + || direction == FocusDirection::DOWN || direction == FocusDirection::UP) { Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget); while (index < count) @@ -1286,7 +1256,7 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi Layout *layout = dynamic_cast(w); if (layout) { - length = layout->caculateFarestDistance(baseWidget); + length = layout->calculateFarestDistance(baseWidget); } else { @@ -1304,39 +1274,6 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi return found; } - index = 0; - found = 0; - distance = -FLT_MAX; - if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) { - Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget); - while (index < count) - { - Widget *w = dynamic_cast(this->getChildren().at(index)); - if (w && w->isFocusEnabled()) - { - Vec2 wPosition = this->getWorldCenterPoint(w); - float length; - Layout *layout = dynamic_cast(w); - if (layout) - { - length = layout->caculateFarestDistance(baseWidget); - } - else - { - length = (wPosition - widgetPosition).getLength(); - } - - if (length > distance) - { - found = index; - distance = length; - } - - } - index++; - } - return found; - } CCASSERT(0, "invalid focus direction!!!"); return 0; } @@ -1368,6 +1305,9 @@ Widget *Layout::findFirstNonLayoutWidget() Layout* layout = dynamic_cast(node); if (layout) { widget = layout->findFirstNonLayoutWidget(); + if (widget != nullptr) { + return widget; + } } else{ Widget *w = dynamic_cast(node); diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h index 2278e64564..e2c9798d37 100644 --- a/cocos/ui/UILayout.h +++ b/cocos/ui/UILayout.h @@ -376,7 +376,7 @@ protected: *@param the base widget which will be used to caculate the distance between the layout's children and itself *@return return the nearest distance between the baseWidget and the layout's children */ - float caculateNearestDistance(Widget* baseWidget); + float calculateNearestDistance(Widget* baseWidget); /** * caculate the farest distance between the baseWidget and the children of the layout @@ -384,7 +384,7 @@ protected: *@return return the farest distance between the baseWidget and the layout's children */ - float caculateFarestDistance(Widget* baseWidget); + float calculateFarestDistance(Widget* baseWidget); /** * when a layout pass the focus to it's child, use this method to determine which algorithm to use, nearest or farest distance algorithm or not diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index c39bed7595..e84a7ed3c1 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -747,38 +747,36 @@ "cocos/platform/android/CCGLView.h", "cocos/platform/android/CCPlatformDefine.h", "cocos/platform/android/CCStdC.h", - "cocos/platform/android/ControllerDelegate/.classpath", - "cocos/platform/android/ControllerDelegate/.project", - "cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs", - "cocos/platform/android/ControllerDelegate/AndroidManifest.xml", - "cocos/platform/android/ControllerDelegate/ant.properties", - "cocos/platform/android/ControllerDelegate/build.xml", - "cocos/platform/android/ControllerDelegate/proguard-project.txt", - "cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java", - "cocos/platform/android/ControllerMoga/.classpath", - "cocos/platform/android/ControllerMoga/.project", - "cocos/platform/android/ControllerMoga/.settings/org.eclipse.jdt.core.prefs", - "cocos/platform/android/ControllerMoga/AndroidManifest.xml", - "cocos/platform/android/ControllerMoga/ant.properties", - "cocos/platform/android/ControllerMoga/build.xml", - "cocos/platform/android/ControllerMoga/proguard-project.txt", - "cocos/platform/android/ControllerMoga/src/org/cocos2dx/lib/GameControllerMoga.java", - "cocos/platform/android/ControllerNibiru/.classpath", - "cocos/platform/android/ControllerNibiru/.project", - "cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs", - "cocos/platform/android/ControllerNibiru/AndroidManifest.xml", - "cocos/platform/android/ControllerNibiru/ant.properties", - "cocos/platform/android/ControllerNibiru/build.xml", - "cocos/platform/android/ControllerNibiru/proguard-project.txt", - "cocos/platform/android/ControllerNibiru/src/org/cocos2dx/lib/GameControllerNibiru.java", - "cocos/platform/android/ControllerOuya/.classpath", - "cocos/platform/android/ControllerOuya/.project", - "cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs", - "cocos/platform/android/ControllerOuya/AndroidManifest.xml", - "cocos/platform/android/ControllerOuya/ant.properties", - "cocos/platform/android/ControllerOuya/build.xml", - "cocos/platform/android/ControllerOuya/proguard-project.txt", - "cocos/platform/android/ControllerOuya/src/org/cocos2dx/lib/GameControllerOuya.java", + "cocos/platform/android/ControllerAutoAdapter/.classpath", + "cocos/platform/android/ControllerAutoAdapter/.project", + "cocos/platform/android/ControllerAutoAdapter/.settings/org.eclipse.jdt.core.prefs", + "cocos/platform/android/ControllerAutoAdapter/AndroidManifest.xml", + "cocos/platform/android/ControllerAutoAdapter/ant.properties", + "cocos/platform/android/ControllerAutoAdapter/build.xml", + "cocos/platform/android/ControllerAutoAdapter/lint.xml", + "cocos/platform/android/ControllerAutoAdapter/proguard-project.txt", + "cocos/platform/android/ControllerAutoAdapter/project.properties", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/GameControllerActivity.java", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/GameControllerHelper.java", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java", + "cocos/platform/android/ControllerManualAdapter/.classpath", + "cocos/platform/android/ControllerManualAdapter/.project", + "cocos/platform/android/ControllerManualAdapter/.settings/org.eclipse.jdt.core.prefs", + "cocos/platform/android/ControllerManualAdapter/AndroidManifest.xml", + "cocos/platform/android/ControllerManualAdapter/ant.properties", + "cocos/platform/android/ControllerManualAdapter/build.xml", + "cocos/platform/android/ControllerManualAdapter/lint.xml", + "cocos/platform/android/ControllerManualAdapter/proguard-project.txt", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java", "cocos/platform/android/java/.classpath", "cocos/platform/android/java/.project", "cocos/platform/android/java/.settings/org.eclipse.jdt.core.prefs", @@ -807,11 +805,8 @@ "cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java", "cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java", "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerAdapter.java", - "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerHelper.java", + "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java", "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerUtils.java", - "cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java", - "cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java", - "cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java", "cocos/platform/android/javaactivity.cpp", "cocos/platform/android/jni/DPIJni.cpp", "cocos/platform/android/jni/DPIJni.h", diff --git a/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp b/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp index fffa01f9b1..3b27fc36f0 100644 --- a/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp +++ b/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp @@ -1269,28 +1269,28 @@ void NodeNameTest::onEnter() // enumerateChildren() // name = regular expression int i = 0; - parent = Node::create(); - for (int i = 0; i < 100; ++i) - { - auto node = Node::create(); - sprintf(name, "node%d", i); - node->setName(name); - parent->addChild(node); - } - - i = 0; - parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool { - ++i; - return false; - }); - CCAssert(i == 100, ""); - - i = 0; - parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool { - ++i; - return true; - }); - CCAssert(i == 1, ""); +// parent = Node::create(); +// for (int i = 0; i < 100; ++i) +// { +// auto node = Node::create(); +// sprintf(name, "node%d", i); +// node->setName(name); +// parent->addChild(node); +// } +// +// i = 0; +// parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool { +// ++i; +// return false; +// }); +// CCAssert(i == 100, ""); +// +// i = 0; +// parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool { +// ++i; +// return true; +// }); +// CCAssert(i == 1, ""); // enumerateChildren @@ -1326,89 +1326,119 @@ void NodeNameTest::onEnter() }); CCAssert(i == 1, ""); - i = 0; - parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool { - ++i; - return false; - }); - CCAssert(i == 10000, ""); - - i = 0; - parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool { - ++i; - return true; - }); - CCAssert(i == 1, ""); - - // search from parent - // name is xxx/.. - i = 0; - parent->enumerateChildren("node/..", [&i](Node* node) -> bool { - ++i; - return true; - }); - CCAssert(i == 1, ""); - - i = 0; - parent->enumerateChildren("node/..", [&i](Node* node) -> bool { - ++i; - return false; - }); - CCAssert(i == 10000, ""); - - // name = /xxx : search from root + // search from root parent = getScene(); - for (int j = 0; j < 100; j++) + for (int i = 0; i < 100; ++i) { auto node = Node::create(); - sprintf(name, "node%d", j); - node->setName(name); + node->setName("node"); parent->addChild(node); - for (int k = 0; k < 100; ++k) + for (int j = 0; j < 100; ++j) { auto child = Node::create(); - sprintf(name, "node%d", k); - child->setName(name); + child->setName("child"); node->addChild(child); } } i = 0; - enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool { + parent->enumerateChildren("/node", [&i](Node* node) -> bool { ++i; return false; }); CCAssert(i == 100, ""); i = 0; - enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool { - ++i; - return true; - }); - CCAssert(i == 1, ""); - - i = 0; - enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool { - ++i; - return false; - }); - CCAssert(i == 10100, ""); // 10000(children) + 100(parent) - - i = 0; - enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool { - ++i; - return true; - }); - CCAssert(i == 1, ""); - - i = 0; - enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool { + parent->enumerateChildren("//child", [&i](Node* node) -> bool { ++i; return false; }); CCAssert(i == 10000, ""); +// i = 0; +// parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool { +// ++i; +// return false; +// }); +// CCAssert(i == 10000, ""); +// +// i = 0; +// parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool { +// ++i; +// return true; +// }); +// CCAssert(i == 1, ""); + + // search from parent + // name is xxx/.. +// i = 0; +// parent->enumerateChildren("node/..", [&i](Node* node) -> bool { +// ++i; +// return true; +// }); +// CCAssert(i == 1, ""); +// +// i = 0; +// parent->enumerateChildren("node/..", [&i](Node* node) -> bool { +// ++i; +// return false; +// }); +// CCAssert(i == 10000, ""); + + // name = /xxx : search from root +// parent = getScene(); +// for (int j = 0; j < 100; j++) +// { +// auto node = Node::create(); +// sprintf(name, "node%d", j); +// node->setName(name); +// parent->addChild(node); +// +// for (int k = 0; k < 100; ++k) +// { +// auto child = Node::create(); +// sprintf(name, "node%d", k); +// child->setName(name); +// node->addChild(child); +// } +// } +// +// i = 0; +// enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool { +// ++i; +// return false; +// }); +// CCAssert(i == 100, ""); + +// i = 0; +// enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool { +// ++i; +// return true; +// }); +// CCAssert(i == 1, ""); +// +// i = 0; +// enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool { +// ++i; +// return false; +// }); +// CCAssert(i == 10100, ""); // 10000(children) + 100(parent) +// +// i = 0; +// enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool { +// ++i; +// return true; +// }); +// CCAssert(i == 1, ""); +// +// i = 0; +// enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool { +// ++i; +// return false; +// }); +// CCAssert(i == 10000, ""); + // utils::findChildren() parent = Node::create(); diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 1f8a1403fd..ac8281b9f6 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -341,7 +341,6 @@ Effect3DOutline::Effect3DOutline() Effect3DOutline::~Effect3DOutline() { - CC_SAFE_RELEASE_NULL(_sprite); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener); #endif @@ -371,8 +370,6 @@ void Effect3DOutline::setTarget(EffectSprite3D *sprite) if(sprite != _sprite) { - CC_SAFE_RETAIN(sprite); - CC_SAFE_RELEASE_NULL(_sprite); _sprite = sprite; auto mesh = sprite->getMesh(); diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index 6695bcfc13..efb5052cc8 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -103,6 +103,7 @@ protected: Vec3 _outlineColor; float _outlineWidth; + //weak reference EffectSprite3D* _sprite; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) EventListenerCustom* _backToForegroundListener; diff --git a/tests/game-controller-test/proj.android/project.properties b/tests/game-controller-test/proj.android/project.properties index 572f7c30de..c851eff541 100644 --- a/tests/game-controller-test/proj.android/project.properties +++ b/tests/game-controller-test/proj.android/project.properties @@ -10,4 +10,4 @@ # Project target. target=android-10 -android.library.reference.1=../../../cocos/platform/android/java +android.library.reference.1=../../../cocos/platform/android/ControllerDelegate diff --git a/tests/game-controller-test/proj.android/src/org/cocos2dx/game_controller_test/AppActivity.java b/tests/game-controller-test/proj.android/src/org/cocos2dx/game_controller_test/AppActivity.java index 2675ce468b..570608bada 100644 --- a/tests/game-controller-test/proj.android/src/org/cocos2dx/game_controller_test/AppActivity.java +++ b/tests/game-controller-test/proj.android/src/org/cocos2dx/game_controller_test/AppActivity.java @@ -25,14 +25,14 @@ package org.cocos2dx.game_controller_test; import java.util.ArrayList; -import org.cocos2dx.lib.Cocos2dxActivity; +import org.cocos2dx.lib.GameControllerActivity; import org.cocos2dx.lib.GameControllerHelper.ControllerListener; import android.bluetooth.BluetoothDevice; import android.os.Bundle; import android.util.Log; -public class AppActivity extends Cocos2dxActivity { +public class AppActivity extends GameControllerActivity { @Override protected void onCreate(Bundle savedInstanceState) {