Close punishment dialog when the user leaves (#1097)

* Close punishment dialog when the user leaves

Prevents silly moments where the wrong person gets banned/kicked

* Fix formatting

---------

Co-authored-by: stonedDiscord <Tukz@gmx.de>
This commit is contained in:
Salanto 2025-05-08 21:21:37 +02:00 committed by GitHub
parent cde34538dc
commit 4db9791873
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 0 deletions

View File

@ -520,6 +520,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app)
connect(m_screenslide_timer, &kal::ScreenSlideTimer::finished, this, &Courtroom::post_transition_cleanup); connect(m_screenslide_timer, &kal::ScreenSlideTimer::finished, this, &Courtroom::post_transition_cleanup);
connect(ui_player_list, &PlayerListWidget::notify, this, [this](const QString &message) { append_server_chatmessage("CLIENT", message, "1"); });
set_widgets(); set_widgets();
set_char_select(); set_char_select();

View File

@ -117,6 +117,7 @@ void PlayerListWidget::onCustomContextMenuRequested(const QPoint &pos)
ModeratorDialog *dialog = new ModeratorDialog(id, false, ao_app); ModeratorDialog *dialog = new ModeratorDialog(id, false, ao_app);
dialog->setWindowTitle(tr("Kick %1").arg(name)); dialog->setWindowTitle(tr("Kick %1").arg(name));
connect(this, &PlayerListWidget::destroyed, dialog, &ModeratorDialog::deleteLater); connect(this, &PlayerListWidget::destroyed, dialog, &ModeratorDialog::deleteLater);
active_moderator_menu = {id, dialog};
dialog->show(); dialog->show();
}); });
@ -125,6 +126,7 @@ void PlayerListWidget::onCustomContextMenuRequested(const QPoint &pos)
ModeratorDialog *dialog = new ModeratorDialog(id, true, ao_app); ModeratorDialog *dialog = new ModeratorDialog(id, true, ao_app);
dialog->setWindowTitle(tr("Ban %1").arg(name)); dialog->setWindowTitle(tr("Ban %1").arg(name));
connect(this, &PlayerListWidget::destroyed, dialog, &ModeratorDialog::deleteLater); connect(this, &PlayerListWidget::destroyed, dialog, &ModeratorDialog::deleteLater);
active_moderator_menu = {id, dialog};
dialog->show(); dialog->show();
}); });
} }
@ -143,6 +145,12 @@ void PlayerListWidget::addPlayer(int playerId)
void PlayerListWidget::removePlayer(int playerId) void PlayerListWidget::removePlayer(int playerId)
{ {
if (active_moderator_menu.first == playerId && active_moderator_menu.second)
{
delete active_moderator_menu.second;
Q_EMIT notify("Closed Moderation Dialog : User left the server.");
}
delete takeItem(row(m_item_map.take(playerId))); delete takeItem(row(m_item_map.take(playerId)));
m_player_map.remove(playerId); m_player_map.remove(playerId);
} }

View File

@ -5,11 +5,14 @@
#include <QList> #include <QList>
#include <QListWidget> #include <QListWidget>
#include <QMap> #include <QMap>
#include <QPointer>
class AOApplication; class AOApplication;
class ModeratorDialog;
class PlayerListWidget : public QListWidget class PlayerListWidget : public QListWidget
{ {
Q_OBJECT
public: public:
explicit PlayerListWidget(AOApplication *ao_app, QWidget *parent = nullptr); explicit PlayerListWidget(AOApplication *ao_app, QWidget *parent = nullptr);
virtual ~PlayerListWidget(); virtual ~PlayerListWidget();
@ -24,6 +27,7 @@ private:
AOApplication *ao_app; AOApplication *ao_app;
QMap<int, PlayerData> m_player_map; QMap<int, PlayerData> m_player_map;
QMap<int, QListWidgetItem *> m_item_map; QMap<int, QListWidgetItem *> m_item_map;
QPair<int, QPointer<ModeratorDialog>> active_moderator_menu;
bool m_is_authenticated = false; bool m_is_authenticated = false;
void addPlayer(int playerId); void addPlayer(int playerId);
@ -34,6 +38,9 @@ private:
void filterPlayerList(); void filterPlayerList();
Q_SIGNALS:
void notify(const QString &messasge);
private Q_SLOTS: private Q_SLOTS:
void onCustomContextMenuRequested(const QPoint &pos); void onCustomContextMenuRequested(const QPoint &pos);
}; };