2022-02-28 23:04:56 +01:00
|
|
|
#include "views/view.hpp"
|
|
|
|
#include "fiber_pool.hpp"
|
|
|
|
#include "natives.hpp"
|
2022-06-30 00:11:54 +02:00
|
|
|
#include "services/vehicle_preview/vehicle_preview_service.hpp"
|
2022-02-28 23:04:56 +01:00
|
|
|
#include "util/vehicle.hpp"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2022-07-12 22:42:07 +08:00
|
|
|
void view::spawn()
|
|
|
|
{
|
2022-05-04 19:16:40 +02:00
|
|
|
ImGui::SetWindowSize({ 0.f, (float)*g_pointers->m_resolution_y }, ImGuiCond_Always);
|
|
|
|
|
2022-03-14 23:31:30 +01:00
|
|
|
ImGui::Checkbox("Preview", &g->spawn.preview_vehicle);
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::Checkbox("Spawn In", &g->spawn.spawn_inside);
|
2022-03-21 17:05:13 -04:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::Checkbox("Spawn Maxed", &g->spawn.spawn_maxed);
|
2022-03-14 23:31:30 +01:00
|
|
|
|
2022-07-10 06:33:14 +08:00
|
|
|
static char plate[9] = { 0 };
|
|
|
|
strncpy(plate, g->spawn.plate.c_str(), 9);
|
2022-05-23 06:38:45 +08:00
|
|
|
|
2022-07-10 06:33:14 +08:00
|
|
|
ImGui::SetNextItemWidth(300.f);
|
|
|
|
components::input_text_with_hint("Plate", "Plate Number", plate, sizeof(plate), ImGuiInputTextFlags_None, [] {
|
|
|
|
g->spawn.plate = plate;
|
|
|
|
});
|
2022-03-14 23:31:30 +01:00
|
|
|
|
2022-07-10 06:33:14 +08:00
|
|
|
static char search[64];
|
|
|
|
static std::string lower_search;
|
2022-03-21 17:05:13 -04:00
|
|
|
|
2022-07-10 06:33:14 +08:00
|
|
|
ImGui::SetNextItemWidth(300.f);
|
|
|
|
components::input_text_with_hint("Model Name", "Search", search, sizeof(search), ImGuiInputTextFlags_None, [] {
|
|
|
|
lower_search = search;
|
|
|
|
std::transform(lower_search.begin(), lower_search.end(), lower_search.begin(), tolower);
|
2022-03-14 23:31:30 +01:00
|
|
|
});
|
2022-07-10 06:33:14 +08:00
|
|
|
|
2022-06-26 00:31:51 +02:00
|
|
|
// arbitrary subtraction this looked nice so idc, works for all resolutions as well
|
2022-07-10 06:33:14 +08:00
|
|
|
if (ImGui::ListBoxHeader("###vehicles", { 300, static_cast<float>(*g_pointers->m_resolution_y - 184 - 38 * 3) }))
|
2022-02-28 23:04:56 +01:00
|
|
|
{
|
2022-07-10 06:33:14 +08:00
|
|
|
|
|
|
|
auto item_arr = g_vehicle_preview_service->get_vehicle_preview_item_arr();
|
|
|
|
|
|
|
|
if (item_arr.size() > 0)
|
2022-03-14 23:31:30 +01:00
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
std::transform(display_name.begin(), display_name.end(), display_name.begin(), ::tolower);
|
|
|
|
std::transform(display_manufacturer.begin(), display_manufacturer.end(), display_manufacturer.begin(), ::tolower);
|
|
|
|
|
|
|
|
if (
|
|
|
|
display_name.find(lower_search) != std::string::npos ||
|
|
|
|
display_manufacturer.find(lower_search) != std::string::npos
|
|
|
|
) {
|
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] {
|
|
|
|
|
|
|
|
float y_offset = 0;
|
|
|
|
|
2022-07-12 22:42:07 +08:00
|
|
|
if (self::veh != 0)
|
2022-07-10 06:33:14 +08:00
|
|
|
{
|
|
|
|
y_offset = 10.f;
|
|
|
|
}
|
|
|
|
else if (!g->spawn.spawn_inside)
|
|
|
|
{
|
|
|
|
y_offset = 5.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 spawn_location = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(self::ped, 0.f, y_offset, 0.f);
|
|
|
|
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
|
|
|
|
|
|
|
if (g->spawn.spawn_inside)
|
2022-03-21 17:05:13 -04:00
|
|
|
{
|
|
|
|
vehicle::telport_into_veh(veh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g->spawn.spawn_maxed)
|
|
|
|
{
|
|
|
|
vehicle::max_vehicle(veh);
|
|
|
|
}
|
|
|
|
|
2022-07-10 06:33:14 +08:00
|
|
|
vehicle::set_plate(veh, plate);
|
|
|
|
|
2022-03-31 01:34:36 +02:00
|
|
|
g_vehicle_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-03-14 23:31:30 +01:00
|
|
|
if (g->spawn.preview_vehicle && ImGui::IsItemHovered())
|
2022-07-10 06:33:14 +08:00
|
|
|
{
|
2022-03-14 23:31:30 +01:00
|
|
|
g_vehicle_preview_service->set_preview_vehicle(item);
|
2022-07-10 06:33:14 +08:00
|
|
|
}
|
2022-05-23 06:38:45 +08:00
|
|
|
else if (g->spawn.preview_vehicle && !ImGui::IsAnyItemHovered())
|
2022-07-10 06:33:14 +08:00
|
|
|
{
|
2022-05-23 06:38:45 +08:00
|
|
|
g_vehicle_preview_service->stop_preview();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|