animation_player_editor_plugin.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  1. /*************************************************************************/
  2. /* animation_player_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "animation_player_editor_plugin.h"
  30. #include "io/resource_loader.h"
  31. #include "os/keyboard.h"
  32. #include "tools/editor/editor_settings.h"
  33. void AnimationPlayerEditor::_node_removed(Node *p_node) {
  34. if (player && player == p_node) {
  35. player=NULL;
  36. hide();
  37. set_process(false);
  38. if (edit_anim->is_pressed()) {
  39. editor->get_animation_editor()->set_animation(Ref<Animation>());
  40. editor->get_animation_editor()->set_root(NULL);
  41. editor->animation_editor_make_visible(false);
  42. edit_anim->set_pressed(false);
  43. }
  44. }
  45. }
  46. void AnimationPlayerEditor::_input_event(InputEvent p_event) {
  47. }
  48. void AnimationPlayerEditor::_notification(int p_what) {
  49. if (p_what==NOTIFICATION_PROCESS) {
  50. if (!player)
  51. return;
  52. updating = true;
  53. if (player->is_playing()) {
  54. {
  55. String animname=player->get_current_animation();
  56. if (player->has_animation(animname)) {
  57. Ref<Animation> anim = player->get_animation(animname);
  58. if (!anim.is_null()) {
  59. seek->set_max(anim->get_length());
  60. }
  61. }
  62. }
  63. seek->set_val(player->get_current_animation_pos());
  64. if (edit_anim->is_pressed())
  65. editor->get_animation_editor()->set_anim_pos(player->get_current_animation_pos());
  66. EditorNode::get_singleton()->get_property_editor()->refresh();
  67. } else if (last_active) {
  68. //need the last frame after it stopped
  69. seek->set_val(player->get_current_animation_pos());
  70. }
  71. last_active=player->is_playing();
  72. //seek->set_val(player->get_pos());
  73. updating = false;
  74. }
  75. if (p_what==NOTIFICATION_ENTER_TREE) {
  76. editor->connect("hide_animation_player_editors",this,"_hide_anim_editors");
  77. add_anim->set_icon( get_icon("New","EditorIcons") );
  78. rename_anim->set_icon( get_icon("Rename","EditorIcons") );
  79. duplicate_anim->set_icon( get_icon("Duplicate","EditorIcons") );
  80. autoplay->set_icon( get_icon("AutoPlay","EditorIcons") );
  81. load_anim->set_icon( get_icon("Folder","EditorIcons") );
  82. remove_anim->set_icon( get_icon("Remove","EditorIcons") );
  83. edit_anim->set_icon( get_icon("Edit","EditorIcons") );
  84. blend_anim->set_icon( get_icon("Blend","EditorIcons") );
  85. play->set_icon( get_icon("PlayStart","EditorIcons") );
  86. play_from->set_icon( get_icon("Play","EditorIcons") );
  87. play_bw->set_icon( get_icon("PlayStartBackwards","EditorIcons") );
  88. play_bw_from->set_icon( get_icon("PlayBackwards","EditorIcons") );
  89. autoplay_icon=get_icon("AutoPlay","EditorIcons");
  90. stop->set_icon( get_icon("Stop","EditorIcons") );
  91. resource_edit_anim->set_icon( get_icon("EditResource","EditorIcons") );
  92. pin->set_normal_texture(get_icon("Pin","EditorIcons") );
  93. pin->set_pressed_texture( get_icon("PinPressed","EditorIcons") );
  94. tool_anim->set_icon(get_icon("Tools","EditorIcons"));
  95. tool_anim->get_popup()->connect("item_pressed",this,"_animation_tool_menu");
  96. blend_editor.next->connect("text_changed",this,"_blend_editor_next_changed");
  97. /*
  98. anim_editor_load->set_normal_texture( get_icon("AnimGet","EditorIcons"));
  99. anim_editor_store->set_normal_texture( get_icon("AnimSet","EditorIcons"));
  100. anim_editor_load->set_pressed_texture( get_icon("AnimGet","EditorIcons"));
  101. anim_editor_store->set_pressed_texture( get_icon("AnimSet","EditorIcons"));
  102. anim_editor_load->set_hover_texture( get_icon("AnimGetHl","EditorIcons"));
  103. anim_editor_store->set_hover_texture( get_icon("AnimSetHl","EditorIcons"));
  104. */
  105. }
  106. if (p_what==NOTIFICATION_READY) {
  107. get_tree()->connect("node_removed",this,"_node_removed");
  108. }
  109. if (p_what==NOTIFICATION_DRAW) {
  110. }
  111. }
  112. void AnimationPlayerEditor::_autoplay_pressed() {
  113. if (updating)
  114. return;
  115. if (animation->get_item_count()==0) {
  116. return;
  117. }
  118. String current = animation->get_item_text( animation->get_selected() );
  119. if (player->get_autoplay()==current) {
  120. //unset
  121. undo_redo->create_action("Toggle Autoplay");
  122. undo_redo->add_do_method(player,"set_autoplay","");
  123. undo_redo->add_undo_method(player,"set_autoplay",player->get_autoplay());
  124. undo_redo->add_do_method(this,"_animation_player_changed",player);
  125. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  126. undo_redo->commit_action();
  127. } else {
  128. //set
  129. undo_redo->create_action("Toggle Autoplay");
  130. undo_redo->add_do_method(player,"set_autoplay",current);
  131. undo_redo->add_undo_method(player,"set_autoplay",player->get_autoplay());
  132. undo_redo->add_do_method(this,"_animation_player_changed",player);
  133. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  134. undo_redo->commit_action();
  135. }
  136. }
  137. void AnimationPlayerEditor::_play_pressed() {
  138. String current;
  139. if (animation->get_selected()>=0 && animation->get_selected()<animation->get_item_count()) {
  140. current = animation->get_item_text( animation->get_selected() );
  141. }
  142. if (current!="") {
  143. if (current==player->get_current_animation())
  144. player->stop(); //so it wont blend with itself
  145. player->play(current );
  146. }
  147. //unstop
  148. stop->set_pressed(false);
  149. //unpause
  150. //pause->set_pressed(false);
  151. }
  152. void AnimationPlayerEditor::_play_from_pressed() {
  153. String current;
  154. if (animation->get_selected()>=0 && animation->get_selected()<animation->get_item_count()) {
  155. current = animation->get_item_text( animation->get_selected() );
  156. }
  157. if (current!="") {
  158. float time = player->get_current_animation_pos();
  159. if (current==player->get_current_animation() && player->is_playing()) {
  160. player->stop(); //so it wont blend with itself
  161. }
  162. player->play( current );
  163. player->seek(time);
  164. }
  165. //unstop
  166. stop->set_pressed(false);
  167. //unpause
  168. //pause->set_pressed(false);
  169. }
  170. void AnimationPlayerEditor::_play_bw_pressed() {
  171. String current;
  172. if (animation->get_selected()>=0 && animation->get_selected()<animation->get_item_count()) {
  173. current = animation->get_item_text( animation->get_selected() );
  174. }
  175. if (current!="") {
  176. if (current==player->get_current_animation())
  177. player->stop(); //so it wont blend with itself
  178. player->play(current,-1,-1,true);
  179. }
  180. //unstop
  181. stop->set_pressed(false);
  182. //unpause
  183. //pause->set_pressed(false);
  184. }
  185. void AnimationPlayerEditor::_play_bw_from_pressed() {
  186. String current;
  187. if (animation->get_selected()>=0 && animation->get_selected()<animation->get_item_count()) {
  188. current = animation->get_item_text( animation->get_selected() );
  189. }
  190. if (current!="") {
  191. float time = player->get_current_animation_pos();
  192. if (current==player->get_current_animation())
  193. player->stop(); //so it wont blend with itself
  194. player->play(current,-1,-1,true);
  195. player->seek(time);
  196. }
  197. //unstop
  198. stop->set_pressed(false);
  199. //unpause
  200. //pause->set_pressed(false);
  201. }
  202. void AnimationPlayerEditor::_stop_pressed() {
  203. player->stop(false);
  204. play->set_pressed(false);
  205. stop->set_pressed(true);
  206. //pause->set_pressed(false);
  207. //player->set_pause(false);
  208. }
  209. void AnimationPlayerEditor::_pause_pressed() {
  210. //player->set_pause( pause->is_pressed() );
  211. }
  212. void AnimationPlayerEditor::_animation_selected(int p_which) {
  213. if (updating)
  214. return;
  215. // when selecting an animation, the idea is that the only interesting behavior
  216. // ui-wise is that it should play/blend the next one if currently playing
  217. String current;
  218. if (animation->get_selected()>=0 && animation->get_selected()<animation->get_item_count()) {
  219. current = animation->get_item_text( animation->get_selected() );
  220. }
  221. if (current!="") {
  222. player->set_current_animation( current );
  223. Ref<Animation> anim = player->get_animation(current);
  224. if (edit_anim->is_pressed()) {
  225. Ref<Animation> anim = player->get_animation(current);
  226. editor->get_animation_editor()->set_animation(anim);
  227. Node *root = player->get_node(player->get_root());
  228. if (root) {
  229. editor->get_animation_editor()->set_root(root);
  230. }
  231. }
  232. seek->set_max(anim->get_length());
  233. } else {
  234. if (edit_anim->is_pressed()) {
  235. editor->get_animation_editor()->set_animation(Ref<Animation>());
  236. editor->get_animation_editor()->set_root(NULL);
  237. }
  238. }
  239. autoplay->set_pressed(current==player->get_autoplay());
  240. }
  241. void AnimationPlayerEditor::_animation_new() {
  242. renaming=false;
  243. name_title->set_text("New Animation Name:");
  244. int count=1;
  245. String base="New Anim";
  246. while(true) {
  247. String attempt = base;
  248. if (count>1)
  249. attempt+=" ("+itos(count)+")";
  250. if (player->has_animation(attempt)) {
  251. count++;
  252. continue;
  253. }
  254. base=attempt;
  255. break;
  256. }
  257. name->set_text(base);
  258. name_dialog->popup_centered(Size2(300,90));
  259. name->select_all();
  260. name->grab_focus();
  261. }
  262. void AnimationPlayerEditor::_animation_rename() {
  263. if (animation->get_item_count()==0)
  264. return;
  265. int selected = animation->get_selected();
  266. String selected_name = animation->get_item_text(selected);
  267. name_title->set_text("Change Animation Name:");
  268. name->set_text(selected_name);
  269. renaming=true;
  270. name_dialog->popup_centered(Size2(300,90));
  271. name->select_all();
  272. name->grab_focus();
  273. }
  274. void AnimationPlayerEditor::_animation_load() {
  275. ERR_FAIL_COND(!player);
  276. file->set_mode( EditorFileDialog::MODE_OPEN_FILE );
  277. file->clear_filters();
  278. List<String> extensions;
  279. ResourceLoader::get_recognized_extensions_for_type("Animation",&extensions);
  280. for (List<String>::Element *E=extensions.front();E;E=E->next()) {
  281. file->add_filter("*."+E->get()+" ; "+E->get().to_upper() );
  282. }
  283. file->popup_centered_ratio();
  284. }
  285. void AnimationPlayerEditor::_animation_remove() {
  286. if (animation->get_item_count()==0)
  287. return;
  288. String current = animation->get_item_text(animation->get_selected());
  289. Ref<Animation> anim = player->get_animation(current);
  290. undo_redo->create_action("Remove Animation");
  291. undo_redo->add_do_method(player,"remove_animation",current);
  292. undo_redo->add_undo_method(player,"add_animation",current,anim);
  293. undo_redo->add_do_method(this,"_animation_player_changed",player);
  294. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  295. undo_redo->commit_action();
  296. }
  297. void AnimationPlayerEditor::_select_anim_by_name(const String& p_anim) {
  298. int idx=-1;
  299. for(int i=0;i<animation->get_item_count();i++) {
  300. if (animation->get_item_text(i)==p_anim) {
  301. idx=i;
  302. break;
  303. }
  304. }
  305. ERR_FAIL_COND(idx==-1);
  306. animation->select(idx);
  307. _animation_selected(idx);
  308. }
  309. void AnimationPlayerEditor::_animation_name_edited() {
  310. player->stop();
  311. String new_name = name->get_text();
  312. if (new_name=="" || new_name.find(":")!=-1 || new_name.find("/")!=-1) {
  313. error_dialog->set_text("ERROR: Invalid animation name!");
  314. error_dialog->popup_centered_minsize();
  315. return;
  316. }
  317. if (renaming && animation->get_item_count()>0 && animation->get_item_text(animation->get_selected())==new_name) {
  318. name_dialog->hide();
  319. return;
  320. }
  321. if (player->has_animation(new_name)) {
  322. error_dialog->set_text("ERROR: Animation Name Already Exists!");
  323. error_dialog->popup_centered_minsize();
  324. return;
  325. }
  326. if (renaming) {
  327. String current = animation->get_item_text(animation->get_selected());
  328. Ref<Animation> anim = player->get_animation(current);
  329. undo_redo->create_action("Rename Animation");
  330. undo_redo->add_do_method(player,"rename_animation",current,new_name);
  331. undo_redo->add_do_method(anim.ptr(),"set_name",new_name);
  332. undo_redo->add_undo_method(player,"rename_animation",new_name,current);
  333. undo_redo->add_undo_method(anim.ptr(),"set_name",current);
  334. undo_redo->add_do_method(this,"_animation_player_changed",player);
  335. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  336. undo_redo->commit_action();
  337. _select_anim_by_name(new_name);
  338. } else {
  339. Ref<Animation> new_anim = Ref<Animation>(memnew( Animation ));
  340. new_anim->set_name(new_name);
  341. undo_redo->create_action("Add Animation");
  342. undo_redo->add_do_method(player,"add_animation",new_name,new_anim);
  343. undo_redo->add_undo_method(player,"remove_animation",new_name);
  344. undo_redo->add_do_method(this,"_animation_player_changed",player);
  345. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  346. undo_redo->commit_action();
  347. _select_anim_by_name(new_name);
  348. }
  349. name_dialog->hide();
  350. }
  351. void AnimationPlayerEditor::_blend_editor_next_changed(const String& p_string) {
  352. if (animation->get_item_count()==0)
  353. return;
  354. String current = animation->get_item_text(animation->get_selected());
  355. player->animation_set_next(current,p_string);
  356. }
  357. void AnimationPlayerEditor::_animation_blend() {
  358. if (updating_blends)
  359. return;
  360. blend_editor.tree->clear();
  361. if (animation->get_item_count()==0)
  362. return;
  363. String current = animation->get_item_text(animation->get_selected());
  364. blend_editor.dialog->popup_centered(Size2(400,400));
  365. blend_editor.tree->set_hide_root(true);
  366. blend_editor.tree->set_column_min_width(0,10);
  367. blend_editor.tree->set_column_min_width(1,3);
  368. List<StringName> anims;
  369. player->get_animation_list(&anims);
  370. TreeItem *root = blend_editor.tree->create_item();
  371. updating_blends=true;
  372. for(List<StringName>::Element *E=anims.front();E;E=E->next()) {
  373. String to=E->get();
  374. TreeItem *blend=blend_editor.tree->create_item(root);
  375. blend->set_editable(0,false);
  376. blend->set_editable(1,true);
  377. blend->set_text(0,to);
  378. blend->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
  379. blend->set_range_config(1,0,3600,0.001);
  380. blend->set_range(1,player->get_blend_time(current,to));
  381. }
  382. blend_editor.next->set_text( player->animation_get_next(current) );
  383. updating_blends=false;
  384. }
  385. void AnimationPlayerEditor::_blend_edited() {
  386. if (updating_blends)
  387. return;
  388. if (animation->get_item_count()==0)
  389. return;
  390. String current = animation->get_item_text(animation->get_selected());
  391. TreeItem *selected = blend_editor.tree->get_edited();
  392. if (!selected)
  393. return;
  394. updating_blends=true;
  395. String to=selected->get_text(0);
  396. float blend_time = selected->get_range(1);
  397. float prev_blend_time = player->get_blend_time(current,to);
  398. undo_redo->create_action("Change Blend Time");
  399. undo_redo->add_do_method(player,"set_blend_time",current,to,blend_time);
  400. undo_redo->add_undo_method(player,"set_blend_time",current,to,prev_blend_time);
  401. undo_redo->add_do_method(this,"_animation_player_changed",player);
  402. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  403. undo_redo->commit_action();
  404. updating_blends=false;
  405. }
  406. void AnimationPlayerEditor::ensure_visibility() {
  407. _animation_edit();
  408. }
  409. Dictionary AnimationPlayerEditor::get_state() const {
  410. Dictionary d;
  411. d["visible"]=is_visible();
  412. if (is_visible() && player) {
  413. d["player"]=EditorNode::get_singleton()->get_edited_scene()->get_path_to(player);
  414. d["animation"]=player->get_current_animation();
  415. d["editing"]=edit_anim->is_pressed();
  416. }
  417. return d;
  418. }
  419. void AnimationPlayerEditor::set_state(const Dictionary& p_state) {
  420. if (p_state.has("visible") && p_state["visible"]) {
  421. Node *n = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["player"]);
  422. if (n && n->cast_to<AnimationPlayer>()) {
  423. player=n->cast_to<AnimationPlayer>();
  424. _update_player();
  425. show();
  426. set_process(true);
  427. ensure_visibility();
  428. EditorNode::get_singleton()->animation_panel_make_visible(true);
  429. if (p_state.has("animation")) {
  430. String anim = p_state["animation"];
  431. _select_anim_by_name(anim);
  432. if (p_state.has("editing") && p_state["editing"]) {
  433. edit_anim->set_pressed(true);
  434. _animation_edit();
  435. }
  436. }
  437. }
  438. }
  439. }
  440. void AnimationPlayerEditor::_animation_resource_edit() {
  441. if (animation->get_item_count()) {
  442. String current = animation->get_item_text(animation->get_selected());
  443. Ref<Animation> anim = player->get_animation(current);
  444. editor->edit_resource(anim);
  445. }
  446. }
  447. void AnimationPlayerEditor::_animation_edit() {
  448. // if (animation->get_item_count()==0)
  449. // return;
  450. if (edit_anim->is_pressed()) {
  451. editor->animation_editor_make_visible(true);
  452. //editor->get_animation_editor()->set_root(player->get_roo); - get root pending
  453. if (animation->get_item_count()) {
  454. String current = animation->get_item_text(animation->get_selected());
  455. Ref<Animation> anim = player->get_animation(current);
  456. editor->get_animation_editor()->set_animation(anim);
  457. Node *root = player->get_node(player->get_root());
  458. if (root) {
  459. editor->get_animation_editor()->set_root(root);
  460. }
  461. } else {
  462. editor->get_animation_editor()->set_animation(Ref<Animation>());
  463. editor->get_animation_editor()->set_root(NULL);
  464. }
  465. } else {
  466. editor->animation_editor_make_visible(false);
  467. editor->get_animation_editor()->set_animation(Ref<Animation>());
  468. editor->get_animation_editor()->set_root(NULL);
  469. }
  470. //get_scene()->get_root_node()->call("_resource_selected",anim,"");
  471. }
  472. void AnimationPlayerEditor::_file_selected(String p_file) {
  473. ERR_FAIL_COND(!player);
  474. Ref<Resource> res = ResourceLoader::load(p_file,"Animation");
  475. ERR_FAIL_COND(res.is_null());
  476. ERR_FAIL_COND( !res->is_type("Animation") );
  477. if (p_file.find_last("/")!=-1) {
  478. p_file=p_file.substr( p_file.find_last("/")+1, p_file.length() );
  479. }
  480. if (p_file.find_last("\\")!=-1) {
  481. p_file=p_file.substr( p_file.find_last("\\")+1, p_file.length() );
  482. }
  483. if (p_file.find(".")!=-1)
  484. p_file=p_file.substr(0,p_file.find("."));
  485. undo_redo->create_action("Load Animation");
  486. undo_redo->add_do_method(player,"add_animation",p_file,res);
  487. undo_redo->add_undo_method(player,"remove_animation",p_file);
  488. if (player->has_animation(p_file)) {
  489. undo_redo->add_undo_method(player,"add_animation",p_file,player->get_animation(p_file));
  490. }
  491. undo_redo->add_do_method(this,"_animation_player_changed",player);
  492. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  493. undo_redo->commit_action();
  494. }
  495. void AnimationPlayerEditor::_scale_changed(const String& p_scale) {
  496. player->set_speed(p_scale.to_double());
  497. }
  498. void AnimationPlayerEditor::_update_animation() {
  499. // the purpose of _update_animation is to reflect the current state
  500. // of the animation player in the current editor..
  501. updating=true;
  502. if (player->is_playing()) {
  503. play->set_pressed(true);
  504. stop->set_pressed(false);
  505. } else {
  506. play->set_pressed(false);
  507. stop->set_pressed(true);
  508. }
  509. scale->set_text( String::num(player->get_speed(),2) );
  510. String current=player->get_current_animation();
  511. for (int i=0;i<animation->get_item_count();i++) {
  512. if (animation->get_item_text(i)==current) {
  513. animation->select(i);
  514. break;
  515. }
  516. }
  517. updating=false;
  518. }
  519. void AnimationPlayerEditor::_update_player() {
  520. if (!player)
  521. return;
  522. updating=true;
  523. List<StringName> animlist;
  524. player->get_animation_list(&animlist);
  525. animation->clear();
  526. nodename->set_text(player->get_name());
  527. stop->set_disabled(animlist.size()==0);
  528. play->set_disabled(animlist.size()==0);
  529. play_bw->set_disabled(animlist.size()==0);
  530. play_bw_from->set_disabled(animlist.size()==0);
  531. play_from->set_disabled(animlist.size()==0);
  532. autoplay->set_disabled(animlist.size()==0);
  533. duplicate_anim->set_disabled(animlist.size()==0);
  534. rename_anim->set_disabled(animlist.size()==0);
  535. blend_anim->set_disabled(animlist.size()==0);
  536. remove_anim->set_disabled(animlist.size()==0);
  537. resource_edit_anim->set_disabled(animlist.size()==0);
  538. int active_idx=-1;
  539. for (List<StringName>::Element *E=animlist.front();E;E=E->next()) {
  540. if (player->get_autoplay()==E->get())
  541. animation->add_icon_item(autoplay_icon,E->get());
  542. else
  543. animation->add_item(E->get());
  544. if (player->get_current_animation()==E->get())
  545. active_idx=animation->get_item_count()-1;
  546. }
  547. updating=false;
  548. if (active_idx!=-1) {
  549. animation->select(active_idx);
  550. autoplay->set_pressed(animation->get_item_text(active_idx)==player->get_autoplay());
  551. _animation_selected(active_idx);
  552. } else if (animation->get_item_count()>0){
  553. animation->select(0);
  554. autoplay->set_pressed(animation->get_item_text(0)==player->get_autoplay());
  555. _animation_selected(0);
  556. }
  557. //pause->set_pressed(player->is_paused());
  558. if (edit_anim->is_pressed()) {
  559. if (animation->get_item_count()) {
  560. String current = animation->get_item_text(animation->get_selected());
  561. Ref<Animation> anim = player->get_animation(current);
  562. editor->get_animation_editor()->set_animation(anim);
  563. Node *root = player->get_node(player->get_root());
  564. if (root) {
  565. editor->get_animation_editor()->set_root(root);
  566. }
  567. }
  568. }
  569. _update_animation();
  570. }
  571. void AnimationPlayerEditor::edit(AnimationPlayer *p_player) {
  572. if (player && pin->is_pressed())
  573. return; //ignore, pinned
  574. player=p_player;
  575. if (player)
  576. _update_player();
  577. else {
  578. // hide();
  579. }
  580. }
  581. void AnimationPlayerEditor::_animation_duplicate() {
  582. if (!animation->get_item_count())
  583. return;
  584. String current = animation->get_item_text(animation->get_selected());
  585. Ref<Animation> anim = player->get_animation(current);
  586. if (!anim.is_valid())
  587. return;
  588. Ref<Animation> new_anim = memnew( Animation );
  589. List<PropertyInfo> plist;
  590. anim->get_property_list(&plist);
  591. for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
  592. if (E->get().usage&PROPERTY_USAGE_STORAGE) {
  593. new_anim->set(E->get().name, anim->get(E->get().name));
  594. }
  595. }
  596. new_anim->set_path("");
  597. String new_name = current;
  598. while(player->has_animation(new_name)) {
  599. new_name=new_name+" (copy)";
  600. }
  601. undo_redo->create_action("Duplicate Animation");
  602. undo_redo->add_do_method(player,"add_animation",new_name,new_anim);
  603. undo_redo->add_undo_method(player,"remove_animation",new_name);
  604. undo_redo->add_do_method(this,"_animation_player_changed",player);
  605. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  606. undo_redo->commit_action();
  607. for(int i=0;i<animation->get_item_count();i++) {
  608. if (animation->get_item_text(i)==new_name) {
  609. animation->select(i);
  610. _animation_selected(i);
  611. return;
  612. }
  613. }
  614. }
  615. void AnimationPlayerEditor::_seek_value_changed(float p_value) {
  616. if (updating || !player || player->is_playing()) {
  617. return;
  618. };
  619. updating=true;
  620. String current=player->get_current_animation(); //animation->get_item_text( animation->get_selected() );
  621. if (current == "" || !player->has_animation(current)) {
  622. updating=false;
  623. current="";
  624. return;
  625. };
  626. Ref<Animation> anim;
  627. anim=player->get_animation(current);
  628. float pos = anim->get_length() * (p_value / seek->get_max());
  629. if (player->is_valid()) {
  630. float cpos = player->get_current_animation_pos();
  631. player->seek_delta(pos,pos-cpos);
  632. } else {
  633. player->seek(pos,true);
  634. }
  635. if (edit_anim->is_pressed())
  636. editor->get_animation_editor()->set_anim_pos(pos);
  637. updating=true;
  638. };
  639. void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) {
  640. if (player==p_pl && is_visible()) {
  641. _update_player();
  642. if (blend_editor.dialog->is_visible())
  643. _animation_blend(); //update
  644. }
  645. }
  646. void AnimationPlayerEditor::_list_changed() {
  647. if(is_visible())
  648. _update_player();
  649. }
  650. #if 0
  651. void AnimationPlayerEditor::_editor_store() {
  652. if (animation->get_item_count()==0)
  653. return;
  654. String current = animation->get_item_text(animation->get_selected());
  655. Ref<Animation> anim = player->get_animation(current);
  656. if (editor->get_animation_editor()->get_current_animation()==anim)
  657. return; //already there
  658. undo_redo->create_action("Store anim in editor");
  659. undo_redo->add_do_method(editor->get_animation_editor(),"set_animation",anim);
  660. undo_redo->add_undo_method(editor->get_animation_editor(),"remove_animation",anim);
  661. undo_redo->commit_action();
  662. }
  663. void AnimationPlayerEditor::_editor_load(){
  664. Ref<Animation> anim = editor->get_animation_editor()->get_current_animation();
  665. if (anim.is_null())
  666. return;
  667. String existing = player->find_animation(anim);
  668. if (existing!="") {
  669. _select_anim_by_name(existing);
  670. return; //already has
  671. }
  672. int count=1;
  673. String base=anim->get_name();
  674. bool noname=false;
  675. if (base=="") {
  676. base="New Anim";
  677. noname=true;
  678. }
  679. while(true) {
  680. String attempt = base;
  681. if (count>1)
  682. attempt+=" ("+itos(count)+")";
  683. if (player->has_animation(attempt)) {
  684. count++;
  685. continue;
  686. }
  687. base=attempt;
  688. break;
  689. }
  690. if (noname)
  691. anim->set_name(base);
  692. undo_redo->create_action("Add Animation From Editor");
  693. undo_redo->add_do_method(player,"add_animation",base,anim);
  694. undo_redo->add_undo_method(player,"remove_animation",base);
  695. undo_redo->add_do_method(this,"_animation_player_changed",player);
  696. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  697. undo_redo->commit_action();
  698. _select_anim_by_name(base);
  699. }
  700. #endif
  701. void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) {
  702. seek->set_max(p_len);
  703. }
  704. void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos) {
  705. if (!is_visible())
  706. return;
  707. if (!player)
  708. return;
  709. if (player->is_playing() )
  710. return;
  711. seek->set_val(p_pos);
  712. EditorNode::get_singleton()->get_property_editor()->refresh();
  713. //seekit
  714. }
  715. void AnimationPlayerEditor::_hide_anim_editors() {
  716. player=NULL;
  717. hide();
  718. set_process(false);
  719. if (edit_anim->is_pressed()) {
  720. editor->get_animation_editor()->set_animation(Ref<Animation>());
  721. editor->get_animation_editor()->set_root(NULL);
  722. editor->animation_editor_make_visible(false);
  723. edit_anim->set_pressed(false);
  724. }
  725. }
  726. void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
  727. switch(p_option) {
  728. case TOOL_COPY_ANIM: {
  729. if (!animation->get_item_count()) {
  730. error_dialog->set_text("ERROR: No animation to copy!");
  731. error_dialog->popup_centered_minsize();
  732. return;
  733. }
  734. String current = animation->get_item_text(animation->get_selected());
  735. Ref<Animation> anim = player->get_animation(current);
  736. //editor->edit_resource(anim);
  737. EditorSettings::get_singleton()->set_resource_clipboard(anim);
  738. } break;
  739. case TOOL_PASTE_ANIM: {
  740. Ref<Animation> anim = EditorSettings::get_singleton()->get_resource_clipboard();
  741. if (!anim.is_valid()) {
  742. error_dialog->set_text("ERROR: No animation resource on clipboard!");
  743. error_dialog->popup_centered_minsize();
  744. return;
  745. }
  746. String name = anim->get_name();
  747. if (name=="") {
  748. name="Pasted Animation";
  749. }
  750. int idx=1;
  751. String base = name;
  752. while (player->has_animation(name)) {
  753. idx++;
  754. name=base+" "+itos(idx);
  755. }
  756. undo_redo->create_action("Paste Animation");
  757. undo_redo->add_do_method(player,"add_animation",name,anim);
  758. undo_redo->add_undo_method(player,"remove_animation",name);
  759. undo_redo->add_do_method(this,"_animation_player_changed",player);
  760. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  761. undo_redo->commit_action();
  762. _select_anim_by_name(name);
  763. } break;
  764. case TOOL_EDIT_RESOURCE: {
  765. if (!animation->get_item_count()) {
  766. error_dialog->set_text("ERROR: No animation to edit!");
  767. error_dialog->popup_centered_minsize();
  768. return;
  769. }
  770. String current = animation->get_item_text(animation->get_selected());
  771. Ref<Animation> anim = player->get_animation(current);
  772. editor->edit_resource(anim);
  773. } break;
  774. }
  775. }
  776. void AnimationPlayerEditor::_unhandled_key_input(const InputEvent& p_ev) {
  777. if (is_visible() && p_ev.type==InputEvent::KEY && p_ev.key.pressed && !p_ev.key.echo && !p_ev.key.mod.alt && !p_ev.key.mod.control && !p_ev.key.mod.meta) {
  778. switch(p_ev.key.scancode) {
  779. case KEY_A: {
  780. if (!p_ev.key.mod.shift)
  781. _play_bw_from_pressed();
  782. else
  783. _play_bw_pressed();
  784. } break;
  785. case KEY_S: {
  786. _stop_pressed();
  787. } break;
  788. case KEY_D: {
  789. if (!p_ev.key.mod.shift)
  790. _play_from_pressed();
  791. else
  792. _play_pressed();
  793. } break;
  794. }
  795. }
  796. }
  797. void AnimationPlayerEditor::_bind_methods() {
  798. ObjectTypeDB::bind_method(_MD("_input_event"),&AnimationPlayerEditor::_input_event);
  799. ObjectTypeDB::bind_method(_MD("_node_removed"),&AnimationPlayerEditor::_node_removed);
  800. ObjectTypeDB::bind_method(_MD("_play_pressed"),&AnimationPlayerEditor::_play_pressed);
  801. ObjectTypeDB::bind_method(_MD("_play_from_pressed"),&AnimationPlayerEditor::_play_from_pressed);
  802. ObjectTypeDB::bind_method(_MD("_play_bw_pressed"),&AnimationPlayerEditor::_play_bw_pressed);
  803. ObjectTypeDB::bind_method(_MD("_play_bw_from_pressed"),&AnimationPlayerEditor::_play_bw_from_pressed);
  804. ObjectTypeDB::bind_method(_MD("_stop_pressed"),&AnimationPlayerEditor::_stop_pressed);
  805. ObjectTypeDB::bind_method(_MD("_autoplay_pressed"),&AnimationPlayerEditor::_autoplay_pressed);
  806. ObjectTypeDB::bind_method(_MD("_pause_pressed"),&AnimationPlayerEditor::_pause_pressed);
  807. ObjectTypeDB::bind_method(_MD("_animation_selected"),&AnimationPlayerEditor::_animation_selected);
  808. ObjectTypeDB::bind_method(_MD("_animation_name_edited"),&AnimationPlayerEditor::_animation_name_edited);
  809. ObjectTypeDB::bind_method(_MD("_animation_new"),&AnimationPlayerEditor::_animation_new);
  810. ObjectTypeDB::bind_method(_MD("_animation_rename"),&AnimationPlayerEditor::_animation_rename);
  811. ObjectTypeDB::bind_method(_MD("_animation_load"),&AnimationPlayerEditor::_animation_load);
  812. ObjectTypeDB::bind_method(_MD("_animation_remove"),&AnimationPlayerEditor::_animation_remove);
  813. ObjectTypeDB::bind_method(_MD("_animation_blend"),&AnimationPlayerEditor::_animation_blend);
  814. ObjectTypeDB::bind_method(_MD("_animation_edit"),&AnimationPlayerEditor::_animation_edit);
  815. ObjectTypeDB::bind_method(_MD("_animation_resource_edit"),&AnimationPlayerEditor::_animation_resource_edit);
  816. ObjectTypeDB::bind_method(_MD("_file_selected"),&AnimationPlayerEditor::_file_selected);
  817. ObjectTypeDB::bind_method(_MD("_seek_value_changed"),&AnimationPlayerEditor::_seek_value_changed);
  818. ObjectTypeDB::bind_method(_MD("_animation_player_changed"),&AnimationPlayerEditor::_animation_player_changed);
  819. ObjectTypeDB::bind_method(_MD("_blend_edited"),&AnimationPlayerEditor::_blend_edited);
  820. // ObjectTypeDB::bind_method(_MD("_seek_frame_changed"),&AnimationPlayerEditor::_seek_frame_changed);
  821. ObjectTypeDB::bind_method(_MD("_scale_changed"),&AnimationPlayerEditor::_scale_changed);
  822. //ObjectTypeDB::bind_method(_MD("_editor_store_all"),&AnimationPlayerEditor::_editor_store_all);
  823. ///jectTypeDB::bind_method(_MD("_editor_load_all"),&AnimationPlayerEditor::_editor_load_all);
  824. ObjectTypeDB::bind_method(_MD("_list_changed"),&AnimationPlayerEditor::_list_changed);
  825. ObjectTypeDB::bind_method(_MD("_animation_key_editor_seek"),&AnimationPlayerEditor::_animation_key_editor_seek);
  826. ObjectTypeDB::bind_method(_MD("_animation_key_editor_anim_len_changed"),&AnimationPlayerEditor::_animation_key_editor_anim_len_changed);
  827. ObjectTypeDB::bind_method(_MD("_hide_anim_editors"),&AnimationPlayerEditor::_hide_anim_editors);
  828. ObjectTypeDB::bind_method(_MD("_animation_duplicate"),&AnimationPlayerEditor::_animation_duplicate);
  829. ObjectTypeDB::bind_method(_MD("_blend_editor_next_changed"),&AnimationPlayerEditor::_blend_editor_next_changed);
  830. ObjectTypeDB::bind_method(_MD("_unhandled_key_input"),&AnimationPlayerEditor::_unhandled_key_input);
  831. ObjectTypeDB::bind_method(_MD("_animation_tool_menu"),&AnimationPlayerEditor::_animation_tool_menu);
  832. }
  833. AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) {
  834. editor=p_editor;
  835. updating=false;
  836. set_focus_mode(FOCUS_ALL);
  837. player=NULL;
  838. add_style_override("panel", get_stylebox("panel","Panel"));
  839. Label * l;
  840. /*l= memnew( Label );
  841. l->set_text("Animation Player:");
  842. add_child(l);*/
  843. HBoxContainer *hb = memnew( HBoxContainer );
  844. add_child(hb);
  845. add_anim = memnew( ToolButton );
  846. add_anim->set_tooltip("Create new animation in player.");
  847. hb->add_child(add_anim);
  848. load_anim = memnew( ToolButton );
  849. load_anim->set_tooltip("Load an animation from disk.");
  850. hb->add_child(load_anim);
  851. duplicate_anim = memnew( ToolButton );
  852. hb->add_child(duplicate_anim);
  853. duplicate_anim->set_tooltip("Duplicate Animation");
  854. rename_anim = memnew( ToolButton );
  855. hb->add_child(rename_anim);
  856. rename_anim->set_tooltip("Rename Animation");
  857. remove_anim = memnew( ToolButton );
  858. hb->add_child(remove_anim);
  859. remove_anim->set_tooltip("Remove Animation");
  860. animation = memnew( OptionButton );
  861. hb->add_child(animation);
  862. animation->set_h_size_flags(SIZE_EXPAND_FILL);
  863. animation->set_tooltip("Display list of animations in player.");
  864. autoplay = memnew( ToolButton );
  865. hb->add_child(autoplay);
  866. autoplay->set_tooltip("Autoplay On Load");
  867. blend_anim = memnew( ToolButton );
  868. hb->add_child(blend_anim);
  869. blend_anim->set_tooltip("Edit Target Blend Times");
  870. tool_anim = memnew( MenuButton);
  871. //tool_anim->set_flat(false);
  872. tool_anim->set_tooltip("Animation Tools");
  873. tool_anim->get_popup()->add_item("Copy Animation",TOOL_COPY_ANIM);
  874. tool_anim->get_popup()->add_item("Paste Animation",TOOL_PASTE_ANIM);
  875. //tool_anim->get_popup()->add_separator();
  876. //tool_anim->get_popup()->add_item("Edit Anim Resource",TOOL_PASTE_ANIM);
  877. hb->add_child(tool_anim);
  878. edit_anim = memnew( ToolButton );
  879. edit_anim->set_toggle_mode(true);
  880. hb->add_child(edit_anim);
  881. edit_anim->set_tooltip("Open animation editor.\nProperty editor will displays all editable keys too.");
  882. hb = memnew (HBoxContainer);
  883. add_child(hb);
  884. play_bw_from = memnew( ToolButton );
  885. play_bw_from->set_tooltip("Play backwards selected animation from current pos. (A)");
  886. hb->add_child(play_bw_from);
  887. play_bw = memnew( ToolButton );
  888. play_bw->set_tooltip("Play backwards selected animation from end. (Shift+A)");
  889. hb->add_child(play_bw);
  890. stop = memnew( ToolButton );
  891. stop->set_toggle_mode(true);
  892. hb->add_child(stop);
  893. stop->set_tooltip("Stop animation playback. (S)");
  894. play = memnew( ToolButton );
  895. play->set_tooltip("Play selected animation from start. (Shift+D)");
  896. hb->add_child(play);
  897. play_from = memnew( ToolButton );
  898. play_from->set_tooltip("Play selected animation from current pos. (D)");
  899. hb->add_child(play_from);
  900. //pause = memnew( Button );
  901. //pause->set_toggle_mode(true);
  902. //hb->add_child(pause);
  903. seek = memnew( HSlider );
  904. seek->set_val(0);
  905. seek->set_step(0.01);
  906. hb->add_child(seek);
  907. seek->set_h_size_flags(SIZE_EXPAND_FILL);
  908. seek->set_stretch_ratio(8);
  909. seek->set_tooltip("Seek animation (when stopped).");
  910. frame = memnew( SpinBox );
  911. hb->add_child(frame);
  912. frame->set_h_size_flags(SIZE_EXPAND_FILL);
  913. frame->set_stretch_ratio(2);
  914. frame->set_tooltip("Animation position (in seconds).");
  915. seek->share(frame);
  916. scale = memnew( LineEdit );
  917. hb->add_child(scale);
  918. scale->set_h_size_flags(SIZE_EXPAND_FILL);
  919. scale->set_stretch_ratio(1);
  920. scale->set_tooltip("Scale animation playback globally for the node.");
  921. scale->hide();
  922. resource_edit_anim= memnew( Button );
  923. hb->add_child(resource_edit_anim);
  924. resource_edit_anim->hide();
  925. file = memnew(EditorFileDialog);
  926. add_child(file);
  927. name_dialog = memnew( ConfirmationDialog );
  928. name_dialog->set_hide_on_ok(false);
  929. add_child(name_dialog);
  930. name = memnew( LineEdit );
  931. name_dialog->add_child(name);
  932. name->set_pos(Point2(18,30));
  933. name->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,10);
  934. name_dialog->register_text_enter(name);
  935. l = memnew( Label );
  936. l->set_text("Animation Name:");
  937. l->set_pos( Point2(10,10) );
  938. name_dialog->add_child(l);
  939. name_title=l;
  940. error_dialog = memnew( ConfirmationDialog );
  941. error_dialog->get_ok()->set_text("Close");
  942. //error_dialog->get_cancel()->set_text("Close");
  943. error_dialog->set_text("Error!");
  944. add_child(error_dialog);
  945. name_dialog->connect("confirmed", this,"_animation_name_edited");
  946. blend_editor.dialog = memnew( AcceptDialog );
  947. add_child(blend_editor.dialog);
  948. blend_editor.dialog->get_ok()->set_text("Close");
  949. blend_editor.dialog->set_hide_on_ok(true);
  950. VBoxContainer *blend_vb = memnew( VBoxContainer);
  951. blend_editor.dialog->add_child(blend_vb);
  952. blend_editor.dialog->set_child_rect(blend_vb);
  953. blend_editor.tree = memnew( Tree );
  954. blend_editor.tree->set_columns(2);
  955. blend_vb->add_margin_child("Blend Times: ",blend_editor.tree,true);
  956. blend_editor.next = memnew( LineEdit );
  957. blend_vb->add_margin_child("Next (Auto Queue):",blend_editor.next);
  958. blend_editor.dialog->set_title("Cross-Animation Blend Times");
  959. updating_blends=false;
  960. blend_editor.tree->connect("item_edited",this,"_blend_edited");
  961. autoplay->connect("pressed", this,"_autoplay_pressed");
  962. autoplay->set_toggle_mode(true);
  963. play->connect("pressed", this,"_play_pressed");
  964. play_from->connect("pressed", this,"_play_from_pressed");
  965. play_bw->connect("pressed", this,"_play_bw_pressed");
  966. play_bw_from->connect("pressed", this,"_play_bw_from_pressed");
  967. stop->connect("pressed", this,"_stop_pressed");
  968. //pause->connect("pressed", this,"_pause_pressed");
  969. add_anim->connect("pressed", this,"_animation_new");
  970. rename_anim->connect("pressed", this,"_animation_rename");
  971. load_anim->connect("pressed", this,"_animation_load");
  972. duplicate_anim->connect("pressed", this,"_animation_duplicate");
  973. //frame->connect("text_entered", this,"_seek_frame_changed");
  974. edit_anim->connect("pressed", this,"_animation_edit");
  975. blend_anim->connect("pressed", this,"_animation_blend");
  976. remove_anim->connect("pressed", this,"_animation_remove");
  977. animation->connect("item_selected", this,"_animation_selected",Vector<Variant>(),true);
  978. resource_edit_anim->connect("pressed", this,"_animation_resource_edit");
  979. file->connect("file_selected", this,"_file_selected");
  980. seek->connect("value_changed", this, "_seek_value_changed",Vector<Variant>(),true);
  981. scale->connect("text_entered", this, "_scale_changed",Vector<Variant>(),true);
  982. editor->get_animation_editor()->connect("timeline_changed",this,"_animation_key_editor_seek");
  983. editor->get_animation_editor()->connect("animation_len_changed",this,"_animation_key_editor_anim_len_changed");
  984. HBoxContainer *ahb = editor->get_animation_panel_hb();
  985. nodename = memnew( Label );
  986. ahb->add_child(nodename);
  987. nodename->set_h_size_flags(SIZE_EXPAND_FILL);
  988. nodename->set_opacity(0.5);
  989. pin = memnew( TextureButton );
  990. pin->set_toggle_mode(true);
  991. ahb->add_child(pin);
  992. renaming=false;
  993. last_active=false;
  994. set_process_unhandled_key_input(true);
  995. }
  996. void AnimationPlayerEditorPlugin::edit(Object *p_object) {
  997. anim_editor->set_undo_redo(&get_undo_redo());
  998. if (!p_object)
  999. return;
  1000. anim_editor->edit(p_object->cast_to<AnimationPlayer>());
  1001. }
  1002. bool AnimationPlayerEditorPlugin::handles(Object *p_object) const {
  1003. return p_object->is_type("AnimationPlayer");
  1004. }
  1005. void AnimationPlayerEditorPlugin::make_visible(bool p_visible) {
  1006. if (p_visible) {
  1007. anim_editor->show();
  1008. anim_editor->set_process(true);
  1009. anim_editor->ensure_visibility();
  1010. editor->animation_panel_make_visible(true);
  1011. } else {
  1012. // anim_editor->hide();
  1013. // anim_editor->set_idle_process(false);
  1014. }
  1015. }
  1016. AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) {
  1017. editor=p_node;
  1018. anim_editor = memnew( AnimationPlayerEditor(editor) );
  1019. anim_editor->set_undo_redo(editor->get_undo_redo());
  1020. editor->get_animation_panel()->add_child(anim_editor);
  1021. /*
  1022. editor->get_viewport()->add_child(anim_editor);
  1023. anim_editor->set_area_as_parent_rect();
  1024. anim_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END);
  1025. anim_editor->set_margin( MARGIN_TOP, 75 );
  1026. anim_editor->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END);
  1027. anim_editor->set_margin( MARGIN_RIGHT, 0 );*/
  1028. anim_editor->hide();
  1029. }
  1030. AnimationPlayerEditorPlugin::~AnimationPlayerEditorPlugin()
  1031. {
  1032. }