fix(PlayerList): remove icon clutter (#480)

This commit is contained in:
Yimura 2022-10-19 22:00:53 +02:00 committed by GitHub
parent 6489969c6f
commit b0c2b1db40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 38 deletions

View File

@ -3,11 +3,11 @@
extern const unsigned char font_storopia[89888]; extern const unsigned char font_storopia[89888];
extern const unsigned char font_icons[7880]; extern const unsigned char font_icons[7880];
#define FONT_ICON_FRIEND "A" constexpr auto FONT_ICON_FRIEND = "A";
#define FONT_ICON_NOTFRIEND "B" constexpr auto FONT_ICON_NOTFRIEND = "B";
#define FONT_ICON_CLIENT "C" constexpr auto FONT_ICON_CLIENT = "C";
#define FONT_ICON_HOST "D" constexpr auto FONT_ICON_HOST = "D";
#define FONT_ICON_VEHICLE "E" constexpr auto FONT_ICON_VEHICLE = "E";
#define FONT_ICON_WALK "F" constexpr auto FONT_ICON_WALK = "F";

View File

@ -14,44 +14,34 @@ namespace big
{ {
static void player_button(const player_ptr& plyr) static void player_button(const player_ptr& plyr)
{ {
bool playerSelected = plyr == g_player_service->get_selected(); bool selected_player = plyr == g_player_service->get_selected();
bool isHost = false;
bool isFriend = false;
bool isInVehicle = false;
if (plyr->is_valid()) {
isHost = plyr->is_host();
isFriend = plyr->is_friend();
isInVehicle = (plyr->get_ped() != nullptr) &&
(plyr->get_ped()->m_ped_task_flag & (uint8_t)ePedTask::TASK_DRIVING);
}
// generate icons string // generate icons string
std::string playerIcons = std::string(isHost ? FONT_ICON_HOST : FONT_ICON_CLIENT) + std::string player_icons;
std::string(isFriend ? FONT_ICON_FRIEND : FONT_ICON_NOTFRIEND) + if (plyr->is_host())
std::string(isInVehicle ? FONT_ICON_VEHICLE : FONT_ICON_WALK); player_icons += FONT_ICON_HOST;
if (plyr->is_friend())
const char* playerIconsCStr = playerIcons.c_str(); player_icons += FONT_ICON_FRIEND;
if (const auto ped = plyr->get_ped(); ped != nullptr && ped->m_ped_task_flag & (uint8_t)ePedTask::TASK_DRIVING)
player_icons += FONT_ICON_VEHICLE;
const auto player_iconsc = player_icons.c_str();
const auto player_icons_end = player_iconsc + player_icons.size();
// calculate icons width // calculate icons width
ImGuiWindow* window = ImGui::GetCurrentWindow(); const auto window = ImGui::GetCurrentWindow();
ImGui::PushFont(g->window.font_icon); ImGui::PushFont(g->window.font_icon);
ImVec2 iconsSize = ImGui::CalcTextSize(playerIconsCStr, playerIconsCStr + playerIcons.size()); const auto icons_size = ImGui::CalcTextSize(player_iconsc, player_icons_end);
ImVec2 iconsPos(window->DC.CursorPos.x + 300.0f - 32.0f - iconsSize.x, window->DC.CursorPos.y + 2.0f); const ImVec2 icons_pos(window->DC.CursorPos.x + 300.0f - 32.0f - icons_size.x, window->DC.CursorPos.y + 2.0f);
ImRect iconsBox(iconsPos, iconsPos + iconsSize); const ImRect icons_box(icons_pos, icons_pos + icons_size);
ImGui::PopFont(); ImGui::PopFont();
if (selected_player)
if (playerSelected)
{
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.29f, 0.45f, 0.69f, 1.f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.29f, 0.45f, 0.69f, 1.f));
}
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, { 0.0, 0.5 }); ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, { 0.0, 0.5 });
ImGui::PushID(plyr->id()); ImGui::PushID(plyr->id());
if (ImGui::Button(plyr->get_name(), {300.0f - 15.0f - ImGui::GetStyle().ScrollbarSize, 0.f})) if (ImGui::Button(plyr->get_name(), { 300.0f - ImGui::GetStyle().ScrollbarSize, 0.f }))
{ {
g_player_service->set_selected(plyr); g_player_service->set_selected(plyr);
g_gui_service->set_selected(tabs::PLAYER); g_gui_service->set_selected(tabs::PLAYER);
@ -60,18 +50,20 @@ namespace big
ImGui::PopID(); ImGui::PopID();
ImGui::PopStyleVar(); ImGui::PopStyleVar();
if (playerSelected) if (selected_player)
ImGui::PopStyleColor(); ImGui::PopStyleColor();
// render icons on top of the player button // render icons on top of the player button
ImGui::PushFont(g->window.font_icon); ImGui::PushFont(g->window.font_icon);
ImGui::RenderTextWrapped(iconsBox.Min, playerIconsCStr, playerIconsCStr + playerIcons.size(), iconsSize.x); ImGui::RenderTextWrapped(icons_box.Min, player_iconsc, player_icons_end, icons_size.x);
ImGui::PopFont(); ImGui::PopFont();
} }
void view::players() void view::players()
{ {
if (!*g_pointers->m_is_session_started) return; const auto player_count = g_player_service->players().size() + 1;
if (!*g_pointers->m_is_session_started && player_count < 2) 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; 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;
ImGui::SetNextWindowSize({ 300.f, 0.f }); ImGui::SetNextWindowSize({ 300.f, 0.f });
@ -80,8 +72,6 @@ namespace big
if (ImGui::Begin("playerlist", nullptr, window_flags)) if (ImGui::Begin("playerlist", nullptr, window_flags))
{ {
const auto player_count = g_player_service->players().size() + 1;
float window_height = (ImGui::CalcTextSize("A").y + ImGui::GetStyle().ItemInnerSpacing.y * 2 + 6.0f) * player_count + 10.0f; float window_height = (ImGui::CalcTextSize("A").y + ImGui::GetStyle().ItemInnerSpacing.y * 2 + 6.0f) * player_count + 10.0f;
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; 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;
@ -92,7 +82,8 @@ namespace big
{ {
player_button(g_player_service->get_self()); player_button(g_player_service->get_self());
ImGui::Separator(); if (player_count > 1)
ImGui::Separator();
for (const auto& [_, player] : g_player_service->players()) for (const auto& [_, player] : g_player_service->players())
player_button(player); player_button(player);