Search in sources :

Example 6 with SceneLayer

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

the class EditActorDialog method inputsToModel.

@Override
protected void inputsToModel(boolean create) {
    String type = typePanel.getText();
    boolean typeChanged = false;
    BaseActor oldElement = e;
    String oldId = null;
    boolean isPlayer = false;
    if (!create) {
        typeChanged = (type.equals(CHARACTER_TYPE_STR) && !(e instanceof CharacterActor)) || (type.equals(SPRITE_TYPE_STR) && (!(e instanceof SpriteActor) || e instanceof CharacterActor)) || (type.equals(BACKGROUND_TYPE_STR) && (!(e instanceof InteractiveActor) || e instanceof SpriteActor)) || (type.equals(OBSTACLE_TYPE_STR) && !(e instanceof ObstacleActor)) || (type.equals(ANCHOR_TYPE_STR) && !(e instanceof AnchorActor));
        isPlayer = parent.getPlayer() == e;
        // remove to allow id, zindex and layer change
        parent.removeActor(e);
        oldId = e.getId();
    }
    if (create || typeChanged) {
        if (type.equals(BACKGROUND_TYPE_STR)) {
            e = new InteractiveActor();
        } else if (type.equals(SPRITE_TYPE_STR)) {
            e = new SpriteActor();
        } else if (type.equals(CHARACTER_TYPE_STR)) {
            e = new CharacterActor();
        } else if (type.equals(OBSTACLE_TYPE_STR)) {
            e = new ObstacleActor();
        } else if (type.equals(ANCHOR_TYPE_STR)) {
            e = new AnchorActor();
        }
        if (!(e instanceof SpriteActor) && !(e instanceof AnchorActor)) {
            Polygon bbox = e.getBBox();
            bbox.setVertices(new float[8]);
            float[] verts = bbox.getVertices();
            verts[0] = -DEFAULT_DIM / 2;
            verts[1] = 0f;
            verts[2] = -DEFAULT_DIM / 2;
            verts[3] = DEFAULT_DIM;
            verts[4] = DEFAULT_DIM / 2;
            verts[5] = DEFAULT_DIM;
            verts[6] = DEFAULT_DIM / 2;
            verts[7] = 0f;
            bbox.dirty();
        }
    }
    if (typeChanged) {
        if (oldElement instanceof InteractiveActor && e instanceof InteractiveActor) {
            HashMap<String, Verb> verbs = ((InteractiveActor) e).getVerbManager().getVerbs();
            HashMap<String, Verb> oldVerbs = ((InteractiveActor) oldElement).getVerbManager().getVerbs();
            for (String k : oldVerbs.keySet()) {
                Verb v = oldVerbs.get(k);
                verbs.put(k, v);
            }
        }
        if (oldElement instanceof SpriteActor && e instanceof SpriteActor) {
            ((SpriteActor) e).setRenderer(((SpriteActor) oldElement).getRenderer());
        }
    }
    e.setId(ElementUtils.getCheckedId(id.getText(), parent.getActors().keySet().toArray(new String[0])));
    e.setVisible(Boolean.parseBoolean(visible.getText()));
    Vector2 p = Param.parseVector2(pos.getText());
    e.setPosition(p.x, p.y);
    if (e instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) e;
        ia.setLayer(layer.getText());
        ia.setInteraction(Boolean.parseBoolean(interaction.getText()));
        Vector2 rp = Param.parseVector2(refPoint.getText());
        ia.setRefPoint(rp.x, rp.y);
        String key = ia.getDesc();
        if (key == null || key.isEmpty() || key.charAt(0) != I18N.PREFIX || !e.getId().equals(oldId))
            key = Ctx.project.getI18N().genKey(parent.getId(), e.getId(), "desc");
        Ctx.project.getI18N().setTranslation(key, desc.getText());
        if (desc.getText() != null)
            ia.setDesc(key);
        else
            ia.setDesc(null);
        ia.setState(state.getText());
        ia.setZIndex(Float.parseFloat(zIndex.getText()));
        if (e instanceof SpriteActor) {
            SpriteActor sa = (SpriteActor) e;
            String rendererType = renderer.getText();
            if (Project.ATLAS_RENDERER_STRING.equals(rendererType)) {
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof AtlasRenderer))
                    sa.setRenderer(new AtlasRenderer());
            } else if (Project.IMAGE_RENDERER_STRING.equals(rendererType)) {
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof ImageRenderer))
                    sa.setRenderer(new ImageRenderer());
            } else if (Project.S3D_RENDERER_STRING.equals(rendererType)) {
                Sprite3DRenderer r;
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof Sprite3DRenderer)) {
                    r = new Sprite3DRenderer();
                    sa.setRenderer(r);
                } else {
                    r = (Sprite3DRenderer) sa.getRenderer();
                }
                r.setCameraFOV(Float.parseFloat(fov.getText()));
                r.setCameraName(cameraName.getText());
                r.setSpriteSize(Param.parseVector2(spriteSize.getText()));
            } else if (Project.PARTICLE_RENDERER_STRING.equals(rendererType)) {
                ParticleRenderer r;
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof ParticleRenderer)) {
                    r = new ParticleRenderer();
                    sa.setRenderer(r);
                } else {
                    r = (ParticleRenderer) sa.getRenderer();
                }
                r.setParticleName(particleName.getText());
                r.setAtlasName(particleAtlas.getText());
            } else if (Project.TEXT_RENDERER_STRING.equals(rendererType)) {
                TextRenderer r;
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof TextRenderer)) {
                    r = new TextRenderer();
                    sa.setRenderer(r);
                } else {
                    r = (TextRenderer) sa.getRenderer();
                }
                key = text.getText();
                if (key == null || key.isEmpty() || key.charAt(0) != I18N.PREFIX || !e.getId().equals(oldId))
                    key = Ctx.project.getI18N().genKey(parent.getId(), e.getId(), "text");
                Ctx.project.getI18N().setTranslation(key, text.getText());
                if (text.getText() != null)
                    r.setText(key, text.getText());
                else
                    r.setText(null, null);
                r.setFontSize(Integer.parseInt(size.getText()));
                r.setFontName(font.getText());
                r.setAlign(AlignUtils.getAlign(textAlign.getText()));
                r.setBorderWidth(Integer.parseInt(borderWidth.getText()));
                r.setBorderColor(Param.parseColor(borderColor.getText()));
                r.setBorderStraight(Boolean.parseBoolean(borderStraight.getText()));
                r.setShadowOffsetX(Integer.parseInt(shadowOffsetX.getText()));
                r.setShadowOffsetY(Integer.parseInt(shadowOffsetY.getText()));
                r.setShadowColor(Param.parseColor(shadowColor.getText()));
                // dispose to force reload the text attributes
                sa.dispose();
            } else if (Project.SPINE_RENDERER_STRING.equals(rendererType)) {
                SpineRenderer r;
                if (sa.getRenderer() == null || !(sa.getRenderer() instanceof SpineRenderer)) {
                    r = new SpineRenderer();
                    sa.setRenderer(r);
                } else {
                    r = (SpineRenderer) sa.getRenderer();
                }
                r.setSkin(spineSkin.getText());
            }
            boolean bbfr = Boolean.parseBoolean(bboxFromRenderer.getText());
            if (bbfr != sa.isBboxFromRenderer())
                sa.setBboxFromRenderer(bbfr);
            sa.setFakeDepth(Boolean.parseBoolean(fakeDepth.getText()));
            sa.setScale(Float.parseFloat(scale.getText()));
            sa.setRot(Float.parseFloat(rot.getText()));
            sa.getRenderer().setOrgAlign(AlignUtils.getAlign(orgAlign.getText()));
            sa.setTint(Param.parseColor(tint.getText()));
            if (e instanceof CharacterActor) {
                CharacterActor ca = (CharacterActor) e;
                ca.setWalkingSpeed(Float.parseFloat(walkingSpeed.getText()));
                ca.setTextColor(Param.parseColor(textColor.getText()));
                ca.setTextStyle(textStyle.getText());
            }
        }
    }
    parent.addActor(e);
    if (isPlayer && !typeChanged)
        parent.setPlayer((CharacterActor) e);
    if (e instanceof InteractiveActor) {
        SceneLayer l = parent.getLayer(((InteractiveActor) e).getLayer());
        l.orderByZIndex();
    }
    if (e instanceof SpriteActor)
        ((SpriteActor) e).retrieveAssets();
    // TODO UNDO OP
    // UndoOp undoOp = new UndoAddElement(doc, e);
    // Ctx.project.getUndoStack().add(undoOp);
    Ctx.project.setModified();
}
Also used : AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) SceneLayer(com.bladecoder.engine.model.SceneLayer) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) ParticleRenderer(com.bladecoder.engine.model.ParticleRenderer) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) CharacterActor(com.bladecoder.engine.model.CharacterActor) AnchorActor(com.bladecoder.engine.model.AnchorActor) ImageRenderer(com.bladecoder.engine.model.ImageRenderer) ObstacleActor(com.bladecoder.engine.model.ObstacleActor) Vector2(com.badlogic.gdx.math.Vector2) Verb(com.bladecoder.engine.model.Verb) Sprite3DRenderer(com.bladecoder.engine.model.Sprite3DRenderer) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Polygon(com.badlogic.gdx.math.Polygon) TextRenderer(com.bladecoder.engine.model.TextRenderer)

Example 7 with SceneLayer

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

the class ScnWidget method act.

@Override
public void act(float delta) {
    if (projectLoadedFlag) {
        projectLoadedFlag = false;
        if (scn != null) {
            scn.dispose();
            scn = null;
        }
        setSelectedScene(Ctx.project.getSelectedScene());
        setSelectedActor(Ctx.project.getSelectedActor());
        setSelectedFA(Ctx.project.getSelectedFA());
    }
    if (scn != null && !loading && !loadingError) {
        if (!inScene)
            faRenderer.update(delta);
        for (SceneLayer layer : scn.getLayers()) layer.update();
        if (animation) {
            for (BaseActor a : scn.getActors().values()) {
                boolean v = a.isVisible();
                a.setVisible(true);
                a.update(delta);
                a.setVisible(v);
            }
        }
        handleKeyPositioning();
    }
}
Also used : SceneLayer(com.bladecoder.engine.model.SceneLayer) BaseActor(com.bladecoder.engine.model.BaseActor)

Example 8 with SceneLayer

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

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

the class LayerList method down.

private void down() {
    int pos = list.getSelectedIndex();
    Array<SceneLayer> items = list.getItems();
    if (pos == -1 || pos == items.size - 1)
        return;
    SceneLayer e = items.get(pos);
    SceneLayer e2 = pos + 1 < items.size ? items.get(pos + 1) : null;
    parent.getLayers().set(pos, e2);
    parent.getLayers().set(pos + 1, e);
    items.removeIndex(pos);
    items.insert(pos + 1, e);
    list.setSelectedIndex(pos + 1);
    upBtn.setDisabled(list.getSelectedIndex() == 0);
    downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1);
    Ctx.project.setModified();
}
Also used : SceneLayer(com.bladecoder.engine.model.SceneLayer)

Example 10 with SceneLayer

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

the class LayerList method delete.

@Override
protected void delete() {
    int pos = list.getSelectedIndex();
    if (pos == -1)
        return;
    if (list.getItems().size < 2) {
        String msg = "The layer will not be deleted, at least one layer must exist";
        Message.showMsg(getStage(), msg, 3);
        return;
    }
    SceneLayer e = list.getSelected();
    if (e.getActors().isEmpty()) {
        SceneLayer l = removeSelected();
        parent.getLayers().remove(l);
        Ctx.project.setModified();
    } else {
        String msg = "The layer is not empty.";
        Message.showMsg(getStage(), msg, 3);
    }
}
Also used : SceneLayer(com.bladecoder.engine.model.SceneLayer)

Aggregations

SceneLayer (com.bladecoder.engine.model.SceneLayer)10 BaseActor (com.bladecoder.engine.model.BaseActor)4 Vector2 (com.badlogic.gdx.math.Vector2)3 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)3 SpriteActor (com.bladecoder.engine.model.SpriteActor)3 CharacterActor (com.bladecoder.engine.model.CharacterActor)2 Scene (com.bladecoder.engine.model.Scene)2 SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)2 Color (com.badlogic.gdx.graphics.Color)1 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)1 Polygon (com.badlogic.gdx.math.Polygon)1 Vector3 (com.badlogic.gdx.math.Vector3)1 Task (com.badlogic.gdx.utils.Timer.Task)1 AnchorActor (com.bladecoder.engine.model.AnchorActor)1 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)1 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)1 MusicDesc (com.bladecoder.engine.model.MusicDesc)1 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)1 ParticleRenderer (com.bladecoder.engine.model.ParticleRenderer)1 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)1