aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterrate.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llfloaterrate.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llfloaterrate.cpp')
-rw-r--r--linden/indra/newview/llfloaterrate.cpp279
1 files changed, 279 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterrate.cpp b/linden/indra/newview/llfloaterrate.cpp
new file mode 100644
index 0000000..128d1e6
--- /dev/null
+++ b/linden/indra/newview/llfloaterrate.cpp
@@ -0,0 +1,279 @@
1/**
2 * @file llfloaterrate.cpp
3 * @brief Dialog for rating avatars. She's a ten!
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llfloaterrate.h"
31
32#include "llcachename.h"
33#include "llfontgl.h"
34#include "lluuid.h"
35#include "message.h"
36
37#include "llagent.h"
38#include "lltextbox.h"
39#include "llbutton.h"
40#include "lllineeditor.h"
41#include "llradiogroup.h"
42#include "llselectmgr.h"
43#include "llvieweruictrlfactory.h"
44#include "llviewermessage.h"
45#include "llviewernetwork.h"
46#include "llviewerregion.h"
47#include "llviewerreputation.h"
48#include "llviewerwindow.h"
49
50// Dollar cost to change your rating of someone
51const S32 RATING_COST = 25;
52
53//static
54LLFloaterRate::instance_map_t LLFloaterRate::sInstanceMap;
55
56//-----------------------------------------------------------------------------
57// Methods
58//-----------------------------------------------------------------------------
59LLFloaterRate::LLFloaterRate(const std::string& name, const LLUUID &id)
60: LLFloater(name),
61 mAvatarID( id ),
62 mLastBehavior( 0.f ),
63 mLastAppearance( 0.f ),
64 mLastBuilding( 0.f ),
65 mReputationRequested( FALSE )
66{
67 gUICtrlFactory->buildFloater(this, "floater_rate.xml");
68
69 childSetAction("OK", onClickOK, this);
70 childSetAction("Cancel", onClickCancel, this);
71}
72
73
74LLFloaterRate::~LLFloaterRate()
75{
76 sInstanceMap.erase(mAvatarID);
77}
78
79
80void LLFloaterRate::draw()
81{
82 LLString name;
83
84 // Construct the name, if possible
85 char firstname[MAX_STRING];
86 char lastname[MAX_STRING];
87 gCacheName->getName(mAvatarID, firstname, lastname);
88 name.assign(firstname);
89 name.append(" ");
90 name.append(lastname);
91
92 // Request the current data, if we haven't already
93 if (!mReputationRequested)
94 {
95 sendReputationIndividualRequest(mAvatarID);
96 }
97
98 LLString title("Your Rating of ");
99 title.append( name );
100
101 setTitle(title);
102
103 F32 behavior = childGetValue("behavior").asString() == "Positive" ? 1.0f : 0.0f;
104 F32 appearance = childGetValue("appearance").asString() == "Positive" ? 1.0f : 0.0f;
105 F32 building = childGetValue("building").asString() == "Positive" ? 1.0f : 0.0f;
106
107 S32 change_count = 0;
108 if (behavior != mLastBehavior) change_count++;
109 if (appearance != mLastAppearance) change_count++;
110 if (building != mLastBuilding) change_count++;
111
112 childSetTextArg("cost", "[COST]", llformat("%d",RATING_COST));
113 childSetTextArg("cost", "[TOTAL]", llformat("%d",RATING_COST * change_count));
114
115 BOOL can_afford = can_afford_transaction(RATING_COST * change_count);
116 BOOL changed = (change_count > 0);
117 childSetEnabled("OK", changed && can_afford );
118
119 LLFloater::draw();
120}
121
122
123// static
124void LLFloaterRate::show(const LLUUID &avatar_id)
125{
126 instance_map_t::iterator iter = sInstanceMap.find(avatar_id);
127 if (iter != sInstanceMap.end())
128 {
129 iter->second->setFocus(TRUE);
130 iter->second->open();
131 }
132 else if (avatar_id != LLUUID::null)
133 {
134 LLFloaterRate *f = new LLFloaterRate("rate", avatar_id);
135 sInstanceMap[avatar_id] = f;
136 f->center();
137 f->setFocus(TRUE);
138 f->sendReputationIndividualRequest(avatar_id);
139 f->open();
140 }
141}
142
143
144// static
145void LLFloaterRate::show(ERateSelection which)
146{
147 LLUUID avatarid;
148 LLString avatarname;
149 switch(which)
150 {
151 case RS_CREATOR:
152 gSelectMgr->selectGetCreator(avatarid, avatarname);
153 break;
154
155 case RS_OWNER:
156 default:
157 gSelectMgr->selectGetOwner(avatarid, avatarname);
158 break;
159 }
160
161 if (avatarid != LLUUID::null)
162 {
163 show(avatarid);
164 }
165 else
166 {
167 gViewerWindow->alertXml("SelectSingleRate");
168 }
169
170
171 // Clean up selection
172 gSelectMgr->deselectTransient();
173}
174
175
176// static
177void LLFloaterRate::onClickOK(void *data)
178{
179 LLFloaterRate *self = (LLFloaterRate *)data;
180
181 F32 behavior = self->childGetValue("behavior").asString() == "Positive" ? 1.0f : 0.0f;
182 F32 appearance = self->childGetValue("appearance").asString() == "Positive" ? 1.0f : 0.0f;
183 F32 building = self->childGetValue("building").asString() == "Positive" ? 1.0f : 0.0f;
184 std::string text = self->childGetValue("mesg editor").asString();
185
186 S32 change_count = 0;
187 if (behavior != self->mLastBehavior) change_count++;
188 if (appearance != self->mLastAppearance) change_count++;
189 if (building != self->mLastBuilding) change_count++;
190
191 if (change_count > 0)
192 {
193 send_reputation_agent_assign(gAgent.getID(), self->mAvatarID,
194 behavior, appearance, building, text.c_str() );
195
196 give_money(LLUUID::null, gAgent.getRegion(), change_count * RATING_COST);
197
198 self->mLastBehavior = behavior;
199 self->mLastAppearance = appearance;
200 self->mLastBuilding = building;
201 }
202
203 self->close();
204}
205
206
207// static
208void LLFloaterRate::onClickCancel(void *data)
209{
210 LLFloaterRate *self = (LLFloaterRate *)data;
211 self->close();
212}
213
214
215void LLFloaterRate::sendReputationIndividualRequest(const LLUUID &avatar_id)
216{
217 mReputationRequested = TRUE;
218
219 LLMessageSystem *msg = gMessageSystem;
220 msg->newMessageFast(_PREHASH_ReputationIndividualRequest);
221 msg->nextBlockFast(_PREHASH_ReputationData);
222 msg->addUUIDFast(_PREHASH_FromID, gAgent.getID() );
223 msg->addUUIDFast(_PREHASH_ToID, avatar_id );
224 msg->sendReliable( gUserServer );
225}
226
227
228// static
229void LLFloaterRate::processReputationIndividualReply(LLMessageSystem *msg, void** data)
230{
231 LLUUID from_id;
232 LLUUID to_id;
233 F32 behavior = 0.f;
234 F32 appearance = 0.f;
235 F32 building = 0.f;
236
237 msg->getUUIDFast(_PREHASH_ReputationData, _PREHASH_FromID, from_id );
238 msg->getUUIDFast(_PREHASH_ReputationData, _PREHASH_ToID, to_id );
239 msg->getF32Fast(_PREHASH_ReputationData, _PREHASH_Behavior, behavior );
240 msg->getF32Fast(_PREHASH_ReputationData, _PREHASH_Appearance, appearance );
241 msg->getF32Fast(_PREHASH_ReputationData, _PREHASH_Building, building );
242
243 instance_map_t::iterator iter = sInstanceMap.find(to_id);
244 if (iter != sInstanceMap.end())
245 {
246 LLFloaterRate* f = iter->second;
247
248 f->mLastBehavior = behavior;
249 f->mLastAppearance = appearance;
250 f->mLastBuilding = building;
251
252 if (behavior > 0.f)
253 {
254 f->childSetValue("behavior", "Positive");
255 }
256 else
257 {
258 f->childSetValue("behavior", "No Rating");
259 }
260
261 if (appearance > 0.f)
262 {
263 f->childSetValue("appearance", "Positive");
264 }
265 else
266 {
267 f->childSetValue("appearance", "No Rating");
268 }
269
270 if (building > 0.f)
271 {
272 f->childSetValue("building", "Positive");
273 }
274 else
275 {
276 f->childSetValue("building", "No Rating");
277 }
278 }
279}