summaryrefslogtreecommitdiff
path: root/indra/newview/llgesturemgr.h
blob: c562587c6fd75f9b6734b3815e82b3d143837f45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/** 
 * @file llgesturemgr.h
 * @brief Manager for playing gestures on the viewer
 *
 * $LicenseInfo:firstyear=2004&license=viewergpl$
 * 
 * Copyright (c) 2004-2009, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at
 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#ifndef LL_LLGESTUREMGR_H
#define LL_LLGESTUREMGR_H

#include <map>
#include <string>
#include <vector>

#include "llassetstorage.h"	// LLAssetType
#include "llinventoryobserver.h"
#include "llsingleton.h"
#include "llviewerinventory.h"

class LLMultiGesture;
class LLGestureStep;
class LLUUID;
class LLVFS;

class LLGestureManagerObserver
{
public:
	virtual ~LLGestureManagerObserver() { };
	virtual void changed() = 0;
};

class LLGestureManager : public LLSingleton<LLGestureManager>, public LLInventoryFetchObserver
{
public:

	typedef boost::function<void (LLMultiGesture* loaded_gesture)> gesture_loaded_callback_t;
	// Maps inventory item_id to gesture
	typedef std::map<LLUUID, LLMultiGesture*> item_map_t;
	typedef std::map<LLUUID, gesture_loaded_callback_t> callback_map_t;

	LLGestureManager();
	~LLGestureManager();

	void init();

	// Call once per frame to manage gestures
	void update();

	// Loads a gesture out of inventory into the in-memory active form
	// Note that the inventory item must exist, so we can look up the 
	// asset id.
	void activateGesture(const LLUUID& item_id);

	// Activate a list of gestures
	void activateGestures(LLViewerInventoryItem::item_array_t& items);

	// If you change a gesture, you need to build a new multigesture
	// and call this method.
	void replaceGesture(const LLUUID& item_id, LLMultiGesture* new_gesture, const LLUUID& asset_id);
	void replaceGesture(const LLUUID& item_id, const LLUUID& asset_id);

	// Load gesture into in-memory active form.
	// Can be called even if the inventory item isn't loaded yet.
	// inform_server TRUE will send message upstream to update database
	// user_gesture_active table, which isn't necessary on login.
	// deactivate_similar will cause other gestures with the same trigger phrase
	// or keybinding to be deactivated.
	void activateGestureWithAsset(const LLUUID& item_id, const LLUUID& asset_id, BOOL inform_server, BOOL deactivate_similar);

	// Takes gesture out of active list and deletes it.
	void deactivateGesture(const LLUUID& item_id);

	// Deactivates all gestures that match either this trigger phrase,
	// or this hot key.
	void deactivateSimilarGestures(LLMultiGesture* gesture, const LLUUID& in_item_id);

	BOOL isGestureActive(const LLUUID& item_id);

	BOOL isGesturePlaying(const LLUUID& item_id);

	BOOL isGesturePlaying(LLMultiGesture* gesture);

	const item_map_t& getActiveGestures() const { return mActive; }
	// Force a gesture to be played, for example, if it is being
	// previewed.
	void playGesture(LLMultiGesture* gesture);
	void playGesture(const LLUUID& item_id);

	// Stop all requested or playing anims for this gesture
	// Also remove from playing list
	void stopGesture(LLMultiGesture* gesture);
	void stopGesture(const LLUUID& item_id);
	/**
	 * Add cb into callbackMap.
	 * Note:
	 * Manager will call cb after gesture will be loaded and will remove cb automatically. 
	 */
	void setGestureLoadedCallback(LLUUID inv_item_id, gesture_loaded_callback_t cb)
	{
		mCallbackMap[inv_item_id] = cb;
	}
	// Trigger the first gesture that matches this key.
	// Returns TRUE if it finds a gesture bound to that key.
	BOOL triggerGesture(KEY key, MASK mask);

	// Trigger all gestures referenced as substrings in this string
	BOOL triggerAndReviseString(const std::string &str, std::string *revised_string = NULL);

	// Does some gesture have this key bound?
	BOOL isKeyBound(KEY key, MASK mask);

	S32 getPlayingCount() const;

	void addObserver(LLGestureManagerObserver* observer);
	void removeObserver(LLGestureManagerObserver* observer);
	void notifyObservers();

	BOOL matchPrefix(const std::string& in_str, std::string* out_str);

	// Copy item ids into the vector
	void getItemIDs(std::vector<LLUUID>* ids);

protected:
	// Handle the processing of a single gesture
	void stepGesture(LLMultiGesture* gesture);

	// Do a single step in a gesture
	void runStep(LLMultiGesture* gesture, LLGestureStep* step);

	// LLInventoryCompletionObserver trigger
	void done();

	// Used by loadGesture
	static void onLoadComplete(LLVFS *vfs,
						   const LLUUID& asset_uuid,
						   LLAssetType::EType type,
						   void* user_data, S32 status, LLExtStat ext_status);

private:
	// Active gestures.
	// NOTE: The gesture pointer CAN BE NULL.  This means that
	// there is a gesture with that item_id, but the asset data
	// is still on its way down from the server.
	item_map_t mActive;

	S32 mLoadingCount;
	std::string mDeactivateSimilarNames;
	
	std::vector<LLGestureManagerObserver*> mObservers;
	callback_map_t mCallbackMap;
	std::vector<LLMultiGesture*> mPlaying;	
	BOOL mValid;
};

#endif