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

游戏引擎

开发平台:

C++ Builder

  1. /**
  2.  * @file LLSidepanelInventory.cpp
  3.  * @brief Side Bar "Inventory" 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 "llsidepanelinventory.h"
  34. #include "llagent.h"
  35. #include "llbutton.h"
  36. #include "llinventorybridge.h"
  37. #include "llinventorypanel.h"
  38. #include "llpanelmaininventory.h"
  39. #include "llsidepaneliteminfo.h"
  40. #include "llsidepaneltaskinfo.h"
  41. #include "lltabcontainer.h"
  42. #include "llselectmgr.h"
  43. static LLRegisterPanelClassWrapper<LLSidepanelInventory> t_inventory("sidepanel_inventory");
  44. LLSidepanelInventory::LLSidepanelInventory()
  45. : LLPanel(),
  46. mItemPanel(NULL),
  47. mPanelMainInventory(NULL)
  48. {
  49. //LLUICtrlFactory::getInstance()->buildPanel(this, "panel_inventory.xml"); // Called from LLRegisterPanelClass::defaultPanelClassBuilder()
  50. }
  51. LLSidepanelInventory::~LLSidepanelInventory()
  52. {
  53. }
  54. BOOL LLSidepanelInventory::postBuild()
  55. {
  56. // UI elements from inventory panel
  57. {
  58. mInventoryPanel = getChild<LLPanel>("sidepanel__inventory_panel");
  59. mInfoBtn = mInventoryPanel->getChild<LLButton>("info_btn");
  60. mInfoBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onInfoButtonClicked, this));
  61. mShareBtn = mInventoryPanel->getChild<LLButton>("share_btn");
  62. mShareBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onShareButtonClicked, this));
  63. mWearBtn = mInventoryPanel->getChild<LLButton>("wear_btn");
  64. mWearBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onWearButtonClicked, this));
  65. mPlayBtn = mInventoryPanel->getChild<LLButton>("play_btn");
  66. mPlayBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onPlayButtonClicked, this));
  67. mTeleportBtn = mInventoryPanel->getChild<LLButton>("teleport_btn");
  68. mTeleportBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onTeleportButtonClicked, this));
  69. mOverflowBtn = mInventoryPanel->getChild<LLButton>("overflow_btn");
  70. mOverflowBtn->setClickedCallback(boost::bind(&LLSidepanelInventory::onOverflowButtonClicked, this));
  71. mPanelMainInventory = mInventoryPanel->getChild<LLPanelMainInventory>("panel_main_inventory");
  72. mPanelMainInventory->setSelectCallback(boost::bind(&LLSidepanelInventory::onSelectionChange, this, _1, _2));
  73. /* 
  74.    EXT-4846 : "Can we suppress the "Landmarks" and "My Favorites" folder since they have their own Task Panel?"
  75.    Deferring this until 2.1.
  76. LLInventoryPanel *my_inventory_panel = mPanelMainInventory->getChild<LLInventoryPanel>("All Items");
  77. my_inventory_panel->addHideFolderType(LLFolderType::FT_LANDMARK);
  78. my_inventory_panel->addHideFolderType(LLFolderType::FT_FAVORITE);
  79. */
  80. }
  81. // UI elements from item panel
  82. {
  83. mItemPanel = getChild<LLSidepanelItemInfo>("sidepanel__item_panel");
  84. LLButton* back_btn = mItemPanel->getChild<LLButton>("back_btn");
  85. back_btn->setClickedCallback(boost::bind(&LLSidepanelInventory::onBackButtonClicked, this));
  86. }
  87. // UI elements from task panel
  88. {
  89. mTaskPanel = getChild<LLSidepanelTaskInfo>("sidepanel__task_panel");
  90. if (mTaskPanel)
  91. {
  92. LLButton* back_btn = mTaskPanel->getChild<LLButton>("back_btn");
  93. back_btn->setClickedCallback(boost::bind(&LLSidepanelInventory::onBackButtonClicked, this));
  94. }
  95. }
  96. return TRUE;
  97. }
  98. void LLSidepanelInventory::onOpen(const LLSD& key)
  99. {
  100. if(key.size() == 0)
  101. return;
  102. mItemPanel->reset();
  103. if (key.has("id"))
  104. {
  105. mItemPanel->setItemID(key["id"].asUUID());
  106. if (key.has("object"))
  107. {
  108. mItemPanel->setObjectID(key["object"].asUUID());
  109. }
  110. showItemInfoPanel();
  111. }
  112. if (key.has("task"))
  113. {
  114. if (mTaskPanel)
  115. mTaskPanel->setObjectSelection(LLSelectMgr::getInstance()->getSelection());
  116. showTaskInfoPanel();
  117. }
  118. }
  119. void LLSidepanelInventory::onInfoButtonClicked()
  120. {
  121. LLInventoryItem *item = getSelectedItem();
  122. if (item)
  123. {
  124. mItemPanel->reset();
  125. mItemPanel->setItemID(item->getUUID());
  126. showItemInfoPanel();
  127. }
  128. }
  129. void LLSidepanelInventory::onShareButtonClicked()
  130. {
  131. }
  132. void LLSidepanelInventory::performActionOnSelection(const std::string &action)
  133. {
  134. LLPanelMainInventory *panel_main_inventory = mInventoryPanel->getChild<LLPanelMainInventory>("panel_main_inventory");
  135. LLFolderViewItem* current_item = panel_main_inventory->getActivePanel()->getRootFolder()->getCurSelectedItem();
  136. if (!current_item)
  137. {
  138. return;
  139. }
  140. current_item->getListener()->performAction(panel_main_inventory->getActivePanel()->getRootFolder(), panel_main_inventory->getActivePanel()->getModel(), action);
  141. }
  142. void LLSidepanelInventory::onWearButtonClicked()
  143. {
  144. performActionOnSelection("wear");
  145. performActionOnSelection("attach");
  146. }
  147. void LLSidepanelInventory::onPlayButtonClicked()
  148. {
  149. const LLInventoryItem *item = getSelectedItem();
  150. if (!item)
  151. {
  152. return;
  153. }
  154. switch(item->getInventoryType())
  155. {
  156. case LLInventoryType::IT_GESTURE:
  157. performActionOnSelection("play");
  158. break;
  159. default:
  160. performActionOnSelection("open");
  161. break;
  162. }
  163. }
  164. void LLSidepanelInventory::onTeleportButtonClicked()
  165. {
  166. performActionOnSelection("teleport");
  167. }
  168. void LLSidepanelInventory::onOverflowButtonClicked()
  169. {
  170. }
  171. void LLSidepanelInventory::onBackButtonClicked()
  172. {
  173. showInventoryPanel();
  174. }
  175. void LLSidepanelInventory::onSelectionChange(const std::deque<LLFolderViewItem*> &items, BOOL user_action)
  176. {
  177. updateVerbs();
  178. }
  179. void LLSidepanelInventory::showItemInfoPanel()
  180. {
  181. mItemPanel->setVisible(TRUE);
  182. if (mTaskPanel)
  183. mTaskPanel->setVisible(FALSE);
  184. mInventoryPanel->setVisible(FALSE);
  185. mItemPanel->dirty();
  186. mItemPanel->setIsEditing(FALSE);
  187. }
  188. void LLSidepanelInventory::showTaskInfoPanel()
  189. {
  190. mItemPanel->setVisible(FALSE);
  191. mInventoryPanel->setVisible(FALSE);
  192. if (mTaskPanel)
  193. {
  194. mTaskPanel->setVisible(TRUE);
  195. mTaskPanel->dirty();
  196. mTaskPanel->setIsEditing(FALSE);
  197. }
  198. }
  199. void LLSidepanelInventory::showInventoryPanel()
  200. {
  201. mItemPanel->setVisible(FALSE);
  202. if (mTaskPanel)
  203. mTaskPanel->setVisible(FALSE);
  204. mInventoryPanel->setVisible(TRUE);
  205. updateVerbs();
  206. }
  207. void LLSidepanelInventory::updateVerbs()
  208. {
  209. mInfoBtn->setEnabled(FALSE);
  210. mShareBtn->setEnabled(FALSE);
  211. mWearBtn->setVisible(FALSE);
  212. mWearBtn->setEnabled(FALSE);
  213. mPlayBtn->setVisible(FALSE);
  214. mPlayBtn->setEnabled(FALSE);
  215.   mTeleportBtn->setVisible(FALSE);
  216.   mTeleportBtn->setEnabled(FALSE);
  217. const LLInventoryItem *item = getSelectedItem();
  218. if (!item)
  219. return;
  220. bool is_single_selection = getSelectedCount() == 1;
  221. mInfoBtn->setEnabled(is_single_selection);
  222. mShareBtn->setEnabled(is_single_selection);
  223. switch(item->getInventoryType())
  224. {
  225. case LLInventoryType::IT_WEARABLE:
  226. case LLInventoryType::IT_OBJECT:
  227. case LLInventoryType::IT_ATTACHMENT:
  228. mWearBtn->setVisible(TRUE);
  229. mWearBtn->setEnabled(TRUE);
  230. break;
  231. case LLInventoryType::IT_SOUND:
  232. case LLInventoryType::IT_GESTURE:
  233. case LLInventoryType::IT_ANIMATION:
  234. mPlayBtn->setVisible(TRUE);
  235. mPlayBtn->setEnabled(TRUE);
  236. break;
  237. case LLInventoryType::IT_LANDMARK:
  238. mTeleportBtn->setVisible(TRUE);
  239. mTeleportBtn->setEnabled(TRUE);
  240. break;
  241. default:
  242. break;
  243. }
  244. }
  245. LLInventoryItem *LLSidepanelInventory::getSelectedItem()
  246. {
  247. LLPanelMainInventory *panel_main_inventory = mInventoryPanel->getChild<LLPanelMainInventory>("panel_main_inventory");
  248. LLFolderViewItem* current_item = panel_main_inventory->getActivePanel()->getRootFolder()->getCurSelectedItem();
  249. if (!current_item)
  250. {
  251. return NULL;
  252. }
  253. const LLUUID &item_id = current_item->getListener()->getUUID();
  254. LLInventoryItem *item = gInventory.getItem(item_id);
  255. return item;
  256. }
  257. U32 LLSidepanelInventory::getSelectedCount()
  258. {
  259. LLPanelMainInventory *panel_main_inventory = mInventoryPanel->getChild<LLPanelMainInventory>("panel_main_inventory");
  260. std::set<LLUUID> selection_list;
  261. panel_main_inventory->getActivePanel()->getRootFolder()->getSelectionList(selection_list);
  262. return selection_list.size();
  263. }
  264. LLInventoryPanel *LLSidepanelInventory::getActivePanel()
  265. {
  266. if (!getVisible())
  267. {
  268. return NULL;
  269. }
  270. if (mInventoryPanel->getVisible())
  271. {
  272. return mPanelMainInventory->getActivePanel();
  273. }
  274. return NULL;
  275. }
  276. BOOL LLSidepanelInventory::isMainInventoryPanelActive() const
  277. {
  278. return mInventoryPanel->getVisible();
  279. }