Search in sources :

Example 1 with TextField

use of com.badlogic.gdx.scenes.scene2d.ui.TextField in project libgdx by libgdx.

the class TextAreaTest method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    TextArea textArea = new TextArea("Text Area\nEssentially, a text field\nwith\nmultiple\nlines.\n" + "It can even handle very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong lines.", skin);
    textArea.setX(10);
    textArea.setY(10);
    textArea.setWidth(200);
    textArea.setHeight(200);
    TextField textField = new TextField("Text field", skin);
    textField.setX(10);
    textField.setY(220);
    textField.setWidth(200);
    textField.setHeight(30);
    stage.addActor(textArea);
    stage.addActor(textField);
}
Also used : TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 2 with TextField

use of com.badlogic.gdx.scenes.scene2d.ui.TextField 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 TextField

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

the class PreviewPane method refresh.

/**
	 * 
	 */
public void refresh() {
    Gdx.app.log("PreviewPane", "Refresh pane!");
    clear();
    ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
    String widget = button.getUserObject().toString();
    String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
    try {
        Class<?> style = Class.forName(widgetStyle);
        ObjectMap<String, ?> styles = game.skinProject.getAll(style);
        if (styles == null) {
            Label label = new Label("No styles defined for this widget type", game.skin, "error");
            add(label).row().pad(10);
        } else {
            Keys<String> keys = styles.keys();
            Array<String> sortedKeys = new Array<String>();
            for (String key : keys) {
                sortedKeys.add(key);
            }
            sortedKeys.sort();
            for (String key : sortedKeys) {
                // We render one per key
                add(new Label(key, game.skin, "title")).left().pad(10).expandX().row();
                try {
                    if (widget.equals("Label")) {
                        Label w = new Label("This is a Label widget", game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("Button")) {
                        // Button
                        Button w = new Button(game.skinProject, key);
                        add(w).width(120).height(32).pad(10).padBottom(20).row();
                    } else if (widget.equals("TextButton")) {
                        // TextButton
                        TextButton w = new TextButton("This is a TextButton widget", game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("ImageButton")) {
                        // ImageButton
                        ImageButton w = new ImageButton(game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("CheckBox")) {
                        // CheckBox
                        CheckBox w = new CheckBox("This is a CheckBox widget", game.skinProject, key);
                        w.setChecked(true);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("TextField")) {
                        // TextField
                        TextField w = new TextField("This is a TextField widget", game.skinProject, key);
                        if (w.getStyle().fontColor == null) {
                            throw new Exception("Textfield style requires a font color!");
                        }
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(220).padBottom(20).row();
                    } else if (widget.equals("List")) {
                        // List
                        List w = new List(game.skinProject, key);
                        Array<String> items = new Array<String>();
                        items.add("This is");
                        items.add("a");
                        items.add("List widget!");
                        w.setItems(items);
                        add(w).pad(10).width(220).height(120).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("SelectBox")) {
                        // SelectBox
                        SelectBox<String> w = new SelectBox<String>(game.skinProject, key);
                        Array<String> items = new Array<String>();
                        items.add("This is");
                        items.add("a");
                        items.add("SelectBox widget!");
                        w.setItems(items);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("ProgressBar")) {
                        // ProgressBar
                        ProgressBarStyle progressStyle = game.skinProject.get(key, ProgressBarStyle.class);
                        // Check for edge-case: fields knob and knobBefore are optional but at least one should be specified
                        if (progressStyle.knob == null && progressStyle.knobBefore == null) {
                            throw new IllegalArgumentException("Fields 'knob' and 'knobBefore' in ProgressBarStyle are both optional but at least one should be specified");
                        }
                        ProgressBar w = new ProgressBar(0, 100, 5, false, progressStyle);
                        w.setValue(50);
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Slider")) {
                        // Slider
                        Slider w = new Slider(0, 100, 5, false, game.skinProject, key);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                        w.addListener(stopTouchDown);
                        Slider w2 = new Slider(0, 100, 5, true, game.skinProject, key);
                        add(w2).pad(10).padBottom(20).expandX().fillX().row();
                        w2.addListener(stopTouchDown);
                    } else if (widget.equals("ScrollPane")) {
                        // ScrollPane
                        Table t = new Table(game.skin);
                        for (int i = 0; i < 20; i++) {
                            t.add("This is a ScrollPane Widget").padRight(10);
                            t.add("This is a ScrollPane Widget").padRight(10);
                            t.add("This is a ScrollPane Widget").row();
                        }
                        ScrollPane w = new ScrollPane(t, game.skinProject, key);
                        w.addListener(stopTouchDown);
                        w.setFlickScroll(true);
                        w.setScrollbarsOnTop(true);
                        w.setScrollBarPositions(true, true);
                        w.setFadeScrollBars(false);
                        add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("SplitPane")) {
                        for (int j = 0; j < 2; j++) {
                            Table t = new Table(game.skin);
                            t.setBackground(game.skin.getDrawable("default-rect"));
                            Table t2 = new Table(game.skin);
                            t2.setBackground(game.skin.getDrawable("default-rect"));
                            for (int i = 0; i < 20; i++) {
                                t.add("This is a SplitPane Widget").pad(10).row();
                                t2.add("This is a SplitPane Widget").pad(10).row();
                            }
                            SplitPane w = new SplitPane(t, t2, (j % 2 == 0), game.skinProject, key);
                            w.addListener(stopTouchDown);
                            add(w).pad(10).width(220).height(160).padBottom(20).expandX().fillX();
                        }
                        row();
                    } else if (widget.equals("Window")) {
                        // Window
                        Table t = new Table(game.skin);
                        for (int i = 0; i < 5; i++) {
                            t.add("This is a Window Widget").row();
                        }
                        Window w = new Window("This is a Window Widget", game.skinProject, key);
                        w.addListener(stopTouchDown);
                        w.add(t);
                        add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Touchpad")) {
                        // Touchpad
                        Touchpad w = new Touchpad(0, game.skinProject, key);
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Tree")) {
                        // Tree
                        Tree w = new Tree(game.skinProject, key);
                        Tree.Node node = new Tree.Node(new Label("This", game.skin));
                        Tree.Node node1 = new Tree.Node(new Label("is", game.skin));
                        Tree.Node node2 = new Tree.Node(new Label("a", game.skin));
                        Tree.Node node3 = new Tree.Node(new Label("Tree", game.skin));
                        Tree.Node node4 = new Tree.Node(new Label("Widget", game.skin));
                        node3.add(node4);
                        node2.add(node3);
                        node1.add(node2);
                        node.add(node1);
                        w.add(node);
                        w.expandAll();
                        add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
                    } else {
                        add(new Label("Unknown widget type!", game.skin, "error")).pad(10).padBottom(20).row();
                    }
                } catch (Exception e) {
                    add(new Label("Please fill all required fields", game.skin, "error")).pad(10).padBottom(20).row();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Node(com.badlogic.gdx.graphics.g3d.model.Node) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) ProgressBarStyle(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar.ProgressBarStyle) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Tree(com.badlogic.gdx.scenes.scene2d.ui.Tree) List(com.badlogic.gdx.scenes.scene2d.ui.List) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Array(com.badlogic.gdx.utils.Array) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)

Example 4 with TextField

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

the class NewFontDialog method refreshFontPreview.

/**
	 * 
	 */
public void refreshFontPreview() {
    try {
        String fontName = selectFonts.getSelected();
        Gdx.app.log("FontPickerDialog", "Refreshing preview for font: " + fontName);
        File fontPath = game.fm.fonts.get(selectFonts.getSelected());
        Gdx.app.log("FontPickerDialog", "Loading font from file:" + fontPath);
        Font font = Font.createFont(Font.TRUETYPE_FONT, fontPath);
        UnicodeFont unicodeFont = new UnicodeFont(font, Integer.valueOf(selectSize.getSelected()), checkBold.isChecked(), checkItalic.isChecked());
        if (checkShadow.isChecked() == true) {
            ColorEffect colorEffect = new ColorEffect();
            colorEffect.setColor(java.awt.Color.BLACK);
            unicodeFont.getEffects().add(colorEffect);
            ShadowEffect shadow = new ShadowEffect();
            shadow.setOpacity(1.0f);
            shadow.setXDistance(1);
            shadow.setYDistance(1);
            shadow.setColor(java.awt.Color.WHITE);
            unicodeFont.getEffects().add(shadow);
        } else {
            ColorEffect colorEffect = new ColorEffect();
            colorEffect.setColor(java.awt.Color.WHITE);
            unicodeFont.getEffects().add(colorEffect);
        }
        unicodeFont.addAsciiGlyphs();
        String newFontName = generateProperFontName(fontName);
        textFontName.setText(newFontName);
        // Create bitmap font
        BMFontUtil bfu = new BMFontUtil(unicodeFont);
        FileHandle handle = new FileHandle(System.getProperty("java.io.tmpdir")).child(newFontName);
        FileHandle handleFont = new FileHandle(handle.file().getAbsolutePath() + ".fnt");
        bfu.save(handle.file());
        FileHandle handleImage = new FileHandle(System.getProperty("java.io.tmpdir")).child(newFontName + ".png");
        TextField.TextFieldStyle textStyle = new TextField.TextFieldStyle();
        textStyle.cursor = game.skin.getDrawable("cursor");
        textStyle.selection = game.skin.getDrawable("selection");
        textStyle.background = game.skin.getDrawable("textfield");
        textStyle.fontColor = Color.YELLOW;
        textStyle.font = new BitmapFont(handleFont, handleImage, false);
        textFontPreview.setStyle(textStyle);
        // Have to do this to force clipping of font
        textFontPreview.setText(textFontPreview.getText());
    } catch (Exception e) {
        e.printStackTrace();
        textFontPreview.getStyle().font = game.skin.getFont("default-font");
        // Have to do this to force clipping of font
        textFontPreview.setText(textFontPreview.getText());
    }
}
Also used : UnicodeFont(com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont) FileHandle(com.badlogic.gdx.files.FileHandle) Font(java.awt.Font) UnicodeFont(com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ColorEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ColorEffect) ShadowEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ShadowEffect) BMFontUtil(com.badlogic.gdx.tools.hiero.BMFontUtil) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) File(java.io.File)

Example 5 with TextField

use of com.badlogic.gdx.scenes.scene2d.ui.TextField 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)

Aggregations

TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)10 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)6 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)5 Actor (com.badlogic.gdx.scenes.scene2d.Actor)4 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)4 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)4 Stage (com.badlogic.gdx.scenes.scene2d.Stage)3 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)3 ColorPickerDialog (org.shadebob.skineditor.ColorPickerDialog)3 DrawablePickerDialog (org.shadebob.skineditor.DrawablePickerDialog)3 FontPickerDialog (org.shadebob.skineditor.FontPickerDialog)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)2 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)2 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)2