Skip to content

Commit

Permalink
Changed width of the virtual keyboard in landscape mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanceewing committed Mar 17, 2024
1 parent fb3e72e commit f101a7e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 54 deletions.
Binary file modified assets/png/landscape_keyboard_lowercase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/png/landscape_keyboard_punc_numbers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/png/landscape_keyboard_uppercase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 23 additions & 38 deletions core/src/main/java/com/agifans/agile/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,34 +286,32 @@ private void draw(float delta) {
batch.draw(keyboardType.getTexture(), 0, keyboardType.getRenderOffset());
}

//else if (keyboardType.equals(KeyboardType.OFF)) {
// The keyboard and joystick icons are rendered only when an input type isn't
// showing.
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);
}
// The keyboard and joystick icons are rendered only when an input type isn't
// showing.
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 {
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);

// 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);
}
//}

} 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 All @@ -322,25 +320,12 @@ private void draw(float delta) {
float joyX = 0;
float joyY = 0;
if (viewportManager.isPortrait()) {
//if (joystickPosition != null) {
// portraitTouchpad.setX(joystickPosition.x);
// portraitTouchpad.setY(joystickPosition.y);
//} else {
portraitTouchpad.setY(0);
//}
portraitTouchpad.setY(viewportManager.getHeight() - 1050);
portraitTouchpadStage.act(delta);
portraitTouchpadStage.draw();
joyX = portraitTouchpad.getKnobPercentX();
joyY = portraitTouchpad.getKnobPercentY();
} else {
//landscapeTouchpad.setY(0);
//if (joystickPosition != null) {
// landscapeTouchpad.setX(joystickPosition.x);
// landscapeTouchpad.setY(joystickPosition.y);
//} else {
landscapeTouchpad.setY(0);
//}
landscapeTouchpad.setY(viewportManager.getHeight() - (viewportManager.getHeight() / 2) - 75);
landscapeTouchpadStage.act(delta);
landscapeTouchpadStage.draw();
Expand Down
36 changes: 20 additions & 16 deletions core/src/main/java/com/agifans/agile/ui/KeyboardType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public enum KeyboardType {
},
"png/landscape_keyboard_lowercase.png",
0.4f,
150,
145,
0,
5,
1911,
176,
1568,
0
),
LANDSCAPE_UPPER_CASE(
Expand All @@ -38,10 +38,10 @@ public enum KeyboardType {
},
"png/landscape_keyboard_uppercase.png",
0.4f,
150,
145,
0,
5,
1911,
176,
1568,
0
),
LANDSCAPE_PUNC_NUMBERS(
Expand All @@ -54,10 +54,10 @@ public enum KeyboardType {
},
"png/landscape_keyboard_punc_numbers.png",
0.4f,
150,
145,
0,
5,
1911,
176,
1568,
0
),
PORTRAIT_LOWER_CASE(
Expand All @@ -70,7 +70,7 @@ public enum KeyboardType {
},
"png/portrait_keyboard_lowercase.png",
0.6f,
150,
145,
0,
1,
-1,
Expand All @@ -86,7 +86,7 @@ public enum KeyboardType {
},
"png/portrait_keyboard_uppercase.png",
0.6f,
150,
145,
0,
1,
-1,
Expand All @@ -102,7 +102,7 @@ public enum KeyboardType {
},
"png/portrait_keyboard_punc_numbers.png",
0.6f,
150,
145,
0,
1,
-1,
Expand Down Expand Up @@ -156,6 +156,11 @@ public enum KeyboardType {
*/
private int yStart;

/**
* The width of the active part of the keyboard image, or -1 to deduce from texture width and xStart.
*/
private int activeWidth;

/**
* Constructor for KeyboardType.
*
Expand Down Expand Up @@ -188,6 +193,7 @@ public enum KeyboardType {
this.opacity = opacity;
this.renderOffset = renderOffset;
this.closeHeight = this.texture.getHeight() + renderOffset + closeBuffer;
this.activeWidth = activeWidth;
}

/**
Expand Down Expand Up @@ -247,10 +253,8 @@ public Integer getKeyCode(float x, float y) {
public boolean isInKeyboard(float x, float y) {
if (isRendered()) {
boolean isInYBounds = (y < (texture.getHeight() + renderOffset) && (y > renderOffset));

// In this case, we only need to test the Y position since the keyboard image
// will span the whole width.
return isInYBounds;
boolean isInXBounds = ((x >= xStart) && (x < (xStart + activeWidth)));
return isInYBounds && isInXBounds;

} else {
// isInKeyboard only applies to rendered keyboards.
Expand Down

0 comments on commit f101a7e

Please sign in to comment.