From 7a2d595785a61ec874ddc566e0d999495684c2aa Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 6 Dec 2011 01:30:04 +0300 Subject: Add gm commands to chat autocomplete list (only for gms) --- src/gui/chatwindow.cpp | 30 +++++++++++++++++++++++++++++- src/gui/chatwindow.h | 3 +++ src/gui/didyouknowwindow.cpp | 6 +++--- src/gui/helpwindow.cpp | 6 +++--- 4 files changed, 38 insertions(+), 7 deletions(-) (limited to 'src/gui') 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 #include @@ -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 list; + resman->loadTextFile(fileName, list); + std::vector::const_iterator it = list.begin(); + std::vector::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 mAwayLog; std::vector 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]); -- cgit v1.2.3-70-g09d2