Implement project-wide node groups

This commit is contained in:
Stanislav Labzyuk
2022-05-12 15:20:12 +07:00
parent 1f5d4a62e9
commit 958699a0c4
14 changed files with 1654 additions and 734 deletions

View File

@ -34,57 +34,94 @@
#include "scene/gui/dialogs.h"
class Button;
class CheckBox;
class CheckButton;
class EditorValidationPanel;
class Label;
class LineEdit;
class PopupMenu;
class Tree;
class TreeItem;
class GroupDialog : public AcceptDialog {
GDCLASS(GroupDialog, AcceptDialog);
class GroupsEditor : public VBoxContainer {
GDCLASS(GroupsEditor, VBoxContainer);
AcceptDialog *error = nullptr;
const String GLOBAL_GROUP_PREFIX = "global_group/";
bool updating_tree = false;
bool updating_groups = false;
bool groups_dirty = false;
bool update_groups_and_tree_queued = false;
Node *node = nullptr;
Node *scene_root_node = nullptr;
SceneTree *scene_tree = nullptr;
TreeItem *groups_root = nullptr;
LineEdit *add_group_text = nullptr;
Button *add_group_button = nullptr;
ConfirmationDialog *add_group_dialog = nullptr;
LineEdit *add_group_name = nullptr;
LineEdit *add_group_description = nullptr;
CheckButton *global_group_button = nullptr;
EditorValidationPanel *add_validation_panel = nullptr;
Tree *groups = nullptr;
ConfirmationDialog *rename_group_dialog = nullptr;
LineEdit *rename_group = nullptr;
CheckBox *rename_check_box = nullptr;
EditorValidationPanel *rename_validation_panel = nullptr;
Tree *nodes_to_add = nullptr;
TreeItem *add_node_root = nullptr;
LineEdit *add_filter = nullptr;
ConfirmationDialog *remove_group_dialog = nullptr;
CheckBox *remove_check_box = nullptr;
Label *remove_label = nullptr;
Tree *nodes_to_remove = nullptr;
TreeItem *remove_node_root = nullptr;
LineEdit *remove_filter = nullptr;
PopupMenu *menu = nullptr;
Label *group_empty = nullptr;
LineEdit *filter = nullptr;
Button *add = nullptr;
Tree *tree = nullptr;
Button *add_button = nullptr;
Button *remove_button = nullptr;
HashMap<Node *, HashMap<StringName, bool>> scene_groups_cache;
HashMap<StringName, bool> scene_groups_for_caching;
String selected_group;
HashMap<StringName, bool> scene_groups;
HashMap<StringName, String> global_groups;
void _group_selected();
void _update_scene_groups(Node *p_node);
void _cache_scene_groups(Node *p_node);
void _remove_filter_changed(const String &p_filter);
void _add_filter_changed(const String &p_filter);
void _show_add_group_dialog();
void _show_rename_group_dialog();
void _show_remove_group_dialog();
void _add_pressed();
void _removed_pressed();
void _add_group_pressed(const String &p_name);
void _add_group_text_changed(const String &p_new_text);
void _check_add();
void _check_rename();
void _validate_name(const String &p_name, EditorValidationPanel *p_validation_panel);
void _group_renamed();
void _rename_group_item(const String &p_old_name, const String &p_new_name);
void _update_tree();
void _add_group(String p_name);
void _modify_group_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
void _delete_group_item(const String &p_name);
void _update_groups();
void _load_scene_groups(Node *p_node);
void _load_groups(Node *p_current);
void _load_nodes(Node *p_current);
void _add_scene_group(const String &p_name);
void _rename_scene_group(const String &p_old_name, const String &p_new_name);
void _remove_scene_group(const String &p_name);
bool _has_group(const String &p_name);
void _set_group_checked(const String &p_name, bool p_checked);
void _confirm_add();
void _confirm_rename();
void _confirm_delete();
void _item_edited();
void _item_mouse_selected(const Vector2 &p_pos, MouseButton p_mouse_button);
void _modify_group(Object *p_item, int p_column, int p_id, MouseButton p_mouse_button);
void _menu_id_pressed(int p_id);
void _update_groups_and_tree();
void _queue_update_groups_and_tree();
void _groups_gui_input(Ref<InputEvent> p_event);
void _node_removed(Node *p_node);
protected:
void _notification(int p_what);
@ -94,45 +131,8 @@ public:
enum ModifyButton {
DELETE_GROUP,
COPY_GROUP,
};
void edit();
GroupDialog();
};
class GroupsEditor : public VBoxContainer {
GDCLASS(GroupsEditor, VBoxContainer);
Node *node = nullptr;
TreeItem *groups_root = nullptr;
GroupDialog *group_dialog = nullptr;
AcceptDialog *error = nullptr;
LineEdit *group_name = nullptr;
Button *add = nullptr;
Tree *tree = nullptr;
String selected_group;
void update_tree();
void _add_group(const String &p_group = "");
void _modify_group(Object *p_item, int p_column, int p_id, MouseButton p_button);
void _group_name_changed(const String &p_new_text);
void _group_selected();
void _group_renamed();
void _show_group_dialog();
protected:
static void _bind_methods();
public:
enum ModifyButton {
DELETE_GROUP,
COPY_GROUP,
RENAME_GROUP,
CONVERT_GROUP,
};
void set_current(Node *p_node);