llfloatermove.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * @file llfloatermove.cpp
  3. * @brief Container for movement buttons like forward, left, fly
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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 "llfloatermove.h"
  34. #include "llbutton.h"
  35. #include "llspinctrl.h"
  36. #include "lluictrlfactory.h"
  37. #include "llagent.h"
  38. #include "llagentwearables.h"
  39. #include "lljoystickbutton.h"
  40. #include "llviewercontrol.h"
  41. #include "llvoavatarself.h"
  42. // Constants
  43. constexpr F32 MOVE_BUTTON_DELAY = 0.f;
  44. constexpr F32 YAW_NUDGE_RATE = 0.05f; // fraction of normal speed
  45. constexpr F32 NUDGE_TIME = 0.25f; // in seconds
  46. LLFloaterMove::LLFloaterMove(const LLSD& key)
  47. : LLFloater("movement controls")
  48. {
  49. setIsChrome(true);
  50. LLUICtrlFactory::getInstance()->buildFloater(this, "floater_moveview.xml",
  51. NULL, false);
  52. mForwardButton = getChild<LLJoystickAgentTurn>("forward btn");
  53. mForwardButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  54. mBackwardButton = getChild<LLJoystickAgentTurn>("backward btn");
  55. mBackwardButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  56. mSlideLeftButton = getChild<LLJoystickAgentSlide>("slide left btn");
  57. mSlideLeftButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  58. mSlideRightButton = getChild<LLJoystickAgentSlide>("slide right btn");
  59. mSlideRightButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  60. mTurnLeftButton = getChild<LLButton>("turn left btn");
  61. mTurnLeftButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  62. mTurnLeftButton->setHeldDownCallback(turnLeft);
  63. mTurnRightButton = getChild<LLButton>("turn right btn");
  64. mTurnRightButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  65. mTurnRightButton->setHeldDownCallback(turnRight);
  66. mMoveUpButton = getChild<LLButton>("move up btn");
  67. childSetAction("move up btn",moveUp,NULL);
  68. mMoveUpButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  69. mMoveUpButton->setHeldDownCallback(moveUp);
  70. mMoveDownButton = getChild<LLButton>("move down btn");
  71. childSetAction("move down btn",moveDown,NULL);
  72. mMoveDownButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
  73. mMoveDownButton->setHeldDownCallback(moveDown);
  74. mFlyButton = getChild<LLButton>("fly btn");
  75. childSetAction("fly btn", onFlyButtonClicked, NULL);
  76. mZOffsetSpinner = getChild<LLSpinCtrl>("z_offset");
  77. mZOffsetSpinner->setToolTip(getString("z_offset_tooltip"));
  78. }
  79. //virtual
  80. void LLFloaterMove::draw()
  81. {
  82. bool sitting = isAgentAvatarValid() && gAgentAvatarp->mIsSitting;
  83. mFlyButton->setEnabled(!sitting && (gAgent.canFly() || gAgent.getFlying()));
  84. mZOffsetSpinner->setEnabled(!LLVOAvatarSelf::canUseServerBaking() ||
  85. LLVOAvatarSelf::useAvatarHoverHeight());
  86. LLFloater::draw();
  87. }
  88. //virtual
  89. void LLFloaterMove::onClose(bool app_quitting)
  90. {
  91. LLFloater::onClose(app_quitting);
  92. if (!app_quitting)
  93. {
  94. gSavedSettings.setBool("ShowMovementControls", false);
  95. }
  96. }
  97. void LLFloaterMove::onOpen()
  98. {
  99. LLFloater::onOpen();
  100. gSavedSettings.setBool("ShowMovementControls", true);
  101. }
  102. //static
  103. void LLFloaterMove::onFlyButtonClicked(void*)
  104. {
  105. gAgent.toggleFlying();
  106. }
  107. //static
  108. F32 LLFloaterMove::getYawRate(F32 time)
  109. {
  110. if (time < NUDGE_TIME)
  111. {
  112. F32 rate = YAW_NUDGE_RATE + time * (1.f - YAW_NUDGE_RATE) / NUDGE_TIME;
  113. return rate;
  114. }
  115. else
  116. {
  117. return 1.f;
  118. }
  119. }
  120. //static
  121. void LLFloaterMove::turnLeft(void*)
  122. {
  123. F32 time = getInstance()->mTurnLeftButton->getHeldDownTime();
  124. gAgent.moveYaw(getYawRate(time));
  125. }
  126. //static
  127. void LLFloaterMove::turnRight(void*)
  128. {
  129. F32 time = getInstance()->mTurnRightButton->getHeldDownTime();
  130. gAgent.moveYaw(-getYawRate(time));
  131. }
  132. //static
  133. void LLFloaterMove::moveUp(void*)
  134. {
  135. // Jumps or flys up, depending on fly state
  136. gAgent.moveUp(1);
  137. }
  138. //static
  139. void LLFloaterMove::moveDown(void*)
  140. {
  141. // Crouches or flys down, depending on fly state
  142. gAgent.moveUp(-1);
  143. }