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);
}
}
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;
}
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());
}
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));
}
}
}
}
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);
}
}
Aggregations