| 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 "tile_atlas_view.h" |
| 34 |
#include "tile_data_editors.h" |
| 35 |
|
| 36 |
#include "scene/gui/split_container.h" |
| 37 |
#include "scene/resources/2d/tile_set.h" |
| 38 |
|
| 39 |
class Popup; |
| 40 |
class TileSet; |
| 41 |
class Tree; |
| 42 |
class VSeparator; |
| 43 |
|
| 44 |
class TileSetAtlasSourceEditor : public HSplitContainer { |
| 45 |
GDCLASS(TileSetAtlasSourceEditor, HSplitContainer); |
| 46 |
|
| 47 |
public: |
| 48 |
|
| 49 |
struct TileSelection { |
| 50 |
Vector2i tile = TileSetSource::INVALID_ATLAS_COORDS; |
| 51 |
int alternative = TileSetSource::INVALID_TILE_ALTERNATIVE; |
| 52 |
|
| 53 |
bool operator<(const TileSelection &p_other) const { |
| 54 |
if (tile == p_other.tile) { |
| 55 |
return alternative < p_other.alternative; |
| 56 |
} else { |
| 57 |
return tile < p_other.tile; |
| 58 |
} |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
class TileSetAtlasSourceProxyObject : public Object { |
| 64 |
GDCLASS(TileSetAtlasSourceProxyObject, Object); |
| 65 |
|
| 66 |
private: |
| 67 |
Ref<TileSet> tile_set; |
| 68 |
Ref<TileSetAtlasSource> tile_set_atlas_source; |
| 69 |
int source_id = TileSet::INVALID_SOURCE; |
| 70 |
|
| 71 |
protected: |
| 72 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 73 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 74 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 75 |
static void _bind_methods(); |
| 76 |
|
| 77 |
public: |
| 78 |
void set_id(int p_id); |
| 79 |
int get_id() const; |
| 80 |
|
| 81 |
void edit(Ref<TileSet> p_tile_set, Ref<TileSetAtlasSource> p_tile_set_atlas_source, int p_source_id); |
| 82 |
Ref<TileSetAtlasSource> get_edited() { return tile_set_atlas_source; } |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
class AtlasTileProxyObject : public Object { |
| 87 |
GDCLASS(AtlasTileProxyObject, Object); |
| 88 |
|
| 89 |
private: |
| 90 |
TileSetAtlasSourceEditor *tiles_set_atlas_source_editor = nullptr; |
| 91 |
|
| 92 |
Ref<TileSetAtlasSource> tile_set_atlas_source; |
| 93 |
RBSet<TileSelection> tiles; |
| 94 |
|
| 95 |
protected: |
| 96 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 97 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 98 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 99 |
|
| 100 |
static void _bind_methods(); |
| 101 |
|
| 102 |
public: |
| 103 |
Ref<TileSetAtlasSource> get_edited_tile_set_atlas_source() const { return tile_set_atlas_source; } |
| 104 |
RBSet<TileSelection> get_edited_tiles() const { return tiles; } |
| 105 |
|
| 106 |
|
| 107 |
void edit(Ref<TileSetAtlasSource> p_tile_set_atlas_source, const RBSet<TileSelection> &p_tiles = RBSet<TileSelection>()); |
| 108 |
|
| 109 |
AtlasTileProxyObject(TileSetAtlasSourceEditor *p_tiles_set_atlas_source_editor) { |
| 110 |
tiles_set_atlas_source_editor = p_tiles_set_atlas_source_editor; |
| 111 |
} |
| 112 |
}; |
| 113 |
|
| 114 |
class TileAtlasControl : public Control { |
| 115 |
TileSetAtlasSourceEditor *editor = nullptr; |
| 116 |
|
| 117 |
public: |
| 118 |
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override; |
| 119 |
TileAtlasControl(TileSetAtlasSourceEditor *p_editor) { editor = p_editor; } |
| 120 |
}; |
| 121 |
friend class TileAtlasControl; |
| 122 |
|
| 123 |
private: |
| 124 |
bool read_only = false; |
| 125 |
|
| 126 |
Ref<TileSet> tile_set; |
| 127 |
TileSetAtlasSource *tile_set_atlas_source = nullptr; |
| 128 |
int tile_set_atlas_source_id = TileSet::INVALID_SOURCE; |
| 129 |
Ref<Texture2D> atlas_source_texture; |
| 130 |
|
| 131 |
bool tile_set_changed_needs_update = false; |
| 132 |
|
| 133 |
|
| 134 |
ScrollContainer *tile_data_editors_scroll = nullptr; |
| 135 |
VBoxContainer *tile_data_painting_editor_container = nullptr; |
| 136 |
Label *tile_data_editors_label = nullptr; |
| 137 |
Button *tile_data_editor_dropdown_button = nullptr; |
| 138 |
Popup *tile_data_editors_popup = nullptr; |
| 139 |
Tree *tile_data_editors_tree = nullptr; |
| 140 |
void _tile_data_editor_dropdown_button_draw(); |
| 141 |
void _tile_data_editor_dropdown_button_pressed(); |
| 142 |
|
| 143 |
|
| 144 |
String current_property; |
| 145 |
HashMap<String, TileDataEditor *> tile_data_editors; |
| 146 |
TileDataEditor *current_tile_data_editor = nullptr; |
| 147 |
void _tile_data_editors_tree_selected(); |
| 148 |
|
| 149 |
|
| 150 |
AtlasTileProxyObject *tile_proxy_object = nullptr; |
| 151 |
EditorInspector *tile_inspector = nullptr; |
| 152 |
Label *tile_inspector_no_tile_selected_label = nullptr; |
| 153 |
String selected_property; |
| 154 |
void _inspector_property_selected(const String &p_property); |
| 155 |
|
| 156 |
TileSetAtlasSourceProxyObject *atlas_source_proxy_object = nullptr; |
| 157 |
EditorInspector *atlas_source_inspector = nullptr; |
| 158 |
|
| 159 |
|
| 160 |
TileAtlasView *tile_atlas_view = nullptr; |
| 161 |
Label *help_label = nullptr; |
| 162 |
|
| 163 |
|
| 164 |
enum DragType { |
| 165 |
DRAG_TYPE_NONE = 0, |
| 166 |
DRAG_TYPE_CREATE_TILES, |
| 167 |
DRAG_TYPE_CREATE_TILES_USING_RECT, |
| 168 |
DRAG_TYPE_CREATE_BIG_TILE, |
| 169 |
DRAG_TYPE_REMOVE_TILES, |
| 170 |
DRAG_TYPE_REMOVE_TILES_USING_RECT, |
| 171 |
|
| 172 |
DRAG_TYPE_MOVE_TILE, |
| 173 |
|
| 174 |
DRAG_TYPE_RECT_SELECT, |
| 175 |
|
| 176 |
DRAG_TYPE_MAY_POPUP_MENU, |
| 177 |
|
| 178 |
|
| 179 |
DRAG_TYPE_RESIZE_TOP_LEFT, |
| 180 |
DRAG_TYPE_RESIZE_TOP, |
| 181 |
DRAG_TYPE_RESIZE_TOP_RIGHT, |
| 182 |
DRAG_TYPE_RESIZE_RIGHT, |
| 183 |
DRAG_TYPE_RESIZE_BOTTOM_RIGHT, |
| 184 |
DRAG_TYPE_RESIZE_BOTTOM, |
| 185 |
DRAG_TYPE_RESIZE_BOTTOM_LEFT, |
| 186 |
DRAG_TYPE_RESIZE_LEFT, |
| 187 |
}; |
| 188 |
DragType drag_type = DRAG_TYPE_NONE; |
| 189 |
Vector2i drag_start_mouse_pos; |
| 190 |
Vector2i drag_last_mouse_pos; |
| 191 |
Vector2i drag_current_tile; |
| 192 |
|
| 193 |
Rect2i drag_start_tile_shape; |
| 194 |
RBSet<Vector2i> drag_modified_tiles; |
| 195 |
void _end_dragging(); |
| 196 |
|
| 197 |
HashMap<Vector2i, List<const PropertyInfo *>> _group_properties_per_tiles(const List<PropertyInfo> &r_list, const TileSetAtlasSource *p_atlas); |
| 198 |
|
| 199 |
|
| 200 |
enum MenuOptions { |
| 201 |
TILE_CREATE, |
| 202 |
TILE_CREATE_ALTERNATIVE, |
| 203 |
TILE_DELETE, |
| 204 |
|
| 205 |
ADVANCED_AUTO_CREATE_TILES, |
| 206 |
ADVANCED_AUTO_REMOVE_TILES, |
| 207 |
ADVANCED_CLEANUP_TILES, |
| 208 |
}; |
| 209 |
Vector2i menu_option_coords; |
| 210 |
int menu_option_alternative = TileSetSource::INVALID_TILE_ALTERNATIVE; |
| 211 |
void _menu_option(int p_option); |
| 212 |
|
| 213 |
|
| 214 |
Ref<ButtonGroup> tools_button_group; |
| 215 |
Button *tool_setup_atlas_source_button = nullptr; |
| 216 |
Button *tool_select_button = nullptr; |
| 217 |
Button *tool_paint_button = nullptr; |
| 218 |
Label *tool_tile_id_label = nullptr; |
| 219 |
|
| 220 |
|
| 221 |
HBoxContainer *tool_settings = nullptr; |
| 222 |
HBoxContainer *tool_settings_tile_data_toolbar_container = nullptr; |
| 223 |
Button *tools_settings_erase_button = nullptr; |
| 224 |
MenuButton *tool_advanced_menu_button = nullptr; |
| 225 |
TextureRect *outside_tiles_warning = nullptr; |
| 226 |
|
| 227 |
|
| 228 |
RBSet<TileSelection> selection; |
| 229 |
|
| 230 |
void _set_selection_from_array(const Array &p_selection); |
| 231 |
Array _get_selection_as_array(); |
| 232 |
|
| 233 |
|
| 234 |
Vector2i hovered_base_tile_coords = TileSetSource::INVALID_ATLAS_COORDS; |
| 235 |
|
| 236 |
PopupMenu *base_tile_popup_menu = nullptr; |
| 237 |
PopupMenu *empty_base_tile_popup_menu = nullptr; |
| 238 |
Ref<Texture2D> resize_handle; |
| 239 |
Ref<Texture2D> resize_handle_disabled; |
| 240 |
Control *tile_atlas_control = nullptr; |
| 241 |
Control *tile_atlas_control_unscaled = nullptr; |
| 242 |
void _tile_atlas_control_draw(); |
| 243 |
void _tile_atlas_control_unscaled_draw(); |
| 244 |
void _tile_atlas_control_mouse_exited(); |
| 245 |
void _tile_atlas_control_gui_input(const Ref<InputEvent> &p_event); |
| 246 |
void _tile_atlas_view_transform_changed(); |
| 247 |
|
| 248 |
|
| 249 |
Vector3i hovered_alternative_tile_coords = Vector3i(TileSetSource::INVALID_ATLAS_COORDS.x, TileSetSource::INVALID_ATLAS_COORDS.y, TileSetSource::INVALID_TILE_ALTERNATIVE); |
| 250 |
|
| 251 |
PopupMenu *alternative_tile_popup_menu = nullptr; |
| 252 |
Control *alternative_tiles_control = nullptr; |
| 253 |
Control *alternative_tiles_control_unscaled = nullptr; |
| 254 |
void _tile_alternatives_create_button_pressed(const Vector2i &p_atlas_coords); |
| 255 |
void _tile_alternatives_control_draw(); |
| 256 |
void _tile_alternatives_control_unscaled_draw(); |
| 257 |
void _tile_alternatives_control_mouse_exited(); |
| 258 |
void _tile_alternatives_control_gui_input(const Ref<InputEvent> &p_event); |
| 259 |
|
| 260 |
|
| 261 |
void _update_tile_id_label(); |
| 262 |
void _update_source_inspector(); |
| 263 |
void _update_fix_selected_and_hovered_tiles(); |
| 264 |
void _update_atlas_source_inspector(); |
| 265 |
void _update_tile_inspector(); |
| 266 |
void _update_tile_data_editors(); |
| 267 |
void _update_current_tile_data_editor(); |
| 268 |
void _update_manage_tile_properties_button(); |
| 269 |
void _update_atlas_view(); |
| 270 |
void _update_toolbar(); |
| 271 |
void _update_buttons(); |
| 272 |
|
| 273 |
|
| 274 |
void _auto_create_tiles(); |
| 275 |
void _auto_remove_tiles(); |
| 276 |
void _cancel_auto_create_tiles(); |
| 277 |
AcceptDialog *confirm_auto_create_tiles = nullptr; |
| 278 |
Vector<Ref<TileSetAtlasSource>> atlases_to_auto_create_tiles; |
| 279 |
Vector2i _get_drag_offset_tile_coords(const Vector2i &p_offset) const; |
| 280 |
|
| 281 |
void _update_source_texture(); |
| 282 |
void _check_outside_tiles(); |
| 283 |
void _cleanup_outside_tiles(); |
| 284 |
|
| 285 |
void _tile_set_changed(); |
| 286 |
void _tile_proxy_object_changed(const String &p_what); |
| 287 |
void _atlas_source_proxy_object_changed(const String &p_what); |
| 288 |
|
| 289 |
void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value); |
| 290 |
|
| 291 |
protected: |
| 292 |
void _notification(int p_what); |
| 293 |
static void _bind_methods(); |
| 294 |
|
| 295 |
|
| 296 |
virtual void shortcut_input(const Ref<InputEvent> &p_event) override; |
| 297 |
|
| 298 |
public: |
| 299 |
void edit(Ref<TileSet> p_tile_set, TileSetAtlasSource *p_tile_set_source, int p_source_id); |
| 300 |
void init_new_atlases(const Vector<Ref<TileSetAtlasSource>> &p_atlases); |
| 301 |
|
| 302 |
TileSetAtlasSourceEditor(); |
| 303 |
~TileSetAtlasSourceEditor(); |
| 304 |
}; |
| 305 |
|
| 306 |
class EditorPropertyTilePolygon : public EditorProperty { |
| 307 |
GDCLASS(EditorPropertyTilePolygon, EditorProperty); |
| 308 |
|
| 309 |
StringName count_property; |
| 310 |
String element_pattern; |
| 311 |
String base_type; |
| 312 |
|
| 313 |
void _add_focusable_children(Node *p_node); |
| 314 |
|
| 315 |
GenericTilePolygonEditor *generic_tile_polygon_editor = nullptr; |
| 316 |
void _polygons_changed(); |
| 317 |
|
| 318 |
public: |
| 319 |
virtual void update_property() override; |
| 320 |
void setup_single_mode(const StringName &p_property, const String &p_base_type); |
| 321 |
void setup_multiple_mode(const StringName &p_property, const StringName &p_count_property, const String &p_element_pattern, const String &p_base_type); |
| 322 |
EditorPropertyTilePolygon(); |
| 323 |
}; |
| 324 |
|
| 325 |
class EditorInspectorPluginTileData : public EditorInspectorPlugin { |
| 326 |
GDCLASS(EditorInspectorPluginTileData, EditorInspectorPlugin); |
| 327 |
|
| 328 |
void _occlusion_polygon_set_callback(); |
| 329 |
void _polygons_changed(Object *p_generic_tile_polygon_editor, Object *p_object, const String &p_path); |
| 330 |
|
| 331 |
public: |
| 332 |
virtual bool can_handle(Object *p_object) override; |
| 333 |
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; |
| 334 |
}; |