Fix menu checks for enabling object sit and touch to not traverse the entire menu holder to update labels

master
Rye Mutt 2022-10-30 06:59:08 -04:00
parent 8669f3f4c2
commit f3dd2bf95f
1 changed files with 9 additions and 11 deletions

View File

@ -2803,14 +2803,15 @@ void handle_object_show_original()
}
static void init_default_item_label(const std::string& item_name)
static void init_default_item_label(LLUICtrl* ctrl)
{
const std::string& item_name = ctrl->getName();
boost::unordered_map<std::string, LLStringExplicit>::iterator it = sDefaultItemLabels.find(item_name);
if (it == sDefaultItemLabels.end())
{
// *NOTE: This will not work for items of type LLMenuItemCheckGL because they return boolean value
// (doesn't seem to matter much ATM).
LLStringExplicit default_label = gMenuHolder->childGetValue(item_name).asString();
LLStringExplicit default_label = ctrl->getValue().asString();
if (!default_label.empty())
{
sDefaultItemLabels.insert(std::pair<std::string, LLStringExplicit>(item_name, default_label));
@ -2841,18 +2842,17 @@ bool enable_object_touch(LLUICtrl* ctrl)
new_value = obj->flagHandleTouch() || (parent && parent->flagHandleTouch());
}
std::string item_name = ctrl->getName();
init_default_item_label(item_name);
init_default_item_label(ctrl);
// Update label based on the node touch name if available.
LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
if (node && node->mValid && !node->mTouchName.empty())
{
gMenuHolder->childSetValue(item_name, node->mTouchName);
ctrl->setValue(node->mTouchName);
}
else
{
gMenuHolder->childSetValue(item_name, get_default_item_label(item_name));
ctrl->setValue(get_default_item_label(ctrl->getName()));
}
return new_value;
@ -6591,20 +6591,18 @@ bool enable_object_sit(LLUICtrl* ctrl)
bool sitting_on_sel = sitting_on_selection();
if (!sitting_on_sel)
{
std::string item_name = ctrl->getName();
// init default labels
init_default_item_label(item_name);
init_default_item_label(ctrl);
// Update label
LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
if (node && node->mValid && !node->mSitName.empty())
{
gMenuHolder->childSetValue(item_name, node->mSitName);
ctrl->setValue(node->mSitName);
}
else
{
gMenuHolder->childSetValue(item_name, get_default_item_label(item_name));
ctrl->setValue(get_default_item_label(ctrl->getName()));
}
}
return !sitting_on_sel && is_object_sittable();