diff --git a/core/src/main/java/com/agifans/agile/GameScreen.java b/core/src/main/java/com/agifans/agile/GameScreen.java index ccf8e33..33545f6 100644 --- a/core/src/main/java/com/agifans/agile/GameScreen.java +++ b/core/src/main/java/com/agifans/agile/GameScreen.java @@ -3,6 +3,7 @@ import com.agifans.agile.config.AppConfigItem; import com.agifans.agile.ui.DialogHandler; import com.agifans.agile.ui.GameScreenInputProcessor; +import com.agifans.agile.ui.KeyboardType; import com.agifans.agile.ui.ViewportManager; import com.badlogic.gdx.Application.ApplicationType; import com.badlogic.gdx.Gdx; @@ -70,8 +71,8 @@ public class GameScreen implements Screen { private ViewportManager viewportManager; // Touchpad - private Stage portraitStage; - private Stage landscapeStage; + private Stage portraitTouchpadStage; + private Stage landscapeTouchpadStage; private Touchpad portraitTouchpad; private Touchpad landscapeTouchpad; @@ -118,20 +119,20 @@ public GameScreen(Agile agile, AgileRunner agileRunner, DialogHandler dialogHand viewportManager = ViewportManager.getInstance(); // Create a Stage and add TouchPad - portraitStage = new Stage(viewportManager.getPortraitViewport(), batch); - portraitStage.addActor(portraitTouchpad); - landscapeStage = new Stage(viewportManager.getLandscapeViewport(), batch); - landscapeStage.addActor(landscapeTouchpad); + portraitTouchpadStage = new Stage(viewportManager.getPortraitViewport(), batch); + portraitTouchpadStage.addActor(portraitTouchpad); + landscapeTouchpadStage = new Stage(viewportManager.getLandscapeViewport(), batch); + landscapeTouchpadStage.addActor(landscapeTouchpad); // Create and register an input processor for keys, etc. gameScreenInputProcessor = new GameScreenInputProcessor(this, dialogHandler); portraitInputProcessor = new InputMultiplexer(); portraitInputProcessor.addProcessor(agileRunner.userInput); - portraitInputProcessor.addProcessor(portraitStage); + portraitInputProcessor.addProcessor(portraitTouchpadStage); portraitInputProcessor.addProcessor(gameScreenInputProcessor); landscapeInputProcessor = new InputMultiplexer(); landscapeInputProcessor.addProcessor(agileRunner.userInput); - landscapeInputProcessor.addProcessor(landscapeStage); + landscapeInputProcessor.addProcessor(landscapeTouchpadStage); landscapeInputProcessor.addProcessor(gameScreenInputProcessor); } @@ -256,8 +257,8 @@ public void render(float delta) { } private void draw(float delta) { - // Get the KeyboardType currently being used by the MachineScreenProcessor. - //KeyboardType keyboardType = machineInputProcessor.getKeyboardType(); + // Get the KeyboardType currently being used by the GameScreenInputProcessor. + KeyboardType keyboardType = gameScreenInputProcessor.getKeyboardType(); Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); @@ -282,19 +283,10 @@ private void draw(float delta) { batch.enableBlending(); batch.begin(); - // TODO: Implement joystick being active. - //if (keyboardType.equals(KeyboardType.JOYSTICK)) { - // if (viewportManager.isPortrait()) { - // // batch.draw(keyboardType.getTexture(KeyboardType.LEFT), 0, 0); - // batch.draw(keyboardType.getTexture(KeyboardType.RIGHT), viewportManager.getWidth() - 135, 0); - // } else { - // // batch.draw(keyboardType.getTexture(KeyboardType.LEFT), 0, 0, 201, 201); - // batch.draw(keyboardType.getTexture(KeyboardType.RIGHT), viewportManager.getWidth() - 135, 0); - // } - //} else if (keyboardType.isRendered()) { - // batch.setColor(c.r, c.g, c.b, keyboardType.getOpacity()); - // batch.draw(keyboardType.getTexture(), 0, keyboardType.getRenderOffset()); - //} else if (keyboardType.equals(KeyboardType.OFF)) { + if (keyboardType.isRendered()) { + batch.setColor(c.r, c.g, c.b, keyboardType.getOpacity()); + 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); @@ -321,25 +313,26 @@ private void draw(float delta) { batch.draw(keyboardIcon, 0, 0); } - //} + } batch.end(); - // if (keyboardType.equals(KeyboardType.JOYSTICK)) { - // float joyX = 0; - // float joyY = 0; - // if (viewportManager.isPortrait()) { - // portraitStage.act(delta); - // portraitStage.draw(); - // joyX = portraitTouchpad.getKnobPercentX(); - // joyY = portraitTouchpad.getKnobPercentY(); - // } else { - // landscapeStage.act(delta); - // landscapeStage.draw(); - // joyX = landscapeTouchpad.getKnobPercentX(); - // joyY = landscapeTouchpad.getKnobPercentY(); - // } - // machine.getJoystick().touchPad(joyX, joyY); - // } + if (gameScreenInputProcessor.isJoystickActive()) { + float joyX = 0; + float joyY = 0; + if (viewportManager.isPortrait()) { + portraitTouchpadStage.act(delta); + portraitTouchpadStage.draw(); + joyX = portraitTouchpad.getKnobPercentX(); + joyY = portraitTouchpad.getKnobPercentY(); + } else { + landscapeTouchpadStage.act(delta); + landscapeTouchpadStage.draw(); + joyX = landscapeTouchpad.getKnobPercentX(); + joyY = landscapeTouchpad.getKnobPercentY(); + } + // TODO: Apply movement + //machine.getJoystick().touchPad(joyX, joyY); + } } @Override 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 30725f1..8fb99e3 100644 --- a/core/src/main/java/com/agifans/agile/ui/GameScreenInputProcessor.java +++ b/core/src/main/java/com/agifans/agile/ui/GameScreenInputProcessor.java @@ -24,6 +24,11 @@ public class GameScreenInputProcessor extends InputAdapter { */ private KeyboardType keyboardType; + /** + * Whether the joystick is active or not. + */ + private boolean joystickActive; + /** * 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. @@ -110,6 +115,8 @@ public GameScreenInputProcessor(GameScreen gameScreen, DialogHandler dialogHandl * @return whether the input was processed */ public boolean touchDown(int screenX, int screenY, int pointer, int button) { + System.out.println("touchDown: screenX=" + screenX + ", screenY=" + screenY); + // Convert the screen coordinates to world coordinates. Vector2 touchXY = viewportManager.unproject(screenX, screenY); @@ -191,6 +198,8 @@ private void updateAGIMouse(Vector2 touchXY, int button, boolean buttonDown) { * @return whether the input was processed */ public boolean touchUp(int screenX, int screenY, int pointer, int button) { + System.out.println("touchUp: screenX=" + screenX + ", screenY=" + screenY); + // Convert the screen coordinates to world coordinates. Vector2 touchXY = viewportManager.unproject(screenX, screenY); @@ -288,7 +297,7 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) { } if (joystickClicked) { - keyboardType = KeyboardType.JOYSTICK; + joystickActive = !joystickActive; } if (fullScreenClicked) { @@ -347,6 +356,8 @@ public boolean mouseMoved (int screenX, int screenY) { * @return whether the input was processed */ public boolean touchDragged(int screenX, int screenY, int pointer) { + System.out.println("touchDragged: screenX=" + screenX + ", screenY=" + screenY); + // Convert the screen coordinates to world coordinates. Vector2 touchXY = viewportManager.unproject(screenX, screenY); @@ -390,7 +401,7 @@ public boolean touchDragged(int screenX, int screenY, int pointer) { * @param height The new screen height. */ public void resize(int width, int height) { - if (keyboardType.isRendered() && !keyboardType.equals(KeyboardType.JOYSTICK)) { + if (keyboardType.isRendered()) { // Switch keyboard layout based on the orientation. keyboardType = (height > width ? KeyboardType.PORTRAIT : KeyboardType.LANDSCAPE); } @@ -404,4 +415,13 @@ public void resize(int width, int height) { public KeyboardType getKeyboardType() { return keyboardType; } + + /** + * Returns whether the joystick is active or not. + * + * @return whether the joystick is active or not. + */ + public boolean isJoystickActive() { + return joystickActive; + } }