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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
/**
* @file LLNearbyChat.cpp
* @brief Nearby chat history scrolling panel implementation
*
* $LicenseInfo:firstyear=2009&license=viewergpl$
*
* Copyright (c) 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$
*/
#include "llviewerprecompiledheaders.h"
#include "llnearbychat.h"
#include "llviewercontrol.h"
#include "llviewerwindow.h"
#include "llrootview.h"
//#include "llchatitemscontainerctrl.h"
#include "lliconctrl.h"
#include "llsidetray.h"
#include "llfocusmgr.h"
#include "llresizebar.h"
#include "llresizehandle.h"
#include "llmenugl.h"
#include "llviewermenu.h"//for gMenuHolder
#include "llnearbychathandler.h"
#include "llchannelmanager.h"
static const S32 RESIZE_BAR_THICKNESS = 3;
LLNearbyChat::LLNearbyChat(const LLSD& key) :
LLFloater(key),
mEChatTearofState(CHAT_PINNED)
{
}
LLNearbyChat::~LLNearbyChat()
{
}
BOOL LLNearbyChat::postBuild()
{
//resize bars
setCanResize(true);
mResizeBar[LLResizeBar::BOTTOM]->setVisible(false);
mResizeBar[LLResizeBar::LEFT]->setVisible(false);
mResizeBar[LLResizeBar::RIGHT]->setVisible(false);
mResizeBar[LLResizeBar::BOTTOM]->setResizeLimits(120,500);
mResizeBar[LLResizeBar::TOP]->setResizeLimits(120,500);
mResizeBar[LLResizeBar::LEFT]->setResizeLimits(220,600);
mResizeBar[LLResizeBar::RIGHT]->setResizeLimits(220,600);
mResizeHandle[0]->setVisible(false);
mResizeHandle[1]->setVisible(false);
mResizeHandle[2]->setVisible(false);
mResizeHandle[3]->setVisible(false);
//menu
LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
enable_registrar.add("NearbyChat.Check", boost::bind(&LLNearbyChat::onNearbyChatCheckContextMenuItem, this, _2));
registrar.add("NearbyChat.Action", boost::bind(&LLNearbyChat::onNearbyChatContextMenuItemClicked, this, _2));
LLMenuGL* menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_nearby_chat.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
if(menu)
mPopupMenuHandle = menu->getHandle();
gSavedSettings.declareS32("nearbychat_showicons_and_names",2,"NearByChat header settings",true);
/*
LLChatItemsContainerCtrl* panel = getChild<LLChatItemsContainerCtrl>("chat_history",false,false);
if(panel)
{
panel->setHeaderVisibility((EShowItemHeader)gSavedSettings.getS32("nearbychat_showicons_and_names"));
}
*/
reshape(getRect().getWidth(), getRect().getHeight(), FALSE);
return LLFloater::postBuild();
}
#include "llagent.h" // gAgent
#include "llfloaterscriptdebug.h"
#include "llviewertexteditor.h"
#include "llstylemap.h"
LLColor4 nearbychat_get_text_color(const LLChat& chat)
{
LLColor4 text_color;
if(chat.mMuted)
{
text_color.setVec(0.8f, 0.8f, 0.8f, 1.f);
}
else
{
switch(chat.mSourceType)
{
case CHAT_SOURCE_SYSTEM:
text_color = LLUIColorTable::instance().getColor("SystemChatColor");
break;
case CHAT_SOURCE_AGENT:
if (chat.mFromID.isNull())
{
text_color = LLUIColorTable::instance().getColor("SystemChatColor");
}
else
{
if(gAgentID == chat.mFromID)
{
text_color = LLUIColorTable::instance().getColor("UserChatColor");
}
else
{
text_color = LLUIColorTable::instance().getColor("AgentChatColor");
}
}
break;
case CHAT_SOURCE_OBJECT:
if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
{
text_color = LLUIColorTable::instance().getColor("ScriptErrorColor");
}
else if ( chat.mChatType == CHAT_TYPE_OWNER )
{
text_color = LLUIColorTable::instance().getColor("llOwnerSayChatColor");
}
else
{
text_color = LLUIColorTable::instance().getColor("ObjectChatColor");
}
break;
default:
text_color.setToWhite();
}
if (!chat.mPosAgent.isExactlyZero())
{
LLVector3 pos_agent = gAgent.getPositionAgent();
F32 distance = dist_vec(pos_agent, chat.mPosAgent);
if (distance > gAgent.getNearChatRadius())
{
// diminish far-off chat
text_color.mV[VALPHA] = 0.8f;
}
}
}
return text_color;
}
void nearbychat_add_timestamped_line(LLViewerTextEditor* edit, LLChat chat, const LLColor4& color)
{
std::string line = chat.mFromName;
line +=": ";
line +=chat.mText;
bool prepend_newline = true;
if (gSavedSettings.getBOOL("ChatShowTimestamps"))
{
edit->appendTime(prepend_newline);
prepend_newline = false;
}
// If the msg is from an agent (not yourself though),
// extract out the sender name and replace it with the hotlinked name.
if (chat.mSourceType == CHAT_SOURCE_AGENT &&
chat.mFromID != LLUUID::null)
{
chat.mURL = llformat("secondlife:///app/agent/%s/about",chat.mFromID.asString().c_str());
}
// If the chat line has an associated url, link it up to the name.
if (!chat.mURL.empty()
&& (line.length() > chat.mFromName.length() && line.find(chat.mFromName,0) == 0))
{
std::string start_line = line.substr(0, chat.mFromName.length() + 1);
line = line.substr(chat.mFromName.length() + 1);
const LLStyleSP &sourceStyle = LLStyleMap::instance().lookup(chat.mFromID,chat.mURL);
edit->appendStyledText(start_line, false, prepend_newline, sourceStyle);
prepend_newline = false;
}
edit->appendColoredText(line, false, prepend_newline, color);
}
void LLNearbyChat::addMessage(const LLChat& chat)
{
/*
LLChatItemsContainerCtrl* panel = getChild<LLChatItemsContainerCtrl>("chat_history",false,false);
if(!panel)
return;
panel->addMessage(message);
*/
//"Chat History Editor" !!!!!
LLColor4 color = nearbychat_get_text_color(chat);
if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
{
LLFloaterScriptDebug::addScriptLine(chat.mText,
chat.mFromName,
color,
chat.mFromID);
if (!gSavedSettings.getBOOL("ScriptErrorsAsChat"))
{
return;
}
}
// could flash the chat button in the status bar here. JC
LLViewerTextEditor* history_editor = getChild<LLViewerTextEditor>("Chat History Editor");
history_editor->setParseHTML(TRUE);
history_editor->setParseHighlights(TRUE);
if (!chat.mMuted)
nearbychat_add_timestamped_line(history_editor, chat, color);
}
void LLNearbyChat::onNearbySpeakers()
{
LLSD param;
param["people_panel_tab_name"] = "nearby_panel";
LLSideTray::getInstance()->showPanel("panel_people",param);
}
void LLNearbyChat::onTearOff()
{
if(mEChatTearofState == CHAT_PINNED)
float_panel();
else
pinn_panel();
}
void LLNearbyChat::reshape(S32 width, S32 height, BOOL called_from_parent)
{
LLFloater::reshape(width, height, called_from_parent);
LLPanel* caption = getChild<LLPanel>("chat_caption",false,false);
LLRect resize_rect;
resize_rect.setLeftTopAndSize( 0, height, width, RESIZE_BAR_THICKNESS);
if (mResizeBar[LLResizeBar::TOP])
{
mResizeBar[LLResizeBar::TOP]->reshape(width,RESIZE_BAR_THICKNESS);
mResizeBar[LLResizeBar::TOP]->setRect(resize_rect);
}
resize_rect.setLeftTopAndSize( 0, RESIZE_BAR_THICKNESS, width, RESIZE_BAR_THICKNESS);
if (mResizeBar[LLResizeBar::BOTTOM])
{
mResizeBar[LLResizeBar::BOTTOM]->reshape(width,RESIZE_BAR_THICKNESS);
mResizeBar[LLResizeBar::BOTTOM]->setRect(resize_rect);
}
resize_rect.setLeftTopAndSize( 0, height, RESIZE_BAR_THICKNESS, height);
if (mResizeBar[LLResizeBar::LEFT])
{
mResizeBar[LLResizeBar::LEFT]->reshape(RESIZE_BAR_THICKNESS,height);
mResizeBar[LLResizeBar::LEFT]->setRect(resize_rect);
}
resize_rect.setLeftTopAndSize( width - RESIZE_BAR_THICKNESS, height, RESIZE_BAR_THICKNESS, height);
if (mResizeBar[LLResizeBar::RIGHT])
{
mResizeBar[LLResizeBar::RIGHT]->reshape(RESIZE_BAR_THICKNESS,height);
mResizeBar[LLResizeBar::RIGHT]->setRect(resize_rect);
}
LLRect caption_rect;
if (caption)
{
caption_rect = caption->getRect();
caption_rect.setLeftTopAndSize( 2, height - RESIZE_BAR_THICKNESS, width - 4, caption_rect.getHeight());
caption->reshape( width - 4, caption_rect.getHeight(), 1);
caption->setRect(caption_rect);
}
//LLPanel* scroll_panel = getChild<LLPanel>("chat_history",false,false);
LLViewerTextEditor* scroll_panel = getChild<LLViewerTextEditor>("Chat History Editor");
if (scroll_panel)
{
LLRect scroll_rect = scroll_panel->getRect();
scroll_rect.setLeftTopAndSize( 2, height - caption_rect.getHeight() - RESIZE_BAR_THICKNESS, width - 4, height - caption_rect.getHeight() - RESIZE_BAR_THICKNESS*2);
scroll_panel->reshape( width - 4, height - caption_rect.getHeight() - RESIZE_BAR_THICKNESS*2, 1);
scroll_panel->setRect(scroll_rect);
}
//
if(mEChatTearofState == CHAT_PINNED)
{
const LLRect& parent_rect = gViewerWindow->getRootView()->getRect();
LLRect panel_rect;
panel_rect.setLeftTopAndSize( parent_rect.mLeft+2, parent_rect.mBottom+height+4, width, height);
setRect(panel_rect);
}
else
{
LLRect panel_rect;
panel_rect.setLeftTopAndSize( getRect().mLeft, getRect().mTop, width, height);
setRect(panel_rect);
}
}
BOOL LLNearbyChat::handleMouseDown (S32 x, S32 y, MASK mask)
{
LLPanel* caption = getChild<LLPanel>("chat_caption",false,false);
if(caption)
{
LLUICtrl* nearby_speakers_btn = caption->getChild<LLUICtrl>("nearby_speakers_btn");
LLUICtrl* tearoff_btn = caption->getChild<LLUICtrl>("tearoff_btn");
LLUICtrl* close_btn = caption->getChild<LLUICtrl>("close_btn");
S32 caption_local_x = x - caption->getRect().mLeft;
S32 caption_local_y = y - caption->getRect().mBottom;
if(nearby_speakers_btn && tearoff_btn)
{
S32 local_x = caption_local_x - nearby_speakers_btn->getRect().mLeft;
S32 local_y = caption_local_y - nearby_speakers_btn->getRect().mBottom;
if(nearby_speakers_btn->pointInView(local_x, local_y))
{
onNearbySpeakers();
bringToFront( x, y );
return true;
}
local_x = caption_local_x - tearoff_btn->getRect().mLeft;
local_y = caption_local_y- tearoff_btn->getRect().mBottom;
if(tearoff_btn->pointInView(local_x, local_y))
{
onTearOff();
bringToFront( x, y );
return true;
}
if(close_btn)
{
local_x = caption_local_x - close_btn->getRect().mLeft;
local_y = caption_local_y - close_btn->getRect().mBottom;
if(close_btn->pointInView(local_x, local_y))
{
setVisible(false);
bringToFront( x, y );
return true;
}
}
}
if(mEChatTearofState == CHAT_UNPINNED && caption->pointInView(caption_local_x, caption_local_y) )
{
//start draggind
gFocusMgr.setMouseCapture(this);
mStart_Y = y;
mStart_X = x;
bringToFront( x, y );
return true;
}
}
return LLFloater::handleMouseDown(x,y,mask);
}
BOOL LLNearbyChat::handleMouseUp(S32 x, S32 y, MASK mask)
{
if( hasMouseCapture() )
{
// Release the mouse
gFocusMgr.setMouseCapture( NULL );
mStart_X = 0;
mStart_Y = 0;
return true;
}
return LLFloater::handleMouseUp(x,y,mask);
}
BOOL LLNearbyChat::handleHover(S32 x, S32 y, MASK mask)
{
if( hasMouseCapture() )
{
translate(x-mStart_X,y-mStart_Y);
return true;
}
return LLFloater::handleHover(x,y,mask);
}
void LLNearbyChat::pinn_panel()
{
mEChatTearofState = CHAT_PINNED;
LLPanel* caption = getChild<LLPanel>("chat_caption",false,false);
LLIconCtrl* tearoff_btn = caption->getChild<LLIconCtrl>("tearoff_btn",false,false);
tearoff_btn->setValue("inv_item_landmark_visited.tga");
const LLRect& parent_rect = gViewerWindow->getRootView()->getRect();
LLRect panel_rect;
panel_rect.setLeftTopAndSize( parent_rect.mLeft+2, parent_rect.mBottom+getRect().getHeight()+4, getRect().getWidth(), getRect().getHeight());
setRect(panel_rect);
mResizeBar[LLResizeBar::BOTTOM]->setVisible(false);
mResizeBar[LLResizeBar::LEFT]->setVisible(false);
mResizeBar[LLResizeBar::RIGHT]->setVisible(false);
}
void LLNearbyChat::float_panel()
{
mEChatTearofState = CHAT_UNPINNED;
LLPanel* caption = getChild<LLPanel>("chat_caption",false,false);
LLIconCtrl* tearoff_btn = caption->getChild<LLIconCtrl>("tearoff_btn",false,false);
tearoff_btn->setValue("inv_item_landmark.tga");
mResizeBar[LLResizeBar::BOTTOM]->setVisible(true);
mResizeBar[LLResizeBar::LEFT]->setVisible(true);
mResizeBar[LLResizeBar::RIGHT]->setVisible(true);
translate(4,4);
}
void LLNearbyChat::onNearbyChatContextMenuItemClicked(const LLSD& userdata)
{
/*
LLChatItemsContainerCtrl* panel = getChild<LLChatItemsContainerCtrl>("chat_history",false,false);
if(!panel)
return;
std::string str = userdata.asString();
if(str == "show_buddy_icons")
panel->setHeaderVisibility(CHATITEMHEADER_SHOW_ONLY_ICON);
else if(str == "show_names")
panel->setHeaderVisibility(CHATITEMHEADER_SHOW_ONLY_NAME);
else if(str == "show_icons_and_names")
panel->setHeaderVisibility(CHATITEMHEADER_SHOW_BOTH);
gSavedSettings.setS32("nearbychat_showicons_and_names", (S32)panel->getHeaderVisibility());
*/
}
bool LLNearbyChat::onNearbyChatCheckContextMenuItem(const LLSD& userdata)
{
std::string str = userdata.asString();
if(str == "nearby_people")
onNearbySpeakers();
/*
LLChatItemsContainerCtrl* panel = getChild<LLChatItemsContainerCtrl>("chat_history",false,false);
if(!panel)
return false;
if(str == "show_buddy_icons")
return panel->getHeaderVisibility() == CHATITEMHEADER_SHOW_ONLY_ICON;
else if(str == "show_names")
return panel->getHeaderVisibility() == CHATITEMHEADER_SHOW_ONLY_NAME;
else if(str == "show_icons_and_names")
return panel->getHeaderVisibility() == CHATITEMHEADER_SHOW_BOTH;
else if(str == "nearby_people")
onNearbySpeakers();
*/
return false;
}
BOOL LLNearbyChat::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
LLPanel* caption = getChild<LLPanel>("chat_caption",false,false);
if(caption && caption->pointInView(x - caption->getRect().mLeft, y - caption->getRect().mBottom) )
{
LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get();
if(menu)
{
menu->buildDrawLabels();
menu->updateParent(LLMenuGL::sMenuContainer);
LLMenuGL::showPopup(this, menu, x, y);
}
return true;
}
return LLFloater::handleRightMouseDown(x, y, mask);
}
void LLNearbyChat::onOpen(const LLSD& key )
{
LLNotificationsUI::LLScreenChannel* chat_channel = LLNotificationsUI::LLChannelManager::getInstance()->getChannelByID(LLUUID(NEARBY_CHAT_ID));
if(chat_channel)
{
chat_channel->removeToastsFromChannel();
}
}
|