From 9c7c7093b94e908efff0798004c2595a8b5c0fcd Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Fri, 11 Oct 2024 23:09:23 +0000 Subject: Add confirmation dialog for leaving guild Memory may not be freed properly, also code is IMO ugly. See !109 for the other way of implementing this (unrelated). Was done in socialWindow as the join confirmation is already there. **** mana/plus!110 --- src/gui/windows/socialwindow.cpp | 34 +++++++++++++++++++++++++++++++++ src/gui/windows/socialwindow.h | 3 +++ src/progs/manaplus/actions/commands.cpp | 4 ++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp index c8c96d4cf..14596dc16 100644 --- a/src/gui/windows/socialwindow.cpp +++ b/src/gui/windows/socialwindow.cpp @@ -55,6 +55,7 @@ SocialWindow::SocialWindow() : PlayerRelationsListener(), mGuildInvited(0), mGuildAcceptDialog(nullptr), + mGuildLeaveDialog(nullptr), mGuildCreateDialog(nullptr), mPartyInviter(), mGuilds(), @@ -159,6 +160,13 @@ SocialWindow::~SocialWindow() mGuildInvited = 0; } + if (mGuildLeaveDialog != nullptr) + { + mGuildLeaveDialog->close(); + mGuildLeaveDialog->scheduleDelete(); + mGuildLeaveDialog = nullptr; + } + if (mPartyAcceptDialog != nullptr) { mPartyAcceptDialog->close(); @@ -351,6 +359,19 @@ void SocialWindow::action(const ActionEvent &event) mGuildInvited = 0; mGuildAcceptDialog = nullptr; } + else if (event.getSource() == mGuildLeaveDialog) + { + if (eventId == "yes") + { + if ((guildHandler != nullptr) && (localPlayer != nullptr)) + { + const Guild *const guild = localPlayer->getGuild(); + if (guild != nullptr) + guildHandler->leave(guild->getId()); + } + } + mGuildLeaveDialog = nullptr; + } else if (eventId == "party") { popupMenu->showPartyPopup(); @@ -425,6 +446,19 @@ void SocialWindow::showGuildInvite(const std::string &restrict guildName, mGuildInvited = guildId; } +void SocialWindow::confirmGuildLeave() +{ + CREATEWIDGETV(mGuildLeaveDialog, ConfirmDialog, + // TRANSLATORS: guild invite message + _("Really leave your guild?"), + "", + SOUND_REQUEST, + false, + Modal_false, + this); + mGuildLeaveDialog->addActionListener(this); +} + void SocialWindow::showPartyInvite(const std::string &restrict partyName, const std::string &restrict inviter, const int partyId) diff --git a/src/gui/windows/socialwindow.h b/src/gui/windows/socialwindow.h index 63310d00d..4014506c2 100644 --- a/src/gui/windows/socialwindow.h +++ b/src/gui/windows/socialwindow.h @@ -70,6 +70,8 @@ class SocialWindow final : public Window, const int guildId, const std::string &restrict inviterName); + void confirmGuildLeave(); + void showPartyInvite(const std::string &restrict partyName, const std::string &restrict inviter, const int partyId); @@ -144,6 +146,7 @@ class SocialWindow final : public Window, int mGuildInvited; ConfirmDialog *mGuildAcceptDialog; + ConfirmDialog *mGuildLeaveDialog; TextDialog *mGuildCreateDialog; std::string mPartyInviter; GuildMap mGuilds; diff --git a/src/progs/manaplus/actions/commands.cpp b/src/progs/manaplus/actions/commands.cpp index ff0d91e3d..53c0996ac 100644 --- a/src/progs/manaplus/actions/commands.cpp +++ b/src/progs/manaplus/actions/commands.cpp @@ -986,11 +986,11 @@ impHandler0(leaveParty) impHandler0(leaveGuild) { - if ((guildHandler != nullptr) && (localPlayer != nullptr)) + if ((socialWindow != nullptr) && (localPlayer != nullptr)) { const Guild *const guild = localPlayer->getGuild(); if (guild != nullptr) - guildHandler->leave(guild->getId()); + socialWindow->confirmGuildLeave(); return true; } return false; -- cgit v1.2.3-70-g09d2