diff --git a/.gitignore b/.gitignore index 8ab969c9a47..cdf277dd713 100644 --- a/.gitignore +++ b/.gitignore @@ -16,12 +16,12 @@ core/method_bind_ext.inc core/script_encryption_key.cpp core/global_defaults.cpp drivers/unix/os_unix_global_settings_path.cpp -tools/editor/register_exporters.cpp -tools/editor/doc_data_compressed.h -tools/editor/certs_compressed.h -tools/editor/editor_icons.cpp -tools/editor/translations.h -tools/editor/builtin_fonts.h +editor/register_exporters.cpp +editor/doc_data_compressed.h +editor/certs_compressed.h +editor/editor_icons.cpp +editor/translations.h +editor/builtin_fonts.h .fscache make.bat log.txt diff --git a/SConstruct b/SConstruct index 4c79304ef2d..2e7683d17ab 100644 --- a/SConstruct +++ b/SConstruct @@ -179,7 +179,7 @@ Help(opts.GenerateHelpText(env_base)) # generate help # add default include paths -env_base.Append(CPPPATH=['#core', '#core/math', '#tools', '#drivers', '#']) +env_base.Append(CPPPATH=['#core', '#core/math', '#editor', '#drivers', '#']) # configure ENV for platform env_base.platform_exporters = platform_exporters @@ -358,7 +358,7 @@ if selected_platform in platform_list: SConscript("core/SCsub") SConscript("servers/SCsub") SConscript("scene/SCsub") - SConscript("tools/editor/SCsub") + SConscript("editor/SCsub") SConscript("drivers/SCsub") SConscript("modules/SCsub") diff --git a/editor/SCsub b/editor/SCsub new file mode 100644 index 00000000000..d7392f82493 --- /dev/null +++ b/editor/SCsub @@ -0,0 +1,205 @@ +#!/usr/bin/env python + +Import('env') +env.editor_sources = [] + +import os + + +def make_certs_header(target, source, env): + + src = source[0].srcnode().abspath + dst = target[0].srcnode().abspath + f = open(src, "rb") + g = open(dst, "wb") + buf = f.read() + decomp_size = len(buf) + import zlib + buf = zlib.compress(buf) + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _CERTS_RAW_H\n") + g.write("#define _CERTS_RAW_H\n") + g.write("static const int _certs_compressed_size=" + str(len(buf)) + ";\n") + g.write("static const int _certs_uncompressed_size=" + str(decomp_size) + ";\n") + g.write("static const unsigned char _certs_compressed[]={\n") + for i in range(len(buf)): + g.write(str(ord(buf[i])) + ",\n") + g.write("};\n") + g.write("#endif") + + +def make_doc_header(target, source, env): + + dst = target[0].srcnode().abspath + g = open(dst, "wb") + buf = "" + docbegin = "" + docend = "" + for s in source: + src = s.srcnode().abspath + f = open(src, "rb") + content = f.read() + buf += content[content.find("")] + if len(docbegin) == 0: + docbegin = content[0: content.find(""): len(buf)] + buf = docbegin + buf + docend + decomp_size = len(buf) + import zlib + buf = zlib.compress(buf) + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _DOC_DATA_RAW_H\n") + g.write("#define _DOC_DATA_RAW_H\n") + g.write("static const int _doc_data_compressed_size=" + str(len(buf)) + ";\n") + g.write("static const int _doc_data_uncompressed_size=" + str(decomp_size) + ";\n") + g.write("static const unsigned char _doc_data_compressed[]={\n") + for i in range(len(buf)): + g.write(str(ord(buf[i])) + ",\n") + g.write("};\n") + g.write("#endif") + + +def make_fonts_header(target, source, env): + + dst = target[0].srcnode().abspath + + g = open(dst, "wb") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _EDITOR_FONTS_H\n") + g.write("#define _EDITOR_FONTS_H\n") + + # saving uncompressed, since freetype will reference from memory pointer + xl_names = [] + for i in range(len(source)): + print("Appending font: " + source[i].srcnode().abspath) + f = open(source[i].srcnode().abspath, "rb") + buf = f.read() + import os.path + + name = os.path.splitext(os.path.basename(source[i].srcnode().abspath))[0] + + g.write("static const int _font_" + name + "_size=" + str(len(buf)) + ";\n") + g.write("static const unsigned char _font_" + name + "[]={\n") + for i in range(len(buf)): + g.write(str(ord(buf[i])) + ",\n") + + g.write("};\n") + + g.write("#endif") + + +def make_translations_header(target, source, env): + + dst = target[0].srcnode().abspath + + g = open(dst, "wb") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _EDITOR_TRANSLATIONS_H\n") + g.write("#define _EDITOR_TRANSLATIONS_H\n") + + import zlib + import os.path + + paths = [node.srcnode().abspath for node in source] + sorted_paths = sorted(paths, key=lambda path: os.path.splitext(os.path.basename(path))[0]) + + xl_names = [] + for i in range(len(sorted_paths)): + print("Appending translation: " + sorted_paths[i]) + f = open(sorted_paths[i], "rb") + buf = f.read() + decomp_size = len(buf) + buf = zlib.compress(buf) + name = os.path.splitext(os.path.basename(sorted_paths[i]))[0] + + #g.write("static const int _translation_"+name+"_compressed_size="+str(len(buf))+";\n") + #g.write("static const int _translation_"+name+"_uncompressed_size="+str(decomp_size)+";\n") + g.write("static const unsigned char _translation_" + name + "_compressed[]={\n") + for i in range(len(buf)): + g.write(str(ord(buf[i])) + ",\n") + + g.write("};\n") + + xl_names.append([name, len(buf), str(decomp_size)]) + + g.write("struct EditorTranslationList {\n") + g.write("\tconst char* lang;\n") + g.write("\tint comp_size;\n") + g.write("\tint uncomp_size;\n") + g.write("\tconst unsigned char* data;\n") + g.write("};\n\n") + g.write("static EditorTranslationList _editor_translations[]={\n") + for x in xl_names: + g.write("\t{ \"" + x[0] + "\", " + str(x[1]) + ", " + str(x[2]) + ",_translation_" + x[0] + "_compressed},\n") + g.write("\t{NULL,0,0,NULL}\n") + g.write("};\n") + + g.write("#endif") + + +if (env["tools"] == "yes"): + + # Register exporters + reg_exporters_inc = '#include "register_exporters.h"\n' + reg_exporters = 'void register_exporters() {\n' + for e in env.platform_exporters: + env.editor_sources.append("#platform/" + e + "/export/export.cpp") + reg_exporters += '\tregister_' + e + '_exporter();\n' + reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n' + reg_exporters += '}\n' + f = open("register_exporters.cpp", "wb") + f.write(reg_exporters_inc) + f.write(reg_exporters) + f.close() + + # API documentation + docs = ["#doc/base/classes.xml"] + moduledir = os.path.join(os.getcwd(), "..", "modules") + for m in os.listdir(moduledir): + curmodle = os.path.join(moduledir, m) + docfile = os.path.join(curmodle, "classes.xml") + if os.path.isdir(curmodle) and os.path.isfile(docfile): + docs.append(docfile) + env.Depends("#editor/doc_data_compressed.h", docs) + env.Command("#editor/doc_data_compressed.h", docs, make_doc_header) + + # Certificates + env.Depends("#editor/certs_compressed.h", "#thirdparty/certs/ca-certificates.crt") + env.Command("#editor/certs_compressed.h", "#thirdparty/certs/ca-certificates.crt", make_certs_header) + + import glob + path = env.Dir('.').abspath + + # Translations + tlist = glob.glob(path + "/translations/*.po") + print("translations: ", tlist) + env.Depends('#editor/translations.h', tlist) + env.Command('#editor/translations.h', tlist, make_translations_header) + + # Fonts + flist = glob.glob(path + "/../thirdparty/fonts/*.ttf") + flist.append(glob.glob(path + "/../thirdparty/fonts/*.otf")) + print("fonts: ", flist) + env.Depends('#editor/builtin_fonts.h', flist) + env.Command('#editor/builtin_fonts.h', flist, make_fonts_header) + + + env.add_source_files(env.editor_sources, "*.cpp") + + SConscript('collada/SCsub') + SConscript('doc/SCsub') + SConscript('fileserver/SCsub') + SConscript('icons/SCsub') + SConscript('import/SCsub') + SConscript('io_plugins/SCsub') + SConscript('plugins/SCsub') + + lib = env.Library("editor", env.editor_sources) + env.Prepend(LIBS=[lib]) + + Export('env') diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp new file mode 100644 index 00000000000..d65f229fcaf --- /dev/null +++ b/editor/animation_editor.cpp @@ -0,0 +1,4331 @@ +/*************************************************************************/ +/* animation_editor.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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" + +#include "editor_settings.h" +#include "os/keyboard.h" +#include "os/os.h" +#include "io/resource_saver.h" +#include "pair.h" +#include "scene/gui/separator.h" +#include "editor_node.h" +#include "editor/plugins/animation_player_editor_plugin.h" +#include "scene/main/viewport.h" +/* 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 +*/ + + +class AnimationCurveEdit : public Control { + GDCLASS( AnimationCurveEdit, Control ); +public: + enum Mode { + MODE_DISABLED, + MODE_SINGLE, + MODE_MULTIPLE + }; +private: + + Set multiples; + float transition; + Mode mode; + + void _notification(int p_what) { + + if (p_what==NOTIFICATION_DRAW) { + + + RID ci = get_canvas_item(); + + Size2 s = get_size(); + Rect2 r(Point2(),s); + + //r=r.grow(3); + Ref sb = get_stylebox("normal","LineEdit"); + sb->draw(ci,r); + r.size-=sb->get_minimum_size(); + r.pos+=sb->get_offset(); + //VisualServer::get_singleton()->canvas_item_add + + Ref f = get_font("font","Label"); + r=r.grow(-2); + Color color = get_color("font_color","Label"); + + int points = 48; + if (mode==MODE_MULTIPLE) { + + Color mcolor=color; + mcolor.a*=0.3; + + Set::Element *E=multiples.front(); + for(int j=0;j<16;j++) { + + if (!E) + break; + + float prev=1.0; + float exp=E->get(); + bool flip=false;//hint_text=="attenuation"; + + + for(int i=1;i<=points;i++) { + + float ifl = i/float(points); + float iflp = (i-1)/float(points); + + float h = 1.0-Math::ease(ifl,exp); + + if (flip) { + ifl=1.0-ifl; + iflp=1.0-iflp; + } + + VisualServer::get_singleton()->canvas_item_add_line(ci,r.pos+Point2(iflp*r.size.width,prev*r.size.height),r.pos+Point2(ifl*r.size.width,h*r.size.height),mcolor); + prev=h; + } + + E=E->next(); + } + } + + float exp=transition; + if (mode!=MODE_DISABLED) { + + + float prev=1.0; + + bool flip=false;//hint_text=="attenuation"; + + + for(int i=1;i<=points;i++) { + + float ifl = i/float(points); + float iflp = (i-1)/float(points); + + float h = 1.0-Math::ease(ifl,exp); + + if (flip) { + ifl=1.0-ifl; + iflp=1.0-iflp; + } + + VisualServer::get_singleton()->canvas_item_add_line(ci,r.pos+Point2(iflp*r.size.width,prev*r.size.height),r.pos+Point2(ifl*r.size.width,h*r.size.height),color); + prev=h; + } + } + + String txt=String::num(exp,2); + if (mode==MODE_DISABLED) { + txt=TTR("Disabled"); + } else if (mode==MODE_MULTIPLE) { + txt+=" - "+TTR("All Selection"); + } + + f->draw(ci,Point2(10,10+f->get_ascent()),txt,color); + + } + } + + void _gui_input(const InputEvent& p_ev) { + if (p_ev.type==InputEvent::MOUSE_MOTION && p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT) { + + if (mode==MODE_DISABLED) + return; + + float rel = p_ev.mouse_motion.relative_x; + if (rel==0) + return; + + bool flip=false; + + if (flip) + rel=-rel; + + float val = transition; + if (val==0) + return; + bool sg = val < 0; + val = Math::absf(val); + + val = Math::log(val)/Math::log((float)2.0); + //logspace + val+=rel*0.05; + // + + val = Math::pow((float)2.0,val); + if (sg) + val=-val; + + transition=val; + update(); + //emit_signal("variant_changed"); + emit_signal("transition_changed",transition); + } + } + +public: + + static void _bind_methods() { + + //ClassDB::bind_method("_update_obj",&AnimationKeyEdit::_update_obj); + ClassDB::bind_method("_gui_input",&AnimationCurveEdit::_gui_input); + ADD_SIGNAL(MethodInfo("transition_changed")); + } + + void set_mode(Mode p_mode) { + + mode=p_mode; + update(); + } + + void clear_multiples() { multiples.clear(); update();} + void set_multiple(float p_transition) { + + multiples.insert(p_transition); + } + + void set_transition(float p_transition) { + transition=p_transition; + update(); + } + + float get_transition() const { + return transition; + } + + void force_transition(float p_value) { + if (mode==MODE_DISABLED) + return; + transition=p_value; + emit_signal("transition_changed",p_value); + update(); + } + + AnimationCurveEdit() { + + transition=1.0; + set_default_cursor_shape(CURSOR_HSPLIT); + mode=MODE_DISABLED; + } + +}; + +class AnimationKeyEdit : public Object { + + GDCLASS(AnimationKeyEdit,Object); +public: + bool setting; + bool hidden; + + static void _bind_methods() { + + ClassDB::bind_method("_update_obj",&AnimationKeyEdit::_update_obj); + ClassDB::bind_method("_key_ofs_changed",&AnimationKeyEdit::_key_ofs_changed); + } + + //PopupDialog *ke_dialog; + + void _fix_node_path(Variant &value) { + + + NodePath np=value; + + if (np==NodePath()) + return; + + Node* root = EditorNode::get_singleton()->get_tree()->get_root(); + + Node* np_node = root->get_node(np); + ERR_FAIL_COND(!np_node); + + Node* edited_node = root->get_node(base); + ERR_FAIL_COND(!edited_node); + + + + value = edited_node->get_path_to(np_node); + } + + + void _update_obj(const Ref &p_anim) { + if (setting) + return; + if (hidden) + return; + if (!(animation==p_anim)) + return; + notify_change(); + } + + void _key_ofs_changed(const Ref &p_anim,float from, float to) { + if (hidden) + return; + if (!(animation==p_anim)) + return; + if (from!=key_ofs) + return; + key_ofs=to; + if (setting) + return; + notify_change(); + } + + bool _set(const StringName& p_name, const Variant& p_value) { + + int key = animation->track_find_key(track,key_ofs,true); + ERR_FAIL_COND_V(key==-1,false); + + String name=p_name; + if (name=="time") { + + float new_time = p_value; + if (new_time==key_ofs) + return true; + + int existing = animation->track_find_key(track,new_time,true); + + setting=true; + undo_redo->create_action(TTR("Move Add Key"),UndoRedo::MERGE_ENDS); + + Variant val = animation->track_get_key_value(track,key); + float trans = animation->track_get_key_transition(track,key); + + 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); + undo_redo->add_undo_method(animation.ptr(),"track_remove_key_at_pos",track,new_time); + 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); + + + 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); + } + + undo_redo->commit_action(); + setting=false; + + return true; + } else if (name=="easing") { + + float val = p_value; + 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); + undo_redo->commit_action(); + setting=false; + return true; + } + + + + switch(animation->track_get_type(track)) { + + + case Animation::TYPE_TRANSFORM: { + + Dictionary d_old = animation->track_get_key_value(track,key); + Dictionary d_new = d_old; + d_new[p_name]=p_value; + setting=true; + undo_redo->create_action(TTR("Anim Change Transform")); + 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); + undo_redo->commit_action(); + setting=false; + return true; + + } break; + case Animation::TYPE_VALUE: { + + if (name=="value") { + + Variant value = p_value; + + if (value.get_type()==Variant::NODE_PATH) { + + _fix_node_path(value); + } + + 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); + undo_redo->commit_action(); + setting=false; + return true; + } + + + + } break; + case Animation::TYPE_METHOD: { + + Dictionary d_old = animation->track_get_key_value(track,key); + Dictionary d_new = d_old; + + bool change_notify_deserved=false; + bool mergeable=false; + + if (name=="name") { + + d_new["method"]=p_value; + + } + + if (name=="arg_count") { + + Vector args = d_old["args"]; + args.resize(p_value); + d_new["args"]=args; + change_notify_deserved=true; + } + + if (name.begins_with("args/")) { + + + Vector args = d_old["args"]; + int idx = name.get_slice("/",1).to_int(); + ERR_FAIL_INDEX_V(idx,args.size(),false); + + String what = name.get_slice("/",2); + if (what=="type") { + Variant::Type t = Variant::Type(int(p_value)); + + if (t!=args[idx].get_type()) { + Variant::CallError err; + 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); + } else { + + args[idx]=Variant::construct(t,NULL,0,err); + } + change_notify_deserved=true; + d_new["args"]=args; + } + + } + if (what=="value") { + + Variant value=p_value; + if (value.get_type()==Variant::NODE_PATH) { + + _fix_node_path(value); + } + + args[idx]=value; + d_new["args"]=args; + mergeable=true; + } + } + + if (mergeable) + undo_redo->create_action(TTR("Anim Change Call"),UndoRedo::MERGE_ENDS); + else + undo_redo->create_action(TTR("Anim Change Call")); + + 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); + undo_redo->commit_action(); + setting=false; + if (change_notify_deserved) + notify_change(); + return true; + } break; + } + + + + return false; + + } + + bool _get(const StringName& p_name,Variant &r_ret) const { + + int key = animation->track_find_key(track,key_ofs,true); + ERR_FAIL_COND_V(key==-1,false); + + String name=p_name; + if (name=="time") { + r_ret = key_ofs; + return true; + } else if (name=="easing") { + r_ret = animation->track_get_key_transition(track,key); + return true; + } + + + + switch(animation->track_get_type(track)) { + + + case Animation::TYPE_TRANSFORM: { + + Dictionary d = animation->track_get_key_value(track,key); + ERR_FAIL_COND_V(!d.has(name),false); + r_ret = d[p_name]; + return true; + + } break; + case Animation::TYPE_VALUE: { + + if (name=="value") { + r_ret = animation->track_get_key_value(track,key); + return true; + } + + + + } break; + case Animation::TYPE_METHOD: { + + Dictionary d = animation->track_get_key_value(track,key); + + if (name=="name") { + + ERR_FAIL_COND_V(!d.has("method"),false); + r_ret=d["method"]; + return true; + } + + ERR_FAIL_COND_V(!d.has("args"),false); + + Vector args = d["args"]; + + + if (name=="arg_count") { + + r_ret=args.size(); + return true; + } + + + if (name.begins_with("args/")) { + + int idx = name.get_slice("/",1).to_int(); + ERR_FAIL_INDEX_V(idx,args.size(),false); + + String what = name.get_slice("/",2); + if (what=="type") { + r_ret=args[idx].get_type(); + return true; + } + if (what=="value") { + r_ret=args[idx]; + return true; + } + } + + } break; + } + + return false; + } + void _get_property_list( List *p_list) const { + + if (animation.is_null()) + return; + + ERR_FAIL_INDEX(track,animation->get_track_count()); + int key = animation->track_find_key(track,key_ofs,true); + ERR_FAIL_COND(key==-1); + + p_list->push_back( PropertyInfo( Variant::REAL, "time", PROPERTY_HINT_RANGE,"0,"+rtos(animation->get_length())+",0.01") ); + + switch(animation->track_get_type(track)) { + + + case Animation::TYPE_TRANSFORM: { + + p_list->push_back( PropertyInfo( Variant::VECTOR3, "loc")); + p_list->push_back( PropertyInfo( Variant::QUAT, "rot")); + p_list->push_back( PropertyInfo( Variant::VECTOR3, "scale")); + + } break; + case Animation::TYPE_VALUE: { + + Variant v = animation->track_get_key_value(track,key); + + + + if (hint.type!=Variant::NIL) { + + PropertyInfo pi=hint; + pi.name="value"; + p_list->push_back( pi ); + } else { + + PropertyHint hint= PROPERTY_HINT_NONE; + String hint_string; + + if (v.get_type()==Variant::OBJECT) { + //could actually check the object property if exists..? yes i will! + Ref res = v; + if (res.is_valid()) { + + hint=PROPERTY_HINT_RESOURCE_TYPE; + hint_string=res->get_class(); + } + } + + if (v.get_type()!=Variant::NIL) + p_list->push_back( PropertyInfo( v.get_type(), "value", hint,hint_string)); + } + + } break; + case Animation::TYPE_METHOD: { + + p_list->push_back( PropertyInfo( Variant::STRING, "name")); + p_list->push_back( PropertyInfo( Variant::INT, "arg_count",PROPERTY_HINT_RANGE,"0,5,1")); + + Dictionary d = animation->track_get_key_value(track,key); + ERR_FAIL_COND(!d.has("args")); + Vector args=d["args"]; + String vtypes; + for(int i=0;i0) + vtypes+=","; + vtypes+=Variant::get_type_name( Variant::Type(i) ); + } + + for(int i=0;ipush_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")); + } + + } break; + } + + /* + if (animation->track_get_type(track)!=Animation::TYPE_METHOD) + p_list->push_back( PropertyInfo( Variant::REAL, "easing", PROPERTY_HINT_EXP_EASING)); + */ + } + + UndoRedo *undo_redo; + Ref animation; + int track; + float key_ofs; + + PropertyInfo hint; + NodePath base; + + + void notify_change() { + + _change_notify(); + } + + AnimationKeyEdit() { hidden=true; key_ofs=0; track=-1; setting=false; } + +}; + + +void AnimationKeyEditor::_menu_add_track(int p_type) { + + ERR_FAIL_COND(!animation.is_valid()); + + + switch(p_type) { + + case ADD_TRACK_MENU_ADD_CALL_TRACK: { + if (root) { + call_select->popup_centered_ratio(); + break; + } + } break; + case ADD_TRACK_MENU_ADD_VALUE_TRACK: + case ADD_TRACK_MENU_ADD_TRANSFORM_TRACK: { + + undo_redo->create_action(TTR("Anim Add Track")); + 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()); + undo_redo->commit_action(); + + + } break; + } +} + +void AnimationKeyEditor::_anim_duplicate_keys(bool transpose) { + //duplicait! + if (selection.size() && animation.is_valid() && selected_track>=0 && selected_trackget_track_count()) { + + int top_track=0x7FFFFFFF; + float top_time = 1e10; + for(Map::Element *E=selection.back();E;E=E->prev()) { + + const SelectedKey &sk = E->key(); + + float t = animation->track_get_key_time(sk.track,sk.key); + if (tcreate_action(TTR("Anim Duplicate Keys")); + + List > new_selection_values; + + for(Map::Element *E=selection.back();E;E=E->prev()) { + + const SelectedKey &sk = E->key(); + + float t = animation->track_get_key_time(sk.track,sk.key); + + float dst_time = t+(timeline_pos - top_time); + int dst_track = sk.track + (start_track - top_track); + + if (dst_track < 0 || dst_track>= animation->get_track_count()) + continue; + + if (animation->track_get_type(dst_track) != animation->track_get_type(sk.track)) + continue; + + int existing_idx = animation->track_find_key(dst_track,dst_time,true); + + 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)); + undo_redo->add_undo_method(animation.ptr(),"track_remove_key_at_pos",dst_track,dst_time); + + Pair p; + p.first=dst_track; + p.second=dst_time; + new_selection_values.push_back( p ); + + if (existing_idx!=-1) { + + 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)); + + } + + } + + undo_redo->commit_action(); + + //reselect duplicated + + Map new_selection; + for (List >::Element *E=new_selection_values.front();E;E=E->next()) { + + int track=E->get().first; + float time = E->get().second; + + int existing_idx = animation->track_find_key(track,time,true); + + if (existing_idx==-1) + continue; + SelectedKey sk2; + sk2.track=track; + sk2.key=existing_idx; + + KeyInfo ki; + ki.pos=time; + + new_selection[sk2]=ki; + + } + + + selection=new_selection; + track_editor->update(); + _edit_if_single_selection(); + + } +} + +void AnimationKeyEditor::_menu_track(int p_type) { + + ERR_FAIL_COND(!animation.is_valid()); + + last_menu_track_opt=p_type; + switch(p_type) { + + case TRACK_MENU_SCALE: + case TRACK_MENU_SCALE_PIVOT: { + + scale_dialog->popup_centered(Size2(200,100)); + } break; + case TRACK_MENU_MOVE_UP: { + + int idx=selected_track; + if (idx>0 && idxget_track_count()) { + undo_redo->create_action(TTR("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(); + selected_track=idx-1; + } + + } break; + case TRACK_MENU_MOVE_DOWN: { + + + int idx=selected_track; + if (idx>=0 && idxget_track_count()-1) { + undo_redo->create_action(TTR("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(); + selected_track=idx+1; + } + + } break; + case TRACK_MENU_REMOVE: { + + int idx=selected_track; + if (idx>=0 && idxget_track_count()) { + undo_redo->create_action(TTR("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;itrack_get_key_count(idx);i++) { + + 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); + + 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); + + } + + 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)); + + } + + undo_redo->commit_action(); + } + + + } break; + case TRACK_MENU_DUPLICATE: + case TRACK_MENU_DUPLICATE_TRANSPOSE: { + + _anim_duplicate_keys(p_type==TRACK_MENU_DUPLICATE_TRANSPOSE); + } 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; + + 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; + } + + undo_redo->create_action(TTR("Set Transitions to:")+" "+rtos(t)); + + for(Map::Element *E=selection.back();E;E=E->prev()) { + + const SelectedKey &sk = E->key(); + + 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)); + + } + + undo_redo->commit_action(); + + } break; + case TRACK_MENU_NEXT_STEP: { + + if (animation.is_null()) + break; + float step = animation->get_step(); + if (step==0) + step=1; + + float pos=timeline_pos; + + pos=Math::stepify(pos+step,step); + if (pos>animation->get_length()) + pos=animation->get_length(); + timeline_pos=pos; + track_pos->update(); + emit_signal("timeline_changed",pos,true); + + } break; + case TRACK_MENU_PREV_STEP: { + if (animation.is_null()) + break; + float step = animation->get_step(); + if (step==0) + step=1; + + float pos=timeline_pos; + pos=Math::stepify(pos-step,step); + if (pos<0) + pos=0; + timeline_pos=pos; + track_pos->update(); + emit_signal("timeline_changed",pos,true); + + + } break; + + case TRACK_MENU_OPTIMIZE: { + + optimize_dialog->popup_centered(Size2(250,180)); + } break; + case TRACK_MENU_CLEAN_UP: { + + cleanup_dialog->popup_centered_minsize(Size2(300,0)); + } break; + case TRACK_MENU_CLEAN_UP_CONFIRM: { + + if (cleanup_all->is_pressed()) { + List names; + AnimationPlayerEditor::singleton->get_player()->get_animation_list(&names); + for (List::Element *E=names.front();E;E=E->next()) { + _cleanup_animation(AnimationPlayerEditor::singleton->get_player()->get_animation(E->get())); + } + } else { + _cleanup_animation(animation); + + } + } break; + case CURVE_SET_LINEAR: { + curve_edit->force_transition(1.0); + + } break; + case CURVE_SET_IN: { + + 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; + + } + +} + +void AnimationKeyEditor::_cleanup_animation(Ref p_animation) { + + + for(int i=0;iget_track_count();i++) { + + bool prop_exists=false; + Variant::Type valid_type=Variant::NIL; + Object *obj=NULL; + + RES res; + Node *node = root->get_node_and_resource(p_animation->track_get_path(i),res); + + if (res.is_valid()) { + obj=res.ptr(); + } else if (node) { + obj=node; + } + + 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); + } + + if (!obj && cleanup_tracks->is_pressed()) { + + p_animation->remove_track(i); + i--; + continue; + } + + if (!prop_exists || p_animation->track_get_type(i)!=Animation::TYPE_VALUE || cleanup_keys->is_pressed()==false) + continue; + + for(int j=0;jtrack_get_key_count(i);j++) { + + Variant v = p_animation->track_get_key_value(i,j); + + if (!Variant::can_convert(v.get_type(),valid_type)) { + p_animation->track_remove_key(i,j); + j--; + } + } + + if (p_animation->track_get_key_count(i)==0 && cleanup_tracks->is_pressed()) { + p_animation->remove_track(i); + i--; + } + } + + undo_redo->clear_history(); + _update_paths(); +} + +void AnimationKeyEditor::_animation_optimize() { + + + + animation->optimize(optimize_linear_error->get_value(),optimize_angular_error->get_value(),optimize_max_angle->get_value()); + track_editor->update(); + undo_redo->clear_history(); + +} + + +float AnimationKeyEditor::_get_zoom_scale() const { + + float zv = zoom->get_value(); + if (zv<1) { + zv = 1.0-zv; + return Math::pow(1.0f+zv,8.0f)*100; + } else { + return 1.0/Math::pow(zv,8.0f)*100; + } +} + +void AnimationKeyEditor::_track_pos_draw() { + + if (!animation.is_valid()) { + return; + } + + + Ref style = get_stylebox("normal","TextEdit"); + Size2 size= track_editor->get_size() - style->get_minimum_size(); + Size2 ofs = style->get_offset(); + + int settings_limit = size.width - right_data_size_cache; + int name_limit = settings_limit * name_column_ratio; + + float keys_from= h_scroll->get_value(); + float zoom_scale = _get_zoom_scale(); + float keys_to=keys_from+(settings_limit-name_limit) / zoom_scale; + + + + //will move to separate control! (for speedup) + if (timeline_pos >= keys_from && timeline_posget_value()) * zoom_scale; + pixel+=name_limit; + track_pos->draw_line(ofs+Point2(pixel,0),ofs+Point2(pixel,size.height),Color(1,0.3,0.3,0.8)); + + } +} + +void AnimationKeyEditor::_track_editor_draw() { + + + if (animation.is_valid() && animation->get_track_count()) { + if (selected_track < 0) + selected_track=0; + else if (selected_track>=animation->get_track_count()) + selected_track=animation->get_track_count()-1; + } + + track_pos->update(); + Control *te=track_editor; + Ref style = get_stylebox("normal","TextEdit"); + te->draw_style_box(style,Rect2(Point2(),track_editor->get_size())); + + if (te->has_focus()) { + te->draw_style_box(get_stylebox("bg_focus","Tree"),Rect2(Point2(),track_editor->get_size())); + } + + if (!animation.is_valid()) { + v_scroll->hide(); + h_scroll->hide(); + menu_add_track->set_disabled(true); + menu_track->set_disabled(true); + edit_button->set_disabled(true); + key_editor_tab->hide(); + move_up_button->set_disabled(true); + move_down_button->set_disabled(true); + remove_button->set_disabled(true); + + return; + } + + menu_add_track->set_disabled(false); + 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); + if (edit_button->is_pressed()) + key_editor_tab->show(); + + te_drawing=true; + + Size2 size= te->get_size() - style->get_minimum_size(); + Size2 ofs = style->get_offset(); + + Ref 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"); + Color sepcolor = get_color("guide_color","Tree"); + Color timecolor = get_color("prop_subsection","Editor"); + timecolor = Color::html("ff4a414f"); + Color hover_color = Color(1,1,1,0.05); + Color select_color = Color(1,1,1,0.1); + Color invalid_path_color = Color(1,0.6,0.4,0.5); + Color track_select_color =Color::html("ffbd8e8e"); + + Ref remove_icon = get_icon("Remove","EditorIcons"); + Ref move_up_icon = get_icon("MoveUp","EditorIcons"); + Ref move_down_icon = get_icon("MoveDown","EditorIcons"); + Ref remove_icon_hl = get_icon("RemoveHl","EditorIcons"); + Ref move_up_icon_hl = get_icon("MoveUpHl","EditorIcons"); + Ref move_down_icon_hl = get_icon("MoveDownHl","EditorIcons"); + Ref add_key_icon = get_icon("TrackAddKey","EditorIcons"); + Ref add_key_icon_hl = get_icon("TrackAddKeyHl","EditorIcons"); + Ref down_icon = get_icon("select_arrow","Tree"); + + Ref wrap_icon[2]={ + get_icon("InterpWrapClamp","EditorIcons"), + get_icon("InterpWrapLoop","EditorIcons"), + }; + + Ref interp_icon[3]={ + get_icon("InterpRaw","EditorIcons"), + get_icon("InterpLinear","EditorIcons"), + get_icon("InterpCubic","EditorIcons") + }; + Ref cont_icon[3]={ + get_icon("TrackContinuous","EditorIcons"), + get_icon("TrackDiscrete","EditorIcons"), + get_icon("TrackTrigger","EditorIcons") + }; + Ref type_icon[3]={ + get_icon("KeyValue","EditorIcons"), + get_icon("KeyXform","EditorIcons"), + get_icon("KeyCall","EditorIcons") + }; + + Ref invalid_icon = get_icon("KeyInvalid","EditorIcons"); + Ref invalid_icon_hover = get_icon("KeyInvalidHover","EditorIcons"); + + Ref hsize_icon = get_icon("Hsize","EditorIcons"); + + Ref type_hover=get_icon("KeyHover","EditorIcons"); + Ref type_selected=get_icon("KeySelected","EditorIcons"); + + 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; + + int h = font->get_height()+sep; + + + int fit = (size.height / h)-1; + int total = animation->get_track_count(); + if (total < fit) { + v_scroll->hide(); + v_scroll->set_max( total ); + v_scroll->set_page( fit ); + } else { + v_scroll->show(); + v_scroll->set_max( total ); + v_scroll->set_page( fit ); + } + + + int settings_limit = size.width - right_separator_ofs; + int name_limit = settings_limit * name_column_ratio; + + te->draw_line(ofs+Point2(name_limit,0),ofs+Point2(name_limit,size.height),color); + te->draw_line(ofs+Point2(settings_limit,0),ofs+Point2(settings_limit,size.height),color); + te->draw_texture(hsize_icon,ofs+Point2(name_limit-hsize_icon->get_width()-hsep,(h-hsize_icon->get_height())/2)); + + te->draw_line(ofs+Point2(0,h),ofs+Point2(size.width,h),color); + // draw time + + float keys_from; + float keys_to; + float zoom_scale; + + + { + + int zoomw = settings_limit-name_limit; + + + float scale = _get_zoom_scale(); + zoom_scale=scale; + + + float l = animation->get_length(); + if (l<=0) + l=0.001; //avoid crashor + + int end_px = (l - h_scroll->get_value()) * scale; + int begin_px = -h_scroll->get_value() * scale; + Color notimecol; + notimecol.r=timecolor.gray(); + notimecol.g=notimecol.r; + notimecol.b=notimecol.r; + notimecol.a=timecolor.a; + + { + + te->draw_rect(Rect2( ofs + Point2(name_limit,0), Point2(zoomw-1,h)), notimecol); + + + if (begin_px < zoomw && end_px >0) { + + if (begin_px<0) + begin_px=0; + if (end_px>zoomw) + end_px=zoomw; + + te->draw_rect(Rect2( ofs + Point2(name_limit+begin_px,0), Point2(end_px-begin_px-1,h)), timecolor); + } + + } + + + + keys_from= h_scroll->get_value(); + keys_to=keys_from+zoomw / scale; + + { + float time_min=0; + float time_max=animation->get_length(); + for(int i=0;iget_track_count();i++) { + + if (animation->track_get_key_count(i)>0) { + + float beg = animation->track_get_key_time(i,0); + if (begtrack_get_key_time(i,animation->track_get_key_count(i)-1); + if (end>time_max) + time_max=end; + } + } + + + + + + float extra = (zoomw / scale)*0.5; + + if (time_min<-0.001) + time_min-=extra; + time_max+=extra; + h_scroll->set_min(time_min); + h_scroll->set_max(time_max); + + if (zoomw / scale < (time_max-time_min)) { + h_scroll->show(); + + } else { + + h_scroll->hide(); + } + + + } + + h_scroll->set_page(zoomw / scale); + + Color color_time_sec = color; + Color color_time_dec = color; + color_time_dec.a*=0.5; +#define SC_ADJ 100 + int min=30; + int dec=1; + int step=1; + int decimals=2; + bool step_found=false; + + while(!step_found) { + + static const int _multp[3]={1,2,5}; + for(int i=0;i<3;i++) { + + step = (_multp[i] * dec); + if (step*scale/SC_ADJ> min) { + step_found=true; + break; + } + + } + if (step_found) + break; + dec*=10; + decimals--; + if (decimals<0) + decimals=0; + } + + + for(int i=0;iget_value() + double(i)/scale; + float prev = h_scroll->get_value() + (double(i)-1.0)/scale; + + + int sc = int(Math::floor(pos*SC_ADJ)); + int prev_sc = int(Math::floor(prev*SC_ADJ)); + bool sub = (sc % SC_ADJ); + + if ((sc/step)!=(prev_sc/step) || (prev_sc<0 && sc>=0)) { + + int scd = sc < 0 ? prev_sc : sc; + te->draw_line( ofs + Point2(name_limit+i,0), ofs+Point2(name_limit+i,h), color); + 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); + } + + + } + } + + color.a*=0.5; + + for(int i=0;iget_value() + i; + if (idx>=animation->get_track_count()) + break; + int y = h+i*h+sep; + + bool prop_exists=false; + Variant::Type valid_type=Variant::NIL; + Object *obj=NULL; + + RES res; + Node *node = root->get_node_and_resource(animation->track_get_path(idx),res); + + if (res.is_valid()) { + obj=res.ptr(); + } else if (node) { + obj=node; + } + + 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); + } + + + 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); + } + + if (selected_track==idx) { + Color tc = select_color; + //tc.a*=0.7; + te->draw_rect(Rect2(ofs+Point2(0,y),Size2(size.width-1,h-1)),tc); + } + + te->draw_texture(type_icon[animation->track_get_type(idx)],ofs+Point2(0,y+(h-type_icon[0]->get_height())/2).floor()); + NodePath np = animation->track_get_path(idx); + Node *n = root->get_node(np); + Color ncol = color; + if (n && editor_selection->is_selected(n)) + 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); + + if (!obj) + te->draw_line(ofs+Point2(0,y+h/2),ofs+Point2(name_limit,y+h/2),invalid_path_color); + + te->draw_line(ofs+Point2(0,y+h),ofs+Point2(size.width,y+h),sepcolor); + + Point2 icon_ofs = ofs + Point2( size.width, y + (h - remove_icon->get_height() )/2).floor(); + icon_ofs.y+=4; + + +/* icon_ofs.x-=remove_icon->get_width(); + + 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; + */ + track_ofs[0]=size.width-icon_ofs.x; + icon_ofs.x-=down_icon->get_width(); + te->draw_texture(down_icon,icon_ofs); + + 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); + + icon_ofs.x-=hsep; + te->draw_line(Point2(icon_ofs.x,ofs.y+y),Point2(icon_ofs.x,ofs.y+y+h),sepcolor); + + track_ofs[1]=size.width-icon_ofs.x; + + icon_ofs.x-=down_icon->get_width(); + te->draw_texture(down_icon,icon_ofs); + + int interp_type = animation->track_get_interpolation_type(idx); + 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); + + icon_ofs.x-=hsep; + te->draw_line(Point2(icon_ofs.x,ofs.y+y),Point2(icon_ofs.x,ofs.y+y+h),sepcolor); + + track_ofs[2]=size.width-icon_ofs.x; + + if (animation->track_get_type(idx)==Animation::TYPE_VALUE) { + + + int umode = animation->value_track_get_update_mode(idx); + + icon_ofs.x-=hsep; + icon_ofs.x-=down_icon->get_width(); + te->draw_texture(down_icon,icon_ofs); + + icon_ofs.x-=hsep; + icon_ofs.x-=cont_icon[umode]->get_width(); + te->draw_texture(cont_icon[umode],icon_ofs); + } else { + + icon_ofs.x -= hsep*2 + cont_icon[0]->get_width() + down_icon->get_width(); + } + + icon_ofs.x-=hsep; + te->draw_line(Point2(icon_ofs.x,ofs.y+y),Point2(icon_ofs.x,ofs.y+y+h),sepcolor); + + track_ofs[3]=size.width-icon_ofs.x; + + 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); + + track_ofs[4]=size.width-icon_ofs.x; + + //draw the keys; + int tt = animation->track_get_type(idx); + 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); + + int kc=animation->track_get_key_count(idx); + bool first=true; + + + + for(int i=0;itrack_get_key_time(idx,i); + if (timekeys_to) { + + if (first && i>0 && animation->track_get_key_value(idx,i)==animation->track_get_key_value(idx,i-1)) { + //draw whole line + te->draw_line(ofs+Vector2(name_limit,y+h/2),ofs+Point2(settings_limit,y+h/2),color); + } + + break; + } + + float x = key_hofs + name_limit + (time-keys_from)*zoom_scale; + + Ref tex = type_icon[tt]; + + SelectedKey sk; + sk.key=i; + sk.track=idx; + if (selection.has(sk)) { + + if (click.click==ClickOver::CLICK_MOVE_KEYS) + continue; + tex=type_selected; + } + + if (mouse_over.over==MouseOver::OVER_KEY && mouse_over.track==idx && mouse_over.over_key==i) + tex=type_hover; + + Variant value = animation->track_get_key_value(idx,i); + if (first && i>0 && value==animation->track_get_key_value(idx,i-1)) { + + te->draw_line(ofs+Vector2(name_limit,y+h/2),ofs+Point2(x,y+h/2),color); + } + + if (itrack_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; + + x_n = MIN( x_n, settings_limit); + te->draw_line(ofs+Point2(x_n,y+h/2),ofs+Point2(x,y+h/2),color); + + } + + if (prop_exists && !Variant::can_convert(value.get_type(),valid_type)) { + te->draw_texture(invalid_icon,ofs+Point2(x,y+key_vofs).floor()); + } + + 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()); + else + te->draw_texture(invalid_icon,ofs+Point2(x,y+key_vofs).floor()); + } else { + + te->draw_texture(tex,ofs+Point2(x,y+key_vofs).floor()); + } + + + first=false; + } + + } + + switch(click.click) { + case ClickOver::CLICK_SELECT_KEYS: { + + te->draw_rect(Rect2(click.at,click.to-click.at),Color(0.7,0.7,1.0,0.5)); + + } break; + case ClickOver::CLICK_MOVE_KEYS: { + + float from_t = 1e20; + + for(Map::Element *E=selection.front();E;E=E->next()) { + float t = animation->track_get_key_time(E->key().track,E->key().key); + if (tget_value()) + motion = Math::stepify(motion,step->get_value()); + + for(Map::Element *E=selection.front();E;E=E->next()) { + + + int idx = E->key().track; + int i = idx-v_scroll->get_value(); + if (i<0 || i>=fit) + continue; + int y = h+i*h+sep; + + float key_vofs = Math::floor((float)(h - type_selected->get_height())/2); + float key_hofs = -Math::floor((float)type_selected->get_height()/2); + + float time = animation->track_get_key_time(idx,E->key().key); + float diff = time-from_t; + + float t = motion + diff; + + float x = (t-keys_from)*zoom_scale; + //x+=click.to.x - click.at.x; + if (x<0 || x>=(settings_limit-name_limit)) + continue; + + x+=name_limit; + + te->draw_texture(type_selected,ofs+Point2(x+key_hofs,y+key_vofs).floor()); + + } + } break; + default: {}; + } + + + te_drawing=false; +} + +void AnimationKeyEditor::_track_name_changed(const String& p_name) { + + ERR_FAIL_COND(!animation.is_valid()); + undo_redo->create_action(TTR("Anim Track Rename")); + 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)); + undo_redo->commit_action(); + track_name->hide(); + +} + +void AnimationKeyEditor::_track_menu_selected(int p_idx) { + + + ERR_FAIL_COND(!animation.is_valid()); + + if (interp_editing!=-1) { + + ERR_FAIL_INDEX(interp_editing,animation->get_track_count()); + undo_redo->create_action(TTR("Anim Track Change Interpolation")); + 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)); + undo_redo->commit_action(); + } else if (cont_editing!=-1) { + + ERR_FAIL_INDEX(cont_editing,animation->get_track_count()); + + undo_redo->create_action(TTR("Anim Track Change Value Mode")); + 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)); + undo_redo->commit_action(); + } else if (wrap_editing!=-1) { + + ERR_FAIL_INDEX(wrap_editing,animation->get_track_count()); + + undo_redo->create_action(TTR("Anim Track Change Wrap Mode")); + 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)); + undo_redo->commit_action(); + } else { + switch (p_idx) { + + case RIGHT_MENU_DUPLICATE: + _anim_duplicate_keys(); break; + case RIGHT_MENU_DUPLICATE_TRANSPOSE: + _anim_duplicate_keys(true); break; + case RIGHT_MENU_REMOVE: + _anim_delete_keys(); break; + } + } + +} + +struct _AnimMoveRestore { + + int track; + float time; + Variant key; + float transition; +}; + +void AnimationKeyEditor::_clear_selection_for_anim(const Ref& p_anim) { + + if (!(animation==p_anim)) + return; + //selection.clear(); + _clear_selection(); + +} + +void AnimationKeyEditor::_select_at_anim(const Ref& p_anim,int p_track,float p_pos){ + + if (!(animation==p_anim)) + return; + + int idx = animation->track_find_key(p_track,p_pos,true); + ERR_FAIL_COND(idx<0); + + SelectedKey sk; + sk.track=p_track; + sk.key=idx; + KeyInfo ki; + ki.pos=p_pos; + + selection.insert(sk,ki); + +} + + +PropertyInfo AnimationKeyEditor::_find_hint_for_track(int p_idx,NodePath& r_base_path) { + + r_base_path=NodePath(); + ERR_FAIL_COND_V(!animation.is_valid(),PropertyInfo()); + ERR_FAIL_INDEX_V(p_idx,animation->get_track_count(),PropertyInfo()); + + if (!root) + return PropertyInfo(); + + NodePath path = animation->track_get_path(p_idx); + + + if (!root->has_node_and_resource(path)) + return PropertyInfo(); + + RES res; + Node *node = root->get_node_and_resource(path,res); + + + if (node) { + r_base_path=node->get_path(); + } + + String property = path.get_property(); + if (property=="") + return PropertyInfo(); + + List pinfo; + if (res.is_valid()) + res->get_property_list(&pinfo); + else + node->get_property_list(&pinfo); + + for(List::Element *E=pinfo.front();E;E=E->next()) { + + if (E->get().name==property) + return E->get(); + } + + return PropertyInfo(); +} + + +void AnimationKeyEditor::_curve_transition_changed(float p_what) { + + if (selection.size()==0) + return; + if (selection.size()==1) + undo_redo->create_action(TTR("Edit Node Curve"),UndoRedo::MERGE_ENDS); + else + undo_redo->create_action(TTR("Edit Selection Curve"),UndoRedo::MERGE_ENDS); + + for(Map::Element *E=selection.front();E;E=E->next()) { + + int track = E->key().track; + int key = E->key().key; + 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); + } + + 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() { + + if (selection.size()!=1) { + + if (selection.size()==0) { + curve_edit->set_mode(AnimationCurveEdit::MODE_DISABLED); + //print_line("disable"); + } else { + + curve_edit->set_mode(AnimationCurveEdit::MODE_MULTIPLE); + curve_edit->set_transition(1.0); + curve_edit->clear_multiples(); + //add all + for(Map::Element *E=selection.front();E;E=E->next()) { + + curve_edit->set_multiple(animation->track_get_key_transition(E->key().track,E->key().key)); + } + //print_line("multiple"); + + } + return false; + } + curve_edit->set_mode(AnimationCurveEdit::MODE_SINGLE); + //print_line("regular"); + + int idx = selection.front()->key().track; + int key = selection.front()->key().key; + { + + 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); + key_edit->notify_change(); + + curve_edit->set_transition(animation->track_get_key_transition(idx,key)); + + /*key_edit_dialog->set_size( Size2( 200,200) ); + key_edit_dialog->set_pos( track_editor->get_global_pos() + ofs + mpos +Point2(-100,20)); + key_edit_dialog->popup();*/ + + } + + return true; + +} + +void AnimationKeyEditor::_anim_delete_keys() { + if (selection.size()) { + undo_redo->create_action(TTR("Anim Delete Keys")); + + for(Map::Element *E=selection.back();E;E=E->prev()) { + + 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)); + + } + undo_redo->add_do_method(this,"_clear_selection_for_anim",animation); + undo_redo->add_undo_method(this,"_clear_selection_for_anim",animation); + undo_redo->commit_action(); + //selection.clear(); + accept_event(); + _edit_if_single_selection(); + } +} + +void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { + + Control *te=track_editor; + Ref style = get_stylebox("normal","TextEdit"); + + if (!animation.is_valid()) { + return; + } + + Size2 size= te->get_size() - style->get_minimum_size(); + Size2 ofs = style->get_offset(); + + Ref font = te->get_font("font","Tree"); + int sep = get_constant("vseparation","Tree"); + int hsep = get_constant("hseparation","Tree"); + Ref remove_icon = get_icon("Remove","EditorIcons"); + Ref move_up_icon = get_icon("MoveUp","EditorIcons"); + Ref move_down_icon = get_icon("MoveDown","EditorIcons"); + Ref down_icon = get_icon("select_arrow","Tree"); + Ref hsize_icon = get_icon("Hsize","EditorIcons"); + Ref add_key_icon = get_icon("TrackAddKey","EditorIcons"); + + Ref wrap_icon[2]={ + get_icon("InterpWrapClamp","EditorIcons"), + get_icon("InterpWrapLoop","EditorIcons"), + }; + Ref interp_icon[3]={ + get_icon("InterpRaw","EditorIcons"), + get_icon("InterpLinear","EditorIcons"), + get_icon("InterpCubic","EditorIcons") + }; + Ref cont_icon[3]={ + get_icon("TrackContinuous","EditorIcons"), + get_icon("TrackDiscrete","EditorIcons"), + get_icon("TrackTrigger","EditorIcons") + }; + Ref type_icon[3]={ + get_icon("KeyValue","EditorIcons"), + get_icon("KeyXform","EditorIcons"), + get_icon("KeyCall","EditorIcons") + }; + 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; + + int h = font->get_height()+sep; + + int fit = (size.height / h)-1; + int total = animation->get_track_count(); + if (total < fit) { + v_scroll->hide(); + } else { + v_scroll->show(); + v_scroll->set_max( total ); + v_scroll->set_page( fit ); + } + + int settings_limit = size.width - right_separator_ofs; + int name_limit = settings_limit * name_column_ratio; + + + switch(p_input.type) { + + case InputEvent::KEY: { + + if (p_input.key.scancode==KEY_D && p_input.key.pressed && p_input.key.mod.command) { + + if (p_input.key.mod.shift) + _menu_track(TRACK_MENU_DUPLICATE_TRANSPOSE); + else + _menu_track(TRACK_MENU_DUPLICATE); + + accept_event(); + + } else if (p_input.key.scancode==KEY_DELETE && p_input.key.pressed && click.click==ClickOver::CLICK_NONE) { + + _anim_delete_keys(); + } else if (animation.is_valid() && animation->get_track_count()>0) { + + if (p_input.is_pressed() && (p_input.is_action("ui_up") || p_input.is_action("ui_page_up"))) { + + if (p_input.is_action("ui_up")) + selected_track--; + if (v_scroll->is_visible_in_tree() && p_input.is_action("ui_page_up")) + selected_track--; + + if (selected_track<0) + selected_track=0; + + + if (v_scroll->is_visible_in_tree()) { + if (v_scroll->get_value() > selected_track) + v_scroll->set_value(selected_track); + + } + + track_editor->update(); + accept_event(); + + } + + if (p_input.is_pressed() && (p_input.is_action("ui_down") || p_input.is_action("ui_page_down"))) { + + if (p_input.is_action("ui_down")) + selected_track++; + else if (v_scroll->is_visible_in_tree() && p_input.is_action("ui_page_down")) + selected_track+=v_scroll->get_page(); + + if (selected_track >= animation->get_track_count()) + selected_track=animation->get_track_count()-1; + + 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); + } + + track_editor->update(); + accept_event(); + } + } + + + } break; + case InputEvent::MOUSE_BUTTON: { + + const InputEventMouseButton &mb = p_input.mouse_button; + + if (mb.button_index==BUTTON_WHEEL_UP && mb.pressed) { + + if (mb.mod.command) { + zoom->set_value(zoom->get_value() + zoom->get_step()); + } else { + v_scroll->set_value( v_scroll->get_value() - v_scroll->get_page() / 8 ); + } + } + + if (mb.button_index==BUTTON_WHEEL_DOWN && mb.pressed) { + + if (mb.mod.command) { + zoom->set_value(zoom->get_value() - zoom->get_step()); + } else { + v_scroll->set_value( v_scroll->get_value() + v_scroll->get_page() / 8 ); + } + } + + if (mb.button_index==BUTTON_RIGHT && mb.pressed) { + + Point2 mpos = Point2(mb.x,mb.y)-ofs; + + 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. + Point2 mpos = Point2(mb.x,mb.y)-ofs; + + if (mpos.y < h ) { + return; + } + + mpos.y -= h; + + int idx = mpos.y / h; + idx+=v_scroll->get_value(); + if (idx <0 || idx>=animation->get_track_count()) + break; + + 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; + + int kidx = animation->track_find_key(idx,pos); + int kidx_n = kidx+1; + int key=-1; + + if (kidx>=0 && kidxtrack_get_key_count(idx)) { + + float kpos = animation->track_get_key_time(idx,kidx); + if (ABS(pos-kpos)<=w_time) { + + key=kidx; + } + } + + if (key==-1 && kidx_n>=0 && kidx_ntrack_get_key_count(idx)) { + + float kpos = animation->track_get_key_time(idx,kidx_n); + if (ABS(pos-kpos)<=w_time) { + + key=kidx_n; + } + } + + if (key==-1) { + + click.click=ClickOver::CLICK_SELECT_KEYS; + click.at=Point2(mb.x,mb.y); + click.to=click.at; + click.shift=mb.mod.shift; + selected_track=idx; + track_editor->update(); + //drag select region + return; + + } + + + + SelectedKey sk; + sk.track=idx; + sk.key=key; + KeyInfo ki; + ki.pos= animation->track_get_key_time(idx,key); + click.shift=mb.mod.shift; + click.selk=sk; + + + if (!mb.mod.shift && !selection.has(sk)) + _clear_selection(); + + selection.insert(sk,ki); + + click.click=ClickOver::CLICK_MOVE_KEYS; + click.at=Point2(mb.x,mb.y); + click.to=click.at; + update(); + selected_track=idx; + track_editor->update(); + + if (_edit_if_single_selection() && mb.mod.command) { + edit_button->set_pressed(true); + key_editor_tab->show(); + } + } + } + + 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); + + track_menu->set_pos(te->get_global_pos()+mpos); + + interp_editing=-1; + cont_editing=-1; + wrap_editing=-1; + + track_menu->popup(); + } + } + + if (mb.button_index==BUTTON_LEFT && !(mb.button_mask&~BUTTON_MASK_LEFT)) { + + + if (mb.pressed) { + + Point2 mpos = Point2(mb.x,mb.y)-ofs; + + if (mpos.y < h ) { + + + if (mpos.x (name_limit - hsep - hsize_icon->get_width())) { + + + click.click=ClickOver::CLICK_RESIZE_NAMES; + click.at=Point2(mb.x,mb.y); + click.to=click.at; + click.at.y=name_limit; + + } + + if (mpos.x>=name_limit && mpos.xget_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(); + timeline_pos=pos; + click.click=ClickOver::CLICK_DRAG_TIMELINE; + click.at=Point2(mb.x,mb.y); + click.to=click.at; + emit_signal("timeline_changed",pos,false); + + } + + return; + } + + mpos.y -= h; + + int idx = mpos.y / h; + idx+=v_scroll->get_value(); + if (idx <0) + break; + + if (idx>=animation->get_track_count()) { + + if (mpos.x >= name_limit && mpos.xupdate(); + break; + } + + Rect2 area(ofs.x,ofs.y+((int(mpos.y)/h)+1)*h,name_limit, h ); + track_name->set_text(animation->track_get_path(idx)); + track_name->set_pos( te->get_global_pos() + area.pos); + track_name->set_size(area.size); + track_name->show_modal(); + track_name->grab_focus(); + track_name->select_all(); + track_name_editing=idx; + + } 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; + + int kidx = animation->track_find_key(idx,pos); + int kidx_n = kidx+1; + int key=-1; + + if (kidx>=0 && kidxtrack_get_key_count(idx)) { + + float kpos = animation->track_get_key_time(idx,kidx); + if (ABS(pos-kpos)<=w_time) { + + key=kidx; + } + } + + if (key==-1 && kidx_n>=0 && kidx_ntrack_get_key_count(idx)) { + + float kpos = animation->track_get_key_time(idx,kidx_n); + if (ABS(pos-kpos)<=w_time) { + + key=kidx_n; + } + } + + if (key==-1) { + + click.click=ClickOver::CLICK_SELECT_KEYS; + click.at=Point2(mb.x,mb.y); + click.to=click.at; + click.shift=mb.mod.shift; + selected_track=idx; + track_editor->update(); + //drag select region + return; + + } + + + + SelectedKey sk; + sk.track=idx; + sk.key=key; + KeyInfo ki; + ki.pos= animation->track_get_key_time(idx,key); + click.shift=mb.mod.shift; + click.selk=sk; + + + if (!mb.mod.shift && !selection.has(sk)) + _clear_selection(); + + selection.insert(sk,ki); + + click.click=ClickOver::CLICK_MOVE_KEYS; + click.at=Point2(mb.x,mb.y); + click.to=click.at; + update(); + selected_track=idx; + track_editor->update(); + + if (_edit_if_single_selection() && mb.mod.command) { + edit_button->set_pressed(true); + key_editor_tab->show(); + } + } else { + //button column + int ofsx = size.width - mpos.x; + if (ofsx < 0) + break; +/* + if (ofsx < remove_icon->get_width()) { + + 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;itrack_get_key_count(idx);i++) { + + 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); + + 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); + + } + + 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)); + + } + + undo_redo->commit_action(); + + + return; + } + + ofsx-=hsep+remove_icon->get_width(); + + if (ofsx < move_down_icon->get_width()) { + + 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; + } + + ofsx-=hsep+move_down_icon->get_width(); + + 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; + } + + + ofsx-=hsep*3+move_up_icon->get_width(); + */ + + + if (ofsx < track_ofs[1]) { + + 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]); + } + + int popup_y = ofs.y+((int(mpos.y)/h)+2)*h; + int popup_x = size.width-track_ofs[1]; + + track_menu->set_pos(te->get_global_pos()+Point2(popup_x,popup_y)); + + + wrap_editing=idx; + interp_editing=-1; + cont_editing=-1; + + track_menu->popup(); + + return; + } + + + if (ofsx < track_ofs[2]) { + + 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]); + } + + int popup_y = ofs.y+((int(mpos.y)/h)+2)*h; + int popup_x = size.width-track_ofs[2]; + + track_menu->set_pos(te->get_global_pos()+Point2(popup_x,popup_y)); + + + interp_editing=idx; + cont_editing=-1; + wrap_editing=-1; + + track_menu->popup(); + + return; + } + + if (ofsx < track_ofs[3]) { + + 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]); + } + + + int popup_y = ofs.y+((int(mpos.y)/h)+2)*h; + int popup_x = size.width-track_ofs[3]; + + track_menu->set_pos(te->get_global_pos()+Point2(popup_x,popup_y)); + + interp_editing=-1; + wrap_editing=-1; + cont_editing=idx; + + track_menu->popup(); + + return; + } + + if (ofsx < track_ofs[4]) { + + Animation::TrackType tt = animation->track_get_type(idx); + + float pos = timeline_pos; + int existing = animation->track_find_key(idx,pos,true); + + + + Variant newval; + + if (tt==Animation::TYPE_TRANSFORM) { + Dictionary d; + d["loc"]=Vector3(); + d["rot"]=Quat(); + d["scale"]=Vector3(); + newval=d; + + } else if (tt==Animation::TYPE_METHOD) { + + Dictionary d; + d["method"]=""; + d["args"]=Vector(); + + + newval=d; + } else if (tt==Animation::TYPE_VALUE) { + + NodePath np; + PropertyInfo inf = _find_hint_for_track(idx,np); + if (inf.type!=Variant::NIL) { + + Variant::CallError err; + newval=Variant::construct(inf.type,NULL,0,err); + + } + + if (newval.get_type()==Variant::NIL) { + //popup a new type + cvi_track=idx; + cvi_pos=pos; + + type_menu->set_pos( get_global_pos() + mpos +ofs ); + type_menu->popup(); + return; + } + + } + + undo_redo->create_action(TTR("Anim Add Key")); + + undo_redo->add_do_method(animation.ptr(),"track_insert_key",idx,pos,newval,1); + undo_redo->add_undo_method(animation.ptr(),"track_remove_key_at_pos",idx,pos); + + 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); + } + + undo_redo->commit_action(); + + + return; + } + + } + + } else { + + switch(click.click) { + case ClickOver::CLICK_SELECT_KEYS: { + + + float zoom_scale=_get_zoom_scale(); + float keys_from = h_scroll->get_value(); + float keys_to = keys_from + (settings_limit-name_limit) / zoom_scale; + + 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; + + + if (to_time < from_time) + SWAP(from_time,to_time); + + if (from_time > keys_to || to_time < keys_from) + break; + + if (from_time < keys_from) + from_time = keys_from; + + if (to_time >= keys_to) + to_time = keys_to; + + + 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) { + + SWAP(from_track,to_track); + SWAP(from_mod,to_mod); + } + + + + + if ((from_mod > (h/2)) && ((click.at.y-ofs.y)>=(h+sep))) { + from_track++; + } + + 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()) + tracks_to=animation->get_track_count()-1; + + tracks_from=0; + tracks_to=animation->get_track_count()-1; + if (to_track >tracks_to) + to_track = tracks_to; + if (from_track tracks_to || to_track < tracks_from) { + if (!click.shift) + _clear_selection(); + _edit_if_single_selection(); + break; + } + + if (!click.shift) + _clear_selection(); + + + int higher_track=0x7FFFFFFF; + for(int i=from_track;i<=to_track;i++) { + + int kc=animation->track_get_key_count(i); + for(int j=0;jtrack_get_key_time(i,j); + if (tto_time) + break; + + if (iupdate(); + } + + + _edit_if_single_selection(); + + + } break; + case ClickOver::CLICK_MOVE_KEYS: { + + if (selection.empty()) + break; + if (click.at==click.to) { + + if (!click.shift) { + + KeyInfo ki=selection[click.selk]; + _clear_selection(); + selection[click.selk]=ki; + _edit_if_single_selection(); + } + + break; + } + + float from_t = 1e20; + + for(Map::Element *E=selection.front();E;E=E->next()) { + float t = animation->track_get_key_time(E->key().track,E->key().key); + if (tget_value()) + motion = Math::stepify(motion,step->get_value()); + + + + + undo_redo->create_action(TTR("Anim Move Keys")); + + List<_AnimMoveRestore> to_restore; + + // 1-remove the keys + for(Map::Element *E=selection.back();E;E=E->prev()) { + + undo_redo->add_do_method(animation.ptr(),"track_remove_key",E->key().track,E->key().key); + } + // 2- remove overlapped keys + for(Map::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 + + undo_redo->add_do_method(animation.ptr(),"track_remove_key_at_pos",E->key().track,newtime); + _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); + + } + + // 3-move the keys (re insert them) + for(Map::Element *E=selection.back();E;E=E->prev()) { + + float newpos=E->get().pos-from_t+motion; + /* + if (newpos<0) + continue; //no add at the begining + */ + 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)); + + } + + // 4-(undo) remove inserted keys + for(Map::Element *E=selection.back();E;E=E->prev()) { + + float newpos=E->get().pos+-from_t+motion; + /* + if (newpos<0) + continue; //no remove what no inserted + */ + undo_redo->add_undo_method(animation.ptr(),"track_remove_key_at_pos",E->key().track,newpos); + + } + + // 5-(undo) reinsert keys + for(Map::Element *E=selection.back();E;E=E->prev()) { + + 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)); + + } + + // 6-(undo) reinsert overlapped keys + for(List<_AnimMoveRestore>::Element *E=to_restore.front();E;E=E->next()) { + + _AnimMoveRestore &amr = E->get(); + undo_redo->add_undo_method(animation.ptr(),"track_insert_key",amr.track,amr.time,amr.key,amr.transition); + + } + + // 6-(undo) reinsert overlapped keys + for(List<_AnimMoveRestore>::Element *E=to_restore.front();E;E=E->next()) { + + _AnimMoveRestore &amr = E->get(); + undo_redo->add_undo_method(animation.ptr(),"track_insert_key",amr.track,amr.time,amr.key,amr.transition); + + } + + undo_redo->add_do_method(this,"_clear_selection_for_anim",animation); + undo_redo->add_undo_method(this,"_clear_selection_for_anim",animation); + + // 7-reselect + + for(Map::Element *E=selection.back();E;E=E->prev()) { + + 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); + + } + + undo_redo->commit_action(); + _edit_if_single_selection(); + + } break; + default: {} + } + + //button released + click.click=ClickOver::CLICK_NONE; + track_editor->update(); + + + } + } + + } break; + + case InputEvent::MOUSE_MOTION: { + + const InputEventMouseMotion &mb = p_input.mouse_motion; + + mouse_over.over=MouseOver::OVER_NONE; + mouse_over.track=-1; + te->update(); + track_editor->set_tooltip(""); + + if (!track_editor->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) + track_editor->call_deferred("grab_focus"); + + + if (click.click!=ClickOver::CLICK_NONE) { + + switch(click.click) { + case ClickOver::CLICK_RESIZE_NAMES: { + + + float base = click.at.y; + float clickp = click.at.x-ofs.x; + float dif = base - clickp; + + float target = mb.x+dif-ofs.x; + + float ratio = target / settings_limit; + + if (ratio>0.9) + ratio=0.9; + else if (ratio<0.2) + ratio=0.2; + + name_column_ratio=ratio; + + + } break; + case ClickOver::CLICK_DRAG_TIMELINE: { + + Point2 mpos = Point2(mb.x,mb.y)-ofs; + /* + if (mpos.xsettings_limit) + mpos.x=settings_limit; + */ + + + //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 ); + } + + timeline_pos=pos; + emit_signal("timeline_changed",pos,true); + + + + } break; + case ClickOver::CLICK_SELECT_KEYS: { + + click.to=Point2(mb.x,mb.y); + if (click.to.yh && mb.relative_y<0) { + + 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.y0) { + + 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; + } + + } break; + case ClickOver::CLICK_MOVE_KEYS: { + + click.to=Point2(mb.x,mb.y); + } break; + default: {} + } + + return; + } else if (mb.button_mask&BUTTON_MASK_MIDDLE) { + + int rel = mb.relative_x; + float relf = rel / _get_zoom_scale(); + h_scroll->set_value( h_scroll->get_value() - relf ); + } + + if (mb.button_mask==0) { + + + Point2 mpos = Point2(mb.x,mb.y)-ofs; + + if (mpos.y < h ) { +#if 0 + //seek + //int zoomw = settings_limit-name_limit; + float scale = _get_zoom_scale(); + float pos = h_scroll->get_val() + (mpos.y-name_limit) / scale; + if (pos<0 ) + pos=0; + if (pos>=animation->get_length()) + pos=animation->get_length(); + timeline->set_val(pos); +#endif + return; + } + + mpos.y -= h; + + int idx = mpos.y / h; + idx+=v_scroll->get_value(); + if (idx <0 || idx>=animation->get_track_count()) + break; + + mouse_over.track=idx; + + if (mpos.x < name_limit) { + //name column + + + mouse_over.over=MouseOver::OVER_NAME; + + } 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; + + int kidx = animation->track_find_key(idx,pos); + int kidx_n = kidx+1; + + bool found = false; + + if (kidx>=0 && kidxtrack_get_key_count(idx)) { + + float kpos = animation->track_get_key_time(idx,kidx); + if (ABS(pos-kpos)<=w_time) { + + mouse_over.over=MouseOver::OVER_KEY; + mouse_over.track=idx; + mouse_over.over_key=kidx; + found=true; + } + } + + if (!found && kidx_n>=0 && kidx_ntrack_get_key_count(idx)) { + + float kpos = animation->track_get_key_time(idx,kidx_n); + if (ABS(pos-kpos)<=w_time) { + + mouse_over.over=MouseOver::OVER_KEY; + mouse_over.track=idx; + mouse_over.over_key=kidx_n; + found=true; + } + } + + + if (found) { + + String text; + text="time: "+rtos(animation->track_get_key_time(idx,mouse_over.over_key))+"\n"; + + + switch(animation->track_get_type(idx)) { + + case Animation::TYPE_TRANSFORM: { + + Dictionary d = animation->track_get_key_value(idx,mouse_over.over_key); + if (d.has("loc")) + text+="loc: "+String(d["loc"])+"\n"; + if (d.has("rot")) + text+="rot: "+String(d["rot"])+"\n"; + if (d.has("scale")) + text+="scale: "+String(d["scale"])+"\n"; + } break; + case Animation::TYPE_VALUE: { + + Variant v = animation->track_get_key_value(idx,mouse_over.over_key); + //text+="value: "+String(v)+"\n"; + + bool prop_exists=false; + Variant::Type valid_type=Variant::NIL; + Object *obj=NULL; + + RES res; + Node *node = root->get_node_and_resource(animation->track_get_path(idx),res); + + if (res.is_valid()) { + obj=res.ptr(); + } else if (node) { + obj=node; + } + + if (obj) { + valid_type=obj->get_static_property_type(animation->track_get_path(idx).get_property(),&prop_exists); + } + + 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 args; + if (d.has("args")) + args=d["args"]; + for(int i=0;i0) + text+=", "; + text+=String(args[i]); + } + text+=")\n"; + + } break; + } + text+="easing: "+rtos(animation->track_get_key_transition(idx,mouse_over.over_key)); + + + + track_editor->set_tooltip(text); + return; + + } + + } else { + //button column + int ofsx = size.width - mpos.x; + if (ofsx < 0) + break; +/* + if (ofsx < remove_icon->get_width()) { + + mouse_over.over=MouseOver::OVER_REMOVE; + + return; + } + + ofsx-=hsep+remove_icon->get_width(); + + if (ofsx < move_down_icon->get_width()) { + + mouse_over.over=MouseOver::OVER_DOWN; + return; + } + + ofsx-=hsep+move_down_icon->get_width(); + + if (ofsx < move_up_icon->get_width()) { + + mouse_over.over=MouseOver::OVER_UP; + return; + } + + ofsx-=hsep*3+move_up_icon->get_width(); + + */ + + if (ofsx < down_icon->get_width() + wrap_icon[0]->get_width() + hsep*3) { + + mouse_over.over=MouseOver::OVER_WRAP; + return; + } + + ofsx-=hsep*3+wrap_icon[0]->get_width() + down_icon->get_width(); + + if (ofsx < down_icon->get_width() + interp_icon[0]->get_width() + hsep*3) { + + mouse_over.over=MouseOver::OVER_INTERP; + return; + } + + + 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; + } + + + } + + } + + } break; + + } +} + +void AnimationKeyEditor::_notification(int p_what) { + + + switch(p_what) { + case NOTIFICATION_VISIBILITY_CHANGED: { + + EditorNode::get_singleton()->update_keying(); + emit_signal("keying_changed"); + } break; + + case NOTIFICATION_ENTER_TREE: { + + key_editor->edit(key_edit); + + zoomicon->set_texture( get_icon("Zoom","EditorIcons") ); + + menu_add_track->set_icon(get_icon("AddTrack","EditorIcons")); + 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); + + 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); + //menu_track->get_popup()->add_submenu_item("Set Transitions..","Transitions"); + //menu_track->get_popup()->add_separator(); + 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->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")); + + 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)); + + + 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")); + edit_button->connect("pressed",this,"_toggle_edit_curves"); + + loop->set_icon(get_icon("Loop","EditorIcons")); + curve_edit->connect("transition_changed",this,"_curve_transition_changed"); + + //edit_button->add_color_override("font_color",get_color("font_color","Tree")); + //edit_button->add_color_override("font_color_hover",get_color("font_color","Tree")); + + { + + right_data_size_cache=0; + int hsep = get_constant("hseparation","Tree"); + Ref remove_icon = get_icon("Remove","EditorIcons"); + Ref move_up_icon = get_icon("MoveUp","EditorIcons"); + Ref move_down_icon = get_icon("MoveDown","EditorIcons"); + Ref down_icon = get_icon("select_arrow","Tree"); + Ref add_key_icon = get_icon("TrackAddKey","EditorIcons"); + Ref interp_icon[3]={ + get_icon("InterpRaw","EditorIcons"), + get_icon("InterpLinear","EditorIcons"), + get_icon("InterpCubic","EditorIcons") + }; + Ref cont_icon[3]={ + get_icon("TrackContinuous","EditorIcons"), + get_icon("TrackDiscrete","EditorIcons"), + get_icon("TrackTrigger","EditorIcons") + }; + + Ref wrap_icon[2]={ + get_icon("InterpWrapClamp","EditorIcons"), + get_icon("InterpWrapLoop","EditorIcons"), + }; + + //right_data_size_cache = remove_icon->get_width() + move_up_icon->get_width() + move_down_icon->get_width() + down_icon->get_width() *2 + interp_icon[0]->get_width() + cont_icon[0]->get_width() + add_key_icon->get_width() + hsep*11; + 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; + + + } + call_select->connect("selected",this,"_add_call_track"); + //rename_anim->set_icon( get_icon("Rename","EditorIcons") ); +/* + edit_anim->set_icon( get_icon("Edit","EditorIcons") ); + blend_anim->set_icon( get_icon("Blend","EditorIcons") ); + play->set_icon( get_icon("Play","EditorIcons") ); + stop->set_icon( get_icon("Stop","EditorIcons") ); + pause->set_icon( get_icon("Pause","EditorIcons") ); +*/ + //menu->set_icon(get_icon("Animation","EditorIcons")); + //play->set_icon(get_icon("AnimationPlay","EditorIcons")); + //menu->set_icon(get_icon("Animation","EditorIcons")); + _update_menu(); + + } 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(); + length->set_value(animation->get_length()); + step->set_value(animation->get_step()); + } +} + + +void AnimationKeyEditor::_root_removed() { + + root=NULL; +} + +void AnimationKeyEditor::_update_menu() { + + + updating=true; + + if (animation.is_valid()) { + + length->set_value(animation->get_length()); + loop->set_pressed(animation->has_loop()); + step->set_value(animation->get_step()); + } + + track_editor->update(); + updating=false; + +} +void AnimationKeyEditor::_clear_selection() { + + selection.clear(); + key_edit->animation=Ref(); + key_edit->track=0; + key_edit->key_ofs=0; + key_edit->hint=PropertyInfo(); + key_edit->base=NodePath(); + key_edit->notify_change(); + +} + + +void AnimationKeyEditor::set_animation(const Ref& p_anim) { + + if (animation.is_valid()) + animation->disconnect("changed",this,"_update_paths"); + animation=p_anim; + if (animation.is_valid()) + animation->connect("changed",this,"_update_paths"); + + timeline_pos=0; + _clear_selection(); + _update_paths(); + + _update_menu(); + selected_track=-1; + _edit_if_single_selection(); + + EditorNode::get_singleton()->update_keying(); +} + +void AnimationKeyEditor::set_root(Node *p_root) { + + if (root) + root->disconnect("tree_exited",this,"_root_removed"); + + root=p_root; + + if (root) + root->connect("tree_exited",this,"_root_removed",make_binds(),CONNECT_ONESHOT); + + +} + +Node *AnimationKeyEditor::get_root() const { + + return root; +} + + + + + + +void AnimationKeyEditor::update_keying() { + + bool keying_enabled=is_visible_in_tree() && animation.is_valid(); + + if (keying_enabled==keying) + return; + + keying=keying_enabled; + _update_menu(); + emit_signal("keying_changed"); + +} + +bool AnimationKeyEditor::has_keying() const { + + return keying; +} + +void AnimationKeyEditor::_query_insert(const InsertData& p_id) { + + + if (insert_frame!=Engine::get_singleton()->get_frames_drawn()) { + //clear insert list for the frame if frame changed + if (insert_confirm->is_visible_in_tree()) + return; //do nothing + insert_data.clear(); + insert_query=false; + } + insert_frame=Engine::get_singleton()->get_frames_drawn(); + + for (List::Element *E=insert_data.front();E;E=E->next()) { + //prevent insertion of multiple tracks + if (E->get().path==p_id.path) + return; //already inserted a track for this on this frame + } + + insert_data.push_back(p_id); + + if (p_id.track_idx==-1) { + if (bool(EDITOR_DEF("editors/animation/confirm_insert_track",true))) { + //potential new key, does not exist + if (insert_data.size()==1) + insert_confirm->set_text(vformat(TTR("Create NEW track for %s and insert key?"),p_id.query)); + else + insert_confirm->set_text(vformat(TTR("Create %d NEW tracks and insert keys?"),insert_data.size())); + + insert_confirm->get_ok()->set_text(TTR("Create")); + insert_confirm->popup_centered_minsize(); + insert_query=true; + } else { + call_deferred("_insert_delay"); + insert_queue=true; + } + + } else { + if (!insert_query && !insert_queue) { + call_deferred("_insert_delay"); + insert_queue=true; + } + } + +} + +void AnimationKeyEditor::insert_transform_key(Spatial *p_node,const String& p_sub,const Transform& p_xform) { + + 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); + if (p_sub!="") + path+=":"+p_sub; + + NodePath np=path; + + int track_idx=-1; + + for(int i=0;iget_track_count();i++) { + + if (animation->track_get_type(i)!=Animation::TYPE_TRANSFORM) + continue; + if (animation->track_get_path(i)!=np) + continue; + + track_idx=i; + break; + } + + InsertData id; + Dictionary val; + + 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; + + //dialog insert + + _query_insert(id); + +} + + +void AnimationKeyEditor::insert_node_value_key(Node* p_node, const String& p_property,const Variant& p_value,bool p_only_if_exists) { + + ERR_FAIL_COND(!root); + //let's build a node path + + Node *node = p_node; + + String path = root->get_path_to(node); + + for(int i=1;iget_path_size();i++) { + + String prop = history->get_path_property(i); + ERR_FAIL_COND(prop==""); + path+=":"+prop; + } + + + path+=":"+p_property; + + NodePath np = path; + + //locate track + + int track_idx=-1; + + for(int i=0;iget_track_count();i++) { + + if (animation->track_get_type(i)!=Animation::TYPE_VALUE) + continue; + if (animation->track_get_path(i)!=np) + continue; + + track_idx=i; + break; + } + + if (p_only_if_exists && track_idx==-1) + return; + InsertData id; + 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; + //dialog insert + _query_insert(id); + + + +} + +void AnimationKeyEditor::insert_value_key(const String& p_property,const Variant& p_value,bool p_advance) { + + ERR_FAIL_COND(!root); + //let's build a node path + ERR_FAIL_COND(history->get_path_size()==0); + Object *obj = ObjectDB::get_instance(history->get_path_object(0)); + ERR_FAIL_COND(!obj || !obj->cast_to()); + + Node *node = obj->cast_to(); + + String path = root->get_path_to(node); + + for(int i=1;iget_path_size();i++) { + + String prop = history->get_path_property(i); + ERR_FAIL_COND(prop==""); + path+=":"+prop; + } + + + + path+=":"+p_property; + + NodePath np = path; + + //locate track + + int track_idx=-1; + + for(int i=0;iget_track_count();i++) { + + if (animation->track_get_type(i)!=Animation::TYPE_VALUE) + continue; + if (animation->track_get_path(i)!=np) + continue; + + track_idx=i; + break; + } + + InsertData id; + 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; + //dialog insert + _query_insert(id); + + + +} + +void AnimationKeyEditor::_confirm_insert_list() { + + + undo_redo->create_action(TTR("Anim Create & Insert")); + + int last_track = animation->get_track_count(); + while(insert_data.size()) { + + last_track=_confirm_insert(insert_data.front()->get(),last_track); + insert_data.pop_front(); + } + + undo_redo->commit_action(); +} + +int AnimationKeyEditor::_confirm_insert(InsertData p_id,int p_last_track) { + + if (p_last_track==-1) + p_last_track=animation->get_track_count(); + + bool created=false; + if (p_id.track_idx<0) { + + created=true; + undo_redo->create_action(TTR("Anim Insert Track & Key")); + Animation::UpdateMode update_mode=Animation::UPDATE_DISCRETE; + + if (p_id.type==Animation::TYPE_VALUE) { + //wants a new tack + + { + //shitty hack + NodePath np; + animation->add_track(p_id.type); + 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 || + h.type==Variant::RECT3 || + h.type==Variant::QUAT || + h.type==Variant::COLOR || + h.type==Variant::TRANSFORM ) { + + update_mode=Animation::UPDATE_CONTINUOUS; + } + + if (h.usage&PROPERTY_USAGE_ANIMATE_AS_TRIGGER) { + update_mode=Animation::UPDATE_TRIGGER; + } + } + } + + p_id.track_idx=p_last_track; + + 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); + + } else { + undo_redo->create_action(TTR("Anim Insert Key")); + } + + float time = timeline_pos; + Variant value; + + + switch(p_id.type) { + + case Animation::TYPE_VALUE: { + + value = p_id.value; + + + } break; + case Animation::TYPE_TRANSFORM: { + + + Transform tr = p_id.value; + Dictionary d; + d["loc"]=tr.origin; + d["scale"]=tr.basis.get_scale(); + d["rot"]=Quat(tr.basis);//.orthonormalized(); + value=d; + } break; + default:{} + } + + + + undo_redo->add_do_method(animation.ptr(),"track_insert_key",p_id.track_idx,time,value); + + if (created) { + + //just remove the track + undo_redo->add_undo_method(animation.ptr(),"remove_track",p_last_track); + p_last_track++; + } else { + + undo_redo->add_undo_method(animation.ptr(),"track_remove_key_at_pos",p_id.track_idx,time); + 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); + } + } + + 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"); + + undo_redo->commit_action(); + + return p_last_track; + +} + + + + +Ref AnimationKeyEditor::get_current_animation() const { + + return animation; +} + +void AnimationKeyEditor::_animation_len_changed(float p_len) { + + + if (updating) + return; + + if (!animation.is_null()) { + + undo_redo->create_action(TTR("Change Anim Len")); + 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"); + undo_redo->commit_action(); + } +} + +void AnimationKeyEditor::_animation_len_update() { + + if (!animation.is_null()) + emit_signal(alc,animation->get_length()); +} + +void AnimationKeyEditor::_animation_changed() { + if (updating) + return; + _update_menu(); + +} + +void AnimationKeyEditor::_animation_loop_changed() { + + if (updating) + return; + + if (!animation.is_null()) { + + undo_redo->create_action(TTR("Change Anim Loop")); + undo_redo->add_do_method(animation.ptr(),"set_loop",loop->is_pressed()); + undo_redo->add_undo_method(animation.ptr(),"set_loop",!loop->is_pressed()); + undo_redo->commit_action(); + } + +} + + +void AnimationKeyEditor::_create_value_item(int p_type) { + + undo_redo->create_action(TTR("Anim Create Typed Value Key")); + + Variant::CallError ce; + 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); + undo_redo->add_undo_method(animation.ptr(),"track_remove_key_at_pos",cvi_track,cvi_pos); + + int existing = animation->track_find_key(cvi_track,cvi_pos,true); + + 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); + } + + undo_redo->commit_action(); + +} + + +void AnimationKeyEditor::set_anim_pos(float p_pos) { + + if (animation.is_null()) + return; + timeline_pos=p_pos; + update(); + track_pos->update(); + track_editor->update(); +} + +void AnimationKeyEditor::_pane_drag(const Point2& p_delta) { + + Size2 ecs = ec->get_custom_minimum_size(); + ecs.y-=p_delta.y; + if (ecs.y<100) + ecs.y=100; + ec->set_custom_minimum_size(ecs); + +} + +void AnimationKeyEditor::_insert_delay() { + + if (insert_query) { + //discard since it's entered into query mode + insert_queue=false; + return; + } + + undo_redo->create_action(TTR("Anim Insert")); + + int last_track = animation->get_track_count(); + bool advance=false; + while(insert_data.size()) { + + if (insert_data.front()->get().advance) + advance=true; + last_track=_confirm_insert(insert_data.front()->get(),last_track); + insert_data.pop_front(); + } + + undo_redo->commit_action(); + + if (advance) { + float step = animation->get_step(); + if (step==0) + step=1; + + float pos=timeline_pos; + + pos=Math::stepify(pos+step,step); + if (pos>animation->get_length()) + pos=animation->get_length(); + timeline_pos=pos; + track_pos->update(); + emit_signal("timeline_changed",pos,true); + } + insert_queue=false; +} + +void AnimationKeyEditor::_step_changed(float p_len) { + + updating=true; + if (!animation.is_null()) { + animation->set_step(p_len); + emit_signal("animation_step_changed",animation->get_step()); + } + updating=false; +} + +void AnimationKeyEditor::_scale() { + + + if (selection.empty()) + return; + + + float from_t = 1e20; + float to_t = -1e20; + float len = -1e20; + float pivot=0; + + for(Map::Element *E=selection.front();E;E=E->next()) { + float t = animation->track_get_key_time(E->key().track,E->key().key); + if (tto_t) + to_t=t; + + } + + len=to_t-from_t; + if (last_menu_track_opt==TRACK_MENU_SCALE_PIVOT) { + pivot = timeline_pos; + + } else { + + pivot=from_t; + + } + + float s = scale->get_value(); + if (s==0) { + ERR_PRINT("Can't scale to 0"); + } + + + + undo_redo->create_action(TTR("Anim Scale Keys")); + + List<_AnimMoveRestore> to_restore; + + // 1-remove the keys + for(Map::Element *E=selection.back();E;E=E->prev()) { + + undo_redo->add_do_method(animation.ptr(),"track_remove_key",E->key().track,E->key().key); + } + // 2- remove overlapped keys + for(Map::Element *E=selection.back();E;E=E->prev()) { + + float newtime = (E->get().pos-from_t)*s+from_t; + 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 + + undo_redo->add_do_method(animation.ptr(),"track_remove_key_at_pos",E->key().track,newtime); + _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); + + } + +#define _NEW_POS(m_ofs) (((s>0)?m_ofs:from_t+(len-(m_ofs-from_t)))-pivot)*ABS(s)+from_t + // 3-move the keys (re insert them) + for(Map::Element *E=selection.back();E;E=E->prev()) { + + 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)); + + } + + // 4-(undo) remove inserted keys + for(Map::Element *E=selection.back();E;E=E->prev()) { + + float newpos=_NEW_POS(E->get().pos); + undo_redo->add_undo_method(animation.ptr(),"track_remove_key_at_pos",E->key().track,newpos); + + } + + // 5-(undo) reinsert keys + for(Map::Element *E=selection.back();E;E=E->prev()) { + + 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)); + + } + + // 6-(undo) reinsert overlapped keys + for(List<_AnimMoveRestore>::Element *E=to_restore.front();E;E=E->next()) { + + _AnimMoveRestore &amr = E->get(); + undo_redo->add_undo_method(animation.ptr(),"track_insert_key",amr.track,amr.time,amr.key,amr.transition); + + } + + // 6-(undo) reinsert overlapped keys + for(List<_AnimMoveRestore>::Element *E=to_restore.front();E;E=E->next()) { + + _AnimMoveRestore &amr = E->get(); + undo_redo->add_undo_method(animation.ptr(),"track_insert_key",amr.track,amr.time,amr.key,amr.transition); + + } + + undo_redo->add_do_method(this,"_clear_selection_for_anim",animation); + undo_redo->add_undo_method(this,"_clear_selection_for_anim",animation); + + // 7-reselect + + for(Map::Element *E=selection.back();E;E=E->prev()) { + + 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); + + } +#undef _NEW_POS + undo_redo->commit_action(); + +} + + +void AnimationKeyEditor::_add_call_track(const NodePath& p_base) { + + + Node* base = EditorNode::get_singleton()->get_edited_scene(); + if (!base) + return; + Node* from=base->get_node(p_base); + if (!from || !root) + return; + + NodePath path = root->get_path_to(from); + + //print_line("root: "+String(root->get_path())); + //print_line("path: "+String(path)); + + undo_redo->create_action(TTR("Anim Add Call Track")); + 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()); + undo_redo->commit_action(); + +} + +void AnimationKeyEditor::cleanup() { + + set_animation(Ref()); +} + +void AnimationKeyEditor::_bind_methods() { + + 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); + + + //ClassDB::bind_method(D_METHOD("_confirm_insert"),&AnimationKeyEditor::_confirm_insert); + 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); + ClassDB::bind_method(D_METHOD("_track_pos_draw"),&AnimationKeyEditor::_track_pos_draw); + 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" ) ); + ADD_SIGNAL( MethodInfo("timeline_changed", PropertyInfo(Variant::REAL,"pos"), PropertyInfo(Variant::BOOL,"drag") ) ); + 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") ) ); + +} + + +AnimationKeyEditor::AnimationKeyEditor() { + + alc="animation_len_changed"; + editor_selection=EditorNode::get_singleton()->get_editor_selection(); + + selected_track=-1; + updating=false; + te_drawing=false; + undo_redo=EditorNode::get_singleton()->get_undo_redo(); + history=EditorNode::get_singleton()->get_editor_history(); + + ec = memnew (Control); + ec->set_custom_minimum_size(Size2(0,150)); + add_child(ec); + ec->set_v_size_flags(SIZE_EXPAND_FILL); + + h_scroll = memnew( HScrollBar ); + h_scroll->connect("value_changed",this,"_scroll_changed"); + add_child(h_scroll); + h_scroll->set_value(0); + + + HBoxContainer *hb = memnew( HBoxContainer ); + add_child(hb); + + + root=NULL; + //menu = memnew( MenuButton ); + //menu->set_flat(true); + //menu->set_pos(Point2()); + //add_child(menu); + + zoomicon = memnew( TextureRect ); + hb->add_child(zoomicon); + zoomicon->set_tooltip(TTR("Animation zoom.")); + + zoom = memnew( HSlider ); + //hb->add_child(zoom); + zoom->set_step(0.01); + zoom->set_min(0.0); + zoom->set_max(2.0); + zoom->set_value(1.0); + zoom->set_h_size_flags(SIZE_EXPAND_FILL); + zoom->set_stretch_ratio(2); + hb->add_child(zoom); + zoom->connect("value_changed",this,"_scroll_changed"); + zoom->set_tooltip(TTR("Animation zoom.")); + + hb->add_child( memnew( VSeparator ) ); + + Label *l = memnew( Label ); + l->set_text(TTR("Length (s):")); + hb->add_child(l); + + length = memnew( SpinBox ); + 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); + length->set_tooltip(TTR("Animation length (in seconds).")); + + hb->add_child(length); + length->connect("value_changed",this,"_animation_len_changed"); + + l = memnew( Label ); + l->set_text(TTR("Step (s):")); + hb->add_child(l); + + step = memnew( SpinBox ); + step->set_min(0.00); + step->set_max(128); + step->set_step(0.01); + step->set_value(0.0); + step->set_h_size_flags(SIZE_EXPAND_FILL); + step->set_stretch_ratio(1); + step->set_tooltip(TTR("Cursor step snap (in seconds).")); + + hb->add_child(step); + step->connect("value_changed",this,"_step_changed"); + + loop = memnew( ToolButton ); + loop->set_toggle_mode(true); + loop->connect("pressed",this,"_animation_loop_changed"); + hb->add_child(loop); + loop->set_tooltip(TTR("Enable/Disable looping in animation.")); + + hb->add_child( memnew( VSeparator ) ); + + menu_add_track = memnew( MenuButton ); + hb->add_child(menu_add_track); + menu_add_track->get_popup()->connect("id_pressed",this,"_menu_add_track"); + menu_add_track->set_tooltip(TTR("Add new tracks.")); + + move_up_button = memnew( ToolButton ); + hb->add_child(move_up_button); + move_up_button->connect("pressed",this,"_menu_track",make_binds(TRACK_MENU_MOVE_UP)); + move_up_button->set_focus_mode(FOCUS_NONE); + move_up_button->set_disabled(true); + move_up_button->set_tooltip(TTR("Move current track up.")); + + move_down_button = memnew( ToolButton ); + hb->add_child(move_down_button); + move_down_button->connect("pressed",this,"_menu_track",make_binds(TRACK_MENU_MOVE_DOWN)); + move_down_button->set_focus_mode(FOCUS_NONE); + move_down_button->set_disabled(true); + move_down_button->set_tooltip(TTR("Move current track down.")); + + remove_button = memnew( ToolButton ); + hb->add_child(remove_button); + remove_button->connect("pressed",this,"_menu_track",make_binds(TRACK_MENU_REMOVE)); + remove_button->set_focus_mode(FOCUS_NONE); + remove_button->set_disabled(true); + remove_button->set_tooltip(TTR("Remove selected track.")); + + hb->add_child(memnew( VSeparator )); + + menu_track = memnew( MenuButton ); + hb->add_child(menu_track); + menu_track->get_popup()->connect("id_pressed",this,"_menu_track"); + menu_track->set_tooltip(TTR("Track tools")); + + edit_button = memnew( ToolButton ); + edit_button->set_toggle_mode(true); + edit_button->set_focus_mode(FOCUS_NONE); + edit_button->set_disabled(true); + + hb->add_child(edit_button); + edit_button->set_tooltip(TTR("Enable editing of individual keys by clicking them.")); + + optimize_dialog = memnew( ConfirmationDialog ); + add_child(optimize_dialog); + optimize_dialog->set_title(TTR("Anim. Optimizer")); + VBoxContainer *optimize_vb = memnew( VBoxContainer ); + optimize_dialog->add_child(optimize_vb); + + optimize_linear_error = memnew( SpinBox ); + optimize_linear_error->set_max(1.0); + optimize_linear_error->set_min(0.001); + optimize_linear_error->set_step(0.001); + optimize_linear_error->set_value(0.05); + optimize_vb->add_margin_child(TTR("Max. Linear Error:"),optimize_linear_error); + optimize_angular_error = memnew( SpinBox ); + optimize_angular_error->set_max(1.0); + optimize_angular_error->set_min(0.001); + optimize_angular_error->set_step(0.001); + optimize_angular_error->set_value(0.01); + + 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); + optimize_max_angle->set_max(360.0); + optimize_max_angle->set_min(0.0); + optimize_max_angle->set_step(0.1); + optimize_max_angle->set_value(22); + + optimize_dialog->get_ok()->set_text(TTR("Optimize")); + + + + /*keying = memnew( Button ); + keying->set_toggle_mode(true); + //keying->set_text("Keys"); + 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"); + */ + +/* l = memnew( Label ); + l->set_text("Base: "); + l->set_pos(Point2(0,3)); + //dr_panel->add_child(l);*/ + + //menu->get_popup()->connect("id_pressed",this,"_menu_callback"); + + + hb = memnew( HBoxContainer); + hb->set_area_as_parent_rect(); + ec->add_child(hb); + hb->set_v_size_flags(SIZE_EXPAND_FILL); + + track_editor = memnew( Control ); + track_editor->connect("draw",this,"_track_editor_draw"); + hb->add_child(track_editor); + track_editor->connect("gui_input",this,"_track_editor_gui_input"); + track_editor->set_focus_mode(Control::FOCUS_ALL); + track_editor->set_h_size_flags(SIZE_EXPAND_FILL); + + + + track_pos = memnew( Control ); + track_pos->set_area_as_parent_rect(); + track_pos->set_mouse_filter(MOUSE_FILTER_IGNORE); + track_editor->add_child(track_pos); + track_pos->connect("draw",this,"_track_pos_draw"); + + select_anim_warning = memnew( Label ); + track_editor->add_child(select_anim_warning); + select_anim_warning->set_area_as_parent_rect(); + 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); + + + + v_scroll = memnew( VScrollBar ); + hb->add_child(v_scroll); + v_scroll->connect("value_changed",this,"_scroll_changed"); + v_scroll->set_value(0); + + key_editor_tab = memnew(TabContainer); + hb->add_child(key_editor_tab); + key_editor_tab->set_custom_minimum_size(Size2(200,0)); + + key_editor = memnew( PropertyEditor ); + key_editor->set_area_as_parent_rect(); + key_editor->hide_top_label(); + key_editor->set_name(TTR("Key")); + key_editor_tab->add_child(key_editor); + + key_edit = memnew( AnimationKeyEdit ); + key_edit->undo_redo=undo_redo; + //key_edit->ke_dialog=key_edit_dialog; + + type_menu = memnew( PopupMenu ); + add_child(type_menu); + for(int i=0;iadd_item(Variant::get_type_name(Variant::Type(i)),i); + type_menu->connect("id_pressed",this,"_create_value_item"); + + VBoxContainer *curve_vb = memnew( VBoxContainer ); + curve_vb->set_name(TTR("Transition")); + HBoxContainer *curve_hb = memnew( HBoxContainer ); + curve_vb->add_child(curve_hb); + + curve_linear = memnew( ToolButton ); + curve_linear->set_focus_mode(FOCUS_NONE); + curve_hb->add_child(curve_linear); + curve_in = memnew( ToolButton ); + curve_in->set_focus_mode(FOCUS_NONE); + curve_hb->add_child(curve_in); + curve_out = memnew( ToolButton ); + curve_out->set_focus_mode(FOCUS_NONE); + curve_hb->add_child(curve_out); + curve_inout = memnew( ToolButton ); + curve_inout->set_focus_mode(FOCUS_NONE); + curve_hb->add_child(curve_inout); + curve_outin = memnew( ToolButton ); + curve_outin->set_focus_mode(FOCUS_NONE); + curve_hb->add_child(curve_outin); + curve_constant = memnew( ToolButton ); + curve_constant->set_focus_mode(FOCUS_NONE); + curve_hb->add_child(curve_constant); + + + curve_edit = memnew( AnimationCurveEdit ); + curve_vb->add_child(curve_edit); + curve_edit->set_v_size_flags(SIZE_EXPAND_FILL); + key_editor_tab->add_child(curve_vb); + + track_name = memnew( LineEdit ); + track_name->set_as_toplevel(true); + track_name->hide(); + add_child(track_name); + track_name->connect("text_entered",this,"_track_name_changed"); + track_menu = memnew( PopupMenu ); + add_child(track_menu); + track_menu->connect("id_pressed",this,"_track_menu_selected"); + + key_editor_tab->hide(); + + last_idx =1; + + _update_menu(); + + + + insert_confirm = memnew( ConfirmationDialog ); + add_child(insert_confirm); + insert_confirm->connect("confirmed",this,"_confirm_insert_list"); + + click.click=ClickOver::CLICK_NONE; + + + name_column_ratio=0.3; + timeline_pos=0; + + + keying=false; + insert_frame=0; + insert_query=false; + insert_queue=false; + + editor_selection->connect("selection_changed",track_editor,"update"); + + + scale_dialog = memnew( ConfirmationDialog ); + VBoxContainer *vbc = memnew( VBoxContainer ); + scale_dialog->add_child(vbc); + + scale = memnew( SpinBox ); + scale->set_min(-99999); + scale->set_max(99999); + scale->set_step(0.001); + vbc->add_margin_child(TTR("Scale Ratio:"),scale); + scale_dialog->connect("confirmed",this,"_scale"); + add_child(scale_dialog); + + call_select = memnew( SceneTreeDialog ); + add_child(call_select); + call_select->set_title(TTR("Call Functions in Which Node?")); + + cleanup_dialog = memnew( ConfirmationDialog ); + add_child(cleanup_dialog); + VBoxContainer *cleanup_vb = memnew( VBoxContainer ); + cleanup_dialog->add_child(cleanup_vb); + + cleanup_keys = memnew( CheckButton ); + cleanup_keys->set_text(TTR("Remove invalid keys")); + cleanup_keys->set_pressed(true); + cleanup_vb->add_child(cleanup_keys); + + cleanup_tracks = memnew( CheckButton ); + cleanup_tracks->set_text(TTR("Remove unresolved and empty tracks")); + cleanup_tracks->set_pressed(true); + cleanup_vb->add_child(cleanup_tracks); + + cleanup_all = memnew( CheckButton ); + cleanup_all->set_text(TTR("Clean-up all animations")); + cleanup_vb->add_child(cleanup_all); + + cleanup_dialog->set_title(TTR("Clean-Up Animation(s) (NO UNDO!)")); + cleanup_dialog->get_ok()->set_text(TTR("Clean-Up")); + + cleanup_dialog->connect("confirmed",this,"_menu_track",varray(TRACK_MENU_CLEAN_UP_CONFIRM)); + + add_constant_override("separation",get_constant("separation","VBoxContainer")); + + track_editor->set_clip_contents(true); + +} + +AnimationKeyEditor::~AnimationKeyEditor() { + + + + memdelete( key_edit ); + +} diff --git a/tools/editor/animation_editor.h b/editor/animation_editor.h similarity index 100% rename from tools/editor/animation_editor.h rename to editor/animation_editor.h diff --git a/tools/editor/array_property_edit.cpp b/editor/array_property_edit.cpp similarity index 100% rename from tools/editor/array_property_edit.cpp rename to editor/array_property_edit.cpp diff --git a/tools/editor/array_property_edit.h b/editor/array_property_edit.h similarity index 100% rename from tools/editor/array_property_edit.h rename to editor/array_property_edit.h diff --git a/tools/editor/asset_library_editor_plugin.cpp b/editor/asset_library_editor_plugin.cpp similarity index 100% rename from tools/editor/asset_library_editor_plugin.cpp rename to editor/asset_library_editor_plugin.cpp diff --git a/tools/editor/asset_library_editor_plugin.h b/editor/asset_library_editor_plugin.h similarity index 100% rename from tools/editor/asset_library_editor_plugin.h rename to editor/asset_library_editor_plugin.h diff --git a/tools/editor/call_dialog.cpp b/editor/call_dialog.cpp similarity index 100% rename from tools/editor/call_dialog.cpp rename to editor/call_dialog.cpp diff --git a/editor/call_dialog.h b/editor/call_dialog.h new file mode 100644 index 00000000000..56fc07c3df0 --- /dev/null +++ b/editor/call_dialog.h @@ -0,0 +1,85 @@ +/*************************************************************************/ +/* call_dialog.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ +#ifndef CALL_DIALOG_H +#define CALL_DIALOG_H + +#include "scene/gui/popup.h" +#include "scene/gui/button.h" +#include "scene/gui/tree.h" +#include "scene/gui/label.h" +#include "scene/gui/line_edit.h" +#include "editor/property_editor.h" +/** + @author Juan Linietsky +*/ + +#if 0 + +class CallDialogParams; + +class CallDialog : public Popup { + + GDCLASS( CallDialog, Popup ); + + + Label* method_label; + Tree *tree; + Button *call; + Button *cancel; + + CallDialogParams *call_params; + PropertyEditor *property_editor; + + Label *return_label; + LineEdit *return_value; + Object *object; + StringName selected; + + Vector methods; + + + void _item_selected(); + void _update_method_list(); + void _call(); + void _cancel(); + +protected: + static void _bind_methods(); + void _notification(int p_what); +public: + + void set_object(Object *p_object,StringName p_selected=""); + + CallDialog(); + ~CallDialog(); + +}; + +#endif +#endif diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp new file mode 100644 index 00000000000..8e9925a0d3b --- /dev/null +++ b/editor/code_editor.cpp @@ -0,0 +1,1323 @@ +/*************************************************************************/ +/* code_editor.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "code_editor.h" + +#include "editor_settings.h" +#include "scene/gui/margin_container.h" +#include "scene/gui/separator.h" +#include "scene/resources/dynamic_font.h" +#include "os/keyboard.h" +#include "editor/editor_scale.h" + +void GotoLineDialog::popup_find_line(TextEdit *p_edit) { + + text_editor=p_edit; + + line->set_text(itos(text_editor->cursor_get_line())); + line->select_all(); + popup_centered(Size2(180,80)); + line->grab_focus(); +} + + +int GotoLineDialog::get_line() const { + + return line->get_text().to_int(); +} + + +void GotoLineDialog::ok_pressed() { + + if (get_line()<1 || get_line()>text_editor->get_line_count()) + return; + text_editor->cursor_set_line(get_line()-1); + hide(); +} + +GotoLineDialog::GotoLineDialog() { + + set_title(TTR("Go to Line")); + Label *l = memnew(Label); + l->set_text(TTR("Line Number:")); + l->set_pos(Point2(5,5)); + add_child(l); + + line = memnew( LineEdit ); + line->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + line->set_begin( Point2(15,22) ); + line->set_end( Point2(15,35) ); + add_child(line); + register_text_enter(line); + text_editor=NULL; + + set_hide_on_ok(false); +} + + +void FindReplaceBar::_notification(int p_what) { + + if (p_what == NOTIFICATION_READY) { + + find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); + find_next->set_icon(get_icon("MoveDown", "EditorIcons")); + hide_button->set_normal_texture(get_icon("Close","EditorIcons")); + hide_button->set_hover_texture(get_icon("CloseHover","EditorIcons")); + hide_button->set_pressed_texture(get_icon("Close","EditorIcons")); + + } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + + set_process_unhandled_input(is_visible_in_tree()); + } +} + +void FindReplaceBar::_unhandled_input(const InputEvent &p_event) { + + if (p_event.type == InputEvent::KEY) { + + const InputEventKey& k = p_event.key; + + if (k.pressed && (text_edit->has_focus() || text_vbc->is_a_parent_of(get_focus_owner()))) { + + bool accepted = true; + + switch (k.scancode) { + + case KEY_ESCAPE: { + + _hide_bar(); + } break; + default: { + + accepted = false; + } break; + } + + if (accepted) { + accept_event(); + } + } + } +} + +bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) { + + int line, col; + String text=get_search_text(); + + bool found=text_edit->search(text,p_flags,p_from_line,p_from_col,line,col); + + if (found) { + if (!preserve_cursor) { + text_edit->cursor_set_line(line, false); + text_edit->cursor_set_column(col+text.length(), false); + text_edit->center_viewport_to_cursor(); + } + + text_edit->set_search_text(text); + text_edit->set_search_flags(p_flags); + text_edit->set_current_search_result(line,col); + + result_line=line; + result_col=col; + + set_error(""); + } else { + result_line=-1; + result_col=-1; + text_edit->set_search_text(""); + set_error(text.empty()?"":TTR("No Matches")); + } + + return found; +} + +void FindReplaceBar::_replace() { + + if (result_line!=-1 && result_col!=-1) { + text_edit->begin_complex_operation(); + + text_edit->select(result_line,result_col,result_line,result_col+get_search_text().length()); + text_edit->insert_text_at_cursor(get_replace_text()); + + text_edit->end_complex_operation(); + } + + search_current(); +} + +void FindReplaceBar::_replace_all() { + + // line as x so it gets priority in comparison, column as y + Point2i orig_cursor(text_edit->cursor_get_line(),text_edit->cursor_get_column()); + Point2i prev_match=Point2(-1,-1); + + bool selection_enabled = text_edit->is_selection_active(); + Point2i selection_begin,selection_end; + if (selection_enabled) { + selection_begin=Point2i(text_edit->get_selection_from_line(),text_edit->get_selection_from_column()); + selection_end=Point2i(text_edit->get_selection_to_line(),text_edit->get_selection_to_column()); + } + + int vsval = text_edit->get_v_scroll(); + + text_edit->cursor_set_line(0); + text_edit->cursor_set_column(0); + + String replace_text=get_replace_text(); + int search_text_len=get_search_text().length(); + + int rc=0; + + replace_all_mode = true; + + text_edit->begin_complex_operation(); + + while (search_next()) { + + // replace area + Point2i match_from(result_line,result_col); + Point2i match_to(result_line,result_col+search_text_len); + + if (match_from < prev_match) + break; // done + + prev_match=Point2i(result_line,result_col+replace_text.length()); + + text_edit->select(result_line,result_col,result_line,match_to.y); + + if (selection_enabled && is_selection_only()) { + + if (match_fromselection_end) + continue; + + // replace but adjust selection bounds + text_edit->insert_text_at_cursor(replace_text); + if (match_to.x==selection_end.x) + selection_end.y+=replace_text.length()-search_text_len; + } else { + // just replace + text_edit->insert_text_at_cursor(replace_text); + } + + rc++; + } + + text_edit->end_complex_operation(); + + replace_all_mode = false; + + // restore editor state (selection, cursor, scroll) + text_edit->cursor_set_line(orig_cursor.x); + text_edit->cursor_set_column(orig_cursor.y); + + if (selection_enabled && is_selection_only()) { + // reselect + text_edit->select(selection_begin.x,selection_begin.y,selection_end.x,selection_end.y); + } else { + text_edit->deselect(); + } + + text_edit->set_v_scroll(vsval); + set_error(vformat(TTR("Replaced %d Ocurrence(s)."), rc)); +} + +void FindReplaceBar::_get_search_from(int& r_line, int& r_col) { + + r_line=text_edit->cursor_get_line(); + r_col=text_edit->cursor_get_column(); + + if (text_edit->is_selection_active() && !replace_all_mode) { + + int selection_line=text_edit->get_selection_from_line(); + + if (text_edit->get_selection_text()==get_search_text() && r_line==selection_line) { + + int selection_from_col=text_edit->get_selection_from_column(); + + if (r_col>=selection_from_col && r_col<=text_edit->get_selection_to_column()) { + r_col=selection_line; + r_col=selection_from_col; + } + } + } + + if (r_line==result_line && r_col>=result_col && r_col<=result_col+get_search_text().length()) { + r_col=result_col; + } +} + +bool FindReplaceBar::search_current() { + + uint32_t flags=0; + + if (is_whole_words()) + flags|=TextEdit::SEARCH_WHOLE_WORDS; + if (is_case_sensitive()) + flags|=TextEdit::SEARCH_MATCH_CASE; + + int line, col; + _get_search_from(line, col); + + return _search(flags,line,col); +} + +bool FindReplaceBar::search_prev() { + + uint32_t flags=0; + String text = get_search_text(); + + if (is_whole_words()) + flags|=TextEdit::SEARCH_WHOLE_WORDS; + if (is_case_sensitive()) + flags|=TextEdit::SEARCH_MATCH_CASE; + + flags|=TextEdit::SEARCH_BACKWARDS; + + int line, col; + _get_search_from(line, col); + + col-=text.length(); + if (col<0) { + line-=1; + if (line<0) + line=text_edit->get_line_count()-1; + col=text_edit->get_line(line).length(); + } + + return _search(flags,line,col); +} + +bool FindReplaceBar::search_next() { + + uint32_t flags=0; + String text = get_search_text(); + + if (is_whole_words()) + flags|=TextEdit::SEARCH_WHOLE_WORDS; + if (is_case_sensitive()) + flags|=TextEdit::SEARCH_MATCH_CASE; + + int line, col; + _get_search_from(line, col); + + if (line==result_line && col==result_col) { + col+=text.length(); + if (col>text_edit->get_line(line).length()) { + line+=1; + if (line>=text_edit->get_line_count()) + line=0; + col=0; + } + } + + return _search(flags,line,col); +} + +void FindReplaceBar::_hide_bar() { + + if (replace_text->has_focus() || search_text->has_focus()) + text_edit->grab_focus(); + + text_edit->set_search_text(""); + result_line = -1; + result_col = -1; + replace_hbc->hide(); + replace_options_hbc->hide(); + hide(); +} + +void FindReplaceBar::_show_search() { + + show(); + search_text->grab_focus(); + + if (text_edit->is_selection_active() && !selection_only->is_pressed()) { + search_text->set_text(text_edit->get_selection_text()); + } + + if (!get_search_text().empty()) { + search_text->select_all(); + search_text->set_cursor_pos(search_text->get_text().length()); + search_current(); + } +} + +void FindReplaceBar::popup_search() { + + replace_hbc->hide(); + replace_options_hbc->hide(); + _show_search(); +} + +void FindReplaceBar::popup_replace() { + + + if (!replace_hbc->is_visible_in_tree() || !replace_options_hbc->is_visible_in_tree()) { + replace_text->clear(); + replace_hbc->show(); + replace_options_hbc->show(); + + } + + selection_only->set_pressed( (text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line()) ); + + _show_search(); +} + +void FindReplaceBar::_search_options_changed(bool p_pressed) { + + search_current(); +} + +void FindReplaceBar::_editor_text_changed() { + + if (is_visible_in_tree()) { + preserve_cursor=true; + search_current(); + preserve_cursor=false; + } +} + +void FindReplaceBar::_search_text_changed(const String& p_text) { + + search_current(); +} + +void FindReplaceBar::_search_text_entered(const String& p_text) { + + search_next(); +} + +void FindReplaceBar::_replace_text_entered(const String& p_text) { + + if (selection_only->is_pressed() && text_edit->is_selection_active()) { + _replace_all(); + _hide_bar(); + } +} + +String FindReplaceBar::get_search_text() const { + + return search_text->get_text(); +} + +String FindReplaceBar::get_replace_text() const { + + return replace_text->get_text(); +} + +bool FindReplaceBar::is_case_sensitive() const { + + return case_sensitive->is_pressed(); +} + +bool FindReplaceBar::is_whole_words() const { + + return whole_words->is_pressed(); +} + +bool FindReplaceBar::is_selection_only() const { + + return selection_only->is_pressed(); +} + +void FindReplaceBar::set_error(const String &p_label) { + + error_label->set_text(p_label); +} + +void FindReplaceBar::set_text_edit(TextEdit *p_text_edit) { + + text_edit = p_text_edit; + text_edit->connect("text_changed",this,"_editor_text_changed"); +} + +void FindReplaceBar::_bind_methods() { + + ClassDB::bind_method("_unhandled_input",&FindReplaceBar::_unhandled_input); + + ClassDB::bind_method("_editor_text_changed",&FindReplaceBar::_editor_text_changed); + ClassDB::bind_method("_search_text_changed",&FindReplaceBar::_search_text_changed); + ClassDB::bind_method("_search_text_entered",&FindReplaceBar::_search_text_entered); + ClassDB::bind_method("_replace_text_entered",&FindReplaceBar::_replace_text_entered); + ClassDB::bind_method("_search_current",&FindReplaceBar::search_current); + ClassDB::bind_method("_search_next",&FindReplaceBar::search_next); + ClassDB::bind_method("_search_prev",&FindReplaceBar::search_prev); + ClassDB::bind_method("_replace_pressed",&FindReplaceBar::_replace); + ClassDB::bind_method("_replace_all_pressed",&FindReplaceBar::_replace_all); + ClassDB::bind_method("_search_options_changed",&FindReplaceBar::_search_options_changed); + ClassDB::bind_method("_hide_pressed",&FindReplaceBar::_hide_bar); + + ADD_SIGNAL(MethodInfo("search")); +} + +FindReplaceBar::FindReplaceBar() { + + replace_all_mode=false; + preserve_cursor=false; + + text_vbc = memnew(VBoxContainer); + add_child(text_vbc); + + HBoxContainer *search_hbc = memnew(HBoxContainer); + text_vbc->add_child(search_hbc); + + search_text = memnew(LineEdit); + search_hbc->add_child(search_text); + search_text->set_custom_minimum_size(Size2(200, 0)); + search_text->connect("text_changed",this,"_search_text_changed"); + search_text->connect("text_entered",this,"_search_text_entered"); + + find_prev = memnew(ToolButton); + search_hbc->add_child(find_prev); + find_prev->set_focus_mode(FOCUS_NONE); + find_prev->connect("pressed",this,"_search_prev"); + + find_next = memnew(ToolButton); + search_hbc->add_child(find_next); + find_next->set_focus_mode(FOCUS_NONE); + find_next->connect("pressed",this,"_search_next"); + + replace_hbc = memnew(HBoxContainer); + text_vbc->add_child(replace_hbc); + replace_hbc->hide(); + + replace_text = memnew(LineEdit); + replace_hbc->add_child(replace_text); + replace_text->set_custom_minimum_size(Size2(200, 0)); + replace_text->connect("text_entered",this,"_replace_text_entered"); + + + replace = memnew(Button); + replace_hbc->add_child(replace); + replace->set_text(TTR("Replace")); + //replace->set_focus_mode(FOCUS_NONE); + replace->connect("pressed",this,"_replace_pressed"); + + replace_all = memnew(Button); + replace_hbc->add_child(replace_all); + replace_all->set_text(TTR("Replace All")); + //replace_all->set_focus_mode(FOCUS_NONE); + replace_all->connect("pressed",this,"_replace_all_pressed"); + + Control *spacer_split = memnew( Control ); + spacer_split->set_custom_minimum_size(Size2(0, 1)); + text_vbc->add_child(spacer_split); + + VBoxContainer *options_vbc = memnew(VBoxContainer); + add_child(options_vbc); + options_vbc->set_h_size_flags(SIZE_EXPAND_FILL); + + HBoxContainer *search_options = memnew(HBoxContainer); + options_vbc->add_child(search_options); + + case_sensitive = memnew(CheckBox); + search_options->add_child(case_sensitive); + case_sensitive->set_text(TTR("Match Case")); + case_sensitive->set_focus_mode(FOCUS_NONE); + case_sensitive->connect("toggled",this,"_search_options_changed"); + + whole_words = memnew(CheckBox); + search_options->add_child(whole_words); + whole_words->set_text(TTR("Whole Words")); + whole_words->set_focus_mode(FOCUS_NONE); + whole_words->connect("toggled",this,"_search_options_changed"); + + error_label = memnew(Label); + search_options->add_child(error_label); + error_label->add_color_override("font_color", Color(1,1,0,1)); + error_label->add_color_override("font_color_shadow", Color(0,0,0,1)); + error_label->add_constant_override("shadow_as_outline", 1); + + search_options->add_spacer(); + + hide_button = memnew(TextureButton); + search_options->add_child(hide_button); + hide_button->set_focus_mode(FOCUS_NONE); + hide_button->connect("pressed",this,"_hide_pressed"); + + replace_options_hbc = memnew(HBoxContainer); + options_vbc->add_child(replace_options_hbc); + replace_options_hbc->hide(); + + selection_only = memnew(CheckBox); + replace_options_hbc->add_child(selection_only); + selection_only->set_text(TTR("Selection Only")); + selection_only->set_focus_mode(FOCUS_NONE); + selection_only->connect("toggled",this,"_search_options_changed"); +} + + +void FindReplaceDialog::popup_search() { + + set_title(TTR("Search")); + replace_mc->hide(); + replace_label->hide(); + replace_vb->hide(); + skip->hide(); + popup_centered(Point2(300,190)); + get_ok()->set_text(TTR("Find")); + search_text->grab_focus(); + if (text_edit->is_selection_active() && ( text_edit->get_selection_from_line() == text_edit->get_selection_to_line())) { + + search_text->set_text( text_edit->get_selection_text() ); + } + search_text->select_all(); + + error_label->set_text(""); + +} + +void FindReplaceDialog::popup_replace() { + + + set_title(TTR("Replace")); + bool do_selection=(text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line()); + + set_replace_selection_only(do_selection); + + if (!do_selection && text_edit->is_selection_active()) { + search_text->set_text(text_edit->get_selection_text()); + } + + replace_mc->show(); + replace_label->show(); + replace_vb->show(); + popup_centered(Point2(300,300)); + if (search_text->get_text()!="" && replace_text->get_text()=="") { + search_text->select(0,0); + replace_text->grab_focus(); + } else { + search_text->grab_focus(); + search_text->select_all(); + } + error_label->set_text(""); + + if (prompt->is_pressed()) { + skip->show(); + get_ok()->set_text(TTR("Next")); + selection_only->set_disabled(true); + + } else { + skip->hide(); + get_ok()->set_text(TTR("Replace")); + selection_only->set_disabled(false); + } + +} + +void FindReplaceDialog::_search_callback() { + + if (is_replace_mode()) + _replace(); + else + _search(); + +} + +void FindReplaceDialog::_replace_skip_callback() { + + _search(); +} + +void FindReplaceDialog::_replace() { + + text_edit->begin_complex_operation(); + if (is_replace_all_mode()) { + + //line as x so it gets priority in comparison, column as y + Point2i orig_cursor(text_edit->cursor_get_line(),text_edit->cursor_get_column()); + Point2i prev_match=Point2(-1,-1); + + + bool selection_enabled = text_edit->is_selection_active(); + Point2i selection_begin,selection_end; + if (selection_enabled) { + selection_begin=Point2i(text_edit->get_selection_from_line(),text_edit->get_selection_from_column()); + selection_end=Point2i(text_edit->get_selection_to_line(),text_edit->get_selection_to_column()); + } + int vsval = text_edit->get_v_scroll(); + //int hsval = text_edit->get_h_scroll(); + + text_edit->cursor_set_line(0); + text_edit->cursor_set_column(0); + + int rc=0; + + while(_search()) { + + if (!text_edit->is_selection_active()) { + //search selects + break; + } + + //replace area + Point2i match_from(text_edit->get_selection_from_line(),text_edit->get_selection_from_column()); + Point2i match_to(text_edit->get_selection_to_line(),text_edit->get_selection_to_column()); + + if (match_from < prev_match) + break; //done + + prev_match=match_to; + + if (selection_enabled && is_replace_selection_only()) { + + if (match_fromselection_end) + continue; + + //replace but adjust selection bounds + + text_edit->insert_text_at_cursor(get_replace_text()); + if (match_to.x==selection_end.x) + selection_end.y+=get_replace_text().length() - get_search_text().length(); + } else { + //just replace + text_edit->insert_text_at_cursor(get_replace_text()); + } + rc++; + + } + //restore editor state (selection, cursor, scroll) + text_edit->cursor_set_line(orig_cursor.x); + text_edit->cursor_set_column(orig_cursor.y); + + if (selection_enabled && is_replace_selection_only()) { + //reselect + text_edit->select(selection_begin.x,selection_begin.y,selection_end.x,selection_end.y); + } else { + text_edit->deselect(); + } + + text_edit->set_v_scroll(vsval); + //text_edit->set_h_scroll(hsval); + error_label->set_text(vformat(TTR("Replaced %d ocurrence(s)."),rc)); + + + //hide(); + } else { + + if (text_edit->get_selection_text()==get_search_text()) { + + text_edit->insert_text_at_cursor(get_replace_text()); + } + + _search(); + } + text_edit->end_complex_operation(); +} + + + +bool FindReplaceDialog::_search() { + + + String text=get_search_text(); + uint32_t flags=0; + + if (is_whole_words()) + flags|=TextEdit::SEARCH_WHOLE_WORDS; + if (is_case_sensitive()) + flags|=TextEdit::SEARCH_MATCH_CASE; + if (is_backwards()) + flags|=TextEdit::SEARCH_BACKWARDS; + + int line=text_edit->cursor_get_line(),col=text_edit->cursor_get_column(); + + if (is_backwards()) { + col-=1; + if (col<0) { + line-=1; + if (line<0) { + line=text_edit->get_line_count()-1; + } + col=text_edit->get_line(line).length(); + } + } + bool found = text_edit->search(text,flags,line,col,line,col); + + + if (found) { + // print_line("found"); + text_edit->cursor_set_line(line); + if (is_backwards()) + text_edit->cursor_set_column(col); + else + text_edit->cursor_set_column(col+text.length()); + text_edit->select(line,col,line,col+text.length()); + set_error(""); + return true; + } else { + + set_error(TTR("Not found!")); + return false; + } + +} + +void FindReplaceDialog::_prompt_changed() { + + if (prompt->is_pressed()) { + skip->show(); + get_ok()->set_text(TTR("Next")); + selection_only->set_disabled(true); + + } else { + skip->hide(); + get_ok()->set_text(TTR("Replace")); + selection_only->set_disabled(false); + } +} + + +void FindReplaceDialog::_skip_pressed() { + + _replace_skip_callback(); +} + +bool FindReplaceDialog::is_replace_mode() const { + + return replace_text->is_visible_in_tree(); +} + +bool FindReplaceDialog::is_replace_all_mode() const { + + return !prompt->is_pressed(); +} + +bool FindReplaceDialog::is_replace_selection_only() const { + + return selection_only->is_pressed(); +} +void FindReplaceDialog::set_replace_selection_only(bool p_enable){ + + selection_only->set_pressed(p_enable); +} + + +void FindReplaceDialog::ok_pressed() { + + _search_callback(); +} + +void FindReplaceDialog::_search_text_entered(const String& p_text) { + + if (replace_text->is_visible_in_tree()) + return; + emit_signal("search"); + _search(); + +} + +void FindReplaceDialog::_replace_text_entered(const String& p_text) { + + if (!replace_text->is_visible_in_tree()) + return; + + emit_signal("search"); + _replace(); + +} + + +String FindReplaceDialog::get_search_text() const { + + return search_text->get_text(); +} +String FindReplaceDialog::get_replace_text() const { + + return replace_text->get_text(); +} +bool FindReplaceDialog::is_whole_words() const { + + return whole_words->is_pressed(); +} +bool FindReplaceDialog::is_case_sensitive() const { + + return case_sensitive->is_pressed(); + +} +bool FindReplaceDialog::is_backwards() const { + + return backwards->is_pressed(); + +} + +void FindReplaceDialog::set_error(const String& p_error) { + + error_label->set_text(p_error); +} + +void FindReplaceDialog::set_text_edit(TextEdit *p_text_edit) { + + text_edit=p_text_edit; +} + +void FindReplaceDialog::search_next() { + _search(); +} + + +void FindReplaceDialog::_bind_methods() { + + ClassDB::bind_method("_search_text_entered",&FindReplaceDialog::_search_text_entered); + ClassDB::bind_method("_replace_text_entered",&FindReplaceDialog::_replace_text_entered); + ClassDB::bind_method("_prompt_changed",&FindReplaceDialog::_prompt_changed); + ClassDB::bind_method("_skip_pressed",&FindReplaceDialog::_skip_pressed); + ADD_SIGNAL(MethodInfo("search")); + ADD_SIGNAL(MethodInfo("skip")); + +} + +FindReplaceDialog::FindReplaceDialog() { + + set_self_modulate(Color(1,1,1,0.8)); + + VBoxContainer *vb = memnew( VBoxContainer ); + add_child(vb); + + + + search_text = memnew( LineEdit ); + vb->add_margin_child(TTR("Search"),search_text); + search_text->connect("text_entered", this,"_search_text_entered"); + //search_text->set_self_opacity(0.7); + + + + replace_label = memnew( Label); + replace_label->set_text(TTR("Replace By")); + vb->add_child(replace_label); + replace_mc= memnew( MarginContainer); + vb->add_child(replace_mc); + + replace_text = memnew( LineEdit ); + replace_text->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + replace_text->set_begin( Point2(15,132) ); + replace_text->set_end( Point2(15,135) ); + //replace_text->set_self_opacity(0.7); + replace_mc->add_child(replace_text); + + + replace_text->connect("text_entered", this,"_replace_text_entered"); + + + + MarginContainer *opt_mg = memnew( MarginContainer ); + vb->add_child(opt_mg); + VBoxContainer *svb = memnew( VBoxContainer); + opt_mg->add_child(svb); + + svb ->add_child(memnew(Label)); + + whole_words = memnew( CheckButton ); + whole_words->set_text(TTR("Whole Words")); + svb->add_child(whole_words); + + case_sensitive = memnew( CheckButton ); + case_sensitive->set_text(TTR("Case Sensitive")); + svb->add_child(case_sensitive); + + backwards = memnew( CheckButton ); + backwards->set_text(TTR("Backwards")); + svb->add_child(backwards); + + opt_mg = memnew( MarginContainer ); + vb->add_child(opt_mg); + VBoxContainer *rvb = memnew( VBoxContainer); + opt_mg->add_child(rvb); + replace_vb=rvb; + //rvb ->add_child(memnew(HSeparator)); + rvb ->add_child(memnew(Label)); + + prompt = memnew( CheckButton ); + prompt->set_text(TTR("Prompt On Replace")); + rvb->add_child(prompt); + prompt->connect("pressed", this,"_prompt_changed"); + + selection_only = memnew( CheckButton ); + selection_only->set_text(TTR("Selection Only")); + rvb->add_child(selection_only); + + + int margin = get_constant("margin","Dialogs"); + int button_margin = get_constant("button_margin","Dialogs"); + + skip = memnew( Button ); + skip->set_anchor( MARGIN_LEFT, ANCHOR_END ); + skip->set_anchor( MARGIN_TOP, ANCHOR_END ); + skip->set_anchor( MARGIN_RIGHT, ANCHOR_END ); + skip->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); + skip->set_begin( Point2( 70, button_margin ) ); + skip->set_end( Point2( 10, margin ) ); + skip->set_text(TTR("Skip")); + add_child(skip); + skip->connect("pressed", this,"_skip_pressed"); + + + error_label = memnew( Label ); + error_label->set_align(Label::ALIGN_CENTER); + error_label->add_color_override("font_color",Color(1,0.4,0.3)); + error_label->add_color_override("font_color_shadow",Color(0,0,0,0.2)); + error_label->add_constant_override("shadow_as_outline",1); + + vb->add_child(error_label); + + + set_hide_on_ok(false); + +} + + +/*** CODE EDITOR ****/ + +void CodeTextEditor::_text_editor_gui_input(const InputEvent& p_event) { + + if (p_event.type==InputEvent::MOUSE_BUTTON) { + + const InputEventMouseButton& mb=p_event.mouse_button; + + if (mb.pressed && mb.mod.command) { + + if (mb.button_index==BUTTON_WHEEL_UP) { + _zoom_in(); + } else if (mb.button_index==BUTTON_WHEEL_DOWN) { + _zoom_out(); + } + } + } else if (p_event.type==InputEvent::KEY) { + + if (p_event.key.pressed) { + if (ED_IS_SHORTCUT("script_editor/zoom_in", p_event)) { + _zoom_in(); + } + if (ED_IS_SHORTCUT("script_editor/zoom_out", p_event)) { + _zoom_out(); + } + if (ED_IS_SHORTCUT("script_editor/reset_zoom", p_event)) { + _reset_zoom(); + } + } + } +} + +void CodeTextEditor::_zoom_in() { + font_resize_val+=1; + + if (font_resize_timer->get_time_left()==0) + font_resize_timer->start(); +} + +void CodeTextEditor::_zoom_out() { + font_resize_val-=1; + + if (font_resize_timer->get_time_left()==0) + font_resize_timer->start(); +} + +void CodeTextEditor::_reset_zoom() { + Ref font = text_editor->get_font("font"); // reset source font size to default + + if (font.is_valid()) { + EditorSettings::get_singleton()->set("interface/source_font_size",14); + font->set_size(14); + } +} + +void CodeTextEditor::_line_col_changed() { + + line_nb->set_text(itos(text_editor->cursor_get_line() + 1)); + col_nb->set_text(itos(text_editor->cursor_get_column() + 1)); +} + +void CodeTextEditor::_text_changed() { + + code_complete_timer->start(); + idle->start(); +} + +void CodeTextEditor::_code_complete_timer_timeout() { + if (!is_visible_in_tree()) + return; + if (enable_complete_timer) + text_editor->query_code_comple(); +} + +void CodeTextEditor::_complete_request() { + + List entries; + String ctext = text_editor->get_text_for_completion(); + _code_complete_script(ctext,&entries); + if (code_complete_func) { + code_complete_func(code_complete_ud,ctext,&entries); + } + // print_line("COMPLETE: "+p_request); + if (entries.size()==0) + return; + Vector strs; + strs.resize(entries.size()); + int i=0; + for(List::Element *E=entries.front();E;E=E->next()) { + + strs[i++]=E->get(); + } + + text_editor->code_complete(strs); +} + +void CodeTextEditor::_font_resize_timeout() { + + Ref font = text_editor->get_font("font"); + + if (font.is_valid()) { + int size=font->get_size()+font_resize_val; + + if (size>=8 && size<=96) { + EditorSettings::get_singleton()->set("interface/source_font_size",size); + font->set_size(size); + } + + font_resize_val=0; + } +} + +void CodeTextEditor::update_editor_settings() { + + text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); + text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); + text_editor->set_tab_size(EditorSettings::get_singleton()->get("text_editor/indent/tab_size")); + text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); + text_editor->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers")); + text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/line_numbers/line_numbers_zero_padded")); + text_editor->set_show_line_length_guideline(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_length_guideline")); + text_editor->set_line_length_guideline_column(EditorSettings::get_singleton()->get("text_editor/line_numbers/line_length_guideline_column")); + text_editor->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting")); + text_editor->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); + text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink")); + text_editor->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed")); + text_editor->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_breakpoint_gutter")); + text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); +} + +void CodeTextEditor::set_error(const String& p_error) { + + if (p_error!="") { + error->set_text(p_error); + error->show(); + } else { + error->hide(); + } + +} + +void CodeTextEditor::_update_font() { + + // FONTS + String editor_font = EDITOR_DEF("text_editor/theme/font", ""); + bool font_overridden = false; + if (editor_font!="") { + Ref fnt = ResourceLoader::load(editor_font); + if (fnt.is_valid()) { + text_editor->add_font_override("font",fnt); + font_overridden = true; + } + } + if(!font_overridden) { + + text_editor->add_font_override("font",get_font("source","EditorFonts")); + } +} + +void CodeTextEditor::_on_settings_change() { + + _update_font(); + + // AUTO BRACE COMPLETION + text_editor->set_auto_brace_completion( + EDITOR_DEF("text_editor/completion/auto_brace_complete", true) + ); + + code_complete_timer->set_wait_time( + EDITOR_DEF("text_editor/completion/code_complete_delay",.3f) + ); + + enable_complete_timer = EDITOR_DEF("text_editor/completion/enable_code_completion_delay",true); + + // call hint settings + text_editor->set_callhint_settings( + EDITOR_DEF("text_editor/completion/put_callhint_tooltip_below_current_line", true), + EDITOR_DEF("text_editor/completion/callhint_tooltip_offset", Vector2()) + ); +} + +void CodeTextEditor::_text_changed_idle_timeout() { + + + _validate_script(); + emit_signal("validate_script"); +} + +void CodeTextEditor::_notification(int p_what) { + + + if (p_what==EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { + _load_theme_settings(); + emit_signal("load_theme_settings"); + } + if (p_what==NOTIFICATION_THEME_CHANGED) { + _update_font(); + } +} + +void CodeTextEditor::_bind_methods() { + + ClassDB::bind_method("_text_editor_gui_input",&CodeTextEditor::_text_editor_gui_input); + ClassDB::bind_method("_line_col_changed",&CodeTextEditor::_line_col_changed); + ClassDB::bind_method("_text_changed",&CodeTextEditor::_text_changed); + ClassDB::bind_method("_on_settings_change",&CodeTextEditor::_on_settings_change); + ClassDB::bind_method("_text_changed_idle_timeout",&CodeTextEditor::_text_changed_idle_timeout); + ClassDB::bind_method("_code_complete_timer_timeout",&CodeTextEditor::_code_complete_timer_timeout); + ClassDB::bind_method("_complete_request",&CodeTextEditor::_complete_request); + ClassDB::bind_method("_font_resize_timeout",&CodeTextEditor::_font_resize_timeout); + + ADD_SIGNAL(MethodInfo("validate_script")); + ADD_SIGNAL(MethodInfo("load_theme_settings")); + +} + +void CodeTextEditor::set_code_complete_func(CodeTextEditorCodeCompleteFunc p_code_complete_func,void * p_ud) { + code_complete_func=p_code_complete_func; + code_complete_ud=p_ud; +} + + +CodeTextEditor::CodeTextEditor() { + + code_complete_func=NULL; + ED_SHORTCUT("script_editor/zoom_in", TTR("Zoom In"), KEY_MASK_CMD|KEY_EQUAL); + ED_SHORTCUT("script_editor/zoom_out", TTR("Zoom Out"), KEY_MASK_CMD|KEY_MINUS); + ED_SHORTCUT("script_editor/reset_zoom", TTR("Reset Zoom"), KEY_MASK_CMD|KEY_0); + + find_replace_bar = memnew( FindReplaceBar ); + add_child(find_replace_bar); + find_replace_bar->set_h_size_flags(SIZE_EXPAND_FILL); + find_replace_bar->hide(); + + text_editor = memnew( TextEdit ); + add_child(text_editor); + text_editor->set_v_size_flags(SIZE_EXPAND_FILL); + + find_replace_bar->set_text_edit(text_editor); + + text_editor->set_show_line_numbers(true); + text_editor->set_brace_matching(true); + text_editor->set_auto_indent(true); + + MarginContainer *status_mc = memnew( MarginContainer ); + add_child(status_mc); + status_mc->set("custom_constants/margin_left", 2); + status_mc->set("custom_constants/margin_top", 5); + status_mc->set("custom_constants/margin_right", 2); + status_mc->set("custom_constants/margin_bottom", 1); + + HBoxContainer *status_bar = memnew( HBoxContainer ); + status_mc->add_child(status_bar); + status_bar->set_h_size_flags(SIZE_EXPAND_FILL); + status_bar->add_child( memnew( Label ) ); //to keep the height if the other labels are not visible + + idle = memnew( Timer ); + add_child(idle); + idle->set_one_shot(true); + idle->set_wait_time(EDITOR_DEF("text_editor/completion/idle_parse_delay",2)); + + code_complete_timer = memnew(Timer); + add_child(code_complete_timer); + code_complete_timer->set_one_shot(true); + enable_complete_timer = EDITOR_DEF("text_editor/completion/enable_code_completion_delay",true); + + code_complete_timer->set_wait_time(EDITOR_DEF("text_editor/completion/code_complete_delay",.3f)); + + error = memnew( Label ); + status_bar->add_child(error); + error->hide(); + error->set_valign(Label::VALIGN_CENTER); + error->add_color_override("font_color",Color(1,0.7,0.6,0.9)); + + status_bar->add_spacer(); + + Label *line_txt = memnew( Label ); + status_bar->add_child(line_txt); + line_txt->set_align(Label::ALIGN_RIGHT); + line_txt->set_valign(Label::VALIGN_CENTER); + line_txt->set_v_size_flags(SIZE_FILL); + line_txt->set_text(TTR("Line:")); + + line_nb = memnew( Label ); + status_bar->add_child(line_nb); + line_nb->set_valign(Label::VALIGN_CENTER); + line_nb->set_v_size_flags(SIZE_FILL); + line_nb->set_autowrap(true); // workaround to prevent resizing the label on each change + line_nb->set_custom_minimum_size(Size2(40,1)*EDSCALE); + + Label *col_txt = memnew( Label ); + status_bar->add_child(col_txt); + col_txt->set_align(Label::ALIGN_RIGHT); + col_txt->set_valign(Label::VALIGN_CENTER); + col_txt->set_v_size_flags(SIZE_FILL); + col_txt->set_text(TTR("Col:")); + + col_nb = memnew( Label ); + status_bar->add_child(col_nb); + col_nb->set_valign(Label::VALIGN_CENTER); + col_nb->set_v_size_flags(SIZE_FILL); + col_nb->set_autowrap(true); // workaround to prevent resizing the label on each change + col_nb->set_custom_minimum_size(Size2(40,1)*EDSCALE); + + text_editor->connect("gui_input", this,"_text_editor_gui_input"); + text_editor->connect("cursor_changed", this,"_line_col_changed"); + text_editor->connect("text_changed", this,"_text_changed"); + text_editor->connect("request_completion", this,"_complete_request"); + Vector cs; + cs.push_back("."); + cs.push_back(","); + cs.push_back("("); + cs.push_back("$"); + text_editor->set_completion(true,cs); + idle->connect("timeout", this,"_text_changed_idle_timeout"); + + code_complete_timer->connect("timeout", this,"_code_complete_timer_timeout"); + + font_resize_val=0; + font_resize_timer = memnew(Timer); + add_child(font_resize_timer); + font_resize_timer->set_one_shot(true); + font_resize_timer->set_wait_time(0.07); + font_resize_timer->connect("timeout", this, "_font_resize_timeout"); + + EditorSettings::get_singleton()->connect("settings_changed",this,"_on_settings_change"); +} diff --git a/editor/code_editor.h b/editor/code_editor.h new file mode 100644 index 00000000000..7582985d4cb --- /dev/null +++ b/editor/code_editor.h @@ -0,0 +1,261 @@ +/*************************************************************************/ +/* code_editor.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ +#ifndef CODE_EDITOR_H +#define CODE_EDITOR_H + +#include "editor/editor_plugin.h" +#include "scene/gui/text_edit.h" +#include "scene/gui/dialogs.h" +#include "scene/main/timer.h" +#include "scene/gui/tool_button.h" +#include "scene/gui/check_button.h" +#include "scene/gui/check_box.h" +#include "scene/gui/line_edit.h" + + + +class GotoLineDialog : public ConfirmationDialog { + + GDCLASS(GotoLineDialog,ConfirmationDialog); + + Label *line_label; + LineEdit *line; + + TextEdit *text_editor; + + virtual void ok_pressed(); +public: + + void popup_find_line(TextEdit *p_edit); + int get_line() const; + + + void set_text_editor(TextEdit *p_text_editor); + GotoLineDialog(); +}; + +class FindReplaceBar : public HBoxContainer { + + GDCLASS(FindReplaceBar,HBoxContainer); + + LineEdit *search_text; + ToolButton *find_prev; + ToolButton *find_next; + CheckBox *case_sensitive; + CheckBox *whole_words; + Label *error_label; + TextureButton *hide_button; + + LineEdit *replace_text; + Button *replace; + Button *replace_all; + CheckBox *selection_only; + + VBoxContainer *text_vbc; + HBoxContainer *replace_hbc; + HBoxContainer *replace_options_hbc; + + TextEdit *text_edit; + + int result_line; + int result_col; + + bool replace_all_mode; + bool preserve_cursor; + + void _get_search_from(int& r_line, int& r_col); + + void _show_search(); + void _hide_bar(); + + void _editor_text_changed(); + void _search_options_changed(bool p_pressed); + void _search_text_changed(const String& p_text); + void _search_text_entered(const String& p_text); + void _replace_text_entered(const String& p_text); + +protected: + void _notification(int p_what); + void _unhandled_input(const InputEvent &p_event); + + bool _search(uint32_t p_flags, int p_from_line, int p_from_col); + + void _replace(); + void _replace_all(); + + static void _bind_methods(); + +public: + String get_search_text() const; + String get_replace_text() const; + + bool is_case_sensitive() const; + bool is_whole_words() const; + bool is_selection_only() const; + void set_error(const String& p_label); + + void set_text_edit(TextEdit *p_text_edit); + + void popup_search(); + void popup_replace(); + + bool search_current(); + bool search_prev(); + bool search_next(); + + FindReplaceBar(); +}; + +class FindReplaceDialog : public ConfirmationDialog { + + GDCLASS(FindReplaceDialog,ConfirmationDialog); + + LineEdit *search_text; + LineEdit *replace_text; + CheckButton *whole_words; + CheckButton *case_sensitive; + CheckButton *backwards; + CheckButton *prompt; + CheckButton *selection_only; + Button *skip; + Label *error_label; + MarginContainer *replace_mc; + Label *replace_label; + VBoxContainer *replace_vb; + + void _search_text_entered(const String& p_text); + void _replace_text_entered(const String& p_text); + void _prompt_changed(); + void _skip_pressed(); + + + TextEdit *text_edit; +protected: + + void _search_callback(); + void _replace_skip_callback(); + + bool _search(); + void _replace(); + + virtual void ok_pressed(); + static void _bind_methods(); +public: + + String get_search_text() const; + String get_replace_text() const; + bool is_whole_words() const; + bool is_case_sensitive() const; + bool is_backwards() const; + bool is_replace_mode() const; + bool is_replace_all_mode() const; + bool is_replace_selection_only() const; + void set_replace_selection_only(bool p_enable); + + void set_error(const String& p_error); + + void popup_search(); + void popup_replace(); + + void set_text_edit(TextEdit *p_text_edit); + + void search_next(); + FindReplaceDialog(); +}; + + +typedef void (*CodeTextEditorCodeCompleteFunc)(void* p_ud,const String& p_code, List* r_options); + +class CodeTextEditor : public VBoxContainer { + + GDCLASS(CodeTextEditor,VBoxContainer); + + TextEdit *text_editor; + FindReplaceBar *find_replace_bar; + + Label *line_nb; + Label *col_nb; + Label *info; + Timer *idle; + Timer *code_complete_timer; + bool enable_complete_timer; + + Timer *font_resize_timer; + int font_resize_val; + + Label *error; + + void _on_settings_change(); + + void _update_font(); + void _complete_request(); + void _font_resize_timeout(); + + void _text_editor_gui_input(const InputEvent& p_event); + void _zoom_in(); + void _zoom_out(); + void _reset_zoom(); + + + CodeTextEditorCodeCompleteFunc code_complete_func; + void *code_complete_ud; + +protected: + + + virtual void _load_theme_settings() {} + virtual void _validate_script() {} + virtual void _code_complete_script(const String& p_code, List* r_options) {} + + void _text_changed_idle_timeout(); + void _code_complete_timer_timeout(); + void _text_changed(); + void _line_col_changed(); + void _notification(int); + static void _bind_methods(); + +public: + + void update_editor_settings(); + void set_error(const String& p_error); + void update_line_and_column() { _line_col_changed(); } + TextEdit *get_text_edit() { return text_editor; } + FindReplaceBar *get_find_replace_bar() { return find_replace_bar; } + virtual void apply_code() {} + + + void set_code_complete_func(CodeTextEditorCodeCompleteFunc p_code_complete_func, void * p_ud); + + + CodeTextEditor(); +}; + + + +#endif // CODE_EDITOR_H diff --git a/tools/editor/collada/SCsub b/editor/collada/SCsub similarity index 100% rename from tools/editor/collada/SCsub rename to editor/collada/SCsub diff --git a/tools/editor/collada/collada.cpp b/editor/collada/collada.cpp similarity index 100% rename from tools/editor/collada/collada.cpp rename to editor/collada/collada.cpp diff --git a/tools/editor/collada/collada.h b/editor/collada/collada.h similarity index 100% rename from tools/editor/collada/collada.h rename to editor/collada/collada.h diff --git a/tools/editor/connections_dialog.cpp b/editor/connections_dialog.cpp similarity index 100% rename from tools/editor/connections_dialog.cpp rename to editor/connections_dialog.cpp diff --git a/editor/connections_dialog.h b/editor/connections_dialog.h new file mode 100644 index 00000000000..6407b83f6e9 --- /dev/null +++ b/editor/connections_dialog.h @@ -0,0 +1,134 @@ +/*************************************************************************/ +/* connections_dialog.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ +#ifndef CONNECTIONS_DIALOG_H +#define CONNECTIONS_DIALOG_H + +#include "scene/gui/popup.h" +#include "scene/gui/button.h" +#include "scene/gui/check_button.h" +#include "scene/gui/tree.h" +#include "scene/gui/dialogs.h" +#include "scene/gui/menu_button.h" +#include "scene/gui/line_edit.h" +#include "editor/scene_tree_editor.h" +#include "editor/property_editor.h" +#include "undo_redo.h" + +/** +@author Juan Linietsky +*/ + +class ConnectDialogBinds; + +class ConnectDialog : public ConfirmationDialog { + + GDCLASS( ConnectDialog, ConfirmationDialog ); + + + ConfirmationDialog *error; + LineEdit *dst_path; + LineEdit *dst_method; + SceneTreeEditor *tree; + //MenuButton *dst_method_list; + OptionButton *type_list; + CheckButton *deferred; + CheckButton *oneshot; + CheckButton *make_callback; + PropertyEditor *bind_editor; + Node *node; + ConnectDialogBinds *cdbinds; + void ok_pressed(); + void _cancel_pressed(); + void _tree_node_selected(); + void _dst_method_list_selected(int p_idx); + void _add_bind(); + void _remove_bind(); + +protected: + + void _notification(int p_what); + static void _bind_methods(); +public: + + + bool get_make_callback() { return make_callback->is_visible() && make_callback->is_pressed(); } + NodePath get_dst_path() const; + StringName get_dst_method() const; + bool get_deferred() const; + bool get_oneshot() const; + Vector get_binds() const; + void set_dst_method(const StringName& p_method); + void set_dst_node(Node* p_node); + + //Button *get_ok() { return ok; } + //Button *get_cancel() { return cancel; } + void edit(Node *p_node); + + ConnectDialog(); + ~ConnectDialog(); + +}; + +class ConnectionsDock : public VBoxContainer { + + GDCLASS( ConnectionsDock , VBoxContainer ); + + Button *connect_button; + EditorNode *editor; + Node *node; + Tree *tree; + ConfirmationDialog *remove_confirm; + ConnectDialog *connect_dialog; + + void update_tree(); + + void _close(); + void _connect(); + void _something_selected(); + void _something_activated(); + UndoRedo *undo_redo; + +protected: + + void _connect_pressed(); + void _notification(int p_what); + static void _bind_methods(); +public: + + void set_undoredo(UndoRedo *p_undo_redo) { undo_redo=p_undo_redo; } + + void set_node(Node* p_node); + String get_selected_type(); + + ConnectionsDock(EditorNode *p_editor=NULL); + ~ConnectionsDock(); + +}; + +#endif diff --git a/tools/editor/create_dialog.cpp b/editor/create_dialog.cpp similarity index 100% rename from tools/editor/create_dialog.cpp rename to editor/create_dialog.cpp diff --git a/tools/editor/create_dialog.h b/editor/create_dialog.h similarity index 100% rename from tools/editor/create_dialog.h rename to editor/create_dialog.h diff --git a/tools/editor/dependency_editor.cpp b/editor/dependency_editor.cpp similarity index 100% rename from tools/editor/dependency_editor.cpp rename to editor/dependency_editor.cpp diff --git a/tools/editor/dependency_editor.h b/editor/dependency_editor.h similarity index 100% rename from tools/editor/dependency_editor.h rename to editor/dependency_editor.h diff --git a/tools/editor/doc/SCsub b/editor/doc/SCsub similarity index 100% rename from tools/editor/doc/SCsub rename to editor/doc/SCsub diff --git a/tools/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp similarity index 100% rename from tools/editor/doc/doc_data.cpp rename to editor/doc/doc_data.cpp diff --git a/tools/editor/doc/doc_data.h b/editor/doc/doc_data.h similarity index 100% rename from tools/editor/doc/doc_data.h rename to editor/doc/doc_data.h diff --git a/tools/editor/doc/doc_dump.cpp b/editor/doc/doc_dump.cpp similarity index 100% rename from tools/editor/doc/doc_dump.cpp rename to editor/doc/doc_dump.cpp diff --git a/tools/editor/doc/doc_dump.h b/editor/doc/doc_dump.h similarity index 100% rename from tools/editor/doc/doc_dump.h rename to editor/doc/doc_dump.h diff --git a/tools/editor/doc_code_font.h b/editor/doc_code_font.h similarity index 100% rename from tools/editor/doc_code_font.h rename to editor/doc_code_font.h diff --git a/tools/editor/doc_font.h b/editor/doc_font.h similarity index 100% rename from tools/editor/doc_font.h rename to editor/doc_font.h diff --git a/tools/editor/doc_title_font.h b/editor/doc_title_font.h similarity index 100% rename from tools/editor/doc_title_font.h rename to editor/doc_title_font.h diff --git a/tools/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp similarity index 100% rename from tools/editor/editor_asset_installer.cpp rename to editor/editor_asset_installer.cpp diff --git a/tools/editor/editor_asset_installer.h b/editor/editor_asset_installer.h similarity index 100% rename from tools/editor/editor_asset_installer.h rename to editor/editor_asset_installer.h diff --git a/tools/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp similarity index 100% rename from tools/editor/editor_audio_buses.cpp rename to editor/editor_audio_buses.cpp diff --git a/editor/editor_audio_buses.h b/editor/editor_audio_buses.h new file mode 100644 index 00000000000..4ac8b27004a --- /dev/null +++ b/editor/editor_audio_buses.h @@ -0,0 +1,186 @@ +#ifndef EDITORAUDIOBUSES_H +#define EDITORAUDIOBUSES_H + + +#include "scene/gui/box_container.h" +#include "scene/gui/button.h" +#include "scene/gui/tool_button.h" +#include "scene/gui/scroll_container.h" +#include "scene/gui/panel_container.h" +#include "scene/gui/slider.h" +#include "scene/gui/texture_progress.h" +#include "scene/gui/texture_rect.h" +#include "scene/gui/line_edit.h" +#include "scene/gui/tree.h" +#include "scene/gui/option_button.h" +#include "scene/gui/panel.h" +#include "editor/editor_file_dialog.h" +#include "editor_plugin.h" + +class EditorAudioBuses; + +class EditorAudioBus : public PanelContainer { + + GDCLASS( EditorAudioBus, PanelContainer ) + + bool prev_active; + float peak_l; + float peak_r; + + Ref disabled_vu; + LineEdit *track_name; + VSlider *slider; + TextureProgress *vu_l; + TextureProgress *vu_r; + TextureRect *scale; + OptionButton *send; + + PopupMenu *effect_options; + PopupMenu *delete_popup; + PopupMenu *delete_effect_popup; + + Button *solo; + Button *mute; + Button *bypass; + + Tree *effects; + + bool updating_bus; + + void _gui_input(const InputEvent& p_event); + void _delete_pressed(int p_option); + + void _name_changed(const String& p_new_name); + void _name_focus_exit() { _name_changed(track_name->get_text()); } + void _volume_db_changed(float p_db); + void _solo_toggled(); + void _mute_toggled(); + void _bypass_toggled(); + void _send_selected(int p_which); + void _effect_edited(); + void _effect_add(int p_which); + void _effect_selected(); + void _delete_effect_pressed(int p_option); + void _effect_rmb(const Vector2& p_pos); + + + virtual Variant get_drag_data(const Point2& p_point); + virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const; + virtual void drop_data(const Point2& p_point,const Variant& p_data); + + + Variant get_drag_data_fw(const Point2& p_point,Control* p_from); + bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const; + void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from); + +friend class EditorAudioBuses; + + EditorAudioBuses *buses; + +protected: + + static void _bind_methods(); + void _notification(int p_what); +public: + + void update_bus(); + void update_send(); + + EditorAudioBus(EditorAudioBuses *p_buses=NULL); +}; + + +class EditorAudioBusDrop : public Panel { + + GDCLASS(EditorAudioBusDrop,Panel); + + virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const; + virtual void drop_data(const Point2& p_point,const Variant& p_data); +protected: + + static void _bind_methods(); +public: + + EditorAudioBusDrop(); +}; + +class EditorAudioBuses : public VBoxContainer { + + GDCLASS(EditorAudioBuses,VBoxContainer) + + HBoxContainer *top_hb; + + Button *add; + ScrollContainer *bus_scroll; + HBoxContainer *bus_hb; + + EditorAudioBusDrop *drop_end; + + Button *file; + Button *load; + Button *save_as; + Button *_default; + Button *_new; + + Timer *save_timer; + String edited_path; + + void _add_bus(); + void _update_buses(); + void _update_bus(int p_index); + void _update_sends(); + + void _delete_bus(Object* p_which); + void _duplicate_bus(int p_which); + + + void _request_drop_end(); + void _drop_at_index(int p_bus,int p_index); + + void _server_save(); + + void _select_layout(); + void _load_layout(); + void _save_as_layout(); + void _load_default_layout(); + void _new_layout(); + + EditorFileDialog *file_dialog; + bool new_layout; + + void _file_dialog_callback(const String& p_string); + +protected: + + static void _bind_methods(); + void _notification(int p_what); +public: + + void open_layout(const String& p_path); + + static EditorAudioBuses* register_editor(); + + EditorAudioBuses(); +}; + + + +class AudioBusesEditorPlugin : public EditorPlugin { + + GDCLASS( AudioBusesEditorPlugin, EditorPlugin ); + + EditorAudioBuses *audio_bus_editor; +public: + + virtual String get_name() const { return "SampleLibrary"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); + + AudioBusesEditorPlugin(EditorAudioBuses *p_node); + ~AudioBusesEditorPlugin(); + +}; + +#endif // EDITORAUDIOBUSES_H diff --git a/tools/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp similarity index 100% rename from tools/editor/editor_autoload_settings.cpp rename to editor/editor_autoload_settings.cpp diff --git a/tools/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h similarity index 100% rename from tools/editor/editor_autoload_settings.h rename to editor/editor_autoload_settings.h diff --git a/tools/editor/editor_data.cpp b/editor/editor_data.cpp similarity index 100% rename from tools/editor/editor_data.cpp rename to editor/editor_data.cpp diff --git a/editor/editor_data.h b/editor/editor_data.h new file mode 100644 index 00000000000..46227916532 --- /dev/null +++ b/editor/editor_data.h @@ -0,0 +1,269 @@ +/*************************************************************************/ +/* editor_data.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ +#ifndef EDITOR_DATA_H +#define EDITOR_DATA_H + +#include "editor/editor_plugin.h" +#include "scene/resources/texture.h" +#include "list.h" +#include "undo_redo.h" +#include "pair.h" + +class EditorHistory { + + enum { + + HISTORY_MAX=64 + }; + + struct Obj { + + REF ref; + ObjectID object; + String property; + }; + + struct History { + + Vector path; + int level; + }; +friend class EditorData; + + Vector history; + int current; + + //Vector editor_plugins; + + struct PropertyData { + + String name; + Variant value; + }; + + + void _cleanup_history(); + + void _add_object(ObjectID p_object,const String& p_property,int p_level_change); + +public: + + bool is_at_begining() const; + bool is_at_end() const; + + void add_object(ObjectID p_object); + void add_object(ObjectID p_object,const String& p_subprop); + void add_object(ObjectID p_object,int p_relevel); + + int get_history_len(); + int get_history_pos(); + ObjectID get_history_obj(int p_obj) const; + + bool next(); + bool previous(); + ObjectID get_current(); + + int get_path_size() const; + ObjectID get_path_object(int p_index) const; + String get_path_property(int p_index) const; + + void clear(); + + EditorHistory(); +}; + +class EditorSelection; + +class EditorData { + +public: + struct CustomType { + + String name; + Ref