Search in sources :

Example 6 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem in project gdx-graph by MarcinSc.

the class GraphContainer method processRightClick.

private void processRightClick(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;
            PopupMenu popupMenu = new PopupMenu();
            MenuItem rename = new MenuItem("Rename group");
            rename.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    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() {
                        }
                    });
                }
            });
            popupMenu.addItem(rename);
            MenuItem remove = new MenuItem("Remove group");
            remove.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    nodeGroups.remove(finalNodeGroup);
                    fire(new GraphChangedEvent(false, false));
                }
            });
            popupMenu.addItem(remove);
            popupMenu.showMenu(getStage(), x + getX(), y + getY());
        } else {
            PopupMenu popupMenu = popupMenuProducer.createPopupMenu(x, y);
            popupMenu.showMenu(getStage(), x + getX(), y + getY());
        }
    }
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) InputDialogListener(com.kotcrab.vis.ui.util.dialog.InputDialogListener) InputValidator(com.kotcrab.vis.ui.util.InputValidator) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) PopupMenu(com.kotcrab.vis.ui.widget.PopupMenu)

Example 7 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem in project talos by rockbite.

the class ModuleWrapperGroup method init.

public void init(Skin skin) {
    this.skin = skin;
    frameImage = new Image(skin.getDrawable("group_frame"));
    frameImage.setColor(44 / 255f, 140 / 255f, 209 / 255f, 1f);
    addActor(frameImage);
    topHit = new Actor();
    topHit.setTouchable(Touchable.enabled);
    addActor(topHit);
    title = new EditableLabel("GROUP NAME", skin);
    addActor(title);
    settings = new ImageButton(skin, "settings");
    settings.setSize(25, 25);
    addActor(settings);
    settings.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            final Vector2 vec = new Vector2(Gdx.input.getX(), Gdx.input.getY());
            (TalosMain.Instance().UIStage().getStage().getViewport()).unproject(vec);
            settingsPopup.showMenu(TalosMain.Instance().UIStage().getStage(), vec.x, vec.y);
        }
    });
    settingsPopup = new PopupMenu();
    MenuItem changeColorMenuItem = new MenuItem("Change Color");
    MenuItem ungroupMenuItem = new MenuItem("Ungroup");
    settingsPopup.addItem(changeColorMenuItem);
    settingsPopup.addItem(ungroupMenuItem);
    changeColorMenuItem.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            TalosMain.Instance().UIStage().showColorPicker(new ColorPickerAdapter() {

                @Override
                public void changed(Color newColor) {
                    super.changed(newColor);
                    frameImage.setColor(newColor);
                }
            });
        }
    });
    ungroupMenuItem.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            TalosMain.Instance().NodeStage().moduleBoardWidget.removeGroup(ModuleWrapperGroup.this);
        }
    });
    topHit.addListener(new ClickListener() {

        Vector2 tmp = new Vector2();

        Vector2 pos = new Vector2();

        Vector2 diff = new Vector2();

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            pos.set(x, y);
            topHit.localToStageCoordinates(pos);
            TalosMain.Instance().NodeStage().moduleBoardWidget.setSelectedWrappers(wrappers);
            return true;
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            tmp.set(x, y);
            topHit.localToStageCoordinates(tmp);
            diff.set(tmp).sub(pos);
            moveGroupBy(diff.x, diff.y);
            pos.set(tmp);
            super.touchDragged(event, x, y, pointer);
        }
    });
    setTouchable(Touchable.childrenOnly);
    frameImage.setTouchable(Touchable.disabled);
}
Also used : Color(com.badlogic.gdx.graphics.Color) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) EditableLabel(com.talosvfx.talos.editor.widgets.ui.EditableLabel) Vector2(com.badlogic.gdx.math.Vector2) Actor(com.badlogic.gdx.scenes.scene2d.Actor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ColorPickerAdapter(com.kotcrab.vis.ui.widget.color.ColorPickerAdapter) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) PopupMenu(com.kotcrab.vis.ui.widget.PopupMenu)

Example 8 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem in project talos by rockbite.

the class HierarchyWidget method showContextMenu.

private void showContextMenu(GameObject gameObject) {
    contextualMenu.clearItems();
    contextualMenu.addItem("Convert to Prefab", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            FilteredTree.Node item = (FilteredTree.Node) tree.getSelection().first();
            GameObject gameObject = objectMap.get(item.getName());
            SceneEditorAddon.get().workspace.convertToPrefab(gameObject);
        }
    });
    contextualMenu.addSeparator();
    contextualMenu.addItem("Cut", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
        }
    });
    contextualMenu.addItem("Copy", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
        }
    });
    contextualMenu.addItem("Paste", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
        }
    });
    contextualMenu.addSeparator();
    contextualMenu.addItem("Rename", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
        }
    });
    contextualMenu.addItem("Duplicate", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
        }
    });
    contextualMenu.addItem("Delete", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            Array<GameObject> gameObjects = new Array<>();
            for (Object nodeObject : tree.getSelection()) {
                FilteredTree.Node node = (FilteredTree.Node) nodeObject;
                if (objectMap.containsKey(node.getName())) {
                    GameObject gameObject = objectMap.get(node.getName());
                    gameObjects.add(gameObject);
                }
            }
            SceneEditorAddon.get().workspace.deleteGameObjects(gameObjects);
        }
    });
    contextualMenu.addSeparator();
    PopupMenu popupMenu = new PopupMenu();
    ObjectMap<String, XmlReader.Element> confMap = SceneEditorAddon.get().workspace.templateListPopup.getConfMap();
    for (String key : confMap.keys()) {
        XmlReader.Element element = confMap.get(key);
        MenuItem item = new MenuItem(element.getAttribute("title"));
        final String name = element.getAttribute("name");
        item.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                SceneEditorAddon.get().workspace.createObjectByTypeName(name, new Vector2(), gameObject);
            }
        });
        popupMenu.addItem(item);
    }
    MenuItem createMenu = contextualMenu.addItem("Create", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
        }
    });
    createMenu.setSubMenu(popupMenu);
    contextualMenu.show(getStage());
}
Also used : MenuItem(com.kotcrab.vis.ui.widget.MenuItem) FilteredTree(com.talosvfx.talos.editor.widgets.ui.FilteredTree) XmlReader(com.badlogic.gdx.utils.XmlReader) Array(com.badlogic.gdx.utils.Array) Vector2(com.badlogic.gdx.math.Vector2) GameObject(com.talosvfx.talos.editor.addons.scene.logic.GameObject) GameObject(com.talosvfx.talos.editor.addons.scene.logic.GameObject) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) PopupMenu(com.kotcrab.vis.ui.widget.PopupMenu)

Example 9 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem in project talos by rockbite.

the class ProjectExplorerWidget method showContextMenu.

public void showContextMenu(Array<FileHandle> files) {
    contextualMenu.clearItems();
    contextualMenu.addItem("Cut", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            invokeCut(files);
        }
    });
    contextualMenu.addItem("Copy", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            invokeCopy(files);
        }
    });
    contextualMenu.addItem("Paste", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            FileHandle destination = files.first();
            invokePaste(destination);
        }
    });
    contextualMenu.addSeparator();
    contextualMenu.addItem("Rename", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            String path = files.first().path();
            if (path != null) {
                FileHandle handle = Gdx.files.absolute(path);
                if (handle.isDirectory()) {
                    if (nodes.get(path) != null) {
                        RowWidget widget = (RowWidget) nodes.get(path).getActor();
                        widget.label.setEditMode();
                    }
                } else {
                    // check if its in the other guy
                    directoryViewWidget.startRenameFor(handle);
                }
            }
        }
    });
    contextualMenu.addItem("Delete", new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            String path = files.first().path();
            Array<String> paths = new Array<>();
            for (FileHandle file : files) {
                paths.add(file.path());
            }
            deletePath(paths);
        }
    });
    if (files.size == 1 && files.first().isDirectory()) {
        contextualMenu.addSeparator();
        PopupMenu popupMenu = new PopupMenu();
        createSubMenuItem(popupMenu, "New Directory", new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                String path = files.first().path();
                if (path != null) {
                    FileHandle handle = Gdx.files.absolute(path);
                    if (handle.isDirectory()) {
                        FileHandle newHandle = findAvailableHandleIn(handle, "New Directory");
                        newHandle.mkdirs();
                        loadDirectoryTree((String) rootNode.getObject());
                        FilteredTree.Node newNode = nodes.get(newHandle.path());
                        expand(newHandle.path());
                        select(newNode.getParent());
                        RowWidget widget = (RowWidget) newNode.getActor();
                        directoryViewWidget.reload();
                        directoryViewWidget.startRenameFor(newHandle);
                    }
                }
            }
        });
        createSubMenuItem(popupMenu, "New Scene", new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                String path = files.first().path();
                FileHandle sceneDestination = AssetImporter.suggestNewName(path, "New Scene", "scn");
                Scene mainScene = new Scene(sceneDestination.path());
                mainScene.save();
                directoryViewWidget.reload();
            }
        });
        createSubMenuItem(popupMenu, "Particle Effect", new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                String path = files.first().path();
                FileHandle tlsDestination = AssetImporter.suggestNewName(path, "New Effect", "tls");
                FileHandle metadataHandle = AssetImporter.makeSimilar(tlsDestination, "meta");
                FileHandle originalTls = Gdx.files.internal("addons/scene/missing/sample.tls");
                originalTls.copyTo(tlsDestination);
                TlsMetadata metadata = new TlsMetadata();
                metadata.tlsChecksum = AssetImporter.checkSum(tlsDestination);
                AssetImporter.saveMetadata(metadataHandle, metadata);
                directoryViewWidget.reload();
            }
        });
        MenuItem createMenu = contextualMenu.addItem("Create", new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
            }
        });
        createMenu.setSubMenu(popupMenu);
    }
    contextualMenu.show(getStage());
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) TlsMetadata(com.talosvfx.talos.editor.addons.scene.utils.metadata.TlsMetadata) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) Scene(com.talosvfx.talos.editor.addons.scene.logic.Scene) Array(com.badlogic.gdx.utils.Array) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) PopupMenu(com.kotcrab.vis.ui.widget.PopupMenu)

Example 10 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem in project talos by rockbite.

the class ProjectExplorerWidget method createSubMenuItem.

private void createSubMenuItem(PopupMenu popupMenu, String name, ClickListener listener) {
    MenuItem item = new MenuItem(name);
    item.addListener(listener);
    popupMenu.addItem(item);
}
Also used : MenuItem(com.kotcrab.vis.ui.widget.MenuItem)

Aggregations

MenuItem (com.kotcrab.vis.ui.widget.MenuItem)29 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)12 PopupMenu (com.kotcrab.vis.ui.widget.PopupMenu)12 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)11 Actor (com.badlogic.gdx.scenes.scene2d.Actor)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Menu (com.kotcrab.vis.ui.widget.Menu)5 Vector2 (com.badlogic.gdx.math.Vector2)4 Array (com.badlogic.gdx.utils.Array)4 MenuItemListener (games.rednblack.editor.event.MenuItemListener)4 H2DPopupMenu (games.rednblack.h2d.common.view.ui.widget.H2DPopupMenu)4 Color (com.badlogic.gdx.graphics.Color)3 ColorPickerAdapter (com.kotcrab.vis.ui.widget.color.ColorPickerAdapter)3 Rectangle (com.badlogic.gdx.math.Rectangle)2 XmlReader (com.badlogic.gdx.utils.XmlReader)2 InputValidator (com.kotcrab.vis.ui.util.InputValidator)2 InputDialogListener (com.kotcrab.vis.ui.util.dialog.InputDialogListener)2 EditableLabel (com.talosvfx.talos.editor.widgets.ui.EditableLabel)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1