| 1 | /**************************************************************************/ |
| 2 | /* tile_set_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 TILE_SET_EDITOR_H |
| 32 | #define TILE_SET_EDITOR_H |
| 33 | |
| 34 | #include "atlas_merging_dialog.h" |
| 35 | #include "scene/gui/tab_bar.h" |
| 36 | #include "scene/resources/tile_set.h" |
| 37 | #include "tile_proxies_manager_dialog.h" |
| 38 | #include "tile_set_atlas_source_editor.h" |
| 39 | #include "tile_set_scenes_collection_source_editor.h" |
| 40 | |
| 41 | class AcceptDialog; |
| 42 | class SpinBox; |
| 43 | class HBoxContainer; |
| 44 | class SplitContainer; |
| 45 | class EditorFileDialog; |
| 46 | class EditorInspectorPlugin; |
| 47 | |
| 48 | class TileSetEditor : public Control { |
| 49 | GDCLASS(TileSetEditor, Control); |
| 50 | |
| 51 | static TileSetEditor *singleton; |
| 52 | |
| 53 | private: |
| 54 | bool read_only = false; |
| 55 | |
| 56 | Ref<TileSet> tile_set; |
| 57 | bool tile_set_changed_needs_update = false; |
| 58 | HSplitContainer *split_container = nullptr; |
| 59 | |
| 60 | // TabBar. |
| 61 | HBoxContainer *tile_set_toolbar = nullptr; |
| 62 | TabBar *tabs_bar = nullptr; |
| 63 | |
| 64 | // Tiles. |
| 65 | Label *no_source_selected_label = nullptr; |
| 66 | TileSetAtlasSourceEditor *tile_set_atlas_source_editor = nullptr; |
| 67 | TileSetScenesCollectionSourceEditor *tile_set_scenes_collection_source_editor = nullptr; |
| 68 | |
| 69 | void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); |
| 70 | bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; |
| 71 | void _load_texture_files(const Vector<String> &p_paths); |
| 72 | |
| 73 | void _update_sources_list(int force_selected_id = -1); |
| 74 | |
| 75 | // Sources management. |
| 76 | Button *sources_delete_button = nullptr; |
| 77 | MenuButton *sources_add_button = nullptr; |
| 78 | MenuButton *source_sort_button = nullptr; |
| 79 | MenuButton * = nullptr; |
| 80 | ItemList *sources_list = nullptr; |
| 81 | Ref<Texture2D> missing_texture_texture; |
| 82 | void _source_selected(int p_source_index); |
| 83 | void _source_delete_pressed(); |
| 84 | void _source_add_id_pressed(int p_id_pressed); |
| 85 | void (int p_id_pressed); |
| 86 | void _set_source_sort(int p_sort); |
| 87 | |
| 88 | EditorFileDialog *texture_file_dialog = nullptr; |
| 89 | AtlasMergingDialog *atlas_merging_dialog = nullptr; |
| 90 | TileProxiesManagerDialog *tile_proxies_manager_dialog = nullptr; |
| 91 | |
| 92 | bool first_edit = true; |
| 93 | |
| 94 | // Patterns. |
| 95 | ItemList *patterns_item_list = nullptr; |
| 96 | Label *patterns_help_label = nullptr; |
| 97 | void _patterns_item_list_gui_input(const Ref<InputEvent> &p_event); |
| 98 | void _pattern_preview_done(Ref<TileMapPattern> p_pattern, Ref<Texture2D> p_texture); |
| 99 | bool select_last_pattern = false; |
| 100 | void _update_patterns_list(); |
| 101 | |
| 102 | // Expanded editor. |
| 103 | PanelContainer *expanded_area = nullptr; |
| 104 | Control *expanded_editor = nullptr; |
| 105 | ObjectID expanded_editor_parent; |
| 106 | LocalVector<SplitContainer *> disable_on_expand; |
| 107 | |
| 108 | void _tile_set_changed(); |
| 109 | void _tab_changed(int p_tab_changed); |
| 110 | |
| 111 | void _move_tile_set_array_element(Object *p_undo_redo, Object *p_edited, String p_array_prefix, int p_from_index, int p_to_pos); |
| 112 | void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, String p_property, Variant p_new_value); |
| 113 | |
| 114 | protected: |
| 115 | void _notification(int p_what); |
| 116 | |
| 117 | public: |
| 118 | _FORCE_INLINE_ static TileSetEditor *get_singleton() { return singleton; } |
| 119 | |
| 120 | void edit(Ref<TileSet> p_tile_set); |
| 121 | |
| 122 | void add_expanded_editor(Control *p_editor); |
| 123 | void remove_expanded_editor(); |
| 124 | void register_split(SplitContainer *p_split); |
| 125 | |
| 126 | TileSetEditor(); |
| 127 | }; |
| 128 | |
| 129 | class TileSourceInspectorPlugin : public EditorInspectorPlugin { |
| 130 | GDCLASS(TileSourceInspectorPlugin, EditorInspectorPlugin); |
| 131 | |
| 132 | AcceptDialog *id_edit_dialog = nullptr; |
| 133 | Label *id_label = nullptr; |
| 134 | SpinBox *id_input = nullptr; |
| 135 | Object *edited_source = nullptr; |
| 136 | |
| 137 | void _show_id_edit_dialog(Object *p_for_source); |
| 138 | void _confirm_change_id(); |
| 139 | |
| 140 | public: |
| 141 | virtual bool can_handle(Object *p_object) override; |
| 142 | virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override; |
| 143 | }; |
| 144 | |
| 145 | #endif // TILE_SET_EDITOR_H |
| 146 | |