tile_set_editor.h 5.9 KB

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