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));
}
}
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();
}
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);
}
}
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();
}
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());
}
}
Aggregations