Skip to content

Commit 4db9791

Browse files
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 <[email protected]>
1 parent cde3453 commit 4db9791

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/courtroom.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app)
520520

521521
connect(m_screenslide_timer, &kal::ScreenSlideTimer::finished, this, &Courtroom::post_transition_cleanup);
522522

523+
connect(ui_player_list, &PlayerListWidget::notify, this, [this](const QString &message) { append_server_chatmessage("CLIENT", message, "1"); });
524+
523525
set_widgets();
524526

525527
set_char_select();

src/widgets/playerlistwidget.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void PlayerListWidget::onCustomContextMenuRequested(const QPoint &pos)
117117
ModeratorDialog *dialog = new ModeratorDialog(id, false, ao_app);
118118
dialog->setWindowTitle(tr("Kick %1").arg(name));
119119
connect(this, &PlayerListWidget::destroyed, dialog, &ModeratorDialog::deleteLater);
120+
active_moderator_menu = {id, dialog};
120121
dialog->show();
121122
});
122123

@@ -125,6 +126,7 @@ void PlayerListWidget::onCustomContextMenuRequested(const QPoint &pos)
125126
ModeratorDialog *dialog = new ModeratorDialog(id, true, ao_app);
126127
dialog->setWindowTitle(tr("Ban %1").arg(name));
127128
connect(this, &PlayerListWidget::destroyed, dialog, &ModeratorDialog::deleteLater);
129+
active_moderator_menu = {id, dialog};
128130
dialog->show();
129131
});
130132
}
@@ -143,6 +145,12 @@ void PlayerListWidget::addPlayer(int playerId)
143145

144146
void PlayerListWidget::removePlayer(int playerId)
145147
{
148+
if (active_moderator_menu.first == playerId && active_moderator_menu.second)
149+
{
150+
delete active_moderator_menu.second;
151+
Q_EMIT notify("Closed Moderation Dialog : User left the server.");
152+
}
153+
146154
delete takeItem(row(m_item_map.take(playerId)));
147155
m_player_map.remove(playerId);
148156
}

src/widgets/playerlistwidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#include <QList>
66
#include <QListWidget>
77
#include <QMap>
8+
#include <QPointer>
89

910
class AOApplication;
11+
class ModeratorDialog;
1012

1113
class PlayerListWidget : public QListWidget
1214
{
15+
Q_OBJECT
1316
public:
1417
explicit PlayerListWidget(AOApplication *ao_app, QWidget *parent = nullptr);
1518
virtual ~PlayerListWidget();
@@ -24,6 +27,7 @@ class PlayerListWidget : public QListWidget
2427
AOApplication *ao_app;
2528
QMap<int, PlayerData> m_player_map;
2629
QMap<int, QListWidgetItem *> m_item_map;
30+
QPair<int, QPointer<ModeratorDialog>> active_moderator_menu;
2731
bool m_is_authenticated = false;
2832

2933
void addPlayer(int playerId);
@@ -34,6 +38,9 @@ class PlayerListWidget : public QListWidget
3438

3539
void filterPlayerList();
3640

41+
Q_SIGNALS:
42+
void notify(const QString &messasge);
43+
3744
private Q_SLOTS:
3845
void onCustomContextMenuRequested(const QPoint &pos);
3946
};

0 commit comments

Comments
 (0)