tiles_editor_plugin.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /**************************************************************************/
  2. /* tiles_editor_plugin.cpp */
  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. #include "tiles_editor_plugin.h"
  31. #include "tile_set_editor.h"
  32. #include "core/os/mutex.h"
  33. #include "editor/editor_command_palette.h"
  34. #include "editor/editor_interface.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_settings.h"
  37. #include "editor/editor_string_names.h"
  38. #include "editor/gui/editor_bottom_panel.h"
  39. #include "editor/multi_node_edit.h"
  40. #include "editor/plugins/canvas_item_editor_plugin.h"
  41. #include "editor/themes/editor_scale.h"
  42. #include "scene/2d/tile_map.h"
  43. #include "scene/2d/tile_map_layer.h"
  44. #include "scene/gui/box_container.h"
  45. #include "scene/gui/button.h"
  46. #include "scene/gui/control.h"
  47. #include "scene/gui/separator.h"
  48. #include "scene/resources/2d/tile_set.h"
  49. #include "scene/resources/image_texture.h"
  50. TilesEditorUtils *TilesEditorUtils::singleton = nullptr;
  51. TileMapEditorPlugin *tile_map_plugin_singleton = nullptr;
  52. TileSetEditorPlugin *tile_set_plugin_singleton = nullptr;
  53. void TilesEditorUtils::_preview_frame_started() {
  54. RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<TilesEditorUtils *>(this), &TilesEditorUtils::_pattern_preview_done));
  55. }
  56. void TilesEditorUtils::_pattern_preview_done() {
  57. pattern_preview_done.post();
  58. }
  59. void TilesEditorUtils::_thread_func(void *ud) {
  60. TilesEditorUtils *te = static_cast<TilesEditorUtils *>(ud);
  61. set_current_thread_safe_for_nodes(true);
  62. te->_thread();
  63. }
  64. void TilesEditorUtils::_thread() {
  65. pattern_thread_exited.clear();
  66. while (!pattern_thread_exit.is_set()) {
  67. pattern_preview_sem.wait();
  68. pattern_preview_mutex.lock();
  69. if (pattern_preview_queue.size() == 0) {
  70. pattern_preview_mutex.unlock();
  71. } else {
  72. QueueItem item = pattern_preview_queue.front()->get();
  73. pattern_preview_queue.pop_front();
  74. pattern_preview_mutex.unlock();
  75. int thumbnail_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size");
  76. thumbnail_size *= EDSCALE;
  77. Vector2 thumbnail_size2 = Vector2(thumbnail_size, thumbnail_size);
  78. if (item.pattern.is_valid() && !item.pattern->is_empty()) {
  79. // Generate the pattern preview
  80. SubViewport *viewport = memnew(SubViewport);
  81. viewport->set_size(thumbnail_size2);
  82. viewport->set_disable_input(true);
  83. viewport->set_transparent_background(true);
  84. viewport->set_update_mode(SubViewport::UPDATE_ONCE);
  85. TileMap *tile_map = memnew(TileMap);
  86. tile_map->set_tileset(item.tile_set);
  87. tile_map->set_pattern(0, Vector2(), item.pattern);
  88. viewport->add_child(tile_map);
  89. TypedArray<Vector2i> used_cells = tile_map->get_used_cells(0);
  90. Rect2 encompassing_rect;
  91. encompassing_rect.set_position(tile_map->map_to_local(used_cells[0]));
  92. for (int i = 0; i < used_cells.size(); i++) {
  93. Vector2i cell = used_cells[i];
  94. Vector2 world_pos = tile_map->map_to_local(cell);
  95. encompassing_rect.expand_to(world_pos);
  96. // Texture.
  97. Ref<TileSetAtlasSource> atlas_source = item.tile_set->get_source(tile_map->get_cell_source_id(0, cell));
  98. if (atlas_source.is_valid()) {
  99. Vector2i coords = tile_map->get_cell_atlas_coords(0, cell);
  100. int alternative = tile_map->get_cell_alternative_tile(0, cell);
  101. if (atlas_source->has_tile(coords) && atlas_source->has_alternative_tile(coords, alternative)) {
  102. Vector2 center = world_pos - atlas_source->get_tile_data(coords, alternative)->get_texture_origin();
  103. encompassing_rect.expand_to(center - atlas_source->get_tile_texture_region(coords).size / 2);
  104. encompassing_rect.expand_to(center + atlas_source->get_tile_texture_region(coords).size / 2);
  105. }
  106. }
  107. }
  108. Vector2 scale = thumbnail_size2 / MAX(encompassing_rect.size.x, encompassing_rect.size.y);
  109. tile_map->set_scale(scale);
  110. tile_map->set_position(-(scale * encompassing_rect.get_center()) + thumbnail_size2 / 2);
  111. // Add the viewport at the last moment to avoid rendering too early.
  112. callable_mp((Node *)EditorNode::get_singleton(), &Node::add_child).call_deferred(viewport, false, Node::INTERNAL_MODE_DISABLED);
  113. RS::get_singleton()->connect(SNAME("frame_pre_draw"), callable_mp(const_cast<TilesEditorUtils *>(this), &TilesEditorUtils::_preview_frame_started), Object::CONNECT_ONE_SHOT);
  114. pattern_preview_done.wait();
  115. Ref<Image> image = viewport->get_texture()->get_image();
  116. // Find the index for the given pattern. TODO: optimize.
  117. item.callback.call(item.pattern, ImageTexture::create_from_image(image));
  118. viewport->queue_free();
  119. }
  120. }
  121. }
  122. pattern_thread_exited.set();
  123. }
  124. void TilesEditorUtils::queue_pattern_preview(Ref<TileSet> p_tile_set, Ref<TileMapPattern> p_pattern, Callable p_callback) {
  125. ERR_FAIL_COND(!p_tile_set.is_valid());
  126. ERR_FAIL_COND(!p_pattern.is_valid());
  127. {
  128. MutexLock lock(pattern_preview_mutex);
  129. pattern_preview_queue.push_back({ p_tile_set, p_pattern, p_callback });
  130. }
  131. pattern_preview_sem.post();
  132. }
  133. void TilesEditorUtils::set_sources_lists_current(int p_current) {
  134. atlas_sources_lists_current = p_current;
  135. }
  136. void TilesEditorUtils::synchronize_sources_list(Object *p_current_list, Object *p_current_sort_button) {
  137. ItemList *item_list = Object::cast_to<ItemList>(p_current_list);
  138. MenuButton *sorting_button = Object::cast_to<MenuButton>(p_current_sort_button);
  139. ERR_FAIL_NULL(item_list);
  140. ERR_FAIL_NULL(sorting_button);
  141. if (sorting_button->is_visible_in_tree()) {
  142. for (int i = 0; i != SOURCE_SORT_MAX; i++) {
  143. sorting_button->get_popup()->set_item_checked(i, (i == (int)source_sort));
  144. }
  145. }
  146. if (item_list->is_visible_in_tree()) {
  147. // Make sure the selection is not overwritten after sorting.
  148. int atlas_sources_lists_current_mem = atlas_sources_lists_current;
  149. item_list->emit_signal(SNAME("sort_request"));
  150. atlas_sources_lists_current = atlas_sources_lists_current_mem;
  151. if (atlas_sources_lists_current < 0 || atlas_sources_lists_current >= item_list->get_item_count()) {
  152. item_list->deselect_all();
  153. } else {
  154. item_list->set_current(atlas_sources_lists_current);
  155. item_list->ensure_current_is_visible();
  156. item_list->emit_signal(SNAME("item_selected"), atlas_sources_lists_current);
  157. }
  158. }
  159. }
  160. void TilesEditorUtils::set_atlas_view_transform(float p_zoom, Vector2 p_scroll) {
  161. atlas_view_zoom = p_zoom;
  162. atlas_view_scroll = p_scroll;
  163. }
  164. void TilesEditorUtils::synchronize_atlas_view(Object *p_current) {
  165. TileAtlasView *tile_atlas_view = Object::cast_to<TileAtlasView>(p_current);
  166. ERR_FAIL_NULL(tile_atlas_view);
  167. if (tile_atlas_view->is_visible_in_tree()) {
  168. tile_atlas_view->set_transform(atlas_view_zoom, atlas_view_scroll);
  169. }
  170. }
  171. void TilesEditorUtils::set_sorting_option(int p_option) {
  172. source_sort = p_option;
  173. }
  174. List<int> TilesEditorUtils::get_sorted_sources(const Ref<TileSet> p_tile_set) const {
  175. SourceNameComparator::tile_set = p_tile_set;
  176. List<int> source_ids;
  177. for (int i = 0; i < p_tile_set->get_source_count(); i++) {
  178. source_ids.push_back(p_tile_set->get_source_id(i));
  179. }
  180. switch (source_sort) {
  181. case SOURCE_SORT_ID_REVERSE:
  182. // Already sorted.
  183. source_ids.reverse();
  184. break;
  185. case SOURCE_SORT_NAME:
  186. source_ids.sort_custom<SourceNameComparator>();
  187. break;
  188. case SOURCE_SORT_NAME_REVERSE:
  189. source_ids.sort_custom<SourceNameComparator>();
  190. source_ids.reverse();
  191. break;
  192. default: // SOURCE_SORT_ID
  193. break;
  194. }
  195. SourceNameComparator::tile_set.unref();
  196. return source_ids;
  197. }
  198. Ref<TileSet> TilesEditorUtils::SourceNameComparator::tile_set;
  199. bool TilesEditorUtils::SourceNameComparator::operator()(const int &p_a, const int &p_b) const {
  200. String name_a;
  201. String name_b;
  202. {
  203. TileSetSource *source = *tile_set->get_source(p_a);
  204. if (!source->get_name().is_empty()) {
  205. name_a = source->get_name();
  206. }
  207. TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
  208. if (atlas_source) {
  209. Ref<Texture2D> texture = atlas_source->get_texture();
  210. if (name_a.is_empty() && texture.is_valid()) {
  211. name_a = texture->get_path().get_file();
  212. }
  213. }
  214. if (name_a.is_empty()) {
  215. name_a = itos(p_a);
  216. }
  217. }
  218. {
  219. TileSetSource *source = *tile_set->get_source(p_b);
  220. if (!source->get_name().is_empty()) {
  221. name_b = source->get_name();
  222. }
  223. TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
  224. if (atlas_source) {
  225. Ref<Texture2D> texture = atlas_source->get_texture();
  226. if (name_b.is_empty() && texture.is_valid()) {
  227. name_b = texture->get_path().get_file();
  228. }
  229. }
  230. if (name_b.is_empty()) {
  231. name_b = itos(p_b);
  232. }
  233. }
  234. return NaturalNoCaseComparator()(name_a, name_b);
  235. }
  236. void TilesEditorUtils::display_tile_set_editor_panel() {
  237. tile_map_plugin_singleton->hide_editor();
  238. tile_set_plugin_singleton->make_visible(true);
  239. }
  240. void TilesEditorUtils::draw_selection_rect(CanvasItem *p_ci, const Rect2 &p_rect, const Color &p_color) {
  241. Ref<Texture2D> selection_texture = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("TileSelection"), EditorStringName(EditorIcons));
  242. real_t scale = p_ci->get_global_transform().get_scale().x * 0.5;
  243. p_ci->draw_set_transform(p_rect.position, 0, Vector2(1, 1) / scale);
  244. RS::get_singleton()->canvas_item_add_nine_patch(
  245. p_ci->get_canvas_item(), Rect2(Vector2(), p_rect.size * scale), Rect2(), selection_texture->get_rid(),
  246. Vector2(2, 2), Vector2(2, 2), RS::NINE_PATCH_STRETCH, RS::NINE_PATCH_STRETCH, false, p_color);
  247. p_ci->draw_set_transform_matrix(Transform2D());
  248. }
  249. TilesEditorUtils::TilesEditorUtils() {
  250. singleton = this;
  251. // Pattern preview generation thread.
  252. pattern_preview_thread.start(_thread_func, this);
  253. }
  254. TilesEditorUtils::~TilesEditorUtils() {
  255. if (pattern_preview_thread.is_started()) {
  256. pattern_thread_exit.set();
  257. pattern_preview_sem.post();
  258. while (!pattern_thread_exited.is_set()) {
  259. OS::get_singleton()->delay_usec(10000);
  260. RenderingServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on visual server
  261. }
  262. pattern_preview_thread.wait_to_finish();
  263. }
  264. singleton = nullptr;
  265. }
  266. void TileMapEditorPlugin::_tile_map_layer_changed() {
  267. if (tile_map_changed_needs_update) {
  268. return;
  269. }
  270. tile_map_changed_needs_update = true;
  271. callable_mp(this, &TileMapEditorPlugin::_update_tile_map).call_deferred();
  272. }
  273. void TileMapEditorPlugin::_tile_map_layer_removed() {
  274. // Workaround for TileMap, making sure the editor stays open when you delete the currently edited layer.
  275. TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_group_id));
  276. if (tile_map) {
  277. edit(tile_map);
  278. }
  279. }
  280. void TileMapEditorPlugin::_update_tile_map() {
  281. TileMapLayer *edited_layer = Object::cast_to<TileMapLayer>(ObjectDB::get_instance(tile_map_layer_id));
  282. if (edited_layer) {
  283. Ref<TileSet> tile_set = edited_layer->get_tile_set();
  284. if (tile_set.is_valid() && tile_set_id != tile_set->get_instance_id()) {
  285. tile_set_plugin_singleton->edit(tile_set.ptr());
  286. tile_set_plugin_singleton->make_visible(true);
  287. tile_set_id = tile_set->get_instance_id();
  288. } else if (tile_set.is_null()) {
  289. tile_set_plugin_singleton->edit(nullptr);
  290. tile_set_plugin_singleton->make_visible(false);
  291. tile_set_id = ObjectID();
  292. }
  293. }
  294. tile_map_changed_needs_update = false;
  295. }
  296. void TileMapEditorPlugin::_select_layer(const StringName &p_name) {
  297. TileMapLayer *edited_layer = Object::cast_to<TileMapLayer>(ObjectDB::get_instance(tile_map_layer_id));
  298. ERR_FAIL_NULL(edited_layer);
  299. Node *parent = edited_layer->get_parent();
  300. if (parent) {
  301. TileMapLayer *new_layer = Object::cast_to<TileMapLayer>(parent->get_node_or_null(String(p_name)));
  302. edit(new_layer);
  303. }
  304. }
  305. void TileMapEditorPlugin::_edit_tile_map_layer(TileMapLayer *p_tile_map_layer, bool p_show_layer_selector) {
  306. ERR_FAIL_NULL(p_tile_map_layer);
  307. editor->edit(p_tile_map_layer);
  308. editor->set_show_layer_selector(p_show_layer_selector);
  309. // Update the object IDs.
  310. tile_map_layer_id = p_tile_map_layer->get_instance_id();
  311. p_tile_map_layer->connect(CoreStringName(changed), callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_changed));
  312. p_tile_map_layer->connect(SceneStringName(tree_exited), callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_removed));
  313. // Update the edited tileset.
  314. Ref<TileSet> tile_set = p_tile_map_layer->get_tile_set();
  315. if (tile_set.is_valid()) {
  316. tile_set_plugin_singleton->edit(tile_set.ptr());
  317. tile_set_plugin_singleton->make_visible(true);
  318. tile_set_id = tile_set->get_instance_id();
  319. } else {
  320. tile_set_plugin_singleton->edit(nullptr);
  321. tile_set_plugin_singleton->make_visible(false);
  322. }
  323. }
  324. void TileMapEditorPlugin::_edit_tile_map(TileMap *p_tile_map) {
  325. ERR_FAIL_NULL(p_tile_map);
  326. if (p_tile_map->get_layers_count() > 0) {
  327. TileMapLayer *selected_layer = Object::cast_to<TileMapLayer>(p_tile_map->get_child(0));
  328. _edit_tile_map_layer(selected_layer, true);
  329. } else {
  330. editor->edit(nullptr);
  331. editor->set_show_layer_selector(false);
  332. }
  333. }
  334. void TileMapEditorPlugin::_notification(int p_notification) {
  335. if (p_notification == NOTIFICATION_EXIT_TREE) {
  336. get_tree()->queue_delete(TilesEditorUtils::get_singleton());
  337. }
  338. }
  339. void TileMapEditorPlugin::edit(Object *p_object) {
  340. TileMapLayer *edited_layer = Object::cast_to<TileMapLayer>(ObjectDB::get_instance(tile_map_layer_id));
  341. if (edited_layer) {
  342. edited_layer->disconnect(CoreStringName(changed), callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_changed));
  343. edited_layer->disconnect(SceneStringName(tree_exited), callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_removed));
  344. }
  345. tile_map_group_id = ObjectID();
  346. tile_map_layer_id = ObjectID();
  347. tile_set_id = ObjectID();
  348. TileMap *tile_map = Object::cast_to<TileMap>(p_object);
  349. TileMapLayer *tile_map_layer = Object::cast_to<TileMapLayer>(p_object);
  350. MultiNodeEdit *multi_node_edit = Object::cast_to<MultiNodeEdit>(p_object);
  351. if (tile_map) {
  352. _edit_tile_map(tile_map);
  353. } else if (tile_map_layer) {
  354. _edit_tile_map_layer(tile_map_layer, false);
  355. } else if (multi_node_edit) {
  356. editor->edit(multi_node_edit);
  357. } else {
  358. editor->edit(nullptr);
  359. }
  360. }
  361. bool TileMapEditorPlugin::handles(Object *p_object) const {
  362. MultiNodeEdit *multi_node_edit = Object::cast_to<MultiNodeEdit>(p_object);
  363. Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
  364. if (multi_node_edit && edited_scene) {
  365. bool only_tile_map_layers = true;
  366. for (int i = 0; i < multi_node_edit->get_node_count(); i++) {
  367. if (!Object::cast_to<TileMapLayer>(edited_scene->get_node(multi_node_edit->get_node(i)))) {
  368. only_tile_map_layers = false;
  369. break;
  370. }
  371. }
  372. return only_tile_map_layers;
  373. }
  374. return Object::cast_to<TileMapLayer>(p_object) != nullptr || Object::cast_to<TileMap>(p_object) != nullptr;
  375. }
  376. void TileMapEditorPlugin::make_visible(bool p_visible) {
  377. if (p_visible) {
  378. button->show();
  379. EditorNode::get_bottom_panel()->make_item_visible(editor);
  380. } else {
  381. button->hide();
  382. if (editor->is_visible_in_tree()) {
  383. EditorNode::get_bottom_panel()->hide_bottom_panel();
  384. }
  385. }
  386. }
  387. bool TileMapEditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
  388. return editor->forward_canvas_gui_input(p_event);
  389. }
  390. void TileMapEditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay) {
  391. editor->forward_canvas_draw_over_viewport(p_overlay);
  392. }
  393. void TileMapEditorPlugin::hide_editor() {
  394. if (editor->is_visible_in_tree()) {
  395. EditorNode::get_bottom_panel()->hide_bottom_panel();
  396. }
  397. }
  398. bool TileMapEditorPlugin::is_editor_visible() const {
  399. return editor->is_visible_in_tree();
  400. }
  401. TileMapEditorPlugin::TileMapEditorPlugin() {
  402. if (!TilesEditorUtils::get_singleton()) {
  403. memnew(TilesEditorUtils);
  404. }
  405. tile_map_plugin_singleton = this;
  406. editor = memnew(TileMapLayerEditor);
  407. editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  408. editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  409. editor->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
  410. editor->hide();
  411. button = EditorNode::get_bottom_panel()->add_item(TTR("TileMap"), editor, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_tile_map_bottom_panel", TTR("Toggle TileMap Bottom Panel")));
  412. button->hide();
  413. }
  414. TileMapEditorPlugin::~TileMapEditorPlugin() {
  415. tile_map_plugin_singleton = nullptr;
  416. }
  417. void TileSetEditorPlugin::edit(Object *p_object) {
  418. editor->edit(Ref<TileSet>(p_object));
  419. if (p_object) {
  420. edited_tileset = p_object->get_instance_id();
  421. } else {
  422. edited_tileset = ObjectID();
  423. }
  424. }
  425. bool TileSetEditorPlugin::handles(Object *p_object) const {
  426. return Object::cast_to<TileSet>(p_object) != nullptr;
  427. }
  428. void TileSetEditorPlugin::make_visible(bool p_visible) {
  429. if (p_visible) {
  430. button->show();
  431. if (!tile_map_plugin_singleton->is_editor_visible()) {
  432. EditorNode::get_bottom_panel()->make_item_visible(editor);
  433. }
  434. } else {
  435. button->hide();
  436. if (editor->is_visible_in_tree()) {
  437. EditorNode::get_bottom_panel()->hide_bottom_panel();
  438. }
  439. }
  440. }
  441. ObjectID TileSetEditorPlugin::get_edited_tileset() const {
  442. return edited_tileset;
  443. }
  444. TileSetEditorPlugin::TileSetEditorPlugin() {
  445. if (!TilesEditorUtils::get_singleton()) {
  446. memnew(TilesEditorUtils);
  447. }
  448. tile_set_plugin_singleton = this;
  449. editor = memnew(TileSetEditor);
  450. editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  451. editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  452. editor->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
  453. editor->hide();
  454. button = EditorNode::get_bottom_panel()->add_item(TTR("TileSet"), editor, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_tile_set_bottom_panel", TTR("Toggle TileSet Bottom Panel")));
  455. button->hide();
  456. }
  457. TileSetEditorPlugin::~TileSetEditorPlugin() {
  458. tile_set_plugin_singleton = nullptr;
  459. }