llviewergesture.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. * @file llviewergesture.cpp
  3. * @brief LLViewerGesture class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-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 "llviewergesture.h"
  34. #include "llanimationstates.h"
  35. #include "llaudioengine.h"
  36. #include "lldir.h"
  37. #include "sound_ids.h" // For testing
  38. #include "llagent.h"
  39. #include "llchatbar.h"
  40. #include "llkeyboard.h" // For key shortcuts for testing
  41. #include "llgridmanager.h"
  42. #include "llinventorymodel.h"
  43. //MK
  44. #include "mkrlinterface.h"
  45. //mk
  46. #include "llviewerinventory.h"
  47. #include "llviewermessage.h" // For send_sound_trigger()
  48. #include "llvoavatar.h"
  49. #include "llxfermanager.h"
  50. // Globals
  51. LLViewerGestureList gGestureList;
  52. constexpr F32 SOUND_VOLUME = 1.f;
  53. LLViewerGesture::LLViewerGesture()
  54. : LLGesture()
  55. {
  56. }
  57. LLViewerGesture::LLViewerGesture(KEY key, MASK mask, const std::string& trigger,
  58. const LLUUID& sound_item_id,
  59. const std::string &animation,
  60. const std::string &output_string)
  61. : LLGesture(key, mask, trigger, sound_item_id, animation, output_string)
  62. {
  63. }
  64. LLViewerGesture::LLViewerGesture(U8** buffer, S32 max_size)
  65. : LLGesture(buffer, max_size)
  66. {
  67. }
  68. LLViewerGesture::LLViewerGesture(const LLViewerGesture& rhs)
  69. : LLGesture((LLGesture)rhs)
  70. {
  71. }
  72. bool LLViewerGesture::trigger(KEY key, MASK mask)
  73. {
  74. if (mKey == key && mMask == mask)
  75. {
  76. doTrigger(true);
  77. return true;
  78. }
  79. return false;
  80. }
  81. bool LLViewerGesture::trigger(const std::string& trigger_string)
  82. {
  83. // Assumes trigger_string is lowercase
  84. if (mTriggerLower == trigger_string)
  85. {
  86. doTrigger(false);
  87. return true;
  88. }
  89. return false;
  90. }
  91. void LLViewerGesture::doTrigger(bool send_chat)
  92. {
  93. if (mSoundItemID.notNull())
  94. {
  95. LLViewerInventoryItem* item;
  96. item = gInventory.getItem(mSoundItemID);
  97. if (item)
  98. {
  99. send_sound_trigger(item->getAssetUUID(), SOUND_VOLUME);
  100. }
  101. }
  102. if (!mAnimation.empty())
  103. {
  104. // AFK animations trigger the special "away" state, which
  105. // includes agent control settings. JC
  106. if (mAnimation == "enter_away_from_keyboard_state" || mAnimation == "away")
  107. {
  108. gAgent.setAFK();
  109. }
  110. else
  111. {
  112. LLUUID anim_id = gAnimLibrary.stringToAnimState(mAnimation);
  113. gAgent.sendAnimationRequest(anim_id, ANIM_REQUEST_START);
  114. }
  115. }
  116. if (send_chat && !mOutputString.empty())
  117. {
  118. // Don't play nodding animation, since that might not blend
  119. // with the gesture animation.
  120. //MK
  121. if (!gRLenabled || !gRLInterface.contains("sendchat"))
  122. {
  123. //mk
  124. if (gChatBarp)
  125. {
  126. gChatBarp->sendChatFromViewer(mOutputString, CHAT_TYPE_NORMAL,
  127. false);
  128. }
  129. //MK
  130. }
  131. //mk
  132. }
  133. }
  134. LLViewerGestureList::LLViewerGestureList()
  135. : LLGestureList()
  136. {
  137. }
  138. // helper for deserialize that creates the right LLGesture subclass
  139. LLGesture* LLViewerGestureList::create_gesture(U8** buffer, S32 max_size)
  140. {
  141. return new LLViewerGesture(buffer, max_size);
  142. }
  143. // Sees if the prefix matches any gesture. If so, returns true and place the
  144. // full text of the gesture trigger into output_str
  145. bool LLViewerGestureList::matchPrefix(const std::string& in_str,
  146. std::string* out_str)
  147. {
  148. S32 in_len = in_str.length();
  149. std::string in_str_lc = in_str;
  150. LLStringUtil::toLower(in_str_lc);
  151. for (S32 i = 0; i < count(); ++i)
  152. {
  153. LLGesture* gesture = get(i);
  154. const std::string &trigger = gesture->getTrigger();
  155. if (in_len > (S32)trigger.length())
  156. {
  157. // too short, bail out
  158. continue;
  159. }
  160. std::string trigger_trunc = utf8str_truncate(trigger, in_len);
  161. LLStringUtil::toLower(trigger_trunc);
  162. if (in_str_lc == trigger_trunc)
  163. {
  164. *out_str = trigger;
  165. return true;
  166. }
  167. }
  168. return false;
  169. }
  170. // static
  171. void LLViewerGestureList::xferCallback(void* data, S32 size, void**,
  172. S32 status)
  173. {
  174. if (status == LL_ERR_NOERR)
  175. {
  176. U8* buffer = (U8*)data;
  177. U8* end = gGestureList.deserialize(buffer, size);
  178. if (end - buffer > size)
  179. {
  180. llerrs << "Read off of end of array, error in serialization"
  181. << llendl;
  182. }
  183. }
  184. else
  185. {
  186. llwarns << "Unable to load gesture list !" << llendl;
  187. }
  188. }