From 80025171cd528ffe0eee4c437c1325f7111558c0 Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 8 Jun 2022 00:50:25 +0200 Subject: [PATCH] Re-add internal image field to ImageTexture --- scene/resources/texture.cpp | 18 ++++++++++++++++++ scene/resources/texture.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index e001aeffc40..815343b0447 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -147,6 +147,24 @@ void ImageTexture::reload_from_file() { } } +bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "image") { + create_from_image(p_value); + } + return false; +} + +bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "image") { + r_ret = get_image(); + } + return false; +} + +void ImageTexture::_get_property_list(List *p_list) const { + p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("image"), PROPERTY_HINT_RESOURCE_TYPE, "Image", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)); +} + void ImageTexture::create_from_image(const Ref &p_image) { ERR_FAIL_COND_MSG(p_image.is_null() || p_image->is_empty(), "Invalid image"); w = p_image->get_width(); diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 3e8ac060c4f..317756e3131 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -102,6 +102,11 @@ class ImageTexture : public Texture2D { protected: virtual void reload_from_file() override; + + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; + static void _bind_methods(); public: