Search in sources :

Example 21 with BaseActor

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

the class ScnWidget method draw.

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();
    Color tmp = batch.getColor();
    batch.setColor(Color.WHITE);
    if (scn != null && !loading && !loadingError) {
        // BACKGROUND
        batch.disableBlending();
        tile.draw(batch, getX(), getY(), getWidth(), getHeight());
        batch.enableBlending();
        Vector3 v = new Vector3(getX(), getY(), 0);
        v = v.prj(batch.getTransformMatrix());
        batch.end();
        HdpiUtils.glViewport((int) v.x, (int) v.y, (int) getWidth(), (int) (getHeight()));
        getStage().calculateScissors(bounds, scissors);
        if (ScissorStack.pushScissors(scissors)) {
            // WORLD CAMERA
            sceneBatch.setProjectionMatrix(camera.combined);
            sceneBatch.begin();
            Array<AtlasRegion> scnBackground = scn.getBackground();
            if (scnBackground != null) {
                sceneBatch.disableBlending();
                float x = 0;
                for (AtlasRegion tile : scnBackground) {
                    sceneBatch.draw(tile, x, 0f);
                    x += tile.getRegionWidth();
                }
                sceneBatch.enableBlending();
            }
            // draw layers from bottom to top
            List<SceneLayer> layers = scn.getLayers();
            for (int i = layers.size() - 1; i >= 0; i--) {
                SceneLayer layer = layers.get(i);
                if (!layer.isVisible())
                    continue;
                List<InteractiveActor> actors = layer.getActors();
                for (InteractiveActor a : actors) {
                    if (a instanceof SpriteActor) {
                        boolean visibility = a.isVisible();
                        a.setVisible(true);
                        ((SpriteActor) a).draw(sceneBatch);
                        a.setVisible(visibility);
                    }
                }
            }
            sceneBatch.end();
            ScissorStack.popScissors();
        }
        drawer.drawBGBounds();
        if (showWalkZone && scn.getPolygonalNavGraph() != null) {
            drawer.drawBBoxWalkZone(scn, false);
            drawer.drawPolygonVertices(scn.getPolygonalNavGraph().getWalkZone(), Color.GREEN);
        }
        drawer.drawBBoxActors(scn);
        if (selectedActor != null) {
            drawer.drawSelectedActor(selectedActor);
        }
        getStage().getViewport().apply();
        // SCREEN CAMERA
        batch.begin();
        drawFakeDepthMarkers((SpriteBatch) batch);
        if (!inScene) {
            faRenderer.draw((SpriteBatch) batch);
        }
        // DRAW COORDS
        Vector2 coords = new Vector2(Gdx.input.getX(), Gdx.input.getY());
        screenToWorldCoords(coords);
        String str = MessageFormat.format("({0}, {1})", (int) coords.x, (int) coords.y);
        textLayout.setText(defaultFont, str);
        RectangleRenderer.draw((SpriteBatch) batch, 0f, getY() + getHeight() - textLayout.height - 15, textLayout.width + 10, textLayout.height + 10, BLACK_TRANSPARENT);
        defaultFont.draw(batch, textLayout, 5, getHeight() + getY() - 10);
        batch.setColor(tmp);
    } else {
        background.draw(batch, getX(), getY(), getWidth(), getHeight());
        String s;
        if (loading) {
            s = "LOADING...";
            Timer.post(new Task() {

                @Override
                public void run() {
                    loading = false;
                    try {
                        EngineAssetManager.getInstance().finishLoading();
                        scn.retrieveAssets();
                        // disable Spine events
                        for (BaseActor a : scn.getActors().values()) {
                            if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof SpineRenderer) {
                                ((SpineRenderer) ((SpriteActor) a).getRenderer()).enableEvents(false);
                            }
                        }
                        drawer.setCamera(camera);
                        invalidate();
                    } catch (Exception e) {
                        Message.showMsg(getStage(), "Could not load assets for scene", 4);
                        EditorLogger.printStackTrace(e);
                        loadingError = true;
                        loading = false;
                    }
                }
            });
        } else if (loadingError) {
            s = "ERROR IN SCENE DATA. CANNOT DISPLAY SCENE";
        } else if (Ctx.project.getProjectDir() == null) {
            s = "CREATE OR LOAD A PROJECT";
        } else {
            s = "THERE ARE NO SCENES IN THIS CHAPTER YET";
        }
        textLayout.setText(bigFont, s);
        bigFont.draw(batch, textLayout, (getWidth() - textLayout.width) / 2, getHeight() / 2 + bigFont.getLineHeight() * 3);
    }
}
Also used : Task(com.badlogic.gdx.utils.Timer.Task) SceneLayer(com.bladecoder.engine.model.SceneLayer) Color(com.badlogic.gdx.graphics.Color) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Vector3(com.badlogic.gdx.math.Vector3) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) Vector2(com.badlogic.gdx.math.Vector2) SpriteActor(com.bladecoder.engine.model.SpriteActor) BaseActor(com.bladecoder.engine.model.BaseActor) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)

Example 22 with BaseActor

use of com.bladecoder.engine.model.BaseActor 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 23 with BaseActor

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

the class ScnWidgetInputListener method keyDown.

@Override
public boolean keyDown(InputEvent event, int keycode) {
    super.keyDown(event, keycode);
    Polygon p = null;
    if (scnWidget.getStage() == null || scnWidget.getStage().getKeyboardFocus() != scnWidget)
        return false;
    switch(keycode) {
        case Keys.ENTER:
            break;
        case Keys.BACKSPACE:
            break;
        case Keys.Z:
            if (UIUtils.ctrl()) {
                Ctx.project.getUndoStack().undo();
            }
            break;
        case Keys.FORWARD_DEL:
            BaseActor a = Ctx.project.getSelectedActor();
            if (a == null)
                return false;
            Ctx.project.getUndoStack().add(new UndoDeleteActor(Ctx.project.getSelectedScene(), a));
            Ctx.project.getSelectedScene().removeActor(a);
            Ctx.project.setModified(this, Project.NOTIFY_ELEMENT_DELETED, null, a);
            break;
        case Keys.S:
            if (UIUtils.ctrl()) {
                try {
                    Ctx.project.saveProject();
                } catch (IOException e1) {
                    String msg = "Something went wrong while saving the actor.\n\n" + e1.getClass().getSimpleName() + " - " + e1.getMessage();
                    Message.showMsgDialog(scnWidget.getStage(), "Error", msg);
                    EditorLogger.printStackTrace(e1);
                }
            }
            break;
        case Keys.UP:
        case Keys.DOWN:
        case Keys.LEFT:
        case Keys.RIGHT:
            selActor = scnWidget.getSelectedActor();
            p = selActor.getBBox();
            undoOrg.set(p.getX(), p.getY());
            Ctx.project.setModified(this, Project.POSITION_PROPERTY, null, selActor);
            break;
        case Keys.PLUS:
        case 70:
            scnWidget.zoom(-1);
            break;
        case Keys.MINUS:
            scnWidget.zoom(1);
            break;
    }
    return false;
}
Also used : BaseActor(com.bladecoder.engine.model.BaseActor) IOException(java.io.IOException) Polygon(com.badlogic.gdx.math.Polygon) UndoDeleteActor(com.bladecoder.engineeditor.undo.UndoDeleteActor)

Example 24 with BaseActor

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

the class ActorList method delete.

@Override
protected void delete() {
    BaseActor a = removeSelected();
    parent.removeActor(a);
    // delete player attr if the actor to delete is the player
    if (parent.getPlayer() == a) {
        parent.setPlayer(null);
    }
    // TRANSLATIONS
    Ctx.project.getI18N().putTranslationsInElement(a);
    // UNDO
    Ctx.project.getUndoStack().add(new UndoDeleteActor(parent, a));
    Ctx.project.setModified();
}
Also used : BaseActor(com.bladecoder.engine.model.BaseActor) UndoDeleteActor(com.bladecoder.engineeditor.undo.UndoDeleteActor)

Example 25 with BaseActor

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

the class ModelWalker method walk.

public void walk(World w) {
    Map<String, Scene> scenes = World.getInstance().getScenes();
    for (StartVisitor sv : startVisitors) sv.start(w);
    for (Scene scn : scenes.values()) {
        for (SceneVisitor sv : sceneVisitors) sv.visit(scn);
        Map<String, BaseActor> actors = scn.getActors();
        // SCENE VERBS
        HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
        for (Verb v : verbs.values()) {
            for (VerbVisitor vv : verbVisitors) vv.visit(scn, null, v);
            ArrayList<Action> actions = v.getActions();
            for (Action act : actions) {
                for (ActionVisitor av : actionVisitors) av.visit(scn, null, v, act);
            }
        }
        for (BaseActor a : actors.values()) {
            for (ActorVisitor av : actorVisitors) av.visit(a);
            if (a instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) a;
                // ACTOR VERBS
                verbs = ia.getVerbManager().getVerbs();
                for (Verb v : verbs.values()) {
                    for (VerbVisitor vv : verbVisitors) vv.visit(scn, ia, v);
                    ArrayList<Action> actions = v.getActions();
                    for (Action act : actions) {
                        for (ActionVisitor av : actionVisitors) av.visit(scn, ia, v, act);
                    }
                }
            }
            // DIALOGS
            if (a instanceof CharacterActor) {
                HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
                if (dialogs != null) {
                    for (Dialog d : dialogs.values()) {
                        for (DialogVisitor dv : dialogVisitors) dv.visit((CharacterActor) a, d);
                        ArrayList<DialogOption> options = d.getOptions();
                        for (DialogOption o : options) {
                            for (DialogOptionVisitor ov : optionVisitors) ov.visit((CharacterActor) a, d, o);
                        }
                    }
                }
            }
        }
    }
    for (EndVisitor ev : endVisitors) ev.end(w);
}
Also used : Action(com.bladecoder.engine.actions.Action) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor) Dialog(com.bladecoder.engine.model.Dialog) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor) DialogOption(com.bladecoder.engine.model.DialogOption)

Aggregations

BaseActor (com.bladecoder.engine.model.BaseActor)40 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)26 Scene (com.bladecoder.engine.model.Scene)16 SpriteActor (com.bladecoder.engine.model.SpriteActor)13 CharacterActor (com.bladecoder.engine.model.CharacterActor)12 Vector2 (com.badlogic.gdx.math.Vector2)8 Verb (com.bladecoder.engine.model.Verb)8 Polygon (com.badlogic.gdx.math.Polygon)7 World (com.bladecoder.engine.model.World)7 Rectangle (com.badlogic.gdx.math.Rectangle)5 Action (com.bladecoder.engine.actions.Action)5 AnchorActor (com.bladecoder.engine.model.AnchorActor)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 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)4 SceneLayer (com.bladecoder.engine.model.SceneLayer)4 Color (com.badlogic.gdx.graphics.Color)3