groups_editor.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #ifndef GROUPS_EDITOR_H
  31. #define GROUPS_EDITOR_H
  32. #include "scene/gui/dialogs.h"
  33. class Button;
  34. class CheckBox;
  35. class CheckButton;
  36. class EditorValidationPanel;
  37. class Label;
  38. class LineEdit;
  39. class PopupMenu;
  40. class Tree;
  41. class TreeItem;
  42. class GroupsEditor : public VBoxContainer {
  43. GDCLASS(GroupsEditor, VBoxContainer);
  44. const String GLOBAL_GROUP_PREFIX = "global_group/";
  45. bool updating_tree = false;
  46. bool updating_groups = false;
  47. bool groups_dirty = false;
  48. bool update_groups_and_tree_queued = false;
  49. Node *node = nullptr;
  50. Node *scene_root_node = nullptr;
  51. SceneTree *scene_tree = nullptr;
  52. ConfirmationDialog *add_group_dialog = nullptr;
  53. LineEdit *add_group_name = nullptr;
  54. LineEdit *add_group_description = nullptr;
  55. CheckButton *global_group_button = nullptr;
  56. EditorValidationPanel *add_validation_panel = nullptr;
  57. ConfirmationDialog *rename_group_dialog = nullptr;
  58. LineEdit *rename_group = nullptr;
  59. CheckBox *rename_check_box = nullptr;
  60. EditorValidationPanel *rename_validation_panel = nullptr;
  61. ConfirmationDialog *remove_group_dialog = nullptr;
  62. CheckBox *remove_check_box = nullptr;
  63. Label *remove_label = nullptr;
  64. PopupMenu *menu = nullptr;
  65. LineEdit *filter = nullptr;
  66. Button *add = nullptr;
  67. Tree *tree = nullptr;
  68. HashMap<ObjectID, HashMap<StringName, bool>> scene_groups_cache;
  69. HashMap<StringName, bool> scene_groups_for_caching;
  70. HashMap<StringName, bool> scene_groups;
  71. HashMap<StringName, String> global_groups;
  72. void _update_scene_groups(const ObjectID &p_id);
  73. void _cache_scene_groups(const ObjectID &p_id);
  74. void _show_add_group_dialog();
  75. void _show_rename_group_dialog();
  76. void _show_remove_group_dialog();
  77. void _check_add();
  78. void _check_rename();
  79. void _validate_name(const String &p_name, EditorValidationPanel *p_validation_panel);
  80. void _update_tree();
  81. void _update_groups();
  82. void _load_scene_groups(Node *p_node);
  83. void _add_scene_group(const String &p_name);
  84. void _rename_scene_group(const String &p_old_name, const String &p_new_name);
  85. void _remove_scene_group(const String &p_name);
  86. bool _has_group(const String &p_name);
  87. void _set_group_checked(const String &p_name, bool p_checked);
  88. void _confirm_add();
  89. void _confirm_rename();
  90. void _confirm_delete();
  91. void _item_edited();
  92. void _item_mouse_selected(const Vector2 &p_pos, MouseButton p_mouse_button);
  93. void _modify_group(Object *p_item, int p_column, int p_id, MouseButton p_mouse_button);
  94. void _menu_id_pressed(int p_id);
  95. void _update_groups_and_tree();
  96. void _queue_update_groups_and_tree();
  97. void _groups_gui_input(Ref<InputEvent> p_event);
  98. void _node_removed(Node *p_node);
  99. protected:
  100. void _notification(int p_what);
  101. static void _bind_methods();
  102. public:
  103. enum ModifyButton {
  104. DELETE_GROUP,
  105. COPY_GROUP,
  106. RENAME_GROUP,
  107. CONVERT_GROUP,
  108. };
  109. void set_current(Node *p_node);
  110. GroupsEditor();
  111. ~GroupsEditor();
  112. };
  113. #endif // GROUPS_EDITOR_H