mirror of
https://github.com/Relintai/procedural_animations.git
synced 2024-11-08 20:22:10 +01:00
Removed multiple animation support per ProceduralAnimation. It will work exactly as the built in Animation. This way the built in animation player can be really easily adapted to work as a procedural animation player.
This commit is contained in:
parent
9f9c0f8940
commit
782020b698
@ -67,105 +67,36 @@ PoolVector<String> ProceduralAnimation::get_animation_keyframe_names() const {
|
||||
return names;
|
||||
}
|
||||
|
||||
//Animations
|
||||
PoolVector<int> ProceduralAnimation::get_animation_indices() const {
|
||||
PoolVector<int> idxr;
|
||||
idxr.resize(_animations.size());
|
||||
|
||||
int i = 0;
|
||||
for (Map<int, AnimationEntry *>::Element *E = _animations.front(); E; E = E->next()) {
|
||||
idxr.set(i, E->key());
|
||||
++i;
|
||||
}
|
||||
|
||||
return idxr;
|
||||
Vector2 ProceduralAnimation::get_start_node_position() const {
|
||||
return _start_node_position;
|
||||
}
|
||||
int ProceduralAnimation::add_animation() {
|
||||
int key = -1;
|
||||
for (Map<int, AnimationEntry *>::Element *E = _animations.front(); E; E = E->next()) {
|
||||
if (E->key() > key) {
|
||||
key = E->key();
|
||||
}
|
||||
}
|
||||
++key;
|
||||
|
||||
AnimationEntry *entry = memnew(AnimationEntry);
|
||||
|
||||
_animations[key] = entry;
|
||||
|
||||
return key;
|
||||
}
|
||||
void ProceduralAnimation::remove_animation(const int animation_index) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
|
||||
AnimationEntry *entry = _animations[animation_index];
|
||||
|
||||
_animations.erase(animation_index);
|
||||
|
||||
memdelete(entry);
|
||||
void ProceduralAnimation::set_start_node_position(const Vector2 &value) {
|
||||
_start_node_position = value;
|
||||
}
|
||||
|
||||
bool ProceduralAnimation::has_animation(const int animation_index) const {
|
||||
return _animations.has(animation_index);
|
||||
int ProceduralAnimation::get_start_frame_index() const {
|
||||
return _start_frame_index;
|
||||
}
|
||||
|
||||
String ProceduralAnimation::get_animation_name(const int animation_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), "");
|
||||
|
||||
return _animations[animation_index]->name;
|
||||
}
|
||||
void ProceduralAnimation::set_animation_name(const int animation_index, const String &value) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
|
||||
_animations[animation_index]->name = value;
|
||||
}
|
||||
|
||||
Vector2 ProceduralAnimation::get_animation_node_position(int animation_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), Vector2());
|
||||
|
||||
return _animations[animation_index]->position;
|
||||
}
|
||||
void ProceduralAnimation::set_animation_node_position(const int animation_index, const Vector2 &value) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
|
||||
_animations[animation_index]->position = value;
|
||||
}
|
||||
|
||||
int ProceduralAnimation::get_animation_start_frame_index(const int animation_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), 0);
|
||||
|
||||
return _animations[animation_index]->start_frame_index;
|
||||
}
|
||||
void ProceduralAnimation::set_animation_start_frame_index(const int animation_index, const int value) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
|
||||
_animations[animation_index]->start_frame_index = value;
|
||||
void ProceduralAnimation::set_start_frame_index(const int value) {
|
||||
_start_frame_index = value;
|
||||
}
|
||||
|
||||
//Keyframes
|
||||
PoolVector<int> ProceduralAnimation::get_keyframe_indices(const int animation_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), PoolVector<int>());
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
PoolVector<int> ProceduralAnimation::get_keyframe_indices() const {
|
||||
PoolVector<int> idxr;
|
||||
idxr.resize(ae->keyframes.size());
|
||||
idxr.resize(_keyframes.size());
|
||||
|
||||
int i = 0;
|
||||
for (Map<int, AnimationKeyFrame *>::Element *E = ae->keyframes.front(); E; E = E->next()) {
|
||||
for (Map<int, AnimationKeyFrame *>::Element *E = _keyframes.front(); E; E = E->next()) {
|
||||
idxr.set(i, E->key());
|
||||
++i;
|
||||
}
|
||||
|
||||
return idxr;
|
||||
}
|
||||
int ProceduralAnimation::add_keyframe(const int animation_index) {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), 0);
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
int ProceduralAnimation::add_keyframe() {
|
||||
int key = -1;
|
||||
for (Map<int, AnimationKeyFrame *>::Element *E = ae->keyframes.front(); E; E = E->next()) {
|
||||
for (Map<int, AnimationKeyFrame *>::Element *E = _keyframes.front(); E; E = E->next()) {
|
||||
if (E->key() > key) {
|
||||
key = E->key();
|
||||
}
|
||||
@ -174,126 +105,77 @@ int ProceduralAnimation::add_keyframe(const int animation_index) {
|
||||
|
||||
AnimationKeyFrame *entry = memnew(AnimationKeyFrame);
|
||||
|
||||
ae->keyframes[key] = entry;
|
||||
_keyframes[key] = entry;
|
||||
|
||||
return key;
|
||||
}
|
||||
void ProceduralAnimation::remove_keyframe(const int animation_index, const int keyframe_index) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
void ProceduralAnimation::remove_keyframe(const int keyframe_index) {
|
||||
ERR_FAIL_COND(!_keyframes.has(keyframe_index));
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
AnimationKeyFrame *entry = _keyframes[keyframe_index];
|
||||
|
||||
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
|
||||
|
||||
AnimationKeyFrame *entry = ae->keyframes[keyframe_index];
|
||||
|
||||
_animations.erase(keyframe_index);
|
||||
_keyframes.erase(keyframe_index);
|
||||
|
||||
memdelete(entry);
|
||||
}
|
||||
|
||||
bool ProceduralAnimation::has_keyframe(const int animation_index, const int keyframe_index) const {
|
||||
if (!_animations.has(animation_index))
|
||||
return false;
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
return ae->keyframes.has(keyframe_index);
|
||||
bool ProceduralAnimation::has_keyframe(const int keyframe_index) const {
|
||||
return _keyframes.has(keyframe_index);
|
||||
}
|
||||
|
||||
String ProceduralAnimation::get_keyframe_name(const int animation_index, const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), "");
|
||||
String ProceduralAnimation::get_keyframe_name(const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), "");
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), "");
|
||||
|
||||
return ae->keyframes[keyframe_index]->name;
|
||||
return _keyframes[keyframe_index]->name;
|
||||
}
|
||||
void ProceduralAnimation::set_keyframe_name(const int animation_index, const int keyframe_index, const String &value) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
void ProceduralAnimation::set_keyframe_name(const int keyframe_index, const String &value) {
|
||||
ERR_FAIL_COND(!_keyframes.has(keyframe_index));
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
|
||||
|
||||
ae->keyframes[keyframe_index]->name = value;
|
||||
_keyframes[keyframe_index]->name = value;
|
||||
}
|
||||
|
||||
int ProceduralAnimation::get_keyframe_animation_keyframe_index(int animation_index, const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), 0);
|
||||
int ProceduralAnimation::get_keyframe_animation_keyframe_index(const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), 0);
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), 0);
|
||||
|
||||
return ae->keyframes[keyframe_index]->animation_keyframe_index;
|
||||
return _keyframes[keyframe_index]->animation_keyframe_index;
|
||||
}
|
||||
void ProceduralAnimation::set_keyframe_animation_keyframe_index(int animation_index, const int keyframe_index, int value) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
void ProceduralAnimation::set_keyframe_animation_keyframe_index(const int keyframe_index, int value) {
|
||||
ERR_FAIL_COND(!_keyframes.has(keyframe_index));
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
|
||||
|
||||
ae->keyframes[keyframe_index]->animation_keyframe_index = value;
|
||||
_keyframes[keyframe_index]->animation_keyframe_index = value;
|
||||
}
|
||||
|
||||
int ProceduralAnimation::get_keyframe_next_keyframe_index(const int animation_index, const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), 0);
|
||||
int ProceduralAnimation::get_keyframe_next_keyframe_index(const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), 0);
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), 0);
|
||||
|
||||
return ae->keyframes[keyframe_index]->next_keyframe;
|
||||
return _keyframes[keyframe_index]->next_keyframe;
|
||||
}
|
||||
void ProceduralAnimation::set_keyframe_next_keyframe_index(const int animation_index, const int keyframe_index, const int value) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
void ProceduralAnimation::set_keyframe_next_keyframe_index(const int keyframe_index, const int value) {
|
||||
ERR_FAIL_COND(!_keyframes.has(keyframe_index));
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
|
||||
|
||||
ae->keyframes[keyframe_index]->next_keyframe = value;
|
||||
_keyframes[keyframe_index]->next_keyframe = value;
|
||||
}
|
||||
|
||||
Ref<Curve> ProceduralAnimation::get_keyframe_in_curve(const int animation_index, const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), Ref<Curve>());
|
||||
Ref<Curve> ProceduralAnimation::get_keyframe_in_curve(const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), Ref<Curve>());
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), Ref<Curve>());
|
||||
|
||||
return ae->keyframes[keyframe_index]->in_curve;
|
||||
return _keyframes[keyframe_index]->in_curve;
|
||||
}
|
||||
void ProceduralAnimation::set_keyframe_in_curve(const int animation_index, const int keyframe_index, const Ref<Curve> &value) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
void ProceduralAnimation::set_keyframe_in_curve(const int keyframe_index, const Ref<Curve> &value) {
|
||||
ERR_FAIL_COND(!_keyframes.has(keyframe_index));
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
|
||||
|
||||
ae->keyframes[keyframe_index]->in_curve = value;
|
||||
_keyframes[keyframe_index]->in_curve = value;
|
||||
}
|
||||
|
||||
Vector2 ProceduralAnimation::get_keyframe_node_position(int animation_index, const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_animations.has(animation_index), Vector2());
|
||||
Vector2 ProceduralAnimation::get_keyframe_node_position(const int keyframe_index) const {
|
||||
ERR_FAIL_COND_V(!_keyframes.has(keyframe_index), Vector2());
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), Vector2());
|
||||
|
||||
return ae->keyframes[keyframe_index]->position;
|
||||
return _keyframes[keyframe_index]->position;
|
||||
}
|
||||
void ProceduralAnimation::set_keyframe_node_position(const int animation_index, const int keyframe_index, const Vector2 &value) {
|
||||
ERR_FAIL_COND(!_animations.has(animation_index));
|
||||
void ProceduralAnimation::set_keyframe_node_position(const int keyframe_index, const Vector2 &value) {
|
||||
ERR_FAIL_COND(!_keyframes.has(keyframe_index));
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
|
||||
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
|
||||
|
||||
ae->keyframes[keyframe_index]->position = value;
|
||||
_keyframes[keyframe_index]->position = value;
|
||||
}
|
||||
|
||||
void ProceduralAnimation::initialize() {
|
||||
@ -307,15 +189,11 @@ void ProceduralAnimation::initialize() {
|
||||
|
||||
_animation_data.clear();
|
||||
|
||||
for (Map<int, AnimationEntry *>::Element *A = _animations.front(); A; A = A->next()) {
|
||||
AnimationEntry *anim_entry = A->get();
|
||||
for (Map<int, AnimationKeyFrame *>::Element *K = _keyframes.front(); K; K = K->next()) {
|
||||
int keyframe_index = K->get()->animation_keyframe_index;
|
||||
|
||||
for (Map<int, AnimationKeyFrame *>::Element *K = anim_entry->keyframes.front(); K; K = K->next()) {
|
||||
int keyframe_index = K->get()->animation_keyframe_index;
|
||||
|
||||
if (!_animation_data.has(keyframe_index))
|
||||
load_keyframe_data(keyframe_index);
|
||||
}
|
||||
if (!_animation_data.has(keyframe_index))
|
||||
load_keyframe_data(keyframe_index);
|
||||
}
|
||||
}
|
||||
|
||||
@ -397,12 +275,11 @@ void ProceduralAnimation::load_keyframe_data(int keyframe_index) {
|
||||
ProceduralAnimation::ProceduralAnimation() {
|
||||
_initialized = false;
|
||||
_animation_fps = 15;
|
||||
_start_frame_index = -1;
|
||||
}
|
||||
|
||||
ProceduralAnimation::~ProceduralAnimation() {
|
||||
Map<int, AnimationEntry *> animations;
|
||||
|
||||
for (Map<int, AnimationEntry *>::Element *E = _animations.front(); E; E = E->next())
|
||||
for (Map<int, AnimationKeyFrame *>::Element *E = _keyframes.front(); E; E = E->next())
|
||||
memdelete(E->get());
|
||||
|
||||
for (Map<int, Vector<AnimationKey> *>::Element *E = _animation_data.front(); E; E = E->next()) {
|
||||
@ -412,7 +289,7 @@ ProceduralAnimation::~ProceduralAnimation() {
|
||||
}
|
||||
|
||||
_animation_data.clear();
|
||||
_animations.clear();
|
||||
_keyframes.clear();
|
||||
|
||||
_animation.unref();
|
||||
}
|
||||
@ -760,65 +637,46 @@ Variant ProceduralAnimation::value_track_interpolate(int p_track, float p_time)
|
||||
bool ProceduralAnimation::_set(const StringName &p_name, const Variant &p_value) {
|
||||
String name = p_name;
|
||||
|
||||
if (name.begins_with("animation/")) {
|
||||
int animation_index = name.get_slicec('/', 1).to_int();
|
||||
String anim_prop_name = name.get_slicec('/', 2);
|
||||
if (name == "start_node_position") {
|
||||
_start_node_position = p_value;
|
||||
|
||||
if (!_animations.has(animation_index)) {
|
||||
AnimationEntry *ae = memnew(AnimationEntry);
|
||||
return true;
|
||||
} else if (name == "start_frame_index") {
|
||||
_start_frame_index = p_value;
|
||||
|
||||
_animations[animation_index] = ae;
|
||||
return true;
|
||||
} else if (name == "keyframe") {
|
||||
int keyframe_index = name.get_slicec('/', 1).to_int();
|
||||
String keyframe_name = name.get_slicec('/', 2);
|
||||
|
||||
if (!_keyframes.has(keyframe_index)) {
|
||||
AnimationKeyFrame *keyframe = memnew(AnimationKeyFrame);
|
||||
|
||||
_keyframes[keyframe_index] = keyframe;
|
||||
}
|
||||
|
||||
AnimationEntry *ae = _animations[animation_index];
|
||||
AnimationKeyFrame *keyframe = _keyframes[keyframe_index];
|
||||
|
||||
if (anim_prop_name == "name") {
|
||||
ae->name = p_value;
|
||||
if (keyframe_name == "name") {
|
||||
keyframe->name = p_value;
|
||||
|
||||
return true;
|
||||
} else if (anim_prop_name == "position") {
|
||||
ae->position = p_value;
|
||||
} else if (keyframe_name == "animation_keyframe_index") {
|
||||
keyframe->animation_keyframe_index = p_value;
|
||||
|
||||
return true;
|
||||
} else if (anim_prop_name == "start_frame_index") {
|
||||
ae->start_frame_index = p_value;
|
||||
} else if (keyframe_name == "next_keyframe") {
|
||||
keyframe->next_keyframe = p_value;
|
||||
|
||||
return true;
|
||||
} else if (anim_prop_name == "keyframe") {
|
||||
int keyframe_index = name.get_slicec('/', 5).to_int();
|
||||
String keyframe_name = name.get_slicec('/', 6);
|
||||
} else if (keyframe_name == "in_curve") {
|
||||
keyframe->in_curve = p_value;
|
||||
|
||||
if (!ae->keyframes.has(keyframe_index)) {
|
||||
AnimationKeyFrame *keyframe = memnew(AnimationKeyFrame);
|
||||
return true;
|
||||
} else if (keyframe_name == "position") {
|
||||
keyframe->position = p_value;
|
||||
|
||||
ae->keyframes[keyframe_index] = keyframe;
|
||||
}
|
||||
|
||||
AnimationKeyFrame *keyframe = ae->keyframes[keyframe_index];
|
||||
|
||||
if (keyframe_name == "name") {
|
||||
keyframe->name = p_value;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_name == "animation_keyframe_index") {
|
||||
keyframe->animation_keyframe_index = p_value;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_name == "next_keyframe") {
|
||||
keyframe->next_keyframe = p_value;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_name == "in_curve") {
|
||||
keyframe->in_curve = p_value;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_name == "position") {
|
||||
keyframe->position = p_value;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -832,53 +690,40 @@ bool ProceduralAnimation::_set(const StringName &p_name, const Variant &p_value)
|
||||
bool ProceduralAnimation::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
String name = p_name;
|
||||
|
||||
if (name.begins_with("animation/")) {
|
||||
int animation_index = name.get_slicec('/', 1).to_int();
|
||||
String anim_prop_name = name.get_slicec('/', 2);
|
||||
if (name == "start_node_position") {
|
||||
r_ret = _start_node_position;
|
||||
|
||||
AnimationEntry *anim = _animations[animation_index];
|
||||
return true;
|
||||
} else if (name == "start_frame_index") {
|
||||
r_ret = _start_frame_index;
|
||||
|
||||
if (anim_prop_name == "name") {
|
||||
r_ret = anim->name;
|
||||
return true;
|
||||
} else if (name == "keyframe") {
|
||||
int keyframe_index = name.get_slicec('/', 1).to_int();
|
||||
String keyframe_prop_name = name.get_slicec('/', 2);
|
||||
|
||||
AnimationKeyFrame *keyframe = _keyframes[keyframe_index];
|
||||
|
||||
if (keyframe_prop_name == "name") {
|
||||
r_ret = keyframe->name;
|
||||
|
||||
return true;
|
||||
} else if (anim_prop_name == "position") {
|
||||
r_ret = anim->position;
|
||||
} else if (keyframe_prop_name == "animation_keyframe_index") {
|
||||
r_ret = keyframe->animation_keyframe_index;
|
||||
|
||||
return true;
|
||||
} else if (anim_prop_name == "start_frame_index") {
|
||||
r_ret = anim->start_frame_index;
|
||||
} else if (keyframe_prop_name == "next_keyframe") {
|
||||
r_ret = keyframe->next_keyframe;
|
||||
|
||||
return true;
|
||||
} else if (anim_prop_name == "keyframe") {
|
||||
int keyframe_index = name.get_slicec('/', 5).to_int();
|
||||
String keyframe_prop_name = name.get_slicec('/', 6);
|
||||
} else if (keyframe_prop_name == "in_curve") {
|
||||
r_ret = keyframe->in_curve;
|
||||
|
||||
AnimationKeyFrame *keyframe = anim->keyframes[keyframe_index];
|
||||
return true;
|
||||
} else if (keyframe_prop_name == "position") {
|
||||
r_ret = keyframe->position;
|
||||
|
||||
if (keyframe_prop_name == "name") {
|
||||
r_ret = keyframe->name;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_prop_name == "animation_keyframe_index") {
|
||||
r_ret = keyframe->animation_keyframe_index;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_prop_name == "next_keyframe") {
|
||||
r_ret = keyframe->next_keyframe;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_prop_name == "in_curve") {
|
||||
r_ret = keyframe->in_curve;
|
||||
|
||||
return true;
|
||||
} else if (keyframe_prop_name == "position") {
|
||||
r_ret = keyframe->position;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -893,20 +738,15 @@ void ProceduralAnimation::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
//int property_usange = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL;
|
||||
int property_usange = PROPERTY_USAGE_DEFAULT;
|
||||
|
||||
for (Map<int, AnimationEntry *>::Element *A = _animations.front(); A; A = A->next()) {
|
||||
AnimationEntry *animation = A->get();
|
||||
p_list->push_back(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "start_frame_index", PROPERTY_HINT_NONE, "", property_usange));
|
||||
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, "animation/" + itos(A->key()) + "/name", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::VECTOR2, "animation/" + itos(A->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "animation/" + itos(A->key()) + "/start_frame_index", PROPERTY_HINT_NONE, "", property_usange));
|
||||
|
||||
for (Map<int, AnimationKeyFrame *>::Element *K = animation->keyframes.front(); K; K = K->next()) {
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, "animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/name", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/animation_keyframe_index", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/next_keyframe", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/in_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::VECTOR2, "animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange));
|
||||
}
|
||||
for (Map<int, AnimationKeyFrame *>::Element *K = _keyframes.front(); K; K = K->next()) {
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, "keyframe/" + itos(K->key()) + "/name", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "keyframe/" + itos(K->key()) + "/animation_keyframe_index", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, "keyframe/" + itos(K->key()) + "/next_keyframe", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "keyframe/" + itos(K->key()) + "/in_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::VECTOR2, "keyframe/" + itos(K->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange));
|
||||
}
|
||||
}
|
||||
|
||||
@ -924,41 +764,32 @@ void ProceduralAnimation::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("remove_animation_keyframe_name", "keyframe_index"), &ProceduralAnimation::remove_animation_keyframe_name);
|
||||
ClassDB::bind_method(D_METHOD("get_animation_keyframe_names"), &ProceduralAnimation::get_animation_keyframe_names);
|
||||
|
||||
//Animations
|
||||
ClassDB::bind_method(D_METHOD("get_animation_indices"), &ProceduralAnimation::get_animation_indices);
|
||||
ClassDB::bind_method(D_METHOD("add_animation"), &ProceduralAnimation::add_animation);
|
||||
ClassDB::bind_method(D_METHOD("remove_animation", "animation_index"), &ProceduralAnimation::remove_animation);
|
||||
ClassDB::bind_method(D_METHOD("has_animation", "animation_index"), &ProceduralAnimation::has_animation);
|
||||
ClassDB::bind_method(D_METHOD("get_start_node_position"), &ProceduralAnimation::get_start_node_position);
|
||||
ClassDB::bind_method(D_METHOD("set_start_node_position", "value"), &ProceduralAnimation::set_start_node_position);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_animation_name", "animation_index"), &ProceduralAnimation::get_animation_name);
|
||||
ClassDB::bind_method(D_METHOD("set_animation_name", "animation_index", "value"), &ProceduralAnimation::set_animation_name);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_animation_node_position", "animation_index"), &ProceduralAnimation::get_animation_node_position);
|
||||
ClassDB::bind_method(D_METHOD("set_animation_node_position", "animation_index", "value"), &ProceduralAnimation::set_animation_node_position);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_animation_start_frame_index", "animation_index"), &ProceduralAnimation::get_animation_start_frame_index);
|
||||
ClassDB::bind_method(D_METHOD("set_animation_start_frame_index", "animation_index", "value"), &ProceduralAnimation::set_animation_start_frame_index);
|
||||
ClassDB::bind_method(D_METHOD("get_start_frame_index"), &ProceduralAnimation::get_start_frame_index);
|
||||
ClassDB::bind_method(D_METHOD("set_start_frame_index", "value"), &ProceduralAnimation::set_start_frame_index);
|
||||
|
||||
//Keyframes
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_indices", "animation_index"), &ProceduralAnimation::get_keyframe_indices);
|
||||
ClassDB::bind_method(D_METHOD("add_keyframe", "animation_index"), &ProceduralAnimation::add_keyframe);
|
||||
ClassDB::bind_method(D_METHOD("remove_keyframe", "animation_index", "keyframe_index"), &ProceduralAnimation::remove_keyframe);
|
||||
ClassDB::bind_method(D_METHOD("has_keyframe", "animation_index", "keyframe_index"), &ProceduralAnimation::has_keyframe);
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_indices"), &ProceduralAnimation::get_keyframe_indices);
|
||||
ClassDB::bind_method(D_METHOD("add_keyframe"), &ProceduralAnimation::add_keyframe);
|
||||
ClassDB::bind_method(D_METHOD("remove_keyframe", "keyframe_index"), &ProceduralAnimation::remove_keyframe);
|
||||
ClassDB::bind_method(D_METHOD("has_keyframe", "keyframe_index"), &ProceduralAnimation::has_keyframe);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_name", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_name);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_name", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_name);
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_name", "keyframe_index"), &ProceduralAnimation::get_keyframe_name);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_name", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_name);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_animation_keyframe_index", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_animation_keyframe_index);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_animation_keyframe_index", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_animation_keyframe_index);
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_animation_keyframe_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_animation_keyframe_index);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_animation_keyframe_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_animation_keyframe_index);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_next_keyframe_index", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_next_keyframe_index);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_next_keyframe_index", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_next_keyframe_index);
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_next_keyframe_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_next_keyframe_index);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_next_keyframe_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_next_keyframe_index);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_in_curve", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_in_curve);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_in_curve", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_in_curve);
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_in_curve", "keyframe_index"), &ProceduralAnimation::get_keyframe_in_curve);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_in_curve", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_in_curve);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_node_position", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_node_position);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_node_position", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_node_position);
|
||||
ClassDB::bind_method(D_METHOD("get_keyframe_node_position", "keyframe_index"), &ProceduralAnimation::get_keyframe_node_position);
|
||||
ClassDB::bind_method(D_METHOD("set_keyframe_node_position", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_node_position);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("initialize"), &ProceduralAnimation::initialize);
|
||||
ClassDB::bind_method(D_METHOD("load_keyframe_data", "keyframe_index"), &ProceduralAnimation::load_keyframe_data);
|
||||
|
@ -131,24 +131,6 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
struct AnimationEntry {
|
||||
String name;
|
||||
Vector2 position;
|
||||
int start_frame_index;
|
||||
Map<int, AnimationKeyFrame *> keyframes;
|
||||
|
||||
AnimationEntry() {
|
||||
start_frame_index = -1;
|
||||
}
|
||||
|
||||
~AnimationEntry() {
|
||||
for (Map<int, AnimationKeyFrame *>::Element *E = keyframes.front(); E; E = E->next())
|
||||
memdelete(E->get());
|
||||
|
||||
keyframes.clear();
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
Ref<Animation> get_animation() const;
|
||||
void set_animation(const Ref<Animation> &value);
|
||||
@ -161,41 +143,32 @@ public:
|
||||
void remove_animation_keyframe_name(int keyframe_index);
|
||||
PoolVector<String> get_animation_keyframe_names() const;
|
||||
|
||||
//Animations
|
||||
PoolVector<int> get_animation_indices() const;
|
||||
int add_animation();
|
||||
void remove_animation(const int animation_index);
|
||||
bool has_animation(const int animation_index) const;
|
||||
Vector2 get_start_node_position() const;
|
||||
void set_start_node_position(const Vector2 &value);
|
||||
|
||||
String get_animation_name(const int animation_index) const;
|
||||
void set_animation_name(const int animation_index, const String &value);
|
||||
|
||||
Vector2 get_animation_node_position(int animation_index) const;
|
||||
void set_animation_node_position(const int animation_index, const Vector2 &value);
|
||||
|
||||
int get_animation_start_frame_index(const int animation_index) const;
|
||||
void set_animation_start_frame_index(const int animation_index, const int value);
|
||||
int get_start_frame_index() const;
|
||||
void set_start_frame_index(const int value);
|
||||
|
||||
//Keyframes
|
||||
PoolVector<int> get_keyframe_indices(const int animation_index) const;
|
||||
int add_keyframe(const int animation_index);
|
||||
void remove_keyframe(const int animation_index, const int keyframe_index);
|
||||
bool has_keyframe(const int animation_index, const int keyframe_index) const;
|
||||
PoolVector<int> get_keyframe_indices() const;
|
||||
int add_keyframe();
|
||||
void remove_keyframe(const int keyframe_index);
|
||||
bool has_keyframe(const int keyframe_index) const;
|
||||
|
||||
String get_keyframe_name(const int animation_index, const int keyframe_index) const;
|
||||
void set_keyframe_name(const int animation_index, const int keyframe_index, const String &value);
|
||||
String get_keyframe_name(const int keyframe_index) const;
|
||||
void set_keyframe_name(const int keyframe_index, const String &value);
|
||||
|
||||
int get_keyframe_animation_keyframe_index(int animation_index, const int keyframe_index) const;
|
||||
void set_keyframe_animation_keyframe_index(int animation_index, const int keyframe_index, int value);
|
||||
int get_keyframe_animation_keyframe_index(const int keyframe_index) const;
|
||||
void set_keyframe_animation_keyframe_index(const int keyframe_index, int value);
|
||||
|
||||
int get_keyframe_next_keyframe_index(const int animation_index, const int keyframe_index) const;
|
||||
void set_keyframe_next_keyframe_index(const int animation_index, const int keyframe_index, const int value);
|
||||
int get_keyframe_next_keyframe_index(const int keyframe_index) const;
|
||||
void set_keyframe_next_keyframe_index(const int keyframe_index, const int value);
|
||||
|
||||
Ref<Curve> get_keyframe_in_curve(const int animation_index, const int keyframe_index) const;
|
||||
void set_keyframe_in_curve(const int animation_index, const int keyframe_index, const Ref<Curve> &value);
|
||||
Ref<Curve> get_keyframe_in_curve(const int keyframe_index) const;
|
||||
void set_keyframe_in_curve(const int keyframe_index, const Ref<Curve> &value);
|
||||
|
||||
Vector2 get_keyframe_node_position(int animation_index, const int keyframe_index) const;
|
||||
void set_keyframe_node_position(const int animation_index, const int keyframe_index, const Vector2 &value);
|
||||
Vector2 get_keyframe_node_position(const int keyframe_index) const;
|
||||
void set_keyframe_node_position(const int keyframe_index, const Vector2 &value);
|
||||
|
||||
void initialize();
|
||||
void load_keyframe_data(int keyframe_index);
|
||||
@ -233,7 +206,10 @@ private:
|
||||
String _editor_add_category_name;
|
||||
String _add_editor_category_animation_name;
|
||||
|
||||
Map<int, AnimationEntry *> _animations;
|
||||
Vector2 _start_node_position;
|
||||
int _start_frame_index;
|
||||
Map<int, AnimationKeyFrame *> _keyframes;
|
||||
|
||||
Map<int, Vector<AnimationKey> *> _animation_data;
|
||||
|
||||
Ref<Animation> _animation;
|
||||
|
@ -27,8 +27,6 @@ SOFTWARE.
|
||||
void ProceduralAnimationEditor::edit(const Ref<ProceduralAnimation> &animation) {
|
||||
_animation = animation;
|
||||
|
||||
_selected_animation = -1;
|
||||
|
||||
_stop->hide();
|
||||
_play->hide();
|
||||
_play_from->hide();
|
||||
@ -36,24 +34,20 @@ void ProceduralAnimationEditor::edit(const Ref<ProceduralAnimation> &animation)
|
||||
_play_bw_from->hide();
|
||||
|
||||
clear_keyframe_nodes();
|
||||
refresh_option_buttons();
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::edit(ProceduralAnimationPlayer *player) {
|
||||
_animation_player = player;
|
||||
|
||||
_selected_animation = -1;
|
||||
|
||||
_stop->show();
|
||||
_play->show();
|
||||
_play_from->show();
|
||||
_play_bw->show();
|
||||
_play_bw_from->show();
|
||||
|
||||
_animation = player->get_animation();
|
||||
//_animation = player->get_animation();
|
||||
|
||||
clear_keyframe_nodes();
|
||||
refresh_option_buttons();
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::load_selected_animation() {
|
||||
@ -61,14 +55,11 @@ void ProceduralAnimationEditor::load_selected_animation() {
|
||||
|
||||
ERR_FAIL_COND(!_animation.is_valid());
|
||||
|
||||
if (_selected_animation == -1)
|
||||
return;
|
||||
|
||||
_start_node->set_offset(_animation->get_animation_node_position(_selected_animation));
|
||||
_start_node->set_offset(_animation->get_start_node_position());
|
||||
|
||||
const PoolVector<String> &animation_names = _animation->get_animation_keyframe_names();
|
||||
|
||||
PoolVector<int> kfind = _animation->get_keyframe_indices(_selected_animation);
|
||||
PoolVector<int> kfind = _animation->get_keyframe_indices();
|
||||
|
||||
for (int i = 0; i < kfind.size(); ++i) {
|
||||
int id = kfind[i];
|
||||
@ -80,24 +71,24 @@ void ProceduralAnimationEditor::load_selected_animation() {
|
||||
//gn->set_animation_keyframe_names(animation_names);
|
||||
|
||||
gn->set_id(id);
|
||||
gn->set_offset(_animation->get_keyframe_node_position(_selected_animation, id));
|
||||
gn->set_keyframe_name(_animation->get_keyframe_name(_selected_animation, id));
|
||||
gn->set_next_keyframe(_animation->get_keyframe_next_keyframe_index(_selected_animation, id));
|
||||
gn->set_in_curve(_animation->get_keyframe_in_curve(_selected_animation, id));
|
||||
gn->set_animation_keyframe_index(_animation->get_keyframe_animation_keyframe_index(_selected_animation, id));
|
||||
gn->set_offset(_animation->get_keyframe_node_position(id));
|
||||
gn->set_keyframe_name(_animation->get_keyframe_name(id));
|
||||
gn->set_next_keyframe(_animation->get_keyframe_next_keyframe_index(id));
|
||||
gn->set_in_curve(_animation->get_keyframe_in_curve(id));
|
||||
gn->set_animation_keyframe_index(_animation->get_keyframe_animation_keyframe_index(id));
|
||||
gn->connect("graphnode_changed", this, "on_keyframe_node_changed");
|
||||
}
|
||||
|
||||
for (int i = 0; i < kfind.size(); ++i) {
|
||||
int id = kfind[i];
|
||||
|
||||
int ni = _animation->get_keyframe_next_keyframe_index(_selected_animation, id);
|
||||
int ni = _animation->get_keyframe_next_keyframe_index(id);
|
||||
|
||||
if (ni != -1)
|
||||
_graph_edit->connect_node(String::num(id), 0, String::num(ni), 0);
|
||||
}
|
||||
|
||||
int st = _animation->get_animation_start_frame_index(_selected_animation);
|
||||
int st = _animation->get_start_frame_index();
|
||||
|
||||
if (st != -1)
|
||||
_graph_edit->connect_node("Start", 0, String::num(st), 0);
|
||||
@ -120,128 +111,24 @@ void ProceduralAnimationEditor::clear_keyframe_nodes() {
|
||||
}
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::refresh_option_buttons() {
|
||||
_animation_option_button->clear();
|
||||
|
||||
if (!_animation.is_valid())
|
||||
return;
|
||||
|
||||
PoolVector<int> aind = _animation->get_animation_indices();
|
||||
|
||||
for (int i = 0; i < aind.size(); ++i) {
|
||||
int indx = aind[i];
|
||||
|
||||
if (_selected_animation == -1)
|
||||
_selected_animation = indx;
|
||||
|
||||
_animation_option_button->add_item(_animation->get_animation_name(indx), indx);
|
||||
}
|
||||
|
||||
if (_selected_animation == -1)
|
||||
return;
|
||||
|
||||
_animation_option_button->select(_selected_animation);
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::on_animation_option_button_pressed(int indx) {
|
||||
if (_selected_animation == indx)
|
||||
return;
|
||||
|
||||
_selected_animation = indx;
|
||||
|
||||
load_selected_animation();
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::refresh_animation_option_button() {
|
||||
_animation_option_button->clear();
|
||||
_selected_animation = -1;
|
||||
|
||||
if (!_animation.is_valid())
|
||||
return;
|
||||
|
||||
PoolVector<int> aind = _animation->get_animation_indices();
|
||||
|
||||
for (int i = 0; i < aind.size(); ++i) {
|
||||
int indx = aind[i];
|
||||
|
||||
if (_selected_animation == -1)
|
||||
_selected_animation = indx;
|
||||
|
||||
_animation_option_button->add_item(_animation->get_animation_name(indx), indx);
|
||||
}
|
||||
|
||||
if (_selected_animation == -1)
|
||||
return;
|
||||
|
||||
_animation_option_button->select(_selected_animation);
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::on_keyframe_node_changed(Node *node) {
|
||||
ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(node);
|
||||
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(gn));
|
||||
ERR_FAIL_COND(!_animation.is_valid());
|
||||
ERR_FAIL_COND(_selected_animation == -1);
|
||||
|
||||
int id = gn->get_id();
|
||||
|
||||
_animation->set_keyframe_animation_keyframe_index(_selected_animation, id, gn->get_animation_keyframe_index());
|
||||
_animation->set_keyframe_in_curve(_selected_animation, id, gn->get_in_curve());
|
||||
_animation->set_keyframe_name(_selected_animation, id, gn->get_keyframe_name());
|
||||
_animation->set_keyframe_next_keyframe_index(_selected_animation, id, gn->get_next_keyframe());
|
||||
_animation->set_keyframe_node_position(_selected_animation, id, gn->get_offset());
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::animation_tool_button_id_pressed(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
show_name_popup(NAME_POPUP_ADD_ANIMATION_NAME);
|
||||
break;
|
||||
case 1:
|
||||
show_name_popup(NAME_POPUP_EDIT_ANIMATION_NAME);
|
||||
break;
|
||||
case 2:
|
||||
_delete_popup_action = DELETE_POPUP_ANIMATION;
|
||||
_delete_popuop->popup_centered();
|
||||
break;
|
||||
}
|
||||
}
|
||||
void ProceduralAnimationEditor::show_name_popup(NamePopupActions action) {
|
||||
_name_popup_action = action;
|
||||
_name_popup_line_edit->set_text("");
|
||||
_name_popuop->popup_centered();
|
||||
_name_popup_line_edit->grab_focus();
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::on_name_popup_confirmed() {
|
||||
switch (_name_popup_action) {
|
||||
case NAME_POPUP_ADD_ANIMATION_NAME:
|
||||
_selected_animation = _animation->add_animation();
|
||||
_animation->set_animation_name(_selected_animation, _name_popup_line_edit->get_text());
|
||||
break;
|
||||
case NAME_POPUP_EDIT_ANIMATION_NAME:
|
||||
ERR_FAIL_COND(_selected_animation == -1);
|
||||
|
||||
_animation->set_animation_name(_selected_animation, _name_popup_line_edit->get_text());
|
||||
break;
|
||||
}
|
||||
|
||||
refresh_option_buttons();
|
||||
_animation->set_keyframe_animation_keyframe_index(id, gn->get_animation_keyframe_index());
|
||||
_animation->set_keyframe_in_curve(id, gn->get_in_curve());
|
||||
_animation->set_keyframe_name(id, gn->get_keyframe_name());
|
||||
_animation->set_keyframe_next_keyframe_index(id, gn->get_next_keyframe());
|
||||
_animation->set_keyframe_node_position(id, gn->get_offset());
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::on_delete_popup_confirmed() {
|
||||
switch (_delete_popup_action) {
|
||||
case DELETE_POPUP_ANIMATION:
|
||||
ERR_FAIL_COND(_selected_animation == -1);
|
||||
|
||||
_animation->remove_animation(_selected_animation);
|
||||
|
||||
_selected_animation = -1;
|
||||
|
||||
refresh_animation_option_button();
|
||||
break;
|
||||
case DELETE_POPUP_KEYFRAME:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -252,24 +139,24 @@ void ProceduralAnimationEditor::on_connection_request(const String &from, const
|
||||
ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(f);
|
||||
|
||||
if (gn != NULL) {
|
||||
int ni = _animation->get_keyframe_next_keyframe_index(_selected_animation, gn->get_id());
|
||||
int ni = _animation->get_keyframe_next_keyframe_index(gn->get_id());
|
||||
|
||||
if (ni != -1) {
|
||||
_graph_edit->disconnect_node(from, from_slot, String::num(ni), 0);
|
||||
}
|
||||
|
||||
_animation->set_keyframe_next_keyframe_index(_selected_animation, gn->get_id(), to.to_int());
|
||||
_animation->set_keyframe_next_keyframe_index(gn->get_id(), to.to_int());
|
||||
} else {
|
||||
GraphNode *g = Object::cast_to<GraphNode>(f);
|
||||
|
||||
if (g != NULL) {
|
||||
int st = _animation->get_animation_start_frame_index(_selected_animation);
|
||||
int st = _animation->get_start_frame_index();
|
||||
|
||||
if (st != -1) {
|
||||
_graph_edit->disconnect_node("Start", 0, String::num(st), 0);
|
||||
}
|
||||
|
||||
_animation->set_animation_start_frame_index(_selected_animation, to.to_int());
|
||||
_animation->set_start_frame_index(to.to_int());
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,12 +168,12 @@ void ProceduralAnimationEditor::on_disconnection_request(const String &from, con
|
||||
ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(f);
|
||||
|
||||
if (gn != NULL) {
|
||||
_animation->set_keyframe_next_keyframe_index(_selected_animation, gn->get_id(), -1);
|
||||
_animation->set_keyframe_next_keyframe_index(gn->get_id(), -1);
|
||||
} else {
|
||||
GraphNode *g = Object::cast_to<GraphNode>(f);
|
||||
|
||||
if (g != NULL) {
|
||||
_animation->set_animation_start_frame_index(_selected_animation, -1);
|
||||
_animation->set_start_frame_index(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,10 +181,7 @@ void ProceduralAnimationEditor::on_disconnection_request(const String &from, con
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::add_frame_button_pressed() {
|
||||
if (_selected_animation == -1)
|
||||
return;
|
||||
|
||||
int id = _animation->add_keyframe(_selected_animation);
|
||||
int id = _animation->add_keyframe();
|
||||
|
||||
ProceduralAnimationEditorGraphNode *gn = memnew(ProceduralAnimationEditorGraphNode);
|
||||
gn->set_id(id);
|
||||
@ -321,15 +205,10 @@ void ProceduralAnimationEditor::_notification(int p_what) {
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("animation_tool_button_id_pressed", "id"), &ProceduralAnimationEditor::animation_tool_button_id_pressed);
|
||||
ClassDB::bind_method(D_METHOD("on_name_popup_confirmed"), &ProceduralAnimationEditor::on_name_popup_confirmed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("on_delete_popup_confirmed"), &ProceduralAnimationEditor::on_delete_popup_confirmed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_frame_button_pressed"), &ProceduralAnimationEditor::add_frame_button_pressed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("on_animation_option_button_pressed", "index"), &ProceduralAnimationEditor::on_animation_option_button_pressed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("on_keyframe_node_changed", "node"), &ProceduralAnimationEditor::on_keyframe_node_changed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("on_connection_request", "from", "from_slot", "to", "to_slot"), &ProceduralAnimationEditor::on_connection_request);
|
||||
@ -338,9 +217,6 @@ void ProceduralAnimationEditor::_bind_methods() {
|
||||
|
||||
ProceduralAnimationEditor::ProceduralAnimationEditor() {
|
||||
_animation_player = NULL;
|
||||
|
||||
_name_popup_action = NAME_POPUP_ADD_ANIMATION_NAME;
|
||||
_selected_animation = -1;
|
||||
}
|
||||
|
||||
ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
|
||||
@ -348,24 +224,10 @@ ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
|
||||
|
||||
set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
_name_popup_action = NAME_POPUP_ADD_ANIMATION_NAME;
|
||||
_selected_animation = -1;
|
||||
|
||||
//top bar
|
||||
HBoxContainer *hbc = memnew(HBoxContainer);
|
||||
add_child(hbc);
|
||||
|
||||
MenuButton *animtn = memnew(MenuButton);
|
||||
animtn->set_text("Animation");
|
||||
|
||||
PopupMenu *apm = animtn->get_popup();
|
||||
apm->add_item("Add", 0);
|
||||
apm->add_item("Rename", 1);
|
||||
apm->add_item("Delete", 2);
|
||||
apm->connect("id_pressed", this, "animation_tool_button_id_pressed");
|
||||
|
||||
hbc->add_child(animtn);
|
||||
|
||||
_animation_option_button = memnew(OptionButton);
|
||||
_animation_option_button->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
_animation_option_button->connect("item_selected", this, "on_animation_option_button_pressed");
|
||||
|
@ -39,13 +39,7 @@ class ProceduralAnimationEditor : public VBoxContainer {
|
||||
GDCLASS(ProceduralAnimationEditor, VBoxContainer);
|
||||
|
||||
public:
|
||||
enum NamePopupActions {
|
||||
NAME_POPUP_ADD_ANIMATION_NAME,
|
||||
NAME_POPUP_EDIT_ANIMATION_NAME,
|
||||
};
|
||||
|
||||
enum DeletePopupActions {
|
||||
DELETE_POPUP_ANIMATION,
|
||||
DELETE_POPUP_KEYFRAME,
|
||||
};
|
||||
|
||||
@ -58,15 +52,8 @@ public:
|
||||
void load_selected_animation();
|
||||
void clear_keyframe_nodes();
|
||||
|
||||
void refresh_option_buttons();
|
||||
|
||||
void on_animation_option_button_pressed(int indx);
|
||||
void refresh_animation_option_button();
|
||||
void on_keyframe_node_changed(Node *node);
|
||||
|
||||
void animation_tool_button_id_pressed(int id);
|
||||
void show_name_popup(NamePopupActions action);
|
||||
void on_name_popup_confirmed();
|
||||
void on_delete_popup_confirmed();
|
||||
|
||||
void on_connection_request(const String &from, const int from_slot, const String &to, const int to_slot);
|
||||
@ -81,14 +68,11 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _selected_animation;
|
||||
|
||||
OptionButton *_animation_option_button;
|
||||
|
||||
DeletePopupActions _delete_popup_action;
|
||||
ConfirmationDialog *_delete_popuop;
|
||||
|
||||
NamePopupActions _name_popup_action;
|
||||
ConfirmationDialog *_name_popuop;
|
||||
Label *_name_pupup_label;
|
||||
LineEdit *_name_popup_line_edit;
|
||||
@ -142,7 +126,6 @@ protected:
|
||||
private:
|
||||
int _id;
|
||||
LineEdit *_name;
|
||||
//OptionButton *_animation_keyframe_index_option_button;
|
||||
SpinBox *_animation_keyframe_spinbox;
|
||||
int _animation_keyframe_index;
|
||||
int _next_keyframe;
|
||||
|
@ -21,112 +21,3 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "procedural_animation_player.h"
|
||||
|
||||
Ref<ProceduralAnimation> ProceduralAnimationPlayer::get_animation() {
|
||||
return _animation;
|
||||
}
|
||||
void ProceduralAnimationPlayer::set_animation(const Ref<ProceduralAnimation> &animation) {
|
||||
_animation = animation;
|
||||
}
|
||||
|
||||
int ProceduralAnimationPlayer::get_current_animation() const {
|
||||
return _current_animation;
|
||||
}
|
||||
void ProceduralAnimationPlayer::set_current_animation(const int p_animation) {
|
||||
_current_animation = p_animation;
|
||||
}
|
||||
|
||||
int ProceduralAnimationPlayer::get_curent_keyframe() const {
|
||||
return _curent_keyframe;
|
||||
}
|
||||
void ProceduralAnimationPlayer::set_curent_keyframe(const int p_keyframe) {
|
||||
_curent_keyframe = p_keyframe;
|
||||
}
|
||||
|
||||
float ProceduralAnimationPlayer::get_scale() const {
|
||||
return _scale;
|
||||
}
|
||||
void ProceduralAnimationPlayer::set_scale(const float p_scale) {
|
||||
_scale = p_scale;
|
||||
}
|
||||
|
||||
bool ProceduralAnimationPlayer::is_playing() const {
|
||||
return _playing;
|
||||
}
|
||||
|
||||
void ProceduralAnimationPlayer::play() {
|
||||
if (_playing)
|
||||
return;
|
||||
|
||||
_playing = true;
|
||||
}
|
||||
void ProceduralAnimationPlayer::stop() {
|
||||
if (!_playing)
|
||||
return;
|
||||
|
||||
_playing = false;
|
||||
}
|
||||
void ProceduralAnimationPlayer::setup_frame() {
|
||||
}
|
||||
void ProceduralAnimationPlayer::advance(float p_delta) {
|
||||
}
|
||||
|
||||
ProceduralAnimationPlayer::ProceduralAnimationPlayer() {
|
||||
_current_animation = 0;
|
||||
_curent_keyframe = 0;
|
||||
_scale = 1.0;
|
||||
_playing = false;
|
||||
}
|
||||
ProceduralAnimationPlayer::~ProceduralAnimationPlayer() {
|
||||
_animation.unref();
|
||||
}
|
||||
|
||||
void ProceduralAnimationPlayer::_validate_property(PropertyInfo &property) const {
|
||||
|
||||
if (property.name == "current_animation") {
|
||||
|
||||
if (_animation.is_valid()) {
|
||||
|
||||
String names;
|
||||
|
||||
PoolIntArray arr = _animation->get_animation_indices();
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
if (i > 0)
|
||||
names += ",";
|
||||
|
||||
names += _animation->get_animation_name(arr[i]);
|
||||
}
|
||||
|
||||
property.hint = PROPERTY_HINT_ENUM;
|
||||
property.hint_string = names;
|
||||
} else {
|
||||
property.hint = PROPERTY_HINT_NONE;
|
||||
property.hint_string = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProceduralAnimationPlayer::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_animation"), &ProceduralAnimationPlayer::get_animation);
|
||||
ClassDB::bind_method(D_METHOD("set_animation", "value"), &ProceduralAnimationPlayer::set_animation);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "animation", PROPERTY_HINT_RESOURCE_TYPE, "ProceduralAnimation"), "set_animation", "get_animation");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_current_animation"), &ProceduralAnimationPlayer::get_current_animation);
|
||||
ClassDB::bind_method(D_METHOD("set_current_animation", "animation"), &ProceduralAnimationPlayer::set_current_animation);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_animation"), "set_current_animation", "get_current_animation");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_curent_keyframe"), &ProceduralAnimationPlayer::get_curent_keyframe);
|
||||
ClassDB::bind_method(D_METHOD("set_curent_keyframe", "animation"), &ProceduralAnimationPlayer::set_curent_keyframe);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "curent_keyframe"), "set_curent_keyframe", "get_curent_keyframe");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_scale"), &ProceduralAnimationPlayer::get_scale);
|
||||
ClassDB::bind_method(D_METHOD("set_scale", "animation"), &ProceduralAnimationPlayer::set_scale);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale"), "set_scale", "get_scale");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("is_playing"), &ProceduralAnimationPlayer::is_playing);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("play"), &ProceduralAnimationPlayer::play);
|
||||
ClassDB::bind_method(D_METHOD("stop"), &ProceduralAnimationPlayer::stop);
|
||||
ClassDB::bind_method(D_METHOD("setup_frame"), &ProceduralAnimationPlayer::setup_frame);
|
||||
ClassDB::bind_method(D_METHOD("advance", "delta"), &ProceduralAnimationPlayer::advance);
|
||||
}
|
@ -25,47 +25,12 @@ SOFTWARE.
|
||||
|
||||
#include "scene/main/node.h"
|
||||
|
||||
#include "core/string_name.h"
|
||||
|
||||
#include "procedural_animation.h"
|
||||
|
||||
class ProceduralAnimationPlayer : public Node {
|
||||
GDCLASS(ProceduralAnimationPlayer, Node);
|
||||
|
||||
public:
|
||||
Ref<ProceduralAnimation> get_animation();
|
||||
void set_animation(const Ref<ProceduralAnimation> &animation);
|
||||
|
||||
int get_current_animation() const;
|
||||
void set_current_animation(const int p_animation);
|
||||
|
||||
int get_curent_keyframe() const;
|
||||
void set_curent_keyframe(const int p_keyframe);
|
||||
|
||||
float get_scale() const;
|
||||
void set_scale(const float p_scale);
|
||||
|
||||
bool is_playing() const;
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
void setup_frame();
|
||||
void advance(float p_delta);
|
||||
|
||||
ProceduralAnimationPlayer();
|
||||
~ProceduralAnimationPlayer();
|
||||
|
||||
protected:
|
||||
void _validate_property(PropertyInfo &property) const;
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<ProceduralAnimation> _animation;
|
||||
|
||||
int _current_animation;
|
||||
int _curent_keyframe;
|
||||
float _scale;
|
||||
bool _playing;
|
||||
friend class Animation;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user