Add a constant StringName for RESET animation
This commit is contained in:
parent
97034939fe
commit
9cb66cac2d
|
@ -39,6 +39,7 @@
|
||||||
#include "editor_scale.h"
|
#include "editor_scale.h"
|
||||||
#include "scene/animation/animation_player.h"
|
#include "scene/animation/animation_player.h"
|
||||||
#include "scene/main/window.h"
|
#include "scene/main/window.h"
|
||||||
|
#include "scene/scene_string_names.h"
|
||||||
#include "servers/audio/audio_stream.h"
|
#include "servers/audio/audio_stream.h"
|
||||||
|
|
||||||
class AnimationTrackKeyEdit : public Object {
|
class AnimationTrackKeyEdit : public Object {
|
||||||
|
@ -3505,7 +3506,7 @@ void AnimationTrackEditor::make_insert_queue() {
|
||||||
void AnimationTrackEditor::commit_insert_queue() {
|
void AnimationTrackEditor::commit_insert_queue() {
|
||||||
bool reset_allowed = true;
|
bool reset_allowed = true;
|
||||||
AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player();
|
AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player();
|
||||||
if (player->has_animation("RESET") && player->get_animation("RESET") == animation) {
|
if (player->has_animation(SceneStringNames::get_singleton()->RESET) && player->get_animation(SceneStringNames::get_singleton()->RESET) == animation) {
|
||||||
// Avoid messing with the reset animation itself.
|
// Avoid messing with the reset animation itself.
|
||||||
reset_allowed = false;
|
reset_allowed = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -3925,15 +3926,15 @@ void AnimationTrackEditor::insert_value_key(const String &p_property, const Vari
|
||||||
|
|
||||||
Ref<Animation> AnimationTrackEditor::_create_and_get_reset_animation() {
|
Ref<Animation> AnimationTrackEditor::_create_and_get_reset_animation() {
|
||||||
AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player();
|
AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player();
|
||||||
if (player->has_animation("RESET")) {
|
if (player->has_animation(SceneStringNames::get_singleton()->RESET)) {
|
||||||
return player->get_animation("RESET");
|
return player->get_animation(SceneStringNames::get_singleton()->RESET);
|
||||||
} else {
|
} else {
|
||||||
Ref<Animation> reset_anim;
|
Ref<Animation> reset_anim;
|
||||||
reset_anim.instantiate();
|
reset_anim.instantiate();
|
||||||
reset_anim->set_length(ANIM_MIN_LENGTH);
|
reset_anim->set_length(ANIM_MIN_LENGTH);
|
||||||
undo_redo->add_do_method(player, "add_animation", "RESET", reset_anim);
|
undo_redo->add_do_method(player, "add_animation", SceneStringNames::get_singleton()->RESET, reset_anim);
|
||||||
undo_redo->add_do_method(AnimationPlayerEditor::get_singleton(), "_animation_player_changed", player);
|
undo_redo->add_do_method(AnimationPlayerEditor::get_singleton(), "_animation_player_changed", player);
|
||||||
undo_redo->add_undo_method(player, "remove_animation", "RESET");
|
undo_redo->add_undo_method(player, "remove_animation", SceneStringNames::get_singleton()->RESET);
|
||||||
undo_redo->add_undo_method(AnimationPlayerEditor::get_singleton(), "_animation_player_changed", player);
|
undo_redo->add_undo_method(AnimationPlayerEditor::get_singleton(), "_animation_player_changed", player);
|
||||||
return reset_anim;
|
return reset_anim;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "editor/plugins/node_3d_editor_plugin.h" // For onion skinning.
|
#include "editor/plugins/node_3d_editor_plugin.h" // For onion skinning.
|
||||||
#include "scene/main/window.h"
|
#include "scene/main/window.h"
|
||||||
#include "scene/resources/animation.h"
|
#include "scene/resources/animation.h"
|
||||||
|
#include "scene/scene_string_names.h"
|
||||||
#include "servers/rendering_server.h"
|
#include "servers/rendering_server.h"
|
||||||
|
|
||||||
void AnimationPlayerEditor::_node_removed(Node *p_node) {
|
void AnimationPlayerEditor::_node_removed(Node *p_node) {
|
||||||
|
@ -836,12 +837,12 @@ void AnimationPlayerEditor::_update_player() {
|
||||||
for (const StringName &E : animlist) {
|
for (const StringName &E : animlist) {
|
||||||
Ref<Texture2D> icon;
|
Ref<Texture2D> icon;
|
||||||
if (E == player->get_autoplay()) {
|
if (E == player->get_autoplay()) {
|
||||||
if (E == "RESET") {
|
if (E == SceneStringNames::get_singleton()->RESET) {
|
||||||
icon = autoplay_reset_icon;
|
icon = autoplay_reset_icon;
|
||||||
} else {
|
} else {
|
||||||
icon = autoplay_icon;
|
icon = autoplay_icon;
|
||||||
}
|
}
|
||||||
} else if (E == "RESET") {
|
} else if (E == SceneStringNames::get_singleton()->RESET) {
|
||||||
icon = reset_icon;
|
icon = reset_icon;
|
||||||
}
|
}
|
||||||
animation->add_icon_item(icon, E);
|
animation->add_icon_item(icon, E);
|
||||||
|
|
|
@ -1754,7 +1754,7 @@ Ref<AnimatedValuesBackup> AnimationPlayer::backup_animated_values(Node *p_root_o
|
||||||
Ref<AnimatedValuesBackup> AnimationPlayer::apply_reset(bool p_user_initiated) {
|
Ref<AnimatedValuesBackup> AnimationPlayer::apply_reset(bool p_user_initiated) {
|
||||||
ERR_FAIL_COND_V(!can_apply_reset(), Ref<AnimatedValuesBackup>());
|
ERR_FAIL_COND_V(!can_apply_reset(), Ref<AnimatedValuesBackup>());
|
||||||
|
|
||||||
Ref<Animation> reset_anim = animation_set["RESET"].animation;
|
Ref<Animation> reset_anim = animation_set[SceneStringNames::get_singleton()->RESET].animation;
|
||||||
ERR_FAIL_COND_V(reset_anim.is_null(), Ref<AnimatedValuesBackup>());
|
ERR_FAIL_COND_V(reset_anim.is_null(), Ref<AnimatedValuesBackup>());
|
||||||
|
|
||||||
Node *root_node = get_node_or_null(root);
|
Node *root_node = get_node_or_null(root);
|
||||||
|
@ -1762,8 +1762,8 @@ Ref<AnimatedValuesBackup> AnimationPlayer::apply_reset(bool p_user_initiated) {
|
||||||
|
|
||||||
AnimationPlayer *aux_player = memnew(AnimationPlayer);
|
AnimationPlayer *aux_player = memnew(AnimationPlayer);
|
||||||
EditorNode::get_singleton()->add_child(aux_player);
|
EditorNode::get_singleton()->add_child(aux_player);
|
||||||
aux_player->add_animation("RESET", reset_anim);
|
aux_player->add_animation(SceneStringNames::get_singleton()->RESET, reset_anim);
|
||||||
aux_player->set_assigned_animation("RESET");
|
aux_player->set_assigned_animation(SceneStringNames::get_singleton()->RESET);
|
||||||
// Forcing the use of the original root because the scene where original player belongs may be not the active one
|
// Forcing the use of the original root because the scene where original player belongs may be not the active one
|
||||||
Node *root = get_node(get_root());
|
Node *root = get_node(get_root());
|
||||||
Ref<AnimatedValuesBackup> old_values = aux_player->backup_animated_values(root);
|
Ref<AnimatedValuesBackup> old_values = aux_player->backup_animated_values(root);
|
||||||
|
@ -1785,7 +1785,7 @@ Ref<AnimatedValuesBackup> AnimationPlayer::apply_reset(bool p_user_initiated) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnimationPlayer::can_apply_reset() const {
|
bool AnimationPlayer::can_apply_reset() const {
|
||||||
return has_animation("RESET") && playback.assigned != StringName("RESET");
|
return has_animation(SceneStringNames::get_singleton()->RESET) && playback.assigned != SceneStringNames::get_singleton()->RESET;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ SceneStringNames::SceneStringNames() {
|
||||||
animation_finished = StaticCString::create("animation_finished");
|
animation_finished = StaticCString::create("animation_finished");
|
||||||
animation_changed = StaticCString::create("animation_changed");
|
animation_changed = StaticCString::create("animation_changed");
|
||||||
animation_started = StaticCString::create("animation_started");
|
animation_started = StaticCString::create("animation_started");
|
||||||
|
RESET = StaticCString::create("RESET");
|
||||||
|
|
||||||
pose_updated = StaticCString::create("pose_updated");
|
pose_updated = StaticCString::create("pose_updated");
|
||||||
bone_pose_changed = StaticCString::create("bone_pose_changed");
|
bone_pose_changed = StaticCString::create("bone_pose_changed");
|
||||||
|
|
|
@ -97,6 +97,7 @@ public:
|
||||||
StringName animation_finished;
|
StringName animation_finished;
|
||||||
StringName animation_changed;
|
StringName animation_changed;
|
||||||
StringName animation_started;
|
StringName animation_started;
|
||||||
|
StringName RESET;
|
||||||
|
|
||||||
StringName pose_updated;
|
StringName pose_updated;
|
||||||
StringName bone_pose_changed;
|
StringName bone_pose_changed;
|
||||||
|
|
Loading…
Reference in New Issue