| 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 | |
| 31 | #ifndef GROUPS_EDITOR_H |
| 32 | #define GROUPS_EDITOR_H |
| 33 | |
| 34 | #include "scene/gui/dialogs.h" |
| 35 | |
| 36 | class Button; |
| 37 | class LineEdit; |
| 38 | class Tree; |
| 39 | class TreeItem; |
| 40 | |
| 41 | class GroupDialog : public AcceptDialog { |
| 42 | GDCLASS(GroupDialog, AcceptDialog); |
| 43 | |
| 44 | AcceptDialog *error = nullptr; |
| 45 | |
| 46 | SceneTree *scene_tree = nullptr; |
| 47 | TreeItem *groups_root = nullptr; |
| 48 | |
| 49 | LineEdit *add_group_text = nullptr; |
| 50 | Button *add_group_button = nullptr; |
| 51 | |
| 52 | Tree *groups = nullptr; |
| 53 | |
| 54 | Tree *nodes_to_add = nullptr; |
| 55 | TreeItem *add_node_root = nullptr; |
| 56 | LineEdit *add_filter = nullptr; |
| 57 | |
| 58 | Tree *nodes_to_remove = nullptr; |
| 59 | TreeItem *remove_node_root = nullptr; |
| 60 | LineEdit *remove_filter = nullptr; |
| 61 | |
| 62 | Label *group_empty = nullptr; |
| 63 | |
| 64 | Button *add_button = nullptr; |
| 65 | Button *remove_button = nullptr; |
| 66 | |
| 67 | String selected_group; |
| 68 | |
| 69 | void _group_selected(); |
| 70 | |
| 71 | void _remove_filter_changed(const String &p_filter); |
| 72 | void _add_filter_changed(const String &p_filter); |
| 73 | |
| 74 | void _add_pressed(); |
| 75 | void _removed_pressed(); |
| 76 | void _add_group_pressed(const String &p_name); |
| 77 | void _add_group_text_changed(const String &p_new_text); |
| 78 | |
| 79 | void _group_renamed(); |
| 80 | void _rename_group_item(const String &p_old_name, const String &p_new_name); |
| 81 | |
| 82 | void _add_group(String p_name); |
| 83 | void _modify_group_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button); |
| 84 | void _delete_group_item(const String &p_name); |
| 85 | |
| 86 | void _load_groups(Node *p_current); |
| 87 | void _load_nodes(Node *p_current); |
| 88 | |
| 89 | protected: |
| 90 | void _notification(int p_what); |
| 91 | static void _bind_methods(); |
| 92 | |
| 93 | public: |
| 94 | enum ModifyButton { |
| 95 | DELETE_GROUP, |
| 96 | COPY_GROUP, |
| 97 | }; |
| 98 | |
| 99 | void edit(); |
| 100 | |
| 101 | GroupDialog(); |
| 102 | }; |
| 103 | |
| 104 | class GroupsEditor : public VBoxContainer { |
| 105 | GDCLASS(GroupsEditor, VBoxContainer); |
| 106 | |
| 107 | Node *node = nullptr; |
| 108 | TreeItem *groups_root = nullptr; |
| 109 | |
| 110 | GroupDialog *group_dialog = nullptr; |
| 111 | AcceptDialog *error = nullptr; |
| 112 | |
| 113 | LineEdit *group_name = nullptr; |
| 114 | Button *add = nullptr; |
| 115 | Tree *tree = nullptr; |
| 116 | |
| 117 | String selected_group; |
| 118 | |
| 119 | void update_tree(); |
| 120 | void _add_group(const String &p_group = "" ); |
| 121 | void _modify_group(Object *p_item, int p_column, int p_id, MouseButton p_button); |
| 122 | void _group_name_changed(const String &p_new_text); |
| 123 | |
| 124 | void _group_selected(); |
| 125 | void _group_renamed(); |
| 126 | |
| 127 | void _show_group_dialog(); |
| 128 | |
| 129 | protected: |
| 130 | static void _bind_methods(); |
| 131 | |
| 132 | public: |
| 133 | enum ModifyButton { |
| 134 | DELETE_GROUP, |
| 135 | COPY_GROUP, |
| 136 | }; |
| 137 | |
| 138 | void set_current(Node *p_node); |
| 139 | |
| 140 | GroupsEditor(); |
| 141 | ~GroupsEditor(); |
| 142 | }; |
| 143 | |
| 144 | #endif // GROUPS_EDITOR_H |
| 145 | |