2022-02-28 23:04:56 +01:00
|
|
|
#include "views/view.hpp"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2022-08-10 08:42:34 +08:00
|
|
|
void view::spawn_vehicle()
|
2022-07-12 22:42:07 +08:00
|
|
|
{
|
2022-05-04 19:16:40 +02:00
|
|
|
ImGui::SetWindowSize({ 0.f, (float)*g_pointers->m_resolution_y }, ImGuiCond_Always);
|
|
|
|
|
2022-08-10 08:42:34 +08:00
|
|
|
if (ImGui::Checkbox("Preview", &g->spawn_vehicle.preview_vehicle))
|
2022-07-31 01:47:48 +08:00
|
|
|
{
|
2022-08-10 08:42:34 +08: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-08-10 08:42:34 +08:00
|
|
|
ImGui::Checkbox("Spawn In", &g->spawn_vehicle.spawn_inside);
|
2022-03-21 17:05:13 -04:00
|
|
|
ImGui::SameLine();
|
2022-08-10 08:42:34 +08:00
|
|
|
ImGui::Checkbox("Spawn Maxed", &g->spawn_vehicle.spawn_maxed);
|
2022-03-14 23:31:30 +01:00
|
|
|
|
2022-07-31 01:47:48 +08:00
|
|
|
static char plate_buf[9] = { 0 };
|
2022-08-10 08:42:34 +08: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);
|
2022-07-31 01:47:48 +08:00
|
|
|
components::input_text_with_hint("Plate", "Plate Number", plate_buf, sizeof(plate_buf), ImGuiInputTextFlags_None, [] {
|
2022-08-10 08:42:34 +08: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;
|
2022-07-19 18:19:19 +08:00
|
|
|
auto class_arr = g_gta_data_service->get_vehicle_class_arr();
|
2022-07-15 20:54:23 +08:00
|
|
|
|
|
|
|
ImGui::SetNextItemWidth(300.f);
|
|
|
|
if (ImGui::BeginCombo("Vehicle Class", selected_class == -1 ? "ALL" : class_arr[selected_class].c_str()))
|
|
|
|
{
|
|
|
|
if (ImGui::Selectable("ALL", selected_class == -1))
|
|
|
|
{
|
|
|
|
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);
|
2022-07-19 18:19:19 +08:00
|
|
|
components::input_text_with_hint("Model Name", "Search", search, sizeof(search), ImGuiInputTextFlags_None);
|
2022-07-10 06:33:14 +08:00
|
|
|
|
2022-07-28 01:42:15 +08:00
|
|
|
|
2022-08-10 08:42:34 +08: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;
|
|
|
|
|
|
|
|
g_fiber_pool->queue_job([] {
|
|
|
|
veh_hash = ENTITY::GET_ENTITY_MODEL(self::veh);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (veh_hash)
|
|
|
|
{
|
|
|
|
auto item = g_gta_data_service->find_vehicle_by_hash(veh_hash);
|
|
|
|
|
|
|
|
components::selectable("Current Vehicle [" + item.display_name + "]", false, [] {
|
|
|
|
if (self::veh)
|
|
|
|
{
|
2022-08-10 08:42:34 +08:00
|
|
|
Vector3 spawn_location = vehicle::get_spawn_location(g->spawn_vehicle.spawn_inside);
|
2022-07-28 01:42:15 +08:00
|
|
|
float spawn_heading = ENTITY::GET_ENTITY_HEADING(self::ped);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
g_notification_service->push_error("Vehicle", "Unable to spawn vehicle");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-10 08:42:34 +08: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-08-10 08:42:34 +08: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-08-10 08:42:34 +08: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([] {
|
2022-07-31 01:47:48 +08:00
|
|
|
g_model_preview_service->show_vehicle(
|
2022-07-28 01:42:15 +08:00
|
|
|
vehicle::get_owned_mods_from_vehicle(self::veh),
|
2022-08-10 08:42:34 +08:00
|
|
|
g->spawn_vehicle.spawn_maxed
|
2022-07-28 01:42:15 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-10 06:33:14 +08:00
|
|
|
|
2022-07-19 18:19:19 +08:00
|
|
|
auto item_arr = g_gta_data_service->get_vehicle_arr();
|
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
|
|
|
|
|
|
|
for (auto& item : item_arr) {
|
|
|
|
std::string display_name = item.display_name;
|
|
|
|
std::string display_manufacturer = item.display_manufacturer;
|
2022-07-15 20:54:23 +08:00
|
|
|
std::string clazz = item.clazz;
|
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);
|
|
|
|
|
2022-07-15 20:54:23 +08:00
|
|
|
if ((
|
|
|
|
selected_class == -1 || class_arr[selected_class] == clazz
|
|
|
|
) && (
|
2022-07-10 06:33:14 +08:00
|
|
|
display_name.find(lower_search) != std::string::npos ||
|
|
|
|
display_manufacturer.find(lower_search) != std::string::npos
|
2022-07-15 20:54:23 +08:00
|
|
|
)) {
|
2022-07-12 22:42:07 +08:00
|
|
|
ImGui::PushID(item.hash);
|
2022-07-10 06:33:14 +08:00
|
|
|
components::selectable(item.display_name, false, [item] {
|
|
|
|
|
2022-08-10 08:42:34 +08:00
|
|
|
Vector3 spawn_location = vehicle::get_spawn_location(g->spawn_vehicle.spawn_inside);
|
2022-07-10 06:33:14 +08:00
|
|
|
float spawn_heading = ENTITY::GET_ENTITY_HEADING(self::ped);
|
|
|
|
|
|
|
|
const Vehicle veh = vehicle::spawn(item.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
|
|
|
{
|
2022-07-28 01:42:15 +08:00
|
|
|
g_notification_service->push_error("Vehicle", "Unable to spawn vehicle");
|
2022-03-21 17:05:13 -04:00
|
|
|
}
|
2022-07-28 01:42:15 +08:00
|
|
|
else
|
|
|
|
{
|
2022-08-10 08:42:34 +08: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-08-10 08:42:34 +08: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-08-10 08:42:34 +08: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-08-10 08:42:34 +08:00
|
|
|
g_model_preview_service->show_vehicle(item.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
|
|
|
|
{
|
|
|
|
ImGui::Text("No vehicles in registry.");
|
|
|
|
}
|
2022-05-23 06:38:45 +08:00
|
|
|
ImGui::ListBoxFooter();
|
2022-02-28 23:04:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|