summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2017-04-03 14:23:52 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2017-04-03 14:42:46 +0200
commit6caa9fc94c2dbb16bbd793e451060992af5160c3 (patch)
tree8b1d01e84ceaf47804d65cc6b72ccc9ab5c8dc37 /scene/2d
parent65f8210e503dd6cc8fdfcae7de5cb7d9a1bed854 (diff)
Improve TouchScreenButton
Fix shape not being updated Add a way to hide the shape on editor and debug-with-visible-shapes Remove useless checks
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/screen_button.cpp31
-rw-r--r--scene/2d/screen_button.h4
2 files changed, 27 insertions, 8 deletions
diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp
index db822ed306..804af7d9c6 100644
--- a/scene/2d/screen_button.cpp
+++ b/scene/2d/screen_button.cpp
@@ -65,12 +65,14 @@ Ref<BitMap> TouchScreenButton::get_bitmask() const {
void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) {
+ if (shape.is_valid())
+ shape->disconnect("changed", this, "update");
+
shape = p_shape;
- if (!is_inside_tree())
- return;
- if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
- return;
+ if (shape.is_valid())
+ shape->connect("changed", this, "update");
+
update();
}
@@ -82,11 +84,17 @@ Ref<Shape2D> TouchScreenButton::get_shape() const {
void TouchScreenButton::set_shape_centered(bool p_shape_centered) {
shape_centered = p_shape_centered;
+ update();
+}
- if (!is_inside_tree())
- return;
- if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
- return;
+bool TouchScreenButton::is_shape_visible() const {
+
+ return shape_visible;
+}
+
+void TouchScreenButton::set_shape_visible(bool p_shape_visible) {
+
+ shape_visible = p_shape_visible;
update();
}
@@ -118,6 +126,8 @@ void TouchScreenButton::_notification(int p_what) {
draw_texture(texture, Point2());
}
+ if (!shape_visible)
+ return;
if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
return;
if (shape.is_valid()) {
@@ -375,6 +385,9 @@ void TouchScreenButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shape_centered", "bool"), &TouchScreenButton::set_shape_centered);
ClassDB::bind_method(D_METHOD("is_shape_centered"), &TouchScreenButton::is_shape_centered);
+ ClassDB::bind_method(D_METHOD("set_shape_visible", "bool"), &TouchScreenButton::set_shape_visible);
+ ClassDB::bind_method(D_METHOD("is_shape_visible"), &TouchScreenButton::is_shape_visible);
+
ClassDB::bind_method(D_METHOD("set_action", "action"), &TouchScreenButton::set_action);
ClassDB::bind_method(D_METHOD("get_action"), &TouchScreenButton::get_action);
@@ -393,6 +406,7 @@ void TouchScreenButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "bitmask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), "set_bitmask", "get_bitmask");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_centered"), "set_shape_centered", "is_shape_centered");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_visible"), "set_shape_visible", "is_shape_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "passby_press"), "set_passby_press", "is_passby_press_enabled");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
ADD_PROPERTY(PropertyInfo(Variant::INT, "visibility_mode", PROPERTY_HINT_ENUM, "Always,TouchScreen Only"), "set_visibility_mode", "get_visibility_mode");
@@ -408,6 +422,7 @@ TouchScreenButton::TouchScreenButton() {
passby_press = false;
visibility = VISIBILITY_ALWAYS;
shape_centered = true;
+ shape_visible = true;
unit_rect = Ref<RectangleShape2D>(memnew(RectangleShape2D));
unit_rect->set_extents(Vector2(0.5, 0.5));
}
diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h
index 201d908bf6..2262723ed3 100644
--- a/scene/2d/screen_button.h
+++ b/scene/2d/screen_button.h
@@ -50,6 +50,7 @@ private:
Ref<BitMap> bitmask;
Ref<Shape2D> shape;
bool shape_centered;
+ bool shape_visible;
Ref<RectangleShape2D> unit_rect;
@@ -85,6 +86,9 @@ public:
void set_shape_centered(bool p_shape_centered);
bool is_shape_centered() const;
+ void set_shape_visible(bool p_shape_visible);
+ bool is_shape_visible() const;
+
void set_action(const String &p_action);
String get_action() const;