diff options
Diffstat (limited to 'editor/action_map_editor.cpp')
-rw-r--r-- | editor/action_map_editor.cpp | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index a8d3bfcc90..71c76f57cf 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -742,7 +742,7 @@ void ActionMapEditor::_event_config_confirmed() { Ref<InputEvent> ev = event_config_dialog->get_event(); Dictionary new_action = current_action.duplicate(); - Array events = new_action["events"]; + Array events = new_action["events"].duplicate(); if (current_action_event_index == -1) { // Add new event @@ -760,12 +760,26 @@ void ActionMapEditor::_add_action_pressed() { _add_action(add_edit->get_text()); } +bool ActionMapEditor::_has_action(const String &p_name) const { + for (const ActionInfo &action_info : actions_cache) { + if (p_name == action_info.name) { + return true; + } + } + return false; +} + void ActionMapEditor::_add_action(const String &p_name) { if (p_name.is_empty() || !_is_action_name_valid(p_name)) { show_message(TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'")); return; } + if (_has_action(p_name)) { + show_message(vformat(TTR("An action with the name '%s' already exists."), p_name)); + return; + } + add_edit->clear(); emit_signal(SNAME("action_added"), p_name); } @@ -791,6 +805,12 @@ void ActionMapEditor::_action_edited() { return; } + if (_has_action(new_name)) { + ti->set_text(0, old_name); + show_message(vformat(TTR("An action with the name '%s' already exists."), new_name)); + return; + } + emit_signal(SNAME("action_renamed"), old_name, new_name); } else if (action_tree->get_selected_column() == 1) { // Deadzone Edited @@ -819,7 +839,6 @@ void ActionMapEditor::_tree_button_pressed(Object *p_item, int p_column, int p_i current_action_event_index = -1; event_config_dialog->popup_and_configure(); - } break; case ActionMapEditor::BUTTON_EDIT_EVENT: { // Action and Action name is located on the parent of the event. @@ -832,7 +851,6 @@ void ActionMapEditor::_tree_button_pressed(Object *p_item, int p_column, int p_i if (ie.is_valid()) { event_config_dialog->popup_and_configure(ie); } - } break; case ActionMapEditor::BUTTON_REMOVE_ACTION: { // Send removed action name @@ -841,12 +859,12 @@ void ActionMapEditor::_tree_button_pressed(Object *p_item, int p_column, int p_i } break; case ActionMapEditor::BUTTON_REMOVE_EVENT: { // Remove event and send updated action - Dictionary action = item->get_parent()->get_meta("__action"); + Dictionary action = item->get_parent()->get_meta("__action").duplicate(); String action_name = item->get_parent()->get_meta("__name"); int event_index = item->get_meta("__index"); - Array events = action["events"]; + Array events = action["events"].duplicate(); events.remove_at(event_index); action["events"] = events; |