From e9c84384d8d0e5b91678eb4722ae30bd3693703f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 19 Jun 2012 01:31:14 +0300 Subject: Add help search commands (?text). Example: ?warps It will open help page about warps. --- data/help/CMakeLists.txt | 3 +++ data/help/Makefile.am | 3 +++ data/help/about.txt | 10 +++----- data/help/searchmany.txt | 4 ++++ data/help/searchnotfound.txt | 7 ++++++ data/help/support.txt | 6 ++++- data/help/tags.idx | 13 +++++++++++ data/help/team.txt | 2 +- data/help/tips/15.txt | 2 ++ data/help/tips/CMakeLists.txt | 1 + data/help/tips/Makefile.am | 3 ++- src/gui/didyouknowwindow.cpp | 2 +- src/gui/helpwindow.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++ src/gui/helpwindow.h | 15 ++++++++++++ src/gui/widgets/chattab.cpp | 25 ++++++++++++++++---- src/gui/widgets/chattab.h | 2 ++ 16 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 data/help/searchmany.txt create mode 100644 data/help/searchnotfound.txt create mode 100644 data/help/tags.idx create mode 100644 data/help/tips/15.txt diff --git a/data/help/CMakeLists.txt b/data/help/CMakeLists.txt index 239539f7f..3c1ba234e 100644 --- a/data/help/CMakeLists.txt +++ b/data/help/CMakeLists.txt @@ -5,8 +5,11 @@ SET(FILES footer.txt header.txt index.txt + searchmany.txt + searchnotfound.txt skills.txt support.txt + tags.idx team.txt windows.txt ) diff --git a/data/help/Makefile.am b/data/help/Makefile.am index 38899eaf1..05ff4d151 100644 --- a/data/help/Makefile.am +++ b/data/help/Makefile.am @@ -9,8 +9,11 @@ help_DATA = \ footer.txt \ header.txt \ index.txt \ + searchmany.txt \ + searchnotfound.txt \ skills.txt \ support.txt \ + tags.idx \ team.txt \ windows.txt diff --git a/data/help/about.txt b/data/help/about.txt index 92f52932b..7aa83747c 100644 --- a/data/help/about.txt +++ b/data/help/about.txt @@ -2,16 +2,12 @@ ##3 === <> === - <<##2ManaPlus##P is extended client based on code from ##2Mana##P client. + <<##2ManaPlus##P is extended client based on old code from ##2Mana##P client. Added many features, improved perfomance, stability, security and more.>> <<##2ManaPlus##P is a serious effort to create an innovative free and open - source MMORPG Client. Mana uses 2D graphics and aims to create a large + source MMORPG Client. ManaPlus uses 2D graphics and aims to create a large and diverse interactive world. It is licensed under the GPL, making sure this game can't ever run away from you.>> - <> - + -> @@team|<>@@ diff --git a/data/help/searchmany.txt b/data/help/searchmany.txt new file mode 100644 index 000000000..45a170d95 --- /dev/null +++ b/data/help/searchmany.txt @@ -0,0 +1,4 @@ + <- @@index|<>@@ + + +##3 === <> ===##1 diff --git a/data/help/searchnotfound.txt b/data/help/searchnotfound.txt new file mode 100644 index 000000000..196881186 --- /dev/null +++ b/data/help/searchnotfound.txt @@ -0,0 +1,7 @@ + <- @@index|<>@@ + + +##3 === <> === +<> + + diff --git a/data/help/support.txt b/data/help/support.txt index 40aeedcee..bd50b471c 100644 --- a/data/help/support.txt +++ b/data/help/support.txt @@ -12,6 +12,11 @@ <> ##2 #evolonline ##P@##2 irc.freenode.net +<< For ManaPlus Online support: + + <> +##2 #manaplus #evolonline ##P@##2 irc.freenode.net + << For TMW support: @@ -23,4 +28,3 @@ developers and how to contact them.>> <> - diff --git a/data/help/tags.idx b/data/help/tags.idx new file mode 100644 index 000000000..c3978cc65 --- /dev/null +++ b/data/help/tags.idx @@ -0,0 +1,13 @@ +about|about +about|about manaplus +about|manaplus about +about|manaplus +chatcommands|chat +chatcommands|commands +chatcommands|chat commands +chatcommands|chat command +skills|skills +index|index +team|team +tips/12|warp +tips/12|warps diff --git a/data/help/team.txt b/data/help/team.txt index db0b602d8..6d36b3240 100644 --- a/data/help/team.txt +++ b/data/help/team.txt @@ -13,7 +13,7 @@ ##9Mihail Barer (Necromonger) <> ##3== <> == -##9alastrim (jp) +##9alastrim (pt) ##9Aline Ferraz de Souza (Freya) (pt, pt_BR) ##9Andrei Karas (4144) (ru) ##9Bernard Hugonnet (Nard) <> (fr) diff --git a/data/help/tips/15.txt b/data/help/tips/15.txt new file mode 100644 index 000000000..0e877ba7a --- /dev/null +++ b/data/help/tips/15.txt @@ -0,0 +1,2 @@ +<> diff --git a/data/help/tips/CMakeLists.txt b/data/help/tips/CMakeLists.txt index dcbfcdf7e..44195aacb 100644 --- a/data/help/tips/CMakeLists.txt +++ b/data/help/tips/CMakeLists.txt @@ -15,6 +15,7 @@ SET(FILES 12.txt 13.txt 14.txt + 15.txt ) INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/help/tips) diff --git a/data/help/tips/Makefile.am b/data/help/tips/Makefile.am index 2972ef839..8551129b6 100644 --- a/data/help/tips/Makefile.am +++ b/data/help/tips/Makefile.am @@ -17,7 +17,8 @@ helptips_DATA = \ 11.txt \ 12.txt \ 13.txt \ - 14.txt + 14.txt \ + 15.txt EXTRA_DIST = \ $(helptips_DATA) \ diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp index 50e0f0188..d17d4f58a 100644 --- a/src/gui/didyouknowwindow.cpp +++ b/src/gui/didyouknowwindow.cpp @@ -46,7 +46,7 @@ #include "debug.h" static const int minTip = 1; -static const int maxTip = 14; +static const int maxTip = 15; DidYouKnowWindow::DidYouKnowWindow(): Window(_("Did You Know?"), false, nullptr, "didyouknow.xml") diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 82a70bca9..c2b0d873f 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -80,6 +80,7 @@ HelpWindow::HelpWindow(): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); + loadTags(); } void HelpWindow::action(const gcn::ActionEvent &event) @@ -120,3 +121,56 @@ void HelpWindow::loadFile(const std::string &file) for (unsigned int i = 0; i < lines.size(); ++i) mBrowserBox->addRow(lines[i]); } + +void HelpWindow::loadTags() +{ + std::string helpPath = branding.getStringValue("helpPath"); + if (helpPath.empty()) + helpPath = paths.getStringValue("help"); + StringVect lines; + ResourceManager::loadTextFile(helpPath + "tags.idx", lines); + for (StringVectCIter it = lines.begin(), it_end = lines.end(); + it != it_end; ++ it) + { + const std::string &str = *it; + size_t idx = str.find('|'); + if (idx != std::string::npos) + mTagFileMap[str.substr(idx + 1)].insert(str.substr(0, idx)); + } +} + +void HelpWindow::search(const std::string &text0) +{ + std::string text = text0; + toLower(text); + if (mTagFileMap.find(text) == mTagFileMap.end()) + { + loadHelp("searchnotfound"); + } + else + { + const HelpNames &names = mTagFileMap[text]; + if (names.size() == 1) + { + loadHelp(*names.begin()); + } + else + { + if (!translator) + return; + mBrowserBox->clearRows(); + loadFile("header"); + loadFile("searchmany"); + for (HelpNamesCIter it = names.begin(), it_end = names.end(); + it != it_end; ++ it) + { + const char *str = (*it).c_str(); + mBrowserBox->addRow(strprintf(" -> @@%s|%s@@", str, + translator->getChar(str))); + } + loadFile("footer"); + mScrollArea->setVerticalScrollAmount(0); + setVisible(true); + } + } +} diff --git a/src/gui/helpwindow.h b/src/gui/helpwindow.h index 675b5c35a..9d89c03c4 100644 --- a/src/gui/helpwindow.h +++ b/src/gui/helpwindow.h @@ -30,6 +30,9 @@ #include "localconsts.h" +#include +#include + class BrowserBox; class LinkHandler; @@ -38,6 +41,10 @@ namespace gcn class ScrollArea; } +typedef std::set HelpNames; +typedef HelpNames::const_iterator HelpNamesCIter; +typedef std::map HelpTagsMap; + /** * The help dialog. */ @@ -66,11 +73,19 @@ class HelpWindow : public Window, public LinkHandler, */ void loadHelp(const std::string &helpFile); + /** + * Seach for given text in tags. + */ + void search(const std::string &text); + private: + void loadTags(); + void loadFile(const std::string &file); BrowserBox *mBrowserBox; gcn::ScrollArea *mScrollArea; + HelpTagsMap mTagFileMap; }; extern HelpWindow *helpWindow; diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 5f97cd613..fa61f0dcd 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -30,6 +30,8 @@ #include "logger.h" #include "sound.h" +#include "gui/helpwindow.h" + #include "gui/widgets/browserbox.h" #include "gui/widgets/scrollarea.h" #include "gui/widgets/itemlinkhandler.h" @@ -379,11 +381,18 @@ void ChatTab::chatInput(const std::string &message) if (commandHandler) commandHandler->replaceVars(msg); - // Prepare ordinary message - if (msg[0] != '/') - handleInput(msg); - else - handleCommand(std::string(msg, 1)); + switch (msg[0]) + { + case '/': + handleCommand(std::string(msg, 1)); + break; + case '?': + handleHelp(std::string(msg, 1)); + break; + default: + handleInput(msg); + break; + } } void ChatTab::scroll(int amount) @@ -414,6 +423,12 @@ void ChatTab::handleCommand(const std::string &msg) commandHandler->handleCommands(msg, this); } +void ChatTab::handleHelp(const std::string &msg) +{ + if (commandHandler) + helpWindow->search(msg); +} + bool ChatTab::handleCommands(const std::string &type, const std::string &args) { // need split to commands and call each diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h index 455152693..e1e2c211d 100644 --- a/src/gui/widgets/chattab.h +++ b/src/gui/widgets/chattab.h @@ -177,6 +177,8 @@ class ChatTab : public Tab virtual void handleCommand(const std::string &msg); + virtual void handleHelp(const std::string &msg); + virtual void getAutoCompleteList(StringVect&) const {} -- cgit v1.2.3-70-g09d2