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));