2023-03-01 21:27:15 +00:00
|
|
|
#include "fiber_pool.hpp"
|
|
|
|
#include "fonts/fonts.hpp"
|
|
|
|
#include "natives.hpp"
|
2022-06-30 00:11:54 +02:00
|
|
|
#include "pointers.hpp"
|
|
|
|
#include "services/gui/gui_service.hpp"
|
2023-06-10 14:47:19 +02:00
|
|
|
#include "services/player_database/player_database_service.hpp"
|
2022-06-30 00:11:54 +02:00
|
|
|
#include "services/players/player_service.hpp"
|
2022-05-04 19:16:40 +02:00
|
|
|
#include "views/view.hpp"
|
2022-07-06 00:56:32 +08:00
|
|
|
|
|
|
|
#define IMGUI_DEFINE_PLACEMENT_NEW
|
|
|
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
|
|
|
#include <imgui_internal.h>
|
2022-05-04 19:16:40 +02:00
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2022-06-24 19:48:03 +02:00
|
|
|
static void player_button(const player_ptr& plyr)
|
|
|
|
{
|
2022-10-19 22:00:53 +02:00
|
|
|
bool selected_player = plyr == g_player_service->get_selected();
|
2022-07-06 00:56:32 +08:00
|
|
|
|
|
|
|
// generate icons string
|
2022-10-19 22:00:53 +02:00
|
|
|
std::string player_icons;
|
|
|
|
if (plyr->is_host())
|
|
|
|
player_icons += FONT_ICON_HOST;
|
|
|
|
if (plyr->is_friend())
|
|
|
|
player_icons += FONT_ICON_FRIEND;
|
2023-07-05 07:30:06 +00:00
|
|
|
if (const auto ped = plyr->get_ped(); (ped != nullptr && ped->m_ped_task_flag & (uint8_t)ePedTask::TASK_DRIVING))
|
2022-10-19 22:00:53 +02:00
|
|
|
player_icons += FONT_ICON_VEHICLE;
|
2022-07-06 00:56:32 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
const auto player_iconsc = player_icons.c_str();
|
2022-10-19 22:00:53 +02:00
|
|
|
const auto player_icons_end = player_iconsc + player_icons.size();
|
2022-07-06 00:56:32 +08:00
|
|
|
|
|
|
|
// calculate icons width
|
2022-10-19 22:00:53 +02:00
|
|
|
const auto window = ImGui::GetCurrentWindow();
|
2022-12-18 23:15:52 +01:00
|
|
|
ImGui::PushFont(g.window.font_icon);
|
2022-10-19 22:00:53 +02:00
|
|
|
const auto icons_size = ImGui::CalcTextSize(player_iconsc, player_icons_end);
|
|
|
|
const ImVec2 icons_pos(window->DC.CursorPos.x + 300.0f - 32.0f - icons_size.x, window->DC.CursorPos.y + 2.0f);
|
|
|
|
const ImRect icons_box(icons_pos, icons_pos + icons_size);
|
2022-07-06 00:56:32 +08:00
|
|
|
ImGui::PopFont();
|
|
|
|
|
2023-04-06 13:55:28 -04:00
|
|
|
if (plyr->is_admin)
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.f, 0.67f, 0.f, 1.f));
|
|
|
|
else if (plyr->is_modder)
|
2022-11-19 01:49:36 +00:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.f, 0.1f, 0.1f, 1.f));
|
|
|
|
|
2022-10-19 22:00:53 +02:00
|
|
|
if (selected_player)
|
2022-06-24 19:48:03 +02:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.29f, 0.45f, 0.69f, 1.f));
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, {0.0, 0.5});
|
2022-07-02 20:55:37 +08:00
|
|
|
ImGui::PushID(plyr->id());
|
2023-03-01 21:27:15 +00:00
|
|
|
if (ImGui::Button(plyr->get_name(), {300.0f - ImGui::GetStyle().ScrollbarSize, 0.f}))
|
2022-06-24 19:48:03 +02:00
|
|
|
{
|
|
|
|
g_player_service->set_selected(plyr);
|
|
|
|
g_gui_service->set_selected(tabs::PLAYER);
|
2022-12-18 23:15:52 +01:00
|
|
|
g.window.switched_view = true;
|
2022-06-24 19:48:03 +02:00
|
|
|
}
|
2023-07-05 07:30:06 +00:00
|
|
|
if (ImGui::IsItemHovered()
|
|
|
|
&& g_player_database_service->get_player_by_rockstar_id(plyr->get_net_data()->m_gamer_handle.m_rockstar_id) != nullptr)
|
2023-06-10 14:47:19 +02:00
|
|
|
{
|
2023-07-05 07:30:06 +00:00
|
|
|
auto sorted_player =
|
|
|
|
g_player_database_service->get_player_by_rockstar_id(plyr->get_net_data()->m_gamer_handle.m_rockstar_id);
|
2023-06-10 14:47:19 +02:00
|
|
|
|
|
|
|
if (!sorted_player->infractions.empty())
|
|
|
|
{
|
|
|
|
ImGui::BeginTooltip();
|
|
|
|
for (auto infraction : sorted_player->infractions)
|
|
|
|
ImGui::BulletText(infraction_desc[(Infraction)infraction]);
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-02 20:55:37 +08:00
|
|
|
ImGui::PopID();
|
2022-07-06 00:56:32 +08:00
|
|
|
ImGui::PopStyleVar();
|
2022-06-24 19:48:03 +02:00
|
|
|
|
2022-10-19 22:00:53 +02:00
|
|
|
if (selected_player)
|
2022-06-24 19:48:03 +02:00
|
|
|
ImGui::PopStyleColor();
|
2022-07-06 00:56:32 +08:00
|
|
|
|
2023-04-06 13:55:28 -04:00
|
|
|
if (plyr->is_admin || plyr->is_modder)
|
2022-11-19 01:49:36 +00:00
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
2022-07-06 00:56:32 +08:00
|
|
|
// render icons on top of the player button
|
2022-12-18 23:15:52 +01:00
|
|
|
ImGui::PushFont(g.window.font_icon);
|
2022-10-19 22:00:53 +02:00
|
|
|
ImGui::RenderTextWrapped(icons_box.Min, player_iconsc, player_icons_end, icons_size.x);
|
2022-07-06 00:56:32 +08:00
|
|
|
ImGui::PopFont();
|
2022-06-24 19:48:03 +02:00
|
|
|
}
|
|
|
|
|
2022-05-04 19:16:40 +02:00
|
|
|
void view::players()
|
|
|
|
{
|
2022-10-19 22:00:53 +02:00
|
|
|
const auto player_count = g_player_service->players().size() + 1;
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
if (!*g_pointers->m_gta.m_is_session_started && player_count < 2)
|
2023-03-01 21:27:15 +00:00
|
|
|
return;
|
|
|
|
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;
|
2022-05-04 19:16:40 +02:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
ImGui::SetNextWindowSize({300.f, 0.f});
|
|
|
|
ImGui::SetNextWindowPos({10.f, window_pos});
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {2.0f, 2.0f});
|
2022-07-06 00:56:32 +08:00
|
|
|
|
2022-05-04 19:16:40 +02:00
|
|
|
if (ImGui::Begin("playerlist", nullptr, window_flags))
|
|
|
|
{
|
2022-07-06 00:56:32 +08:00
|
|
|
float window_height = (ImGui::CalcTextSize("A").y + ImGui::GetStyle().ItemInnerSpacing.y * 2 + 6.0f) * player_count + 10.0f;
|
2023-06-10 14:47:19 +02:00
|
|
|
window_height =
|
|
|
|
window_height + window_pos > (float)*g_pointers->m_gta.m_resolution_y - 10.f ? (float)*g_pointers->m_gta.m_resolution_y - (window_pos + 40.f) : window_height;
|
2022-05-04 19:16:40 +02:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, {0.f, 0.f, 0.f, 0.f});
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ScrollbarBg, {0.f, 0.f, 0.f, 0.f});
|
2022-06-24 19:48:03 +02:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
if (ImGui::BeginListBox("##players", {ImGui::GetWindowSize().x - ImGui::GetStyle().WindowPadding.x * 2, window_height}))
|
2022-06-24 19:48:03 +02:00
|
|
|
{
|
|
|
|
player_button(g_player_service->get_self());
|
|
|
|
|
2022-10-19 22:00:53 +02:00
|
|
|
if (player_count > 1)
|
|
|
|
ImGui::Separator();
|
2022-06-24 19:48:03 +02:00
|
|
|
|
|
|
|
for (const auto& [_, player] : g_player_service->players())
|
|
|
|
player_button(player);
|
2022-05-04 19:16:40 +02:00
|
|
|
|
|
|
|
ImGui::EndListBox();
|
|
|
|
}
|
|
|
|
ImGui::PopStyleColor(2);
|
|
|
|
}
|
2022-07-06 00:56:32 +08:00
|
|
|
|
|
|
|
ImGui::PopStyleVar();
|
2022-06-24 19:48:03 +02:00
|
|
|
ImGui::End();
|
2022-05-04 19:16:40 +02:00
|
|
|
}
|
|
|
|
}
|