1/**************************************************************************/
2/* tile_set_scenes_collection_source_editor.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#ifndef TILE_SET_SCENES_COLLECTION_SOURCE_EDITOR_H
32#define TILE_SET_SCENES_COLLECTION_SOURCE_EDITOR_H
33
34#include "editor/editor_inspector.h"
35#include "scene/gui/box_container.h"
36#include "scene/resources/tile_set.h"
37
38class Button;
39class ItemList;
40class Label;
41class EditorFileDialog;
42
43class TileSetScenesCollectionSourceEditor : public HBoxContainer {
44 GDCLASS(TileSetScenesCollectionSourceEditor, HBoxContainer);
45
46private:
47 // -- Proxy object for an atlas source, needed by the inspector --
48 class TileSetScenesCollectionProxyObject : public Object {
49 GDCLASS(TileSetScenesCollectionProxyObject, Object);
50
51 private:
52 Ref<TileSet> tile_set;
53 TileSetScenesCollectionSource *tile_set_scenes_collection_source = nullptr;
54 int source_id = -1;
55
56 protected:
57 bool _set(const StringName &p_name, const Variant &p_value);
58 bool _get(const StringName &p_name, Variant &r_ret) const;
59 void _get_property_list(List<PropertyInfo> *p_list) const;
60 static void _bind_methods();
61
62 public:
63 void set_id(int p_id);
64 int get_id();
65
66 void edit(Ref<TileSet> p_tile_set, TileSetScenesCollectionSource *p_tile_set_scenes_collection_source, int p_source_id);
67 };
68
69 // -- Proxy object for a tile, needed by the inspector --
70 class SceneTileProxyObject : public Object {
71 GDCLASS(SceneTileProxyObject, Object);
72
73 private:
74 TileSetScenesCollectionSourceEditor *tile_set_scenes_collection_source_editor = nullptr;
75
76 TileSetScenesCollectionSource *tile_set_scenes_collection_source = nullptr;
77 int source_id;
78 int scene_id;
79
80 protected:
81 bool _set(const StringName &p_name, const Variant &p_value);
82 bool _get(const StringName &p_name, Variant &r_ret) const;
83 void _get_property_list(List<PropertyInfo> *p_list) const;
84
85 static void _bind_methods();
86
87 public:
88 // Update the proxyed object.
89 void edit(TileSetScenesCollectionSource *p_tile_set_atlas_source, int p_scene_id);
90
91 SceneTileProxyObject(TileSetScenesCollectionSourceEditor *p_tiles_set_scenes_collection_source_editor) {
92 tile_set_scenes_collection_source_editor = p_tiles_set_scenes_collection_source_editor;
93 }
94 };
95
96private:
97 bool read_only = false;
98
99 Ref<TileSet> tile_set;
100 TileSetScenesCollectionSource *tile_set_scenes_collection_source = nullptr;
101 int tile_set_source_id = -1;
102
103 bool tile_set_scenes_collection_source_changed_needs_update = false;
104
105 // Source inspector.
106 TileSetScenesCollectionProxyObject *scenes_collection_source_proxy_object = nullptr;
107 Label *scenes_collection_source_inspector_label = nullptr;
108 EditorInspector *scenes_collection_source_inspector = nullptr;
109
110 // Tile inspector.
111 SceneTileProxyObject *tile_proxy_object = nullptr;
112 Label *tile_inspector_label = nullptr;
113 EditorInspector *tile_inspector = nullptr;
114
115 ItemList *scene_tiles_list = nullptr;
116 Button *scene_tile_add_button = nullptr;
117 Button *scene_tile_delete_button = nullptr;
118 EditorFileDialog *scene_select_dialog = nullptr;
119
120 void _tile_set_scenes_collection_source_changed();
121 void _scenes_collection_source_proxy_object_changed(String p_what);
122 void _scene_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, Variant p_ud);
123 void _scenes_list_item_activated(int p_index);
124
125 void _source_add_pressed();
126 void _scene_file_selected(const String &p_path);
127 void _source_delete_pressed();
128
129 // Update methods.
130 void _update_source_inspector();
131 void _update_tile_inspector();
132 void _update_scenes_list();
133 void _update_action_buttons();
134
135 void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
136 bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
137
138protected:
139 void _notification(int p_what);
140 static void _bind_methods();
141
142public:
143 void edit(Ref<TileSet> p_tile_set, TileSetScenesCollectionSource *p_tile_set_scenes_collection_source, int p_source_id);
144 TileSetScenesCollectionSourceEditor();
145 ~TileSetScenesCollectionSourceEditor();
146};
147
148#endif // TILE_SET_SCENES_COLLECTION_SOURCE_EDITOR_H
149