diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-08-27 16:57:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-08-27 16:57:34 +0300 |
commit | e70704f2b1609b49319e34f466afaf4454d92382 (patch) | |
tree | 8e6cccc2103fcb80e420c95a28801c6f7aff2435 | |
parent | 8f173afdd496eda7fddd2b166e11626651600501 (diff) | |
download | manaplus-e70704f2b1609b49319e34f466afaf4454d92382.tar.gz manaplus-e70704f2b1609b49319e34f466afaf4454d92382.tar.bz2 manaplus-e70704f2b1609b49319e34f466afaf4454d92382.tar.xz manaplus-e70704f2b1609b49319e34f466afaf4454d92382.zip |
Move method replaceVars into chatutils.cpp.
-rw-r--r-- | src/commands.cpp | 75 | ||||
-rw-r--r-- | src/commands.h | 5 | ||||
-rw-r--r-- | src/gui/widgets/tabs/chattab.cpp | 3 | ||||
-rw-r--r-- | src/utils/chatutils.cpp | 77 | ||||
-rw-r--r-- | src/utils/chatutils.h | 2 |
5 files changed, 81 insertions, 81 deletions
diff --git a/src/commands.cpp b/src/commands.cpp index ac854bc39..15f76351d 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -159,79 +159,4 @@ static void uploadFile(const std::string &str, upload->start(); } -void replaceVars(std::string &str) -{ - if (!localPlayer || !actorManager) - return; - - if (str.find("<PLAYER>") != std::string::npos) - { - const Being *target = localPlayer->getTarget(); - if (!target || target->getType() != ActorType::PLAYER) - { - target = actorManager->findNearestLivingBeing( - localPlayer, 20, ActorType::PLAYER, true); - } - if (target) - replaceAll(str, "<PLAYER>", target->getName()); - else - replaceAll(str, "<PLAYER>", ""); - } - if (str.find("<MONSTER>") != std::string::npos) - { - const Being *target = localPlayer->getTarget(); - if (!target || target->getType() != ActorType::MONSTER) - { - target = actorManager->findNearestLivingBeing( - localPlayer, 20, ActorType::MONSTER, true); - } - if (target) - replaceAll(str, "<MONSTER>", target->getName()); - else - replaceAll(str, "<MONSTER>", ""); - } - if (str.find("<PEOPLE>") != std::string::npos) - { - StringVect names; - std::string newStr; - actorManager->getPlayerNames(names, false); - FOR_EACH (StringVectCIter, it, names) - { - if (*it != localPlayer->getName()) - newStr.append(*it).append(","); - } - if (newStr[newStr.size() - 1] == ',') - newStr = newStr.substr(0, newStr.size() - 1); - if (!newStr.empty()) - replaceAll(str, "<PEOPLE>", newStr); - else - replaceAll(str, "<PEOPLE>", ""); - } - if (str.find("<PARTY>") != std::string::npos) - { - StringVect names; - std::string newStr; - const Party *party = nullptr; - if (localPlayer->isInParty() && (party = localPlayer->getParty())) - { - party->getNames(names); - FOR_EACH (StringVectCIter, it, names) - { - if (*it != localPlayer->getName()) - newStr.append(*it).append(","); - } - if (newStr[newStr.size() - 1] == ',') - newStr = newStr.substr(0, newStr.size() - 1); - if (!newStr.empty()) - replaceAll(str, "<PARTY>", newStr); - else - replaceAll(str, "<PARTY>", ""); - } - else - { - replaceAll(str, "<PARTY>", ""); - } - } -} - } // namespace Commands diff --git a/src/commands.h b/src/commands.h index 424969210..6bcdf6790 100644 --- a/src/commands.h +++ b/src/commands.h @@ -49,11 +49,6 @@ struct CommandInfo final bool useArgs; }; -namespace Commands -{ - void replaceVars(std::string &str); -} // namespace Commands - enum { END_COMMANDS = 0 diff --git a/src/gui/widgets/tabs/chattab.cpp b/src/gui/widgets/tabs/chattab.cpp index f9a6e960f..44ab6d89c 100644 --- a/src/gui/widgets/tabs/chattab.cpp +++ b/src/gui/widgets/tabs/chattab.cpp @@ -51,6 +51,7 @@ #include "resources/db/itemdb.h" +#include "utils/chatutils.h" #include "utils/delete2.h" #include "utils/gettext.h" @@ -398,7 +399,7 @@ void ChatTab::chatInput(const std::string &message) start = msg.find('[', start + 1); } - Commands::replaceVars(msg); + replaceVars(msg); switch (msg[0]) { diff --git a/src/utils/chatutils.cpp b/src/utils/chatutils.cpp index 09c2c69fb..41fcaa77b 100644 --- a/src/utils/chatutils.cpp +++ b/src/utils/chatutils.cpp @@ -20,8 +20,10 @@ #include "utils/chatutils.h" +#include "actormanager.h" #include "guild.h" #include "guildmanager.h" +#include "party.h" #include "being/localplayer.h" @@ -90,3 +92,78 @@ void outStringNormal(ChatTab *const tab, break; } } + +void replaceVars(std::string &str) +{ + if (!localPlayer || !actorManager) + return; + + if (str.find("<PLAYER>") != std::string::npos) + { + const Being *target = localPlayer->getTarget(); + if (!target || target->getType() != ActorType::PLAYER) + { + target = actorManager->findNearestLivingBeing( + localPlayer, 20, ActorType::PLAYER, true); + } + if (target) + replaceAll(str, "<PLAYER>", target->getName()); + else + replaceAll(str, "<PLAYER>", ""); + } + if (str.find("<MONSTER>") != std::string::npos) + { + const Being *target = localPlayer->getTarget(); + if (!target || target->getType() != ActorType::MONSTER) + { + target = actorManager->findNearestLivingBeing( + localPlayer, 20, ActorType::MONSTER, true); + } + if (target) + replaceAll(str, "<MONSTER>", target->getName()); + else + replaceAll(str, "<MONSTER>", ""); + } + if (str.find("<PEOPLE>") != std::string::npos) + { + StringVect names; + std::string newStr; + actorManager->getPlayerNames(names, false); + FOR_EACH (StringVectCIter, it, names) + { + if (*it != localPlayer->getName()) + newStr.append(*it).append(","); + } + if (newStr[newStr.size() - 1] == ',') + newStr = newStr.substr(0, newStr.size() - 1); + if (!newStr.empty()) + replaceAll(str, "<PEOPLE>", newStr); + else + replaceAll(str, "<PEOPLE>", ""); + } + if (str.find("<PARTY>") != std::string::npos) + { + StringVect names; + std::string newStr; + const Party *party = nullptr; + if (localPlayer->isInParty() && (party = localPlayer->getParty())) + { + party->getNames(names); + FOR_EACH (StringVectCIter, it, names) + { + if (*it != localPlayer->getName()) + newStr.append(*it).append(","); + } + if (newStr[newStr.size() - 1] == ',') + newStr = newStr.substr(0, newStr.size() - 1); + if (!newStr.empty()) + replaceAll(str, "<PARTY>", newStr); + else + replaceAll(str, "<PARTY>", ""); + } + else + { + replaceAll(str, "<PARTY>", ""); + } + } +} diff --git a/src/utils/chatutils.h b/src/utils/chatutils.h index 976110d9c..79f6f2093 100644 --- a/src/utils/chatutils.h +++ b/src/utils/chatutils.h @@ -29,4 +29,6 @@ void outStringNormal(ChatTab *const tab, const std::string &str, const std::string &def); +void replaceVars(std::string &str); + #endif // ACTIONS_ACTIONS_H |