Skip to content

Commit

Permalink
Hotfix: Kick and Block buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
FlavioFS committed Feb 24, 2023
1 parent 55e9a75 commit 4d8bb1a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 31 deletions.
3 changes: 1 addition & 2 deletions ParsecSoda/Widgets/ConfirmPopupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ bool ConfirmPopupWidget::render(const char * title, bool &showPopup)
AppStyle::pushTitle();
if (ImGui::BeginPopupModal(title, nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize))
{
ImGui::BeginChild(title, ImVec2(10, 40));
ImGui::EndChild();
ImGui::Dummy(ImVec2(10, 40));

ImGui::Indent(10);
if (IconButton::render(AppIcons::no, AppColors::negative, BUTTON_SIZE))
Expand Down
6 changes: 1 addition & 5 deletions ParsecSoda/Widgets/GamepadsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,12 @@ bool GamepadsWidget::render()

ImGui::Dummy(ImVec2(0, 5));
}
ImGui::PopStyleVar();
ImGui::PopStyleVar();
ImGui::PopStyleVar(4);

ImGui::PopStyleVar();
AppStyle::pop();
ImGui::End();
AppStyle::pop();

ImGui::PopStyleVar();


if (isConnectionButtonPressed)
{
Expand Down
61 changes: 39 additions & 22 deletions ParsecSoda/Widgets/GuestListWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GuestListWidget::GuestListWidget(Hosting& hosting)
bool GuestListWidget::render()
{
AppStyle::pushTitle();
ImGui::SetNextWindowSizeConstraints(ImVec2(300, 300), ImVec2(800, 900));
ImGui::SetNextWindowSizeConstraints(ImVec2(250, 300), ImVec2(800, 900));
ImGui::Begin("Guests", (bool*)0);
AppStyle::pushInput();

Expand Down Expand Up @@ -88,33 +88,28 @@ void GuestListWidget::renderOneOnlineGuest(Guest& guest, size_t index)
static GuestData guestData;
guestData = GuestData(guest.name, guest.userID);

Action enqueueKickAction = [&]() { _actionQueue.add([&]() {sendHostMessage("!kick", guest.userID); }); };
renderPopupButton("Kick", "!kick", guestData, showKickPopup, kickPopupTitle, AppIcons::kick, enqueueKickAction);

ImGui::SameLine();

Action enqueueBanAction = [&]() { _actionQueue.add([&]() {sendHostMessage("!ban", guest.userID); }); };
renderPopupButton("Ban", "!ban", guestData, showBanPopup, banPopupTitle, AppIcons::block, enqueueBanAction);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(1, 1));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(1, 1));

ImGui::Dummy(ImVec2(1, 5));

ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(1, 1));
ImGui::SameLine();
ImGui::PushID(("## Online guest " + to_string(index)).c_str());

// ===================
// Name and userID
// ===================
cursor = ImGui::GetCursorPos();
ImGui::BeginGroup();
AppStyle::pushLabel();
ImGui::TextWrapped("(# %d)\t", guest.userID);
ImGui::TextWrapped("# %d\t", guest.userID);
AppStyle::pop();
AppStyle::pushInput();
ImGui::TextWrapped(guest.name.c_str());
AppStyle::pop();
ImGui::Dummy(ImVec2(0.0f, 5.0f));
ImGui::EndGroup();
ImGui::SetCursorPos(cursor);
ImGui::Button((string("##") + to_string(index + 1)).c_str(), ImVec2(size.x - 45, 40));
ImGui::Button((string("##") + to_string(index + 1)).c_str(), ImVec2(size.x, 30));

if (ImGui::BeginDragDropSource())
{
Expand All @@ -133,22 +128,35 @@ void GuestListWidget::renderOneOnlineGuest(Guest& guest, size_t index)
ImGui::EndDragDropSource();
}

ImGui::Dummy(ImVec2(10.0f, 0.0f));
Action enqueueKickAction = [&]() { _actionQueue.add([&]() {sendHostMessage("!kick", guest.userID); }); };
renderPopupButton("Kick", "!kick", guestData, index, showKickPopup, kickPopupTitle, AppIcons::kick, enqueueKickAction);

ImGui::SameLine();

Action enqueueBanAction = [&]() { _actionQueue.add([&]() {sendHostMessage("!ban", guest.userID); }); };
renderPopupButton("Ban", "!ban", guestData, index, showBanPopup, banPopupTitle, AppIcons::block, enqueueBanAction);

ImGui::SameLine();
ImGui::Dummy(ImVec2(5, 0));
ImGui::SameLine();

// ===================
// Latency
// ===================
static ImVec4 latencyColor;
static const float TEXT_HEIGHT = ImGui::CalcTextSize("ms").y, BUTTON_HEIGHT = 20;
latencyColor = getLatencyColor(guest.metrics.getLatency());
AppStyle::pushInput();
AppColors::pushColor(latencyColor);
ImGui::AlignTextToFramePadding();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 0.5f * (BUTTON_HEIGHT - TEXT_HEIGHT));
ImGui::Text("%.0f ms", guest.metrics.getLatency());
renderGuestMetricsTooltip(guestData);
AppColors::pop();
AppStyle::pop();

ImGui::PopStyleVar();
ImGui::PopID();
ImGui::PopStyleVar(2);
}

void GuestListWidget::renderOneBannedGuest(GuestData& guest, size_t index)
Expand All @@ -157,6 +165,8 @@ void GuestListWidget::renderOneBannedGuest(GuestData& guest, size_t index)
static string popupTitle = "";
static size_t popupIndex;

ImGui::PushID((string("Banned Guest ") + to_string(index)).c_str());

IconButton::render(AppIcons::userOff, AppColors::negative, ImVec2(30, 30));
if (ImGui::IsItemActive())
{
Expand Down Expand Up @@ -194,6 +204,8 @@ void GuestListWidget::renderOneBannedGuest(GuestData& guest, size_t index)
ImGui::Dummy(ImVec2(0.0f, 5.0f));
ImGui::EndGroup();
ImGui::PopStyleVar();

ImGui::PopID();
}

void GuestListWidget::renderOneHistoryGuest(GuestData& guest, size_t index)
Expand All @@ -202,6 +214,8 @@ void GuestListWidget::renderOneHistoryGuest(GuestData& guest, size_t index)
static string popupTitle = "";
static size_t popupIndex;

ImGui::PushID((string("History Guest ") + to_string(index)).c_str());

IconButton::render(AppIcons::block, AppColors::primary, ImVec2(30, 30));
if (ImGui::IsItemActive())
{
Expand Down Expand Up @@ -237,6 +251,8 @@ void GuestListWidget::renderOneHistoryGuest(GuestData& guest, size_t index)
ImGui::Dummy(ImVec2(0.0f, 5.0f));
ImGui::EndGroup();
ImGui::PopStyleVar();

ImGui::PopID();
}


Expand Down Expand Up @@ -317,19 +333,20 @@ ImVec4 GuestListWidget::getLatencyColor(float latency)
return AppColors::warning;
}

void GuestListWidget::renderPopupButton(const string title, const string command, const GuestData guest, bool& showPopup, string& popupTitle, Icon btnIcon, Action action)
void GuestListWidget::renderPopupButton(const string title, const string command, const GuestData& guest, const size_t& index, bool& showPopup, string& popupTitle, Icon btnIcon, Action action)
{
IconButton::render(btnIcon, AppColors::primary, ImVec2(30, 30));
if (ImGui::IsItemActive())
static string tooltipTitle, tooltipDescription, id;

tooltipTitle = title + " user";
tooltipDescription = "Press to " + title + " " + guest.name;
id = title + " " + to_string(index);
if (BadgeButtonWidget::render(btnIcon, tooltipTitle.c_str(), tooltipDescription.c_str(), id.c_str(), ImVec2(20, 20)))
{
showPopup = true;
popupTitle = title + " " + guest.name + "?" + "##Online " + title + to_string(guest.userID);
popupTitle = title + " " + guest.name + "?" + "##Online " + to_string(index)+ title + to_string(guest.userID);
ImGui::OpenPopup(popupTitle.c_str());
}
TitleTooltipWidget::render(
(title + " user").c_str(),
(string("Press to ") + title + " " + guest.name).c_str()
);

if (showPopup)
{
if (ConfirmPopupWidget::render(
Expand Down
3 changes: 2 additions & 1 deletion ParsecSoda/Widgets/GuestListWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../CircularMetrics.h"
#include <functional>
#include "IconButton.h"
#include "BadgeButtonWidget.h"
#include "TitleTooltipWidget.h"
#include "AbstractTooltipWidget.h"
#include "ConfirmPopupWidget.h"
Expand All @@ -35,7 +36,7 @@ class GuestListWidget
bool isGuestFilterMatch(const string name, const uint32_t userID, const string filterTextStr);
void sendHostMessage(const string command, const uint32_t userID);
ImVec4 getLatencyColor(float latency);
void renderPopupButton(const string title, const string command, const GuestData guest, bool& showPopup, string& popupTitle, Icon btnIcon, Action action);
void renderPopupButton(const string title, const string command, const GuestData& guest, const size_t& index, bool& showPopup, string& popupTitle, Icon btnIcon, Action action);

void renderGuestMetricsTooltip(GuestData guest);

Expand Down
2 changes: 1 addition & 1 deletion ParsecSoda/Widgets/VersionWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool VersionWidget::render()
ImGui::SetNextWindowSize(ImVec2(100, 32));
ImGui::Begin("##Version", (bool*)0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBringToFrontOnFocus);
AppStyle::pushLabel();
ImGui::Text("v. 1.2.0");
ImGui::Text("v. 1.2.1");
AppStyle::pop();
ImGui::End();

Expand Down

0 comments on commit 4d8bb1a

Please sign in to comment.