Debian Codegraph @

editor/scene/2d/tiles/tiles_editor_plugin.h

raw symbols SCIP
1 /**************************************************************************/
2 /* tiles_editor_plugin.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 #pragma once
32
33 #include "editor/plugins/editor_plugin.h"
34
35 #include "tile_map_layer_editor.h"
36 #include "tile_set_editor.h"
37
38 class TilesEditorUtils : public Object {
39 GDCLASS(TilesEditorUtils, Object);
40
41 static TilesEditorUtils *singleton;
42
43 public:
44 enum SourceSortOption {
45 SOURCE_SORT_ID = 0,
46 SOURCE_SORT_ID_REVERSE,
47 SOURCE_SORT_NAME,
48 SOURCE_SORT_NAME_REVERSE,
49 SOURCE_SORT_MAX
50 };
51
52 private:
53 // For synchronization.
54 int atlas_sources_lists_current = 0;
55 float atlas_view_zoom = 1.0;
56 Vector2 atlas_view_scroll;
57
58 // Source sorting.
59 int source_sort = SOURCE_SORT_ID;
60
61 struct SourceNameComparator {
62 static Ref<TileSet> tile_set;
63 bool operator()(const int &p_a, const int &p_b) const;
64 };
65
66 // Patterns preview generation.
67 struct QueueItem {
68 Ref<TileSet> tile_set;
69 Ref<TileMapPattern> pattern;
70 Callable callback;
71 };
72 List<QueueItem> pattern_preview_queue;
73 Mutex pattern_preview_mutex;
74 Semaphore pattern_preview_sem;
75 Thread pattern_preview_thread;
76 SafeFlag pattern_thread_exit;
77 SafeFlag pattern_thread_exited;
78 Semaphore pattern_preview_done;
79 void _preview_frame_started();
80 void _pattern_preview_done();
81 static void _thread_func(void *ud);
82 void _thread();
83
84 public:
85 _FORCE_INLINE_ static TilesEditorUtils *get_singleton() { return singleton; }
86
87 // Pattern preview API.
88 void queue_pattern_preview(Ref<TileSet> p_tile_set, Ref<TileMapPattern> p_pattern, Callable p_callback);
89
90 // To synchronize the atlas sources lists.
91 void set_sources_lists_current(int p_current);
92 void synchronize_sources_list(Object *p_current_list, Object *p_current_sort_button);
93
94 void set_atlas_view_transform(float p_zoom, Vector2 p_scroll);
95 void synchronize_atlas_view(Object *p_current);
96
97 // Sorting.
98 void set_sorting_option(int p_option);
99 List<int> get_sorted_sources(const Ref<TileSet> p_tile_set) const;
100
101 // Misc.
102 void display_tile_set_editor_panel();
103
104 static void draw_selection_rect(CanvasItem *p_ci, const Rect2 &p_rect, const Color &p_color = Color(1.0, 1.0, 1.0));
105
106 TilesEditorUtils();
107 ~TilesEditorUtils();
108 };
109
110 class TileSetSourceItemList : public ItemList {
111 GDCLASS(TileSetSourceItemList, ItemList);
112
113 public:
114 Ref<TileSet> tile_set;
115
116 virtual String get_tooltip(const Point2 &p_pos) const override;
117
118 TileSetSourceItemList();
119 };
120
121 class TileMapEditorPlugin : public EditorPlugin {
122 GDCLASS(TileMapEditorPlugin, EditorPlugin);
123
124 TileMapLayerEditor *editor = nullptr;
125 ObjectID tile_map_layer_id;
126 ObjectID tile_map_group_id; // Allow keeping the layer selector up to date.
127
128 bool tile_map_changed_needs_update = false;
129 ObjectID tile_set_id; // The TileSet associated with the TileMap.
130
131 void _tile_map_layer_changed();
132 void _tile_map_layer_removed();
133 void _update_tile_map();
134 void _select_layer(const StringName &p_name);
135
136 void _edit_tile_map_layer(TileMapLayer *p_tile_map_layer, bool p_show_layer_selector);
137 void _edit_tile_map(TileMap *p_tile_map);
138
139 protected:
140 void _notification(int p_notification);
141
142 public:
143 virtual void edit(Object *p_object) override;
144 virtual bool handles(Object *p_object) const override;
145 virtual void make_visible(bool p_visible) override;
146
147 virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override;
148 virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override;
149
150 bool is_editor_visible() const;
151
152 TileMapEditorPlugin();
153 ~TileMapEditorPlugin();
154 };
155
156 class TileSetEditorPlugin : public EditorPlugin {
157 GDCLASS(TileSetEditorPlugin, EditorPlugin);
158
159 TileSetEditor *editor = nullptr;
160
161 ObjectID edited_tileset;
162
163 public:
164 virtual void edit(Object *p_object) override;
165 virtual bool handles(Object *p_object) const override;
166 virtual void make_visible(bool p_visible) override;
167 void open_editor();
168
169 ObjectID get_edited_tileset() const;
170
171 TileSetEditorPlugin();
172 ~TileSetEditorPlugin();
173 };