Search in sources :

Example 1 with AnimationRenderer

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

the class IfAttrAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = actor.getScene();
    final String actorId = actor.getActorId();
    if (actorId == null) {
        // if called inside a scene verb and no actor is specified, return
        EngineLogger.error(getClass() + ": No actor specified");
        return false;
    }
    BaseActor a = s.getActor(actorId, true);
    if (attr.equals(ActorAttribute.STATE) && a instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) a;
        if (!ActionUtils.compareNullStr(value, ia.getState())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.VISIBLE)) {
        boolean val = Boolean.parseBoolean(value);
        if (val != a.isVisible()) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.INTERACTIVE)) {
        boolean val = Boolean.parseBoolean(value);
        if (a instanceof InteractiveActor) {
            if (val != ((InteractiveActor) a).getInteraction()) {
                gotoElse((VerbRunner) cb);
            }
        } else if (val == true) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.IN_INVENTORY)) {
        boolean val = Boolean.parseBoolean(value);
        SpriteActor item = null;
        if (a != null)
            item = World.getInstance().getInventory().get(a.getId());
        if ((val && item == null) || (!val && item != null)) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.TARGET)) {
        if (!ActionUtils.compareNullStr(value, cb.getCurrentTarget())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.IN_SCENE)) {
        boolean val = Boolean.parseBoolean(value);
        BaseActor a2 = s.getActor(actorId, false);
        if ((val && a2 == null) || (!val && a2 != null))
            gotoElse((VerbRunner) cb);
    } else if (attr.equals(ActorAttribute.LAYER) && a instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) a;
        if (!ActionUtils.compareNullStr(value, ia.getLayer())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.DIRECTION) && a instanceof SpriteActor) {
        SpriteActor sa = (SpriteActor) a;
        if (sa.getRenderer() instanceof AnimationRenderer) {
            String dir = null;
            String anim = ((AnimationRenderer) sa.getRenderer()).getCurrentAnimationId();
            int idx = anim.lastIndexOf('.');
            if (idx != -1)
                dir = anim.substring(idx + 1);
            if (!ActionUtils.compareNullStr(value, dir)) {
                gotoElse((VerbRunner) cb);
            }
        }
    }
    return false;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) VerbRunner(com.bladecoder.engine.model.VerbRunner) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 2 with AnimationRenderer

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

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

the class AnimationWidget method draw.

public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    if (renderer == null || ((AnimationRenderer) renderer).getCurrentAnimation() == null)
        return;
    Color tmp = batch.getColor();
    batch.setColor(Color.WHITE);
    renderer.update(Gdx.graphics.getDeltaTime());
    RectangleRenderer.draw((SpriteBatch) batch, getX(), getY(), getWidth(), getHeight(), Color.MAGENTA);
    float scalew = getWidth() / renderer.getWidth();
    float scaleh = getHeight() / renderer.getHeight();
    float scale = scalew > scaleh ? scaleh : scalew;
    renderer.draw((SpriteBatch) batch, getX() + renderer.getWidth() * scale / 2, getY(), scale, 0f, null);
    batch.setColor(tmp);
}
Also used : Color(com.badlogic.gdx.graphics.Color) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 4 with AnimationRenderer

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

Example 5 with AnimationRenderer

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

the class SpriteList method flipInit.

private void flipInit() {
    int pos = list.getSelectedIndex();
    if (pos == -1)
        return;
    AnimationRenderer renderer = (AnimationRenderer) ((SpriteActor) Ctx.project.getSelectedActor()).getRenderer();
    String id = list.getItems().get(pos).id;
    String newValue = AnimationRenderer.getFlipId(id);
    renderer.setInitAnimation(newValue);
    Ctx.project.setModified(this, "init_animation", id, newValue);
}
Also used : AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Aggregations

AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)12 SpriteActor (com.bladecoder.engine.model.SpriteActor)6 AnimationDesc (com.bladecoder.engine.anim.AnimationDesc)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)2 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)2 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)2 Scene (com.bladecoder.engine.model.Scene)2 SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)2 Color (com.badlogic.gdx.graphics.Color)1 Vector2 (com.badlogic.gdx.math.Vector2)1 AtlasAnimationDesc (com.bladecoder.engine.anim.AtlasAnimationDesc)1 SpineAnimationDesc (com.bladecoder.engine.anim.SpineAnimationDesc)1 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)1 BaseActor (com.bladecoder.engine.model.BaseActor)1 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)1 VerbRunner (com.bladecoder.engine.model.VerbRunner)1 UndoDeleteAnimation (com.bladecoder.engineeditor.undo.UndoDeleteAnimation)1 ArrayList (java.util.ArrayList)1