Skip to content

Commit

Permalink
🐛 Fixed category mixup in LoaderUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Aug 21, 2021
1 parent aebb2ac commit e8b79f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
30 changes: 16 additions & 14 deletions source/main/gui/panels/GUI_MainSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions source/main/gui/panels/GUI_MainSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoaderType, int> m_last_selected_category; //!< Stores the last manually selected category index for each loader type
std::map<LoaderType, int> m_last_selected_category; //!< Last category-combobox position for each loader type
std::map<LoaderType, int> m_last_selected_cid; //!< Last selected category-ID for each loader type
std::map<LoaderType, int> m_last_selected_entry; //!< Stores the last manually selected entry index for each loader type
};

Expand Down

0 comments on commit e8b79f6

Please # to comment.