From db011c8c9ed37fe207da3201ba115c32b1133f71 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Thu, 22 Sep 2022 01:26:40 +0600 Subject: [PATCH] Add clipping support for ImageList --- .vscode/settings.json | 3 +- resource/common/locale/English.toml | 2 +- resource/common/locale/Portuguese.toml | 2 +- resource/common/locale/Russian.toml | 2 +- resource/common/locale/Spanish.toml | 2 +- src/utils/resourcestore.cpp | 123 +++++-- src/utils/resourcestore.h | 26 +- src/utils/widget.cpp | 463 ++++++++++--------------- src/utils/widget.h | 3 - 9 files changed, 305 insertions(+), 321 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bfc5f93..f66b1ec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -77,6 +77,7 @@ "*.rh": "cpp", "csignal": "cpp", "coroutine": "cpp", - "any": "cpp" + "any": "cpp", + "variant": "cpp" } } \ No newline at end of file diff --git a/resource/common/locale/English.toml b/resource/common/locale/English.toml index aae7743..e9c6b57 100644 --- a/resource/common/locale/English.toml +++ b/resource/common/locale/English.toml @@ -149,7 +149,7 @@ CheckUpdate = "Check update" Commands = "Commands" Config = "Config" Coords = "Coords: %.2f, %.2f, %.2f" -CopyrightDisclaimer = "Copyright Grinch_ 2019-2022. All rights reserved." +CopyrightDisclaimer = "Copyright Grinch_ 2019-2023. All rights reserved." CPUUsage = "CPU usage: %.2f%%" Credits = "Credits" CurrentVersion = "Current version" diff --git a/resource/common/locale/Portuguese.toml b/resource/common/locale/Portuguese.toml index 8833507..2b8d0cf 100644 --- a/resource/common/locale/Portuguese.toml +++ b/resource/common/locale/Portuguese.toml @@ -141,7 +141,7 @@ Build = "Build" CheckUpdate = "Verificar atualizações" Commands = "Comandos" Config = "Configuração" -CopyrightDisclaimer = "Copyright Grinch_ 2019-2022. Todos os direitos reservados." +CopyrightDisclaimer = "Copyright Grinch_ 2019-2023. Todos os direitos reservados." Credits = "Créditos" DiscordRPC = "Status personalizado Discord (rich presence)" DiscordServer = "Servidor do Discord" diff --git a/resource/common/locale/Russian.toml b/resource/common/locale/Russian.toml index ca55fcc..2c35e5b 100644 --- a/resource/common/locale/Russian.toml +++ b/resource/common/locale/Russian.toml @@ -159,7 +159,7 @@ CheckUpdate = "Проверить обновления" Commands = "Команды" Config = "Настройки" Coords = "Координаты: %.2f, %.2f, %.2f" -CopyrightDisclaimer = "© Grinch_ 2019-2022. Все права защищены." +CopyrightDisclaimer = "© Grinch_ 2019-2023. Все права защищены." CPUUsage = "Использование ЦП: %.2f%%" Credits = "Ответственен за" CurrentVersion = "Текущая версия" diff --git a/resource/common/locale/Spanish.toml b/resource/common/locale/Spanish.toml index 1e5e5f3..eff8e61 100644 --- a/resource/common/locale/Spanish.toml +++ b/resource/common/locale/Spanish.toml @@ -136,7 +136,7 @@ Build = "Build" CheckUpdate = "Buscar actualización" Commands = "Comandos" Config = "Configuración" -CopyrightDisclaimer = "Copyright Grinch_ 2019-2022. Todos los derechos reservados." +CopyrightDisclaimer = "Copyright Grinch_ 2019-2023. Todos los derechos reservados." Credits = "Creditos" DiscordServer = "Server de Discord" FixVehKey = "Arreglar vehiculo actual" diff --git a/src/utils/resourcestore.cpp b/src/utils/resourcestore.cpp index c72d6ec..02646ff 100644 --- a/src/utils/resourcestore.cpp +++ b/src/utils/resourcestore.cpp @@ -144,45 +144,128 @@ void ResourceStore::LoadTextureResource(std::string&& name) } while ( pEndDic != (RwTexDictionary*)&pRwTexDictionary->texturesInDict ); } + m_bSearchListUpdateRequired = true; } -void ResourceStore::UpdateSearchList(bool favourites) +void ResourceStore::UpdateSearchList(bool favourites, fRtnArg1_t getNameFunc, fRtnBoolArg1_t verifyFunc) { m_nSearchList.clear(); if (favourites) { - for (auto [key, val] : *m_pData->GetTable("Favourites")) + if (m_Type == eResourceType::TYPE_TEXT) { - std::string label = std::string(key.str()); - if (m_Filter.PassFilter(label.c_str())) + for (auto [key, val] : *m_pData->GetTable("Favourites")) { - std::string data = val.value_or("Unkonwn"); - m_nSearchList.push_back({std::move(std::string("Favourites")), std::move(label), std::move(data)}); + ListLookup lookup; + lookup.key = std::string(key.str()); + if (m_Filter.PassFilter(lookup.key.c_str())) + { + lookup.cat = "Favourites"; + lookup.val = val.value_or("Unkonwn"); + m_nSearchList.push_back(std::move(lookup)); + } + } + } + else + { + for (auto [key, val] : *m_pData->GetTable("Favourites")) + { + for (uint i = 0; i < m_ImagesList.size(); ++i) + { + ImageLookup lookup; + lookup.m_FileName = m_ImagesList[i]->m_FileName; + lookup.m_ModelName = getNameFunc == nullptr ? "" : getNameFunc(lookup.m_FileName); + + if (lookup.m_ModelName == key.str() && m_Filter.PassFilter(lookup.m_ModelName.c_str()) + && (verifyFunc == nullptr || verifyFunc(lookup.m_FileName))) + { + lookup.m_bCustom = lookup.m_FileName.find("Added") != std::string::npos; + lookup.m_pTexture = m_ImagesList[i]->m_pTexture; + m_nSearchList.push_back(std::move(lookup)); + break; + } + } + + if (m_Type == eResourceType::TYPE_IMAGE_TEXT) + { + for (auto [key, val] : *m_pData->GetTable("Custom")) + { + ImageLookup lookup; + lookup.m_FileName = val.as_string()->value_or("0"); + lookup.m_ModelName = std::string(key.str()); + if (lookup.m_ModelName == key.str() && m_Filter.PassFilter(lookup.m_ModelName.c_str()) + && (m_Selected == "Custom" || m_Selected == "All")) + { + lookup.m_bCustom = true; + m_nSearchList.push_back(std::move(lookup)); + } + } + } } } } else { - for (auto [cat, table] : m_pData->Items()) + if (m_Type == eResourceType::TYPE_TEXT) { - // Don't show favourites in "All" - if (m_Selected == "All" && cat == "Favourites") + for (auto [cat, table] : m_pData->Items()) { - continue; - } - if (cat.str() == m_Selected || m_Selected == "All") - { - if (!table.as_table()) + // Don't show favourites in "All" + if (m_Selected == "All" && cat == "Favourites") { - return; + continue; } - for (auto [key, val] : *table.as_table()->as_table()) + if (cat.str() == m_Selected || m_Selected == "All") { - std::string label = std::string(key.str()); - if (m_Filter.PassFilter(label.c_str())) + if (!table.as_table()) { - std::string data = val.value_or("Unkonwn"); - m_nSearchList.push_back({std::move(std::string(cat.str())), std::move(label), std::move(data)}); + return; + } + for (auto [key, val] : *table.as_table()->as_table()) + { + ListLookup lookup; + lookup.key = std::string(key.str()); + if (m_Filter.PassFilter(lookup.key.c_str())) + { + lookup.cat = "Favourites"; + lookup.val = val.value_or("Unkonwn"); + m_nSearchList.push_back(std::move(lookup)); + } + } + } + } + } + else + { + for (uint i = 0; i < m_ImagesList.size(); ++i) + { + ImageLookup lookup; + lookup.m_FileName = m_ImagesList[i]->m_FileName; + lookup.m_ModelName = getNameFunc == nullptr ? "" : getNameFunc(lookup.m_FileName); + + if (m_Filter.PassFilter(lookup.m_ModelName.c_str()) + && (m_ImagesList[i]->m_CategoryName == m_Selected || m_Selected == "All") + && (verifyFunc == nullptr || verifyFunc(lookup.m_FileName)) + ) + { + lookup.m_bCustom = false; + lookup.m_pTexture = m_ImagesList[i]->m_pTexture; + m_nSearchList.push_back(std::move(lookup)); + } + } + + if (m_Type == eResourceType::TYPE_IMAGE_TEXT) + { + for (auto [k, v] : *m_pData->GetTable("Custom")) + { + ImageLookup lookup; + lookup.m_FileName = v.as_string()->value_or("0"); + lookup.m_ModelName = std::string(k.str()); + if (m_Filter.PassFilter(lookup.m_ModelName.c_str()) + && (m_Selected == "Custom" || m_Selected == "All")) + { + lookup.m_bCustom = true; + m_nSearchList.push_back(std::move(lookup)); } } } diff --git a/src/utils/resourcestore.h b/src/utils/resourcestore.h index 967122a..2a8aeb3 100644 --- a/src/utils/resourcestore.h +++ b/src/utils/resourcestore.h @@ -2,6 +2,7 @@ #include #include #include +#include #include "imgui/imgui.h" #include "utils/datastore.h" @@ -45,6 +46,21 @@ enum eResourceType TYPE_TEXT_IMAGE, // priotizes texts }; +// Lookup table used for DataList +struct ListLookup +{ + std::string cat, key, val; +}; + +// Lookup table used for ImageList +struct ImageLookup +{ + std::string m_FileName; + std::string m_ModelName; + void *m_pTexture; + bool m_bCustom; +}; + /* Global Resource Handler Class Handles loading & unloading both text (json) & image files @@ -52,11 +68,6 @@ enum eResourceType class ResourceStore { private: - struct SearchLookup - { - std::string cat, key, val; - }; - // Loads a image texture from it's path void LoadTextureResource(std::string&& path); @@ -66,7 +77,8 @@ public: std::string m_Selected = "All"; std::string m_FileName; std::unique_ptr m_pData; - std::vector m_nSearchList; + std::vector> m_nSearchList; + bool m_bSearchListUpdateRequired = false; eResourceType m_Type; ImVec2 m_ImageSize; std::vector> m_ImagesList; @@ -75,5 +87,5 @@ public: RwTexture* FindRwTextureByName(const std::string& name); IDirect3DTexture9** FindTextureByName(const std::string& name); - void UpdateSearchList(bool favourites = false); + void UpdateSearchList(bool favourites = false, std::function getNameFunc = nullptr, std::function verifyFunc = nullptr); }; \ No newline at end of file diff --git a/src/utils/widget.cpp b/src/utils/widget.cpp index 0fe1dfa..b94e65b 100644 --- a/src/utils/widget.cpp +++ b/src/utils/widget.cpp @@ -75,7 +75,7 @@ bool Widget::Filter(const char* label, ImGuiTextFilter& filter, const char* hint return state; } -void Widget::DrawClippedList(ResourceStore& data, fArg3_t clickFunc, bool favourites, bool isEditItem) +void DrawClippedList(ResourceStore& data, fArg3_t clickFunc, bool favourites, bool isEditItem) { // Category box ImGui::PushItemWidth(favourites ? ImGui::GetWindowContentRegionWidth() : @@ -83,30 +83,33 @@ void Widget::DrawClippedList(ResourceStore& data, fArg3_t clickFunc, bool favour if (!favourites) { - if (ListBox("##Categories", data.m_Categories, data.m_Selected)) + if (Widget::ListBox("##Categories", data.m_Categories, data.m_Selected)) { data.UpdateSearchList(favourites); } ImGui::SameLine(); } - if (Filter("##Filter", data.m_Filter, TEXT("Window.Search"))) + if (Widget::Filter("##Filter", data.m_Filter, TEXT("Window.Search"))) { data.UpdateSearchList(favourites); } ImGui::PopItemWidth(); ImGui::Spacing(); - ImGui::BeginChild(1); - + if (favourites && data.m_pData->GetTable("Favourites")->size() == 0) + { + Widget::TextCentered(TEXT("Menu.FavouritesNone")); + } + ImGui::BeginChild("CliipingLIst"); ImGuiListClipper clipper(data.m_nSearchList.size(), ImGui::GetTextLineHeight()); while (clipper.Step()) { for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i) { - std::string &label = data.m_nSearchList[i].key; - std::string &cat = data.m_nSearchList[i].cat; - std::string &val = data.m_nSearchList[i].val; + std::string &label = std::get(data.m_nSearchList[i]).key; + std::string &cat = std::get(data.m_nSearchList[i]).cat; + std::string &val = std::get(data.m_nSearchList[i]).val; if (isEditItem) { #ifdef GTASA @@ -127,6 +130,52 @@ void Widget::DrawClippedList(ResourceStore& data, fArg3_t clickFunc, bool favour } } } + + if (contextMenu.show) + { + if (ImGui::BeginPopupContextWindow()) + { + ImGui::Text(contextMenu.key.c_str()); + ImGui::Separator(); + + if (!favourites && ImGui::MenuItem(TEXT("Menu.Favourites"))) + { + data.m_pData->Set(std::format("Favourites.{}", contextMenu.key).c_str(), contextMenu.val); + data.m_pData->Save(); + Util::SetMessage(TEXT("Menu.FavouritesText")); + } + if (!favourites && ImGui::MenuItem(TEXT("Menu.Remove"))) + { + if (contextMenu.root == "Custom") + { + data.m_pData->RemoveKey("Custom", contextMenu.key.c_str()); + data.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); + data.m_pData->Save(); + data.UpdateSearchList(); + Util::SetMessage(TEXT("Window.RemoveEntry")); + } + else + { + Util::SetMessage(TEXT("Window.CustomRemoveOnly")); + } + } + + if (favourites &&ImGui::MenuItem(TEXT("Menu.FavouritesRemove"))) + { + data.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); + data.m_pData->Save(); + data.UpdateSearchList(true); + Util::SetMessage(TEXT("Menu.FavouritesRemoveText")); + } + + if (ImGui::MenuItem(TEXT("Menu.Close"))) + { + contextMenu.show = false; + } + ImGui::EndPopup(); + } + } + ImGui::EndChild(); } void Widget::DataList(ResourceStore& data, fArg3_t clickFunc, fArgNone_t addFunc, bool isEditItem) @@ -143,42 +192,6 @@ void Widget::DataList(ResourceStore& data, fArg3_t clickFunc, fArgNone_t addFunc { ImGui::Spacing(); DrawClippedList(data, clickFunc, false, isEditItem); - if (contextMenu.show) - { - if (ImGui::BeginPopupContextWindow()) - { - ImGui::Text(contextMenu.key.c_str()); - ImGui::Separator(); - if (ImGui::MenuItem(TEXT("Menu.Favourites"))) - { - data.m_pData->Set(std::format("Favourites.{}", contextMenu.key).c_str(), contextMenu.val); - data.m_pData->Save(); - Util::SetMessage(TEXT("Menu.FavouritesText")); - } - if (ImGui::MenuItem(TEXT("Menu.Remove"))) - { - if (contextMenu.root == "Custom") - { - data.m_pData->RemoveKey("Custom", contextMenu.key.c_str()); - data.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); - data.m_pData->Save(); - data.UpdateSearchList(); - Util::SetMessage(TEXT("Window.RemoveEntry")); - } - else - { - Util::SetMessage(TEXT("Window.CustomRemoveOnly")); - } - } - if (ImGui::MenuItem(TEXT("Menu.Close"))) - { - contextMenu.show = false; - } - - ImGui::EndPopup(); - } - } - ImGui::EndChild(); ImGui::EndTabItem(); } if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) @@ -189,32 +202,6 @@ void Widget::DataList(ResourceStore& data, fArg3_t clickFunc, fArgNone_t addFunc { ImGui::Spacing(); DrawClippedList(data, clickFunc, true, isEditItem); - if (data.m_pData->GetTable("Favourites")->size() == 0) - { - Widget::TextCentered(TEXT("Menu.FavouritesNone")); - } - if (contextMenu.show) - { - if (ImGui::BeginPopupContextWindow()) - { - ImGui::Text(contextMenu.key.c_str()); - ImGui::Separator(); - if (ImGui::MenuItem(TEXT("Menu.FavouritesRemove"))) - { - data.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); - data.m_pData->Save(); - data.UpdateSearchList(true); - Util::SetMessage(TEXT("Menu.FavouritesRemoveText")); - } - if (ImGui::MenuItem(TEXT("Menu.Close"))) - { - contextMenu.show = false; - } - - ImGui::EndPopup(); - } - } - ImGui::EndChild(); ImGui::EndTabItem(); } if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) @@ -285,6 +272,109 @@ static bool RoundedImageButton(ImTextureID textureID, ImVec2& size, const char* return ImGui::IsItemClicked(0); } +void DrawClippedImages(ResourceStore& data, ImVec2 imgSz, size_t imagesInRow, bool showImages, + bool favourites, fArg1_t clickFunc, fRtnArg1_t getNameFunc, fRtnBoolArg1_t verifyFunc) +{ + static IDirect3DTexture9 **pDefaultTex = gTextureList.FindTextureByName("placeholder"); + ImGuiStyle &style = ImGui::GetStyle(); + + // Category box + ImGui::PushItemWidth(favourites ? ImGui::GetWindowContentRegionWidth() : + (ImGui::GetWindowContentRegionWidth() - ImGui::GetStyle().ItemSpacing.x)/2); + if (!favourites) + { + if (Widget::ListBox("##Categories", data.m_Categories, data.m_Selected)) + { + data.UpdateSearchList(favourites); + } + ImGui::SameLine(); + } + if (Widget::Filter("##Filter", data.m_Filter, TEXT("Window.Search"))) + { + data.UpdateSearchList(favourites); + } + ImGui::PopItemWidth(); + + ImGui::Spacing(); + ImGui::BeginChild("CliipingImag"); + if (favourites && data.m_pData->GetTable("Favourites")->size() == 0) + { + Widget::TextCentered(TEXT("Menu.FavouritesNone")); + } + + float itemSz = imgSz.y/(imagesInRow+1); + int imageCount = 1; + ImGuiListClipper clipper(data.m_nSearchList.size(), itemSz); + while (clipper.Step()) + { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i) + { + std::string &text = std::get(data.m_nSearchList[i]).m_FileName; + std::string &modelName = std::get(data.m_nSearchList[i]).m_ModelName; + bool custom = std::get(data.m_nSearchList[i]).m_bCustom; + void *pTexture = custom ? pDefaultTex : std::get(data.m_nSearchList[i]).m_pTexture; + if (showImages ? RoundedImageButton(pTexture, imgSz, modelName.c_str(), custom) + : ImGui::MenuItem(modelName.c_str()) + ) + { + clickFunc(text); + } + + // Right click popup + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) + { + contextMenu.show = true; + contextMenu.added = custom; + contextMenu.val = std::string(text); + contextMenu.key = std::string(modelName); + } + + if (showImages) + { + if (imageCount % imagesInRow != 0) + { + ImGui::SameLine(0.0, style.ItemInnerSpacing.x); + } + } + imageCount++; + } + } + if (contextMenu.show) + { + if (ImGui::BeginPopupContextWindow()) + { + ImGui::Text(contextMenu.key.c_str()); + ImGui::Separator(); + if (!favourites && ImGui::MenuItem(TEXT("Menu.Favourites"))) + { + data.m_pData->Set(std::format("Favourites.{}", contextMenu.key).c_str(), contextMenu.val); + data.m_pData->Save(); + Util::SetMessage(TEXT("Menu.FavouritesText")); + } + if (!favourites && contextMenu.added && ImGui::MenuItem(TEXT("Menu.Remove"))) + { + data.m_pData->RemoveKey("Custom", contextMenu.key.c_str()); + data.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); + data.m_pData->Save(); + data.UpdateSearchList(false, getNameFunc, verifyFunc); + } + if (favourites && ImGui::MenuItem(TEXT("Menu.FavouritesRemove"))) + { + data.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); + data.m_pData->Save(); + data.UpdateSearchList(true, getNameFunc, verifyFunc); + Util::SetMessage(TEXT("Menu.FavouritesRemoveText")); + } + if (ImGui::MenuItem(TEXT("Menu.Close"))) + { + contextMenu.show = false; + } + + ImGui::EndPopup(); + } + } + ImGui::EndChild(); +} /* Here we go again... This direly needs a refactor oof @@ -292,7 +382,6 @@ static bool RoundedImageButton(ImTextureID textureID, ImVec2& size, const char* void Widget::ImageList(ResourceStore &store, fArg1_t clickFunc, fRtnArg1_t getNameFunc, fRtnBoolArg1_t verifyFunc, fArgNone_t addFunc) { - static IDirect3DTexture9 **pDefaultTex = nullptr; ImGuiStyle& style = ImGui::GetStyle(); /* Trying to scale images based on resolutions @@ -302,7 +391,6 @@ void Widget::ImageList(ResourceStore &store, fArg1_t clickFunc, fRtnArg1_t getNa m_ImageSize.x *= screen::GetScreenWidth() / 1366.0f; m_ImageSize.y *= screen::GetScreenHeight() / 768.0f; - int imageCount = 1; int imagesInRow = static_cast(ImGui::GetWindowContentRegionWidth() / m_ImageSize.x); m_ImageSize.x = ImGui::GetWindowContentRegionWidth() - style.ItemSpacing.x * (imagesInRow-1); m_ImageSize.x /= imagesInRow; @@ -316,7 +404,7 @@ void Widget::ImageList(ResourceStore &store, fArg1_t clickFunc, fRtnArg1_t getNa ImGui::Spacing(); // Hide the popup if right clicked again - if (ImGui::IsMouseClicked(1)) + if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { contextMenu.show = false; } @@ -329,232 +417,35 @@ void Widget::ImageList(ResourceStore &store, fArg1_t clickFunc, fRtnArg1_t getNa ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, 10.0f); } + if (store.m_bSearchListUpdateRequired) + { + store.UpdateSearchList(false, getNameFunc, verifyFunc); + store.m_bSearchListUpdateRequired = false; + } + // Draw images here if (ImGui::BeginTabBar("MYTABS")) { if (ImGui::BeginTabItem(TEXT("Window.Search"))) { ImGui::Spacing(); - ImGui::PushItemWidth((ImGui::GetWindowContentRegionWidth() - style.ItemSpacing.x)/2); - Widget::ListBox("##Categories", store.m_Categories, store.m_Selected); - ImGui::SameLine(); - Filter("##Filter", store.m_Filter, "Search"); - ImGui::PopItemWidth(); - ImGui::Spacing(); - ImGui::BeginChild("DrawImages"); - - for (uint i = 0; i < store.m_ImagesList.size(); ++i) - { - std::string text = store.m_ImagesList[i]->m_FileName; - std::string modelName = getNameFunc(text); - - if (store.m_Filter.PassFilter(modelName.c_str()) - && (store.m_ImagesList[i]->m_CategoryName == store.m_Selected || store.m_Selected == "All") - && (verifyFunc == nullptr || verifyFunc(text)) - ) - { - if (showImages ? RoundedImageButton(store.m_ImagesList[i]->m_pTexture, m_ImageSize, modelName.c_str()) - : ImGui::MenuItem(modelName.c_str()) - ) - { - clickFunc(text); - } - - // Right click popup - if (ImGui::IsItemClicked(1)) - { - contextMenu.show = true; - contextMenu.added = false; - contextMenu.val = text; - contextMenu.key = modelName; - } - - if (showImages) - { - if (imageCount % imagesInRow != 0) - { - ImGui::SameLine(0.0, style.ItemInnerSpacing.x); - } - } - imageCount++; - } - } - for (auto [k, v] : *store.m_pData->GetTable("Custom")) - { - if (!pDefaultTex) - { - pDefaultTex = gTextureList.FindTextureByName("placeholder"); - } - std::string modelName = std::string(k.str()); - std::string text = v.as_string()->value_or("0"); - if (store.m_Filter.PassFilter(modelName.c_str()) - && (store.m_Selected == "Custom" || store.m_Selected == "All")) - { - if (showImages ? RoundedImageButton(pDefaultTex, m_ImageSize, modelName.c_str(), true) - : ImGui::MenuItem(modelName.c_str()) - ) - { - clickFunc(text); - } - - // Right click popup - if (ImGui::IsItemClicked(1)) - { - contextMenu.show = true; - contextMenu.added = (addFunc != nullptr); - contextMenu.val = text; - contextMenu.key = modelName; - } - - if (showImages) - { - if (imageCount % imagesInRow != 0) - { - ImGui::SameLine(0.0, style.ItemInnerSpacing.x); - } - } - imageCount++; - } - } - if (contextMenu.show) - { - if (ImGui::BeginPopupContextWindow()) - { - ImGui::Text(contextMenu.key.c_str()); - ImGui::Separator(); - if (ImGui::MenuItem(TEXT("Menu.Favourites"))) - { - store.m_pData->Set(std::format("Favourites.{}", contextMenu.key).c_str(), contextMenu.val); - store.m_pData->Save(); - Util::SetMessage(TEXT("Menu.FavouritesText")); - } - if (contextMenu.added && ImGui::MenuItem(TEXT("Menu.Remove"))) - { - store.m_pData->RemoveKey("Custom", contextMenu.key.c_str()); - store.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); - store.m_pData->Save(); - } - if (ImGui::MenuItem(TEXT("Menu.Close"))) - { - contextMenu.show = false; - } - - ImGui::EndPopup(); - } - } - ImGui::EndChild(); + DrawClippedImages(store, m_ImageSize, imagesInRow, showImages, false, clickFunc, getNameFunc, verifyFunc); ImGui::EndTabItem(); } + if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) + { + store.UpdateSearchList(false, getNameFunc, verifyFunc); + } if (ImGui::BeginTabItem(TEXT("Window.FavouritesTab"))) { ImGui::Spacing(); - ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth()); - Filter("##Filter", store.m_Filter, TEXT("Window.Search")); - ImGui::PopItemWidth(); - ImGui::Spacing(); - ImGui::BeginChild("DrawFavourites"); - - for (auto [k, v] : *store.m_pData->GetTable("Favourites")) - { - auto str = k.str(); - bool state = str.find("Added") != std::string::npos; - if (state) - { - std::string modelName = std::string(k.str()); - std::string text = v.as_string()->value_or("0"); - if (store.m_Filter.PassFilter(modelName.c_str())) - { - if (showImages ? RoundedImageButton(pDefaultTex, m_ImageSize, modelName.c_str(), true) - : ImGui::MenuItem(modelName.c_str()) - ) - { - clickFunc(text); - } - - // Right click popup - if (ImGui::IsItemClicked(1)) - { - contextMenu.show = true; - contextMenu.added = false; - contextMenu.val = text; - contextMenu.key = modelName; - } - - if (showImages) - { - if (imageCount % imagesInRow != 0) - { - ImGui::SameLine(0.0, style.ItemInnerSpacing.x); - } - } - imageCount++; - } - } - else - { - for (uint i = 0; i < store.m_ImagesList.size(); ++i) - { - std::string text = store.m_ImagesList[i]->m_FileName; - std::string modelName = getNameFunc(text); - - if (modelName == k.str() && store.m_Filter.PassFilter(modelName.c_str()) && (verifyFunc == nullptr || verifyFunc(text))) - { - if (showImages ? RoundedImageButton(store.m_ImagesList[i]->m_pTexture, m_ImageSize, modelName.c_str()) - : ImGui::MenuItem(modelName.c_str()) - ) - { - clickFunc(text); - } - - // Right click popup - if (ImGui::IsItemClicked(1)) - { - contextMenu.show = true; - contextMenu.added = false; - contextMenu.val = text; - contextMenu.key = modelName; - } - - if (showImages) - { - if (imageCount % imagesInRow != 0) - { - ImGui::SameLine(0.0, style.ItemInnerSpacing.x); - } - } - imageCount++; - } - } - } - } - if (store.m_pData->GetTable("Favourites")->size() == 0) - { - Widget::TextCentered(TEXT("Menu.FavouritesNone")); - } - if (contextMenu.show) - { - if (ImGui::BeginPopupContextWindow()) - { - ImGui::Text(contextMenu.key.c_str()); - ImGui::Separator(); - if (ImGui::MenuItem(TEXT("Menu.FavouritesRemove"))) - { - store.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); - store.m_pData->Save(); - Util::SetMessage(TEXT("Menu.FavouritesRemoveText")); - } - if (ImGui::MenuItem(TEXT("Menu.Close"))) - { - contextMenu.show = false; - contextMenu.added = false; - } - - ImGui::EndPopup(); - } - } - ImGui::EndChild(); + DrawClippedImages(store, m_ImageSize, imagesInRow, showImages, true, clickFunc, getNameFunc, verifyFunc); ImGui::EndTabItem(); } + if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) + { + store.UpdateSearchList(true, getNameFunc, verifyFunc); + } if (addFunc) { if (ImGui::BeginTabItem(TEXT("Window.AddNew"))) diff --git a/src/utils/widget.h b/src/utils/widget.h index 6ceaa13..728a587 100644 --- a/src/utils/widget.h +++ b/src/utils/widget.h @@ -43,9 +43,6 @@ public: // Draws DataStore data in the interface static void DataList(ResourceStore& data, fArg3_t clickFunc = nullptr, fArgNone_t addFunc = nullptr, bool isEditItem = false); - // Draws listed data, used in DataList - static void DrawClippedList(ResourceStore& data, fArg3_t clickFunc = nullptr, bool favourites = false, bool isEditItem = false); - // Draws a dropdown editor for memory address template static void EditAddr(const char* label, uint address, int min = 0, int def = 0, int max = 100);