animation_player_editor_plugin.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  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("Del","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( FileDialog::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. void AnimationPlayerEditor::_animation_resource_edit() {
  410. if (animation->get_item_count()) {
  411. String current = animation->get_item_text(animation->get_selected());
  412. Ref<Animation> anim = player->get_animation(current);
  413. editor->edit_resource(anim);
  414. }
  415. }
  416. void AnimationPlayerEditor::_animation_edit() {
  417. // if (animation->get_item_count()==0)
  418. // return;
  419. if (edit_anim->is_pressed()) {
  420. editor->animation_editor_make_visible(true);
  421. //editor->get_animation_editor()->set_root(player->get_roo); - get root pending
  422. if (animation->get_item_count()) {
  423. String current = animation->get_item_text(animation->get_selected());
  424. Ref<Animation> anim = player->get_animation(current);
  425. editor->get_animation_editor()->set_animation(anim);
  426. Node *root = player->get_node(player->get_root());
  427. if (root) {
  428. editor->get_animation_editor()->set_root(root);
  429. }
  430. } else {
  431. editor->get_animation_editor()->set_animation(Ref<Animation>());
  432. editor->get_animation_editor()->set_root(NULL);
  433. }
  434. } else {
  435. editor->animation_editor_make_visible(false);
  436. editor->get_animation_editor()->set_animation(Ref<Animation>());
  437. editor->get_animation_editor()->set_root(NULL);
  438. }
  439. //get_scene()->get_root_node()->call("_resource_selected",anim,"");
  440. }
  441. void AnimationPlayerEditor::_file_selected(String p_file) {
  442. ERR_FAIL_COND(!player);
  443. Ref<Resource> res = ResourceLoader::load(p_file,"Animation");
  444. ERR_FAIL_COND(res.is_null());
  445. ERR_FAIL_COND( !res->is_type("Animation") );
  446. if (p_file.find_last("/")!=-1) {
  447. p_file=p_file.substr( p_file.find_last("/")+1, p_file.length() );
  448. }
  449. if (p_file.find_last("\\")!=-1) {
  450. p_file=p_file.substr( p_file.find_last("\\")+1, p_file.length() );
  451. }
  452. if (p_file.find(".")!=-1)
  453. p_file=p_file.substr(0,p_file.find("."));
  454. undo_redo->create_action("Load Animation");
  455. undo_redo->add_do_method(player,"add_animation",p_file,res);
  456. undo_redo->add_undo_method(player,"remove_animation",p_file);
  457. if (player->has_animation(p_file)) {
  458. undo_redo->add_undo_method(player,"add_animation",p_file,player->get_animation(p_file));
  459. }
  460. undo_redo->add_do_method(this,"_animation_player_changed",player);
  461. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  462. undo_redo->commit_action();
  463. }
  464. void AnimationPlayerEditor::_scale_changed(const String& p_scale) {
  465. player->set_speed(p_scale.to_double());
  466. }
  467. void AnimationPlayerEditor::_update_animation() {
  468. // the purpose of _update_animation is to reflect the current state
  469. // of the animation player in the current editor..
  470. updating=true;
  471. if (player->is_playing()) {
  472. play->set_pressed(true);
  473. stop->set_pressed(false);
  474. } else {
  475. play->set_pressed(false);
  476. stop->set_pressed(true);
  477. }
  478. scale->set_text( String::num(player->get_speed(),2) );
  479. String current=player->get_current_animation();
  480. for (int i=0;i<animation->get_item_count();i++) {
  481. if (animation->get_item_text(i)==current) {
  482. animation->select(i);
  483. break;
  484. }
  485. }
  486. updating=false;
  487. }
  488. void AnimationPlayerEditor::_update_player() {
  489. if (!player)
  490. return;
  491. updating=true;
  492. List<StringName> animlist;
  493. player->get_animation_list(&animlist);
  494. animation->clear();
  495. nodename->set_text(player->get_name());
  496. stop->set_disabled(animlist.size()==0);
  497. play->set_disabled(animlist.size()==0);
  498. play_bw->set_disabled(animlist.size()==0);
  499. play_bw_from->set_disabled(animlist.size()==0);
  500. play_from->set_disabled(animlist.size()==0);
  501. autoplay->set_disabled(animlist.size()==0);
  502. duplicate_anim->set_disabled(animlist.size()==0);
  503. rename_anim->set_disabled(animlist.size()==0);
  504. blend_anim->set_disabled(animlist.size()==0);
  505. remove_anim->set_disabled(animlist.size()==0);
  506. resource_edit_anim->set_disabled(animlist.size()==0);
  507. int active_idx=-1;
  508. for (List<StringName>::Element *E=animlist.front();E;E=E->next()) {
  509. if (player->get_autoplay()==E->get())
  510. animation->add_icon_item(autoplay_icon,E->get());
  511. else
  512. animation->add_item(E->get());
  513. if (player->get_current_animation()==E->get())
  514. active_idx=animation->get_item_count()-1;
  515. }
  516. updating=false;
  517. if (active_idx!=-1) {
  518. animation->select(active_idx);
  519. autoplay->set_pressed(animation->get_item_text(active_idx)==player->get_autoplay());
  520. _animation_selected(active_idx);
  521. } else if (animation->get_item_count()>0){
  522. animation->select(0);
  523. autoplay->set_pressed(animation->get_item_text(0)==player->get_autoplay());
  524. _animation_selected(0);
  525. }
  526. //pause->set_pressed(player->is_paused());
  527. if (edit_anim->is_pressed()) {
  528. if (animation->get_item_count()) {
  529. String current = animation->get_item_text(animation->get_selected());
  530. Ref<Animation> anim = player->get_animation(current);
  531. editor->get_animation_editor()->set_animation(anim);
  532. Node *root = player->get_node(player->get_root());
  533. if (root) {
  534. editor->get_animation_editor()->set_root(root);
  535. }
  536. }
  537. }
  538. _update_animation();
  539. }
  540. void AnimationPlayerEditor::edit(AnimationPlayer *p_player) {
  541. if (player && pin->is_pressed())
  542. return; //ignore, pinned
  543. player=p_player;
  544. if (player)
  545. _update_player();
  546. else {
  547. // hide();
  548. }
  549. }
  550. void AnimationPlayerEditor::_animation_duplicate() {
  551. if (!animation->get_item_count())
  552. return;
  553. String current = animation->get_item_text(animation->get_selected());
  554. Ref<Animation> anim = player->get_animation(current);
  555. if (!anim.is_valid())
  556. return;
  557. Ref<Animation> new_anim = memnew( Animation );
  558. List<PropertyInfo> plist;
  559. anim->get_property_list(&plist);
  560. for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
  561. if (E->get().usage&PROPERTY_USAGE_STORAGE) {
  562. new_anim->set(E->get().name, anim->get(E->get().name));
  563. }
  564. }
  565. new_anim->set_path("");
  566. String new_name = current;
  567. while(player->has_animation(new_name)) {
  568. new_name=new_name+" (copy)";
  569. }
  570. undo_redo->create_action("Duplicate Animation");
  571. undo_redo->add_do_method(player,"add_animation",new_name,new_anim);
  572. undo_redo->add_undo_method(player,"remove_animation",new_name);
  573. undo_redo->add_do_method(this,"_animation_player_changed",player);
  574. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  575. undo_redo->commit_action();
  576. for(int i=0;i<animation->get_item_count();i++) {
  577. if (animation->get_item_text(i)==new_name) {
  578. animation->select(i);
  579. _animation_selected(i);
  580. return;
  581. }
  582. }
  583. }
  584. void AnimationPlayerEditor::_seek_value_changed(float p_value) {
  585. if (updating || !player || player->is_playing()) {
  586. return;
  587. };
  588. updating=true;
  589. String current=player->get_current_animation(); //animation->get_item_text( animation->get_selected() );
  590. if (current == "" || !player->has_animation(current)) {
  591. updating=false;
  592. current="";
  593. return;
  594. };
  595. Ref<Animation> anim;
  596. anim=player->get_animation(current);
  597. float pos = anim->get_length() * (p_value / seek->get_max());
  598. if (player->is_valid()) {
  599. float cpos = player->get_current_animation_pos();
  600. player->seek_delta(pos,pos-cpos);
  601. } else {
  602. player->seek(pos,true);
  603. }
  604. if (edit_anim->is_pressed())
  605. editor->get_animation_editor()->set_anim_pos(pos);
  606. updating=true;
  607. };
  608. void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) {
  609. if (player==p_pl && is_visible()) {
  610. _update_player();
  611. if (blend_editor.dialog->is_visible())
  612. _animation_blend(); //update
  613. }
  614. }
  615. void AnimationPlayerEditor::_list_changed() {
  616. if(is_visible())
  617. _update_player();
  618. }
  619. #if 0
  620. void AnimationPlayerEditor::_editor_store() {
  621. if (animation->get_item_count()==0)
  622. return;
  623. String current = animation->get_item_text(animation->get_selected());
  624. Ref<Animation> anim = player->get_animation(current);
  625. if (editor->get_animation_editor()->get_current_animation()==anim)
  626. return; //already there
  627. undo_redo->create_action("Store anim in editor");
  628. undo_redo->add_do_method(editor->get_animation_editor(),"set_animation",anim);
  629. undo_redo->add_undo_method(editor->get_animation_editor(),"remove_animation",anim);
  630. undo_redo->commit_action();
  631. }
  632. void AnimationPlayerEditor::_editor_load(){
  633. Ref<Animation> anim = editor->get_animation_editor()->get_current_animation();
  634. if (anim.is_null())
  635. return;
  636. String existing = player->find_animation(anim);
  637. if (existing!="") {
  638. _select_anim_by_name(existing);
  639. return; //already has
  640. }
  641. int count=1;
  642. String base=anim->get_name();
  643. bool noname=false;
  644. if (base=="") {
  645. base="New Anim";
  646. noname=true;
  647. }
  648. while(true) {
  649. String attempt = base;
  650. if (count>1)
  651. attempt+=" ("+itos(count)+")";
  652. if (player->has_animation(attempt)) {
  653. count++;
  654. continue;
  655. }
  656. base=attempt;
  657. break;
  658. }
  659. if (noname)
  660. anim->set_name(base);
  661. undo_redo->create_action("Add Animation From Editor");
  662. undo_redo->add_do_method(player,"add_animation",base,anim);
  663. undo_redo->add_undo_method(player,"remove_animation",base);
  664. undo_redo->add_do_method(this,"_animation_player_changed",player);
  665. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  666. undo_redo->commit_action();
  667. _select_anim_by_name(base);
  668. }
  669. #endif
  670. void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) {
  671. seek->set_max(p_len);
  672. }
  673. void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos) {
  674. if (!is_visible())
  675. return;
  676. if (!player)
  677. return;
  678. if (player->is_playing() )
  679. return;
  680. seek->set_val(p_pos);
  681. EditorNode::get_singleton()->get_property_editor()->refresh();
  682. //seekit
  683. }
  684. void AnimationPlayerEditor::_hide_anim_editors() {
  685. player=NULL;
  686. hide();
  687. set_process(false);
  688. if (edit_anim->is_pressed()) {
  689. editor->get_animation_editor()->set_animation(Ref<Animation>());
  690. editor->get_animation_editor()->set_root(NULL);
  691. editor->animation_editor_make_visible(false);
  692. edit_anim->set_pressed(false);
  693. }
  694. }
  695. void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
  696. switch(p_option) {
  697. case TOOL_COPY_ANIM: {
  698. if (!animation->get_item_count()) {
  699. error_dialog->set_text("ERROR: No animation to copy!");
  700. error_dialog->popup_centered_minsize();
  701. return;
  702. }
  703. String current = animation->get_item_text(animation->get_selected());
  704. Ref<Animation> anim = player->get_animation(current);
  705. //editor->edit_resource(anim);
  706. EditorSettings::get_singleton()->set_resource_clipboard(anim);
  707. } break;
  708. case TOOL_PASTE_ANIM: {
  709. Ref<Animation> anim = EditorSettings::get_singleton()->get_resource_clipboard();
  710. if (!anim.is_valid()) {
  711. error_dialog->set_text("ERROR: No animation resource on clipboard!");
  712. error_dialog->popup_centered_minsize();
  713. return;
  714. }
  715. String name = anim->get_name();
  716. if (name=="") {
  717. name="Pasted Animation";
  718. }
  719. int idx=1;
  720. String base = name;
  721. while (player->has_animation(name)) {
  722. idx++;
  723. name=base+" "+itos(idx);
  724. }
  725. undo_redo->create_action("Paste Animation");
  726. undo_redo->add_do_method(player,"add_animation",name,anim);
  727. undo_redo->add_undo_method(player,"remove_animation",name);
  728. undo_redo->add_do_method(this,"_animation_player_changed",player);
  729. undo_redo->add_undo_method(this,"_animation_player_changed",player);
  730. undo_redo->commit_action();
  731. _select_anim_by_name(name);
  732. } break;
  733. case TOOL_EDIT_RESOURCE: {
  734. if (!animation->get_item_count()) {
  735. error_dialog->set_text("ERROR: No animation to edit!");
  736. error_dialog->popup_centered_minsize();
  737. return;
  738. }
  739. String current = animation->get_item_text(animation->get_selected());
  740. Ref<Animation> anim = player->get_animation(current);
  741. editor->edit_resource(anim);
  742. } break;
  743. }
  744. }
  745. void AnimationPlayerEditor::_unhandled_key_input(const InputEvent& p_ev) {
  746. 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) {
  747. switch(p_ev.key.scancode) {
  748. case KEY_A: {
  749. if (!p_ev.key.mod.shift)
  750. _play_bw_from_pressed();
  751. else
  752. _play_bw_pressed();
  753. } break;
  754. case KEY_S: {
  755. _stop_pressed();
  756. } break;
  757. case KEY_D: {
  758. if (!p_ev.key.mod.shift)
  759. _play_from_pressed();
  760. else
  761. _play_pressed();
  762. } break;
  763. }
  764. }
  765. }
  766. void AnimationPlayerEditor::_bind_methods() {
  767. ObjectTypeDB::bind_method(_MD("_input_event"),&AnimationPlayerEditor::_input_event);
  768. ObjectTypeDB::bind_method(_MD("_node_removed"),&AnimationPlayerEditor::_node_removed);
  769. ObjectTypeDB::bind_method(_MD("_play_pressed"),&AnimationPlayerEditor::_play_pressed);
  770. ObjectTypeDB::bind_method(_MD("_play_from_pressed"),&AnimationPlayerEditor::_play_from_pressed);
  771. ObjectTypeDB::bind_method(_MD("_play_bw_pressed"),&AnimationPlayerEditor::_play_bw_pressed);
  772. ObjectTypeDB::bind_method(_MD("_play_bw_from_pressed"),&AnimationPlayerEditor::_play_bw_from_pressed);
  773. ObjectTypeDB::bind_method(_MD("_stop_pressed"),&AnimationPlayerEditor::_stop_pressed);
  774. ObjectTypeDB::bind_method(_MD("_autoplay_pressed"),&AnimationPlayerEditor::_autoplay_pressed);
  775. ObjectTypeDB::bind_method(_MD("_pause_pressed"),&AnimationPlayerEditor::_pause_pressed);
  776. ObjectTypeDB::bind_method(_MD("_animation_selected"),&AnimationPlayerEditor::_animation_selected);
  777. ObjectTypeDB::bind_method(_MD("_animation_name_edited"),&AnimationPlayerEditor::_animation_name_edited);
  778. ObjectTypeDB::bind_method(_MD("_animation_new"),&AnimationPlayerEditor::_animation_new);
  779. ObjectTypeDB::bind_method(_MD("_animation_rename"),&AnimationPlayerEditor::_animation_rename);
  780. ObjectTypeDB::bind_method(_MD("_animation_load"),&AnimationPlayerEditor::_animation_load);
  781. ObjectTypeDB::bind_method(_MD("_animation_remove"),&AnimationPlayerEditor::_animation_remove);
  782. ObjectTypeDB::bind_method(_MD("_animation_blend"),&AnimationPlayerEditor::_animation_blend);
  783. ObjectTypeDB::bind_method(_MD("_animation_edit"),&AnimationPlayerEditor::_animation_edit);
  784. ObjectTypeDB::bind_method(_MD("_animation_resource_edit"),&AnimationPlayerEditor::_animation_resource_edit);
  785. ObjectTypeDB::bind_method(_MD("_file_selected"),&AnimationPlayerEditor::_file_selected);
  786. ObjectTypeDB::bind_method(_MD("_seek_value_changed"),&AnimationPlayerEditor::_seek_value_changed);
  787. ObjectTypeDB::bind_method(_MD("_animation_player_changed"),&AnimationPlayerEditor::_animation_player_changed);
  788. ObjectTypeDB::bind_method(_MD("_blend_edited"),&AnimationPlayerEditor::_blend_edited);
  789. // ObjectTypeDB::bind_method(_MD("_seek_frame_changed"),&AnimationPlayerEditor::_seek_frame_changed);
  790. ObjectTypeDB::bind_method(_MD("_scale_changed"),&AnimationPlayerEditor::_scale_changed);
  791. //ObjectTypeDB::bind_method(_MD("_editor_store_all"),&AnimationPlayerEditor::_editor_store_all);
  792. ///jectTypeDB::bind_method(_MD("_editor_load_all"),&AnimationPlayerEditor::_editor_load_all);
  793. ObjectTypeDB::bind_method(_MD("_list_changed"),&AnimationPlayerEditor::_list_changed);
  794. ObjectTypeDB::bind_method(_MD("_animation_key_editor_seek"),&AnimationPlayerEditor::_animation_key_editor_seek);
  795. ObjectTypeDB::bind_method(_MD("_animation_key_editor_anim_len_changed"),&AnimationPlayerEditor::_animation_key_editor_anim_len_changed);
  796. ObjectTypeDB::bind_method(_MD("_hide_anim_editors"),&AnimationPlayerEditor::_hide_anim_editors);
  797. ObjectTypeDB::bind_method(_MD("_animation_duplicate"),&AnimationPlayerEditor::_animation_duplicate);
  798. ObjectTypeDB::bind_method(_MD("_blend_editor_next_changed"),&AnimationPlayerEditor::_blend_editor_next_changed);
  799. ObjectTypeDB::bind_method(_MD("_unhandled_key_input"),&AnimationPlayerEditor::_unhandled_key_input);
  800. ObjectTypeDB::bind_method(_MD("_animation_tool_menu"),&AnimationPlayerEditor::_animation_tool_menu);
  801. }
  802. AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) {
  803. editor=p_editor;
  804. updating=false;
  805. set_focus_mode(FOCUS_ALL);
  806. player=NULL;
  807. add_style_override("panel", get_stylebox("panel","Panel"));
  808. Label * l;
  809. /*l= memnew( Label );
  810. l->set_text("Animation Player:");
  811. add_child(l);*/
  812. HBoxContainer *hb = memnew( HBoxContainer );
  813. add_child(hb);
  814. add_anim = memnew( ToolButton );
  815. add_anim->set_tooltip("Create new animation in player.");
  816. hb->add_child(add_anim);
  817. load_anim = memnew( ToolButton );
  818. load_anim->set_tooltip("Load an animation from disk.");
  819. hb->add_child(load_anim);
  820. duplicate_anim = memnew( ToolButton );
  821. hb->add_child(duplicate_anim);
  822. duplicate_anim->set_tooltip("Duplicate Animation");
  823. rename_anim = memnew( ToolButton );
  824. hb->add_child(rename_anim);
  825. rename_anim->set_tooltip("Rename Animation");
  826. remove_anim = memnew( ToolButton );
  827. hb->add_child(remove_anim);
  828. remove_anim->set_tooltip("Remove Animation");
  829. animation = memnew( OptionButton );
  830. hb->add_child(animation);
  831. animation->set_h_size_flags(SIZE_EXPAND_FILL);
  832. animation->set_tooltip("Display list of animations in player.");
  833. autoplay = memnew( ToolButton );
  834. hb->add_child(autoplay);
  835. autoplay->set_tooltip("Autoplay On Load");
  836. blend_anim = memnew( ToolButton );
  837. hb->add_child(blend_anim);
  838. blend_anim->set_tooltip("Edit Target Blend Times");
  839. tool_anim = memnew( MenuButton);
  840. //tool_anim->set_flat(false);
  841. tool_anim->set_tooltip("Animation Tools");
  842. tool_anim->get_popup()->add_item("Copy Animation",TOOL_COPY_ANIM);
  843. tool_anim->get_popup()->add_item("Paste Animation",TOOL_PASTE_ANIM);
  844. //tool_anim->get_popup()->add_separator();
  845. //tool_anim->get_popup()->add_item("Edit Anim Resource",TOOL_PASTE_ANIM);
  846. hb->add_child(tool_anim);
  847. edit_anim = memnew( ToolButton );
  848. edit_anim->set_toggle_mode(true);
  849. hb->add_child(edit_anim);
  850. edit_anim->set_tooltip("Open animation editor.\nProperty editor will displays all editable keys too.");
  851. hb = memnew (HBoxContainer);
  852. add_child(hb);
  853. play_bw_from = memnew( ToolButton );
  854. play_bw_from->set_tooltip("Play backwards selected animation from current pos. (A)");
  855. hb->add_child(play_bw_from);
  856. play_bw = memnew( ToolButton );
  857. play_bw->set_tooltip("Play backwards selected animation from end. (Shift+A)");
  858. hb->add_child(play_bw);
  859. stop = memnew( ToolButton );
  860. stop->set_toggle_mode(true);
  861. hb->add_child(stop);
  862. stop->set_tooltip("Stop animation playback. (S)");
  863. play = memnew( ToolButton );
  864. play->set_tooltip("Play selected animation from start. (Shift+D)");
  865. hb->add_child(play);
  866. play_from = memnew( ToolButton );
  867. play_from->set_tooltip("Play selected animation from current pos. (D)");
  868. hb->add_child(play_from);
  869. //pause = memnew( Button );
  870. //pause->set_toggle_mode(true);
  871. //hb->add_child(pause);
  872. seek = memnew( HSlider );
  873. seek->set_val(0);
  874. seek->set_step(0.01);
  875. hb->add_child(seek);
  876. seek->set_h_size_flags(SIZE_EXPAND_FILL);
  877. seek->set_stretch_ratio(8);
  878. seek->set_tooltip("Seek animation (when stopped).");
  879. frame = memnew( SpinBox );
  880. hb->add_child(frame);
  881. frame->set_h_size_flags(SIZE_EXPAND_FILL);
  882. frame->set_stretch_ratio(2);
  883. frame->set_tooltip("Animation position (in seconds).");
  884. seek->share(frame);
  885. scale = memnew( LineEdit );
  886. hb->add_child(scale);
  887. scale->set_h_size_flags(SIZE_EXPAND_FILL);
  888. scale->set_stretch_ratio(1);
  889. scale->set_tooltip("Scale animation playback globally for the node.");
  890. scale->hide();
  891. resource_edit_anim= memnew( Button );
  892. hb->add_child(resource_edit_anim);
  893. resource_edit_anim->hide();
  894. file = memnew(FileDialog);
  895. add_child(file);
  896. name_dialog = memnew( ConfirmationDialog );
  897. name_dialog->set_hide_on_ok(false);
  898. add_child(name_dialog);
  899. name = memnew( LineEdit );
  900. name_dialog->add_child(name);
  901. name->set_pos(Point2(18,30));
  902. name->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,10);
  903. name_dialog->register_text_enter(name);
  904. l = memnew( Label );
  905. l->set_text("Animation Name:");
  906. l->set_pos( Point2(10,10) );
  907. name_dialog->add_child(l);
  908. name_title=l;
  909. error_dialog = memnew( ConfirmationDialog );
  910. error_dialog->get_ok()->set_text("Close");
  911. //error_dialog->get_cancel()->set_text("Close");
  912. error_dialog->set_text("Error!");
  913. add_child(error_dialog);
  914. name_dialog->connect("confirmed", this,"_animation_name_edited");
  915. blend_editor.dialog = memnew( AcceptDialog );
  916. add_child(blend_editor.dialog);
  917. blend_editor.dialog->get_ok()->set_text("Close");
  918. blend_editor.dialog->set_hide_on_ok(true);
  919. VBoxContainer *blend_vb = memnew( VBoxContainer);
  920. blend_editor.dialog->add_child(blend_vb);
  921. blend_editor.dialog->set_child_rect(blend_vb);
  922. blend_editor.tree = memnew( Tree );
  923. blend_editor.tree->set_columns(2);
  924. blend_vb->add_margin_child("Blend Times: ",blend_editor.tree,true);
  925. blend_editor.next = memnew( LineEdit );
  926. blend_vb->add_margin_child("Next (Auto Queue):",blend_editor.next);
  927. blend_editor.dialog->set_title("Cross-Animation Blend Times");
  928. updating_blends=false;
  929. blend_editor.tree->connect("item_edited",this,"_blend_edited");
  930. autoplay->connect("pressed", this,"_autoplay_pressed");
  931. autoplay->set_toggle_mode(true);
  932. play->connect("pressed", this,"_play_pressed");
  933. play_from->connect("pressed", this,"_play_from_pressed");
  934. play_bw->connect("pressed", this,"_play_bw_pressed");
  935. play_bw_from->connect("pressed", this,"_play_bw_from_pressed");
  936. stop->connect("pressed", this,"_stop_pressed");
  937. //pause->connect("pressed", this,"_pause_pressed");
  938. add_anim->connect("pressed", this,"_animation_new");
  939. rename_anim->connect("pressed", this,"_animation_rename");
  940. load_anim->connect("pressed", this,"_animation_load");
  941. duplicate_anim->connect("pressed", this,"_animation_duplicate");
  942. //frame->connect("text_entered", this,"_seek_frame_changed");
  943. edit_anim->connect("pressed", this,"_animation_edit");
  944. blend_anim->connect("pressed", this,"_animation_blend");
  945. remove_anim->connect("pressed", this,"_animation_remove");
  946. animation->connect("item_selected", this,"_animation_selected",Vector<Variant>(),true);
  947. resource_edit_anim->connect("pressed", this,"_animation_resource_edit");
  948. file->connect("file_selected", this,"_file_selected");
  949. seek->connect("value_changed", this, "_seek_value_changed",Vector<Variant>(),true);
  950. scale->connect("text_entered", this, "_scale_changed",Vector<Variant>(),true);
  951. editor->get_animation_editor()->connect("timeline_changed",this,"_animation_key_editor_seek");
  952. editor->get_animation_editor()->connect("animation_len_changed",this,"_animation_key_editor_anim_len_changed");
  953. HBoxContainer *ahb = editor->get_animation_panel_hb();
  954. nodename = memnew( Label );
  955. ahb->add_child(nodename);
  956. nodename->set_h_size_flags(SIZE_EXPAND_FILL);
  957. nodename->set_opacity(0.5);
  958. pin = memnew( TextureButton );
  959. pin->set_toggle_mode(true);
  960. ahb->add_child(pin);
  961. renaming=false;
  962. last_active=false;
  963. set_process_unhandled_key_input(true);
  964. }
  965. void AnimationPlayerEditorPlugin::edit(Object *p_object) {
  966. anim_editor->set_undo_redo(&get_undo_redo());
  967. if (!p_object)
  968. return;
  969. anim_editor->edit(p_object->cast_to<AnimationPlayer>());
  970. }
  971. bool AnimationPlayerEditorPlugin::handles(Object *p_object) const {
  972. return p_object->is_type("AnimationPlayer");
  973. }
  974. void AnimationPlayerEditorPlugin::make_visible(bool p_visible) {
  975. if (p_visible) {
  976. anim_editor->show();
  977. anim_editor->set_process(true);
  978. anim_editor->ensure_visibility();
  979. editor->animation_panel_make_visible(true);
  980. } else {
  981. // anim_editor->hide();
  982. // anim_editor->set_idle_process(false);
  983. }
  984. }
  985. AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) {
  986. editor=p_node;
  987. anim_editor = memnew( AnimationPlayerEditor(editor) );
  988. editor->get_animation_panel()->add_child(anim_editor);
  989. /*
  990. editor->get_viewport()->add_child(anim_editor);
  991. anim_editor->set_area_as_parent_rect();
  992. anim_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END);
  993. anim_editor->set_margin( MARGIN_TOP, 75 );
  994. anim_editor->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END);
  995. anim_editor->set_margin( MARGIN_RIGHT, 0 );*/
  996. anim_editor->hide();
  997. }
  998. AnimationPlayerEditorPlugin::~AnimationPlayerEditorPlugin()
  999. {
  1000. }