1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Check if action name exists before adding it or renaming an action to it

This commit is contained in:
Marcel Admiraal
2021-12-28 17:08:06 +00:00
parent a7839df869
commit 5737e7dd2d
3 changed files with 25 additions and 8 deletions

View File

@@ -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