From 1003a7a74f72f17f59f4a74eacf95a1744a64506 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 2 Dec 2014 17:56:13 +0300 Subject: Move death dialog showing from playerhandler. --- src/being/localplayer.cpp | 18 ++++++++++++++++++ src/being/localplayer.h | 4 ++++ src/client.cpp | 3 ++- src/gui/dialogsmanager.cpp | 30 +++++++++++++++++++++++++++++- src/gui/dialogsmanager.h | 10 +++++++++- src/gui/windows/okdialog.cpp | 1 - src/listeners/playerpostdeathlistener.h | 6 +++--- src/net/ea/playerhandler.cpp | 21 --------------------- 8 files changed, 65 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 935b64c70..a9a51bd56 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -110,6 +110,7 @@ extern SkillDialog *skillDialog; LocalPlayer::LocalPlayer(const int id, const uint16_t subtype) : Being(id, ActorType::Player, subtype, nullptr), AttributeListener(), + PlayerDeathListener(), StatListener(), mGMLevel(0), mCrazyMoveState(0), @@ -1106,6 +1107,13 @@ void LocalPlayer::attributeChanged(const int id, case Attributes::LEVEL: mLevel = newVal; break; + case Attributes::HP: + if (oldVal != 0 && newVal == 0 + && localPlayer->getCurrentAction() != BeingAction::DEAD) + { + PlayerDeathListener::distributeEvent(); + } + break; default: break; } @@ -3276,3 +3284,13 @@ void LocalPlayer::setTestParticle(const std::string &fileName, mTestParticleHash = UpdaterWindow::getFileHash(mTestParticleName); } } + +void LocalPlayer::playerDeath() +{ + if (mAction != BeingAction::DEAD) + { + setAction(BeingAction::DEAD, 0); + recalcSpritesOrder(); + } +} + diff --git a/src/being/localplayer.h b/src/being/localplayer.h index 46ed22cb8..dd5043572 100644 --- a/src/being/localplayer.h +++ b/src/being/localplayer.h @@ -31,6 +31,7 @@ #include "listeners/actorspritelistener.h" #include "listeners/attributelistener.h" +#include "listeners/playerdeathlistener.h" #include "listeners/statlistener.h" #include @@ -49,6 +50,7 @@ class OkDialog; class LocalPlayer final : public Being, public ActorSpriteListener, public AttributeListener, + public PlayerDeathListener, public StatListener { public: @@ -289,6 +291,8 @@ class LocalPlayer final : public Being, */ void optionChanged(const std::string &value) override final; + void playerDeath() override final; + /** * set a following player. */ diff --git a/src/client.cpp b/src/client.cpp index f0919ed9a..b12d4a004 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -382,7 +382,7 @@ void Client::gameInit() gui = new Gui(); gui->postInit(mainGraphics); - + dialogsManager = new DialogsManager; popupManager = new PopupManager; initSoundManager(); @@ -654,6 +654,7 @@ void Client::gameClear() delete2(mCurrentDialog); delete2(popupManager); + delete2(dialogsManager); delete2(gui); if (inventoryHandler) diff --git a/src/gui/dialogsmanager.cpp b/src/gui/dialogsmanager.cpp index 0b515c2f3..0ef8a1582 100644 --- a/src/gui/dialogsmanager.cpp +++ b/src/gui/dialogsmanager.cpp @@ -36,8 +36,12 @@ #include "gui/windows/okdialog.h" #include "gui/windows/updaterwindow.h" +#include "listeners/playerpostdeathlistener.h" + #include "net/inventoryhandler.h" +#include "resources/db/deaddb.h" + #include "utils/gettext.h" #include "debug.h" @@ -46,7 +50,18 @@ #undef ERROR #endif -extern OkDialog *deathNotice; +OkDialog *deathNotice; +DialogsManager *dialogsManager = nullptr; + +namespace +{ + PlayerPostDeathListener postDeathListener; +} // namespace + +DialogsManager::DialogsManager() : + PlayerDeathListener() +{ +} void DialogsManager::closeDialogs() { @@ -96,3 +111,16 @@ Window *DialogsManager::openErrorDialog(const std::string &header, return dialog; } } + +void DialogsManager::playerDeath() +{ + logger->log("DialogsManager::playerDeath"); + // TRANSLATORS: message header + deathNotice = new OkDialog(_("Message"), + DeadDB::getRandomString(), + // TRANSLATORS: ok dialog button + _("Revive"), + DialogType::OK, + false, true, nullptr, 260); + deathNotice->addActionListener(&postDeathListener); +} diff --git a/src/gui/dialogsmanager.h b/src/gui/dialogsmanager.h index 9c7dc0d46..b9625ae07 100644 --- a/src/gui/dialogsmanager.h +++ b/src/gui/dialogsmanager.h @@ -23,15 +23,19 @@ #ifndef GUI_DIALOGSMANAGER_H #define GUI_DIALOGSMANAGER_H +#include "listeners/playerdeathlistener.h" + #include #include "localconsts.h" class Window; -class DialogsManager final +class DialogsManager final : public PlayerDeathListener { public: + DialogsManager(); + static void closeDialogs(); static void createUpdaterWindow(); @@ -39,6 +43,10 @@ class DialogsManager final static Window *openErrorDialog(const std::string &header, const std::string &message, const bool modal); + + void playerDeath() override final; }; +extern DialogsManager *dialogsManager; + #endif // GUI_DIALOGSMANAGER_H diff --git a/src/gui/windows/okdialog.cpp b/src/gui/windows/okdialog.cpp index b6c3bfc41..37d0d018a 100644 --- a/src/gui/windows/okdialog.cpp +++ b/src/gui/windows/okdialog.cpp @@ -35,7 +35,6 @@ #include "debug.h" OkDialog *weightNotice = nullptr; -OkDialog *deathNotice = nullptr; OkDialog::OkDialog(const std::string &restrict title, const std::string &restrict msg, diff --git a/src/listeners/playerpostdeathlistener.h b/src/listeners/playerpostdeathlistener.h index 6ab8fd25b..152dbd361 100644 --- a/src/listeners/playerpostdeathlistener.h +++ b/src/listeners/playerpostdeathlistener.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef LISTENERS_PLAYERDEATHLISTENER_H -#define LISTENERS_PLAYERDEATHLISTENER_H +#ifndef LISTENERS_PLAYERPOSTDEATHLISTENER_H +#define LISTENERS_PLAYERPOSTDEATHLISTENER_H #include "being/localplayer.h" @@ -60,4 +60,4 @@ struct PlayerPostDeathListener final : public ActionListener } }; -#endif // LISTENERS_PLAYERDEATHLISTENER_H +#endif // LISTENERS_PLAYERPOSTDEATHLISTENER_H diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 940b629d4..2835b3def 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -41,11 +41,8 @@ #include "resources/notifytypes.h" -#include "resources/db/deaddb.h" - #include "resources/map/map.h" -#include "listeners/playerpostdeathlistener.h" #include "listeners/weightlistener.h" #include "net/messagein.h" @@ -65,7 +62,6 @@ static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; namespace { WeightListener weightListener; - PlayerPostDeathListener postDeathListener; } // anonymous namespace namespace Ea @@ -186,23 +182,6 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) } playerHandler->setStat(type, value, -1, true); - - if (PlayerInfo::getAttribute(Attributes::HP) == 0 && !deathNotice) - { - // TRANSLATORS: message header - deathNotice = new OkDialog(_("Message"), - DeadDB::getRandomString(), - // TRANSLATORS: ok dialog button - _("Revive"), - DialogType::OK, - false, true, nullptr, 260); - deathNotice->addActionListener(&postDeathListener); - if (localPlayer->getCurrentAction() != BeingAction::DEAD) - { - localPlayer->setAction(BeingAction::DEAD, 0); - localPlayer->recalcSpritesOrder(); - } - } BLOCK_END("PlayerHandler::processPlayerStatUpdate1") } -- cgit v1.2.3-70-g09d2