فهرست منبع

Animation: Get rid of the ChannelDialog/Change PlaybackParams and control the speed by the AnimComposer, as it would happen that way in code as well

MeFisto94 5 سال پیش
والد
کامیت
307038ee6d

+ 6 - 42
jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/animation/JmeAnimClip.java

@@ -33,7 +33,6 @@ package com.jme3.gde.core.sceneexplorer.nodes.animation;
 
 import com.jme3.anim.AnimClip;
 import com.jme3.anim.AnimComposer;
-import com.jme3.animation.AnimChannel;
 import com.jme3.gde.core.icons.IconList;
 import com.jme3.gde.core.properties.AnimationProperty;
 import com.jme3.gde.core.scene.SceneApplication;
@@ -70,8 +69,6 @@ public class JmeAnimClip extends AbstractSceneExplorerNode {
     private Image icon;
     private JmeAnimComposer jmeControl;
     private boolean playing = false;
-    private float animSpeed = 1.0f;
-    private AnimChannel channel = null;
 
     public JmeAnimClip() {
     }
@@ -109,10 +106,8 @@ public class JmeAnimClip extends AbstractSceneExplorerNode {
     public void toggleIcon(boolean enabled) {
         if (!playing) {
             icon = IconList.animation.getImage();
-
         } else {
             icon = IconList.animationPlay.getImage();
-
         }
         fireIconChange();
     }
@@ -149,13 +144,12 @@ public class JmeAnimClip extends AbstractSceneExplorerNode {
     @Override
     public Action[] getActions(boolean context) {
         return new Action[]{Actions.alwaysEnabled(new PlayAction(), playing ? "Stop" : "Play", "", false),
-                    //Actions.alwaysEnabled(new PlayBackParamsAction(), "Playback parameters", "", false),
-                    SystemAction.get(RenameAction.class),
-                    SystemAction.get(DeleteAction.class),
-                    //Actions.alwaysEnabled(new EffectTrackWizardAction(jmeControl.getLookup().lookup(AnimComposer.class).getSpatial(), this), "Add Effect Track", "", false),
-                    //Actions.alwaysEnabled(new AudioTrackWizardAction(jmeControl.getLookup().lookup(AnimComposer.class).getSpatial(), this), "Add Audio Track", "", false),
-                    // @TODO: not working yet, Actions.alwaysEnabled(new ExtractAnimationAction(), "Extract sub-animation", "", true)
-                };
+            SystemAction.get(RenameAction.class),
+            SystemAction.get(DeleteAction.class),
+            //Actions.alwaysEnabled(new EffectTrackWizardAction(jmeControl.getLookup().lookup(AnimComposer.class).getSpatial(), this), "Add Effect Track", "", false),
+            //Actions.alwaysEnabled(new AudioTrackWizardAction(jmeControl.getLookup().lookup(AnimComposer.class).getSpatial(), this), "Add Audio Track", "", false),
+            // @TODO: not working yet, Actions.alwaysEnabled(new ExtractAnimationAction(), "Extract sub-animation", "", true)
+        };
     }
 
     @Override
@@ -236,36 +230,6 @@ public class JmeAnimClip extends AbstractSceneExplorerNode {
             }
         }
     }
-
-    /*class PlayBackParamsAction implements ActionListener {
-        ChannelDialog dialog = new ChannelDialog(null, false, JmeAnimClip.this);
-
-        @Override
-        public void actionPerformed(ActionEvent e) {
-            dialog.setLocationRelativeTo(null);
-            dialog.setVisible(true);
-
-        }
-    }*/
-
-    public float getAnimSpeed() {
-        return animSpeed;
-    }
-
-    public void setAnimSpeed(float speed) {
-        this.animSpeed = speed;
-        try {
-            SceneApplication.getApplication().enqueue(() -> {
-                final AnimComposer composer = jmeControl.getLookup().lookup(AnimComposer.class);
-                if (composer != null) {
-                    composer.setGlobalSpeed(animSpeed);
-                }
-                return null;
-            }).get();
-        } catch (InterruptedException | ExecutionException ex) {
-            Exceptions.printStackTrace(ex);
-        }
-    }
     
     @Override
     public boolean canRename() {

+ 25 - 4
jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/animation/JmeAnimComposer.java

@@ -33,16 +33,21 @@ package com.jme3.gde.core.sceneexplorer.nodes.animation;
 
 import com.jme3.anim.AnimComposer;
 import com.jme3.gde.core.icons.IconList;
+import com.jme3.gde.core.properties.AnimationProperty;
+import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeControl;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeTrackChildren;
 import com.jme3.gde.core.sceneexplorer.nodes.SceneExplorerNode;
 import com.jme3.gde.core.sceneexplorer.nodes.actions.ControlsPopup;
+import com.jme3.gde.core.util.PropertyUtils;
 import java.awt.Image;
+import java.util.concurrent.ExecutionException;
 import javax.swing.Action;
 import org.openide.actions.DeleteAction;
 import org.openide.loaders.DataObject;
 import org.openide.nodes.Node;
 import org.openide.nodes.Sheet;
+import org.openide.util.Exceptions;
 import org.openide.util.actions.SystemAction;
 
 /**
@@ -93,6 +98,7 @@ public class JmeAnimComposer extends JmeControl {
 
         if (animComposer != null) {
             //set.put(new AnimationProperty(animComposer));
+            set.put(makeProperty(this, JmeAnimComposer.class, "GlobalSpeed", "Global Animation Speed"));
             sheet.put(set);
         } // else: Empty Sheet
         
@@ -109,14 +115,29 @@ public class JmeAnimComposer extends JmeControl {
         }
         playingAnimation = anim;
     }
+    
+    public float getGlobalSpeed() {
+        return animComposer.getGlobalSpeed();
+    }
+
+    public void setGlobalSpeed(final float speed) {
+        try {
+            SceneApplication.getApplication().enqueue(() -> {
+                animComposer.setGlobalSpeed(speed);
+                return null;
+            }).get();
+        } catch (InterruptedException | ExecutionException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+    }
 
     @Override
     public Action[] getActions(boolean context) {
         return new Action[]{
-                    //new TrackVisibilityPopup(this),
-                    new ControlsPopup(this),
-                    SystemAction.get(DeleteAction.class)
-                };
+            //new TrackVisibilityPopup(this),
+            new ControlsPopup(this),
+            SystemAction.get(DeleteAction.class)
+        };
     }
 
     @Override