diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-09-27 22:35:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-09-27 22:35:38 +0300 |
commit | 9429dc4f5b5b6102a8b575de25ce5d8e7170551f (patch) | |
tree | d4603ddbea06f75e8637a1ff94da4432d7b96951 /src/gui/windows | |
parent | 64d30eda264c342aced8d791b47a35def0e4d15c (diff) | |
download | manaverse-9429dc4f5b5b6102a8b575de25ce5d8e7170551f.tar.gz manaverse-9429dc4f5b5b6102a8b575de25ce5d8e7170551f.tar.bz2 manaverse-9429dc4f5b5b6102a8b575de25ce5d8e7170551f.tar.xz manaverse-9429dc4f5b5b6102a8b575de25ce5d8e7170551f.zip |
Change player job level, exp from stat object to attribute.
Diffstat (limited to 'src/gui/windows')
-rw-r--r-- | src/gui/windows/chatwindow.cpp | 42 | ||||
-rw-r--r-- | src/gui/windows/chatwindow.h | 6 | ||||
-rw-r--r-- | src/gui/windows/ministatuswindow.cpp | 28 | ||||
-rw-r--r-- | src/gui/windows/statuswindow.cpp | 126 | ||||
-rw-r--r-- | src/gui/windows/statuswindow.h | 8 |
5 files changed, 102 insertions, 108 deletions
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index a3bb4829b..aa899202d 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -999,29 +999,6 @@ bool ChatWindow::addCurrentToHistory() return true; } -void ChatWindow::statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2) -{ - if (!mShowBattleEvents || !config.getBoolValue("showJobExp")) - return; - - if (id != Attributes::PLAYER_JOB) - return; - - const std::pair<int, int> exp = PlayerInfo::getStatExperience(id); - if (oldVal1 > exp.first || (oldVal2 == 0)) - return; - - const int change = exp.first - oldVal1; - if (change != 0) - { - battleChatLog(std::string("+").append(toString( - change)).append(" job"), - ChatMsgType::BY_SERVER); - } -} - void ChatWindow::attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal) @@ -1051,6 +1028,25 @@ void ChatWindow::attributeChanged(const AttributesT id, newVal))), ChatMsgType::BY_SERVER); break; + case Attributes::PLAYER_JOB_EXP: + { + if (!config.getBoolValue("showJobExp")) + return; + if (oldVal > newVal || + PlayerInfo::getAttribute( + Attributes::PLAYER_JOB_EXP_NEEDED) == 0) + { + return; + } + const int64_t change = newVal - oldVal; + if (change != 0) + { + battleChatLog(std::string("+").append(toString(CAST_U64( + change))).append(" job"), + ChatMsgType::BY_SERVER); + } + break; + } default: break; }; diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h index 2328a012f..7d02e0fd3 100644 --- a/src/gui/windows/chatwindow.h +++ b/src/gui/windows/chatwindow.h @@ -35,7 +35,6 @@ #include "listeners/attributelistener.h" #include "listeners/debugmessagelistener.h" #include "listeners/keylistener.h" -#include "listeners/statlistener.h" class Button; class ChannelTab; @@ -57,7 +56,6 @@ class ChatWindow final : public Window, public KeyListener, public ConfigListener, public AttributeListener, - public StatListener, public DebugMessageListener { public: @@ -298,10 +296,6 @@ class ChatWindow final : public Window, const int64_t oldVal, const int64_t newVal) override final; - void statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2) override final; - void postConnection(); void showGMTab(); diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp index fcaff8759..c97fa1cd4 100644 --- a/src/gui/windows/ministatuswindow.cpp +++ b/src/gui/windows/ministatuswindow.cpp @@ -407,24 +407,36 @@ void MiniStatusWindow::mouseMoved(MouseEvent &event) } else if (event.getSource() == mJobBar) { - const std::pair<int, int> exp = PlayerInfo::getStatExperience( + const int64_t exp = PlayerInfo::getAttribute64( + Attributes::PLAYER_JOB_EXP); + const int64_t expNeed = PlayerInfo::getAttribute64( + Attributes::PLAYER_JOB_EXP_NEEDED); + const int32_t jobLevel = PlayerInfo::getAttribute( Attributes::PLAYER_JOB); + const std::string expStr = toString(CAST_U64(exp)); + const std::string expNeedStr = toString(CAST_U64(expNeed)); + const std::string jobLevelStr = toString(CAST_U64(jobLevel)); + const std::string expLeftStr = toString(CAST_U64(expNeed - exp)); // TRANSLATORS: job bar label const std::string level = strprintf(_("Job level: %d"), - PlayerInfo::getStatBase(Attributes::PLAYER_JOB)); + jobLevel); - if (exp.first > exp.second) + if (exp > expNeed) { - textPopup->show(x + rect.x, y + rect.y, level, - strprintf("%d/%d", exp.first, exp.second)); + textPopup->show(x + rect.x, + y + rect.y, + level, + strprintf("%s/%s", expStr.c_str(), expNeedStr.c_str())); } else { - textPopup->show(x + rect.x, y + rect.y, level, - strprintf("%d/%d", exp.first, exp.second), + textPopup->show(x + rect.x, + y + rect.y, + level, + strprintf("%s/%s", expStr.c_str(), expNeedStr.c_str()), // TRANSLATORS: status bar label - strprintf("%s: %d", _("Need"), exp.second - exp.first)); + strprintf("%s: %s", _("Need"), expLeftStr.c_str())); } mStatusPopup->hide(); } diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp index 462f22021..f096a3dd1 100644 --- a/src/gui/windows/statuswindow.cpp +++ b/src/gui/windows/statuswindow.cpp @@ -68,7 +68,6 @@ StatusWindow::StatusWindow() : "?", Modal_false, nullptr, "status.xml"), ActionListener(), AttributeListener(), - StatListener(), mPages(), mTabs(CREATEWIDGETR(TabbedArea, this)), // TRANSLATORS: status window label @@ -284,67 +283,12 @@ void StatusWindow::updateLevelLabel() mLvlLabel->adjustSize(); } -void StatusWindow::statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2 A_UNUSED) -{ - static bool blocked = false; - if (blocked) - return; - - if (id == Attributes::PLAYER_JOB) - { - if (mJobLvlLabel != nullptr) - { - int lvl = PlayerInfo::getStatBase(id); - const int oldExp = oldVal1; - const std::pair<int, int> exp = PlayerInfo::getStatExperience(id); - - if (lvl == 0) - { - // possible server broken and don't send job level, - // then we fixing it :) - if (exp.second < 20000) - { - lvl = 0; - } - else - { - lvl = (exp.second - 20000) / 150; - blocked = true; - PlayerInfo::setStatBase(id, lvl); - blocked = false; - } - } - - if (exp.first < oldExp && exp.second >= 20000) - { // possible job level up. but server broken and don't send - // new job exp limit, we fixing it - lvl ++; - blocked = true; - PlayerInfo::setStatExperience( - id, exp.first, 20000 + lvl * 150); - PlayerInfo::setStatBase(id, lvl); - blocked = false; - } - - // TRANSLATORS: status window label - mJobLvlLabel->setCaption(strprintf(_("Job: %d"), lvl)); - mJobLvlLabel->adjustSize(); - - updateJobBar(mJobBar, false); - } - } - else - { - updateMPBar(mMpBar, true); - } -} - void StatusWindow::attributeChanged(const AttributesT id, - const int64_t oldVal A_UNUSED, + const int64_t oldVal, const int64_t newVal) { + static bool blocked = false; + PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wswitch-enum") switch (id) @@ -378,6 +322,57 @@ void StatusWindow::attributeChanged(const AttributesT id, mLvlLabel->adjustSize(); break; + case Attributes::PLAYER_JOB: + case Attributes::PLAYER_JOB_EXP: + case Attributes::PLAYER_JOB_EXP_NEEDED: + if (blocked) + return; + if (mJobLvlLabel != nullptr) + { + int lvl = PlayerInfo::getAttribute(Attributes::PLAYER_JOB); + const int64_t exp = PlayerInfo::getAttribute( + Attributes::PLAYER_JOB_EXP); + const int64_t expNeed = PlayerInfo::getAttribute( + Attributes::PLAYER_JOB_EXP_NEEDED); + + if (lvl == 0) + { + // possible server broken and don't send job level, + // then we fixing it. + if (expNeed < 20000) + { + lvl = 0; + } + else + { + lvl = (expNeed - 20000) / 150; + blocked = true; + PlayerInfo::setAttribute(Attributes::PLAYER_JOB, lvl); + blocked = false; + } + } + + if (id == Attributes::PLAYER_JOB_EXP && + exp < oldVal && + expNeed >= 20000) + { // possible job level up. but server broken and don't send + // new job exp limit, we fixing it + lvl ++; + blocked = true; + PlayerInfo::setAttribute(Attributes::PLAYER_JOB_EXP_NEEDED, + 20000 + lvl * 150); + PlayerInfo::setAttribute(Attributes::PLAYER_JOB, lvl); + blocked = false; + } + + // TRANSLATORS: status window label + mJobLvlLabel->setCaption(strprintf(_("Job: %d"), lvl)); + mJobLvlLabel->adjustSize(); + + updateJobBar(mJobBar, false); + } + break; + default: break; } @@ -481,8 +476,10 @@ void StatusWindow::updateXPBar(ProgressBar *const bar, const bool percent) if (bar == nullptr) return; - updateProgressBar(bar, PlayerInfo::getAttribute(Attributes::PLAYER_EXP), - PlayerInfo::getAttribute(Attributes::PLAYER_EXP_NEEDED), percent); + updateProgressBar(bar, + PlayerInfo::getAttribute(Attributes::PLAYER_EXP), + PlayerInfo::getAttribute(Attributes::PLAYER_EXP_NEEDED), + percent); } void StatusWindow::updateJobBar(ProgressBar *const bar, const bool percent) @@ -490,9 +487,10 @@ void StatusWindow::updateJobBar(ProgressBar *const bar, const bool percent) if (bar == nullptr) return; - const std::pair<int, int> exp = PlayerInfo::getStatExperience( - Attributes::PLAYER_JOB); - updateProgressBar(bar, exp.first, exp.second, percent); + updateProgressBar(bar, + PlayerInfo::getAttribute(Attributes::PLAYER_JOB_EXP), + PlayerInfo::getAttribute(Attributes::PLAYER_JOB_EXP_NEEDED), + percent); } void StatusWindow::updateProgressBar(ProgressBar *const bar, diff --git a/src/gui/windows/statuswindow.h b/src/gui/windows/statuswindow.h index daced90b2..233840d17 100644 --- a/src/gui/windows/statuswindow.h +++ b/src/gui/windows/statuswindow.h @@ -27,7 +27,6 @@ #include "listeners/actionlistener.h" #include "listeners/attributelistener.h" -#include "listeners/statlistener.h" class Button; class Label; @@ -43,8 +42,7 @@ class TabbedArea; */ class StatusWindow final : public Window, public ActionListener, - public AttributeListener, - public StatListener + public AttributeListener { public: /** @@ -86,10 +84,6 @@ class StatusWindow final : public Window, const int64_t oldVal, const int64_t newVal) override final; - void statChanged(const AttributesT id, - const int oldVal1, - const int oldVal2) override final; - void updateLevelLabel(); private: |