Search in sources :

Example 6 with AnimationDesc

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

the class ActorAnimationInputPanel method actorSelected.

private void actorSelected() {
    String s = actor.getSelected();
    SpriteActor a = null;
    if (Ctx.project.getSelectedActor() instanceof SpriteActor)
        a = (SpriteActor) Ctx.project.getSelectedActor();
    ArrayList<String> values = new ArrayList<String>();
    if (s != null && !s.isEmpty()) {
        a = (SpriteActor) Ctx.project.getSelectedScene().getActor(s, false);
    }
    if (a != null && a.getRenderer() instanceof AnimationRenderer) {
        HashMap<String, AnimationDesc> animations = ((AnimationRenderer) a.getRenderer()).getAnimations();
        if (!isMandatory()) {
            values.add("");
        }
        for (AnimationDesc anim : animations.values()) {
            values.add(anim.id);
            String flipped = AnimationRenderer.getFlipId(anim.id);
            if (!flipped.isEmpty()) {
                values.add(flipped);
            }
        }
    }
    String[] array = values.toArray(new String[values.size()]);
    Arrays.sort(array);
    animation.setItems(array);
    if (values.size() > 0)
        animation.setSelected("");
}
Also used : ArrayList(java.util.ArrayList) SpriteActor(com.bladecoder.engine.model.SpriteActor) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 7 with AnimationDesc

use of com.bladecoder.engine.anim.AnimationDesc 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 8 with AnimationDesc

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

the class SpriteList method paste.

@Override
protected void paste() {
    AnimationDesc newElement = (AnimationDesc) ElementUtils.cloneElement(clipboard);
    int pos = list.getSelectedIndex() + 1;
    list.getItems().insert(pos, newElement);
    ((AnimationRenderer) parent.getRenderer()).addAnimation(newElement);
    list.setSelectedIndex(pos);
    list.invalidateHierarchy();
    Ctx.project.setModified();
}
Also used : AnimationDesc(com.bladecoder.engine.anim.AnimationDesc) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 9 with AnimationDesc

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

the class CheckInteractionVerbs method visit.

@Override
public void visit(BaseActor a) {
    if (a instanceof InteractiveActor) {
        ia = (InteractiveActor) a;
        hasLookat = false;
        hasPickup = false;
        hasTalkto = false;
        hasLeave = false;
        hasEnterExit = false;
        hasUse = false;
        if (ia.getInteraction()) {
            HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
            for (Verb v : verbs.values()) checkVerb(v);
            if (hasLeave || hasEnterExit)
                return;
            // discard inventory actors
            if (hasLookat) {
                if (ia instanceof SpriteActor) {
                    SpriteActor sa = (SpriteActor) ia;
                    if (sa.getRenderer() instanceof AtlasRenderer) {
                        AtlasRenderer r = (AtlasRenderer) sa.getRenderer();
                        HashMap<String, AnimationDesc> animations = r.getAnimations();
                        if (animations.size() == 0) {
                            EditorLogger.error("CheckInteractionVerbs: Actor with no animations! - " + sa.getScene().getId() + "." + sa.getId());
                        }
                        if (animations.get(r.getInitAnimation()).source.contains("inventory")) {
                            if (!hasUse)
                                EditorLogger.msg("CheckInteractionVerbs: Inventory item should has default 'use' - " + sa.getScene().getId() + "." + sa.getId());
                            return;
                        }
                    }
                }
            }
            // check for lookat and pickup/talk verbs
            if (!hasLookat || (!hasPickup && !hasTalkto)) {
                String msg = "CheckInteractionVerbs: " + a.getScene().getId() + "." + a.getId();
                if (!hasLookat)
                    EditorLogger.error(msg);
                else
                    EditorLogger.msg(msg);
            }
        }
    }
}
Also used : AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Verb(com.bladecoder.engine.model.Verb) SpriteActor(com.bladecoder.engine.model.SpriteActor) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Example 10 with AnimationDesc

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

the class Sprite3DRenderer method startAnimation.

// public Array<Animation> getAnimations() {
// return modelInstance.animations;
// }
@Override
public void startAnimation(String id, Tween.Type repeatType, int count, ActionCallback cb) {
    AnimationDesc fa = fanims.get(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 (currentSource == null || currentSource.refCounter < 1) {
        // If the source is not loaded. Load it.
        loadSource(fa.source);
        EngineAssetManager.getInstance().finishLoading();
        retrieveSource(fa.source);
        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;
    }
    lastAnimationTime = 0;
    float speed = currentAnimation.duration;
    if (currentAnimationType == Tween.Type.REVERSE || currentAnimationType == Tween.Type.REVERSE_REPEAT)
        speed *= -1;
    ModelCacheEntry cs = (ModelCacheEntry) currentSource;
    if (cs.modelInstance.getAnimation(id) != null) {
        animationCb = cb;
        cs.controller.setAnimation(id, currentCount, speed, animationListener);
        computeBbox();
        return;
    }
    int idx = id.indexOf('.');
    if (idx != -1) {
        String s = id.substring(0, idx);
        String dir = id.substring(idx + 1);
        lookat(dir);
        if (cs.modelInstance.getAnimation(s) != null) {
            cs.controller.setAnimation(s, count, speed, animationListener);
            computeBbox();
            return;
        }
    }
    // ERROR CASE
    EngineLogger.error("Animation NOT FOUND: " + id);
    for (Animation a : cs.modelInstance.animations) {
        EngineLogger.debug(a.id);
    }
    if (cb != null) {
        ActionCallbackQueue.add(cb);
    }
    computeBbox();
}
Also used : Animation(com.badlogic.gdx.graphics.g3d.model.Animation) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Aggregations

AnimationDesc (com.bladecoder.engine.anim.AnimationDesc)13 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)3 Vector2 (com.badlogic.gdx.math.Vector2)2 AtlasAnimationDesc (com.bladecoder.engine.anim.AtlasAnimationDesc)2 SpineAnimationDesc (com.bladecoder.engine.anim.SpineAnimationDesc)2 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)2 SpriteActor (com.bladecoder.engine.model.SpriteActor)2 SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)2 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)1 Action (com.bladecoder.engine.actions.Action)1 PlaySoundAction (com.bladecoder.engine.actions.PlaySoundAction)1 SoundAction (com.bladecoder.engine.actions.SoundAction)1 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)1 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)1 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)1 Verb (com.bladecoder.engine.model.Verb)1 UndoDeleteAnimation (com.bladecoder.engineeditor.undo.UndoDeleteAnimation)1 ArrayList (java.util.ArrayList)1