From 3a2d25ce3057ac36dc16aaa4b5a5239e231b7cc1 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Thu, 8 Nov 2012 18:36:19 +0000 Subject: [PATCH] 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 --- .../core/com/jme3/cinematic/Cinematic.java | 56 ++++++++++++++++++- .../src/core/com/jme3/cinematic/KeyFrame.java | 4 ++ .../src/core/com/jme3/cinematic/TimeLine.java | 2 + 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/engine/src/core/com/jme3/cinematic/Cinematic.java b/engine/src/core/com/jme3/cinematic/Cinematic.java index 16601b753..dd01bca19 100644 --- a/engine/src/core/com/jme3/cinematic/Cinematic.java +++ b/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(); diff --git a/engine/src/core/com/jme3/cinematic/KeyFrame.java b/engine/src/core/com/jme3/cinematic/KeyFrame.java index 9bf515e1a..a794e3cd0 100644 --- a/engine/src/core/com/jme3/cinematic/KeyFrame.java +++ b/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); diff --git a/engine/src/core/com/jme3/cinematic/TimeLine.java b/engine/src/core/com/jme3/cinematic/TimeLine.java index 973450190..e51c909dd 100644 --- a/engine/src/core/com/jme3/cinematic/TimeLine.java +++ b/engine/src/core/com/jme3/cinematic/TimeLine.java @@ -81,6 +81,8 @@ public class TimeLine extends HashMap implements Savable { } } } + + public void removeKeyFrame(float time) { removeKeyFrame(getKeyFrameIndexFromTime(time));