From f807c7e569802b5b6ec058137a26b6c03e98624c Mon Sep 17 00:00:00 2001 From: foxydevloper <12120644+foxydevloper@users.noreply.github.com> Date: Thu, 29 Jul 2021 00:26:34 -0400 Subject: [PATCH] Name nodes added from drag & drop by `name_casing` (cherry picked from commit 07a8f0fe3822edf39df737dcd82071e8ab80b4b0) --- editor/plugins/canvas_item_editor_plugin.cpp | 17 ++++++++++++++++- scene/main/node.h | 12 ++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 6c439c791ba..a8b4e768d3f 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -6279,7 +6279,22 @@ bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_targe } void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) { - child->set_name(path.get_file().get_basename()); + // Adjust casing according to project setting. The file name is expected to be in snake_case, but will work for others. + String name = path.get_file().get_basename(); + switch (ProjectSettings::get_singleton()->get("editor/node_naming/name_casing").operator int()) { + case NAME_CASING_PASCAL_CASE: + name = name.capitalize().replace(" ", ""); + break; + case NAME_CASING_CAMEL_CASE: + name = name.capitalize().replace(" ", ""); + name[0] = name.to_lower()[0]; + break; + case NAME_CASING_SNAKE_CASE: + name = name.capitalize().replace(" ", "_").to_lower(); + break; + } + child->set_name(name); + Ref texture = Ref(Object::cast_to(ResourceCache::get(path))); Size2 texture_size = texture->get_size(); diff --git a/scene/main/node.h b/scene/main/node.h index dc7541d9987..28f68ba5695 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -64,6 +64,12 @@ public: #endif }; + enum NameCasing { + NAME_CASING_PASCAL_CASE, + NAME_CASING_CAMEL_CASE, + NAME_CASING_SNAKE_CASE + }; + struct Comparator { bool operator()(const Node *p_a, const Node *p_b) const { return p_b->is_greater_than(p_a); } }; @@ -138,12 +144,6 @@ private: } data; - enum NameCasing { - NAME_CASING_PASCAL_CASE, - NAME_CASING_CAMEL_CASE, - NAME_CASING_SNAKE_CASE - }; - Ref multiplayer; void _print_tree_pretty(const String &prefix, const bool last);