Improve scene tiles workflow

This commit is contained in:
kobewi 2023-08-18 13:46:58 +02:00
parent ff5c884153
commit a88e3b8604
6 changed files with 42 additions and 7 deletions

View File

@ -632,7 +632,7 @@ TileAtlasView::TileAtlasView() {
panel->add_child(center_container);
missing_source_label = memnew(Label);
missing_source_label->set_text(TTR("No atlas source with a valid texture selected."));
missing_source_label->set_text(TTR("The selected atlas source has no valid texture. Assign a texture in the TileSet bottom tab."));
center_container->add_child(missing_source_label);
margin_container = memnew(MarginContainer);

View File

@ -177,7 +177,11 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() {
if (scene_collection_source) {
texture = tiles_bottom_panel->get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons"));
if (item_text.is_empty()) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
if (scene_collection_source->get_scene_tiles_count() > 0) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
} else {
item_text = vformat(TTR("Empty Scene Collection Source (ID: %d)"), source_id);
}
}
}
@ -398,6 +402,10 @@ void TileMapEditorTilesPlugin::_update_scenes_collection_view() {
scene_tiles_list->select(item_index, false);
}
}
if (scene_tiles_list->get_item_count() == 0) {
scene_tiles_list->add_item(TTR("The selected scene collection source has no scenes. Add scenes in the TileSet bottom tab."));
scene_tiles_list->set_item_disabled(-1, true);
}
// Icon size update.
int int_size = int(EDITOR_GET("filesystem/file_dialog/thumbnail_size")) * EDSCALE;

View File

@ -181,7 +181,11 @@ void TileSetEditor::_update_sources_list(int force_selected_id) {
if (scene_collection_source) {
texture = get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons"));
if (item_text.is_empty()) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
if (scene_collection_source->get_scene_tiles_count() > 0) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
} else {
item_text = vformat(TTR("Empty Scene Collection Source (ID: %d)"), source_id);
}
}
}

View File

@ -36,6 +36,7 @@
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_file_dialog.h"
#include "editor/plugins/tiles/tile_set_editor.h"
#include "scene/gui/button.h"
@ -239,10 +240,26 @@ void TileSetScenesCollectionSourceEditor::_scenes_list_item_activated(int p_inde
}
void TileSetScenesCollectionSourceEditor::_source_add_pressed() {
if (!scene_select_dialog) {
scene_select_dialog = memnew(EditorFileDialog);
add_child(scene_select_dialog);
scene_select_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
scene_select_dialog->connect("file_selected", callable_mp(this, &TileSetScenesCollectionSourceEditor::_scene_file_selected));
for (const String &E : Vector<String>{ "tscn", "scn" }) {
scene_select_dialog->add_filter("*." + E, E.to_upper());
}
}
scene_select_dialog->popup_file_dialog();
}
void TileSetScenesCollectionSourceEditor::_scene_file_selected(const String &p_path) {
Ref<PackedScene> scene = ResourceLoader::load(p_path);
int scene_id = tile_set_scenes_collection_source->get_next_scene_tile_id();
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Add a Scene Tile"));
undo_redo->add_do_method(tile_set_scenes_collection_source, "create_scene_tile", Ref<PackedScene>(), scene_id);
undo_redo->add_do_method(tile_set_scenes_collection_source, "create_scene_tile", scene, scene_id);
undo_redo->add_undo_method(tile_set_scenes_collection_source, "remove_scene_tile", scene_id);
undo_redo->commit_action();
_update_scenes_list();
@ -323,6 +340,10 @@ void TileSetScenesCollectionSourceEditor::_update_scenes_list() {
to_reselect = i;
}
}
if (scene_tiles_list->get_item_count() == 0) {
scene_tiles_list->add_item(TTR("Drag and drop scenes here or use the Add button."));
scene_tiles_list->set_item_disabled(-1, true);
}
// Reselect if needed.
if (to_reselect >= 0) {
@ -336,7 +357,6 @@ void TileSetScenesCollectionSourceEditor::_update_scenes_list() {
void TileSetScenesCollectionSourceEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
scene_tile_add_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
scene_tile_delete_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));

View File

@ -38,6 +38,7 @@
class Button;
class ItemList;
class Label;
class EditorFileDialog;
class TileSetScenesCollectionSourceEditor : public HBoxContainer {
GDCLASS(TileSetScenesCollectionSourceEditor, HBoxContainer);
@ -114,6 +115,7 @@ private:
ItemList *scene_tiles_list = nullptr;
Button *scene_tile_add_button = nullptr;
Button *scene_tile_delete_button = nullptr;
EditorFileDialog *scene_select_dialog = nullptr;
void _tile_set_scenes_collection_source_changed();
void _scenes_collection_source_proxy_object_changed(String p_what);
@ -121,6 +123,7 @@ private:
void _scenes_list_item_activated(int p_index);
void _source_add_pressed();
void _scene_file_selected(const String &p_path);
void _source_delete_pressed();
// Update methods.

View File

@ -4867,9 +4867,9 @@ void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedSce
type = scene_state->get_node_type(0);
scene_state = scene_state->get_base_scene_state();
}
ERR_FAIL_COND_MSG(type.is_empty(), vformat("Invalid PackedScene for TileSetScenesCollectionSource: %s. Could not get the type of the root node.", p_packed_scene->get_path()));
ERR_FAIL_COND_EDMSG(type.is_empty(), vformat("Invalid PackedScene for TileSetScenesCollectionSource: %s. Could not get the type of the root node.", p_packed_scene->get_path()));
bool extends_correct_class = ClassDB::is_parent_class(type, "CanvasItem");
ERR_FAIL_COND_MSG(!extends_correct_class, vformat("Invalid PackedScene for TileSetScenesCollectionSource: %s. Root node should extend CanvasItem. Found %s instead.", p_packed_scene->get_path(), type));
ERR_FAIL_COND_EDMSG(!extends_correct_class, vformat("Invalid PackedScene for TileSetScenesCollectionSource: %s. Root node should extend CanvasItem. Found %s instead.", p_packed_scene->get_path(), type));
scenes[p_id].scene = p_packed_scene;
} else {