Skip to content

Commit

Permalink
Updated icon click testing to cater for new positions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanceewing committed Mar 22, 2024
1 parent bdf4c17 commit 3d05ac7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
28 changes: 15 additions & 13 deletions core/src/main/java/com/agifans/agile/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private void draw(float delta) {
float topPadding = ((viewportManager.getHeight() - agiScreenHeight) / 2);
cameraYOffset = (topPadding / agiHeightRatio);
}
gameScreenInputProcessor.setCameraXOffset(cameraXOffset);
camera.position.set((ADJUSTED_WIDTH / 2) + cameraXOffset, (ADJUSTED_HEIGHT / 2) - cameraYOffset, 0.0f);
camera.update();
batch.setProjectionMatrix(camera.combined);
Expand Down Expand Up @@ -318,23 +319,24 @@ private void draw(float delta) {
batch.draw(backIcon, viewportManager.getWidth() - 116, 20);
} else {
// Landscape
if (cameraXOffset != 0) {
if (joystickAlignment.equals(JoystickAlignment.LEFT)) {
batch.draw(joystickIcon, 16, viewportManager.getHeight() - 324);
batch.draw(fullScreenIcon, 16, viewportManager.getHeight() - 112);
batch.draw(backIcon, 16, 16);
batch.draw(keyboardIcon, 16, 228);
} else {
batch.draw(joystickIcon, viewportManager.getWidth() - 112, viewportManager.getHeight() - 324);
batch.draw(fullScreenIcon, viewportManager.getWidth() - 112, viewportManager.getHeight() - 112);
batch.draw(backIcon, viewportManager.getWidth() - 112, 16);
batch.draw(keyboardIcon, viewportManager.getWidth() - 112, 228);
}
} else {
if (cameraXOffset == 0) {
// Middle
batch.draw(joystickIcon, 16, viewportManager.getHeight() - 112);
batch.draw(fullScreenIcon, viewportManager.getWidth() - 112, viewportManager.getHeight() - 112);
batch.draw(backIcon, viewportManager.getWidth() - 112, 16);
batch.draw(keyboardIcon, 16, 0);
} else if (cameraXOffset < 0) {
// Left
batch.draw(joystickIcon, 16, viewportManager.getHeight() - 324);
batch.draw(fullScreenIcon, 16, viewportManager.getHeight() - 112);
batch.draw(backIcon, 16, 16);
batch.draw(keyboardIcon, 16, 228);
} else if (cameraXOffset > 0) {
// Right
batch.draw(joystickIcon, viewportManager.getWidth() - 112, viewportManager.getHeight() - 324);
batch.draw(fullScreenIcon, viewportManager.getWidth() - 112, viewportManager.getHeight() - 112);
batch.draw(backIcon, viewportManager.getWidth() - 112, 16);
batch.draw(keyboardIcon, viewportManager.getWidth() - 112, 228);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class GameScreenInputProcessor extends InputAdapter {
*/
private JoystickAlignment joystickAlignment = JoystickAlignment.OFF;

/**
* The current offset from centre of the camera in the X direction.
*/
private float cameraXOffset;

/**
* Invoked by AGILE whenever it would like to show a dialog, such as when it
* needs the user to confirm an action, or to choose a file.
Expand Down Expand Up @@ -334,17 +339,37 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
} else {
// Landscape.
int screenTop = (int) viewportManager.getHeight();
if (touchXY.y > (screenTop - 104)) {
if (touchXY.x < 112) {
joystickClicked = true;
} else if (touchXY.x > (viewportManager.getWidth() - 112)) {
fullScreenClicked = true;
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 < 104) {
if (touchXY.x > (viewportManager.getWidth() - 112)) {
backArrowClicked = true;
} else if (touchXY.x < 112) {
keyboardClicked = true;
}
else {
// All buttons on same side
if ((touchXY.x < 128) || (touchXY.x > (viewportManager.getWidth() - 128))) {
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;
}
}
}
}
Expand Down Expand Up @@ -523,4 +548,13 @@ JoystickAlignment rotateValue() {
return values()[(ordinal() + 1) % 4];
}
}

/**
* Sets the current offset from centre of the camera in the X direction.
*
* @param cameraXOffset The current offset from centre of the camera in the X direction.
*/
public void setCameraXOffset(float cameraXOffset) {
this.cameraXOffset = cameraXOffset;
}
}

0 comments on commit 3d05ac7

Please sign in to comment.