Search in sources :

Example 16 with InteractiveActor

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

the class ActorInputPanel method getValues.

private static String[] getValues(boolean mandatory, Param.Type type) {
    Map<String, BaseActor> actors = Ctx.project.getSelectedScene().getActors();
    ArrayList<BaseActor> filteredActors = new ArrayList<BaseActor>();
    for (BaseActor a : actors.values()) {
        if (type == Param.Type.CHARACTER_ACTOR) {
            if (a instanceof CharacterActor)
                filteredActors.add(a);
        } else if (type == Param.Type.INTERACTIVE_ACTOR) {
            if (a instanceof InteractiveActor)
                filteredActors.add(a);
        } else if (type == Param.Type.SPRITE_ACTOR) {
            if (a instanceof SpriteActor)
                filteredActors.add(a);
        } else {
            filteredActors.add(a);
        }
    }
    String[] result = new String[filteredActors.size() + 1];
    // Add player variable to the list
    result[0] = Scene.VAR_PLAYER;
    for (int i = 0; i < filteredActors.size(); i++) {
        result[i + 1] = filteredActors.get(i).getId();
    }
    Arrays.sort(result);
    return result;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) ArrayList(java.util.ArrayList) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 17 with InteractiveActor

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

the class CheckDesc method visit.

@Override
public void visit(BaseActor a) {
    if (a instanceof InteractiveActor) {
        ia = (InteractiveActor) a;
        hasLeave = false;
        hasEnterExit = false;
        if (ia.getInteraction()) {
            HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
            for (Verb v : verbs.values()) checkVerb(v);
            if (hasLeave || hasEnterExit)
                return;
            if (ia.getDesc() == null || ia.getDesc().trim().isEmpty()) {
                EditorLogger.error("CheckDesc: " + a.getScene().getId() + "." + a.getId());
            }
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Verb(com.bladecoder.engine.model.Verb)

Example 18 with InteractiveActor

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

the class CanvasDrawer method drawBBoxActors.

public void drawBBoxActors(Scene scn) {
    drawer.setProjectionMatrix(camera.combined);
    drawer.setTransformMatrix(new Matrix4());
    drawer.begin(ShapeType.Line);
    for (BaseActor a : scn.getActors().values()) {
        Polygon p = a.getBBox();
        if (p == null) {
            EditorLogger.error("ERROR DRAWING BBOX FOR: " + a.getId());
        }
        if (a instanceof ObstacleActor) {
            drawer.setColor(Scene.OBSTACLE_COLOR);
            drawer.polygon(p.getTransformedVertices());
        } else if (a instanceof InteractiveActor) {
            InteractiveActor iActor = (InteractiveActor) a;
            if (!scn.getLayer(iActor.getLayer()).isVisible())
                continue;
            drawer.setColor(Scene.ACTOR_BBOX_COLOR);
            if (p.getTransformedVertices().length > 2)
                drawer.polygon(p.getTransformedVertices());
        } else if (a instanceof AnchorActor) {
            drawer.setColor(Scene.ANCHOR_COLOR);
            drawer.line(p.getX() - Scene.ANCHOR_RADIUS, p.getY(), p.getX() + Scene.ANCHOR_RADIUS, p.getY());
            drawer.line(p.getX(), p.getY() - Scene.ANCHOR_RADIUS, p.getX(), p.getY() + Scene.ANCHOR_RADIUS);
        }
    // drawer.rect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    }
    drawer.end();
}
Also used : AnchorActor(com.bladecoder.engine.model.AnchorActor) ObstacleActor(com.bladecoder.engine.model.ObstacleActor) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) Polygon(com.badlogic.gdx.math.Polygon) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 19 with InteractiveActor

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

the class CanvasDrawer method drawSelectedActor.

public void drawSelectedActor(BaseActor selectedActor) {
    // Gdx.gl20.glLineWidth(3);
    Gdx.gl20.glEnable(GL20.GL_BLEND);
    // Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    drawer.setProjectionMatrix(camera.combined);
    if (selectedActor instanceof AnchorActor) {
        drawer.begin(ShapeRenderer.ShapeType.Line);
        drawer.setColor(MOUSESELECTION_STROKE_COLOR);
        drawer.rect(selectedActor.getX() - Scene.ANCHOR_RADIUS, selectedActor.getY() - Scene.ANCHOR_RADIUS, Scene.ANCHOR_RADIUS * 2, Scene.ANCHOR_RADIUS * 2);
        drawer.end();
    } else {
        Polygon p = selectedActor.getBBox();
        Rectangle rect = p.getBoundingRectangle();
        drawer.begin(ShapeRenderer.ShapeType.Filled);
        drawer.setColor(MOUSESELECTION_FILL_COLOR);
        drawer.rect(rect.x, rect.y, rect.width, rect.height);
        drawer.end();
        drawer.begin(ShapeRenderer.ShapeType.Line);
        drawer.setColor(MOUSESELECTION_STROKE_COLOR);
        drawer.rect(rect.x, rect.y, rect.width, rect.height);
        // DRAW SELECTION BOUNDS
        if ((!(selectedActor instanceof SpriteActor) || !((SpriteActor) selectedActor).isBboxFromRenderer()) && !(selectedActor instanceof AnchorActor)) {
            float[] verts = selectedActor.getBBox().getTransformedVertices();
            for (int i = 0; i < verts.length; i += 2) drawer.rect(verts[i] - CORNER_DIST / 2, verts[i + 1] - CORNER_DIST / 2, CORNER_DIST, CORNER_DIST);
        }
        // DRAW REFPOINT
        if (selectedActor instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) selectedActor).getRefPoint();
            float orgX = selectedActor.getX() + refPoint.x;
            float orgY = selectedActor.getY() + refPoint.y;
            drawer.line(orgX - Scene.ANCHOR_RADIUS, orgY, orgX + Scene.ANCHOR_RADIUS, orgY);
            drawer.line(orgX, orgY - Scene.ANCHOR_RADIUS, orgX, orgY + Scene.ANCHOR_RADIUS);
        }
        drawer.end();
    }
}
Also used : AnchorActor(com.bladecoder.engine.model.AnchorActor) Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Rectangle(com.badlogic.gdx.math.Rectangle) SpriteActor(com.bladecoder.engine.model.SpriteActor) Polygon(com.badlogic.gdx.math.Polygon)

Example 20 with InteractiveActor

use of com.bladecoder.engine.model.InteractiveActor 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)

Aggregations

InteractiveActor (com.bladecoder.engine.model.InteractiveActor)43 BaseActor (com.bladecoder.engine.model.BaseActor)25 Scene (com.bladecoder.engine.model.Scene)17 SpriteActor (com.bladecoder.engine.model.SpriteActor)16 Verb (com.bladecoder.engine.model.Verb)14 CharacterActor (com.bladecoder.engine.model.CharacterActor)13 Vector2 (com.badlogic.gdx.math.Vector2)11 Rectangle (com.badlogic.gdx.math.Rectangle)7 Polygon (com.badlogic.gdx.math.Polygon)6 Action (com.bladecoder.engine.actions.Action)6 AnchorActor (com.bladecoder.engine.model.AnchorActor)6 Dialog (com.bladecoder.engine.model.Dialog)6 World (com.bladecoder.engine.model.World)6 TextRenderer (com.bladecoder.engine.model.TextRenderer)5 Color (com.badlogic.gdx.graphics.Color)4 LookAtAction (com.bladecoder.engine.actions.LookAtAction)4 SayAction (com.bladecoder.engine.actions.SayAction)4 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)4 DialogOption (com.bladecoder.engine.model.DialogOption)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)3