diff options
Diffstat (limited to 'indra/newview/llfloateravatarpicker.cpp')
-rw-r--r-- | indra/newview/llfloateravatarpicker.cpp | 238 |
1 files changed, 162 insertions, 76 deletions
diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp index ccfe7d4b64..2cb0cdf368 100644 --- a/indra/newview/llfloateravatarpicker.cpp +++ b/indra/newview/llfloateravatarpicker.cpp @@ -35,12 +35,14 @@ // Viewer includes #include "llagent.h" +#include "llcallingcard.h" #include "llfocusmgr.h" #include "llfloaterreg.h" #include "llviewercontrol.h" #include "llworld.h" // Linden libraries +#include "llbutton.h" #include "lllineeditor.h" #include "llscrolllistctrl.h" #include "llscrolllistitem.h" @@ -49,20 +51,28 @@ #include "lluictrlfactory.h" #include "message.h" -LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(callback_t callback, - void* userdata, +LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(select_callback_t callback, BOOL allow_multiple, BOOL closeOnSelect) { // *TODO: Use a key to allow this not to be an effective singleton - LLFloaterAvatarPicker* floater = LLFloaterReg::showTypedInstance<LLFloaterAvatarPicker>("avatar_picker"); + LLFloaterAvatarPicker* floater = + LLFloaterReg::showTypedInstance<LLFloaterAvatarPicker>("avatar_picker"); - floater->mCallback = callback; - floater->mCallbackUserdata = userdata; + floater->mSelectionCallback = callback; floater->setAllowMultiple(allow_multiple); floater->mNearMeListComplete = FALSE; floater->mCloseOnSelect = closeOnSelect; + if (!closeOnSelect) + { + // Use Select/Close + std::string select_string = floater->getString("Select"); + std::string close_string = floater->getString("Close"); + floater->getChild<LLButton>("ok_btn")->setLabel(select_string); + floater->getChild<LLButton>("cancel_btn")->setLabel(close_string); + } + return floater; } @@ -70,36 +80,38 @@ LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(callback_t callback, LLFloaterAvatarPicker::LLFloaterAvatarPicker(const LLSD& key) : LLFloater(key), mNumResultsReturned(0), - mCallback(NULL), - mCallbackUserdata(NULL), mNearMeListComplete(FALSE), mCloseOnSelect(FALSE) { // LLUICtrlFactory::getInstance()->buildFloater(this, "floater_avatar_picker.xml"); + mCommitCallbackRegistrar.add("Refresh.FriendList", boost::bind(&LLFloaterAvatarPicker::populateFriend, this)); } BOOL LLFloaterAvatarPicker::postBuild() { - getChild<LLLineEditor>("Edit")->setKeystrokeCallback(editKeystroke, this); + getChild<LLLineEditor>("Edit")->setKeystrokeCallback( boost::bind(&LLFloaterAvatarPicker::editKeystroke, this, _1, _2),NULL); - childSetAction("Find", onBtnFind, this); + childSetAction("Find", boost::bind(&LLFloaterAvatarPicker::onBtnFind, this)); childDisable("Find"); - childSetAction("Refresh", onBtnRefresh, this); - childSetCommitCallback("near_me_range", onRangeAdjust, this); + childSetAction("Refresh", boost::bind(&LLFloaterAvatarPicker::onBtnRefresh, this)); + getChild<LLUICtrl>("near_me_range")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onRangeAdjust, this)); LLScrollListCtrl* searchresults = getChild<LLScrollListCtrl>("SearchResults"); - searchresults->setDoubleClickCallback(onBtnSelect, this); - childSetCommitCallback("SearchResults", onList, this); + searchresults->setDoubleClickCallback( boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + searchresults->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); childDisable("SearchResults"); LLScrollListCtrl* nearme = getChild<LLScrollListCtrl>("NearMe"); - nearme->setDoubleClickCallback(onBtnSelect, this); - childSetCommitCallback("NearMe", onList, this); - - childSetAction("Select", onBtnSelect, this); - childDisable("Select"); + nearme->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + nearme->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); - childSetAction("Cancel", onBtnClose, this); + LLScrollListCtrl* friends = getChild<LLScrollListCtrl>("Friends"); + friends->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + getChild<LLUICtrl>("Friends")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); + + childSetAction("ok_btn", boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + childDisable("ok_btn"); + childSetAction("cancel_btn", boost::bind(&LLFloaterAvatarPicker::onBtnClose, this)); childSetFocus("Edit"); @@ -119,12 +131,19 @@ BOOL LLFloaterAvatarPicker::postBuild() center(); + populateFriend(); + return TRUE; } +void LLFloaterAvatarPicker::setOkBtnEnableCb(validate_callback_t cb) +{ + mOkButtonValidateSignal.connect(cb); +} + void LLFloaterAvatarPicker::onTabChanged() { - childSetEnabled("Select", visibleItemsSelected()); + childSetEnabled("ok_btn", isSelectBtnEnabled()); } // Destroys the object @@ -133,13 +152,12 @@ LLFloaterAvatarPicker::~LLFloaterAvatarPicker() gFocusMgr.releaseFocusIfNeeded( this ); } -void LLFloaterAvatarPicker::onBtnFind(void* userdata) +void LLFloaterAvatarPicker::onBtnFind() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if(self) self->find(); + find(); } -static void getSelectedAvatarData(const LLScrollListCtrl* from, std::vector<std::string>& avatar_names, std::vector<LLUUID>& avatar_ids) +static void getSelectedAvatarData(const LLScrollListCtrl* from, std::vector<std::string>& avatar_names, uuid_vec_t& avatar_ids) { std::vector<LLScrollListItem*> items = from->getAllSelected(); for (std::vector<LLScrollListItem*>::iterator iter = items.begin(); iter != items.end(); ++iter) @@ -153,69 +171,73 @@ static void getSelectedAvatarData(const LLScrollListCtrl* from, std::vector<std: } } -void LLFloaterAvatarPicker::onBtnSelect(void* userdata) +void LLFloaterAvatarPicker::onBtnSelect() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if(self->mCallback) - { - LLPanel* active_panel = self->childGetVisibleTab("ResidentChooserTabs"); + // If select btn not enabled then do not callback + if (!isSelectBtnEnabled()) + return; - if(active_panel == self->getChild<LLPanel>("SearchPanel")) + if(mSelectionCallback) + { + std::string acvtive_panel_name; + LLScrollListCtrl* list = NULL; + LLPanel* active_panel = childGetVisibleTab("ResidentChooserTabs"); + if(active_panel) { - std::vector<std::string> avatar_names; - std::vector<LLUUID> avatar_ids; - getSelectedAvatarData(self->getChild<LLScrollListCtrl>("SearchResults"), avatar_names, avatar_ids); - self->mCallback(avatar_names, avatar_ids, self->mCallbackUserdata); + acvtive_panel_name = active_panel->getName(); + } + if(acvtive_panel_name == "SearchPanel") + { + list = getChild<LLScrollListCtrl>("SearchResults"); } - else if(active_panel == self->getChild<LLPanel>("NearMePanel")) + else if(acvtive_panel_name == "NearMePanel") + { + list = getChild<LLScrollListCtrl>("NearMe"); + } + else if (acvtive_panel_name == "FriendsPanel") + { + list = getChild<LLScrollListCtrl>("Friends"); + } + + if(list) { std::vector<std::string> avatar_names; - std::vector<LLUUID> avatar_ids; - getSelectedAvatarData(self->getChild<LLScrollListCtrl>("NearMe"), avatar_names, avatar_ids); - self->mCallback(avatar_names, avatar_ids, self->mCallbackUserdata); + uuid_vec_t avatar_ids; + getSelectedAvatarData(list, avatar_names, avatar_ids); + mSelectionCallback(avatar_names, avatar_ids); } } - self->getChild<LLScrollListCtrl>("SearchResults")->deselectAllItems(TRUE); - self->getChild<LLScrollListCtrl>("NearMe")->deselectAllItems(TRUE); - if(self->mCloseOnSelect) + getChild<LLScrollListCtrl>("SearchResults")->deselectAllItems(TRUE); + getChild<LLScrollListCtrl>("NearMe")->deselectAllItems(TRUE); + getChild<LLScrollListCtrl>("Friends")->deselectAllItems(TRUE); + if(mCloseOnSelect) { - self->mCloseOnSelect = FALSE; - self->closeFloater(); + mCloseOnSelect = FALSE; + closeFloater(); } } -void LLFloaterAvatarPicker::onBtnRefresh(void* userdata) +void LLFloaterAvatarPicker::onBtnRefresh() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if (!self) - { - return; - } - - self->getChild<LLScrollListCtrl>("NearMe")->deleteAllItems(); - self->getChild<LLScrollListCtrl>("NearMe")->setCommentText(self->getString("searching")); - self->mNearMeListComplete = FALSE; + getChild<LLScrollListCtrl>("NearMe")->deleteAllItems(); + getChild<LLScrollListCtrl>("NearMe")->setCommentText(getString("searching")); + mNearMeListComplete = FALSE; } -void LLFloaterAvatarPicker::onBtnClose(void* userdata) +void LLFloaterAvatarPicker::onBtnClose() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if(self) self->closeFloater(); + closeFloater(); } -void LLFloaterAvatarPicker::onRangeAdjust(LLUICtrl* source, void* data) +void LLFloaterAvatarPicker::onRangeAdjust() { - LLFloaterAvatarPicker::onBtnRefresh(data); + onBtnRefresh(); } -void LLFloaterAvatarPicker::onList(LLUICtrl* ctrl, void* userdata) +void LLFloaterAvatarPicker::onList() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if (self) - { - self->childSetEnabled("Select", self->visibleItemsSelected()); - } + childSetEnabled("ok_btn", isSelectBtnEnabled()); } void LLFloaterAvatarPicker::populateNearMe() @@ -225,7 +247,7 @@ void LLFloaterAvatarPicker::populateNearMe() LLScrollListCtrl* near_me_scroller = getChild<LLScrollListCtrl>("NearMe"); near_me_scroller->deleteAllItems(); - std::vector<LLUUID> avatar_ids; + uuid_vec_t avatar_ids; LLWorld::getInstance()->getAvatars(&avatar_ids, NULL, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange")); for(U32 i=0; i<avatar_ids.size(); i++) { @@ -250,15 +272,15 @@ void LLFloaterAvatarPicker::populateNearMe() if (empty) { childDisable("NearMe"); - childDisable("Select"); + childDisable("ok_btn"); near_me_scroller->setCommentText(getString("no_one_near")); } else { childEnable("NearMe"); - childEnable("Select"); + childEnable("ok_btn"); near_me_scroller->selectFirstItem(); - onList(near_me_scroller, this); + onList(); near_me_scroller->setFocus(TRUE); } @@ -268,6 +290,26 @@ void LLFloaterAvatarPicker::populateNearMe() } } +void LLFloaterAvatarPicker::populateFriend() +{ + LLScrollListCtrl* friends_scroller = getChild<LLScrollListCtrl>("Friends"); + friends_scroller->deleteAllItems(); + LLCollectAllBuddies collector; + LLAvatarTracker::instance().applyFunctor(collector); + LLCollectAllBuddies::buddy_map_t::iterator it; + + + for(it = collector.mOnline.begin(); it!=collector.mOnline.end(); it++) + { + friends_scroller->addStringUUIDItem(it->first, it->second); + } + for(it = collector.mOffline.begin(); it!=collector.mOffline.end(); it++) + { + friends_scroller->addStringUUIDItem(it->first, it->second); + } + friends_scroller->sortByColumnIndex(0, TRUE); +} + void LLFloaterAvatarPicker::draw() { LLFloater::draw(); @@ -289,6 +331,10 @@ BOOL LLFloaterAvatarPicker::visibleItemsSelected() const { return getChild<LLScrollListCtrl>("NearMe")->getFirstSelectedIndex() >= 0; } + else if(active_panel == getChild<LLPanel>("FriendsPanel")) + { + return getChild<LLScrollListCtrl>("Friends")->getFirstSelectedIndex() >= 0; + } return FALSE; } @@ -313,7 +359,7 @@ void LLFloaterAvatarPicker::find() getChild<LLScrollListCtrl>("SearchResults")->deleteAllItems(); getChild<LLScrollListCtrl>("SearchResults")->setCommentText(getString("searching")); - childSetEnabled("Select", FALSE); + childSetEnabled("ok_btn", FALSE); mNumResultsReturned = 0; } @@ -321,6 +367,7 @@ void LLFloaterAvatarPicker::setAllowMultiple(BOOL allow_multiple) { getChild<LLScrollListCtrl>("SearchResults")->setAllowMultipleSelection(allow_multiple); getChild<LLScrollListCtrl>("NearMe")->setAllowMultipleSelection(allow_multiple); + getChild<LLScrollListCtrl>("Friends")->setAllowMultipleSelection(allow_multiple); } // static @@ -369,7 +416,7 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void* map["[TEXT]"] = floater->childGetText("Edit"); avatar_name = floater->getString("not_found", map); search_results->setEnabled(FALSE); - floater->childDisable("Select"); + floater->childDisable("ok_btn"); } else { @@ -385,9 +432,9 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void* if (found_one) { - floater->childEnable("Select"); + floater->childEnable("ok_btn"); search_results->selectFirstItem(); - floater->onList(search_results, floater); + floater->onList(); search_results->setFocus(TRUE); } } @@ -395,8 +442,7 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void* //static void LLFloaterAvatarPicker::editKeystroke(LLLineEditor* caller, void* user_data) { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)user_data; - self->childSetEnabled("Find", caller->getText().size() >= 3); + childSetEnabled("Find", caller->getText().size() >= 3); } // virtual @@ -406,11 +452,11 @@ BOOL LLFloaterAvatarPicker::handleKeyHere(KEY key, MASK mask) { if (childHasFocus("Edit")) { - onBtnFind(this); + onBtnFind(); } else { - onBtnSelect(this); + onBtnSelect(); } return TRUE; } @@ -422,3 +468,43 @@ BOOL LLFloaterAvatarPicker::handleKeyHere(KEY key, MASK mask) return LLFloater::handleKeyHere(key, mask); } + +bool LLFloaterAvatarPicker::isSelectBtnEnabled() +{ + bool ret_val = visibleItemsSelected(); + + if ( ret_val && mOkButtonValidateSignal.num_slots() ) + { + std::string acvtive_panel_name; + LLScrollListCtrl* list = NULL; + LLPanel* active_panel = childGetVisibleTab("ResidentChooserTabs"); + + if(active_panel) + { + acvtive_panel_name = active_panel->getName(); + } + + if(acvtive_panel_name == "SearchPanel") + { + list = getChild<LLScrollListCtrl>("SearchResults"); + } + else if(acvtive_panel_name == "NearMePanel") + { + list = getChild<LLScrollListCtrl>("NearMe"); + } + else if (acvtive_panel_name == "FriendsPanel") + { + list = getChild<LLScrollListCtrl>("Friends"); + } + + if(list) + { + uuid_vec_t avatar_ids; + std::vector<std::string> avatar_names; + getSelectedAvatarData(list, avatar_names, avatar_ids); + return mOkButtonValidateSignal(avatar_ids); + } + } + + return ret_val; +} |