2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* animation_tree_editor_plugin.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "animation_tree_editor_plugin.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "core/io/resource_loader.h"
|
2017-07-21 11:57:46 +00:00
|
|
|
#include "core/project_settings.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os/input.h"
|
|
|
|
#include "os/keyboard.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/gui/menu_button.h"
|
|
|
|
#include "scene/gui/panel.h"
|
|
|
|
#include "scene/main/viewport.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreeEditor::edit(AnimationTreePlayer *p_anim_tree) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree = p_anim_tree;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!anim_tree) {
|
|
|
|
hide();
|
|
|
|
} else {
|
|
|
|
order.clear();
|
|
|
|
p_anim_tree->get_node_list(&order);
|
|
|
|
/*
|
|
|
|
for(List<StringName>::Element* E=order.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (E->get() >= (int)last_id)
|
|
|
|
last_id=E->get()+1;
|
|
|
|
}*/
|
|
|
|
play_button->set_pressed(p_anim_tree->is_active());
|
|
|
|
//read the orders
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Size2 AnimationTreeEditor::_get_maximum_size() {
|
|
|
|
|
|
|
|
Size2 max;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<StringName>::Element *E = order.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Point2 pos = anim_tree->node_get_pos(E->get());
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (click_type == CLICK_NODE && click_node == E->get()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos += click_motion - click_pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
pos += get_node_size(E->get());
|
|
|
|
if (pos.x > max.x)
|
|
|
|
max.x = pos.x;
|
|
|
|
if (pos.y > max.y)
|
|
|
|
max.y = pos.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const char *AnimationTreeEditor::_node_type_names[] = { "Output", "Animation", "OneShot", "Mix", "Blend2", "Blend3", "Blend4", "TimeScale", "TimeSeek", "Transition" };
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Size2 AnimationTreeEditor::get_node_size(const StringName &p_node) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<StyleBox> style = get_stylebox("panel", "PopupMenu");
|
|
|
|
Ref<Font> font = get_font("font", "PopupMenu");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Size2 size = style->get_minimum_size();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int count = 2; // title and name
|
2014-02-10 01:10:30 +00:00
|
|
|
int inputs = anim_tree->node_get_input_count(p_node);
|
2017-03-05 15:44:50 +00:00
|
|
|
count += inputs ? inputs : 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
String name = p_node;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float name_w = font->get_string_size(name).width;
|
|
|
|
float type_w = font->get_string_size(String(_node_type_names[type])).width;
|
|
|
|
float max_w = MAX(name_w, type_w);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case AnimationTreePlayer::NODE_TIMESEEK:
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_OUTPUT: {
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case AnimationTreePlayer::NODE_ANIMATION:
|
|
|
|
case AnimationTreePlayer::NODE_ONESHOT:
|
|
|
|
case AnimationTreePlayer::NODE_MIX:
|
|
|
|
case AnimationTreePlayer::NODE_BLEND2:
|
|
|
|
case AnimationTreePlayer::NODE_BLEND3:
|
|
|
|
case AnimationTreePlayer::NODE_BLEND4:
|
|
|
|
case AnimationTreePlayer::NODE_TIMESCALE:
|
|
|
|
case AnimationTreePlayer::NODE_TRANSITION: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
size.height += font->get_height();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_MAX: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
size.x += max_w + 20;
|
|
|
|
size.y += count * (font->get_height() + get_constant("vseparation", "PopupMenu"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_edit_dialog_changede(String) {
|
|
|
|
|
|
|
|
edit_dialog->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_edit_dialog_changeds(String s) {
|
|
|
|
|
|
|
|
_edit_dialog_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_edit_dialog_changedf(float) {
|
|
|
|
|
|
|
|
_edit_dialog_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_edit_dialog_changed() {
|
|
|
|
|
|
|
|
if (updating_edit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (renaming_edit) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (anim_tree->node_rename(edited_node, edit_line[0]->get_text()) == OK) {
|
|
|
|
for (List<StringName>::Element *E = order.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (E->get() == edited_node)
|
2017-03-05 15:44:50 +00:00
|
|
|
E->get() = edit_line[0]->get_text();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
edited_node = edit_line[0]->get_text();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_TIMESCALE:
|
|
|
|
anim_tree->timescale_node_set_scale(edited_node, edit_line[0]->get_text().to_double());
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_ONESHOT:
|
|
|
|
anim_tree->oneshot_node_set_fadein_time(edited_node, edit_line[0]->get_text().to_double());
|
|
|
|
anim_tree->oneshot_node_set_fadeout_time(edited_node, edit_line[1]->get_text().to_double());
|
|
|
|
anim_tree->oneshot_node_set_autorestart_delay(edited_node, edit_line[2]->get_text().to_double());
|
|
|
|
anim_tree->oneshot_node_set_autorestart_random_delay(edited_node, edit_line[3]->get_text().to_double());
|
|
|
|
anim_tree->oneshot_node_set_autorestart(edited_node, edit_check->is_pressed());
|
|
|
|
anim_tree->oneshot_node_set_mix_mode(edited_node, edit_option->get_selected());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_MIX:
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->mix_node_set_amount(edited_node, edit_scroll[0]->get_value());
|
|
|
|
break;
|
|
|
|
case AnimationTreePlayer::NODE_BLEND2:
|
|
|
|
anim_tree->blend2_node_set_amount(edited_node, edit_scroll[0]->get_value());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_BLEND3:
|
|
|
|
anim_tree->blend3_node_set_amount(edited_node, edit_scroll[0]->get_value());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case AnimationTreePlayer::NODE_BLEND4:
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->blend4_node_set_amount(edited_node, Point2(edit_scroll[0]->get_value(), edit_scroll[1]->get_value()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_TRANSITION: {
|
|
|
|
anim_tree->transition_node_set_xfade_time(edited_node, edit_line[0]->get_text().to_double());
|
|
|
|
if (anim_tree->transition_node_get_current(edited_node) != edit_option->get_selected())
|
|
|
|
anim_tree->transition_node_set_current(edited_node, edit_option->get_selected());
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_edit_dialog_animation_changed() {
|
|
|
|
|
|
|
|
Ref<Animation> anim = property_editor->get_variant().operator RefPtr();
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->animation_node_set_animation(edited_node, anim);
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_edit_dialog_edit_animation() {
|
|
|
|
|
2017-08-18 23:02:56 +00:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2014-11-06 00:20:42 +00:00
|
|
|
get_tree()->get_root()->get_child(0)->call("_resource_selected", property_editor->get_variant().operator RefPtr());
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_edit_oneshot_start() {
|
|
|
|
|
|
|
|
anim_tree->oneshot_node_start(edited_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_play_toggled() {
|
|
|
|
|
|
|
|
anim_tree->set_active(play_button->is_pressed());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_master_anim_menu_item(int p_item) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_item == 0)
|
|
|
|
_edit_filters();
|
2016-04-25 09:41:23 +00:00
|
|
|
else {
|
|
|
|
|
|
|
|
String str = master_anim_popup->get_item_text(p_item);
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->animation_node_set_master_animation(edited_node, str);
|
2016-04-25 09:41:23 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_popup_edit_dialog() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_edit = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 2; i++)
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_scroll[i]->hide();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
edit_line[i]->hide();
|
|
|
|
edit_label[i]->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
edit_option->hide();
|
2017-01-14 17:03:38 +00:00
|
|
|
edit_button->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
filter_button->hide();
|
2017-01-14 17:03:38 +00:00
|
|
|
edit_check->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 pos = anim_tree->node_get_pos(edited_node) - Point2(h_scroll->get_value(), v_scroll->get_value());
|
|
|
|
Ref<StyleBox> style = get_stylebox("panel", "PopupMenu");
|
2014-02-10 01:10:30 +00:00
|
|
|
Size2 size = get_node_size(edited_node);
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 popup_pos(pos.x + style->get_margin(MARGIN_LEFT), pos.y + size.y - style->get_margin(MARGIN_BOTTOM));
|
2017-03-29 15:29:38 +00:00
|
|
|
popup_pos += get_global_position();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (renaming_edit) {
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_label[0]->set_text(TTR("New name:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[0]->set_position(Point2(5, 5));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_label[0]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_line[0]->set_begin(Point2(15, 25));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_line[0]->set_text(edited_node);
|
|
|
|
edit_line[0]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_dialog->set_size(Size2(150, 50));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::NodeType type = anim_tree->node_get_type(edited_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case AnimationTreePlayer::NODE_ANIMATION:
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (anim_tree->get_master_player() != NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
AnimationPlayer *ap = anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>();
|
|
|
|
master_anim_popup->clear();
|
2016-04-25 09:41:23 +00:00
|
|
|
master_anim_popup->add_item("Edit Filters");
|
|
|
|
master_anim_popup->add_separator();
|
2014-02-10 01:10:30 +00:00
|
|
|
List<StringName> sn;
|
|
|
|
ap->get_animation_list(&sn);
|
|
|
|
sn.sort_custom<StringName::AlphCompare>();
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<StringName>::Element *E = sn.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
master_anim_popup->add_item(E->get());
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
master_anim_popup->set_position(popup_pos);
|
2014-02-10 01:10:30 +00:00
|
|
|
master_anim_popup->popup();
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
property_editor->edit(this, "", Variant::OBJECT, anim_tree->animation_node_get_animation(edited_node), PROPERTY_HINT_RESOURCE_TYPE, "Animation");
|
2017-03-29 15:29:38 +00:00
|
|
|
property_editor->set_position(popup_pos);
|
2014-02-10 01:10:30 +00:00
|
|
|
property_editor->popup();
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_edit = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_TIMESCALE:
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_label[0]->set_text(TTR("Scale:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[0]->set_position(Point2(5, 5));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_label[0]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_line[0]->set_begin(Point2(15, 25));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_line[0]->set_text(rtos(anim_tree->timescale_node_get_scale(edited_node)));
|
|
|
|
edit_line[0]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_dialog->set_size(Size2(150, 50));
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_ONESHOT:
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_label[0]->set_text(TTR("Fade In (s):"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[0]->set_position(Point2(5, 5));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_label[0]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_line[0]->set_begin(Point2(15, 25));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_line[0]->set_text(rtos(anim_tree->oneshot_node_get_fadein_time(edited_node)));
|
|
|
|
edit_line[0]->show();
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_label[1]->set_text(TTR("Fade Out (s):"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[1]->set_position(Point2(5, 55));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_label[1]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_line[1]->set_begin(Point2(15, 75));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_line[1]->set_text(rtos(anim_tree->oneshot_node_get_fadeout_time(edited_node)));
|
|
|
|
edit_line[1]->show();
|
|
|
|
|
|
|
|
edit_option->clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_option->add_item(TTR("Blend"), 0);
|
|
|
|
edit_option->add_item(TTR("Mix"), 1);
|
|
|
|
edit_option->set_begin(Point2(15, 105));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_option->select(anim_tree->oneshot_node_get_mix_mode(edited_node));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_option->show();
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_check->set_text(TTR("Auto Restart:"));
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_check->set_begin(Point2(15, 125));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_check->set_pressed(anim_tree->oneshot_node_has_autorestart(edited_node));
|
|
|
|
edit_check->show();
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_label[2]->set_text(TTR("Restart (s):"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[2]->set_position(Point2(5, 145));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_label[2]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_line[2]->set_begin(Point2(15, 165));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_line[2]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_delay(edited_node)));
|
|
|
|
edit_line[2]->show();
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_label[3]->set_text(TTR("Random Restart (s):"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[3]->set_position(Point2(5, 195));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_label[3]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_line[3]->set_begin(Point2(15, 215));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_line[3]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_random_delay(edited_node)));
|
|
|
|
edit_line[3]->show();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
filter_button->set_begin(Point2(10, 245));
|
2014-02-10 01:10:30 +00:00
|
|
|
filter_button->show();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_button->set_begin(Point2(10, 268));
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_button->set_text(TTR("Start!"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
edit_button->show();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_dialog->set_size(Size2(180, 293));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimationTreePlayer::NODE_MIX:
|
|
|
|
|
|
|
|
edit_label[0]->set_text(TTR("Amount:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[0]->set_position(Point2(5, 5));
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_label[0]->show();
|
|
|
|
edit_scroll[0]->set_min(0);
|
|
|
|
edit_scroll[0]->set_max(1);
|
2017-07-21 11:57:46 +00:00
|
|
|
edit_scroll[0]->set_step(0.01);
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_scroll[0]->set_value(anim_tree->mix_node_get_amount(edited_node));
|
|
|
|
edit_scroll[0]->set_begin(Point2(15, 25));
|
|
|
|
edit_scroll[0]->show();
|
|
|
|
edit_dialog->set_size(Size2(150, 50));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_BLEND2:
|
|
|
|
edit_label[0]->set_text(TTR("Blend:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[0]->set_position(Point2(5, 5));
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_label[0]->show();
|
|
|
|
edit_scroll[0]->set_min(0);
|
|
|
|
edit_scroll[0]->set_max(1);
|
2017-07-21 11:57:46 +00:00
|
|
|
edit_scroll[0]->set_step(0.01);
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_scroll[0]->set_value(anim_tree->blend2_node_get_amount(edited_node));
|
|
|
|
edit_scroll[0]->set_begin(Point2(15, 25));
|
|
|
|
edit_scroll[0]->show();
|
|
|
|
filter_button->set_begin(Point2(10, 47));
|
|
|
|
filter_button->show();
|
|
|
|
edit_dialog->set_size(Size2(150, 74));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimationTreePlayer::NODE_BLEND3:
|
|
|
|
edit_label[0]->set_text(TTR("Blend:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[0]->set_position(Point2(5, 5));
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_label[0]->show();
|
|
|
|
edit_scroll[0]->set_min(-1);
|
|
|
|
edit_scroll[0]->set_max(1);
|
2017-07-21 11:57:46 +00:00
|
|
|
edit_scroll[0]->set_step(0.01);
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_scroll[0]->set_value(anim_tree->blend3_node_get_amount(edited_node));
|
|
|
|
edit_scroll[0]->set_begin(Point2(15, 25));
|
|
|
|
edit_scroll[0]->show();
|
|
|
|
edit_dialog->set_size(Size2(150, 50));
|
|
|
|
|
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case AnimationTreePlayer::NODE_BLEND4:
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_label[0]->set_text(TTR("Blend 0:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[0]->set_position(Point2(5, 5));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_label[0]->show();
|
|
|
|
edit_scroll[0]->set_min(0);
|
|
|
|
edit_scroll[0]->set_max(1);
|
2017-07-21 11:57:46 +00:00
|
|
|
edit_scroll[0]->set_step(0.01);
|
2017-01-04 04:16:14 +00:00
|
|
|
edit_scroll[0]->set_value(anim_tree->blend4_node_get_amount(edited_node).x);
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_scroll[0]->set_begin(Point2(15, 25));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_scroll[0]->show();
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_label[1]->set_text(TTR("Blend 1:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[1]->set_position(Point2(5, 55));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_label[1]->show();
|
|
|
|
edit_scroll[1]->set_min(0);
|
|
|
|
edit_scroll[1]->set_max(1);
|
2017-07-21 11:57:46 +00:00
|
|
|
edit_scroll[1]->set_step(0.01);
|
2017-01-04 04:16:14 +00:00
|
|
|
edit_scroll[1]->set_value(anim_tree->blend4_node_get_amount(edited_node).y);
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_scroll[1]->set_begin(Point2(15, 75));
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_scroll[1]->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_dialog->set_size(Size2(150, 100));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case AnimationTreePlayer::NODE_TRANSITION: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_label[0]->set_text(TTR("X-Fade Time (s):"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[0]->set_position(Point2(5, 5));
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_label[0]->show();
|
|
|
|
edit_line[0]->set_begin(Point2(15, 25));
|
|
|
|
edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node)));
|
|
|
|
edit_line[0]->show();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_label[1]->set_text(TTR("Current:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_label[1]->set_position(Point2(5, 55));
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_label[1]->show();
|
|
|
|
edit_option->set_begin(Point2(15, 75));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_option->clear();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < anim_tree->transition_node_get_input_count(edited_node); i++) {
|
|
|
|
edit_option->add_item(itos(i), i);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_option->select(anim_tree->transition_node_get_current(edited_node));
|
|
|
|
edit_option->show();
|
|
|
|
edit_dialog->set_size(Size2(150, 100));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
edit_dialog->set_position(popup_pos);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_dialog->popup();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_edit = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreeEditor::_draw_node(const StringName &p_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
RID ci = get_canvas_item();
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::NodeType type = anim_tree->node_get_type(p_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<StyleBox> style = get_stylebox("panel", "PopupMenu");
|
|
|
|
Ref<Font> font = get_font("font", "PopupMenu");
|
|
|
|
Color font_color = get_color("font_color", "PopupMenu");
|
|
|
|
Color font_color_title = get_color("font_color_hover", "PopupMenu");
|
|
|
|
font_color_title.a *= 0.8;
|
|
|
|
Ref<Texture> slot_icon = get_icon("NodeRealSlot", "EditorIcons");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Size2 size = get_node_size(p_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
Point2 pos = anim_tree->node_get_pos(p_node);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (click_type == CLICK_NODE && click_node == p_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos += click_motion - click_pos;
|
|
|
|
if (pos.x < 5)
|
|
|
|
pos.x = 5;
|
|
|
|
if (pos.y < 5)
|
|
|
|
pos.y = 5;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
style->draw(ci, Rect2(pos, size));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float w = size.width - style->get_minimum_size().width;
|
|
|
|
float h = font->get_height() + get_constant("vseparation", "PopupMenu");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 ofs = style->get_offset() + pos;
|
|
|
|
Point2 ascofs(0, font->get_ascent());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Color bx = font_color_title;
|
2017-03-05 15:44:50 +00:00
|
|
|
bx.a *= 0.1;
|
|
|
|
draw_rect(Rect2(ofs, Size2(size.width - style->get_minimum_size().width, font->get_height())), bx);
|
|
|
|
font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, String(_node_type_names[type]), font_color_title);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ofs.y += h;
|
|
|
|
font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, p_node, font_color);
|
|
|
|
ofs.y += h;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int count = 2; // title and name
|
2014-02-10 01:10:30 +00:00
|
|
|
int inputs = anim_tree->node_get_input_count(p_node);
|
2017-03-05 15:44:50 +00:00
|
|
|
count += inputs ? inputs : 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float icon_h_ofs = Math::floor((font->get_height() - slot_icon->get_height()) / 2.0) + 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (type != AnimationTreePlayer::NODE_OUTPUT)
|
|
|
|
slot_icon->draw(ci, ofs + Point2(w, icon_h_ofs)); //output
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (inputs) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < inputs; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
slot_icon->draw(ci, ofs + Point2(-slot_icon->get_width(), icon_h_ofs));
|
2014-02-10 01:10:30 +00:00
|
|
|
String text;
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case AnimationTreePlayer::NODE_TIMESCALE:
|
|
|
|
case AnimationTreePlayer::NODE_TIMESEEK: text = "in"; break;
|
|
|
|
case AnimationTreePlayer::NODE_OUTPUT: text = "out"; break;
|
|
|
|
case AnimationTreePlayer::NODE_ANIMATION: break;
|
|
|
|
case AnimationTreePlayer::NODE_ONESHOT: text = (i == 0 ? "in" : "add"); break;
|
|
|
|
case AnimationTreePlayer::NODE_BLEND2:
|
|
|
|
case AnimationTreePlayer::NODE_MIX: text = (i == 0 ? "a" : "b"); break;
|
|
|
|
case AnimationTreePlayer::NODE_BLEND3:
|
|
|
|
switch (i) {
|
|
|
|
case 0: text = "b-"; break;
|
|
|
|
case 1: text = "a"; break;
|
|
|
|
case 2: text = "b+"; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimationTreePlayer::NODE_BLEND4:
|
|
|
|
switch (i) {
|
|
|
|
case 0: text = "a0"; break;
|
|
|
|
case 1: text = "b0"; break;
|
|
|
|
case 2: text = "a1"; break;
|
|
|
|
case 3: text = "b1"; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AnimationTreePlayer::NODE_TRANSITION:
|
|
|
|
text = itos(i);
|
|
|
|
if (anim_tree->transition_node_has_input_auto_advance(p_node, i))
|
|
|
|
text += "->";
|
|
|
|
|
|
|
|
break;
|
|
|
|
default: {}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
font->draw(ci, ofs + ascofs + Point2(3, 0), text, font_color);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ofs.y += h;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
ofs.y += h;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<StyleBox> pg_bg = get_stylebox("bg", "ProgressBar");
|
|
|
|
Ref<StyleBox> pg_fill = get_stylebox("fill", "ProgressBar");
|
|
|
|
Rect2 pg_rect(ofs, Size2(w, h));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool editable = true;
|
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case AnimationTreePlayer::NODE_ANIMATION: {
|
|
|
|
|
|
|
|
Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node);
|
|
|
|
String text;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (anim_tree->animation_node_get_master_animation(p_node) != "")
|
|
|
|
text = anim_tree->animation_node_get_master_animation(p_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
else if (anim.is_null())
|
2017-03-05 15:44:50 +00:00
|
|
|
text = "load..";
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
text = anim->get_name();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, text, font_color_title);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case AnimationTreePlayer::NODE_ONESHOT:
|
2016-03-08 23:00:52 +00:00
|
|
|
case AnimationTreePlayer::NODE_MIX:
|
2014-02-10 01:10:30 +00:00
|
|
|
case AnimationTreePlayer::NODE_BLEND2:
|
|
|
|
case AnimationTreePlayer::NODE_BLEND3:
|
|
|
|
case AnimationTreePlayer::NODE_BLEND4:
|
|
|
|
case AnimationTreePlayer::NODE_TIMESCALE:
|
|
|
|
case AnimationTreePlayer::NODE_TRANSITION: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
font->draw_halign(ci, ofs + ascofs, HALIGN_CENTER, w, "edit..", font_color_title);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
default: editable = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (editable) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> arrow = get_icon("arrow", "Tree");
|
|
|
|
Point2 arrow_ofs(w - arrow->get_width(), Math::floor((h - arrow->get_height()) / 2));
|
|
|
|
arrow->draw(ci, ofs + arrow_ofs);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void AnimationTreeEditor::_node_param_changed() {
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//anim_tree->node_set_param( click_node,property_editor->get_variant() );
|
|
|
|
//update();
|
|
|
|
//_write_anim_tree_graph();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreeEditor::ClickType AnimationTreeEditor::_locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<StyleBox> style = get_stylebox("panel", "PopupMenu");
|
|
|
|
Ref<Font> font = get_font("font", "PopupMenu");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float h = (font->get_height() + get_constant("vseparation", "PopupMenu"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (const List<StringName>::Element *E = order.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
StringName node = E->get();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreePlayer::NodeType type = anim_tree->node_get_type(node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Point2 pos = anim_tree->node_get_pos(node);
|
|
|
|
Size2 size = get_node_size(node);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!Rect2(pos, size).has_point(p_click))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (p_node_id)
|
2017-03-05 15:44:50 +00:00
|
|
|
*p_node_id = node;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos = p_click - pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float y = pos.y - style->get_offset().height;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (y < 2 * h)
|
2014-02-10 01:10:30 +00:00
|
|
|
return CLICK_NODE;
|
2017-03-05 15:44:50 +00:00
|
|
|
y -= 2 * h;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int inputs = anim_tree->node_get_input_count(node);
|
2017-03-05 15:44:50 +00:00
|
|
|
int count = MAX(inputs, 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (inputs == 0 || (pos.x > size.width / 2 && type != AnimationTreePlayer::NODE_OUTPUT)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (y < count * h) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-04-25 09:41:23 +00:00
|
|
|
if (p_slot_index)
|
2017-03-05 15:44:50 +00:00
|
|
|
*p_slot_index = 0;
|
2016-04-25 09:41:23 +00:00
|
|
|
return CLICK_OUTPUT_SLOT;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (y < h) {
|
2016-04-25 09:41:23 +00:00
|
|
|
if (p_slot_index)
|
2017-03-05 15:44:50 +00:00
|
|
|
*p_slot_index = i;
|
2016-04-25 09:41:23 +00:00
|
|
|
return CLICK_INPUT_SLOT;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
y -= h;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool has_parameters = type != AnimationTreePlayer::NODE_OUTPUT && type != AnimationTreePlayer::NODE_TIMESEEK;
|
2016-04-25 09:41:23 +00:00
|
|
|
return has_parameters ? CLICK_PARAMETER : CLICK_NODE;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CLICK_NONE;
|
|
|
|
}
|
|
|
|
|
2017-08-12 16:52:50 +00:00
|
|
|
Point2 AnimationTreeEditor::_get_slot_pos(const StringName &p_node_id, bool p_input, int p_slot) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<StyleBox> style = get_stylebox("panel", "PopupMenu");
|
|
|
|
Ref<Font> font = get_font("font", "PopupMenu");
|
|
|
|
Ref<Texture> slot_icon = get_icon("NodeRealSlot", "EditorIcons");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-12 16:52:50 +00:00
|
|
|
Size2 size = get_node_size(p_node_id);
|
|
|
|
Point2 pos = anim_tree->node_get_pos(p_node_id);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-12 16:52:50 +00:00
|
|
|
if (click_type == CLICK_NODE && click_node == p_node_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos += click_motion - click_pos;
|
|
|
|
if (pos.x < 5)
|
|
|
|
pos.x = 5;
|
|
|
|
if (pos.y < 5)
|
|
|
|
pos.y = 5;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float w = size.width - style->get_minimum_size().width;
|
|
|
|
float h = font->get_height() + get_constant("vseparation", "PopupMenu");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos += style->get_offset();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos.y += h * 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos.y += h * p_slot;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos += Point2(-slot_icon->get_width() / 2.0, h / 2.0).floor();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!p_input) {
|
|
|
|
pos.x += w + slot_icon->get_width();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void AnimationTreeEditor::_node_edit_property(const StringName& p_node) {
|
|
|
|
|
|
|
|
Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
|
|
|
|
Size2 size = get_node_size(p_node);
|
|
|
|
Point2 pos = Point2( anim_tree->node_get_pos_x(p_node), anim_tree->node_get_pos_y(p_node) )-offset;
|
|
|
|
|
|
|
|
VisualServer::AnimationTreeNodeType type=anim_tree->node_get_type(p_node);
|
|
|
|
|
|
|
|
PropertyInfo ph = VisualServer::get_singleton()->anim_tree_node_get_type_info(type);
|
|
|
|
if (ph.type==Variant::NIL)
|
|
|
|
return;
|
|
|
|
if (ph.type==Variant::_RID)
|
|
|
|
ph.type=Variant::RESOURCE;
|
|
|
|
|
|
|
|
property_editor->edit(NULL,ph.name,ph.type,anim_tree->node_get_param(p_node),ph.hint,ph.hint_string);
|
|
|
|
|
|
|
|
Point2 popup_pos=Point2( pos.x+(size.width-property_editor->get_size().width)/2.0,pos.y+(size.y-style->get_margin(MARGIN_BOTTOM))).floor();
|
2017-03-29 15:29:38 +00:00
|
|
|
popup_pos+=get_global_position();
|
|
|
|
property_editor->set_position(popup_pos);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
property_editor->popup();
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseButton> mb = p_event;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb.is_valid()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->is_pressed()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->get_button_index() == 1) {
|
2017-06-03 08:54:24 +00:00
|
|
|
click_pos = Point2(mb->get_position().x, mb->get_position().y);
|
2017-05-20 15:38:03 +00:00
|
|
|
click_motion = click_pos;
|
|
|
|
click_type = _locate_click(click_pos, &click_node, &click_slot);
|
|
|
|
if (click_type != CLICK_NONE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
order.erase(click_node);
|
|
|
|
order.push_back(click_node);
|
|
|
|
update();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
switch (click_type) {
|
|
|
|
case CLICK_INPUT_SLOT: {
|
|
|
|
click_pos = _get_slot_pos(click_node, true, click_slot);
|
|
|
|
} break;
|
|
|
|
case CLICK_OUTPUT_SLOT: {
|
|
|
|
click_pos = _get_slot_pos(click_node, false, click_slot);
|
|
|
|
} break;
|
|
|
|
case CLICK_PARAMETER: {
|
|
|
|
|
|
|
|
edited_node = click_node;
|
|
|
|
renaming_edit = false;
|
|
|
|
_popup_edit_dialog();
|
|
|
|
//open editor
|
|
|
|
//_node_edit_property(click_node);
|
|
|
|
} break;
|
|
|
|
default: {}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
}
|
|
|
|
if (mb->get_button_index() == 2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (click_type != CLICK_NONE) {
|
|
|
|
click_type = CLICK_NONE;
|
|
|
|
update();
|
|
|
|
} else {
|
|
|
|
// try to disconnect/remove
|
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
Point2 rclick_pos = Point2(mb->get_position().x, mb->get_position().y);
|
2017-05-20 15:38:03 +00:00
|
|
|
rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot);
|
|
|
|
if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) {
|
|
|
|
|
|
|
|
node_popup->clear();
|
|
|
|
node_popup->add_item(TTR("Disconnect"), NODE_DISCONNECT);
|
|
|
|
if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) {
|
|
|
|
node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT);
|
|
|
|
if (rclick_type == CLICK_INPUT_SLOT) {
|
|
|
|
if (anim_tree->transition_node_has_input_auto_advance(rclick_node, rclick_slot))
|
|
|
|
node_popup->add_item(TTR("Clear Auto-Advance"), NODE_CLEAR_AUTOADVANCE);
|
|
|
|
else
|
|
|
|
node_popup->add_item(TTR("Set Auto-Advance"), NODE_SET_AUTOADVANCE);
|
|
|
|
node_popup->add_item(TTR("Delete Input"), NODE_DELETE_INPUT);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
node_popup->set_position(rclick_pos + get_global_position());
|
|
|
|
node_popup->popup();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (rclick_type == CLICK_NODE) {
|
|
|
|
node_popup->clear();
|
|
|
|
node_popup->add_item(TTR("Rename"), NODE_RENAME);
|
|
|
|
node_popup->add_item(TTR("Remove"), NODE_ERASE);
|
|
|
|
if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION)
|
|
|
|
node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT);
|
|
|
|
node_popup->set_position(rclick_pos + get_global_position());
|
|
|
|
node_popup->popup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->get_button_index() == 1 && click_type != CLICK_NONE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
switch (click_type) {
|
|
|
|
case CLICK_INPUT_SLOT:
|
|
|
|
case CLICK_OUTPUT_SLOT: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
Point2 dst_click_pos = Point2(mb->get_position().x, mb->get_position().y);
|
2017-05-20 15:38:03 +00:00
|
|
|
StringName id;
|
|
|
|
int slot;
|
|
|
|
ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (dst_click_type == CLICK_INPUT_SLOT && click_type == CLICK_OUTPUT_SLOT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
anim_tree->connect_nodes(click_node, id, slot);
|
|
|
|
}
|
|
|
|
if (click_type == CLICK_INPUT_SLOT && dst_click_type == CLICK_OUTPUT_SLOT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
anim_tree->connect_nodes(id, click_node, click_slot);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} break;
|
|
|
|
case CLICK_NODE: {
|
|
|
|
Point2 new_pos = anim_tree->node_get_pos(click_node) + (click_motion - click_pos);
|
|
|
|
if (new_pos.x < 5)
|
|
|
|
new_pos.x = 5;
|
|
|
|
if (new_pos.y < 5)
|
|
|
|
new_pos.y = 5;
|
|
|
|
anim_tree->node_set_pos(click_node, new_pos);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
|
|
|
|
click_type = CLICK_NONE;
|
|
|
|
update();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseMotion> mm = p_event;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mm.is_valid()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mm->get_button_mask() & 1 && click_type != CLICK_NONE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
click_motion = Point2(mm->get_position().x, mm->get_position().y);
|
2017-05-20 15:38:03 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
if ((mm->get_button_mask() & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x);
|
|
|
|
v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y);
|
|
|
|
update();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreeEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p_to, const Color &p_color) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static const int steps = 20;
|
|
|
|
|
|
|
|
Rect2 r;
|
2017-06-03 22:25:13 +00:00
|
|
|
r.position = p_from;
|
2014-02-10 01:10:30 +00:00
|
|
|
r.expand_to(p_to);
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1);
|
2014-02-10 01:10:30 +00:00
|
|
|
bool flip = sign.x * sign.y < 0;
|
|
|
|
|
|
|
|
Vector2 prev;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i <= steps; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float d = i / float(steps);
|
|
|
|
float c = -Math::cos(d * Math_PI) * 0.5 + 0.5;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (flip)
|
2017-03-05 15:44:50 +00:00
|
|
|
c = 1.0 - c;
|
2017-06-03 22:25:13 +00:00
|
|
|
Vector2 p = r.position + Vector2(d * r.size.width, c * r.size.height);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i > 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
draw_line(prev, p, p_color, 2);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
prev = p;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
play_button->set_icon(get_icon("Play", "EditorIcons"));
|
|
|
|
add_menu->set_icon(get_icon("Add", "EditorIcons"));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
|
|
|
|
_update_scrollbars();
|
|
|
|
//VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1));
|
2017-03-05 15:44:50 +00:00
|
|
|
get_stylebox("bg", "Tree")->draw(get_canvas_item(), Rect2(Point2(), get_size()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<StringName>::Element *E = order.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_draw_node(E->get());
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (click_type == CLICK_INPUT_SLOT || click_type == CLICK_OUTPUT_SLOT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_draw_cos_line(click_pos, click_motion, Color(0.5, 1, 0.5, 0.8));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
List<AnimationTreePlayer::Connection> connections;
|
|
|
|
anim_tree->get_connection_list(&connections);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<AnimationTreePlayer::Connection>::Element *E = connections.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const AnimationTreePlayer::Connection &c = E->get();
|
|
|
|
Point2 source = _get_slot_pos(c.src_node, false, 0);
|
|
|
|
Point2 dest = _get_slot_pos(c.dst_node, true, c.dst_input);
|
|
|
|
Color col = Color(1, 1, 0.5, 0.8);
|
|
|
|
/*
|
2014-02-10 01:10:30 +00:00
|
|
|
if (click_type==CLICK_NODE && click_node==c.src_node) {
|
|
|
|
|
|
|
|
source+=click_motion-click_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (click_type==CLICK_NODE && click_node==c.dst_node) {
|
|
|
|
|
|
|
|
dest+=click_motion-click_pos;
|
|
|
|
}*/
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_draw_cos_line(source, dest, col);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (anim_tree->get_last_error()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case AnimationTreePlayer::CONNECT_OK: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Font> f = get_font("font", "Label");
|
|
|
|
f->draw(get_canvas_item(), Point2(5, 25 + f->get_ascent()), TTR("Animation tree is valid."), Color(0, 1, 0.6, 0.8));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Font> f = get_font("font", "Label");
|
|
|
|
f->draw(get_canvas_item(), Point2(5, 25 + f->get_ascent()), TTR("Animation tree is invalid."), Color(1, 0.6, 0.0, 0.8));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_update_scrollbars() {
|
|
|
|
|
|
|
|
Size2 size = get_size();
|
|
|
|
Size2 hmin = h_scroll->get_combined_minimum_size();
|
|
|
|
Size2 vmin = v_scroll->get_combined_minimum_size();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v_scroll->set_begin(Point2(size.width - vmin.width, 0));
|
|
|
|
v_scroll->set_end(Point2(size.width, size.height));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
h_scroll->set_begin(Point2(0, size.height - hmin.height));
|
|
|
|
h_scroll->set_end(Point2(size.width - vmin.width, size.height));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Size2 min = _get_maximum_size();
|
|
|
|
|
|
|
|
if (min.height < size.height - hmin.height) {
|
|
|
|
|
|
|
|
v_scroll->hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
offset.y = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
v_scroll->show();
|
|
|
|
v_scroll->set_max(min.height);
|
|
|
|
v_scroll->set_page(size.height - hmin.height);
|
2017-03-05 15:44:50 +00:00
|
|
|
offset.y = v_scroll->get_value();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (min.width < size.width - vmin.width) {
|
|
|
|
|
|
|
|
h_scroll->hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
offset.x = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
h_scroll->show();
|
|
|
|
h_scroll->set_max(min.width);
|
|
|
|
h_scroll->set_page(size.width - vmin.width);
|
2017-03-05 15:44:50 +00:00
|
|
|
offset.x = h_scroll->get_value();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_scroll_moved(float) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
offset.x = h_scroll->get_value();
|
|
|
|
offset.y = v_scroll->get_value();
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_node_menu_item(int p_item) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_item) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case NODE_DISCONNECT: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (rclick_type == CLICK_INPUT_SLOT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->disconnect_nodes(rclick_node, rclick_slot);
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (rclick_type == CLICK_OUTPUT_SLOT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<AnimationTreePlayer::Connection> connections;
|
|
|
|
anim_tree->get_connection_list(&connections);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<AnimationTreePlayer::Connection>::Element *E = connections.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
const AnimationTreePlayer::Connection &c = E->get();
|
|
|
|
if (c.dst_node == rclick_node) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->disconnect_nodes(c.dst_node, c.dst_input);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_RENAME: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
renaming_edit = true;
|
|
|
|
edited_node = rclick_node;
|
2014-02-10 01:10:30 +00:00
|
|
|
_popup_edit_dialog();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NODE_ADD_INPUT: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->transition_node_set_input_count(rclick_node, anim_tree->transition_node_get_input_count(rclick_node) + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case NODE_DELETE_INPUT: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->transition_node_delete_input(rclick_node, rclick_slot);
|
|
|
|
update();
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case NODE_SET_AUTOADVANCE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
|
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
case NODE_CLEAR_AUTOADVANCE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->transition_node_set_input_auto_advance(rclick_node, rclick_slot, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NODE_ERASE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (rclick_node == "out")
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
order.erase(rclick_node);
|
|
|
|
anim_tree->remove_node(rclick_node);
|
|
|
|
update();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName AnimationTreeEditor::_add_node(int p_item) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *bname[] = {
|
2014-02-10 01:10:30 +00:00
|
|
|
"out",
|
|
|
|
"anim",
|
|
|
|
"oneshot",
|
|
|
|
"mix",
|
|
|
|
"blend2",
|
|
|
|
"blend3",
|
|
|
|
"blend4",
|
|
|
|
"scale",
|
|
|
|
"seek",
|
|
|
|
"transition"
|
|
|
|
};
|
|
|
|
|
|
|
|
String name;
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
name = bname[p_item];
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx > 1)
|
|
|
|
name += " " + itos(idx);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (anim_tree->node_exists(name))
|
|
|
|
idx++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
anim_tree->add_node((AnimationTreePlayer::NodeType)p_item, name);
|
|
|
|
anim_tree->node_set_pos(name, Point2(last_x, last_y));
|
2014-02-10 01:10:30 +00:00
|
|
|
order.push_back(name);
|
2017-03-05 15:44:50 +00:00
|
|
|
last_x += 10;
|
|
|
|
last_y += 10;
|
|
|
|
last_x = last_x % (int)get_size().width;
|
|
|
|
last_y = last_y % (int)get_size().height;
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
|
|
|
|
return name;
|
|
|
|
};
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_file_dialog_selected(String p_path) {
|
|
|
|
|
|
|
|
switch (file_op) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
case MENU_IMPORT_ANIMATIONS: {
|
|
|
|
Vector<String> files = file_dialog->get_selected_files();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < files.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
StringName node = _add_node(AnimationTreePlayer::NODE_ANIMATION);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
RES anim = ResourceLoader::load(files[i]);
|
|
|
|
anim_tree->animation_node_set_animation(node, anim);
|
|
|
|
//anim_tree->node_set_name(node, files[i].get_file());
|
|
|
|
};
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_add_menu_item(int p_item) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_item == MENU_GRAPH_CLEAR) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//clear
|
|
|
|
} else if (p_item == MENU_IMPORT_ANIMATIONS) {
|
|
|
|
|
|
|
|
file_op = MENU_IMPORT_ANIMATIONS;
|
2015-06-06 12:44:38 +00:00
|
|
|
file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
|
2014-02-10 01:10:30 +00:00
|
|
|
file_dialog->popup_centered_ratio();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_add_node(p_item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Size2 AnimationTreeEditor::get_minimum_size() const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return Size2(10, 200);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationTreeEditor::_find_paths_for_filter(const StringName &p_node, Set<String> &paths) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(!anim_tree->node_exists(p_node));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < anim_tree->node_get_input_count(p_node); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
StringName port = anim_tree->node_get_input_source(p_node, i);
|
|
|
|
if (port == StringName())
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
_find_paths_for_filter(port, paths);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (anim_tree->node_get_type(p_node) == AnimationTreePlayer::NODE_ANIMATION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node);
|
|
|
|
if (anim.is_valid()) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < anim->get_track_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
paths.insert(anim->track_get_path(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_filter_edited() {
|
|
|
|
|
|
|
|
TreeItem *ed = filter->get_edited();
|
|
|
|
if (!ed)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) {
|
|
|
|
anim_tree->oneshot_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0));
|
|
|
|
} else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) {
|
|
|
|
anim_tree->blend2_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0));
|
|
|
|
} else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) {
|
|
|
|
anim_tree->animation_node_set_filter_path(edited_node, ed->get_metadata(0), ed->is_checked(0));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_edit_filters() {
|
|
|
|
|
|
|
|
filter_dialog->popup_centered_ratio();
|
|
|
|
filter->clear();
|
|
|
|
|
|
|
|
Set<String> npb;
|
2017-03-05 15:44:50 +00:00
|
|
|
_find_paths_for_filter(edited_node, npb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
TreeItem *root = filter->create_item();
|
|
|
|
filter->set_hide_root(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<String, TreeItem *> pm;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *base = anim_tree->get_node(anim_tree->get_base_path());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Set<String>::Element *E = npb.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *parent = root;
|
|
|
|
String descr = E->get();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (base) {
|
|
|
|
NodePath np = E->get();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (np.get_property() != StringName()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *n = base->get_node(np);
|
|
|
|
Skeleton *s = n->cast_to<Skeleton>();
|
|
|
|
if (s) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String skelbase = E->get().substr(0, E->get().find(":"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int bidx = s->find_bone(np.get_property());
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (bidx != -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
int bparent = s->get_bone_parent(bidx);
|
|
|
|
//
|
2017-03-05 15:44:50 +00:00
|
|
|
if (bparent != -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String bpn = skelbase + ":" + s->get_bone_name(bparent);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (pm.has(bpn)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
parent = pm[bpn];
|
|
|
|
descr = np.get_property();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (pm.has(skelbase)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
parent = pm[skelbase];
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *it = filter->create_item(parent);
|
2017-03-05 15:44:50 +00:00
|
|
|
it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
|
|
|
it->set_text(0, descr);
|
|
|
|
it->set_metadata(0, NodePath(E->get()));
|
|
|
|
it->set_editable(0, true);
|
|
|
|
if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ONESHOT) {
|
|
|
|
it->set_checked(0, anim_tree->oneshot_node_is_path_filtered(edited_node, E->get()));
|
|
|
|
} else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_BLEND2) {
|
|
|
|
it->set_checked(0, anim_tree->blend2_node_is_path_filtered(edited_node, E->get()));
|
|
|
|
} else if (anim_tree->node_get_type(edited_node) == AnimationTreePlayer::NODE_ANIMATION) {
|
|
|
|
it->set_checked(0, anim_tree->animation_node_is_path_filtered(edited_node, E->get()));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
pm[E->get()] = it;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditor::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("_add_menu_item", &AnimationTreeEditor::_add_menu_item);
|
|
|
|
ClassDB::bind_method("_node_menu_item", &AnimationTreeEditor::_node_menu_item);
|
|
|
|
ClassDB::bind_method("_gui_input", &AnimationTreeEditor::_gui_input);
|
2017-01-14 11:26:56 +00:00
|
|
|
//ClassDB::bind_method( "_node_param_changed", &AnimationTreeEditor::_node_param_changed );
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("_scroll_moved", &AnimationTreeEditor::_scroll_moved);
|
|
|
|
ClassDB::bind_method("_edit_dialog_changeds", &AnimationTreeEditor::_edit_dialog_changeds);
|
|
|
|
ClassDB::bind_method("_edit_dialog_changede", &AnimationTreeEditor::_edit_dialog_changede);
|
|
|
|
ClassDB::bind_method("_edit_dialog_changedf", &AnimationTreeEditor::_edit_dialog_changedf);
|
|
|
|
ClassDB::bind_method("_edit_dialog_changed", &AnimationTreeEditor::_edit_dialog_changed);
|
|
|
|
ClassDB::bind_method("_edit_dialog_animation_changed", &AnimationTreeEditor::_edit_dialog_animation_changed);
|
|
|
|
ClassDB::bind_method("_edit_dialog_edit_animation", &AnimationTreeEditor::_edit_dialog_edit_animation);
|
|
|
|
ClassDB::bind_method("_play_toggled", &AnimationTreeEditor::_play_toggled);
|
|
|
|
ClassDB::bind_method("_edit_oneshot_start", &AnimationTreeEditor::_edit_oneshot_start);
|
|
|
|
ClassDB::bind_method("_file_dialog_selected", &AnimationTreeEditor::_file_dialog_selected);
|
|
|
|
ClassDB::bind_method("_master_anim_menu_item", &AnimationTreeEditor::_master_anim_menu_item);
|
|
|
|
ClassDB::bind_method("_edit_filters", &AnimationTreeEditor::_edit_filters);
|
|
|
|
ClassDB::bind_method("_filter_edited", &AnimationTreeEditor::_filter_edited);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTreeEditor::AnimationTreeEditor() {
|
|
|
|
|
|
|
|
set_focus_mode(FOCUS_ALL);
|
|
|
|
|
|
|
|
PopupMenu *p;
|
|
|
|
List<PropertyInfo> defaults;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
add_menu = memnew(MenuButton);
|
2014-02-10 01:10:30 +00:00
|
|
|
//add_menu->set_
|
2017-03-29 15:29:38 +00:00
|
|
|
add_menu->set_position(Point2(0, 0));
|
2017-03-05 15:44:50 +00:00
|
|
|
add_menu->set_size(Point2(25, 15));
|
|
|
|
add_child(add_menu);
|
|
|
|
|
|
|
|
p = add_menu->get_popup();
|
|
|
|
p->add_item(TTR("Animation Node"), AnimationTreePlayer::NODE_ANIMATION);
|
|
|
|
p->add_item(TTR("OneShot Node"), AnimationTreePlayer::NODE_ONESHOT);
|
|
|
|
p->add_item(TTR("Mix Node"), AnimationTreePlayer::NODE_MIX);
|
|
|
|
p->add_item(TTR("Blend2 Node"), AnimationTreePlayer::NODE_BLEND2);
|
|
|
|
p->add_item(TTR("Blend3 Node"), AnimationTreePlayer::NODE_BLEND3);
|
|
|
|
p->add_item(TTR("Blend4 Node"), AnimationTreePlayer::NODE_BLEND4);
|
|
|
|
p->add_item(TTR("TimeScale Node"), AnimationTreePlayer::NODE_TIMESCALE);
|
|
|
|
p->add_item(TTR("TimeSeek Node"), AnimationTreePlayer::NODE_TIMESEEK);
|
|
|
|
p->add_item(TTR("Transition Node"), AnimationTreePlayer::NODE_TRANSITION);
|
2014-02-10 01:10:30 +00:00
|
|
|
p->add_separator();
|
2016-05-18 22:08:12 +00:00
|
|
|
p->add_item(TTR("Import Animations.."), MENU_IMPORT_ANIMATIONS); // wtf
|
2014-02-10 01:10:30 +00:00
|
|
|
p->add_separator();
|
2017-03-05 15:44:50 +00:00
|
|
|
p->add_item(TTR("Clear"), MENU_GRAPH_CLEAR);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p->connect("id_pressed", this, "_add_menu_item");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
play_button = memnew(Button);
|
2017-03-29 15:29:38 +00:00
|
|
|
play_button->set_position(Point2(25, 0));
|
2017-03-05 15:44:50 +00:00
|
|
|
play_button->set_size(Point2(25, 15));
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(play_button);
|
|
|
|
play_button->set_toggle_mode(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
play_button->connect("pressed", this, "_play_toggled");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_x = 50;
|
|
|
|
last_y = 50;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
property_editor = memnew(CustomPropertyEditor);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(property_editor);
|
2017-03-05 15:44:50 +00:00
|
|
|
property_editor->connect("variant_changed", this, "_edit_dialog_animation_changed");
|
|
|
|
property_editor->connect("resource_edit_request", this, "_edit_dialog_edit_animation");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
h_scroll = memnew(HScrollBar);
|
|
|
|
v_scroll = memnew(VScrollBar);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
add_child(h_scroll);
|
|
|
|
add_child(v_scroll);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
h_scroll->connect("value_changed", this, "_scroll_moved");
|
|
|
|
v_scroll->connect("value_changed", this, "_scroll_moved");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
node_popup = memnew(PopupMenu);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(node_popup);
|
|
|
|
node_popup->set_as_toplevel(true);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
master_anim_popup = memnew(PopupMenu);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(master_anim_popup);
|
2017-03-05 15:44:50 +00:00
|
|
|
master_anim_popup->connect("id_pressed", this, "_master_anim_menu_item");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
node_popup->connect("id_pressed", this, "_node_menu_item");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating_edit = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_dialog = memnew(PopupPanel);
|
2017-01-14 11:26:56 +00:00
|
|
|
//edit_dialog->get_ok()->hide();
|
|
|
|
//edit_dialog->get_cancel()->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(edit_dialog);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_option = memnew(OptionButton);
|
|
|
|
edit_option->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
2017-07-06 07:16:27 +00:00
|
|
|
edit_option->set_margin(MARGIN_RIGHT, -10);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_dialog->add_child(edit_option);
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_option->connect("item_selected", this, "_edit_dialog_changedf");
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_option->hide();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
edit_scroll[i] = memnew(HSlider);
|
|
|
|
edit_scroll[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
2017-07-06 07:16:27 +00:00
|
|
|
edit_scroll[i]->set_margin(MARGIN_RIGHT, -10);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_dialog->add_child(edit_scroll[i]);
|
|
|
|
edit_scroll[i]->hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_scroll[i]->connect("value_changed", this, "_edit_dialog_changedf");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
edit_line[i] = memnew(LineEdit);
|
|
|
|
edit_line[i]->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
2017-07-06 07:16:27 +00:00
|
|
|
edit_line[i]->set_margin(MARGIN_RIGHT, -10);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_dialog->add_child(edit_line[i]);
|
|
|
|
edit_line[i]->hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_line[i]->connect("text_changed", this, "_edit_dialog_changeds");
|
|
|
|
edit_line[i]->connect("text_entered", this, "_edit_dialog_changede");
|
|
|
|
edit_label[i] = memnew(Label);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_dialog->add_child(edit_label[i]);
|
|
|
|
edit_label[i]->hide();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_button = memnew(Button);
|
|
|
|
edit_button->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
2017-07-06 07:16:27 +00:00
|
|
|
edit_button->set_margin(MARGIN_RIGHT, -10);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_dialog->add_child(edit_button);
|
2017-01-14 17:03:38 +00:00
|
|
|
edit_button->hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_button->connect("pressed", this, "_edit_oneshot_start");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_check = memnew(CheckButton);
|
|
|
|
edit_check->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
2017-07-06 07:16:27 +00:00
|
|
|
edit_check->set_margin(MARGIN_RIGHT, -10);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_dialog->add_child(edit_check);
|
2017-01-14 17:03:38 +00:00
|
|
|
edit_check->hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_check->connect("pressed", this, "_edit_dialog_changed");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
file_dialog = memnew(EditorFileDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
file_dialog->set_enable_multiple_selection(true);
|
2017-07-19 20:00:46 +00:00
|
|
|
file_dialog->set_current_dir(ProjectSettings::get_singleton()->get_resource_path());
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(file_dialog);
|
2017-03-05 15:44:50 +00:00
|
|
|
file_dialog->connect("file_selected", this, "_file_dialog_selected");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
filter_dialog = memnew(AcceptDialog);
|
2016-05-04 01:25:37 +00:00
|
|
|
filter_dialog->set_title(TTR("Edit Node Filters"));
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(filter_dialog);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
filter = memnew(Tree);
|
2014-02-10 01:10:30 +00:00
|
|
|
filter_dialog->add_child(filter);
|
2017-01-10 04:49:55 +00:00
|
|
|
//filter_dialog->set_child_rect(filter);
|
2017-03-05 15:44:50 +00:00
|
|
|
filter->connect("item_edited", this, "_filter_edited");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
filter_button = memnew(Button);
|
|
|
|
filter_button->set_anchor(MARGIN_RIGHT, ANCHOR_END);
|
2017-07-06 07:16:27 +00:00
|
|
|
filter_button->set_margin(MARGIN_RIGHT, -10);
|
2014-02-10 01:10:30 +00:00
|
|
|
edit_dialog->add_child(filter_button);
|
2017-01-14 17:03:38 +00:00
|
|
|
filter_button->hide();
|
2016-05-04 01:25:37 +00:00
|
|
|
filter_button->set_text(TTR("Filters.."));
|
2017-03-05 15:44:50 +00:00
|
|
|
filter_button->connect("pressed", this, "_edit_filters");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-09 18:50:08 +00:00
|
|
|
set_clip_contents(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditorPlugin::edit(Object *p_object) {
|
|
|
|
|
|
|
|
anim_tree_editor->edit(p_object->cast_to<AnimationTreePlayer>());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AnimationTreeEditorPlugin::handles(Object *p_object) const {
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
return p_object->is_class("AnimationTreePlayer");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationTreeEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
|
|
|
|
if (p_visible) {
|
2017-01-14 11:26:56 +00:00
|
|
|
//editor->hide_animation_player_editors();
|
|
|
|
//editor->animation_panel_make_visible(true);
|
2016-01-17 23:03:57 +00:00
|
|
|
button->show();
|
|
|
|
editor->make_bottom_panel_item_visible(anim_tree_editor);
|
2014-02-10 01:10:30 +00:00
|
|
|
anim_tree_editor->set_fixed_process(true);
|
|
|
|
} else {
|
|
|
|
|
2017-01-13 13:45:50 +00:00
|
|
|
if (anim_tree_editor->is_visible_in_tree())
|
2016-01-17 23:03:57 +00:00
|
|
|
editor->hide_bottom_panel();
|
|
|
|
button->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
anim_tree_editor->set_fixed_process(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTreeEditorPlugin::AnimationTreeEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
editor = p_node;
|
|
|
|
anim_tree_editor = memnew(AnimationTreeEditor);
|
|
|
|
anim_tree_editor->set_custom_minimum_size(Size2(0, 300));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
button = editor->add_bottom_panel_item("AnimationTree", anim_tree_editor);
|
2016-01-17 23:03:57 +00:00
|
|
|
button->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationTreeEditorPlugin::~AnimationTreeEditorPlugin() {
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|