groups_editor.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**************************************************************************/
  2. /* groups_editor.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "scene/gui/dialogs.h"
  32. class Button;
  33. class CheckBox;
  34. class CheckButton;
  35. class EditorValidationPanel;
  36. class Label;
  37. class LineEdit;
  38. class PopupMenu;
  39. class Tree;
  40. class TreeItem;
  41. class GroupsEditor : public VBoxContainer {
  42. GDCLASS(GroupsEditor, VBoxContainer);
  43. const String GLOBAL_GROUP_PREFIX = "global_group/";
  44. bool updating_tree = false;
  45. bool updating_groups = false;
  46. bool groups_dirty = false;
  47. bool update_groups_and_tree_queued = false;
  48. LocalVector<Node *> selection;
  49. Node *scene_root_node = nullptr;
  50. SceneTree *scene_tree = nullptr;
  51. ConfirmationDialog *add_group_dialog = nullptr;
  52. LineEdit *add_group_name = nullptr;
  53. LineEdit *add_group_description = nullptr;
  54. CheckButton *global_group_button = nullptr;
  55. EditorValidationPanel *add_validation_panel = nullptr;
  56. ConfirmationDialog *rename_group_dialog = nullptr;
  57. LineEdit *rename_group = nullptr;
  58. CheckBox *rename_check_box = nullptr;
  59. EditorValidationPanel *rename_validation_panel = nullptr;
  60. ConfirmationDialog *remove_group_dialog = nullptr;
  61. CheckBox *remove_check_box = nullptr;
  62. Label *remove_label = nullptr;
  63. PopupMenu *menu = nullptr;
  64. VBoxContainer *holder = nullptr;
  65. LineEdit *filter = nullptr;
  66. Button *add = nullptr;
  67. Tree *tree = nullptr;
  68. Label *select_a_node = nullptr;
  69. HashMap<ObjectID, HashMap<StringName, bool>> scene_groups_cache;
  70. HashMap<StringName, bool> scene_groups_for_caching;
  71. HashMap<StringName, bool> scene_groups;
  72. HashMap<StringName, String> global_groups;
  73. void _update_scene_groups(const ObjectID &p_id);
  74. void _cache_scene_groups(const ObjectID &p_id);
  75. void _show_add_group_dialog();
  76. void _show_rename_group_dialog();
  77. void _show_remove_group_dialog();
  78. void _check_add();
  79. void _check_rename();
  80. void _validate_name(const String &p_name, EditorValidationPanel *p_validation_panel);
  81. void _update_tree();
  82. void _update_groups();
  83. void _load_scene_groups(Node *p_node);
  84. void _add_scene_group(const String &p_name);
  85. void _rename_scene_group(const String &p_old_name, const String &p_new_name);
  86. void _remove_scene_group(const String &p_name);
  87. bool _has_group(const String &p_name);
  88. void _set_group_checked(const String &p_name, bool p_checked);
  89. void _confirm_add();
  90. void _confirm_rename();
  91. void _confirm_delete();
  92. void _item_edited();
  93. void _item_mouse_selected(const Vector2 &p_pos, MouseButton p_mouse_button);
  94. void _modify_group(Object *p_item, int p_column, int p_id, MouseButton p_mouse_button);
  95. void _menu_id_pressed(int p_id);
  96. void _update_groups_and_tree();
  97. void _queue_update_groups_and_tree();
  98. void _groups_gui_input(Ref<InputEvent> p_event);
  99. void _node_removed(Node *p_node);
  100. void _add_to_group(const StringName &p_name, bool p_persist, const Array &p_nodes);
  101. void _remove_from_group(const StringName &p_name, const Array &p_nodes);
  102. void _get_group_mask(const StringName &p_name, Array &r_nodes, bool p_invert);
  103. bool _can_edit(const StringName &p_group);
  104. protected:
  105. void _notification(int p_what);
  106. static void _bind_methods();
  107. public:
  108. enum ModifyButton {
  109. DELETE_GROUP,
  110. COPY_GROUP,
  111. RENAME_GROUP,
  112. CONVERT_GROUP,
  113. };
  114. void set_selection(const Vector<Node *> &p_nodes);
  115. GroupsEditor();
  116. };