summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-19 01:31:14 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-19 01:33:40 +0300
commite9c84384d8d0e5b91678eb4722ae30bd3693703f (patch)
tree6f30e3d8500f9b0c4620a6c5393df498a04c0a0c /src/gui
parent0a068a5f08b1805d5b385b8f81aaf3c7199bff06 (diff)
downloadmanaverse-e9c84384d8d0e5b91678eb4722ae30bd3693703f.tar.gz
manaverse-e9c84384d8d0e5b91678eb4722ae30bd3693703f.tar.bz2
manaverse-e9c84384d8d0e5b91678eb4722ae30bd3693703f.tar.xz
manaverse-e9c84384d8d0e5b91678eb4722ae30bd3693703f.zip
Add help search commands (?text).
Example: ?warps It will open help page about warps.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/didyouknowwindow.cpp2
-rw-r--r--src/gui/helpwindow.cpp54
-rw-r--r--src/gui/helpwindow.h15
-rw-r--r--src/gui/widgets/chattab.cpp25
-rw-r--r--src/gui/widgets/chattab.h2
5 files changed, 92 insertions, 6 deletions
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 <map>
+#include <set>
+
class BrowserBox;
class LinkHandler;
@@ -38,6 +41,10 @@ namespace gcn
class ScrollArea;
}
+typedef std::set<std::string> HelpNames;
+typedef HelpNames::const_iterator HelpNamesCIter;
+typedef std::map<std::string, HelpNames> 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
{}