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 3fca488876
commit 8626bf2184
8 changed files with 141 additions and 118 deletions

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();
}
}