|
@@ -124,6 +124,10 @@ void TileMapEditorTilesPlugin::_tab_changed() {
|
|
|
void TileMapEditorTilesPlugin::_update_tile_set_sources_list() {
|
|
|
// Update the sources.
|
|
|
int old_current = sources_list->get_current();
|
|
|
+ int old_source = -1;
|
|
|
+ if (old_current > -1) {
|
|
|
+ old_source = sources_list->get_item_metadata(old_current);
|
|
|
+ }
|
|
|
sources_list->clear();
|
|
|
|
|
|
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
|
|
@@ -136,9 +140,12 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- for (int i = 0; i < tile_set->get_source_count(); i++) {
|
|
|
- int source_id = tile_set->get_source_id(i);
|
|
|
+ if (!tile_set->has_source(old_source)) {
|
|
|
+ old_source = -1;
|
|
|
+ }
|
|
|
|
|
|
+ List<int> source_ids = TilesEditorPlugin::get_singleton()->get_sorted_sources(tile_set);
|
|
|
+ for (const int &source_id : source_ids) {
|
|
|
TileSetSource *source = *tile_set->get_source(source_id);
|
|
|
|
|
|
Ref<Texture2D> texture;
|
|
@@ -157,7 +164,7 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() {
|
|
|
if (texture.is_valid()) {
|
|
|
item_text = vformat("%s (ID: %d)", texture->get_path().get_file(), source_id);
|
|
|
} else {
|
|
|
- item_text = vformat("No Texture Atlas Source (ID: %d)", source_id);
|
|
|
+ item_text = vformat(TTR("No Texture Atlas Source (ID: %d)"), source_id);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -180,20 +187,25 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() {
|
|
|
}
|
|
|
|
|
|
sources_list->add_item(item_text, texture);
|
|
|
- sources_list->set_item_metadata(i, source_id);
|
|
|
+ sources_list->set_item_metadata(sources_list->get_item_count() - 1, source_id);
|
|
|
}
|
|
|
|
|
|
if (sources_list->get_item_count() > 0) {
|
|
|
- if (old_current > 0) {
|
|
|
- // Keep the current selected item if needed.
|
|
|
- sources_list->set_current(CLAMP(old_current, 0, sources_list->get_item_count() - 1));
|
|
|
+ if (old_source >= 0) {
|
|
|
+ for (int i = 0; i < sources_list->get_item_count(); i++) {
|
|
|
+ if ((int)sources_list->get_item_metadata(i) == old_source) {
|
|
|
+ sources_list->set_current(i);
|
|
|
+ sources_list->ensure_current_is_visible();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
sources_list->set_current(0);
|
|
|
}
|
|
|
sources_list->emit_signal(SNAME("item_selected"), sources_list->get_current());
|
|
|
}
|
|
|
|
|
|
- // Synchronize
|
|
|
+ // Synchronize the lists.
|
|
|
TilesEditorPlugin::get_singleton()->set_sources_lists_current(sources_list->get_current());
|
|
|
}
|
|
|
|
|
@@ -439,6 +451,7 @@ void TileMapEditorTilesPlugin::_scenes_list_nothing_selected() {
|
|
|
}
|
|
|
|
|
|
void TileMapEditorTilesPlugin::_update_theme() {
|
|
|
+ source_sort_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("Sort"), SNAME("EditorIcons")));
|
|
|
select_tool_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons")));
|
|
|
paint_tool_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
|
|
|
line_tool_button->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("CurveLinear"), SNAME("EditorIcons")));
|
|
@@ -1950,6 +1963,14 @@ void TileMapEditorTilesPlugin::edit(ObjectID p_tile_map_id, int p_tile_map_layer
|
|
|
tile_map_layer = p_tile_map_layer;
|
|
|
}
|
|
|
|
|
|
+void TileMapEditorTilesPlugin::_set_source_sort(int p_sort) {
|
|
|
+ for (int i = 0; i != TilesEditorPlugin::SOURCE_SORT_MAX; i++) {
|
|
|
+ source_sort_button->get_popup()->set_item_checked(i, (i == (int)p_sort));
|
|
|
+ }
|
|
|
+ TilesEditorPlugin::get_singleton()->set_sorting_option(p_sort);
|
|
|
+ _update_tile_set_sources_list();
|
|
|
+}
|
|
|
+
|
|
|
void TileMapEditorTilesPlugin::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("_scene_thumbnail_done"), &TileMapEditorTilesPlugin::_scene_thumbnail_done);
|
|
|
ClassDB::bind_method(D_METHOD("_set_tile_map_selection", "selection"), &TileMapEditorTilesPlugin::_set_tile_map_selection);
|
|
@@ -2106,17 +2127,44 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() {
|
|
|
atlas_sources_split_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
tiles_bottom_panel->add_child(atlas_sources_split_container);
|
|
|
|
|
|
+ VBoxContainer *split_container_left_side = memnew(VBoxContainer);
|
|
|
+ split_container_left_side->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
+ split_container_left_side->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
+ split_container_left_side->set_stretch_ratio(0.25);
|
|
|
+ split_container_left_side->set_custom_minimum_size(Size2i(70, 0) * EDSCALE);
|
|
|
+ atlas_sources_split_container->add_child(split_container_left_side);
|
|
|
+
|
|
|
+ HBoxContainer *sources_bottom_actions = memnew(HBoxContainer);
|
|
|
+ sources_bottom_actions->set_alignment(HBoxContainer::ALIGNMENT_END);
|
|
|
+
|
|
|
+ source_sort_button = memnew(MenuButton);
|
|
|
+ source_sort_button->set_flat(true);
|
|
|
+ source_sort_button->set_tooltip(TTR("Sort sources"));
|
|
|
+
|
|
|
+ PopupMenu *p = source_sort_button->get_popup();
|
|
|
+ p->connect("id_pressed", callable_mp(this, &TileMapEditorTilesPlugin::_set_source_sort));
|
|
|
+ p->add_radio_check_item(TTR("Sort by ID (Ascending)"), TilesEditorPlugin::SOURCE_SORT_ID);
|
|
|
+ p->add_radio_check_item(TTR("Sort by ID (Descending)"), TilesEditorPlugin::SOURCE_SORT_ID_REVERSE);
|
|
|
+ p->add_radio_check_item(TTR("Sort by Name (Ascending)"), TilesEditorPlugin::SOURCE_SORT_NAME);
|
|
|
+ p->add_radio_check_item(TTR("Sort by Name (Descending)"), TilesEditorPlugin::SOURCE_SORT_NAME_REVERSE);
|
|
|
+ p->set_item_checked(TilesEditorPlugin::SOURCE_SORT_ID, true);
|
|
|
+ sources_bottom_actions->add_child(source_sort_button);
|
|
|
+
|
|
|
sources_list = memnew(ItemList);
|
|
|
sources_list->set_fixed_icon_size(Size2i(60, 60) * EDSCALE);
|
|
|
sources_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
+ sources_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
sources_list->set_stretch_ratio(0.25);
|
|
|
sources_list->set_custom_minimum_size(Size2i(70, 0) * EDSCALE);
|
|
|
sources_list->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST);
|
|
|
sources_list->connect("item_selected", callable_mp(this, &TileMapEditorTilesPlugin::_update_fix_selected_and_hovered).unbind(1));
|
|
|
sources_list->connect("item_selected", callable_mp(this, &TileMapEditorTilesPlugin::_update_source_display).unbind(1));
|
|
|
sources_list->connect("item_selected", callable_mp(TilesEditorPlugin::get_singleton(), &TilesEditorPlugin::set_sources_lists_current));
|
|
|
- sources_list->connect("visibility_changed", callable_mp(TilesEditorPlugin::get_singleton(), &TilesEditorPlugin::synchronize_sources_list), varray(sources_list));
|
|
|
- atlas_sources_split_container->add_child(sources_list);
|
|
|
+ sources_list->connect("visibility_changed", callable_mp(TilesEditorPlugin::get_singleton(), &TilesEditorPlugin::synchronize_sources_list), varray(sources_list, source_sort_button));
|
|
|
+ sources_list->add_user_signal(MethodInfo("sort_request"));
|
|
|
+ sources_list->connect("sort_request", callable_mp(this, &TileMapEditorTilesPlugin::_update_tile_set_sources_list));
|
|
|
+ split_container_left_side->add_child(sources_list);
|
|
|
+ split_container_left_side->add_child(sources_bottom_actions);
|
|
|
|
|
|
// Tile atlas source.
|
|
|
tile_atlas_view = memnew(TileAtlasView);
|