diff options
author | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2018-01-12 00:35:12 +0200 |
---|---|---|
committer | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2018-01-12 00:58:14 +0200 |
commit | 9b8e8b2220b4e2bac3310262d3d1cd7a8eb3b0a5 (patch) | |
tree | 805b828de2c1b899392245dbf77d45c4450664c8 /scene/animation | |
parent | c1c17b04bd5090503416cef24b4da9209d5cf563 (diff) |
Bind many more properties to scripts
Notable potentially breaking changes:
- PROPERTY_USAGE_NOEDITOR is now PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK, without PROPERTY_USAGE_INTERNAL
- Some properties were renamed, and sometimes even shadowed by new ones
- New getter methods (some virtual) were added
Diffstat (limited to 'scene/animation')
-rw-r--r-- | scene/animation/animation_player.cpp | 118 | ||||
-rw-r--r-- | scene/animation/animation_player.h | 1 | ||||
-rw-r--r-- | scene/animation/tween.cpp | 2 |
3 files changed, 63 insertions, 58 deletions
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 7d909d0cb3..2a276981db 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -49,24 +49,15 @@ bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; - if (p_name == SceneStringNames::get_singleton()->playback_speed || p_name == SceneStringNames::get_singleton()->speed) { //bw compatibility - set_speed_scale(p_value); + if (name.begins_with("playback/play")) { // bw compatibility - } else if (p_name == SceneStringNames::get_singleton()->playback_active) { - set_active(p_value); - } else if (name.begins_with("playback/play")) { + set_current_animation(p_value); - String which = p_value; - - if (which == "[stop]") - stop(); - else - play(which); } else if (name.begins_with("anims/")) { String which = name.get_slicec('/', 1); - add_animation(which, p_value); + } else if (name.begins_with("next/")) { String which = name.get_slicec('/', 1); @@ -100,24 +91,15 @@ bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; - if (name == "playback/speed") { //bw compatibility + if (name == "playback/play") { // bw compatibility - r_ret = speed_scale; - } else if (name == "playback/active") { - - r_ret = is_active(); - } else if (name == "playback/play") { - - if (is_active() && is_playing()) - r_ret = playback.assigned; - else - r_ret = "[stop]"; + r_ret = get_current_animation(); } else if (name.begins_with("anims/")) { String which = name.get_slicec('/', 1); - r_ret = get_animation(which).get_ref_ptr(); + } else if (name.begins_with("next/")) { String which = name.get_slicec('/', 1); @@ -150,18 +132,37 @@ bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const { return true; } -void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const { +void AnimationPlayer::_validate_property(PropertyInfo &property) const { + + if (property.name == "current_animation") { + List<String> names; + + for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) { + names.push_back(E->key()); + } + names.sort(); + names.push_front("[stop]"); + String hint; + for (List<String>::Element *E = names.front(); E; E = E->next()) { - List<String> names; + if (E != names.front()) + hint += ","; + hint += E->get(); + } + + property.hint_string = hint; + } +} + +void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const { List<PropertyInfo> anim_names; for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) { - anim_names.push_back(PropertyInfo(Variant::OBJECT, "anims/" + String(E->key()), PROPERTY_HINT_RESOURCE_TYPE, "Animation", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE)); + anim_names.push_back(PropertyInfo(Variant::OBJECT, "anims/" + String(E->key()), PROPERTY_HINT_RESOURCE_TYPE, "Animation", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE)); if (E->get().next != StringName()) - anim_names.push_back(PropertyInfo(Variant::STRING, "next/" + String(E->key()), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); - names.push_back(E->key()); + anim_names.push_back(PropertyInfo(Variant::STRING, "next/" + String(E->key()), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); } anim_names.sort(); @@ -170,23 +171,7 @@ void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(E->get()); } - { - names.sort(); - names.push_front("[stop]"); - String hint; - for (List<String>::Element *E = names.front(); E; E = E->next()) { - - if (E != names.front()) - hint += ","; - hint += E->get(); - } - - p_list->push_back(PropertyInfo(Variant::STRING, "playback/play", PROPERTY_HINT_ENUM, hint, PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER)); - p_list->push_back(PropertyInfo(Variant::BOOL, "playback/active", PROPERTY_HINT_NONE, "")); - p_list->push_back(PropertyInfo(Variant::REAL, "playback/speed", PROPERTY_HINT_RANGE, "-64,64,0.01")); - } - - p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } @@ -990,23 +975,29 @@ bool AnimationPlayer::is_playing() const { }; return true; - */ + */ } void AnimationPlayer::set_current_animation(const String &p_anim) { - if (is_playing()) { + if (p_anim == "[stop]" || p_anim == "") { + stop(); + } else if (!is_playing() || playback.assigned != p_anim) { play(p_anim); } else { - ERR_FAIL_COND(!animation_set.has(p_anim)); - playback.current.pos = 0; - playback.current.from = &animation_set[p_anim]; - playback.assigned = p_anim; + // Same animation, do not replay from start } + + /* + ERR_FAIL_COND(!animation_set.has(p_anim)); + playback.current.pos = 0; + playback.current.from = &animation_set[p_anim]; + playback.assigned = p_anim; + */ } String AnimationPlayer::get_current_animation() const { - return (playback.assigned); + return (is_playing() ? playback.assigned : ""); } void AnimationPlayer::stop(bool p_reset) { @@ -1033,8 +1024,10 @@ float AnimationPlayer::get_speed_scale() const { void AnimationPlayer::seek(float p_time, bool p_update) { if (!playback.current.from) { - if (playback.assigned) - set_current_animation(playback.assigned); + if (playback.assigned) { + ERR_FAIL_COND(!animation_set.has(playback.assigned)); + playback.current.from = &animation_set[playback.assigned]; + } ERR_FAIL_COND(!playback.current.from); } @@ -1047,8 +1040,10 @@ void AnimationPlayer::seek(float p_time, bool p_update) { void AnimationPlayer::seek_delta(float p_time, float p_delta) { if (!playback.current.from) { - if (playback.assigned) - set_current_animation(playback.assigned); + if (playback.assigned) { + ERR_FAIL_COND(!animation_set.has(playback.assigned)); + playback.current.from = &animation_set[playback.assigned]; + } ERR_FAIL_COND(!playback.current.from); } @@ -1334,10 +1329,17 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("seek", "seconds", "update"), &AnimationPlayer::seek, DEFVAL(false)); ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationPlayer::advance); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER), "set_current_animation", "get_current_animation"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_autoplay", "get_autoplay"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_length", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_length"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position"); + ADD_GROUP("Playback Options", "playback_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_animation_process_mode", "get_animation_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_default_blend_time", "get_default_blend_time"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_active", PROPERTY_HINT_NONE, "", 0), "set_active", "is_active"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale"); ADD_SIGNAL(MethodInfo("animation_finished", PropertyInfo(Variant::STRING, "name"))); ADD_SIGNAL(MethodInfo("animation_changed", PropertyInfo(Variant::STRING, "old_name"), PropertyInfo(Variant::STRING, "new_name"))); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index ef17e5adac..ef1720443f 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -251,6 +251,7 @@ private: protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; + virtual void _validate_property(PropertyInfo &property) const; void _get_property_list(List<PropertyInfo> *p_list) const; void _notification(int p_what); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 3fc68fc5e8..000dbb9cbd 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -223,7 +223,9 @@ void Tween::_bind_methods() { ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key"), PropertyInfo(Variant::REAL, "elapsed"), PropertyInfo(Variant::OBJECT, "value"))); ADD_SIGNAL(MethodInfo("tween_completed", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key"))); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "repeat"), "set_repeat", "is_repeat"); ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_tween_process_mode", "get_tween_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale"); BIND_ENUM_CONSTANT(TWEEN_PROCESS_PHYSICS); BIND_ENUM_CONSTANT(TWEEN_PROCESS_IDLE); |