| 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 "scene/gui/margin_container.h" |
| 34 |
#include "tile_atlas_view.h" |
| 35 |
|
| 36 |
#include "core/os/thread.h" |
| 37 |
#include "editor/docks/editor_dock.h" |
| 38 |
#include "scene/gui/box_container.h" |
| 39 |
#include "scene/gui/check_box.h" |
| 40 |
#include "scene/gui/flow_container.h" |
| 41 |
#include "scene/gui/item_list.h" |
| 42 |
#include "scene/gui/menu_button.h" |
| 43 |
#include "scene/gui/option_button.h" |
| 44 |
#include "scene/gui/separator.h" |
| 45 |
#include "scene/gui/spin_box.h" |
| 46 |
#include "scene/gui/split_container.h" |
| 47 |
#include "scene/gui/tab_bar.h" |
| 48 |
#include "scene/gui/tree.h" |
| 49 |
|
| 50 |
class TileMapLayer; |
| 51 |
class TileMapLayerEditor; |
| 52 |
class TileSetSourceItemList; |
| 53 |
class GridContainer; |
| 54 |
|
| 55 |
class SwitchSeparator : public MarginContainer { |
| 56 |
GDCLASS(SwitchSeparator, MarginContainer); |
| 57 |
|
| 58 |
HSeparator *h_separator = nullptr; |
| 59 |
VSeparator *v_separator = nullptr; |
| 60 |
|
| 61 |
public: |
| 62 |
void set_vertical(bool p_vertical); |
| 63 |
|
| 64 |
SwitchSeparator(); |
| 65 |
}; |
| 66 |
|
| 67 |
class TileMapLayerSubEditorPlugin : public Object { |
| 68 |
GDSOFTCLASS(TileMapLayerSubEditorPlugin, Object); |
| 69 |
|
| 70 |
protected: |
| 71 |
ObjectID edited_tile_map_layer_id; |
| 72 |
TileMapLayer *_get_edited_layer() const; |
| 73 |
static void _add_to_output_if_tile_changed(HashMap<Vector2i, TileMapCell> &p_output, const TileMapLayer *p_layer, Vector2i p_coords, const TileMapCell &p_cell); |
| 74 |
|
| 75 |
public: |
| 76 |
struct TabData { |
| 77 |
Vector<Control *> toolbar; |
| 78 |
Control *wide_toolbar; |
| 79 |
Control *panel = nullptr; |
| 80 |
}; |
| 81 |
|
| 82 |
virtual Vector<TabData> get_tabs() const { |
| 83 |
return Vector<TabData>(); |
| 84 |
} |
| 85 |
|
| 86 |
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return false; } |
| 87 |
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) {} |
| 88 |
virtual void tile_set_changed() {} |
| 89 |
virtual void edit(ObjectID p_tile_map_layer_id) {} |
| 90 |
virtual void draw_tile_coords_over_viewport(Control *p_overlay, const TileMapLayer *p_edited_layer, Ref<TileSet> p_tile_set, bool p_show_rectangle_size, const Vector2i &p_rectangle_origin); |
| 91 |
virtual void update_layout(EditorDock::DockLayout p_layout) {} |
| 92 |
}; |
| 93 |
|
| 94 |
class TileMapLayerEditorTilesPlugin : public TileMapLayerSubEditorPlugin { |
| 95 |
GDCLASS(TileMapLayerEditorTilesPlugin, TileMapLayerSubEditorPlugin); |
| 96 |
|
| 97 |
public: |
| 98 |
enum TileTransformType { |
| 99 |
TRANSFORM_ROTATE_LEFT, |
| 100 |
TRANSFORM_ROTATE_RIGHT, |
| 101 |
TRANSFORM_FLIP_H, |
| 102 |
TRANSFORM_FLIP_V, |
| 103 |
}; |
| 104 |
|
| 105 |
private: |
| 106 |
|
| 107 |
HBoxContainer *wide_toolbar = nullptr; |
| 108 |
|
| 109 |
BoxContainer *tilemap_tiles_tools_buttons = nullptr; |
| 110 |
Ref<ButtonGroup> tool_buttons_group; |
| 111 |
Button *select_tool_button = nullptr; |
| 112 |
Button *paint_tool_button = nullptr; |
| 113 |
Button *line_tool_button = nullptr; |
| 114 |
Button *rect_tool_button = nullptr; |
| 115 |
Button *bucket_tool_button = nullptr; |
| 116 |
|
| 117 |
BoxContainer *tools_settings = nullptr; |
| 118 |
|
| 119 |
SwitchSeparator *tools_settings_vsep = nullptr; |
| 120 |
Button *picker_button = nullptr; |
| 121 |
Button *erase_button = nullptr; |
| 122 |
|
| 123 |
BoxContainer *transform_toolbar = nullptr; |
| 124 |
Button *transform_button_rotate_left = nullptr; |
| 125 |
Button *transform_button_rotate_right = nullptr; |
| 126 |
Button *transform_button_flip_h = nullptr; |
| 127 |
Button *transform_button_flip_v = nullptr; |
| 128 |
SwitchSeparator *transform_separator = nullptr; |
| 129 |
|
| 130 |
CheckBox *bucket_contiguous_checkbox = nullptr; |
| 131 |
Button *random_tile_toggle = nullptr; |
| 132 |
|
| 133 |
BoxContainer *scatter_controls_container = nullptr; |
| 134 |
float scattering = 0.0; |
| 135 |
Label *scatter_label = nullptr; |
| 136 |
SpinBox *scatter_spinbox = nullptr; |
| 137 |
void _on_random_tile_checkbox_toggled(bool p_pressed); |
| 138 |
void _on_scattering_spinbox_changed(double p_value); |
| 139 |
|
| 140 |
void _update_toolbar(); |
| 141 |
void _update_transform_buttons(); |
| 142 |
void _set_transform_buttons_state(const Vector<Button *> &p_enabled_buttons, const Vector<Button *> &p_disabled_buttons, const String &p_why_disabled); |
| 143 |
|
| 144 |
|
| 145 |
bool has_mouse = false; |
| 146 |
void _mouse_exited_viewport(); |
| 147 |
|
| 148 |
enum DragType { |
| 149 |
DRAG_TYPE_NONE = 0, |
| 150 |
DRAG_TYPE_SELECT, |
| 151 |
DRAG_TYPE_MOVE, |
| 152 |
DRAG_TYPE_PAINT, |
| 153 |
DRAG_TYPE_LINE, |
| 154 |
DRAG_TYPE_RECT, |
| 155 |
DRAG_TYPE_BUCKET, |
| 156 |
DRAG_TYPE_PICK, |
| 157 |
DRAG_TYPE_CLIPBOARD_PASTE, |
| 158 |
}; |
| 159 |
DragType drag_type = DRAG_TYPE_NONE; |
| 160 |
bool drag_erasing = false; |
| 161 |
Vector2 drag_start_mouse_pos; |
| 162 |
Vector2 drag_last_mouse_pos; |
| 163 |
HashMap<Vector2i, TileMapCell> drag_modified; |
| 164 |
|
| 165 |
TileMapCell _pick_random_tile(Ref<TileMapPattern> p_pattern); |
| 166 |
HashMap<Vector2i, TileMapCell> _draw_line(Vector2 p_start_drag_mouse_pos, Vector2 p_from_mouse_pos, Vector2 p_to_mouse_pos, bool p_erase); |
| 167 |
HashMap<Vector2i, TileMapCell> _draw_rect(Vector2i p_start_cell, Vector2i p_end_cell, bool p_erase); |
| 168 |
HashMap<Vector2i, TileMapCell> _draw_bucket_fill(Vector2i p_coords, bool p_contiguous, bool p_erase); |
| 169 |
void _stop_dragging(); |
| 170 |
|
| 171 |
void _apply_transform(TileTransformType p_type); |
| 172 |
int _get_transformed_alternative(int p_alternative_id, TileTransformType p_transform); |
| 173 |
|
| 174 |
|
| 175 |
RBSet<Vector2i> tile_map_selection; |
| 176 |
Ref<TileMapPattern> tile_map_clipboard; |
| 177 |
Ref<TileMapPattern> selection_pattern; |
| 178 |
Ref<TileMapPattern> erase_pattern; |
| 179 |
void _set_tile_map_selection(const TypedArray<Vector2i> &p_selection); |
| 180 |
TypedArray<Vector2i> _get_tile_map_selection() const; |
| 181 |
|
| 182 |
RBSet<TileMapCell> tile_set_selection; |
| 183 |
|
| 184 |
void _update_selection_pattern_from_tilemap_selection(); |
| 185 |
void _update_selection_pattern_from_tileset_tiles_selection(); |
| 186 |
void _update_selection_pattern_from_tileset_pattern_selection(); |
| 187 |
void _update_tileset_selection_from_selection_pattern(); |
| 188 |
void _update_fix_selected_and_hovered(); |
| 189 |
void _fix_invalid_tiles_in_tile_map_selection(); |
| 190 |
|
| 191 |
void patterns_item_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index); |
| 192 |
|
| 193 |
|
| 194 |
BoxContainer *split_container_left_side = nullptr; |
| 195 |
|
| 196 |
void _tab_changed(); |
| 197 |
|
| 198 |
|
| 199 |
VBoxContainer *tiles_bottom_panel = nullptr; |
| 200 |
Label *missing_source_label = nullptr; |
| 201 |
Label *invalid_source_label = nullptr; |
| 202 |
|
| 203 |
TileSetSourceItemList *sources_list = nullptr; |
| 204 |
MenuButton *source_sort_button = nullptr; |
| 205 |
|
| 206 |
Ref<Texture2D> missing_atlas_texture_icon; |
| 207 |
void _update_tile_set_sources_list(); |
| 208 |
|
| 209 |
void _update_source_display(); |
| 210 |
|
| 211 |
|
| 212 |
TileMapCell hovered_tile; |
| 213 |
TileAtlasView *tile_atlas_view = nullptr; |
| 214 |
SplitContainer *atlas_sources_split_container = nullptr; |
| 215 |
|
| 216 |
bool tile_set_dragging_selection = false; |
| 217 |
Vector2i tile_set_drag_start_mouse_pos; |
| 218 |
|
| 219 |
Control *tile_atlas_control = nullptr; |
| 220 |
void _tile_atlas_control_mouse_exited(); |
| 221 |
void _tile_atlas_control_gui_input(const Ref<InputEvent> &p_event); |
| 222 |
void _tile_atlas_control_draw(); |
| 223 |
|
| 224 |
Control *alternative_tiles_control = nullptr; |
| 225 |
void _tile_alternatives_control_draw(); |
| 226 |
void _tile_alternatives_control_mouse_exited(); |
| 227 |
void _tile_alternatives_control_gui_input(const Ref<InputEvent> &p_event); |
| 228 |
|
| 229 |
void _update_atlas_view(); |
| 230 |
void _set_source_sort(int p_sort); |
| 231 |
|
| 232 |
|
| 233 |
ItemList *scene_tiles_list = nullptr; |
| 234 |
|
| 235 |
void _update_scenes_collection_view(); |
| 236 |
void _scene_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, int p_index); |
| 237 |
void _scenes_list_multi_selected(int p_index, bool p_selected); |
| 238 |
void _scenes_list_lmb_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index); |
| 239 |
|
| 240 |
|
| 241 |
MarginContainer *patterns_mc = nullptr; |
| 242 |
ItemList *patterns_item_list = nullptr; |
| 243 |
Label *patterns_help_label = nullptr; |
| 244 |
void _patterns_item_list_gui_input(const Ref<InputEvent> &p_event); |
| 245 |
void _pattern_preview_done(Ref<TileMapPattern> p_pattern, Ref<Texture2D> p_texture); |
| 246 |
bool select_last_pattern = false; |
| 247 |
void _update_patterns_list(); |
| 248 |
|
| 249 |
|
| 250 |
void _update_theme(); |
| 251 |
List<BaseButton *> viewport_shortcut_buttons; |
| 252 |
|
| 253 |
|
| 254 |
virtual void tile_set_changed() override; |
| 255 |
|
| 256 |
protected: |
| 257 |
static void _bind_methods(); |
| 258 |
|
| 259 |
public: |
| 260 |
virtual Vector<TabData> get_tabs() const override; |
| 261 |
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override; |
| 262 |
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override; |
| 263 |
virtual void update_layout(EditorDock::DockLayout p_layout) override; |
| 264 |
|
| 265 |
virtual void edit(ObjectID p_tile_map_layer_id) override; |
| 266 |
|
| 267 |
TileMapLayerEditorTilesPlugin(); |
| 268 |
}; |
| 269 |
|
| 270 |
class TileMapLayerEditorTerrainsPlugin : public TileMapLayerSubEditorPlugin { |
| 271 |
GDCLASS(TileMapLayerEditorTerrainsPlugin, TileMapLayerSubEditorPlugin); |
| 272 |
|
| 273 |
private: |
| 274 |
|
| 275 |
HBoxContainer *wide_toolbar = nullptr; |
| 276 |
|
| 277 |
BoxContainer *tilemap_tiles_tools_buttons = nullptr; |
| 278 |
Ref<ButtonGroup> tool_buttons_group; |
| 279 |
Button *paint_tool_button = nullptr; |
| 280 |
Button *line_tool_button = nullptr; |
| 281 |
Button *rect_tool_button = nullptr; |
| 282 |
Button *bucket_tool_button = nullptr; |
| 283 |
|
| 284 |
BoxContainer *tools_settings = nullptr; |
| 285 |
|
| 286 |
SwitchSeparator *tools_settings_vsep = nullptr; |
| 287 |
Button *picker_button = nullptr; |
| 288 |
Button *erase_button = nullptr; |
| 289 |
|
| 290 |
CheckBox *bucket_contiguous_checkbox = nullptr; |
| 291 |
void _update_toolbar(); |
| 292 |
|
| 293 |
|
| 294 |
BoxContainer *main_box_container = nullptr; |
| 295 |
SplitContainer *tilemap_tab_terrains = nullptr; |
| 296 |
|
| 297 |
|
| 298 |
bool has_mouse = false; |
| 299 |
void _mouse_exited_viewport(); |
| 300 |
|
| 301 |
enum DragType { |
| 302 |
DRAG_TYPE_NONE = 0, |
| 303 |
DRAG_TYPE_PAINT, |
| 304 |
DRAG_TYPE_LINE, |
| 305 |
DRAG_TYPE_RECT, |
| 306 |
DRAG_TYPE_BUCKET, |
| 307 |
DRAG_TYPE_PICK, |
| 308 |
}; |
| 309 |
DragType drag_type = DRAG_TYPE_NONE; |
| 310 |
bool drag_erasing = false; |
| 311 |
Vector2 drag_start_mouse_pos; |
| 312 |
Vector2 drag_last_mouse_pos; |
| 313 |
HashMap<Vector2i, TileMapCell> drag_modified; |
| 314 |
|
| 315 |
|
| 316 |
HashMap<Vector2i, TileMapCell> _draw_terrain_path_or_connect(const Vector<Vector2i> &p_to_paint, int p_terrain_set, int p_terrain, bool p_connect) const; |
| 317 |
HashMap<Vector2i, TileMapCell> _draw_terrain_pattern(const Vector<Vector2i> &p_to_paint, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern) const; |
| 318 |
HashMap<Vector2i, TileMapCell> _draw_line(Vector2i p_start_cell, Vector2i p_end_cell, bool p_erase); |
| 319 |
HashMap<Vector2i, TileMapCell> _draw_rect(Vector2i p_start_cell, Vector2i p_end_cell, bool p_erase); |
| 320 |
RBSet<Vector2i> _get_cells_for_bucket_fill(Vector2i p_coords, bool p_contiguous); |
| 321 |
HashMap<Vector2i, TileMapCell> _draw_bucket_fill(Vector2i p_coords, bool p_contiguous, bool p_erase); |
| 322 |
void _stop_dragging(); |
| 323 |
|
| 324 |
enum SelectedType { |
| 325 |
SELECTED_TYPE_CONNECT = 0, |
| 326 |
SELECTED_TYPE_PATH, |
| 327 |
SELECTED_TYPE_PATTERN, |
| 328 |
}; |
| 329 |
SelectedType selected_type = SELECTED_TYPE_CONNECT; |
| 330 |
int selected_terrain_set = -1; |
| 331 |
int selected_terrain = -1; |
| 332 |
TileSet::TerrainsPattern selected_terrains_pattern; |
| 333 |
void _update_selection(); |
| 334 |
|
| 335 |
|
| 336 |
Tree *terrains_tree = nullptr; |
| 337 |
ItemList *terrains_tile_list = nullptr; |
| 338 |
|
| 339 |
|
| 340 |
LocalVector<LocalVector<RBSet<TileSet::TerrainsPattern>>> per_terrain_terrains_patterns; |
| 341 |
List<BaseButton *> viewport_shortcut_buttons; |
| 342 |
|
| 343 |
|
| 344 |
void _update_terrains_cache(); |
| 345 |
void _update_terrains_tree(); |
| 346 |
void _update_tiles_list(); |
| 347 |
void _update_theme(); |
| 348 |
|
| 349 |
|
| 350 |
virtual void tile_set_changed() override; |
| 351 |
|
| 352 |
public: |
| 353 |
virtual Vector<TabData> get_tabs() const override; |
| 354 |
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) override; |
| 355 |
virtual void forward_canvas_draw_over_viewport(Control *p_overlay) override; |
| 356 |
virtual void update_layout(EditorDock::DockLayout p_layout) override; |
| 357 |
|
| 358 |
virtual void edit(ObjectID p_tile_map_layer_id) override; |
| 359 |
|
| 360 |
TileMapLayerEditorTerrainsPlugin(); |
| 361 |
}; |
| 362 |
|
| 363 |
class TileMapLayerEditor : public EditorDock { |
| 364 |
GDCLASS(TileMapLayerEditor, EditorDock); |
| 365 |
|
| 366 |
private: |
| 367 |
bool tile_map_layer_changed_needs_update = false; |
| 368 |
|
| 369 |
ObjectID edited_tile_map_layer_id; |
| 370 |
bool is_multi_node_edit = false; |
| 371 |
Vector<TileMapLayer *> tile_map_layers_in_scene_cache; |
| 372 |
bool layers_in_scene_list_cache_needs_update = false; |
| 373 |
TileMapLayer *_get_edited_layer() const; |
| 374 |
void _find_tile_map_layers_in_scene(Node *p_current, const Node *p_owner, Vector<TileMapLayer *> &r_list) const; |
| 375 |
void _update_tile_map_layers_in_scene_list_cache(); |
| 376 |
void _node_change(Node *p_node); |
| 377 |
|
| 378 |
Control *custom_overlay = nullptr; |
| 379 |
void _draw_overlay(); |
| 380 |
|
| 381 |
|
| 382 |
Vector<TileMapLayerSubEditorPlugin *> tile_map_editor_plugins; |
| 383 |
|
| 384 |
|
| 385 |
GridContainer *main_box_container = nullptr; |
| 386 |
VBoxContainer *tile_map_wide_toolbar = nullptr; |
| 387 |
FlowContainer *tile_map_toolbar = nullptr; |
| 388 |
Control *padding_control = nullptr; |
| 389 |
SwitchSeparator *layer_selector_separator = nullptr; |
| 390 |
|
| 391 |
bool show_layers_selector = false; |
| 392 |
|
| 393 |
BoxContainer *layer_selection_hbox = nullptr; |
| 394 |
Button *select_previous_layer = nullptr; |
| 395 |
void _select_previous_layer_pressed(); |
| 396 |
Button *select_next_layer = nullptr; |
| 397 |
void _select_next_layer_pressed(); |
| 398 |
Button *select_all_layers = nullptr; |
| 399 |
void _select_all_layers_pressed(); |
| 400 |
OptionButton *layers_selection_button = nullptr; |
| 401 |
void _layers_selection_item_selected(int p_index); |
| 402 |
void _update_layers_selector(); |
| 403 |
|
| 404 |
Button *toggle_highlight_selected_layer_button = nullptr; |
| 405 |
void _clear_all_layers_highlighting(); |
| 406 |
void _update_all_layers_highlighting(); |
| 407 |
void _highlight_selected_layer_button_toggled(bool p_pressed); |
| 408 |
void _update_layer_selector_layout(bool p_is_vertical); |
| 409 |
|
| 410 |
Button *toggle_grid_button = nullptr; |
| 411 |
void _on_grid_toggled(bool p_pressed); |
| 412 |
|
| 413 |
enum { |
| 414 |
ADVANCED_MENU_REPLACE_WITH_PROXIES, |
| 415 |
ADVANCED_MENU_EXTRACT_TILE_MAP_LAYERS, |
| 416 |
}; |
| 417 |
MenuButton *advanced_menu_button = nullptr; |
| 418 |
void _advanced_menu_button_id_pressed(int p_id); |
| 419 |
|
| 420 |
|
| 421 |
Label *cant_edit_label = nullptr; |
| 422 |
TabBar *tabs_bar = nullptr; |
| 423 |
PanelContainer *tabs_panel = nullptr; |
| 424 |
LocalVector<TileMapLayerSubEditorPlugin::TabData> tabs_data; |
| 425 |
LocalVector<TileMapLayerSubEditorPlugin *> tabs_plugins; |
| 426 |
void _update_bottom_panel(); |
| 427 |
|
| 428 |
|
| 429 |
Ref<Texture2D> missing_tile_texture; |
| 430 |
Ref<Texture2D> warning_pattern_texture; |
| 431 |
|
| 432 |
|
| 433 |
void _tile_map_layer_changed(); |
| 434 |
void _tab_changed(int p_tab_changed); |
| 435 |
|
| 436 |
|
| 437 |
void _layers_select_next_or_previous(bool p_next); |
| 438 |
|
| 439 |
|
| 440 |
void _move_tile_map_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos); |
| 441 |
|
| 442 |
protected: |
| 443 |
void _notification(int p_what); |
| 444 |
void _draw_shape(Control *p_control, Rect2 p_region, TileSet::TileShape p_shape, TileSet::TileOffsetAxis p_offset_axis, Color p_color); |
| 445 |
virtual void update_layout(DockLayout p_layout) override; |
| 446 |
|
| 447 |
public: |
| 448 |
bool forward_canvas_gui_input(const Ref<InputEvent> &p_event); |
| 449 |
void forward_canvas_draw_over_viewport(Control *p_overlay); |
| 450 |
|
| 451 |
void edit(Object *p_tile_map_layer); |
| 452 |
void set_show_layer_selector(bool p_show_layer_selector); |
| 453 |
|
| 454 |
TileMapLayerEditor(); |
| 455 |
~TileMapLayerEditor(); |
| 456 |
|
| 457 |
|
| 458 |
static Vector<Vector2i> get_line(const TileMapLayer *p_tile_map_layer, Vector2i p_from_cell, Vector2i p_to_cell); |
| 459 |
}; |
| 460 |
|
| 461 |
VARIANT_ENUM_CAST(TileMapLayerEditorTilesPlugin::TileTransformType); |