feat(PlayerList): Show self at the top, separated by a divider (#271)

Additionally I redesigned how the player service worked.

Co-authored-by: Yimura <andreas.maerten@scarlet.be>
This commit is contained in:
mentolixite
2022-06-24 19:48:03 +02:00
committed by GitHub
parent 2e57cd273f
commit 340e743e65
8 changed files with 141 additions and 118 deletions

View File

@ -1,10 +1,9 @@
#include "view_esp.hpp"
#include "gta_util.hpp"
#include "pointers.hpp"
#include "services/player_service.hpp"
#include "util/math.hpp"
#include "gta_util.hpp"
#include "util/misc.hpp"
#include "services/context_menu_service.hpp"
namespace big
{
@ -24,16 +23,14 @@ namespace big
if (const auto draw_list = ImGui::GetBackgroundDrawList(); draw_list)
{
for (auto& item : g_player_service->m_players)
for (const auto& [_, plyr] : g_player_service->players())
{
const std::unique_ptr<player>& plyr = item.second;
if (g->esp.hide_self && plyr->id() == gta_util::get_network_player_mgr()->m_local_net_player->m_player_id ||
!plyr->is_valid() ||
!plyr->get_ped() ||
!plyr->get_ped()->m_navigation) continue;
rage::fvector3& player_pos = plyr->get_ped()->m_navigation->m_position;
auto& player_pos = plyr->get_ped()->m_navigation->m_position;
float screen_x, screen_y;
@ -49,9 +46,9 @@ namespace big
const float esp_x = (float)*g_pointers->m_resolution_x * screen_x;
const float esp_y = (float)*g_pointers->m_resolution_y * screen_y;
const float esp_side_x = esp_x + (67.5f * multplr);
// const float esp_side_x = esp_x + (67.5f * multplr); // unused?
std::string name_str = "";
std::string name_str;
ImVec2 name_pos = { esp_x - (62.5f * multplr), esp_y - (175.f * multplr) - 20.f };
ImU32 esp_color = g->esp.default_color;

View File

@ -3,6 +3,22 @@
namespace big
{
static void player_button(const player_ptr& plyr)
{
if (plyr->is_host())
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.29f, 0.45f, 0.69f, 1.f));
if (ImGui::Button(plyr->get_name(), { ImGui::GetWindowSize().x - 15.f, 0.f }))
{
g_player_service->set_selected(plyr);
g_gui_service->set_selected(tabs::PLAYER);
g->window.switched_view = true;
}
if (plyr->is_host())
ImGui::PopStyleColor();
}
void view::players()
{
float window_pos = 110.f + g_gui_service->nav_ctr * ImGui::CalcTextSize("W").y + g_gui_service->nav_ctr * ImGui::GetStyle().ItemSpacing.y + g_gui_service->nav_ctr * ImGui::GetStyle().ItemInnerSpacing.y + ImGui::GetStyle().WindowPadding.y;
@ -11,34 +27,30 @@ namespace big
ImGui::SetNextWindowPos({ 10.f, window_pos });
if (ImGui::Begin("playerlist", nullptr, window_flags))
{
const auto player_count = g_player_service->m_players.size();
float window_height = (ImGui::CalcTextSize("A").y + ImGui::GetStyle().ItemInnerSpacing.y * 2 + 6.5f) * player_count;
const auto player_count = g_player_service->players().size() + 1;
window_height = window_height + window_pos > (float)*g_pointers->m_resolution_y - 10.f ? (float)*g_pointers->m_resolution_y - (window_pos + 40.f) : window_height;
// https://github.com/ocornut/imgui/issues/4399
float window_height = 1.f;
window_height += (ImGui::CalcTextSize("A").y + ImGui::GetStyle().ItemInnerSpacing.y * 2 + 6.5f) * player_count;
window_height += window_pos > (float)*g_pointers->m_resolution_y - 10.f ? (float)*g_pointers->m_resolution_y - (window_pos + 40.f) : 0;
ImGui::PushStyleColor(ImGuiCol_FrameBg, { 0.f, 0.f, 0.f, 0.f });
ImGui::PushStyleColor(ImGuiCol_ScrollbarBg, { 0.f, 0.f, 0.f, 0.f });
if (ImGui::BeginListBox("##players", { 250.f - ImGui::GetStyle().WindowPadding.x * 2 , window_height })) {
for (auto& item : g_player_service->m_players)
{
const auto& plyr = item.second;
if (plyr->is_host())
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.29f, 0.45f, 0.69f, 1.f));
if (ImGui::Button(plyr->get_name(), { ImGui::GetWindowSize().x - 15.f, 0.f }))
{
g_player_service->set_selected(plyr.get());
g_gui_service->set_selected(tabs::PLAYER);
g->window.switched_view = true;
}
if (plyr->is_host())
ImGui::PopStyleColor();
}
if (ImGui::BeginListBox("##players", { 250.f - ImGui::GetStyle().WindowPadding.x * 2 , window_height }))
{
player_button(g_player_service->get_self());
ImGui::Separator();
for (const auto& [_, player] : g_player_service->players())
player_button(player);
ImGui::EndListBox();
}
ImGui::PopStyleColor(2);
ImGui::End();
}
ImGui::End();
}
}