Commit a845a361 authored by kenan's avatar kenan

Merge remote-tracking branch 'remotes/origin/dev_surface'

parents 2e45d5a3 aa59f65d
......@@ -15,6 +15,7 @@
#include <android/CAndroidGUIEditBox.h>
#include <android/CAndroidGUIComboBox.h>
#include <android/CAndroidGUISkin.h>
#include <Android/CIrrDeviceAndroid.h>
#include <COGLES2ExtensionHandler.h>
#include <COGLESExtensionHandler.h>
#include <COGLES2Driver.h>
......@@ -25,7 +26,18 @@ const unsigned short PRO_VERSION = 0x134B;
namespace ygo {
Game* mainGame;
Game *mainGame;
void Game::process(irr::SEvent &event) {
if (event.EventType == EET_MOUSE_INPUT_EVENT) {
s32 x = event.MouseInput.X;
s32 y = event.MouseInput.Y;
event.MouseInput.X = optX(x);
event.MouseInput.Y = optY(y);
// __android_log_print(ANDROID_LOG_DEBUG, "ygo", "Android comman process %d,%d -> %d,%d", x, y,
// event.MouseInput.X, event.MouseInput.Y);
}
}
#ifdef _IRR_ANDROID_PLATFORM_
bool Game::Initialize(ANDROID_APP app) {
......@@ -61,10 +73,14 @@ bool Game::Initialize() {
if(!device)
return false;
#ifdef _IRR_ANDROID_PLATFORM_
if (!android::perfromTrick(app)) {
return false;
}
android::initJavaBridge(app, device);
core::position2di appPosition = android::initJavaBridge(app, device);
setPositionFix(appPosition);
device->setProcessReceiver(this);
soundEffectPlayer = new AndroidSoundEffectPlayer(app);
soundEffectPlayer->setSEEnabled(options->isSoundEffectEnabled());
app->onInputEvent = android::handleInput;
......
......@@ -107,7 +107,7 @@ struct FadingUnit {
irr::core::vector2di fadingDiff;
};
class Game {
class Game :IProcessEventReceiver{
public:
#ifdef _IRR_ANDROID_PLATFORM_
......@@ -542,10 +542,30 @@ public:
irr::android::CustomShaderConstantSetCallBack customShadersCallback;
Signal externalSignal;
#endif
void setPositionFix(core::position2di fix){
InputFix = fix;
}
float optX(float x) {
float x2 = x - InputFix.X;
if (x2 < 0) {
return 0;
}
return x2;
}
};
float optY(float y) {
float y2 = y - InputFix.Y;
if (y2 < 0) {
return 0;
}
return y2;
}
void process(irr::SEvent &event);
private:
core::position2di InputFix;
};
extern Game* mainGame;
extern Game *mainGame;
}
......
......@@ -539,6 +539,15 @@ public:
virtual bool OnEvent(const SEvent& event) = 0;
};
class IProcessEventReceiver
{
public:
//! Destructor
virtual ~IProcessEventReceiver() {}
virtual void process(SEvent& event) = 0;
};
//! Information on a joystick, returned from @ref irr::IrrlichtDevice::activateJoysticks()
struct SJoystickInfo
......
......@@ -307,6 +307,8 @@ namespace irr
//! Get context manager
virtual video::IContextManager* getContextManager() =0;
virtual void setProcessReceiver(IProcessEventReceiver* receiver) = 0;
//! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.
/** When set to 0 no double- and tripleclicks will be generated.
\param timeMs maximal time in milliseconds for two consecutive clicks to be recognized as double click
......
......@@ -56,6 +56,8 @@ namespace irr
virtual E_DEVICE_TYPE getType() const;
core::array<EKEY_CODE> KeyMap;
private:
static void handleAndroidCommand(ANDROID_APP app, int32_t cmd);
......@@ -80,7 +82,6 @@ namespace irr
video::SExposedVideoData ExposedVideoData;
core::array<EKEY_CODE> KeyMap;
};
} // end namespace irr
......
......@@ -224,10 +224,15 @@ u32 CIrrDeviceStub::checkSuccessiveClicks(s32 mouseX, s32 mouseY, EMOUSE_INPUT_E
//! send the event to the right receiver
bool CIrrDeviceStub::postEventFromUser(const SEvent& event)
bool CIrrDeviceStub::postEventFromUser(const SEvent& _event)
{
SEvent event = _event;
bool absorbed = false;
if(ProcessReceiver){
ProcessReceiver->process(event);
}
if (UserReceiver)
absorbed = UserReceiver->OnEvent(event);
......
......@@ -178,6 +178,9 @@ namespace irr
//! Resize the render window.
virtual void setWindowSize(const irr::core::dimension2d<u32>& size) _IRR_OVERRIDE_ {}
virtual void setProcessReceiver(IProcessEventReceiver* receiver) _IRR_OVERRIDE_{
ProcessReceiver = receiver;
}
protected:
void createGUIAndScene();
......@@ -200,6 +203,7 @@ namespace irr
ITimer* Timer;
gui::ICursorControl* CursorControl;
IEventReceiver* UserReceiver;
IProcessEventReceiver* ProcessReceiver;
CLogger* Logger;
IOSOperator* Operator;
IRandomizer* Randomizer;
......
......@@ -743,20 +743,29 @@ void toggleGlobalIME(ANDROID_APP app, bool pShow) {
app->activity->vm->DetachCurrentThread();
}
void initJavaBridge(ANDROID_APP app, void* handle) {
core::position2di initJavaBridge(ANDROID_APP app, void* handle) {
if (!app || !app->activity || !app->activity->vm)
return;
return core::position2di(0, 0);
JNIEnv* jni = 0;
app->activity->vm->AttachCurrentThread(&jni, NULL);
jobject lNativeActivity = app->activity->clazz;
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
jmethodID MethodSetHandle = jni->GetMethodID(ClassNativeActivity,
"setNativeHandle", "(I)V");
"setNativeHandle", "(I)V");
jint code = (int) handle;
jni->CallVoidMethod(lNativeActivity, MethodSetHandle, code);
jmethodID methodX = jni->GetMethodID(ClassNativeActivity,
"getPositionX", "()I");
jint posX = jni->CallIntMethod(lNativeActivity, methodX);
jmethodID methodY = jni->GetMethodID(ClassNativeActivity,
"getPositionY", "()I");
jint posY = jni->CallIntMethod(lNativeActivity, methodY);
jni->DeleteLocalRef(ClassNativeActivity);
app->activity->vm->DetachCurrentThread();
return;
__android_log_print(ANDROID_LOG_INFO, "ygo", "Android command initJavaBridge posX=%d, posY=%d", posX, posY);
return core::position2di((int)posX, (int)posY);
}
InitOptions* getInitOptions(ANDROID_APP app) {
......
......@@ -115,7 +115,7 @@ extern void toggleGlobalIME(ANDROID_APP app, bool pShow);
extern void toggleIME(ANDROID_APP app, bool pShow, const char* hint);
//Init Java Irrlicht world.
extern void initJavaBridge(ANDROID_APP app, void* handle);
extern core::position2di initJavaBridge(ANDROID_APP app, void* handle);
//Cause a haptic feedback.
extern void perfromHapticFeedback(ANDROID_APP app);
......
......@@ -4,8 +4,10 @@
#include "../Classes/gframe/os.h"
#include <unistd.h>
#include <pthread.h>
#include <Android/CIrrDeviceAndroid.h>
#include "../android/YGOGameOptions.h"
#include "../Classes/gframe/game.h"
#include <android/log.h>
using namespace irr;
using namespace gui;
......@@ -292,6 +294,14 @@ static void* join_game_thread(void* param) {
}
}
JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeSetInputFix(
JNIEnv* env, jclass clazz, jint handle, jint x, jint y) {
if(ygo::mainGame) {
__android_log_print(ANDROID_LOG_INFO, "ygo", "setInputFix posX=%d, posY=%d", x, y);
ygo::mainGame->setPositionFix(core::position2di(x, y));
}
}
static void* cancel_chain_thread(void* param) {
IrrlichtDevice* device = (IrrlichtDevice*) param;
irr::os::Printer::log("before send cancel chain");
......
......@@ -19,6 +19,8 @@ import android.util.Log;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
......@@ -78,7 +80,11 @@ public class YGOMobileActivity extends NativeActivity implements
private GameApplication mApp;
private Handler handler = new Handler();
private FullScreenUtils mFullScreenUtils;
private volatile int mPositionX, mPositionY;
private FrameLayout mLayout;
private SurfaceView mSurfaceView;
private boolean replaced = false;
private static boolean USE_SURFACE = true;
// public static int notchHeight;
......@@ -100,11 +106,14 @@ public class YGOMobileActivity extends NativeActivity implements
@SuppressWarnings("WrongConstant")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("YGOStarter","跳转完成"+System.currentTimeMillis());
if(USE_SURFACE) {
mSurfaceView = new SurfaceView(this);
}
mFullScreenUtils = new FullScreenUtils(this, app().isImmerSiveMode());
mFullScreenUtils.fullscreen();
mFullScreenUtils.onCreate();
super.onCreate(savedInstanceState);
Log.e("YGOStarter","跳转完成"+System.currentTimeMillis());
if (sChainControlXPostion < 0) {
initPostion();
}
......@@ -212,16 +221,18 @@ public class YGOMobileActivity extends NativeActivity implements
if (app().isImmerSiveMode()) {
mFullScreenUtils.fullscreen();
app().attachGame(this);
//游戏大小
int[] size = getGameSize();
if(app().isKeepScale()) {
getWindow().setLayout(size[0], size[1]);
if (USE_SURFACE) {
changeGameSize();
} else {
int[] size = getGameSize();
if (app().isKeepScale()) {
getWindow().setLayout(size[0], size[1]);
}
}
}
}
private int[] getGameSize() {
private int[] getGameSize(){
//调整padding
float xScale = app().getXScale();
float yScale = app().getYScale();
......@@ -231,18 +242,74 @@ public class YGOMobileActivity extends NativeActivity implements
return new int[]{w, h};
}
@Override
public int getPositionX() {
synchronized (this) {
return mPositionX;
}
}
@Override
public int getPositionY() {
synchronized (this) {
return mPositionY;
}
}
@Override
public void setContentView(View view) {
int[] size = getGameSize();
int w = size[0];
int h = size[1];
mLayout = new FrameLayout(this);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h);
FrameLayout layout = new FrameLayout(this);
lp.gravity = Gravity.CENTER;
layout.addView(view, lp);
getWindow().setLayout(w, h);
getWindow().setGravity(Gravity.CENTER);
super.setContentView(layout);
if (USE_SURFACE) {
mLayout.addView(mSurfaceView, lp);
mLayout.addView(view, lp);
super.setContentView(mLayout);
app().attachGame(this);
changeGameSize();
getWindow().takeSurface(null);
replaced = true;
mSurfaceView.getHolder().addCallback(this);
mSurfaceView.requestFocus();
getWindow().setGravity(Gravity.CENTER);
} else {
mLayout.addView(view, lp);
getWindow().setLayout(w, h);
getWindow().setGravity(Gravity.CENTER);
super.setContentView(mLayout);
}
}
private void changeGameSize(){
//游戏大小
int[] size = getGameSize();
int w = (int) app().getScreenHeight();
int h = (int) app().getScreenWidth();
int spX = (int) ((w - size[0]) / 2.0f);
int spY = (int) ((h - size[1]) / 2.0f);
// Log.i("ygo", "Android command 1:posX=" + spX + ",posY=" + spY);
boolean update = false;
synchronized (this) {
if (spX != mPositionX || spY != mPositionY) {
mPositionX = spX;
mPositionY = spY;
update = true;
}
}
if (update) {
// Log.i("ygo", "Android command setInputFix2:posX=" + spX + ",posY=" + spY);
IrrlichtBridge.setInputFix(mPositionX, mPositionY);
}
if (app().isKeepScale()) {
//设置为屏幕宽高
getWindow().setLayout(w, h);
} else {
//拉伸,画布设置为游戏宽高
getWindow().setLayout(size[0], size[1]);
}
}
private void initExtraView() {
......@@ -419,4 +486,44 @@ public class YGOMobileActivity extends NativeActivity implements
public void setNativeHandle(int nativeHandle) {
IrrlichtBridge.sNativeHandle = nativeHandle;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if(USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceCreated(holder);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if(USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceChanged(holder, format, width, height);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if(USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceDestroyed(holder);
}
@Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
if(USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceRedrawNeeded(holder);
}
}
......@@ -59,6 +59,8 @@ public final class IrrlichtBridge {
private static native void nativeJoinGame(int handle, ByteBuffer buffer, int length);
private static native void nativeSetInputFix(int handle, int x, int y);
private static final boolean DEBUG = false;
private static final String TAG = IrrlichtBridge.class.getSimpleName();
......@@ -118,6 +120,10 @@ public final class IrrlichtBridge {
}
}
public static void setInputFix(int x, int y){
nativeSetInputFix(sNativeHandle, x, y);
}
public static void cancelChain() {
nativeCancelChain(sNativeHandle);
}
......@@ -202,5 +208,9 @@ public final class IrrlichtBridge {
int getLocalAddress();
void setNativeHandle(int nativeHandle);
int getPositionX();
int getPositionY();
}
}
......@@ -35,6 +35,7 @@ android {
}
buildTypes {
debug {
applicationIdSuffix ".debug"
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
......
......@@ -2,6 +2,7 @@ package cn.garymb.ygomobile.ui.adapters;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.view.ViewGroup;
......@@ -36,7 +37,7 @@ public class ServerListAdapter extends BaseRecyclerAdapterPlus<ServerInfo, Serve
builder.setMessage(R.string.join_helper_tip);
builder.setLeftButtonText(R.string.Open_Alert_Window);
builder.setLeftButtonListener((dlg, s) -> {
getContext().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION));
getContext().startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:"+context.getPackageName())));
dlg.dismiss();
});
builder.show();
......
......@@ -66,7 +66,7 @@ public class PermissionUtil {
dialog.setLeftButtonListener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
context.startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION));
context.startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:"+context.getPackageName())));
dialog.dismiss();
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment