Skip to content

Commit

Permalink
Improve scene tiles workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Aug 18, 2023
1 parent ff5c884 commit a88e3b8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion editor/plugins/tiles/tile_atlas_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion editor/plugins/tiles/tile_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion editor/plugins/tiles/tile_set_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
24 changes: 22 additions & 2 deletions editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
class Button;
class ItemList;
class Label;
class EditorFileDialog;

class TileSetScenesCollectionSourceEditor : public HBoxContainer {
GDCLASS(TileSetScenesCollectionSourceEditor, HBoxContainer);
Expand Down Expand Up @@ -114,13 +115,15 @@ class TileSetScenesCollectionSourceEditor : public HBoxContainer {
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);
void _scene_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, Variant p_ud);
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.
Expand Down
4 changes: 2 additions & 2 deletions scene/resources/tile_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a88e3b8

Please sign in to comment.