From aeec9ca9881bbd4fdc332b342b09a795ee3961b4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 12 Jul 2013 20:11:09 +0300 Subject: 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." --- src/gui/widgets/browserbox.cpp | 22 +++++++++++++++++++++- src/gui/widgets/browserbox.h | 4 ++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src/gui/widgets') 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(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; -- cgit v1.2.3-70-g09d2