2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* animation_editor.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
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_editor.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "editor/plugins/animation_player_editor_plugin.h"
|
|
|
|
#include "editor_node.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "editor_settings.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "io/resource_saver.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os/keyboard.h"
|
|
|
|
#include "os/os.h"
|
|
|
|
#include "pair.h"
|
|
|
|
#include "scene/gui/separator.h"
|
2016-01-31 23:06:37 +00:00
|
|
|
#include "scene/main/viewport.h"
|
2017-08-27 19:07:15 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/* Missing to fix:
|
|
|
|
|
|
|
|
*Set
|
|
|
|
*Find better source for hint for edited value keys
|
|
|
|
* + button on track to add a key
|
|
|
|
* when clicked for first time, erase selection of not selected at first
|
|
|
|
* automatically create discrete/continuous tracks!!
|
|
|
|
*when create track do undo/redo
|
|
|
|
*/
|
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
class AnimationCurveEdit : public Control {
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(AnimationCurveEdit, Control);
|
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
public:
|
|
|
|
enum Mode {
|
|
|
|
MODE_DISABLED,
|
|
|
|
MODE_SINGLE,
|
|
|
|
MODE_MULTIPLE
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
private:
|
2015-05-25 04:46:45 +00:00
|
|
|
Set<float> multiples;
|
|
|
|
float transition;
|
|
|
|
Mode mode;
|
|
|
|
|
2017-10-15 01:14:13 +00:00
|
|
|
LineEdit *value_edit;
|
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
void _notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_DRAW) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
RID ci = get_canvas_item();
|
|
|
|
|
|
|
|
Size2 s = get_size();
|
2017-03-05 15:44:50 +00:00
|
|
|
Rect2 r(Point2(), s);
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
//r=r.grow(3);
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<StyleBox> sb = get_stylebox("normal", "LineEdit");
|
|
|
|
sb->draw(ci, r);
|
|
|
|
r.size -= sb->get_minimum_size();
|
2017-06-03 22:25:13 +00:00
|
|
|
r.position += sb->get_offset();
|
2015-05-25 04:46:45 +00:00
|
|
|
//VisualServer::get_singleton()->canvas_item_add
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Font> f = get_font("font", "Label");
|
|
|
|
r = r.grow(-2);
|
|
|
|
Color color = get_color("font_color", "Label");
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
int points = 48;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_MULTIPLE) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Color mcolor = color;
|
|
|
|
mcolor.a *= 0.3;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Set<float>::Element *E = multiples.front();
|
|
|
|
for (int j = 0; j < 16; j++) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
if (!E)
|
|
|
|
break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float prev = 1.0;
|
|
|
|
float exp = E->get();
|
|
|
|
bool flip = false; //hint_text=="attenuation";
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 1; i <= points; i++) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float ifl = i / float(points);
|
|
|
|
float iflp = (i - 1) / float(points);
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float h = 1.0 - Math::ease(ifl, exp);
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
if (flip) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ifl = 1.0 - ifl;
|
|
|
|
iflp = 1.0 - iflp;
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 22:25:13 +00:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_line(ci, r.position + Point2(iflp * r.size.width, prev * r.size.height), r.position + Point2(ifl * r.size.width, h * r.size.height), mcolor);
|
2017-03-05 15:44:50 +00:00
|
|
|
prev = h;
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
E = E->next();
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float exp = transition;
|
|
|
|
if (mode != MODE_DISABLED) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float prev = 1.0;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool flip = false; //hint_text=="attenuation";
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 1; i <= points; i++) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float ifl = i / float(points);
|
|
|
|
float iflp = (i - 1) / float(points);
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float h = 1.0 - Math::ease(ifl, exp);
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
if (flip) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ifl = 1.0 - ifl;
|
|
|
|
iflp = 1.0 - iflp;
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 22:25:13 +00:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_line(ci, r.position + Point2(iflp * r.size.width, prev * r.size.height), r.position + Point2(ifl * r.size.width, h * r.size.height), color);
|
2017-03-05 15:44:50 +00:00
|
|
|
prev = h;
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_DISABLED) {
|
2017-10-15 01:14:13 +00:00
|
|
|
f->draw(ci, Point2(5, 5 + f->get_ascent()), TTR("Disabled"), color);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (mode == MODE_MULTIPLE) {
|
2017-10-15 01:14:13 +00:00
|
|
|
f->draw(ci, Point2(5, 5 + f->get_ascent() + value_edit->get_size().height), TTR("All Selection"), color);
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void _gui_input(const Ref<InputEvent> &p_ev) {
|
|
|
|
|
|
|
|
Ref<InputEventMouseMotion> mm = p_ev;
|
|
|
|
if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_DISABLED)
|
2015-05-25 04:46:45 +00:00
|
|
|
return;
|
|
|
|
|
2017-10-15 01:14:13 +00:00
|
|
|
value_edit->release_focus();
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float rel = mm->get_relative().x;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (rel == 0)
|
|
|
|
return;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool flip = false;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
if (flip)
|
2017-03-05 15:44:50 +00:00
|
|
|
rel = -rel;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
float val = transition;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (val == 0)
|
2015-05-25 04:46:45 +00:00
|
|
|
return;
|
|
|
|
bool sg = val < 0;
|
|
|
|
val = Math::absf(val);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
val = Math::log(val) / Math::log((float)2.0);
|
2015-05-25 04:46:45 +00:00
|
|
|
//logspace
|
2017-03-05 15:44:50 +00:00
|
|
|
val += rel * 0.05;
|
2015-05-25 04:46:45 +00:00
|
|
|
//
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
val = Math::pow((float)2.0, val);
|
2015-05-25 04:46:45 +00:00
|
|
|
if (sg)
|
2017-03-05 15:44:50 +00:00
|
|
|
val = -val;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-10-15 01:14:13 +00:00
|
|
|
force_transition(val);
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 01:14:13 +00:00
|
|
|
void _edit_value_changed(const String &p_value_str) {
|
|
|
|
|
|
|
|
force_transition(p_value_str.to_float());
|
|
|
|
}
|
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
public:
|
|
|
|
static void _bind_methods() {
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//ClassDB::bind_method("_update_obj",&AnimationKeyEdit::_update_obj);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("_gui_input", &AnimationCurveEdit::_gui_input);
|
2017-10-15 01:14:13 +00:00
|
|
|
ClassDB::bind_method("_edit_value_changed", &AnimationCurveEdit::_edit_value_changed);
|
2015-05-25 04:46:45 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("transition_changed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_mode(Mode p_mode) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
mode = p_mode;
|
2017-10-15 01:14:13 +00:00
|
|
|
value_edit->set_visible(mode != MODE_DISABLED);
|
2015-05-25 04:46:45 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void clear_multiples() {
|
|
|
|
multiples.clear();
|
|
|
|
update();
|
|
|
|
}
|
2015-05-25 04:46:45 +00:00
|
|
|
void set_multiple(float p_transition) {
|
|
|
|
|
|
|
|
multiples.insert(p_transition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_transition(float p_transition) {
|
2017-10-15 01:14:13 +00:00
|
|
|
transition = Math::stepify(p_transition, 0.01);
|
|
|
|
value_edit->set_text(String::num(transition));
|
2015-05-25 04:46:45 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
float get_transition() const {
|
|
|
|
return transition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void force_transition(float p_value) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_DISABLED)
|
2015-05-25 04:46:45 +00:00
|
|
|
return;
|
2017-10-15 01:14:13 +00:00
|
|
|
set_transition(p_value);
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("transition_changed", p_value);
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationCurveEdit() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
transition = 1.0;
|
2015-05-25 04:46:45 +00:00
|
|
|
set_default_cursor_shape(CURSOR_HSPLIT);
|
2017-03-05 15:44:50 +00:00
|
|
|
mode = MODE_DISABLED;
|
2017-10-15 01:14:13 +00:00
|
|
|
|
|
|
|
value_edit = memnew(LineEdit);
|
|
|
|
value_edit->hide();
|
|
|
|
value_edit->connect("text_entered", this, "_edit_value_changed");
|
|
|
|
add_child(value_edit);
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class AnimationKeyEdit : public Object {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(AnimationKeyEdit, Object);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
|
|
|
bool setting;
|
2015-05-25 04:46:45 +00:00
|
|
|
bool hidden;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static void _bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("_update_obj", &AnimationKeyEdit::_update_obj);
|
|
|
|
ClassDB::bind_method("_key_ofs_changed", &AnimationKeyEdit::_key_ofs_changed);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
//PopupDialog *ke_dialog;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-01-31 23:06:37 +00:00
|
|
|
void _fix_node_path(Variant &value) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
NodePath np = value;
|
2016-01-31 23:06:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (np == NodePath())
|
2016-02-02 22:04:45 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *root = EditorNode::get_singleton()->get_tree()->get_root();
|
2016-01-31 23:06:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *np_node = root->get_node(np);
|
2016-01-31 23:06:37 +00:00
|
|
|
ERR_FAIL_COND(!np_node);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *edited_node = root->get_node(base);
|
2016-01-31 23:06:37 +00:00
|
|
|
ERR_FAIL_COND(!edited_node);
|
|
|
|
|
|
|
|
value = edited_node->get_path_to(np_node);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _update_obj(const Ref<Animation> &p_anim) {
|
|
|
|
if (setting)
|
|
|
|
return;
|
2015-05-25 04:46:45 +00:00
|
|
|
if (hidden)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(animation == p_anim))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
notify_change();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to) {
|
2015-05-25 04:46:45 +00:00
|
|
|
if (hidden)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(animation == p_anim))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (from != key_ofs)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
key_ofs = to;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (setting)
|
|
|
|
return;
|
|
|
|
notify_change();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int key = animation->track_find_key(track, key_ofs, true);
|
|
|
|
ERR_FAIL_COND_V(key == -1, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String name = p_name;
|
|
|
|
if (name == "time") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float new_time = p_value;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (new_time == key_ofs)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int existing = animation->track_find_key(track, new_time, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
setting = true;
|
|
|
|
undo_redo->create_action(TTR("Move Add Key"), UndoRedo::MERGE_ENDS);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant val = animation->track_get_key_value(track, key);
|
|
|
|
float trans = animation->track_get_key_transition(track, key);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_remove_key", track, key);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_insert_key", track, new_time, val, trans);
|
|
|
|
undo_redo->add_do_method(this, "_key_ofs_changed", animation, key_ofs, new_time);
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", track, new_time);
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, key_ofs, val, trans);
|
|
|
|
undo_redo->add_undo_method(this, "_key_ofs_changed", animation, new_time, key_ofs);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (existing != -1) {
|
|
|
|
Variant v = animation->track_get_key_value(track, existing);
|
|
|
|
float trans = animation->track_get_key_transition(track, existing);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", track, new_time, v, trans);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
setting = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return true;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (name == "easing") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float val = p_value;
|
2017-03-05 15:44:50 +00:00
|
|
|
float prev_val = animation->track_get_key_transition(track, key);
|
|
|
|
setting = true;
|
|
|
|
undo_redo->create_action(TTR("Anim Change Transition"), UndoRedo::MERGE_ENDS);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_key_transition", track, key, val);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_key_transition", track, key, prev_val);
|
|
|
|
undo_redo->add_do_method(this, "_update_obj", animation);
|
|
|
|
undo_redo->add_undo_method(this, "_update_obj", animation);
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
setting = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (animation->track_get_type(track)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case Animation::TYPE_TRANSFORM: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d_old = animation->track_get_key_value(track, key);
|
2014-02-10 01:10:30 +00:00
|
|
|
Dictionary d_new = d_old;
|
2017-03-05 15:44:50 +00:00
|
|
|
d_new[p_name] = p_value;
|
|
|
|
setting = true;
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Change Transform"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, d_new);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_key_value", track, key, d_old);
|
|
|
|
undo_redo->add_do_method(this, "_update_obj", animation);
|
|
|
|
undo_redo->add_undo_method(this, "_update_obj", animation);
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
setting = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_VALUE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (name == "value") {
|
2016-01-31 23:06:37 +00:00
|
|
|
|
|
|
|
Variant value = p_value;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (value.get_type() == Variant::NODE_PATH) {
|
2016-01-31 23:06:37 +00:00
|
|
|
|
|
|
|
_fix_node_path(value);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
setting = true;
|
|
|
|
undo_redo->create_action(TTR("Anim Change Value"), UndoRedo::MERGE_ENDS);
|
|
|
|
Variant prev = animation->track_get_key_value(track, key);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, value);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_key_value", track, key, prev);
|
|
|
|
undo_redo->add_do_method(this, "_update_obj", animation);
|
|
|
|
undo_redo->add_undo_method(this, "_update_obj", animation);
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
setting = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_METHOD: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d_old = animation->track_get_key_value(track, key);
|
2014-02-10 01:10:30 +00:00
|
|
|
Dictionary d_new = d_old;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool change_notify_deserved = false;
|
|
|
|
bool mergeable = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (name == "name") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
d_new["method"] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (name == "arg_count") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector<Variant> args = d_old["args"];
|
|
|
|
args.resize(p_value);
|
2017-03-05 15:44:50 +00:00
|
|
|
d_new["args"] = args;
|
|
|
|
change_notify_deserved = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name.begins_with("args/")) {
|
|
|
|
|
|
|
|
Vector<Variant> args = d_old["args"];
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = name.get_slice("/", 1).to_int();
|
|
|
|
ERR_FAIL_INDEX_V(idx, args.size(), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String what = name.get_slice("/", 2);
|
|
|
|
if (what == "type") {
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant::Type t = Variant::Type(int(p_value));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (t != args[idx].get_type()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant::CallError err;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (Variant::can_convert(args[idx].get_type(), t)) {
|
|
|
|
Variant old = args[idx];
|
|
|
|
Variant *ptrs[1] = { &old };
|
|
|
|
args[idx] = Variant::construct(t, (const Variant **)ptrs, 1, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
args[idx] = Variant::construct(t, NULL, 0, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
change_notify_deserved = true;
|
|
|
|
d_new["args"] = args;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (what == "value") {
|
2016-01-31 23:06:37 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant value = p_value;
|
|
|
|
if (value.get_type() == Variant::NODE_PATH) {
|
2016-01-31 23:06:37 +00:00
|
|
|
|
|
|
|
_fix_node_path(value);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
args[idx] = value;
|
|
|
|
d_new["args"] = args;
|
|
|
|
mergeable = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 20:14:51 +00:00
|
|
|
if (mergeable)
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Change Call"), UndoRedo::MERGE_ENDS);
|
2016-08-17 20:14:51 +00:00
|
|
|
else
|
|
|
|
undo_redo->create_action(TTR("Anim Change Call"));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant prev = animation->track_get_key_value(track, key);
|
|
|
|
setting = true;
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, d_new);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_key_value", track, key, d_old);
|
|
|
|
undo_redo->add_do_method(this, "_update_obj", animation);
|
|
|
|
undo_redo->add_undo_method(this, "_update_obj", animation);
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
setting = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (change_notify_deserved)
|
|
|
|
notify_change();
|
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int key = animation->track_find_key(track, key_ofs, true);
|
|
|
|
ERR_FAIL_COND_V(key == -1, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String name = p_name;
|
|
|
|
if (name == "time") {
|
2014-02-10 01:10:30 +00:00
|
|
|
r_ret = key_ofs;
|
|
|
|
return true;
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (name == "easing") {
|
|
|
|
r_ret = animation->track_get_key_transition(track, key);
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (animation->track_get_type(track)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case Animation::TYPE_TRANSFORM: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d = animation->track_get_key_value(track, key);
|
|
|
|
ERR_FAIL_COND_V(!d.has(name), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
r_ret = d[p_name];
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_VALUE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (name == "value") {
|
|
|
|
r_ret = animation->track_get_key_value(track, key);
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_METHOD: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d = animation->track_get_key_value(track, key);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (name == "name") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!d.has("method"), false);
|
|
|
|
r_ret = d["method"];
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!d.has("args"), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector<Variant> args = d["args"];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (name == "arg_count") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_ret = args.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name.begins_with("args/")) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = name.get_slice("/", 1).to_int();
|
|
|
|
ERR_FAIL_INDEX_V(idx, args.size(), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String what = name.get_slice("/", 2);
|
|
|
|
if (what == "type") {
|
|
|
|
r_ret = args[idx].get_type();
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (what == "value") {
|
|
|
|
r_ret = args[idx];
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (animation.is_null())
|
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(track, animation->get_track_count());
|
|
|
|
int key = animation->track_find_key(track, key_ofs, true);
|
|
|
|
ERR_FAIL_COND(key == -1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "time", PROPERTY_HINT_RANGE, "0," + rtos(animation->get_length()) + ",0.01"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (animation->track_get_type(track)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case Animation::TYPE_TRANSFORM: {
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "location"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::QUAT, "rotation"));
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "scale"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_VALUE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant v = animation->track_get_key_value(track, key);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (hint.type != Variant::NIL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
PropertyInfo pi = hint;
|
|
|
|
pi.name = "value";
|
|
|
|
p_list->push_back(pi);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
PropertyHint hint = PROPERTY_HINT_NONE;
|
2014-02-10 01:10:30 +00:00
|
|
|
String hint_string;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (v.get_type() == Variant::OBJECT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//could actually check the object property if exists..? yes i will!
|
|
|
|
Ref<Resource> res = v;
|
|
|
|
if (res.is_valid()) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
hint = PROPERTY_HINT_RESOURCE_TYPE;
|
|
|
|
hint_string = res->get_class();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (v.get_type() != Variant::NIL)
|
|
|
|
p_list->push_back(PropertyInfo(v.get_type(), "value", hint, hint_string));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_METHOD: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "name"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "arg_count", PROPERTY_HINT_RANGE, "0,5,1"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Dictionary d = animation->track_get_key_value(track, key);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!d.has("args"));
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector<Variant> args = d["args"];
|
2014-02-10 01:10:30 +00:00
|
|
|
String vtypes;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i > 0)
|
|
|
|
vtypes += ",";
|
|
|
|
vtypes += Variant::get_type_name(Variant::Type(i));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < args.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "args/" + itos(i) + "/type", PROPERTY_HINT_ENUM, vtypes));
|
|
|
|
if (args[i].get_type() != Variant::NIL)
|
|
|
|
p_list->push_back(PropertyInfo(args[i].get_type(), "args/" + itos(i) + "/value"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
/*
|
|
|
|
if (animation->track_get_type(track)!=Animation::TYPE_METHOD)
|
|
|
|
p_list->push_back( PropertyInfo( Variant::REAL, "easing", PROPERTY_HINT_EXP_EASING));
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UndoRedo *undo_redo;
|
|
|
|
Ref<Animation> animation;
|
|
|
|
int track;
|
|
|
|
float key_ofs;
|
|
|
|
|
|
|
|
PropertyInfo hint;
|
2016-01-31 23:06:37 +00:00
|
|
|
NodePath base;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void notify_change() {
|
|
|
|
|
|
|
|
_change_notify();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
AnimationKeyEdit() {
|
|
|
|
hidden = true;
|
|
|
|
key_ofs = 0;
|
|
|
|
track = -1;
|
|
|
|
setting = false;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2015-11-18 21:55:05 +00:00
|
|
|
void AnimationKeyEditor::_menu_add_track(int p_type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!animation.is_valid());
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-11-18 21:55:05 +00:00
|
|
|
case ADD_TRACK_MENU_ADD_CALL_TRACK: {
|
2015-08-30 13:10:51 +00:00
|
|
|
if (root) {
|
|
|
|
call_select->popup_centered_ratio();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
2015-11-18 21:55:05 +00:00
|
|
|
case ADD_TRACK_MENU_ADD_VALUE_TRACK:
|
|
|
|
case ADD_TRACK_MENU_ADD_TRANSFORM_TRACK: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Add Track"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "add_track", p_type);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_path", animation->get_track_count(), ".");
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "remove_track", animation->get_track_count());
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
} break;
|
2015-11-18 21:55:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 01:22:03 +00:00
|
|
|
void AnimationKeyEditor::_anim_duplicate_keys(bool transpose) {
|
|
|
|
//duplicait!
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selection.size() && animation.is_valid() && selected_track >= 0 && selected_track < animation->get_track_count()) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int top_track = 0x7FFFFFFF;
|
2016-06-19 01:22:03 +00:00
|
|
|
float top_time = 1e10;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
|
|
|
const SelectedKey &sk = E->key();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float t = animation->track_get_key_time(sk.track, sk.key);
|
|
|
|
if (t < top_time)
|
|
|
|
top_time = t;
|
|
|
|
if (sk.track < top_track)
|
|
|
|
top_track = sk.track;
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(top_track == 0x7FFFFFFF || top_time == 1e10);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
int start_track = transpose ? selected_track : top_track;
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Anim Duplicate Keys"));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
List<Pair<int, float> > new_selection_values;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
|
|
|
const SelectedKey &sk = E->key();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float t = animation->track_get_key_time(sk.track, sk.key);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float dst_time = t + (timeline_pos - top_time);
|
2016-06-19 01:22:03 +00:00
|
|
|
int dst_track = sk.track + (start_track - top_track);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (dst_track < 0 || dst_track >= animation->get_track_count())
|
2016-06-19 01:22:03 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (animation->track_get_type(dst_track) != animation->track_get_type(sk.track))
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int existing_idx = animation->track_find_key(dst_track, dst_time, true);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_insert_key", dst_track, dst_time, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", dst_track, dst_time);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Pair<int, float> p;
|
|
|
|
p.first = dst_track;
|
|
|
|
p.second = dst_time;
|
|
|
|
new_selection_values.push_back(p);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (existing_idx != -1) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", dst_track, dst_time, animation->track_get_key_value(dst_track, existing_idx), animation->track_get_key_transition(dst_track, existing_idx));
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
//reselect duplicated
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<SelectedKey, KeyInfo> new_selection;
|
|
|
|
for (List<Pair<int, float> >::Element *E = new_selection_values.front(); E; E = E->next()) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int track = E->get().first;
|
2016-06-19 01:22:03 +00:00
|
|
|
float time = E->get().second;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int existing_idx = animation->track_find_key(track, time, true);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (existing_idx == -1)
|
2016-06-19 01:22:03 +00:00
|
|
|
continue;
|
|
|
|
SelectedKey sk2;
|
2017-03-05 15:44:50 +00:00
|
|
|
sk2.track = track;
|
|
|
|
sk2.key = existing_idx;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
|
|
|
KeyInfo ki;
|
2017-03-05 15:44:50 +00:00
|
|
|
ki.pos = time;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
new_selection[sk2] = ki;
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
selection = new_selection;
|
2016-06-19 01:22:03 +00:00
|
|
|
track_editor->update();
|
|
|
|
_edit_if_single_selection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 21:55:05 +00:00
|
|
|
void AnimationKeyEditor::_menu_track(int p_type) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!animation.is_valid());
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_menu_track_opt = p_type;
|
|
|
|
switch (p_type) {
|
2015-11-18 21:55:05 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
case TRACK_MENU_SCALE:
|
|
|
|
case TRACK_MENU_SCALE_PIVOT: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scale_dialog->popup_centered(Size2(200, 100));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case TRACK_MENU_MOVE_UP: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = selected_track;
|
|
|
|
if (idx > 0 && idx < animation->get_track_count()) {
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Move Anim Track Up"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_move_down", idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_move_up", idx - 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
selected_track = idx - 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRACK_MENU_MOVE_DOWN: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = selected_track;
|
|
|
|
if (idx >= 0 && idx < animation->get_track_count() - 1) {
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Move Anim Track Down"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_move_up", idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_move_down", idx + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
selected_track = idx + 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRACK_MENU_REMOVE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = selected_track;
|
|
|
|
if (idx >= 0 && idx < animation->get_track_count()) {
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Remove Anim Track"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "remove_track", idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "add_track", animation->track_get_type(idx), idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_path", idx, animation->track_get_path(idx));
|
2014-02-10 01:10:30 +00:00
|
|
|
//todo interpolation
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < animation->track_get_key_count(idx); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant v = animation->track_get_key_value(idx, i);
|
|
|
|
float time = animation->track_get_key_time(idx, i);
|
|
|
|
float trans = animation->track_get_key_transition(idx, i);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", idx, time, v);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_key_transition", idx, i, trans);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_interpolation_type", idx, animation->track_get_interpolation_type(idx));
|
|
|
|
if (animation->track_get_type(idx) == Animation::TYPE_VALUE) {
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "value_track_set_update_mode", idx, animation->value_track_get_update_mode(idx));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRACK_MENU_DUPLICATE:
|
|
|
|
case TRACK_MENU_DUPLICATE_TRANSPOSE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_anim_duplicate_keys(p_type == TRACK_MENU_DUPLICATE_TRANSPOSE);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_LINEAR:
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_CONSTANT:
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_OUT:
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_IN:
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_INOUT:
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_OUTIN: {
|
|
|
|
|
|
|
|
if (!selection.size() || !animation.is_valid())
|
|
|
|
break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float t = 0;
|
|
|
|
switch (p_type) {
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_LINEAR: t = 1.0; break;
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_CONSTANT: t = 0.0; break;
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_OUT: t = 0.5; break;
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_IN: t = 2.0; break;
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_INOUT: t = -0.5; break;
|
|
|
|
case TRACK_MENU_SET_ALL_TRANS_OUTIN: t = -2.0; break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->create_action(TTR("Set Transitions to:") + " " + rtos(t));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
const SelectedKey &sk = E->key();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_key_transition", sk.track, sk.key, t);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_key_transition", sk.track, sk.key, animation->track_get_key_transition(sk.track, sk.key));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRACK_MENU_NEXT_STEP: {
|
|
|
|
|
|
|
|
if (animation.is_null())
|
|
|
|
break;
|
|
|
|
float step = animation->get_step();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (step == 0)
|
|
|
|
step = 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float pos = timeline_pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos = Math::stepify(pos + step, step);
|
|
|
|
if (pos > animation->get_length())
|
|
|
|
pos = animation->get_length();
|
|
|
|
timeline_pos = pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
track_pos->update();
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("timeline_changed", pos, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRACK_MENU_PREV_STEP: {
|
|
|
|
if (animation.is_null())
|
|
|
|
break;
|
|
|
|
float step = animation->get_step();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (step == 0)
|
|
|
|
step = 1;
|
|
|
|
|
|
|
|
float pos = timeline_pos;
|
|
|
|
pos = Math::stepify(pos - step, step);
|
|
|
|
if (pos < 0)
|
|
|
|
pos = 0;
|
|
|
|
timeline_pos = pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
track_pos->update();
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("timeline_changed", pos, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case TRACK_MENU_OPTIMIZE: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
optimize_dialog->popup_centered(Size2(250, 180));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2015-12-05 17:18:22 +00:00
|
|
|
case TRACK_MENU_CLEAN_UP: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cleanup_dialog->popup_centered_minsize(Size2(300, 0));
|
2015-12-05 17:18:22 +00:00
|
|
|
} break;
|
|
|
|
case TRACK_MENU_CLEAN_UP_CONFIRM: {
|
|
|
|
|
|
|
|
if (cleanup_all->is_pressed()) {
|
|
|
|
List<StringName> names;
|
|
|
|
AnimationPlayerEditor::singleton->get_player()->get_animation_list(&names);
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
|
2015-12-05 17:18:22 +00:00
|
|
|
_cleanup_animation(AnimationPlayerEditor::singleton->get_player()->get_animation(E->get()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_cleanup_animation(animation);
|
|
|
|
}
|
|
|
|
} break;
|
2015-05-25 04:46:45 +00:00
|
|
|
case CURVE_SET_LINEAR: {
|
|
|
|
curve_edit->force_transition(1.0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
} break;
|
|
|
|
case CURVE_SET_IN: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_edit->force_transition(4.0);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case CURVE_SET_OUT: {
|
|
|
|
|
|
|
|
curve_edit->force_transition(0.25);
|
|
|
|
} break;
|
|
|
|
case CURVE_SET_INOUT: {
|
|
|
|
curve_edit->force_transition(-4);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case CURVE_SET_OUTIN: {
|
|
|
|
|
|
|
|
curve_edit->force_transition(-0.25);
|
|
|
|
} break;
|
|
|
|
case CURVE_SET_CONSTANT: {
|
|
|
|
|
|
|
|
curve_edit->force_transition(0);
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-05 17:18:22 +00:00
|
|
|
void AnimationKeyEditor::_cleanup_animation(Ref<Animation> p_animation) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < p_animation->get_track_count(); i++) {
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool prop_exists = false;
|
|
|
|
Variant::Type valid_type = Variant::NIL;
|
|
|
|
Object *obj = NULL;
|
2015-12-05 17:18:22 +00:00
|
|
|
|
|
|
|
RES res;
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *node = root->get_node_and_resource(p_animation->track_get_path(i), res);
|
2015-12-05 17:18:22 +00:00
|
|
|
|
|
|
|
if (res.is_valid()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
obj = res.ptr();
|
2015-12-05 17:18:22 +00:00
|
|
|
} else if (node) {
|
2017-03-05 15:44:50 +00:00
|
|
|
obj = node;
|
2015-12-05 17:18:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (obj && p_animation->track_get_type(i) == Animation::TYPE_VALUE) {
|
|
|
|
valid_type = obj->get_static_property_type(p_animation->track_get_path(i).get_property(), &prop_exists);
|
2015-12-05 17:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!obj && cleanup_tracks->is_pressed()) {
|
|
|
|
|
2015-12-08 14:21:12 +00:00
|
|
|
p_animation->remove_track(i);
|
2015-12-05 17:18:22 +00:00
|
|
|
i--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!prop_exists || p_animation->track_get_type(i) != Animation::TYPE_VALUE || cleanup_keys->is_pressed() == false)
|
2015-12-05 17:18:22 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < p_animation->track_get_key_count(i); j++) {
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant v = p_animation->track_get_key_value(i, j);
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!Variant::can_convert(v.get_type(), valid_type)) {
|
|
|
|
p_animation->track_remove_key(i, j);
|
2015-12-05 17:18:22 +00:00
|
|
|
j--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_animation->track_get_key_count(i) == 0 && cleanup_tracks->is_pressed()) {
|
2015-12-08 14:21:12 +00:00
|
|
|
p_animation->remove_track(i);
|
2015-12-05 17:18:22 +00:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->clear_history();
|
|
|
|
_update_paths();
|
|
|
|
}
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::_animation_optimize() {
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
animation->optimize(optimize_linear_error->get_value(), optimize_angular_error->get_value(), optimize_max_angle->get_value());
|
2014-11-12 14:23:23 +00:00
|
|
|
track_editor->update();
|
|
|
|
undo_redo->clear_history();
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
float AnimationKeyEditor::_get_zoom_scale() const {
|
|
|
|
|
2017-01-04 04:16:14 +00:00
|
|
|
float zv = zoom->get_value();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (zv < 1) {
|
|
|
|
zv = 1.0 - zv;
|
|
|
|
return Math::pow(1.0f + zv, 8.0f) * 100;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
return 1.0 / Math::pow(zv, 8.0f) * 100;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
void AnimationKeyEditor::_track_position_draw() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!animation.is_valid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<StyleBox> style = get_stylebox("normal", "TextEdit");
|
|
|
|
Size2 size = track_editor->get_size() - style->get_minimum_size();
|
2014-02-10 01:10:30 +00:00
|
|
|
Size2 ofs = style->get_offset();
|
|
|
|
|
|
|
|
int settings_limit = size.width - right_data_size_cache;
|
|
|
|
int name_limit = settings_limit * name_column_ratio;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float keys_from = h_scroll->get_value();
|
2014-02-10 01:10:30 +00:00
|
|
|
float zoom_scale = _get_zoom_scale();
|
2017-03-05 15:44:50 +00:00
|
|
|
float keys_to = keys_from + (settings_limit - name_limit) / zoom_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//will move to separate control! (for speedup)
|
2017-03-05 15:44:50 +00:00
|
|
|
if (timeline_pos >= keys_from && timeline_pos < keys_to) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//draw position
|
2017-01-04 04:16:14 +00:00
|
|
|
int pixel = (timeline_pos - h_scroll->get_value()) * zoom_scale;
|
2017-03-05 15:44:50 +00:00
|
|
|
pixel += name_limit;
|
2017-09-08 06:06:02 +00:00
|
|
|
track_pos->draw_line(ofs + Point2(pixel, 0), ofs + Point2(pixel, size.height), get_color("accent_color", "Editor"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_track_editor_draw() {
|
|
|
|
|
|
|
|
if (animation.is_valid() && animation->get_track_count()) {
|
|
|
|
if (selected_track < 0)
|
2017-03-05 15:44:50 +00:00
|
|
|
selected_track = 0;
|
|
|
|
else if (selected_track >= animation->get_track_count())
|
|
|
|
selected_track = animation->get_track_count() - 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
track_pos->update();
|
2017-03-05 15:44:50 +00:00
|
|
|
Control *te = track_editor;
|
|
|
|
Ref<StyleBox> style = get_stylebox("normal", "TextEdit");
|
|
|
|
te->draw_style_box(style, Rect2(Point2(), track_editor->get_size()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (te->has_focus()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_style_box(get_stylebox("bg_focus", "Tree"), Rect2(Point2(), track_editor->get_size()));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!animation.is_valid()) {
|
|
|
|
v_scroll->hide();
|
|
|
|
h_scroll->hide();
|
2015-11-18 21:55:05 +00:00
|
|
|
menu_add_track->set_disabled(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
menu_track->set_disabled(true);
|
|
|
|
edit_button->set_disabled(true);
|
2015-05-25 04:46:45 +00:00
|
|
|
key_editor_tab->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
move_up_button->set_disabled(true);
|
|
|
|
move_down_button->set_disabled(true);
|
|
|
|
remove_button->set_disabled(true);
|
2016-01-17 23:03:57 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-18 21:55:05 +00:00
|
|
|
menu_add_track->set_disabled(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
menu_track->set_disabled(false);
|
|
|
|
edit_button->set_disabled(false);
|
|
|
|
move_up_button->set_disabled(false);
|
|
|
|
move_down_button->set_disabled(false);
|
|
|
|
remove_button->set_disabled(false);
|
2015-05-25 04:46:45 +00:00
|
|
|
if (edit_button->is_pressed())
|
|
|
|
key_editor_tab->show();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te_drawing = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Size2 size = te->get_size() - style->get_minimum_size();
|
2014-02-10 01:10:30 +00:00
|
|
|
Size2 ofs = style->get_offset();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Font> font = te->get_font("font", "Tree");
|
|
|
|
int sep = get_constant("vseparation", "Tree");
|
|
|
|
int hsep = get_constant("hseparation", "Tree");
|
|
|
|
Color color = get_color("font_color", "Tree");
|
2017-09-09 01:32:06 +00:00
|
|
|
Color sepcolor = color;
|
|
|
|
sepcolor.a = 0.2;
|
|
|
|
Color timecolor = color;
|
|
|
|
timecolor.a = 0.2;
|
|
|
|
Color hover_color = color;
|
|
|
|
hover_color.a = 0.05;
|
|
|
|
Color select_color = color;
|
|
|
|
select_color.a = 0.1;
|
2017-08-08 02:55:24 +00:00
|
|
|
Color invalid_path_color = get_color("error_color", "Editor");
|
2017-10-12 18:59:25 +00:00
|
|
|
Color track_select_color = get_color("highlighted_font_color", "Editor");
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
Ref<Texture> remove_icon = get_icon("Remove", "EditorIcons");
|
|
|
|
Ref<Texture> move_up_icon = get_icon("MoveUp", "EditorIcons");
|
|
|
|
Ref<Texture> move_down_icon = get_icon("MoveDown", "EditorIcons");
|
|
|
|
Ref<Texture> remove_icon_hl = get_icon("RemoveHl", "EditorIcons");
|
|
|
|
Ref<Texture> move_up_icon_hl = get_icon("MoveUpHl", "EditorIcons");
|
|
|
|
Ref<Texture> move_down_icon_hl = get_icon("MoveDownHl", "EditorIcons");
|
|
|
|
Ref<Texture> add_key_icon = get_icon("TrackAddKey", "EditorIcons");
|
|
|
|
Ref<Texture> add_key_icon_hl = get_icon("TrackAddKeyHl", "EditorIcons");
|
|
|
|
Ref<Texture> down_icon = get_icon("select_arrow", "Tree");
|
|
|
|
|
|
|
|
Ref<Texture> wrap_icon[2] = {
|
|
|
|
get_icon("InterpWrapClamp", "EditorIcons"),
|
|
|
|
get_icon("InterpWrapLoop", "EditorIcons"),
|
2017-01-09 03:41:16 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> interp_icon[3] = {
|
|
|
|
get_icon("InterpRaw", "EditorIcons"),
|
|
|
|
get_icon("InterpLinear", "EditorIcons"),
|
|
|
|
get_icon("InterpCubic", "EditorIcons")
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> cont_icon[3] = {
|
|
|
|
get_icon("TrackContinuous", "EditorIcons"),
|
|
|
|
get_icon("TrackDiscrete", "EditorIcons"),
|
|
|
|
get_icon("TrackTrigger", "EditorIcons")
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> type_icon[3] = {
|
|
|
|
get_icon("KeyValue", "EditorIcons"),
|
|
|
|
get_icon("KeyXform", "EditorIcons"),
|
|
|
|
get_icon("KeyCall", "EditorIcons")
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> invalid_icon = get_icon("KeyInvalid", "EditorIcons");
|
|
|
|
Ref<Texture> invalid_icon_hover = get_icon("KeyInvalidHover", "EditorIcons");
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> hsize_icon = get_icon("Hsize", "EditorIcons");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> type_hover = get_icon("KeyHover", "EditorIcons");
|
|
|
|
Ref<Texture> type_selected = get_icon("KeySelected", "EditorIcons");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int right_separator_ofs = down_icon->get_width() * 3 + add_key_icon->get_width() + interp_icon[0]->get_width() + wrap_icon[0]->get_width() + cont_icon[0]->get_width() + hsep * 9;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int h = font->get_height() + sep;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int fit = (size.height / h) - 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
int total = animation->get_track_count();
|
|
|
|
if (total < fit) {
|
|
|
|
v_scroll->hide();
|
2017-03-05 15:44:50 +00:00
|
|
|
v_scroll->set_max(total);
|
|
|
|
v_scroll->set_page(fit);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
v_scroll->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
v_scroll->set_max(total);
|
|
|
|
v_scroll->set_page(fit);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int settings_limit = size.width - right_separator_ofs;
|
|
|
|
int name_limit = settings_limit * name_column_ratio;
|
|
|
|
|
2017-09-09 01:32:06 +00:00
|
|
|
Color linecolor = color;
|
|
|
|
linecolor.a = 0.2;
|
2017-08-08 02:55:24 +00:00
|
|
|
te->draw_line(ofs + Point2(name_limit, 0), ofs + Point2(name_limit, size.height), linecolor);
|
|
|
|
te->draw_line(ofs + Point2(settings_limit, 0), ofs + Point2(settings_limit, size.height), linecolor);
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_texture(hsize_icon, ofs + Point2(name_limit - hsize_icon->get_width() - hsep, (h - hsize_icon->get_height()) / 2));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-08 02:55:24 +00:00
|
|
|
te->draw_line(ofs + Point2(0, h), ofs + Point2(size.width, h), linecolor);
|
2014-02-10 01:10:30 +00:00
|
|
|
// draw time
|
|
|
|
|
|
|
|
float keys_from;
|
|
|
|
float keys_to;
|
|
|
|
float zoom_scale;
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int zoomw = settings_limit - name_limit;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float scale = _get_zoom_scale();
|
2017-03-05 15:44:50 +00:00
|
|
|
zoom_scale = scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float l = animation->get_length();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (l <= 0)
|
|
|
|
l = 0.001; //avoid crashor
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-04 04:16:14 +00:00
|
|
|
int end_px = (l - h_scroll->get_value()) * scale;
|
|
|
|
int begin_px = -h_scroll->get_value() * scale;
|
2017-08-08 02:55:24 +00:00
|
|
|
Color notimecol = get_color("dark_color_2", "Editor");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_rect(Rect2(ofs + Point2(name_limit, 0), Point2(zoomw - 1, h)), notimecol);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (begin_px < zoomw && end_px > 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (begin_px < 0)
|
|
|
|
begin_px = 0;
|
|
|
|
if (end_px > zoomw)
|
|
|
|
end_px = zoomw;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_rect(Rect2(ofs + Point2(name_limit + begin_px, 0), Point2(end_px - begin_px - 1, h)), timecolor);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
keys_from = h_scroll->get_value();
|
|
|
|
keys_to = keys_from + zoomw / scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
float time_min = 0;
|
|
|
|
float time_max = animation->get_length();
|
|
|
|
for (int i = 0; i < animation->get_track_count(); i++) {
|
|
|
|
|
|
|
|
if (animation->track_get_key_count(i) > 0) {
|
|
|
|
|
|
|
|
float beg = animation->track_get_key_time(i, 0);
|
|
|
|
if (beg < time_min)
|
|
|
|
time_min = beg;
|
|
|
|
float end = animation->track_get_key_time(i, animation->track_get_key_count(i) - 1);
|
|
|
|
if (end > time_max)
|
|
|
|
time_max = end;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float extra = (zoomw / scale) * 0.5;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (time_min < -0.001)
|
|
|
|
time_min -= extra;
|
|
|
|
time_max += extra;
|
2014-02-10 01:10:30 +00:00
|
|
|
h_scroll->set_min(time_min);
|
|
|
|
h_scroll->set_max(time_max);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (zoomw / scale < (time_max - time_min)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
h_scroll->show();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
h_scroll->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
h_scroll->set_page(zoomw / scale);
|
|
|
|
|
|
|
|
Color color_time_sec = color;
|
|
|
|
Color color_time_dec = color;
|
2017-03-05 15:44:50 +00:00
|
|
|
color_time_dec.a *= 0.5;
|
2014-02-10 01:10:30 +00:00
|
|
|
#define SC_ADJ 100
|
2017-03-05 15:44:50 +00:00
|
|
|
int min = 30;
|
|
|
|
int dec = 1;
|
|
|
|
int step = 1;
|
|
|
|
int decimals = 2;
|
|
|
|
bool step_found = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (!step_found) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const int _multp[3] = { 1, 2, 5 };
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
step = (_multp[i] * dec);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (step * scale / SC_ADJ > min) {
|
|
|
|
step_found = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (step_found)
|
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
dec *= 10;
|
2014-02-10 01:10:30 +00:00
|
|
|
decimals--;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (decimals < 0)
|
|
|
|
decimals = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < zoomw; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float pos = h_scroll->get_value() + double(i) / scale;
|
|
|
|
float prev = h_scroll->get_value() + (double(i) - 1.0) / scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int sc = int(Math::floor(pos * SC_ADJ));
|
|
|
|
int prev_sc = int(Math::floor(prev * SC_ADJ));
|
2014-02-10 01:10:30 +00:00
|
|
|
bool sub = (sc % SC_ADJ);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if ((sc / step) != (prev_sc / step) || (prev_sc < 0 && sc >= 0)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int scd = sc < 0 ? prev_sc : sc;
|
2017-08-08 02:55:24 +00:00
|
|
|
te->draw_line(ofs + Point2(name_limit + i, 0), ofs + Point2(name_limit + i, h), linecolor);
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_string(font, ofs + Point2(name_limit + i + 3, (h - font->get_height()) / 2 + font->get_ascent()).floor(), String::num((scd - (scd % step)) / double(SC_ADJ), decimals), sub ? color_time_dec : color_time_sec, zoomw - i);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
color.a *= 0.5;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < fit; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
//this code sucks, i always forget how it works
|
|
|
|
|
2017-01-04 04:16:14 +00:00
|
|
|
int idx = v_scroll->get_value() + i;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (idx >= animation->get_track_count())
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2017-03-05 15:44:50 +00:00
|
|
|
int y = h + i * h + sep;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool prop_exists = false;
|
|
|
|
Variant::Type valid_type = Variant::NIL;
|
|
|
|
Object *obj = NULL;
|
2015-12-05 17:18:22 +00:00
|
|
|
|
|
|
|
RES res;
|
2017-08-15 22:05:13 +00:00
|
|
|
Node *node = root ? root->get_node_and_resource(animation->track_get_path(idx), res) : (Node *)NULL;
|
2015-12-05 17:18:22 +00:00
|
|
|
|
|
|
|
if (res.is_valid()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
obj = res.ptr();
|
2015-12-05 17:18:22 +00:00
|
|
|
} else if (node) {
|
2017-03-05 15:44:50 +00:00
|
|
|
obj = node;
|
2015-12-05 17:18:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (obj && animation->track_get_type(idx) == Animation::TYPE_VALUE) {
|
|
|
|
valid_type = obj->get_static_property_type(animation->track_get_path(idx).get_property(), &prop_exists);
|
2015-12-05 17:18:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (/*mouse_over.over!=MouseOver::OVER_NONE &&*/ idx == mouse_over.track) {
|
|
|
|
Color sepc = hover_color;
|
|
|
|
te->draw_rect(Rect2(ofs + Point2(0, y), Size2(size.width, h - 1)), sepc);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selected_track == idx) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Color tc = select_color;
|
|
|
|
//tc.a*=0.7;
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_rect(Rect2(ofs + Point2(0, y), Size2(size.width - 1, h - 1)), tc);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_texture(type_icon[animation->track_get_type(idx)], ofs + Point2(0, y + (h - type_icon[0]->get_height()) / 2).floor());
|
2014-02-10 01:10:30 +00:00
|
|
|
NodePath np = animation->track_get_path(idx);
|
2017-08-15 22:05:13 +00:00
|
|
|
Node *n = root ? root->get_node(np) : (Node *)NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
Color ncol = color;
|
|
|
|
if (n && editor_selection->is_selected(n))
|
2017-03-05 15:44:50 +00:00
|
|
|
ncol = track_select_color;
|
|
|
|
te->draw_string(font, Point2(ofs + Point2(type_icon[0]->get_width() + sep, y + font->get_ascent() + (sep / 2))).floor(), np, ncol, name_limit - (type_icon[0]->get_width() + sep) - 5);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-12-05 17:18:22 +00:00
|
|
|
if (!obj)
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_line(ofs + Point2(0, y + h / 2), ofs + Point2(name_limit, y + h / 2), invalid_path_color);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_line(ofs + Point2(0, y + h), ofs + Point2(size.width, y + h), sepcolor);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Point2 icon_ofs = ofs + Point2(size.width, y + (h - remove_icon->get_height()) / 2).floor();
|
2017-08-08 02:55:24 +00:00
|
|
|
icon_ofs.y += 4 * EDSCALE;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/* icon_ofs.x-=remove_icon->get_width();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
te->draw_texture((mouse_over.over==MouseOver::OVER_REMOVE && mouse_over.track==idx)?remove_icon_hl:remove_icon,icon_ofs);
|
|
|
|
icon_ofs.x-=hsep;
|
|
|
|
icon_ofs.x-=move_down_icon->get_width();
|
|
|
|
te->draw_texture((mouse_over.over==MouseOver::OVER_DOWN && mouse_over.track==idx)?move_down_icon_hl:move_down_icon,icon_ofs);
|
|
|
|
icon_ofs.x-=hsep;
|
|
|
|
icon_ofs.x-=move_up_icon->get_width();
|
|
|
|
te->draw_texture((mouse_over.over==MouseOver::OVER_UP && mouse_over.track==idx)?move_up_icon_hl:move_up_icon,icon_ofs);
|
|
|
|
icon_ofs.x-=hsep;
|
|
|
|
te->draw_line(Point2(icon_ofs.x,ofs.y+y),Point2(icon_ofs.x,ofs.y+y+h),sepcolor);
|
|
|
|
|
|
|
|
icon_ofs.x-=hsep;
|
|
|
|
*/
|
2017-11-18 15:23:22 +00:00
|
|
|
track_ofs[0] = size.width - icon_ofs.x + ofs.x;
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= down_icon->get_width();
|
2017-08-08 02:55:24 +00:00
|
|
|
te->draw_texture(down_icon, icon_ofs - Size2(0, 4 * EDSCALE));
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int wrap_type = animation->track_get_interpolation_loop_wrap(idx) ? 1 : 0;
|
|
|
|
icon_ofs.x -= hsep;
|
|
|
|
icon_ofs.x -= wrap_icon[wrap_type]->get_width();
|
|
|
|
te->draw_texture(wrap_icon[wrap_type], icon_ofs);
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= hsep;
|
|
|
|
te->draw_line(Point2(icon_ofs.x, ofs.y + y), Point2(icon_ofs.x, ofs.y + y + h), sepcolor);
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-11-18 15:23:22 +00:00
|
|
|
track_ofs[1] = size.width - icon_ofs.x + ofs.x;
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= down_icon->get_width();
|
2017-08-08 02:55:24 +00:00
|
|
|
te->draw_texture(down_icon, icon_ofs - Size2(0, 4 * EDSCALE));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int interp_type = animation->track_get_interpolation_type(idx);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_CONTINUE(interp_type < 0 || interp_type >= 3);
|
|
|
|
icon_ofs.x -= hsep;
|
|
|
|
icon_ofs.x -= interp_icon[interp_type]->get_width();
|
|
|
|
te->draw_texture(interp_icon[interp_type], icon_ofs);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= hsep;
|
|
|
|
te->draw_line(Point2(icon_ofs.x, ofs.y + y), Point2(icon_ofs.x, ofs.y + y + h), sepcolor);
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-11-18 15:23:22 +00:00
|
|
|
track_ofs[2] = size.width - icon_ofs.x + ofs.x;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (animation->track_get_type(idx) == Animation::TYPE_VALUE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-19 04:43:02 +00:00
|
|
|
int umode = animation->value_track_get_update_mode(idx);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= hsep;
|
|
|
|
icon_ofs.x -= down_icon->get_width();
|
2017-08-08 02:55:24 +00:00
|
|
|
te->draw_texture(down_icon, icon_ofs - Size2(0, 4 * EDSCALE));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= hsep;
|
|
|
|
icon_ofs.x -= cont_icon[umode]->get_width();
|
|
|
|
te->draw_texture(cont_icon[umode], icon_ofs);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= hsep * 2 + cont_icon[0]->get_width() + down_icon->get_width();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= hsep;
|
|
|
|
te->draw_line(Point2(icon_ofs.x, ofs.y + y), Point2(icon_ofs.x, ofs.y + y + h), sepcolor);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-18 15:23:22 +00:00
|
|
|
track_ofs[3] = size.width - icon_ofs.x + ofs.x;
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
icon_ofs.x -= hsep;
|
|
|
|
icon_ofs.x -= add_key_icon->get_width();
|
|
|
|
te->draw_texture((mouse_over.over == MouseOver::OVER_ADD_KEY && mouse_over.track == idx) ? add_key_icon_hl : add_key_icon, icon_ofs);
|
2017-11-18 15:23:22 +00:00
|
|
|
track_ofs[4] = size.width - icon_ofs.x + ofs.x;
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//draw the keys;
|
|
|
|
int tt = animation->track_get_type(idx);
|
2017-03-05 15:44:50 +00:00
|
|
|
float key_vofs = Math::floor((float)(h - type_icon[tt]->get_height()) / 2);
|
|
|
|
float key_hofs = -Math::floor((float)type_icon[tt]->get_height() / 2);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int kc = animation->track_get_key_count(idx);
|
|
|
|
bool first = true;
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < kc; i++) {
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float time = animation->track_get_key_time(idx, i);
|
|
|
|
if (time < keys_from)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (time > keys_to) {
|
2015-05-27 20:30:50 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (first && i > 0 && animation->track_get_key_value(idx, i) == animation->track_get_key_value(idx, i - 1)) {
|
2015-05-27 20:30:50 +00:00
|
|
|
//draw whole line
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_line(ofs + Vector2(name_limit, y + h / 2), ofs + Point2(settings_limit, y + h / 2), color);
|
2015-05-27 20:30:50 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2015-05-27 20:30:50 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float x = key_hofs + name_limit + (time - keys_from) * zoom_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Ref<Texture> tex = type_icon[tt];
|
|
|
|
|
|
|
|
SelectedKey sk;
|
2017-03-05 15:44:50 +00:00
|
|
|
sk.key = i;
|
|
|
|
sk.track = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (selection.has(sk)) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (click.click == ClickOver::CLICK_MOVE_KEYS)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
tex = type_selected;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mouse_over.over == MouseOver::OVER_KEY && mouse_over.track == idx && mouse_over.over_key == i)
|
|
|
|
tex = type_hover;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant value = animation->track_get_key_value(idx, i);
|
|
|
|
if (first && i > 0 && value == animation->track_get_key_value(idx, i - 1)) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_line(ofs + Vector2(name_limit, y + h / 2), ofs + Point2(x, y + h / 2), color);
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i < kc - 1 && value == animation->track_get_key_value(idx, i + 1)) {
|
|
|
|
float x_n = key_hofs + name_limit + (animation->track_get_key_time(idx, i + 1) - keys_from) * zoom_scale;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
x_n = MIN(x_n, settings_limit);
|
|
|
|
te->draw_line(ofs + Point2(x_n, y + h / 2), ofs + Point2(x, y + h / 2), color);
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (prop_exists && !Variant::can_convert(value.get_type(), valid_type)) {
|
|
|
|
te->draw_texture(invalid_icon, ofs + Point2(x, y + key_vofs).floor());
|
2015-12-05 17:18:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (prop_exists && !Variant::can_convert(value.get_type(), valid_type)) {
|
|
|
|
if (tex == type_hover)
|
|
|
|
te->draw_texture(invalid_icon_hover, ofs + Point2(x, y + key_vofs).floor());
|
2015-12-05 17:18:22 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_texture(invalid_icon, ofs + Point2(x, y + key_vofs).floor());
|
2015-12-05 17:18:22 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_texture(tex, ofs + Point2(x, y + key_vofs).floor());
|
2015-12-05 17:18:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
first = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (click.click) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case ClickOver::CLICK_SELECT_KEYS: {
|
|
|
|
|
2017-09-08 06:06:02 +00:00
|
|
|
Color box_color = get_color("accent_color", "Editor");
|
2017-05-02 20:13:12 +00:00
|
|
|
box_color.a = 0.35;
|
|
|
|
te->draw_rect(Rect2(click.at, click.to - click.at), box_color);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case ClickOver::CLICK_MOVE_KEYS: {
|
|
|
|
|
|
|
|
float from_t = 1e20;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
|
|
|
|
float t = animation->track_get_key_time(E->key().track, E->key().key);
|
|
|
|
if (t < from_t)
|
|
|
|
from_t = t;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float motion = from_t + (click.to.x - click.at.x) / zoom_scale;
|
2017-01-04 04:16:14 +00:00
|
|
|
if (step->get_value())
|
2017-03-05 15:44:50 +00:00
|
|
|
motion = Math::stepify(motion, step->get_value());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int idx = E->key().track;
|
2017-03-05 15:44:50 +00:00
|
|
|
int i = idx - v_scroll->get_value();
|
|
|
|
if (i < 0 || i >= fit)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
int y = h + i * h + sep;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float key_vofs = Math::floor((float)(h - type_selected->get_height()) / 2);
|
|
|
|
float key_hofs = -Math::floor((float)type_selected->get_height() / 2);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float time = animation->track_get_key_time(idx, E->key().key);
|
|
|
|
float diff = time - from_t;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float t = motion + diff;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float x = (t - keys_from) * zoom_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
//x+=click.to.x - click.at.x;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (x < 0 || x >= (settings_limit - name_limit))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
x += name_limit;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te->draw_texture(type_selected, ofs + Point2(x + key_hofs, y + key_vofs).floor());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default: {};
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
te_drawing = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::_track_name_changed(const String &p_name) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!animation.is_valid());
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Track Rename"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_path", track_name_editing, p_name);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_path", track_name_editing, animation->track_get_path(track_name_editing));
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
track_name->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_track_menu_selected(int p_idx) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!animation.is_valid());
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (interp_editing != -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(interp_editing, animation->get_track_count());
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Track Change Interpolation"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_interpolation_type", interp_editing, p_idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_interpolation_type", interp_editing, animation->track_get_interpolation_type(interp_editing));
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (cont_editing != -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(cont_editing, animation->get_track_count());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Track Change Value Mode"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "value_track_set_update_mode", cont_editing, p_idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "value_track_set_update_mode", cont_editing, animation->value_track_get_update_mode(cont_editing));
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (wrap_editing != -1) {
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(wrap_editing, animation->get_track_count());
|
2017-01-09 03:41:16 +00:00
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Anim Track Change Wrap Mode"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_interpolation_loop_wrap", wrap_editing, p_idx ? true : false);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_interpolation_loop_wrap", wrap_editing, animation->track_get_interpolation_loop_wrap(wrap_editing));
|
2017-01-09 03:41:16 +00:00
|
|
|
undo_redo->commit_action();
|
2016-06-19 01:22:03 +00:00
|
|
|
} else {
|
|
|
|
switch (p_idx) {
|
|
|
|
|
|
|
|
case RIGHT_MENU_DUPLICATE:
|
2017-03-05 15:44:50 +00:00
|
|
|
_anim_duplicate_keys();
|
|
|
|
break;
|
2016-06-19 01:22:03 +00:00
|
|
|
case RIGHT_MENU_DUPLICATE_TRANSPOSE:
|
2017-03-05 15:44:50 +00:00
|
|
|
_anim_duplicate_keys(true);
|
|
|
|
break;
|
2016-06-19 01:22:03 +00:00
|
|
|
case RIGHT_MENU_REMOVE:
|
2017-03-05 15:44:50 +00:00
|
|
|
_anim_delete_keys();
|
|
|
|
break;
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct _AnimMoveRestore {
|
|
|
|
|
|
|
|
int track;
|
|
|
|
float time;
|
|
|
|
Variant key;
|
|
|
|
float transition;
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::_clear_selection_for_anim(const Ref<Animation> &p_anim) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(animation == p_anim))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2015-05-25 04:46:45 +00:00
|
|
|
//selection.clear();
|
|
|
|
_clear_selection();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::_select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!(animation == p_anim))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = animation->track_find_key(p_track, p_pos, true);
|
|
|
|
ERR_FAIL_COND(idx < 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
SelectedKey sk;
|
2017-03-05 15:44:50 +00:00
|
|
|
sk.track = p_track;
|
|
|
|
sk.key = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
KeyInfo ki;
|
2017-03-05 15:44:50 +00:00
|
|
|
ki.pos = p_pos;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
selection.insert(sk, ki);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
PropertyInfo AnimationKeyEditor::_find_hint_for_track(int p_idx, NodePath &r_base_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
r_base_path = NodePath();
|
|
|
|
ERR_FAIL_COND_V(!animation.is_valid(), PropertyInfo());
|
|
|
|
ERR_FAIL_INDEX_V(p_idx, animation->get_track_count(), PropertyInfo());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!root)
|
|
|
|
return PropertyInfo();
|
|
|
|
|
|
|
|
NodePath path = animation->track_get_path(p_idx);
|
|
|
|
|
|
|
|
if (!root->has_node_and_resource(path))
|
|
|
|
return PropertyInfo();
|
|
|
|
|
|
|
|
RES res;
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *node = root->get_node_and_resource(path, res);
|
2016-01-31 23:06:37 +00:00
|
|
|
|
|
|
|
if (node) {
|
2017-03-05 15:44:50 +00:00
|
|
|
r_base_path = node->get_path();
|
2016-01-31 23:06:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String property = path.get_property();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (property == "")
|
2016-01-31 23:06:37 +00:00
|
|
|
return PropertyInfo();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
if (res.is_valid())
|
|
|
|
res->get_property_list(&pinfo);
|
2017-08-25 15:14:33 +00:00
|
|
|
else if (node)
|
2014-02-10 01:10:30 +00:00
|
|
|
node->get_property_list(&pinfo);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (E->get().name == property)
|
2014-02-10 01:10:30 +00:00
|
|
|
return E->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
void AnimationKeyEditor::_curve_transition_changed(float p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selection.size() == 0)
|
2015-05-25 04:46:45 +00:00
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selection.size() == 1)
|
|
|
|
undo_redo->create_action(TTR("Edit Node Curve"), UndoRedo::MERGE_ENDS);
|
2015-05-25 04:46:45 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->create_action(TTR("Edit Selection Curve"), UndoRedo::MERGE_ENDS);
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
int track = E->key().track;
|
|
|
|
int key = E->key().key;
|
2017-03-05 15:44:50 +00:00
|
|
|
float prev_val = animation->track_get_key_transition(track, key);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_key_transition", track, key, p_what);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_set_key_transition", track, key, prev_val);
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_toggle_edit_curves() {
|
|
|
|
|
|
|
|
if (edit_button->is_pressed())
|
|
|
|
key_editor_tab->show();
|
|
|
|
else
|
|
|
|
key_editor_tab->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AnimationKeyEditor::_edit_if_single_selection() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selection.size() != 1) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selection.size() == 0) {
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_edit->set_mode(AnimationCurveEdit::MODE_DISABLED);
|
2016-01-10 14:51:05 +00:00
|
|
|
//print_line("disable");
|
2015-05-25 04:46:45 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
curve_edit->set_mode(AnimationCurveEdit::MODE_MULTIPLE);
|
|
|
|
curve_edit->set_transition(1.0);
|
|
|
|
curve_edit->clear_multiples();
|
|
|
|
//add all
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_edit->set_multiple(animation->track_get_key_transition(E->key().track, E->key().key));
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
2016-01-10 14:51:05 +00:00
|
|
|
//print_line("multiple");
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
curve_edit->set_mode(AnimationCurveEdit::MODE_SINGLE);
|
2016-01-10 14:51:05 +00:00
|
|
|
//print_line("regular");
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
int idx = selection.front()->key().track;
|
|
|
|
int key = selection.front()->key().key;
|
|
|
|
{
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
key_edit->animation = animation;
|
|
|
|
key_edit->track = idx;
|
|
|
|
key_edit->key_ofs = animation->track_get_key_time(idx, key);
|
|
|
|
key_edit->hint = _find_hint_for_track(idx, key_edit->base);
|
2015-05-25 04:46:45 +00:00
|
|
|
key_edit->notify_change();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_edit->set_transition(animation->track_get_key_transition(idx, key));
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
/*key_edit_dialog->set_size( Size2( 200,200) );
|
2017-03-29 15:29:38 +00:00
|
|
|
key_edit_dialog->set_position( track_editor->get_global_position() + ofs + mpos +Point2(-100,20));
|
2015-05-25 04:46:45 +00:00
|
|
|
key_edit_dialog->popup();*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-19 01:22:03 +00:00
|
|
|
void AnimationKeyEditor::_anim_delete_keys() {
|
|
|
|
if (selection.size()) {
|
|
|
|
undo_redo->create_action(TTR("Anim Delete Keys"));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->key().track, E->key().key);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->key().track, E->get().pos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
|
|
|
|
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
2016-06-19 01:22:03 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
//selection.clear();
|
|
|
|
accept_event();
|
|
|
|
_edit_if_single_selection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Control *te = track_editor;
|
|
|
|
Ref<StyleBox> style = get_stylebox("normal", "TextEdit");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!animation.is_valid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Size2 size = te->get_size() - style->get_minimum_size();
|
2014-02-10 01:10:30 +00:00
|
|
|
Size2 ofs = style->get_offset();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Font> font = te->get_font("font", "Tree");
|
|
|
|
int sep = get_constant("vseparation", "Tree");
|
|
|
|
int hsep = get_constant("hseparation", "Tree");
|
|
|
|
Ref<Texture> remove_icon = get_icon("Remove", "EditorIcons");
|
|
|
|
Ref<Texture> move_up_icon = get_icon("MoveUp", "EditorIcons");
|
|
|
|
Ref<Texture> move_down_icon = get_icon("MoveDown", "EditorIcons");
|
|
|
|
Ref<Texture> down_icon = get_icon("select_arrow", "Tree");
|
|
|
|
Ref<Texture> hsize_icon = get_icon("Hsize", "EditorIcons");
|
|
|
|
Ref<Texture> add_key_icon = get_icon("TrackAddKey", "EditorIcons");
|
|
|
|
|
|
|
|
Ref<Texture> wrap_icon[2] = {
|
|
|
|
get_icon("InterpWrapClamp", "EditorIcons"),
|
|
|
|
get_icon("InterpWrapLoop", "EditorIcons"),
|
2017-01-09 03:41:16 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> interp_icon[3] = {
|
|
|
|
get_icon("InterpRaw", "EditorIcons"),
|
|
|
|
get_icon("InterpLinear", "EditorIcons"),
|
|
|
|
get_icon("InterpCubic", "EditorIcons")
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> cont_icon[3] = {
|
|
|
|
get_icon("TrackContinuous", "EditorIcons"),
|
|
|
|
get_icon("TrackDiscrete", "EditorIcons"),
|
|
|
|
get_icon("TrackTrigger", "EditorIcons")
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> type_icon[3] = {
|
|
|
|
get_icon("KeyValue", "EditorIcons"),
|
|
|
|
get_icon("KeyXform", "EditorIcons"),
|
|
|
|
get_icon("KeyCall", "EditorIcons")
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
int right_separator_ofs = down_icon->get_width() * 3 + add_key_icon->get_width() + interp_icon[0]->get_width() + wrap_icon[0]->get_width() + cont_icon[0]->get_width() + hsep * 9;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int h = font->get_height() + sep;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int fit = (size.height / h) - 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
int total = animation->get_track_count();
|
|
|
|
if (total < fit) {
|
|
|
|
v_scroll->hide();
|
|
|
|
} else {
|
|
|
|
v_scroll->show();
|
2017-03-05 15:44:50 +00:00
|
|
|
v_scroll->set_max(total);
|
|
|
|
v_scroll->set_page(fit);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int settings_limit = size.width - right_separator_ofs;
|
|
|
|
int name_limit = settings_limit * name_column_ratio;
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventKey> key = p_input;
|
|
|
|
if (key.is_valid()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key->get_scancode() == KEY_D && key->is_pressed() && key->get_command()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key->get_shift())
|
|
|
|
_menu_track(TRACK_MENU_DUPLICATE_TRANSPOSE);
|
|
|
|
else
|
|
|
|
_menu_track(TRACK_MENU_DUPLICATE);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
accept_event();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} else if (key->get_scancode() == KEY_DELETE && key->is_pressed() && click.click == ClickOver::CLICK_NONE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
_anim_delete_keys();
|
|
|
|
} else if (animation.is_valid() && animation->get_track_count() > 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key->is_pressed() && (key->is_action("ui_up") || key->is_action("ui_page_up"))) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key->is_action("ui_up"))
|
|
|
|
selected_track--;
|
|
|
|
if (v_scroll->is_visible_in_tree() && key->is_action("ui_page_up"))
|
|
|
|
selected_track--;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (selected_track < 0)
|
|
|
|
selected_track = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (v_scroll->is_visible_in_tree()) {
|
|
|
|
if (v_scroll->get_value() > selected_track)
|
|
|
|
v_scroll->set_value(selected_track);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_editor->update();
|
|
|
|
accept_event();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key->is_pressed() && (key->is_action("ui_down") || key->is_action("ui_page_down"))) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key->is_action("ui_down"))
|
|
|
|
selected_track++;
|
|
|
|
else if (v_scroll->is_visible_in_tree() && key->is_action("ui_page_down"))
|
|
|
|
selected_track += v_scroll->get_page();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (selected_track >= animation->get_track_count())
|
|
|
|
selected_track = animation->get_track_count() - 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (v_scroll->is_visible_in_tree() && v_scroll->get_page() + v_scroll->get_value() < selected_track + 1) {
|
|
|
|
v_scroll->set_value(selected_track - v_scroll->get_page() + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
|
|
|
|
track_editor->update();
|
|
|
|
accept_event();
|
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<InputEventMouseButton> mb = p_input;
|
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->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->get_command()) {
|
2017-02-21 22:45:31 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
zoom->set_value(zoom->get_value() + zoom->get_step());
|
|
|
|
} else {
|
2017-02-21 22:45:31 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * mb->get_factor() / 8);
|
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
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->get_command()) {
|
2017-02-21 22:45:31 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
zoom->set_value(zoom->get_value() - zoom->get_step());
|
|
|
|
} else {
|
2017-02-21 22:45:31 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb->get_factor() / 8);
|
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
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_RIGHT && mb->is_pressed()) {
|
2017-02-21 22:45:31 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * mb->get_factor() / 8);
|
|
|
|
}
|
2017-02-21 22:45:31 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_LEFT && mb->is_pressed()) {
|
2017-02-21 22:45:31 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb->get_factor() / 8);
|
|
|
|
}
|
2017-02-21 22:45:31 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
Point2 mpos = mb->get_position() - ofs;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (selection.size() == 0) {
|
|
|
|
// Auto-select on right-click if nothing is selected
|
|
|
|
// Note: This code is pretty much duplicated from the left click code,
|
|
|
|
// both codes could be moved into a function to avoid the duplicated code.
|
2017-06-03 08:54:24 +00:00
|
|
|
Point2 mpos = mb->get_position() - ofs;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.y < h) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mpos.y -= h;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int idx = mpos.y / h;
|
|
|
|
idx += v_scroll->get_value();
|
|
|
|
if (idx < 0 || idx >= animation->get_track_count())
|
|
|
|
return;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.x < name_limit) {
|
|
|
|
} else if (mpos.x < settings_limit) {
|
|
|
|
float pos = mpos.x - name_limit;
|
|
|
|
pos /= _get_zoom_scale();
|
|
|
|
pos += h_scroll->get_value();
|
|
|
|
float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int kidx = animation->track_find_key(idx, pos);
|
|
|
|
int kidx_n = kidx + 1;
|
|
|
|
int key = -1;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float kpos = animation->track_get_key_time(idx, kidx);
|
|
|
|
if (ABS(pos - kpos) <= w_time) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
key = kidx;
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
}
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key == -1 && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float kpos = animation->track_get_key_time(idx, kidx_n);
|
|
|
|
if (ABS(pos - kpos) <= w_time) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
key = kidx_n;
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
}
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key == -1) {
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
click.click = ClickOver::CLICK_SELECT_KEYS;
|
2017-06-03 08:54:24 +00:00
|
|
|
click.at = mb->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
click.to = click.at;
|
|
|
|
click.shift = mb->get_shift();
|
|
|
|
selected_track = idx;
|
|
|
|
track_editor->update();
|
|
|
|
//drag select region
|
|
|
|
return;
|
|
|
|
}
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
SelectedKey sk;
|
|
|
|
sk.track = idx;
|
|
|
|
sk.key = key;
|
|
|
|
KeyInfo ki;
|
|
|
|
ki.pos = animation->track_get_key_time(idx, key);
|
|
|
|
click.shift = mb->get_shift();
|
|
|
|
click.selk = sk;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (!mb->get_shift() && !selection.has(sk))
|
|
|
|
_clear_selection();
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
selection.insert(sk, ki);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
click.click = ClickOver::CLICK_MOVE_KEYS;
|
2017-06-03 08:54:24 +00:00
|
|
|
click.at = mb->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
click.to = click.at;
|
|
|
|
update();
|
|
|
|
selected_track = idx;
|
|
|
|
track_editor->update();
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (_edit_if_single_selection() && mb->get_command()) {
|
|
|
|
edit_button->set_pressed(true);
|
|
|
|
key_editor_tab->show();
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
}
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (selection.size()) {
|
|
|
|
// User has right clicked and we have a selection, show a popup menu with options
|
|
|
|
track_menu->clear();
|
|
|
|
track_menu->set_size(Point2(1, 1));
|
|
|
|
track_menu->add_item(TTR("Duplicate Selection"), RIGHT_MENU_DUPLICATE);
|
|
|
|
track_menu->add_item(TTR("Duplicate Transposed"), RIGHT_MENU_DUPLICATE_TRANSPOSE);
|
|
|
|
track_menu->add_item(TTR("Remove Selection"), RIGHT_MENU_REMOVE);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->set_position(te->get_global_position() + mpos);
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
interp_editing = -1;
|
|
|
|
cont_editing = -1;
|
|
|
|
wrap_editing = -1;
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->popup();
|
2016-06-19 01:22:03 +00:00
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
}
|
2016-06-19 01:22:03 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb->get_button_index() == BUTTON_LEFT && !(mb->get_button_mask() & ~BUTTON_MASK_LEFT)) {
|
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-06-03 08:54:24 +00:00
|
|
|
Point2 mpos = mb->get_position() - ofs;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.y < h) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.x < name_limit && mpos.x > (name_limit - hsep - hsize_icon->get_width())) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
click.click = ClickOver::CLICK_RESIZE_NAMES;
|
2017-06-03 08:54:24 +00:00
|
|
|
click.at = mb->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
click.to = click.at;
|
|
|
|
click.at.y = name_limit;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.x >= name_limit && mpos.x < settings_limit) {
|
|
|
|
//seek
|
|
|
|
//int zoomw = settings_limit-name_limit;
|
|
|
|
float scale = _get_zoom_scale();
|
|
|
|
float pos = h_scroll->get_value() + (mpos.x - name_limit) / scale;
|
|
|
|
if (animation->get_step())
|
|
|
|
pos = Math::stepify(pos, animation->get_step());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (pos < 0)
|
|
|
|
pos = 0;
|
|
|
|
if (pos >= animation->get_length())
|
|
|
|
pos = animation->get_length();
|
|
|
|
timeline_pos = pos;
|
|
|
|
click.click = ClickOver::CLICK_DRAG_TIMELINE;
|
2017-06-03 08:54:24 +00:00
|
|
|
click.at = mb->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
click.to = click.at;
|
|
|
|
emit_signal("timeline_changed", pos, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mpos.y -= h;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int idx = mpos.y / h;
|
|
|
|
idx += v_scroll->get_value();
|
|
|
|
if (idx < 0)
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (idx >= animation->get_track_count()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.x >= name_limit && mpos.x < settings_limit) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
click.click = ClickOver::CLICK_SELECT_KEYS;
|
2017-06-03 08:54:24 +00:00
|
|
|
click.at = mb->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
click.to = click.at;
|
|
|
|
//drag select region
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.x < name_limit) {
|
|
|
|
//name column
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
// area
|
|
|
|
if (idx != selected_track) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
selected_track = idx;
|
|
|
|
track_editor->update();
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Rect2 area(ofs.x, ofs.y + ((int(mpos.y) / h) + 1) * h, name_limit, h);
|
|
|
|
track_name->set_text(animation->track_get_path(idx));
|
2017-06-03 22:25:13 +00:00
|
|
|
track_name->set_position(te->get_global_position() + area.position);
|
2017-05-20 15:38:03 +00:00
|
|
|
track_name->set_size(area.size);
|
|
|
|
track_name->show_modal();
|
|
|
|
track_name->grab_focus();
|
|
|
|
track_name->select_all();
|
|
|
|
track_name_editing = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} else if (mpos.x < settings_limit) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float pos = mpos.x - name_limit;
|
|
|
|
pos /= _get_zoom_scale();
|
|
|
|
pos += h_scroll->get_value();
|
|
|
|
float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int kidx = animation->track_find_key(idx, pos);
|
|
|
|
int kidx_n = kidx + 1;
|
|
|
|
int key = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float kpos = animation->track_get_key_time(idx, kidx);
|
|
|
|
if (ABS(pos - kpos) <= w_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
key = kidx;
|
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
|
|
|
if (key == -1 && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float kpos = animation->track_get_key_time(idx, kidx_n);
|
|
|
|
if (ABS(pos - kpos) <= w_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
key = kidx_n;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (key == -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
click.click = ClickOver::CLICK_SELECT_KEYS;
|
2017-06-03 08:54:24 +00:00
|
|
|
click.at = mb->get_position();
|
2017-03-05 15:44:50 +00:00
|
|
|
click.to = click.at;
|
2017-05-20 15:38:03 +00:00
|
|
|
click.shift = mb->get_shift();
|
2017-03-05 15:44:50 +00:00
|
|
|
selected_track = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
track_editor->update();
|
2017-05-20 15:38:03 +00:00
|
|
|
//drag select region
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
SelectedKey sk;
|
|
|
|
sk.track = idx;
|
|
|
|
sk.key = key;
|
|
|
|
KeyInfo ki;
|
|
|
|
ki.pos = animation->track_get_key_time(idx, key);
|
|
|
|
click.shift = mb->get_shift();
|
|
|
|
click.selk = sk;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (!mb->get_shift() && !selection.has(sk))
|
|
|
|
_clear_selection();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
selection.insert(sk, ki);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
click.click = ClickOver::CLICK_MOVE_KEYS;
|
2017-06-03 08:54:24 +00:00
|
|
|
click.at = mb->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
click.to = click.at;
|
|
|
|
update();
|
|
|
|
selected_track = idx;
|
|
|
|
track_editor->update();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (_edit_if_single_selection() && mb->get_command()) {
|
|
|
|
edit_button->set_pressed(true);
|
|
|
|
key_editor_tab->show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//button column
|
|
|
|
int ofsx = size.width - mpos.x;
|
|
|
|
if (ofsx < 0)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
if (ofsx < remove_icon->get_width()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->create_action("Remove Anim Track");
|
|
|
|
undo_redo->add_do_method(animation.ptr(),"remove_track",idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(),"add_track",animation->track_get_type(idx),idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(),"track_set_path",idx,animation->track_get_path(idx));
|
|
|
|
//todo interpolation
|
|
|
|
for(int i=0;i<animation->track_get_key_count(idx);i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Variant v = animation->track_get_key_value(idx,i);
|
|
|
|
float time = animation->track_get_key_time(idx,i);
|
|
|
|
float trans = animation->track_get_key_transition(idx,i);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(),"track_insert_key",idx,time,v);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(),"track_set_key_transition",idx,i,trans);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(),"track_set_interpolation_type",idx,animation->track_get_interpolation_type(idx));
|
|
|
|
if (animation->track_get_type(idx)==Animation::TYPE_VALUE) {
|
|
|
|
undo_redo->add_undo_method(animation.ptr(),"value_track_set_continuous",idx,animation->value_track_is_continuous(idx));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->commit_action();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
ofsx-=hsep+remove_icon->get_width();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < move_down_icon->get_width()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (idx < animation->get_track_count() -1) {
|
|
|
|
undo_redo->create_action("Move Anim Track Down");
|
|
|
|
undo_redo->add_do_method(animation.ptr(),"track_move_up",idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(),"track_move_down",idx+1);
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
ofsx-=hsep+move_down_icon->get_width();
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < move_up_icon->get_width()) {
|
|
|
|
|
|
|
|
if (idx >0) {
|
|
|
|
undo_redo->create_action("Move Anim Track Up");
|
|
|
|
undo_redo->add_do_method(animation.ptr(),"track_move_down",idx);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(),"track_move_up",idx-1);
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-01-09 03:41:16 +00:00
|
|
|
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
ofsx-=hsep*3+move_up_icon->get_width();
|
|
|
|
*/
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < track_ofs[1]) {
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->clear();
|
|
|
|
track_menu->set_size(Point2(1, 1));
|
|
|
|
static const char *interp_name[2] = { "Clamp Loop Interp", "Wrap Loop Interp" };
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
track_menu->add_icon_item(wrap_icon[i], interp_name[i]);
|
2017-01-09 03:41:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
|
|
|
|
int popup_x = size.width - track_ofs[1];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
wrap_editing = idx;
|
|
|
|
interp_editing = -1;
|
|
|
|
cont_editing = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->popup();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < track_ofs[2]) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->clear();
|
|
|
|
track_menu->set_size(Point2(1, 1));
|
|
|
|
static const char *interp_name[3] = { "Nearest", "Linear", "Cubic" };
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
track_menu->add_icon_item(interp_icon[i], interp_name[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
|
|
|
|
int popup_x = size.width - track_ofs[2];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
interp_editing = idx;
|
|
|
|
cont_editing = -1;
|
|
|
|
wrap_editing = -1;
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->popup();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < track_ofs[3]) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->clear();
|
|
|
|
track_menu->set_size(Point2(1, 1));
|
|
|
|
String cont_name[3] = { TTR("Continuous"), TTR("Discrete"), TTR("Trigger") };
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
track_menu->add_icon_item(cont_icon[i], cont_name[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
|
|
|
|
int popup_x = size.width - track_ofs[3];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
interp_editing = -1;
|
|
|
|
wrap_editing = -1;
|
|
|
|
cont_editing = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_menu->popup();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < track_ofs[4]) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Animation::TrackType tt = animation->track_get_type(idx);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float pos = timeline_pos;
|
|
|
|
int existing = animation->track_find_key(idx, pos, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Variant newval;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (tt == Animation::TYPE_TRANSFORM) {
|
|
|
|
Dictionary d;
|
2017-09-10 13:37:49 +00:00
|
|
|
d["location"] = Vector3();
|
|
|
|
d["rotation"] = Quat();
|
2017-05-20 15:38:03 +00:00
|
|
|
d["scale"] = Vector3();
|
|
|
|
newval = d;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} else if (tt == Animation::TYPE_METHOD) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Dictionary d;
|
|
|
|
d["method"] = "";
|
|
|
|
d["args"] = Vector<Variant>();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
newval = d;
|
|
|
|
} else if (tt == Animation::TYPE_VALUE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
NodePath np;
|
|
|
|
PropertyInfo inf = _find_hint_for_track(idx, np);
|
|
|
|
if (inf.type != Variant::NIL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Variant::CallError err;
|
|
|
|
newval = Variant::construct(inf.type, NULL, 0, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (newval.get_type() == Variant::NIL) {
|
|
|
|
//popup a new type
|
|
|
|
cvi_track = idx;
|
|
|
|
cvi_pos = pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
type_menu->set_position(get_global_position() + mpos + ofs);
|
|
|
|
type_menu->popup();
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Add Key"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_insert_key", idx, pos, newval, 1);
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", idx, pos);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (existing != -1) {
|
|
|
|
Variant v = animation->track_get_key_value(idx, existing);
|
|
|
|
float trans = animation->track_get_key_transition(idx, existing);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", idx, pos, v, trans);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->commit_action();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
switch (click.click) {
|
|
|
|
case ClickOver::CLICK_SELECT_KEYS: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float zoom_scale = _get_zoom_scale();
|
|
|
|
float keys_from = h_scroll->get_value();
|
|
|
|
float keys_to = keys_from + (settings_limit - name_limit) / zoom_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float from_time = keys_from + (click.at.x - (name_limit + ofs.x)) / zoom_scale;
|
|
|
|
float to_time = keys_from + (click.to.x - (name_limit + ofs.x)) / zoom_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (to_time < from_time)
|
|
|
|
SWAP(from_time, to_time);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (from_time > keys_to || to_time < keys_from)
|
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (from_time < keys_from)
|
|
|
|
from_time = keys_from;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (to_time >= keys_to)
|
|
|
|
to_time = keys_to;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int from_track = int(click.at.y - ofs.y - h - sep) / h + v_scroll->get_value();
|
|
|
|
int to_track = int(click.to.y - ofs.y - h - sep) / h + v_scroll->get_value();
|
|
|
|
int from_mod = int(click.at.y - ofs.y - sep) % h;
|
|
|
|
int to_mod = int(click.to.y - ofs.y - sep) % h;
|
|
|
|
|
|
|
|
if (to_track < from_track) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
SWAP(from_track, to_track);
|
|
|
|
SWAP(from_mod, to_mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((from_mod > (h / 2)) && ((click.at.y - ofs.y) >= (h + sep))) {
|
|
|
|
from_track++;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (to_mod < h / 2) {
|
|
|
|
to_track--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (from_track > to_track) {
|
|
|
|
if (!click.shift)
|
|
|
|
_clear_selection();
|
|
|
|
_edit_if_single_selection();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tracks_from = v_scroll->get_value();
|
|
|
|
int tracks_to = v_scroll->get_value() + fit - 1;
|
|
|
|
if (tracks_to >= animation->get_track_count())
|
2017-03-05 15:44:50 +00:00
|
|
|
tracks_to = animation->get_track_count() - 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
tracks_from = 0;
|
|
|
|
tracks_to = animation->get_track_count() - 1;
|
|
|
|
if (to_track > tracks_to)
|
|
|
|
to_track = tracks_to;
|
|
|
|
if (from_track < tracks_from)
|
|
|
|
from_track = tracks_from;
|
|
|
|
|
|
|
|
if (from_track > tracks_to || to_track < tracks_from) {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!click.shift)
|
2015-05-25 04:46:45 +00:00
|
|
|
_clear_selection();
|
2017-05-20 15:38:03 +00:00
|
|
|
_edit_if_single_selection();
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (!click.shift)
|
|
|
|
_clear_selection();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int higher_track = 0x7FFFFFFF;
|
|
|
|
for (int i = from_track; i <= to_track; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int kc = animation->track_get_key_count(i);
|
|
|
|
for (int j = 0; j < kc; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float t = animation->track_get_key_time(i, j);
|
|
|
|
if (t < from_time)
|
|
|
|
continue;
|
|
|
|
if (t > to_time)
|
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (i < higher_track)
|
|
|
|
higher_track = i;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
SelectedKey sk;
|
|
|
|
sk.track = i;
|
|
|
|
sk.key = j;
|
|
|
|
KeyInfo ki;
|
|
|
|
ki.pos = t;
|
|
|
|
selection[sk] = ki;
|
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
|
|
|
if (higher_track != 0x7FFFFFFF) {
|
|
|
|
selected_track = higher_track;
|
|
|
|
track_editor->update();
|
|
|
|
}
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
_edit_if_single_selection();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} break;
|
|
|
|
case ClickOver::CLICK_MOVE_KEYS: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (selection.empty())
|
|
|
|
break;
|
|
|
|
if (click.at == click.to) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (!click.shift) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
KeyInfo ki = selection[click.selk];
|
|
|
|
_clear_selection();
|
|
|
|
selection[click.selk] = ki;
|
|
|
|
_edit_if_single_selection();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float from_t = 1e20;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
|
|
|
|
float t = animation->track_get_key_time(E->key().track, E->key().key);
|
|
|
|
if (t < from_t)
|
|
|
|
from_t = t;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float motion = from_t + (click.to.x - click.at.x) / _get_zoom_scale();
|
|
|
|
if (step->get_value())
|
|
|
|
motion = Math::stepify(motion, step->get_value());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Move Keys"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
List<_AnimMoveRestore> to_restore;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
// 1-remove the keys
|
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->key().track, E->key().key);
|
|
|
|
}
|
|
|
|
// 2- remove overlapped keys
|
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
|
|
|
|
float newtime = E->get().pos - from_t + motion;
|
|
|
|
int idx = animation->track_find_key(E->key().track, newtime, true);
|
|
|
|
if (idx == -1)
|
|
|
|
continue;
|
|
|
|
SelectedKey sk;
|
|
|
|
sk.key = idx;
|
|
|
|
sk.track = E->key().track;
|
|
|
|
if (selection.has(sk))
|
|
|
|
continue; //already in selection, don't save
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", E->key().track, newtime);
|
2017-05-20 15:38:03 +00:00
|
|
|
_AnimMoveRestore amr;
|
|
|
|
|
|
|
|
amr.key = animation->track_get_key_value(E->key().track, idx);
|
|
|
|
amr.track = E->key().track;
|
|
|
|
amr.time = newtime;
|
|
|
|
amr.transition = animation->track_get_key_transition(E->key().track, idx);
|
|
|
|
|
|
|
|
to_restore.push_back(amr);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
// 3-move the keys (re insert them)
|
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float newpos = E->get().pos - from_t + motion;
|
|
|
|
/*
|
|
|
|
if (newpos<0)
|
|
|
|
continue; //no add at the beginning
|
|
|
|
*/
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->key().track, newpos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
// 4-(undo) remove inserted keys
|
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float newpos = E->get().pos + -from_t + motion;
|
|
|
|
/*
|
|
|
|
if (newpos<0)
|
|
|
|
continue; //no remove what no inserted
|
|
|
|
*/
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", E->key().track, newpos);
|
2017-05-20 15:38:03 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
// 5-(undo) reinsert keys
|
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->key().track, E->get().pos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
// 6-(undo) reinsert overlapped keys
|
|
|
|
for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
_AnimMoveRestore &amr = E->get();
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
// 6-(undo) reinsert overlapped keys
|
|
|
|
for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
_AnimMoveRestore &amr = E->get();
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
|
|
|
|
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
// 7-reselect
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float oldpos = E->get().pos;
|
|
|
|
float newpos = oldpos - from_t + motion;
|
|
|
|
//if (newpos>=0)
|
|
|
|
undo_redo->add_do_method(this, "_select_at_anim", animation, E->key().track, newpos);
|
|
|
|
undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, oldpos);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
_edit_if_single_selection();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
//button released
|
|
|
|
click.click = ClickOver::CLICK_NONE;
|
|
|
|
track_editor->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseMotion> mm = p_input;
|
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
|
|
|
mouse_over.over = MouseOver::OVER_NONE;
|
|
|
|
mouse_over.track = -1;
|
|
|
|
te->update();
|
|
|
|
track_editor->set_tooltip("");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (!track_editor->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
|
|
|
|
track_editor->call_deferred("grab_focus");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (click.click != ClickOver::CLICK_NONE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
switch (click.click) {
|
|
|
|
case ClickOver::CLICK_RESIZE_NAMES: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float base = click.at.y;
|
|
|
|
float clickp = click.at.x - ofs.x;
|
|
|
|
float dif = base - clickp;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
float target = mm->get_position().x + dif - ofs.x;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float ratio = target / settings_limit;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ratio > 0.9)
|
|
|
|
ratio = 0.9;
|
|
|
|
else if (ratio < 0.2)
|
|
|
|
ratio = 0.2;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
name_column_ratio = ratio;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} break;
|
|
|
|
case ClickOver::CLICK_DRAG_TIMELINE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
Point2 mpos = mm->get_position() - ofs;
|
2017-05-20 15:38:03 +00:00
|
|
|
/*
|
|
|
|
if (mpos.x<name_limit)
|
|
|
|
mpos.x=name_limit;
|
|
|
|
if (mpos.x>settings_limit)
|
|
|
|
mpos.x=settings_limit;
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
//int zoomw = settings_limit-name_limit;
|
|
|
|
float scale = _get_zoom_scale();
|
|
|
|
float pos = h_scroll->get_value() + (mpos.x - name_limit) / scale;
|
|
|
|
if (animation->get_step()) {
|
|
|
|
pos = Math::stepify(pos, animation->get_step());
|
|
|
|
}
|
|
|
|
if (pos < 0)
|
|
|
|
pos = 0;
|
|
|
|
if (pos >= animation->get_length())
|
|
|
|
pos = animation->get_length();
|
|
|
|
|
|
|
|
if (pos < h_scroll->get_value()) {
|
|
|
|
h_scroll->set_value(pos);
|
|
|
|
} else if (pos > h_scroll->get_value() + (settings_limit - name_limit) / scale) {
|
|
|
|
h_scroll->set_value(pos - (settings_limit - name_limit) / scale);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
timeline_pos = pos;
|
|
|
|
emit_signal("timeline_changed", pos, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} break;
|
|
|
|
case ClickOver::CLICK_SELECT_KEYS: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
click.to = mm->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
if (click.to.y < h && click.at.y > h && mm->get_relative().y < 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float prev = v_scroll->get_value();
|
|
|
|
v_scroll->set_value(v_scroll->get_value() - 1);
|
|
|
|
if (prev != v_scroll->get_value())
|
|
|
|
click.at.y += h;
|
|
|
|
}
|
|
|
|
if (click.to.y > size.height && click.at.y < size.height && mm->get_relative().y > 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float prev = v_scroll->get_value();
|
|
|
|
v_scroll->set_value(v_scroll->get_value() + 1);
|
|
|
|
if (prev != v_scroll->get_value())
|
|
|
|
click.at.y -= h;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} break;
|
|
|
|
case ClickOver::CLICK_MOVE_KEYS: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
click.to = mm->get_position();
|
2017-05-20 15:38:03 +00:00
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
2017-05-27 09:05:15 +00:00
|
|
|
} else if (mm->get_button_mask() & BUTTON_MASK_MIDDLE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int rel = mm->get_relative().x;
|
|
|
|
float relf = rel / _get_zoom_scale();
|
|
|
|
h_scroll->set_value(h_scroll->get_value() - relf);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-27 09:05:15 +00:00
|
|
|
if (mm->get_button_mask() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-03 08:54:24 +00:00
|
|
|
Point2 mpos = mm->get_position() - ofs;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.y < h) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mpos.y -= h;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int idx = mpos.y / h;
|
|
|
|
idx += v_scroll->get_value();
|
|
|
|
if (idx < 0 || idx >= animation->get_track_count())
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mouse_over.track = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mpos.x < name_limit) {
|
|
|
|
//name column
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mouse_over.over = MouseOver::OVER_NAME;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} else if (mpos.x < settings_limit) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float pos = mpos.x - name_limit;
|
|
|
|
pos /= _get_zoom_scale();
|
|
|
|
pos += h_scroll->get_value();
|
|
|
|
float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
int kidx = animation->track_find_key(idx, pos);
|
|
|
|
int kidx_n = kidx + 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
bool found = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float kpos = animation->track_get_key_time(idx, kidx);
|
|
|
|
if (ABS(pos - kpos) <= w_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mouse_over.over = MouseOver::OVER_KEY;
|
|
|
|
mouse_over.track = idx;
|
|
|
|
mouse_over.over_key = kidx;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (!found && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
float kpos = animation->track_get_key_time(idx, kidx_n);
|
|
|
|
if (ABS(pos - kpos) <= w_time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mouse_over.over = MouseOver::OVER_KEY;
|
|
|
|
mouse_over.track = idx;
|
|
|
|
mouse_over.over_key = kidx_n;
|
|
|
|
found = true;
|
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
|
|
|
if (found) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
String text;
|
|
|
|
text = "time: " + rtos(animation->track_get_key_time(idx, mouse_over.over_key)) + "\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
switch (animation->track_get_type(idx)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
case Animation::TYPE_TRANSFORM: {
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Dictionary d = animation->track_get_key_value(idx, mouse_over.over_key);
|
2017-09-10 13:37:49 +00:00
|
|
|
if (d.has("location"))
|
|
|
|
text += "location: " + String(d["location"]) + "\n";
|
|
|
|
if (d.has("rotation"))
|
|
|
|
text += "rot: " + String(d["rotation"]) + "\n";
|
2017-05-20 15:38:03 +00:00
|
|
|
if (d.has("scale"))
|
|
|
|
text += "scale: " + String(d["scale"]) + "\n";
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_VALUE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Variant v = animation->track_get_key_value(idx, mouse_over.over_key);
|
|
|
|
//text+="value: "+String(v)+"\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
bool prop_exists = false;
|
|
|
|
Variant::Type valid_type = Variant::NIL;
|
|
|
|
Object *obj = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
RES res;
|
|
|
|
Node *node = root->get_node_and_resource(animation->track_get_path(idx), res);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (res.is_valid()) {
|
|
|
|
obj = res.ptr();
|
|
|
|
} else if (node) {
|
|
|
|
obj = node;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (obj) {
|
|
|
|
valid_type = obj->get_static_property_type(animation->track_get_path(idx).get_property(), &prop_exists);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
text += "type: " + Variant::get_type_name(v.get_type()) + "\n";
|
|
|
|
if (prop_exists && !Variant::can_convert(v.get_type(), valid_type)) {
|
|
|
|
text += "value: " + String(v) + " (Invalid, expected type: " + Variant::get_type_name(valid_type) + ")\n";
|
|
|
|
} else {
|
|
|
|
text += "value: " + String(v) + "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_METHOD: {
|
|
|
|
|
|
|
|
Dictionary d = animation->track_get_key_value(idx, mouse_over.over_key);
|
|
|
|
if (d.has("method"))
|
|
|
|
text += String(d["method"]);
|
|
|
|
text += "(";
|
|
|
|
Vector<Variant> args;
|
|
|
|
if (d.has("args"))
|
|
|
|
args = d["args"];
|
|
|
|
for (int i = 0; i < args.size(); i++) {
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
text += ", ";
|
|
|
|
text += String(args[i]);
|
|
|
|
}
|
|
|
|
text += ")\n";
|
|
|
|
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-05-20 15:38:03 +00:00
|
|
|
text += "easing: " + rtos(animation->track_get_key_transition(idx, mouse_over.over_key));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
track_editor->set_tooltip(text);
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
} else {
|
|
|
|
//button column
|
|
|
|
int ofsx = size.width - mpos.x;
|
|
|
|
if (ofsx < 0)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
if (ofsx < remove_icon->get_width()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mouse_over.over=MouseOver::OVER_REMOVE;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
ofsx-=hsep+remove_icon->get_width();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < move_down_icon->get_width()) {
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mouse_over.over=MouseOver::OVER_DOWN;
|
|
|
|
return;
|
|
|
|
}
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
ofsx-=hsep+move_down_icon->get_width();
|
2017-01-09 03:41:16 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < move_up_icon->get_width()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mouse_over.over=MouseOver::OVER_UP;
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
ofsx-=hsep*3+move_up_icon->get_width();
|
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
|
|
|
if (ofsx < down_icon->get_width() + wrap_icon[0]->get_width() + hsep * 3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
mouse_over.over = MouseOver::OVER_WRAP;
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
ofsx -= hsep * 3 + wrap_icon[0]->get_width() + down_icon->get_width();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (ofsx < down_icon->get_width() + interp_icon[0]->get_width() + hsep * 3) {
|
|
|
|
|
|
|
|
mouse_over.over = MouseOver::OVER_INTERP;
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
ofsx -= hsep * 2 + interp_icon[0]->get_width() + down_icon->get_width();
|
|
|
|
|
|
|
|
if (ofsx < down_icon->get_width() + cont_icon[0]->get_width() + hsep * 3) {
|
|
|
|
|
|
|
|
mouse_over.over = MouseOver::OVER_VALUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofsx -= hsep * 3 + cont_icon[0]->get_width() + down_icon->get_width();
|
|
|
|
|
|
|
|
if (ofsx < add_key_icon->get_width()) {
|
|
|
|
|
|
|
|
mouse_over.over = MouseOver::OVER_ADD_KEY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2016-01-17 23:10:24 +00:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
|
|
|
|
EditorNode::get_singleton()->update_keying();
|
2016-02-09 19:09:29 +00:00
|
|
|
emit_signal("keying_changed");
|
2016-01-17 23:10:24 +00:00
|
|
|
} break;
|
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
|
|
|
key_editor->edit(key_edit);
|
|
|
|
|
2017-05-02 20:13:12 +00:00
|
|
|
zoomicon->set_custom_minimum_size(Size2(24 * EDSCALE, 0));
|
|
|
|
zoomicon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
menu_track->set_icon(get_icon("Tools", "EditorIcons"));
|
|
|
|
menu_track->get_popup()->add_item(TTR("Scale Selection"), TRACK_MENU_SCALE);
|
|
|
|
menu_track->get_popup()->add_item(TTR("Scale From Cursor"), TRACK_MENU_SCALE_PIVOT);
|
|
|
|
menu_track->get_popup()->add_separator();
|
|
|
|
menu_track->get_popup()->add_item(TTR("Duplicate Selection"), TRACK_MENU_DUPLICATE);
|
|
|
|
menu_track->get_popup()->add_item(TTR("Duplicate Transposed"), TRACK_MENU_DUPLICATE_TRANSPOSE);
|
|
|
|
menu_track->get_popup()->add_separator();
|
|
|
|
menu_track->get_popup()->add_item(TTR("Goto Next Step"), TRACK_MENU_NEXT_STEP, KEY_MASK_CMD | KEY_RIGHT);
|
|
|
|
menu_track->get_popup()->add_item(TTR("Goto Prev Step"), TRACK_MENU_PREV_STEP, KEY_MASK_CMD | KEY_LEFT);
|
|
|
|
menu_track->get_popup()->add_separator();
|
|
|
|
PopupMenu *tpp = memnew(PopupMenu);
|
|
|
|
tpp->add_item(TTR("Linear"), TRACK_MENU_SET_ALL_TRANS_LINEAR);
|
|
|
|
tpp->add_item(TTR("Constant"), TRACK_MENU_SET_ALL_TRANS_CONSTANT);
|
|
|
|
tpp->add_item(TTR("In"), TRACK_MENU_SET_ALL_TRANS_IN);
|
|
|
|
tpp->add_item(TTR("Out"), TRACK_MENU_SET_ALL_TRANS_OUT);
|
|
|
|
tpp->add_item(TTR("In-Out"), TRACK_MENU_SET_ALL_TRANS_INOUT);
|
|
|
|
tpp->add_item(TTR("Out-In"), TRACK_MENU_SET_ALL_TRANS_OUTIN);
|
|
|
|
tpp->set_name(TTR("Transitions"));
|
|
|
|
tpp->connect("id_pressed", this, "_menu_track");
|
|
|
|
optimize_dialog->connect("confirmed", this, "_animation_optimize");
|
|
|
|
|
|
|
|
menu_track->get_popup()->add_child(tpp);
|
2017-09-09 01:47:58 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
menu_track->get_popup()->add_item(TTR("Optimize Animation"), TRACK_MENU_OPTIMIZE);
|
|
|
|
menu_track->get_popup()->add_item(TTR("Clean-Up Animation"), TRACK_MENU_CLEAN_UP);
|
|
|
|
|
|
|
|
curve_linear->connect("pressed", this, "_menu_track", varray(CURVE_SET_LINEAR));
|
|
|
|
curve_in->connect("pressed", this, "_menu_track", varray(CURVE_SET_IN));
|
|
|
|
curve_out->connect("pressed", this, "_menu_track", varray(CURVE_SET_OUT));
|
|
|
|
curve_inout->connect("pressed", this, "_menu_track", varray(CURVE_SET_INOUT));
|
|
|
|
curve_outin->connect("pressed", this, "_menu_track", varray(CURVE_SET_OUTIN));
|
|
|
|
curve_constant->connect("pressed", this, "_menu_track", varray(CURVE_SET_CONSTANT));
|
|
|
|
|
2017-09-09 01:47:58 +00:00
|
|
|
edit_button->connect("pressed", this, "_toggle_edit_curves");
|
|
|
|
|
|
|
|
curve_edit->connect("transition_changed", this, "_curve_transition_changed");
|
|
|
|
call_select->connect("selected", this, "_add_call_track");
|
|
|
|
|
|
|
|
_update_menu();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
|
|
zoomicon->set_texture(get_icon("Zoom", "EditorIcons"));
|
|
|
|
|
|
|
|
menu_add_track->set_icon(get_icon("Add", "EditorIcons"));
|
|
|
|
|
|
|
|
menu_track->set_icon(get_icon("Tools", "EditorIcons"));
|
|
|
|
|
|
|
|
menu_add_track->get_popup()->set_item_icon(ADD_TRACK_MENU_ADD_VALUE_TRACK, get_icon("KeyValue", "EditorIcons"));
|
|
|
|
menu_add_track->get_popup()->set_item_icon(ADD_TRACK_MENU_ADD_TRANSFORM_TRACK, get_icon("KeyXform", "EditorIcons"));
|
|
|
|
menu_add_track->get_popup()->set_item_icon(ADD_TRACK_MENU_ADD_CALL_TRACK, get_icon("KeyCall", "EditorIcons"));
|
|
|
|
|
|
|
|
curve_linear->set_icon(get_icon("CurveLinear", "EditorIcons"));
|
|
|
|
curve_in->set_icon(get_icon("CurveIn", "EditorIcons"));
|
|
|
|
curve_out->set_icon(get_icon("CurveOut", "EditorIcons"));
|
|
|
|
curve_inout->set_icon(get_icon("CurveInOut", "EditorIcons"));
|
|
|
|
curve_outin->set_icon(get_icon("CurveOutIn", "EditorIcons"));
|
|
|
|
curve_constant->set_icon(get_icon("CurveConstant", "EditorIcons"));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
move_up_button->set_icon(get_icon("MoveUp", "EditorIcons"));
|
|
|
|
move_down_button->set_icon(get_icon("MoveDown", "EditorIcons"));
|
|
|
|
remove_button->set_icon(get_icon("Remove", "EditorIcons"));
|
|
|
|
edit_button->set_icon(get_icon("EditKey", "EditorIcons"));
|
|
|
|
|
|
|
|
loop->set_icon(get_icon("Loop", "EditorIcons"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
{
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
right_data_size_cache = 0;
|
|
|
|
int hsep = get_constant("hseparation", "Tree");
|
|
|
|
Ref<Texture> remove_icon = get_icon("Remove", "EditorIcons");
|
|
|
|
Ref<Texture> move_up_icon = get_icon("MoveUp", "EditorIcons");
|
|
|
|
Ref<Texture> move_down_icon = get_icon("MoveDown", "EditorIcons");
|
|
|
|
Ref<Texture> down_icon = get_icon("select_arrow", "Tree");
|
|
|
|
Ref<Texture> add_key_icon = get_icon("TrackAddKey", "EditorIcons");
|
|
|
|
Ref<Texture> interp_icon[3] = {
|
|
|
|
get_icon("InterpRaw", "EditorIcons"),
|
|
|
|
get_icon("InterpLinear", "EditorIcons"),
|
|
|
|
get_icon("InterpCubic", "EditorIcons")
|
|
|
|
};
|
|
|
|
Ref<Texture> cont_icon[3] = {
|
|
|
|
get_icon("TrackContinuous", "EditorIcons"),
|
|
|
|
get_icon("TrackDiscrete", "EditorIcons"),
|
|
|
|
get_icon("TrackTrigger", "EditorIcons")
|
|
|
|
};
|
|
|
|
|
|
|
|
Ref<Texture> wrap_icon[2] = {
|
|
|
|
get_icon("InterpWrapClamp", "EditorIcons"),
|
|
|
|
get_icon("InterpWrapLoop", "EditorIcons"),
|
|
|
|
};
|
|
|
|
right_data_size_cache = down_icon->get_width() * 3 + add_key_icon->get_width() + interp_icon[0]->get_width() + cont_icon[0]->get_width() + wrap_icon[0]->get_width() + hsep * 8;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_scroll_changed(double) {
|
|
|
|
|
|
|
|
if (te_drawing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
track_editor->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_update_paths() {
|
|
|
|
|
|
|
|
if (animation.is_valid()) {
|
|
|
|
//timeline->set_max(animation->get_length());
|
|
|
|
//timeline->set_step(0.01);
|
|
|
|
track_editor->update();
|
2017-01-04 04:16:14 +00:00
|
|
|
length->set_value(animation->get_length());
|
|
|
|
step->set_value(animation->get_step());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_root_removed() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
root = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_update_menu() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (animation.is_valid()) {
|
|
|
|
|
2017-01-04 04:16:14 +00:00
|
|
|
length->set_value(animation->get_length());
|
2014-02-10 01:10:30 +00:00
|
|
|
loop->set_pressed(animation->has_loop());
|
2017-01-04 04:16:14 +00:00
|
|
|
step->set_value(animation->get_step());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
track_editor->update();
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-05-25 04:46:45 +00:00
|
|
|
void AnimationKeyEditor::_clear_selection() {
|
|
|
|
|
|
|
|
selection.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
key_edit->animation = Ref<Animation>();
|
|
|
|
key_edit->track = 0;
|
|
|
|
key_edit->key_ofs = 0;
|
|
|
|
key_edit->hint = PropertyInfo();
|
|
|
|
key_edit->base = NodePath();
|
2015-05-25 04:46:45 +00:00
|
|
|
key_edit->notify_change();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::set_animation(const Ref<Animation> &p_anim) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (animation.is_valid())
|
2017-03-05 15:44:50 +00:00
|
|
|
animation->disconnect("changed", this, "_update_paths");
|
|
|
|
animation = p_anim;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (animation.is_valid())
|
2017-03-05 15:44:50 +00:00
|
|
|
animation->connect("changed", this, "_update_paths");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
timeline_pos = 0;
|
2015-05-25 04:46:45 +00:00
|
|
|
_clear_selection();
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_paths();
|
|
|
|
|
|
|
|
_update_menu();
|
2017-03-05 15:44:50 +00:00
|
|
|
selected_track = -1;
|
2015-05-25 04:46:45 +00:00
|
|
|
_edit_if_single_selection();
|
2016-01-17 23:10:24 +00:00
|
|
|
|
|
|
|
EditorNode::get_singleton()->update_keying();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::set_root(Node *p_root) {
|
|
|
|
|
|
|
|
if (root)
|
2017-03-05 15:44:50 +00:00
|
|
|
root->disconnect("tree_exited", this, "_root_removed");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
root = p_root;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (root)
|
2017-03-05 15:44:50 +00:00
|
|
|
root->connect("tree_exited", this, "_root_removed", make_binds(), CONNECT_ONESHOT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node *AnimationKeyEditor::get_root() const {
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
2016-01-27 14:10:51 +00:00
|
|
|
void AnimationKeyEditor::update_keying() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool keying_enabled = is_visible_in_tree() && animation.is_valid();
|
2016-01-27 14:10:51 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (keying_enabled == keying)
|
2016-01-27 14:10:51 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
keying = keying_enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_menu();
|
2016-01-09 11:35:57 +00:00
|
|
|
emit_signal("keying_changed");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AnimationKeyEditor::has_keying() const {
|
|
|
|
|
2016-01-27 14:10:51 +00:00
|
|
|
return keying;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::_query_insert(const InsertData &p_id) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (insert_frame != Engine::get_singleton()->get_frames_drawn()) {
|
2014-12-07 05:04:20 +00:00
|
|
|
//clear insert list for the frame if frame changed
|
2017-01-13 13:45:50 +00:00
|
|
|
if (insert_confirm->is_visible_in_tree())
|
2014-02-10 01:10:30 +00:00
|
|
|
return; //do nothing
|
|
|
|
insert_data.clear();
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_query = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_frame = Engine::get_singleton()->get_frames_drawn();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<InsertData>::Element *E = insert_data.front(); E; E = E->next()) {
|
2014-12-07 05:04:20 +00:00
|
|
|
//prevent insertion of multiple tracks
|
2017-03-05 15:44:50 +00:00
|
|
|
if (E->get().path == p_id.path)
|
2014-12-07 05:04:20 +00:00
|
|
|
return; //already inserted a track for this on this frame
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
insert_data.push_back(p_id);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_id.track_idx == -1) {
|
|
|
|
if (bool(EDITOR_DEF("editors/animation/confirm_insert_track", true))) {
|
2016-03-08 23:00:52 +00:00
|
|
|
//potential new key, does not exist
|
2017-03-05 15:44:50 +00:00
|
|
|
if (insert_data.size() == 1)
|
|
|
|
insert_confirm->set_text(vformat(TTR("Create NEW track for %s and insert key?"), p_id.query));
|
2014-12-08 09:35:06 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_confirm->set_text(vformat(TTR("Create %d NEW tracks and insert keys?"), insert_data.size()));
|
2014-12-08 09:35:06 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
insert_confirm->get_ok()->set_text(TTR("Create"));
|
2015-04-29 01:46:05 +00:00
|
|
|
insert_confirm->popup_centered_minsize();
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_query = true;
|
2014-12-08 09:35:06 +00:00
|
|
|
} else {
|
|
|
|
call_deferred("_insert_delay");
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_queue = true;
|
2014-12-08 09:35:06 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!insert_query && !insert_queue) {
|
|
|
|
call_deferred("_insert_delay");
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_queue = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::insert_transform_key(Spatial *p_node, const String &p_sub, const Transform &p_xform) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!keying)
|
|
|
|
return;
|
|
|
|
if (!animation.is_valid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!root);
|
|
|
|
//let's build a node path
|
|
|
|
String path = root->get_path_to(p_node);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_sub != "")
|
|
|
|
path += ":" + p_sub;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
NodePath np = path;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int track_idx = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < animation->get_track_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (animation->track_get_type(i) != Animation::TYPE_TRANSFORM)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (animation->track_get_path(i) != np)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
track_idx = i;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
InsertData id;
|
|
|
|
Dictionary val;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
id.path = np;
|
|
|
|
id.track_idx = track_idx;
|
|
|
|
id.value = p_xform;
|
|
|
|
id.type = Animation::TYPE_TRANSFORM;
|
|
|
|
id.query = "node '" + p_node->get_name() + "'";
|
|
|
|
id.advance = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//dialog insert
|
|
|
|
|
|
|
|
_query_insert(id);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::insert_node_value_key(Node *p_node, const String &p_property, const Variant &p_value, bool p_only_if_exists) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!root);
|
|
|
|
//let's build a node path
|
|
|
|
|
|
|
|
Node *node = p_node;
|
|
|
|
|
|
|
|
String path = root->get_path_to(node);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 1; i < history->get_path_size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String prop = history->get_path_property(i);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(prop == "");
|
|
|
|
path += ":" + prop;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
path += ":" + p_property;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodePath np = path;
|
|
|
|
|
|
|
|
//locate track
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int track_idx = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < animation->get_track_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (animation->track_get_type(i) != Animation::TYPE_VALUE)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (animation->track_get_path(i) != np)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
track_idx = i;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_only_if_exists && track_idx == -1)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
InsertData id;
|
2017-03-05 15:44:50 +00:00
|
|
|
id.path = np;
|
|
|
|
id.track_idx = track_idx;
|
|
|
|
id.value = p_value;
|
|
|
|
id.type = Animation::TYPE_VALUE;
|
|
|
|
id.query = "property '" + p_property + "'";
|
|
|
|
id.advance = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
//dialog insert
|
|
|
|
_query_insert(id);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::insert_value_key(const String &p_property, const Variant &p_value, bool p_advance) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!root);
|
|
|
|
//let's build a node path
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(history->get_path_size() == 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
Object *obj = ObjectDB::get_instance(history->get_path_object(0));
|
2017-08-24 20:58:51 +00:00
|
|
|
ERR_FAIL_COND(!Object::cast_to<Node>(obj));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-24 20:58:51 +00:00
|
|
|
Node *node = Object::cast_to<Node>(obj);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String path = root->get_path_to(node);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 1; i < history->get_path_size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String prop = history->get_path_property(i);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(prop == "");
|
|
|
|
path += ":" + prop;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
path += ":" + p_property;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
NodePath np = path;
|
|
|
|
|
|
|
|
//locate track
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int track_idx = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < animation->get_track_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (animation->track_get_type(i) != Animation::TYPE_VALUE)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (animation->track_get_path(i) != np)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
track_idx = i;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
InsertData id;
|
2017-03-05 15:44:50 +00:00
|
|
|
id.path = np;
|
|
|
|
id.track_idx = track_idx;
|
|
|
|
id.value = p_value;
|
|
|
|
id.type = Animation::TYPE_VALUE;
|
|
|
|
id.query = "property '" + p_property + "'";
|
|
|
|
id.advance = p_advance;
|
2014-02-10 01:10:30 +00:00
|
|
|
//dialog insert
|
|
|
|
_query_insert(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_confirm_insert_list() {
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Create & Insert"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int last_track = animation->get_track_count();
|
2017-03-05 15:44:50 +00:00
|
|
|
while (insert_data.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_track = _confirm_insert(insert_data.front()->get(), last_track);
|
2014-02-10 01:10:30 +00:00
|
|
|
insert_data.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int AnimationKeyEditor::_confirm_insert(InsertData p_id, int p_last_track) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_last_track == -1)
|
|
|
|
p_last_track = animation->get_track_count();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool created = false;
|
|
|
|
if (p_id.track_idx < 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
created = true;
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Insert Track & Key"));
|
2017-03-05 15:44:50 +00:00
|
|
|
Animation::UpdateMode update_mode = Animation::UPDATE_DISCRETE;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_id.type == Animation::TYPE_VALUE) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//wants a new tack
|
|
|
|
|
|
|
|
{
|
|
|
|
//shitty hack
|
2016-01-31 23:06:37 +00:00
|
|
|
NodePath np;
|
2014-02-10 01:10:30 +00:00
|
|
|
animation->add_track(p_id.type);
|
2017-03-05 15:44:50 +00:00
|
|
|
animation->track_set_path(animation->get_track_count() - 1, p_id.path);
|
|
|
|
PropertyInfo h = _find_hint_for_track(animation->get_track_count() - 1, np);
|
|
|
|
animation->remove_track(animation->get_track_count() - 1); //hack
|
|
|
|
|
|
|
|
if (h.type == Variant::REAL ||
|
|
|
|
h.type == Variant::VECTOR2 ||
|
|
|
|
h.type == Variant::RECT2 ||
|
|
|
|
h.type == Variant::VECTOR3 ||
|
2017-11-17 02:09:00 +00:00
|
|
|
h.type == Variant::AABB ||
|
2017-03-05 15:44:50 +00:00
|
|
|
h.type == Variant::QUAT ||
|
|
|
|
h.type == Variant::COLOR ||
|
|
|
|
h.type == Variant::TRANSFORM) {
|
|
|
|
|
|
|
|
update_mode = Animation::UPDATE_CONTINUOUS;
|
2016-06-19 04:43:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (h.usage & PROPERTY_USAGE_ANIMATE_AS_TRIGGER) {
|
|
|
|
update_mode = Animation::UPDATE_TRIGGER;
|
2016-06-19 04:43:02 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_id.track_idx = p_last_track;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "add_track", p_id.type);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_path", p_id.track_idx, p_id.path);
|
|
|
|
if (p_id.type == Animation::TYPE_VALUE)
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "value_track_set_update_mode", p_id.track_idx, update_mode);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Insert Key"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float time = timeline_pos;
|
|
|
|
Variant value;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_id.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case Animation::TYPE_VALUE: {
|
|
|
|
|
|
|
|
value = p_id.value;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Animation::TYPE_TRANSFORM: {
|
|
|
|
|
|
|
|
Transform tr = p_id.value;
|
|
|
|
Dictionary d;
|
2017-09-10 13:37:49 +00:00
|
|
|
d["location"] = tr.origin;
|
2017-03-05 15:44:50 +00:00
|
|
|
d["scale"] = tr.basis.get_scale();
|
2017-09-10 13:37:49 +00:00
|
|
|
d["rotation"] = Quat(tr.basis); //.orthonormalized();
|
2017-03-05 15:44:50 +00:00
|
|
|
value = d;
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-03-05 15:44:50 +00:00
|
|
|
default: {}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_insert_key", p_id.track_idx, time, value);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (created) {
|
|
|
|
|
|
|
|
//just remove the track
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "remove_track", p_last_track);
|
2014-02-10 01:10:30 +00:00
|
|
|
p_last_track++;
|
|
|
|
} else {
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", p_id.track_idx, time);
|
2017-03-05 15:44:50 +00:00
|
|
|
int existing = animation->track_find_key(p_id.track_idx, time, true);
|
|
|
|
if (existing != -1) {
|
|
|
|
Variant v = animation->track_get_key_value(p_id.track_idx, existing);
|
|
|
|
float trans = animation->track_get_key_transition(p_id.track_idx, existing);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", p_id.track_idx, time, v, trans);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(this, "update");
|
|
|
|
undo_redo->add_undo_method(this, "update");
|
|
|
|
undo_redo->add_do_method(track_editor, "update");
|
|
|
|
undo_redo->add_undo_method(track_editor, "update");
|
|
|
|
undo_redo->add_do_method(track_pos, "update");
|
|
|
|
undo_redo->add_undo_method(track_pos, "update");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
return p_last_track;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Animation> AnimationKeyEditor::get_current_animation() const {
|
|
|
|
|
|
|
|
return animation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_animation_len_changed(float p_len) {
|
|
|
|
|
|
|
|
if (updating)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!animation.is_null()) {
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Change Anim Len"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "set_length", p_len);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "set_length", animation->get_length());
|
|
|
|
undo_redo->add_do_method(this, "_animation_len_update");
|
|
|
|
undo_redo->add_undo_method(this, "_animation_len_update");
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_animation_len_update() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!animation.is_null())
|
|
|
|
emit_signal(alc, animation->get_length());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_animation_changed() {
|
|
|
|
if (updating)
|
|
|
|
return;
|
|
|
|
_update_menu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_animation_loop_changed() {
|
|
|
|
|
|
|
|
if (updating)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!animation.is_null()) {
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Change Anim Loop"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "set_loop", loop->is_pressed());
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "set_loop", !loop->is_pressed());
|
2014-02-10 01:10:30 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_create_value_item(int p_type) {
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Create Typed Value Key"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Variant::CallError ce;
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant v = Variant::construct(Variant::Type(p_type), NULL, 0, ce);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_insert_key", cvi_track, cvi_pos, v);
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", cvi_track, cvi_pos);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int existing = animation->track_find_key(cvi_track, cvi_pos, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (existing != -1) {
|
|
|
|
Variant v = animation->track_get_key_value(cvi_track, existing);
|
|
|
|
float trans = animation->track_get_key_transition(cvi_track, existing);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", cvi_track, cvi_pos, v, trans);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::set_anim_pos(float p_pos) {
|
|
|
|
|
|
|
|
if (animation.is_null())
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
timeline_pos = p_pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
update();
|
|
|
|
track_pos->update();
|
|
|
|
track_editor->update();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::_pane_drag(const Point2 &p_delta) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-01-03 20:24:16 +00:00
|
|
|
Size2 ecs = ec->get_custom_minimum_size();
|
2017-03-05 15:44:50 +00:00
|
|
|
ecs.y -= p_delta.y;
|
|
|
|
if (ecs.y < 100)
|
|
|
|
ecs.y = 100;
|
2017-01-14 17:03:38 +00:00
|
|
|
ec->set_custom_minimum_size(ecs);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_insert_delay() {
|
|
|
|
|
|
|
|
if (insert_query) {
|
|
|
|
//discard since it's entered into query mode
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_queue = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-18 22:08:12 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Insert"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int last_track = animation->get_track_count();
|
2017-03-05 15:44:50 +00:00
|
|
|
bool advance = false;
|
|
|
|
while (insert_data.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
if (insert_data.front()->get().advance)
|
2017-03-05 15:44:50 +00:00
|
|
|
advance = true;
|
|
|
|
last_track = _confirm_insert(insert_data.front()->get(), last_track);
|
2014-02-10 01:10:30 +00:00
|
|
|
insert_data.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
2015-05-25 04:46:45 +00:00
|
|
|
|
|
|
|
if (advance) {
|
|
|
|
float step = animation->get_step();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (step == 0)
|
|
|
|
step = 1;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float pos = timeline_pos;
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pos = Math::stepify(pos + step, step);
|
|
|
|
if (pos > animation->get_length())
|
|
|
|
pos = animation->get_length();
|
|
|
|
timeline_pos = pos;
|
2015-05-25 04:46:45 +00:00
|
|
|
track_pos->update();
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("timeline_changed", pos, true);
|
2015-05-25 04:46:45 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_queue = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_step_changed(float p_len) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = true;
|
2016-01-17 23:03:57 +00:00
|
|
|
if (!animation.is_null()) {
|
2015-06-11 12:39:50 +00:00
|
|
|
animation->set_step(p_len);
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("animation_step_changed", animation->get_step());
|
2016-01-17 23:03:57 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
updating = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_scale() {
|
|
|
|
|
|
|
|
if (selection.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
float from_t = 1e20;
|
|
|
|
float to_t = -1e20;
|
|
|
|
float len = -1e20;
|
2017-03-05 15:44:50 +00:00
|
|
|
float pivot = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
|
|
|
|
float t = animation->track_get_key_time(E->key().track, E->key().key);
|
|
|
|
if (t < from_t)
|
|
|
|
from_t = t;
|
|
|
|
if (t > to_t)
|
|
|
|
to_t = t;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
len = to_t - from_t;
|
|
|
|
if (last_menu_track_opt == TRACK_MENU_SCALE_PIVOT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
pivot = timeline_pos;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
pivot = from_t;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 04:16:14 +00:00
|
|
|
float s = scale->get_value();
|
2017-03-05 15:44:50 +00:00
|
|
|
if (s == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_PRINT("Can't scale to 0");
|
|
|
|
}
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Scale Keys"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<_AnimMoveRestore> to_restore;
|
|
|
|
|
|
|
|
// 1-remove the keys
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->key().track, E->key().key);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
// 2- remove overlapped keys
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float newtime = (E->get().pos - from_t) * s + from_t;
|
|
|
|
int idx = animation->track_find_key(E->key().track, newtime, true);
|
|
|
|
if (idx == -1)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
SelectedKey sk;
|
2017-03-05 15:44:50 +00:00
|
|
|
sk.key = idx;
|
|
|
|
sk.track = E->key().track;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (selection.has(sk))
|
|
|
|
continue; //already in selection, don't save
|
|
|
|
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", E->key().track, newtime);
|
2014-02-10 01:10:30 +00:00
|
|
|
_AnimMoveRestore amr;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
amr.key = animation->track_get_key_value(E->key().track, idx);
|
|
|
|
amr.track = E->key().track;
|
|
|
|
amr.time = newtime;
|
|
|
|
amr.transition = animation->track_get_key_transition(E->key().track, idx);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
to_restore.push_back(amr);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#define _NEW_POS(m_ofs) (((s > 0) ? m_ofs : from_t + (len - (m_ofs - from_t))) - pivot) * ABS(s) + from_t
|
2014-02-10 01:10:30 +00:00
|
|
|
// 3-move the keys (re insert them)
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float newpos = _NEW_POS(E->get().pos);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->key().track, newpos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 4-(undo) remove inserted keys
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float newpos = _NEW_POS(E->get().pos);
|
2017-09-10 13:37:49 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_position", E->key().track, newpos);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 5-(undo) reinsert keys
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->key().track, E->get().pos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 6-(undo) reinsert overlapped keys
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_AnimMoveRestore &amr = E->get();
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 6-(undo) reinsert overlapped keys
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_AnimMoveRestore &amr = E->get();
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
|
|
|
|
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// 7-reselect
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float oldpos = E->get().pos;
|
|
|
|
float newpos = _NEW_POS(oldpos);
|
|
|
|
if (newpos >= 0)
|
|
|
|
undo_redo->add_do_method(this, "_select_at_anim", animation, E->key().track, newpos);
|
|
|
|
undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, oldpos);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#undef _NEW_POS
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void AnimationKeyEditor::_add_call_track(const NodePath &p_base) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *base = EditorNode::get_singleton()->get_edited_scene();
|
2015-08-30 13:10:51 +00:00
|
|
|
if (!base)
|
|
|
|
return;
|
2017-03-05 15:44:50 +00:00
|
|
|
Node *from = base->get_node(p_base);
|
2015-08-30 13:10:51 +00:00
|
|
|
if (!from || !root)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NodePath path = root->get_path_to(from);
|
|
|
|
|
2016-01-31 23:06:37 +00:00
|
|
|
//print_line("root: "+String(root->get_path()));
|
|
|
|
//print_line("path: "+String(path));
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
undo_redo->create_action(TTR("Anim Add Call Track"));
|
2017-03-05 15:44:50 +00:00
|
|
|
undo_redo->add_do_method(animation.ptr(), "add_track", Animation::TYPE_METHOD);
|
|
|
|
undo_redo->add_do_method(animation.ptr(), "track_set_path", animation->get_track_count(), path);
|
|
|
|
undo_redo->add_undo_method(animation.ptr(), "remove_track", animation->get_track_count());
|
2015-08-30 13:10:51 +00:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void AnimationKeyEditor::cleanup() {
|
|
|
|
|
|
|
|
set_animation(Ref<Animation>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AnimationKeyEditor::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_root_removed"), &AnimationKeyEditor::_root_removed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_scale"), &AnimationKeyEditor::_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_root"), &AnimationKeyEditor::set_root);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
//ClassDB::bind_method(D_METHOD("_confirm_insert"),&AnimationKeyEditor::_confirm_insert);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_confirm_insert_list"), &AnimationKeyEditor::_confirm_insert_list);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_paths"), &AnimationKeyEditor::_update_paths);
|
|
|
|
ClassDB::bind_method(D_METHOD("_track_editor_draw"), &AnimationKeyEditor::_track_editor_draw);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_animation_changed"), &AnimationKeyEditor::_animation_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_scroll_changed"), &AnimationKeyEditor::_scroll_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_track_editor_gui_input"), &AnimationKeyEditor::_track_editor_gui_input);
|
|
|
|
ClassDB::bind_method(D_METHOD("_track_name_changed"), &AnimationKeyEditor::_track_name_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_track_menu_selected"), &AnimationKeyEditor::_track_menu_selected);
|
|
|
|
ClassDB::bind_method(D_METHOD("_menu_add_track"), &AnimationKeyEditor::_menu_add_track);
|
|
|
|
ClassDB::bind_method(D_METHOD("_menu_track"), &AnimationKeyEditor::_menu_track);
|
|
|
|
ClassDB::bind_method(D_METHOD("_clear_selection_for_anim"), &AnimationKeyEditor::_clear_selection_for_anim);
|
|
|
|
ClassDB::bind_method(D_METHOD("_select_at_anim"), &AnimationKeyEditor::_select_at_anim);
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_track_position_draw"), &AnimationKeyEditor::_track_position_draw);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_insert_delay"), &AnimationKeyEditor::_insert_delay);
|
|
|
|
ClassDB::bind_method(D_METHOD("_step_changed"), &AnimationKeyEditor::_step_changed);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_animation_loop_changed"), &AnimationKeyEditor::_animation_loop_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_animation_len_changed"), &AnimationKeyEditor::_animation_len_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_create_value_item"), &AnimationKeyEditor::_create_value_item);
|
|
|
|
ClassDB::bind_method(D_METHOD("_pane_drag"), &AnimationKeyEditor::_pane_drag);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_animation_len_update"), &AnimationKeyEditor::_animation_len_update);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_animation"), &AnimationKeyEditor::set_animation);
|
|
|
|
ClassDB::bind_method(D_METHOD("_animation_optimize"), &AnimationKeyEditor::_animation_optimize);
|
|
|
|
ClassDB::bind_method(D_METHOD("_curve_transition_changed"), &AnimationKeyEditor::_curve_transition_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_toggle_edit_curves"), &AnimationKeyEditor::_toggle_edit_curves);
|
|
|
|
ClassDB::bind_method(D_METHOD("_add_call_track"), &AnimationKeyEditor::_add_call_track);
|
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "res"), PropertyInfo(Variant::STRING, "prop")));
|
|
|
|
ADD_SIGNAL(MethodInfo("keying_changed"));
|
2017-09-10 13:37:49 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::REAL, "position"), PropertyInfo(Variant::BOOL, "drag")));
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("animation_len_changed", PropertyInfo(Variant::REAL, "len")));
|
|
|
|
ADD_SIGNAL(MethodInfo("animation_step_changed", PropertyInfo(Variant::REAL, "step")));
|
|
|
|
ADD_SIGNAL(MethodInfo("key_edited", PropertyInfo(Variant::INT, "track"), PropertyInfo(Variant::INT, "key")));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 23:03:57 +00:00
|
|
|
AnimationKeyEditor::AnimationKeyEditor() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
alc = "animation_len_changed";
|
|
|
|
editor_selection = EditorNode::get_singleton()->get_editor_selection();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
selected_track = -1;
|
|
|
|
updating = false;
|
|
|
|
te_drawing = false;
|
|
|
|
undo_redo = EditorNode::get_singleton()->get_undo_redo();
|
|
|
|
history = EditorNode::get_singleton()->get_editor_history();
|
2016-01-17 23:03:57 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ec = memnew(Control);
|
2017-08-08 02:55:24 +00:00
|
|
|
ec->set_custom_minimum_size(Size2(0, 150) * EDSCALE);
|
2016-01-17 23:03:57 +00:00
|
|
|
add_child(ec);
|
|
|
|
ec->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
h_scroll = memnew(HScrollBar);
|
|
|
|
h_scroll->connect("value_changed", this, "_scroll_changed");
|
2016-01-17 23:03:57 +00:00
|
|
|
add_child(h_scroll);
|
2017-01-04 04:16:14 +00:00
|
|
|
h_scroll->set_value(0);
|
2016-01-17 23:03:57 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(hb);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
root = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
//menu = memnew( MenuButton );
|
|
|
|
//menu->set_flat(true);
|
2017-03-29 15:29:38 +00:00
|
|
|
//menu->set_position(Point2());
|
2014-02-10 01:10:30 +00:00
|
|
|
//add_child(menu);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
zoomicon = memnew(TextureRect);
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(zoomicon);
|
2016-05-04 01:25:37 +00:00
|
|
|
zoomicon->set_tooltip(TTR("Animation zoom."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
zoom = memnew(HSlider);
|
2014-02-10 01:10:30 +00:00
|
|
|
//hb->add_child(zoom);
|
|
|
|
zoom->set_step(0.01);
|
|
|
|
zoom->set_min(0.0);
|
|
|
|
zoom->set_max(2.0);
|
2017-01-04 04:16:14 +00:00
|
|
|
zoom->set_value(1.0);
|
2014-02-10 01:10:30 +00:00
|
|
|
zoom->set_h_size_flags(SIZE_EXPAND_FILL);
|
2017-07-18 06:32:25 +00:00
|
|
|
zoom->set_v_size_flags(SIZE_EXPAND_FILL);
|
2014-02-10 01:10:30 +00:00
|
|
|
zoom->set_stretch_ratio(2);
|
|
|
|
hb->add_child(zoom);
|
2017-03-05 15:44:50 +00:00
|
|
|
zoom->connect("value_changed", this, "_scroll_changed");
|
2016-05-04 01:25:37 +00:00
|
|
|
zoom->set_tooltip(TTR("Animation zoom."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
hb->add_child(memnew(VSeparator));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Label *l = memnew(Label);
|
2016-05-18 22:08:12 +00:00
|
|
|
l->set_text(TTR("Length (s):"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(l);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
length = memnew(SpinBox);
|
2014-02-10 01:10:30 +00:00
|
|
|
length->set_min(0.01);
|
|
|
|
length->set_max(10000);
|
|
|
|
length->set_step(0.01);
|
|
|
|
length->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
length->set_stretch_ratio(1);
|
2016-05-04 01:25:37 +00:00
|
|
|
length->set_tooltip(TTR("Animation length (in seconds)."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
hb->add_child(length);
|
2017-03-05 15:44:50 +00:00
|
|
|
length->connect("value_changed", this, "_animation_len_changed");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
l = memnew(Label);
|
2016-05-18 22:08:12 +00:00
|
|
|
l->set_text(TTR("Step (s):"));
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(l);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
step = memnew(SpinBox);
|
2014-02-10 01:10:30 +00:00
|
|
|
step->set_min(0.00);
|
|
|
|
step->set_max(128);
|
|
|
|
step->set_step(0.01);
|
2017-01-04 04:16:14 +00:00
|
|
|
step->set_value(0.0);
|
2014-02-10 01:10:30 +00:00
|
|
|
step->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
step->set_stretch_ratio(1);
|
2016-05-04 01:25:37 +00:00
|
|
|
step->set_tooltip(TTR("Cursor step snap (in seconds)."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
hb->add_child(step);
|
2017-03-05 15:44:50 +00:00
|
|
|
step->connect("value_changed", this, "_step_changed");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
loop = memnew(ToolButton);
|
2014-02-10 01:10:30 +00:00
|
|
|
loop->set_toggle_mode(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
loop->connect("pressed", this, "_animation_loop_changed");
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(loop);
|
2016-05-04 01:25:37 +00:00
|
|
|
loop->set_tooltip(TTR("Enable/Disable looping in animation."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
hb->add_child(memnew(VSeparator));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
menu_add_track = memnew(MenuButton);
|
2015-11-18 21:55:05 +00:00
|
|
|
hb->add_child(menu_add_track);
|
2017-03-05 15:44:50 +00:00
|
|
|
menu_add_track->get_popup()->connect("id_pressed", this, "_menu_add_track");
|
2016-05-04 01:25:37 +00:00
|
|
|
menu_add_track->set_tooltip(TTR("Add new tracks."));
|
2017-09-17 15:38:44 +00:00
|
|
|
menu_add_track->get_popup()->add_icon_item(get_icon("KeyValue", "EditorIcons"), "Add Normal Track", ADD_TRACK_MENU_ADD_VALUE_TRACK);
|
|
|
|
menu_add_track->get_popup()->add_icon_item(get_icon("KeyXform", "EditorIcons"), "Add Transform Track", ADD_TRACK_MENU_ADD_TRANSFORM_TRACK);
|
|
|
|
menu_add_track->get_popup()->add_icon_item(get_icon("KeyCall", "EditorIcons"), "Add Call Func Track", ADD_TRACK_MENU_ADD_CALL_TRACK);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
move_up_button = memnew(ToolButton);
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(move_up_button);
|
2017-03-05 15:44:50 +00:00
|
|
|
move_up_button->connect("pressed", this, "_menu_track", make_binds(TRACK_MENU_MOVE_UP));
|
2014-02-10 01:10:30 +00:00
|
|
|
move_up_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
move_up_button->set_disabled(true);
|
2016-05-04 01:25:37 +00:00
|
|
|
move_up_button->set_tooltip(TTR("Move current track up."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
move_down_button = memnew(ToolButton);
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(move_down_button);
|
2017-03-05 15:44:50 +00:00
|
|
|
move_down_button->connect("pressed", this, "_menu_track", make_binds(TRACK_MENU_MOVE_DOWN));
|
2014-02-10 01:10:30 +00:00
|
|
|
move_down_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
move_down_button->set_disabled(true);
|
2016-05-04 01:25:37 +00:00
|
|
|
move_down_button->set_tooltip(TTR("Move current track down."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
remove_button = memnew(ToolButton);
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(remove_button);
|
2017-03-05 15:44:50 +00:00
|
|
|
remove_button->connect("pressed", this, "_menu_track", make_binds(TRACK_MENU_REMOVE));
|
2014-02-10 01:10:30 +00:00
|
|
|
remove_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
remove_button->set_disabled(true);
|
2016-05-04 01:25:37 +00:00
|
|
|
remove_button->set_tooltip(TTR("Remove selected track."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
hb->add_child(memnew(VSeparator));
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
menu_track = memnew(MenuButton);
|
2015-11-18 21:55:05 +00:00
|
|
|
hb->add_child(menu_track);
|
2017-03-05 15:44:50 +00:00
|
|
|
menu_track->get_popup()->connect("id_pressed", this, "_menu_track");
|
2016-05-04 01:25:37 +00:00
|
|
|
menu_track->set_tooltip(TTR("Track tools"));
|
2015-11-18 21:55:05 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
edit_button = memnew(ToolButton);
|
2015-05-25 04:46:45 +00:00
|
|
|
edit_button->set_toggle_mode(true);
|
|
|
|
edit_button->set_focus_mode(FOCUS_NONE);
|
|
|
|
edit_button->set_disabled(true);
|
|
|
|
|
|
|
|
hb->add_child(edit_button);
|
2016-05-04 01:25:37 +00:00
|
|
|
edit_button->set_tooltip(TTR("Enable editing of individual keys by clicking them."));
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
optimize_dialog = memnew(ConfirmationDialog);
|
2014-11-12 14:23:23 +00:00
|
|
|
add_child(optimize_dialog);
|
2016-05-04 01:25:37 +00:00
|
|
|
optimize_dialog->set_title(TTR("Anim. Optimizer"));
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *optimize_vb = memnew(VBoxContainer);
|
2014-11-12 14:23:23 +00:00
|
|
|
optimize_dialog->add_child(optimize_vb);
|
2017-01-10 04:49:55 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
optimize_linear_error = memnew(SpinBox);
|
2014-11-12 14:23:23 +00:00
|
|
|
optimize_linear_error->set_max(1.0);
|
|
|
|
optimize_linear_error->set_min(0.001);
|
|
|
|
optimize_linear_error->set_step(0.001);
|
2017-01-04 04:16:14 +00:00
|
|
|
optimize_linear_error->set_value(0.05);
|
2017-03-05 15:44:50 +00:00
|
|
|
optimize_vb->add_margin_child(TTR("Max. Linear Error:"), optimize_linear_error);
|
|
|
|
optimize_angular_error = memnew(SpinBox);
|
2014-11-12 14:23:23 +00:00
|
|
|
optimize_angular_error->set_max(1.0);
|
|
|
|
optimize_angular_error->set_min(0.001);
|
|
|
|
optimize_angular_error->set_step(0.001);
|
2017-01-04 04:16:14 +00:00
|
|
|
optimize_angular_error->set_value(0.01);
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
optimize_vb->add_margin_child(TTR("Max. Angular Error:"), optimize_angular_error);
|
|
|
|
optimize_max_angle = memnew(SpinBox);
|
|
|
|
optimize_vb->add_margin_child(TTR("Max Optimizable Angle:"), optimize_max_angle);
|
2014-11-12 14:23:23 +00:00
|
|
|
optimize_max_angle->set_max(360.0);
|
|
|
|
optimize_max_angle->set_min(0.0);
|
|
|
|
optimize_max_angle->set_step(0.1);
|
2017-01-04 04:16:14 +00:00
|
|
|
optimize_max_angle->set_value(22);
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
optimize_dialog->get_ok()->set_text(TTR("Optimize"));
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/*keying = memnew( Button );
|
|
|
|
keying->set_toggle_mode(true);
|
2016-05-18 22:08:12 +00:00
|
|
|
//keying->set_text("Keys");
|
2014-02-10 01:10:30 +00:00
|
|
|
keying->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,60);
|
|
|
|
keying->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,10);
|
|
|
|
keying->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,55);
|
|
|
|
keying->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,10);
|
|
|
|
//add_child(keying);
|
|
|
|
keying->connect("pressed",this,"_keying_toggled");
|
|
|
|
*/
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/* l = memnew( Label );
|
2016-05-18 22:08:12 +00:00
|
|
|
l->set_text("Base: ");
|
2017-03-29 15:29:38 +00:00
|
|
|
l->set_position(Point2(0,3));
|
2017-01-14 11:26:56 +00:00
|
|
|
//dr_panel->add_child(l);*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
//menu->get_popup()->connect("id_pressed",this,"_menu_callback");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
hb = memnew(HBoxContainer);
|
2017-09-21 22:12:33 +00:00
|
|
|
hb->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
2014-02-10 01:10:30 +00:00
|
|
|
ec->add_child(hb);
|
|
|
|
hb->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
track_editor = memnew(Control);
|
|
|
|
track_editor->connect("draw", this, "_track_editor_draw");
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(track_editor);
|
2017-03-05 15:44:50 +00:00
|
|
|
track_editor->connect("gui_input", this, "_track_editor_gui_input");
|
2014-02-10 01:10:30 +00:00
|
|
|
track_editor->set_focus_mode(Control::FOCUS_ALL);
|
|
|
|
track_editor->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
track_pos = memnew(Control);
|
2017-09-21 22:12:33 +00:00
|
|
|
track_pos->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
2017-01-08 22:54:19 +00:00
|
|
|
track_pos->set_mouse_filter(MOUSE_FILTER_IGNORE);
|
2014-02-10 01:10:30 +00:00
|
|
|
track_editor->add_child(track_pos);
|
2017-09-10 13:37:49 +00:00
|
|
|
track_pos->connect("draw", this, "_track_position_draw");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
select_anim_warning = memnew(Label);
|
2016-07-22 12:42:12 +00:00
|
|
|
track_editor->add_child(select_anim_warning);
|
2017-09-21 22:12:33 +00:00
|
|
|
select_anim_warning->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
2016-07-22 12:42:12 +00:00
|
|
|
select_anim_warning->set_text(TTR("Select an AnimationPlayer from the Scene Tree to edit animations."));
|
|
|
|
select_anim_warning->set_autowrap(true);
|
|
|
|
select_anim_warning->set_align(Label::ALIGN_CENTER);
|
|
|
|
select_anim_warning->set_valign(Label::VALIGN_CENTER);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v_scroll = memnew(VScrollBar);
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(v_scroll);
|
2017-03-05 15:44:50 +00:00
|
|
|
v_scroll->connect("value_changed", this, "_scroll_changed");
|
2017-01-04 04:16:14 +00:00
|
|
|
v_scroll->set_value(0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
key_editor_tab = memnew(TabContainer);
|
2017-05-02 20:13:12 +00:00
|
|
|
key_editor_tab->set_tab_align(TabContainer::ALIGN_LEFT);
|
2015-05-25 04:46:45 +00:00
|
|
|
hb->add_child(key_editor_tab);
|
2017-09-18 19:39:37 +00:00
|
|
|
key_editor_tab->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
key_editor = memnew(PropertyEditor);
|
2015-05-25 04:46:45 +00:00
|
|
|
key_editor->hide_top_label();
|
2016-05-04 01:25:37 +00:00
|
|
|
key_editor->set_name(TTR("Key"));
|
2015-05-25 04:46:45 +00:00
|
|
|
key_editor_tab->add_child(key_editor);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
key_edit = memnew(AnimationKeyEdit);
|
|
|
|
key_edit->undo_redo = undo_redo;
|
2015-05-25 04:46:45 +00:00
|
|
|
//key_edit->ke_dialog=key_edit_dialog;
|
2016-01-23 22:51:51 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
type_menu = memnew(PopupMenu);
|
2015-05-25 04:46:45 +00:00
|
|
|
add_child(type_menu);
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < Variant::VARIANT_MAX; i++)
|
|
|
|
type_menu->add_item(Variant::get_type_name(Variant::Type(i)), i);
|
|
|
|
type_menu->connect("id_pressed", this, "_create_value_item");
|
2015-05-25 04:46:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *curve_vb = memnew(VBoxContainer);
|
2016-05-04 01:25:37 +00:00
|
|
|
curve_vb->set_name(TTR("Transition"));
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *curve_hb = memnew(HBoxContainer);
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_vb->add_child(curve_hb);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_linear = memnew(ToolButton);
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_linear->set_focus_mode(FOCUS_NONE);
|
|
|
|
curve_hb->add_child(curve_linear);
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_in = memnew(ToolButton);
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_in->set_focus_mode(FOCUS_NONE);
|
|
|
|
curve_hb->add_child(curve_in);
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_out = memnew(ToolButton);
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_out->set_focus_mode(FOCUS_NONE);
|
|
|
|
curve_hb->add_child(curve_out);
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_inout = memnew(ToolButton);
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_inout->set_focus_mode(FOCUS_NONE);
|
|
|
|
curve_hb->add_child(curve_inout);
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_outin = memnew(ToolButton);
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_outin->set_focus_mode(FOCUS_NONE);
|
|
|
|
curve_hb->add_child(curve_outin);
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_constant = memnew(ToolButton);
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_constant->set_focus_mode(FOCUS_NONE);
|
|
|
|
curve_hb->add_child(curve_constant);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
curve_edit = memnew(AnimationCurveEdit);
|
2015-05-25 04:46:45 +00:00
|
|
|
curve_vb->add_child(curve_edit);
|
|
|
|
curve_edit->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
key_editor_tab->add_child(curve_vb);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
track_name = memnew(LineEdit);
|
2014-02-10 01:10:30 +00:00
|
|
|
track_name->set_as_toplevel(true);
|
|
|
|
track_name->hide();
|
|
|
|
add_child(track_name);
|
2017-03-05 15:44:50 +00:00
|
|
|
track_name->connect("text_entered", this, "_track_name_changed");
|
|
|
|
track_menu = memnew(PopupMenu);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(track_menu);
|
2017-03-05 15:44:50 +00:00
|
|
|
track_menu->connect("id_pressed", this, "_track_menu_selected");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
key_editor_tab->hide();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
last_idx = 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_update_menu();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_confirm = memnew(ConfirmationDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(insert_confirm);
|
2017-03-05 15:44:50 +00:00
|
|
|
insert_confirm->connect("confirmed", this, "_confirm_insert_list");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
click.click = ClickOver::CLICK_NONE;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
name_column_ratio = 0.3;
|
|
|
|
timeline_pos = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
keying = false;
|
|
|
|
insert_frame = 0;
|
|
|
|
insert_query = false;
|
|
|
|
insert_queue = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
editor_selection->connect("selection_changed", track_editor, "update");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scale_dialog = memnew(ConfirmationDialog);
|
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
scale_dialog->add_child(vbc);
|
2017-01-10 04:49:55 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scale = memnew(SpinBox);
|
2014-02-10 01:10:30 +00:00
|
|
|
scale->set_min(-99999);
|
|
|
|
scale->set_max(99999);
|
|
|
|
scale->set_step(0.001);
|
2017-03-05 15:44:50 +00:00
|
|
|
vbc->add_margin_child(TTR("Scale Ratio:"), scale);
|
|
|
|
scale_dialog->connect("confirmed", this, "_scale");
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(scale_dialog);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
call_select = memnew(SceneTreeDialog);
|
2015-08-30 13:10:51 +00:00
|
|
|
add_child(call_select);
|
2016-05-04 01:25:37 +00:00
|
|
|
call_select->set_title(TTR("Call Functions in Which Node?"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cleanup_dialog = memnew(ConfirmationDialog);
|
2015-12-05 17:18:22 +00:00
|
|
|
add_child(cleanup_dialog);
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *cleanup_vb = memnew(VBoxContainer);
|
2015-12-05 17:18:22 +00:00
|
|
|
cleanup_dialog->add_child(cleanup_vb);
|
2017-01-10 04:49:55 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cleanup_keys = memnew(CheckButton);
|
2016-05-04 01:25:37 +00:00
|
|
|
cleanup_keys->set_text(TTR("Remove invalid keys"));
|
2015-12-05 17:18:22 +00:00
|
|
|
cleanup_keys->set_pressed(true);
|
|
|
|
cleanup_vb->add_child(cleanup_keys);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cleanup_tracks = memnew(CheckButton);
|
2016-05-04 01:25:37 +00:00
|
|
|
cleanup_tracks->set_text(TTR("Remove unresolved and empty tracks"));
|
2015-12-05 17:18:22 +00:00
|
|
|
cleanup_tracks->set_pressed(true);
|
|
|
|
cleanup_vb->add_child(cleanup_tracks);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cleanup_all = memnew(CheckButton);
|
2016-05-18 22:08:12 +00:00
|
|
|
cleanup_all->set_text(TTR("Clean-up all animations"));
|
2015-12-05 17:18:22 +00:00
|
|
|
cleanup_vb->add_child(cleanup_all);
|
|
|
|
|
2016-05-18 22:08:12 +00:00
|
|
|
cleanup_dialog->set_title(TTR("Clean-Up Animation(s) (NO UNDO!)"));
|
2016-05-04 01:25:37 +00:00
|
|
|
cleanup_dialog->get_ok()->set_text(TTR("Clean-Up"));
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
cleanup_dialog->connect("confirmed", this, "_menu_track", varray(TRACK_MENU_CLEAN_UP_CONFIRM));
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2017-01-09 18:50:08 +00:00
|
|
|
track_editor->set_clip_contents(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AnimationKeyEditor::~AnimationKeyEditor() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
memdelete(key_edit);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|