diff --git a/core/src/main/java/com/agifans/agile/GameScreen.java b/core/src/main/java/com/agifans/agile/GameScreen.java index db23a33..64acedc 100644 --- a/core/src/main/java/com/agifans/agile/GameScreen.java +++ b/core/src/main/java/com/agifans/agile/GameScreen.java @@ -278,14 +278,15 @@ private void draw(float delta) { // Render the AGI screen. float cameraXOffset = 0; float cameraYOffset = 0; - float sidePaddingWidth = 0; + float sidePaddingWidth = viewportManager.getSidePaddingWidth(); + if (viewportManager.doesScreenFitWidth()) { // Override default screen centering logic to allow for narrower screens, so // that the joystick can be rendered as a decent size. - float agiScreenWidth = (viewportManager.getHeight() * 1.32f); - float agiWidthRatio = (agiScreenWidth / ADJUSTED_WIDTH); - sidePaddingWidth = ((viewportManager.getWidth() - agiScreenWidth) / 2); - if (sidePaddingWidth < 232) { + float agiWidthRatio = (viewportManager.getAgiScreenWidth() / ADJUSTED_WIDTH); + if ((sidePaddingWidth > 64) && (sidePaddingWidth < 232)) { + // 232 = 2 * min width on sides. + // 64 = when icon on one side is perfectly centred. float unadjustedXOffset = Math.min(232 - sidePaddingWidth, sidePaddingWidth); cameraXOffset = (unadjustedXOffset / agiWidthRatio); if (joystickAlignment.equals(JoystickAlignment.LEFT)) { @@ -342,11 +343,20 @@ private void draw(float delta) { } else { // Landscape 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); + // Middle. + if ((viewportManager.getAgiScreenBase() > 0) || (sidePaddingWidth <= 64)) { + // The area between full landscape and full portrait. + float leftAdjustment = (viewportManager.getWidth() / 4) - 32; + batch.draw(fullScreenIcon, ((viewportManager.getWidth() / 2) - 48) - leftAdjustment, 16); + batch.draw(joystickIcon, ((viewportManager.getWidth() - (viewportManager.getWidth() / 3)) - 64) - leftAdjustment, 16); + batch.draw(keyboardIcon, ((viewportManager.getWidth() - (viewportManager.getWidth() / 6)) - 80) - leftAdjustment, 16); + batch.draw(backIcon, (viewportManager.getWidth() - 112) - leftAdjustment, 16); + } else { + 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); @@ -371,7 +381,7 @@ private void draw(float delta) { if (viewportManager.isPortrait()) { // Top of keyboard is: 765 + 135 = 900. int joyWidth = 200; - int agiScreenBase = (int)(viewportManager.getHeight() - (viewportManager.getWidth() / 1.32)); + int agiScreenBase = viewportManager.getAgiScreenBase(); int midBetweenKeybAndPic = ((agiScreenBase + 900) / 2); portraitTouchpad.setSize(joyWidth, joyWidth); portraitTouchpad.setY(midBetweenKeybAndPic - (joyWidth / 2)); @@ -394,27 +404,40 @@ private void draw(float delta) { joyY = portraitTouchpad.getKnobPercentY(); } else { // Landscape - float joyWidth = Math.min(Math.max((sidePaddingWidth * 2) - 32, 96), 200); - landscapeTouchpad.setSize(joyWidth, joyWidth); - landscapeTouchpad.getStyle().knob.setMinHeight(joyWidth * 0.6f); - landscapeTouchpad.getStyle().knob.setMinWidth(joyWidth * 0.6f); - landscapeTouchpad.setY(viewportManager.getHeight() - (viewportManager.getHeight() / 2) - (joyWidth / 2)); - switch (joystickAlignment) { - case OFF: - break; - case RIGHT: - landscapeTouchpad.setX(1920 - joyWidth - 16); - break; - case MIDDLE: - break; - case LEFT: - landscapeTouchpad.setX(16); - break; + if ((viewportManager.getAgiScreenBase() > 0) || (sidePaddingWidth <= 64)) { + int joyWidth = Math.max(Math.min(140 + viewportManager.getAgiScreenBase(), 216), 140); + landscapeTouchpad.setSize(joyWidth, joyWidth); + landscapeTouchpad.setY(16); + landscapeTouchpad.setX(viewportManager.getWidth() - joyWidth - 16); + landscapeTouchpad.getStyle().knob.setMinHeight(joyWidth * 0.6f); + landscapeTouchpad.getStyle().knob.setMinWidth(joyWidth * 0.6f); + landscapeTouchpadStage.act(delta); + landscapeTouchpadStage.draw(); + joyX = landscapeTouchpad.getKnobPercentX(); + joyY = landscapeTouchpad.getKnobPercentY(); + } else { + float joyWidth = Math.min(Math.max((sidePaddingWidth * 2) - 32, 96), 200); + landscapeTouchpad.setSize(joyWidth, joyWidth); + landscapeTouchpad.getStyle().knob.setMinHeight(joyWidth * 0.6f); + landscapeTouchpad.getStyle().knob.setMinWidth(joyWidth * 0.6f); + landscapeTouchpad.setY(viewportManager.getHeight() - (viewportManager.getHeight() / 2) - (joyWidth / 2)); + switch (joystickAlignment) { + case OFF: + break; + case RIGHT: + landscapeTouchpad.setX(1920 - joyWidth - 16); + break; + case MIDDLE: + break; + case LEFT: + landscapeTouchpad.setX(16); + break; + } + landscapeTouchpadStage.act(delta); + landscapeTouchpadStage.draw(); + joyX = landscapeTouchpad.getKnobPercentX(); + joyY = landscapeTouchpad.getKnobPercentY(); } - landscapeTouchpadStage.act(delta); - landscapeTouchpadStage.draw(); - joyX = landscapeTouchpad.getKnobPercentX(); - joyY = landscapeTouchpad.getKnobPercentY(); } processJoystickInput(joyX, joyY); } diff --git a/core/src/main/java/com/agifans/agile/ui/GameScreenInputProcessor.java b/core/src/main/java/com/agifans/agile/ui/GameScreenInputProcessor.java index 8d12064..e4e29b7 100644 --- a/core/src/main/java/com/agifans/agile/ui/GameScreenInputProcessor.java +++ b/core/src/main/java/com/agifans/agile/ui/GameScreenInputProcessor.java @@ -259,12 +259,21 @@ private boolean updateAGIMouse(Vector2 touchXY, int button, boolean buttonDown) } else { // Landscape - agiY = 200 - Math.round((touchXY.y / viewportManager.getHeight()) * 200); - float agiWidth = (viewportManager.getHeight() * 1.32f); - float agiRatio = (agiWidth / 160); - float agiStart = (1920 / 2) - (agiWidth / 2); - float adjustedCameraXOffset = (cameraXOffset * (agiWidth / 264)); - agiX = (int)(Math.round(((touchXY.x + adjustedCameraXOffset) - agiStart) / agiRatio)); + if ((viewportManager.getAgiScreenBase() > 0) || (viewportManager.getSidePaddingWidth() <= 64)) { + // Landscape/Portrait hybrid mode. + agiX = Math.round((touchXY.x / viewportManager.getWidth()) * 160); + float agiHeight = (1920.0f / 1.32f); + float agiRatio = (agiHeight / 200); + float agiStart = (viewportManager.getHeight() - agiHeight); + agiY = 200 - Math.round((touchXY.y - agiStart) / agiRatio); + } else { + agiY = 200 - Math.round((touchXY.y / viewportManager.getHeight()) * 200); + float agiWidth = (viewportManager.getHeight() * 1.32f); + float agiRatio = (agiWidth / 160); + float agiStart = (1920 / 2) - (agiWidth / 2); + float adjustedCameraXOffset = (cameraXOffset * (agiWidth / 264)); + agiX = (int)(Math.round(((touchXY.x + adjustedCameraXOffset) - agiStart) / agiRatio)); + } } boolean agiMouseUpdated = false; @@ -348,18 +357,43 @@ else if ((touchXY.x > (twoThirdPos - 84)) && (touchXY.x < (twoThirdPos + 42))) { // 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; + if ((viewportManager.getAgiScreenBase() > 0) || (viewportManager.getSidePaddingWidth() <= 64)) { + if (touchXY.y < 104) { + float leftAdjustment = (viewportManager.getWidth() / 4) - 32; + if ((touchXY.x >= ((viewportManager.getWidth() / 2) - 48) - leftAdjustment) && + (touchXY.x <= ((viewportManager.getWidth() / 2) + 48) - leftAdjustment)) { + fullScreenClicked = true; + } + else + if ((touchXY.x >= ((viewportManager.getWidth() - (viewportManager.getWidth() / 3)) - 64) - leftAdjustment) && + (touchXY.x <= ((viewportManager.getWidth() - (viewportManager.getWidth() / 3)) + 32) - leftAdjustment)) { + joystickClicked = true; + } + else + if ((touchXY.x >= ((viewportManager.getWidth() - (viewportManager.getWidth() / 6)) - 80) - leftAdjustment) && + (touchXY.x <= ((viewportManager.getWidth() - (viewportManager.getWidth() / 6)) + 16) - leftAdjustment)) { + keyboardClicked = true; + } + else + if ((touchXY.x >= (viewportManager.getWidth() - 112) - leftAdjustment) && + (touchXY.x <= (viewportManager.getWidth() - 16) - leftAdjustment)) { + backArrowClicked = true; + } } - } else if (touchXY.y < 104) { - if (touchXY.x > (viewportManager.getWidth() - 112)) { - backArrowClicked = true; - } else if (touchXY.x < 112) { - keyboardClicked = true; + } else { + // 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; + } } } } @@ -395,8 +429,15 @@ else if ((touchXY.y > 0) && (touchXY.y < 128)) { if (joystickClicked) { // Rotate the joystick screen alignment. joystickAlignment = joystickAlignment.rotateValue(); - if (!viewportManager.isPortrait() && joystickAlignment.equals(JoystickAlignment.MIDDLE)) { - joystickAlignment = joystickAlignment.rotateValue(); + if (!viewportManager.isPortrait()) { + if (joystickAlignment.equals(JoystickAlignment.MIDDLE)) { + joystickAlignment = joystickAlignment.rotateValue(); + } + if ((viewportManager.getAgiScreenBase() > 0) || (viewportManager.getSidePaddingWidth() <= 64)) { + if (joystickAlignment.equals(JoystickAlignment.LEFT)) { + joystickAlignment = joystickAlignment.rotateValue(); + } + } } } diff --git a/core/src/main/java/com/agifans/agile/ui/KeyboardType.java b/core/src/main/java/com/agifans/agile/ui/KeyboardType.java index 1746cd4..4c21ee2 100644 --- a/core/src/main/java/com/agifans/agile/ui/KeyboardType.java +++ b/core/src/main/java/com/agifans/agile/ui/KeyboardType.java @@ -232,7 +232,7 @@ public float getHeight() { return texture.getHeight(); } else { ViewportManager viewportManager = ViewportManager.getInstance(); - int keyboardHeight = viewportManager.getScreenBase() - getRenderOffset(); + int keyboardHeight = viewportManager.getAgiScreenBase() - getRenderOffset(); return Math.max(Math.min(keyboardHeight, texture.getHeight()), 365); } } @@ -313,7 +313,16 @@ public boolean isPortrait() { * at. */ public int getRenderOffset() { - return renderOffset; + if (isLandscape()) { + ViewportManager viewportManager = ViewportManager.getInstance(); + if (viewportManager.getAgiScreenBase() > 0) { + return 135; + } else { + return renderOffset; + } + } else { + return renderOffset; + } } /** diff --git a/core/src/main/java/com/agifans/agile/ui/ViewportManager.java b/core/src/main/java/com/agifans/agile/ui/ViewportManager.java index 98680ef..9f482c7 100644 --- a/core/src/main/java/com/agifans/agile/ui/ViewportManager.java +++ b/core/src/main/java/com/agifans/agile/ui/ViewportManager.java @@ -76,9 +76,6 @@ public void update(int width, int height) { // 1.13 when icons are no longer overlapping // 1.00 square // 0.80 where keyboard top matches screen base - //portrait = (height > (width / 1.32f)); - //portrait = (height > (width / 1.00f)); - portrait = (height > (width / 0.80f)); getCurrentViewport().update(width, height, true); @@ -109,11 +106,45 @@ public boolean isLandscape() { return !portrait; } + /** + * Tests where the AGI screen exactly fits the width of the viewport. + * + * @return + */ public boolean doesScreenFitWidth() { return !(getHeight() > (getWidth() / 1.32f)); } - public int getScreenBase() { + /** + * Calculates and returns the width of the AGI screen using the current + * viewport height. + * + * @return + */ + public float getAgiScreenWidth() { + return (getHeight() * 1.32f); + } + + /** + * Calculates and returns the width of the padding either side of the AGI + * screen, when in landscape mode. + * + * @return The width of the padding either side of the AGI screen. + */ + public float getSidePaddingWidth() { + float sidePaddingWidth = 0; + if (doesScreenFitWidth()) { + sidePaddingWidth = ((getWidth() - getAgiScreenWidth()) / 2); + } + return sidePaddingWidth; + } + + /** + * Gets the Y value of the base of the AGI screen. + * + * @return The Y value of the base of the AGI screen. + */ + public int getAgiScreenBase() { return (int)(getHeight() - (getWidth() / 1.32)); }