Skip to content

Commit

Permalink
Merge pull request #60757 from timothyqiu/animated-sprite-autocomplet…
Browse files Browse the repository at this point in the history
…e-3.x
  • Loading branch information
akien-mga authored May 5, 2022
2 parents eea48d9 + 0f7f3d0 commit 6f5d57e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scene/2d/animated_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include "core/os/os.h"
#include "scene/scene_string_names.h"

#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
#endif

#define NORMAL_SUFFIX "_normal"

#ifdef TOOLS_ENABLED
Expand Down Expand Up @@ -651,6 +655,23 @@ String AnimatedSprite::get_configuration_warning() const {
return warning;
}

void AnimatedSprite::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
#else
const String quote_style = "\"";
#endif

if (p_idx == 0 && p_function == "play" && frames.is_valid()) {
List<StringName> al;
frames->get_animation_list(&al);
for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
r_options->push_back(quote_style + String(E->get()) + quote_style);
}
}
Node::get_argument_options(p_function, p_idx, r_options);
}

void AnimatedSprite::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite::set_sprite_frames);
ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite::get_sprite_frames);
Expand Down
2 changes: 2 additions & 0 deletions scene/2d/animated_sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class AnimatedSprite : public Node2D {
bool is_flipped_v() const;

virtual String get_configuration_warning() const;
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;

AnimatedSprite();
};

Expand Down
21 changes: 21 additions & 0 deletions scene/3d/sprite_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include "core/core_string_names.h"
#include "scene/scene_string_names.h"

#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
#endif

Color SpriteBase3D::_get_color_accum() {
if (!color_dirty) {
return color_accum;
Expand Down Expand Up @@ -1176,6 +1180,23 @@ String AnimatedSprite3D::get_configuration_warning() const {
return warning;
}

void AnimatedSprite3D::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
#else
const String quote_style = "\"";
#endif

if (p_idx == 0 && p_function == "play" && frames.is_valid()) {
List<StringName> al;
frames->get_animation_list(&al);
for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
r_options->push_back(quote_style + String(E->get()) + quote_style);
}
}
Node::get_argument_options(p_function, p_idx, r_options);
}

void AnimatedSprite3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite3D::set_sprite_frames);
ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite3D::get_sprite_frames);
Expand Down
2 changes: 2 additions & 0 deletions scene/3d/sprite_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class AnimatedSprite3D : public SpriteBase3D {
virtual Rect2 get_item_rect() const;

virtual String get_configuration_warning() const;
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;

AnimatedSprite3D();
};

Expand Down

0 comments on commit 6f5d57e

Please sign in to comment.