Skip to content

Commit

Permalink
Name nodes added from drag & drop by name_casing
Browse files Browse the repository at this point in the history
  • Loading branch information
foxydevloper committed Jul 29, 2021
1 parent 4885719 commit 07a8f0f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 16 additions & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5780,7 +5780,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<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(ResourceCache::get(path)));
Size2 texture_size = texture->get_size();

Expand Down
12 changes: 6 additions & 6 deletions scene/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class Node : public Object {
#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); }
};
Expand Down Expand Up @@ -140,12 +146,6 @@ class Node : public Object {

} data;

enum NameCasing {
NAME_CASING_PASCAL_CASE,
NAME_CASING_CAMEL_CASE,
NAME_CASING_SNAKE_CASE
};

Ref<MultiplayerAPI> multiplayer;

void _print_tree_pretty(const String &prefix, const bool last);
Expand Down

0 comments on commit 07a8f0f

Please sign in to comment.