2022-02-28 23:04:56 +01:00
|
|
|
#include "fiber_pool.hpp"
|
|
|
|
#include "natives.hpp"
|
2022-07-31 01:47:48 +08:00
|
|
|
#include "services/gta_data/gta_data_service.hpp"
|
|
|
|
#include "services/model_preview/model_preview_service.hpp"
|
2022-02-28 23:04:56 +01:00
|
|
|
#include "util/vehicle.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "views/view.hpp"
|
2022-02-28 23:04:56 +01:00
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2022-08-10 08:42:34 +08:00
|
|
|
void view::spawn_vehicle()
|
2022-07-12 22:42:07 +08:00
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
ImGui::SetWindowSize({0.f, (float)*g_pointers->m_resolution_y}, ImGuiCond_Always);
|
2022-05-04 19:16:40 +02:00
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
if (ImGui::Checkbox("PREVIEW"_T.data(), &g.spawn_vehicle.preview_vehicle))
|
2022-07-31 01:47:48 +08:00
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
if (!g.spawn_vehicle.preview_vehicle)
|
2022-07-31 01:47:48 +08:00
|
|
|
{
|
|
|
|
g_model_preview_service->stop_preview();
|
|
|
|
}
|
|
|
|
}
|
2022-03-14 23:31:30 +01:00
|
|
|
ImGui::SameLine();
|
2022-12-22 21:23:32 +00:00
|
|
|
components::command_checkbox<"spawnin">();
|
2022-03-21 17:05:13 -04:00
|
|
|
ImGui::SameLine();
|
2022-12-22 21:23:32 +00:00
|
|
|
components::command_checkbox<"spawnmaxed">();
|
2022-03-14 23:31:30 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
static char plate_buf[9] = {0};
|
2022-12-18 23:15:52 +01:00
|
|
|
strncpy(plate_buf, g.spawn_vehicle.plate.c_str(), 9);
|
2022-05-23 06:38:45 +08:00
|
|
|
|
2022-07-10 06:33:14 +08:00
|
|
|
ImGui::SetNextItemWidth(300.f);
|
2023-02-01 19:46:33 +01:00
|
|
|
components::input_text_with_hint("PLATE"_T, "PLATE_NUMBER"_T, plate_buf, sizeof(plate_buf), ImGuiInputTextFlags_None, [] {
|
2022-12-18 23:15:52 +01:00
|
|
|
g.spawn_vehicle.plate = plate_buf;
|
2022-07-10 06:33:14 +08:00
|
|
|
});
|
2022-03-14 23:31:30 +01:00
|
|
|
|
2022-07-15 20:54:23 +08:00
|
|
|
static int selected_class = -1;
|
2023-03-01 21:27:15 +00:00
|
|
|
const auto& class_arr = g_gta_data_service->vehicle_classes();
|
2022-07-15 20:54:23 +08:00
|
|
|
|
|
|
|
ImGui::SetNextItemWidth(300.f);
|
2023-03-01 21:27:15 +00:00
|
|
|
if (ImGui::BeginCombo("VEHICLE_CLASS"_T.data(),
|
|
|
|
selected_class == -1 ? "ALL"_T.data() : class_arr[selected_class].c_str()))
|
2022-07-15 20:54:23 +08:00
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
if (ImGui::Selectable("ALL"_T.data(), selected_class == -1))
|
2022-07-15 20:54:23 +08:00
|
|
|
{
|
|
|
|
selected_class = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < class_arr.size(); i++)
|
|
|
|
{
|
|
|
|
if (ImGui::Selectable(class_arr[i].c_str(), selected_class == i))
|
|
|
|
{
|
|
|
|
selected_class = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected_class == i)
|
|
|
|
{
|
|
|
|
ImGui::SetItemDefaultFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndCombo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-10 06:33:14 +08:00
|
|
|
static char search[64];
|
2022-03-21 17:05:13 -04:00
|
|
|
|
2022-07-10 06:33:14 +08:00
|
|
|
ImGui::SetNextItemWidth(300.f);
|
2023-02-01 19:46:33 +01:00
|
|
|
components::input_text_with_hint("MODEL_NAME"_T, "SEARCH"_T, search, sizeof(search), ImGuiInputTextFlags_None);
|
2022-07-10 06:33:14 +08:00
|
|
|
|
2022-07-28 01:42:15 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
if (ImGui::ListBoxHeader("###vehicles", {300, static_cast<float>(*g_pointers->m_resolution_y - 188 - 38 * 4)}))
|
2022-02-28 23:04:56 +01:00
|
|
|
{
|
2022-07-28 01:42:15 +08:00
|
|
|
if (self::veh)
|
|
|
|
{
|
|
|
|
static auto veh_hash = 0;
|
2023-03-01 21:27:15 +00:00
|
|
|
|
2022-07-28 01:42:15 +08:00
|
|
|
g_fiber_pool->queue_job([] {
|
|
|
|
veh_hash = ENTITY::GET_ENTITY_MODEL(self::veh);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (veh_hash)
|
|
|
|
{
|
2022-10-19 00:30:32 +02:00
|
|
|
const auto& item = g_gta_data_service->vehicle_by_hash(veh_hash);
|
2022-07-28 01:42:15 +08:00
|
|
|
|
2023-02-01 19:46:33 +01:00
|
|
|
components::selectable(std::vformat("SPAWN_VEHICLE_CURRENT_VEHICLE"_T, std::make_format_args(item.m_display_name)), false, [] {
|
2022-07-28 01:42:15 +08:00
|
|
|
if (self::veh)
|
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
Vector3 spawn_location = vehicle::get_spawn_location(g.spawn_vehicle.spawn_inside);
|
2023-03-01 21:27:15 +00:00
|
|
|
float spawn_heading = ENTITY::GET_ENTITY_HEADING(self::ped);
|
2022-07-28 01:42:15 +08:00
|
|
|
|
|
|
|
auto owned_mods = vehicle::get_owned_mods_from_vehicle(self::veh);
|
|
|
|
|
|
|
|
auto veh = vehicle::clone_from_owned_mods(owned_mods, spawn_location, spawn_heading);
|
|
|
|
|
|
|
|
if (veh == 0)
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_error("VEHICLE"_T.data(), "UNABLE_TO_SPAWN_VEHICLE"_T.data());
|
2022-07-28 01:42:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.spawn_vehicle.spawn_maxed)
|
2022-07-28 01:42:15 +08:00
|
|
|
{
|
|
|
|
vehicle::max_vehicle(veh);
|
|
|
|
}
|
|
|
|
|
2022-07-31 01:47:48 +08:00
|
|
|
vehicle::set_plate(veh, plate_buf);
|
2022-07-28 01:42:15 +08:00
|
|
|
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.spawn_vehicle.spawn_inside)
|
2022-07-28 01:42:15 +08:00
|
|
|
{
|
|
|
|
vehicle::teleport_into_vehicle(veh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-31 01:47:48 +08:00
|
|
|
g_model_preview_service->stop_preview();
|
2022-07-28 01:42:15 +08:00
|
|
|
});
|
|
|
|
|
2022-12-18 23:15:52 +01:00
|
|
|
if (!g.spawn_vehicle.preview_vehicle || (g.spawn_vehicle.preview_vehicle && !ImGui::IsAnyItemHovered()))
|
2022-07-31 01:47:48 +08:00
|
|
|
{
|
|
|
|
g_model_preview_service->stop_preview();
|
|
|
|
}
|
|
|
|
else if (ImGui::IsItemHovered())
|
2022-07-28 01:42:15 +08:00
|
|
|
{
|
|
|
|
g_fiber_pool->queue_job([] {
|
2023-03-01 21:27:15 +00:00
|
|
|
g_model_preview_service->show_vehicle(vehicle::get_owned_mods_from_vehicle(self::veh),
|
|
|
|
g.spawn_vehicle.spawn_maxed);
|
2022-07-28 01:42:15 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-10 06:33:14 +08:00
|
|
|
|
2022-10-19 00:30:32 +02:00
|
|
|
const auto& item_arr = g_gta_data_service->vehicles();
|
2022-07-10 06:33:14 +08:00
|
|
|
if (item_arr.size() > 0)
|
2022-03-14 23:31:30 +01:00
|
|
|
{
|
2022-07-19 18:19:19 +08:00
|
|
|
std::string lower_search = search;
|
|
|
|
std::transform(lower_search.begin(), lower_search.end(), lower_search.begin(), tolower);
|
2022-07-10 06:33:14 +08:00
|
|
|
|
2022-10-19 00:30:32 +02:00
|
|
|
for (auto& item : item_arr)
|
|
|
|
{
|
|
|
|
const auto& vehicle = item.second;
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
std::string display_name = vehicle.m_display_name;
|
2022-10-19 00:30:32 +02:00
|
|
|
std::string display_manufacturer = vehicle.m_display_manufacturer;
|
2023-03-01 21:27:15 +00:00
|
|
|
std::string clazz = vehicle.m_vehicle_class;
|
2022-07-10 06:33:14 +08:00
|
|
|
|
|
|
|
std::transform(display_name.begin(), display_name.end(), display_name.begin(), ::tolower);
|
|
|
|
std::transform(display_manufacturer.begin(), display_manufacturer.end(), display_manufacturer.begin(), ::tolower);
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
if ((selected_class == -1 || class_arr[selected_class] == clazz)
|
|
|
|
&& (display_name.find(lower_search) != std::string::npos || display_manufacturer.find(lower_search) != std::string::npos))
|
|
|
|
{
|
2022-10-19 00:30:32 +02:00
|
|
|
ImGui::PushID(vehicle.m_hash);
|
2023-03-01 21:27:15 +00:00
|
|
|
components::selectable(vehicle.m_display_name, false, [&vehicle] {
|
2022-12-18 23:15:52 +01:00
|
|
|
const auto spawn_location = vehicle::get_spawn_location(g.spawn_vehicle.spawn_inside);
|
2023-03-01 21:27:15 +00:00
|
|
|
const auto spawn_heading = ENTITY::GET_ENTITY_HEADING(self::ped);
|
2022-07-10 06:33:14 +08:00
|
|
|
|
2022-10-19 00:30:32 +02:00
|
|
|
const auto veh = vehicle::spawn(vehicle.m_hash, spawn_location, spawn_heading);
|
2022-03-14 23:31:30 +01:00
|
|
|
|
2022-07-28 01:42:15 +08:00
|
|
|
if (veh == 0)
|
2022-03-21 17:05:13 -04:00
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_error("VEHICLE"_T.data(), "UNABLE_TO_SPAWN_VEHICLE"_T.data());
|
2022-03-21 17:05:13 -04:00
|
|
|
}
|
2022-07-28 01:42:15 +08:00
|
|
|
else
|
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.spawn_vehicle.spawn_maxed)
|
2022-07-28 01:42:15 +08:00
|
|
|
{
|
|
|
|
vehicle::max_vehicle(veh);
|
|
|
|
}
|
2022-03-21 17:05:13 -04:00
|
|
|
|
2022-07-31 01:47:48 +08:00
|
|
|
vehicle::set_plate(veh, plate_buf);
|
2022-07-10 06:33:14 +08:00
|
|
|
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.spawn_vehicle.spawn_inside)
|
2022-07-28 01:42:15 +08:00
|
|
|
{
|
|
|
|
vehicle::teleport_into_vehicle(veh);
|
|
|
|
}
|
2022-07-17 04:36:05 +08:00
|
|
|
}
|
|
|
|
|
2022-07-31 01:47:48 +08:00
|
|
|
g_model_preview_service->stop_preview();
|
2022-03-14 23:31:30 +01:00
|
|
|
});
|
2022-07-12 22:42:07 +08:00
|
|
|
ImGui::PopID();
|
2022-02-28 23:04:56 +01:00
|
|
|
|
2022-12-18 23:15:52 +01:00
|
|
|
if (!g.spawn_vehicle.preview_vehicle || (g.spawn_vehicle.preview_vehicle && !ImGui::IsAnyItemHovered()))
|
2022-07-10 06:33:14 +08:00
|
|
|
{
|
2022-07-31 01:47:48 +08:00
|
|
|
g_model_preview_service->stop_preview();
|
2022-07-10 06:33:14 +08:00
|
|
|
}
|
2022-07-31 01:47:48 +08:00
|
|
|
else if (ImGui::IsItemHovered())
|
2022-07-10 06:33:14 +08:00
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
g_model_preview_service->show_vehicle(vehicle.m_hash, g.spawn_vehicle.spawn_maxed);
|
2022-07-10 06:33:14 +08:00
|
|
|
}
|
2022-03-14 23:31:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-10 06:33:14 +08:00
|
|
|
else
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
ImGui::Text("NO_VEHICLE_IN_REGISTRY"_T.data());
|
2022-07-10 06:33:14 +08:00
|
|
|
}
|
2022-05-23 06:38:45 +08:00
|
|
|
ImGui::ListBoxFooter();
|
2022-02-28 23:04:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|