Skip to content

Commit

Permalink
Removed keyboard icon from portrait mode. Will always be shown. Added…
Browse files Browse the repository at this point in the history
… fullscreen icon to portrait.
  • Loading branch information
lanceewing committed Mar 17, 2024
1 parent f6a3de6 commit 9963c1f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 41 deletions.
19 changes: 3 additions & 16 deletions core/src/main/java/com/agifans/agile/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private void draw(float delta) {
batch.enableBlending();
batch.begin();

if (keyboardType.isRendered()) {
if (keyboardType.isRendered() || viewportManager.isPortrait()) {
batch.setColor(c.r, c.g, c.b, keyboardType.getOpacity());
batch.draw(keyboardType.getTexture(), 0, keyboardType.getRenderOffset());
}
Expand All @@ -290,26 +290,13 @@ private void draw(float delta) {
batch.setColor(c.r, c.g, c.b, 0.5f);
if (viewportManager.isPortrait()) {
batch.draw(joystickIcon, 0, 0);
if (Gdx.app.getType().equals(ApplicationType.Android)) {
// Main AGI keyboard on the left.
batch.draw(keyboardIcon, viewportManager.getWidth() - 145, 0);
// Mobile keyboard for debug purpose. Wouldn't normally make this available.
batch.setColor(c.r, c.g, c.b, 0.15f);
batch.draw(keyboardIcon, viewportManager.getWidth() - viewportManager.getWidth() / 2 - 70, 0);

} else {
// Desktop puts keyboard button in the middle.
batch.draw(keyboardIcon, viewportManager.getWidth() - viewportManager.getWidth() / 2 - 70, 0);
// and the back button on the right.
batch.draw(backIcon, viewportManager.getWidth() - 145, 0);
}

batch.draw(fullScreenIcon, viewportManager.getWidth() - viewportManager.getWidth() / 2 - 70, 0);
batch.draw(backIcon, viewportManager.getWidth() - 145, 0);
} else {
batch.draw(joystickIcon, 0, viewportManager.getHeight() - 140);
batch.draw(fullScreenIcon, viewportManager.getWidth() - 150, viewportManager.getHeight() - 140);
batch.draw(backIcon, viewportManager.getWidth() - 150, 0);
batch.draw(keyboardIcon, 0, 0);

}

batch.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,6 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if (keycode != null) {
processVirtualKeyboardKeyUp(keycode);
}
} else if (keyboardType.equals(KeyboardType.MOBILE_ON_SCREEN)) {
// If the onscreen keyboard is being shown then if we receive a tap event, it
// won't be on the virtual keyboard but must therefore be outside it. So we
// hide the keyboard.
Gdx.input.setOnscreenKeyboardVisible(false);
keyboardType = KeyboardType.OFF;

}

// TODO: Need to handle the magic numbers in this block in a better way.
Expand All @@ -329,24 +322,12 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if (touchXY.y < 130) {
if (touchXY.x < 140) {
joystickClicked = true;

} else if (touchXY.x > (viewportManager.getWidth() - 145)) {
// If not Android, then right area is Back button.
if (Gdx.app.getType().equals(ApplicationType.Android)) {
keyboardClicked = true;
} else {
backArrowClicked = true;
}
backArrowClicked = true;
} else {
// Mobile soft keyboard is only available in portrait mode (debug only)
int midWidth = (int) (viewportManager.getWidth() - viewportManager.getWidth() / 2);
if ((touchXY.x > (midWidth - 70)) && (touchXY.y < (midWidth + 70))) {
if (Gdx.app.getType().equals(ApplicationType.Android)) {
Gdx.input.setOnscreenKeyboardVisible(true);
keyboardType = KeyboardType.MOBILE_ON_SCREEN;
} else {
keyboardClicked = true;
}
fullScreenClicked = true;
}
}
}
Expand Down Expand Up @@ -473,15 +454,22 @@ public boolean touchDragged(int screenX, int screenY, int pointer) {
}

/**
* Invokes by its MachineScreen when the screen has resized.
* Invokes by its GameScreen when the screen has resized.
*
* @param width The new screen width.
* @param height The new screen height.
*/
public void resize(int width, int height) {
if (keyboardType.isRendered()) {
// Switch keyboard layout based on the orientation.
keyboardType = (height > width ? KeyboardType.PORTRAIT_LOWER_CASE : KeyboardType.LANDSCAPE_LOWER_CASE);
if (height > width) {
// Change to portrait if it is not already a portrait keyboard.
if (!keyboardType.isPortrait()) {
keyboardType = KeyboardType.PORTRAIT_LOWER_CASE;
}
} else if (keyboardType.isRendered()) {
// Change to landscape if it is not already a landscape keyboard.
if (!keyboardType.isLandscape()) {
keyboardType = KeyboardType.LANDSCAPE_LOWER_CASE;
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions core/src/main/java/com/agifans/agile/ui/KeyboardType.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,24 @@ public float getOpacity() {
public boolean isRendered() {
return (texture != null);
}

/**
* @return true if this KeyboardType is a landscape keyboard, otherwise false.
*/
public boolean isLandscape() {
return (equals(LANDSCAPE_LOWER_CASE) ||
equals(LANDSCAPE_UPPER_CASE) ||
equals(LANDSCAPE_PUNC_NUMBERS));
}

/**
* @return true if this KeyboardType is a portrait keyboard, otherwise false.
*/
public boolean isPortrait() {
return (equals(PORTRAIT_LOWER_CASE) ||
equals(PORTRAIT_UPPER_CASE) ||
equals(PORTRAIT_PUNC_NUMBERS));
}

/**
* @return Offset from the bottom of the screen that the keyboard is rendered
Expand Down

0 comments on commit 9963c1f

Please sign in to comment.