Search in sources :

Example 1 with DuplicateStyleUndoable

use of com.ray3k.skincomposer.UndoableManager.DuplicateStyleUndoable in project skin-composer by raeleus.

the class DialogFactory method showDuplicateStyleDialog.

public void showDuplicateStyleDialog(Skin skin, Stage stage) {
    Class selectedClass = main.getRootTable().getSelectedClass();
    StyleData originalStyle = main.getRootTable().getSelectedStyle();
    final TextField textField = new TextField("", skin);
    Dialog dialog = new Dialog("Duplicate Style", skin, "bg") {

        @Override
        protected void result(Object object) {
            if ((Boolean) object) {
                main.getUndoableManager().addUndoable(new DuplicateStyleUndoable(originalStyle, textField.getText(), main), true);
            }
        }
    };
    dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
    dialog.button("OK", true).button("Cancel", false);
    final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();
    okButton.addListener(main.getHandListener());
    dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    textField.setTextFieldListener((TextField textField1, char c) -> {
        if (c == '\n') {
            if (!okButton.isDisabled()) {
                main.getUndoableManager().addUndoable(new DuplicateStyleUndoable(originalStyle, textField.getText(), main), true);
                dialog.hide();
            }
            main.getStage().setKeyboardFocus(textField1);
        }
    });
    textField.addListener(main.getIbeamListener());
    dialog.getTitleLabel().setAlignment(Align.center);
    dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
    dialog.text("What is the name of the new, duplicated style?");
    dialog.getContentTable().getCells().first().pad(10.0f);
    dialog.getContentTable().row();
    dialog.getContentTable().add(textField).growX();
    okButton.setDisabled(true);
    Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            boolean disable = !StyleData.validate(textField.getText());
            if (!disable) {
                for (StyleData data : currentStyles) {
                    if (data.name.equals(textField.getText())) {
                        disable = true;
                        break;
                    }
                }
            }
            okButton.setDisabled(disable);
        }
    });
    dialog.key(Input.Keys.ESCAPE, false);
    dialog.show(stage);
    stage.setKeyboardFocus(textField);
    textField.setFocusTraversal(false);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) DuplicateStyleUndoable(com.ray3k.skincomposer.UndoableManager.DuplicateStyleUndoable) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) CustomClass(com.ray3k.skincomposer.data.CustomClass) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) StyleData(com.ray3k.skincomposer.data.StyleData)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)1 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 DuplicateStyleUndoable (com.ray3k.skincomposer.UndoableManager.DuplicateStyleUndoable)1 CustomClass (com.ray3k.skincomposer.data.CustomClass)1 StyleData (com.ray3k.skincomposer.data.StyleData)1