Example usage for com.badlogic.gdx.scenes.scene2d.ui Touchpad Touchpad

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Touchpad Touchpad

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Touchpad Touchpad.

Prototype

public Touchpad(float deadzoneRadius, TouchpadStyle style) 

Source Link

Usage

From source file:com.dongbat.game.system.GameStageSystem.java

@Override
protected void initialize() {
    Viewport viewport = stage.getViewport();
    float worldHeight = viewport.getWorldHeight();
    float worldWidth = viewport.getWorldWidth();
    float width = worldWidth / 60;
    float height = worldHeight / 60;

    buttonFleeAbility = new AbilityButton("Flee", skin, "flee");
    buttonFleeAbility.setSize(width * 7, width * 7);
    buttonFleeAbility.setPosition(worldWidth - width * 7, height * 2);
    buttonBlowAbility = new AbilityButton("HotBlow", skin, "blow");
    buttonBlowAbility.setSize(width * 7, width * 7);
    buttonBlowAbility.setPosition(worldWidth - width * 7, height * 2 + width * 7);
    buttonSplitAbility = new AbilityButton("SplitAndJoin", skin, "split");
    buttonSplitAbility.setSize(width * 7, width * 7);
    buttonSplitAbility.setPosition(worldWidth - width * 7, height * 2 + width * 14);
    buttonVacuumAbility = new AbilityButton("Vacuum", skin, "vacuum");
    buttonVacuumAbility.setSize(width * 7, width * 7);
    buttonVacuumAbility.setPosition(worldWidth - width * 7, height * 2 + width * 21);

    //    title.setPosition(worldWidth - width * 30, worldHeight - height * 2);
    Touchpad.TouchpadStyle touchpadStyle = new Touchpad.TouchpadStyle(skin.get(Touchpad.TouchpadStyle.class));
    SpriteDrawable bg = new SpriteDrawable(new Sprite(AssetUtil.joyBg));
    bg.setMinWidth(worldHeight / 2.5f);//w  w  w  . j  a v  a2  s . c  om
    bg.setMinHeight(worldHeight / 2.5f);
    touchpadStyle.background = bg;

    SpriteDrawable knob = new SpriteDrawable(new Sprite(AssetUtil.joyKnob));
    knob.setMinWidth(worldHeight / 5f);
    knob.setMinHeight(worldHeight / 5f);
    touchpadStyle.knob = knob;

    touchpad = new Touchpad(10, touchpadStyle);
    touchpad.setBounds(15, 15, 200, 200);

    touchpad.setSize(worldHeight / 2.5f, worldHeight / 2.5f);

    stage.addActor(touchpad);
    stage.addActor(buttonVacuumAbility);
    stage.addActor(buttonSplitAbility);
    stage.addActor(buttonBlowAbility);
    stage.addActor(buttonFleeAbility);
    //    stage.addActor(title);
    InputUtil.addProcessor(stage, 0);
}

From source file:com.ray3k.skincomposer.RootTable.java

License:Open Source License

public void refreshPreview() {
    if (previewTable != null) {
        previewTable.clear();/*from  w  w  w  .j a va 2  s.  c  om*/
        previewTable.setColor((Color) previewProperties.get("bgcolor"));

        for (BitmapFont font : previewFonts) {
            font.dispose();
        }

        if (classSelectBox.getSelectedIndex() >= 0) {
            StyleData styleData = getSelectedStyle();
            Class clazz = Main.BASIC_CLASSES[classSelectBox.getSelectedIndex()];

            if (!styleData.hasMandatoryFields()) {
                Label label;
                if (clazz.equals(SelectBox.class)) {
                    label = new Label(
                            "Please fill all mandatory fields\n(Highlighted on the left)\n\nscrollStyle and listStyle\nmust already be defined",
                            getSkin());
                } else if (clazz.equals(TextTooltip.class)) {
                    label = new Label(
                            "Please fill all mandatory fields\n(Highlighted on the left)\n\nlabel must already be defined",
                            getSkin());
                } else {
                    label = new Label("Please fill all mandatory fields\n(Highlighted on the left)", getSkin());
                }
                label.setAlignment(Align.center);
                previewTable.add(label);
            } else if (styleData.hasAllNullFields()) {
                Label label;
                label = new Label(
                        "All fields are empty!\nEmpty classes are not exported\nAdd style properties in the menu to the left",
                        getSkin());
                label.setAlignment(Align.center);
                previewTable.add(label);
            } else {
                Actor widget = null;
                if (clazz.equals(Button.class)) {
                    Button.ButtonStyle style = createPreviewStyle(Button.ButtonStyle.class, styleData);
                    widget = new Button(style);
                    ((Button) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(CheckBox.class)) {
                    CheckBox.CheckBoxStyle style = createPreviewStyle(CheckBox.CheckBoxStyle.class, styleData);
                    widget = new CheckBox("", style);
                    ((CheckBox) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((CheckBox) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ImageButton.class)) {
                    ImageButtonStyle style = createPreviewStyle(ImageButtonStyle.class, styleData);
                    widget = new ImageButton(style);
                    ((ImageButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ImageTextButton.class)) {
                    ImageTextButton.ImageTextButtonStyle style = createPreviewStyle(
                            ImageTextButton.ImageTextButtonStyle.class, styleData);
                    widget = new ImageTextButton("", style);
                    ((ImageTextButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((ImageTextButton) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Label.class)) {
                    LabelStyle style = createPreviewStyle(LabelStyle.class, styleData);
                    widget = new Label("", style);
                    ((Label) widget).setText((String) previewProperties.get("text"));
                } else if (clazz.equals(List.class)) {
                    ListStyle style = createPreviewStyle(ListStyle.class, styleData);
                    widget = new List(style);
                    Array<String> items = new Array<>(((String) previewProperties.get("text")).split("\\n"));
                    ((List) widget).setItems(items);
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ProgressBar.class)) {
                    ProgressBar.ProgressBarStyle style = createPreviewStyle(ProgressBar.ProgressBarStyle.class,
                            styleData);
                    widget = new ProgressBar((float) (double) previewProperties.get("minimum"),
                            (float) (double) previewProperties.get("maximum"),
                            (float) (double) previewProperties.get("increment"),
                            (boolean) previewProperties.get("orientation"), style);
                    ((ProgressBar) widget).setValue((float) (double) previewProperties.get("value"));
                    ((ProgressBar) widget).setDisabled((boolean) previewProperties.get("disabled"));
                } else if (clazz.equals(ScrollPane.class)) {
                    ScrollPaneStyle style = createPreviewStyle(ScrollPaneStyle.class, styleData);
                    Label label = new Label("", getSkin());
                    widget = new ScrollPane(label, style);
                    ((ScrollPane) widget)
                            .setScrollbarsOnTop((boolean) previewProperties.get("scrollbarsOnTop"));
                    ((ScrollPane) widget).setScrollBarPositions(
                            (boolean) previewProperties.get("hScrollBarPosition"),
                            (boolean) previewProperties.get("vScrollBarPosition"));
                    ((ScrollPane) widget).setScrollingDisabled(
                            (boolean) previewProperties.get("hScrollDisabled"),
                            (boolean) previewProperties.get("vScrollDisabled"));
                    ((ScrollPane) widget).setForceScroll((boolean) previewProperties.get("forceHscroll"),
                            (boolean) previewProperties.get("forceVscroll"));
                    ((ScrollPane) widget)
                            .setVariableSizeKnobs((boolean) previewProperties.get("variableSizeKnobs"));
                    ((ScrollPane) widget).setOverscroll((boolean) previewProperties.get("hOverscroll"),
                            (boolean) previewProperties.get("vOverscroll"));
                    ((ScrollPane) widget).setFadeScrollBars((boolean) previewProperties.get("fadeScroll"));
                    ((ScrollPane) widget).setSmoothScrolling((boolean) previewProperties.get("smoothScroll"));
                    ((ScrollPane) widget).setFlickScroll((boolean) previewProperties.get("flickScroll"));
                    ((ScrollPane) widget).setClamp((boolean) previewProperties.get("clamp"));
                    label.setText((String) previewProperties.get("text"));
                } else if (clazz.equals(SelectBox.class)) {
                    SelectBox.SelectBoxStyle style = createPreviewStyle(SelectBox.SelectBoxStyle.class,
                            styleData);
                    widget = new SelectBox(style);
                    ((SelectBox) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    Array<String> items = new Array<>(((String) previewProperties.get("text")).split("\\n"));
                    ((SelectBox) widget).setItems(items);
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Slider.class)) {
                    Slider.SliderStyle style = createPreviewStyle(Slider.SliderStyle.class, styleData);
                    widget = new Slider((float) (double) previewProperties.get("minimum"),
                            (float) (double) previewProperties.get("maximum"),
                            (float) (double) previewProperties.get("increment"),
                            (boolean) previewProperties.get("orientation"), style);
                    ((Slider) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(SplitPane.class)) {
                    SplitPane.SplitPaneStyle style = createPreviewStyle(SplitPane.SplitPaneStyle.class,
                            styleData);
                    Label label1 = new Label("", getSkin());
                    Label label2 = new Label("", getSkin());
                    widget = new SplitPane(label1, label2, (boolean) previewProperties.get("orientation"),
                            style);
                    label1.setText((String) previewProperties.get("text"));
                    label2.setText((String) previewProperties.get("text"));

                    if ((boolean) previewProperties.get("orientation")) {
                        widget.addListener(vSplitPaneDragListener);
                        widget.addListener(vSplitPaneInputListener);
                    } else {
                        widget.addListener(hSplitPaneDragListener);
                        widget.addListener(hSplitPaneInputListener);
                    }
                } else if (clazz.equals(TextButton.class)) {
                    TextButtonStyle style = createPreviewStyle(TextButtonStyle.class, styleData);
                    widget = new TextButton("", style);
                    ((TextButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((TextButton) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(TextField.class)) {
                    TextFieldStyle style = createPreviewStyle(TextFieldStyle.class, styleData);
                    widget = new TextField("", style);
                    ((TextField) widget).setFocusTraversal(false);
                    ((TextField) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((TextField) widget).setPasswordMode((boolean) previewProperties.get("passwordMode"));
                    ((TextField) widget).setAlignment((int) previewProperties.get("alignment"));
                    ((TextField) widget).setText((String) previewProperties.get("text"));
                    ((TextField) widget).setMessageText((String) previewProperties.get("message"));
                    String string = (String) previewProperties.get("password");
                    if (string.length() > 0) {
                        ((TextField) widget).setPasswordCharacter(string.charAt(0));
                    }
                    widget.addListener(main.getIbeamListener());
                } else if (clazz.equals(TextTooltip.class)) {
                    TextTooltip.TextTooltipStyle style = createPreviewStyle(TextTooltip.TextTooltipStyle.class,
                            styleData);

                    TooltipManager manager = new TooltipManager();
                    manager.animations = false;
                    manager.initialTime = 0.0f;
                    manager.resetTime = 0.0f;
                    manager.subsequentTime = 0.0f;
                    manager.hideAll();
                    manager.instant();
                    TextTooltip toolTip = new TextTooltip((String) previewProperties.get("text"), manager,
                            style);

                    widget = new Label("Hover over me", getSkin());
                    widget.addListener(toolTip);
                } else if (clazz.equals(Touchpad.class)) {
                    Touchpad.TouchpadStyle style = createPreviewStyle(Touchpad.TouchpadStyle.class, styleData);
                    widget = new Touchpad(0, style);
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Tree.class)) {
                    Tree.TreeStyle style = createPreviewStyle(Tree.TreeStyle.class, styleData);
                    widget = new Tree(style);
                    String[] lines = { "this", "is", "a", "test" };
                    Tree.Node parentNode = null;
                    for (String line : lines) {
                        Label label = new Label(line, getSkin());
                        Tree.Node node = new Tree.Node(label);
                        if (parentNode == null) {
                            ((Tree) widget).add(node);
                        } else {
                            parentNode.add(node);
                        }
                        parentNode = node;
                    }
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Window.class)) {
                    Window.WindowStyle style = createPreviewStyle(Window.WindowStyle.class, styleData);

                    Label sampleText = new Label("", getSkin());
                    sampleText.setText((String) previewProperties.get("text"));

                    widget = new Window((String) previewProperties.get("title"), style);
                    ((Window) widget).add(sampleText);
                }

                if (widget != null) {
                    switch ((int) previewProperties.get("size")) {
                    case (0):
                        previewTable.add(widget).size(10.0f);
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (1):
                        previewTable.add(widget);
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (2):
                        previewTable.add(widget).size(200.0f);
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (3):
                        previewTable.add(widget).growX();
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (4):
                        previewTable.add(widget).growY();
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (5):
                        previewTable.add(widget).grow();
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (6):
                        Actor addWidget = widget;
                        TextField widthField = new TextField("", getSkin());
                        TextField heightField = new TextField("", getSkin());
                        System.out.println("trigger");
                        Dialog dialog = new Dialog("Enter dimensions...", getSkin()) {
                            @Override
                            protected void result(Object object) {
                                if ((boolean) object) {
                                    previewTable.add(addWidget).size(Integer.parseInt(widthField.getText()),
                                            Integer.parseInt(heightField.getText()));
                                    Array<String> items = new Array<>(DEFAULT_SIZES);
                                    items.add(widthField.getText() + "x" + heightField.getText());
                                    previewProperties.put("sizeX", Integer.parseInt(widthField.getText()));
                                    previewProperties.put("sizeY", Integer.parseInt(heightField.getText()));
                                    previewSizeSelectBox.setItems(items);
                                    previewSizeSelectBox.setSelectedIndex(7);
                                } else {
                                    previewSizeSelectBox.setSelectedIndex(1);
                                }
                            }
                        };
                        dialog.getTitleTable().getCells().first().padLeft(5.0f);
                        dialog.text("Enter the preview dimensions: ");
                        dialog.getContentTable().getCells().first().pad(10.0f);
                        dialog.getContentTable().row();
                        Table sizeTable = new Table();
                        sizeTable.add(widthField).padLeft(10.0f);
                        sizeTable.add(new Label(" x ", getSkin()));
                        sizeTable.add(heightField).padRight(10.0f);
                        dialog.getContentTable().add(sizeTable);
                        dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
                        dialog.button("OK", true);
                        dialog.button("Cancel", false);
                        dialog.key(Input.Keys.ESCAPE, false);
                        dialog.key(Input.Keys.ENTER, true);
                        dialog.show(stage);
                        stage.setKeyboardFocus(widthField);
                        break;
                    case (7):
                        previewTable.add(widget).size((int) previewProperties.get("sizeX"),
                                (int) previewProperties.get("sizeY"));
                        break;
                    }
                }
            }
        }
    }
}

From source file:com.sturdyhelmetgames.dodgethecars.screen.GameScreen.java

License:Apache License

public GameScreen(final DodgeTheCarsGame game) {
    super(game);//from w  ww.  ja  va  2s  . co m

    Gdx.input.setCatchBackKey(true);

    player = new Squirrel();
    gameEntities.add(player);

    trafficLight = new TrafficLight();

    camera.project(scoreTextPosition);

    stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true) {
        @Override
        public boolean keyDown(int keyCode) {
            if (gameTime > 3.5f) {
                if (!paused && !gameOver) {
                    if (keyCode == Keys.P || keyCode == Keys.ESCAPE || keyCode == Keys.BACK
                            || keyCode == Keys.HOME) {
                        pause();
                        return true;
                    }
                } else if (paused) {
                    if (keyCode == Keys.P || keyCode == Keys.ESCAPE || keyCode == Keys.BACK
                            || keyCode == Keys.C) {
                        resumeGame();
                        return true;
                    } else if (keyCode == Keys.Q) {
                        updateLeaderboard();
                        game.setScreen(new TitleScreen(game));
                        return true;
                    }
                }

                if (gameOver) {
                    if (keyCode == Keys.R) {
                        game.setScreen(new GameScreen(game));
                        return true;
                    } else if (keyCode == Keys.Q) {
                        game.setScreen(new TitleScreen(game));
                        return true;
                    }
                }
            }
            return super.keyDown(keyCode);
        }

        @Override
        public boolean touchUp(int screenX, int screenY, int pointer, int button) {
            final Vector3 position = new Vector3(screenX, screenY, 0f);
            camera.unproject(position);

            if (gameTime > 3.5f) {
                if (paused) {
                    // very dirty code, sorry :)
                    if (position.x > -7f && position.x < 7f && position.y > 3f && position.y < 6f) {
                        resumeGame();
                        return true;
                    } else if (position.x > -7f && position.x < 7f && position.y < -4f && position.y > -7f) {
                        updateLeaderboard();
                        game.setScreen(new TitleScreen(game));
                        return true;
                    }
                }
                if (gameOver) {
                    // very dirty code, sorry :)
                    if (position.x > -7f && position.x < 7f && position.y > 4f && position.y < 7f) {
                        game.setScreen(new GameScreen(game));
                        return true;
                    } else if (position.x > -7f && position.x < 7f && position.y < -4f && position.y > -7f) {
                        game.setScreen(new TitleScreen(game));
                        return true;
                    }
                }
            }

            return super.touchUp(screenX, screenY, pointer, button);
        }

    };
    Gdx.input.setInputProcessor(stage);
    touchpad = new Touchpad(2.0f, Art.skin.get("touchpad", TouchpadStyle.class));
    touchpad.setBounds(15, 15, 200, 200);
    stage.addActor(touchpad);

    // if touch-based device, activate touch controls
    if (ApplicationType.Android.equals(Gdx.app.getType()) || ApplicationType.iOS.equals(Gdx.app.getType())) {
        isTouchActive = true;
    }
}

From source file:EntityManager.ScreenControlsSystem.java

public ScreenControlsSystem() {

    touchpadStyle = new Touchpad.TouchpadStyle();
    touchpadSkin = new Skin();
    //Set background image
    touchpadSkin.add("touchBackground", new Texture("touchBackground.png"));
    //Set knob image
    touchpadSkin.add("touchKnob", new Texture("touchKnob.png"));
    touchpadStyle.background = touchpadSkin.getDrawable("touchBackground");
    touchpadStyle.knob = touchpadSkin.getDrawable("touchKnob");

    //Set background image
    //        touchpadStyle.background = new Texture("data/touchBackground.png");
    //        //Set knob image
    //        touchpadSkin.add("touchKnob", new Texture("data/touchKnob.png"));
    touchpad = new Touchpad(10, touchpadStyle);
    touchpadRight = new Touchpad(10, touchpadStyle);
    touchpad.setBounds(0, 0, Gdx.graphics.getWidth() / 4, Gdx.graphics.getWidth() / 4);
    touchpadRight.setBounds(Gdx.graphics.getWidth() - Gdx.graphics.getWidth() / 4, 0,
            Gdx.graphics.getWidth() / 4, Gdx.graphics.getWidth() / 4);

    button = new Button(touchpadSkin.getDrawable("touchKnob"));
    button.setBounds(Gdx.graphics.getWidth() - Gdx.graphics.getWidth() / 9, Gdx.graphics.getWidth() / 4,
            Gdx.graphics.getWidth() / 10, Gdx.graphics.getWidth() / 10);
    button.addListener(new ClickListener() {
        @Override/*from ww w.  j a  v  a 2s . c  o  m*/
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            button1press = true;
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            button1press = false;

        }
    });

    button2 = new Button(touchpadSkin.getDrawable("touchKnob"));
    button2.setBounds(Gdx.graphics.getWidth() - Gdx.graphics.getWidth() / 4, Gdx.graphics.getWidth() / 4,
            Gdx.graphics.getWidth() / 10, Gdx.graphics.getWidth() / 10);
    button2.addListener(new ClickListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            button2press = true;
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            button2press = false;

        }
    });

    stage = new Stage();
    stage.addActor(touchpad);
    stage.addActor(touchpadRight);
    stage.addActor(button);
    stage.addActor(button2);
    //        world.setContactListener(new ContactListener() {
    //
    //            @Override
    //            public void beginContact(Contact contact) {
    //                contact.getFixtureA();
    //                if (contact.getFixtureB() == player.body.getFixtureList().get(0)){
    //                    System.out.println("touch!");
    //                    for(Door door:doors){
    //                        if(contact.getFixtureA().equals(SceneBuilder.platform1.getFixtureList().get(0))){
    //                            door.collidePlayer = true;
    //
    //                        }
    //                    }
    //                }
    //            }
    //
    //            @Override
    //            public void endContact(Contact contact) {
    //            }
    //
    //            @Override
    //            public void preSolve(Contact contact, Manifold oldManifold) {
    //            }
    //
    //            @Override
    //            public void postSolve(Contact contact, ContactImpulse impulse) {
    //            }
    //        });
    Gdx.input.setInputProcessor(stage);
    //        Gdx.input.setInputProcessor(inputM);
}

From source file:gui.screen.MainPlayerHud.java

public MainPlayerHud(final EntityManager entityManager, Game game, Server server, Client client,
        final MapLoader map, OrthographicCamera camera) {
    super(game, client, server);

    deathMessageArray = new ArrayList<>();
    textMessageArray = new ArrayList<>();

    //Initialise Objects
    this.stage = new Stage(new StretchViewport(Constants.SCREENWIDTH, Constants.SCREENHEIGHT));
    this.stack = new Stack(); //A container in wich you can place multiple widgets to "stack" them
    this.touchTable.setSize(stage.getWidth(), stage.getHeight());
    this.camera = camera;
    touchTable.setTouchable(Touchable.enabled);
    stage.addActor(touchTable);/*w  w w  .  j  a  va 2s. co m*/
    this.entityManager = entityManager;

    //Initialise Font
    this.generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/lunchtime-doubly-so/lunchds.ttf"));
    this.parameter = new FreeTypeFontParameter();
    parameter.size = 15;

    //Table settings
    Table backgroundTable = new Table();
    backgroundTable.top();
    backgroundTable.setFillParent(true);

    //Table settings 2
    Table foregroundTable = new Table();
    foregroundTable.top();
    foregroundTable.setFillParent(true);

    /**------------------------EXIT DIALOG------------------------**/
    exitDialog = new Dialog("Confirm exit", TextureManager.skin) {
        @Override
        public void result(Object obj) {
            boolean result = (boolean) obj;

            if (result == true) {
                //Stop music
                AudioManager.getCurrentMusic().stop();

                quitGame();
            } else {
                Gdx.input.setCursorCatched(true);
            }
        }
    };
    exitDialog.text("Are you sure you want to quit?");
    exitDialog.button("Yes", true); //sends "true" as the result
    exitDialog.button("No", false); //sends "false" as the result

    if (Constants.ISRUNNINGONSMARTPHONE && Constants.TOUCHSCREEN) {
        touchTable.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int buttonCode) {

                Player player = entityManager.getPlayerManager().getCurrentPlayerObject();

                if (player != null) {
                    // Calculate correct world position
                    ThinGridCoordinates aim = new ThinGridCoordinates(
                            player.getPosition().getX() + (x - touchTable.getWidth() / 2f),
                            player.getPosition().getY() + (y - touchTable.getHeight() / 2f));
                    aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f,
                            aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f);

                    // Change to block center
                    ThinGridCoordinates blockCenter = new ThinGridCoordinates(new MapCellCoordinates(aim));
                    aim.setX(blockCenter.getX() + (Constants.MAPTEXTUREWIDTH - Constants.PLAYERWIDTH) / 2);
                    aim.setY(
                            blockCenter.getY() + (Constants.MAPTEXTUREHEIGHT - Constants.PLAYERHEIGHT / 4) / 2);

                    goToCoordiantes = aim;
                }

                return true;
            }

            @Override
            public void touchDragged(InputEvent event, float x, float y, int pointer) {
                Player player = entityManager.getPlayerManager().getCurrentPlayerObject();

                if (player != null) {
                    // Calculate correct world position
                    ThinGridCoordinates aim = new ThinGridCoordinates(
                            player.getPosition().getX() + (x - touchTable.getWidth() / 2f),
                            player.getPosition().getY() + (y - touchTable.getHeight() / 2f));
                    aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f,
                            aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f);

                    // Change to block center
                    ThinGridCoordinates blockCenter = new ThinGridCoordinates(new MapCellCoordinates(aim));
                    aim.setX(blockCenter.getX() + (Constants.MAPTEXTUREWIDTH - Constants.PLAYERWIDTH) / 2);
                    aim.setY(
                            blockCenter.getY() + (Constants.MAPTEXTUREHEIGHT - Constants.PLAYERHEIGHT / 4) / 2);

                    goToCoordiantes = aim;
                }

            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {

            }

        });
    }

    /*-------------------------MOVEMENT TOUCHPAD--------------------------*/
    if (Constants.ISRUNNINGONSMARTPHONE && Constants.TOUCHPAD) {
        //Create a touchpad skin
        touchpadSkin = new Skin();
        //Set background image
        touchpadSkin.add("touchBackground", new Texture("hud/touchBackground.png"));
        //Set knob image
        touchpadSkin.add("touchKnob", new Texture("hud/touchKnob.png"));
        //Create TouchPad Style
        touchpadStyle = new Touchpad.TouchpadStyle();
        //Create Drawable's from TouchPad skin
        touchBackground = touchpadSkin.getDrawable("touchBackground");
        touchKnob = touchpadSkin.getDrawable("touchKnob");
        //Apply the Drawables to the TouchPad Style
        touchpadStyle.background = touchBackground;
        touchpadStyle.knob = touchKnob;
        //Create new TouchPad with the created style
        touchpad = new Touchpad(10, touchpadStyle);
        //setBounds(x,y,width,height)
        touchpad.setBounds(15, 15, 150, 150);

        stage.addActor(touchpad);

        touchpad.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer,
                    int buttonCode) {

                return true;
            }

            @Override
            public void touchDragged(InputEvent event, float screenX, float screenY, int pointer) {
                ThinGridCoordinates aim = null;

                Player player = entityManager.getPlayerManager().getCurrentPlayerObject();

                if (player != null) {

                    // Left
                    if (touchpad.getKnobPercentX() < -0.5) {
                        float x = 370;
                        float y = 250;

                        // Calculate correct world position
                        aim = new ThinGridCoordinates(
                                player.getPosition().getX() + (x - touchTable.getWidth() / 2f),
                                player.getPosition().getY() + (y - touchTable.getHeight() / 2f));
                        aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f,
                                aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f);

                        //Right
                    } else if (touchpad.getKnobPercentX() > 0.5) {
                        float x = 460;
                        float y = 250;

                        // Calculate correct world position
                        aim = new ThinGridCoordinates(
                                player.getPosition().getX() + (x - touchTable.getWidth() / 2f),
                                player.getPosition().getY() + (y - touchTable.getHeight() / 2f));
                        aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f,
                                aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f);
                    }

                    // Down
                    if (touchpad.getKnobPercentY() < -0.5) {
                        float x = 415;
                        float y = 200;

                        // Calculate correct world position
                        aim = new ThinGridCoordinates(
                                player.getPosition().getX() + (x - touchTable.getWidth() / 2f),
                                player.getPosition().getY() + (y - touchTable.getHeight() / 2f));
                        aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f,
                                aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f);

                        // Up
                    } else if (touchpad.getKnobPercentY() > 0.5) {

                        float x = 415;
                        float y = 300;

                        // Calculate correct world position
                        aim = new ThinGridCoordinates(
                                player.getPosition().getX() + (x - touchTable.getWidth() / 2f),
                                player.getPosition().getY() + (y - touchTable.getHeight() / 2f));
                        aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f,
                                aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f);
                    }

                    if (aim != null) {
                        // Change to block center
                        ThinGridCoordinates blockCenter = new ThinGridCoordinates(new MapCellCoordinates(aim));
                        aim.setX(blockCenter.getX() + (Constants.MAPTEXTUREWIDTH - Constants.PLAYERWIDTH) / 2);
                        aim.setY(blockCenter.getY()
                                + (Constants.MAPTEXTUREHEIGHT - Constants.PLAYERHEIGHT / 4) / 2);
                    }

                    goToCoordiantes = aim;
                }
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                InputHandler.setAnyKey(false);
                InputHandler.resetMovementKeys();

            }
        });
    }

    /*-------------------------ACTION TOUCHPAD--------------------------*/
    if (Constants.ISRUNNINGONSMARTPHONE) {
        Table table = new Table();
        table.setFillParent(true);
        table.right().bottom().toFront();

        /*-------------------------PLACE BOMB--------------------------*/
        placeBombButton.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer,
                    int buttonCode) {

                InputHandler.setAnyKey(true);
                InputHandler.setPlaceBombKey(true);

                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                InputHandler.setAnyKey(false);
                InputHandler.setPlaceBombKey(false);
            }

        });

        placeBombButton.setSize(100, 100);

        table.add(placeBombButton).size(placeBombButton.getWidth(), placeBombButton.getHeight()).padBottom(10)
                .padRight(10);

        stage.addActor(table);

        /*-------------------------TRIGGER REMOTE BUTTON--------------------------*/
        Table table1 = new Table();
        table1.right().bottom().toFront();

        triggerRemoteButton.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer,
                    int buttonCode) {

                InputHandler.setAnyKey(true);
                InputHandler.setRemoteKey(true);

                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                InputHandler.setAnyKey(false);
                InputHandler.setRemoteKey(false);
            }

        });

        triggerRemoteButton.setSize(60, 60);

        table1.add(triggerRemoteButton).size(triggerRemoteButton.getWidth(), triggerRemoteButton.getHeight());
        table1.setPosition(685, 80);
        stage.addActor(table1);

        /*-------------------------TELEPORT BUTTON--------------------------*/
        Table table2 = new Table();
        table1.right().bottom().toFront();

        teleportButton.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer,
                    int buttonCode) {

                InputHandler.setAnyKey(true);
                InputHandler.setTeleportKey(true);

                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                InputHandler.setAnyKey(false);
                InputHandler.setTeleportKey(false);
            }

        });

        teleportButton.setSize(60, 60);

        table2.add(teleportButton).size(teleportButton.getWidth(), teleportButton.getHeight());
        table2.setPosition(Constants.SCREENWIDTH - 65, 155);
        stage.addActor(table2);
    }

    /*-------------------------RESIZE ELEMENTS IN HUD--------------------------*/
    if (Constants.ISRUNNINGONSMARTPHONE) {
        scaleCounterHud = 4; // Default 3
        scaleInventoryImg = 1.8f; // Default 1.5
        addToPositionX = 20; // Default -2
        scaleTextMessage = 6; // Default 5
        Constants.DEFAULTZOOM = 0.7f; // Default 1f
    }

    /*-------------------------GO BACK TO MENU BUTTON--------------------------*/
    if (Constants.ISRUNNINGONSMARTPHONE) {
        Table table = new Table();

        goToMenuButton.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer,
                    int buttonCode) {

                InputHandler.setAnyKey(true);
                InputHandler.setEscKey(true);

                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {

                InputHandler.setAnyKey(false);
                InputHandler.setEscKey(false);
            }
        });

        goToMenuButton.setSize(70, 70);

        table.add(goToMenuButton).size(goToMenuButton.getWidth(), goToMenuButton.getHeight());
        table.setSize(goToMenuButton.getWidth(), goToMenuButton.getHeight());
        table.padTop(40);
        table.padRight(40);
        table.setPosition(Constants.SCREENWIDTH - table.getWidth(), Constants.SCREENHEIGHT - table.getHeight());

        stage.addActor(table);
    }

    /*-------------------------SCREEN MESSAGE--------------------------*/
    Table messageLabel = new Table();
    messageLabel.setFillParent(true);
    messageLabel.right();

    parameter.size = 4 * (int) scaleTextMessage;
    deathMessageLabel = new Label("",
            new Label.LabelStyle(generator.generateFont(parameter), Color.valueOf("f7472c")));
    deathMessageLabel.setAlignment(Align.center);
    deathMessageLabel.setSize(200, 50);
    messageLabel.add(deathMessageLabel);

    textMessageLabel = new Label("", new Label.LabelStyle(generator.generateFont(parameter), Color.YELLOW));
    textMessageLabel.setAlignment(Align.center);
    textMessageLabel.setSize(200, 50);
    messageLabel.add(textMessageLabel);

    stage.addActor(messageLabel);

    /*-------------------------LIFE & COUNTER HUD--------------------------*/
    parameter.size = 5 * (int) scaleCounterHud;
    //Labels (textfields)
    bombCounterLabel = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.WHITE));
    coinCounterLabel = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.WHITE));
    speedCounterLabel = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.WHITE));
    rangeCounterLabel = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.WHITE));

    //Live & coins display image
    uiCounterImage = new Image(TextureManager.hudCounterFullLive);

    //Calculate image width (scaledCounterX) and image height (scaleY)
    float scaledCounterX = TextureManager.hudCounterFullLive.getWidth() * scaleCounterHud;
    float scaledCounterY = TextureManager.hudCounterFullLive.getHeight() * scaleCounterHud;

    //Add image to background messageLabel
    backgroundTable.add(uiCounterImage).width(scaledCounterX).height(scaledCounterY);

    //Add label to foreground messageLabel
    foregroundTable.row().expandX().padTop(8 * scaleCounterHud);
    foregroundTable.add(bombCounterLabel).padLeft(40 * scaleCounterHud);
    foregroundTable.add(coinCounterLabel).padLeft(16 * scaleCounterHud);
    foregroundTable.add(rangeCounterLabel).padLeft(13 * scaleCounterHud);
    foregroundTable.add(speedCounterLabel).padLeft(18 * scaleCounterHud);

    //Set container to the height of the image and position it on the top left
    stack.setWidth(scaledCounterX);
    stack.setHeight(scaledCounterY);
    stack.setPosition(0, 470 - scaledCounterY);

    //End messageLabel and container (stack)
    stack.add(backgroundTable);
    stack.add(foregroundTable);
    stage.addActor(stack);

    /*-------------------------BOMB INVENTORY HUD--------------------------*/

    // Inventory Image
    uiInventoryImage = new Image(TextureManager.hudInventoryHiglighted1);
    uiInventoryImage.setWidth(280 * scaleInventoryImg);// 1,5x bigger
    uiInventoryImage.setHeight(32 * scaleInventoryImg);
    uiInventoryImage.setPosition((Constants.SCREENWIDTH - uiInventoryImage.getWidth()) / 2 + addToPositionX, 5);
    stage.addActor(uiInventoryImage);

    // Price labels
    bombPrice1 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));
    bombPrice2 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));
    bombPrice3 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));
    bombPrice4 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));
    bombPrice5 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));
    bombPrice6 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));
    bombPrice7 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));
    bombPrice8 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));
    bombPrice9 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD));

    Table pricesTable = new Table();
    pricesTable.setFillParent(true);

    //31x31
    pricesTable.add(bombPrice1).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);
    pricesTable.add(bombPrice2).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);
    pricesTable.add(bombPrice3).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);
    pricesTable.add(bombPrice4).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);
    pricesTable.add(bombPrice5).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);
    pricesTable.add(bombPrice6).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);
    pricesTable.add(bombPrice7).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);
    pricesTable.add(bombPrice8).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);
    pricesTable.add(bombPrice9).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg);

    pricesLabelGroup.addActor(pricesTable);
    pricesLabelGroup.setPosition((Constants.SCREENWIDTH - pricesLabelGroup.getWidth()) / 2 + addToPositionX + 3,
            15);
    stage.addActor(pricesLabelGroup);

    if (Constants.ISRUNNINGONSMARTPHONE) {
        Table touchTable = new Table();

        touchTable.add(getContainerWithBombListener(1)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);
        touchTable.add(getContainerWithBombListener(2)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);
        touchTable.add(getContainerWithBombListener(3)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);
        touchTable.add(getContainerWithBombListener(4)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);
        touchTable.add(getContainerWithBombListener(5)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);
        touchTable.add(getContainerWithBombListener(6)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);
        touchTable.add(getContainerWithBombListener(7)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);
        touchTable.add(getContainerWithBombListener(8)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);
        touchTable.add(getContainerWithBombListener(9)).width(31 * scaleInventoryImg)
                .height(31 * scaleInventoryImg);

        touchTable.setPosition((Constants.SCREENWIDTH - touchTable.getWidth()) / 2 + addToPositionX, 35);
        stage.addActor(touchTable);
    }

    generator.dispose();
}

From source file:net.bplaced.therefactory.voraciousviper.input.gamescreen.JoystickInputProcessor.java

License:Open Source License

public JoystickInputProcessor(final GameScreen gameScreen, FitViewport viewport, TextureAtlas textureAtlas,
        ShapeRenderer shapeRenderer, BitmapFont font) {
    super(gameScreen, viewport, textureAtlas, shapeRenderer);

    //Create a touchpad skin   
    Skin touchpadSkin = new Skin();
    //Set background image
    //Set knob image
    touchpadSkin.add("touchKnob", new Texture("touchKnob.png"));
    //Create TouchPad Style
    TouchpadStyle touchpadStyle = new TouchpadStyle();
    //Create Drawable's from TouchPad skin
    Drawable touchKnob = touchpadSkin.getDrawable("touchKnob");
    //Apply the Drawables to the TouchPad Style
    //touchpadStyle.background = touchBackground;
    touchpadStyle.knob = touchKnob;//from w  w w  .j a  v a 2s . c  o  m
    //Create new TouchPad with the created style
    touchpad = new Touchpad(10, touchpadStyle);
    //setBounds(x,y,width,height)
    touchpad.setBounds(viewport.getWorldWidth() - 15 - 200, 15, 200, 200);
    circleX = touchpad.getX() + touchpad.getWidth() / 2;
    circleY = touchpad.getY() + touchpad.getHeight() / 2;
    touchpad.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            if (gameScreen.getState() == GameState.GameIsBeginning) {
                gameScreen.setState(GameState.GameIsRunning);
            }
        }
    });
    stage.addActor(touchpad);
}

From source file:presentation.concretion.game.HUD.java

License:Open Source License

private void initComponentsMobilePhone() {
    // Define Tables
    Table tMControl = new Table();
    tMControl.setFillParent(true);/*from   www.j  ava  2s.c  o  m*/
    stage.addActor(tMControl);
    Table tMButtons = new Table();
    tMButtons.setFillParent(true);
    stage.addActor(tMButtons);

    // Touch pad.
    tMControl.bottom().left().padLeft(100);
    TextureRegionDrawable backgroundDrawable = new TextureRegionDrawable(ResourcesHUD.bakgroundControl);
    TextureRegionDrawable knobDrawable = new TextureRegionDrawable(ResourcesHUD.knobControl);
    control = new Touchpad(10, new Touchpad.TouchpadStyle(backgroundDrawable, knobDrawable));
    control.setBounds(15, 15, 300, 300);
    tMControl.add(control);
    // Buttons
    tMButtons.bottom().right();
    Drawable imageUp, imageDown;
    imageUp = new TextureRegionDrawable(ResourcesHUD.buttonAttackUp);
    imageDown = new TextureRegionDrawable(ResourcesHUD.buttonAttackDown);
    this.buttonAttack = new ImageButton(imageUp, imageDown);
    tMButtons.add(this.buttonAttack).padRight(50);
    imageUp = new TextureRegionDrawable(ResourcesHUD.buttonJumpUp);
    imageDown = new TextureRegionDrawable(ResourcesHUD.buttonJumpDown);
    this.buttonJump = new ImageButton(imageUp, imageDown);
    tMButtons.add(this.buttonJump).padRight(50);

}