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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llpanelgroup.cpp
  3.  *
  4.  * $LicenseInfo:firstyear=2006&license=viewergpl$
  5.  * 
  6.  * Copyright (c) 2006-2010, Linden Research, Inc.
  7.  * 
  8.  * Second Life Viewer Source Code
  9.  * The source code in this file ("Source Code") is provided by Linden Lab
  10.  * to you under the terms of the GNU General Public License, version 2.0
  11.  * ("GPL"), unless you have obtained a separate licensing agreement
  12.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  13.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15.  * 
  16.  * There are special exceptions to the terms and conditions of the GPL as
  17.  * it is applied to this Source Code. View the full text of the exception
  18.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  19.  * online at
  20.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21.  * 
  22.  * By copying, modifying or distributing this software, you acknowledge
  23.  * that you have read and understood your obligations described above,
  24.  * and agree to abide by those obligations.
  25.  * 
  26.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28.  * COMPLETENESS OR PERFORMANCE.
  29.  * $/LicenseInfo$
  30.  */
  31. #include "llviewerprecompiledheaders.h"
  32. #include "llpanelgroup.h"
  33. // Library includes
  34. #include "llbutton.h"
  35. #include "lltabcontainer.h"
  36. #include "lltextbox.h"
  37. #include "lluictrlfactory.h"
  38. // Viewer includes
  39. #include "llviewermessage.h"
  40. #include "llviewerwindow.h"
  41. #include "llappviewer.h"
  42. #include "llnotificationsutil.h"
  43. #include "llfloaterreg.h"
  44. #include "llfloater.h"
  45. #include "llgroupactions.h"
  46. #include "llagent.h" 
  47. #include "llsidetraypanelcontainer.h"
  48. #include "llpanelgroupnotices.h"
  49. #include "llpanelgroupgeneral.h"
  50. #include "llsidetray.h"
  51. #include "llaccordionctrltab.h"
  52. #include "llaccordionctrl.h"
  53. static LLRegisterPanelClassWrapper<LLPanelGroup> t_panel_group("panel_group_info_sidetray");
  54. LLPanelGroupTab::LLPanelGroupTab()
  55. : LLPanel(),
  56.   mAllowEdit(TRUE),
  57.   mHasModal(FALSE)
  58. {
  59. mGroupID = LLUUID::null;
  60. }
  61. LLPanelGroupTab::~LLPanelGroupTab()
  62. {
  63. }
  64. BOOL LLPanelGroupTab::isVisibleByAgent(LLAgent* agentp)
  65. {
  66. //default to being visible
  67. return TRUE;
  68. }
  69. BOOL LLPanelGroupTab::postBuild()
  70. {
  71. return TRUE;
  72. }
  73. LLPanelGroup::LLPanelGroup()
  74. : LLPanel(),
  75. LLGroupMgrObserver( LLUUID() ),
  76. mSkipRefresh(FALSE),
  77. mButtonJoin(NULL),
  78. mShowingNotifyDialog(false)
  79. {
  80. // Set up the factory callbacks.
  81. // Roles sub tabs
  82. LLGroupMgr::getInstance()->addObserver(this);
  83. }
  84. LLPanelGroup::~LLPanelGroup()
  85. {
  86. LLGroupMgr::getInstance()->removeObserver(this);
  87. if(LLVoiceClient::getInstance())
  88. LLVoiceClient::getInstance()->removeObserver(this);
  89. }
  90. void LLPanelGroup::onOpen(const LLSD& key)
  91. {
  92. if(!key.has("group_id"))
  93. return;
  94. LLUUID group_id = key["group_id"];
  95. if(!key.has("action"))
  96. {
  97. setGroupID(group_id);
  98. return;
  99. }
  100. std::string str_action = key["action"];
  101. if(str_action == "refresh")
  102. {
  103. if(mID == group_id || group_id == LLUUID::null)
  104. refreshData();
  105. }
  106. else if(str_action == "close")
  107. {
  108. onBackBtnClick();
  109. }
  110. else if(str_action == "create")
  111. {
  112. setGroupID(LLUUID::null);
  113. }
  114. else if(str_action == "refresh_notices")
  115. {
  116. LLPanelGroupNotices* panel_notices = findChild<LLPanelGroupNotices>("group_notices_tab_panel");
  117. if(panel_notices)
  118. panel_notices->refreshNotices();
  119. }
  120. }
  121. BOOL LLPanelGroup::postBuild()
  122. {
  123. mDefaultNeedsApplyMesg = getString("default_needs_apply_text");
  124. mWantApplyMesg = getString("want_apply_text");
  125. LLButton* button;
  126. button = getChild<LLButton>("btn_apply");
  127. button->setClickedCallback(onBtnApply, this);
  128. button->setVisible(true);
  129. button->setEnabled(false);
  130. button = getChild<LLButton>("btn_call");
  131. button->setClickedCallback(onBtnGroupCallClicked, this);
  132. button = getChild<LLButton>("btn_chat");
  133. button->setClickedCallback(onBtnGroupChatClicked, this);
  134. button = getChild<LLButton>("btn_cancel");
  135. button->setVisible(false); button->setEnabled(true);
  136. button = getChild<LLButton>("btn_refresh");
  137. button->setClickedCallback(onBtnRefresh, this);
  138. getChild<LLButton>("btn_create")->setVisible(false);
  139. childSetCommitCallback("back",boost::bind(&LLPanelGroup::onBackBtnClick,this),NULL);
  140. childSetCommitCallback("btn_create",boost::bind(&LLPanelGroup::onBtnCreate,this),NULL);
  141. childSetCommitCallback("btn_cancel",boost::bind(&LLPanelGroup::onBtnCancel,this),NULL);
  142. LLPanelGroupTab* panel_general = findChild<LLPanelGroupTab>("group_general_tab_panel");
  143. LLPanelGroupTab* panel_roles = findChild<LLPanelGroupTab>("group_roles_tab_panel");
  144. LLPanelGroupTab* panel_notices = findChild<LLPanelGroupTab>("group_notices_tab_panel");
  145. LLPanelGroupTab* panel_land = findChild<LLPanelGroupTab>("group_land_tab_panel");
  146. if(panel_general) mTabs.push_back(panel_general);
  147. if(panel_roles) mTabs.push_back(panel_roles);
  148. if(panel_notices) mTabs.push_back(panel_notices);
  149. if(panel_land) mTabs.push_back(panel_land);
  150. if(panel_general)
  151. {
  152. panel_general->setupCtrls(this);
  153. button = panel_general->getChild<LLButton>("btn_join");
  154. button->setVisible(false);
  155. button->setEnabled(true);
  156. mButtonJoin = button;
  157. mButtonJoin->setCommitCallback(boost::bind(&LLPanelGroup::onBtnJoin,this));
  158. mJoinText = panel_general->getChild<LLUICtrl>("join_cost_text");
  159. }
  160. gVoiceClient->addObserver(this);
  161. return TRUE;
  162. }
  163. void LLPanelGroup::reposButton(const std::string& name)
  164. {
  165. LLButton* button = findChild<LLButton>(name);
  166. if(!button)
  167. return;
  168. LLRect btn_rect = button->getRect();
  169. btn_rect.setLeftTopAndSize( btn_rect.mLeft, btn_rect.getHeight() + 2, btn_rect.getWidth(), btn_rect.getHeight());
  170. button->setRect(btn_rect);
  171. }
  172. void LLPanelGroup::reposButtons()
  173. {
  174. LLButton* button_refresh = findChild<LLButton>("btn_refresh");
  175. LLButton* button_cancel = findChild<LLButton>("btn_cancel");
  176. if(button_refresh && button_cancel && button_refresh->getVisible() && button_cancel->getVisible())
  177. {
  178. LLRect btn_refresh_rect = button_refresh->getRect();
  179. LLRect btn_cancel_rect = button_cancel->getRect();
  180. btn_refresh_rect.setLeftTopAndSize( btn_cancel_rect.mLeft + btn_cancel_rect.getWidth() + 2, 
  181. btn_refresh_rect.getHeight() + 2, btn_refresh_rect.getWidth(), btn_refresh_rect.getHeight());
  182. button_refresh->setRect(btn_refresh_rect);
  183. }
  184. reposButton("btn_apply");
  185. reposButton("btn_create");
  186. reposButton("btn_refresh");
  187. reposButton("btn_cancel");
  188. reposButton("btn_chat");
  189. reposButton("btn_call");
  190. }
  191. void LLPanelGroup::reshape(S32 width, S32 height, BOOL called_from_parent )
  192. {
  193. LLPanel::reshape(width, height, called_from_parent );
  194. reposButtons();
  195. }
  196. void LLPanelGroup::onBackBtnClick()
  197. {
  198. LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
  199. if(parent)
  200. {
  201. parent->openPreviousPanel();
  202. }
  203. }
  204. void LLPanelGroup::onBtnCreate()
  205. {
  206. LLPanelGroupGeneral* panel_general = findChild<LLPanelGroupGeneral>("group_general_tab_panel");
  207. if(!panel_general)
  208. return;
  209. std::string apply_mesg;
  210. if(panel_general->apply(apply_mesg))//yes yes you need to call apply to create...
  211. return;
  212. if ( !apply_mesg.empty() )
  213. {
  214. LLSD args;
  215. args["MESSAGE"] = apply_mesg;
  216. LLNotificationsUtil::add("GenericAlert", args);
  217. }
  218. }
  219. void LLPanelGroup::onBtnRefresh(void* user_data)
  220. {
  221. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  222. self->refreshData();
  223. }
  224. void LLPanelGroup::onBtnApply(void* user_data)
  225. {
  226. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  227. self->apply();
  228. }
  229. void LLPanelGroup::onBtnGroupCallClicked(void* user_data)
  230. {
  231. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  232. self->callGroup();
  233. }
  234. void LLPanelGroup::onBtnGroupChatClicked(void* user_data)
  235. {
  236. LLPanelGroup* self = static_cast<LLPanelGroup*>(user_data);
  237. self->chatGroup();
  238. }
  239. void LLPanelGroup::onBtnJoin()
  240. {
  241. lldebugs << "joining group: " << mID << llendl;
  242. LLGroupActions::join(mID);
  243. }
  244. void LLPanelGroup::onBtnCancel()
  245. {
  246. onBackBtnClick();
  247. }
  248. void LLPanelGroup::changed(LLGroupChange gc)
  249. {
  250. for(std::vector<LLPanelGroupTab* >::iterator it = mTabs.begin();it!=mTabs.end();++it)
  251. (*it)->update(gc);
  252. update(gc);
  253. }
  254. // virtual
  255. void LLPanelGroup::onChange(EStatusType status, const std::string &channelURI, bool proximal)
  256. {
  257. if(status == STATUS_JOINING || status == STATUS_LEFT_CHANNEL)
  258. {
  259. return;
  260. }
  261. childSetEnabled("btn_call", LLVoiceClient::voiceEnabled() && gVoiceClient->voiceWorking());
  262. }
  263. void LLPanelGroup::notifyObservers()
  264. {
  265. changed(GC_ALL);
  266. }
  267. void LLPanelGroup::update(LLGroupChange gc)
  268. {
  269. LLGroupMgrGroupData* gdatap = LLGroupMgr::getInstance()->getGroupData(mID);
  270. if(gdatap)
  271. {
  272. childSetValue("group_name", gdatap->mName);
  273. childSetToolTip("group_name",gdatap->mName);
  274. LLGroupData agent_gdatap;
  275. bool is_member = gAgent.getGroupData(mID,agent_gdatap);
  276. bool join_btn_visible = !is_member && gdatap->mOpenEnrollment;
  277. mButtonJoin->setVisible(join_btn_visible);
  278. mJoinText->setVisible(join_btn_visible);
  279. if(join_btn_visible)
  280. {
  281. LLStringUtil::format_map_t string_args;
  282. std::string fee_buff;
  283. if(gdatap->mMembershipFee)
  284. {
  285. string_args["[AMOUNT]"] = llformat("%d", gdatap->mMembershipFee);
  286. fee_buff = getString("group_join_btn", string_args);
  287. }
  288. else
  289. {
  290. fee_buff = getString("group_join_free", string_args);
  291. }
  292. mJoinText->setValue(fee_buff);
  293. }
  294. }
  295. }
  296. void LLPanelGroup::setGroupID(const LLUUID& group_id)
  297. {
  298. std::string str_group_id;
  299. group_id.toString(str_group_id);
  300. bool is_same_id = group_id == mID;
  301. LLGroupMgr::getInstance()->removeObserver(this);
  302. mID = group_id;
  303. LLGroupMgr::getInstance()->addObserver(this);
  304. for(std::vector<LLPanelGroupTab* >::iterator it = mTabs.begin();it!=mTabs.end();++it)
  305. (*it)->setGroupID(group_id);
  306. LLGroupMgrGroupData* gdatap = LLGroupMgr::getInstance()->getGroupData(mID);
  307. if(gdatap)
  308. {
  309. childSetValue("group_name", gdatap->mName);
  310. childSetToolTip("group_name",gdatap->mName);
  311. }
  312. LLButton* button_apply = findChild<LLButton>("btn_apply");
  313. LLButton* button_refresh = findChild<LLButton>("btn_refresh");
  314. LLButton* button_create = findChild<LLButton>("btn_create");
  315. LLButton* button_cancel = findChild<LLButton>("btn_cancel");
  316. LLButton* button_call = findChild<LLButton>("btn_call");
  317. LLButton* button_chat = findChild<LLButton>("btn_chat");
  318. bool is_null_group_id = group_id == LLUUID::null;
  319. if(button_apply)
  320. button_apply->setVisible(!is_null_group_id);
  321. if(button_refresh)
  322. button_refresh->setVisible(!is_null_group_id);
  323. if(button_create)
  324. button_create->setVisible(is_null_group_id);
  325. if(button_cancel)
  326. button_cancel->setVisible(!is_null_group_id);
  327. if(button_call)
  328. button_call->setVisible(!is_null_group_id);
  329. if(button_chat)
  330. button_chat->setVisible(!is_null_group_id);
  331. getChild<LLUICtrl>("prepend_founded_by")->setVisible(!is_null_group_id);
  332. LLAccordionCtrl* tab_ctrl = findChild<LLAccordionCtrl>("group_accordion");
  333. if(tab_ctrl)
  334. tab_ctrl->reset();
  335. LLAccordionCtrlTab* tab_general = findChild<LLAccordionCtrlTab>("group_general_tab");
  336. LLAccordionCtrlTab* tab_roles = findChild<LLAccordionCtrlTab>("group_roles_tab");
  337. LLAccordionCtrlTab* tab_notices = findChild<LLAccordionCtrlTab>("group_notices_tab");
  338. LLAccordionCtrlTab* tab_land = findChild<LLAccordionCtrlTab>("group_land_tab");
  339. if(!tab_general || !tab_roles || !tab_notices || !tab_land)
  340. return;
  341. if(mButtonJoin)
  342. mButtonJoin->setVisible(false);
  343. if(is_null_group_id)//creating new group
  344. {
  345. if(!tab_general->getDisplayChildren())
  346. tab_general->changeOpenClose(tab_general->getDisplayChildren());
  347. if(tab_roles->getDisplayChildren())
  348. tab_roles->changeOpenClose(tab_roles->getDisplayChildren());
  349. if(tab_notices->getDisplayChildren())
  350. tab_notices->changeOpenClose(tab_notices->getDisplayChildren());
  351. if(tab_land->getDisplayChildren())
  352. tab_land->changeOpenClose(tab_land->getDisplayChildren());
  353. tab_roles->setVisible(false);
  354. tab_notices->setVisible(false);
  355. tab_land->setVisible(false);
  356. getChild<LLUICtrl>("group_name")->setVisible(false);
  357. getChild<LLUICtrl>("group_name_editor")->setVisible(true);
  358. if(button_call)
  359. button_call->setVisible(false);
  360. if(button_chat)
  361. button_chat->setVisible(false);
  362. }
  363. else 
  364. {
  365. if(!is_same_id)
  366. {
  367. if(!tab_general->getDisplayChildren())
  368. tab_general->changeOpenClose(tab_general->getDisplayChildren());
  369. if(tab_roles->getDisplayChildren())
  370. tab_roles->changeOpenClose(tab_roles->getDisplayChildren());
  371. if(tab_notices->getDisplayChildren())
  372. tab_notices->changeOpenClose(tab_notices->getDisplayChildren());
  373. if(tab_land->getDisplayChildren())
  374. tab_land->changeOpenClose(tab_land->getDisplayChildren());
  375. }
  376. LLGroupData agent_gdatap;
  377. bool is_member = gAgent.getGroupData(mID,agent_gdatap);
  378. tab_roles->setVisible(is_member);
  379. tab_notices->setVisible(is_member);
  380. tab_land->setVisible(is_member);
  381. getChild<LLUICtrl>("group_name")->setVisible(true);
  382. getChild<LLUICtrl>("group_name_editor")->setVisible(false);
  383. if(button_apply)
  384. button_apply->setVisible(is_member);
  385. if(button_call)
  386. button_call->setVisible(is_member);
  387. if(button_chat)
  388. button_chat->setVisible(is_member);
  389. }
  390. reposButtons();
  391. update(GC_ALL);//show/hide "join" button if data is already ready
  392. }
  393. bool LLPanelGroup::apply(LLPanelGroupTab* tab)
  394. {
  395. if(!tab)
  396. return false;
  397. std::string mesg;
  398. if ( !tab->needsApply(mesg) )
  399. return true;
  400. std::string apply_mesg;
  401. if(tab->apply( apply_mesg ) )
  402. {
  403. //we skip refreshing group after ew manually apply changes since its very annoying
  404. //for those who are editing group
  405. mSkipRefresh = TRUE;
  406. return true;
  407. }
  408. if ( !apply_mesg.empty() )
  409. {
  410. LLSD args;
  411. args["MESSAGE"] = apply_mesg;
  412. LLNotificationsUtil::add("GenericAlert", args);
  413. }
  414. return false;
  415. }
  416. bool LLPanelGroup::apply()
  417. {
  418. return apply(findChild<LLPanelGroupTab>("group_general_tab_panel")) 
  419. && apply(findChild<LLPanelGroupTab>("group_roles_tab_panel"))
  420. && apply(findChild<LLPanelGroupTab>("group_notices_tab_panel"))
  421. && apply(findChild<LLPanelGroupTab>("group_land_tab_panel"))
  422. ;
  423. }
  424. // virtual
  425. void LLPanelGroup::draw()
  426. {
  427. LLPanel::draw();
  428. if (mRefreshTimer.hasExpired())
  429. {
  430. mRefreshTimer.stop();
  431. childEnable("btn_refresh");
  432. }
  433. LLButton* button_apply = findChild<LLButton>("btn_apply");
  434. if(button_apply && button_apply->getVisible())
  435. {
  436. bool enable = false;
  437. std::string mesg;
  438. for(std::vector<LLPanelGroupTab* >::iterator it = mTabs.begin();it!=mTabs.end();++it)
  439. enable = enable || (*it)->needsApply(mesg);
  440. childSetEnabled("btn_apply", enable);
  441. }
  442. }
  443. void LLPanelGroup::refreshData()
  444. {
  445. if(mSkipRefresh)
  446. {
  447. mSkipRefresh = FALSE;
  448. return;
  449. }
  450. LLGroupMgr::getInstance()->clearGroupData(getID());
  451. setGroupID(getID());
  452. // 5 second timeout
  453. childDisable("btn_refresh");
  454. mRefreshTimer.start();
  455. mRefreshTimer.setTimerExpirySec(5);
  456. }
  457. void LLPanelGroup::callGroup()
  458. {
  459. LLGroupActions::startCall(getID());
  460. }
  461. void LLPanelGroup::chatGroup()
  462. {
  463. LLGroupActions::startIM(getID());
  464. }
  465. void LLPanelGroup::showNotice(const std::string& subject,
  466.       const std::string& message,
  467.       const bool& has_inventory,
  468.       const std::string& inventory_name,
  469.       LLOfferInfo* inventory_offer)
  470. {
  471. LLPanelGroupNotices* panel_notices = findChild<LLPanelGroupNotices>("group_notices_tab_panel");
  472. if(!panel_notices)
  473. {
  474. // We need to clean up that inventory offer.
  475. if (inventory_offer)
  476. {
  477. inventory_offer->forceResponse(IOR_DECLINE);
  478. }
  479. return;
  480. }
  481. panel_notices->showNotice(subject,message,has_inventory,inventory_name,inventory_offer);
  482. }
  483. //static
  484. void LLPanelGroup::refreshCreatedGroup(const LLUUID& group_id)
  485. {
  486. LLPanelGroup* panel = LLSideTray::getInstance()->findChild<LLPanelGroup>("panel_group_info_sidetray");
  487. if(!panel)
  488. return;
  489. panel->setGroupID(group_id);
  490. }
  491. //static
  492. void LLPanelGroup::showNotice(const std::string& subject,
  493.    const std::string& message,
  494.    const LLUUID& group_id,
  495.    const bool& has_inventory,
  496.    const std::string& inventory_name,
  497.    LLOfferInfo* inventory_offer)
  498. {
  499. LLPanelGroup* panel = LLSideTray::getInstance()->findChild<LLPanelGroup>("panel_group_info_sidetray");
  500. if(!panel)
  501. return;
  502. if(panel->getID() != group_id)//???? only for current group_id or switch panels? FIXME
  503. return;
  504. panel->showNotice(subject,message,has_inventory,inventory_name,inventory_offer);
  505. }
  506. bool LLPanelGroup::canClose()
  507. {
  508. if(getVisible() == false)
  509. return true;
  510. bool need_save = false;
  511. std::string mesg;
  512. for(std::vector<LLPanelGroupTab* >::iterator it = mTabs.begin();it!=mTabs.end();++it)
  513. if(need_save|=(*it)->needsApply(mesg))
  514. break;
  515. if(!need_save)
  516. return false;
  517. // If no message was provided, give a generic one.
  518. if (mesg.empty())
  519. {
  520. mesg = mDefaultNeedsApplyMesg;
  521. }
  522. // Create a notify box, telling the user about the unapplied tab.
  523. LLSD args;
  524. args["NEEDS_APPLY_MESSAGE"] = mesg;
  525. args["WANT_APPLY_MESSAGE"] = mWantApplyMesg;
  526. LLNotificationsUtil::add("SaveChanges", args, LLSD(), boost::bind(&LLPanelGroup::handleNotifyCallback,this, _1, _2));
  527. mShowingNotifyDialog = true;
  528. return false;
  529. }
  530. bool LLPanelGroup::notifyChildren(const LLSD& info)
  531. {
  532. if(info.has("request") && mID.isNull() )
  533. {
  534. std::string str_action = info["request"];
  535. if (str_action == "quit" )
  536. {
  537. canClose();
  538. return true;
  539. }
  540. if(str_action == "wait_quit")
  541. return mShowingNotifyDialog;
  542. }
  543. return false;
  544. }
  545. bool LLPanelGroup::handleNotifyCallback(const LLSD& notification, const LLSD& response)
  546. {
  547. S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
  548. mShowingNotifyDialog = false;
  549. switch (option)
  550. {
  551. case 0: // "Apply Changes"
  552. apply();
  553. break;
  554. case 1: // "Ignore Changes"
  555. break;
  556. case 2: // "Cancel"
  557. default:
  558. // Do nothing.  The user is canceling the action.
  559. // If we were quitting, we didn't really mean it.
  560. LLAppViewer::instance()->abortQuit();
  561. break;
  562. }
  563. return false;
  564. }