Fixed up the editor plugin. Also now ProceduralAnimation generates keys properly.

This commit is contained in:
Relintai 2020-03-31 23:42:26 +02:00
parent 16d0ff1ed1
commit ab4a274057
4 changed files with 159 additions and 145 deletions

View File

@ -79,6 +79,8 @@ int ProceduralAnimation::get_start_frame_index() const {
} }
void ProceduralAnimation::set_start_frame_index(const int value) { void ProceduralAnimation::set_start_frame_index(const int value) {
_start_frame_index = value; _start_frame_index = value;
process_animation_data();
} }
//Keyframes //Keyframes
@ -107,6 +109,8 @@ int ProceduralAnimation::add_keyframe() {
_keyframes[key] = entry; _keyframes[key] = entry;
process_animation_data();
return key; return key;
} }
void ProceduralAnimation::remove_keyframe(const int keyframe_index) { void ProceduralAnimation::remove_keyframe(const int keyframe_index) {
@ -117,6 +121,8 @@ void ProceduralAnimation::remove_keyframe(const int keyframe_index) {
_keyframes.erase(keyframe_index); _keyframes.erase(keyframe_index);
memdelete(entry); memdelete(entry);
process_animation_data();
} }
bool ProceduralAnimation::has_keyframe(const int keyframe_index) const { bool ProceduralAnimation::has_keyframe(const int keyframe_index) const {
@ -139,10 +145,12 @@ int ProceduralAnimation::get_keyframe_animation_keyframe_index(const int keyfram
return _keyframes[keyframe_index]->animation_keyframe_index; return _keyframes[keyframe_index]->animation_keyframe_index;
} }
void ProceduralAnimation::set_keyframe_animation_keyframe_index(const int keyframe_index, int value) { void ProceduralAnimation::set_keyframe_animation_keyframe_index(const int keyframe_index, const int value) {
ERR_FAIL_COND(!_keyframes.has(keyframe_index)); ERR_FAIL_COND(!_keyframes.has(keyframe_index));
_keyframes[keyframe_index]->animation_keyframe_index = value; _keyframes[keyframe_index]->animation_keyframe_index = value;
process_animation_data();
} }
int ProceduralAnimation::get_keyframe_next_keyframe_index(const int keyframe_index) const { int ProceduralAnimation::get_keyframe_next_keyframe_index(const int keyframe_index) const {
@ -154,6 +162,8 @@ void ProceduralAnimation::set_keyframe_next_keyframe_index(const int keyframe_in
ERR_FAIL_COND(!_keyframes.has(keyframe_index)); ERR_FAIL_COND(!_keyframes.has(keyframe_index));
_keyframes[keyframe_index]->next_keyframe = value; _keyframes[keyframe_index]->next_keyframe = value;
process_animation_data();
} }
Ref<Curve> ProceduralAnimation::get_keyframe_in_curve(const int keyframe_index) const { Ref<Curve> ProceduralAnimation::get_keyframe_in_curve(const int keyframe_index) const {
@ -165,6 +175,8 @@ void ProceduralAnimation::set_keyframe_in_curve(const int keyframe_index, const
ERR_FAIL_COND(!_keyframes.has(keyframe_index)); ERR_FAIL_COND(!_keyframes.has(keyframe_index));
_keyframes[keyframe_index]->in_curve = value; _keyframes[keyframe_index]->in_curve = value;
process_animation_data();
} }
Vector2 ProceduralAnimation::get_keyframe_node_position(const int keyframe_index) const { Vector2 ProceduralAnimation::get_keyframe_node_position(const int keyframe_index) const {
@ -178,8 +190,9 @@ void ProceduralAnimation::set_keyframe_node_position(const int keyframe_index, c
_keyframes[keyframe_index]->position = value; _keyframes[keyframe_index]->position = value;
} }
void ProceduralAnimation::initialize() { void ProceduralAnimation::process_animation_data() {
ERR_FAIL_COND(!_animation.is_valid()); if (!_animation.is_valid())
return;
clear(); clear();
@ -200,7 +213,6 @@ void ProceduralAnimation::initialize() {
} break; } break;
case Animation::TYPE_VALUE: { case Animation::TYPE_VALUE: {
value_track_set_update_mode(i, _animation->value_track_get_update_mode(i)); value_track_set_update_mode(i, _animation->value_track_get_update_mode(i));
value_track_set_update_mode(i, _animation->value_track_get_update_mode(i));
} break; } break;
case Animation::TYPE_METHOD: { case Animation::TYPE_METHOD: {
//nothing to do //nothing to do
@ -217,18 +229,18 @@ void ProceduralAnimation::initialize() {
} }
} }
float keyframe_time = 0; float target_keyframe_time = 0;
for (Map<int, AnimationKeyFrame *>::Element *K = _keyframes.front(); K; K = K->next()) { for (Map<int, AnimationKeyFrame *>::Element *K = _keyframes.front(); K; K = K->next()) {
int keyframe_index = K->get()->animation_keyframe_index; int keyframe_index = K->get()->animation_keyframe_index;
load_keyframe_data(keyframe_time, keyframe_index); load_keyframe_data(target_keyframe_time, keyframe_index);
//TODO add param //TODO add param
keyframe_time += 1.0; target_keyframe_time += 1.0;
} }
} }
void ProceduralAnimation::load_keyframe_data(const float keyframe_time, const int keyframe_index, const bool interpolation_allowed) { void ProceduralAnimation::load_keyframe_data(const float target_keyframe_time, const int keyframe_index, const bool interpolation_allowed) {
ERR_FAIL_COND(!_animation.is_valid()); ERR_FAIL_COND(!_animation.is_valid());
float time = keyframe_index * _animation->get_length() / static_cast<float>(_animation_fps); float time = keyframe_index * _animation->get_length() / static_cast<float>(_animation_fps);
@ -237,8 +249,14 @@ void ProceduralAnimation::load_keyframe_data(const float keyframe_time, const in
int key_index = _animation->track_find_key(i, time, true); int key_index = _animation->track_find_key(i, time, true);
if (key_index == -1) { if (key_index == -1) {
if (!interpolation_allowed) if (!interpolation_allowed) {
key_index = _animation->track_find_key(i, time, false);
if (key_index != -1)
track_insert_key(i, target_keyframe_time, _animation->track_get_key_value(i, key_index));
continue; continue;
}
//track doesn't have a key at the specified time. Try to create one with interpolations. //track doesn't have a key at the specified time. Try to create one with interpolations.
@ -248,7 +266,7 @@ void ProceduralAnimation::load_keyframe_data(const float keyframe_time, const in
case Animation::TYPE_VALUE: { case Animation::TYPE_VALUE: {
Variant val = value_track_interpolate(i, time); Variant val = value_track_interpolate(i, time);
track_insert_key(i, keyframe_time, val); track_insert_key(i, target_keyframe_time, val);
} break; } break;
case Animation::TYPE_TRANSFORM: { case Animation::TYPE_TRANSFORM: {
Vector3 loc; Vector3 loc;
@ -256,7 +274,7 @@ void ProceduralAnimation::load_keyframe_data(const float keyframe_time, const in
Vector3 scale; Vector3 scale;
if (_animation->transform_track_interpolate(i, time, &loc, &rot, &scale) == OK) { if (_animation->transform_track_interpolate(i, time, &loc, &rot, &scale) == OK) {
transform_track_insert_key(i, keyframe_time, loc, rot, scale); transform_track_insert_key(i, target_keyframe_time, loc, rot, scale);
} }
} break; } break;
case Animation::TYPE_METHOD: { case Animation::TYPE_METHOD: {
@ -269,7 +287,7 @@ void ProceduralAnimation::load_keyframe_data(const float keyframe_time, const in
} break; } break;
} }
} else { } else {
track_insert_key(i, keyframe_time, _animation->track_get_key_value(i, key_index)); track_insert_key(i, target_keyframe_time, _animation->track_get_key_value(i, key_index));
} }
} }
} }
@ -300,7 +318,7 @@ bool ProceduralAnimation::_set(const StringName &p_name, const Variant &p_value)
_start_frame_index = p_value; _start_frame_index = p_value;
return true; return true;
} else if (name == "keyframe") { } else if (name.get_slicec('/', 0) == "keyframe") {
int keyframe_index = name.get_slicec('/', 1).to_int(); int keyframe_index = name.get_slicec('/', 1).to_int();
String keyframe_name = name.get_slicec('/', 2); String keyframe_name = name.get_slicec('/', 2);
@ -353,7 +371,7 @@ bool ProceduralAnimation::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = _start_frame_index; r_ret = _start_frame_index;
return true; return true;
} else if (name == "keyframe") { } else if (name.get_slicec('/', 0) == "keyframe") {
int keyframe_index = name.get_slicec('/', 1).to_int(); int keyframe_index = name.get_slicec('/', 1).to_int();
String keyframe_prop_name = name.get_slicec('/', 2); String keyframe_prop_name = name.get_slicec('/', 2);
@ -393,7 +411,7 @@ void ProceduralAnimation::_get_property_list(List<PropertyInfo> *p_list) const {
//int property_usange = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL; //int property_usange = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL;
int property_usange = PROPERTY_USAGE_DEFAULT; int property_usange = PROPERTY_USAGE_DEFAULT;
p_list->push_back(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "", property_usange)); p_list->push_back(PropertyInfo(Variant::VECTOR2, "start_node_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::INT, "start_frame_index", PROPERTY_HINT_NONE, "", property_usange));
for (Map<int, AnimationKeyFrame *>::Element *K = _keyframes.front(); K; K = K->next()) { for (Map<int, AnimationKeyFrame *>::Element *K = _keyframes.front(); K; K = K->next()) {
@ -446,6 +464,6 @@ void ProceduralAnimation::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_keyframe_node_position", "keyframe_index"), &ProceduralAnimation::get_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("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("process_animation_data"), &ProceduralAnimation::process_animation_data);
ClassDB::bind_method(D_METHOD("load_keyframe_data", "keyframe_index", "keyframe_index", "interpolation_allowed"), &ProceduralAnimation::load_keyframe_data, DEFVAL(false)); ClassDB::bind_method(D_METHOD("load_keyframe_data", "keyframe_index", "keyframe_index", "interpolation_allowed"), &ProceduralAnimation::load_keyframe_data, DEFVAL(false));
} }

View File

@ -83,7 +83,7 @@ public:
void set_keyframe_name(const int keyframe_index, const String &value); void set_keyframe_name(const int keyframe_index, const String &value);
int get_keyframe_animation_keyframe_index(const int keyframe_index) const; int get_keyframe_animation_keyframe_index(const int keyframe_index) const;
void set_keyframe_animation_keyframe_index(const int keyframe_index, int value); void set_keyframe_animation_keyframe_index(const int keyframe_index, const int value);
int get_keyframe_next_keyframe_index(const int keyframe_index) const; int get_keyframe_next_keyframe_index(const int keyframe_index) const;
void set_keyframe_next_keyframe_index(const int keyframe_index, const int value); void set_keyframe_next_keyframe_index(const int keyframe_index, const int value);
@ -94,7 +94,7 @@ public:
Vector2 get_keyframe_node_position(const int keyframe_index) const; Vector2 get_keyframe_node_position(const int keyframe_index) const;
void set_keyframe_node_position(const int keyframe_index, const Vector2 &value); void set_keyframe_node_position(const int keyframe_index, const Vector2 &value);
void initialize(); void process_animation_data();
void load_keyframe_data(const float keyframe_time, const int keyframe_index, const bool interpolation_allowed = false); void load_keyframe_data(const float keyframe_time, const int keyframe_index, const bool interpolation_allowed = false);
ProceduralAnimation(); ProceduralAnimation();

View File

@ -24,19 +24,18 @@ SOFTWARE.
#include "editor/editor_scale.h" #include "editor/editor_scale.h"
// S -------- ProceduralAnimationEditor --------
void ProceduralAnimationEditor::edit(const Ref<ProceduralAnimation> &animation) { void ProceduralAnimationEditor::edit(const Ref<ProceduralAnimation> &animation) {
_animation = animation; _animation = animation;
_stop->hide();
_play->hide();
_play_from->hide();
_play_bw->hide();
_play_bw_from->hide();
clear_keyframe_nodes(); clear_keyframe_nodes();
if (animation.is_valid())
load_animation();
} }
void ProceduralAnimationEditor::load_selected_animation() { void ProceduralAnimationEditor::load_animation() {
clear_keyframe_nodes(); clear_keyframe_nodes();
ERR_FAIL_COND(!_animation.is_valid()); ERR_FAIL_COND(!_animation.is_valid());
@ -51,18 +50,10 @@ void ProceduralAnimationEditor::load_selected_animation() {
int id = kfind[i]; int id = kfind[i];
ProceduralAnimationEditorGraphNode *gn = memnew(ProceduralAnimationEditorGraphNode); ProceduralAnimationEditorGraphNode *gn = memnew(ProceduralAnimationEditorGraphNode);
gn->set_name(String::num(id));
_graph_edit->add_child(gn); _graph_edit->add_child(gn);
gn->set_name(String::num(id));
//gn->set_animation_keyframe_names(animation_names);
gn->set_id(id); gn->set_id(id);
gn->set_offset(_animation->get_keyframe_node_position(id)); gn->set_animation(_animation);
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) { for (int i = 0; i < kfind.size(); ++i) {
@ -86,32 +77,21 @@ void ProceduralAnimationEditor::clear_keyframe_nodes() {
for (int i = 0; i < _graph_edit->get_child_count(); ++i) { for (int i = 0; i < _graph_edit->get_child_count(); ++i) {
Node *n = _graph_edit->get_child(i); Node *n = _graph_edit->get_child(i);
if (n == _start_node) {
continue;
}
ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(n); ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(n);
if (!ObjectDB::instance_validate(gn)) { if (!ObjectDB::instance_validate(gn)) {
continue; continue;
} }
gn->disconnect("graphnode_changed", this, "on_keyframe_node_changed"); gn->set_name("d" + gn->get_name());
gn->queue_delete(); gn->queue_delete();
} }
} }
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());
int id = gn->get_id();
_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() { void ProceduralAnimationEditor::on_delete_popup_confirmed() {
switch (_delete_popup_action) { switch (_delete_popup_action) {
case DELETE_POPUP_KEYFRAME: case DELETE_POPUP_KEYFRAME:
@ -178,13 +158,6 @@ void ProceduralAnimationEditor::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
_play->set_icon(get_icon("PlayStart", "EditorIcons"));
_play_from->set_icon(get_icon("Play", "EditorIcons"));
_play_bw->set_icon(get_icon("PlayStartBackwards", "EditorIcons"));
_play_bw_from->set_icon(get_icon("PlayBackwards", "EditorIcons"));
_stop->set_icon(get_icon("Stop", "EditorIcons"));
_pin->set_icon(get_icon("Pin", "EditorIcons")); _pin->set_icon(get_icon("Pin", "EditorIcons"));
} break; } break;
} }
@ -195,8 +168,6 @@ void ProceduralAnimationEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_frame_button_pressed"), &ProceduralAnimationEditor::add_frame_button_pressed); ClassDB::bind_method(D_METHOD("add_frame_button_pressed"), &ProceduralAnimationEditor::add_frame_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); ClassDB::bind_method(D_METHOD("on_connection_request", "from", "from_slot", "to", "to_slot"), &ProceduralAnimationEditor::on_connection_request);
ClassDB::bind_method(D_METHOD("on_disconnection_request", "from", "from_slot", "to", "to_slot"), &ProceduralAnimationEditor::on_disconnection_request); ClassDB::bind_method(D_METHOD("on_disconnection_request", "from", "from_slot", "to", "to_slot"), &ProceduralAnimationEditor::on_disconnection_request);
} }
@ -211,37 +182,15 @@ ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
HBoxContainer *hbc = memnew(HBoxContainer); HBoxContainer *hbc = memnew(HBoxContainer);
add_child(hbc); add_child(hbc);
_animation_option_button = memnew(OptionButton); Control *spacer = memnew(Control);
_animation_option_button->set_h_size_flags(SIZE_EXPAND_FILL); spacer->set_h_size_flags(SIZE_EXPAND_FILL);
_animation_option_button->connect("item_selected", this, "on_animation_option_button_pressed"); hbc->add_child(spacer);
hbc->add_child(_animation_option_button);
Button *aafb = memnew(Button); Button *aafb = memnew(Button);
aafb->set_text("add frame"); aafb->set_text("add frame");
aafb->connect("pressed", this, "add_frame_button_pressed"); aafb->connect("pressed", this, "add_frame_button_pressed");
hbc->add_child(aafb); hbc->add_child(aafb);
_play_bw_from = memnew(ToolButton);
_play_bw_from->set_tooltip(TTR("Play selected animation backwards from current pos. (A)"));
hbc->add_child(_play_bw_from);
_play_bw = memnew(ToolButton);
_play_bw->set_tooltip(TTR("Play selected animation backwards from end. (Shift+A)"));
hbc->add_child(_play_bw);
_stop = memnew(ToolButton);
_stop->set_toggle_mode(true);
hbc->add_child(_stop);
_stop->set_tooltip(TTR("Stop animation playback. (S)"));
_play = memnew(ToolButton);
_play->set_tooltip(TTR("Play selected animation from start. (Shift+D)"));
hbc->add_child(_play);
_play_from = memnew(ToolButton);
_play_from->set_tooltip(TTR("Play selected animation from current pos. (D)"));
hbc->add_child(_play_from);
_pin = memnew(ToolButton); _pin = memnew(ToolButton);
_pin->set_toggle_mode(true); _pin->set_toggle_mode(true);
_pin->set_tooltip(TTR("Pin")); _pin->set_tooltip(TTR("Pin"));
@ -300,12 +249,15 @@ ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
ProceduralAnimationEditor::~ProceduralAnimationEditor() { ProceduralAnimationEditor::~ProceduralAnimationEditor() {
} }
// E -------- ProceduralAnimationEditor --------
// S -------- ProceduralAnimationEditorGraphNode --------
int ProceduralAnimationEditorGraphNode::get_id() const { int ProceduralAnimationEditorGraphNode::get_id() const {
return _id; return _id;
} }
void ProceduralAnimationEditorGraphNode::set_id(const int id) { void ProceduralAnimationEditorGraphNode::set_id(const int id) {
_id = id; _id = id;
emit_signal("graphnode_changed", this);
} }
String ProceduralAnimationEditorGraphNode::get_keyframe_name() const { String ProceduralAnimationEditorGraphNode::get_keyframe_name() const {
@ -313,10 +265,16 @@ String ProceduralAnimationEditorGraphNode::get_keyframe_name() const {
} }
void ProceduralAnimationEditorGraphNode::set_keyframe_name(const String &value) { void ProceduralAnimationEditorGraphNode::set_keyframe_name(const String &value) {
_name->set_text(value); _name->set_text(value);
emit_signal("graphnode_changed", this);
if (!_animation.is_valid())
return;
_animation->set_keyframe_name(_id, value);
changed();
} }
void ProceduralAnimationEditorGraphNode::on_keyframe_name_modified(const String &value) { void ProceduralAnimationEditorGraphNode::on_keyframe_name_modified(const String &value) {
emit_signal("graphnode_changed", this); set_keyframe_name(value);
} }
int ProceduralAnimationEditorGraphNode::get_animation_keyframe_index() const { int ProceduralAnimationEditorGraphNode::get_animation_keyframe_index() const {
@ -326,13 +284,16 @@ void ProceduralAnimationEditorGraphNode::set_animation_keyframe_index(const int
if (_animation_keyframe_index == value) if (_animation_keyframe_index == value)
return; return;
if (_animation_keyframe_spinbox->get_line_edit()->get_text().to_int() != value) { _animation_keyframe_spinbox->set_value(value);
_animation_keyframe_spinbox->get_line_edit()->set_text(String::num(value));
}
_animation_keyframe_index = value; _animation_keyframe_index = value;
//_animation_keyframe_index_option_button->select(value);
emit_signal("graphnode_changed", this); if (!_animation.is_valid())
return;
_animation->set_keyframe_animation_keyframe_index(_id, value);
changed();
} }
int ProceduralAnimationEditorGraphNode::get_next_keyframe() const { int ProceduralAnimationEditorGraphNode::get_next_keyframe() const {
@ -340,7 +301,13 @@ int ProceduralAnimationEditorGraphNode::get_next_keyframe() const {
} }
void ProceduralAnimationEditorGraphNode::set_next_keyframe(const int value) { void ProceduralAnimationEditorGraphNode::set_next_keyframe(const int value) {
_next_keyframe = value; _next_keyframe = value;
emit_signal("graphnode_changed", this);
if (!_animation.is_valid())
return;
_animation->set_keyframe_next_keyframe_index(_id, value);
changed();
} }
Ref<Curve> ProceduralAnimationEditorGraphNode::get_in_curve() const { Ref<Curve> ProceduralAnimationEditorGraphNode::get_in_curve() const {
@ -354,25 +321,31 @@ void ProceduralAnimationEditorGraphNode::set_in_curve(const Ref<Curve> &value) {
_in_curve = value; _in_curve = value;
_curve_editor->set_curve(value); _curve_editor->set_curve(value);
_in_curve->connect(CoreStringNames::get_singleton()->changed, this, "changed"); _in_curve->connect(CoreStringNames::get_singleton()->changed, this, "changed");
emit_signal("graphnode_changed", this);
if (!_animation.is_valid())
return;
_animation->set_keyframe_in_curve(_id, _in_curve);
changed();
} }
void ProceduralAnimationEditorGraphNode::set_animation_keyframe_names(const PoolVector<String> &names) { Ref<ProceduralAnimation> ProceduralAnimationEditorGraphNode::get_animation() {
//_animation_keyframe_index_option_button->clear(); return _animation;
//for (int i = 0; i < names.size(); ++i) {
// const String &s = names[i];
// _animation_keyframe_index_option_button->add_item(s, s.get_slicec(' ', 0).to_int());
//}
} }
void ProceduralAnimationEditorGraphNode::set_animation(const Ref<ProceduralAnimation> &animation) {
_animation.unref();
void ProceduralAnimationEditorGraphNode::on_animation_keyframe_spinbox_value_changed(const String &value) { if (!animation.is_valid())
set_animation_keyframe_index(value.to_int()); return;
}
void ProceduralAnimationEditorGraphNode::changed() { set_offset(animation->get_keyframe_node_position(_id));
emit_signal("graphnode_changed", this); set_keyframe_name(animation->get_keyframe_name(_id));
set_next_keyframe(animation->get_keyframe_next_keyframe_index(_id));
set_in_curve(animation->get_keyframe_in_curve(_id));
set_animation_keyframe_index(animation->get_keyframe_animation_keyframe_index(_id));
_animation = animation;
} }
ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() { ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() {
@ -399,21 +372,9 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() {
_animation_keyframe_spinbox = memnew(SpinBox); _animation_keyframe_spinbox = memnew(SpinBox);
_animation_keyframe_spinbox->set_max(999999999); _animation_keyframe_spinbox->set_max(999999999);
_animation_keyframe_spinbox->set_h_size_flags(SIZE_EXPAND_FILL); _animation_keyframe_spinbox->set_h_size_flags(SIZE_EXPAND_FILL);
_animation_keyframe_spinbox->get_line_edit()->connect("text_changed", this, "on_animation_keyframe_spinbox_value_changed"); _animation_keyframe_spinbox->connect("value_changed", this, "on_animation_keyframe_spinbox_value_changed");
add_child(_animation_keyframe_spinbox); add_child(_animation_keyframe_spinbox);
//HBoxContainer *kfc = memnew(HBoxContainer);
//add_child(kfc);
//_animation_keyframe_index_option_button = memnew(OptionButton);
//_animation_keyframe_index_option_button->set_h_size_flags(SIZE_EXPAND_FILL);
//_animation_keyframe_index_option_button->connect("item_selected", this, "set_animation_keyframe_index");
//kfc->add_child(_animation_keyframe_index_option_button);
//Button *kb = memnew(Button);
//kb->set_text("E");
//kfc->add_child(kb);
Label *l3 = memnew(Label); Label *l3 = memnew(Label);
l3->set_text("In Curve"); l3->set_text("In Curve");
add_child(l3); add_child(l3);
@ -429,6 +390,23 @@ ProceduralAnimationEditorGraphNode::~ProceduralAnimationEditorGraphNode() {
_in_curve.unref(); _in_curve.unref();
} }
void ProceduralAnimationEditorGraphNode::on_animation_keyframe_spinbox_value_changed(float value) {
set_animation_keyframe_index(value);
}
void ProceduralAnimationEditorGraphNode::on_dragged(Vector2 from, Vector2 to) {
if (!_animation.is_valid())
return;
_animation->set_keyframe_node_position(_id, get_offset());
changed();
}
void ProceduralAnimationEditorGraphNode::changed() {
emit_signal("graphnode_changed", this);
}
void ProceduralAnimationEditorGraphNode::_notification(int p_what) { void ProceduralAnimationEditorGraphNode::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: case NOTIFICATION_ENTER_TREE:
@ -443,8 +421,14 @@ void ProceduralAnimationEditorGraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("on_keyframe_name_modified", "name"), &ProceduralAnimationEditorGraphNode::on_keyframe_name_modified); ClassDB::bind_method(D_METHOD("on_keyframe_name_modified", "name"), &ProceduralAnimationEditorGraphNode::on_keyframe_name_modified);
ClassDB::bind_method(D_METHOD("changed"), &ProceduralAnimationEditorGraphNode::changed); ClassDB::bind_method(D_METHOD("changed"), &ProceduralAnimationEditorGraphNode::changed);
ClassDB::bind_method(D_METHOD("on_animation_keyframe_spinbox_value_changed", "value"), &ProceduralAnimationEditorGraphNode::on_animation_keyframe_spinbox_value_changed); ClassDB::bind_method(D_METHOD("on_animation_keyframe_spinbox_value_changed", "value"), &ProceduralAnimationEditorGraphNode::on_animation_keyframe_spinbox_value_changed);
ClassDB::bind_method(D_METHOD("on_dragged", "from", "to"), &ProceduralAnimationEditorGraphNode::on_dragged);
} }
// E -------- ProceduralAnimationEditorGraphNode --------
// S -------- ProceduralAnimationEditorPlugin --------
void ProceduralAnimationEditorPlugin::edit(Object *p_object) { void ProceduralAnimationEditorPlugin::edit(Object *p_object) {
if (Object::cast_to<ProceduralAnimation>(p_object)) { if (Object::cast_to<ProceduralAnimation>(p_object)) {
animation_editor->edit(Object::cast_to<ProceduralAnimation>(p_object)); animation_editor->edit(Object::cast_to<ProceduralAnimation>(p_object));
@ -456,21 +440,32 @@ void ProceduralAnimationEditorPlugin::edit(Object *p_object) {
} }
bool ProceduralAnimationEditorPlugin::handles(Object *p_object) const { bool ProceduralAnimationEditorPlugin::handles(Object *p_object) const {
bool player = p_object->is_class("ProceduralAnimationPlayer"); if (p_object->is_class("ProceduralAnimation")) {
bool handles = p_object->is_class("ProceduralAnimation") || player;
if (handles) {
animation_editor_button->show(); animation_editor_button->show();
animation_editor_button->set_pressed(true);
if (player) return true;
animation_editor_button->set_pressed(true);
} else {
animation_editor_button->set_pressed(false);
animation_editor_button->hide();
} }
return handles; if (p_object->is_class("AnimationPlayer")) {
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(p_object);
String an = player->get_assigned_animation();
if (an != "") {
Ref<ProceduralAnimation> anim = player->get_animation(an);
if (anim.is_valid()) {
animation_editor_button->show();
//animation_editor_button->set_pressed(true);
return true;
}
}
}
animation_editor_button->set_pressed(false);
animation_editor_button->hide();
return false;
} }
void ProceduralAnimationEditorPlugin::make_visible(bool p_visible) { void ProceduralAnimationEditorPlugin::make_visible(bool p_visible) {
@ -489,3 +484,5 @@ ProceduralAnimationEditorPlugin::ProceduralAnimationEditorPlugin(EditorNode *p_n
ProceduralAnimationEditorPlugin::~ProceduralAnimationEditorPlugin() { ProceduralAnimationEditorPlugin::~ProceduralAnimationEditorPlugin() {
} }
// E -------- ProceduralAnimationEditorPlugin --------

View File

@ -47,7 +47,7 @@ public:
void add_frame_button_pressed(); void add_frame_button_pressed();
void load_selected_animation(); void load_animation();
void clear_keyframe_nodes(); void clear_keyframe_nodes();
void on_keyframe_node_changed(Node *node); void on_keyframe_node_changed(Node *node);
@ -66,8 +66,6 @@ protected:
static void _bind_methods(); static void _bind_methods();
private: private:
OptionButton *_animation_option_button;
DeletePopupActions _delete_popup_action; DeletePopupActions _delete_popup_action;
ConfirmationDialog *_delete_popuop; ConfirmationDialog *_delete_popuop;
@ -79,11 +77,6 @@ private:
Ref<ProceduralAnimation> _animation; Ref<ProceduralAnimation> _animation;
GraphEdit *_graph_edit; GraphEdit *_graph_edit;
Button *_stop;
Button *_play;
Button *_play_from;
Button *_play_bw;
Button *_play_bw_from;
ToolButton *_pin; ToolButton *_pin;
}; };
@ -107,15 +100,18 @@ public:
Ref<Curve> get_in_curve() const; Ref<Curve> get_in_curve() const;
void set_in_curve(const Ref<Curve> &value); void set_in_curve(const Ref<Curve> &value);
void set_animation_keyframe_names(const PoolVector<String> &names); Ref<ProceduralAnimation> get_animation();
void set_animation(const Ref<ProceduralAnimation> &animation);
void on_animation_keyframe_spinbox_value_changed(const String &value);
void changed();
ProceduralAnimationEditorGraphNode(); ProceduralAnimationEditorGraphNode();
~ProceduralAnimationEditorGraphNode(); ~ProceduralAnimationEditorGraphNode();
protected: protected:
void on_animation_keyframe_spinbox_value_changed(float value);
void on_dragged(Vector2 from, Vector2 to);
void changed();
void _notification(int p_what); void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
@ -123,10 +119,13 @@ private:
int _id; int _id;
LineEdit *_name; LineEdit *_name;
SpinBox *_animation_keyframe_spinbox; SpinBox *_animation_keyframe_spinbox;
int _animation_keyframe_index; int _animation_keyframe_index;
int _next_keyframe; int _next_keyframe;
CurveEditor *_curve_editor; CurveEditor *_curve_editor;
Ref<Curve> _in_curve; Ref<Curve> _in_curve;
Ref<ProceduralAnimation> _animation;
}; };
class ProceduralAnimationEditorPlugin : public EditorPlugin { class ProceduralAnimationEditorPlugin : public EditorPlugin {