Commit bd22e195 authored by kenan's avatar kenan

刷新会闪退

parent 0f6ff7ba
......@@ -199,7 +199,7 @@ void Game::DrawBackGround() {
DrawShadowText(numFont, dInfo.str_total_attack[1], recti(885 * mainGame->xScale, 271 * mainGame->yScale, 905 * mainGame->xScale, 291 * mainGame->yScale), recti(0, 1, 2, 0), dInfo.total_attack_color[1], 0xff000000, true, false, 0);
} else {
driver->drawVertexPrimitiveList(matManager.vTotalAtkopT, 4, matManager.iRectangle, 2);
DrawShadowText(numFont, dInfo.str_total_attack[1], recti(740 * mainGame->xScale, 295 * mainGame->yScale, 760 * mainGame->xScale, 3315 * mainGame->yScale), recti(0, 1, 2, 0), dInfo.total_attack_color[1], 0xff000000, true, false, 0);
DrawShadowText(numFont, dInfo.str_total_attack[1], recti(740 * mainGame->xScale, 295 * mainGame->yScale, 760 * mainGame->xScale, 315 * mainGame->yScale), recti(0, 1, 2, 0), dInfo.total_attack_color[1], 0xff000000, true, false, 0);
}
}
......
......@@ -226,38 +226,27 @@ static void* join_game_thread(void* param) {
return NULL;
}
bool sendKey(int handle, int keycode, bool begin){
if(handle) {
CIrrDeviceAndroid *device = (CIrrDeviceAndroid *) handle;
/*
* Class: cn_garymb_ygomobile_core_IrrlichtBridge
* Method: nativeRefreshTexture
* Signature: (I)V
*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeRefreshTexture(
JNIEnv* env, jclass clazz, jint handle) {
if (handle) {
IrrlichtDevice* device = (IrrlichtDevice*) handle;
if (device->isWindowFocused()) {
irr::os::Printer::log("before send refresh event");
SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
int keyCode = keycode;
if (keyCode >= 0 && (u32) keyCode < device->KeyMap.size())
event.KeyInput.Key = device->KeyMap[keyCode];
else
event.KeyInput.Key = KEY_UNKNOWN;
event.KeyInput.PressedDown = begin;
//just cause a right up event to refresh texture
event.KeyInput.PressedDown = true;
event.KeyInput.Shift = false;
event.KeyInput.Control = false;
event.KeyInput.Key = KEY_KEY_R;
device->postEventFromUser(event);
return true;
}
}
return false;
}
/*
* Class: cn_garymb_ygomobile_core_IrrlichtBridge
* Method: nativeRefreshTexture
* Signature: (I)V
*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeRefreshTexture(
JNIEnv* env, jclass clazz, jint handle) {
if(sendKey(handle, KEY_KEY_R, true)){
irr::os::Printer::log("before send refresh event");
}
}
/*
......@@ -266,8 +255,19 @@ bool sendKey(int handle, int keycode, bool begin){
* Signature: (IZ)V
*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeIgnoreChain(
JNIEnv* env, jclass clazz, jint handle, jboolean begin) {
if(sendKey(handle, KEY_KEY_S, true)){
irr::os::Printer::log("before send ignore chain");
if (handle) {
IrrlichtDevice* device = (IrrlichtDevice*) handle;
if (device->isWindowFocused()) {
irr::os::Printer::log("before send ignore chain");
SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
//just cause a right up event to refresh texture
event.KeyInput.PressedDown = begin;
event.KeyInput.Shift = false;
event.KeyInput.Control = false;
event.KeyInput.Key = KEY_KEY_S;
device->postEventFromUser(event);
}
}
}
......@@ -277,16 +277,19 @@ bool sendKey(int handle, int keycode, bool begin){
* Signature: (IZ)V
*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeReactChain(
JNIEnv* env, jclass clazz, jint handle, jboolean begin) {
if(sendKey(handle, KEY_KEY_A, true)){
irr::os::Printer::log("before send react chain");
}
}
//key事件
JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeSendKey(
JNIEnv* env, jclass clazz, jint handle, jint keycode, jboolean begin) {
if(sendKey(handle, keycode, begin)){
irr::os::Printer::log("before send nativeSendKey");
if (handle) {
IrrlichtDevice* device = (IrrlichtDevice*) handle;
if (device->isWindowFocused()) {
irr::os::Printer::log("before send react chain");
SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
//just cause a right up event to refresh texture
event.KeyInput.PressedDown = begin;
event.KeyInput.Shift = false;
event.KeyInput.Control = false;
event.KeyInput.Key = KEY_KEY_A;
device->postEventFromUser(event);
}
}
}
......
......@@ -263,8 +263,8 @@ public class YGOMobileActivity extends NativeActivity implements
int[] size = getGameSize();
int w = size[0];
int h = size[1];
getWindow().takeInputQueue(null);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h);
lp.gravity = Gravity.CENTER;
layout.addView(mSurfaceView, lp);
layout.addView(view, lp);
......@@ -290,7 +290,7 @@ public class YGOMobileActivity extends NativeActivity implements
final int action = event.getAction();
final float x = event.getX();
final float y = event.getY();
mWorker.post(new Runnable() {
doWork(new Runnable() {
@Override
public void run() {
IrrlichtBridge.sendTouch(action, x, y, 0);
......@@ -303,9 +303,8 @@ public class YGOMobileActivity extends NativeActivity implements
// getWindow().setLayout(w, h);
// getWindow().setGravity(Gravity.CENTER);
super.setContentView(layout);
mSurfaceView.requestFocus();
getWindow().takeSurface(null);
getWindow().takeInputQueue(null);
mSurfaceView.requestFocus();
}
@Override
......@@ -321,7 +320,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
public boolean onKeyDown(final int keyCode, KeyEvent event) {
if(keyCode != KeyEvent.KEYCODE_BACK){
mWorker.post(new Runnable() {
doWork(new Runnable() {
@Override
public void run() {
IrrlichtBridge.sendKey(keyCode, true);
......@@ -335,7 +334,7 @@ public class YGOMobileActivity extends NativeActivity implements
@Override
public boolean onKeyUp(final int keyCode, KeyEvent event) {
if(keyCode != KeyEvent.KEYCODE_BACK){
mWorker.post(new Runnable() {
doWork(new Runnable() {
@Override
public void run() {
IrrlichtBridge.sendKey(keyCode, false);
......@@ -346,6 +345,10 @@ public class YGOMobileActivity extends NativeActivity implements
return super.onKeyUp(keyCode, event);
}
private void doWork(Runnable runnable){
mWorker.post(runnable);
}
@Override
public void onBackPressed() {
Toast.makeText(this, "请在游戏里面退出", Toast.LENGTH_SHORT).show();
......
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