tile_set_editor.h 5.8 KB

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