Search in sources :

Example 1 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project AmazingMaze by TheVirtualMachine.

the class FishMiniGame method dialog.

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

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

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

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

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

Example 2 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project AmazingMaze by TheVirtualMachine.

the class ContinueScreen method highScoreDialog.

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

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

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

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

Example 3 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.

the class SkinEditorGame method showNotice.

/**
	 * Display a dialog with a notice
	 */
public void showNotice(String title, String message, Stage stage) {
    Dialog dlg = new Dialog(title, skin);
    dlg.pad(20);
    dlg.getContentTable().add(message).pad(20);
    dlg.button("OK", true);
    dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
    dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
    dlg.show(stage);
}
Also used : Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog)

Example 4 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.

the class MenuBar method showExportDialog.

/*
	 * Show export dialog
	 */
protected void showExportDialog() {
    final Preferences prefs = Gdx.app.getPreferences("skin_editor_project_" + game.screenMain.getcurrentProject());
    final TextField textDirectory = new TextField(prefs.getString("export_to_directory"), game.skin);
    Dialog dlg = new Dialog("Export to Directory", game.skin) {

        @Override
        protected void result(Object object) {
            if ((Boolean) object == true) {
                if (textDirectory.getText().isEmpty() == true) {
                    game.showNotice("Warning", "Directory field is empty!", game.screenMain.stage);
                    return;
                }
                FileHandle targetDirectory = new FileHandle(textDirectory.getText());
                if (targetDirectory.exists() == false) {
                    game.showNotice("Warning", "Directory not found!", game.screenMain.stage);
                    return;
                }
                // Copy uiskin.* and *.fnt 
                FileHandle projectFolder = Gdx.files.local("projects").child(game.screenMain.getcurrentProject());
                for (FileHandle file : projectFolder.list()) {
                    if (file.name().startsWith("uiskin.") || (file.extension().equalsIgnoreCase("fnt"))) {
                        Gdx.app.log("MenuBar", "Copying file: " + file.name() + " ...");
                        FileHandle target = targetDirectory.child(file.name());
                        file.copyTo(target);
                    }
                }
                game.showNotice("Operation Completed", "Project successfully exported!", game.screenMain.stage);
            }
        }
    };
    dlg.pad(20);
    Table table = dlg.getContentTable();
    table.padTop(20);
    table.add("Directory:");
    table.add(textDirectory).width(320);
    TextButton buttonChoose = new TextButton("...", game.skin);
    buttonChoose.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            // Need to steal focus first with this hack (Thanks to Z-Man)
            Frame frame = new Frame();
            frame.setUndecorated(true);
            frame.setOpacity(0);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            frame.toFront();
            frame.setVisible(false);
            frame.dispose();
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int ret = chooser.showOpenDialog(null);
            if (ret == JFileChooser.APPROVE_OPTION) {
                File f = chooser.getSelectedFile();
                textDirectory.setText(f.getAbsolutePath());
                // Store to file
                prefs.putString("export_to_directory", f.getAbsolutePath());
                prefs.flush();
            }
        }
    });
    table.add(buttonChoose);
    table.row();
    table.padBottom(20);
    dlg.button("Export", true);
    dlg.button("Cancel", false);
    dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
    dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
    dlg.show(getStage());
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Frame(java.awt.Frame) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) FileHandle(com.badlogic.gdx.files.FileHandle) JFileChooser(javax.swing.JFileChooser) DrawablePickerDialog(org.shadebob.skineditor.DrawablePickerDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) ColorPickerDialog(org.shadebob.skineditor.ColorPickerDialog) FontPickerDialog(org.shadebob.skineditor.FontPickerDialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) Preferences(com.badlogic.gdx.Preferences) File(java.io.File)

Example 5 with Dialog

use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.

the class WelcomeScreen method showDeleteDialog.

/**
	 * 
	 */
private void showDeleteDialog() {
    Dialog dlgStyle = new Dialog("Delete Project", game.skin) {

        @Override
        protected void result(Object object) {
            if ((Boolean) object == false) {
                return;
            }
            // We delete it
            FileHandle projectFolder = Gdx.files.local("projects/" + (String) listProjects.getSelected());
            projectFolder.deleteDirectory();
            refreshProjects();
        }
    };
    dlgStyle.pad(20);
    dlgStyle.getContentTable().add("You are sure you want to delete this project?");
    dlgStyle.button("OK", true);
    dlgStyle.button("Cancel", false);
    dlgStyle.key(com.badlogic.gdx.Input.Keys.ENTER, true);
    dlgStyle.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
    dlgStyle.show(stage);
}
Also used : NinePatchEditorDialog(org.shadebob.skineditor.NinePatchEditorDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) FileHandle(com.badlogic.gdx.files.FileHandle)

Aggregations

Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)13 Actor (com.badlogic.gdx.scenes.scene2d.Actor)6 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)6 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)5 ColorPickerDialog (org.shadebob.skineditor.ColorPickerDialog)4 DrawablePickerDialog (org.shadebob.skineditor.DrawablePickerDialog)4 FontPickerDialog (org.shadebob.skineditor.FontPickerDialog)4 FileHandle (com.badlogic.gdx.files.FileHandle)3 Texture (com.badlogic.gdx.graphics.Texture)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 TextFieldListener (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener)2 NinePatchEditorDialog (org.shadebob.skineditor.NinePatchEditorDialog)2 Preferences (com.badlogic.gdx.Preferences)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1