2
0

animation_player.cpp 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. /**************************************************************************/
  2. /* animation_player.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "animation_player.h"
  31. #include "animation_player.compat.inc"
  32. #include "core/config/engine.h"
  33. bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) {
  34. String name = p_name;
  35. if (name.begins_with("playback/play")) { // For backward compatibility.
  36. set_current_animation(p_value);
  37. } else if (name.begins_with("next/")) {
  38. String which = name.get_slicec('/', 1);
  39. animation_set_next(which, p_value);
  40. } else if (p_name == SceneStringName(blend_times)) {
  41. Array array = p_value;
  42. int len = array.size();
  43. ERR_FAIL_COND_V(len % 3, false);
  44. for (int i = 0; i < len / 3; i++) {
  45. StringName from = array[i * 3 + 0];
  46. StringName to = array[i * 3 + 1];
  47. float time = array[i * 3 + 2];
  48. set_blend_time(from, to, time);
  49. }
  50. #ifndef DISABLE_DEPRECATED
  51. } else if (p_name == "method_call_mode") {
  52. set_callback_mode_method(static_cast<AnimationCallbackModeMethod>((int)p_value));
  53. } else if (p_name == "playback_process_mode") {
  54. set_callback_mode_process(static_cast<AnimationCallbackModeProcess>((int)p_value));
  55. } else if (p_name == "playback_active") {
  56. set_active(p_value);
  57. #endif // DISABLE_DEPRECATED
  58. } else {
  59. return false;
  60. }
  61. return true;
  62. }
  63. bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {
  64. String name = p_name;
  65. if (name == "playback/play") { // For backward compatibility.
  66. r_ret = get_current_animation();
  67. } else if (name.begins_with("next/")) {
  68. String which = name.get_slicec('/', 1);
  69. r_ret = animation_get_next(which);
  70. } else if (p_name == SceneStringName(blend_times)) {
  71. Vector<BlendKey> keys;
  72. for (const KeyValue<BlendKey, double> &E : blend_times) {
  73. keys.ordered_insert(E.key);
  74. }
  75. Array array;
  76. for (int i = 0; i < keys.size(); i++) {
  77. array.push_back(keys[i].from);
  78. array.push_back(keys[i].to);
  79. array.push_back(blend_times.get(keys[i]));
  80. }
  81. r_ret = array;
  82. #ifndef DISABLE_DEPRECATED
  83. } else if (name == "method_call_mode") {
  84. r_ret = get_callback_mode_method();
  85. } else if (name == "playback_process_mode") {
  86. r_ret = get_callback_mode_process();
  87. } else if (name == "playback_active") {
  88. r_ret = is_active();
  89. #endif // DISABLE_DEPRECATED
  90. } else {
  91. return false;
  92. }
  93. return true;
  94. }
  95. void AnimationPlayer::_validate_property(PropertyInfo &p_property) const {
  96. AnimationMixer::_validate_property(p_property);
  97. if (p_property.name == "current_animation") {
  98. List<String> names;
  99. for (const KeyValue<StringName, AnimationData> &E : animation_set) {
  100. names.push_back(E.key);
  101. }
  102. names.push_front("[stop]");
  103. String hint;
  104. for (List<String>::Element *E = names.front(); E; E = E->next()) {
  105. if (E != names.front()) {
  106. hint += ",";
  107. }
  108. hint += E->get();
  109. }
  110. p_property.hint_string = hint;
  111. } else if (!auto_capture && p_property.name.begins_with("playback_auto_capture_")) {
  112. p_property.usage = PROPERTY_USAGE_NONE;
  113. }
  114. }
  115. void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const {
  116. List<PropertyInfo> anim_names;
  117. for (const KeyValue<StringName, AnimationData> &E : animation_set) {
  118. AHashMap<StringName, StringName>::ConstIterator F = animation_next_set.find(E.key);
  119. if (F && F->value != StringName()) {
  120. anim_names.push_back(PropertyInfo(Variant::STRING, "next/" + String(E.key), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
  121. }
  122. }
  123. for (const PropertyInfo &E : anim_names) {
  124. p_list->push_back(E);
  125. }
  126. p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
  127. }
  128. void AnimationPlayer::_notification(int p_what) {
  129. switch (p_what) {
  130. case NOTIFICATION_READY: {
  131. if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) {
  132. set_active(active);
  133. play(autoplay);
  134. _check_immediately_after_start();
  135. }
  136. } break;
  137. }
  138. }
  139. void AnimationPlayer::_process_playback_data(PlaybackData &cd, double p_delta, float p_blend, bool p_seeked, bool p_internal_seeked, bool p_started, bool p_is_current) {
  140. double speed = speed_scale * cd.speed_scale;
  141. bool backwards = signbit(speed); // Negative zero means playing backwards too.
  142. double delta = p_started ? 0 : p_delta * speed;
  143. double next_pos = cd.pos + delta;
  144. double start = cd.get_start_time();
  145. double end = cd.get_end_time();
  146. Animation::LoopedFlag looped_flag = Animation::LOOPED_FLAG_NONE;
  147. switch (cd.from->animation->get_loop_mode()) {
  148. case Animation::LOOP_NONE: {
  149. if (Animation::is_less_approx(next_pos, start)) {
  150. next_pos = start;
  151. } else if (Animation::is_greater_approx(next_pos, end)) {
  152. next_pos = end;
  153. }
  154. delta = next_pos - cd.pos; // Fix delta (after determination of backwards because negative zero is lost here).
  155. } break;
  156. case Animation::LOOP_LINEAR: {
  157. if (Animation::is_less_approx(next_pos, start) && Animation::is_greater_or_equal_approx(cd.pos, start)) {
  158. looped_flag = Animation::LOOPED_FLAG_START;
  159. }
  160. if (Animation::is_greater_approx(next_pos, end) && Animation::is_less_or_equal_approx(cd.pos, end)) {
  161. looped_flag = Animation::LOOPED_FLAG_END;
  162. }
  163. next_pos = Math::fposmod(next_pos - start, end - start) + start;
  164. } break;
  165. case Animation::LOOP_PINGPONG: {
  166. if (Animation::is_less_approx(next_pos, start) && Animation::is_greater_or_equal_approx(cd.pos, start)) {
  167. cd.speed_scale *= -1.0;
  168. looped_flag = Animation::LOOPED_FLAG_START;
  169. }
  170. if (Animation::is_greater_approx(next_pos, end) && Animation::is_less_or_equal_approx(cd.pos, end)) {
  171. cd.speed_scale *= -1.0;
  172. looped_flag = Animation::LOOPED_FLAG_END;
  173. }
  174. next_pos = Math::pingpong(next_pos - start, end - start) + start;
  175. } break;
  176. default:
  177. break;
  178. }
  179. double prev_pos = cd.pos; // The animation may be changed during process, so it is safer that the state is changed before process.
  180. // End detection.
  181. if (p_is_current) {
  182. if (cd.from->animation->get_loop_mode() == Animation::LOOP_NONE) {
  183. if (!backwards && Animation::is_less_or_equal_approx(prev_pos, end) && Math::is_equal_approx(next_pos, end)) {
  184. // Playback finished.
  185. next_pos = end; // Snap to the edge.
  186. end_reached = true;
  187. end_notify = Animation::is_less_approx(prev_pos, end); // Notify only if not already at the end.
  188. p_blend = 1.0;
  189. }
  190. if (backwards && Animation::is_greater_or_equal_approx(prev_pos, start) && Math::is_equal_approx(next_pos, start)) {
  191. // Playback finished.
  192. next_pos = start; // Snap to the edge.
  193. end_reached = true;
  194. end_notify = Animation::is_greater_approx(prev_pos, start); // Notify only if not already at the beginning.
  195. p_blend = 1.0;
  196. }
  197. }
  198. }
  199. cd.pos = next_pos;
  200. PlaybackInfo pi;
  201. if (p_started) {
  202. pi.time = prev_pos;
  203. pi.delta = 0;
  204. pi.start = start;
  205. pi.end = end;
  206. pi.seeked = true;
  207. } else {
  208. pi.time = next_pos;
  209. pi.delta = delta;
  210. pi.start = start;
  211. pi.end = end;
  212. pi.seeked = p_seeked;
  213. }
  214. if (Math::is_zero_approx(pi.delta) && backwards) {
  215. pi.delta = -0.0; // Sign is needed to handle converted Continuous track from Discrete track correctly.
  216. }
  217. // Immediately after playback, discrete keys should be retrieved with EXACT mode since behind keys must be ignored at that time.
  218. pi.is_external_seeking = !p_internal_seeked && !p_started;
  219. pi.looped_flag = looped_flag;
  220. pi.weight = p_blend;
  221. make_animation_instance(cd.from->name, pi);
  222. }
  223. float AnimationPlayer::get_current_blend_amount() {
  224. Playback &c = playback;
  225. float blend = 1.0;
  226. for (List<Blend>::Element *E = c.blend.front(); E; E = E->next()) {
  227. Blend &b = E->get();
  228. blend = blend - b.blend_left;
  229. }
  230. return MAX(0, blend);
  231. }
  232. void AnimationPlayer::_blend_playback_data(double p_delta, bool p_started) {
  233. Playback &c = playback;
  234. bool seeked = c.seeked; // The animation may be changed during process, so it is safer that the state is changed before process.
  235. bool internal_seeked = c.internal_seeked;
  236. if (!Math::is_zero_approx(p_delta)) {
  237. c.seeked = false;
  238. c.internal_seeked = false;
  239. }
  240. // Second, process current animation to check if the animation end reached.
  241. _process_playback_data(c.current, p_delta, get_current_blend_amount(), seeked, internal_seeked, p_started, true);
  242. // Finally, if not end the animation, do blending.
  243. if (end_reached) {
  244. playback.blend.clear();
  245. return;
  246. }
  247. List<List<Blend>::Element *> to_erase;
  248. for (List<Blend>::Element *E = c.blend.front(); E; E = E->next()) {
  249. Blend &b = E->get();
  250. b.blend_left = MAX(0, b.blend_left - Math::absf(speed_scale * p_delta) / b.blend_time);
  251. if (Animation::is_less_or_equal_approx(b.blend_left, 0)) {
  252. to_erase.push_back(E);
  253. b.blend_left = CMP_EPSILON; // May want to play last frame.
  254. }
  255. // Note: There may be issues if an animation event triggers an animation change while this blend is active,
  256. // so it is best to use "deferred" calls instead of "immediate" for animation events that can trigger new animations.
  257. _process_playback_data(b.data, p_delta, b.blend_left, false, false, false);
  258. }
  259. for (List<Blend>::Element *&E : to_erase) {
  260. c.blend.erase(E);
  261. }
  262. }
  263. bool AnimationPlayer::_blend_pre_process(double p_delta, int p_track_count, const AHashMap<NodePath, int> &p_track_map) {
  264. if (!playback.current.from) {
  265. _set_process(false);
  266. return false;
  267. }
  268. tmp_from = playback.current.from->animation->get_instance_id();
  269. end_reached = false;
  270. end_notify = false;
  271. bool started = playback.started; // The animation may be changed during process, so it is safer that the state is changed before process.
  272. if (playback.started) {
  273. playback.started = false;
  274. }
  275. AnimationData *prev_from = playback.current.from;
  276. _blend_playback_data(p_delta, started);
  277. if (prev_from != playback.current.from) {
  278. return false; // Animation has been changed in the process (may be caused by method track), abort process.
  279. }
  280. return true;
  281. }
  282. void AnimationPlayer::_blend_capture(double p_delta) {
  283. blend_capture(p_delta * Math::abs(speed_scale));
  284. }
  285. void AnimationPlayer::_blend_post_process() {
  286. if (end_reached) {
  287. // If the method track changes current animation, the animation is not finished.
  288. if (tmp_from == playback.current.from->animation->get_instance_id()) {
  289. if (playback_queue.size()) {
  290. String old = playback.assigned;
  291. play(playback_queue.front()->get());
  292. String new_name = playback.assigned;
  293. playback_queue.pop_front();
  294. if (end_notify) {
  295. emit_signal(SceneStringName(animation_changed), old, new_name);
  296. }
  297. } else {
  298. _clear_caches();
  299. playing = false;
  300. _set_process(false);
  301. if (end_notify) {
  302. emit_signal(SceneStringName(animation_finished), playback.assigned);
  303. if (movie_quit_on_finish && OS::get_singleton()->has_feature("movie")) {
  304. print_line(vformat("Movie Maker mode is enabled. Quitting on animation finish as requested by: %s", get_path()));
  305. get_tree()->quit();
  306. }
  307. }
  308. }
  309. }
  310. end_reached = false;
  311. end_notify = false;
  312. }
  313. tmp_from = ObjectID();
  314. }
  315. void AnimationPlayer::queue(const StringName &p_name) {
  316. if (!is_playing()) {
  317. play(p_name);
  318. } else {
  319. playback_queue.push_back(p_name);
  320. }
  321. }
  322. Vector<String> AnimationPlayer::get_queue() {
  323. Vector<String> ret;
  324. for (const StringName &E : playback_queue) {
  325. ret.push_back(E);
  326. }
  327. return ret;
  328. }
  329. void AnimationPlayer::clear_queue() {
  330. playback_queue.clear();
  331. }
  332. void AnimationPlayer::play_backwards(const StringName &p_name, double p_custom_blend) {
  333. play(p_name, p_custom_blend, -1, true);
  334. }
  335. void AnimationPlayer::play_section_with_markers_backwards(const StringName &p_name, const StringName &p_start_marker, const StringName &p_end_marker, double p_custom_blend) {
  336. play_section_with_markers(p_name, p_start_marker, p_end_marker, p_custom_blend, -1, true);
  337. }
  338. void AnimationPlayer::play_section_backwards(const StringName &p_name, double p_start_time, double p_end_time, double p_custom_blend) {
  339. play_section(p_name, p_start_time, p_end_time, p_custom_blend, -1, true);
  340. }
  341. void AnimationPlayer::play(const StringName &p_name, double p_custom_blend, float p_custom_scale, bool p_from_end) {
  342. if (auto_capture) {
  343. play_with_capture(p_name, auto_capture_duration, p_custom_blend, p_custom_scale, p_from_end, auto_capture_transition_type, auto_capture_ease_type);
  344. } else {
  345. _play(p_name, p_custom_blend, p_custom_scale, p_from_end);
  346. }
  347. }
  348. void AnimationPlayer::_play(const StringName &p_name, double p_custom_blend, float p_custom_scale, bool p_from_end) {
  349. play_section_with_markers(p_name, StringName(), StringName(), p_custom_blend, p_custom_scale, p_from_end);
  350. }
  351. void AnimationPlayer::play_section_with_markers(const StringName &p_name, const StringName &p_start_marker, const StringName &p_end_marker, double p_custom_blend, float p_custom_scale, bool p_from_end) {
  352. StringName name = p_name;
  353. if (name == StringName()) {
  354. name = playback.assigned;
  355. }
  356. ERR_FAIL_COND_MSG(!animation_set.has(name), vformat("Animation not found: %s.", name));
  357. Ref<Animation> animation = animation_set[name].animation;
  358. ERR_FAIL_COND_MSG(p_start_marker == p_end_marker && p_start_marker, vformat("Start marker and end marker cannot be the same marker: %s.", p_start_marker));
  359. ERR_FAIL_COND_MSG(p_start_marker && !animation->has_marker(p_start_marker), vformat("Marker %s not found in animation: %s.", p_start_marker, name));
  360. ERR_FAIL_COND_MSG(p_end_marker && !animation->has_marker(p_end_marker), vformat("Marker %s not found in animation: %s.", p_end_marker, name));
  361. double start_time = p_start_marker ? animation->get_marker_time(p_start_marker) : -1;
  362. double end_time = p_end_marker ? animation->get_marker_time(p_end_marker) : -1;
  363. ERR_FAIL_COND_MSG(p_start_marker && p_end_marker && Animation::is_greater_approx(start_time, end_time), vformat("End marker %s is placed earlier than start marker %s in animation: %s.", p_end_marker, p_start_marker, name));
  364. if (p_start_marker && Animation::is_less_approx(start_time, 0)) {
  365. WARN_PRINT_ED(vformat("Negative time start marker: %s is invalid in the section, so the start of the animation: %s is used instead.", p_start_marker, playback.current.from->animation->get_name()));
  366. }
  367. if (p_end_marker && Animation::is_less_approx(end_time, 0)) {
  368. WARN_PRINT_ED(vformat("Negative time end marker: %s is invalid in the section, so the end of the animation: %s is used instead.", p_end_marker, playback.current.from->animation->get_name()));
  369. }
  370. play_section(name, start_time, end_time, p_custom_blend, p_custom_scale, p_from_end);
  371. }
  372. void AnimationPlayer::play_section(const StringName &p_name, double p_start_time, double p_end_time, double p_custom_blend, float p_custom_scale, bool p_from_end) {
  373. StringName name = p_name;
  374. if (name == StringName()) {
  375. name = playback.assigned;
  376. }
  377. ERR_FAIL_COND_MSG(!animation_set.has(name), vformat("Animation not found: %s.", name));
  378. ERR_FAIL_COND_MSG(p_start_time >= 0 && p_end_time >= 0 && Math::is_equal_approx(p_start_time, p_end_time), "Start time and end time must not equal to each other.");
  379. ERR_FAIL_COND_MSG(p_start_time >= 0 && p_end_time >= 0 && Animation::is_greater_approx(p_start_time, p_end_time), vformat("Start time %f is greater than end time %f.", p_start_time, p_end_time));
  380. Playback &c = playback;
  381. if (c.current.from) {
  382. double blend_time = 0.0;
  383. // Find if it can blend.
  384. BlendKey bk;
  385. bk.from = c.current.from->name;
  386. bk.to = name;
  387. if (Animation::is_greater_or_equal_approx(p_custom_blend, 0)) {
  388. blend_time = p_custom_blend;
  389. } else if (blend_times.has(bk)) {
  390. blend_time = blend_times[bk];
  391. } else {
  392. bk.from = "*";
  393. if (blend_times.has(bk)) {
  394. blend_time = blend_times[bk];
  395. } else {
  396. bk.from = c.current.from->name;
  397. bk.to = "*";
  398. if (blend_times.has(bk)) {
  399. blend_time = blend_times[bk];
  400. }
  401. }
  402. }
  403. if (Animation::is_less_approx(p_custom_blend, 0) && Math::is_zero_approx(blend_time) && default_blend_time) {
  404. blend_time = default_blend_time;
  405. }
  406. if (Animation::is_greater_approx(blend_time, 0)) {
  407. Blend b;
  408. b.data = c.current;
  409. b.blend_left = get_current_blend_amount();
  410. b.blend_time = blend_time;
  411. c.blend.push_back(b);
  412. } else {
  413. c.blend.clear();
  414. }
  415. }
  416. if (get_current_animation() != p_name) {
  417. _clear_playing_caches();
  418. }
  419. c.current.from = &animation_set[name];
  420. c.current.speed_scale = p_custom_scale;
  421. c.current.start_time = p_start_time;
  422. c.current.end_time = p_end_time;
  423. double start = playback.current.get_start_time();
  424. double end = playback.current.get_end_time();
  425. if (!end_reached) {
  426. playback_queue.clear();
  427. }
  428. if (c.assigned != name) { // Reset.
  429. c.current.pos = p_from_end ? end : start;
  430. c.assigned = name;
  431. emit_signal(SNAME("current_animation_changed"), c.assigned);
  432. } else {
  433. if (p_from_end && Math::is_equal_approx(c.current.pos, start)) {
  434. // Animation reset but played backwards, set position to the end.
  435. seek_internal(end, true, true, true);
  436. } else if (!p_from_end && Math::is_equal_approx(c.current.pos, end)) {
  437. // Animation resumed but already ended, set position to the beginning.
  438. seek_internal(start, true, true, true);
  439. } else if (playing) {
  440. return;
  441. }
  442. }
  443. c.seeked = false;
  444. c.started = true;
  445. _set_process(true); // Always process when starting an animation.
  446. playing = true;
  447. emit_signal(SceneStringName(animation_started), c.assigned);
  448. if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
  449. return; // No next in this case.
  450. }
  451. StringName next = animation_get_next(p_name);
  452. if (next != StringName() && animation_set.has(next)) {
  453. queue(next);
  454. }
  455. }
  456. void AnimationPlayer::_capture(const StringName &p_name, bool p_from_end, double p_duration, Tween::TransitionType p_trans_type, Tween::EaseType p_ease_type) {
  457. StringName name = p_name;
  458. if (name == StringName()) {
  459. name = playback.assigned;
  460. }
  461. Ref<Animation> anim = get_animation(name);
  462. if (anim.is_null() || !anim->is_capture_included()) {
  463. return;
  464. }
  465. if (signbit(p_duration)) {
  466. double max_dur = 0;
  467. double current_pos = playback.current.pos;
  468. if (playback.assigned != name) {
  469. current_pos = p_from_end ? anim->get_length() : 0;
  470. }
  471. for (int i = 0; i < anim->get_track_count(); i++) {
  472. if (anim->track_get_type(i) != Animation::TYPE_VALUE) {
  473. continue;
  474. }
  475. if (anim->value_track_get_update_mode(i) != Animation::UPDATE_CAPTURE) {
  476. continue;
  477. }
  478. if (anim->track_get_key_count(i) == 0) {
  479. continue;
  480. }
  481. max_dur = MAX(max_dur, p_from_end ? current_pos - anim->track_get_key_time(i, anim->track_get_key_count(i) - 1) : anim->track_get_key_time(i, 0) - current_pos);
  482. }
  483. p_duration = max_dur;
  484. }
  485. if (Math::is_zero_approx(p_duration)) {
  486. return;
  487. }
  488. capture(name, p_duration, p_trans_type, p_ease_type);
  489. }
  490. void AnimationPlayer::play_with_capture(const StringName &p_name, double p_duration, double p_custom_blend, float p_custom_scale, bool p_from_end, Tween::TransitionType p_trans_type, Tween::EaseType p_ease_type) {
  491. _capture(p_name, p_from_end, p_duration, p_trans_type, p_ease_type);
  492. _play(p_name, p_custom_blend, p_custom_scale, p_from_end);
  493. }
  494. bool AnimationPlayer::is_playing() const {
  495. return playing;
  496. }
  497. void AnimationPlayer::set_current_animation(const String &p_animation) {
  498. if (p_animation == "[stop]" || p_animation.is_empty()) {
  499. stop();
  500. } else if (!is_playing()) {
  501. play(p_animation);
  502. } else if (playback.assigned != p_animation) {
  503. float speed = playback.current.speed_scale;
  504. play(p_animation, -1.0, speed, signbit(speed));
  505. } else {
  506. // Same animation, do not replay from start.
  507. }
  508. }
  509. String AnimationPlayer::get_current_animation() const {
  510. return (is_playing() ? playback.assigned : "");
  511. }
  512. void AnimationPlayer::set_assigned_animation(const String &p_animation) {
  513. if (is_playing()) {
  514. float speed = playback.current.speed_scale;
  515. play(p_animation, -1.0, speed, signbit(speed));
  516. } else {
  517. ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation));
  518. playback.current.pos = 0;
  519. playback.current.from = &animation_set[p_animation];
  520. playback.current.start_time = -1;
  521. playback.current.end_time = -1;
  522. playback.assigned = p_animation;
  523. emit_signal(SNAME("current_animation_changed"), playback.assigned);
  524. }
  525. }
  526. String AnimationPlayer::get_assigned_animation() const {
  527. return playback.assigned;
  528. }
  529. void AnimationPlayer::pause() {
  530. _stop_internal(false, false);
  531. }
  532. void AnimationPlayer::stop(bool p_keep_state) {
  533. _stop_internal(true, p_keep_state);
  534. }
  535. void AnimationPlayer::set_speed_scale(float p_speed) {
  536. speed_scale = p_speed;
  537. }
  538. float AnimationPlayer::get_speed_scale() const {
  539. return speed_scale;
  540. }
  541. float AnimationPlayer::get_playing_speed() const {
  542. if (!playing) {
  543. return 0;
  544. }
  545. return speed_scale * playback.current.speed_scale;
  546. }
  547. void AnimationPlayer::seek_internal(double p_time, bool p_update, bool p_update_only, bool p_is_internal_seek) {
  548. if (!active) {
  549. return;
  550. }
  551. bool is_backward = Animation::is_less_approx(p_time, playback.current.pos);
  552. _check_immediately_after_start();
  553. playback.current.pos = p_time;
  554. if (!playback.current.from) {
  555. if (playback.assigned) {
  556. ERR_FAIL_COND_MSG(!animation_set.has(playback.assigned), vformat("Animation not found: %s.", playback.assigned));
  557. playback.current.from = &animation_set[playback.assigned];
  558. }
  559. if (!playback.current.from) {
  560. return; // There is no animation.
  561. }
  562. }
  563. double start = playback.current.get_start_time();
  564. double end = playback.current.get_end_time();
  565. // Clamp the seek position.
  566. p_time = CLAMP(p_time, start, end);
  567. playback.seeked = true;
  568. playback.internal_seeked = p_is_internal_seek;
  569. if (p_update) {
  570. _process_animation(is_backward ? -0.0 : 0.0, p_update_only);
  571. playback.seeked = false; // If animation was proceeded here, no more seek in internal process.
  572. }
  573. }
  574. void AnimationPlayer::seek(double p_time, bool p_update, bool p_update_only) {
  575. seek_internal(p_time, p_update, p_update_only);
  576. }
  577. void AnimationPlayer::advance(double p_time) {
  578. _check_immediately_after_start();
  579. AnimationMixer::advance(p_time);
  580. }
  581. void AnimationPlayer::_check_immediately_after_start() {
  582. if (playback.started) {
  583. _process_animation(0); // Force process current key for Discrete/Method/Audio/AnimationPlayback. Then, started flag is cleared.
  584. }
  585. }
  586. bool AnimationPlayer::is_valid() const {
  587. return (playback.current.from);
  588. }
  589. double AnimationPlayer::get_current_animation_position() const {
  590. ERR_FAIL_NULL_V_MSG(playback.current.from, 0, "AnimationPlayer has no current animation.");
  591. return playback.current.pos;
  592. }
  593. double AnimationPlayer::get_current_animation_length() const {
  594. ERR_FAIL_NULL_V_MSG(playback.current.from, 0, "AnimationPlayer has no current animation.");
  595. return playback.current.from->animation->get_length();
  596. }
  597. void AnimationPlayer::set_section_with_markers(const StringName &p_start_marker, const StringName &p_end_marker) {
  598. ERR_FAIL_NULL_MSG(playback.current.from, "AnimationPlayer has no current animation.");
  599. ERR_FAIL_COND_MSG(p_start_marker == p_end_marker && p_start_marker, vformat("Start marker and end marker cannot be the same marker: %s.", p_start_marker));
  600. ERR_FAIL_COND_MSG(p_start_marker && !playback.current.from->animation->has_marker(p_start_marker), vformat("Marker %s not found in animation: %s.", p_start_marker, playback.current.from->animation->get_name()));
  601. ERR_FAIL_COND_MSG(p_end_marker && !playback.current.from->animation->has_marker(p_end_marker), vformat("Marker %s not found in animation: %s.", p_end_marker, playback.current.from->animation->get_name()));
  602. double start_time = p_start_marker ? playback.current.from->animation->get_marker_time(p_start_marker) : -1;
  603. double end_time = p_end_marker ? playback.current.from->animation->get_marker_time(p_end_marker) : -1;
  604. if (p_start_marker && Animation::is_less_approx(start_time, 0)) {
  605. WARN_PRINT_ONCE_ED(vformat("Marker %s time must be positive in animation: %s.", p_start_marker, playback.current.from->animation->get_name()));
  606. }
  607. if (p_end_marker && Animation::is_less_approx(end_time, 0)) {
  608. WARN_PRINT_ONCE_ED(vformat("Marker %s time must be positive in animation: %s.", p_end_marker, playback.current.from->animation->get_name()));
  609. }
  610. set_section(start_time, end_time);
  611. }
  612. void AnimationPlayer::set_section(double p_start_time, double p_end_time) {
  613. ERR_FAIL_NULL_MSG(playback.current.from, "AnimationPlayer has no current animation.");
  614. ERR_FAIL_COND_MSG(Animation::is_greater_or_equal_approx(p_start_time, 0) && Animation::is_greater_or_equal_approx(p_end_time, 0) && Animation::is_greater_or_equal_approx(p_start_time, p_end_time), vformat("Start time %f is greater than end time %f.", p_start_time, p_end_time));
  615. playback.current.start_time = p_start_time;
  616. playback.current.end_time = p_end_time;
  617. playback.current.pos = CLAMP(playback.current.pos, playback.current.get_start_time(), playback.current.get_end_time());
  618. }
  619. void AnimationPlayer::reset_section() {
  620. playback.current.start_time = -1;
  621. playback.current.end_time = -1;
  622. }
  623. double AnimationPlayer::get_section_start_time() const {
  624. ERR_FAIL_NULL_V_MSG(playback.current.from, playback.current.start_time, "AnimationPlayer has no current animation.");
  625. return playback.current.get_start_time();
  626. }
  627. double AnimationPlayer::get_section_end_time() const {
  628. ERR_FAIL_NULL_V_MSG(playback.current.from, playback.current.end_time, "AnimationPlayer has no current animation.");
  629. return playback.current.get_end_time();
  630. }
  631. bool AnimationPlayer::has_section() const {
  632. return Animation::is_greater_or_equal_approx(playback.current.start_time, 0) || Animation::is_greater_or_equal_approx(playback.current.end_time, 0);
  633. }
  634. void AnimationPlayer::set_autoplay(const String &p_name) {
  635. if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
  636. WARN_PRINT("Setting autoplay after the node has been added to the scene has no effect.");
  637. }
  638. autoplay = p_name;
  639. }
  640. String AnimationPlayer::get_autoplay() const {
  641. return autoplay;
  642. }
  643. void AnimationPlayer::set_movie_quit_on_finish_enabled(bool p_enabled) {
  644. movie_quit_on_finish = p_enabled;
  645. }
  646. bool AnimationPlayer::is_movie_quit_on_finish_enabled() const {
  647. return movie_quit_on_finish;
  648. }
  649. void AnimationPlayer::_stop_internal(bool p_reset, bool p_keep_state) {
  650. _clear_caches();
  651. Playback &c = playback;
  652. // c.blend.clear();
  653. double start = c.current.from ? playback.current.get_start_time() : 0;
  654. if (p_reset) {
  655. c.blend.clear();
  656. if (p_keep_state) {
  657. c.current.pos = start;
  658. } else {
  659. is_stopping = true;
  660. seek_internal(start, true, true, true);
  661. is_stopping = false;
  662. }
  663. c.current.from = nullptr;
  664. c.current.speed_scale = 1;
  665. emit_signal(SNAME("current_animation_changed"), "");
  666. }
  667. _set_process(false);
  668. playback_queue.clear();
  669. playing = false;
  670. }
  671. void AnimationPlayer::animation_set_next(const StringName &p_animation, const StringName &p_next) {
  672. ERR_FAIL_COND_MSG(!animation_set.has(p_animation), vformat("Animation not found: %s.", p_animation));
  673. animation_next_set[p_animation] = p_next;
  674. }
  675. StringName AnimationPlayer::animation_get_next(const StringName &p_animation) const {
  676. if (!animation_next_set.has(p_animation)) {
  677. return StringName();
  678. }
  679. return animation_next_set[p_animation];
  680. }
  681. void AnimationPlayer::set_default_blend_time(double p_default) {
  682. default_blend_time = p_default;
  683. }
  684. double AnimationPlayer::get_default_blend_time() const {
  685. return default_blend_time;
  686. }
  687. void AnimationPlayer::set_blend_time(const StringName &p_animation1, const StringName &p_animation2, double p_time) {
  688. ERR_FAIL_COND_MSG(!animation_set.has(p_animation1), vformat("Animation not found: %s.", p_animation1));
  689. ERR_FAIL_COND_MSG(!animation_set.has(p_animation2), vformat("Animation not found: %s.", p_animation2));
  690. ERR_FAIL_COND_MSG(p_time < 0, "Blend time cannot be smaller than 0.");
  691. BlendKey bk;
  692. bk.from = p_animation1;
  693. bk.to = p_animation2;
  694. if (Math::is_zero_approx(p_time)) {
  695. blend_times.erase(bk);
  696. } else {
  697. blend_times[bk] = p_time;
  698. }
  699. }
  700. double AnimationPlayer::get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const {
  701. BlendKey bk;
  702. bk.from = p_animation1;
  703. bk.to = p_animation2;
  704. if (blend_times.has(bk)) {
  705. return blend_times[bk];
  706. } else {
  707. return 0;
  708. }
  709. }
  710. void AnimationPlayer::set_auto_capture(bool p_auto_capture) {
  711. auto_capture = p_auto_capture;
  712. notify_property_list_changed();
  713. }
  714. bool AnimationPlayer::is_auto_capture() const {
  715. return auto_capture;
  716. }
  717. void AnimationPlayer::set_auto_capture_duration(double p_auto_capture_duration) {
  718. auto_capture_duration = p_auto_capture_duration;
  719. }
  720. double AnimationPlayer::get_auto_capture_duration() const {
  721. return auto_capture_duration;
  722. }
  723. void AnimationPlayer::set_auto_capture_transition_type(Tween::TransitionType p_auto_capture_transition_type) {
  724. auto_capture_transition_type = p_auto_capture_transition_type;
  725. }
  726. Tween::TransitionType AnimationPlayer::get_auto_capture_transition_type() const {
  727. return auto_capture_transition_type;
  728. }
  729. void AnimationPlayer::set_auto_capture_ease_type(Tween::EaseType p_auto_capture_ease_type) {
  730. auto_capture_ease_type = p_auto_capture_ease_type;
  731. }
  732. Tween::EaseType AnimationPlayer::get_auto_capture_ease_type() const {
  733. return auto_capture_ease_type;
  734. }
  735. #ifdef TOOLS_ENABLED
  736. void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  737. const String pf = p_function;
  738. if (p_idx == 0 && (pf == "play" || pf == "play_backwards" || pf == "has_animation" || pf == "queue")) {
  739. List<StringName> al;
  740. get_animation_list(&al);
  741. for (const StringName &name : al) {
  742. r_options->push_back(String(name).quote());
  743. }
  744. }
  745. AnimationMixer::get_argument_options(p_function, p_idx, r_options);
  746. }
  747. #endif
  748. void AnimationPlayer::_animation_removed(const StringName &p_name, const StringName &p_library) {
  749. AnimationMixer::_animation_removed(p_name, p_library);
  750. StringName name = p_library == StringName() ? p_name : StringName(String(p_library) + "/" + String(p_name));
  751. if (!animation_set.has(name)) {
  752. return; // No need to update because not the one from the library being used.
  753. }
  754. _animation_set_cache_update();
  755. // Erase blends if needed
  756. List<BlendKey> to_erase;
  757. for (const KeyValue<BlendKey, double> &E : blend_times) {
  758. BlendKey bk = E.key;
  759. if (bk.from == name || bk.to == name) {
  760. to_erase.push_back(bk);
  761. }
  762. }
  763. while (to_erase.size()) {
  764. blend_times.erase(to_erase.front()->get());
  765. to_erase.pop_front();
  766. }
  767. }
  768. void AnimationPlayer::_rename_animation(const StringName &p_from_name, const StringName &p_to_name) {
  769. AnimationMixer::_rename_animation(p_from_name, p_to_name);
  770. // Rename autoplay or blends if needed.
  771. List<BlendKey> to_erase;
  772. HashMap<BlendKey, double, BlendKey> to_insert;
  773. for (const KeyValue<BlendKey, double> &E : blend_times) {
  774. BlendKey bk = E.key;
  775. BlendKey new_bk = bk;
  776. bool erase = false;
  777. if (bk.from == p_from_name) {
  778. new_bk.from = p_to_name;
  779. erase = true;
  780. }
  781. if (bk.to == p_from_name) {
  782. new_bk.to = p_to_name;
  783. erase = true;
  784. }
  785. if (erase) {
  786. to_erase.push_back(bk);
  787. to_insert[new_bk] = E.value;
  788. }
  789. }
  790. while (to_erase.size()) {
  791. blend_times.erase(to_erase.front()->get());
  792. to_erase.pop_front();
  793. }
  794. while (to_insert.size()) {
  795. blend_times[to_insert.begin()->key] = to_insert.begin()->value;
  796. to_insert.remove(to_insert.begin());
  797. }
  798. if (autoplay == p_from_name) {
  799. autoplay = p_to_name;
  800. }
  801. }
  802. void AnimationPlayer::_bind_methods() {
  803. ClassDB::bind_method(D_METHOD("animation_set_next", "animation_from", "animation_to"), &AnimationPlayer::animation_set_next);
  804. ClassDB::bind_method(D_METHOD("animation_get_next", "animation_from"), &AnimationPlayer::animation_get_next);
  805. ClassDB::bind_method(D_METHOD("set_blend_time", "animation_from", "animation_to", "sec"), &AnimationPlayer::set_blend_time);
  806. ClassDB::bind_method(D_METHOD("get_blend_time", "animation_from", "animation_to"), &AnimationPlayer::get_blend_time);
  807. ClassDB::bind_method(D_METHOD("set_default_blend_time", "sec"), &AnimationPlayer::set_default_blend_time);
  808. ClassDB::bind_method(D_METHOD("get_default_blend_time"), &AnimationPlayer::get_default_blend_time);
  809. ClassDB::bind_method(D_METHOD("set_auto_capture", "auto_capture"), &AnimationPlayer::set_auto_capture);
  810. ClassDB::bind_method(D_METHOD("is_auto_capture"), &AnimationPlayer::is_auto_capture);
  811. ClassDB::bind_method(D_METHOD("set_auto_capture_duration", "auto_capture_duration"), &AnimationPlayer::set_auto_capture_duration);
  812. ClassDB::bind_method(D_METHOD("get_auto_capture_duration"), &AnimationPlayer::get_auto_capture_duration);
  813. ClassDB::bind_method(D_METHOD("set_auto_capture_transition_type", "auto_capture_transition_type"), &AnimationPlayer::set_auto_capture_transition_type);
  814. ClassDB::bind_method(D_METHOD("get_auto_capture_transition_type"), &AnimationPlayer::get_auto_capture_transition_type);
  815. ClassDB::bind_method(D_METHOD("set_auto_capture_ease_type", "auto_capture_ease_type"), &AnimationPlayer::set_auto_capture_ease_type);
  816. ClassDB::bind_method(D_METHOD("get_auto_capture_ease_type"), &AnimationPlayer::get_auto_capture_ease_type);
  817. ClassDB::bind_method(D_METHOD("play", "name", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play, DEFVAL(StringName()), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
  818. ClassDB::bind_method(D_METHOD("play_section_with_markers", "name", "start_marker", "end_marker", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play_section_with_markers, DEFVAL(StringName()), DEFVAL(StringName()), DEFVAL(StringName()), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
  819. ClassDB::bind_method(D_METHOD("play_section", "name", "start_time", "end_time", "custom_blend", "custom_speed", "from_end"), &AnimationPlayer::play_section, DEFVAL(StringName()), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false));
  820. ClassDB::bind_method(D_METHOD("play_backwards", "name", "custom_blend"), &AnimationPlayer::play_backwards, DEFVAL(StringName()), DEFVAL(-1));
  821. ClassDB::bind_method(D_METHOD("play_section_with_markers_backwards", "name", "start_marker", "end_marker", "custom_blend"), &AnimationPlayer::play_section_with_markers_backwards, DEFVAL(StringName()), DEFVAL(StringName()), DEFVAL(StringName()), DEFVAL(-1));
  822. ClassDB::bind_method(D_METHOD("play_section_backwards", "name", "start_time", "end_time", "custom_blend"), &AnimationPlayer::play_section_backwards, DEFVAL(StringName()), DEFVAL(-1), DEFVAL(-1), DEFVAL(-1));
  823. ClassDB::bind_method(D_METHOD("play_with_capture", "name", "duration", "custom_blend", "custom_speed", "from_end", "trans_type", "ease_type"), &AnimationPlayer::play_with_capture, DEFVAL(StringName()), DEFVAL(-1.0), DEFVAL(-1), DEFVAL(1.0), DEFVAL(false), DEFVAL(Tween::TRANS_LINEAR), DEFVAL(Tween::EASE_IN));
  824. ClassDB::bind_method(D_METHOD("pause"), &AnimationPlayer::pause);
  825. ClassDB::bind_method(D_METHOD("stop", "keep_state"), &AnimationPlayer::stop, DEFVAL(false));
  826. ClassDB::bind_method(D_METHOD("is_playing"), &AnimationPlayer::is_playing);
  827. ClassDB::bind_method(D_METHOD("set_current_animation", "animation"), &AnimationPlayer::set_current_animation);
  828. ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation);
  829. ClassDB::bind_method(D_METHOD("set_assigned_animation", "animation"), &AnimationPlayer::set_assigned_animation);
  830. ClassDB::bind_method(D_METHOD("get_assigned_animation"), &AnimationPlayer::get_assigned_animation);
  831. ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue);
  832. ClassDB::bind_method(D_METHOD("get_queue"), &AnimationPlayer::get_queue);
  833. ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue);
  834. ClassDB::bind_method(D_METHOD("set_speed_scale", "speed"), &AnimationPlayer::set_speed_scale);
  835. ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimationPlayer::get_speed_scale);
  836. ClassDB::bind_method(D_METHOD("get_playing_speed"), &AnimationPlayer::get_playing_speed);
  837. ClassDB::bind_method(D_METHOD("set_autoplay", "name"), &AnimationPlayer::set_autoplay);
  838. ClassDB::bind_method(D_METHOD("get_autoplay"), &AnimationPlayer::get_autoplay);
  839. ClassDB::bind_method(D_METHOD("find_animation", "animation"), &AnimationPlayer::find_animation);
  840. ClassDB::bind_method(D_METHOD("find_animation_library", "animation"), &AnimationPlayer::find_animation_library);
  841. ClassDB::bind_method(D_METHOD("set_movie_quit_on_finish_enabled", "enabled"), &AnimationPlayer::set_movie_quit_on_finish_enabled);
  842. ClassDB::bind_method(D_METHOD("is_movie_quit_on_finish_enabled"), &AnimationPlayer::is_movie_quit_on_finish_enabled);
  843. ClassDB::bind_method(D_METHOD("get_current_animation_position"), &AnimationPlayer::get_current_animation_position);
  844. ClassDB::bind_method(D_METHOD("get_current_animation_length"), &AnimationPlayer::get_current_animation_length);
  845. ClassDB::bind_method(D_METHOD("set_section_with_markers", "start_marker", "end_marker"), &AnimationPlayer::set_section_with_markers, DEFVAL(StringName()), DEFVAL(StringName()));
  846. ClassDB::bind_method(D_METHOD("set_section", "start_time", "end_time"), &AnimationPlayer::set_section, DEFVAL(-1), DEFVAL(-1));
  847. ClassDB::bind_method(D_METHOD("reset_section"), &AnimationPlayer::reset_section);
  848. ClassDB::bind_method(D_METHOD("get_section_start_time"), &AnimationPlayer::get_section_start_time);
  849. ClassDB::bind_method(D_METHOD("get_section_end_time"), &AnimationPlayer::get_section_end_time);
  850. ClassDB::bind_method(D_METHOD("has_section"), &AnimationPlayer::has_section);
  851. ClassDB::bind_method(D_METHOD("seek", "seconds", "update", "update_only"), &AnimationPlayer::seek, DEFVAL(false), DEFVAL(false));
  852. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR), "set_current_animation", "get_current_animation");
  853. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "assigned_animation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_assigned_animation", "get_assigned_animation");
  854. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_autoplay", "get_autoplay");
  855. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "current_animation_length", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_current_animation_length");
  856. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "current_animation_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_current_animation_position");
  857. ADD_GROUP("Playback Options", "playback_");
  858. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_auto_capture"), "set_auto_capture", "is_auto_capture");
  859. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_auto_capture_duration", PROPERTY_HINT_NONE, "suffix:s"), "set_auto_capture_duration", "get_auto_capture_duration");
  860. ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_auto_capture_transition_type", PROPERTY_HINT_ENUM, "Linear,Sine,Quint,Quart,Quad,Expo,Elastic,Cubic,Circ,Bounce,Back,Spring"), "set_auto_capture_transition_type", "get_auto_capture_transition_type");
  861. ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_auto_capture_ease_type", PROPERTY_HINT_ENUM, "In,Out,InOut,OutIn"), "set_auto_capture_ease_type", "get_auto_capture_ease_type");
  862. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01,suffix:s"), "set_default_blend_time", "get_default_blend_time");
  863. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "-4,4,0.001,or_less,or_greater"), "set_speed_scale", "get_speed_scale");
  864. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "movie_quit_on_finish"), "set_movie_quit_on_finish_enabled", "is_movie_quit_on_finish_enabled");
  865. ADD_SIGNAL(MethodInfo(SNAME("current_animation_changed"), PropertyInfo(Variant::STRING, "name")));
  866. ADD_SIGNAL(MethodInfo(SNAME("animation_changed"), PropertyInfo(Variant::STRING_NAME, "old_name"), PropertyInfo(Variant::STRING_NAME, "new_name")));
  867. }
  868. AnimationPlayer::AnimationPlayer() {
  869. }
  870. AnimationPlayer::~AnimationPlayer() {
  871. }