Search in sources :

Example 6 with InputDialogListener

use of com.kotcrab.vis.ui.util.dialog.InputDialogListener in project HyperLap2D by rednblackgames.

the class GraphContainer method setupListeners.

private void setupListeners() {
    addListener(new ClickListener(Input.Buttons.RIGHT) {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!containedInWindow(x, y)) {
                NodeGroupImpl nodeGroup = null;
                for (Map.Entry<NodeGroupImpl, Rectangle> nodeGroupEntry : nodeGroups.entrySet()) {
                    Rectangle rectangle = nodeGroupEntry.getValue();
                    if (rectangle.contains(x, y) && y > rectangle.y + rectangle.height - GROUP_LABEL_HEIGHT) {
                        // Hit the label
                        nodeGroup = nodeGroupEntry.getKey();
                        break;
                    }
                }
                if (nodeGroup != null) {
                    final NodeGroupImpl finalNodeGroup = nodeGroup;
                    H2DPopupMenu popupMenu = new H2DPopupMenu();
                    MenuItem rename = new MenuItem("Rename group");
                    rename.addListener(new ClickListener(Input.Buttons.LEFT) {

                        @Override
                        public void clicked(InputEvent event, float x, float y) {
                            Dialogs.showInputDialog(getStage(), "Enter group name", "Name", new InputValidator() {

                                @Override
                                public boolean validateInput(String input) {
                                    return !input.trim().isEmpty();
                                }
                            }, new InputDialogListener() {

                                @Override
                                public void finished(String input) {
                                    finalNodeGroup.setName(input.trim());
                                    fire(new GraphChangedEvent(false, false));
                                }

                                @Override
                                public void canceled() {
                                }
                            }).setText(finalNodeGroup.getName(), true);
                        }
                    });
                    popupMenu.addItem(rename);
                    MenuItem remove = new MenuItem("Remove group");
                    remove.addListener(new ClickListener(Input.Buttons.LEFT) {

                        @Override
                        public void clicked(InputEvent event, float x, float y) {
                            nodeGroups.remove(finalNodeGroup);
                            fire(new GraphChangedEvent(false, false));
                        }
                    });
                    popupMenu.addItem(remove);
                    showPopupMenu(popupMenu);
                } else {
                    H2DPopupMenu popupMenu = popupMenuProducer.createPopupMenu(x, y);
                    showPopupMenu(popupMenu);
                }
            }
        }
    });
    addListener(new ClickListener(Input.Buttons.LEFT) {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            processLeftClick(x, y);
            return super.touchDown(event, x, y, pointer, button);
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            processLeftClick(x, y);
        }
    });
    DragListener dragListener = new DragListener() {

        private float canvasXStart;

        private float canvasYStart;

        private NodeGroup dragGroup;

        private float movedByX = 0;

        private float movedByY = 0;

        @Override
        public void dragStart(InputEvent event, float x, float y, int pointer) {
            if (event.getTarget() == GraphContainer.this) {
                canvasXStart = canvasX;
                canvasYStart = canvasY;
                movedByX = 0;
                movedByY = 0;
                dragGroup = null;
                for (Map.Entry<NodeGroupImpl, Rectangle> nodeGroupEntry : nodeGroups.entrySet()) {
                    Rectangle rectangle = nodeGroupEntry.getValue();
                    if (rectangle.contains(x, y) && y > rectangle.y + rectangle.height - GROUP_LABEL_HEIGHT) {
                        // Hit the label
                        dragGroup = nodeGroupEntry.getKey();
                        break;
                    }
                }
            }
        }

        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            if (event.getTarget() == GraphContainer.this) {
                if (dragGroup != null) {
                    movingSelected = true;
                    float moveByX = x - getDragStartX() - movedByX;
                    float moveByY = y - getDragStartY() - movedByY;
                    for (String nodeId : dragGroup.getNodeIds()) {
                        getBoxWindow(nodeId).moveBy(moveByX, moveByY);
                    }
                    movedByX += moveByX;
                    movedByY += moveByY;
                    windowsMoved();
                    updateNodeGroups();
                    movingSelected = false;
                } else {
                    navigateTo(canvasXStart + getDragStartX() - x, canvasYStart + getDragStartY() - y);
                }
            }
        }
    };
    dragListener.setTapSquareSize(0f);
    dragListener.setButton(Input.Buttons.MIDDLE);
    addListener(dragListener);
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) H2DPopupMenu(games.rednblack.h2d.common.view.ui.widget.H2DPopupMenu) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) InputDialogListener(com.kotcrab.vis.ui.util.dialog.InputDialogListener) DragListener(com.badlogic.gdx.scenes.scene2d.utils.DragListener) InputValidator(com.kotcrab.vis.ui.util.InputValidator) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

InputDialogListener (com.kotcrab.vis.ui.util.dialog.InputDialogListener)6 Rectangle (com.badlogic.gdx.math.Rectangle)2 InputValidator (com.kotcrab.vis.ui.util.InputValidator)2 MenuItem (com.kotcrab.vis.ui.widget.MenuItem)2 Sandbox (games.rednblack.editor.view.stage.Sandbox)2 StringNameValidator (games.rednblack.editor.view.ui.validator.StringNameValidator)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 DragListener (com.badlogic.gdx.scenes.scene2d.utils.DragListener)1 Json (com.badlogic.gdx.utils.Json)1 PopupMenu (com.kotcrab.vis.ui.widget.PopupMenu)1 ProjectManager (games.rednblack.editor.proxy.ProjectManager)1 SceneDataManager (games.rednblack.editor.proxy.SceneDataManager)1 ZIndexComponent (games.rednblack.editor.renderer.components.ZIndexComponent)1 GraphVO (games.rednblack.editor.renderer.data.GraphVO)1 LayerItemVO (games.rednblack.editor.renderer.data.LayerItemVO)1 HyperJson (games.rednblack.editor.renderer.utils.HyperJson)1 H2DPopupMenu (games.rednblack.h2d.common.view.ui.widget.H2DPopupMenu)1