Search in sources :

Example 1 with SpineAnimationDesc

use of com.bladecoder.engine.anim.SpineAnimationDesc in project bladecoder-adventure-engine by bladecoder.

the class EditAnimationDialog method modelToInputs.

@Override
protected void modelToInputs() {
    source.setText(e.source);
    if (atlas.isVisible() && e instanceof SpineAnimationDesc)
        atlas.setText(((SpineAnimationDesc) e).atlas);
    id.setText(e.id);
    repeat.setText(e.animationType.toString());
    speed.setText(Float.toString(e.duration));
    count.setText(Integer.toString(e.count));
    in.setText(Param.toStringParam(e.inD));
    out.setText(Param.toStringParam(e.outD));
    sound.setText(e.sound);
    preload.setText(Boolean.toString(e.preload));
    dispose.setText(Boolean.toString(e.disposeWhenPlayed));
    showHideFieldsDelayCountFields();
    ActorRenderer renderer = parent.getRenderer();
    if (renderer instanceof ImageRenderer && e.source != null && e.source.length() > 1 && e.source.charAt(0) == I18N.PREFIX) {
        localizable.setText("true");
        source.setText(e.source.substring(1));
    }
}
Also used : SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) ImageRenderer(com.bladecoder.engine.model.ImageRenderer) ActorRenderer(com.bladecoder.engine.model.ActorRenderer)

Example 2 with SpineAnimationDesc

use of com.bladecoder.engine.anim.SpineAnimationDesc 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 SpineAnimationDesc

use of com.bladecoder.engine.anim.SpineAnimationDesc in project bladecoder-adventure-engine by bladecoder.

the class EditAnimationDialog method setSource.

private void setSource() {
    AnimationDesc anim = null;
    ActorRenderer renderer = parent.getRenderer();
    String sourceStr = source.getText();
    if (renderer instanceof SpineRenderer) {
        anim = new SpineAnimationDesc();
        if (spineAtlasExists(sourceStr)) {
            ((SpineAnimationDesc) anim).atlas = null;
            setVisible(atlas, false);
        } else {
            if (!atlas.isVisible()) {
                setVisible(atlas, true);
            }
            ((SpineAnimationDesc) anim).atlas = atlas.getText();
        }
    } else if (renderer instanceof AtlasRenderer) {
        anim = new AtlasAnimationDesc();
    } else {
        anim = new AnimationDesc();
    }
    anim.source = sourceStr;
    anim.count = Tween.INFINITY;
    anim.preload = true;
    anim.disposeWhenPlayed = false;
    if (renderer instanceof SpineRenderer) {
        spriteWidget.setSource(Project.SPINE_RENDERER_STRING, anim);
    } else if (renderer instanceof AtlasRenderer) {
        spriteWidget.setSource(Project.ATLAS_RENDERER_STRING, anim);
    } else if (renderer instanceof ImageRenderer) {
        spriteWidget.setSource(Project.IMAGE_RENDERER_STRING, anim);
    } else if (renderer instanceof Sprite3DRenderer) {
        spriteWidget.setSource(Project.S3D_RENDERER_STRING, anim);
    }
}
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) Sprite3DRenderer(com.bladecoder.engine.model.Sprite3DRenderer) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc) AtlasAnimationDesc(com.bladecoder.engine.anim.AtlasAnimationDesc) SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) SpineRenderer(com.bladecoder.engine.spine.SpineRenderer) ActorRenderer(com.bladecoder.engine.model.ActorRenderer)

Example 4 with SpineAnimationDesc

use of com.bladecoder.engine.anim.SpineAnimationDesc in project bladecoder-adventure-engine by bladecoder.

the class SpineRenderer method startAnimation.

@Override
public void startAnimation(String id, Tween.Type repeatType, int count, ActionCallback cb) {
    SpineAnimationDesc fa = (SpineAnimationDesc) getAnimation(id);
    if (fa == null) {
        EngineLogger.error("AnimationDesc not found: " + id);
        return;
    }
    if (currentAnimation != null && currentAnimation.disposeWhenPlayed)
        disposeSource(currentAnimation.source);
    currentAnimation = fa;
    currentSource = sourceCache.get(fa.source);
    animationCb = cb;
    // If the source is not loaded. Load it.
    if (currentSource == null || currentSource.refCounter < 1) {
        loadSource(fa.source, fa.atlas);
        EngineAssetManager.getInstance().finishLoading();
        retrieveSource(fa.source, fa.atlas);
        currentSource = sourceCache.get(fa.source);
        if (currentSource == null) {
            EngineLogger.error("Could not load AnimationDesc: " + id);
            currentAnimation = null;
            return;
        }
    }
    if (repeatType == Tween.Type.SPRITE_DEFINED) {
        currentAnimationType = currentAnimation.animationType;
        currentCount = currentAnimation.count;
    } else {
        currentCount = count;
        currentAnimationType = repeatType;
    }
    if (currentAnimationType == Tween.Type.REVERSE) {
        // get animation duration
        Array<Animation> animations = ((SkeletonCacheEntry) currentSource).skeleton.getData().getAnimations();
        for (Animation a : animations) {
            if (a.getName().equals(currentAnimation.id)) {
                lastAnimationTime = a.getDuration() / currentAnimation.duration - 0.01f;
                break;
            }
        }
    } else {
        lastAnimationTime = 0f;
    }
    complete = false;
    loopCount = 0;
    setCurrentAnimation();
}
Also used : SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) Animation(com.esotericsoftware.spine.Animation)

Example 5 with SpineAnimationDesc

use of com.bladecoder.engine.anim.SpineAnimationDesc in project bladecoder-adventure-engine by bladecoder.

the class SpineRenderer method setSecondaryAnimation.

public void setSecondaryAnimation(String animation) {
    secondaryAnimation = animation;
    SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource;
    try {
        if (animation == null) {
            cs.animation.setEmptyAnimation(1, 0);
        // cs.animation.clearTrack(1);
        } else {
            SpineAnimationDesc fa = (SpineAnimationDesc) fanims.get(animation);
            if (fa == null) {
                EngineLogger.error("SpineRenderer:setCurrentFA Animation not found: " + animation);
                return;
            }
            cs.animation.setAnimation(1, secondaryAnimation, fa.animationType == Tween.Type.REPEAT);
        }
        updateAnimation(0);
    } catch (Exception e) {
        EngineLogger.error("SpineRenderer:setCurrentFA " + e.getMessage());
    }
}
Also used : SpineAnimationDesc(com.bladecoder.engine.anim.SpineAnimationDesc) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Aggregations

SpineAnimationDesc (com.bladecoder.engine.anim.SpineAnimationDesc)5 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)3 AnimationDesc (com.bladecoder.engine.anim.AnimationDesc)2 AtlasAnimationDesc (com.bladecoder.engine.anim.AtlasAnimationDesc)2 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)2 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)2 SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)1 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)1 Animation (com.esotericsoftware.spine.Animation)1