llfloatertrustnetrate.cpp

Go to the documentation of this file.
00001 
00029 #include "llviewerprecompiledheaders.h"
00030 
00031 #include "llfloatertrustnetrate.h"
00032 
00033 #include "llcachename.h"
00034 #include "llfontgl.h"
00035 #include "lluuid.h"
00036 #include "message.h"
00037 
00038 #include "llagent.h"
00039 #include "lltextbox.h"
00040 #include "llbutton.h"
00041 #include "lllineeditor.h"
00042 #include "llradiogroup.h"
00043 #include "llselectmgr.h"
00044 #include "llvieweruictrlfactory.h"
00045 #include "llviewermessage.h"
00046 #include "llviewernetwork.h"
00047 #include "llviewerregion.h"
00048 //#include "llviewerreputation.h"
00049 #include "llviewerwindow.h"
00050 
00051 // Dollar cost to change your rating of someone
00052 const S32 RATING_COST = 25;
00053 
00054 //static
00055 LLFloaterTrustNetRate::instance_map_t LLFloaterTrustNetRate::sInstanceMap;
00056 
00057 //-----------------------------------------------------------------------------
00058 // Methods
00059 //-----------------------------------------------------------------------------
00060 LLFloaterTrustNetRate::LLFloaterTrustNetRate(const std::string& name, const LLUUID &id)
00061 :       LLFloater(name),
00062         mAvatarID( id ),
00063         mLastBehavior( 0.f ),
00064         mLastAppearance( 0.f ),
00065         mLastBuilding( 0.f ),
00066         mReputationRequested( FALSE )
00067 {
00068         gUICtrlFactory->buildFloater(this, "floater_trustnetrate.xml");
00069 
00070         childSetAction("OK", onClickOK, this);
00071         childSetAction("Cancel", onClickCancel, this);
00072 
00073         mObjectSelection = gSelectMgr->getEditSelection();
00074 }
00075 
00076 
00077 LLFloaterTrustNetRate::~LLFloaterTrustNetRate()
00078 {
00079         sInstanceMap.erase(mAvatarID);
00080 }
00081 
00082 
00083 void LLFloaterTrustNetRate::draw()
00084 {
00085         LLString name;
00086 
00087         // Construct the name, if possible
00088         char firstname[MAX_STRING];             /* Flawfinder: ignore */
00089         char lastname[MAX_STRING];              /* Flawfinder: ignore */
00090         gCacheName->getName(mAvatarID, firstname, lastname);
00091         name.assign(firstname);
00092         name.append(" ");
00093         name.append(lastname);
00094 
00095         // Request the current data, if we haven't already
00096         if (!mReputationRequested)
00097         {
00098                 sendReputationIndividualRequest(mAvatarID);
00099         }
00100 
00101         LLString title("Your Rating of ");
00102         title.append( name );
00103 
00104         setTitle(title);
00105 
00106         F32 behavior   = childGetValue("behavior").asString() == "Positive" ? 1.0f : 0.0f;
00107         F32 appearance   = childGetValue("appearance").asString() == "Positive" ? 1.0f : 0.0f;
00108         F32 building   = childGetValue("building").asString() == "Positive" ? 1.0f : 0.0f;
00109 
00110         S32 change_count = 0;
00111         if (behavior != mLastBehavior) change_count++;
00112         if (appearance != mLastAppearance) change_count++;
00113         if (building != mLastBuilding) change_count++;
00114 
00115         childSetTextArg("cost", "[COST]", llformat("%d",RATING_COST));
00116         childSetTextArg("cost", "[TOTAL]", llformat("%d",RATING_COST * change_count));
00117 
00118         BOOL can_afford = can_afford_transaction(RATING_COST * change_count);
00119         BOOL changed = (change_count > 0);
00120         childSetEnabled("OK",  changed && can_afford );
00121 
00122         LLFloater::draw();
00123 }
00124 
00125 
00126 // static
00127 void LLFloaterTrustNetRate::show(const LLUUID &avatar_id)
00128 {
00129         instance_map_t::iterator iter = sInstanceMap.find(avatar_id);
00130         if (iter != sInstanceMap.end())
00131         {
00132                 iter->second->setFocus(TRUE);
00133                 iter->second->open();           /* Flawfinder: ignore */
00134         }
00135         else if (avatar_id != LLUUID::null)
00136         {
00137                 LLFloaterTrustNetRate *f = new LLFloaterTrustNetRate("rate", avatar_id);
00138                 sInstanceMap[avatar_id] = f;
00139                 f->center();
00140                 f->setFocus(TRUE);
00141                 f->sendReputationIndividualRequest(avatar_id);
00142                 f->open();              /* Flawfinder: ignore */
00143         }
00144 }
00145 
00146 
00147 // static
00148 void LLFloaterTrustNetRate::show(ERateSelection which)
00149 {
00150         LLUUID avatarid;
00151         LLString avatarname;
00152         switch(which)
00153         {
00154           case RS_CREATOR:
00155                 gSelectMgr->selectGetCreator(avatarid, avatarname);
00156                 break;
00157 
00158           case RS_OWNER:
00159           default:
00160                 gSelectMgr->selectGetOwner(avatarid, avatarname);
00161                 break;
00162         }
00163 
00164         if (avatarid != LLUUID::null)
00165         {
00166                 show(avatarid);
00167         }
00168         else
00169         {
00170                 gViewerWindow->alertXml("SelectSingleRate");
00171         }
00172 }
00173 
00174 
00175 // static
00176 void LLFloaterTrustNetRate::onClickOK(void *data)
00177 {
00178         LLFloaterTrustNetRate *self = (LLFloaterTrustNetRate *)data;
00179         
00180         F32 behavior   = self->childGetValue("behavior").asString() == "Positive" ? 1.0f : 0.0f;
00181         F32 appearance   = self->childGetValue("appearance").asString() == "Positive" ? 1.0f : 0.0f;
00182         F32 building   = self->childGetValue("building").asString() == "Positive" ? 1.0f : 0.0f;
00183         std::string text = self->childGetValue("mesg editor").asString();
00184 
00185         S32 change_count = 0;
00186         if (behavior != self->mLastBehavior) change_count++;
00187         if (appearance != self->mLastAppearance) change_count++;
00188         if (building != self->mLastBuilding) change_count++;
00189 
00190         if (change_count > 0)
00191         {
00192 //              send_reputation_agent_assign(gAgent.getID(), self->mAvatarID, 
00193 //                                                                       behavior, appearance, building, text.c_str() );
00194 
00195 //              give_money(LLUUID::null, gAgent.getRegion(), change_count * RATING_COST);
00196 
00197                 self->mLastBehavior = behavior;
00198                 self->mLastAppearance = appearance;
00199                 self->mLastBuilding = building;
00200         }
00201 
00202         self->close();
00203 }
00204 
00205 
00206 // static
00207 void LLFloaterTrustNetRate::onClickCancel(void *data) 
00208 {
00209         LLFloaterTrustNetRate *self = (LLFloaterTrustNetRate *)data;
00210         self->close();
00211 }
00212 
00213 
00214 void LLFloaterTrustNetRate::sendReputationIndividualRequest(const LLUUID &avatar_id)
00215 {
00216 //      mReputationRequested = TRUE;
00217 //
00218 //      LLMessageSystem *msg = gMessageSystem;
00219 //      msg->newMessageFast(_PREHASH_ReputationIndividualRequest);
00220 //      msg->nextBlockFast(_PREHASH_ReputationData);
00221 //      msg->addUUIDFast(_PREHASH_FromID, gAgent.getID() );
00222 //      msg->addUUIDFast(_PREHASH_ToID, avatar_id );
00223 //      msg->sendReliable( gUserServer );
00224 }
00225 
00226 
00227 // static
00228 void LLFloaterTrustNetRate::processReputationIndividualReply(LLMessageSystem *msg, void** data)
00229 {
00230 //      LLUUID from_id;
00231 //      LLUUID to_id;
00232 //      F32 behavior = 0.f;
00233 //      F32 appearance = 0.f;
00234 //      F32 building = 0.f;
00235 // 
00236 //      msg->getUUIDFast(_PREHASH_ReputationData, _PREHASH_FromID, from_id );
00237 //      msg->getUUIDFast(_PREHASH_ReputationData, _PREHASH_ToID, to_id );
00238 //      msg->getF32Fast(_PREHASH_ReputationData, _PREHASH_Behavior, behavior );
00239 //      msg->getF32Fast(_PREHASH_ReputationData, _PREHASH_Appearance, appearance );
00240 //      msg->getF32Fast(_PREHASH_ReputationData, _PREHASH_Building, building );
00241 // 
00242 //      instance_map_t::iterator iter = sInstanceMap.find(to_id);
00243 //      if (iter != sInstanceMap.end())
00244 //      {
00245 //              LLFloaterTrustNetRate* f = iter->second;
00246 // 
00247 //              f->mLastBehavior = behavior;
00248 //              f->mLastAppearance = appearance;
00249 //              f->mLastBuilding = building;
00250 // 
00251 //              if (behavior > 0.f)
00252 //              {
00253 //                      f->childSetValue("behavior", "Positive");
00254 //              }
00255 //              else
00256 //              {       
00257 //                      f->childSetValue("behavior", "No Rating");
00258 //              }
00259 // 
00260 //              if (appearance > 0.f)
00261 //              {
00262 //                      f->childSetValue("appearance", "Positive");
00263 //              }
00264 //              else
00265 //              {       
00266 //                      f->childSetValue("appearance", "No Rating");
00267 //              }
00268 // 
00269 //              if (building > 0.f)
00270 //              {
00271 //                      f->childSetValue("building", "Positive");
00272 //              }
00273 //              else
00274 //              {       
00275 //                      f->childSetValue("building", "No Rating");
00276 //              }
00277 //      }
00278 }

Generated on Thu Jul 1 06:08:36 2010 for Second Life Viewer by  doxygen 1.4.7