Search in sources :

Example 26 with InputEvent

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

the class GuiFactory method createPadButtons.

public Table createPadButtons(float width, float height, InputEntity player) {
    Table tableControlPad = new Table();
    PlayerInputController stateController = player.getPlayerInputController();
    tableControlPad.row().height(height);
    ImageButton btnLeft = new ImageButton(skin, "buttonLeft");
    tableControlPad.add(btnLeft).width(width).expandY().fill();
    btnLeft.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchDown(event, x, y, pointer, button);
            //                controller.leftPressed();
            //                controller.rightReleased();
            player.replacePlayerInputController(true, false, stateController.jumpPressed);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchUp(event, x, y, pointer, button);
            //                controller.leftReleased();
            player.replacePlayerInputController(false, stateController.rightPressed, stateController.jumpPressed);
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            System.out.println("Event- " + event.getType());
            super.touchDragged(event, x, y, pointer);
            if (isOver(event.getListenerActor(), x, y)) {
                //                    controller.rightReleased();
                //                    controller.leftPressed();
                player.replacePlayerInputController(true, false, stateController.jumpPressed);
            } else {
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, stateController.rightPressed, stateController.jumpPressed);
            }
        }
    });
    ImageButton btnRight = new ImageButton(skin, "buttonRight");
    tableControlPad.add(btnRight).width(width).expandY().fill().padRight((width) * 2);
    btnRight.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchDown(event, x, y, pointer, button);
            //                controller.leftReleased();
            //                controller.rightPressed();
            player.replacePlayerInputController(false, true, stateController.jumpPressed);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchUp(event, x, y, pointer, button);
            //                controller.rightReleased();
            player.replacePlayerInputController(stateController.leftPressed, false, stateController.jumpPressed);
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            System.out.println("Event- " + event.getType());
            super.touchDragged(event, x, y, pointer);
            if (isOver(event.getListenerActor(), x, y)) {
                //                    controller.rightPressed();
                //                    controller.leftReleased();
                player.replacePlayerInputController(false, true, stateController.jumpPressed);
            } else {
                //                    controller.rightReleased();
                player.replacePlayerInputController(stateController.leftPressed, false, stateController.jumpPressed);
            }
        }
    });
    ImageButton btnUP = new ImageButton(skin, "buttonUp");
    tableControlPad.add(btnUP).width(width).expandY().fill();
    btnUP.addListener(new ClickListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchDown(event, x, y, pointer, button);
            //                controller.jumpPressed();
            player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("Event " + event.getType());
            super.touchUp(event, x, y, pointer, button);
            //                controller.jumpReleased();
            player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            System.out.println("Event- " + event.getType());
            super.touchDragged(event, x, y, pointer);
            if (isOver(event.getListenerActor(), x, y)) {
                //                    controller.jumpPressed();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
            } else {
                //                    controller.jumpReleased();
                player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
            }
        }
    });
    tableControlPad.setBounds(0, 0, Gdx.graphics.getWidth(), height + 10);
    return tableControlPad;
}
Also used : PlayerInputController(com.indignado.games.states.game.component.input.PlayerInputController) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)26 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)17 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)16 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)16 Stage (com.badlogic.gdx.scenes.scene2d.Stage)15 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)13 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)10 Actor (com.badlogic.gdx.scenes.scene2d.Actor)9 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)7 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Texture (com.badlogic.gdx.graphics.Texture)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)3 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)3 List (com.badlogic.gdx.scenes.scene2d.ui.List)3 TextButtonStyle (com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle)3 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)3 Batch (com.badlogic.gdx.graphics.g2d.Batch)2