Added filter vehicle by class feature. (#336)
This commit is contained in:
parent
320cdbec34
commit
4999c25e93
@ -14,6 +14,7 @@ namespace big
|
|||||||
this->name = "";
|
this->name = "";
|
||||||
this->display_name = "";
|
this->display_name = "";
|
||||||
this->display_manufacturer = "";
|
this->display_manufacturer = "";
|
||||||
|
this->clazz = "";
|
||||||
this->hash = 0;
|
this->hash = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ namespace big
|
|||||||
this->name = item_json["Name"];
|
this->name = item_json["Name"];
|
||||||
this->display_name = item_json["Name"];
|
this->display_name = item_json["Name"];
|
||||||
this->display_manufacturer = "";
|
this->display_manufacturer = "";
|
||||||
|
this->clazz = "";
|
||||||
this->hash = item_json["Hash"];
|
this->hash = item_json["Hash"];
|
||||||
|
|
||||||
if (!item_json["DisplayName"].is_null())
|
if (!item_json["DisplayName"].is_null())
|
||||||
@ -37,6 +39,16 @@ namespace big
|
|||||||
{
|
{
|
||||||
this->display_manufacturer = item_json["Manufacturer"];
|
this->display_manufacturer = item_json["Manufacturer"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!item_json["Class"].is_null())
|
||||||
|
{
|
||||||
|
this->clazz = item_json["Class"];
|
||||||
|
|
||||||
|
if (this->clazz == "COMPACTS")
|
||||||
|
{
|
||||||
|
this->clazz = "COMPACT";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vehicle_preview_service::vehicle_preview_service() :
|
vehicle_preview_service::vehicle_preview_service() :
|
||||||
@ -94,6 +106,11 @@ namespace big
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string>& vehicle_preview_service::get_vehicle_class_arr()
|
||||||
|
{
|
||||||
|
return m_vehicle_class_arr;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<vehicle_preview_item>& vehicle_preview_service::get_vehicle_preview_item_arr()
|
std::vector<vehicle_preview_item>& vehicle_preview_service::get_vehicle_preview_item_arr()
|
||||||
{
|
{
|
||||||
return m_vehicle_preview_item_arr;
|
return m_vehicle_preview_item_arr;
|
||||||
@ -189,6 +206,7 @@ namespace big
|
|||||||
LOG(WARNING) << "Failed to load vehicles.json:\n" << ex.what();
|
LOG(WARNING) << "Failed to load vehicles.json:\n" << ex.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (auto& item_json : all_vehicles)
|
for (auto& item_json : all_vehicles)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
@ -201,8 +219,18 @@ namespace big
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto item = vehicle_preview_item(item_json);
|
||||||
|
|
||||||
m_hash_idx_map[item_json["Hash"]] = (int)m_vehicle_preview_item_arr.size();
|
m_hash_idx_map[item_json["Hash"]] = (int)m_vehicle_preview_item_arr.size();
|
||||||
m_vehicle_preview_item_arr.push_back(vehicle_preview_item(item_json));
|
|
||||||
|
m_vehicle_preview_item_arr.push_back(item);
|
||||||
|
|
||||||
|
if (std::find(m_vehicle_class_arr.begin(), m_vehicle_class_arr.end(), item.clazz) == m_vehicle_class_arr.end())
|
||||||
|
{
|
||||||
|
m_vehicle_class_arr.push_back(item.clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(m_vehicle_class_arr.begin(), m_vehicle_class_arr.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ namespace big
|
|||||||
std::string name;
|
std::string name;
|
||||||
std::string display_name;
|
std::string display_name;
|
||||||
std::string display_manufacturer;
|
std::string display_manufacturer;
|
||||||
|
std::string clazz;
|
||||||
Hash hash;
|
Hash hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ namespace big
|
|||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
|
|
||||||
std::map<Hash, int> m_hash_idx_map;
|
std::map<Hash, int> m_hash_idx_map;
|
||||||
|
std::vector<std::string> m_vehicle_class_arr;
|
||||||
std::vector<vehicle_preview_item> m_vehicle_preview_item_arr;
|
std::vector<vehicle_preview_item> m_vehicle_preview_item_arr;
|
||||||
const vehicle_preview_item empty_item = vehicle_preview_item();
|
const vehicle_preview_item empty_item = vehicle_preview_item();
|
||||||
|
|
||||||
@ -37,6 +39,7 @@ namespace big
|
|||||||
~vehicle_preview_service();
|
~vehicle_preview_service();
|
||||||
|
|
||||||
const vehicle_preview_item& find_vehicle_item_by_hash(Hash hash);
|
const vehicle_preview_item& find_vehicle_item_by_hash(Hash hash);
|
||||||
|
std::vector<std::string>& get_vehicle_class_arr();
|
||||||
std::vector<vehicle_preview_item>& get_vehicle_preview_item_arr();
|
std::vector<vehicle_preview_item>& get_vehicle_preview_item_arr();
|
||||||
void set_preview_vehicle(const vehicle_preview_item& item);
|
void set_preview_vehicle(const vehicle_preview_item& item);
|
||||||
|
|
||||||
|
@ -16,12 +16,12 @@ namespace big
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
static char plate[9] = { 0 };
|
static char plate[9] = { 0 };
|
||||||
int num_of_rows = 2;
|
int num_of_rows = 3;
|
||||||
|
|
||||||
ImGui::Checkbox("Spawn Clone", &g->clone_pv.spawn_clone);
|
ImGui::Checkbox("Spawn Clone", &g->clone_pv.spawn_clone);
|
||||||
if (g->clone_pv.spawn_clone)
|
if (g->clone_pv.spawn_clone)
|
||||||
{
|
{
|
||||||
num_of_rows = 4;
|
num_of_rows = 5;
|
||||||
|
|
||||||
ImGui::Checkbox("Spawn Maxed", &g->clone_pv.spawn_maxed);
|
ImGui::Checkbox("Spawn Maxed", &g->clone_pv.spawn_maxed);
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ namespace big
|
|||||||
ImGui::Checkbox("Clone PV Plate", &g->clone_pv.clone_plate);
|
ImGui::Checkbox("Clone PV Plate", &g->clone_pv.clone_plate);
|
||||||
if (g->clone_pv.clone_plate)
|
if (g->clone_pv.clone_plate)
|
||||||
{
|
{
|
||||||
num_of_rows = 3;
|
num_of_rows = 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -42,6 +42,35 @@ namespace big
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int selected_class = -1;
|
||||||
|
auto class_arr = g_vehicle_preview_service->get_vehicle_class_arr();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char search[64];
|
static char search[64];
|
||||||
static std::string lower_search;
|
static std::string lower_search;
|
||||||
|
|
||||||
@ -61,22 +90,24 @@ namespace big
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
for (const auto& it : g_mobile_service->personal_vehicles())
|
for (const auto& it : g_mobile_service->personal_vehicles())
|
||||||
{
|
{
|
||||||
const auto& label = it.first;
|
const auto& label = it.first;
|
||||||
const auto& personal_veh = it.second;
|
const auto& personal_veh = it.second;
|
||||||
auto item = g_vehicle_preview_service->find_vehicle_item_by_hash(personal_veh->get_hash());
|
auto item = g_vehicle_preview_service->find_vehicle_item_by_hash(personal_veh->get_hash());
|
||||||
|
|
||||||
|
std::string clazz = item.clazz;
|
||||||
std::string display_name = label;
|
std::string display_name = label;
|
||||||
std::string display_manufacturer = item.display_manufacturer;
|
std::string display_manufacturer = item.display_manufacturer;
|
||||||
std::transform(display_name.begin(), display_name.end(), display_name.begin(), ::tolower);
|
std::transform(display_name.begin(), display_name.end(), display_name.begin(), ::tolower);
|
||||||
std::transform(display_manufacturer.begin(), display_manufacturer.end(), display_manufacturer.begin(), ::tolower);
|
std::transform(display_manufacturer.begin(), display_manufacturer.end(), display_manufacturer.begin(), ::tolower);
|
||||||
|
|
||||||
if (
|
if ((
|
||||||
|
selected_class == -1 || class_arr[selected_class] == clazz
|
||||||
|
) && (
|
||||||
display_name.find(lower_search) != std::string::npos ||
|
display_name.find(lower_search) != std::string::npos ||
|
||||||
display_manufacturer.find(lower_search) != std::string::npos
|
display_manufacturer.find(lower_search) != std::string::npos
|
||||||
) {
|
)) {
|
||||||
ImGui::PushID('v' << 24 & personal_veh->get_id());
|
ImGui::PushID('v' << 24 & personal_veh->get_id());
|
||||||
|
|
||||||
components::selectable(label, false, [&personal_veh] {
|
components::selectable(label, false, [&personal_veh] {
|
||||||
|
@ -24,6 +24,35 @@ namespace big
|
|||||||
g->spawn.plate = plate;
|
g->spawn.plate = plate;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
static int selected_class = -1;
|
||||||
|
auto class_arr = g_vehicle_preview_service->get_vehicle_class_arr();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char search[64];
|
static char search[64];
|
||||||
static std::string lower_search;
|
static std::string lower_search;
|
||||||
|
|
||||||
@ -34,7 +63,7 @@ namespace big
|
|||||||
});
|
});
|
||||||
|
|
||||||
// arbitrary subtraction this looked nice so idc, works for all resolutions as well
|
// arbitrary subtraction this looked nice so idc, works for all resolutions as well
|
||||||
if (ImGui::ListBoxHeader("###vehicles", { 300, static_cast<float>(*g_pointers->m_resolution_y - 184 - 38 * 3) }))
|
if (ImGui::ListBoxHeader("###vehicles", { 300, static_cast<float>(*g_pointers->m_resolution_y - 184 - 38 * 4) }))
|
||||||
{
|
{
|
||||||
|
|
||||||
auto item_arr = g_vehicle_preview_service->get_vehicle_preview_item_arr();
|
auto item_arr = g_vehicle_preview_service->get_vehicle_preview_item_arr();
|
||||||
@ -45,14 +74,17 @@ namespace big
|
|||||||
for (auto& item : item_arr) {
|
for (auto& item : item_arr) {
|
||||||
std::string display_name = item.display_name;
|
std::string display_name = item.display_name;
|
||||||
std::string display_manufacturer = item.display_manufacturer;
|
std::string display_manufacturer = item.display_manufacturer;
|
||||||
|
std::string clazz = item.clazz;
|
||||||
|
|
||||||
std::transform(display_name.begin(), display_name.end(), display_name.begin(), ::tolower);
|
std::transform(display_name.begin(), display_name.end(), display_name.begin(), ::tolower);
|
||||||
std::transform(display_manufacturer.begin(), display_manufacturer.end(), display_manufacturer.begin(), ::tolower);
|
std::transform(display_manufacturer.begin(), display_manufacturer.end(), display_manufacturer.begin(), ::tolower);
|
||||||
|
|
||||||
if (
|
if ((
|
||||||
|
selected_class == -1 || class_arr[selected_class] == clazz
|
||||||
|
) && (
|
||||||
display_name.find(lower_search) != std::string::npos ||
|
display_name.find(lower_search) != std::string::npos ||
|
||||||
display_manufacturer.find(lower_search) != std::string::npos
|
display_manufacturer.find(lower_search) != std::string::npos
|
||||||
) {
|
)) {
|
||||||
ImGui::PushID(item.hash);
|
ImGui::PushID(item.hash);
|
||||||
components::selectable(item.display_name, false, [item] {
|
components::selectable(item.display_name, false, [item] {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user