[III] Finish vehicle tab

This commit is contained in:
Grinch_ 2021-10-24 02:57:34 +06:00
parent 525f426725
commit e74089ec74
4 changed files with 162 additions and 227 deletions

View File

@ -61,8 +61,7 @@ void FileHandler::GenerateHandlingFile(int pHandling, std::map<int, std::string>
fclose(fp);
}
void FileHandler::FetchColorData(std::vector<std::vector<float>>& storeVec,
std::map<std::string, std::vector<int>>& storeMap)
void FileHandler::FetchColorData(std::vector<std::vector<float>>& storeVec)
{
std::string m_FilePath = GAME_PATH((char*)"/data/carcols.dat");
@ -129,37 +128,6 @@ void FileHandler::FetchColorData(std::vector<std::vector<float>>& storeVec,
gLog << "Error parsing carcols.dat, " << line << std::endl;
}
}
if (bIsCar)
{
std::string temp;
std::stringstream ss(line);
// Format: modelname, colorindex1, colorindex2,...
getline(ss, temp, ',');
std::string name = temp;
while (getline(ss, temp, ','))
{
try
{
std::for_each(name.begin(), name.end(), [](char& c)
{
c = ::toupper(c);
});
int val = std::stoi(temp);
if (!(std::find(storeMap[name].begin(), storeMap[name].end(), val) !=
storeMap[name].end()))
{
storeMap[name].push_back(val);
}
}
catch (...)
{
gLog << "Error parsing carcols.dat, " << line << std::endl;
}
}
}
}
file.close();

View File

@ -10,11 +10,10 @@ public:
FileHandler(FileHandler&) = delete;
/*
Parses data/carcols.dat file and stores color data per vehicle
Parses data/carcols.dat file and stores color data
TODO: Implement something that also parses modloader data
*/
static void FetchColorData(std::vector<std::vector<float>>& storeVec,
std::map<std::string, std::vector<int>>& storeMap);
static void FetchColorData(std::vector<std::vector<float>>& storeVec);
/*
Parses data/vehicles.ide file and stores handingId in a map
TODO: Implement something that also parses modloader data

View File

@ -36,7 +36,7 @@ Vehicle::Vehicle()
#ifdef GTASA
FileHandler::FetchHandlingID(m_VehicleIDE);
#endif
FileHandler::FetchColorData(m_CarcolsColorData, m_CarcolsCarData);
FileHandler::FetchColorData(m_CarcolsColorData);
Events::processScriptsEvent += [this]
{
@ -335,8 +335,6 @@ void Vehicle::SpawnVehicle(std::string& rootkey, std::string& vehName, std::stri
int interior = BY_GAME(player->m_nAreaCode, player->m_nInterior, 0);
if (Command<Commands::IS_MODEL_AVAILABLE>(imodel))
{
CVector pos = player->GetPosition();
int speed = 0;
@ -487,17 +485,14 @@ void Vehicle::SpawnVehicle(std::string& rootkey, std::string& vehName, std::stri
Command<Commands::RESTORE_CAMERA_JUMPCUT>();
#endif
}
}
std::string Vehicle::GetNameFromModel(int model)
{
CBaseModelInfo* info;
#ifdef GTASA
info = CModelInfo::GetModelInfo(model);
#ifdef GTA3
return std::to_string(model);
#else
info = CModelInfo::ms_modelInfoPtrs[model];
return (const char*)CModelInfo::GetModelInfo(model) + 0x32;
#endif
return (const char*)info + 0x32;
}
int Vehicle::GetModelFromName(const char* name)
@ -522,7 +517,7 @@ void Vehicle::Draw()
int hplayer = CPools::GetPedRef(pPlayer);
CVehicle *pVeh = pPlayer->m_pVehicle;
if (ImGui::Button("Blow up cars", ImVec2(Ui::GetSize(BY_GAME(3,2)))))
if (ImGui::Button("Blow up cars", ImVec2(Ui::GetSize(BY_GAME(3,2,2)))))
{
for (CVehicle *pVeh : CPools::ms_pVehiclePool)
{
@ -532,7 +527,7 @@ void Vehicle::Draw()
ImGui::SameLine();
if (ImGui::Button("Fix vehicle", ImVec2(Ui::GetSize(BY_GAME(3,2)))))
if (ImGui::Button("Fix vehicle", ImVec2(Ui::GetSize(BY_GAME(3,2,2)))))
{
if (pPlayer && pVeh)
{
@ -802,7 +797,10 @@ void Vehicle::Draw()
{
ImGui::Spacing();
ImGui::BeginChild("MenusChild");
#ifdef GTASA
Ui::EditAddress<float>("Density multiplier", 0x8A5B20, 0, 1, 10);
#endif
if (ImGui::CollapsingHeader("Enter nearest vehicle as"))
{
int hplayer = CPools::GetPedRef(pPlayer);
@ -829,6 +827,7 @@ void Vehicle::Draw()
Command<Commands::WARP_CHAR_INTO_CAR>(hplayer, pClosestVeh);
}
#ifndef GTA3
for (int i = 0; i < seats; ++i)
{
if (i % 2 != 1)
@ -846,6 +845,7 @@ void Vehicle::Draw()
#endif
}
}
#endif
}
else
{
@ -865,7 +865,7 @@ void Vehicle::Draw()
for (CVehicle* pVeh : CPools::ms_pVehiclePool)
{
if (DistanceBetweenPoints(pVeh->GetPosition(), player->GetPosition()) < m_nVehRemoveRadius
&& !(BY_GAME(player->m_nPedFlags.bInVehicle, true, true) && player->m_pVehicle == pVeh))
&& player->m_pVehicle != pVeh)
{
Command<Commands::DELETE_CAR>(CPools::GetVehicleRef(pVeh));
}
@ -875,6 +875,7 @@ void Vehicle::Draw()
ImGui::Separator();
}
#ifndef GTA3
if (ImGui::CollapsingHeader("Traffic options"))
{
@ -894,6 +895,7 @@ void Vehicle::Draw()
ImGui::Spacing();
ImGui::Separator();
}
#endif
if (pPlayer && pPlayer->m_pVehicle)
{
CVehicle* pVeh = pPlayer->m_pVehicle;
@ -1019,7 +1021,7 @@ void Vehicle::Draw()
{
return GetNameFromModel(std::stoi(str));
});
#elif GTAVC
#else // GTA3 & GTAVC
Ui::DrawJSON(m_Spawner::m_VehData, SpawnVehicle, nullptr);
#endif
ImGui::EndTabItem();
@ -1061,14 +1063,12 @@ void Vehicle::Draw()
ImGui::RadioButton("Primary", &m_Color::m_nRadioButton, 1);
ImGui::RadioButton("Secondary", &m_Color::m_nRadioButton, 2);
ImGui::NextColumn();
ImGui::Checkbox("Show all", &m_Color::bShowAll);
ImGui::NewLine();
ImGui::RadioButton("Tertiary", &m_Color::m_nRadioButton, 3);
ImGui::RadioButton("Quaternary", &m_Color::m_nRadioButton, 4);
#elif GTAVC
ImGui::Checkbox("Show all", &m_Color::bShowAll);
#else // GTA3 & GTAVC
ImGui::RadioButton("Primary", &m_Color::m_nRadioButton, 1);
ImGui::NextColumn();
ImGui::NewLine();
ImGui::RadioButton("Secondary", &m_Color::m_nRadioButton, 2);
#endif
ImGui::Spacing();
@ -1085,13 +1085,11 @@ void Vehicle::Draw()
ImGui::BeginChild("Colorss");
if (m_Color::bShowAll)
{
for (int colorId = 0; colorId < count; ++colorId)
{
if (Ui::ColorButton(colorId, m_CarcolsColorData[colorId], ImVec2(btnSize, btnSize)))
{
*(uint8_replacement*)(int(veh) + BY_GAME(0x433, 0x19F) + m_Color::m_nRadioButton) = colorId;
*(uint8_replacement*)(int(veh) + BY_GAME(0x433, 0x19F, 0x19B) + m_Color::m_nRadioButton) = colorId;
}
if ((colorId + 1) % btnsInRow != 0)
@ -1099,34 +1097,6 @@ void Vehicle::Draw()
ImGui::SameLine(0.0, 4.0);
}
}
}
else
{
std::string vehName = GetNameFromModel(pPlayer->m_pVehicle->m_nModelIndex);
for (auto entry : m_CarcolsCarData)
{
if (entry.first == vehName)
{
int count = 1;
for (int colorId : entry.second)
{
if (Ui::ColorButton(colorId, m_CarcolsColorData[colorId],
ImVec2(btnSize, btnSize)))
{
*(uint8_replacement*)(int(veh) + BY_GAME(0x433, 0x19F) + m_Color::m_nRadioButton) = colorId;
}
if (count % btnsInRow != 0)
{
ImGui::SameLine(0.0, 4.0);
}
++count;
}
break;
}
}
}
ImGui::EndChild();
ImGui::EndTabItem();

View File

@ -24,12 +24,10 @@ private:
static inline bool m_bLockSpeed;
static inline float m_fLockSpeed;
static inline std::vector<std::vector<float>> m_CarcolsColorData;
static inline std::map<std::string, std::vector<int>> m_CarcolsCarData;
struct m_Color
{
static inline bool m_bMatFilter = true;
static inline int m_nRadioButton = 1;
static inline bool bShowAll;
static inline float m_fColorPicker[3]{ 0, 0, 0 };
};