diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-03-13 11:02:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-13 11:02:47 +0100 |
commit | e8ce94b09285afcee9e8189f144f906009a4010f (patch) | |
tree | 7232e737757bb0e9102e71ae1f6f596e0c56b81e /scene | |
parent | a45e6f67d58e5a646db89a6b06891946e47881a6 (diff) | |
parent | a0ecbb5ac00155b86c2d9d12328e82ae5236b070 (diff) |
Merge pull request #7988 from RandomShaper/fix-touch-button
Several fixes for TouchScreenButton
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/screen_button.cpp | 23 | ||||
-rw-r--r-- | scene/2d/screen_button.h | 1 |
2 files changed, 16 insertions, 8 deletions
diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp index 9b9fa6cfa8..db822ed306 100644 --- a/scene/2d/screen_button.cpp +++ b/scene/2d/screen_button.cpp @@ -135,7 +135,7 @@ void TouchScreenButton::_notification(int p_what) { update(); if (!get_tree()->is_editor_hint()) - set_process_input(true); + set_process_input(is_visible_in_tree()); if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) { action_id = InputMap::get_singleton()->get_action_id(action); @@ -147,10 +147,21 @@ void TouchScreenButton::_notification(int p_what) { if (is_pressed()) _release(true); } break; + case NOTIFICATION_VISIBILITY_CHANGED: { + if (get_tree()->is_editor_hint()) + break; + if (is_visible_in_tree()) { + set_process_input(true); + } else { + set_process_input(false); + if (is_pressed()) + _release(); + } + } break; case NOTIFICATION_PAUSED: { - // So the button can be pressed again even though the release gets unhandled because of coming during pause - allow_repress = true; - } + if (is_pressed()) + _release(); + } break; } } @@ -230,7 +241,7 @@ void TouchScreenButton::_input(const InputEvent &p_event) { if (!is_visible_in_tree()) return; - const bool can_press = finger_pressed == -1 || allow_repress; + const bool can_press = finger_pressed == -1; if (!can_press) return; //already fingering @@ -276,7 +287,6 @@ void TouchScreenButton::_input(const InputEvent &p_event) { void TouchScreenButton::_press(int p_finger_pressed) { finger_pressed = p_finger_pressed; - allow_repress = false; if (action_id != -1) { @@ -394,7 +404,6 @@ void TouchScreenButton::_bind_methods() { TouchScreenButton::TouchScreenButton() { finger_pressed = -1; - allow_repress = false; action_id = -1; passby_press = false; visibility = VISIBILITY_ALWAYS; diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h index d648920b21..201d908bf6 100644 --- a/scene/2d/screen_button.h +++ b/scene/2d/screen_button.h @@ -56,7 +56,6 @@ private: StringName action; bool passby_press; int finger_pressed; - bool allow_repress; int action_id; VisibilityMode visibility; |