diff options
-rw-r--r-- | src/actionmanager.cpp | 3 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 65 | ||||
-rw-r--r-- | src/being/localplayer.h | 17 | ||||
-rw-r--r-- | src/eventsmanager.cpp | 4 | ||||
-rw-r--r-- | src/game.cpp | 6 | ||||
-rw-r--r-- | src/gamemodifiers.cpp | 66 | ||||
-rw-r--r-- | src/gamemodifiers.h | 4 | ||||
-rw-r--r-- | src/gui/popups/statuspopup.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/chatwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/statuswindow.cpp | 2 | ||||
-rw-r--r-- | src/input/inputmanager.cpp | 2 | ||||
-rw-r--r-- | src/listeners/awaylistener.cpp | 7 | ||||
-rw-r--r-- | src/settings.h | 4 |
13 files changed, 103 insertions, 81 deletions
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index 9aed163d6..08e88c0fc 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -579,9 +579,10 @@ impHandler0(changeAudio) impHandler0(away) { + if (modifiers) + modifiers->changeAwayMode(); if (player_node) { - player_node->changeAwayMode(); player_node->updateStatus(); if (Game::instance()) Game::instance()->setValidSpeed(); diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 36275dbbe..77706051c 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -27,6 +27,7 @@ #include "client.h" #include "configuration.h" #include "dropshortcut.h" +#include "gamemodifiers.h" #include "guild.h" #include "item.h" #include "party.h" @@ -173,7 +174,6 @@ LocalPlayer::LocalPlayer(const int id, const uint16_t subtype) : mKeepAttacking(false), mPathSetByMouse(false), mWaitPing(false), - mAwayMode(false), mPseudoAwayMode(false), mShowNavigePath(false) { @@ -342,7 +342,7 @@ void LocalPlayer::slowLogic() if (mTradebot && shopWindow && !shopWindow->isShopEmpty()) smile |= BeingFlag::SHOP; - if (mAwayMode || mPseudoAwayMode) + if (settings.awayMode || mPseudoAwayMode) smile |= BeingFlag::AWAY; if (mInactive) @@ -1255,61 +1255,6 @@ void LocalPlayer::changeMode(unsigned *restrict const var, debugMsg(str.substr(4)); } -const unsigned awayModeSize = 2; - -void LocalPlayer::changeAwayMode() -{ - mAwayMode = !mAwayMode; - mAfkTime = 0; - mInactive = false; - updateName(); - UpdateStatusListener::distributeEvent(); - if (mAwayMode) - { - if (chatWindow) - chatWindow->clearAwayLog(); - - cancelFollow(); - navigateClean(); - if (outfitWindow) - outfitWindow->wearAwayOutfit(); - // TRANSLATORS: away message box header - mAwayDialog = new OkDialog(_("Away"), - config.getStringValue("afkMessage"), - DialogType::SILENCE, true, false); - mAwayDialog->addActionListener(mAwayListener); - soundManager.volumeOff(); - addAfkEffect(); - } - else - { - mAwayDialog = nullptr; - soundManager.volumeRestore(); - if (chatWindow) - { - chatWindow->displayAwayLog(); - chatWindow->clearAwayLog(); - } - removeAfkEffect(); - } -} - -static const char *const awayModeStrings[] = -{ - // TRANSLATORS: away type in status bar - N_("(O) on keyboard"), - // TRANSLATORS: away type in status bar - N_("(A) away"), - // TRANSLATORS: away type in status bar - N_("(?) away") -}; - -std::string LocalPlayer::getAwayModeString() -{ - return gettext(getVarItem(&awayModeStrings[0], - mAwayMode, awayModeSize)); -} - const unsigned cameraModeSize = 2; static const char *const cameraModeStrings[] = @@ -2576,7 +2521,7 @@ void LocalPlayer::tryPingRequest() void LocalPlayer::setAway(const std::string &message) { setAfkMessage(message); - changeAwayMode(); + modifiers->changeAwayMode(); updateStatus(); } @@ -2605,7 +2550,7 @@ void LocalPlayer::setPseudoAway(const std::string &message) void LocalPlayer::afkRespond(ChatTab *const tab, const std::string &nick) { - if (mAwayMode) + if (settings.awayMode) { const int time = cur_time; if (mAfkTime == 0 || time < mAfkTime @@ -3399,7 +3344,7 @@ void LocalPlayer::updateStatus() const if (mTradebot && shopWindow && !shopWindow->isShopEmpty()) status |= BeingFlag::SHOP; - if (mAwayMode || mPseudoAwayMode) + if (settings.awayMode || mPseudoAwayMode) status |= BeingFlag::AWAY; if (mInactive) diff --git a/src/being/localplayer.h b/src/being/localplayer.h index cf604a1ca..3aabda22d 100644 --- a/src/being/localplayer.h +++ b/src/being/localplayer.h @@ -232,15 +232,10 @@ class LocalPlayer final : public Being, void pingResponse(); - void changeAwayMode(); - void setAway(const std::string &message); void setPseudoAway(const std::string &message); - bool getAway() const A_WARN_UNUSED - { return mAwayMode; } - bool getPseudoAway() const A_WARN_UNUSED { return mPseudoAwayMode; } @@ -392,8 +387,6 @@ class LocalPlayer final : public Being, void setTestParticle(const std::string &fileName, const bool updateHash = true); - std::string getAwayModeString(); - static std::string getCameraModeString(); int getLastAttackX() const override final @@ -412,6 +405,15 @@ class LocalPlayer final : public Being, void updateMusic(); + void setAfkTime(const int v) + { mAfkTime = v; } + + void setAwayDialog(OkDialog *const dialog) + { mAwayDialog = dialog; } + + AwayListener *getAwayListener() const A_WARN_UNUSED + { return mAwayListener; } + protected: void updateCoords() override final; @@ -534,7 +536,6 @@ class LocalPlayer final : public Being, // Tells if the path was set using mouse bool mPathSetByMouse; bool mWaitPing; - bool mAwayMode; bool mPseudoAwayMode; bool mShowNavigePath; }; diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp index cdb1a5f03..fc86bc7db 100644 --- a/src/eventsmanager.cpp +++ b/src/eventsmanager.cpp @@ -498,7 +498,7 @@ void EventsManager::handleActive(const SDL_Event &event) WindowManager::setIsMinimized(false); if (inGame && player_node) { - if (!player_node->getAway()) + if (!settings.awayMode) fpsLimit = config.getIntValue("fpslimit"); player_node->setHalfAway(false); } @@ -510,7 +510,7 @@ void EventsManager::handleActive(const SDL_Event &event) client->setState(STATE_EXIT); #else WindowManager::setIsMinimized(true); - if (inGame && player_node && !player_node->getAway()) + if (inGame && player_node && !settings.awayMode) { fpsLimit = config.getIntValue("altfpslimit"); player_node->setHalfAway(true); diff --git a/src/game.cpp b/src/game.cpp index f97b55d66..aaa0ed9cf 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -686,7 +686,7 @@ void Game::adjustPerfomance() mNextAdjustTime = time + adjustDelay; if (mAdjustLevel > 3 || !player_node || player_node->getHalfAway() - || player_node->getAway()) + || settings.awayMode) { return; } @@ -906,7 +906,7 @@ void Game::updateFrameRate(int fpsLimit) { if (!fpsLimit) { - if (player_node && player_node->getAway()) + if (settings.awayMode) { if (settings.inputFocused || settings.mouseFocused) fpsLimit = config.getIntValue("fpslimit"); @@ -934,7 +934,7 @@ void Game::handleInput() eventsManager.handleGameEvents(); // If the user is configuring the keys then don't respond. - if (!player_node || !keyboard.isEnabled() || player_node->getAway()) + if (!keyboard.isEnabled() || settings.awayMode) { BLOCK_END("Game::handleInput 1") return; diff --git a/src/gamemodifiers.cpp b/src/gamemodifiers.cpp index 7c94b5c4c..cd3f1d352 100644 --- a/src/gamemodifiers.cpp +++ b/src/gamemodifiers.cpp @@ -22,13 +22,20 @@ #include "configuration.h" #include "settings.h" +#include "soundmanager.h" #include "being/localplayer.h" +#include "gui/dialogtype.h" #include "gui/viewport.h" +#include "gui/windows/chatwindow.h" +#include "gui/windows/okdialog.h" +#include "gui/windows/outfitwindow.h" + #include "gui/widgets/tabs/chattab.h" +#include "listeners/awaylistener.h" #include "listeners/updatestatuslistener.h" #include "utils/gettext.h" @@ -492,3 +499,62 @@ std::string GameModifiers::getMapDrawTypeString() return gettext(getVarItem(&mapDrawTypeStrings[0], settings.mapDrawType, mapDrawTypeSize)); } + +const unsigned awayModeSize = 2; + +void GameModifiers::changeAwayMode() +{ + if (!player_node) + return; + + settings.awayMode = !settings.awayMode; + player_node->setAfkTime(0); + player_node->setHalfAway(false); + player_node->updateName(); + UpdateStatusListener::distributeEvent(); + if (settings.awayMode) + { + if (chatWindow) + chatWindow->clearAwayLog(); + + player_node->cancelFollow(); + player_node->navigateClean(); + if (outfitWindow) + outfitWindow->wearAwayOutfit(); + // TRANSLATORS: away message box header + OkDialog *const dialog = new OkDialog(_("Away"), + config.getStringValue("afkMessage"), + DialogType::SILENCE, true, false); + player_node->setAwayDialog(dialog); + dialog->addActionListener(player_node->getAwayListener()); + soundManager.volumeOff(); + player_node->addAfkEffect(); + } + else + { + player_node->setAwayDialog(nullptr); + soundManager.volumeRestore(); + if (chatWindow) + { + chatWindow->displayAwayLog(); + chatWindow->clearAwayLog(); + } + player_node->removeAfkEffect(); + } +} + +static const char *const awayModeStrings[] = +{ + // TRANSLATORS: away type in status bar + N_("(O) on keyboard"), + // TRANSLATORS: away type in status bar + N_("(A) away"), + // TRANSLATORS: away type in status bar + N_("(?) away") +}; + +std::string GameModifiers::getAwayModeString() +{ + return gettext(getVarItem(&awayModeStrings[0], + settings.awayMode, awayModeSize)); +} diff --git a/src/gamemodifiers.h b/src/gamemodifiers.h index 75b871136..76c23003a 100644 --- a/src/gamemodifiers.h +++ b/src/gamemodifiers.h @@ -66,6 +66,8 @@ class GameModifiers final void changeGameModifiers(); + void changeAwayMode(); + void setQuickDropCounter(const int n); std::string getMoveTypeString(); @@ -94,6 +96,8 @@ class GameModifiers final std::string getMapDrawTypeString(); + std::string getAwayModeString(); + protected: static const char *getVarItem(const char *const *const arr, const unsigned index, diff --git a/src/gui/popups/statuspopup.cpp b/src/gui/popups/statuspopup.cpp index 476871e0b..776845bfa 100644 --- a/src/gui/popups/statuspopup.cpp +++ b/src/gui/popups/statuspopup.cpp @@ -166,7 +166,7 @@ void StatusPopup::updateLabels() const InputAction::DISABLE_GAME_MODIFIERS); setLabelText(12, modifiers->getImitationModeString(), InputAction::CHANGE_IMITATION_MODE); - setLabelText(13, player_node->getAwayModeString(), + setLabelText(13, modifiers->getAwayModeString(), InputAction::AWAY); setLabelText(14, LocalPlayer::getCameraModeString(), InputAction::CAMERA); diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index 776ad9501..d4ae8ed14 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -1711,7 +1711,7 @@ void ChatWindow::loadCustomList() void ChatWindow::addToAwayLog(const std::string &line) { - if (!player_node || !player_node->getAway()) + if (!settings.awayMode) return; if (mAwayLog.size() > 20) diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp index a371f9b52..c4b645424 100644 --- a/src/gui/windows/statuswindow.cpp +++ b/src/gui/windows/statuswindow.cpp @@ -660,7 +660,7 @@ void StatusWindow::updateStatusBar(ProgressBar *const bar, .append(" ").append(translateLetter2( modifiers->getImitationModeString())) .append(translateLetter2(LocalPlayer::getCameraModeString())) - .append(translateLetter2(player_node->getAwayModeString()))); + .append(translateLetter2(modifiers->getAwayModeString()))); bar->setProgress(50); if (settings.disableGameModifiers) diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index f8d3f7505..6cb2c998b 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -653,7 +653,7 @@ void InputManager::updateConditionMask() if (!BuyDialog::isActive() && !SellDialog::isActive()) mMask |= InputCondition::NOBUYSELL; - if (!player_node || !player_node->getAway()) + if (!settings.awayMode) mMask |= InputCondition::NOAWAY; if (!setupWindow || !setupWindow->isWindowVisible()) diff --git a/src/listeners/awaylistener.cpp b/src/listeners/awaylistener.cpp index 1fb7dd4a9..17e48c1a8 100644 --- a/src/listeners/awaylistener.cpp +++ b/src/listeners/awaylistener.cpp @@ -22,6 +22,9 @@ #include "listeners/awaylistener.h" +#include "gamemodifiers.h" +#include "settings.h" + #include "being/localplayer.h" #include "gui/windows/outfitwindow.h" @@ -32,9 +35,9 @@ void AwayListener::action(const ActionEvent &event) { - if (event.getId() == "ok" && player_node && player_node->getAway()) + if (event.getId() == "ok" && modifiers && player_node && settings.awayMode) { - player_node->changeAwayMode(); + modifiers->changeAwayMode(); player_node->updateStatus(); if (outfitWindow) outfitWindow->unwearAwayOutfit(); diff --git a/src/settings.h b/src/settings.h index 21b0fdf91..1c9a4b8f0 100644 --- a/src/settings.h +++ b/src/settings.h @@ -70,7 +70,8 @@ class Settings final limitFps(false), inputFocused(true), mouseFocused(true), - disableGameModifiers(false) + disableGameModifiers(false), + awayMode(false) { } std::string updateHost; @@ -110,6 +111,7 @@ class Settings final bool inputFocused; bool mouseFocused; bool disableGameModifiers; + bool awayMode; }; extern Settings settings; |