Search in sources :

Example 6 with FocusListener

use of com.badlogic.gdx.scenes.scene2d.utils.FocusListener in project skin-composer by raeleus.

the class Spinner method addWidgets.

private void addWidgets() {
    buttonMinus = new Button(style.buttonMinusStyle);
    buttonPlus = new Button(style.buttonPlusStyle);
    textField = new TextField("", style.textFieldStyle) {

        @Override
        public void next(boolean up) {
            if (up) {
                if (transversalPrevious != null) {
                    getStage().setKeyboardFocus(transversalPrevious);
                    if (transversalPrevious instanceof TextField) {
                        ((TextField) transversalPrevious).selectAll();
                    }
                } else {
                    super.next(up);
                }
            } else {
                if (transversalNext != null) {
                    getStage().setKeyboardFocus(transversalNext);
                    if (transversalNext instanceof TextField) {
                        ((TextField) transversalNext).selectAll();
                    }
                } else {
                    super.next(up);
                }
            }
        }
    };
    textField.setAlignment(Align.center);
    textField.addListener(new InputListener() {

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.UP) {
                addValue();
                fire(new ChangeListener.ChangeEvent());
            } else if (keycode == Keys.DOWN) {
                subtractValue();
                fire(new ChangeListener.ChangeEvent());
            }
            return false;
        }
    });
    textField.setTextFieldFilter(new TextField.TextFieldFilter() {

        @Override
        public boolean acceptChar(TextField textField1, char c) {
            boolean returnValue = false;
            if ((c >= 48 && c <= 57) || c == 45 || (!rounding && c == 46)) {
                String text = textField1.getText();
                if (textField1.getCursorPosition() <= text.length()) {
                    text = text.substring(0, textField1.getCursorPosition());
                    text += c + textField1.getText().substring(textField1.getCursorPosition());
                }
                if (text.matches("-?\\d*\\.?\\d*")) {
                    returnValue = true;
                }
            }
            return returnValue;
        }
    });
    updateText();
    if (null != orientation)
        switch(orientation) {
            case HORIZONTAL:
                add(buttonMinus);
                add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
                add(buttonPlus);
                break;
            case HORIZONTAL_FLIPPED:
                add(buttonPlus);
                add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
                add(buttonMinus);
                break;
            case VERTICAL:
                add(buttonPlus);
                row();
                add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
                row();
                add(buttonMinus);
                break;
            case VERTICAL_FLIPPED:
                add(buttonMinus);
                row();
                add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
                row();
                add(buttonPlus);
                break;
            case RIGHT_STACK:
                {
                    add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
                    VerticalGroup group = new VerticalGroup();
                    add(group);
                    group.addActor(buttonPlus);
                    group.addActor(buttonMinus);
                    break;
                }
            case LEFT_STACK:
                {
                    VerticalGroup group = new VerticalGroup();
                    add(group);
                    group.addActor(buttonPlus);
                    group.addActor(buttonMinus);
                    add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
                    break;
                }
            default:
                break;
        }
    buttonMinus.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            subtractValue();
        }
    });
    buttonPlus.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            addValue();
        }
    });
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner parent = (Spinner) actor;
            String text = textField.getText();
            if (text.matches("\\-?(\\d+\\.?\\d*)|(\\.\\d+)")) {
                double value = Double.parseDouble(text);
                if (usingMinimum && value < parent.minimum) {
                    value = parent.minimum;
                } else if (usingMaximum && value > parent.maximum) {
                    value = parent.maximum;
                }
                parent.value = BigDecimal.valueOf(value);
            } else {
                parent.value = BigDecimal.valueOf(usingMinimum ? parent.minimum : 0);
            }
        }
    });
    textField.addListener(new FocusListener() {

        @Override
        public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
            Spinner parent = (Spinner) textField.getParent();
            if (usingMinimum && parent.value.doubleValue() < parent.minimum) {
                parent.value = BigDecimal.valueOf(parent.minimum);
            }
            if (usingMaximum && parent.value.doubleValue() > parent.maximum) {
                parent.value = BigDecimal.valueOf(parent.maximum);
            }
            parent.updateText();
        }
    });
    final Spinner spinner = this;
    addCaptureListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            event.setTarget(spinner);
        }
    });
}
Also used : VerticalGroup(com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener)

Example 7 with FocusListener

use of com.badlogic.gdx.scenes.scene2d.utils.FocusListener in project ultimate-java by pantinor.

the class ConversationDialog method initialize.

private void initialize() {
    screen.gameTimer.active = false;
    setModal(true);
    defaults().space(10);
    add(internalTable = new Table(Ultima4.skin)).expand().fill();
    row();
    internalTable.defaults().pad(1);
    scrollPane = new LogScrollPane(Ultima4.skin, width);
    scrollPane.setHeight(height);
    input = new TextField("", Ultima4.skin);
    input.setTextFieldListener(new TextFieldListener() {

        @Override
        public void keyTyped(TextField tf, char key) {
            if (key == '\r') {
                if (tf.getText().length() == 0) {
                    if (!cancelHide) {
                        hide();
                    }
                    cancelHide = false;
                }
                Conversation conversation = person.getConversation();
                if (conversation != null) {
                    if (conversation instanceof CustomInputConversation) {
                        ((CustomInputConversation) conversation).setParty(screen.context.getParty());
                    }
                    String query = tf.getText();
                    Topic t = conversation.matchTopic(query);
                    if (t != null) {
                        if (t.getQuery() != null && t.getQuery().equals("join")) {
                            String name = conversation.getName();
                            Virtue virtue = screen.context.getParty().getVirtueForJoinable(name);
                            if (virtue != null) {
                                CannotJoinError join = screen.context.getParty().join(name);
                                if (join == CannotJoinError.JOIN_SUCCEEDED) {
                                    scrollPane.add("I am honored to join thee!");
                                    screen.context.getCurrentMap().removeJoinedPartyMemberFromPeopleList(screen.context.getParty());
                                } else {
                                    scrollPane.add("Thou art not " + (join == CannotJoinError.JOIN_NOT_VIRTUOUS ? virtue.getDescription() : "experienced") + " enough for me to join thee.");
                                }
                            } else {
                                scrollPane.add("I cannot join thee.");
                            }
                        } else {
                            if (!conversation.isStandardQuery(query)) {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), t.getPhrase());
                            }
                            scrollPane.add(t.getPhrase());
                            if (t.getQuestion() != null) {
                                scrollPane.add(t.getQuestion());
                            }
                        }
                        previousTopic = t;
                    } else {
                        if (previousTopic != null && previousTopic.getQuestion() != null) {
                            if (query.toLowerCase().contains("y")) {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), previousTopic.getYesResponse());
                                scrollPane.add(previousTopic.getYesResponse());
                                if (conversation.getRespAffectsHumility() > 0) {
                                    screen.context.getParty().adjustKarma(KarmaAction.BRAGGED);
                                }
                            } else {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), previousTopic.getNoResponse());
                                scrollPane.add(previousTopic.getNoResponse());
                                if (previousTopic.isLbHeal()) {
                                    for (PartyMember pm : screen.context.getParty().getMembers()) {
                                        pm.heal(HealType.CURE);
                                        pm.heal(HealType.FULLHEAL);
                                    }
                                    Sounds.play(Sound.HEALING);
                                }
                                if (conversation.getRespAffectsHumility() > 0) {
                                    screen.context.getParty().adjustKarma(KarmaAction.HUMBLE);
                                }
                            }
                        } else {
                            scrollPane.add("That I cannot help thee with.");
                        }
                        previousTopic = null;
                    }
                } else if (person.getRole() != null && vendor != null) {
                    String input = tf.getText();
                    vendor.setResponse(input);
                    vendor.nextDialog();
                }
                tf.setText("");
            }
        }
    });
    defaults().pad(5);
    internalTable.add(scrollPane).maxWidth(width).width(width);
    internalTable.row();
    internalTable.add(input).maxWidth(width).width(width);
    focusListener = new FocusListener() {

        @Override
        public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            if (!focused) {
                focusChanged(event);
            }
        }

        @Override
        public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            if (!focused) {
                focusChanged(event);
            }
        }

        private void focusChanged(FocusEvent event) {
            Stage stage = getStage();
            if (isModal() && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == ConversationDialog.this) {
                Actor newFocusedActor = event.getRelatedActor();
                if (newFocusedActor != null && !newFocusedActor.isDescendantOf(ConversationDialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus))) {
                    event.cancel();
                }
            }
        }
    };
    person.setTalking(true);
    if (person.getConversation() != null) {
        if (person.getRole() != null && person.getRole().getRole().equals("lordbritish")) {
            LordBritishConversation conv = (LordBritishConversation) person.getConversation();
            scrollPane.add(conv.intro(screen.context));
            SequenceAction seq = Actions.action(SequenceAction.class);
            Party party = screen.context.getParty();
            if (party.getMember(0).getPlayer().status == StatusType.DEAD) {
                party.getMember(0).heal(HealType.RESURRECT);
                party.getMember(0).heal(HealType.FULLHEAL);
                seq.addAction(Actions.run(new LBAction(Sound.HEALING, "I resurrect thee.")));
                seq.addAction(Actions.delay(3f));
            }
            for (int i = 0; i < party.getMembers().size(); i++) {
                PartyMember pm = party.getMember(i);
                if (pm.getPlayer().advanceLevel()) {
                    seq.addAction(Actions.run(new LBAction(Sound.MAGIC, pm.getPlayer().name + " thou art now level " + pm.getPlayer().getLevel())));
                    seq.addAction(Actions.delay(3f));
                }
            }
            stage.addAction(seq);
        } else if (person.getRole() != null && person.getRole().getRole().equals("hawkwind")) {
            HawkwindConversation conv = (HawkwindConversation) person.getConversation();
            conv.setParty(screen.context.getParty());
            scrollPane.add(conv.intro());
        } else {
            scrollPane.add("You meet " + person.getConversation().getDescription().toLowerCase() + ".");
        }
    } else if (person.getRole() != null && person.getRole().getInventoryType() != null) {
        vendor = Ultima4.vendorClassSet.getVendorImpl(person.getRole().getInventoryType(), Maps.get(screen.context.getCurrentMap().getId()), screen.context);
        vendor.setScreen(screen);
        vendor.setScrollPane(scrollPane);
        vendor.nextDialog();
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) PartyMember(objects.Party.PartyMember) LordBritishConversation(objects.LordBritishConversation) LogScrollPane(util.LogScrollPane) Conversation(objects.Conversation) CustomInputConversation(objects.CustomInputConversation) LordBritishConversation(objects.LordBritishConversation) HawkwindConversation(objects.HawkwindConversation) HawkwindConversation(objects.HawkwindConversation) Party(objects.Party) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) Topic(objects.Conversation.Topic) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener) SequenceAction(com.badlogic.gdx.scenes.scene2d.actions.SequenceAction) CustomInputConversation(objects.CustomInputConversation)

Example 8 with FocusListener

use of com.badlogic.gdx.scenes.scene2d.utils.FocusListener in project skin-composer by raeleus.

the class PopSettings method populate.

public void populate() {
    pad(10);
    defaults().space(15);
    var label = new Label("Settings", skin, "title");
    add(label);
    row();
    var table = new Table();
    add(table);
    table.defaults().growX().space(5);
    if (!Utils.isMac()) {
        var textButton = new TextButton("Open temp/log directory", skin);
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(Main.appFolder.child("temp/"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening temp folder", e);
                    dialogFactory.showDialogError("Folder Error...", "Error opening temp folder.\n\nOpen log?");
                }
            }
        });
        textButton.addListener(handListener);
        table.add(textButton);
        table.row();
        textButton = new TextButton("Open preferences directory", skin);
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(Gdx.files.external(".prefs/"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening preferences folder", e);
                    dialogFactory.showDialogError("Folder Error...", "Error opening preferences folder.\n\nOpen log?");
                }
            }
        });
        textButton.addListener(handListener);
        table.add(textButton);
        if (projectData.areChangesSaved() && projectData.getSaveFile().exists()) {
            table.row();
            textButton = new TextButton("Open project/import directory", skin);
            textButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    try {
                        Utils.openFileExplorer(projectData.getSaveFile().sibling(projectData.getSaveFile().nameWithoutExtension() + "_data"));
                    } catch (Exception e) {
                        Gdx.app.error(getClass().getName(), "Error opening project folder", e);
                        dialogFactory.showDialogError("Folder Error...", "Error opening project folder\n\nOpen log?");
                    }
                }
            });
            textButton.addListener(handListener);
            table.add(textButton);
        }
        table.row();
        textButton = new TextButton("Open texture packer settings file for export", skin);
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(Main.appFolder.child("texturepacker/atlas-export-settings.json"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening atlas-export-settings.json", e);
                    dialogFactory.showDialogError("File Error...", "Error opening atlas-export-settings.json\n\nOpen log?");
                }
            }
        });
        textButton.addListener(handListener);
        table.add(textButton);
        table.row();
        textButton = new TextButton("Open texture packer settings file for preview", skin);
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(Main.appFolder.child("texturepacker/atlas-internal-settings.json"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening atlas-internal-settings.json", e);
                    dialogFactory.showDialogError("File Error...", "Error opening atlas-internal-settings.json\n\nOpen log?");
                }
            }
        });
        textButton.addListener(handListener);
        table.add(textButton);
    }
    row();
    table = new Table();
    add(table);
    table.defaults().space(5);
    label = new Label("UI Scale:", skin);
    table.add(label);
    var slider = new Slider(1, 3, 1, false, skin);
    slider.setValue(uiScale);
    table.add(slider);
    slider.addListener(handListener);
    var scaleLabel = new Label(uiScale + "x", skin);
    table.add(scaleLabel).width(25);
    slider.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            uiScale = (int) slider.getValue();
            scaleLabel.setText(uiScale + "x");
            main.resizeUiScale(uiScale, uiScale > 1);
            changedUIscale = true;
        }
    });
    var textButton = new TextButton("Auto", skin);
    table.add(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            var display = Gdx.graphics.getDisplayMode();
            uiScale = display.height >= 1440 ? 2 : 1;
            slider.setValue(uiScale);
            scaleLabel.setText(uiScale + "x");
            main.resizeUiScale(uiScale, uiScale > 1);
            changedUIscale = true;
        }
    });
    row();
    table = new Table();
    add(table);
    table.defaults().space(5);
    label = new Label("Max Number of Undos: ", skin);
    table.add(label);
    var spinner = new Spinner(projectData.getMaxUndos(), 1.0, true, Orientation.HORIZONTAL, getSkin());
    spinner.setMinimum(1.0);
    spinner.setMaximum(100.0);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            maxUndos = (int) spinner.getValue();
        }
    });
    spinner.addListener(new FocusListener() {

        @Override
        public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
            maxUndos = (int) spinner.getValue();
        }
    });
    spinner.getTextField().addListener(ibeamListener);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    table.add(spinner).minWidth(100.0f);
    row();
    table = new Table();
    add(table);
    table.defaults().expandX().left().space(5);
    var relativeCheckBox = new ImageTextButton("Keep resources relative?", getSkin(), "checkbox");
    relativeCheckBox.setChecked(resourcesRelative);
    relativeCheckBox.addListener(handListener);
    relativeCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            resourcesRelative = relativeCheckBox.isChecked();
        }
    });
    table.add(relativeCheckBox);
    table.row();
    var welcomeCheckBox = new ImageTextButton("Show welcome screen?", getSkin(), "checkbox");
    welcomeCheckBox.setChecked(allowingWelcome);
    welcomeCheckBox.addListener(handListener);
    welcomeCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            allowingWelcome = welcomeCheckBox.isChecked();
        }
    });
    table.add(welcomeCheckBox);
    table.row();
    var exportWarningsCheckBox = new ImageTextButton("Show export warnings?", getSkin(), "checkbox");
    exportWarningsCheckBox.setChecked(exportWarnings);
    exportWarningsCheckBox.addListener(handListener);
    exportWarningsCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            exportWarnings = exportWarningsCheckBox.isChecked();
        }
    });
    table.add(exportWarningsCheckBox);
    table.row();
    var fullPathCheckBox = new ImageTextButton("Show full path in recent files", getSkin(), "checkbox");
    fullPathCheckBox.setChecked(recentFullPath);
    fullPathCheckBox.addListener(handListener);
    fullPathCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            recentFullPath = fullPathCheckBox.isChecked();
        }
    });
    table.add(fullPathCheckBox);
    table.row();
    var updatesCheckBox = new ImageTextButton("Check for updates?", getSkin(), "checkbox");
    updatesCheckBox.setChecked(allowingUpdates);
    updatesCheckBox.addListener(handListener);
    updatesCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            allowingUpdates = updatesCheckBox.isChecked();
        }
    });
    table.add(updatesCheckBox);
    row();
    var buttonTable = new Table();
    buttonTable.pad(5);
    add(buttonTable);
    buttonTable.defaults().minWidth(75).space(5);
    textButton = new TextButton("OK", getSkin());
    textButton.addListener(handListener);
    buttonTable.add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            approve();
        }
    });
    textButton = new TextButton("CANCEL", getSkin());
    textButton.addListener(handListener);
    buttonTable.add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            cancel();
        }
    });
    key(Keys.ESCAPE, () -> {
        cancel();
    });
}
Also used : RootTable(com.ray3k.skincomposer.RootTable) PopTable(com.ray3k.stripe.PopTable) Spinner(com.ray3k.stripe.Spinner) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)8 FocusListener (com.badlogic.gdx.scenes.scene2d.utils.FocusListener)8 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)7 Stage (com.badlogic.gdx.scenes.scene2d.Stage)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)3 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)2 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)2 TextFieldListener (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener)2 SequenceAction (com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)1 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)1 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)1 VerticalGroup (com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup)1 Array (com.badlogic.gdx.utils.Array)1 RootTable (com.ray3k.skincomposer.RootTable)1 Spinner (com.ray3k.skincomposer.Spinner)1 PopTable (com.ray3k.stripe.PopTable)1