fix FUISprite gray to normal doesn't work

This commit is contained in:
halx99 2020-12-10 16:54:59 +08:00
parent ca4597a1ff
commit 78aaf568c6
6 changed files with 17 additions and 35 deletions

View File

@ -217,10 +217,10 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
msg.obj = new Cocos2dxHandler.DialogMessage(pTitle, pMessage); msg.obj = new Cocos2dxHandler.DialogMessage(pTitle, pMessage);
this.mHandler.sendMessage(msg); this.mHandler.sendMessage(msg);
} }
@Deprecated @Override
public void runOnGLThread(final Runnable runnable) { public void runOnGLThread(final Runnable pRunnable) {
Cocos2dxHelper.runOnGLThread(runnable); this.mGLSurfaceView.queueEvent(pRunnable);
} }
@Override @Override

View File

@ -130,7 +130,7 @@ public class Cocos2dxEditBoxHelper {
public void afterTextChanged(final Editable s) { public void afterTextChanged(final Editable s) {
if (!editBox.getChangedTextProgrammatically()) { if (!editBox.getChangedTextProgrammatically()) {
if ((Boolean) editBox.getTag()) { if ((Boolean) editBox.getTag()) {
Cocos2dxHelper.runOnGLThread(new Runnable() { mCocos2dxActivity.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxEditBoxHelper.__editBoxEditingChanged(index, s.toString()); Cocos2dxEditBoxHelper.__editBoxEditingChanged(index, s.toString());
@ -152,7 +152,7 @@ public class Cocos2dxEditBoxHelper {
editBox.setTag(true); editBox.setTag(true);
editBox.setChangedTextProgrammatically(false); editBox.setChangedTextProgrammatically(false);
if (hasFocus) { if (hasFocus) {
Cocos2dxHelper.runOnGLThread(new Runnable() { mCocos2dxActivity.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
editBox.endAction = Cocos2dxEditBox.kEndActionUnknown; 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 // 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. // on UI thread while 's.toString' is invoked at the same time.
final String text = new String(editBox.getText().toString()); final String text = new String(editBox.getText().toString());
Cocos2dxHelper.runOnGLThread(new Runnable() { mCocos2dxActivity.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
int action = editBox.endAction; int action = editBox.endAction;

View File

@ -111,7 +111,7 @@ public class Cocos2dxHelper {
// =========================================================== // ===========================================================
public static void runOnGLThread(final Runnable r) { public static void runOnGLThread(final Runnable r) {
nativeRunOnGLThread(r); ((Cocos2dxActivity)sActivity).runOnGLThread(r);
} }
private static boolean sInited = false; private static boolean sInited = false;
@ -264,8 +264,6 @@ public class Cocos2dxHelper {
// Methods // Methods
// =========================================================== // ===========================================================
private static native void nativeRunOnGLThread(final Object runnable);
private static native void nativeSetEditTextDialogResult(final byte[] pBytes); private static native void nativeSetEditTextDialogResult(final byte[] pBytes);
private static native void nativeSetContext(final Object pContext, final Object pAssetManager); private static native void nativeSetContext(final Object pContext, final Object pAssetManager);
@ -396,7 +394,7 @@ public class Cocos2dxHelper {
try { try {
final byte[] bytesUTF8 = pResult.getBytes("UTF8"); final byte[] bytesUTF8 = pResult.getBytes("UTF8");
Cocos2dxHelper.runOnGLThread(new Runnable() { Cocos2dxHelper.sCocos2dxHelperListener.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxHelper.nativeSetEditTextDialogResult(bytesUTF8); Cocos2dxHelper.nativeSetEditTextDialogResult(bytesUTF8);
@ -610,6 +608,8 @@ public class Cocos2dxHelper {
public static interface Cocos2dxHelperListener { public static interface Cocos2dxHelperListener {
public void showDialog(final String pTitle, final String pMessage); public void showDialog(final String pTitle, final String pMessage);
public void runOnGLThread(final Runnable pRunnable);
} }
//Enhance API modification begin //Enhance API modification begin

View File

@ -33,8 +33,6 @@ import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import org.cocos2dx.lib.Cocos2dxHelper;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -111,7 +109,7 @@ public class Cocos2dxWebView extends WebView {
try { try {
URI uri = URI.create(urlString); URI uri = URI.create(urlString);
if (uri != null && uri.getScheme().equals(mJSScheme)) { if (uri != null && uri.getScheme().equals(mJSScheme)) {
Cocos2dxHelper.runOnGLThread(new Runnable() { activity.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebViewHelper._onJsCallback(mViewTag, urlString); Cocos2dxWebViewHelper._onJsCallback(mViewTag, urlString);
@ -127,7 +125,7 @@ public class Cocos2dxWebView extends WebView {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
// run worker on cocos thread // 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 // wait for result from cocos thread
try { try {
@ -142,7 +140,8 @@ public class Cocos2dxWebView extends WebView {
@Override @Override
public void onPageFinished(WebView view, final String url) { public void onPageFinished(WebView view, final String url) {
super.onPageFinished(view, url); super.onPageFinished(view, url);
Cocos2dxHelper.runOnGLThread(new Runnable() { Cocos2dxActivity activity = (Cocos2dxActivity)getContext();
activity.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebViewHelper._didFinishLoading(mViewTag, url); 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) { public void onReceivedError(WebView view, int errorCode, String description, final String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl); super.onReceivedError(view, errorCode, description, failingUrl);
Cocos2dxActivity activity = (Cocos2dxActivity)getContext(); Cocos2dxActivity activity = (Cocos2dxActivity)getContext();
Cocos2dxHelper.runOnGLThread(new Runnable() { activity.runOnGLThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebViewHelper._didFailLoading(mViewTag, failingUrl); Cocos2dxWebViewHelper._didFailLoading(mViewTag, failingUrl);

View File

@ -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<jobject>;
struct jobject_delete {
void operator()(jobject_type* __ptr) const _NOEXCEPT {
JniHelper::getEnv()->DeleteGlobalRef(__ptr);
}
};
cocos2d::Director::getInstance()->getScheduler()->performFunctionInCocosThread([wrap = std::make_shared<std::unique_ptr<jobject_type, jobject_delete>>(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() { const char * getApkPath() {

View File

@ -101,7 +101,7 @@ void FUISprite::setScaleByTile(bool value)
void FUISprite::setGrayed(bool value) void FUISprite::setGrayed(bool value)
{ {
#if defined(ENGINEX_VERSION) #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 #elif COCOS2D_VERSION >= 0x00040000
auto isETC1 = getTexture() && getTexture()->getAlphaTextureName(); auto isETC1 = getTexture() && getTexture()->getAlphaTextureName();
if (value) { if (value) {