diff options
author | Joshua Leung <aligorith@gmail.com> | 2015-02-28 02:57:17 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2015-02-28 16:34:50 +0300 |
commit | 13a0dce51c949e09842876da1c4dc68c047d6ed0 (patch) | |
tree | 6457defc461d73311615b3d98965721dcc4dbe01 | |
parent | b16fbabd616944007e4730640dd55db5fa021afa (diff) |
Action Stashing: Don't allow an action to get stashed more than once
-rw-r--r-- | source/blender/blenkernel/BKE_nla.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/nla.c | 32 | ||||
-rw-r--r-- | source/blender/editors/space_action/action_edit.c | 5 |
3 files changed, 40 insertions, 3 deletions
diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h index d9f6182ce88..c3fc29e811f 100644 --- a/source/blender/blenkernel/BKE_nla.h +++ b/source/blender/blenkernel/BKE_nla.h @@ -105,9 +105,13 @@ void BKE_nla_validate_state(struct AnimData *adt); /* ............ */ -void BKE_nla_action_pushdown(struct AnimData *adt); +bool BKE_nla_action_is_stashed(struct AnimData *adt, struct bAction *act); bool BKE_nla_action_stash(struct AnimData *adt); +/* ............ */ + +void BKE_nla_action_pushdown(struct AnimData *adt); + bool BKE_nla_tweakmode_enter(struct AnimData *adt); void BKE_nla_tweakmode_exit(struct AnimData *adt); diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 9be413ddcde..4af1f4ca411 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -1525,17 +1525,45 @@ void BKE_nla_validate_state(AnimData *adt) /* Action Stashing -------------------------------------- */ +/* name of stashed tracks - the translation stuff is included here to save extra work */ +#define STASH_TRACK_NAME DATA_("[Action Stash]") + +/* Check if an action is "stashed" in the NLA already + * + * The criteria for this are: + * 1) The action in question lives in a "stash" track + * 2) We only check first-level strips. That is, we will not check inside meta strips. + */ +bool BKE_nla_action_is_stashed(AnimData *adt, bAction *act) +{ + NlaTrack *nlt; + NlaStrip *strip; + + for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { + if (strstr(nlt->name, STASH_TRACK_NAME)) { + for (strip = nlt->strips.first; strip; strip = strip->next) { + if (strip->act == act) + return true; + } + } + } + + return false; +} + /* "Stash" an action (i.e. store it as a track/layer in the NLA, but non-contributing) * to retain it in the file for future uses */ bool BKE_nla_action_stash(AnimData *adt) { - const char *STASH_TRACK_NAME = DATA_("[Action Stash]"); - NlaTrack *prev_track = NULL; NlaTrack *nlt; NlaStrip *strip; + /* do not add if it is already stashed */ + if (BKE_nla_action_is_stashed(adt, adt->action)) + return false; + /* create a new track, and add this immediately above the previous stashing track */ for (prev_track = adt->nla_tracks.last; prev_track; prev_track = prev_track->prev) { if (strstr(prev_track->name, STASH_TRACK_NAME)) { diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index c4ed44c91f5..ba06c7cf0e2 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -327,6 +327,11 @@ static int action_stash_exec(bContext *C, wmOperator *op) saction->action = NULL; actedit_change_action(C, new_action); } + else { + /* action has already been added - simply warn about this, and clear */ + BKE_report(op->reports, RPT_ERROR, "Action has already been stashed"); + actedit_change_action(C, NULL); + } } } |