From 73ca5da694508f9e17f9d32249c54551af4c8e79 Mon Sep 17 00:00:00 2001 From: CringeArab Date: Mon, 24 Jun 2024 21:27:16 +0300 Subject: [PATCH] Filters to the player database (#3268) --- .../player_database_service.cpp | 10 +++-- .../player_database_service.hpp | 2 +- src/views/network/view_player_database.cpp | 38 ++++++++++++++++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/services/player_database/player_database_service.cpp b/src/services/player_database/player_database_service.cpp index 04715951..b64b1ba0 100644 --- a/src/services/player_database/player_database_service.cpp +++ b/src/services/player_database/player_database_service.cpp @@ -219,11 +219,13 @@ namespace big return player; } - void player_database_service::remove_untrusted_players() + void player_database_service::remove_filtered_players(bool filter_modder, bool filter_trust, bool filter_block_join, bool filter_track_player) { for (auto it = m_players.begin(); it != m_players.end();) { - if (!it->second->is_trusted) + auto player = it->second; + if ((filter_modder && player->is_modder) || (filter_trust && player->is_trusted) + || (filter_block_join && player->block_join) || (filter_track_player && player->notify_online)) { it = m_players.erase(it); } @@ -235,7 +237,9 @@ namespace big for (auto it = m_sorted_players.begin(); it != m_sorted_players.end();) { - if (!it->second->is_trusted) + auto player = it->second; + if ((filter_modder && player->is_modder) || (filter_trust && player->is_trusted) + || (filter_block_join && player->block_join) || (filter_track_player && player->notify_online)) { it = m_sorted_players.erase(it); } diff --git a/src/services/player_database/player_database_service.hpp b/src/services/player_database/player_database_service.hpp index f8407740..8ccea2fc 100644 --- a/src/services/player_database/player_database_service.hpp +++ b/src/services/player_database/player_database_service.hpp @@ -47,7 +47,7 @@ namespace big std::map>& get_sorted_players(); std::shared_ptr get_player_by_rockstar_id(uint64_t rockstar_id); std::shared_ptr get_or_create_player(player_ptr player); - void remove_untrusted_players(); + void remove_filtered_players(bool filter_modder, bool filter_trust, bool filter_block_join, bool filter_track_player); void update_rockstar_id(uint64_t old, uint64_t _new); void remove_rockstar_id(uint64_t rockstar_id); diff --git a/src/views/network/view_player_database.cpp b/src/views/network/view_player_database.cpp index 6a4847e6..d2f7d9a5 100644 --- a/src/views/network/view_player_database.cpp +++ b/src/views/network/view_player_database.cpp @@ -17,6 +17,10 @@ namespace big char note_buffer[1024]; bool notes_dirty = false; std::shared_ptr current_player; + bool filter_modder = false; + bool filter_trust = false; + bool filter_block_join = false; + bool filter_track_player = false; ImVec4 get_player_color(persistent_player& player) { @@ -30,12 +34,25 @@ namespace big return ImVec4(0.f, 1.f, 0.f, 1.f); } - void draw_player_db_entry(std::shared_ptr player, const std::string& lower_search) + bool apply_filters(const std::shared_ptr& player) + { + if (filter_modder && !player->is_modder) + return false; + if (filter_trust && !player->is_trusted) + return false; + if (filter_block_join && !player->block_join) + return false; + if (filter_track_player && !player->notify_online) + return false; + return true; + } + + void draw_player_db_entry(const std::shared_ptr& player, const std::string& lower_search) { std::string name = player->name; std::transform(name.begin(), name.end(), name.begin(), ::tolower); - if (lower_search.empty() || name.find(lower_search) != std::string::npos) + if ((lower_search.empty() || name.find(lower_search) != std::string::npos) && apply_filters(player)) { ImGui::PushID(player->rockstar_id); @@ -281,19 +298,19 @@ namespace big ImGui::EndChild(); } - if (ImGui::Button("REMOVE_UNTRUSTED"_T.data())) + if (ImGui::Button("REMOVE_FILTERED"_T.data())) { - ImGui::OpenPopup("##removeuntrusted"); + ImGui::OpenPopup("##removefiltered"); } - if (ImGui::BeginPopupModal("##removeuntrusted")) + if (ImGui::BeginPopupModal("##removefiltered")) { ImGui::Text("VIEW_NET_PLAYER_DB_ARE_YOU_SURE"_T.data()); if (ImGui::Button("YES"_T.data())) { g_player_database_service->set_selected(nullptr); - g_player_database_service->remove_untrusted_players(); + g_player_database_service->remove_filtered_players(filter_modder, filter_trust, filter_block_join, filter_track_player); g_player_database_service->save(); ImGui::CloseCurrentPopup(); } @@ -355,6 +372,15 @@ namespace big ImGui::Checkbox("VIEW_NET_PLAYER_DB_NOTIFY_MISSION_CHANGE"_T.data(), &g.player_db.notify_on_mission_change); ImGui::TreePop(); } + if (ImGui::TreeNode("VIEW_NET_PLAYER_DB_FILTERS"_T.data())) + { + ImGui::Checkbox("IS_MODDER"_T.data(), &filter_modder); + ImGui::Checkbox("TRUST"_T.data(), &filter_trust); + ImGui::Checkbox("BLOCK_JOIN"_T.data(), &filter_block_join); + ImGui::Checkbox("VIEW_NET_PLAYER_DB_TRACK_PLAYER"_T.data(), &filter_track_player); + + ImGui::TreePop(); + } ImGui::Separator(); components::sub_title("NEW_ENTRY"_T);