From 5568018bd20a43c30caca0c6288e63bfae29a2e3 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Sun, 10 Nov 2019 19:06:03 +0200 Subject: SL-6109 Better key and table localization support and fix for key-replacing --- indra/llcommon/llkeybind.cpp | 31 +++---------- indra/llwindow/llkeyboard.cpp | 11 +++-- indra/llwindow/llkeyboard.h | 2 +- indra/newview/llkeyconflict.cpp | 3 +- indra/newview/llkeyconflict.h | 1 + .../default/xui/en/control_table_contents.xml | 52 ++++++++++++++++++++++ 6 files changed, 68 insertions(+), 32 deletions(-) diff --git a/indra/llcommon/llkeybind.cpp b/indra/llcommon/llkeybind.cpp index 46a3230240..ecfc289cb3 100644 --- a/indra/llcommon/llkeybind.cpp +++ b/indra/llcommon/llkeybind.cpp @@ -340,43 +340,24 @@ bool LLKeyBind::addKeyData(const LLKeyData& data) void LLKeyBind::replaceKeyData(EMouseClickType mouse, KEY key, MASK mask, bool ignore, U32 index) { - if (mouse != CLICK_NONE || key != KEY_NONE ) - { - // if both click and key are none, we are inserting a placeholder, we don't want to reset anything - // otherwise reset identical key - for (data_vector_t::iterator iter = mData.begin(); iter != mData.end(); iter++) - { - if (iter->mKey == key - && iter->mMouse == mouse - && iter->mIgnoreMasks == ignore - && (iter->mIgnoreMasks || iter->mMask == mask)) - { - iter->reset(); - break; - } - } - } - if (mData.size() > index) - { - mData[index] = LLKeyData(mouse, key, mask, ignore); - } - else - { - mData.push_back(LLKeyData(mouse, key, mask, ignore)); - } + replaceKeyData(LLKeyData(mouse, key, mask, ignore), index); } void LLKeyBind::replaceKeyData(const LLKeyData& data, U32 index) { if (!data.isEmpty()) { + // if both click and key are none (isEmpty()), we are inserting a placeholder, we don't want to reset anything + // otherwise reset identical key for (data_vector_t::iterator iter = mData.begin(); iter != mData.end(); iter++) { if (iter->mKey == data.mKey && iter->mMouse == data.mMouse && iter->mIgnoreMasks == data.mIgnoreMasks - && (iter->mIgnoreMasks || iter->mMask == data.mMask)) + && iter->mMask == data.mMask) { + // Replacing only fully equal combinations even in case 'ignore' is set + // Reason: Simplicity and user might decide to do a 'move' command as W and Shift+Ctrl+W, and 'run' as Shift+W iter->reset(); break; } diff --git a/indra/llwindow/llkeyboard.cpp b/indra/llwindow/llkeyboard.cpp index 8e75325859..5404ac50e5 100644 --- a/indra/llwindow/llkeyboard.cpp +++ b/indra/llwindow/llkeyboard.cpp @@ -327,7 +327,7 @@ BOOL LLKeyboard::keyFromString(const std::string& str, KEY *key) // static -std::string LLKeyboard::stringFromKey(KEY key) +std::string LLKeyboard::stringFromKey(KEY key, bool translate) { std::string res = get_if_there(sKeysToNames, key, std::string()); if (res.empty()) @@ -338,10 +338,13 @@ std::string LLKeyboard::stringFromKey(KEY key) res = std::string(buffer); } - LLKeyStringTranslatorFunc *trans = gKeyboard->mStringTranslator; - if (trans != NULL) + if (translate) { - res = trans(res.c_str()); + LLKeyStringTranslatorFunc *trans = gKeyboard->mStringTranslator; + if (trans != NULL) + { + res = trans(res.c_str()); + } } return res; diff --git a/indra/llwindow/llkeyboard.h b/indra/llwindow/llkeyboard.h index f6404164e7..36bd8bcbed 100644 --- a/indra/llwindow/llkeyboard.h +++ b/indra/llwindow/llkeyboard.h @@ -94,7 +94,7 @@ public: static BOOL maskFromString(const std::string& str, MASK *mask); // False on failure static BOOL keyFromString(const std::string& str, KEY *key); // False on failure - static std::string stringFromKey(KEY key); + static std::string stringFromKey(KEY key, bool translate = true); static std::string stringFromAccelerator( MASK accel_mask ); // separated for convinience, returns with "+": "Shift+" or "Shift+Alt+"... static std::string stringFromAccelerator( MASK accel_mask, KEY key ); diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp index 121965a388..882a1d0caf 100644 --- a/indra/newview/llkeyconflict.cpp +++ b/indra/newview/llkeyconflict.cpp @@ -517,8 +517,7 @@ void LLKeyConflictHandler::saveToSettings(bool temporary) } else { - // Note: this is UI string, we might want to hardcode our own for 'fixed' use in keys.xml - binding.key = LLKeyboard::stringFromKey(data.mKey); + binding.key = LLKeyboard::stringFromKey(data.mKey, false /*Do not localize*/); } binding.mask = string_from_mask(data.mMask); if (data.mMouse == CLICK_NONE) diff --git a/indra/newview/llkeyconflict.h b/indra/newview/llkeyconflict.h index 48af0ccdfe..84730e4d4f 100644 --- a/indra/newview/llkeyconflict.h +++ b/indra/newview/llkeyconflict.h @@ -86,6 +86,7 @@ public: LLKeyData getControl(const std::string &control_name, U32 data_index); + // localized string static std::string getStringFromKeyData(const LLKeyData& keydata); std::string getControlString(const std::string &control_name, U32 data_index); diff --git a/indra/newview/skins/default/xui/en/control_table_contents.xml b/indra/newview/skins/default/xui/en/control_table_contents.xml index da9cceb2db..7b777befee 100644 --- a/indra/newview/skins/default/xui/en/control_table_contents.xml +++ b/indra/newview/skins/default/xui/en/control_table_contents.xml @@ -30,6 +30,7 @@ value="Move_Walk_Off" />