This commit is contained in:
Grinch_ 2021-08-13 23:45:56 +06:00
parent d34a1ff213
commit e56f5b02c4
14 changed files with 102 additions and 87 deletions

View File

@ -6,10 +6,10 @@
"${workspaceFolder}/**",
"${PLUGIN_SDK_DIR}/*",
"${DIRECTX9_SDK_DIR}/Include/*",
// "${PLUGIN_SDK_DIR}/plugin_sa/*",
// "${PLUGIN_SDK_DIR}/plugin_sa/game_sa/*",
"${PLUGIN_SDK_DIR}/plugin_vc/*",
"${PLUGIN_SDK_DIR}/plugin_vc/game_vc/*",
"${PLUGIN_SDK_DIR}/plugin_sa/*",
"${PLUGIN_SDK_DIR}/plugin_sa/game_sa/*",
// "${PLUGIN_SDK_DIR}/plugin_vc/*",
// "${PLUGIN_SDK_DIR}/plugin_vc/game_vc/*",
"${PLUGIN_SDK_DIR}/shared/*",
"${PLUGIN_SDK_DIR}/shared/game/*",
"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt\\*",
@ -20,7 +20,7 @@
"IS_PLATFORM_WIN",
"_CRT_SECURE_NO_WARNINGS",
"_CRT_NON_CONFORMING_SWPRINTFS",
"GTAVC",
"GTASA",
"_DX9_SDK_INSTALLED",
"PLUGIN_SGV_10US"
],

View File

@ -73,7 +73,7 @@ private:
inline static VehicleExtendedData<VehData> m_VehData;
protected:
inline static ResourceStore m_TextureData { "textures" };
inline static ResourceStore m_TextureData { "textures", eResourceType::TYPE_IMAGE, ImVec2(100, 80) };
struct veh_nodes
{

View File

@ -260,8 +260,7 @@ void Ped::Draw()
{
ImGui::Spacing();
#ifdef GTASA
Ui::DrawImages(m_PedData.m_ImagesList, ImVec2(65, 110), m_PedData.m_Categories, m_PedData.m_Selected,
m_PedData.m_Filter, SpawnPed, nullptr,
Ui::DrawImages(m_PedData, SpawnPed, nullptr,
[](std::string str) { return m_PedData.m_pJson->m_Data[str].get<std::string>(); });
#elif GTAVC
Ui::DrawJSON(m_PedData, SpawnPed, nullptr);
@ -295,8 +294,7 @@ void Ped::Draw()
Weapon::m_WeaponData.m_pJson->m_Data[std::to_string(m_SpawnPed::m_nWeaponId)].get<std::string>().c_str());
ImGui::Spacing();
Ui::DrawImages(Weapon::m_WeaponData.m_ImagesList, ImVec2(65, 65), Weapon::m_WeaponData.m_Categories,
Weapon::m_WeaponData.m_Selected, Weapon::m_WeaponData.m_Filter,
Ui::DrawImages(Weapon::m_WeaponData,
[](std::string str) { m_SpawnPed::m_nWeaponId = std::stoi(str); },
nullptr,
[](std::string str)

View File

@ -11,7 +11,7 @@ private:
inline static CJson m_SpecialPedJson = CJson("ped special");
#endif
inline static ResourceStore m_PedData{"ped", eResourceType::TYPE_TEXT};
inline static ResourceStore m_PedData{"ped", eResourceType::TYPE_TEXT, ImVec2(65, 110)};
inline static bool m_bImagesLoaded;
inline static bool m_bExGangWarsInstalled;
inline static int m_nPedRemoveRadius = 5;

View File

@ -534,8 +534,7 @@ void Player::Draw()
{
if (bClothOption == 0)
{
Ui::DrawImages(m_ClothData.m_ImagesList, ImVec2(70, 100), m_ClothData.m_Categories, m_ClothData.m_Selected,
m_ClothData.m_Filter, ChangePlayerCloth, nullptr,
Ui::DrawImages(m_ClothData, ChangePlayerCloth, nullptr,
[](std::string str)
{
std::stringstream ss(str);
@ -596,8 +595,7 @@ void Player::Draw()
}
if (ImGui::BeginTabItem("Ped skins"))
{
Ui::DrawImages(Ped::m_PedData.m_ImagesList, ImVec2(65, 110), Ped::m_PedData.m_Categories,
Ped::m_PedData.m_Selected, Ped::m_PedData.m_Filter, ChangePlayerModel, nullptr,
Ui::DrawImages(Ped::m_PedData, ChangePlayerModel, nullptr,
[](std::string str) { return Ped::m_PedData.m_pJson->m_Data[str].get<std::string>(); });
ImGui::EndTabItem();
}

View File

@ -15,7 +15,7 @@ private:
#ifdef GTASA
inline static bool m_bAimSkinChanger;
inline static int m_nUiBodyState;
inline static ResourceStore m_ClothData { "clothes" };
inline static ResourceStore m_ClothData { "clothes" , eResourceType::TYPE_IMAGE, ImVec2(70, 100)};
struct m_CustomSkins
{
inline static std::string m_Path = paths::GetGameDirPathA() + std::string("\\modloader\\Custom Skins\\");;

View File

@ -2,10 +2,15 @@
#include "CFileLoader.h"
#include "extensions/Paths.h"
ResourceStore::ResourceStore(const char* text, eResourceType type)
ResourceStore::ResourceStore(const char* text, eResourceType type, ImVec2 imageSize)
: m_ImageSize(imageSize)
{
if (type == eResourceType::TYPE_IMAGE)
if (type != eResourceType::TYPE_TEXT)
{
/*
Textures need to be loaded from main thread
Loading it directly here doesn't work
*/
Events::processScriptsEvent += [text, this]()
{
if (!m_bTexturesLoaded)
@ -14,9 +19,15 @@ ResourceStore::ResourceStore(const char* text, eResourceType type)
m_bTexturesLoaded = true;
}
};
if (type == eResourceType::TYPE_BOTH)
{
goto loadJson;
}
}
else
{
loadJson:
m_pJson = std::make_unique<CJson>(text);
// Generate categories

View File

@ -40,6 +40,7 @@ enum eResourceType
{
TYPE_IMAGE,
TYPE_TEXT,
TYPE_BOTH,
};
using TextureResourceList = std::vector<std::unique_ptr<STextureResource>>;
@ -54,7 +55,8 @@ public:
std::string m_Selected = "All";
std::unique_ptr<CJson> m_pJson;
TextureResourceList m_ImagesList;
ImVec2 m_ImageSize;
bool m_bTexturesLoaded = false;
ResourceStore(const char* text, eResourceType type = TYPE_IMAGE);
ResourceStore(const char* text, eResourceType type = TYPE_IMAGE, ImVec2 imageSize = ImVec2(64, 64));
};

View File

@ -42,10 +42,10 @@ bool Ui::ListBoxStr(const char* label, std::vector<std::string>& all_items, std:
return rtn;
}
bool Ui::ListBoxCustomNames(const char* label, std::vector<std::string>& all_items, std::string& selected, const char* custom_names[], size_t length)
bool Ui::ListBoxCustomNames(const char* label, std::vector<std::string>& all_items, std::string& selected, const char* customNames[], size_t length)
{
bool rtn = false;
std::string display_selected = (selected == "All") ? selected : custom_names[std::stoi(selected)];
std::string display_selected = (selected == "All") ? selected : customNames[std::stoi(selected)];
if (ImGui::BeginCombo(label, display_selected.c_str()))
{
@ -57,7 +57,7 @@ bool Ui::ListBoxCustomNames(const char* label, std::vector<std::string>& all_ite
for (size_t i = 0; i < length; ++i)
{
if (ImGui::MenuItem(custom_names[i]))
if (ImGui::MenuItem(customNames[i]))
{
selected = std::to_string(i);
rtn = true;
@ -183,7 +183,7 @@ bool Ui::CheckboxWithHint(const char* label, bool* v, const char* hint, bool is_
// set things up
bool pressed = false;
const ImGuiStyle& style = ImGui::GetStyle();
const ImVec2 text_size = ImGui::CalcTextSize(label, nullptr, true);
const ImVec2 textSize = ImGui::CalcTextSize(label, nullptr, true);
float square_sz = ImGui::GetFrameHeight();
ImDrawList* drawlist = ImGui::GetWindowDrawList();
ImU32 color = ImGui::GetColorU32(ImGuiCol_FrameBg);
@ -482,74 +482,79 @@ void Ui::FilterWithHint(const char* label, ImGuiTextFilter& filter, const char*
}
}
// clean up the code someday
void Ui::DrawImages(std::vector<std::unique_ptr<STextureResource>>& img_vec, ImVec2 image_size,
std::vector<std::string>& category_vec, std::string& selected_item, ImGuiTextFilter& filter,
std::function<void(std::string&)> on_left_click, std::function<void(std::string&)> on_right_click,
std::function<std::string(std::string&)> get_name_func,
std::function<bool(std::string&)> verify_func, const char** custom_names, size_t length)
void Ui::DrawImages(ResourceStore &store, std::function<void(std::string&)> onLeftClick, std::function<void(std::string&)> onRightClick,
std::function<std::string(std::string&)> getName, std::function<bool(std::string&)> verifyFunc,
const char** customNames, size_t length)
{
// scale image size
image_size.x *= screen::GetScreenWidth() / 1366.0f;
image_size.y *= screen::GetScreenHeight() / 768.0f;
/*
Trying to scale images based on resolutions
Native 1366x768
*/
store.m_ImageSize.x *= screen::GetScreenWidth() / 1366.0f;
store.m_ImageSize.y *= screen::GetScreenHeight() / 768.0f;
int images_in_row = static_cast<int>(ImGui::GetWindowContentRegionWidth() / image_size.x);
image_size.x = ImGui::GetWindowContentRegionWidth() / images_in_row - static_cast<int>(ImGuiStyleVar_ItemSpacing) *
0.65f;
int images_count = 1;
int imageCount = 1;
int imagesInRow = static_cast<int>(ImGui::GetWindowContentRegionWidth() / store.m_ImageSize.x);
store.m_ImageSize.x = ImGui::GetWindowContentRegionWidth() / imagesInRow - static_cast<int>(ImGuiStyleVar_ItemSpacing) * 0.65f;
ImGui::Spacing();
// Hide the popup if right clicked again
if (ImGui::IsMouseClicked(1))
{
imgPopup.function = nullptr;
}
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() / 2 - 5);
if (custom_names)
if (customNames)
{
ListBoxCustomNames("##Categories", category_vec, selected_item, custom_names, length);
ListBoxCustomNames("##Categories", store.m_Categories, store.m_Selected, customNames, length);
}
else
{
ListBoxStr("##Categories", category_vec, selected_item);
ListBoxStr("##Categories", store.m_Categories, store.m_Selected);
}
ImGui::SameLine();
FilterWithHint("##Filter", filter, "Search");
FilterWithHint("##Filter", store.m_Filter, "Search");
ImGui::Spacing();
ImGui::BeginChild("DrawImages");
for (uint i = 0; i < img_vec.size(); i++)
for (uint i = 0; i < store.m_ImagesList.size(); ++i)
{
std::string text = img_vec[i]->m_FileName;
std::string model_name = get_name_func(text);
std::string text = store.m_ImagesList[i]->m_FileName;
std::string modelName = getName(text);
if (filter.PassFilter(model_name.c_str())
&& (img_vec[i]->m_CategoryName == selected_item || selected_item == "All")
&& (verify_func == nullptr || verify_func(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))
)
{
/*
Couldn't figure out how to laod images for Dx11
Using texts for now
*/
if (Globals::renderer == Render_DirectX11)
{
if (ImGui::MenuItem(model_name.c_str()))
if (ImGui::MenuItem(modelName.c_str()))
{
on_left_click(text);
onLeftClick(text);
}
}
else
{
if (ImGui::ImageButton(img_vec[i]->m_pTexture, image_size, ImVec2(0, 0), ImVec2(1, 1), 1, ImVec4(1, 1, 1, 1), ImVec4(1, 1, 1, 1)))
if (ImGui::ImageButton(store.m_ImagesList[i]->m_pTexture, store.m_ImageSize, ImVec2(0, 0), ImVec2(1, 1), 1, ImVec4(1, 1, 1, 1), ImVec4(1, 1, 1, 1)))
{
on_left_click(text);
onLeftClick(text);
}
}
if (ImGui::IsItemClicked(1) && on_right_click != nullptr)
// Right click popup
if (ImGui::IsItemClicked(1) && onRightClick != nullptr)
{
imgPopup.function = on_right_click;
imgPopup.value = model_name;
imgPopup.function = onRightClick;
imgPopup.value = modelName;
}
if (Globals::renderer != Render_DirectX11)
@ -558,45 +563,46 @@ void Ui::DrawImages(std::vector<std::unique_ptr<STextureResource>>& img_vec, ImV
{
ImDrawList* drawlist = ImGui::GetWindowDrawList();
ImVec2 btn_min = ImGui::GetItemRectMin();
ImVec2 btn_max = ImGui::GetItemRectMax();
// Drawing selected overlay
ImVec2 btnMin = ImGui::GetItemRectMin();
ImVec2 btnMax = ImGui::GetItemRectMax();
drawlist->AddRectFilled(btnMin, btnMax, ImGui::GetColorU32(ImGuiCol_ModalWindowDimBg));
drawlist->AddRectFilled(btn_min, btn_max, ImGui::GetColorU32(ImGuiCol_ModalWindowDimBg));
ImVec2 text_size = ImGui::CalcTextSize(model_name.c_str());
if (text_size.x < image_size.x)
// Calculating and drawing text over the image
ImVec2 textSize = ImGui::CalcTextSize(modelName.c_str());
if (textSize.x < store.m_ImageSize.x)
{
float offsetX = (ImGui::GetItemRectSize().x - text_size.x) / 2;
drawlist->AddText(ImVec2(btn_min.x + offsetX, btn_min.y + 10), ImGui::GetColorU32(ImGuiCol_Text),
model_name.c_str());
float offsetX = (ImGui::GetItemRectSize().x - textSize.x) / 2;
drawlist->AddText(ImVec2(btnMin.x + offsetX, btnMin.y + 10), ImGui::GetColorU32(ImGuiCol_Text),
modelName.c_str());
}
else
{
std::string buff = "";
std::stringstream ss(model_name);
std::stringstream ss(modelName);
short count = 1;
while (ss >> buff)
{
text_size = ImGui::CalcTextSize(buff.c_str());
float offsetX = (ImGui::GetItemRectSize().x - text_size.x) / 2;
drawlist->AddText(ImVec2(btn_min.x + offsetX, btn_min.y + 10 * count),
textSize = ImGui::CalcTextSize(buff.c_str());
float offsetX = (ImGui::GetItemRectSize().x - textSize.x) / 2;
drawlist->AddText(ImVec2(btnMin.x + offsetX, btnMin.y + 10 * count),
ImGui::GetColorU32(ImGuiCol_Text), buff.c_str());
++count;
}
}
}
if (images_count % images_in_row != 0)
if (imageCount % imagesInRow != 0)
{
ImGui::SameLine(0.0, ImGui::GetStyle().ItemInnerSpacing.x);
}
}
images_count++;
imageCount++;
}
}
// Draw popup code
if (imgPopup.function != nullptr)
{
if (ImGui::BeginPopupContextWindow())
@ -604,11 +610,14 @@ void Ui::DrawImages(std::vector<std::unique_ptr<STextureResource>>& img_vec, ImV
ImGui::Text(imgPopup.value.c_str());
ImGui::Separator();
if (ImGui::MenuItem("Remove"))
{
imgPopup.function(imgPopup.value);
}
if (ImGui::MenuItem("Close"))
{
imgPopup.function = nullptr;
}
ImGui::EndPopup();
}

View File

@ -51,9 +51,7 @@ public:
static void DrawJSON(ResourceStore& data,
std::function<void(std::string&, std::string&, std::string&)> func_left_click,
std::function<void(std::string&, std::string&, std::string&)> func_right_click);
static void DrawImages(std::vector<std::unique_ptr<STextureResource>>& img_vec, ImVec2 image_size,
std::vector<std::string>& category_vec, std::string& selected_item, ImGuiTextFilter& filter,
std::function<void(std::string&)> on_left_click,
static void DrawImages(ResourceStore &store, std::function<void(std::string&)> on_left_click,
std::function<void(std::string&)> on_right_click,
std::function<std::string(std::string&)> get_name_func,
std::function<bool(std::string&)> verify_func = nullptr,

View File

@ -1106,8 +1106,7 @@ void Vehicle::Draw()
ImGui::SetNextItemWidth(ImGui::GetWindowContentRegionWidth() - 2.5);
ImGui::InputTextWithHint("##LicenseText", "License plate text", m_Spawner::m_nLicenseText, 9);
Ui::DrawImages(m_Spawner::m_VehData.m_ImagesList, ImVec2(100, 75), m_Spawner::m_VehData.m_Categories,
m_Spawner::m_VehData.m_Selected, m_Spawner::m_VehData.m_Filter, SpawnVehicle, nullptr,
Ui::DrawImages(m_Spawner::m_VehData, SpawnVehicle, nullptr,
[](std::string str)
{
return GetNameFromModel(std::stoi(str));
@ -1320,8 +1319,7 @@ void Vehicle::Draw()
ImGui::SameLine();
ImGui::Checkbox("Material filter", &m_Color::m_bMatFilter);
ImGui::Spacing();
Ui::DrawImages(m_TextureData.m_ImagesList, ImVec2(100, 80), m_TextureData.m_Categories, m_TextureData.m_Selected,
m_TextureData.m_Filter,
Ui::DrawImages(m_TextureData,
[](std::string& str)
{
Paint::SetNodeTexture(FindPlayerPed()->m_pVehicle, Paint::veh_nodes::selected, str,
@ -1339,8 +1337,7 @@ void Vehicle::Draw()
if (ImGui::BeginTabItem("Tune"))
{
ImGui::Spacing();
Ui::DrawImages(m_TuneData.m_ImagesList, ImVec2(100, 80), m_TuneData.m_Categories, m_TuneData.m_Selected,
m_TuneData.m_Filter,
Ui::DrawImages(m_TuneData,
[](std::string& str) { AddComponent(str); },
[](std::string& str) { RemoveComponent(str); },
[](std::string& str) { return str; },

View File

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

View File

@ -230,8 +230,7 @@ void Weapon::Draw()
m_WeaponData.m_pJson->m_Data[std::to_string(m_nGangWeaponList[m_nSelectedGang][m_nSelectedWeapon])].get<
std::string>().c_str());
ImGui::Spacing();
Ui::DrawImages(m_WeaponData.m_ImagesList, ImVec2(65, 65), m_WeaponData.m_Categories, m_WeaponData.m_Selected,
m_WeaponData.m_Filter, SetGangWeapon, nullptr,
Ui::DrawImages(m_WeaponData, SetGangWeapon, nullptr,
[](std::string str) { return m_WeaponData.m_pJson->m_Data[str].get<std::string>(); },
[](std::string str) { return str != "-1"; /*Jetpack*/ }
);
@ -245,8 +244,7 @@ void Weapon::Draw()
m_nAmmoCount = (m_nAmmoCount < 0) ? 0 : m_nAmmoCount;
m_nAmmoCount = (m_nAmmoCount > 99999) ? 99999 : m_nAmmoCount;
}
Ui::DrawImages(m_WeaponData.m_ImagesList, ImVec2(65, 65), m_WeaponData.m_Categories, m_WeaponData.m_Selected,
m_WeaponData.m_Filter, GiveWeaponToPlayer, nullptr,
Ui::DrawImages(m_WeaponData, GiveWeaponToPlayer, nullptr,
[](std::string str) { return m_WeaponData.m_pJson->m_Data[str].get<std::string>(); },
[](std::string str) { return str != "0"; /*Unarmed*/ }
);

View File

@ -3,7 +3,11 @@
class Weapon
{
public:
#ifdef GTASA
inline static ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_BOTH, ImVec2(65, 65) };
#elif GTAVC
inline static ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_TEXT };
#endif
inline static bool m_bAutoAim;
inline static bool m_bFastReload;
inline static bool m_bHugeDamage;