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,13 +70,17 @@ void MenuThread(void* param)
}
#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();
// Checking for updates once a day
SYSTEMTIME st;
GetSystemTime(&st);
if (gConfig.Get("Menu.LastUpdateChecked", 0) != st.wDay)
{
Updater::CheckUpdate();
@ -84,6 +88,12 @@ void MenuThread(void* param)
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)
{
Updater::Process();

View File

@ -471,7 +471,7 @@ void Game::ShowPage()
#ifdef GTASA
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);
#endif

View File

@ -305,7 +305,7 @@ void Ped::ShowPage()
{
ImGui::Spacing();
#ifdef GTASA
Widget::ImageList(m_PedData, SpawnPed, nullptr,
Widget::ImageList(m_PedData, SpawnPed,
[](std::string& str)
{
return m_PedData.m_pData->Get(str.c_str(), "Unknown");
@ -356,7 +356,6 @@ void Ped::ShowPage()
Spawner::m_nWeaponId = std::stoi(str);
weaponName = Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown");
},
nullptr,
[](std::string& str)
{
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)
{
Widget::ImageList(m_ClothData, ChangePlayerCloth, nullptr, [](std::string& str)
Widget::ImageList(m_ClothData, ChangePlayerCloth, [](std::string& str)
{
std::stringstream ss(str);
std::string temp;
@ -787,7 +787,7 @@ void Player::ShowPage()
getline(ss, temp, '$');
return temp;
});// nullptr, clothNameList, sizeof(clothNameList) / sizeof(const char*));
});
}
else
{
@ -841,7 +841,7 @@ void Player::ShowPage()
}
if (ImGui::BeginTabItem(TEXT("Player.PedSkinsTab")))
{
Widget::ImageList(Ped::m_PedData, ChangePlayerModel, nullptr,
Widget::ImageList(Ped::m_PedData, ChangePlayerModel,
[](std::string& str)
{
return Ped::m_PedData.m_pData->Get(str.c_str(), "Unknown");

View File

@ -1061,7 +1061,7 @@ void Vehicle::ShowPage()
ImGui::SetNextItemWidth(width);
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)
{
return GetNameFromModel(std::stoi(str));
@ -1274,7 +1274,6 @@ void Vehicle::ShowPage()
Paint::SetNodeTexture(FindPlayerPed()->m_pVehicle, PaintData::m_Selected, str,
PaintData::m_bMatFilter);
},
nullptr,
[](std::string& str)
{
return str;
@ -1291,10 +1290,10 @@ void Vehicle::ShowPage()
{
AddComponent(str);
},
[](std::string& str)
{
RemoveComponent(str);
},
// [](std::string& str)
// {
// RemoveComponent(str);
// },
[](std::string& str)
{
return str;

View File

@ -39,13 +39,13 @@ private:
static inline bool m_bApplyOnTraffic;
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
struct Spawner
{
#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
static inline ResourceStore m_VehData {"vehicles", eResourceType::TYPE_TEXT};
#endif

View File

@ -347,7 +347,7 @@ void Weapon::ShowPage()
m_nAmmoCount = (m_nAmmoCount > 99999) ? 99999 : m_nAmmoCount;
}
#ifdef GTASA
Widget::ImageList(m_WeaponData, GiveWeaponToPlayer, nullptr,
Widget::ImageList(m_WeaponData, GiveWeaponToPlayer,
[](std::string& str)
{
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"
"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("Ped.SelectWeapon"), &m_nSelectedWeapon, str.c_str());
ImGui::Combo(TEXT("Ped.SelectWeapon"), &m_nSelectedWeapon, "Weapon 1\0Weapon 2\0Weapon 3\0");
ImGui::Spacing();
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::Spacing();
Widget::ImageList(m_WeaponData, SetGangWeapon, nullptr,
Widget::ImageList(m_WeaponData, SetGangWeapon,
[](std::string& str)
{
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);
}
void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallback rightClickFunc,
ArgCallbackRtn getNameFunc, ArgCallbackRtnBool verifyFunc)
void Widget::ImageList(ResourceStore &store, ArgCallback clickFunc, ArgCallbackRtn getNameFunc, ArgCallbackRtnBool verifyFunc)
{
ImGuiStyle& style = ImGui::GetStyle();
/*
@ -280,14 +279,6 @@ void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallb
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)
{
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(3, 3));
@ -297,6 +288,19 @@ void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallb
}
// 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;
@ -315,7 +319,7 @@ void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallb
{
if (RoundedImageButton(store.m_ImagesList[i]->m_pTexture, m_ImageSize, modelName.c_str()))
{
leftClickFunc(text);
clickFunc(text);
}
}
@ -323,15 +327,16 @@ void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallb
{
if (ImGui::MenuItem(modelName.c_str()))
{
leftClickFunc(text);
clickFunc(text);
}
}
// Right click popup
if (ImGui::IsItemClicked(1) && rightClickFunc != nullptr)
if (ImGui::IsItemClicked(1))
{
contextMenu.func = rightClickFunc;
contextMenu.val = modelName;
contextMenu.func = (void*)1;
contextMenu.val = text;
contextMenu.key = std::format("{} ({})", modelName, text);
}
if (showImages)
@ -344,25 +349,19 @@ void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallb
imageCount++;
}
}
if (showImages)
{
ImGui::PopStyleVar(4);
}
// Draw popup code
if (contextMenu.func != nullptr)
{
if (ImGui::BeginPopupContextWindow())
{
ImGui::Text(contextMenu.val.c_str());
ImGui::Text(contextMenu.key.c_str());
ImGui::Separator();
if (ImGui::MenuItem("Remove"))
if (ImGui::MenuItem(TEXT("Menu.Favourites")))
{
static_cast<ArgCallback>(contextMenu.func)(contextMenu.val);
store.m_pData->Set(std::format("Favourites.{}", contextMenu.key).c_str(), contextMenu.val);
store.m_pData->Save();
SetHelpMessage(TEXT("Menu.FavouritesText"));
}
if (ImGui::MenuItem("Close"))
if (ImGui::MenuItem(TEXT("Menu.Close")))
{
contextMenu.func = nullptr;
}
@ -371,6 +370,70 @@ void Widget::ImageList(ResourceStore &store, ArgCallback leftClickFunc, ArgCallb
}
}
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)
{
ImGui::PopStyleVar(4);
}
}
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 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)
{

View File

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