From 78aaf568c6b4e8f8fda44d69ba600303ca462ae7 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 10 Dec 2020 16:54:59 +0800 Subject: [PATCH] fix FUISprite gray to normal doesn't work --- .../src/org/cocos2dx/lib/Cocos2dxActivity.java | 8 ++++---- .../org/cocos2dx/lib/Cocos2dxEditBoxHelper.java | 6 +++--- .../src/org/cocos2dx/lib/Cocos2dxHelper.java | 8 ++++---- .../src/org/cocos2dx/lib/Cocos2dxWebView.java | 11 +++++------ .../Java_org_cocos2dx_lib_Cocos2dxHelper.cpp | 17 ----------------- extensions/fairygui/display/FUISprite.cpp | 2 +- 6 files changed, 17 insertions(+), 35 deletions(-) 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 6c1a9d478f..db33da2540 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -217,10 +217,10 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe msg.obj = new Cocos2dxHandler.DialogMessage(pTitle, pMessage); this.mHandler.sendMessage(msg); } - - @Deprecated - public void runOnGLThread(final Runnable runnable) { - Cocos2dxHelper.runOnGLThread(runnable); + + @Override + public void runOnGLThread(final Runnable pRunnable) { + this.mGLSurfaceView.queueEvent(pRunnable); } @Override diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBoxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBoxHelper.java index 14bf7af5c2..a697de5d2f 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBoxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxEditBoxHelper.java @@ -130,7 +130,7 @@ public class Cocos2dxEditBoxHelper { public void afterTextChanged(final Editable s) { if (!editBox.getChangedTextProgrammatically()) { if ((Boolean) editBox.getTag()) { - Cocos2dxHelper.runOnGLThread(new Runnable() { + mCocos2dxActivity.runOnGLThread(new Runnable() { @Override public void run() { Cocos2dxEditBoxHelper.__editBoxEditingChanged(index, s.toString()); @@ -152,7 +152,7 @@ public class Cocos2dxEditBoxHelper { editBox.setTag(true); editBox.setChangedTextProgrammatically(false); if (hasFocus) { - Cocos2dxHelper.runOnGLThread(new Runnable() { + mCocos2dxActivity.runOnGLThread(new Runnable() { @Override public void run() { editBox.endAction = Cocos2dxEditBox.kEndActionUnknown; @@ -168,7 +168,7 @@ public class Cocos2dxEditBoxHelper { // Note that we must to copy a string to prevent string content is modified // on UI thread while 's.toString' is invoked at the same time. final String text = new String(editBox.getText().toString()); - Cocos2dxHelper.runOnGLThread(new Runnable() { + mCocos2dxActivity.runOnGLThread(new Runnable() { @Override public void run() { int action = editBox.endAction; diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index 7b19cc7d6d..11d0a08982 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -111,7 +111,7 @@ public class Cocos2dxHelper { // =========================================================== public static void runOnGLThread(final Runnable r) { - nativeRunOnGLThread(r); + ((Cocos2dxActivity)sActivity).runOnGLThread(r); } private static boolean sInited = false; @@ -264,8 +264,6 @@ public class Cocos2dxHelper { // Methods // =========================================================== - private static native void nativeRunOnGLThread(final Object runnable); - private static native void nativeSetEditTextDialogResult(final byte[] pBytes); private static native void nativeSetContext(final Object pContext, final Object pAssetManager); @@ -396,7 +394,7 @@ public class Cocos2dxHelper { try { final byte[] bytesUTF8 = pResult.getBytes("UTF8"); - Cocos2dxHelper.runOnGLThread(new Runnable() { + Cocos2dxHelper.sCocos2dxHelperListener.runOnGLThread(new Runnable() { @Override public void run() { Cocos2dxHelper.nativeSetEditTextDialogResult(bytesUTF8); @@ -610,6 +608,8 @@ public class Cocos2dxHelper { public static interface Cocos2dxHelperListener { public void showDialog(final String pTitle, final String pMessage); + + public void runOnGLThread(final Runnable pRunnable); } //Enhance API modification begin diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java index b211bf6049..6c8e3b15da 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java @@ -33,8 +33,6 @@ import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.FrameLayout; -import org.cocos2dx.lib.Cocos2dxHelper; - import java.lang.reflect.Method; import java.net.URI; import java.util.concurrent.CountDownLatch; @@ -111,7 +109,7 @@ public class Cocos2dxWebView extends WebView { try { URI uri = URI.create(urlString); if (uri != null && uri.getScheme().equals(mJSScheme)) { - Cocos2dxHelper.runOnGLThread(new Runnable() { + activity.runOnGLThread(new Runnable() { @Override public void run() { Cocos2dxWebViewHelper._onJsCallback(mViewTag, urlString); @@ -127,7 +125,7 @@ public class Cocos2dxWebView extends WebView { CountDownLatch latch = new CountDownLatch(1); // run worker on cocos thread - Cocos2dxHelper.runOnGLThread(new ShouldStartLoadingWorker(latch, result, mViewTag, urlString)); + activity.runOnGLThread(new ShouldStartLoadingWorker(latch, result, mViewTag, urlString)); // wait for result from cocos thread try { @@ -142,7 +140,8 @@ public class Cocos2dxWebView extends WebView { @Override public void onPageFinished(WebView view, final String url) { super.onPageFinished(view, url); - Cocos2dxHelper.runOnGLThread(new Runnable() { + Cocos2dxActivity activity = (Cocos2dxActivity)getContext(); + activity.runOnGLThread(new Runnable() { @Override public void run() { Cocos2dxWebViewHelper._didFinishLoading(mViewTag, url); @@ -154,7 +153,7 @@ public class Cocos2dxWebView extends WebView { public void onReceivedError(WebView view, int errorCode, String description, final String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); Cocos2dxActivity activity = (Cocos2dxActivity)getContext(); - Cocos2dxHelper.runOnGLThread(new Runnable() { + activity.runOnGLThread(new Runnable() { @Override public void run() { Cocos2dxWebViewHelper._didFailLoading(mViewTag, failingUrl); diff --git a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp index 1997ae31eb..7b46460b64 100644 --- a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp +++ b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp @@ -82,23 +82,6 @@ extern "C" { } } - JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeRunOnGLThread(JNIEnv* env, jclass, jobject runnable) { - using jobject_type = std::remove_pointer_t; - struct jobject_delete { - void operator()(jobject_type* __ptr) const _NOEXCEPT { - JniHelper::getEnv()->DeleteGlobalRef(__ptr); - } - }; - - cocos2d::Director::getInstance()->getScheduler()->performFunctionInCocosThread([wrap = std::make_shared>(env->NewGlobalRef(runnable))]{ - auto curEnv = JniHelper::getEnv(); - - JniMethodInfo mi; - if(JniHelper::getMethodInfo(mi, "java/lang/Runnable", "run", "()V")){ - curEnv->CallVoidMethod(wrap.get()->get(), mi.methodID); - } - }); - } } const char * getApkPath() { diff --git a/extensions/fairygui/display/FUISprite.cpp b/extensions/fairygui/display/FUISprite.cpp index 1cc0869617..de968b68d3 100644 --- a/extensions/fairygui/display/FUISprite.cpp +++ b/extensions/fairygui/display/FUISprite.cpp @@ -101,7 +101,7 @@ void FUISprite::setScaleByTile(bool value) void FUISprite::setGrayed(bool value) { #if defined(ENGINEX_VERSION) - Sprite::setProgramState(backend::ProgramType::GRAY_SCALE); + Sprite::setProgramState(value ? backend::ProgramType::GRAY_SCALE : backend::ProgramType::POSITION_TEXTURE_COLOR); #elif COCOS2D_VERSION >= 0x00040000 auto isETC1 = getTexture() && getTexture()->getAlphaTextureName(); if (value) {