mirror of
https://github.com/Relintai/procedural_animations.git
synced 2024-11-08 20:22:10 +01:00
Fixed up the editor plugin. Also now ProceduralAnimation generates keys properly.
This commit is contained in:
parent
16d0ff1ed1
commit
ab4a274057
@ -79,6 +79,8 @@ int ProceduralAnimation::get_start_frame_index() const {
|
||||
}
|
||||
void ProceduralAnimation::set_start_frame_index(const int value) {
|
||||
_start_frame_index = value;
|
||||
|
||||
process_animation_data();
|
||||
}
|
||||
|
||||
//Keyframes
|
||||
@ -107,6 +109,8 @@ int ProceduralAnimation::add_keyframe() {
|
||||
|
||||
_keyframes[key] = entry;
|
||||
|
||||
process_animation_data();
|
||||
|
||||
return key;
|
||||
}
|
||||
void ProceduralAnimation::remove_keyframe(const int keyframe_index) {
|
||||
@ -117,6 +121,8 @@ void ProceduralAnimation::remove_keyframe(const int keyframe_index) {
|
||||
_keyframes.erase(keyframe_index);
|
||||
|
||||
memdelete(entry);
|
||||
|
||||
process_animation_data();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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));
|
||||
|
||||
_keyframes[keyframe_index]->animation_keyframe_index = value;
|
||||
|
||||
process_animation_data();
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
_keyframes[keyframe_index]->next_keyframe = value;
|
||||
|
||||
process_animation_data();
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
_keyframes[keyframe_index]->in_curve = value;
|
||||
|
||||
process_animation_data();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void ProceduralAnimation::initialize() {
|
||||
ERR_FAIL_COND(!_animation.is_valid());
|
||||
void ProceduralAnimation::process_animation_data() {
|
||||
if (!_animation.is_valid())
|
||||
return;
|
||||
|
||||
clear();
|
||||
|
||||
@ -200,7 +213,6 @@ void ProceduralAnimation::initialize() {
|
||||
} break;
|
||||
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));
|
||||
} break;
|
||||
case Animation::TYPE_METHOD: {
|
||||
//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()) {
|
||||
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
|
||||
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());
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//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: {
|
||||
Variant val = value_track_interpolate(i, time);
|
||||
|
||||
track_insert_key(i, keyframe_time, val);
|
||||
track_insert_key(i, target_keyframe_time, val);
|
||||
} break;
|
||||
case Animation::TYPE_TRANSFORM: {
|
||||
Vector3 loc;
|
||||
@ -256,7 +274,7 @@ void ProceduralAnimation::load_keyframe_data(const float keyframe_time, const in
|
||||
Vector3 scale;
|
||||
|
||||
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;
|
||||
case Animation::TYPE_METHOD: {
|
||||
@ -269,7 +287,7 @@ void ProceduralAnimation::load_keyframe_data(const float keyframe_time, const in
|
||||
} break;
|
||||
}
|
||||
} 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;
|
||||
|
||||
return true;
|
||||
} else if (name == "keyframe") {
|
||||
} else if (name.get_slicec('/', 0) == "keyframe") {
|
||||
int keyframe_index = name.get_slicec('/', 1).to_int();
|
||||
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;
|
||||
|
||||
return true;
|
||||
} else if (name == "keyframe") {
|
||||
} else if (name.get_slicec('/', 0) == "keyframe") {
|
||||
int keyframe_index = name.get_slicec('/', 1).to_int();
|
||||
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_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));
|
||||
|
||||
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("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));
|
||||
}
|
@ -83,7 +83,7 @@ public:
|
||||
void set_keyframe_name(const int keyframe_index, const String &value);
|
||||
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
|
||||
ProceduralAnimation();
|
||||
|
@ -24,19 +24,18 @@ SOFTWARE.
|
||||
|
||||
#include "editor/editor_scale.h"
|
||||
|
||||
// S -------- ProceduralAnimationEditor --------
|
||||
|
||||
void ProceduralAnimationEditor::edit(const Ref<ProceduralAnimation> &animation) {
|
||||
_animation = animation;
|
||||
|
||||
_stop->hide();
|
||||
_play->hide();
|
||||
_play_from->hide();
|
||||
_play_bw->hide();
|
||||
_play_bw_from->hide();
|
||||
|
||||
clear_keyframe_nodes();
|
||||
|
||||
if (animation.is_valid())
|
||||
load_animation();
|
||||
}
|
||||
|
||||
void ProceduralAnimationEditor::load_selected_animation() {
|
||||
void ProceduralAnimationEditor::load_animation() {
|
||||
clear_keyframe_nodes();
|
||||
|
||||
ERR_FAIL_COND(!_animation.is_valid());
|
||||
@ -51,18 +50,10 @@ void ProceduralAnimationEditor::load_selected_animation() {
|
||||
int id = kfind[i];
|
||||
|
||||
ProceduralAnimationEditorGraphNode *gn = memnew(ProceduralAnimationEditorGraphNode);
|
||||
gn->set_name(String::num(id));
|
||||
_graph_edit->add_child(gn);
|
||||
|
||||
//gn->set_animation_keyframe_names(animation_names);
|
||||
|
||||
gn->set_name(String::num(id));
|
||||
gn->set_id(id);
|
||||
gn->set_offset(_animation->get_keyframe_node_position(id));
|
||||
gn->set_keyframe_name(_animation->get_keyframe_name(id));
|
||||
gn->set_next_keyframe(_animation->get_keyframe_next_keyframe_index(id));
|
||||
gn->set_in_curve(_animation->get_keyframe_in_curve(id));
|
||||
gn->set_animation_keyframe_index(_animation->get_keyframe_animation_keyframe_index(id));
|
||||
gn->connect("graphnode_changed", this, "on_keyframe_node_changed");
|
||||
gn->set_animation(_animation);
|
||||
}
|
||||
|
||||
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) {
|
||||
Node *n = _graph_edit->get_child(i);
|
||||
|
||||
if (n == _start_node) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(n);
|
||||
|
||||
if (!ObjectDB::instance_validate(gn)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
gn->disconnect("graphnode_changed", this, "on_keyframe_node_changed");
|
||||
gn->set_name("d" + gn->get_name());
|
||||
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() {
|
||||
switch (_delete_popup_action) {
|
||||
case DELETE_POPUP_KEYFRAME:
|
||||
@ -178,13 +158,6 @@ void ProceduralAnimationEditor::_notification(int p_what) {
|
||||
|
||||
switch (p_what) {
|
||||
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"));
|
||||
} 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("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_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);
|
||||
add_child(hbc);
|
||||
|
||||
_animation_option_button = memnew(OptionButton);
|
||||
_animation_option_button->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
_animation_option_button->connect("item_selected", this, "on_animation_option_button_pressed");
|
||||
hbc->add_child(_animation_option_button);
|
||||
Control *spacer = memnew(Control);
|
||||
spacer->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
hbc->add_child(spacer);
|
||||
|
||||
Button *aafb = memnew(Button);
|
||||
aafb->set_text("add frame");
|
||||
aafb->connect("pressed", this, "add_frame_button_pressed");
|
||||
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->set_toggle_mode(true);
|
||||
_pin->set_tooltip(TTR("Pin"));
|
||||
@ -300,12 +249,15 @@ ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
|
||||
ProceduralAnimationEditor::~ProceduralAnimationEditor() {
|
||||
}
|
||||
|
||||
// E -------- ProceduralAnimationEditor --------
|
||||
|
||||
// S -------- ProceduralAnimationEditorGraphNode --------
|
||||
|
||||
int ProceduralAnimationEditorGraphNode::get_id() const {
|
||||
return _id;
|
||||
}
|
||||
void ProceduralAnimationEditorGraphNode::set_id(const int id) {
|
||||
_id = id;
|
||||
emit_signal("graphnode_changed", this);
|
||||
}
|
||||
|
||||
String ProceduralAnimationEditorGraphNode::get_keyframe_name() const {
|
||||
@ -313,10 +265,16 @@ String ProceduralAnimationEditorGraphNode::get_keyframe_name() const {
|
||||
}
|
||||
void ProceduralAnimationEditorGraphNode::set_keyframe_name(const String &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) {
|
||||
emit_signal("graphnode_changed", this);
|
||||
set_keyframe_name(value);
|
||||
}
|
||||
|
||||
int ProceduralAnimationEditorGraphNode::get_animation_keyframe_index() const {
|
||||
@ -326,13 +284,16 @@ void ProceduralAnimationEditorGraphNode::set_animation_keyframe_index(const int
|
||||
if (_animation_keyframe_index == value)
|
||||
return;
|
||||
|
||||
if (_animation_keyframe_spinbox->get_line_edit()->get_text().to_int() != value) {
|
||||
_animation_keyframe_spinbox->get_line_edit()->set_text(String::num(value));
|
||||
}
|
||||
_animation_keyframe_spinbox->set_value(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 {
|
||||
@ -340,7 +301,13 @@ int ProceduralAnimationEditorGraphNode::get_next_keyframe() const {
|
||||
}
|
||||
void ProceduralAnimationEditorGraphNode::set_next_keyframe(const int 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 {
|
||||
@ -354,25 +321,31 @@ void ProceduralAnimationEditorGraphNode::set_in_curve(const Ref<Curve> &value) {
|
||||
_in_curve = value;
|
||||
_curve_editor->set_curve(value);
|
||||
_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) {
|
||||
//_animation_keyframe_index_option_button->clear();
|
||||
|
||||
//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());
|
||||
//}
|
||||
Ref<ProceduralAnimation> ProceduralAnimationEditorGraphNode::get_animation() {
|
||||
return _animation;
|
||||
}
|
||||
void ProceduralAnimationEditorGraphNode::set_animation(const Ref<ProceduralAnimation> &animation) {
|
||||
_animation.unref();
|
||||
|
||||
void ProceduralAnimationEditorGraphNode::on_animation_keyframe_spinbox_value_changed(const String &value) {
|
||||
set_animation_keyframe_index(value.to_int());
|
||||
}
|
||||
if (!animation.is_valid())
|
||||
return;
|
||||
|
||||
void ProceduralAnimationEditorGraphNode::changed() {
|
||||
emit_signal("graphnode_changed", this);
|
||||
set_offset(animation->get_keyframe_node_position(_id));
|
||||
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() {
|
||||
@ -399,21 +372,9 @@ ProceduralAnimationEditorGraphNode::ProceduralAnimationEditorGraphNode() {
|
||||
_animation_keyframe_spinbox = memnew(SpinBox);
|
||||
_animation_keyframe_spinbox->set_max(999999999);
|
||||
_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);
|
||||
|
||||
//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);
|
||||
l3->set_text("In Curve");
|
||||
add_child(l3);
|
||||
@ -429,6 +390,23 @@ ProceduralAnimationEditorGraphNode::~ProceduralAnimationEditorGraphNode() {
|
||||
_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) {
|
||||
switch (p_what) {
|
||||
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("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_dragged", "from", "to"), &ProceduralAnimationEditorGraphNode::on_dragged);
|
||||
}
|
||||
|
||||
// E -------- ProceduralAnimationEditorGraphNode --------
|
||||
|
||||
// S -------- ProceduralAnimationEditorPlugin --------
|
||||
|
||||
void ProceduralAnimationEditorPlugin::edit(Object *p_object) {
|
||||
if (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 player = p_object->is_class("ProceduralAnimationPlayer");
|
||||
bool handles = p_object->is_class("ProceduralAnimation") || player;
|
||||
|
||||
if (handles) {
|
||||
if (p_object->is_class("ProceduralAnimation")) {
|
||||
animation_editor_button->show();
|
||||
|
||||
if (player)
|
||||
animation_editor_button->set_pressed(true);
|
||||
} else {
|
||||
animation_editor_button->set_pressed(false);
|
||||
|
||||
animation_editor_button->hide();
|
||||
animation_editor_button->set_pressed(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -489,3 +484,5 @@ ProceduralAnimationEditorPlugin::ProceduralAnimationEditorPlugin(EditorNode *p_n
|
||||
|
||||
ProceduralAnimationEditorPlugin::~ProceduralAnimationEditorPlugin() {
|
||||
}
|
||||
|
||||
// E -------- ProceduralAnimationEditorPlugin --------
|
@ -47,7 +47,7 @@ public:
|
||||
|
||||
void add_frame_button_pressed();
|
||||
|
||||
void load_selected_animation();
|
||||
void load_animation();
|
||||
void clear_keyframe_nodes();
|
||||
|
||||
void on_keyframe_node_changed(Node *node);
|
||||
@ -66,8 +66,6 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
OptionButton *_animation_option_button;
|
||||
|
||||
DeletePopupActions _delete_popup_action;
|
||||
ConfirmationDialog *_delete_popuop;
|
||||
|
||||
@ -79,11 +77,6 @@ private:
|
||||
Ref<ProceduralAnimation> _animation;
|
||||
GraphEdit *_graph_edit;
|
||||
|
||||
Button *_stop;
|
||||
Button *_play;
|
||||
Button *_play_from;
|
||||
Button *_play_bw;
|
||||
Button *_play_bw_from;
|
||||
ToolButton *_pin;
|
||||
};
|
||||
|
||||
@ -107,15 +100,18 @@ public:
|
||||
Ref<Curve> get_in_curve() const;
|
||||
void set_in_curve(const Ref<Curve> &value);
|
||||
|
||||
void set_animation_keyframe_names(const PoolVector<String> &names);
|
||||
|
||||
void on_animation_keyframe_spinbox_value_changed(const String &value);
|
||||
void changed();
|
||||
Ref<ProceduralAnimation> get_animation();
|
||||
void set_animation(const Ref<ProceduralAnimation> &animation);
|
||||
|
||||
ProceduralAnimationEditorGraphNode();
|
||||
~ProceduralAnimationEditorGraphNode();
|
||||
|
||||
protected:
|
||||
void on_animation_keyframe_spinbox_value_changed(float value);
|
||||
void on_dragged(Vector2 from, Vector2 to);
|
||||
|
||||
void changed();
|
||||
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
@ -123,10 +119,13 @@ private:
|
||||
int _id;
|
||||
LineEdit *_name;
|
||||
SpinBox *_animation_keyframe_spinbox;
|
||||
|
||||
int _animation_keyframe_index;
|
||||
int _next_keyframe;
|
||||
CurveEditor *_curve_editor;
|
||||
Ref<Curve> _in_curve;
|
||||
|
||||
Ref<ProceduralAnimation> _animation;
|
||||
};
|
||||
|
||||
class ProceduralAnimationEditorPlugin : public EditorPlugin {
|
||||
|
Loading…
Reference in New Issue
Block a user