diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-07-12 20:11:09 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-07-12 20:20:59 +0300 |
commit | aeec9ca9881bbd4fdc332b342b09a795ee3961b4 (patch) | |
tree | 3e32a1dd828464a7e6e8c439f658421772a62f40 | |
parent | 36027fc87b99b8f048265f6ac470227a1c32d481 (diff) | |
download | manaverse-aeec9ca9881bbd4fdc332b342b09a795ee3961b4.tar.gz manaverse-aeec9ca9881bbd4fdc332b342b09a795ee3961b4.tar.bz2 manaverse-aeec9ca9881bbd4fdc332b342b09a795ee3961b4.tar.xz manaverse-aeec9ca9881bbd4fdc332b342b09a795ee3961b4.zip |
add ability to show assigned keys in browserbox.
Example: This is chat modifier key: ###ChatMod;.
If chat mod key is left shift, it will show:
"This is chat modifier key: left shift."
-rw-r--r-- | src/gui/didyouknowwindow.cpp | 1 | ||||
-rw-r--r-- | src/gui/helpwindow.cpp | 1 | ||||
-rw-r--r-- | src/gui/npcdialog.cpp | 1 | ||||
-rw-r--r-- | src/gui/updaterwindow.cpp | 1 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 22 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.h | 4 | ||||
-rw-r--r-- | src/inputmanager.cpp | 14 | ||||
-rw-r--r-- | src/inputmanager.h | 4 |
8 files changed, 46 insertions, 2 deletions
diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp index 17b89b9b6..1c08010f2 100644 --- a/src/gui/didyouknowwindow.cpp +++ b/src/gui/didyouknowwindow.cpp @@ -81,6 +81,7 @@ DidYouKnowWindow::DidYouKnowWindow() : mBrowserBox->setFont(gui->getHelpFont()); mBrowserBox->setProcessVersion(true); mBrowserBox->setEnableImages(true); + mBrowserBox->setEnableKeys(true); place(0, 0, mScrollArea, 5, 3).setPadding(3); place(0, 3, mOpenAgainCheckBox, 5); diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 6ad12d6c7..f760a14cb 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -73,6 +73,7 @@ HelpWindow::HelpWindow() : mBrowserBox->setFont(gui->getHelpFont()); mBrowserBox->setProcessVersion(true); mBrowserBox->setEnableImages(true); + mBrowserBox->setEnableKeys(true); place(4, 3, mDYKButton); place(0, 0, mScrollArea, 5, 3).setPadding(3); diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index be2404875..03e0006b5 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -133,6 +133,7 @@ NpcDialog::NpcDialog(const int npcId) : mTextBox->setMaxRow(config.getIntValue("ChatLogLength")); mTextBox->setLinkHandler(mItemLinkHandler); mTextBox->setFont(gui->getNpcFont()); + mTextBox->setEnableKeys(true); mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mScrollArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 80ff0c580..55726d7d5 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -195,6 +195,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mProgressBar->setSmoothProgress(false); mBrowserBox->setOpaque(false); mBrowserBox->setLinkHandler(this); + mBrowserBox->setEnableKeys(true); mPlayButton->setEnabled(false); ContainerPlacer placer; diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index ff269d384..6527019de 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -24,6 +24,7 @@ #include "gui/widgets/browserbox.h" #include "client.h" +#include "inputmanager.h" #include "gui/gui.h" #include "gui/sdlfont.h" @@ -67,6 +68,7 @@ BrowserBox::BrowserBox(const Widget2 *const widget, const unsigned int mode, mAlwaysUpdate(true), mProcessVersion(false), mEnableImages(false), + mEnableKeys(false), mPadding(0), mNewLinePadding(15), mBackgroundColor(getThemeColor(Theme::BACKGROUND)), @@ -157,8 +159,26 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) BrowserLink bLink; // Check for links in format "@@link|Caption@@" - idx1 = tmp.find("@@"); const int sz = static_cast<int>(mTextRows.size()); + + if (mEnableKeys) + { + idx1 = tmp.find("###"); + while (idx1 != std::string::npos) + { + const size_t idx2 = tmp.find(";", idx1); + if (idx2 == std::string::npos) + break; + + const std::string str = inputManager.getKeyValueByName( + "key" + tmp.substr(idx1 + 3, idx2 - idx1 - 3)); + tmp.replace(idx1, idx2 - idx1 + 1, str); + + idx1 = tmp.find("###"); + } + } + + idx1 = tmp.find("@@"); while (idx1 != std::string::npos) { const size_t idx2 = tmp.find("|", idx1); diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 3fa8bf579..c9219f9ba 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -225,6 +225,9 @@ class BrowserBox final : public gcn::Widget, void setEnableImages(bool n) { mEnableImages = n; } + void setEnableKeys(bool n) + { mEnableKeys = n; } + std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED; int getPadding() const A_WARN_UNUSED @@ -261,6 +264,7 @@ class BrowserBox final : public gcn::Widget, bool mAlwaysUpdate; bool mProcessVersion; bool mEnableImages; + bool mEnableKeys; int mPadding; int mNewLinePadding; diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 4b5988a57..3b99c3498 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -66,7 +66,8 @@ static class KeyFunctor final InputManager::InputManager() : mSetupInput(nullptr), mNewKeyIndex(Input::KEY_NO_VALUE), - mMask(1) + mMask(1), + mNameMap() { } @@ -104,6 +105,7 @@ void InputManager::retrieve() const char *const cf = keyData[i].configField; if (*cf) { + mNameMap[cf] = i; KeyFunction &kf = mKey[i]; const std::string keyStr = config.getValue(cf, ""); if (keyStr.empty()) @@ -392,6 +394,16 @@ std::string InputManager::getKeyValueString(const int index) const return keyStr; } +std::string InputManager::getKeyValueByName(const std::string &keyName) +{ + const std::map<std::string, int>::const_iterator + it = mNameMap.find(keyName); + + if (it == mNameMap.end()) + return std::string(); + return getKeyValueString((*it).second); +} + void InputManager::addActionKey(const int action, const int type, const int val) { diff --git a/src/inputmanager.h b/src/inputmanager.h index 71f1f8a72..2f3a9afc1 100644 --- a/src/inputmanager.h +++ b/src/inputmanager.h @@ -120,6 +120,8 @@ class InputManager final std::string getKeyStringLong(const int index) const A_WARN_UNUSED; + std::string getKeyValueByName(const std::string &keyName); + void addActionKey(const int action, const int type, const int val); void setNewKey(const SDL_Event &event, const int type); @@ -176,6 +178,8 @@ class InputManager final int mMask; + std::map<std::string, int> mNameMap; + KeyFunction mKey[Input::KEY_TOTAL]; /**< Pointer to all the key data */ }; |