diff options
Diffstat (limited to 'scene/2d/animated_sprite_2d.cpp')
-rw-r--r-- | scene/2d/animated_sprite_2d.cpp | 53 |
1 files changed, 10 insertions, 43 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index 3268544519..0f98fad824 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -31,11 +31,9 @@ #include "animated_sprite_2d.h" #include "core/os/os.h" +#include "scene/main/viewport.h" #include "scene/scene_string_names.h" -#define NORMAL_SUFFIX "_normal" -#define SPECULAR_SUFFIX "_specular" - #ifdef TOOLS_ENABLED Dictionary AnimatedSprite2D::_edit_get_state() const { Dictionary state = Node2D::_edit_get_state(); @@ -152,8 +150,6 @@ void SpriteFrames::add_animation(const StringName &p_anim) { ERR_FAIL_COND_MSG(animations.has(p_anim), "SpriteFrames already has animation '" + p_anim + "'."); animations[p_anim] = Anim(); - animations[p_anim].normal_name = String(p_anim) + NORMAL_SUFFIX; - animations[p_anim].specular_name = String(p_anim) + SPECULAR_SUFFIX; } bool SpriteFrames::has_animation(const StringName &p_anim) const { @@ -171,8 +167,6 @@ void SpriteFrames::rename_animation(const StringName &p_prev, const StringName & Anim anim = animations[p_prev]; animations.erase(p_prev); animations[p_next] = anim; - animations[p_next].normal_name = String(p_next) + NORMAL_SUFFIX; - animations[p_next].specular_name = String(p_next) + SPECULAR_SUFFIX; } Vector<String> SpriteFrames::_get_animation_list() const { @@ -441,9 +435,6 @@ void AnimatedSprite2D::_notification(int p_what) { return; } - Ref<Texture2D> normal = frames->get_normal_frame(animation, frame); - Ref<Texture2D> specular = frames->get_specular_frame(animation, frame); - RID ci = get_canvas_item(); Size2i s; @@ -453,7 +444,7 @@ void AnimatedSprite2D::_notification(int p_what) { ofs -= s / 2; } - if (Engine::get_singleton()->get_use_pixel_snap()) { + if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { ofs = ofs.floor(); } Rect2 dst_rect(ofs, s); @@ -465,7 +456,7 @@ void AnimatedSprite2D::_notification(int p_what) { dst_rect.size.y = -dst_rect.size.y; } - texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false, normal, specular, Color(specular_color.r, specular_color.g, specular_color.b, shininess)); + texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false); } break; } @@ -660,29 +651,16 @@ StringName AnimatedSprite2D::get_animation() const { } String AnimatedSprite2D::get_configuration_warning() const { + String warning = Node2D::get_configuration_warning(); + if (frames.is_null()) { - return TTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite to display frames."); + if (!warning.empty()) { + warning += "\n\n"; + } + warning += TTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite to display frames."); } - return String(); -} - -void AnimatedSprite2D::set_specular_color(const Color &p_color) { - specular_color = p_color; - update(); -} - -Color AnimatedSprite2D::get_specular_color() const { - return specular_color; -} - -void AnimatedSprite2D::set_shininess(float p_shininess) { - shininess = CLAMP(p_shininess, 0.0, 1.0); - update(); -} - -float AnimatedSprite2D::get_shininess() const { - return shininess; + return warning; } void AnimatedSprite2D::_bind_methods() { @@ -717,12 +695,6 @@ void AnimatedSprite2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite2D::set_speed_scale); ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite2D::get_speed_scale); - ClassDB::bind_method(D_METHOD("set_specular_color", "color"), &AnimatedSprite2D::set_specular_color); - ClassDB::bind_method(D_METHOD("get_specular_color"), &AnimatedSprite2D::get_specular_color); - - ClassDB::bind_method(D_METHOD("set_shininess", "shininess"), &AnimatedSprite2D::set_shininess); - ClassDB::bind_method(D_METHOD("get_shininess"), &AnimatedSprite2D::get_shininess); - ADD_SIGNAL(MethodInfo("frame_changed")); ADD_SIGNAL(MethodInfo("animation_finished")); @@ -732,9 +704,6 @@ void AnimatedSprite2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "frame"), "set_frame", "get_frame"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale"), "set_speed_scale", "get_speed_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing"); - ADD_GROUP("Lighting", ""); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_specular_color", "get_specular_color"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "shininess", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_shininess", "get_shininess"); ADD_GROUP("Offset", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset"); @@ -754,6 +723,4 @@ AnimatedSprite2D::AnimatedSprite2D() { animation = "default"; timeout = 0; is_over = false; - specular_color = Color(1, 1, 1, 1); - shininess = 1.0; } |