Show favourite images for image tabs

This commit is contained in:
Grinch_ 2022-07-07 08:28:09 +06:00
parent 7057088c1f
commit a9ca03253c
3 changed files with 71 additions and 40 deletions

View File

@ -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.

View File

@ -103,8 +103,8 @@ 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;
if (pos.x > left && pos.x < right)
{
pos.x -= left;
pos.x -= size/2;
pos.y -= size/2;
@ -124,6 +124,7 @@ void Teleport::Init()
target.m_nRadarSprite = sprite;
}
}
}
};
#endif
}

View File

@ -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 = std::string(k.str());
for (uint i = 0; i < store.m_ImagesList.size(); ++i)
{
std::string val = v.value_or<std::string>("Unkonwn");
if (ImGui::MenuItem(key.c_str()) && clickFunc != nullptr)
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)))
{
clickFunc(val);
/*
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 = {std::string("Favourites"), key, val, nullptr, true};
contextMenu.show = true;
contextMenu.val = text;
contextMenu.key = modelName;
}
if (showImages)
{
if (imageCount % imagesInRow != 0)
{
ImGui::SameLine(0.0, style.ItemInnerSpacing.x);
}
}
++count;
imageCount++;
}
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"));
}