Confirmation for duplicate input events when adding to action
This commit is contained in:
parent
e3213aaef5
commit
651920a106
2 changed files with 29 additions and 0 deletions
|
@ -52,6 +52,27 @@ static bool _is_action_name_valid(const String &p_name) {
|
||||||
|
|
||||||
void ActionMapEditor::_event_config_confirmed() {
|
void ActionMapEditor::_event_config_confirmed() {
|
||||||
Ref<InputEvent> ev = event_config_dialog->get_event();
|
Ref<InputEvent> 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<InputEvent> 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<InputEvent> ev = event_config_dialog->get_event();
|
||||||
|
|
||||||
Dictionary new_action = current_action.duplicate();
|
Dictionary new_action = current_action.duplicate();
|
||||||
Array events = new_action["events"].duplicate();
|
Array events = new_action["events"].duplicate();
|
||||||
|
@ -620,4 +641,9 @@ ActionMapEditor::ActionMapEditor() {
|
||||||
|
|
||||||
message = memnew(AcceptDialog);
|
message = memnew(AcceptDialog);
|
||||||
add_child(message);
|
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"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#define ACTION_MAP_EDITOR_H
|
#define ACTION_MAP_EDITOR_H
|
||||||
|
|
||||||
#include "scene/gui/control.h"
|
#include "scene/gui/control.h"
|
||||||
|
#include "scene/gui/dialogs.h"
|
||||||
|
|
||||||
class Button;
|
class Button;
|
||||||
class HBoxContainer;
|
class HBoxContainer;
|
||||||
|
@ -78,6 +79,7 @@ private:
|
||||||
|
|
||||||
InputEventConfigurationDialog *event_config_dialog = nullptr;
|
InputEventConfigurationDialog *event_config_dialog = nullptr;
|
||||||
AcceptDialog *message = nullptr;
|
AcceptDialog *message = nullptr;
|
||||||
|
ConfirmationDialog *accept_warning = nullptr;
|
||||||
|
|
||||||
// Filtering and Adding actions
|
// Filtering and Adding actions
|
||||||
|
|
||||||
|
@ -92,6 +94,7 @@ private:
|
||||||
Button *add_button = nullptr;
|
Button *add_button = nullptr;
|
||||||
|
|
||||||
void _event_config_confirmed();
|
void _event_config_confirmed();
|
||||||
|
void _event_add_edit_confirmed();
|
||||||
|
|
||||||
void _add_action_pressed();
|
void _add_action_pressed();
|
||||||
void _add_edit_text_changed(const String &p_name);
|
void _add_edit_text_changed(const String &p_name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue