Skip to content

Commit

Permalink
Updated AGI mouse code so that it doesn't run if virtual keyboard was…
Browse files Browse the repository at this point in the history
… used.
  • Loading branch information
lanceewing committed Apr 28, 2024
1 parent f91d90c commit c6d44a8
Showing 1 changed file with 102 additions and 101 deletions.
203 changes: 102 additions & 101 deletions core/src/main/java/com/agifans/agile/ui/GameScreenInputProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
// Convert the screen coordinates to world coordinates.
Vector2 touchXY = viewportManager.unproject(screenX, screenY);

// Update AGI mouse variables.
updateAGIMouse(touchXY, button, true);

// Update the touch info for this pointer.
TouchInfo touchInfo = null;
if (pointer < MAX_SIMULTANEOUS_TOUCH_EVENTS) {
Expand All @@ -146,6 +143,9 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (touchInfo != null) {
touchInfo.lastKey = keycode;
}
} else {
// Update AGI mouse variables.
updateAGIMouse(touchXY, button, true);
}

return true;
Expand Down Expand Up @@ -301,9 +301,6 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
// Convert the screen coordinates to world coordinates.
Vector2 touchXY = viewportManager.unproject(screenX, screenY);

// Update AGI mouse variables (click/touch released, so clear all to 0)
updateAGIMouse(touchXY, button, false);

// Update the touch info for this pointer.
TouchInfo touchInfo = null;
if (pointer < MAX_SIMULTANEOUS_TOUCH_EVENTS) {
Expand All @@ -319,115 +316,119 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
processVirtualKeyboardKeyUp(keycode);
}
}

// TODO: Need to handle the magic numbers in this block in a better way.
boolean keyboardClicked = false;
boolean joystickClicked = false;
boolean backArrowClicked = false;
boolean fullScreenClicked = false;

if (viewportManager.isPortrait()) {
// Portrait.
if (touchXY.y < 135) {
if (touchXY.x < 126) {
fullScreenClicked = true;
} else if (touchXY.x > (viewportManager.getWidth() - 126)) {
backArrowClicked = true;
} else {
float thirdPos = (viewportManager.getWidth() / 3);
float twoThirdPos = (viewportManager.getWidth() - (viewportManager.getWidth() / 3));
if ((touchXY.x > (thirdPos - 42)) && (touchXY.x < (thirdPos + 84))) {
joystickClicked = true;
}
else if ((touchXY.x > (twoThirdPos - 84)) && (touchXY.x < (twoThirdPos + 42))) {
keyboardClicked = true;
}
}
}
} else {
// Landscape.
int screenTop = (int) viewportManager.getHeight();
if (cameraXOffset == 0) {
// Screen in middle.
if (touchXY.y > (screenTop - 104)) {
if (touchXY.x < 112) {
joystickClicked = true;
} else if (touchXY.x > (viewportManager.getWidth() - 112)) {
else {
// Update AGI mouse variables (click/touch released, so clear all to 0)
updateAGIMouse(touchXY, button, false);

// TODO: Need to handle the magic numbers in this block in a better way.
boolean keyboardClicked = false;
boolean joystickClicked = false;
boolean backArrowClicked = false;
boolean fullScreenClicked = false;

if (viewportManager.isPortrait()) {
// Portrait.
if (touchXY.y < 135) {
if (touchXY.x < 126) {
fullScreenClicked = true;
}
} else if (touchXY.y < 104) {
if (touchXY.x > (viewportManager.getWidth() - 112)) {
} else if (touchXY.x > (viewportManager.getWidth() - 126)) {
backArrowClicked = true;
} else if (touchXY.x < 112) {
keyboardClicked = true;
} else {
float thirdPos = (viewportManager.getWidth() / 3);
float twoThirdPos = (viewportManager.getWidth() - (viewportManager.getWidth() / 3));
if ((touchXY.x > (thirdPos - 42)) && (touchXY.x < (thirdPos + 84))) {
joystickClicked = true;
}
else if ((touchXY.x > (twoThirdPos - 84)) && (touchXY.x < (twoThirdPos + 42))) {
keyboardClicked = true;
}
}
}
}
else {
// All buttons on same side
if (((touchXY.x < 128) && (cameraXOffset < 0)) ||
((touchXY.x > (viewportManager.getWidth() - 128)) && (cameraXOffset > 0))) {
if (touchXY.y > (screenTop - 128)) {
fullScreenClicked = true;
}
else if ((touchXY.y < (screenTop - 212)) && (touchXY.y > (screenTop - 340))) {
joystickClicked = true;
}
else if ((touchXY.y > 212) && (touchXY.y < 340)) {
keyboardClicked = true;
} else {
// Landscape.
int screenTop = (int) viewportManager.getHeight();
if (cameraXOffset == 0) {
// Screen in middle.
if (touchXY.y > (screenTop - 104)) {
if (touchXY.x < 112) {
joystickClicked = true;
} else if (touchXY.x > (viewportManager.getWidth() - 112)) {
fullScreenClicked = true;
}
} else if (touchXY.y < 104) {
if (touchXY.x > (viewportManager.getWidth() - 112)) {
backArrowClicked = true;
} else if (touchXY.x < 112) {
keyboardClicked = true;
}
}
else if ((touchXY.y > 0) && (touchXY.y < 128)) {
backArrowClicked = true;
}
else {
// All buttons on same side
if (((touchXY.x < 128) && (cameraXOffset < 0)) ||
((touchXY.x > (viewportManager.getWidth() - 128)) && (cameraXOffset > 0))) {
if (touchXY.y > (screenTop - 128)) {
fullScreenClicked = true;
}
else if ((touchXY.y < (screenTop - 212)) && (touchXY.y > (screenTop - 340))) {
joystickClicked = true;
}
else if ((touchXY.y > 212) && (touchXY.y < 340)) {
keyboardClicked = true;
}
else if ((touchXY.y > 0) && (touchXY.y < 128)) {
backArrowClicked = true;
}
}
}
}
}

if (keyboardClicked) {
if (keyboardType.equals(KeyboardType.OFF)) {
keyboardType = (viewportManager.isPortrait() ? KeyboardType.PORTRAIT_LOWER_CASE : KeyboardType.LANDSCAPE_LOWER_CASE);
viewportManager.update();
} else {
keyboardType = KeyboardType.OFF;

if (keyboardClicked) {
if (keyboardType.equals(KeyboardType.OFF)) {
keyboardType = (viewportManager.isPortrait() ? KeyboardType.PORTRAIT_LOWER_CASE : KeyboardType.LANDSCAPE_LOWER_CASE);
viewportManager.update();
} else {
keyboardType = KeyboardType.OFF;
}
}
}

if (joystickClicked) {
// Rotate the joystick screen alignment.
joystickAlignment = joystickAlignment.rotateValue();
if (!viewportManager.isPortrait() && joystickAlignment.equals(JoystickAlignment.MIDDLE)) {

if (joystickClicked) {
// Rotate the joystick screen alignment.
joystickAlignment = joystickAlignment.rotateValue();
}
}

if (fullScreenClicked) {
Boolean fullScreen = Gdx.graphics.isFullscreen();
if (fullScreen == true) {
switchOutOfFullScreen();
}
else {
switchIntoFullScreen();
}
}

if (backArrowClicked) {
if (Gdx.app.getType().equals(ApplicationType.Desktop) && Gdx.graphics.isFullscreen()) {
// Dialog won't show for desktop unless we exit full screen,
switchOutOfFullScreen();
if (!viewportManager.isPortrait() && joystickAlignment.equals(JoystickAlignment.MIDDLE)) {
joystickAlignment = joystickAlignment.rotateValue();
}
}

dialogHandler.confirm("Are you sure you want to quit the game?",
new ConfirmResponseHandler() {
@Override
public void yes() {
gameScreen.getAgileRunner().stop();
if (fullScreenClicked) {
Boolean fullScreen = Gdx.graphics.isFullscreen();
if (fullScreen == true) {
switchOutOfFullScreen();
}

@Override
public void no() {
// Nothing to do.
else {
switchIntoFullScreen();
}
}

if (backArrowClicked) {
if (Gdx.app.getType().equals(ApplicationType.Desktop) && Gdx.graphics.isFullscreen()) {
// Dialog won't show for desktop unless we exit full screen,
switchOutOfFullScreen();
}
});

dialogHandler.confirm("Are you sure you want to quit the game?",
new ConfirmResponseHandler() {
@Override
public void yes() {
gameScreen.getAgileRunner().stop();
}

@Override
public void no() {
// Nothing to do.
}
});
}
}

return true;
Expand Down

0 comments on commit c6d44a8

Please sign in to comment.