diff --git a/source/main/gui/panels/GUI_MainSelector.cpp b/source/main/gui/panels/GUI_MainSelector.cpp index 77518f2cb2..a4f54d3f0e 100644 --- a/source/main/gui/panels/GUI_MainSelector.cpp +++ b/source/main/gui/panels/GUI_MainSelector.cpp @@ -55,12 +55,18 @@ using namespace GUI; void MainSelector::Show(LoaderType type, std::string const& filter_guid) { m_loader_type = type; - m_selected_category = m_last_selected_category[type]; // Bounds are checked in UpdateDisplayLists() m_search_method = CacheSearchMethod::NONE; m_search_input.Clear(); m_search_string.clear(); m_filter_guid = filter_guid; + m_selected_cid = m_last_selected_cid[type]; + if (m_selected_cid == 0) + m_selected_cid = CID_All; this->UpdateDisplayLists(); + if (m_last_selected_category[m_loader_type] < m_display_categories.size()) + { + m_selected_category = m_last_selected_category[m_loader_type]; + } if (m_last_selected_entry[m_loader_type] < m_display_entries.size()) { m_selected_entry = m_last_selected_entry[m_loader_type]; @@ -90,12 +96,16 @@ void MainSelector::Draw() { m_selected_category = (m_selected_category + 1) % num_categories; // select next item and wrap around at bottom. m_last_selected_category[m_loader_type] = m_selected_category; + m_selected_cid = m_display_categories[m_selected_category].sdc_category_id; + m_last_selected_cid[m_loader_type] = m_selected_cid; this->UpdateDisplayLists(); } else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_LeftArrow))) { m_selected_category = (m_selected_category > 0) ? (m_selected_category - 1) : (num_categories - 1); // select prev. item and wrap around on top m_last_selected_category[m_loader_type] = m_selected_category; + m_selected_cid = m_display_categories[m_selected_category].sdc_category_id; + m_last_selected_cid[m_loader_type] = m_selected_cid; this->UpdateDisplayLists(); } } @@ -107,6 +117,8 @@ void MainSelector::Draw() &MainSelector::CatComboItemGetter, &m_display_categories, num_categories)) { m_last_selected_category[m_loader_type] = m_selected_category; + m_selected_cid = m_display_categories[m_selected_category].sdc_category_id; + m_last_selected_cid[m_loader_type] = m_selected_cid; this->UpdateDisplayLists(); } ImGui::PopItemWidth(); @@ -395,16 +407,6 @@ struct sort_cats void MainSelector::UpdateDisplayLists() { - int active_category_id = CID_All; // Fallback - if (!m_display_categories.empty()) - { - if (m_selected_category >= m_display_categories.size()) - { - m_selected_category = 0; - } - active_category_id = m_display_categories[m_selected_category].sdc_category_id; - } - m_display_categories.clear(); m_display_entries.clear(); @@ -418,13 +420,13 @@ void MainSelector::UpdateDisplayLists() // Find all relevant entries CacheQuery query; query.cqy_filter_type = m_loader_type; - query.cqy_filter_category_id = active_category_id; + query.cqy_filter_category_id = m_selected_cid; query.cqy_search_method = m_search_method; query.cqy_search_string = m_search_string; query.cqy_filter_guid = m_filter_guid; App::GetCacheSystem()->Query(query); - if (active_category_id == CacheCategoryId::CID_All) + if (m_selected_cid == CacheCategoryId::CID_All) { m_cache_file_freshness = query.cqy_res_last_update; } @@ -438,7 +440,7 @@ void MainSelector::UpdateDisplayLists() query.cqy_res_category_usage[CacheCategoryId::CID_Fresh]++; } - if (active_category_id != CacheCategoryId::CID_Fresh || is_fresh) + if (m_selected_cid != CacheCategoryId::CID_Fresh || is_fresh) { m_display_entries.push_back(res.cqr_entry); m_selected_entry = 0; diff --git a/source/main/gui/panels/GUI_MainSelector.h b/source/main/gui/panels/GUI_MainSelector.h index 4d97292e17..6eb5732697 100644 --- a/source/main/gui/panels/GUI_MainSelector.h +++ b/source/main/gui/panels/GUI_MainSelector.h @@ -94,11 +94,13 @@ class MainSelector bool m_searchbox_was_active = false; CacheEntry m_dummy_skin; - int m_selected_category = 0; + int m_selected_category = 0; //!< Combobox position (uses display list) + int m_selected_cid = 0; //!< Category ID int m_selected_entry = -1; int m_selected_sectionconfig = 0; - std::map m_last_selected_category; //!< Stores the last manually selected category index for each loader type + std::map m_last_selected_category; //!< Last category-combobox position for each loader type + std::map m_last_selected_cid; //!< Last selected category-ID for each loader type std::map m_last_selected_entry; //!< Stores the last manually selected entry index for each loader type };