Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

ItemList, Tree: Fix analog stick moving through many items at once.

Matt Giucaaaf21bc4fbcb
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 2d6c293c415..4228d13537f 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -30,6 +30,7 @@
#include "input_event.h"
+#include "core/input/input.h"
#include "core/input/input_map.h"
#include "core/input/shortcut.h"
#include "core/math/transform_2d.h"
@@ -63,6 +64,10 @@ bool InputEvent::is_action_released(const StringName &p_action, bool p_exact_mat
return valid && !pressed_state;
}
+bool InputEvent::is_action_just_pressed_or_echo(const StringName &p_action, bool p_exact_match) const {
+ return is_action(p_action, p_exact_match) && (is_echo() || Input::get_singleton()->is_action_just_pressed_by_event(p_action, const_cast<InputEvent *>(this)));
+}
+
float InputEvent::get_action_strength(const StringName &p_action, bool p_exact_match) const {
float strength;
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>(const_cast<InputEvent *>(this)), p_action, p_exact_match, nullptr, &strength, nullptr);
diff --git a/core/input/input_event.h b/core/input/input_event.h
index ec00dfdc589..c6f37d20794 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -72,6 +72,7 @@ public:
bool is_action(const StringName &p_action, bool p_exact_match = false) const;
bool is_action_pressed(const StringName &p_action, bool p_allow_echo = false, bool p_exact_match = false) const;
bool is_action_released(const StringName &p_action, bool p_exact_match = false) const;
+ bool is_action_just_pressed_or_echo(const StringName &p_action, bool p_exact_match = false) const;
float get_action_strength(const StringName &p_action, bool p_exact_match = false) const;
float get_action_raw_strength(const StringName &p_action, bool p_exact_match = false) const;
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 9b232afbb42..1809e5e260b 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -934,7 +934,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
- else if (p_event->is_action("ui_up", true)) {
+ else if (p_event->is_action_just_pressed_or_echo("ui_up", true)) {
if (!search_string.is_empty()) {
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
@@ -981,7 +981,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
- else if (p_event->is_action("ui_down", true)) {
+ else if (p_event->is_action_just_pressed_or_echo("ui_down", true)) {
if (!search_string.is_empty()) {
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
@@ -1058,7 +1058,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
- else if (p_event->is_action("ui_left", true)) {
+ else if (p_event->is_action_just_pressed_or_echo("ui_left", true)) {
search_string = ""; //any mousepress cancels
if (current % current_columns != 0) {
@@ -1087,7 +1087,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
- else if (p_event->is_action("ui_right", true)) {
+ else if (p_event->is_action_just_pressed_or_echo("ui_right", true)) {
search_string = ""; //any mousepress cancels
if (current % current_columns != (current_columns - 1) && current + 1 < items.size()) {
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index eb936106e1a..e91d341c7f9 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -3899,7 +3899,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
}
bool is_command = k.is_valid() && k->is_command_or_control_pressed();
- if (p_event->is_action(cache.rtl ? "ui_left" : "ui_right") && p_event->is_pressed()) {
+ if (p_event->is_action_just_pressed_or_echo(cache.rtl ? "ui_left" : "ui_right")) {
if (!cursor_can_exit_tree) {
accept_event();
}
@@ -3917,7 +3917,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
} else {
_go_down();
}
- } else if (p_event->is_action(cache.rtl ? "ui_right" : "ui_left") && p_event->is_pressed()) {
+ } else if (p_event->is_action_just_pressed_or_echo(cache.rtl ? "ui_right" : "ui_left")) {
if (!cursor_can_exit_tree) {
accept_event();
}
@@ -3935,7 +3935,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
} else {
_go_up();
}
- } else if (p_event->is_action("ui_up") && p_event->is_pressed() && !is_command) {
+ } else if (p_event->is_action_just_pressed_or_echo("ui_up") && !is_command) {
if (!cursor_can_exit_tree) {
accept_event();
}
@@ -3947,7 +3947,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
_go_up();
}
- } else if (p_event->is_action("ui_down") && p_event->is_pressed() && !is_command) {
+ } else if (p_event->is_action_just_pressed_or_echo("ui_down") && !is_command) {
if (!cursor_can_exit_tree) {
accept_event();
}