From 651920a1066c75cb6fc5e76f2d625d52f587a9a3 Mon Sep 17 00:00:00 2001 From: Jayden Sipe Date: Mon, 30 Sep 2024 22:02:07 -0400 Subject: [PATCH] Confirmation for duplicate input events when adding to action --- editor/action_map_editor.cpp | 26 ++++++++++++++++++++++++++ editor/action_map_editor.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index 0d89f37dd2e..604fd16c2e8 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -52,6 +52,27 @@ static bool _is_action_name_valid(const String &p_name) { void ActionMapEditor::_event_config_confirmed() { Ref ev = event_config_dialog->get_event(); + Array events = current_action["events"]; + + // Check for duplicate events on action, allows user to add duplicate event if desired + for (Ref event : events) { + if (ev->is_match(event, true)) { + if (accept_warning->is_connected(SceneStringName(confirmed), callable_mp(this, &ActionMapEditor::_event_add_edit_confirmed))) { + accept_warning->disconnect(SceneStringName(confirmed), callable_mp(this, &ActionMapEditor::_event_add_edit_confirmed)); + } + + accept_warning->set_text(vformat(TTR("Action \"%s\" already has an Event with this Input."), current_action_name)); + accept_warning->connect(SceneStringName(confirmed), callable_mp(this, &ActionMapEditor::_event_add_edit_confirmed)); + accept_warning->popup_centered(); + return; + } + } + + _event_add_edit_confirmed(); +} + +void ActionMapEditor::_event_add_edit_confirmed() { + Ref ev = event_config_dialog->get_event(); Dictionary new_action = current_action.duplicate(); Array events = new_action["events"].duplicate(); @@ -620,4 +641,9 @@ ActionMapEditor::ActionMapEditor() { message = memnew(AcceptDialog); add_child(message); + + accept_warning = memnew(ConfirmationDialog); + add_child(accept_warning); + accept_warning->set_title(TTR("Input Configuration Warning!")); + accept_warning->set_ok_button_text(TTR("Add Anyway")); } diff --git a/editor/action_map_editor.h b/editor/action_map_editor.h index 017296bfaa2..92244c91dae 100644 --- a/editor/action_map_editor.h +++ b/editor/action_map_editor.h @@ -32,6 +32,7 @@ #define ACTION_MAP_EDITOR_H #include "scene/gui/control.h" +#include "scene/gui/dialogs.h" class Button; class HBoxContainer; @@ -78,6 +79,7 @@ private: InputEventConfigurationDialog *event_config_dialog = nullptr; AcceptDialog *message = nullptr; + ConfirmationDialog *accept_warning = nullptr; // Filtering and Adding actions @@ -92,6 +94,7 @@ private: Button *add_button = nullptr; void _event_config_confirmed(); + void _event_add_edit_confirmed(); void _add_action_pressed(); void _add_edit_text_changed(const String &p_name);