Search in sources :

Example 1 with GameObject

use of com.talosvfx.talos.editor.addons.scene.logic.GameObject in project talos by rockbite.

the class HierarchyWidget method onGameObjectSelectionChanged.

@EventHandler
public void onGameObjectSelectionChanged(GameObjectSelectionChanged event) {
    if (currentContainer != null) {
        Array<GameObject> gameObjects = event.get();
        Array<FilteredTree.Node> nodes = new Array<>();
        for (GameObject gameObject : gameObjects) {
            nodes.add(nodeMap.get(gameObject));
        }
        tree.getSelection().clear();
        tree.getSelection().addAll(nodes);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) GameObject(com.talosvfx.talos.editor.addons.scene.logic.GameObject) EventHandler(com.talosvfx.talos.editor.notifications.EventHandler)

Example 2 with GameObject

use of com.talosvfx.talos.editor.addons.scene.logic.GameObject in project talos by rockbite.

the class HierarchyWidget method onGameObjectNameChanged.

@EventHandler
public void onGameObjectNameChanged(GameObjectNameChanged event) {
    GameObject gameObject = objectMap.get(event.oldName);
    objectMap.remove(event.oldName);
    objectMap.put(event.newName, gameObject);
    nodeMap.get(gameObject).name = event.newName;
}
Also used : GameObject(com.talosvfx.talos.editor.addons.scene.logic.GameObject) EventHandler(com.talosvfx.talos.editor.notifications.EventHandler)

Example 3 with GameObject

use of com.talosvfx.talos.editor.addons.scene.logic.GameObject 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 4 with GameObject

use of com.talosvfx.talos.editor.addons.scene.logic.GameObject in project talos by rockbite.

the class SmartTransformGizmo method moveInLayerOrder.

protected void moveInLayerOrder(GameObject gameObject, int direction) {
    // direction -1 for down, 1 for up
    if (gameObject.hasComponent(SpriteRendererComponent.class)) {
        SpriteRendererComponent component = gameObject.getComponent(SpriteRendererComponent.class);
        String sortingLayer = component.sortingLayer;
        Array<GameObject> list = SceneEditorAddon.get().workspace.getRootGO().getChildrenByComponent(SpriteRendererComponent.class, new Array<>());
        for (int i = list.size - 1; i >= 0; i--) {
            if (!list.get(i).getComponent(SpriteRendererComponent.class).sortingLayer.equals(sortingLayer)) {
                list.removeIndex(i);
            }
        }
        // find closest game object if any that is lower to my index, and swap with it
        if (list.size > 1) {
            GameObject closest = list.first();
            if (list.first() == gameObject) {
                closest = list.get(1);
            }
            int origDst = component.orderingInLayer - closest.getComponent(SpriteRendererComponent.class).orderingInLayer;
            for (GameObject candidate : list) {
                int dst = component.orderingInLayer - candidate.getComponent(SpriteRendererComponent.class).orderingInLayer;
                boolean matchesDirection = false;
                boolean matchesDirectionEquals = false;
                if (direction == -1 && dst >= 0)
                    matchesDirectionEquals = true;
                if (direction == 1 && dst <= 0)
                    matchesDirectionEquals = true;
                if (direction == -1 && origDst > dst)
                    matchesDirection = true;
                if (direction == 1 && origDst < dst)
                    matchesDirection = true;
                if (matchesDirectionEquals && candidate != gameObject) {
                    if (matchesDirection) {
                        origDst = dst;
                        closest = candidate;
                    }
                }
            }
            SpriteRendererComponent closestComponent = closest.getComponent(SpriteRendererComponent.class);
            if (closestComponent.orderingInLayer > component.orderingInLayer && direction == -1) {
                return;
            }
            if (closestComponent.orderingInLayer < component.orderingInLayer && direction == 1) {
                return;
            }
            if (closestComponent.orderingInLayer == component.orderingInLayer) {
                if (direction == -1) {
                    closestComponent.orderingInLayer++;
                    Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(closestComponent, false));
                } else if (direction == 1) {
                    component.orderingInLayer++;
                    Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(component, false));
                }
            } else {
                // swap
                int tmp = component.orderingInLayer;
                component.orderingInLayer = closestComponent.orderingInLayer;
                closestComponent.orderingInLayer = tmp;
                Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(component, false));
                Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(closestComponent, false));
            }
        }
    }
}
Also used : SpriteRendererComponent(com.talosvfx.talos.editor.addons.scene.logic.components.SpriteRendererComponent) GameObject(com.talosvfx.talos.editor.addons.scene.logic.GameObject) ComponentUpdated(com.talosvfx.talos.editor.addons.scene.events.ComponentUpdated)

Example 5 with GameObject

use of com.talosvfx.talos.editor.addons.scene.logic.GameObject in project talos by rockbite.

the class AssetImporter method createAssetInstance.

public static void createAssetInstance(FileHandle fileHandle, GameObject parent) {
    if (fileHandle.extension().equals("png")) {
        // check if non imported nine patch
        if (fileHandle.name().endsWith(".9.png")) {
            // import it
            attemptToImport(fileHandle);
        } else {
            importerMap.get(AssetType.SPRITE).makeInstance(fileHandle, parent);
        }
    }
    if (fileHandle.extension().equals("tls")) {
        importerMap.get(AssetType.TLS).makeInstance(fileHandle, parent);
    }
    if (fileHandle.extension().equals("p")) {
        importerMap.get(AssetType.TLS).makeInstance(fileHandle, parent);
    }
    if (fileHandle.extension().equals("skel")) {
        importerMap.get(AssetType.SPINE).makeInstance(fileHandle, parent);
    }
    if (fileHandle.extension().equals("prefab")) {
        SceneEditorWorkspace workspace = SceneEditorAddon.get().workspace;
        Vector2 sceneCords = workspace.getMouseCordsOnScene();
        Prefab prefab = Prefab.from(fileHandle);
        GameObject gameObject = workspace.createFromPrefab(prefab, sceneCords, parent);
    }
}
Also used : SceneEditorWorkspace(com.talosvfx.talos.editor.addons.scene.SceneEditorWorkspace) Vector2(com.badlogic.gdx.math.Vector2) GameObject(com.talosvfx.talos.editor.addons.scene.logic.GameObject) Prefab(com.talosvfx.talos.editor.addons.scene.logic.Prefab)

Aggregations

GameObject (com.talosvfx.talos.editor.addons.scene.logic.GameObject)14 Vector2 (com.badlogic.gdx.math.Vector2)5 SceneEditorWorkspace (com.talosvfx.talos.editor.addons.scene.SceneEditorWorkspace)5 Array (com.badlogic.gdx.utils.Array)3 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)2 Prefab (com.talosvfx.talos.editor.addons.scene.logic.Prefab)2 SpriteRendererComponent (com.talosvfx.talos.editor.addons.scene.logic.components.SpriteRendererComponent)2 EventHandler (com.talosvfx.talos.editor.notifications.EventHandler)2 FilteredTree (com.talosvfx.talos.editor.widgets.ui.FilteredTree)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Texture (com.badlogic.gdx.graphics.Texture)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 XmlReader (com.badlogic.gdx.utils.XmlReader)1 MenuItem (com.kotcrab.vis.ui.widget.MenuItem)1 PopupMenu (com.kotcrab.vis.ui.widget.PopupMenu)1 MainRenderer (com.talosvfx.talos.editor.addons.scene.MainRenderer)1 ComponentUpdated (com.talosvfx.talos.editor.addons.scene.events.ComponentUpdated)1 ParticleComponent (com.talosvfx.talos.editor.addons.scene.logic.components.ParticleComponent)1