Check if action name exists before adding it or renaming an action to it
This commit is contained in:
parent
a7839df869
commit
5737e7dd2d
|
@ -760,12 +760,26 @@ void ActionMapEditor::_add_action_pressed() {
|
||||||
_add_action(add_edit->get_text());
|
_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) {
|
void ActionMapEditor::_add_action(const String &p_name) {
|
||||||
if (p_name.is_empty() || !_is_action_name_valid(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 '\"'"));
|
show_message(TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_has_action(p_name)) {
|
||||||
|
show_message(vformat(TTR("An action with the name '%s' already exists."), p_name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
add_edit->clear();
|
add_edit->clear();
|
||||||
emit_signal(SNAME("action_added"), p_name);
|
emit_signal(SNAME("action_added"), p_name);
|
||||||
}
|
}
|
||||||
|
@ -791,6 +805,12 @@ void ActionMapEditor::_action_edited() {
|
||||||
return;
|
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);
|
emit_signal(SNAME("action_renamed"), old_name, new_name);
|
||||||
} else if (action_tree->get_selected_column() == 1) {
|
} else if (action_tree->get_selected_column() == 1) {
|
||||||
// Deadzone Edited
|
// Deadzone Edited
|
||||||
|
|
|
@ -168,6 +168,7 @@ private:
|
||||||
void _event_config_confirmed();
|
void _event_config_confirmed();
|
||||||
|
|
||||||
void _add_action_pressed();
|
void _add_action_pressed();
|
||||||
|
bool _has_action(const String &p_name) const;
|
||||||
void _add_action(const String &p_name);
|
void _add_action(const String &p_name);
|
||||||
void _action_edited();
|
void _action_edited();
|
||||||
|
|
||||||
|
|
|
@ -275,10 +275,8 @@ void ProjectSettingsEditor::_editor_restart_close() {
|
||||||
void ProjectSettingsEditor::_action_added(const String &p_name) {
|
void ProjectSettingsEditor::_action_added(const String &p_name) {
|
||||||
String name = "input/" + p_name;
|
String name = "input/" + p_name;
|
||||||
|
|
||||||
if (ProjectSettings::get_singleton()->has_setting(name)) {
|
ERR_FAIL_COND_MSG(ProjectSettings::get_singleton()->has_setting(name),
|
||||||
action_map->show_message(vformat(TTR("An action with the name '%s' already exists."), name));
|
"An action with this name already exists.");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary action;
|
Dictionary action;
|
||||||
action["events"] = Array();
|
action["events"] = Array();
|
||||||
|
@ -351,10 +349,8 @@ void ProjectSettingsEditor::_action_renamed(const String &p_old_name, const Stri
|
||||||
const String old_property_name = "input/" + p_old_name;
|
const String old_property_name = "input/" + p_old_name;
|
||||||
const String new_property_name = "input/" + p_new_name;
|
const String new_property_name = "input/" + p_new_name;
|
||||||
|
|
||||||
if (ProjectSettings::get_singleton()->has_setting(new_property_name)) {
|
ERR_FAIL_COND_MSG(ProjectSettings::get_singleton()->has_setting(new_property_name),
|
||||||
action_map->show_message(vformat(TTR("An action with the name '%s' already exists."), new_property_name));
|
"An action with this name already exists.");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int order = ProjectSettings::get_singleton()->get_order(old_property_name);
|
int order = ProjectSettings::get_singleton()->get_order(old_property_name);
|
||||||
Dictionary action = ProjectSettings::get_singleton()->get(old_property_name);
|
Dictionary action = ProjectSettings::get_singleton()->get(old_property_name);
|
||||||
|
|
Loading…
Reference in New Issue