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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
|
/**
* @file llfloaterpathfindingcharacters.cpp
* @author William Todd Stinson
* @brief "Pathfinding linksets" floater, allowing manipulation of the Havok AI pathfinding settings.
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llfloater.h"
#include "llfloaterpathfindingcharacters.h"
#include "llpathfindingcharacter.h"
#include "llsd.h"
#include "llagent.h"
#include "llhandle.h"
#include "llfloaterreg.h"
#include "lltextbase.h"
#include "llscrolllistitem.h"
#include "llscrolllistctrl.h"
#include "llcheckboxctrl.h"
#include "llradiogroup.h"
#include "llbutton.h"
#include "llresmgr.h"
#include "llviewerregion.h"
#include "llhttpclient.h"
#include "lluuid.h"
//---------------------------------------------------------------------------
// CharactersGetResponder
//---------------------------------------------------------------------------
class CharactersGetResponder : public LLHTTPClient::Responder
{
public:
CharactersGetResponder(const std::string& pCharactersDataGetURL,
const LLHandle<LLFloaterPathfindingCharacters> &pCharactersFloaterHandle);
virtual ~CharactersGetResponder();
virtual void result(const LLSD& pContent);
virtual void error(U32 pStatus, const std::string& pReason);
private:
CharactersGetResponder(const CharactersGetResponder& pOther);
std::string mCharactersDataGetURL;
LLHandle<LLFloaterPathfindingCharacters> mCharactersFloaterHandle;
};
//---------------------------------------------------------------------------
// LLFloaterPathfindingCharacters
//---------------------------------------------------------------------------
BOOL LLFloaterPathfindingCharacters::postBuild()
{
childSetAction("refresh_characters_list", boost::bind(&LLFloaterPathfindingCharacters::onRefreshCharactersClicked, this));
childSetAction("select_all_characters", boost::bind(&LLFloaterPathfindingCharacters::onSelectAllCharactersClicked, this));
childSetAction("select_none_characters", boost::bind(&LLFloaterPathfindingCharacters::onSelectNoneCharactersClicked, this));
mCharactersScrollList = findChild<LLScrollListCtrl>("pathfinding_characters");
llassert(mCharactersScrollList != NULL);
mCharactersScrollList->setCommitCallback(boost::bind(&LLFloaterPathfindingCharacters::onCharactersSelectionChange, this));
mCharactersScrollList->setCommitOnSelectionChange(true);
mCharactersScrollList->sortByColumnIndex(0, true);
mCharactersStatus = findChild<LLTextBase>("characters_status");
llassert(mCharactersStatus != NULL);
mLabelActions = findChild<LLTextBase>("actions_label");
llassert(mLabelActions != NULL);
mShowBeaconCheckBox = findChild<LLCheckBoxCtrl>("show_beacon");
llassert(mShowBeaconCheckBox != NULL);
mShowBeaconCheckBox->setCommitCallback(boost::bind(&LLFloaterPathfindingCharacters::onShowBeaconToggled, this));
mTakeBtn = findChild<LLButton>("take_characters");
llassert(mTakeBtn != NULL)
mTakeBtn->setCommitCallback(boost::bind(&LLFloaterPathfindingCharacters::onTakeCharactersClicked, this));
mTakeCopyBtn = findChild<LLButton>("take_copy_characters");
llassert(mTakeCopyBtn != NULL)
mTakeCopyBtn->setCommitCallback(boost::bind(&LLFloaterPathfindingCharacters::onTakeCopyCharactersClicked, this));
mReturnBtn = findChild<LLButton>("return_characters");
llassert(mReturnBtn != NULL)
mReturnBtn->setCommitCallback(boost::bind(&LLFloaterPathfindingCharacters::onReturnCharactersClicked, this));
mDeleteBtn = findChild<LLButton>("delete_characters");
llassert(mDeleteBtn != NULL)
mDeleteBtn->setCommitCallback(boost::bind(&LLFloaterPathfindingCharacters::onDeleteCharactersClicked, this));
mTeleportBtn = findChild<LLButton>("teleport_to_character");
llassert(mTeleportBtn != NULL)
mTeleportBtn->setCommitCallback(boost::bind(&LLFloaterPathfindingCharacters::onTeleportCharacterToMeClicked, this));
setEnableActionFields(false);
setMessagingState(kMessagingInitial);
return LLFloater::postBuild();
}
void LLFloaterPathfindingCharacters::onOpen(const LLSD& pKey)
{
sendCharactersDataGetRequest();
}
LLFloaterPathfindingCharacters::EMessagingState LLFloaterPathfindingCharacters::getMessagingState() const
{
return mMessagingState;
}
BOOL LLFloaterPathfindingCharacters::isMessagingInProgress() const
{
BOOL retVal;
switch (getMessagingState())
{
case kMessagingFetchStarting :
case kMessagingFetchRequestSent :
case kMessagingFetchRequestSent_MultiRequested :
case kMessagingFetchReceived :
retVal = true;
break;
default :
retVal = false;
break;
}
return retVal;
}
LLFloaterPathfindingCharacters::LLFloaterPathfindingCharacters(const LLSD& pSeed)
: LLFloater(pSeed),
mSelfHandle(),
mPathfindingCharacters(),
mMessagingState(kMessagingInitial),
mCharactersScrollList(NULL),
mCharactersStatus(NULL),
mLabelActions(NULL),
mShowBeaconCheckBox(NULL),
mTakeBtn(NULL),
mTakeCopyBtn(NULL),
mReturnBtn(NULL),
mDeleteBtn(NULL),
mTeleportBtn(NULL)
{
mSelfHandle.bind(this);
}
LLFloaterPathfindingCharacters::~LLFloaterPathfindingCharacters()
{
mPathfindingCharacters.clear();
}
void LLFloaterPathfindingCharacters::sendCharactersDataGetRequest()
{
if (isMessagingInProgress())
{
if (getMessagingState() == kMessagingFetchRequestSent)
{
setMessagingState(kMessagingFetchRequestSent_MultiRequested);
}
}
else
{
setMessagingState(kMessagingFetchStarting);
mPathfindingCharacters.clear();
updateCharactersList();
std::string charactersDataURL = getCapabilityURL();
if (charactersDataURL.empty())
{
setMessagingState(kMessagingServiceNotAvailable);
llwarns << "cannot query pathfinding characters from current region '" << getRegionName() << "'" << llendl;
}
else
{
setMessagingState(kMessagingFetchRequestSent);
LLHTTPClient::get(charactersDataURL, new CharactersGetResponder(charactersDataURL, mSelfHandle));
}
}
}
void LLFloaterPathfindingCharacters::handleCharactersDataGetReply(const LLSD& pCharactersData)
{
setMessagingState(kMessagingFetchReceived);
mPathfindingCharacters.clear();
parseCharactersData(pCharactersData);
updateCharactersList();
setMessagingState(kMessagingComplete);
}
void LLFloaterPathfindingCharacters::handleCharactersDataGetError(const std::string& pURL, const std::string& pErrorReason)
{
setMessagingState(kMessagingFetchError);
mPathfindingCharacters.clear();
updateCharactersList();
llwarns << "Error fetching pathfinding characters from URL '" << pURL << "' because " << pErrorReason << llendl;
}
std::string LLFloaterPathfindingCharacters::getRegionName() const
{
std::string regionName("");
LLViewerRegion* region = gAgent.getRegion();
if (region != NULL)
{
regionName = region->getName();
}
return regionName;
}
std::string LLFloaterPathfindingCharacters::getCapabilityURL() const
{
std::string charactersDataURL("");
LLViewerRegion* region = gAgent.getRegion();
if (region != NULL)
{
charactersDataURL = region->getCapability("CharacterProperties");
}
return charactersDataURL;
}
void LLFloaterPathfindingCharacters::parseCharactersData(const LLSD &pCharactersData)
{
for (LLSD::map_const_iterator characterItemIter = pCharactersData.beginMap();
characterItemIter != pCharactersData.endMap(); ++characterItemIter)
{
const std::string &uuid(characterItemIter->first);
const LLSD &characterData(characterItemIter->second);
LLPathfindingCharacter character(uuid, characterData);
mPathfindingCharacters.insert(std::pair<std::string, LLPathfindingCharacter>(uuid, character));
}
}
void LLFloaterPathfindingCharacters::setMessagingState(EMessagingState pMessagingState)
{
mMessagingState = pMessagingState;
updateCharactersList();
updateActionFields();
}
void LLFloaterPathfindingCharacters::onCharactersSelectionChange()
{
updateCharactersStatusMessage();
updateActionFields();
}
void LLFloaterPathfindingCharacters::onRefreshCharactersClicked()
{
sendCharactersDataGetRequest();
}
void LLFloaterPathfindingCharacters::onSelectAllCharactersClicked()
{
selectAllCharacters();
}
void LLFloaterPathfindingCharacters::onSelectNoneCharactersClicked()
{
selectNoneCharacters();
}
void LLFloaterPathfindingCharacters::onShowBeaconToggled()
{
llwarns << "functionality has not yet been implemented to toggle show beacon" << llendl;
}
void LLFloaterPathfindingCharacters::onTakeCharactersClicked()
{
llwarns << "functionality has not yet been implemented to take characters" << llendl;
}
void LLFloaterPathfindingCharacters::onTakeCopyCharactersClicked()
{
llwarns << "functionality has not yet been implemented to take a copy of characters" << llendl;
}
void LLFloaterPathfindingCharacters::onReturnCharactersClicked()
{
llwarns << "functionality has not yet been implemented to return characters" << llendl;
}
void LLFloaterPathfindingCharacters::onDeleteCharactersClicked()
{
llwarns << "functionality has not yet been implemented to delete characters" << llendl;
}
void LLFloaterPathfindingCharacters::onTeleportCharacterToMeClicked()
{
llwarns << "functionality has not yet been implemented to teleport me tothe character" << llendl;
}
void LLFloaterPathfindingCharacters::updateCharactersList()
{
std::vector<LLScrollListItem*> selectedItems = mCharactersScrollList->getAllSelected();
int numSelectedItems = selectedItems.size();
uuid_vec_t selectedUUIDs;
if (numSelectedItems > 0)
{
selectedUUIDs.reserve(selectedItems.size());
for (std::vector<LLScrollListItem*>::const_iterator itemIter = selectedItems.begin();
itemIter != selectedItems.end(); ++itemIter)
{
const LLScrollListItem *listItem = *itemIter;
selectedUUIDs.push_back(listItem->getUUID());
}
}
mCharactersScrollList->deleteAllItems();
updateCharactersStatusMessage();
for (PathfindingCharacterMap::const_iterator characterIter = mPathfindingCharacters.begin();
characterIter != mPathfindingCharacters.end(); ++characterIter)
{
const LLPathfindingCharacter& character(characterIter->second);
LLSD columns;
columns[0]["column"] = "name";
columns[0]["value"] = character.getName();
columns[0]["font"] = "SANSSERIF";
columns[1]["column"] = "description";
columns[1]["value"] = character.getDescription();
columns[1]["font"] = "SANSSERIF";
columns[2]["column"] = "owner";
columns[2]["value"] = character.getOwner();
columns[2]["font"] = "SANSSERIF";
columns[3]["column"] = "cpu_time";
columns[3]["value"] = llformat("%3d ms", character.getCPUTime());
columns[3]["font"] = "SANSSERIF";
columns[4]["column"] = "altitude";
columns[4]["value"] = llformat("%1.0f m", character.getLocation()[2]);
columns[4]["font"] = "SANSSERIF";
LLSD element;
element["id"] = character.getUUID().asString();
element["column"] = columns;
mCharactersScrollList->addElement(element);
}
mCharactersScrollList->selectMultiple(selectedUUIDs);
updateCharactersStatusMessage();
updateActionFields();
}
void LLFloaterPathfindingCharacters::selectAllCharacters()
{
mCharactersScrollList->selectAll();
}
void LLFloaterPathfindingCharacters::selectNoneCharacters()
{
mCharactersScrollList->deselectAllItems();
}
void LLFloaterPathfindingCharacters::updateCharactersStatusMessage()
{
static const LLColor4 warningColor = LLUIColorTable::instance().getColor("DrYellow");
std::string statusText("");
LLStyle::Params styleParams;
switch (getMessagingState())
{
case kMessagingInitial:
statusText = getString("characters_messaging_initial");
break;
case kMessagingFetchStarting :
statusText = getString("characters_messaging_fetch_starting");
break;
case kMessagingFetchRequestSent :
statusText = getString("characters_messaging_fetch_inprogress");
break;
case kMessagingFetchRequestSent_MultiRequested :
statusText = getString("characters_messaging_fetch_inprogress_multi_request");
break;
case kMessagingFetchReceived :
statusText = getString("characters_messaging_fetch_received");
break;
case kMessagingFetchError :
statusText = getString("characters_messaging_fetch_error");
styleParams.color = warningColor;
break;
case kMessagingComplete :
if (mCharactersScrollList->isEmpty())
{
statusText = getString("characters_messaging_complete_none_found");
}
else
{
S32 numItems = mCharactersScrollList->getItemCount();
S32 numSelectedItems = mCharactersScrollList->getNumSelected();
LLLocale locale(LLStringUtil::getLocale());
std::string numItemsString;
LLResMgr::getInstance()->getIntegerString(numItemsString, numItems);
std::string numSelectedItemsString;
LLResMgr::getInstance()->getIntegerString(numSelectedItemsString, numSelectedItems);
LLStringUtil::format_map_t string_args;
string_args["[NUM_SELECTED]"] = numSelectedItemsString;
string_args["[NUM_TOTAL]"] = numItemsString;
statusText = getString("characters_messaging_complete_available", string_args);
}
break;
case kMessagingServiceNotAvailable:
statusText = getString("characters_messaging_service_not_available");
styleParams.color = warningColor;
break;
default:
statusText = getString("characters_messaging_initial");
llassert(0);
break;
}
mCharactersStatus->setText((LLStringExplicit)statusText, styleParams);
}
void LLFloaterPathfindingCharacters::updateActionFields()
{
std::vector<LLScrollListItem*> selectedItems = mCharactersScrollList->getAllSelected();
setEnableActionFields(!selectedItems.empty());
}
void LLFloaterPathfindingCharacters::setEnableActionFields(BOOL pEnabled)
{
mLabelActions->setEnabled(pEnabled);
mShowBeaconCheckBox->setEnabled(pEnabled);
mTakeBtn->setEnabled(pEnabled);
mTakeCopyBtn->setEnabled(pEnabled);
mReturnBtn->setEnabled(pEnabled);
mDeleteBtn->setEnabled(pEnabled);
mTeleportBtn->setEnabled(pEnabled && (mCharactersScrollList->getNumSelected() == 1));
}
//---------------------------------------------------------------------------
// CharactersGetResponder
//---------------------------------------------------------------------------
CharactersGetResponder::CharactersGetResponder(const std::string& pCharactersDataGetURL,
const LLHandle<LLFloaterPathfindingCharacters> &pCharactersFloaterHandle)
: mCharactersDataGetURL(pCharactersDataGetURL),
mCharactersFloaterHandle(pCharactersFloaterHandle)
{
}
CharactersGetResponder::~CharactersGetResponder()
{
}
void CharactersGetResponder::result(const LLSD& pContent)
{
LLFloaterPathfindingCharacters *charactersFloater = mCharactersFloaterHandle.get();
if (charactersFloater != NULL)
{
charactersFloater->handleCharactersDataGetReply(pContent);
}
}
void CharactersGetResponder::error(U32 status, const std::string& reason)
{
LLFloaterPathfindingCharacters *charactersFloater = mCharactersFloaterHandle.get();
if (charactersFloater != NULL)
{
charactersFloater->handleCharactersDataGetError(mCharactersDataGetURL, reason);
}
}
|