Example usage for com.badlogic.gdx.scenes.scene2d.ui Dialog getButtonTable

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

Introduction

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

Prototype

public Table getButtonTable() 

Source Link

Usage

From source file:ca.hiphiparray.amazingmaze.ContinueScreen.java

License:Open Source License

/**
 * Displays the high score dialog.//from   w  ww  . jav  a 2s  .  c  o  m
 */
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);
}

From source file:ca.hiphiparray.amazingmaze.FishMiniGame.java

License:Open Source License

/**
 * Constructor for FishMiniGame.//from  w  w  w .  j av a 2 s.c  o  m
 *
 * @param game the {@link AmazingMazeGame} instance that is managing this screen.
 * @param player the {@link Player} instance that completed the last level.
 */
public FishMiniGame(final AmazingMazeGame game, Player player) {
    this.game = game;
    this.player = player;
    fishNumber = new int[5];

    fishNumber[0] = this.player.blueCollected;
    fishNumber[1] = this.player.purpleCollected;
    fishNumber[2] = this.player.greenCollected;
    fishNumber[3] = this.player.redCollected;
    fishNumber[4] = this.player.orangeCollected;

    answer = 0;
    for (int i = 0; i < fishNumber.length; i++) {
        answer += fishNumber[i] * fishValue[i];
    }

    stage = new Stage(new ScreenViewport(), this.game.batch);

    menuTable = new Table();
    fishTable = new Table();

    canvas = new Canvas(
            new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() + shift, Pixmap.Format.RGB565));

    menuTable.setFillParent(true);
    menuTable.top();
    fishTable.bottom();
    fishTable.setFillParent(true);

    fishImage = new Image[5];

    TextureAtlas atlas = this.game.assets.manager.get(Assets.GAME_ATLAS_LOCATION, TextureAtlas.class);
    fishImage[0] = new Image(atlas.findRegion(Assets.FISH + Assets.BLUE_MODIFIER));
    fishImage[0].setScale(4f);
    fishImage[1] = new Image(atlas.findRegion(Assets.FISH + Assets.PURPLE_MODIFIER));
    fishImage[1].setScale(4f);
    fishImage[2] = new Image(atlas.findRegion(Assets.FISH + Assets.GREEN_MODIFIER));
    fishImage[2].setScale(4f);
    fishImage[3] = new Image(atlas.findRegion(Assets.FISH + Assets.RED_MODIFIER));
    fishImage[3].setScale(4f);
    fishImage[4] = new Image(atlas.findRegion(Assets.FISH + Assets.ORANGE_MODIFIER));
    fishImage[4].setScale(4f);

    pencilButton = new Button(new TextureRegionDrawable(
            new TextureRegion(this.game.assets.manager.get(Assets.PENCIL_BUTTON, Texture.class))));
    pencilButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (pencilButton.isPressed()) {
                canvas.setColor(drawColor);
            }
        }
    });

    eraserButton = new Button(new TextureRegionDrawable(
            new TextureRegion(this.game.assets.manager.get(Assets.ERASER_BUTTON, Texture.class))));
    eraserButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (eraserButton.isPressed()) {
                canvas.setColor(clearColor);
            }
        }
    });

    helpButton = new Button(new TextureRegionDrawable(
            new TextureRegion(this.game.assets.manager.get(Assets.HELP_BUTTON, Texture.class))));
    helpButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (helpButton.isPressed()) {
                Label.LabelStyle labelStyle = new Label.LabelStyle(
                        game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
                final Dialog dialog = new Dialog("Help", game.assets.skin);
                final TextButton okButton = new TextButton("OK", game.assets.skin);
                dialog.getButtonTable().bottom();
                Label label = new Label("Find the total value of fish that you retrieved!\n"
                        + "Each colour corresponds to the colour of Canadian money.\n"
                        + "The numbers correspond to each number of fish you got.\n\n"
                        + "In case you forgot: blue is 5, purple is 10, green is 20, red is 50, and orange is 100.",
                        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.key(Keys.ENTER, true);
                dialog.show(stage);
            }
        }
    });

    checkButton = new Button(new TextureRegionDrawable(
            new TextureRegion(this.game.assets.manager.get(Assets.CHECK_BUTTON, Texture.class))));
    checkButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            dialog();
        }
    });

    clearButton = new Button(new TextureRegionDrawable(
            new TextureRegion(this.game.assets.manager.get(Assets.CLEAR_BUTTON, Texture.class))));
    clearButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (clearButton.isPressed()) {
                canvas.clear();
                canvas.setColor(drawColor);
            }
        }
    });

    answerField = new TextField("", game.assets.skin);
    answerField.setTextFieldListener(new TextFieldListener() {
        @Override
        public void keyTyped(TextField textField, char key) {
            if (key == (char) 13) {
                stage.unfocus(answerField);
                dialog();
            }
        }
    });
    stage.addActor(menuTable);
    stage.addActor(canvas);
    stage.addActor(fishTable);

    menuTable.clear();
    fishTable.clear();
    helpButton.right();
    menuTable.background(new TextureRegionDrawable(
            new TextureRegion(this.game.assets.manager.get(Assets.MINI_BACKGROUND, Texture.class))));
    menuTable.add(pencilButton).pad(10).size(64);
    menuTable.add(eraserButton).pad(10).size(64);
    menuTable.add(clearButton).pad(10).size(64);
    menuTable.add(helpButton).pad(10).size(64);

    menuTable.row();

    Label.LabelStyle labelStyle = new Label.LabelStyle(
            game.assets.getFont(Assets.SANS_REGULAR, Assets.REGULAR_FONT_SIZE), Color.WHITE);

    for (int i = 0; i < 5; i++) {
        fishTable.add(fishImage[i]).bottom().left().padLeft(10);
    }
    fishTable.add(answerField).minWidth(150).padLeft(150);
    fishTable.add(checkButton).pad(10).size(64);
    fishTable.row();

    for (int i = 0; i < 5; i++) {
        fishTable.add(new Label(fishNumber[i] + "", labelStyle)).pad(30).center();
    }
    fishTable.row();

    setupPauseMenu();
    input = new InputMultiplexer(stage, this);
    input.addProcessor(pauseMenu);
}

From source file:ca.hiphiparray.amazingmaze.FishMiniGame.java

License:Open Source License

/**
 * Displays the results dialog./*from www.  j  av a2  s  . com*/
 */
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);
}

From source file:com.bladecoder.engine.ui.MenuScreen.java

License:Apache License

@Override
public void show() {
    stage = new Stage(new ScreenViewport());

    final Skin skin = ui.getSkin();
    final World world = World.getInstance();

    final MenuScreenStyle style = skin.get(MenuScreenStyle.class);
    final BitmapFont f = skin.get(style.textButtonStyle, TextButtonStyle.class).font;
    float buttonWidth = f.getCapHeight() * 15f;

    // Image background = new Image(style.background);
    Drawable bg = style.background;/*from www.j a v  a2  s.c  o m*/

    if (bg == null && style.bgFile != null) {
        bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile));
        bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        bg = new TextureRegionDrawable(new TextureRegion(bgTexFile));
    }

    final Table table = new Table();
    table.setFillParent(true);
    table.center();

    if (bg != null)
        table.setBackground(bg);

    table.addListener(new InputListener() {
        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK)
                if (world.getCurrentScene() != null)
                    ui.setCurrentScreen(Screens.SCENE_SCREEN);

            return true;
        }
    });

    table.defaults().pad(BUTTON_PADDING).width(buttonWidth);

    stage.setKeyboardFocus(table);

    if (style.showTitle) {

        Label title = new Label(Config.getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin,
                style.titleStyle);

        title.setAlignment(Align.center);

        table.add(title).padBottom(DPIUtils.getMarginSize() * 2);
        table.row();
    }

    if (world.savedGameExists() || world.getCurrentScene() != null) {
        TextButton continueGame = new TextButton(I18N.getString("ui.continue"), skin, style.textButtonStyle);

        continueGame.addListener(new ClickListener() {
            public void clicked(InputEvent event, float x, float y) {
                if (world.getCurrentScene() == null)
                    try {
                        world.load();
                    } catch (Exception e) {
                        Gdx.app.exit();
                    }

                ui.setCurrentScreen(Screens.SCENE_SCREEN);
            }
        });

        table.add(continueGame);
    }

    TextButton newGame = new TextButton(I18N.getString("ui.new"), skin, style.textButtonStyle);
    newGame.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            if (world.savedGameExists()) {
                Dialog d = new Dialog("", skin) {
                    protected void result(Object object) {
                        if (((Boolean) object).booleanValue()) {
                            try {
                                world.newGame();
                            } catch (Exception e) {
                                Gdx.app.exit();
                            }
                            ui.setCurrentScreen(Screens.SCENE_SCREEN);
                        }
                    }
                };

                d.pad(DPIUtils.getMarginSize());
                d.getButtonTable().padTop(DPIUtils.getMarginSize());
                d.getButtonTable().defaults().padLeft(DPIUtils.getMarginSize())
                        .padRight(DPIUtils.getMarginSize());

                Label l = new Label(I18N.getString("ui.override"), ui.getSkin(), "ui-dialog");
                l.setWrap(true);
                l.setAlignment(Align.center);

                d.getContentTable().add(l).prefWidth(Gdx.graphics.getWidth() * .7f);

                d.button(I18N.getString("ui.yes"), true, ui.getSkin().get("ui-dialog", TextButtonStyle.class));
                d.button(I18N.getString("ui.no"), false, ui.getSkin().get("ui-dialog", TextButtonStyle.class));
                d.key(Keys.ENTER, true).key(Keys.ESCAPE, false);

                d.show(stage);
            } else {

                try {
                    world.newGame();
                } catch (Exception e) {
                    Gdx.app.exit();
                }
                ui.setCurrentScreen(Screens.SCENE_SCREEN);
            }
        }
    });

    table.row();
    table.add(newGame);

    TextButton loadGame = new TextButton(I18N.getString("ui.load"), skin, style.textButtonStyle);
    loadGame.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.LOAD_GAME_SCREEN);
        }
    });

    table.row();
    table.add(loadGame);

    //      if (world.getCurrentScene() != null) {
    //         TextButton saveGame = new TextButton(I18N.getString("ui.save"), skin, style.textButtonStyle);
    //         saveGame.addListener(new ClickListener() {
    //            public void clicked(InputEvent event, float x, float y) {
    //               ui.setCurrentScreen(Screens.SAVE_GAME_SCREEN);
    //            }
    //         });
    //
    //         table.row();
    //         table.add(saveGame);
    //      }

    TextButton quit = new TextButton(I18N.getString("ui.quit"), skin, style.textButtonStyle);
    quit.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            Gdx.app.exit();
        }
    });

    table.row();
    table.add(quit);

    table.pack();

    stage.addActor(table);

    // BOTTOM-RIGHT BUTTON STACK
    credits = new Button(skin, "credits");
    credits.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.CREDIT_SCREEN);
        }
    });

    help = new Button(skin, "help");
    help.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.HELP_SCREEN);
        }
    });

    debug = new Button(skin, "debug");
    debug.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            DebugScreen debugScr = new DebugScreen();
            debugScr.setUI(ui);
            ui.setCurrentScreen(debugScr);
        }
    });

    Table buttonStack = new Table();
    buttonStack.defaults().pad(DPIUtils.getSpacing()).size(DPIUtils.getPrefButtonSize(),
            DPIUtils.getPrefButtonSize());
    buttonStack.pad(DPIUtils.getMarginSize() * 2);

    if (EngineLogger.debugMode() && world.getCurrentScene() != null) {
        buttonStack.add(debug);
        buttonStack.row();
    }

    buttonStack.add(help);
    buttonStack.row();
    buttonStack.add(credits);
    buttonStack.bottom().right();
    buttonStack.setFillParent(true);
    buttonStack.pack();
    stage.addActor(buttonStack);

    Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin);
    version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize());
    stage.addActor(version);

    debug.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            DebugScreen debugScr = new DebugScreen();
            debugScr.setUI(ui);
            ui.setCurrentScreen(debugScr);
        }
    });

    pointer = new Pointer(skin);
    stage.addActor(pointer);

    Gdx.input.setInputProcessor(stage);
}

From source file:com.gdx.extension.screen.BaseScreen.java

License:Apache License

/**
 * Show a modal popup on top of all the screens children
 * //from www .  j a v  a2s .co  m
 * @param title the title of the popup
 * @param message text you want to display in the popup
 */
public void showPopup(String title, String message) {
    final Dialog _dialog = new Dialog(title, skin);
    Label _message = new Label(message, skin);
    _message.setAlignment(Align.center);

    TextButton _okButton = new TextButton("Ok", skin);
    _okButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            _dialog.hide();
        }

    });

    _dialog.getContentTable().add(_message).minWidth(300f).pad(10f);
    _dialog.getButtonTable().add(_okButton).minWidth(100f).pad(10f);
    _dialog.setTitleAlignment(Align.center);
    _dialog.setMovable(false);
    _dialog.center();
    _dialog.show(stage);
}

From source file:com.ray3k.skincomposer.dialog.DialogColors.java

License:Open Source License

private void showColorPicker() {
    dialogFactory.showDialogColorPicker(new DialogColorPicker.ColorListener() {
        @Override/*  www  . ja  v a  2 s.c om*/
        public void selected(Color color) {
            if (color != null) {
                final TextField field = new TextField("RGBA_" + (int) (color.r * 255) + "_"
                        + (int) (color.g * 255) + "_" + (int) (color.b * 255) + "_" + (int) (color.a * 255),
                        skin);
                final Dialog dialog = new Dialog("Color name...", skin, "bg") {
                    @Override
                    protected void result(Object object) {
                        if ((Boolean) object == true) {
                            newColor(field.getText(), color);
                        }
                    }
                };

                dialog.getTitleTable().padLeft(5.0f);

                dialog.button("Ok", true).button("Cancel", false).key(Keys.ESCAPE, false);
                final TextButton button = (TextButton) dialog.getButtonTable().getCells().first().getActor();
                button.addListener(main.getHandListener());
                dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
                dialog.getButtonTable().pad(15.0f);

                field.setTextFieldListener(new TextField.TextFieldListener() {
                    @Override
                    public void keyTyped(TextField textField, char c) {
                        if (c == '\n') {
                            if (!button.isDisabled()) {
                                String name = field.getText();
                                if (newColor(name, color)) {
                                    dialog.hide();
                                }
                            }
                            main.getStage().setKeyboardFocus(textField);
                        }
                    }
                });

                field.addListener(main.getIbeamListener());

                dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
                dialog.text("Please enter a name for the new color: ");
                dialog.getContentTable().row();
                dialog.getContentTable().add(field).growX();
                dialog.getContentTable().row();
                dialog.text("Preview:");
                dialog.getContentTable().row();
                Table table = new Table(skin);
                table.setBackground("white");
                table.setColor(color);
                dialog.getContentTable().add(table).minSize(50.0f);
                button.setDisabled(!ColorData.validate(field.getText()));
                field.addListener(new ChangeListener() {
                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        boolean disable = !ColorData.validate(field.getText());
                        if (!disable) {
                            for (ColorData data : jsonData.getColors()) {
                                if (data.getName().equals(field.getText())) {
                                    disable = true;
                                    break;
                                }
                            }
                        }
                        button.setDisabled(disable);
                    }
                });
                dialog.show(getStage());
                getStage().setKeyboardFocus(field);
                field.selectAll();
                field.setFocusTraversal(false);
            }
        }
    });
}

From source file:com.ray3k.skincomposer.dialog.DialogColors.java

License:Open Source License

private void renameDialog(ColorData color) {
    TextField textField = new TextField("", skin);
    TextButton okButton;//  w w w.jav a2s  .  c  o  m

    Dialog dialog = new Dialog("Rename Color?", skin, "bg") {
        @Override
        protected void result(Object object) {
            if ((boolean) object) {
                renameColor(color, textField.getText());
            }
        }

        @Override
        public Dialog show(Stage stage) {
            Dialog dialog = super.show(stage);
            main.getStage().setKeyboardFocus(textField);
            return dialog;
        }
    };

    dialog.getTitleTable().padLeft(5.0f);

    float brightness = Utils.brightness(color.color);
    Color borderColor;
    if (brightness > .35f) {
        borderColor = Color.BLACK;
    } else {
        borderColor = Color.WHITE;
    }

    Table bg = new Table(skin);
    bg.setBackground("white");
    bg.setColor(borderColor);
    dialog.getContentTable().add(bg);

    Label label = new Label(color.getName(), skin, "white");
    label.setColor(color.color);
    bg.add(label).pad(10);

    dialog.getContentTable().row();
    label = new Label("What do you want to rename the color to?", skin);
    dialog.getContentTable().add(label);

    dialog.getContentTable().row();
    textField.setText(color.getName());
    textField.selectAll();
    textField.addListener(main.getIbeamListener());
    dialog.getContentTable().add(textField);
    dialog.getCell(dialog.getContentTable()).pad(15.0f);

    dialog.button("OK", true);
    dialog.button("Cancel", false).key(Keys.ESCAPE, false);
    okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor();
    okButton.setDisabled(true);
    okButton.addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.getButtonTable().padBottom(15.0f);

    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !ColorData.validate(textField.getText());
            if (!disable) {
                for (ColorData data : jsonData.getColors()) {
                    if (data.getName().equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }
            okButton.setDisabled(disable);
        }
    });
    textField.setTextFieldListener(new TextField.TextFieldListener() {
        @Override
        public void keyTyped(TextField textField, char c) {
            if (c == '\n') {
                if (!okButton.isDisabled()) {
                    renameColor(color, textField.getText());
                    dialog.hide();
                }
            }
        }
    });

    textField.setFocusTraversal(false);
    dialog.show(getStage());
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

private void colorSwatchesDialog(DrawableData drawableData) {
    DialogColors dialog = new DialogColors(getSkin(), "dialog", null, true, dialogFactory, jsonData,
            projectData, atlasData, main, (ColorData colorData) -> {
                if (colorData != null) {
                    final DrawableData tintedDrawable = new DrawableData(drawableData.file);
                    tintedDrawable.tintName = colorData.getName();

                    //Fix background color for new, tinted drawable
                    Color temp = Utils.averageEdgeColor(tintedDrawable.file, colorData.color);

                    if (Utils.brightness(temp) > .5f) {
                        tintedDrawable.bgColor = Color.BLACK;
                    } else {
                        tintedDrawable.bgColor = Color.WHITE;
                    }// www  .  j a  v  a 2  s  .  c o  m

                    final TextField textField = new TextField(drawableData.name, getSkin());
                    final TextButton button = new TextButton("OK", getSkin());
                    button.setDisabled(!DrawableData.validate(textField.getText())
                            || checkIfNameExists(textField.getText()));
                    button.addListener(main.getHandListener());
                    textField.addListener(new ChangeListener() {
                        @Override
                        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                            button.setDisabled(!DrawableData.validate(textField.getText())
                                    || checkIfNameExists(textField.getText()));
                        }
                    });
                    textField.addListener(main.getIbeamListener());

                    Dialog approveDialog = new Dialog("TintedDrawable...", getSkin(), "bg") {
                        @Override
                        protected void result(Object object) {
                            if (object instanceof Boolean && (boolean) object) {
                                tintedDrawable.name = textField.getText();
                                atlasData.getDrawables().add(tintedDrawable);
                                projectData.setChangesSaved(false);
                            }
                        }

                        @Override
                        public boolean remove() {
                            gatherDrawables();
                            produceAtlas();
                            sortBySelectedMode();
                            getStage().setScrollFocus(scrollPane);
                            return super.remove();
                        }
                    };
                    approveDialog.addCaptureListener(new InputListener() {
                        @Override
                        public boolean keyDown(InputEvent event, int keycode2) {
                            if (keycode2 == Input.Keys.ENTER) {
                                if (!button.isDisabled()) {
                                    tintedDrawable.name = textField.getText();
                                    atlasData.getDrawables().add(tintedDrawable);
                                    projectData.setChangesSaved(false);
                                    approveDialog.hide();
                                }
                            }
                            return false;
                        }
                    });

                    approveDialog.getTitleTable().padLeft(5.0f);
                    approveDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
                    approveDialog.getButtonTable().padBottom(15.0f);

                    approveDialog.text("What is the name of the new tinted drawable?");

                    Drawable drawable = drawablePairs.get(drawableData);
                    Drawable preview = null;
                    if (drawable instanceof SpriteDrawable) {
                        preview = ((SpriteDrawable) drawable).tint(colorData.color);
                    } else if (drawable instanceof NinePatchDrawable) {
                        preview = ((NinePatchDrawable) drawable).tint(colorData.color);
                    }
                    if (preview != null) {
                        approveDialog.getContentTable().row();
                        Table table = new Table();
                        table.setBackground(preview);
                        approveDialog.getContentTable().add(table);
                    }

                    approveDialog.getContentTable().row();
                    approveDialog.getContentTable().add(textField).growX();

                    approveDialog.button(button, true);
                    approveDialog.button("Cancel", false);
                    approveDialog.getButtonTable().getCells().get(1).getActor()
                            .addListener(main.getHandListener());
                    approveDialog.key(Input.Keys.ESCAPE, false);
                    approveDialog.show(getStage());
                    getStage().setKeyboardFocus(textField);
                    textField.selectAll();

                    textField.setFocusTraversal(false);
                }
            });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.populate();
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

private void renameDrawableDialog(DrawableData drawable) {
    TextField textField = new TextField("", getSkin());
    Dialog dialog = new Dialog("Rename drawable?", getSkin(), "bg") {
        @Override//from   w  ww .  java  2  s.  c  o m
        protected void result(Object object) {
            super.result(object);

            if (object instanceof Boolean && (boolean) object == true) {
                renameDrawable(drawable, textField.getText());
            }
            getStage().setScrollFocus(scrollPane);
        }

        @Override
        public Dialog show(Stage stage) {
            Dialog dialog = super.show(stage);
            stage.setKeyboardFocus(textField);
            return dialog;
        }
    };

    dialog.getTitleTable().padLeft(5.0f);
    dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
    dialog.getButtonTable().padBottom(15.0f);

    dialog.getContentTable().add(new Label("Please enter a new name for the drawable: ", getSkin()));

    dialog.button("OK", true);
    dialog.button("Cancel", false).key(Keys.ESCAPE, false);
    TextButton okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor();
    okButton.setDisabled(true);
    okButton.addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());

    dialog.getContentTable().row();
    textField.setText(drawable.name);
    textField.selectAll();
    textField.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !DrawableData.validate(textField.getText());
            if (!disable) {
                for (DrawableData data : atlasData.getDrawables()) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }
            okButton.setDisabled(disable);
        }
    });
    textField.setTextFieldListener(new TextField.TextFieldListener() {
        @Override
        public void keyTyped(TextField textField, char c) {
            if (c == '\n') {
                if (!okButton.isDisabled()) {
                    renameDrawable(drawable, textField.getText());
                    dialog.hide();
                }
            }
        }
    });
    textField.addListener(main.getIbeamListener());
    dialog.getContentTable().add(textField);

    textField.setFocusTraversal(false);

    dialog.show(getStage());
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

/**
 * Shows a dialog to confirm deletion of all TintedDrawables based on the
 * provided drawable data. This is called when the delete button is pressed
 * on a drawable in the drawable list./*from  ww w  . j  a v a2s  .  c  om*/
 * @param drawable 
 */
private void showConfirmDeleteDialog(DrawableData drawable) {
    Dialog dialog = new Dialog("Delete duplicates?", getSkin(), "bg") {
        @Override
        protected void result(Object object) {
            if ((boolean) object) {
                removeDuplicateDrawables(drawable.file);
                gatherDrawables();
                sortBySelectedMode();
            }
        }
    };

    dialog.getTitleTable().padLeft(5.0f);
    dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
    dialog.getButtonTable().padBottom(15.0f);

    dialog.text(
            "Deleting this drawable will also delete one or more tinted drawables.\n" + "Delete duplicates?");
    dialog.button("OK", true);
    dialog.button("Cancel", false);
    dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    dialog.key(Input.Keys.ENTER, true);
    dialog.key(Input.Keys.ESCAPE, false);
    dialog.show(getStage());
}