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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llmoveview.cpp
  3.  * @brief Container for movement buttons like forward, left, fly
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-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 "llmoveview.h"
  34. // Library includes
  35. #include "indra_constants.h"
  36. #include "llparcel.h"
  37. // Viewer includes
  38. #include "llagent.h"
  39. #include "llvoavatarself.h" // to check gAgent.getAvatarObject()->isSitting()
  40. #include "llbottomtray.h"
  41. #include "llbutton.h"
  42. #include "llfloaterreg.h"
  43. #include "lljoystickbutton.h"
  44. #include "lluictrlfactory.h"
  45. #include "llviewerwindow.h"
  46. #include "llviewercontrol.h"
  47. #include "llselectmgr.h" 
  48. #include "llviewerparcelmgr.h"
  49. #include "llviewerregion.h"
  50. #include "lltooltip.h"
  51. //
  52. // Constants
  53. //
  54. const F32 MOVE_BUTTON_DELAY = 0.0f;
  55. const F32 YAW_NUDGE_RATE = 0.05f; // fraction of normal speed
  56. const F32 NUDGE_TIME = 0.25f; // in seconds
  57. const std::string BOTTOM_TRAY_BUTTON_NAME = "movement_btn";
  58. //
  59. // Member functions
  60. //
  61. // protected
  62. LLFloaterMove::LLFloaterMove(const LLSD& key)
  63. : LLTransientDockableFloater(NULL, true, key),
  64. mForwardButton(NULL),
  65. mBackwardButton(NULL),
  66. mTurnLeftButton(NULL), 
  67. mTurnRightButton(NULL),
  68. mMoveUpButton(NULL),
  69. mMoveDownButton(NULL),
  70. mStopFlyingButton(NULL),
  71. mModeActionsPanel(NULL),
  72. mCurrentMode(MM_WALK)
  73. {
  74. }
  75. // virtual
  76. BOOL LLFloaterMove::postBuild()
  77. {
  78. setIsChrome(TRUE);
  79. LLDockableFloater::postBuild();
  80. mForwardButton = getChild<LLJoystickAgentTurn>("forward btn"); 
  81. mForwardButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  82. mBackwardButton = getChild<LLJoystickAgentTurn>("backward btn"); 
  83. mBackwardButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  84. mTurnLeftButton = getChild<LLButton>("turn left btn"); 
  85. mTurnLeftButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  86. mTurnLeftButton->setHeldDownCallback(boost::bind(&LLFloaterMove::turnLeft, this));
  87. mTurnRightButton = getChild<LLButton>("turn right btn"); 
  88. mTurnRightButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  89. mTurnRightButton->setHeldDownCallback(boost::bind(&LLFloaterMove::turnRight, this));
  90. mMoveUpButton = getChild<LLButton>("move up btn"); 
  91. mMoveUpButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  92. mMoveUpButton->setHeldDownCallback(boost::bind(&LLFloaterMove::moveUp, this));
  93. mMoveDownButton = getChild<LLButton>("move down btn"); 
  94. mMoveDownButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  95. mMoveDownButton->setHeldDownCallback(boost::bind(&LLFloaterMove::moveDown, this));
  96. mStopFlyingButton = getChild<LLButton>("stop_fly_btn");
  97. mModeActionsPanel = getChild<LLPanel>("panel_modes");
  98. LLButton* btn;
  99. btn = getChild<LLButton>("mode_walk_btn");
  100. btn->setCommitCallback(boost::bind(&LLFloaterMove::onWalkButtonClick, this));
  101. btn = getChild<LLButton>("mode_run_btn");
  102. btn->setCommitCallback(boost::bind(&LLFloaterMove::onRunButtonClick, this));
  103. btn = getChild<LLButton>("mode_fly_btn");
  104. btn->setCommitCallback(boost::bind(&LLFloaterMove::onFlyButtonClick, this));
  105. btn = getChild<LLButton>("stop_fly_btn");
  106. btn->setCommitCallback(boost::bind(&LLFloaterMove::onStopFlyingButtonClick, this));
  107. showFlyControls(false);
  108. initModeTooltips();
  109. initModeButtonMap();
  110. initMovementMode();
  111. LLViewerParcelMgr::getInstance()->addAgentParcelChangedCallback(LLFloaterMove::sUpdateFlyingStatus);
  112. return TRUE;
  113. }
  114. // virtual
  115. void LLFloaterMove::setEnabled(BOOL enabled)
  116. {
  117. //we need to enable/disable only buttons, EXT-1061.
  118. // is called before postBuild() - use findChild here.
  119. LLPanel *panel_actions = findChild<LLPanel>("panel_actions");
  120. if (panel_actions) panel_actions->setEnabled(enabled);
  121. showModeButtons(enabled);
  122. }
  123. // *NOTE: we assume that setVisible() is called on floater close.
  124. // virtual
  125. void LLFloaterMove::setVisible(BOOL visible)
  126. {
  127. // Do nothing with Stand/Stop Flying panel in excessive calls of this method (from LLTransientFloaterMgr?).
  128. if (getVisible() == visible)
  129. {
  130. LLTransientDockableFloater::setVisible(visible);
  131. return;
  132. }
  133. if (visible)
  134. {
  135. // Attach the Stand/Stop Flying panel.
  136. LLPanelStandStopFlying* ssf_panel = LLPanelStandStopFlying::getInstance();
  137. ssf_panel->reparent(this);
  138. const LLRect& mode_actions_rect = mModeActionsPanel->getRect();
  139. ssf_panel->setOrigin(mode_actions_rect.mLeft, mode_actions_rect.mBottom);
  140. }
  141. else
  142. {
  143. // Detach the Stand/Stop Flying panel.
  144. LLPanelStandStopFlying::getInstance()->reparent(NULL);
  145. }
  146. LLTransientDockableFloater::setVisible(visible);
  147. }
  148. // static 
  149. F32 LLFloaterMove::getYawRate( F32 time )
  150. {
  151. if( time < NUDGE_TIME )
  152. {
  153. F32 rate = YAW_NUDGE_RATE + time * (1 - YAW_NUDGE_RATE)/ NUDGE_TIME;
  154. return rate;
  155. }
  156. else
  157. {
  158. return 1.f;
  159. }
  160. }
  161. // static 
  162. void LLFloaterMove::setFlyingMode(BOOL fly)
  163. {
  164. LLFloaterMove* instance = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
  165. if (instance)
  166. {
  167. instance->setFlyingModeImpl(fly);
  168. instance->showModeButtons(!fly);
  169. }
  170. if (fly)
  171. {
  172. LLPanelStandStopFlying::setStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STOP_FLYING);
  173. }
  174. else
  175. {
  176. LLPanelStandStopFlying::clearStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STOP_FLYING);
  177. }
  178. }
  179. //static
  180. void LLFloaterMove::setAlwaysRunMode(bool run)
  181. {
  182. LLFloaterMove* instance = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
  183. if (instance)
  184. {
  185. instance->setAlwaysRunModeImpl(run);
  186. }
  187. }
  188. void LLFloaterMove::setFlyingModeImpl(BOOL fly)
  189. {
  190. updateButtonsWithMovementMode(fly ? MM_FLY : (gAgent.getAlwaysRun() ? MM_RUN : MM_WALK));
  191. }
  192. void LLFloaterMove::setAlwaysRunModeImpl(bool run)
  193. {
  194. if (!gAgent.getFlying())
  195. {
  196. updateButtonsWithMovementMode(run ? MM_RUN : MM_WALK);
  197. }
  198. }
  199. //static
  200. void LLFloaterMove::setSittingMode(BOOL bSitting)
  201. {
  202. if (bSitting)
  203. {
  204. LLPanelStandStopFlying::setStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STAND);
  205. }
  206. else
  207. {
  208. LLPanelStandStopFlying::clearStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STAND);
  209. // show "Stop Flying" button if needed. EXT-871
  210. if (gAgent.getFlying())
  211. {
  212. LLPanelStandStopFlying::setStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STOP_FLYING);
  213. }
  214. }
  215. enableInstance(!bSitting);
  216. }
  217. // protected 
  218. void LLFloaterMove::turnLeft()
  219. {
  220. F32 time = mTurnLeftButton->getHeldDownTime();
  221. gAgent.moveYaw( getYawRate( time ) );
  222. }
  223. // protected
  224. void LLFloaterMove::turnRight()
  225. {
  226. F32 time = mTurnRightButton->getHeldDownTime();
  227. gAgent.moveYaw( -getYawRate( time ) );
  228. }
  229. // protected
  230. void LLFloaterMove::moveUp()
  231. {
  232. // Jumps or flys up, depending on fly state
  233. gAgent.moveUp(1);
  234. }
  235. // protected
  236. void LLFloaterMove::moveDown()
  237. {
  238. // Crouches or flys down, depending on fly state
  239. gAgent.moveUp(-1);
  240. }
  241. //////////////////////////////////////////////////////////////////////////
  242. // Private Section:
  243. //////////////////////////////////////////////////////////////////////////
  244. void LLFloaterMove::onWalkButtonClick()
  245. {
  246. setMovementMode(MM_WALK);
  247. }
  248. void LLFloaterMove::onRunButtonClick()
  249. {
  250. setMovementMode(MM_RUN);
  251. }
  252. void LLFloaterMove::onFlyButtonClick()
  253. {
  254. setMovementMode(MM_FLY);
  255. }
  256. void LLFloaterMove::onStopFlyingButtonClick()
  257. {
  258. setMovementMode(gAgent.getAlwaysRun() ? MM_RUN : MM_WALK);
  259. }
  260. void LLFloaterMove::setMovementMode(const EMovementMode mode)
  261. {
  262. mCurrentMode = mode;
  263. gAgent.setFlying(MM_FLY == mode);
  264. // attempts to set avatar flying can not set it real flying in some cases.
  265. // For ex. when avatar fell down & is standing up.
  266. // So, no need to continue processing FLY mode. See EXT-1079
  267. if (MM_FLY == mode && !gAgent.getFlying())
  268. {
  269. return;
  270. }
  271. switch (mode)
  272. {
  273. case MM_RUN:
  274. gAgent.setAlwaysRun();
  275. gAgent.setRunning();
  276. break;
  277. case MM_WALK:
  278. gAgent.clearAlwaysRun();
  279. gAgent.clearRunning();
  280. break;
  281. default:
  282. //do nothing for other modes (MM_FLY)
  283. break;
  284. }
  285. // tell the simulator.
  286. gAgent.sendWalkRun(gAgent.getAlwaysRun());
  287. updateButtonsWithMovementMode(mode);
  288. bool bHideModeButtons = MM_FLY == mode
  289. || (gAgent.getAvatarObject() && gAgent.getAvatarObject()->isSitting());
  290. showModeButtons(!bHideModeButtons);
  291. }
  292. void LLFloaterMove::updateButtonsWithMovementMode(const EMovementMode newMode)
  293. {
  294. showFlyControls(MM_FLY == newMode);
  295. setModeTooltip(newMode);
  296. setModeButtonToggleState(newMode);
  297. }
  298. void LLFloaterMove::showFlyControls(bool bShow)
  299. {
  300. mMoveUpButton->setVisible(bShow);
  301. mMoveDownButton->setVisible(bShow);
  302. // *TODO: mantipov: mStopFlyingButton from the FloaterMove is not used now.
  303. // It was not completly removed until functionality is reviewed by LL
  304. mStopFlyingButton->setVisible(FALSE);
  305. }
  306. void LLFloaterMove::initModeTooltips()
  307. {
  308. control_tooltip_map_t walkTipMap;
  309. walkTipMap.insert(std::make_pair(mForwardButton, getString("walk_forward_tooltip")));
  310. walkTipMap.insert(std::make_pair(mBackwardButton, getString("walk_back_tooltip")));
  311. mModeControlTooltipsMap[MM_WALK] = walkTipMap;
  312. control_tooltip_map_t runTipMap;
  313. runTipMap.insert(std::make_pair(mForwardButton, getString("run_forward_tooltip")));
  314. runTipMap.insert(std::make_pair(mBackwardButton, getString("run_back_tooltip")));
  315. mModeControlTooltipsMap[MM_RUN] = runTipMap;
  316. control_tooltip_map_t flyTipMap;
  317. flyTipMap.insert(std::make_pair(mForwardButton, getString("fly_forward_tooltip")));
  318. flyTipMap.insert(std::make_pair(mBackwardButton, getString("fly_back_tooltip")));
  319. mModeControlTooltipsMap[MM_FLY] = flyTipMap;
  320. setModeTooltip(MM_WALK);
  321. }
  322. void LLFloaterMove::initModeButtonMap()
  323. {
  324. mModeControlButtonMap[MM_WALK] = getChild<LLButton>("mode_walk_btn");
  325. mModeControlButtonMap[MM_RUN] = getChild<LLButton>("mode_run_btn");
  326. mModeControlButtonMap[MM_FLY] = getChild<LLButton>("mode_fly_btn");
  327. }
  328. void LLFloaterMove::initMovementMode()
  329. {
  330. EMovementMode initMovementMode = gAgent.getAlwaysRun() ? MM_RUN : MM_WALK;
  331. if (gAgent.getFlying())
  332. {
  333. initMovementMode = MM_FLY;
  334. }
  335. setMovementMode(initMovementMode);
  336. if (gAgent.getAvatarObject())
  337. {
  338. setEnabled(!gAgent.getAvatarObject()->isSitting());
  339. }
  340. }
  341. void LLFloaterMove::setModeTooltip(const EMovementMode mode)
  342. {
  343. llassert_always(mModeControlTooltipsMap.end() != mModeControlTooltipsMap.find(mode));
  344. control_tooltip_map_t controlsTipMap = mModeControlTooltipsMap[mode];
  345. control_tooltip_map_t::const_iterator it = controlsTipMap.begin();
  346. for (; it != controlsTipMap.end(); ++it)
  347. {
  348. LLView* ctrl = it->first;
  349. std::string tooltip = it->second;
  350. ctrl->setToolTip(tooltip);
  351. }
  352. }
  353. /**
  354.  * Updates position of the floater to be center aligned with Move button.
  355.  * 
  356.  * Because Tip floater created as dependent floater this method 
  357.  * must be called before "showQuickTips()" to get Tip floater be positioned at the right side of the floater
  358.  */
  359. void LLFloaterMove::updatePosition()
  360. {
  361. LLBottomTray* tray = LLBottomTray::getInstance();
  362. if (!tray) return;
  363. LLButton* movement_btn = tray->getChild<LLButton>(BOTTOM_TRAY_BUTTON_NAME);
  364. //align centers of a button and a floater
  365. S32 x = movement_btn->calcScreenRect().getCenterX() - getRect().getWidth()/2;
  366. S32 y = 0;
  367. if (!mModeActionsPanel->getVisible())
  368. {
  369. y = mModeActionsPanel->getRect().getHeight();
  370. }
  371. setOrigin(x, y);
  372. }
  373. //static
  374. void LLFloaterMove::sUpdateFlyingStatus()
  375. {
  376. LLFloaterMove *floater = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
  377. if (floater) floater->mModeControlButtonMap[MM_FLY]->setEnabled(gAgent.canFly());
  378. }
  379. void LLFloaterMove::showModeButtons(BOOL bShow)
  380. {
  381. // is called from setEnabled so can be called before postBuild(), check mModeActionsPanel agains to NULL
  382. if (NULL == mModeActionsPanel || mModeActionsPanel->getVisible() == bShow)
  383. return;
  384. mModeActionsPanel->setVisible(bShow);
  385. }
  386. //static
  387. void LLFloaterMove::enableInstance(BOOL bEnable)
  388. {
  389. LLFloaterMove* instance = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
  390. if (instance)
  391. {
  392. instance->setEnabled(bEnable);
  393. if (gAgent.getFlying())
  394. {
  395. instance->showModeButtons(FALSE);
  396. }
  397. }
  398. }
  399. void LLFloaterMove::onOpen(const LLSD& key)
  400. {
  401. LLButton *anchor_panel = LLBottomTray::getInstance()->getChild<LLButton>("movement_btn");
  402. if (gAgent.getFlying())
  403. {
  404. setFlyingMode(TRUE);
  405. showModeButtons(FALSE);
  406. }
  407. if (gAgent.getAvatarObject() && gAgent.getAvatarObject()->isSitting())
  408. {
  409. setSittingMode(TRUE);
  410. showModeButtons(FALSE);
  411. }
  412. setDockControl(new LLDockControl(
  413. anchor_panel, this,
  414. getDockTongue(), LLDockControl::TOP));
  415. sUpdateFlyingStatus();
  416. }
  417. //virtual
  418. void LLFloaterMove::setDocked(bool docked, bool pop_on_undock/* = true*/)
  419. {
  420. LLTransientDockableFloater::setDocked(docked, pop_on_undock);
  421. }
  422. void LLFloaterMove::setModeButtonToggleState(const EMovementMode mode)
  423. {
  424. llassert_always(mModeControlButtonMap.end() != mModeControlButtonMap.find(mode));
  425. mode_control_button_map_t::const_iterator it = mModeControlButtonMap.begin();
  426. for (; it != mModeControlButtonMap.end(); ++it)
  427. {
  428. it->second->setToggleState(FALSE);
  429. }
  430. mModeControlButtonMap[mode]->setToggleState(TRUE);
  431. }
  432. /************************************************************************/
  433. /*                        LLPanelStandStopFlying                        */
  434. /************************************************************************/
  435. LLPanelStandStopFlying::LLPanelStandStopFlying() :
  436. mStandButton(NULL),
  437. mStopFlyingButton(NULL),
  438. mAttached(false)
  439. {
  440. // make sure we have the only instance of this class
  441. static bool b = true;
  442. llassert_always(b);
  443. b=false;
  444. }
  445. // static
  446. inline LLPanelStandStopFlying* LLPanelStandStopFlying::getInstance()
  447. {
  448. static LLPanelStandStopFlying* panel = getStandStopFlyingPanel();
  449. return panel;
  450. }
  451. //static
  452. void LLPanelStandStopFlying::setStandStopFlyingMode(EStandStopFlyingMode mode)
  453. {
  454. LLPanelStandStopFlying* panel = getInstance();
  455. panel->mStandButton->setVisible(SSFM_STAND == mode);
  456. panel->mStopFlyingButton->setVisible(SSFM_STOP_FLYING == mode);
  457. //visibility of it should be updated after updating visibility of the buttons
  458. panel->setVisible(TRUE);
  459. }
  460. //static
  461. void LLPanelStandStopFlying::clearStandStopFlyingMode(EStandStopFlyingMode mode)
  462. {
  463. LLPanelStandStopFlying* panel = getInstance();
  464. switch(mode) {
  465. case SSFM_STAND:
  466. panel->mStandButton->setVisible(FALSE);
  467. break;
  468. case SSFM_STOP_FLYING:
  469. panel->mStopFlyingButton->setVisible(FALSE);
  470. break;
  471. default:
  472. llerrs << "Unexpected EStandStopFlyingMode is passed: " << mode << llendl;
  473. }
  474. }
  475. BOOL LLPanelStandStopFlying::postBuild()
  476. {
  477. mStandButton = getChild<LLButton>("stand_btn");
  478. mStandButton->setCommitCallback(boost::bind(&LLPanelStandStopFlying::onStandButtonClick, this));
  479. mStandButton->setCommitCallback(boost::bind(&LLFloaterMove::enableInstance, TRUE));
  480. mStandButton->setVisible(FALSE);
  481. mStopFlyingButton = getChild<LLButton>("stop_fly_btn");
  482. //mStopFlyingButton->setCommitCallback(boost::bind(&LLFloaterMove::setFlyingMode, FALSE));
  483. mStopFlyingButton->setCommitCallback(boost::bind(&LLPanelStandStopFlying::onStopFlyingButtonClick, this));
  484. mStopFlyingButton->setVisible(FALSE);
  485. return TRUE;
  486. }
  487. //virtual
  488. void LLPanelStandStopFlying::setVisible(BOOL visible)
  489. {
  490. //we dont need to show the panel if these buttons are not activated
  491. if (gAgent.getCameraMode() == CAMERA_MODE_MOUSELOOK) visible = false;
  492. if (visible)
  493. {
  494. updatePosition();
  495. }
  496. // do not change parent visibility in case panel is attached into Move Floater: EXT-3632, EXT-4646
  497. if (!mAttached) 
  498. {
  499. //change visibility of parent layout_panel to animate in/out. EXT-2504
  500. if (getParent()) getParent()->setVisible(visible);
  501. }
  502. // also change own visibility to avoid displaying the panel in mouselook (broken when EXT-2504 was implemented).
  503. // See EXT-4718.
  504. LLPanel::setVisible(visible);
  505. }
  506. BOOL LLPanelStandStopFlying::handleToolTip(S32 x, S32 y, MASK mask)
  507. {
  508. LLToolTipMgr::instance().unblockToolTips();
  509. if (mStandButton->getVisible())
  510. {
  511. LLToolTipMgr::instance().show(mStandButton->getToolTip());
  512. }
  513. else if (mStopFlyingButton->getVisible())
  514. {
  515. LLToolTipMgr::instance().show(mStopFlyingButton->getToolTip());
  516. }
  517. return LLPanel::handleToolTip(x, y, mask);
  518. }
  519. void LLPanelStandStopFlying::reparent(LLFloaterMove* move_view)
  520. {
  521. LLPanel* parent = dynamic_cast<LLPanel*>(getParent());
  522. if (!parent)
  523. {
  524. llwarns << "Stand/stop flying panel parent is unset, already attached?: " << mAttached << ", new parent: " << (move_view == NULL ? "NULL" : "Move Floater") << llendl;
  525. return;
  526. }
  527. if (move_view != NULL)
  528. {
  529. llassert(move_view != parent); // sanity check
  530. // Save our original container.
  531. if (!mOriginalParent.get())
  532. mOriginalParent = parent->getHandle();
  533. // Attach to movement controls.
  534. parent->removeChild(this);
  535. move_view->addChild(this);
  536. // Origin must be set by movement controls.
  537. mAttached = true;
  538. }
  539. else
  540. {
  541. if (!mOriginalParent.get())
  542. {
  543. llwarns << "Original parent of the stand / stop flying panel not found" << llendl;
  544. return;
  545. }
  546. // Detach from movement controls. 
  547. parent->removeChild(this);
  548. mOriginalParent.get()->addChild(this);
  549. // update parent with self visibility (it is changed in setVisible()). EXT-4743
  550. mOriginalParent.get()->setVisible(getVisible());
  551. mAttached = false;
  552. updatePosition(); // don't defer until next draw() to avoid flicker
  553. }
  554. }
  555. //////////////////////////////////////////////////////////////////////////
  556. // Private Section
  557. //////////////////////////////////////////////////////////////////////////
  558. //static
  559. LLPanelStandStopFlying* LLPanelStandStopFlying::getStandStopFlyingPanel()
  560. {
  561. LLPanelStandStopFlying* panel = new LLPanelStandStopFlying();
  562. LLUICtrlFactory::getInstance()->buildPanel(panel, "panel_stand_stop_flying.xml");
  563. panel->setVisible(FALSE);
  564. //LLUI::getRootView()->addChild(panel);
  565. llinfos << "Build LLPanelStandStopFlying panel" << llendl;
  566. panel->updatePosition();
  567. return panel;
  568. }
  569. void LLPanelStandStopFlying::onStandButtonClick()
  570. {
  571. LLSelectMgr::getInstance()->deselectAllForStandingUp();
  572. gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);
  573. setFocus(FALSE); // EXT-482
  574. }
  575. void LLPanelStandStopFlying::onStopFlyingButtonClick()
  576. {
  577. gAgent.setFlying(FALSE);
  578. setFocus(FALSE); // EXT-482
  579. setVisible(FALSE);
  580. }
  581. /**
  582.  * Updates position of the Stand & Stop Flying panel to be center aligned with Move button.
  583.  */
  584. void LLPanelStandStopFlying::updatePosition()
  585. {
  586. LLBottomTray* tray = LLBottomTray::getInstance();
  587. if (!tray || mAttached) return;
  588. LLButton* movement_btn = tray->getChild<LLButton>(BOTTOM_TRAY_BUTTON_NAME);
  589. // Align centers of the button and the panel.
  590. S32 x = movement_btn->calcScreenRect().getCenterX() - getRect().getWidth()/2;
  591. setOrigin(x, 0);
  592. }
  593. // EOF