Add favourites section for image spawner

This commit is contained in:
Grinch_ 2022-07-03 00:14:40 +06:00
parent 3d10fda889
commit 1a15581dff
9 changed files with 164 additions and 95 deletions

View File

@ -70,19 +70,29 @@ void MenuThread(void* param)
} }
#endif #endif
Log::Print<eLogLevel::None>("Stating " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n"); Log::Print<eLogLevel::None>("Starting " MENU_TITLE " (" BUILD_NUMBER ")\nAuthor: Grinch_\nDiscord: "
DISCORD_INVITE "\nMore Info: " GITHUB_LINK);
// date time
SYSTEMTIME st;
GetSystemTime(&st);
Log::Print<eLogLevel::None>("Date: {}-{}-{} Time: {}:{}\n", st.wYear, st.wMonth, st.wDay,
st.wHour, st.wMinute);
CheatMenu::Init(); CheatMenu::Init();
// Checking for updates once a day // Checking for updates once a day
SYSTEMTIME st;
GetSystemTime(&st);
if (gConfig.Get("Menu.LastUpdateChecked", 0) != st.wDay) if (gConfig.Get("Menu.LastUpdateChecked", 0) != st.wDay)
{ {
Updater::CheckUpdate(); Updater::CheckUpdate();
Updater::IncrementDailyUsageCounter(); Updater::IncrementDailyUsageCounter();
gConfig.Set("Menu.LastUpdateChecked", st.wDay); gConfig.Set("Menu.LastUpdateChecked", st.wDay);
} }
if (Updater::IsUpdateAvailable())
{
Updater::GetUpdateVersion();
Log::Print<eLogLevel::Info>("New update available: %s", Updater::GetUpdateVersion().c_str());
}
while (true) while (true)
{ {

View File

@ -471,7 +471,7 @@ void Game::ShowPage()
#ifdef GTASA #ifdef GTASA
if (Widget::Checkbox(TEXT("Game.ForbiddenWantedLevel"), &m_bForbiddenArea, TEXT("Game.ForbiddenWantedLevelText"))) if (Widget::Checkbox(TEXT("Game.ForbiddenWantedLevel"), &m_bForbiddenArea, TEXT("Game.ForbiddenWantedLevelText")))
{ {
patch::Set<BYTE>(0x441770, m_bForbiddenArea ? 0x83 : 0xC3, false); patch::Set<BYTE>(0x441770, m_bForbiddenArea ? 0x83 : 0xC3);
} }
Widget::CheckboxAddr(TEXT("Game.FreePNS"), 0x96C009); Widget::CheckboxAddr(TEXT("Game.FreePNS"), 0x96C009);
#endif #endif

View File

@ -305,7 +305,7 @@ void Ped::ShowPage()
{ {
ImGui::Spacing(); ImGui::Spacing();
#ifdef GTASA #ifdef GTASA
Widget::ImageList(m_PedData, SpawnPed, nullptr, Widget::ImageList(m_PedData, SpawnPed,
[](std::string& str) [](std::string& str)
{ {
return m_PedData.m_pData->Get(str.c_str(), "Unknown"); return m_PedData.m_pData->Get(str.c_str(), "Unknown");
@ -356,7 +356,6 @@ void Ped::ShowPage()
Spawner::m_nWeaponId = std::stoi(str); Spawner::m_nWeaponId = std::stoi(str);
weaponName = Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); weaponName = Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown");
}, },
nullptr,
[](std::string& str) [](std::string& str)
{ {
return Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); return Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown");

View File

@ -778,7 +778,7 @@ void Player::ShowPage()
{ {
if (pPlayer->m_nModelIndex == 0) if (pPlayer->m_nModelIndex == 0)
{ {
Widget::ImageList(m_ClothData, ChangePlayerCloth, nullptr, [](std::string& str) Widget::ImageList(m_ClothData, ChangePlayerCloth, [](std::string& str)
{ {
std::stringstream ss(str); std::stringstream ss(str);
std::string temp; std::string temp;
@ -787,7 +787,7 @@ void Player::ShowPage()
getline(ss, temp, '$'); getline(ss, temp, '$');
return temp; return temp;
});// nullptr, clothNameList, sizeof(clothNameList) / sizeof(const char*)); });
} }
else else
{ {
@ -841,7 +841,7 @@ void Player::ShowPage()
} }
if (ImGui::BeginTabItem(TEXT("Player.PedSkinsTab"))) if (ImGui::BeginTabItem(TEXT("Player.PedSkinsTab")))
{ {
Widget::ImageList(Ped::m_PedData, ChangePlayerModel, nullptr, Widget::ImageList(Ped::m_PedData, ChangePlayerModel,
[](std::string& str) [](std::string& str)
{ {
return Ped::m_PedData.m_pData->Get(str.c_str(), "Unknown"); return Ped::m_PedData.m_pData->Get(str.c_str(), "Unknown");

View File

@ -1061,8 +1061,8 @@ void Vehicle::ShowPage()
ImGui::SetNextItemWidth(width); ImGui::SetNextItemWidth(width);
ImGui::InputTextWithHint("##LicenseText", TEXT("Vehicle.PlateText"), Spawner::m_nLicenseText, 9); ImGui::InputTextWithHint("##LicenseText", TEXT("Vehicle.PlateText"), Spawner::m_nLicenseText, 9);
Widget::ImageList(Spawner::m_VehData, SpawnVehicle, nullptr, Widget::ImageList(Spawner::m_VehData, SpawnVehicle,
[](std::string& str) [](std::string& str)
{ {
return GetNameFromModel(std::stoi(str)); return GetNameFromModel(std::stoi(str));
}); });
@ -1274,7 +1274,6 @@ void Vehicle::ShowPage()
Paint::SetNodeTexture(FindPlayerPed()->m_pVehicle, PaintData::m_Selected, str, Paint::SetNodeTexture(FindPlayerPed()->m_pVehicle, PaintData::m_Selected, str,
PaintData::m_bMatFilter); PaintData::m_bMatFilter);
}, },
nullptr,
[](std::string& str) [](std::string& str)
{ {
return str; return str;
@ -1291,10 +1290,10 @@ void Vehicle::ShowPage()
{ {
AddComponent(str); AddComponent(str);
}, },
[](std::string& str) // [](std::string& str)
{ // {
RemoveComponent(str); // RemoveComponent(str);
}, // },
[](std::string& str) [](std::string& str)
{ {
return str; return str;

View File

@ -39,13 +39,13 @@ private:
static inline bool m_bApplyOnTraffic; static inline bool m_bApplyOnTraffic;
static inline uint m_bTrafficTimer; static inline uint m_bTrafficTimer;
}; };
static inline ResourceStore m_TuneData { "components", eResourceType::TYPE_IMAGE, ImVec2(100, 80) }; static inline ResourceStore m_TuneData { "components", eResourceType::TYPE_IMAGE_TEXT, ImVec2(100, 80) };
#endif #endif
struct Spawner struct Spawner
{ {
#ifdef GTASA #ifdef GTASA
static inline ResourceStore m_VehData { "vehicles", eResourceType::TYPE_IMAGE, ImVec2(100, 75)}; static inline ResourceStore m_VehData { "vehicles", eResourceType::TYPE_IMAGE_TEXT, ImVec2(100, 75)};
#else #else
static inline ResourceStore m_VehData {"vehicles", eResourceType::TYPE_TEXT}; static inline ResourceStore m_VehData {"vehicles", eResourceType::TYPE_TEXT};
#endif #endif

View File

@ -347,7 +347,7 @@ void Weapon::ShowPage()
m_nAmmoCount = (m_nAmmoCount > 99999) ? 99999 : m_nAmmoCount; m_nAmmoCount = (m_nAmmoCount > 99999) ? 99999 : m_nAmmoCount;
} }
#ifdef GTASA #ifdef GTASA
Widget::ImageList(m_WeaponData, GiveWeaponToPlayer, nullptr, Widget::ImageList(m_WeaponData, GiveWeaponToPlayer,
[](std::string& str) [](std::string& str)
{ {
return m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); return m_WeaponData.m_pData->Get(str.c_str(), "Unknown");
@ -370,16 +370,14 @@ void Weapon::ShowPage()
"Ballas\0Grove street families\0Los santos vagos\0San fierro rifa\0Da nang boys\0" "Ballas\0Grove street families\0Los santos vagos\0San fierro rifa\0Da nang boys\0"
"Mafia\0Mountain cloud triad\0Varrio los aztecas\0Gang9\0Gang10\0" "Mafia\0Mountain cloud triad\0Varrio los aztecas\0Gang9\0Gang10\0"
}; };
std::string str = std::format("{}\0{}\0{}\0", TEXT("Weapon.Weapon1"), TEXT("Weapon.Weapon2"),
TEXT("Weapon.Weapon3"));
ImGui::Combo(TEXT("Weapon.SelectGang"), &m_nSelectedGang, gangList); ImGui::Combo(TEXT("Weapon.SelectGang"), &m_nSelectedGang, gangList);
ImGui::Combo(TEXT("Ped.SelectWeapon"), &m_nSelectedWeapon, str.c_str()); ImGui::Combo(TEXT("Ped.SelectWeapon"), &m_nSelectedWeapon, "Weapon 1\0Weapon 2\0Weapon 3\0");
ImGui::Spacing(); ImGui::Spacing();
std::string key = std::to_string(m_nGangWeaponList[m_nSelectedGang][m_nSelectedWeapon]); std::string key = std::to_string(m_nGangWeaponList[m_nSelectedGang][m_nSelectedWeapon]);
ImGui::Text(TEXT("Weapon.CurrentWeapon"), m_WeaponData.m_pData->Get(key.c_str(), "Unknown").c_str()); ImGui::Text(TEXT("Weapon.CurrentWeapon"), m_WeaponData.m_pData->Get(key.c_str(), "Unknown").c_str());
ImGui::Spacing(); ImGui::Spacing();
Widget::ImageList(m_WeaponData, SetGangWeapon, nullptr, Widget::ImageList(m_WeaponData, SetGangWeapon,
[](std::string& str) [](std::string& str)
{ {
return m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); return m_WeaponData.m_pData->Get(str.c_str(), "Unknown");

View File

@ -249,8 +249,7 @@ static bool RoundedImageButton(ImTextureID user_texture_id, ImVec2& size, const
return ImGui::IsItemClicked(0); return ImGui::IsItemClicked(0);
} }
void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallback rightClickFunc, void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackRtn getNameFunc, ArgCallbackRtnBool verifyFunc)
ArgCallbackRtn getNameFunc, ArgCallbackRtnBool verifyFunc)
{ {
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
/* /*
@ -280,14 +279,6 @@ void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallb
contextMenu.func = nullptr; contextMenu.func = nullptr;
} }
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::Spacing();
ImGui::BeginChild("DrawImages");
if (showImages) if (showImages)
{ {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(3, 3)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(3, 3));
@ -297,80 +288,152 @@ void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallb
} }
// Draw images here // Draw images here
for (uint i = 0; i < store.m_ImagesList.size(); ++i) if (ImGui::BeginTabBar("MYTABS"))
{ {
std::string text = store.m_ImagesList[i]->m_FileName; if (ImGui::BeginTabItem(TEXT("Window.Search")))
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))
)
{ {
/* ImGui::Spacing();
Couldn't figure out how to laod images for Dx11 ImGui::PushItemWidth((ImGui::GetWindowContentRegionWidth() - style.ItemSpacing.x)/2);
Using texts for now Widget::ListBox("##Categories", store.m_Categories, store.m_Selected);
*/ ImGui::SameLine();
if (showImages) Filter("##Filter", store.m_Filter, "Search");
{ ImGui::PopItemWidth();
if (RoundedImageButton(store.m_ImagesList[i]->m_pTexture, m_ImageSize, modelName.c_str())) ImGui::Spacing();
{ ImGui::BeginChild("DrawImages");
leftClickFunc(text);
}
}
else
{
if (ImGui::MenuItem(modelName.c_str()))
{
leftClickFunc(text);
}
}
// Right click popup for (uint i = 0; i < store.m_ImagesList.size(); ++i)
if (ImGui::IsItemClicked(1) && rightClickFunc != nullptr)
{ {
contextMenu.func = rightClickFunc; std::string text = store.m_ImagesList[i]->m_FileName;
contextMenu.val = modelName; std::string modelName = getNameFunc(text);
}
if (showImages) if (store.m_Filter.PassFilter(modelName.c_str())
{ && (store.m_ImagesList[i]->m_CategoryName == store.m_Selected || store.m_Selected == "All")
if (imageCount % imagesInRow != 0) && (verifyFunc == nullptr || verifyFunc(text))
)
{ {
ImGui::SameLine(0.0, style.ItemInnerSpacing.x); /*
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.func = (void*)1;
contextMenu.val = text;
contextMenu.key = std::format("{} ({})", modelName, text);
}
if (showImages)
{
if (imageCount % imagesInRow != 0)
{
ImGui::SameLine(0.0, style.ItemInnerSpacing.x);
}
}
imageCount++;
} }
} }
imageCount++; if (contextMenu.func != nullptr)
{
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();
SetHelpMessage(TEXT("Menu.FavouritesText"));
}
if (ImGui::MenuItem(TEXT("Menu.Close")))
{
contextMenu.func = nullptr;
}
ImGui::EndPopup();
}
}
ImGui::EndChild();
ImGui::EndTabItem();
} }
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");
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<std::string>("Unkonwn");
if (ImGui::MenuItem(key.c_str()) && clickFunc != nullptr)
{
clickFunc(val);
}
if (ImGui::IsItemClicked(1))
{
contextMenu = {std::string("Favourites"), key, val, (void*)1};
}
}
++count;
}
if (count == 0)
{
Widget::TextCentered(TEXT("Menu.FavouritesNone"));
}
if (contextMenu.func != nullptr)
{
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();
SetHelpMessage(TEXT("Menu.FavouritesRemoveText"));
}
if (ImGui::MenuItem(TEXT("Menu.Close")))
{
contextMenu.func = nullptr;
}
ImGui::EndPopup();
}
}
ImGui::EndChild();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
} }
if (showImages) if (showImages)
{ {
ImGui::PopStyleVar(4); ImGui::PopStyleVar(4);
} }
// Draw popup code
if (contextMenu.func != nullptr)
{
if (ImGui::BeginPopupContextWindow())
{
ImGui::Text(contextMenu.val.c_str());
ImGui::Separator();
if (ImGui::MenuItem("Remove"))
{
static_cast<ArgCallback>(contextMenu.func)(contextMenu.val);
}
if (ImGui::MenuItem("Close"))
{
contextMenu.func = nullptr;
}
ImGui::EndPopup();
}
}
ImGui::EndChild();
} }
bool Widget::ColorBtn(int colorId, std::vector<float>& color, ImVec2 size) bool Widget::ColorBtn(int colorId, std::vector<float>& color, ImVec2 size)
@ -717,7 +780,7 @@ bool Widget::ListBox(const char* label, VecStr& allItems, std::string& selected)
bool Widget::ListBox(const char* label, VecStr& allItems, int& selected) bool Widget::ListBox(const char* label, VecStr& allItems, int& selected)
{ {
bool rtn = false; bool rtn = false;
if (ImGui::BeginCombo(label, std::to_string(selected).c_str())) if (ImGui::BeginCombo(label, allItems[selected].c_str()))
{ {
for (size_t index = 0; index < allItems.size(); ++index) for (size_t index = 0; index < allItems.size(); ++index)
{ {

View File

@ -65,8 +65,8 @@ public:
static void Filter(const char* label, ImGuiTextFilter& filter, const char* hint); static void Filter(const char* label, ImGuiTextFilter& filter, const char* hint);
// Draws ResourceStore images in the interface // Draws ResourceStore images in the interface
static void ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallback rightClickFunc, static void ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackRtn getNameFunc,
ArgCallbackRtn getNameFunc, ArgCallbackRtnBool verifyFunc = nullptr); ArgCallbackRtnBool verifyFunc = nullptr);
// Draws a dropdown listbox // Draws a dropdown listbox
static bool ListBox(const char* label, VecStr& allItems, int& selected); static bool ListBox(const char* label, VecStr& allItems, int& selected);