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" Location = "Location"
LocationHint = "Groove Street" LocationHint = "Groove Street"
LocationRemoved = "Location removed" LocationRemoved = "Location removed"
QuickTeleport = "Quick Teleport" QuickTeleport = "Quick teleport"
QuickTeleportHint = "Open quick teleport using " QuickTeleportHint = "Open quick teleport using "
TeleportMarkerHint = """ TeleportMarkerHint = """
Teleport to the location of your radar Teleport to the location of your radar
@ -573,7 +573,7 @@ TotalSeats = "Total seats: %d"
TractionBias = "Traction bias" TractionBias = "Traction bias"
TractionLoss = "Traction loss" TractionLoss = "Traction loss"
TractionMul = "Traction multiplier" TractionMul = "Traction multiplier"
TrafficColor = "TrafficColor" TrafficColor = "Traffic color"
TrafficNeon = "Traffic neons" TrafficNeon = "Traffic neons"
TrafficNeonMSG = """ TrafficNeonMSG = """
Adds neon lights to traffic vehicles. Adds neon lights to traffic vehicles.

View File

@ -103,25 +103,26 @@ void Teleport::Init()
{ {
// Convert screen space to image space // Convert screen space to image space
ImVec2 pos = ImGui::GetMousePos(); ImVec2 pos = ImGui::GetMousePos();
pos.x = (pos.x < left) ? left : pos.x; if (pos.x > left && pos.x < right)
pos.x = (pos.x > right) ? right : pos.x; {
pos.x -= left; pos.x -= left;
pos.x -= size/2; pos.x -= size/2;
pos.y -= size/2; pos.y -= size/2;
// Convert image space to map space // Convert image space to map space
pos.x = pos.x / size * 6000; pos.x = pos.x / size * 6000;
pos.y = pos.y / size * 6000; pos.y = pos.y / size * 6000;
pos.y *= -1; pos.y *= -1;
tRadarTrace &target = CRadar::ms_RadarTrace[FrontEndMenuManager.m_nTargetBlipIndex]; tRadarTrace &target = CRadar::ms_RadarTrace[FrontEndMenuManager.m_nTargetBlipIndex];
CVector temp = target.m_vecPos; CVector temp = target.m_vecPos;
unsigned char sprite = target.m_nRadarSprite; unsigned char sprite = target.m_nRadarSprite;
target.m_nRadarSprite = RADAR_SPRITE_WAYPOINT; target.m_nRadarSprite = RADAR_SPRITE_WAYPOINT;
target.m_vecPos = {pos.x, pos.y, 0.0f}; target.m_vecPos = {pos.x, pos.y, 0.0f};
TeleportPlayer(true); TeleportPlayer(true);
target.m_vecPos = temp; target.m_vecPos = temp;
target.m_nRadarSprite = sprite; target.m_nRadarSprite = sprite;
}
} }
} }
}; };

View File

@ -162,7 +162,6 @@ void Widget::DataList(ResourceStore& data, ArgCallback3 clickFunc, ArgCallback3
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::Spacing(); ImGui::Spacing();
ImGui::BeginChild(1); ImGui::BeginChild(1);
size_t count = 0;
for (auto [k, v] : *data.m_pData->GetTable("Favourites")) for (auto [k, v] : *data.m_pData->GetTable("Favourites"))
{ {
std::string key = std::string(k.str()); 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}; 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")); Widget::TextCentered(TEXT("Menu.FavouritesNone"));
} }
@ -343,7 +341,7 @@ void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackR
{ {
contextMenu.show = true; contextMenu.show = true;
contextMenu.val = text; contextMenu.val = text;
contextMenu.key = std::format("{} ({})", modelName, text); contextMenu.key = modelName;
} }
if (showImages) if (showImages)
@ -364,7 +362,7 @@ void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackR
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem(TEXT("Menu.Favourites"))) 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(); store.m_pData->Save();
SetHelpMessage(TEXT("Menu.FavouritesText")); SetHelpMessage(TEXT("Menu.FavouritesText"));
} }
@ -387,26 +385,58 @@ void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackR
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::Spacing(); ImGui::Spacing();
ImGui::BeginChild("DrawFavourites"); ImGui::BeginChild("DrawFavourites");
size_t count = 0;
for (auto [k, v] : *store.m_pData->GetTable("Favourites")) for (auto [k, v] : *store.m_pData->GetTable("Favourites"))
{ {
std::string key = std::string(k.str()); std::string val = std::string(k.str());
if (store.m_Filter.PassFilter(key.c_str()))
{
std::string val = v.value_or<std::string>("Unkonwn");
if (ImGui::MenuItem(key.c_str()) && clickFunc != nullptr)
{
clickFunc(val);
}
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")); Widget::TextCentered(TEXT("Menu.FavouritesNone"));
} }
@ -418,7 +448,7 @@ void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackR
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem(TEXT("Menu.FavouritesRemove"))) 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(); store.m_pData->Save();
SetHelpMessage(TEXT("Menu.FavouritesRemoveText")); SetHelpMessage(TEXT("Menu.FavouritesRemoveText"));
} }