feat(Players): Added friends again

This commit is contained in:
Yimura 2022-02-21 00:55:21 +01:00
parent accabcdfa1
commit b9f61c522b
5 changed files with 66 additions and 1 deletions

View File

@ -13,10 +13,23 @@ namespace big
ImGui::SetNextWindowPos({ g.window.x - width, height_correction }, ImGuiCond_Always);
if (g.window.users && ImGui::Begin("###player_menu", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav))
{
ImGui::Text("Friends:");
for (auto& item : g_player_service->m_players)
{
std::unique_ptr<player>& plyr = item.second;
if (ImGui::Button(plyr->get_name(), { ImGui::GetWindowSize().x - 15.f, 0.f }))
if (plyr->is_friend() && ImGui::Button(plyr->get_name(), { ImGui::GetWindowSize().x - 15.f, 0.f }))
{
g_player_service->set_selected(plyr.get());
g.window.player = true;
}
}
ImGui::Text("Players:");
for (auto& item : g_player_service->m_players)
{
std::unique_ptr<player>& plyr = item.second;
if (!plyr->is_friend() && ImGui::Button(plyr->get_name(), { ImGui::GetWindowSize().x - 15.f, 0.f }))
{
g_player_service->set_selected(plyr.get());

View File

@ -0,0 +1,25 @@
#include "friends_service.hpp"
#include "pointers.hpp"
namespace big
{
friends_service::friends_service()
{
g_friends_service = this;
}
friends_service::~friends_service()
{
g_friends_service = nullptr;
}
bool friends_service::is_friend(const std::unique_ptr<player>& plyr)
{
const std::uint64_t rockstar_id = plyr->get_net_data()->m_rockstar_id2;
for (std::uint32_t i = 0; i < g_pointers->m_friend_registry->m_friend_count; i++)
if (rockstar_id == g_pointers->m_friend_registry->m_friends_list->m_data[i].m_rockstar_id)
return true;
return false;
}
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "player_service.hpp"
namespace big
{
class friends_service final
{
public:
friends_service();
virtual ~friends_service();
static bool is_friend(const std::unique_ptr<player>& plyr);
};
inline friends_service* g_friends_service{};
}

View File

@ -1,4 +1,5 @@
#include "gta_util.hpp"
#include "friends_service.hpp"
#include "player_service.hpp"
#include "util/notify.hpp"
@ -58,6 +59,12 @@ namespace big
return m_net_game_player == nullptr ? false : m_net_game_player->is_host();
}
bool player::is_friend()
{
return m_is_friend;
}
bool player::is_valid()
{
return m_net_game_player == nullptr ? false : m_net_game_player->is_valid();
@ -85,6 +92,7 @@ namespace big
if (CNetGamePlayer* net_game_player = network_player_mgr->m_player_list[i]; net_game_player != nullptr)
{
std::unique_ptr<player> plyr = std::make_unique<player>(net_game_player);
plyr->m_is_friend = friends_service::is_friend(plyr);
m_players.emplace(
plyr->to_lowercase_identifier(),
@ -132,6 +140,7 @@ namespace big
notify::player_joined(net_game_player);
std::unique_ptr<player> plyr = std::make_unique<player>(net_game_player);
plyr->m_is_friend = friends_service::is_friend(plyr);
m_players.emplace(
plyr->to_lowercase_identifier(),

View File

@ -9,6 +9,7 @@ namespace big
CNetGamePlayer* m_net_game_player = nullptr;
std::string m_identifier;
bool m_is_friend;
public:
player(CNetGamePlayer* net_game_player);
@ -23,6 +24,7 @@ namespace big
uint8_t id();
bool is_friend();
bool is_host();
bool is_valid();