llpanelme.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:9k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llpanelme.cpp
  3.  * @brief Side tray "Me" (My Profile) panel
  4.  *
  5.  * $LicenseInfo:firstyear=2009&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2009-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpanelprofile.h"
  34. #include "llavatarconstants.h"
  35. #include "llpanelme.h"
  36. #include "llagent.h"
  37. #include "llagentwearables.h"
  38. #include "lliconctrl.h"
  39. #include "llsidetray.h"
  40. #include "lltabcontainer.h"
  41. #include "lltexturectrl.h"
  42. #include "llviewercontrol.h"
  43. #define PICKER_SECOND_LIFE "2nd_life_pic"
  44. #define PICKER_FIRST_LIFE "real_world_pic"
  45. #define PANEL_PROFILE "panel_profile"
  46. static LLRegisterPanelClassWrapper<LLPanelMyProfileEdit> t_panel_me_profile_edit("edit_profile_panel");
  47. static LLRegisterPanelClassWrapper<LLPanelMe> t_panel_me_profile("panel_me");
  48. LLPanelMe::LLPanelMe(void) 
  49.  : LLPanelProfile()
  50.  , mEditPanel(NULL)
  51. {
  52. setAvatarId(gAgent.getID());
  53. }
  54. BOOL LLPanelMe::postBuild()
  55. {
  56. LLPanelProfile::postBuild();
  57. getTabContainer()[PANEL_PROFILE]->childSetAction("edit_profile_btn", boost::bind(&LLPanelMe::onEditProfileClicked, this), this);
  58. getTabContainer()[PANEL_PROFILE]->childSetAction("edit_appearance_btn", boost::bind(&LLPanelMe::onEditAppearanceClicked, this), this);
  59. return TRUE;
  60. }
  61. void LLPanelMe::onOpen(const LLSD& key)
  62. {
  63. LLPanelProfile::onOpen(key);
  64. // Force Edit My Profile if this is the first time when user is opening Me Panel (EXT-5068)
  65. bool opened = gSavedSettings.getBOOL("MePanelOpened");
  66. // In some cases Side Tray my call onOpen() twice, check getCollapsed() to be sure this
  67. // is the last time onOpen() is called
  68. if( !opened && !LLSideTray::getInstance()->getCollapsed() )
  69. {
  70. buildEditPanel();
  71. openPanel(mEditPanel, getAvatarId());
  72. gSavedSettings.setBOOL("MePanelOpened", true);
  73. }
  74. }
  75. bool LLPanelMe::notifyChildren(const LLSD& info)
  76. {
  77. if (info.has("task-panel-action") && info["task-panel-action"].asString() == "handle-tri-state")
  78. {
  79. // Implement task panel tri-state behavior.
  80. //
  81. // When the button of an active open task panel is clicked, side tray
  82. // calls notifyChildren() on the panel, passing task-panel-action=>handle-tri-state as an argument.
  83. // The task panel is supposed to handle this by reverting to the default view,
  84. // i.e. closing any dependent panels like "pick info" or "profile edit".
  85. bool on_default_view = true;
  86. const LLRect& task_panel_rect = getRect();
  87. for (LLView* child = getFirstChild(); child; child = findNextSibling(child))
  88. {
  89. LLPanel* panel = dynamic_cast<LLPanel*>(child);
  90. if (!panel)
  91. continue;
  92. // *HACK: implement panel stack instead (e.g. me->pick_info->pick_edit).
  93. if (panel->getRect().getWidth()  == task_panel_rect.getWidth()  &&
  94. panel->getRect().getHeight() == task_panel_rect.getHeight() &&
  95. panel->getVisible())
  96. {
  97. panel->setVisible(FALSE);
  98. on_default_view = false;
  99. }
  100. }
  101. if (on_default_view)
  102. LLSideTray::getInstance()->collapseSideBar();
  103. return true; // this notification is only supposed to be handled by task panels 
  104. }
  105. return LLPanel::notifyChildren(info);
  106. }
  107. void LLPanelMe::buildEditPanel()
  108. {
  109. if (NULL == mEditPanel)
  110. {
  111. mEditPanel = new LLPanelMyProfileEdit();
  112. mEditPanel->childSetAction("save_btn", boost::bind(&LLPanelMe::onSaveChangesClicked, this), this);
  113. mEditPanel->childSetAction("cancel_btn", boost::bind(&LLPanelMe::onCancelClicked, this), this);
  114. }
  115. }
  116. void LLPanelMe::onEditProfileClicked()
  117. {
  118. buildEditPanel();
  119. togglePanel(mEditPanel, getAvatarId()); // open
  120. }
  121. void LLPanelMe::onEditAppearanceClicked()
  122. {
  123. if (gAgentWearables.areWearablesLoaded())
  124. {
  125. gAgent.changeCameraToCustomizeAvatar();
  126. }
  127. }
  128. void LLPanelMe::onSaveChangesClicked()
  129. {
  130. LLAvatarData data = LLAvatarData();
  131. data.avatar_id = gAgent.getID();
  132. data.image_id = mEditPanel->getChild<LLTextureCtrl>(PICKER_SECOND_LIFE)->getImageAssetID();
  133. data.fl_image_id = mEditPanel->getChild<LLTextureCtrl>(PICKER_FIRST_LIFE)->getImageAssetID();
  134. data.about_text = mEditPanel->childGetValue("sl_description_edit").asString();
  135. data.fl_about_text = mEditPanel->childGetValue("fl_description_edit").asString();
  136. data.profile_url = mEditPanel->childGetValue("homepage_edit").asString();
  137. data.allow_publish = mEditPanel->childGetValue("show_in_search_checkbox");
  138. LLAvatarPropertiesProcessor::getInstance()->sendAvatarPropertiesUpdate(&data);
  139. togglePanel(mEditPanel); // close
  140. onOpen(getAvatarId());
  141. }
  142. void LLPanelMe::onCancelClicked()
  143. {
  144. togglePanel(mEditPanel); // close
  145. }
  146. //////////////////////////////////////////////////////////////////////////
  147. //////////////////////////////////////////////////////////////////////////
  148. //////////////////////////////////////////////////////////////////////////
  149. LLPanelMyProfileEdit::LLPanelMyProfileEdit() 
  150.  : LLPanelMyProfile()
  151. {
  152. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_edit_profile.xml");
  153. setAvatarId(gAgent.getID());
  154. }
  155. void LLPanelMyProfileEdit::onOpen(const LLSD& key)
  156. {
  157. resetData();
  158. // Disable editing until data is loaded, or edited fields will be overwritten when data
  159. // is loaded.
  160. enableEditing(false);
  161. LLPanelMyProfile::onOpen(getAvatarId());
  162. }
  163. void LLPanelMyProfileEdit::processProperties(void* data, EAvatarProcessorType type)
  164. {
  165. if(APT_PROPERTIES == type)
  166. {
  167. const LLAvatarData* avatar_data = static_cast<const LLAvatarData*>(data);
  168. if(avatar_data && getAvatarId() == avatar_data->avatar_id)
  169. {
  170. // *TODO dzaporozhan
  171. // Workaround for ticket EXT-1099, waiting for fix for ticket EXT-1128
  172. enableEditing(true);
  173. processProfileProperties(avatar_data);
  174. LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(),this);
  175. }
  176. }
  177. }
  178. void LLPanelMyProfileEdit::processProfileProperties(const LLAvatarData* avatar_data)
  179. {
  180. fillCommonData(avatar_data);
  181. // 'Home page' was hidden in LLPanelAvatarProfile::fillCommonData() to fix  EXT-4734
  182. // Show 'Home page' in Edit My Profile (EXT-4873)
  183. childSetVisible("homepage_edit", true);
  184. fillPartnerData(avatar_data);
  185. fillAccountStatus(avatar_data);
  186. childSetValue("show_in_search_checkbox", (BOOL)(avatar_data->flags & AVATAR_ALLOW_PUBLISH));
  187. std::string first, last;
  188. BOOL found = gCacheName->getName(avatar_data->avatar_id, first, last);
  189. if (found)
  190. {
  191. childSetTextArg("name_text", "[FIRST]", first);
  192. childSetTextArg("name_text", "[LAST]", last);
  193. }
  194. }
  195. BOOL LLPanelMyProfileEdit::postBuild()
  196. {
  197. initTexturePickerMouseEvents();
  198. childSetTextArg("partner_edit_link", "[URL]", getString("partner_edit_link_url"));
  199. childSetTextArg("my_account_link", "[URL]", getString("my_account_link_url"));
  200. return LLPanelAvatarProfile::postBuild();
  201. }
  202. /**
  203.  * Inits map with texture picker and appropriate edit icon.
  204.  * Sets callbacks of Mouse Enter and Mouse Leave signals of Texture Pickers 
  205.  */
  206. void LLPanelMyProfileEdit::initTexturePickerMouseEvents()
  207. {
  208. LLTextureCtrl* text_pic = getChild<LLTextureCtrl>(PICKER_SECOND_LIFE);
  209. LLIconCtrl* text_icon = getChild<LLIconCtrl>("2nd_life_edit_icon");
  210. mTextureEditIconMap[text_pic->getName()] = text_icon;
  211. text_pic->setMouseEnterCallback(boost::bind(&LLPanelMyProfileEdit::onTexturePickerMouseEnter, this, _1));
  212. text_pic->setMouseLeaveCallback(boost::bind(&LLPanelMyProfileEdit::onTexturePickerMouseLeave, this, _1));
  213. text_icon->setVisible(FALSE);
  214. text_pic = getChild<LLTextureCtrl>(PICKER_FIRST_LIFE);
  215. text_icon = getChild<LLIconCtrl>("real_world_edit_icon");
  216. mTextureEditIconMap[text_pic->getName()] = text_icon;
  217. text_pic->setMouseEnterCallback(boost::bind(&LLPanelMyProfileEdit::onTexturePickerMouseEnter, this, _1));
  218. text_pic->setMouseLeaveCallback(boost::bind(&LLPanelMyProfileEdit::onTexturePickerMouseLeave, this, _1));
  219. text_icon->setVisible(FALSE);
  220. }
  221. void LLPanelMyProfileEdit::resetData()
  222. {
  223. LLPanelMyProfile::resetData();
  224. childSetTextArg("name_text", "[FIRST]", LLStringUtil::null);
  225. childSetTextArg("name_text", "[LAST]", LLStringUtil::null);
  226. }
  227. void LLPanelMyProfileEdit::onTexturePickerMouseEnter(LLUICtrl* ctrl)
  228. {
  229. mTextureEditIconMap[ctrl->getName()]->setVisible(TRUE);
  230. }
  231. void LLPanelMyProfileEdit::onTexturePickerMouseLeave(LLUICtrl* ctrl)
  232. {
  233. mTextureEditIconMap[ctrl->getName()]->setVisible(FALSE);
  234. }
  235. void LLPanelMyProfileEdit::enableEditing(bool enable)
  236. {
  237. childSetEnabled("2nd_life_pic", enable);
  238. childSetEnabled("real_world_pic", enable);
  239. childSetEnabled("sl_description_edit", enable);
  240. childSetEnabled("fl_description_edit", enable);
  241. childSetEnabled("homepage_edit", enable);
  242. childSetEnabled("show_in_search_checkbox", enable);
  243. }