Search in sources :

Example 1 with InputDialogListener

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

the class UILayerBoxMediator method handleNotification.

@Override
public void handleNotification(INotification notification) {
    super.handleNotification(notification);
    Sandbox sandbox = Sandbox.getInstance();
    UILayerBox.UILayerItem layerItem;
    switch(notification.getName()) {
        case MsgAPI.SCENE_LOADED:
            initLayerData();
            int layerid = getFirstFreeLayer();
            viewComponent.setCurrentSelectedLayer(layerid);
            viewComponent.currentSelectedLayerIndex = layerid;
            break;
        case CompositeCameraChangeCommand.DONE:
            initLayerData();
            layerid = getFirstFreeLayer();
            viewComponent.setCurrentSelectedLayer(layerid);
            viewComponent.currentSelectedLayerIndex = layerid;
            break;
        case NewLayerCommand.DONE:
            initLayerData();
            setSelectedByName(notification.getBody());
            break;
        case DeleteLayerCommand.DONE:
            initLayerData();
            int deletedIndex = (int) notification.getBody() - 1;
            if (deletedIndex == -1)
                deletedIndex = 0;
            viewComponent.setCurrentSelectedLayer(deletedIndex);
            viewComponent.currentSelectedLayerIndex = deletedIndex;
            break;
        case DeleteLayerCommand.UNDONE:
            initLayerData();
            setSelectedByName(notification.getBody());
            break;
        case UILayerBox.LAYER_ROW_CLICKED:
            layerItem = notification.getBody();
            selectEntitiesByLayerName(layerItem);
            break;
        case UILayerBox.CREATE_NEW_LAYER:
            Dialogs.showInputDialog(Sandbox.getInstance().getUIStage(), "New Layer", "Please set unique name for your Layer", false, new InputDialogListener() {

                @Override
                public void finished(String input) {
                    if (checkIfNameIsUnique(input)) {
                        Object[] payload = NewLayerCommand.payload(viewComponent.getCurrentSelectedLayerIndex() + 1, input);
                        facade.sendNotification(MsgAPI.ACTION_NEW_LAYER, payload);
                    } else {
                    // show error dialog
                    }
                }

                @Override
                public void canceled() {
                }
            });
            break;
        case UILayerBox.LAYER_DROPPED:
            facade.sendNotification(MsgAPI.ACTION_SWAP_LAYERS, notification.getBody());
            break;
        case LayerSwapCommand.DONE:
            int index = viewComponent.getCurrentSelectedLayerIndex();
            initLayerData();
            viewComponent.setCurrentSelectedLayer(index);
            break;
        case UILayerBox.DELETE_LAYER:
            if (layers == null)
                return;
            int deletingLayerIndex = viewComponent.getCurrentSelectedLayerIndex();
            if (deletingLayerIndex != -1) {
                String layerName = layers.get(deletingLayerIndex).layerName;
                Dialogs.showConfirmDialog(sandbox.getUIStage(), "Delete Layer", "Do you really want to delete '" + layerName + "' layer?", new String[] { "Cancel", "Delete" }, new Integer[] { 0, 1 }, r -> {
                    if (r == 1) {
                        facade.sendNotification(MsgAPI.ACTION_DELETE_LAYER, layerName);
                    }
                }).padBottom(20).pack();
            }
            break;
        case UILayerBox.LOCK_LAYER:
            layerItem = notification.getBody();
            lockLayerByName(layerItem, true);
            break;
        case UILayerBox.UNLOCK_LAYER:
            layerItem = notification.getBody();
            lockLayerByName(layerItem, false);
            break;
        case UILayerBox.HIDE_LAYER:
            layerItem = notification.getBody();
            setEntityVisibilityByLayer(layerItem, false);
            break;
        case UILayerBox.UNHIDE_LAYER:
            layerItem = notification.getBody();
            setEntityVisibilityByLayer(layerItem, true);
            break;
        case MsgAPI.ITEM_SELECTION_CHANGED:
            Set<Integer> selection = notification.getBody();
            if (selection.size() == 1) {
                ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(selection.iterator().next(), ZIndexComponent.class);
                index = findLayerByName(zIndexComponent.layerName);
                if (index == -1) {
                // handle this somehow
                } else {
                    viewComponent.setCurrentSelectedLayer(index);
                    viewComponent.currentSelectedLayerIndex = index;
                }
            } else if (selection.size() > 1) {
            // multi selection handling not yet clear
            }
            break;
        case MsgAPI.NEW_ITEM_ADDED:
            index = viewComponent.getCurrentSelectedLayerIndex();
            int item = notification.getBody();
            ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(item, ZIndexComponent.class);
            if (zIndexComponent.layerName == null)
                zIndexComponent.layerName = layers.get(index).layerName;
            break;
        case UILayerBox.CHANGE_LAYER_NAME:
            String layerName = notification.getBody();
            int layerIndex = viewComponent.getCurrentSelectedLayerIndex();
            if (layerIndex == -1)
                break;
            LayerItemVO layerVO = layers.get(layerIndex);
            facade.sendNotification(MsgAPI.ACTION_RENAME_LAYER, RenameLayerCommand.payload(layerVO.layerName, layerName));
            break;
        case RenameLayerCommand.DONE:
            index = viewComponent.getCurrentSelectedLayerIndex();
            initLayerData();
            viewComponent.setCurrentSelectedLayer(index);
            break;
        default:
            break;
    }
}
Also used : InputDialogListener(com.kotcrab.vis.ui.util.dialog.InputDialogListener) ZIndexComponent(games.rednblack.editor.renderer.components.ZIndexComponent) Sandbox(games.rednblack.editor.view.stage.Sandbox) LayerItemVO(games.rednblack.editor.renderer.data.LayerItemVO)

Example 2 with InputDialogListener

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

the class DuplicateLibraryAction method doAction.

@Override
public void doAction() {
    String libraryActionName = notification.getBody();
    ProjectManager projectManager = HyperLap2DFacade.getInstance().retrieveProxy(ProjectManager.NAME);
    HashMap<String, GraphVO> libraryActions = projectManager.currentProjectInfoVO.libraryActions;
    GraphVO actionToDuplicate = libraryActions.get(libraryActionName);
    Dialogs.showInputDialog(Sandbox.getInstance().getUIStage(), "Duplicate " + libraryActionName, "New name : ", false, new StringNameValidator(), new InputDialogListener() {

        @Override
        public void finished(String input) {
            if (input == null || input.equals("")) {
                return;
            }
            Json json = HyperJson.getJson();
            GraphVO duplicated = json.fromJson(GraphVO.class, json.toJson(actionToDuplicate));
            Object[] payload = AddToLibraryAction.getPayload(input, duplicated);
            HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_ADD_TO_LIBRARY_ACTION, payload);
        }

        @Override
        public void canceled() {
            cancel();
        }
    });
}
Also used : StringNameValidator(games.rednblack.editor.view.ui.validator.StringNameValidator) InputDialogListener(com.kotcrab.vis.ui.util.dialog.InputDialogListener) GraphVO(games.rednblack.editor.renderer.data.GraphVO) HyperJson(games.rednblack.editor.renderer.utils.HyperJson) Json(com.badlogic.gdx.utils.Json) ProjectManager(games.rednblack.editor.proxy.ProjectManager)

Example 3 with InputDialogListener

use of com.kotcrab.vis.ui.util.dialog.InputDialogListener 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 4 with InputDialogListener

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

the class UIStageMediator method handleNotification.

@Override
public void handleNotification(INotification notification) {
    switch(notification.getName()) {
        case MsgAPI.SHOW_ADD_LIBRARY_DIALOG:
            Sandbox sandbox = Sandbox.getInstance();
            int item = notification.getBody();
            Dialogs.showInputDialog(sandbox.getUIStage(), "New Library Item ", "Unique Name", new InputDialogListener() {

                @Override
                public void finished(String input) {
                    Object[] payload = new Object[2];
                    payload[0] = item;
                    payload[1] = input;
                    facade.sendNotification(MsgAPI.ACTION_ADD_TO_LIBRARY, payload);
                }

                @Override
                public void canceled() {
                }
            });
            break;
        case MsgAPI.SAVE_EDITOR_CONFIG:
            Gdx.app.postRunnable(() -> getViewComponent().updateViewportDensity());
            break;
    }
}
Also used : InputDialogListener(com.kotcrab.vis.ui.util.dialog.InputDialogListener)

Example 5 with InputDialogListener

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

the class UISceneBoxMediator method handleNotification.

@Override
public void handleNotification(INotification notification) {
    super.handleNotification(notification);
    Sandbox sandbox = Sandbox.getInstance();
    switch(notification.getName()) {
        case ProjectManager.PROJECT_OPENED:
        case MsgAPI.SCENE_LOADED:
            viewComponent.update();
            break;
        case UISceneBox.CHANGE_SCENE_BTN_CLICKED:
            facade.sendNotification(MsgAPI.CHECK_EDITS_ACTION, (Runnable) () -> sandbox.loadScene(notification.getBody()));
            break;
        case UISceneBox.CREATE_NEW_SCENE_BTN_CLICKED:
            Dialogs.showInputDialog(sandbox.getUIStage(), "Create New Scene", "Scene Name : ", false, new StringNameValidator(), new InputDialogListener() {

                @Override
                public void finished(String input) {
                    if (input == null || input.equals("")) {
                        viewComponent.setCurrentScene();
                        return;
                    }
                    SceneDataManager sceneDataManager = facade.retrieveProxy(SceneDataManager.NAME);
                    sceneDataManager.createNewScene(input);
                    facade.sendNotification(MsgAPI.CHECK_EDITS_ACTION, (Runnable) () -> sandbox.loadScene(input));
                }

                @Override
                public void canceled() {
                    viewComponent.setCurrentScene();
                }
            });
            break;
        case UISceneBox.DELETE_CURRENT_SCENE_BTN_CLICKED:
            Dialogs.showConfirmDialog(sandbox.getUIStage(), "Delete Scene", "Do you really want to delete '" + notification.getBody() + "' scene?", new String[] { "Cancel", "Delete" }, new Integer[] { 0, 1 }, result -> {
                if (result == 1) {
                    SceneDataManager sceneDataManager = facade.retrieveProxy(SceneDataManager.NAME);
                    sceneDataManager.deleteCurrentScene();
                    sandbox.loadScene("MainScene");
                }
            }).padBottom(20).pack();
            break;
        default:
            break;
    }
}
Also used : StringNameValidator(games.rednblack.editor.view.ui.validator.StringNameValidator) InputDialogListener(com.kotcrab.vis.ui.util.dialog.InputDialogListener) SceneDataManager(games.rednblack.editor.proxy.SceneDataManager) Sandbox(games.rednblack.editor.view.stage.Sandbox)

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