summaryrefslogtreecommitdiff
path: root/indra/newview/llviewerchat.cpp
blob: 00520f100e754810ebaf7d44cb8a41750728648c (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
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
/**
 * @file llviewerchat.cpp
 * @brief Builds menus out of items.
 *
 * $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 "llviewerchat.h"

// newview includes
#include "llagent.h"    // gAgent
#include "llslurl.h"
#include "lltrans.h"
#include "lluicolor.h"
#include "lluicolortable.h"
#include "llviewercontrol.h" // gSavedSettings
#include "llviewerregion.h"
#include "llworld.h"
#include "llinstantmessage.h" //SYSTEM_FROM

// LLViewerChat
LLViewerChat::font_change_signal_t LLViewerChat::sChatFontChangedSignal;

//static
void LLViewerChat::getChatColor(const LLChat& chat, LLColor4& r_color)
{
    if(chat.mMuted)
    {
        r_color= LLUIColorTable::instance().getColor("LtGray");
    }
    else
    {
        switch(chat.mSourceType)
        {
            case CHAT_SOURCE_SYSTEM:
                r_color = LLUIColorTable::instance().getColor("SystemChatColor");
                break;
            case CHAT_SOURCE_AGENT:
                if (chat.mFromID.isNull() || SYSTEM_FROM == chat.mFromName)
                {
                    r_color = LLUIColorTable::instance().getColor("SystemChatColor");
                }
                else
                {
                    if(gAgentID == chat.mFromID)
                    {
                        r_color = LLUIColorTable::instance().getColor("UserChatColor");
                    }
                    else
                    {
                        r_color = LLUIColorTable::instance().getColor("AgentChatColor");
                    }
                }
                break;
            case CHAT_SOURCE_OBJECT:
                if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
                {
                    r_color = LLUIColorTable::instance().getColor("ScriptErrorColor");
                }
                else if ( chat.mChatType == CHAT_TYPE_OWNER )
                {
                    r_color = LLUIColorTable::instance().getColor("llOwnerSayChatColor");
                }
                else if ( chat.mChatType == CHAT_TYPE_DIRECT )
                {
                    r_color = LLUIColorTable::instance().getColor("DirectChatColor");
                }
                else
                {
                    r_color = LLUIColorTable::instance().getColor("ObjectChatColor");
                }
                break;
            default:
                r_color.setToWhite();
        }

        if (!chat.mPosAgent.isExactlyZero())
        {
            LLVector3 pos_agent = gAgent.getPositionAgent();
            F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent);
            F32 dist_near_chat = gAgent.getNearChatRadius();
            if (distance_squared > dist_near_chat * dist_near_chat)
            {
                // diminish far-off chat
                r_color.mV[VALPHA] = 0.8f;
            }
        }
    }
}


//static
void LLViewerChat::getChatColor(const LLChat& chat, std::string& r_color_name, F32& r_color_alpha)
{
    if(chat.mMuted)
    {
        r_color_name = "LtGray";
    }
    else
    {
        switch(chat.mSourceType)
        {
            case CHAT_SOURCE_SYSTEM:
                r_color_name = "SystemChatColor";
                break;

            case CHAT_SOURCE_AGENT:
                if (chat.mFromID.isNull())
                {
                    r_color_name = "SystemChatColor";
                }
                else
                {
                    if(gAgentID == chat.mFromID)
                    {
                        r_color_name = "UserChatColor";
                    }
                    else
                    {
                        r_color_name = "AgentChatColor";
                    }
                }
                break;

            case CHAT_SOURCE_OBJECT:
                if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
                {
                    r_color_name = "ScriptErrorColor";
                }
                else if ( chat.mChatType == CHAT_TYPE_OWNER )
                {
                    r_color_name = "llOwnerSayChatColor";
                }
                else if ( chat.mChatType == CHAT_TYPE_DIRECT )
                {
                    r_color_name = "DirectChatColor";
                }
                else
                {
                    r_color_name = "ObjectChatColor";
                }
                break;
            default:
                r_color_name = "White";
        }

        if (!chat.mPosAgent.isExactlyZero())
        {
            LLVector3 pos_agent = gAgent.getPositionAgent();
            F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent);
            F32 dist_near_chat = gAgent.getNearChatRadius();
            if (distance_squared > dist_near_chat * dist_near_chat)
            {
                // diminish far-off chat
                r_color_alpha = 0.8f;
            }
            else
            {
                r_color_alpha = 1.0f;
            }
        }
    }

}


//static
LLFontGL* LLViewerChat::getChatFont()
{
    S32 font_size = gSavedSettings.getS32("ChatFontSize");
    LLFontGL* fontp = NULL;
    switch(font_size)
    {
        case 0:
            fontp = LLFontGL::getFontSansSerifSmall();
            break;
        default:
        case 1:
            fontp = LLFontGL::getFontSansSerif();
            break;
        case 2:
            fontp = LLFontGL::getFontSansSerifBig();
            break;
    }

    return fontp;

}

//static
S32 LLViewerChat::getChatFontSize()
{
    return gSavedSettings.getS32("ChatFontSize");
}


//static
void LLViewerChat::formatChatMsg(const LLChat& chat, std::string& formated_msg)
{
    std::string tmpmsg = without_LUA_PREFIX(chat.mText, chat.mIsScript);
    if(chat.mChatStyle == CHAT_STYLE_IRC)
    {
        formated_msg = chat.mFromName + tmpmsg.substr(3);
    }
    else
    {
        formated_msg = tmpmsg;
    }

    if (chat.mIsScript) 
    {
        formated_msg = LLTrans::getString("ScriptStr") + formated_msg;
    }

}

//static
std::string LLViewerChat::getSenderSLURL(const LLChat& chat, const LLSD& args)
{
    switch (chat.mSourceType)
    {
    case CHAT_SOURCE_AGENT:
        return LLSLURL("agent", chat.mFromID, "about").getSLURLString();

    case CHAT_SOURCE_OBJECT:
        return getObjectImSLURL(chat, args);

    default:
        LL_WARNS() << "Getting SLURL for an unsupported sender type: " << chat.mSourceType << LL_ENDL;
    }

    return LLStringUtil::null;
}

//static
std::string LLViewerChat::getObjectImSLURL(const LLChat& chat, const LLSD& args)
{
    std::string url = LLSLURL("objectim", chat.mFromID, "").getSLURLString();
    url += "?name=" + chat.mFromName;
    url += "&owner=" + chat.mOwnerID.asString();

    std::string slurl = args["slurl"].asString();
    if (slurl.empty())
    {
        LLViewerRegion *region = LLWorld::getInstance()->getRegionFromPosAgent(chat.mPosAgent);
        if(region)
        {
            LLSLURL region_slurl(region->getName(), chat.mPosAgent);
            slurl = region_slurl.getLocationString();
        }
    }

    url += "&slurl=" + LLURI::escape(slurl);

    return url;
}

//static
boost::signals2::connection LLViewerChat::setFontChangedCallback(const font_change_signal_t::slot_type& cb)
{
    return sChatFontChangedSignal.connect(cb);
}

//static
void LLViewerChat::signalChatFontChanged()
{
    // Notify all observers that our font has changed
    sChatFontChangedSignal(getChatFont());
}