diff options
author | Steven Bennetts <steve@lindenlab.com> | 2009-07-02 00:38:13 +0000 |
---|---|---|
committer | Steven Bennetts <steve@lindenlab.com> | 2009-07-02 00:38:13 +0000 |
commit | 39905b927d60e204438705728d2c214cb3f9ef81 (patch) | |
tree | 7bb617cc204514b233e081457d905693aa0ae409 /indra/newview/llpanelpicks.cpp | |
parent | 687cff0eb8dfe663b99e18cfd953e0764d8ab372 (diff) |
merge https://svn.aws.productengine.com/secondlife/export-from-ll/viewer-2-0@873 https://svn.aws.productengine.com/secondlife/pe/stable@888 -> viewer-2.0.0-pe-4
Diffstat (limited to 'indra/newview/llpanelpicks.cpp')
-rw-r--r-- | indra/newview/llpanelpicks.cpp | 352 |
1 files changed, 197 insertions, 155 deletions
diff --git a/indra/newview/llpanelpicks.cpp b/indra/newview/llpanelpicks.cpp index 1a3aa8a33a..c32af24423 100644 --- a/indra/newview/llpanelpicks.cpp +++ b/indra/newview/llpanelpicks.cpp @@ -36,37 +36,39 @@ #include "llavatarconstants.h" #include "lltexturectrl.h" #include "llviewergenericmessage.h" // send_generic_message -#include "llworldmap.h" -#include "llfloaterworldmap.h" -#include "llpanelmeprofile.h" -#include "llfloaterreg.h" +#include "llmenugl.h" +#include "llviewermenu.h" + #include "llpanelpicks.h" #include "llavatarpropertiesprocessor.h" +#include "llpanelavatar.h" #include "llpanelpick.h" -#define XML_BTN_NEW "new_btn" -#define XML_BTN_DELETE "trash_btn" -#define XML_BTN_INFO "info_btn" +static const std::string XML_BTN_NEW = "new_btn"; +static const std::string XML_BTN_DELETE = "trash_btn"; +static const std::string XML_BTN_INFO = "info_btn"; +static const std::string XML_BTN_TELEPORT = "teleport_btn"; +static const std::string XML_BTN_SHOW_ON_MAP = "show_on_map_btn"; + +static const std::string XML_PICKS_LIST = "back_panel"; + +#define PICK_ITEMS_BETWEEN 5 //----------------------------------------------------------------------------- // LLPanelPicks //----------------------------------------------------------------------------- LLPanelPicks::LLPanelPicks(const LLUUID& avatar_id /* = LLUUID::null */) -:LLPanelProfileTab(avatar_id), mMeProfilePanel(NULL) +: LLPanelProfileTab(avatar_id), + mPopupMenu(NULL), + mSelectedPickItem(NULL) { updateData(); } -LLPanelPicks::LLPanelPicks(const Params& params) -:LLPanelProfileTab(params), mMeProfilePanel(NULL) -{ - -} - LLPanelPicks::~LLPanelPicks() { - if(!getAvatarId().isNull()) + if(getAvatarId().notNull()) { LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(),this); } @@ -99,8 +101,13 @@ void LLPanelPicks::processProperties(void* data, EAvatarProcessorType type) gCacheName->getName(getAvatarId(),name,second_name); childSetTextArg("pick_title", "[NAME]",name); - LLView* picks_list = getChild<LLView>("back_panel",TRUE,FALSE); + LLView* picks_list = getPicksList(); if(!picks_list) return; + + // to restore selection of the same item later + LLUUID pick_id_selected(LLUUID::null); + if (mSelectedPickItem) pick_id_selected = mSelectedPickItem->getPickId(); + clear(); //*TODO move it somewhere else? @@ -108,13 +115,9 @@ void LLPanelPicks::processProperties(void* data, EAvatarProcessorType type) childSetEnabled(XML_BTN_NEW, false); childSetEnabled(XML_BTN_DELETE, false); childSetEnabled(XML_BTN_INFO, false); + childSetEnabled(XML_BTN_TELEPORT,!avatar_picks->picks_list.empty()); + childSetEnabled(XML_BTN_SHOW_ON_MAP,!avatar_picks->picks_list.empty()); - S32 height = avatar_picks->picks_list.size() * 85; - LLRect rc = picks_list->getRect(); - rc.setLeftTopAndSize(rc.mLeft,rc.mTop,rc.getWidth(),height); - picks_list->setRect(rc); - picks_list->reshape(rc.getWidth(),rc.getHeight()); - LLAvatarPicks::picks_list_t::const_iterator it = avatar_picks->picks_list.begin(); for(; avatar_picks->picks_list.end() != it; ++it) { @@ -124,30 +127,22 @@ void LLPanelPicks::processProperties(void* data, EAvatarProcessorType type) LLPickItem* picture = LLPickItem::create(); picks_list->addChild(picture); - picture->setPictureName(pick_name); - picture->setPictureId(pick_id); + picture->setPickName(pick_name); + picture->setPickId(pick_id); picture->setCreatorId(getAvatarId()); - S32 last_bottom = picks_list->getRect().getHeight(); - if(mPickItemList.size() > 0) - { - last_bottom = mPickItemList[mPickItemList.size()-1]->getRect().mBottom; - last_bottom -= 5; - } - LLRect rc = picture->getRect(); - rc.mBottom = last_bottom - rc.getHeight(); - rc.mTop = last_bottom; - picture->reshape(rc.getWidth(),rc.getHeight()); - picture->setRect(rc); - - LLAvatarPropertiesProcessor::instance().addObserver(mAvatarId, picture); picture->update(); mPickItemList.push_back(picture); + if (pick_id_selected != LLUUID::null && + pick_id == pick_id_selected) setSelectedPickItem(picture); } + + reshapePicksList(); LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(),this); updateButtons(); + if (!mSelectedPickItem && mPickItemList.size()) setSelectedPickItem(mPickItemList.back()); picks_list->setEnabled(TRUE); } @@ -156,7 +151,7 @@ void LLPanelPicks::processProperties(void* data, EAvatarProcessorType type) void LLPanelPicks::clear() { - LLView* scroll = getChild<LLView>("back_panel",TRUE,FALSE); + LLView* scroll = getPicksList(); if(scroll) { picture_list_t::const_iterator it = mPickItemList.begin(); @@ -167,16 +162,85 @@ void LLPanelPicks::clear() } } mPickItemList.clear(); + mSelectedPickItem = NULL; +} + + +LLPickItem* LLPanelPicks::getSelectedPickItem() +{ + return mSelectedPickItem; +} + + +void LLPanelPicks::removePickItem( LLPickItem* pick_item ) +{ + LLView* scroll = getPicksList(); + scroll->removeChild(pick_item); + mPickItemList.remove(pick_item); + if (mPickItemList.size() == 0) + { + mSelectedPickItem = NULL; + } + else + { + setSelectedPickItem(mPickItemList.back()); + } + + reshapePicksList(); +} + +void LLPanelPicks::reshapePicksList() +{ + if (!mPickItemList.size()) return; + LLView* pickList = getPicksList(); + + S32 last_bottom = pickList->getRect().getHeight(); + child_list_const_iter_t child_it, child_first_it = pickList->getChildList()->begin(); + for ( child_it = child_first_it; child_it != pickList->getChildList()->end(); ++child_it) + { + LLView* const childp = *child_it; + if(child_it != child_first_it) + { + last_bottom -= childp->getRect().getHeight(); + last_bottom -= PICK_ITEMS_BETWEEN; + } + reshapePickItem(childp, last_bottom); + } + + S32 height = pickList->getChildCount() * ((*child_first_it)->getRect().getHeight() + PICK_ITEMS_BETWEEN); + LLRect rc = pickList->getRect(); + rc.setLeftTopAndSize(rc.mLeft, rc.mTop, rc.getWidth(), height); + pickList->reshape(rc.getWidth(), rc.getHeight()); + pickList->setRect(rc); +} + +void LLPanelPicks::reshapePickItem(LLView* const pick_item, const S32 last_bottom) +{ + LLRect rc = pick_item->getRect(); + rc.mBottom = last_bottom - rc.getHeight(); + rc.mTop = last_bottom; + pick_item->reshape(rc.getWidth(), rc.getHeight()); + pick_item->setRect(rc); +} + +LLView* LLPanelPicks::getPicksList() const +{ + return getChild<LLView>(XML_PICKS_LIST, TRUE, FALSE); } BOOL LLPanelPicks::postBuild(void) { - childSetAction(XML_BTN_INFO, onClickInfo, this); - childSetAction(XML_BTN_NEW, onClickNew, this); childSetAction(XML_BTN_DELETE, onClickDelete, this); childSetAction("teleport_btn", onClickTeleport, this); childSetAction("show_on_map_btn", onClickMap, this); + + mCommitCallbackRegistrar.add("Pick.Teleport", boost::bind(onClickTeleport, this)); + mCommitCallbackRegistrar.add("Pick.Map", boost::bind(onClickMap, this)); + mCommitCallbackRegistrar.add("Pick.Delete", boost::bind(onClickDelete, this)); + + mPopupMenu = LLUICtrlFactory::getInstance()->createFromFile<LLContextMenu>("menu_picks.xml", gMenuHolder); + return TRUE; } @@ -188,6 +252,14 @@ void LLPanelPicks::onActivate(const LLUUID& id) childSetEnabled("edit_panel", self); childSetVisible("edit_panel", self); + // Disable buttons when viewing profile for first time + if(getAvatarId() != id) + { + childSetEnabled(XML_BTN_INFO,FALSE); + childSetEnabled(XML_BTN_TELEPORT,FALSE); + childSetEnabled(XML_BTN_SHOW_ON_MAP,FALSE); + } + // and see a special title - set as invisible by default in xml file if (self) { @@ -198,141 +270,74 @@ void LLPanelPicks::onActivate(const LLUUID& id) LLPanelProfileTab::onActivate(id); } - -//static -void LLPanelPicks::onClickInfo(void *data) -{ - LLPanelPicks* self = (LLPanelPicks*) data; - if (self) - { - LLPanelPick* panel_pick_info = new LLPanelPick(); - - //*TODO redo, use the selected pick from List View, but not the first (last) one - LLView* scroll = self->getChild<LLView>("back_panel", TRUE, FALSE); - LLPickItem* pick = static_cast<LLPickItem*>(scroll->getFirstChild()); - if (!pick) return; - - panel_pick_info->init(pick->getCreatorId(), pick->getPickId()); - - //*HACK redo toggling of panels (should work on both "profiles") - if (self->mMeProfilePanel) - { - panel_pick_info->setPanelMeProfile(self->mMeProfilePanel); - //self->mMeProfilePanel->addChildInBack(panel_pick_info); - self->mMeProfilePanel->togglePanel(panel_pick_info); - } - } -} - -//static -void LLPanelPicks::onClickNew(void *data) -{ - LLPanelPicks* self = (LLPanelPicks*) data; - if(self && self->mMeProfilePanel) - { - if (self->mPickItemList.size() >= MAX_AVATAR_PICKS) - { - //*TODO show warning message - return; - } - - //in edit mode - LLPanelPick* panel_edit_pick = new LLPanelPick(TRUE); - panel_edit_pick->createNewPick(); - - //*HACK redo toggling of panels - panel_edit_pick->setPanelMeProfile(self->mMeProfilePanel); - self->mMeProfilePanel->togglePanel(panel_edit_pick); - } -} - //static void LLPanelPicks::onClickDelete(void *data) { LLPanelPicks* self = (LLPanelPicks*) data; - if(self && self->mMeProfilePanel) - { - //*TODO redo, use the selected pick from List View, but not the first (last) one - LLView* scroll = self->getChild<LLView>("back_panel", TRUE, FALSE); - LLPickItem* first_pick = static_cast<LLPickItem*>(scroll->getFirstChild()); - if (!first_pick) return; + if (!self) return; + + LLPickItem* pick_item = self->getSelectedPickItem(); + if (!pick_item) return; LLSD args; - args["PICK"] = first_pick->getPickName(); + args["PICK"] = pick_item->getPickName(); LLNotifications::instance().add("DeleteAvatarPick", args, LLSD(), boost::bind(&LLPanelPicks::callbackDelete, self, _1, _2)); - } } bool LLPanelPicks::callbackDelete(const LLSD& notification, const LLSD& response) { S32 option = LLNotification::getSelectedOption(notification, response); - //*TODO redo, use the selected pick from List View, but not the first (last) one - LLView* scroll = getChild<LLView>("back_panel",TRUE,FALSE); - LLPickItem* first_pick = static_cast<LLPickItem*>(scroll->getFirstChild()); - if (!first_pick) return false; + LLPickItem* pick_item = getSelectedPickItem(); if (0 == option) { - LLAvatarPropertiesProcessor::instance().sendPickDelete(first_pick->getPickId()); - - scroll->removeChild(first_pick); - mPickItemList.pop_back(); - first_pick = NULL; + LLAvatarPropertiesProcessor::instance().sendPickDelete(pick_item->getPickId()); + removePickItem(pick_item); } updateButtons(); return false; } -void LLPanelPicks::setPanelMeProfile(LLPanelMeProfile* meProfilePanel) -{ - mMeProfilePanel = meProfilePanel; -} - -//static -void LLPanelPicks::teleport(const LLVector3d& position) -{ - if (!position.isExactlyZero()) - { - gAgent.teleportViaLocation(position); - LLFloaterWorldMap::getInstance()->trackLocation(position); - } -} - //static void LLPanelPicks::onClickTeleport(void* data) { LLPanelPicks* self = (LLPanelPicks*)data; - - if (!self->mPickItemList.size()) return; - - //*TODO use the selected Pick instead of the last one in the list of Picks - LLPickItem* last_pick = self->mPickItemList.back(); - if (!last_pick) return; - - teleport(last_pick->getPosGlobal()); + LLPickItem* pick_item = self->getSelectedPickItem(); + if (!pick_item) return; + LLPanelPick::teleport(pick_item->getPosGlobal()); } //static void LLPanelPicks::onClickMap(void* data) { LLPanelPicks* self = (LLPanelPicks*)data; - - if (!self->mPickItemList.size()) return; - - //*TODO use the selected Pick instead of the last one in the list of Picks - LLPickItem* last_pick = self->mPickItemList.back(); - if (!last_pick) return; + LLPickItem* pick_item = self->getSelectedPickItem(); + if (!pick_item) return; + LLPanelPick::showOnMap(pick_item->getPosGlobal()); +} - showOnMap(last_pick->getPosGlobal()); +BOOL LLPanelPicks::handleRightMouseDown(S32 x, S32 y, MASK mask) +{ + if (isMouseInPick(x, y)) + { + if (mPopupMenu) + { + mPopupMenu->buildDrawLabels(); + mPopupMenu->updateParent(LLMenuGL::sMenuContainer); + ((LLContextMenu*)mPopupMenu)->show(x, y, FALSE); + LLMenuGL::showPopup(this, mPopupMenu, x, y); + } + return TRUE; + } + return LLPanel::handleRightMouseDown(x, y, mask); } -//static -void LLPanelPicks::showOnMap(const LLVector3d& position) +BOOL LLPanelPicks::handleMouseDown( S32 x, S32 y, MASK mask ) { - LLFloaterWorldMap::getInstance()->trackLocation(position); - LLFloaterReg::showInstance("world_map", "center"); + if (isMouseInPick(x, y)) return TRUE; + return LLPanel::handleMouseDown(x, y, mask); } void LLPanelPicks::updateButtons() @@ -344,7 +349,49 @@ void LLPanelPicks::updateButtons() { childSetEnabled(XML_BTN_NEW, picks_num < MAX_AVATAR_PICKS); childSetEnabled(XML_BTN_DELETE, picks_num > 0); + + //*TODO move somewhere this calls + // we'd better set them up earlier when a panel was being constructed + mPopupMenu->setItemVisible("pick_delete", TRUE); + mPopupMenu->setItemVisible("pick_edit", TRUE); + mPopupMenu->setItemVisible("pick_separator", TRUE); } + + //*TODO update buttons like Show on Map, Teleport etc. + +} + +void LLPanelPicks::setSelectedPickItem( LLPickItem* item ) +{ + if (!item) return; + if (mSelectedPickItem == item) return; + if (mSelectedPickItem && mSelectedPickItem->isBackgroundVisible()) + { + mSelectedPickItem->setBackgroundVisible(FALSE); + } + item->setBackgroundVisible(TRUE); + mSelectedPickItem = item; +} + +BOOL LLPanelPicks::isMouseInPick( S32 x, S32 y ) +{ + LLView* scroll = getChild<LLView>("profile_scroll"); + if (!scroll->parentPointInView(x, y)) return FALSE; + + S32 x_l = x; + S32 y_l = y; + + picture_list_t::const_iterator it = mPickItemList.begin(); + for(; mPickItemList.end() != it; ++it) + { + localPointToOtherView(x, y, &x_l, &y_l, (*it)); + if ((*it)->pointInView(x_l, y_l)) + { + setSelectedPickItem(*it); + return TRUE; + } + } + return FALSE; } @@ -353,18 +400,18 @@ void LLPanelPicks::updateButtons() //----------------------------------------------------------------------------- LLPickItem::LLPickItem() : LLPanel() -, mPicID(LLUUID::null) +, mPickID(LLUUID::null) , mCreatorID(LLUUID::null) , mParcelID(LLUUID::null) , mSnapshotID(LLUUID::null) , mNeedData(true) { - LLUICtrlFactory::getInstance()->buildPanel(this,"panel_pic_list_item.xml"); + LLUICtrlFactory::getInstance()->buildPanel(this,"panel_pick_list_item.xml"); } LLPickItem::~LLPickItem() { - if (!mCreatorID.isNull()) + if (mCreatorID.notNull()) { LLAvatarPropertiesProcessor::instance().removeObserver(mCreatorID, this); } @@ -378,7 +425,7 @@ LLPickItem* LLPickItem::create() void LLPickItem::init(LLPickData* pick_data) { - setPictureDescription(pick_data->desc); + setPickDesc(pick_data->desc); setSnapshotId(pick_data->snapshot_id); mPosGlobal = pick_data->pos_global; mLocation = pick_data->location_text; @@ -390,12 +437,7 @@ void LLPickItem::init(LLPickData* pick_data) } } -void LLPickItem::setPicture() -{ - -} - -void LLPickItem::setPictureName(const std::string& name) +void LLPickItem::setPickName(const std::string& name) { mPickName = name; childSetValue("picture_name",name); @@ -417,19 +459,19 @@ const LLUUID& LLPickItem::getSnapshotId() return mSnapshotID; } -void LLPickItem::setPictureDescription(const std::string& descr) +void LLPickItem::setPickDesc(const std::string& descr) { childSetValue("picture_descr",descr); } -void LLPickItem::setPictureId(const LLUUID& id) +void LLPickItem::setPickId(const LLUUID& id) { - mPicID = id; + mPickID = id; } const LLUUID& LLPickItem::getPickId() { - return mPicID; + return mPickID; } const LLVector3d& LLPickItem::getPosGlobal() @@ -450,7 +492,7 @@ const std::string LLPickItem::getDescription() void LLPickItem::update() { mNeedData = true; - LLAvatarPropertiesProcessor::instance().sendDataRequest(mCreatorID, APT_PICK_INFO, &mPicID); + LLAvatarPropertiesProcessor::instance().sendDataRequest(mCreatorID, APT_PICK_INFO, &mPickID); mNeedData = false; } @@ -461,7 +503,7 @@ void LLPickItem::processProperties(void *data, EAvatarProcessorType type) LLPickData* pick_data = static_cast<LLPickData *>(data); if (!pick_data) return; - if (mPicID != pick_data->pick_id) return; + if (mPickID != pick_data->pick_id) return; init(pick_data); LLAvatarPropertiesProcessor::instance().removeObserver(pick_data->agent_id, this); |