@Override public boolean onTouch(View view, MotionEvent event) { // Log.d("FFNG", "event: " + event.getAction()); float screenX = event.getX(); float screenY = event.getY(); boolean result = false; switch (touchState) { case TOUCH_STATE_BUTTON_PRESSED: switch (event.getAction()) { case MotionEvent.ACTION_MOVE: // sleep(5); result = true; break; case MotionEvent.ACTION_UP: // case MotionEvent.ACTION_OUTSIDE: // case MotionEvent.ACTION_CANCEL: app.eventQueue.add(new FFNGInputEvent(FFNGInputEvent.KEYUP, lastKey)); for (int i = 0; i < app.moreGroup.length; ++i) { if (app.moreGroup[i] == touchedArea) app.moreButtonsClose(); } touchState = TOUCH_STATE_NONE; touchedArea.touched = false; touchedArea = null; result = true; break; } break; case TOUCH_STATE_JAVA_BUTTON_PRESSED: switch (lastKey) { case MORE_BUTTONS: if (event.getAction() == MotionEvent.ACTION_UP) { app.moreButtons(); touchState = TOUCH_STATE_NONE; touchedArea.touched = false; touchedArea = null; } result = true; break; } break; case TOUCH_STATE_NONE: int key = 0; if (app.gameState == GAMESTATE_LEVEL) { touchedArea = app.controls.getTouchArea(screenX, screenY); key = touchedArea == null ? 0 : touchedArea.value; // key = app.controls.getTouchValue(screenX, screenY); } if (key >= 100) { // FFNG java buttons switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touchState = TOUCH_STATE_JAVA_BUTTON_PRESSED; touchedArea.touched = true; lastKey = key; result = true; break; } } else if (key > 0) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: app.eventQueue.add(new FFNGInputEvent(FFNGInputEvent.KEYDOWN, key)); touchState = TOUCH_STATE_BUTTON_PRESSED; touchedArea.touched = true; lastKey = key; result = true; break; } } else { float x = (screenX - app.windowX) / app.windowScale; float y = (screenY - app.windowY) / app.windowScale; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: app.setTouch(x, y); // touch_start(x, y); // invalidate(); result = true; break; case MotionEvent.ACTION_MOVE: app.setTouch(x, y); // sleep(5); // touch_move(x, y); // invalidate(); result = true; break; case MotionEvent.ACTION_UP: // case MotionEvent.ACTION_OUTSIDE: // case MotionEvent.ACTION_CANCEL: app.setTouch(-1, -1); app.eventQueue.add(new FFNGInputEvent(FFNGInputEvent.MOUSEBUTTONDOWN, x, y)); // touch_up(); // invalidate(); result = true; break; } } break; } return result; }
private void setGameState(int newState) { moreButtonsClose(); gameState = newState; }