Search in sources :

Example 11 with TransformComponent

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

the class SceneEditorWorkspace method createObjectByTypeName.

public GameObject createObjectByTypeName(String idName, Vector2 position, GameObject parent) {
    GameObject gameObject = new GameObject();
    XmlReader.Element template = templateListPopup.getTemplate(idName);
    String name = getUniqueGOName(template.getAttribute("nameTemplate", "gameObject"), true);
    gameObject.setName(name);
    initComponentsFromTemplate(gameObject, templateListPopup.getTemplate(idName));
    if (position != null && gameObject.hasComponent(TransformComponent.class)) {
        // oh boi always special case with this fuckers
        TransformComponent transformComponent = gameObject.getComponent(TransformComponent.class);
        transformComponent.position.set(position.x, position.y);
    }
    if (parent == null) {
        currentContainer.addGameObject(gameObject);
    } else {
        parent.addGameObject(gameObject);
    }
    initGizmos(gameObject);
    Notifications.fireEvent(Notifications.obtainEvent(GameObjectCreated.class).setTarget(gameObject));
    Gdx.app.postRunnable(new Runnable() {

        @Override
        public void run() {
            selectGameObjectExternally(gameObject);
        }
    });
    return gameObject;
}
Also used : TransformComponent(com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent)

Example 12 with TransformComponent

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

the class SceneEditorWorkspace method createFromPrefab.

public GameObject createFromPrefab(Prefab prefab, Vector2 position, GameObject parent) {
    GameObject gameObject = prefab.root;
    String name = getUniqueGOName(prefab.name, true);
    gameObject.setName(name);
    if (position != null && gameObject.hasComponent(TransformComponent.class)) {
        TransformComponent transformComponent = gameObject.getComponent(TransformComponent.class);
        transformComponent.position.set(position.x, position.y);
        transformComponent.rotation = 0;
        transformComponent.scale.set(1, 1);
    }
    if (parent == null) {
        currentContainer.addGameObject(gameObject);
    } else {
        parent.addGameObject(gameObject);
    }
    initGizmos(gameObject);
    Notifications.fireEvent(Notifications.obtainEvent(GameObjectCreated.class).setTarget(gameObject));
    selectGameObjectExternally(gameObject);
    return gameObject;
}
Also used : TransformComponent(com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent)

Example 13 with TransformComponent

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

the class Gizmo method getTransformPosition.

public Vector2 getTransformPosition(Vector2 pos) {
    if (gameObject.hasComponent(TransformComponent.class)) {
        TransformComponent transformComponent = gameObject.getComponent(TransformComponent.class);
        pos.set(transformComponent.position);
        return pos;
    } else {
        pos.set(0, 0);
    }
    return pos;
}
Also used : TransformComponent(com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent)

Example 14 with TransformComponent

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

the class SmartTransformGizmo method transformOldToNew.

protected void transformOldToNew() {
    TransformComponent transform = gameObject.getComponent(TransformComponent.class);
    float xDiff = getPintsAngle(nextPoints[RT], nextPoints[LT]) - getPintsAngle(prevPoints[RT], prevPoints[LT]);
    float yDiff = getPintsAngle(nextPoints[LT], nextPoints[LB]) - getPintsAngle(prevPoints[LT], prevPoints[LB]);
    // bring old next points to local space
    for (int i = 0; i < 4; i++) {
        TransformComponent.worldToLocal(gameObject.parent, nextPoints[i]);
    }
    float xSign = transform.scale.x < 0 ? -1 : 1;
    float ySign = transform.scale.y < 0 ? -1 : 1;
    transform.scale.set(nextPoints[RB].dst(nextPoints[LB]) * xSign, nextPoints[LB].dst(nextPoints[LT]) * ySign);
    if (xDiff != 0) {
        transform.scale.x = transform.scale.x * -1f;
    }
    if (yDiff != 0) {
        transform.scale.y = transform.scale.y * -1f;
    }
    transform.scale = lowerPrecision(transform.scale);
    // this is midpoint
    tmp.set(nextPoints[RT]).sub(nextPoints[LB]).scl(0.5f).add(nextPoints[LB]);
    if (!Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
        // lol, this is a funny story actually
        transform.position.set(tmp);
    }
    transform.position = lowerPrecision(transform.position);
}
Also used : TransformComponent(com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent)

Example 15 with TransformComponent

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

the class SmartTransformGizmo method reportResizeUpdated.

protected void reportResizeUpdated(boolean isRapid) {
    TransformComponent transform = gameObject.getComponent(TransformComponent.class);
    Notifications.fireEvent(Notifications.obtainEvent(ComponentUpdated.class).set(transform, isRapid));
}
Also used : TransformComponent(com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent)

Aggregations

TransformComponent (com.talosvfx.talos.editor.addons.scene.logic.components.TransformComponent)19 CameraComponent (com.talosvfx.talos.editor.addons.scene.logic.components.CameraComponent)3 Vector2 (com.badlogic.gdx.math.Vector2)2 SpriteRendererComponent (com.talosvfx.talos.editor.addons.scene.logic.components.SpriteRendererComponent)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Texture (com.badlogic.gdx.graphics.Texture)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Vector3 (com.badlogic.gdx.math.Vector3)1 SceneEditorWorkspace (com.talosvfx.talos.editor.addons.scene.SceneEditorWorkspace)1 GameObject (com.talosvfx.talos.editor.addons.scene.logic.GameObject)1 SpriteMetadata (com.talosvfx.talos.editor.addons.scene.utils.metadata.SpriteMetadata)1 IOException (java.io.IOException)1