Search in sources :

Example 16 with Scene

use of com.bladecoder.engine.model.Scene in project bladecoder-adventure-engine by bladecoder.

the class SceneList method paste.

@Override
protected void paste() {
    Scene newElement = (Scene) ElementUtils.cloneElement(clipboard);
    newElement.setId(ElementUtils.getCheckedId(newElement.getId(), World.getInstance().getScenes().keySet().toArray(new String[0])));
    int pos = list.getSelectedIndex() + 1;
    list.getItems().insert(pos, newElement);
    World.getInstance().addScene(newElement);
    Ctx.project.getI18N().extractStrings(newElement);
    if (parent.getInitScene() == null) {
        parent.setInitScene(newElement.getId());
    }
    list.setSelectedIndex(pos);
    list.invalidateHierarchy();
    Ctx.project.setModified();
}
Also used : Scene(com.bladecoder.engine.model.Scene) UndoDeleteScene(com.bladecoder.engineeditor.undo.UndoDeleteScene)

Example 17 with Scene

use of com.bladecoder.engine.model.Scene in project bladecoder-adventure-engine by bladecoder.

the class SceneList method delete.

@Override
protected void delete() {
    Scene s = removeSelected();
    parent.getScenes().remove(s.getId());
    // init_scene
    if (parent.getInitScene() != null && parent.getInitScene().equals(s.getId())) {
        if (parent.getScenes().size() > 0)
            parent.setInitScene(parent.getScenes().values().iterator().next().getId());
        else
            parent.setInitScene(null);
    }
    // TRANSLATIONS
    Ctx.project.getI18N().putTranslationsInElement(s);
    // UNDO
    UndoOp undoOp = new UndoDeleteScene(s);
    Ctx.project.getUndoStack().add(undoOp);
    Ctx.project.setModified();
}
Also used : UndoDeleteScene(com.bladecoder.engineeditor.undo.UndoDeleteScene) Scene(com.bladecoder.engine.model.Scene) UndoDeleteScene(com.bladecoder.engineeditor.undo.UndoDeleteScene) UndoOp(com.bladecoder.engineeditor.undo.UndoOp)

Example 18 with Scene

use of com.bladecoder.engine.model.Scene in project bladecoder-adventure-engine by bladecoder.

the class ScnWidgetInputListener method touchDown.

@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
    super.touchDown(event, x, y, pointer, button);
    // EditorLogger.debug("Touch Down - X: " + x + " Y: " + y);
    Scene scn = scnWidget.getScene();
    if (scn == null)
        return false;
    Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY());
    scnWidget.screenToWorldCoords(p);
    org.set(p);
    if (button == Buttons.LEFT) {
        selActor = scnWidget.getSelectedActor();
        if (scn.getPolygonalNavGraph() != null && scnWidget.getShowWalkZone()) {
            // Check
            // WALKZONE
            // CHECK WALKZONE VERTEXS
            Polygon wzPoly = scn.getPolygonalNavGraph().getWalkZone();
            float[] verts = wzPoly.getTransformedVertices();
            for (int i = 0; i < verts.length; i += 2) {
                if (p.dst(verts[i], verts[i + 1]) < CanvasDrawer.CORNER_DIST) {
                    draggingMode = DraggingModes.DRAGGING_WALKZONE_POINT;
                    vertIndex = i;
                    float[] v = wzPoly.getVertices();
                    undoOrg.set(v[i], v[i + 1]);
                    return true;
                }
            }
            // CHECK FOR WALKZONE DRAGGING
            if (wzPoly.contains(p.x, p.y)) {
                draggingMode = DraggingModes.DRAGGING_WALKZONE;
                undoOrg.set(wzPoly.getX(), wzPoly.getY());
                return true;
            }
        }
        // SELACTOR ORIGIN DRAGGING
        if (selActor != null && selActor instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) selActor).getRefPoint();
            float orgX = selActor.getX() + refPoint.x;
            float orgY = selActor.getY() + refPoint.y;
            float dst = Vector2.dst(p.x, p.y, orgX, orgY);
            if (dst < Scene.ANCHOR_RADIUS) {
                draggingMode = DraggingModes.DRAGGING_REFPOINT;
                undoOrg.set(refPoint.x, refPoint.y);
                return true;
            }
        }
        // SELACTOR VERTEXs DRAGGING
        if (selActor != null && (!(selActor instanceof SpriteActor) || !((SpriteActor) selActor).isBboxFromRenderer()) && !(scnWidget.getSelectedActor() instanceof AnchorActor)) {
            Polygon bbox = selActor.getBBox();
            float[] verts = bbox.getTransformedVertices();
            for (int i = 0; i < verts.length; i += 2) {
                if (p.dst(verts[i], verts[i + 1]) < CanvasDrawer.CORNER_DIST) {
                    draggingMode = DraggingModes.DRAGGING_BBOX_POINT;
                    vertIndex = i;
                    float[] v = bbox.getVertices();
                    undoOrg.set(v[i], v[i + 1]);
                    return true;
                }
            }
        }
        // CHECK FOR ACTORS
        BaseActor a = scn.getActorAt(p.x, p.y);
        if (a != null && a != selActor) {
            selActor = a;
            BaseActor da = Ctx.project.getActor(selActor.getId());
            Ctx.project.setSelectedActor(da);
            return true;
        }
        if (a != null) {
            draggingMode = DraggingModes.DRAGGING_ACTOR;
            undoOrg.set(selActor.getX(), selActor.getY());
            return true;
        }
        // CHECK FOR DRAGGING DEPTH MARKERS
        Vector2 depthVector = scnWidget.getScene().getDepthVector();
        if (depthVector != null) {
            p.set(0, depthVector.x);
            scnWidget.worldToScreenCoords(p);
            if (Vector2.dst(p.x - 40, p.y, x, y) < 50) {
                draggingMode = DraggingModes.DRAGGING_MARKER_0;
                Vector2 dv = scnWidget.getScene().getDepthVector();
                undoOrg.set(dv.x, dv.y);
                return true;
            }
            p.set(0, depthVector.y);
            scnWidget.worldToScreenCoords(p);
            if (Vector2.dst(p.x - 40, p.y, x, y) < 50) {
                draggingMode = DraggingModes.DRAGGING_MARKER_100;
                Vector2 dv = scnWidget.getScene().getDepthVector();
                undoOrg.set(dv.x, dv.y);
                return true;
            }
        }
    }
    return true;
}
Also used : AnchorActor(com.bladecoder.engine.model.AnchorActor) Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene) Polygon(com.badlogic.gdx.math.Polygon)

Example 19 with Scene

use of com.bladecoder.engine.model.Scene in project bladecoder-adventure-engine by bladecoder.

the class ScnWidgetInputListener method clicked.

@Override
public void clicked(InputEvent event, float x, float y) {
    Scene scn = scnWidget.getScene();
    if (scn == null)
        return;
    Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY());
    scnWidget.screenToWorldCoords(p);
    // DOUBLE CLICK TO CREATE OR DELETE POINTS
    if (getTapCount() == 2) {
        // Check WALKZONE
        if (scn.getPolygonalNavGraph() != null && scnWidget.getShowWalkZone()) {
            Polygon poly = scn.getPolygonalNavGraph().getWalkZone();
            if (UIUtils.ctrl()) {
                // Delete the point if selected
                boolean deleted = PolygonUtils.deletePoint(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
                if (deleted) {
                    Ctx.project.setModified();
                    return;
                }
            } else {
                boolean created = PolygonUtils.addClampPointIfTolerance(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
                if (created) {
                    Ctx.project.setModified();
                    return;
                }
            }
        }
        if (scnWidget.getSelectedActor() != null) {
            Polygon poly = scnWidget.getSelectedActor().getBBox();
            if ((!(scnWidget.getSelectedActor() instanceof SpriteActor) || !((SpriteActor) scnWidget.getSelectedActor()).isBboxFromRenderer()) && !(scnWidget.getSelectedActor() instanceof AnchorActor)) {
                if (UIUtils.ctrl()) {
                    // Delete the point if selected
                    boolean deleted = PolygonUtils.deletePoint(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
                    if (deleted) {
                        Ctx.project.setModified();
                        return;
                    }
                } else {
                    boolean created = PolygonUtils.addClampPointIfTolerance(poly, p.x, p.y, CanvasDrawer.CORNER_DIST);
                    if (created) {
                        Ctx.project.setModified();
                        return;
                    }
                }
            }
        }
    }
}
Also used : AnchorActor(com.bladecoder.engine.model.AnchorActor) Vector2(com.badlogic.gdx.math.Vector2) SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene) Polygon(com.badlogic.gdx.math.Polygon)

Example 20 with Scene

use of com.bladecoder.engine.model.Scene in project bladecoder-adventure-engine by bladecoder.

the class ScnWidgetInputListener method touchDragged.

@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
    // EditorLogger.debug("Touch Dragged - X: " + Gdx.input.getX() + " Y: "
    // + Gdx.input.getY());
    super.touchDragged(event, x, y, pointer);
    if (Gdx.input.isButtonPressed(Buttons.LEFT)) {
        Scene scn = scnWidget.getScene();
        if (scn == null)
            return;
        Vector2 d = new Vector2(Gdx.input.getX(), Gdx.input.getY());
        scnWidget.screenToWorldCoords(d);
        d.sub(org);
        org.add(d);
        if (draggingMode == DraggingModes.DRAGGING_ACTOR) {
            selActor.setPosition(selActor.getX() + d.x, selActor.getY() + d.y);
            Ctx.project.setModified(this, Project.POSITION_PROPERTY, null, selActor);
        } else if (draggingMode == DraggingModes.DRAGGING_REFPOINT) {
            Vector2 refPoint = ((InteractiveActor) selActor).getRefPoint();
            refPoint.add(d.x, d.y);
            Ctx.project.setModified();
        } else if (draggingMode == DraggingModes.DRAGGING_BBOX_POINT) {
            Polygon poly = selActor.getBBox();
            float[] verts = poly.getVertices();
            verts[vertIndex] += d.x;
            verts[vertIndex + 1] += d.y;
            poly.dirty();
            Ctx.project.setModified();
        } else if (draggingMode == DraggingModes.DRAGGING_WALKZONE_POINT) {
            Polygon poly = scn.getPolygonalNavGraph().getWalkZone();
            float[] verts = poly.getVertices();
            verts[vertIndex] += d.x;
            verts[vertIndex + 1] += d.y;
            poly.dirty();
            Ctx.project.setModified();
        } else if (draggingMode == DraggingModes.DRAGGING_WALKZONE) {
            Polygon poly = scn.getPolygonalNavGraph().getWalkZone();
            poly.translate(d.x, d.y);
            Ctx.project.setModified();
        } else if (draggingMode == DraggingModes.DRAGGING_MARKER_0) {
            Vector2 depthVector = scnWidget.getScene().getDepthVector();
            depthVector.x += d.y;
            Ctx.project.setModified();
            updateFakeDepth();
        } else if (draggingMode == DraggingModes.DRAGGING_MARKER_100) {
            Vector2 depthVector = scnWidget.getScene().getDepthVector();
            depthVector.y += d.y;
            Ctx.project.setModified();
            updateFakeDepth();
        }
    } else if (Gdx.input.isButtonPressed(Buttons.RIGHT) || Gdx.input.isButtonPressed(Buttons.MIDDLE)) {
        Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY());
        scnWidget.screenToWorldCoords(p);
        p.sub(org);
        scnWidget.translate(p);
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) Scene(com.bladecoder.engine.model.Scene) Polygon(com.badlogic.gdx.math.Polygon)

Aggregations

Scene (com.bladecoder.engine.model.Scene)35 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)18 BaseActor (com.bladecoder.engine.model.BaseActor)16 Verb (com.bladecoder.engine.model.Verb)9 Vector2 (com.badlogic.gdx.math.Vector2)8 CharacterActor (com.bladecoder.engine.model.CharacterActor)8 SpriteActor (com.bladecoder.engine.model.SpriteActor)8 Action (com.bladecoder.engine.actions.Action)6 World (com.bladecoder.engine.model.World)5 LookAtAction (com.bladecoder.engine.actions.LookAtAction)4 SayAction (com.bladecoder.engine.actions.SayAction)4 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)4 Dialog (com.bladecoder.engine.model.Dialog)4 DialogOption (com.bladecoder.engine.model.DialogOption)4 Polygon (com.badlogic.gdx.math.Polygon)3 AnchorActor (com.bladecoder.engine.model.AnchorActor)3 UndoDeleteScene (com.bladecoder.engineeditor.undo.UndoDeleteScene)3 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)2 SceneLayer (com.bladecoder.engine.model.SceneLayer)2 VerbRunner (com.bladecoder.engine.model.VerbRunner)2