From f924674239571a40b0806136a49b4da3edcadbbf Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 2 Dec 2014 19:05:34 +0300 Subject: Move weight notification from playerhander. --- src/game.cpp | 2 -- src/gui/dialogsmanager.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++- src/gui/dialogsmanager.h | 8 ++++++- src/gui/windows/okdialog.cpp | 2 -- src/net/ea/playerhandler.cpp | 49 -------------------------------------- 5 files changed, 62 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 675667cf0..e00e42d09 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -129,8 +129,6 @@ QuitDialog *quitDialog = nullptr; Window *disconnectedDialog = nullptr; -int weightNoticeTime = 0; - bool mStatsReUpdated = false; const unsigned adjustDelay = 10; diff --git a/src/gui/dialogsmanager.cpp b/src/gui/dialogsmanager.cpp index 0ef8a1582..eb60a574a 100644 --- a/src/gui/dialogsmanager.cpp +++ b/src/gui/dialogsmanager.cpp @@ -25,6 +25,8 @@ #include "configuration.h" #include "settings.h" +#include "being/attributes.h" + #include "gui/dialogtype.h" #include "gui/widgets/selldialog.h" @@ -37,6 +39,7 @@ #include "gui/windows/updaterwindow.h" #include "listeners/playerpostdeathlistener.h" +#include "listeners/weightlistener.h" #include "net/inventoryhandler.h" @@ -50,15 +53,19 @@ #undef ERROR #endif -OkDialog *deathNotice; +OkDialog *deathNotice = nullptr; DialogsManager *dialogsManager = nullptr; +OkDialog *weightNotice = nullptr; +int weightNoticeTime = 0; namespace { PlayerPostDeathListener postDeathListener; + WeightListener weightListener; } // namespace DialogsManager::DialogsManager() : + AttributeListener(), PlayerDeathListener() { } @@ -124,3 +131,50 @@ void DialogsManager::playerDeath() false, true, nullptr, 260); deathNotice->addActionListener(&postDeathListener); } + +void DialogsManager::attributeChanged(const int id, + const int oldVal, + const int newVal) +{ + if (id == Attributes::TOTAL_WEIGHT) + { + if (!weightNotice && config.getBoolValue("weightMsg")) + { + const int max = PlayerInfo::getAttribute( + Attributes::MAX_WEIGHT) / 2; + const int total = oldVal; + if (newVal >= max && total < max) + { + weightNoticeTime = cur_time + 5; + // TRANSLATORS: message header + weightNotice = new OkDialog(_("Message"), + // TRANSLATORS: weight message + _("You are carrying more than " + "half your weight. You are " + "unable to regain health."), + // TRANSLATORS: ok dialog button + _("OK"), + DialogType::OK, + false, true, nullptr, 260); + weightNotice->addActionListener( + &weightListener); + } + else if (newVal < max && total >= max) + { + weightNoticeTime = cur_time + 5; + // TRANSLATORS: message header + weightNotice = new OkDialog(_("Message"), + // TRANSLATORS: weight message + _("You are carrying less than " + "half your weight. You " + "can regain health."), + // TRANSLATORS: ok dialog button + _("OK"), + DialogType::OK, + false, true, nullptr, 260); + weightNotice->addActionListener( + &weightListener); + } + } + } +} diff --git a/src/gui/dialogsmanager.h b/src/gui/dialogsmanager.h index b9625ae07..b45b3b12c 100644 --- a/src/gui/dialogsmanager.h +++ b/src/gui/dialogsmanager.h @@ -23,6 +23,7 @@ #ifndef GUI_DIALOGSMANAGER_H #define GUI_DIALOGSMANAGER_H +#include "listeners/attributelistener.h" #include "listeners/playerdeathlistener.h" #include @@ -31,7 +32,8 @@ class Window; -class DialogsManager final : public PlayerDeathListener +class DialogsManager final : public AttributeListener, + public PlayerDeathListener { public: DialogsManager(); @@ -45,6 +47,10 @@ class DialogsManager final : public PlayerDeathListener const bool modal); void playerDeath() override final; + + void attributeChanged(const int id, + const int oldVal, + const int newVal) override final; }; extern DialogsManager *dialogsManager; diff --git a/src/gui/windows/okdialog.cpp b/src/gui/windows/okdialog.cpp index 37d0d018a..b58987c7c 100644 --- a/src/gui/windows/okdialog.cpp +++ b/src/gui/windows/okdialog.cpp @@ -34,8 +34,6 @@ #include "debug.h" -OkDialog *weightNotice = nullptr; - OkDialog::OkDialog(const std::string &restrict title, const std::string &restrict msg, const std::string &restrict button, diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 2835b3def..fa892af29 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -35,7 +35,6 @@ #include "gui/dialogtype.h" #include "gui/viewport.h" -#include "gui/windows/okdialog.h" #include "gui/windows/skilldialog.h" #include "gui/windows/statuswindow.h" @@ -43,8 +42,6 @@ #include "resources/map/map.h" -#include "listeners/weightlistener.h" - #include "net/messagein.h" #include "net/ea/eaprotocol.h" @@ -53,17 +50,10 @@ #include "debug.h" -extern int weightNoticeTime; - // Max. distance we are willing to scroll after a teleport; // everything beyond will reset the port hard. static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; -namespace -{ - WeightListener weightListener; -} // anonymous namespace - namespace Ea { @@ -385,45 +375,6 @@ void PlayerHandler::setStat(const int type, PlayerInfo::getStatExperience(Attributes::JOB).first, base); break; case Ea::TOTAL_WEIGHT: - if (!weightNotice && config.getBoolValue("weightMsg")) - { - const int max = PlayerInfo::getAttribute( - Attributes::MAX_WEIGHT) / 2; - const int total = PlayerInfo::getAttribute( - Attributes::TOTAL_WEIGHT); - if (base >= max && total < max) - { - weightNoticeTime = cur_time + 5; - // TRANSLATORS: message header - weightNotice = new OkDialog(_("Message"), - // TRANSLATORS: weight message - _("You are carrying more than " - "half your weight. You are " - "unable to regain health."), - // TRANSLATORS: ok dialog button - _("OK"), - DialogType::OK, - false, true, nullptr, 260); - weightNotice->addActionListener( - &weightListener); - } - else if (base < max && total >= max) - { - weightNoticeTime = cur_time + 5; - // TRANSLATORS: message header - weightNotice = new OkDialog(_("Message"), - // TRANSLATORS: weight message - _("You are carrying less than " - "half your weight. You " - "can regain health."), - // TRANSLATORS: ok dialog button - _("OK"), - DialogType::OK, - false, true, nullptr, 260); - weightNotice->addActionListener( - &weightListener); - } - } PlayerInfo::setAttribute(Attributes::TOTAL_WEIGHT, base); break; case Ea::MAX_WEIGHT: -- cgit v1.2.3-70-g09d2