forked from siana/SingularityViewer
-
Notifications
You must be signed in to change notification settings - Fork 62
/
rlvcommon.h
323 lines (269 loc) · 11.7 KB
/
rlvcommon.h
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/**
*
* Copyright (c) 2009-2011, Kitty Barnett
*
* The source code in this file is provided to you under the terms of the
* GNU Lesser General Public License, version 2.1, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. Terms of the LGPL can be found in doc/LGPL-licence.txt
* in this distribution, or online at http://www.gnu.org/licenses/lgpl-2.1.txt
*
* 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.
*
*/
#ifndef RLV_COMMON_H
#define RLV_COMMON_H
#include "llavatarname.h"
#include "llselectmgr.h"
#include "llviewercontrol.h"
#include "llmemberlistener.h"
#include "rlvdefines.h"
#ifdef LL_WINDOWS
#pragma warning (push)
#pragma warning (disable : 4702) // warning C4702: unreachable code
#endif
#include <boost/variant.hpp>
#ifdef LL_WINDOWS
#pragma warning (pop)
#endif
using namespace LLOldEvents;
// ============================================================================
// Forward declarations
//
//
// General viewer source
//
class LLInventoryItem;
class LLViewerInventoryCategory;
class LLViewerInventoryItem;
class LLViewerJointAttachment;
class LLViewerWearable;
class LLWearable;
//
// RLVa-specific
//
class RlvCommand;
typedef std::list<RlvCommand> rlv_command_list_t;
class RlvObject;
struct RlvException;
typedef boost::variant<std::string, LLUUID, S32, F32, LLColor3, ERlvBehaviour> RlvExceptionOption;
class RlvGCTimer;
// ============================================================================
// RlvSettings
//
template<typename T> inline T rlvGetSetting(const std::string& strSetting, const T& defaultValue)
{
RLV_ASSERT_DBG(gSavedSettings.controlExists(strSetting));
return (gSavedSettings.controlExists(strSetting)) ? gSavedSettings.get<T>(strSetting) : defaultValue;
}
template<typename T> inline T rlvGetPerUserSetting(const std::string& strSetting, const T& defaultValue)
{
RLV_ASSERT_DBG(gSavedPerAccountSettings.controlExists(strSetting));
return (gSavedPerAccountSettings.controlExists(strSetting)) ? gSavedPerAccountSettings.get<T>(strSetting) : defaultValue;
}
class RlvSettings
{
public:
static bool getDebug() { return rlvGetSetting<bool>(RLV_SETTING_DEBUG, false); }
static bool getCanOOC() { return fCanOOC; }
static bool getForbidGiveToRLV() { return rlvGetSetting<bool>(RLV_SETTING_FORBIDGIVETORLV, true); }
static bool getNoSetEnv() { return fNoSetEnv; }
static std::string getWearAddPrefix() { return rlvGetSetting<std::string>(RLV_SETTING_WEARADDPREFIX, LLStringUtil::null); }
static std::string getWearReplacePrefix() { return rlvGetSetting<std::string>(RLV_SETTING_WEARREPLACEPREFIX, LLStringUtil::null); }
static bool getDebugHideUnsetDup() { return rlvGetSetting<bool>(RLV_SETTING_DEBUGHIDEUNSETDUP, false); }
#ifdef RLV_EXPERIMENTAL_COMPOSITEFOLDERS
static BOOL getEnableComposites() { return fCompositeFolders; }
#endif // RLV_EXPERIMENTAL_COMPOSITEFOLDERS
static bool getEnableLegacyNaming() { return fLegacyNaming; }
static bool getEnableSharedWear() { return rlvGetSetting<bool>(RLV_SETTING_ENABLESHAREDWEAR, false); }
static bool getHideLockedLayers() { return rlvGetSetting<bool>(RLV_SETTING_HIDELOCKEDLAYER, false); }
static bool getHideLockedAttach() { return rlvGetSetting<bool>(RLV_SETTING_HIDELOCKEDATTACH, false); }
static bool getHideLockedInventory() { return rlvGetSetting<bool>(RLV_SETTING_HIDELOCKEDINVENTORY, false); }
static bool getSharedInvAutoRename() { return rlvGetSetting<bool>(RLV_SETTING_SHAREDINVAUTORENAME, true); }
static bool getShowNameTags() { return fShowNameTags; }
#ifdef RLV_EXTENSION_STARTLOCATION
static bool getLoginLastLocation() { return rlvGetPerUserSetting<bool>(RLV_SETTING_LOGINLASTLOCATION, true); }
static void updateLoginLastLocation();
#endif // RLV_EXTENSION_STARTLOCATION
static void initClass();
protected:
static bool onChangedAvatarOffset(const LLSD& sdValue);
static bool onChangedMenuLevel();
static bool onChangedSettingBOOL(const LLSD& sdValue, bool* pfSetting);
#ifdef RLV_EXPERIMENTAL_COMPOSITEFOLDERS
static BOOL fCompositeFolders;
#endif // RLV_EXPERIMENTAL_COMPOSITEFOLDERS
static bool fCanOOC;
static bool fLegacyNaming;
static bool fNoSetEnv;
static bool fShowNameTags;
};
// ============================================================================
// RlvStrings
//
class RlvStrings
{
public:
static void initClass();
static void loadFromFile(const std::string& strFilePath, bool fDefault);
static void saveToFile(const std::string& strFilePath);
static const std::string& getAnonym(const LLAvatarName& avName); // @shownames
static const std::string& getAnonym(const std::string& strName); // @shownames
static const std::string& getString(const std::string& strStringName);
static const char* getStringFromReturnCode(ERlvCmdRet eRet);
static const std::string& getStringMapPath() { return m_StringMapPath; }
static std::string getVersion(bool fLegacy = false); // @version
static std::string getVersionAbout(); // Shown in Help / About
static std::string getVersionNum(); // @versionnum
static bool hasString(const std::string& strStringName, bool fCheckCustom = false);
static void setCustomString(const std::string& strStringName, const std::string& strStringValue);
protected:
static std::vector<std::string> m_Anonyms;
typedef std::map<std::string, std::list<std::string> > string_map_t;
static string_map_t m_StringMap;
static std::string m_StringMapPath;
};
// ============================================================================
// RlvUtil - Collection of (static) helper functions
//
class RlvUtil
{
public:
static bool isEmote(const std::string& strUTF8Text);
static bool isNearbyAgent(const LLUUID& idAgent); // @shownames
static bool isNearbyRegion(const std::string& strRegion); // @showloc
static void filterLocation(std::string& strUTF8Text); // @showloc
static void filterNames(std::string& strUTF8Text, bool fFilterLegacy = true); // @shownames
static void filterScriptQuestions(S32& nQuestions, LLSD& sdPayload);
static bool isForceTp() { return m_fForceTp; }
static void forceTp(const LLVector3d& posDest); // Ignores restrictions that might otherwise prevent tp'ing
static void notifyBlocked(const std::string& strNotifcation, const LLSD& sdArgs = LLSD());
static void notifyBlockedGeneric() { notifyBlocked(RLV_STRING_BLOCKED_GENERIC); }
static void notifyBlockedViewXXX(LLAssetType::EType assetType) { notifyBlocked(RLV_STRING_BLOCKED_VIEWXXX, LLSD().with("[TYPE]", LLAssetType::lookup(assetType))); }
static void notifyFailedAssertion(const std::string& strAssert, const std::string& strFile, int nLine);
static void sendBusyMessage(const LLUUID& idTo, const std::string& strMsg, const LLUUID& idSession = LLUUID::null);
static bool isValidReplyChannel(S32 nChannel);
static bool sendChatReply(S32 nChannel, const std::string& strUTF8Text);
static bool sendChatReply(const std::string& strChannel, const std::string& strUTF8Text);
protected:
static bool m_fForceTp; // @standtp
};
// ============================================================================
// Extensibility classes
//
class RlvCommandHandler
{
public:
virtual ~RlvCommandHandler() {}
virtual bool onAddRemCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet) { return false; }
virtual bool onClearCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet) { return false; }
virtual bool onReplyCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet) { return false; }
virtual bool onForceCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet) { return false; }
};
typedef bool (RlvCommandHandler::*rlvCommandHandler)(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet);
// ============================================================================
// Generic menu enablers
//
BOOL rlvMenuCheckEnabled(void*);
void rlvMenuToggleEnabled(void*);
void rlvMenuToggleVisible();
//bool rlvMenuEnableIfNot(const LLSD& sdParam);
class RlvEnableIfNot : public LLMemberListener<LLView>
{
bool handleEvent(LLPointer<LLEvent>, const LLSD&);
};
// ============================================================================
// Selection functors
//
bool rlvCanDeleteOrReturn();
bool rlvCanDeleteOrReturn(const LLViewerObject* pObj);
struct RlvSelectHasLockedAttach : public LLSelectedNodeFunctor
{
RlvSelectHasLockedAttach() {}
virtual bool apply(LLSelectNode* pNode);
};
// Filters out selected objects that can't be editable (i.e. getFirstNode() will return NULL if the selection is fully editable)
struct RlvSelectIsEditable : public LLSelectedNodeFunctor
{
RlvSelectIsEditable() {}
/*virtual*/ bool apply(LLSelectNode* pNode);
};
struct RlvSelectIsSittingOn : public LLSelectedNodeFunctor
{
RlvSelectIsSittingOn(const LLVOAvatar* pAvatar) : m_pAvatar(pAvatar) {}
/*virtual*/ bool apply(LLSelectNode* pNode);
protected:
const LLVOAvatar* m_pAvatar;
};
// ============================================================================
// Predicates
//
bool rlvPredCanWearItem(const LLViewerInventoryItem* pItem, ERlvWearMask eWearMask);
bool rlvPredCanNotWearItem(const LLViewerInventoryItem* pItem, ERlvWearMask eWearMask);
bool rlvPredCanRemoveItem(const LLViewerInventoryItem* pItem);
bool rlvPredCanNotRemoveItem(const LLViewerInventoryItem* pItem);
struct RlvPredCanWearItem
{
RlvPredCanWearItem(ERlvWearMask eWearMask) : m_eWearMask(eWearMask) {}
bool operator()(const LLViewerInventoryItem* pItem) { return rlvPredCanWearItem(pItem, m_eWearMask); }
protected:
ERlvWearMask m_eWearMask;
};
struct RlvPredCanNotWearItem
{
RlvPredCanNotWearItem(ERlvWearMask eWearMask) : m_eWearMask(eWearMask) {}
bool operator()(const LLViewerInventoryItem* pItem) { return rlvPredCanNotWearItem(pItem, m_eWearMask); }
protected:
ERlvWearMask m_eWearMask;
};
struct RlvPredCanRemoveItem
{
RlvPredCanRemoveItem() {}
bool operator()(const LLViewerInventoryItem* pItem) { return rlvPredCanRemoveItem(pItem); }
};
struct RlvPredCanNotRemoveItem
{
RlvPredCanNotRemoveItem() {}
bool operator()(const LLViewerInventoryItem* pItem) { return rlvPredCanNotRemoveItem(pItem); }
};
struct RlvPredIsEqualOrLinkedItem
{
RlvPredIsEqualOrLinkedItem(const LLViewerInventoryItem* pItem) : m_pItem(pItem) {}
RlvPredIsEqualOrLinkedItem(const LLUUID& idItem);
bool operator()(const LLViewerInventoryItem* pItem) const;
protected:
const LLViewerInventoryItem* m_pItem;
};
template<typename T> struct RlvPredValuesEqual
{
bool operator()(const T* pT2) const { return (pT1) && (pT2) && (*pT1 == *pT2); }
const T* pT1;
};
// ============================================================================
// Inlined class member functions
//
// Checked: 2010-10-31 (RLVa-1.2.2a) | Added: RLVa-1.2.2a
inline const std::string& RlvStrings::getAnonym(const LLAvatarName& avName)
{
return getAnonym(avName.getDisplayName());
}
// Checked: 2010-03-26 (RLVa-1.2.0b) | Modified: RLVa-1.0.2a
inline bool RlvUtil::isEmote(const std::string& strUTF8Text)
{
return (strUTF8Text.length() > 4) && ( (strUTF8Text.compare(0, 4, "/me ") == 0) || (strUTF8Text.compare(0, 4, "/me'") == 0) );
}
// Checked: 2010-03-09 (RLVa-1.2.0b) | Added: RLVa-1.0.2a
inline bool RlvUtil::isValidReplyChannel(S32 nChannel)
{
return (nChannel > 0) && (CHAT_CHANNEL_DEBUG != nChannel);
}
// Checked: 2009-08-05 (RLVa-1.0.1e) | Added: RLVa-1.0.0e
inline bool RlvUtil::sendChatReply(const std::string& strChannel, const std::string& strUTF8Text)
{
S32 nChannel;
return (LLStringUtil::convertToS32(strChannel, nChannel)) ? sendChatReply(nChannel, strUTF8Text) : false;
}
// ============================================================================
#endif // RLV_COMMON_H