PageRenderTime 154ms CodeModel.GetById 49ms app.highlight 50ms RepoModel.GetById 20ms app.codeStats 21ms

/indra/newview/llviewergesture.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 204 lines | 135 code | 31 blank | 38 comment | 23 complexity | 74950b2cd28c70cffafa8f382c6d491a MD5 | raw file
  1/** 
  2 * @file llviewergesture.cpp
  3 * @brief LLViewerGesture class implementation
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llviewergesture.h"
 30
 31#include "llaudioengine.h"
 32#include "lldir.h"
 33#include "llviewerinventory.h"
 34#include "sound_ids.h"		// for testing
 35
 36#include "llkeyboard.h"		// for key shortcuts for testing
 37#include "llinventorymodel.h"
 38#include "llvoavatar.h"
 39#include "llxfermanager.h"
 40#include "llviewermessage.h" // send_guid_sound_trigger
 41#include "llviewernetwork.h"
 42#include "llagent.h"
 43#include "llnearbychatbar.h"
 44
 45// Globals
 46LLViewerGestureList gGestureList;
 47
 48const F32 LLViewerGesture::SOUND_VOLUME = 1.f;
 49
 50LLViewerGesture::LLViewerGesture()
 51:	LLGesture()
 52{ }
 53
 54LLViewerGesture::LLViewerGesture(KEY key, MASK mask, const std::string &trigger,
 55								 const LLUUID &sound_item_id, 
 56								 const std::string &animation,
 57								 const std::string &output_string)
 58:	LLGesture(key, mask, trigger, sound_item_id, animation, output_string)
 59{
 60}
 61
 62LLViewerGesture::LLViewerGesture(U8 **buffer, S32 max_size)
 63:	LLGesture(buffer, max_size)
 64{
 65}
 66
 67LLViewerGesture::LLViewerGesture(const LLViewerGesture &rhs)
 68:	LLGesture((LLGesture)rhs)
 69{
 70}
 71
 72BOOL LLViewerGesture::trigger(KEY key, MASK mask)
 73{
 74	if (mKey == key && mMask == mask)
 75	{
 76		doTrigger( TRUE );
 77		return TRUE;
 78	}
 79	else
 80	{
 81		return FALSE;
 82	}
 83}
 84
 85
 86BOOL LLViewerGesture::trigger(const std::string &trigger_string)
 87{
 88	// Assumes trigger_string is lowercase
 89	if (mTriggerLower == trigger_string)
 90	{
 91		doTrigger( FALSE );
 92		return TRUE;
 93	}
 94	else
 95	{
 96		return FALSE;
 97	}
 98}
 99
100
101// private
102void LLViewerGesture::doTrigger( BOOL send_chat )
103{
104	if (mSoundItemID != LLUUID::null)
105	{
106		LLViewerInventoryItem *item;
107		item = gInventory.getItem(mSoundItemID);
108		if (item)
109		{
110			send_sound_trigger(item->getAssetUUID(), SOUND_VOLUME);
111		}
112	}
113
114	if (!mAnimation.empty())
115	{
116		// AFK animations trigger the special "away" state, which
117		// includes agent control settings. JC
118		if (mAnimation == "enter_away_from_keyboard_state" || mAnimation == "away")
119		{
120			gAgent.setAFK();
121		}
122		else
123		{
124			LLUUID anim_id = gAnimLibrary.stringToAnimState(mAnimation);
125			gAgent.sendAnimationRequest(anim_id, ANIM_REQUEST_START);
126		}
127	}
128
129	if (send_chat && !mOutputString.empty())
130	{
131		// Don't play nodding animation, since that might not blend
132		// with the gesture animation.
133		LLNearbyChatBar::getInstance()->sendChatFromViewer(mOutputString, CHAT_TYPE_NORMAL, FALSE);
134	}
135}
136
137
138LLViewerGestureList::LLViewerGestureList()
139:	LLGestureList()
140{
141	mIsLoaded = FALSE;
142}
143
144
145// helper for deserialize that creates the right LLGesture subclass
146LLGesture *LLViewerGestureList::create_gesture(U8 **buffer, S32 max_size)
147{
148	return new LLViewerGesture(buffer, max_size);
149}
150
151
152// See if the prefix matches any gesture.  If so, return TRUE
153// and place the full text of the gesture trigger into
154// output_str
155BOOL LLViewerGestureList::matchPrefix(const std::string& in_str, std::string* out_str)
156{
157	S32 in_len = in_str.length();
158
159	std::string in_str_lc = in_str;
160	LLStringUtil::toLower(in_str_lc);
161
162	for (S32 i = 0; i < count(); i++)
163	{
164		LLGesture* gesture = get(i);
165		const std::string &trigger = gesture->getTrigger();
166		
167		if (in_len > (S32)trigger.length())
168		{
169			// too short, bail out
170			continue;
171		}
172
173		std::string trigger_trunc = utf8str_truncate(trigger, in_len);
174		LLStringUtil::toLower(trigger_trunc);
175		if (in_str_lc == trigger_trunc)
176		{
177			*out_str = trigger;
178			return TRUE;
179		}
180	}
181	return FALSE;
182}
183
184
185// static
186void LLViewerGestureList::xferCallback(void *data, S32 size, void** /*user_data*/, S32 status)
187{
188	if (LL_ERR_NOERR == status)
189	{
190		U8 *buffer = (U8 *)data;
191		U8 *end = gGestureList.deserialize(buffer, size);
192
193		if (end - buffer > size)
194		{
195			llerrs << "Read off of end of array, error in serialization" << llendl;
196		}
197
198		gGestureList.mIsLoaded = TRUE;
199	}
200	else
201	{
202		llwarns << "Unable to load gesture list!" << llendl;
203	}
204}