Search in sources :

Example 26 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem in project HyperLap2D by rednblackgames.

the class FileMenu method addRecent.

public void addRecent(ArrayList<String> paths) {
    for (String path : paths) {
        MenuItem menuItem = new MenuItem(getFolderNameAndPath(path), new MenuItemListener(RECENT_PROJECTS, path, FILE_MENU));
        recentProjectsMenuItems.add(menuItem);
        recentProjectsPopupMenu.addItem(menuItem);
    }
}
Also used : MenuItem(com.kotcrab.vis.ui.widget.MenuItem) MenuItemListener(games.rednblack.editor.event.MenuItemListener)

Example 27 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem in project HyperLap2D by rednblackgames.

the class NodeEditorDialog method createGraphPopupMenu.

private H2DPopupMenu createGraphPopupMenu(final float popupX, final float popupY) {
    H2DPopupMenu popupMenu = new H2DPopupMenu();
    for (final GraphBoxProducer<ActionFieldType> producer : graphBoxProducers) {
        if (producer.isUnique())
            continue;
        String menuLocation = producer.getMenuLocation();
        if (menuLocation != null) {
            String[] menuSplit = menuLocation.split("/");
            PopupMenu targetMenu = findOrCreatePopupMenu(popupMenu, menuSplit, 0);
            final String title = producer.getName();
            MenuItem valueMenuItem = new MenuItem(title);
            valueMenuItem.addListener(new ClickListener(Input.Buttons.LEFT) {

                @Override
                public void clicked(InputEvent event, float x, float y) {
                    String id = UUID.randomUUID().toString().replace("-", "");
                    GraphBox<ActionFieldType> graphBox = producer.createDefault(skin, id);
                    graphContainer.addGraphBox(graphBox, title, true, popupX, popupY);
                }
            });
            targetMenu.addItem(valueMenuItem);
        }
    }
    return popupMenu;
}
Also used : ActionFieldType(games.rednblack.editor.graph.actions.ActionFieldType) H2DPopupMenu(games.rednblack.h2d.common.view.ui.widget.H2DPopupMenu) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) H2DPopupMenu(games.rednblack.h2d.common.view.ui.widget.H2DPopupMenu) PopupMenu(com.kotcrab.vis.ui.widget.PopupMenu)

Example 28 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem 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)

Example 29 with MenuItem

use of com.kotcrab.vis.ui.widget.MenuItem in project Eidolons by IDemiurge.

the class MenuPanel method initControlMenus.

public void initControlMenus(LE_ControlPanel[] panels) {
    Menu.MenuStyle style = (StyleHolder.getMenuStyle());
    TextButton.TextButtonStyle btnStyle = (StyleHolder.getMenuBtnStyle());
    for (LE_ControlPanel panel : panels) {
        Menu menu = new Menu(TabbedControlPanel.getTitleFromClass(panel.getClazz()), style);
        addMenu(menu);
        for (Method method : panel.getClazz().getMethods()) {
            MenuItem item = new MenuItem(StringMaster.format(method.getName()));
            item.addListener(createItemListener(item, method, panel.getHandler()));
            menu.addItem(item);
            item.setStyle(btnStyle);
        }
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) Menu(com.kotcrab.vis.ui.widget.Menu) Method(java.lang.reflect.Method)

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