Fix TouchScreenButton not redrawn when texture changes

Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
This commit is contained in:
Haoyu Qiu 2023-08-29 09:15:34 +08:00
parent 3c7114e1c1
commit aea0c1235d

View file

@ -33,9 +33,19 @@
#include "core/input_map.h" #include "core/input_map.h"
#include "core/os/input.h" #include "core/os/input.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "scene/scene_string_names.h"
void TouchScreenButton::set_texture(const Ref<Texture> &p_texture) { void TouchScreenButton::set_texture(const Ref<Texture> &p_texture) {
if (texture == p_texture) {
return;
}
if (texture.is_valid()) {
texture->disconnect(SceneStringNames::get_singleton()->changed, this, "update");
}
texture = p_texture; texture = p_texture;
if (texture.is_valid()) {
texture->connect(SceneStringNames::get_singleton()->changed, this, "update", varray(), CONNECT_REFERENCE_COUNTED);
}
update(); update();
} }
@ -44,7 +54,16 @@ Ref<Texture> TouchScreenButton::get_texture() const {
} }
void TouchScreenButton::set_texture_pressed(const Ref<Texture> &p_texture_pressed) { void TouchScreenButton::set_texture_pressed(const Ref<Texture> &p_texture_pressed) {
if (texture_pressed == p_texture_pressed) {
return;
}
if (texture_pressed.is_valid()) {
texture_pressed->disconnect(SceneStringNames::get_singleton()->changed, this, "update");
}
texture_pressed = p_texture_pressed; texture_pressed = p_texture_pressed;
if (texture_pressed.is_valid()) {
texture_pressed->connect(SceneStringNames::get_singleton()->changed, this, "update", varray(), CONNECT_REFERENCE_COUNTED);
}
update(); update();
} }
@ -61,16 +80,16 @@ Ref<BitMap> TouchScreenButton::get_bitmask() const {
} }
void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) { void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) {
if (shape.is_valid()) { if (shape == p_shape) {
shape->disconnect("changed", this, "update"); return;
}
if (shape.is_valid()) {
shape->disconnect(SceneStringNames::get_singleton()->changed, this, "update");
} }
shape = p_shape; shape = p_shape;
if (shape.is_valid()) { if (shape.is_valid()) {
shape->connect("changed", this, "update"); shape->connect(SceneStringNames::get_singleton()->changed, this, "update");
} }
update(); update();
} }