From 0167556de5545dc34c22172fabe5464ce832111c Mon Sep 17 00:00:00 2001 From: Yimura Date: Sat, 8 Jan 2022 17:48:46 +0100 Subject: [PATCH] feat(PersonalVehicles): Alphabetic list --- BigBaseV2/src/gui/window/main/tab_mobile.cpp | 9 +++++---- BigBaseV2/src/services/mobile_service.cpp | 18 ++++++++++++++---- BigBaseV2/src/services/mobile_service.hpp | 3 ++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/BigBaseV2/src/gui/window/main/tab_mobile.cpp b/BigBaseV2/src/gui/window/main/tab_mobile.cpp index dd1cf871..b27e3ae1 100644 --- a/BigBaseV2/src/gui/window/main/tab_mobile.cpp +++ b/BigBaseV2/src/gui/window/main/tab_mobile.cpp @@ -53,16 +53,17 @@ namespace big { for (auto& it : g_mobile_service->m_personal_vehicles) { + std::string label = it.first; auto& personal_veh = it.second; - std::string lower = personal_veh.get_display_name().c_str(); + std::string lower = label.c_str(); std::transform(lower.begin(), lower.end(), lower.begin(), tolower); if (lower.find(lower_search) != std::string::npos) { if (ImGui::Selectable( - personal_veh.get_display_name().c_str(), - personal_veh.get_id() == mobile::util::get_current_personal_vehicle() + label.c_str(), + personal_veh->get_id() == mobile::util::get_current_personal_vehicle() )) { strcpy(search, ""); @@ -70,7 +71,7 @@ namespace big QUEUE_JOB_BEGIN_CLAUSE(&personal_veh) { - personal_veh.summon(); + personal_veh->summon(); }QUEUE_JOB_END_CLAUSE } } diff --git a/BigBaseV2/src/services/mobile_service.cpp b/BigBaseV2/src/services/mobile_service.cpp index ce3ed6a8..e7a6f837 100644 --- a/BigBaseV2/src/services/mobile_service.cpp +++ b/BigBaseV2/src/services/mobile_service.cpp @@ -56,10 +56,20 @@ namespace big Hash hash = *veh_idx_global.at(66).as(); if (STREAMING::IS_MODEL_A_VEHICLE(hash)) { - if (auto& it = m_personal_vehicles.find(i); it != m_personal_vehicles.end() && it->second.get_hash() != hash) - it->second = PersonalVehicle(i, veh_idx_global); - else - m_personal_vehicles.emplace(i, PersonalVehicle(i, veh_idx_global)); + auto veh = std::make_unique(i, veh_idx_global); + + if (auto& it = m_pv_lookup.find(i); it != m_pv_lookup.end()) + { + m_personal_vehicles.erase(it->second); + + it->second = veh->get_display_name(); + m_personal_vehicles.emplace(veh->get_display_name(), std::move(veh)); + + continue; + } + + m_pv_lookup.emplace(i, veh->get_display_name()); + m_personal_vehicles.emplace(veh->get_display_name(), std::move(veh)); } script::get_current()->yield(); diff --git a/BigBaseV2/src/services/mobile_service.hpp b/BigBaseV2/src/services/mobile_service.hpp index 70dde76d..5020b0f5 100644 --- a/BigBaseV2/src/services/mobile_service.hpp +++ b/BigBaseV2/src/services/mobile_service.hpp @@ -29,7 +29,8 @@ namespace big void register_vehicles(); - std::map m_personal_vehicles; + std::map> m_personal_vehicles; + std::map m_pv_lookup; };