Search in sources :

Example 6 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project Entitas-Java by Rubentxu.

the class GuiFactory method createTouchPad.

public Touchpad createTouchPad(float width, float height, InputEntity player) {
    Touchpad touchpad = new Touchpad(10 * ScaleUtil.getSizeRatio(), skin);
    touchpad.setPosition(25 * ScaleUtil.getSizeRatio(), 15);
    touchpad.setWidth(width);
    touchpad.setHeight(height);
    PlayerInputController stateController = player.getPlayerInputController();
    touchpad.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            System.out.println("PercentX " + ((Touchpad) actor).getKnobPercentX() + "PercentY " + ((Touchpad) actor).getKnobPercentY());
            if (((Touchpad) actor).getKnobPercentX() == 0 || ((Touchpad) actor).getKnobPercentX() < 0.5 && ((Touchpad) actor).getKnobPercentX() > -0.5) {
                //                    controller.rightReleased();
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, false, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentX() > 0.5) {
                //                    controller.rightPressed();
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, true, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentX() < -0.5) {
                //                    controller.leftPressed();
                //                    controller.rightReleased();
                player.replacePlayerInputController(true, false, stateController.jumpPressed);
            }
            if (((Touchpad) actor).getKnobPercentY() > 0.5) {
                //                    controller.jumpPressed();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
            } else {
                //                    controller.jumpReleased();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
            }
        }
    });
    return touchpad;
}
Also used : PlayerInputController(com.indignado.games.states.game.component.input.PlayerInputController) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 7 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project AmazingMaze by TheVirtualMachine.

the class FishMiniGame method dialog.

/**
	 * Displays the results dialog.
	 */
public void dialog() {
    message = formatString(answerField.getText());
    Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
    final Dialog dialog = new Dialog("Results", game.assets.skin);
    final TextButton okButton = new TextButton("OK", game.assets.skin);
    dialog.getButtonTable().bottom();
    if (checkAnswer() == -1) {
        Label label = new Label("Invalid answer. Please try again.", labelStyle);
        label.setScale(.5f);
        label.setWrap(true);
        label.setAlignment(Align.center);
        dialog.add(label).width(500).pad(50);
        dialog.add(okButton).bottom();
        okButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (okButton.isPressed()) {
                    dialog.hide();
                    canvas.setColor(drawColor);
                }
            }
        });
        dialog.addListener(new InputListener() {

            @Override
            public boolean keyDown(InputEvent event, int keycode) {
                if (keycode == Keys.ENTER) {
                    dialog.hide();
                    return true;
                }
                return false;
            }
        });
    } else {
        Label label = new Label("Your answer was: " + message + ". " + "The correct answer was: " + answer + ". " + "You get " + checkAnswer() + " back!", labelStyle);
        game.save.addScore(checkAnswer());
        game.save.setLives(player.getLives());
        label.setScale(.5f);
        label.setWrap(true);
        label.setAlignment(Align.center);
        dialog.add(label).width(500).pad(50);
        dialog.add(okButton).bottom();
        okButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (okButton.isPressed()) {
                    dialog.cancel();
                    if ((game.save.getLevel() - 1) % 5 == 0) {
                        game.setScreen(new ContinueScreen(game, true));
                    } else {
                        game.setScreen(new MazeScreen(game, false));
                    }
                }
            }
        });
        dialog.addListener(new InputListener() {

            @Override
            public boolean keyDown(InputEvent event, int keycode) {
                if (keycode == Keys.ENTER) {
                    if ((game.save.getLevel() - 1) % 5 == 0) {
                        game.setScreen(new ContinueScreen(game, true));
                    } else {
                        game.setScreen(new MazeScreen(game, false));
                    }
                    return true;
                }
                return false;
            }
        });
    }
    dialog.show(stage);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 8 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project AmazingMaze by TheVirtualMachine.

the class ContinueScreen method highScoreDialog.

/**
	 * Displays the high score dialog.
	 */
public void highScoreDialog() {
    Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
    final Dialog dialog = new Dialog("High Score", game.assets.skin);
    final TextButton okButton = new TextButton("OK", game.assets.skin);
    dialog.getButtonTable().bottom();
    Label label = new Label("Enter your name:", labelStyle);
    label.setScale(.5f);
    label.setWrap(true);
    label.setAlignment(Align.center);
    final TextField nameField = new TextField("", game.assets.skin);
    dialog.add(label).width(500).pad(50);
    dialog.add(nameField);
    dialog.add(okButton).bottom();
    nameField.setTextFieldListener(new TextFieldListener() {

        @Override
        public void keyTyped(TextField textField, char key) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (key == (char) 13) {
                    displayHighScores(name);
                }
            }
        }
    });
    okButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (okButton.isPressed()) {
                    dialog.hide();
                    displayHighScores(name);
                }
            }
        }
    });
    dialog.addListener(new InputListener() {

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (keycode == Keys.ENTER) {
                    displayHighScores(name);
                    return true;
                }
            }
            return false;
        }
    });
    dialog.show(stage);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 9 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project AmazingMaze by TheVirtualMachine.

the class MazeScreen method setupPauseMenu.

/** Create the pause menu. */
private void setupPauseMenu() {
    pauseMenu = new Stage(new ScreenViewport(), game.batch);
    Table table = new Table();
    table.setFillParent(true);
    table.center();
    pauseMenu.addActor(table);
    TextButton resumeButton = new TextButton("Resume", game.assets.skin);
    resumeButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            paused = false;
        }
    });
    table.add(resumeButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
    table.row();
    TextButton settingsButton = new TextButton("Settings", game.assets.skin);
    final Screen sourceScreen = this;
    settingsButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            game.settingsScreen.setSourceScreen(sourceScreen);
            game.setScreen(game.settingsScreen);
        }
    });
    table.add(settingsButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
    table.row();
    TextButton quitButton = new TextButton("Main Menu", game.assets.skin);
    quitButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            game.setScreen(game.menuScreen);
        }
    });
    table.add(quitButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Screen(com.badlogic.gdx.Screen) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport)

Example 10 with ChangeListener

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project AmazingMaze by TheVirtualMachine.

the class StoryScreen method setupUI.

/** Helper method to setup the UI. */
private void setupUI() {
    stage = new Stage(new ScreenViewport(), game.batch);
    table = new Table();
    table.top().center();
    table.setFillParent(true);
    stage.addActor(table);
    header = new Label("Story", game.assets.skin, Assets.SERIF_HEADER_STYLE);
    table.add(header).padTop(Gdx.graphics.getHeight() / 25f);
    storyLabel = new Label(readStory(), game.assets.skin, Assets.STORY_STYLE);
    storyLabel.setWrap(true);
    table.row();
    table.add(storyLabel).maxWidth(Gdx.graphics.getWidth()).prefWidth(Gdx.graphics.getWidth() / 1.125f).pad(Gdx.graphics.getHeight() / 25f);
    continueButton = new TextButton("Continue...", game.assets.skin);
    continueButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (continueButton.isPressed()) {
                game.setScreen(new MazeScreen(game, false));
            }
        }
    });
    table.row();
    table.add(continueButton).width(Gdx.graphics.getWidth() / 4f).pad(Gdx.graphics.getHeight() / 25f).expandY().bottom().fillY();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)26 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)26 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)18 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)16 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)14 Stage (com.badlogic.gdx.scenes.scene2d.Stage)13 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)9 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)6 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)6 Texture (com.badlogic.gdx.graphics.Texture)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)5 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)5 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)5 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)5 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)4 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)4 FileHandle (com.badlogic.gdx.files.FileHandle)3