Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/2d/tiles/tiles_editor_plugin.h
9906 views
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 TileMapEditorPlugin : public EditorPlugin {
111
GDCLASS(TileMapEditorPlugin, EditorPlugin);
112
113
TileMapLayerEditor *editor = nullptr;
114
Button *button = nullptr;
115
ObjectID tile_map_layer_id;
116
ObjectID tile_map_group_id; // Allow keeping the layer selector up to date.
117
118
bool tile_map_changed_needs_update = false;
119
ObjectID tile_set_id; // The TileSet associated with the TileMap.
120
121
void _tile_map_layer_changed();
122
void _tile_map_layer_removed();
123
void _update_tile_map();
124
void _select_layer(const StringName &p_name);
125
126
void _edit_tile_map_layer(TileMapLayer *p_tile_map_layer, bool p_show_layer_selector);
127
void _edit_tile_map(TileMap *p_tile_map);
128
129
protected:
130
void _notification(int p_notification);
131
132
public:
133
virtual void edit(Object *p_object) override;
134
virtual bool handles(Object *p_object) const override;
135
virtual void make_visible(bool p_visible) override;
136
137
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override;
138
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override;
139
140
void hide_editor();
141
bool is_editor_visible() const;
142
143
TileMapEditorPlugin();
144
~TileMapEditorPlugin();
145
};
146
147
class TileSetEditorPlugin : public EditorPlugin {
148
GDCLASS(TileSetEditorPlugin, EditorPlugin);
149
150
TileSetEditor *editor = nullptr;
151
Button *button = nullptr;
152
153
ObjectID edited_tileset;
154
155
public:
156
virtual void edit(Object *p_object) override;
157
virtual bool handles(Object *p_object) const override;
158
virtual void make_visible(bool p_visible) override;
159
160
ObjectID get_edited_tileset() const;
161
162
TileSetEditorPlugin();
163
~TileSetEditorPlugin();
164
};
165
166