Search in sources :

Example 1 with AtlasRenderer

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

the class EditActorDialog method modelToInputs.

@Override
protected void modelToInputs() {
    id.setText(e.getId());
    visible.setText(Boolean.toString(e.isVisible()));
    pos.setText(Param.toStringParam(new Vector2(e.getX(), e.getY())));
    if (e instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) e;
        layer.setText(ia.getLayer());
        interaction.setText(Boolean.toString(ia.getInteraction()));
        refPoint.setText(Param.toStringParam(ia.getRefPoint()));
        desc.setText(Ctx.project.translate(ia.getDesc()));
        state.setText(ia.getState());
        zIndex.setText(Float.toString(ia.getZIndex()));
        if (e instanceof SpriteActor) {
            SpriteActor sa = (SpriteActor) e;
            ActorRenderer r = sa.getRenderer();
            if (r instanceof AtlasRenderer) {
                renderer.setText(Project.ATLAS_RENDERER_STRING);
            } else if (r instanceof ImageRenderer) {
                renderer.setText(Project.IMAGE_RENDERER_STRING);
            } else if (r instanceof Sprite3DRenderer) {
                renderer.setText(Project.S3D_RENDERER_STRING);
                Sprite3DRenderer s3d = (Sprite3DRenderer) r;
                fov.setText(Float.toString(s3d.getCameraFOV()));
                cameraName.setText(s3d.getCameraName());
                spriteSize.setText(Param.toStringParam(s3d.getSpriteSize()));
            } else if (r instanceof ParticleRenderer) {
                renderer.setText(Project.PARTICLE_RENDERER_STRING);
                ParticleRenderer pr = (ParticleRenderer) r;
                particleName.setText(pr.getParticleName());
                particleAtlas.setText(pr.getAtlasName());
            } else if (r instanceof TextRenderer) {
                renderer.setText(Project.TEXT_RENDERER_STRING);
                TextRenderer tr = (TextRenderer) r;
                text.setText(Ctx.project.translate(tr.getText()));
                size.setText(Integer.toString(tr.getFontSize()));
                font.setText(tr.getFontName());
                borderWidth.setText(Integer.toString(tr.getBorderWidth()));
                textAlign.setText(AlignUtils.getAlign(tr.getAlign()));
                borderColor.setText(tr.getBorderColor().toString());
                borderStraight.setText(Boolean.toString(tr.isBorderStraight()));
                shadowOffsetX.setText(Integer.toString(tr.getShadowOffsetX()));
                shadowOffsetY.setText(Integer.toString(tr.getShadowOffsetY()));
                shadowColor.setText(tr.getShadowColor().toString());
            } else if (r instanceof SpineRenderer) {
                renderer.setText(Project.SPINE_RENDERER_STRING);
                spineSkin.setText(((SpineRenderer) r).getSkin());
            }
            fakeDepth.setText(Boolean.toString(sa.getFakeDepth()));
            scale.setText(Float.toString(sa.getScale()));
            rot.setText(Float.toString(sa.getRot()));
            tint.setText(sa.getTint() == null ? null : sa.getTint().toString());
            bboxFromRenderer.setText(Boolean.toString(sa.isBboxFromRenderer()));
            orgAlign.setText(AlignUtils.getAlign(sa.getRenderer().getOrgAlign()));
            if (e instanceof CharacterActor) {
                CharacterActor ca = (CharacterActor) e;
                walkingSpeed.setText(Float.toString(ca.getWalkingSpeed()));
                textColor.setText(ca.getTextColor() == null ? null : ca.getTextColor().toString());
                textStyle.setText(ca.getTextStyle());
                typePanel.setText(CHARACTER_TYPE_STR);
            } else {
                typePanel.setText(SPRITE_TYPE_STR);
            }
        } else {
            typePanel.setText(BACKGROUND_TYPE_STR);
        }
    } else if (e instanceof AnchorActor) {
        typePanel.setText(ANCHOR_TYPE_STR);
    } else if (e instanceof ObstacleActor) {
        typePanel.setText(OBSTACLE_TYPE_STR);
    }
}
Also used : AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) 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) Vector2(com.badlogic.gdx.math.Vector2) ObstacleActor(com.bladecoder.engine.model.ObstacleActor) Sprite3DRenderer(com.bladecoder.engine.model.Sprite3DRenderer) SpriteActor(com.bladecoder.engine.model.SpriteActor) ActorRenderer(com.bladecoder.engine.model.ActorRenderer) TextRenderer(com.bladecoder.engine.model.TextRenderer)

Example 2 with AtlasRenderer

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

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

the class EditAnimationDialog method inputsToModel.

@Override
protected void inputsToModel(boolean create) {
    String sourceStr = source.getText();
    AnimationRenderer renderer = (AnimationRenderer) parent.getRenderer();
    if (create) {
        if (renderer instanceof SpineRenderer) {
            e = new SpineAnimationDesc();
            if (spineAtlasExists(sourceStr)) {
                ((SpineAnimationDesc) e).atlas = null;
                setVisible(atlas, false);
            } else {
                if (!atlas.isVisible()) {
                    setVisible(atlas, true);
                }
                ((SpineAnimationDesc) e).atlas = atlas.getText();
            }
        } else if (renderer instanceof AtlasRenderer) {
            e = new AtlasAnimationDesc();
        } else {
            e = new AnimationDesc();
        }
    } else {
        HashMap<String, AnimationDesc> animations = renderer.getAnimations();
        animations.remove(e.id);
        if (e.id.equals(renderer.getInitAnimation()))
            renderer.setInitAnimation(null);
    }
    e.id = id.getText();
    e.sound = sound.getText();
    e.source = sourceStr;
    e.count = Integer.parseInt(count.getText());
    e.preload = Boolean.parseBoolean(preload.getText());
    e.disposeWhenPlayed = Boolean.parseBoolean(dispose.getText());
    e.animationType = Type.valueOf(repeat.getText());
    e.inD = Param.parseVector2(in.getText());
    e.outD = Param.parseVector2(out.getText());
    e.duration = Float.parseFloat(speed.getText());
    ((AnimationRenderer) parent.getRenderer()).addAnimation(e);
    if (renderer instanceof ImageRenderer && Boolean.parseBoolean(localizable.getText()) && e.source != null && e.source.length() > 0) {
        e.source = I18N.PREFIX + e.source;
    }
    if (renderer.getInitAnimation() == null)
        renderer.setInitAnimation(e.id);
    // TODO UNDO OP
    // UndoOp undoOp = new UndoAddElement(doc, e);
    // Ctx.project.getUndoStack().add(undoOp);
    Ctx.project.setModified();
}
Also used : AtlasAnimationDesc(com.bladecoder.engine.anim.AtlasAnimationDesc) SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) ImageRenderer(com.bladecoder.engine.model.ImageRenderer) AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc) AtlasAnimationDesc(com.bladecoder.engine.anim.AtlasAnimationDesc) SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 4 with AtlasRenderer

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

the class AnimationWidget method setSource.

public void setSource(String type, AnimationDesc anim) {
    fa = anim;
    if (renderer != null) {
        renderer.dispose();
        renderer = null;
    }
    if (type.equals(Project.S3D_RENDERER_STRING)) {
        renderer = new Sprite3DRenderer();
        ((Sprite3DRenderer) renderer).setSpriteSize(new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
    } else if (type.equals(Project.SPINE_RENDERER_STRING)) {
        renderer = new SpineRenderer();
        ((SpineRenderer) renderer).enableEvents(false);
    } else if (type.equals(Project.IMAGE_RENDERER_STRING)) {
        renderer = new ImageRenderer();
    } else {
        renderer = new AtlasRenderer();
    }
    renderer.setOrgAlign(Align.bottom);
    renderer.loadAssets();
    EngineAssetManager.getInstance().finishLoading();
    renderer.retrieveAssets();
}
Also used : ImageRenderer(com.bladecoder.engine.model.ImageRenderer) AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) Vector2(com.badlogic.gdx.math.Vector2) Sprite3DRenderer(com.bladecoder.engine.model.Sprite3DRenderer) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer)

Example 5 with AtlasRenderer

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

the class AnimationDrawer method setActor.

public void setActor(BaseActor a) {
    if (renderer != null) {
        renderer.dispose();
        renderer = null;
    }
    if (a instanceof SpriteActor && ((SpriteActor) a).getRenderer() instanceof AnimationRenderer) {
        ActorRenderer r = ((SpriteActor) a).getRenderer();
        if (r instanceof Sprite3DRenderer) {
            renderer = new Sprite3DRenderer();
            ((Sprite3DRenderer) renderer).setSpriteSize(new Vector2(r.getWidth(), r.getHeight()));
        } else if (r instanceof SpineRenderer) {
            renderer = new SpineRenderer();
            ((SpineRenderer) renderer).enableEvents(false);
            ((SpineRenderer) renderer).setSkin(((SpineRenderer) r).getSkin());
        } else if (r instanceof ImageRenderer) {
            renderer = new ImageRenderer();
        } else if (r instanceof AtlasRenderer) {
            renderer = new AtlasRenderer();
        }
        renderer.setOrgAlign(Align.bottom);
    }
}
Also used : ImageRenderer(com.bladecoder.engine.model.ImageRenderer) AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) Vector2(com.badlogic.gdx.math.Vector2) Sprite3DRenderer(com.bladecoder.engine.model.Sprite3DRenderer) SpriteActor(com.bladecoder.engine.model.SpriteActor) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) ActorRenderer(com.bladecoder.engine.model.ActorRenderer) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Aggregations

AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)8 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)7 SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)7 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)6 Vector2 (com.badlogic.gdx.math.Vector2)4 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)4 SpriteActor (com.bladecoder.engine.model.SpriteActor)4 AnimationDesc (com.bladecoder.engine.anim.AnimationDesc)3 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)3 AtlasAnimationDesc (com.bladecoder.engine.anim.AtlasAnimationDesc)2 SpineAnimationDesc (com.bladecoder.engine.anim.SpineAnimationDesc)2 AnchorActor (com.bladecoder.engine.model.AnchorActor)2 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)2 CharacterActor (com.bladecoder.engine.model.CharacterActor)2 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)2 ParticleRenderer (com.bladecoder.engine.model.ParticleRenderer)2 TextRenderer (com.bladecoder.engine.model.TextRenderer)2 Verb (com.bladecoder.engine.model.Verb)2 Polygon (com.badlogic.gdx.math.Polygon)1 BaseActor (com.bladecoder.engine.model.BaseActor)1