Forráskód Böngészése

One can now remove a cinematic event from a cinematic

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9976 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
rem..om 13 éve
szülő
commit
3a2d25ce30

+ 54 - 2
engine/src/core/com/jme3/cinematic/Cinematic.java

@@ -242,6 +242,15 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
         }
     }
 
+    /**
+     * Adds a cinematic event to this cinematic at the given timestamp. This
+     * operation returns a keyFrame
+     *
+     * @param timeStamp the time when the event will start after the begining of
+     * the cinematic
+     * @param cinematicEvent the cinematic event
+     * @return the keyFrame for that event.
+     */
     public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) {
         KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp);
         if (keyFrame == null) {
@@ -253,6 +262,49 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
         return keyFrame;
     }
 
+    /**
+     * removes the first occurence found of the given cinematicEvent.
+     *
+     * @param cinematicEvent the cinematicEvent to remove
+     * @return true if the element has been removed
+     */
+    public boolean removeCinematicEvent(CinematicEvent cinematicEvent) {
+        cinematicEvents.remove(cinematicEvent);
+        for (KeyFrame keyFrame : timeLine.values()) {
+            if (keyFrame.cinematicEvents.remove(cinematicEvent)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * removes the first occurence found of the given cinematicEvent for the given time stamp.
+     * @param timeStamp the timestamp when the cinematicEvent has been added
+     * @param cinematicEvent the cinematicEvent to remove
+     * @return true if the element has been removed
+     */
+    public boolean removeCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) {
+        KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp);
+        return removeCinematicEvent(keyFrame, cinematicEvent);
+    }
+    
+    /**
+     * removes the first occurence found of the given cinematicEvent for the given keyFrame
+     * @param keyFrame the keyFrame returned by the addCinematicEvent method.
+     * @param cinematicEvent the cinematicEvent to remove
+     * @return true if the element has been removed
+     */
+    public boolean removeCinematicEvent(KeyFrame keyFrame, CinematicEvent cinematicEvent) {
+        boolean ret = keyFrame.cinematicEvents.remove(cinematicEvent);
+        cinematicEvents.remove(cinematicEvent);
+        if (keyFrame.isEmpty()) {
+           timeLine.removeKeyFrame(keyFrame.getIndex());
+        }
+        return ret;
+    }
+    
+
     public void render(RenderManager rm) {
     }
 
@@ -263,7 +315,8 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
     }
 
     /**
-     * fits the duration of the cinamatic to the duration of all its child cinematic events
+     * fits the duration of the cinamatic to the duration of all its child
+     * cinematic events
      */
     public void fitDuration() {
         KeyFrame kf = timeLine.getKeyFrameAtTime(timeLine.getLastKeyFrameIndex());
@@ -308,7 +361,6 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
 
     public void activateCamera(final float timeStamp, final String cameraName) {
         addCinematicEvent(timeStamp, new AbstractCinematicEvent() {
-
             @Override
             public void play() {
                 super.play();

+ 4 - 0
engine/src/core/com/jme3/cinematic/KeyFrame.java

@@ -60,6 +60,10 @@ public class KeyFrame implements Savable {
         }
         return cinematicEvents;
     }
+    
+    public boolean isEmpty(){
+        return cinematicEvents.isEmpty();
+    }
 
     public void write(JmeExporter ex) throws IOException {
         OutputCapsule oc = ex.getCapsule(this);

+ 2 - 0
engine/src/core/com/jme3/cinematic/TimeLine.java

@@ -81,6 +81,8 @@ public class TimeLine extends HashMap<Integer, KeyFrame> implements Savable {
             }
         }
     }
+    
+    
 
     public void removeKeyFrame(float time) {
         removeKeyFrame(getKeyFrameIndexFromTime(time));