From a9ca03253cd76562529303b658a934ce32db9d2a Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Thu, 7 Jul 2022 08:28:09 +0600 Subject: [PATCH] Show favourite images for image tabs --- resource/common/locale/English.toml | 4 +- src/teleport.cpp | 39 +++++++++-------- src/widget.cpp | 68 +++++++++++++++++++++-------- 3 files changed, 71 insertions(+), 40 deletions(-) diff --git a/resource/common/locale/English.toml b/resource/common/locale/English.toml index c834d59..0027dad 100644 --- a/resource/common/locale/English.toml +++ b/resource/common/locale/English.toml @@ -400,7 +400,7 @@ InvalidLocation = "Invalid location" Location = "Location" LocationHint = "Groove Street" LocationRemoved = "Location removed" -QuickTeleport = "Quick Teleport" +QuickTeleport = "Quick teleport" QuickTeleportHint = "Open quick teleport using " TeleportMarkerHint = """ Teleport to the location of your radar @@ -573,7 +573,7 @@ TotalSeats = "Total seats: %d" TractionBias = "Traction bias" TractionLoss = "Traction loss" TractionMul = "Traction multiplier" -TrafficColor = "TrafficColor" +TrafficColor = "Traffic color" TrafficNeon = "Traffic neons" TrafficNeonMSG = """ Adds neon lights to traffic vehicles. diff --git a/src/teleport.cpp b/src/teleport.cpp index 47a5419..7d11fa3 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -103,25 +103,26 @@ void Teleport::Init() { // Convert screen space to image space ImVec2 pos = ImGui::GetMousePos(); - pos.x = (pos.x < left) ? left : pos.x; - pos.x = (pos.x > right) ? right : pos.x; - pos.x -= left; - pos.x -= size/2; - pos.y -= size/2; - - // Convert image space to map space - pos.x = pos.x / size * 6000; - pos.y = pos.y / size * 6000; - pos.y *= -1; - - tRadarTrace &target = CRadar::ms_RadarTrace[FrontEndMenuManager.m_nTargetBlipIndex]; - CVector temp = target.m_vecPos; - unsigned char sprite = target.m_nRadarSprite; - target.m_nRadarSprite = RADAR_SPRITE_WAYPOINT; - target.m_vecPos = {pos.x, pos.y, 0.0f}; - TeleportPlayer(true); - target.m_vecPos = temp; - target.m_nRadarSprite = sprite; + if (pos.x > left && pos.x < right) + { + pos.x -= left; + pos.x -= size/2; + pos.y -= size/2; + + // Convert image space to map space + pos.x = pos.x / size * 6000; + pos.y = pos.y / size * 6000; + pos.y *= -1; + + tRadarTrace &target = CRadar::ms_RadarTrace[FrontEndMenuManager.m_nTargetBlipIndex]; + CVector temp = target.m_vecPos; + unsigned char sprite = target.m_nRadarSprite; + target.m_nRadarSprite = RADAR_SPRITE_WAYPOINT; + target.m_vecPos = {pos.x, pos.y, 0.0f}; + TeleportPlayer(true); + target.m_vecPos = temp; + target.m_nRadarSprite = sprite; + } } } }; diff --git a/src/widget.cpp b/src/widget.cpp index 0385447..f536ffe 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -162,7 +162,6 @@ void Widget::DataList(ResourceStore& data, ArgCallback3 clickFunc, ArgCallback3 ImGui::PopItemWidth(); ImGui::Spacing(); ImGui::BeginChild(1); - size_t count = 0; for (auto [k, v] : *data.m_pData->GetTable("Favourites")) { std::string key = std::string(k.str()); @@ -180,9 +179,8 @@ void Widget::DataList(ResourceStore& data, ArgCallback3 clickFunc, ArgCallback3 contextMenu = {std::string("Favourites"), key, val, removeFunc, true}; } } - ++count; } - if (count == 0) + if (data.m_pData->GetTable("Favourites")->size() == 0) { Widget::TextCentered(TEXT("Menu.FavouritesNone")); } @@ -343,7 +341,7 @@ void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackR { contextMenu.show = true; contextMenu.val = text; - contextMenu.key = std::format("{} ({})", modelName, text); + contextMenu.key = modelName; } if (showImages) @@ -364,7 +362,7 @@ void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackR ImGui::Separator(); if (ImGui::MenuItem(TEXT("Menu.Favourites"))) { - store.m_pData->Set(std::format("Favourites.{}", contextMenu.key).c_str(), contextMenu.val); + store.m_pData->Set(std::format("Favourites.{}", contextMenu.val).c_str(), contextMenu.key); store.m_pData->Save(); SetHelpMessage(TEXT("Menu.FavouritesText")); } @@ -387,26 +385,58 @@ void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackR ImGui::PopItemWidth(); ImGui::Spacing(); ImGui::BeginChild("DrawFavourites"); - size_t count = 0; + for (auto [k, v] : *store.m_pData->GetTable("Favourites")) { - std::string key = std::string(k.str()); - if (store.m_Filter.PassFilter(key.c_str())) - { - std::string val = v.value_or("Unkonwn"); - if (ImGui::MenuItem(key.c_str()) && clickFunc != nullptr) - { - clickFunc(val); - } + std::string val = std::string(k.str()); - if (ImGui::IsItemClicked(1)) + 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 (text == val && store.m_Filter.PassFilter(modelName.c_str()) && (verifyFunc == nullptr || verifyFunc(text))) { - contextMenu = {std::string("Favourites"), key, val, nullptr, true}; + /* + Couldn't figure out how to laod images for Dx11 + Using texts for now + */ + if (showImages) + { + if (RoundedImageButton(store.m_ImagesList[i]->m_pTexture, m_ImageSize, modelName.c_str())) + { + clickFunc(text); + } + + } + else + { + if (ImGui::MenuItem(modelName.c_str())) + { + clickFunc(text); + } + } + + // Right click popup + if (ImGui::IsItemClicked(1)) + { + contextMenu.show = true; + contextMenu.val = text; + contextMenu.key = modelName; + } + + if (showImages) + { + if (imageCount % imagesInRow != 0) + { + ImGui::SameLine(0.0, style.ItemInnerSpacing.x); + } + } + imageCount++; } } - ++count; } - if (count == 0) + if (store.m_pData->GetTable("Favourites")->size() == 0) { Widget::TextCentered(TEXT("Menu.FavouritesNone")); } @@ -418,7 +448,7 @@ void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackR ImGui::Separator(); if (ImGui::MenuItem(TEXT("Menu.FavouritesRemove"))) { - store.m_pData->RemoveKey("Favourites", contextMenu.key.c_str()); + store.m_pData->RemoveKey("Favourites", contextMenu.val.c_str()); store.m_pData->Save(); SetHelpMessage(TEXT("Menu.FavouritesRemoveText")); }