| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 54 |
int atlas_sources_lists_current = 0; |
| 55 |
float atlas_view_zoom = 1.0; |
| 56 |
Vector2 atlas_view_scroll; |
| 57 |
|
| 58 |
|
| 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 |
|
| 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 |
|
| 88 |
void queue_pattern_preview(Ref<TileSet> p_tile_set, Ref<TileMapPattern> p_pattern, Callable p_callback); |
| 89 |
|
| 90 |
|
| 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 |
|
| 98 |
void set_sorting_option(int p_option); |
| 99 |
List<int> get_sorted_sources(const Ref<TileSet> p_tile_set) const; |
| 100 |
|
| 101 |
|
| 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; |
| 127 |
|
| 128 |
bool tile_map_changed_needs_update = false; |
| 129 |
ObjectID tile_set_id; |
| 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 |
}; |