diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-12-06 01:30:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-12-06 01:30:04 +0300 |
commit | 7a2d595785a61ec874ddc566e0d999495684c2aa (patch) | |
tree | c0b6d8b0137e002eb4847d8ead44562264ad1e18 | |
parent | 2d452dd8faf2529fda01913b0ab26f4a1f22ef3d (diff) | |
download | plus-7a2d595785a61ec874ddc566e0d999495684c2aa.tar.gz plus-7a2d595785a61ec874ddc566e0d999495684c2aa.tar.bz2 plus-7a2d595785a61ec874ddc566e0d999495684c2aa.tar.xz plus-7a2d595785a61ec874ddc566e0d999495684c2aa.zip |
Add gm commands to chat autocomplete list (only for gms)
-rw-r--r-- | data/perserver/default/CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/perserver/default/Makefile.am | 3 | ||||
-rw-r--r-- | data/perserver/default/gmcommands.txt | 32 | ||||
-rw-r--r-- | packaging/windows/setup.nsi | 1 | ||||
-rw-r--r-- | src/gui/chatwindow.cpp | 30 | ||||
-rw-r--r-- | src/gui/chatwindow.h | 3 | ||||
-rw-r--r-- | src/gui/didyouknowwindow.cpp | 6 | ||||
-rw-r--r-- | src/gui/helpwindow.cpp | 6 | ||||
-rw-r--r-- | src/localplayer.cpp | 4 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 9 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 3 |
11 files changed, 84 insertions, 14 deletions
diff --git a/data/perserver/default/CMakeLists.txt b/data/perserver/default/CMakeLists.txt index 61bd98df1..f4e5c6cae 100644 --- a/data/perserver/default/CMakeLists.txt +++ b/data/perserver/default/CMakeLists.txt @@ -1,5 +1,6 @@ SET (FILES charcreation.xml + gmcommands.txt ) INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/perserver/default) diff --git a/data/perserver/default/Makefile.am b/data/perserver/default/Makefile.am index 7ab87da67..08e324ca3 100644 --- a/data/perserver/default/Makefile.am +++ b/data/perserver/default/Makefile.am @@ -1,7 +1,8 @@ defaultdir = $(pkgdatadir)/data/perserver/default default_DATA = \ - charcreation.xml + charcreation.xml \ + gmcommands.txt EXTRA_DIST = \ $(default_DATA) \ diff --git a/data/perserver/default/gmcommands.txt b/data/perserver/default/gmcommands.txt new file mode 100644 index 000000000..da271a12f --- /dev/null +++ b/data/perserver/default/gmcommands.txt @@ -0,0 +1,32 @@ +@spawn +@item +@hugo +@linus +@warp +@goto +@jump +@save +@storage +@gstorage +@hide +@visible +@invisible +@die +@kill +@alive +@blvl +@jlvl +@pvpon +@pvpoff +@killmonster +@kick +@broadcast +@localbroadcast +@hairstyle +@haircolor +@ignorelist +@killer +@killable +@summon +@skill-learn +@ipcheck diff --git a/packaging/windows/setup.nsi b/packaging/windows/setup.nsi index eb0e5ffe9..ebb2002a1 100644 --- a/packaging/windows/setup.nsi +++ b/packaging/windows/setup.nsi @@ -320,6 +320,7 @@ Section "Core files (required)" SecCore SetOutPath "$INSTDIR\data\icons\" File "${SRCDIR}\data\icons\manaplus.ico" SetOutPath "$INSTDIR\data\perserver\default\" + File "${SRCDIR}\data\perserver\default\*.txt" File "${SRCDIR}\data\perserver\default\*.xml" SetOutPath "$INSTDIR\docs" File "${SRCDIR}\docs\FAQ.txt" diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 9ba54016e..33c24e9c7 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -60,6 +60,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "resources/resourcemanager.h" + #include <guichan/focushandler.hpp> #include <guichan/focuslistener.hpp> @@ -152,7 +154,8 @@ public: ChatWindow::ChatWindow(): Window(_("Chat"), false, nullptr, "chat.xml"), mTmpVisible(false), - mChatHistoryIndex(0) + mChatHistoryIndex(0), + mGMLoaded(false) { listen(CHANNEL_NOTICES); listen(Mana::CHANNEL_ATTRIBUTES); @@ -212,6 +215,8 @@ ChatWindow::ChatWindow(): mColorPicker->setVisible(config.getBoolValue("showChatColorsList")); fillCommands(); + if (player_node && player_node->isGM()) + loadGMCommands(); initTradeFilter(); loadCustomList(); parseHighlights(); @@ -302,6 +307,29 @@ void ChatWindow::fillCommands() mCommands.push_back("/pseudoaway "); } +void ChatWindow::loadGMCommands() +{ + if (mGMLoaded) + return; + + const char *fileName = "gmcommands.txt"; + ResourceManager *resman = ResourceManager::getInstance(); + std::vector<std::string> list; + resman->loadTextFile(fileName, list); + std::vector<std::string>::const_iterator it = list.begin(); + std::vector<std::string>::const_iterator it_end = list.end(); + + while (it != it_end) + { + const std::string str = *it; + if (!str.empty()) + mCommands.push_back(str); + + ++ it; + } + mGMLoaded = true; +} + void ChatWindow::resetToDefaultSize() { Window::resetToDefaultSize(); diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index 9d63ca402..3c1195e8f 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -243,6 +243,8 @@ class ChatWindow : public Window, void loadCustomList(); + void loadGMCommands(); + std::string doReplace(const std::string &msg); void adjustTabSize(); @@ -330,6 +332,7 @@ class ChatWindow : public Window, unsigned int mChatHistoryIndex; std::list<std::string> mAwayLog; std::vector<std::string> mHighlights; + bool mGMLoaded; }; extern ChatWindow *chatWindow; diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp index 9a913a305..b5a7da634 100644 --- a/src/gui/didyouknowwindow.cpp +++ b/src/gui/didyouknowwindow.cpp @@ -138,16 +138,16 @@ void DidYouKnowWindow::loadFile(int num) { std::string name = helpPath + langs[0] + "/" + file + ".txt"; if (resman->exists(name)) - lines = resman->loadTextFile(name); + resman->loadTextFile(name, lines); if (lines.empty() && langs.size() > 1) { name = helpPath + langs[1] + "/" + file + ".txt"; - lines = resman->loadTextFile(name); + resman->loadTextFile(name, lines); } } if (lines.empty()) - lines = resman->loadTextFile(helpPath + file + ".txt"); + resman->loadTextFile(helpPath + file + ".txt", lines); for (unsigned int i = 0; i < lines.size(); ++i) mBrowserBox->addRow(lines[i]); diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 49f309bca..b1175d709 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -114,16 +114,16 @@ void HelpWindow::loadFile(const std::string &file) { std::string name = helpPath + langs[0] + "/" + file + ".txt"; if (resman->exists(name)) - lines = resman->loadTextFile(name); + resman->loadTextFile(name, lines); if (lines.empty() && langs.size() > 1) { name = helpPath + langs[1] + "/" + file + ".txt"; - lines = resman->loadTextFile(name); + resman->loadTextFile(name, lines); } } if (lines.empty()) - lines = resman->loadTextFile(helpPath + file + ".txt"); + resman->loadTextFile(helpPath + file + ".txt", lines); for (unsigned int i = 0; i < lines.size(); ++i) mBrowserBox->addRow(lines[i]); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index cbf75a5f9..c83082a44 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -397,7 +397,11 @@ void LocalPlayer::setGMLevel(int level) mGMLevel = level; if (level > 0) + { setGM(true); + if (chatWindow) + chatWindow->loadGMCommands(); + } } diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index a99ca622e..c7552b9b7 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -634,18 +634,17 @@ bool ResourceManager::copyFile(const std::string &src, const std::string &dst) return true; } -std::vector<std::string> ResourceManager::loadTextFile( - const std::string &fileName) +bool ResourceManager::loadTextFile(const std::string &fileName, + std::vector<std::string> &lines) { int contentsLength; char *fileContents = static_cast<char*>( loadFile(fileName, contentsLength)); - std::vector<std::string> lines; if (!fileContents) { logger->log("Couldn't load text file: %s", fileName.c_str()); - return lines; + return false; } std::istringstream iss(std::string(fileContents, contentsLength)); @@ -655,7 +654,7 @@ std::vector<std::string> ResourceManager::loadTextFile( lines.push_back(line); free(fileContents); - return lines; + return true; } std::vector<std::string> ResourceManager::loadTextFileLocal( diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index f70fbece4..8cc851cca 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -217,7 +217,8 @@ class ResourceManager /** * Retrieves the contents of a text file (PhysFS). */ - std::vector<std::string> loadTextFile(const std::string &fileName); + bool loadTextFile(const std::string &fileName, + std::vector<std::string> &lines); /** * Retrieves the contents of a text file. |