llviewergesture.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llviewergesture.h"
00035 
00036 #include "audioengine.h"
00037 #include "lldir.h"
00038 #include "llviewerinventory.h"
00039 #include "sound_ids.h"          // for testing
00040 
00041 #include "llchatbar.h"
00042 #include "llkeyboard.h"         // for key shortcuts for testing
00043 #include "llinventorymodel.h"
00044 #include "llvoavatar.h"
00045 #include "llxfermanager.h"
00046 #include "llviewermessage.h" // send_guid_sound_trigger
00047 #include "llviewernetwork.h"
00048 #include "llagent.h"
00049 
00050 // Globals
00051 LLViewerGestureList gGestureList;
00052 
00053 const F32 LLViewerGesture::SOUND_VOLUME = 1.f;
00054 
00055 LLViewerGesture::LLViewerGesture()
00056 :       LLGesture()
00057 { }
00058 
00059 LLViewerGesture::LLViewerGesture(KEY key, MASK mask, const std::string &trigger,
00060                                                                  const LLUUID &sound_item_id, 
00061                                                                  const std::string &animation,
00062                                                                  const std::string &output_string)
00063 :       LLGesture(key, mask, trigger, sound_item_id, animation, output_string)
00064 {
00065 }
00066 
00067 LLViewerGesture::LLViewerGesture(U8 **buffer, S32 max_size)
00068 :       LLGesture(buffer, max_size)
00069 {
00070 }
00071 
00072 LLViewerGesture::LLViewerGesture(const LLViewerGesture &rhs)
00073 :       LLGesture((LLGesture)rhs)
00074 {
00075 }
00076 
00077 BOOL LLViewerGesture::trigger(KEY key, MASK mask)
00078 {
00079         if (mKey == key && mMask == mask)
00080         {
00081                 doTrigger( TRUE );
00082                 return TRUE;
00083         }
00084         else
00085         {
00086                 return FALSE;
00087         }
00088 }
00089 
00090 
00091 BOOL LLViewerGesture::trigger(const std::string &trigger_string)
00092 {
00093         // Assumes trigger_string is lowercase
00094         if (mTriggerLower == trigger_string)
00095         {
00096                 doTrigger( FALSE );
00097                 return TRUE;
00098         }
00099         else
00100         {
00101                 return FALSE;
00102         }
00103 }
00104 
00105 
00106 // private
00107 void LLViewerGesture::doTrigger( BOOL send_chat )
00108 {
00109         if (mSoundItemID != LLUUID::null)
00110         {
00111                 LLViewerInventoryItem *item;
00112                 item = gInventory.getItem(mSoundItemID);
00113                 if (item)
00114                 {
00115                         send_sound_trigger(item->getAssetUUID(), SOUND_VOLUME);
00116                 }
00117         }
00118 
00119         if (!mAnimation.empty())
00120         {
00121                 // AFK animations trigger the special "away" state, which
00122                 // includes agent control settings. JC
00123                 if (mAnimation == "enter_away_from_keyboard_state" || mAnimation == "away")
00124                 {
00125                         gAgent.setAFK();
00126                 }
00127                 else
00128                 {
00129                         LLUUID anim_id = gAnimLibrary.stringToAnimState(mAnimation.c_str());
00130                         gAgent.sendAnimationRequest(anim_id, ANIM_REQUEST_START);
00131                 }
00132         }
00133 
00134         if ( send_chat && !mOutputString.empty())
00135         {
00136                 // Don't play nodding animation, since that might not blend
00137                 // with the gesture animation.
00138                 gChatBar->sendChatFromViewer(mOutputString, CHAT_TYPE_NORMAL, FALSE);
00139         }
00140 }
00141 
00142 
00143 LLViewerGestureList::LLViewerGestureList()
00144 :       LLGestureList()
00145 {
00146         mIsLoaded = FALSE;
00147 }
00148 
00149 
00150 // helper for deserialize that creates the right LLGesture subclass
00151 LLGesture *LLViewerGestureList::create_gesture(U8 **buffer, S32 max_size)
00152 {
00153         return new LLViewerGesture(buffer, max_size);
00154 }
00155 
00156 
00157 // See if the prefix matches any gesture.  If so, return TRUE
00158 // and place the full text of the gesture trigger into
00159 // output_str
00160 BOOL LLViewerGestureList::matchPrefix(const std::string& in_str, std::string* out_str)
00161 {
00162         S32 in_len = in_str.length();
00163 
00164         LLString in_str_lc = in_str;
00165         LLString::toLower(in_str_lc);
00166 
00167         for (S32 i = 0; i < count(); i++)
00168         {
00169                 LLGesture* gesture = get(i);
00170                 const std::string &trigger = gesture->getTrigger();
00171                 
00172                 if (in_len > (S32)trigger.length())
00173                 {
00174                         // too short, bail out
00175                         continue;
00176                 }
00177 
00178                 std::string trigger_trunc = utf8str_truncate(trigger, in_len);
00179                 LLString::toLower(trigger_trunc);
00180                 if (in_str_lc == trigger_trunc)
00181                 {
00182                         *out_str = trigger;
00183                         return TRUE;
00184                 }
00185         }
00186         return FALSE;
00187 }
00188 
00189 
00190 // static
00191 void LLViewerGestureList::xferCallback(void *data, S32 size, void** /*user_data*/, S32 status)
00192 {
00193         if (LL_ERR_NOERR == status)
00194         {
00195                 U8 *buffer = (U8 *)data;
00196                 U8 *end = gGestureList.deserialize(buffer, size);
00197 
00198                 if (end - buffer > size)
00199                 {
00200                         llerrs << "Read off of end of array, error in serialization" << llendl;
00201                 }
00202 
00203                 gGestureList.mIsLoaded = TRUE;
00204         }
00205         else
00206         {
00207                 llwarns << "Unable to load gesture list!" << llendl;
00208         }
00209 }

Generated on Thu Jul 1 06:09:27 2010 for Second Life Viewer by  doxygen 1.4.7