feat(Gui): Improved playerlist. (#317)
This commit is contained in:
@ -9,9 +9,9 @@ namespace big
|
||||
|
||||
static float alpha = 1.f;
|
||||
|
||||
ImGui::SetNextWindowPos({ 250.f + 20.f, 100.f }, ImGuiCond_Always);
|
||||
ImGui::SetNextWindowPos({ 300.f + 20.f, 100.f }, ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize({ 0.f, 0.f });
|
||||
ImGui::SetNextWindowSizeConstraints({ 250.f, 100.f }, { (float)*g_pointers->m_resolution_x - 270.f, (float)*g_pointers->m_resolution_y - 110.f });
|
||||
ImGui::SetNextWindowSizeConstraints({ 300.f, 100.f }, { (float)*g_pointers->m_resolution_x - 270.f, (float)*g_pointers->m_resolution_y - 110.f });
|
||||
if (ImGui::Begin("main", nullptr, window_flags))
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha);
|
||||
|
@ -4,7 +4,7 @@ namespace big
|
||||
{
|
||||
void view::heading()
|
||||
{
|
||||
ImGui::SetNextWindowSize({ 250.f, 80.f });
|
||||
ImGui::SetNextWindowSize({ 300.f, 80.f });
|
||||
ImGui::SetNextWindowPos({ 10.f, 10.f });
|
||||
if (ImGui::Begin("menu_heading", nullptr, window_flags | ImGuiWindowFlags_NoScrollbar))
|
||||
{
|
||||
@ -15,7 +15,7 @@ namespace big
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::EndGroup();
|
||||
ImGui::SameLine();
|
||||
ImGui::SetCursorPos({ 250.f - ImGui::CalcTextSize("Unload").x - ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().WindowPadding.y / 2 + ImGui::GetStyle().ItemSpacing.y + (ImGui::CalcTextSize("W").y / 2) });
|
||||
ImGui::SetCursorPos({ 300.f - ImGui::CalcTextSize("Unload").x - ImGui::GetStyle().ItemSpacing.x, ImGui::GetStyle().WindowPadding.y / 2 + ImGui::GetStyle().ItemSpacing.y + (ImGui::CalcTextSize("W").y / 2) });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.69f, 0.29f, 0.29f, 1.00f));
|
||||
if (components::nav_button("Unload"))
|
||||
{
|
||||
|
@ -5,7 +5,7 @@ namespace big
|
||||
{
|
||||
void view::navigation() {
|
||||
ImGui::SetNextWindowPos({ 10.f, 100.f }, ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize({ 250.f, 0.f }, ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize({ 300.f, 0.f }, ImGuiCond_Always);
|
||||
|
||||
if (ImGui::Begin("navigation", 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav))
|
||||
{
|
||||
|
@ -2,44 +2,90 @@
|
||||
#include "services/gui/gui_service.hpp"
|
||||
#include "services/players/player_service.hpp"
|
||||
#include "views/view.hpp"
|
||||
#include "fonts/fonts.hpp"
|
||||
#include <renderer.hpp>
|
||||
#include <natives.hpp>
|
||||
|
||||
#define IMGUI_DEFINE_PLACEMENT_NEW
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include <imgui_internal.h>
|
||||
#include "fiber_pool.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
static void player_button(const player_ptr& plyr)
|
||||
{
|
||||
if (plyr->is_host())
|
||||
bool playerSelected = 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_current_vehicle() != nullptr;
|
||||
}
|
||||
|
||||
// generate icons string
|
||||
std::string playerIcons = std::string(isHost ? FONT_ICON_HOST : FONT_ICON_CLIENT) +
|
||||
std::string(isFriend ? FONT_ICON_FRIEND : FONT_ICON_NOTFRIEND) +
|
||||
std::string(isInVehicle ? FONT_ICON_VEHICLE : FONT_ICON_WALK);
|
||||
|
||||
const char* playerIconsCStr = playerIcons.c_str();
|
||||
|
||||
|
||||
// calculate icons width
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
ImGui::PushFont(g_renderer->m_font_icons);
|
||||
ImVec2 iconsSize = ImGui::CalcTextSize(playerIconsCStr, playerIconsCStr + playerIcons.size());
|
||||
ImVec2 iconsPos(window->DC.CursorPos.x + 300.0f - 32.0f - iconsSize.x, window->DC.CursorPos.y + 2.0f);
|
||||
ImRect iconsBox(iconsPos, iconsPos + iconsSize);
|
||||
ImGui::PopFont();
|
||||
|
||||
|
||||
if (playerSelected)
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.29f, 0.45f, 0.69f, 1.f));
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, { 0.0, 0.5 });
|
||||
ImGui::PushID(plyr->id());
|
||||
if (ImGui::Button(plyr->get_name(), {ImGui::GetWindowSize().x - 15.f, 0.f}))
|
||||
if (ImGui::Button(plyr->get_name(), { 300.0f - 15.0f - ImGui::GetStyle().ScrollbarSize, 0.f }))
|
||||
{
|
||||
g_player_service->set_selected(plyr);
|
||||
g_gui_service->set_selected(tabs::PLAYER);
|
||||
g->window.switched_view = true;
|
||||
}
|
||||
ImGui::PopID();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (plyr->is_host())
|
||||
if (playerSelected)
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
// render icons on top of the player button
|
||||
ImGui::PushFont(g_renderer->m_font_icons);
|
||||
ImGui::RenderTextWrapped(iconsBox.Min, playerIconsCStr, playerIconsCStr + playerIcons.size(), iconsSize.x);
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
ImGui::SetNextWindowSize({ 250.f, 0.f });
|
||||
ImGui::SetNextWindowSize({ 300.f, 0.f });
|
||||
ImGui::SetNextWindowPos({ 10.f, window_pos });
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 2.0f, 2.0f });
|
||||
|
||||
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 + 8.5f) * player_count;
|
||||
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;
|
||||
|
||||
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 }))
|
||||
if (ImGui::BeginListBox("##players", { ImGui::GetWindowSize().x - ImGui::GetStyle().WindowPadding.x * 2 , window_height }))
|
||||
{
|
||||
player_button(g_player_service->get_self());
|
||||
|
||||
@ -52,6 +98,8 @@ namespace big
|
||||
}
|
||||
ImGui::PopStyleColor(2);
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user