Removed categories.

This commit is contained in:
Relintai 2020-03-25 15:05:10 +01:00
parent 1126980e9d
commit 9f9c0f8940
8 changed files with 607 additions and 618 deletions

View File

@ -0,0 +1,293 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ProceduralAnimation" inherits="Resource" version="3.2">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="add_animation">
<return type="int">
</return>
<description>
</description>
</method>
<method name="add_keyframe">
<return type="int">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_animation_indices" qualifiers="const">
<return type="PoolIntArray">
</return>
<description>
</description>
</method>
<method name="get_animation_keyframe_name" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_animation_keyframe_names" qualifiers="const">
<return type="PoolStringArray">
</return>
<description>
</description>
</method>
<method name="get_animation_name" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_animation_node_position" qualifiers="const">
<return type="Vector2">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_animation_start_frame_index" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_keyframe_animation_keyframe_index" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_keyframe_in_curve" qualifiers="const">
<return type="Curve">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_keyframe_indices" qualifiers="const">
<return type="PoolIntArray">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_keyframe_name" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_keyframe_next_keyframe_index" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_keyframe_node_position" qualifiers="const">
<return type="Vector2">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="has_animation" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<description>
</description>
</method>
<method name="has_keyframe" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="initialize">
<return type="void">
</return>
<description>
</description>
</method>
<method name="load_keyframe_data">
<return type="void">
</return>
<argument index="0" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="remove_animation">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<description>
</description>
</method>
<method name="remove_animation_keyframe_name">
<return type="void">
</return>
<argument index="0" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="remove_keyframe">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<description>
</description>
</method>
<method name="set_animation_keyframe_name">
<return type="void">
</return>
<argument index="0" name="keyframe_index" type="int">
</argument>
<argument index="1" name="value" type="String">
</argument>
<description>
</description>
</method>
<method name="set_animation_name">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="value" type="String">
</argument>
<description>
</description>
</method>
<method name="set_animation_node_position">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="value" type="Vector2">
</argument>
<description>
</description>
</method>
<method name="set_animation_start_frame_index">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="value" type="int">
</argument>
<description>
</description>
</method>
<method name="set_keyframe_animation_keyframe_index">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<argument index="2" name="value" type="int">
</argument>
<description>
</description>
</method>
<method name="set_keyframe_in_curve">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<argument index="2" name="value" type="Curve">
</argument>
<description>
</description>
</method>
<method name="set_keyframe_name">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<argument index="2" name="value" type="String">
</argument>
<description>
</description>
</method>
<method name="set_keyframe_next_keyframe_index">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<argument index="2" name="value" type="int">
</argument>
<description>
</description>
</method>
<method name="set_keyframe_node_position">
<return type="void">
</return>
<argument index="0" name="animation_index" type="int">
</argument>
<argument index="1" name="keyframe_index" type="int">
</argument>
<argument index="2" name="value" type="Vector2">
</argument>
<description>
</description>
</method>
</methods>
<members>
<member name="animation" type="Animation" setter="set_animation" getter="get_animation">
</member>
<member name="animation_fps" type="int" setter="set_animation_fps" getter="get_animation_fps" default="15">
</member>
</members>
<constants>
</constants>
</class>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ProceduralAnimationPlayer" inherits="Node" version="3.2">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="advance">
<return type="void">
</return>
<argument index="0" name="delta" type="float">
</argument>
<description>
</description>
</method>
<method name="is_playing" qualifiers="const">
<return type="bool">
</return>
<description>
</description>
</method>
<method name="play">
<return type="void">
</return>
<description>
</description>
</method>
<method name="setup_frame">
<return type="void">
</return>
<description>
</description>
</method>
<method name="stop">
<return type="void">
</return>
<description>
</description>
</method>
</methods>
<members>
<member name="animation" type="ProceduralAnimation" setter="set_animation" getter="get_animation">
</member>
<member name="curent_keyframe" type="int" setter="set_curent_keyframe" getter="get_curent_keyframe" default="0">
</member>
<member name="current_animation" type="int" setter="set_current_animation" getter="get_current_animation" default="0">
</member>
<member name="scale" type="float" setter="set_scale" getter="get_scale" default="1.0">
</member>
</members>
<constants>
</constants>
</class>

View File

@ -67,84 +67,22 @@ PoolVector<String> ProceduralAnimation::get_animation_keyframe_names() const {
return names;
}
//Categories
PoolVector<int> ProceduralAnimation::get_category_indices() const {
PoolVector<int> idxr;
idxr.resize(_categories.size());
int i = 0;
for (Map<int, Category *>::Element *E = _categories.front(); E; E = E->next()) {
idxr.set(i, E->key());
++i;
}
return idxr;
}
int ProceduralAnimation::add_category(const String &name) {
Category *cat = memnew(Category);
cat->name = name;
int key = -1;
for (Map<int, Category *>::Element *E = _categories.front(); E; E = E->next()) {
if (E->key() > key) {
key = E->key();
}
}
++key;
_categories[key] = cat;
return key;
}
void ProceduralAnimation::remove_category(const int index) {
ERR_FAIL_COND(!_categories.has(index));
Category *category = _categories[index];
_categories.erase(index);
memdelete(category);
}
bool ProceduralAnimation::has_category(const int index) const {
return _categories.has(index);
}
String ProceduralAnimation::get_category_name(const int category_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), "");
return _categories[category_index]->name;
}
void ProceduralAnimation::set_category_name(const int category_index, const String &value) {
ERR_FAIL_COND(!_categories.has(category_index));
_categories[category_index]->name = value;
}
//Animations
PoolVector<int> ProceduralAnimation::get_animation_indices(const int category_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), PoolVector<int>());
Category *cat = _categories[category_index];
PoolVector<int> ProceduralAnimation::get_animation_indices() const {
PoolVector<int> idxr;
idxr.resize(cat->animations.size());
idxr.resize(_animations.size());
int i = 0;
for (Map<int, AnimationEntry *>::Element *E = cat->animations.front(); E; E = E->next()) {
for (Map<int, AnimationEntry *>::Element *E = _animations.front(); E; E = E->next()) {
idxr.set(i, E->key());
++i;
}
return idxr;
}
int ProceduralAnimation::add_animation(const int category_index) {
ERR_FAIL_COND_V(!_categories.has(category_index), 0);
Category *cat = _categories[category_index];
int ProceduralAnimation::add_animation() {
int key = -1;
for (Map<int, AnimationEntry *>::Element *E = cat->animations.front(); E; E = E->next()) {
for (Map<int, AnimationEntry *>::Element *E = _animations.front(); E; E = E->next()) {
if (E->key() > key) {
key = E->key();
}
@ -153,99 +91,62 @@ int ProceduralAnimation::add_animation(const int category_index) {
AnimationEntry *entry = memnew(AnimationEntry);
cat->animations[key] = entry;
_animations[key] = entry;
return key;
}
void ProceduralAnimation::remove_animation(const int category_index, const int animation_index) {
ERR_FAIL_COND(!_categories.has(category_index));
void ProceduralAnimation::remove_animation(const int animation_index) {
ERR_FAIL_COND(!_animations.has(animation_index));
Category *cat = _categories[category_index];
AnimationEntry *entry = _animations[animation_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
AnimationEntry *entry = cat->animations[animation_index];
cat->animations.erase(animation_index);
_animations.erase(animation_index);
memdelete(entry);
}
bool ProceduralAnimation::has_animation(const int category_index, const int animation_index) const {
if (!_categories.has(category_index))
return false;
Category *cat = _categories[category_index];
return cat->animations.has(animation_index);
bool ProceduralAnimation::has_animation(const int animation_index) const {
return _animations.has(animation_index);
}
String ProceduralAnimation::get_animation_name(const int category_index, const int animation_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), "");
String ProceduralAnimation::get_animation_name(const int animation_index) const {
ERR_FAIL_COND_V(!_animations.has(animation_index), "");
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), "");
return cat->animations[animation_index]->name;
return _animations[animation_index]->name;
}
void ProceduralAnimation::set_animation_name(const int category_index, const int animation_index, const String &value) {
ERR_FAIL_COND(!_categories.has(category_index));
void ProceduralAnimation::set_animation_name(const int animation_index, const String &value) {
ERR_FAIL_COND(!_animations.has(animation_index));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
cat->animations[animation_index]->name = value;
_animations[animation_index]->name = value;
}
Vector2 ProceduralAnimation::get_animation_node_position(const int category_index, int animation_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), Vector2());
Vector2 ProceduralAnimation::get_animation_node_position(int animation_index) const {
ERR_FAIL_COND_V(!_animations.has(animation_index), Vector2());
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), Vector2());
return cat->animations[animation_index]->position;
return _animations[animation_index]->position;
}
void ProceduralAnimation::set_animation_node_position(const int category_index, const int animation_index, const Vector2 &value) {
ERR_FAIL_COND(!_categories.has(category_index));
void ProceduralAnimation::set_animation_node_position(const int animation_index, const Vector2 &value) {
ERR_FAIL_COND(!_animations.has(animation_index));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
cat->animations[animation_index]->position = value;
_animations[animation_index]->position = value;
}
int ProceduralAnimation::get_animation_start_frame_index(const int category_index, const int animation_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), 0);
int ProceduralAnimation::get_animation_start_frame_index(const int animation_index) const {
ERR_FAIL_COND_V(!_animations.has(animation_index), 0);
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), 0);
return cat->animations[animation_index]->start_frame_index;
return _animations[animation_index]->start_frame_index;
}
void ProceduralAnimation::set_animation_start_frame_index(const int category_index, const int animation_index, const int value) {
ERR_FAIL_COND(!_categories.has(category_index));
void ProceduralAnimation::set_animation_start_frame_index(const int animation_index, const int value) {
ERR_FAIL_COND(!_animations.has(animation_index));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
cat->animations[animation_index]->start_frame_index = value;
_animations[animation_index]->start_frame_index = value;
}
//Keyframes
PoolVector<int> ProceduralAnimation::get_keyframe_indices(const int category_index, const int animation_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), PoolVector<int>());
PoolVector<int> ProceduralAnimation::get_keyframe_indices(const int animation_index) const {
ERR_FAIL_COND_V(!_animations.has(animation_index), PoolVector<int>());
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), PoolVector<int>());
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
PoolVector<int> idxr;
idxr.resize(ae->keyframes.size());
@ -258,14 +159,10 @@ PoolVector<int> ProceduralAnimation::get_keyframe_indices(const int category_ind
return idxr;
}
int ProceduralAnimation::add_keyframe(const int category_index, const int animation_index) {
ERR_FAIL_COND_V(!_categories.has(category_index), 0);
int ProceduralAnimation::add_keyframe(const int animation_index) {
ERR_FAIL_COND_V(!_animations.has(animation_index), 0);
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), 0);
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
int key = -1;
for (Map<int, AnimationKeyFrame *>::Element *E = ae->keyframes.front(); E; E = E->next()) {
@ -281,167 +178,118 @@ int ProceduralAnimation::add_keyframe(const int category_index, const int animat
return key;
}
void ProceduralAnimation::remove_keyframe(const int category_index, const int animation_index, const int keyframe_index) {
ERR_FAIL_COND(!_categories.has(category_index));
void ProceduralAnimation::remove_keyframe(const int animation_index, const int keyframe_index) {
ERR_FAIL_COND(!_animations.has(animation_index));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
AnimationKeyFrame *entry = ae->keyframes[keyframe_index];
cat->animations.erase(keyframe_index);
_animations.erase(keyframe_index);
memdelete(entry);
}
bool ProceduralAnimation::has_keyframe(const int category_index, const int animation_index, const int keyframe_index) const {
if (!_categories.has(category_index))
bool ProceduralAnimation::has_keyframe(const int animation_index, const int keyframe_index) const {
if (!_animations.has(animation_index))
return false;
Category *cat = _categories[category_index];
if (!cat->animations.has(animation_index))
return false;
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
return ae->keyframes.has(keyframe_index);
}
String ProceduralAnimation::get_keyframe_name(const int category_index, const int animation_index, const int keyframe_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), "");
String ProceduralAnimation::get_keyframe_name(const int animation_index, const int keyframe_index) const {
ERR_FAIL_COND_V(!_animations.has(animation_index), "");
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), "");
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), "");
return ae->keyframes[keyframe_index]->name;
}
void ProceduralAnimation::set_keyframe_name(const int category_index, const int animation_index, const int keyframe_index, const String &value) {
ERR_FAIL_COND(!_categories.has(category_index));
void ProceduralAnimation::set_keyframe_name(const int animation_index, const int keyframe_index, const String &value) {
ERR_FAIL_COND(!_animations.has(animation_index));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
ae->keyframes[keyframe_index]->name = value;
}
int ProceduralAnimation::get_keyframe_animation_keyframe_index(const int category_index, int animation_index, const int keyframe_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), 0);
int ProceduralAnimation::get_keyframe_animation_keyframe_index(int animation_index, const int keyframe_index) const {
ERR_FAIL_COND_V(!_animations.has(animation_index), 0);
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), 0);
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), 0);
return ae->keyframes[keyframe_index]->animation_keyframe_index;
}
void ProceduralAnimation::set_keyframe_animation_keyframe_index(const int category_index, int animation_index, const int keyframe_index, int value) {
ERR_FAIL_COND(!_categories.has(category_index));
void ProceduralAnimation::set_keyframe_animation_keyframe_index(int animation_index, const int keyframe_index, int value) {
ERR_FAIL_COND(!_animations.has(animation_index));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
ae->keyframes[keyframe_index]->animation_keyframe_index = value;
}
int ProceduralAnimation::get_keyframe_next_keyframe_index(const int category_index, const int animation_index, const int keyframe_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), 0);
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);
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), 0);
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), 0);
return ae->keyframes[keyframe_index]->next_keyframe;
}
void ProceduralAnimation::set_keyframe_next_keyframe_index(const int category_index, const int animation_index, const int keyframe_index, const int value) {
ERR_FAIL_COND(!_categories.has(category_index));
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));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
ae->keyframes[keyframe_index]->next_keyframe = value;
}
Ref<Curve> ProceduralAnimation::get_keyframe_in_curve(const int category_index, const int animation_index, const int keyframe_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), Ref<Curve>());
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>());
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), Ref<Curve>());
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), Ref<Curve>());
return ae->keyframes[keyframe_index]->in_curve;
}
void ProceduralAnimation::set_keyframe_in_curve(const int category_index, const int animation_index, const int keyframe_index, const Ref<Curve> &value) {
ERR_FAIL_COND(!_categories.has(category_index));
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));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
ae->keyframes[keyframe_index]->in_curve = value;
}
Vector2 ProceduralAnimation::get_keyframe_node_position(const int category_index, int animation_index, const int keyframe_index) const {
ERR_FAIL_COND_V(!_categories.has(category_index), Vector2());
Vector2 ProceduralAnimation::get_keyframe_node_position(int animation_index, const int keyframe_index) const {
ERR_FAIL_COND_V(!_animations.has(animation_index), Vector2());
Category *cat = _categories[category_index];
ERR_FAIL_COND_V(!cat->animations.has(animation_index), Vector2());
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND_V(!ae->keyframes.has(keyframe_index), Vector2());
return ae->keyframes[keyframe_index]->position;
}
void ProceduralAnimation::set_keyframe_node_position(const int category_index, const int animation_index, const int keyframe_index, const Vector2 &value) {
ERR_FAIL_COND(!_categories.has(category_index));
void ProceduralAnimation::set_keyframe_node_position(const int animation_index, const int keyframe_index, const Vector2 &value) {
ERR_FAIL_COND(!_animations.has(animation_index));
Category *cat = _categories[category_index];
ERR_FAIL_COND(!cat->animations.has(animation_index));
AnimationEntry *ae = cat->animations[animation_index];
AnimationEntry *ae = _animations[animation_index];
ERR_FAIL_COND(!ae->keyframes.has(keyframe_index));
@ -459,18 +307,14 @@ void ProceduralAnimation::initialize() {
_animation_data.clear();
for (Map<int, Category *>::Element *E = _categories.front(); E; E = E->next()) {
Category *category = E->get();
for (Map<int, AnimationEntry *>::Element *A = _animations.front(); A; A = A->next()) {
AnimationEntry *anim_entry = A->get();
for (Map<int, AnimationEntry *>::Element *A = category->animations.front(); A; A = A->next()) {
AnimationEntry *anim_entry = A->get();
for (Map<int, AnimationKeyFrame *>::Element *K = anim_entry->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);
}
}
}
@ -556,9 +400,10 @@ ProceduralAnimation::ProceduralAnimation() {
}
ProceduralAnimation::~ProceduralAnimation() {
for (Map<int, Category *>::Element *E = _categories.front(); E; E = E->next()) {
Map<int, AnimationEntry *> animations;
for (Map<int, AnimationEntry *>::Element *E = _animations.front(); E; E = E->next())
memdelete(E->get());
}
for (Map<int, Vector<AnimationKey> *>::Element *E = _animation_data.front(); E; E = E->next()) {
Vector<AnimationKey> *data = E->get();
@ -567,8 +412,7 @@ ProceduralAnimation::~ProceduralAnimation() {
}
_animation_data.clear();
_categories.clear();
_animations.clear();
_animation.unref();
}
@ -916,85 +760,67 @@ 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("categories/")) {
if (name.begins_with("animation/")) {
int animation_index = name.get_slicec('/', 1).to_int();
String anim_prop_name = name.get_slicec('/', 2);
int category_index = name.get_slicec('/', 1).to_int();
String what = name.get_slicec('/', 2);
if (!_animations.has(animation_index)) {
AnimationEntry *ae = memnew(AnimationEntry);
if (!_categories.has(category_index)) {
Category *cat = memnew(Category);
_categories[category_index] = cat;
_animations[animation_index] = ae;
}
Category *cat = _categories[category_index];
AnimationEntry *ae = _animations[animation_index];
if (what == "name") {
cat->name = p_value;
if (anim_prop_name == "name") {
ae->name = p_value;
return true;
} else if (what == "animation") {
int animation_index = name.get_slicec('/', 3).to_int();
String anim_prop_name = name.get_slicec('/', 4);
} else if (anim_prop_name == "position") {
ae->position = p_value;
if (!cat->animations.has(animation_index)) {
AnimationEntry *ae = memnew(AnimationEntry);
return true;
} else if (anim_prop_name == "start_frame_index") {
ae->start_frame_index = p_value;
cat->animations[animation_index] = ae;
return true;
} else if (anim_prop_name == "keyframe") {
int keyframe_index = name.get_slicec('/', 5).to_int();
String keyframe_name = name.get_slicec('/', 6);
if (!ae->keyframes.has(keyframe_index)) {
AnimationKeyFrame *keyframe = memnew(AnimationKeyFrame);
ae->keyframes[keyframe_index] = keyframe;
}
AnimationEntry *ae = cat->animations[animation_index];
AnimationKeyFrame *keyframe = ae->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;
}
} else {
return false;
}
} else {
return false;
@ -1006,64 +832,50 @@ 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("categories/")) {
if (name.begins_with("animation/")) {
int animation_index = name.get_slicec('/', 1).to_int();
String anim_prop_name = name.get_slicec('/', 2);
int category_index = name.get_slicec('/', 1).to_int();
String what = name.get_slicec('/', 2);
AnimationEntry *anim = _animations[animation_index];
Category *category = _categories[category_index];
if (what == "name") {
r_ret = category->name;
if (anim_prop_name == "name") {
r_ret = anim->name;
return true;
} else if (what == "animation") {
int animation_index = name.get_slicec('/', 3).to_int();
String anim_prop_name = name.get_slicec('/', 4);
} else if (anim_prop_name == "position") {
r_ret = anim->position;
AnimationEntry *anim = category->animations[animation_index];
return true;
} else if (anim_prop_name == "start_frame_index") {
r_ret = anim->start_frame_index;
if (anim_prop_name == "name") {
r_ret = anim->name;
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);
AnimationKeyFrame *keyframe = anim->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;
}
@ -1081,25 +893,19 @@ 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, Category *>::Element *E = _categories.front(); E; E = E->next()) {
Category *category = E->get();
for (Map<int, AnimationEntry *>::Element *A = _animations.front(); A; A = A->next()) {
AnimationEntry *animation = A->get();
p_list->push_back(PropertyInfo(Variant::STRING, "categories/" + itos(E->key()) + "/name", 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, AnimationEntry *>::Element *A = category->animations.front(); A; A = A->next()) {
AnimationEntry *animation = A->get();
p_list->push_back(PropertyInfo(Variant::STRING, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/name", PROPERTY_HINT_NONE, "", property_usange));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/position", PROPERTY_HINT_NONE, "", property_usange));
p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/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, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/name", PROPERTY_HINT_NONE, "", property_usange));
p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/animation_keyframe_index", PROPERTY_HINT_NONE, "", property_usange));
p_list->push_back(PropertyInfo(Variant::INT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/next_keyframe", PROPERTY_HINT_NONE, "", property_usange));
p_list->push_back(PropertyInfo(Variant::OBJECT, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/in_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve", property_usange));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "categories/" + itos(E->key()) + "/animation/" + itos(A->key()) + "/keyframe/" + itos(K->key()) + "/position", 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));
}
}
}
@ -1118,50 +924,41 @@ 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);
//Categories
ClassDB::bind_method(D_METHOD("get_category_indices"), &ProceduralAnimation::get_category_indices);
ClassDB::bind_method(D_METHOD("add_category", "name"), &ProceduralAnimation::add_category);
ClassDB::bind_method(D_METHOD("remove_category", "index"), &ProceduralAnimation::remove_category);
ClassDB::bind_method(D_METHOD("has_category", "index"), &ProceduralAnimation::has_category);
ClassDB::bind_method(D_METHOD("get_category_name", "category_index"), &ProceduralAnimation::get_category_name);
ClassDB::bind_method(D_METHOD("set_category_name", "category_index"), &ProceduralAnimation::set_category_name);
//Animations
ClassDB::bind_method(D_METHOD("get_animation_indices", "category_index"), &ProceduralAnimation::get_animation_indices);
ClassDB::bind_method(D_METHOD("add_animation", "category_index"), &ProceduralAnimation::add_animation);
ClassDB::bind_method(D_METHOD("remove_animation", "category_index", "animation_index"), &ProceduralAnimation::remove_animation);
ClassDB::bind_method(D_METHOD("has_animation", "category_index", "animation_index"), &ProceduralAnimation::has_animation);
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_animation_name", "category_index", "animation_index"), &ProceduralAnimation::get_animation_name);
ClassDB::bind_method(D_METHOD("set_animation_name", "category_index", "animation_index", "value"), &ProceduralAnimation::set_animation_name);
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", "category_index", "animation_index"), &ProceduralAnimation::get_animation_node_position);
ClassDB::bind_method(D_METHOD("set_animation_node_position", "category_index", "animation_index", "value"), &ProceduralAnimation::set_animation_node_position);
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", "category_index", "animation_index"), &ProceduralAnimation::get_animation_start_frame_index);
ClassDB::bind_method(D_METHOD("set_animation_start_frame_index", "category_index", "animation_index", "value"), &ProceduralAnimation::set_animation_start_frame_index);
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);
//Keyframes
ClassDB::bind_method(D_METHOD("get_keyframe_indices", "category_index", "animation_index"), &ProceduralAnimation::get_keyframe_indices);
ClassDB::bind_method(D_METHOD("add_keyframe", "category_index", "animation_index"), &ProceduralAnimation::add_keyframe);
ClassDB::bind_method(D_METHOD("remove_keyframe", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::remove_keyframe);
ClassDB::bind_method(D_METHOD("has_keyframe", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::has_keyframe);
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_name", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_name);
ClassDB::bind_method(D_METHOD("set_keyframe_name", "category_index", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_name);
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_animation_keyframe_index", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_animation_keyframe_index);
ClassDB::bind_method(D_METHOD("set_keyframe_animation_keyframe_index", "category_index", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_animation_keyframe_index);
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_next_keyframe_index", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_next_keyframe_index);
ClassDB::bind_method(D_METHOD("set_keyframe_next_keyframe_index", "category_index", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_next_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_in_curve", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_in_curve);
ClassDB::bind_method(D_METHOD("set_keyframe_in_curve", "category_index", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_in_curve);
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_node_position", "category_index", "animation_index", "keyframe_index"), &ProceduralAnimation::get_keyframe_node_position);
ClassDB::bind_method(D_METHOD("set_keyframe_node_position", "category_index", "animation_index", "keyframe_index", "value"), &ProceduralAnimation::set_keyframe_node_position);
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("initialize"), &ProceduralAnimation::initialize);
ClassDB::bind_method(D_METHOD("load_keyframe_data", "keyframe_index"), &ProceduralAnimation::load_keyframe_data);

View File

@ -149,18 +149,6 @@ protected:
}
};
struct Category {
String name;
Map<int, AnimationEntry *> animations;
~Category() {
for (Map<int, AnimationEntry *>::Element *E = animations.front(); E; E = E->next())
memdelete(E->get());
animations.clear();
}
};
public:
Ref<Animation> get_animation() const;
void set_animation(const Ref<Animation> &value);
@ -173,50 +161,41 @@ public:
void remove_animation_keyframe_name(int keyframe_index);
PoolVector<String> get_animation_keyframe_names() const;
//Categories
PoolVector<int> get_category_indices() const;
int add_category(const String &name);
void remove_category(const int index);
bool has_category(const int index) const;
String get_category_name(const int category_index) const;
void set_category_name(const int category_index, const String &value);
//Animations
PoolVector<int> get_animation_indices(const int category_index) const;
int add_animation(const int category_index);
void remove_animation(const int category_index, const int animation_index);
bool has_animation(const int category_index, const int animation_index) const;
PoolVector<int> get_animation_indices() const;
int add_animation();
void remove_animation(const int animation_index);
bool has_animation(const int animation_index) const;
String get_animation_name(const int category_index, const int animation_index) const;
void set_animation_name(const int category_index, const int animation_index, const String &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(const int category_index, int animation_index) const;
void set_animation_node_position(const int category_index, const int animation_index, const Vector2 &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 category_index, const int animation_index) const;
void set_animation_start_frame_index(const int category_index, const int animation_index, const int 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);
//Keyframes
PoolVector<int> get_keyframe_indices(const int category_index, const int animation_index) const;
int add_keyframe(const int category_index, const int animation_index);
void remove_keyframe(const int category_index, const int animation_index, const int keyframe_index);
bool has_keyframe(const int category_index, const int animation_index, const int keyframe_index) const;
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;
String get_keyframe_name(const int category_index, const int animation_index, const int keyframe_index) const;
void set_keyframe_name(const int category_index, const int animation_index, const int keyframe_index, const String &value);
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);
int get_keyframe_animation_keyframe_index(const int category_index, int animation_index, const int keyframe_index) const;
void set_keyframe_animation_keyframe_index(const int category_index, int animation_index, const int keyframe_index, int 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_next_keyframe_index(const int category_index, const int animation_index, const int keyframe_index) const;
void set_keyframe_next_keyframe_index(const int category_index, const int animation_index, const int keyframe_index, const 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);
Ref<Curve> get_keyframe_in_curve(const int category_index, const int animation_index, const int keyframe_index) const;
void set_keyframe_in_curve(const int category_index, const int animation_index, const int keyframe_index, const Ref<Curve> &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);
Vector2 get_keyframe_node_position(const int category_index, int animation_index, const int keyframe_index) const;
void set_keyframe_node_position(const int category_index, const int animation_index, const int keyframe_index, const Vector2 &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);
void initialize();
void load_keyframe_data(int keyframe_index);
@ -254,7 +233,7 @@ private:
String _editor_add_category_name;
String _add_editor_category_animation_name;
Map<int, Category *> _categories;
Map<int, AnimationEntry *> _animations;
Map<int, Vector<AnimationKey> *> _animation_data;
Ref<Animation> _animation;

View File

@ -27,7 +27,6 @@ SOFTWARE.
void ProceduralAnimationEditor::edit(const Ref<ProceduralAnimation> &animation) {
_animation = animation;
_selected_category = -1;
_selected_animation = -1;
_stop->hide();
@ -43,7 +42,6 @@ void ProceduralAnimationEditor::edit(const Ref<ProceduralAnimation> &animation)
void ProceduralAnimationEditor::edit(ProceduralAnimationPlayer *player) {
_animation_player = player;
_selected_category = -1;
_selected_animation = -1;
_stop->show();
@ -63,14 +61,14 @@ void ProceduralAnimationEditor::load_selected_animation() {
ERR_FAIL_COND(!_animation.is_valid());
if (_selected_category == -1 || _selected_animation == -1)
if (_selected_animation == -1)
return;
_start_node->set_offset(_animation->get_animation_node_position(_selected_category, _selected_animation));
_start_node->set_offset(_animation->get_animation_node_position(_selected_animation));
const PoolVector<String> &animation_names = _animation->get_animation_keyframe_names();
PoolVector<int> kfind = _animation->get_keyframe_indices(_selected_category, _selected_animation);
PoolVector<int> kfind = _animation->get_keyframe_indices(_selected_animation);
for (int i = 0; i < kfind.size(); ++i) {
int id = kfind[i];
@ -82,24 +80,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_category, _selected_animation, id));
gn->set_keyframe_name(_animation->get_keyframe_name(_selected_category, _selected_animation, id));
gn->set_next_keyframe(_animation->get_keyframe_next_keyframe_index(_selected_category, _selected_animation, id));
gn->set_in_curve(_animation->get_keyframe_in_curve(_selected_category, _selected_animation, id));
gn->set_animation_keyframe_index(_animation->get_keyframe_animation_keyframe_index(_selected_category, _selected_animation, 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->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_category, _selected_animation, id);
int ni = _animation->get_keyframe_next_keyframe_index(_selected_animation, 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_category, _selected_animation);
int st = _animation->get_animation_start_frame_index(_selected_animation);
if (st != -1)
_graph_edit->connect_node("Start", 0, String::num(st), 0);
@ -122,52 +120,13 @@ void ProceduralAnimationEditor::clear_keyframe_nodes() {
}
}
void ProceduralAnimationEditor::on_animation_option_button_pressed(int indx) {
if (_selected_category == -1)
return;
if (_selected_animation == indx)
return;
_selected_animation = indx;
load_selected_animation();
}
void ProceduralAnimationEditor::on_category_option_button_pressed(int indx) {
if (_selected_category == indx)
return;
_selected_category = indx;
_selected_animation = -1;
refresh_animation_option_button();
}
void ProceduralAnimationEditor::refresh_option_buttons() {
_category_option_button->clear();
_animation_option_button->clear();
if (!_animation.is_valid())
return;
PoolVector<int> cind = _animation->get_category_indices();
for (int i = 0; i < cind.size(); ++i) {
int indx = cind[i];
if (_selected_category == -1)
_selected_category = indx;
_category_option_button->add_item(_animation->get_category_name(indx), indx);
}
if (_selected_category == -1)
return;
_category_option_button->select(_selected_category);
PoolVector<int> aind = _animation->get_animation_indices(_selected_category);
PoolVector<int> aind = _animation->get_animation_indices();
for (int i = 0; i < aind.size(); ++i) {
int indx = aind[i];
@ -175,7 +134,7 @@ void ProceduralAnimationEditor::refresh_option_buttons() {
if (_selected_animation == -1)
_selected_animation = indx;
_animation_option_button->add_item(_animation->get_animation_name(_selected_category, indx), indx);
_animation_option_button->add_item(_animation->get_animation_name(indx), indx);
}
if (_selected_animation == -1)
@ -184,6 +143,15 @@ void ProceduralAnimationEditor::refresh_option_buttons() {
_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;
@ -191,10 +159,7 @@ void ProceduralAnimationEditor::refresh_animation_option_button() {
if (!_animation.is_valid())
return;
if (_selected_category == -1)
return;
PoolVector<int> aind = _animation->get_animation_indices(_selected_category);
PoolVector<int> aind = _animation->get_animation_indices();
for (int i = 0; i < aind.size(); ++i) {
int indx = aind[i];
@ -202,7 +167,7 @@ void ProceduralAnimationEditor::refresh_animation_option_button() {
if (_selected_animation == -1)
_selected_animation = indx;
_animation_option_button->add_item(_animation->get_animation_name(_selected_category, indx), indx);
_animation_option_button->add_item(_animation->get_animation_name(indx), indx);
}
if (_selected_animation == -1)
@ -216,32 +181,17 @@ void ProceduralAnimationEditor::on_keyframe_node_changed(Node *node) {
ERR_FAIL_COND(!ObjectDB::instance_validate(gn));
ERR_FAIL_COND(!_animation.is_valid());
ERR_FAIL_COND(_selected_category == -1);
ERR_FAIL_COND(_selected_animation == -1);
int id = gn->get_id();
_animation->set_keyframe_animation_keyframe_index(_selected_category, _selected_animation, id, gn->get_animation_keyframe_index());
_animation->set_keyframe_in_curve(_selected_category, _selected_animation, id, gn->get_in_curve());
_animation->set_keyframe_name(_selected_category, _selected_animation, id, gn->get_keyframe_name());
_animation->set_keyframe_next_keyframe_index(_selected_category, _selected_animation, id, gn->get_next_keyframe());
_animation->set_keyframe_node_position(_selected_category, _selected_animation, id, gn->get_offset());
_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::category_tool_button_id_pressed(int id) {
switch (id) {
case 0:
show_name_popup(NAME_POPUP_ADD_CATEGORY_NAME);
break;
case 1:
show_name_popup(NAME_POPUP_EDIT_CATEGORY_NAME);
break;
case 2:
_delete_popup_action = DELETE_POPUP_CATEGORY;
_delete_popuop->popup_centered();
break;
}
}
void ProceduralAnimationEditor::animation_tool_button_id_pressed(int id) {
switch (id) {
case 0:
@ -265,25 +215,14 @@ void ProceduralAnimationEditor::show_name_popup(NamePopupActions action) {
void ProceduralAnimationEditor::on_name_popup_confirmed() {
switch (_name_popup_action) {
case NAME_POPUP_ADD_CATEGORY_NAME:
_selected_category = _animation->add_category(_name_popup_line_edit->get_text());
_selected_animation = -1;
break;
case NAME_POPUP_EDIT_CATEGORY_NAME:
_animation->set_category_name(_selected_category, _name_popup_line_edit->get_text());
break;
case NAME_POPUP_ADD_ANIMATION_NAME:
ERR_FAIL_COND(_selected_category == -1);
_selected_animation = _animation->add_animation(_selected_category);
_animation->set_animation_name(_selected_category, _selected_animation, _name_popup_line_edit->get_text());
_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_category == -1);
ERR_FAIL_COND(_selected_animation == -1);
_animation->set_animation_name(_selected_category, _selected_animation, _name_popup_line_edit->get_text());
_animation->set_animation_name(_selected_animation, _name_popup_line_edit->get_text());
break;
}
@ -292,21 +231,10 @@ void ProceduralAnimationEditor::on_name_popup_confirmed() {
void ProceduralAnimationEditor::on_delete_popup_confirmed() {
switch (_delete_popup_action) {
case DELETE_POPUP_CATEGORY:
ERR_FAIL_COND(_selected_category == -1);
_animation->remove_category(_selected_category);
_selected_category = -1;
_selected_animation = -1;
refresh_option_buttons();
break;
case DELETE_POPUP_ANIMATION:
ERR_FAIL_COND(_selected_category == -1);
ERR_FAIL_COND(_selected_animation == -1);
_animation->remove_animation(_selected_category, _selected_animation);
_animation->remove_animation(_selected_animation);
_selected_animation = -1;
@ -324,24 +252,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_category, _selected_animation, gn->get_id());
int ni = _animation->get_keyframe_next_keyframe_index(_selected_animation, gn->get_id());
if (ni != -1) {
_graph_edit->disconnect_node(from, from_slot, String::num(ni), 0);
}
_animation->set_keyframe_next_keyframe_index(_selected_category, _selected_animation, gn->get_id(), to.to_int());
_animation->set_keyframe_next_keyframe_index(_selected_animation, 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_category, _selected_animation);
int st = _animation->get_animation_start_frame_index(_selected_animation);
if (st != -1) {
_graph_edit->disconnect_node("Start", 0, String::num(st), 0);
}
_animation->set_animation_start_frame_index(_selected_category, _selected_animation, to.to_int());
_animation->set_animation_start_frame_index(_selected_animation, to.to_int());
}
}
@ -353,12 +281,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_category, _selected_animation, gn->get_id(), -1);
_animation->set_keyframe_next_keyframe_index(_selected_animation, gn->get_id(), -1);
} else {
GraphNode *g = Object::cast_to<GraphNode>(f);
if (g != NULL) {
_animation->set_animation_start_frame_index(_selected_category, _selected_animation, -1);
_animation->set_animation_start_frame_index(_selected_animation, -1);
}
}
@ -366,10 +294,10 @@ void ProceduralAnimationEditor::on_disconnection_request(const String &from, con
}
void ProceduralAnimationEditor::add_frame_button_pressed() {
if (_selected_category == -1 || _selected_animation == -1)
if (_selected_animation == -1)
return;
int id = _animation->add_keyframe(_selected_category, _selected_animation);
int id = _animation->add_keyframe(_selected_animation);
ProceduralAnimationEditorGraphNode *gn = memnew(ProceduralAnimationEditorGraphNode);
gn->set_id(id);
@ -393,9 +321,6 @@ void ProceduralAnimationEditor::_notification(int p_what) {
}
void ProceduralAnimationEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("on_category_option_button_pressed", "id"), &ProceduralAnimationEditor::on_category_option_button_pressed);
ClassDB::bind_method(D_METHOD("category_tool_button_id_pressed", "id"), &ProceduralAnimationEditor::category_tool_button_id_pressed);
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);
@ -414,8 +339,7 @@ void ProceduralAnimationEditor::_bind_methods() {
ProceduralAnimationEditor::ProceduralAnimationEditor() {
_animation_player = NULL;
_name_popup_action = NAME_POPUP_ADD_CATEGORY_NAME;
_selected_category = -1;
_name_popup_action = NAME_POPUP_ADD_ANIMATION_NAME;
_selected_animation = -1;
}
@ -424,30 +348,13 @@ ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
set_h_size_flags(SIZE_EXPAND_FILL);
_name_popup_action = NAME_POPUP_ADD_CATEGORY_NAME;
_selected_category = -1;
_name_popup_action = NAME_POPUP_ADD_ANIMATION_NAME;
_selected_animation = -1;
//top bar
HBoxContainer *hbc = memnew(HBoxContainer);
add_child(hbc);
MenuButton *categtnb = memnew(MenuButton);
categtnb->set_text("Category");
PopupMenu *cpm = categtnb->get_popup();
cpm->add_item("Add", 0);
cpm->add_item("Rename", 1);
cpm->add_item("Delete", 2);
cpm->connect("id_pressed", this, "category_tool_button_id_pressed");
hbc->add_child(categtnb);
_category_option_button = memnew(OptionButton);
_category_option_button->set_h_size_flags(SIZE_EXPAND_FILL);
_category_option_button->connect("item_selected", this, "on_category_option_button_pressed");
hbc->add_child(_category_option_button);
MenuButton *animtn = memnew(MenuButton);
animtn->set_text("Animation");

View File

@ -40,14 +40,11 @@ class ProceduralAnimationEditor : public VBoxContainer {
public:
enum NamePopupActions {
NAME_POPUP_ADD_CATEGORY_NAME,
NAME_POPUP_EDIT_CATEGORY_NAME,
NAME_POPUP_ADD_ANIMATION_NAME,
NAME_POPUP_EDIT_ANIMATION_NAME,
};
enum DeletePopupActions {
DELETE_POPUP_CATEGORY,
DELETE_POPUP_ANIMATION,
DELETE_POPUP_KEYFRAME,
};
@ -61,13 +58,12 @@ public:
void load_selected_animation();
void clear_keyframe_nodes();
void on_animation_option_button_pressed(int indx);
void on_category_option_button_pressed(int indx);
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 category_tool_button_id_pressed(int id);
void animation_tool_button_id_pressed(int id);
void show_name_popup(NamePopupActions action);
void on_name_popup_confirmed();
@ -85,10 +81,8 @@ protected:
static void _bind_methods();
private:
int _selected_category;
int _selected_animation;
OptionButton *_category_option_button;
OptionButton *_animation_option_button;
DeletePopupActions _delete_popup_action;

View File

@ -29,13 +29,6 @@ void ProceduralAnimationPlayer::set_animation(const Ref<ProceduralAnimation> &an
_animation = animation;
}
int ProceduralAnimationPlayer::get_current_category() const {
return _current_category;
}
void ProceduralAnimationPlayer::set_current_category(const int p_category) {
_current_category = p_category;
}
int ProceduralAnimationPlayer::get_current_animation() const {
return _current_animation;
}
@ -79,7 +72,6 @@ void ProceduralAnimationPlayer::advance(float p_delta) {
}
ProceduralAnimationPlayer::ProceduralAnimationPlayer() {
_current_category = 0;
_current_animation = 0;
_curent_keyframe = 0;
_scale = 1.0;
@ -91,39 +83,18 @@ ProceduralAnimationPlayer::~ProceduralAnimationPlayer() {
void ProceduralAnimationPlayer::_validate_property(PropertyInfo &property) const {
if (property.name == "current_category") {
if (property.name == "current_animation") {
if (_animation.is_valid()) {
String names;
PoolIntArray arr = _animation->get_category_indices();
PoolIntArray arr = _animation->get_animation_indices();
for (int i = 0; i < arr.size(); ++i) {
if (i > 0)
names += ",";
names += _animation->get_category_name(arr[i]);
}
property.hint = PROPERTY_HINT_ENUM;
property.hint_string = names;
} else {
property.hint = PROPERTY_HINT_NONE;
property.hint_string = "";
}
} else if (property.name == "current_animation") {
if (_animation.is_valid() && _animation->has_category(_current_category)) {
String names;
PoolIntArray arr = _animation->get_animation_indices(_current_category);
for (int i = 0; i < arr.size(); ++i) {
if (i > 0)
names += ",";
names += _animation->get_animation_name(_current_category, arr[i]);
names += _animation->get_animation_name(arr[i]);
}
property.hint = PROPERTY_HINT_ENUM;
@ -140,10 +111,6 @@ void ProceduralAnimationPlayer::_bind_methods() {
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_category"), &ProceduralAnimationPlayer::get_current_category);
ClassDB::bind_method(D_METHOD("set_current_category", "category"), &ProceduralAnimationPlayer::set_current_category);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_category"), "set_current_category", "get_current_category");
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");

View File

@ -36,9 +36,6 @@ public:
Ref<ProceduralAnimation> get_animation();
void set_animation(const Ref<ProceduralAnimation> &animation);
int get_current_category() const;
void set_current_category(const int p_category);
int get_current_animation() const;
void set_current_animation(const int p_animation);
@ -64,7 +61,7 @@ protected:
private:
Ref<ProceduralAnimation> _animation;
int _current_category;
int _current_animation;
int _curent_keyframe;
float _scale;