llfloatertelehub.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 
00035 #include "llfloatertelehub.h"
00036 
00037 #include "message.h"
00038 #include "llfontgl.h"
00039 
00040 #include "llagent.h"
00041 #include "llfloatertools.h"
00042 #include "llscrolllistctrl.h"
00043 #include "llselectmgr.h"
00044 #include "lltoolcomp.h"
00045 #include "lltoolmgr.h"
00046 #include "llviewerobject.h"
00047 #include "llviewerobjectlist.h"
00048 #include "llvieweruictrlfactory.h"
00049 
00050 LLFloaterTelehub* LLFloaterTelehub::sInstance = NULL;
00051 
00052 
00053 // static
00054 void LLFloaterTelehub::show()
00055 {
00056         if (sInstance)
00057         {
00058                 sInstance->setVisibleAndFrontmost();
00059                 return;
00060         }
00061 
00062         sInstance = new LLFloaterTelehub();
00063 
00064         // Show tools floater by selecting translate (select) tool
00065         gToolMgr->setCurrentToolset(gBasicToolset);
00066         gToolMgr->getCurrentToolset()->selectTool( gToolTranslate );
00067 
00068         // Find tools floater, glue to bottom
00069         if (gFloaterTools)
00070         {
00071                 gFloaterTools->showMore(FALSE);
00072                 LLRect tools_rect = gFloaterTools->getRect();
00073                 S32 our_width = sInstance->getRect().getWidth();
00074                 S32 our_height = sInstance->getRect().getHeight();
00075                 LLRect our_rect;
00076                 our_rect.setLeftTopAndSize(tools_rect.mLeft, tools_rect.mBottom, our_width, our_height);
00077                 sInstance->setRect(our_rect);
00078         }
00079 
00080         sInstance->sendTelehubInfoRequest();
00081 }
00082 
00083 LLFloaterTelehub::LLFloaterTelehub()
00084 :       LLFloater("telehub"),
00085         mTelehubObjectID(),
00086         mTelehubObjectName(),
00087         mTelehubPos(),
00088         mTelehubRot(),
00089         mNumSpawn(0)
00090 {
00091         sInstance = this;
00092 
00093         gMessageSystem->setHandlerFunc("TelehubInfo", processTelehubInfo);
00094 
00095         gUICtrlFactory->buildFloater(sInstance, "floater_telehub.xml");
00096 
00097         childSetAction("connect_btn", onClickConnect, this);
00098         childSetAction("disconnect_btn", onClickDisconnect, this);
00099         childSetAction("add_spawn_point_btn", onClickAddSpawnPoint, this);
00100         childSetAction("remove_spawn_point_btn", onClickRemoveSpawnPoint, this);
00101 
00102         LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(this, "spawn_points_list");
00103         if (list)
00104         {
00105                 // otherwise you can't walk with arrow keys while floater is up
00106                 list->setAllowKeyboardMovement(FALSE);
00107         }
00108 
00109         mObjectSelection = gSelectMgr->getEditSelection();
00110 }
00111 
00112 LLFloaterTelehub::~LLFloaterTelehub()
00113 {
00114         sInstance = NULL;
00115 
00116         // no longer interested in this message
00117         gMessageSystem->setHandlerFunc("TelehubInfo", NULL);
00118 }
00119 
00120 void LLFloaterTelehub::draw()
00121 {
00122         if (getVisible() && !isMinimized())
00123         {
00124                 refresh();
00125         }
00126         LLFloater::draw();
00127 }
00128 
00129 // Per-frame updates, because we don't have a selection manager observer.
00130 void LLFloaterTelehub::refresh()
00131 {
00132         const BOOL children_ok = TRUE;
00133         LLViewerObject* object = mObjectSelection->getFirstRootObject(children_ok);
00134         
00135         BOOL have_selection = (object != NULL);
00136         BOOL all_volume = gSelectMgr->selectionAllPCode( LL_PCODE_VOLUME );
00137         childSetEnabled("connect_btn", have_selection && all_volume);
00138 
00139         BOOL have_telehub = mTelehubObjectID.notNull();
00140         childSetEnabled("disconnect_btn", have_telehub);
00141 
00142         BOOL space_avail = (mNumSpawn < MAX_SPAWNPOINTS_PER_TELEHUB);
00143         childSetEnabled("add_spawn_point_btn", have_selection && all_volume && space_avail);
00144 
00145         LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(this, "spawn_points_list");
00146         if (list)
00147         {
00148                 BOOL enable_remove = (list->getFirstSelected() != NULL);
00149                 childSetEnabled("remove_spawn_point_btn", enable_remove);
00150         }
00151 }
00152 
00153 // static
00154 BOOL LLFloaterTelehub::renderBeacons()
00155 {
00156         // only render if we've got a telehub
00157         return sInstance && sInstance->mTelehubObjectID.notNull();
00158 }
00159 
00160 // static
00161 void LLFloaterTelehub::addBeacons()
00162 {
00163         if (!sInstance) return;
00164 
00165         // Find the telehub position, either our cached old position, or
00166         // an updated one based on the actual object position.
00167         LLVector3 hub_pos_region = sInstance->mTelehubPos;
00168         LLQuaternion hub_rot = sInstance->mTelehubRot;
00169         LLViewerObject* obj = gObjectList.findObject(sInstance->mTelehubObjectID);
00170         if (obj)
00171         {
00172                 hub_pos_region = obj->getPositionRegion();
00173                 hub_rot = obj->getRotationRegion();
00174         }
00175         // Draw nice thick 3-pixel lines.
00176         gObjectList.addDebugBeacon(hub_pos_region, "", LLColor4::yellow, LLColor4::white, 4);
00177 
00178         LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(sInstance, "spawn_points_list");
00179         if (list)
00180         {
00181                 S32 spawn_index = list->getFirstSelectedIndex();
00182                 if (spawn_index >= 0)
00183                 {
00184                         LLVector3 spawn_pos = hub_pos_region  + (sInstance->mSpawnPointPos[spawn_index] * hub_rot);
00185                         gObjectList.addDebugBeacon(spawn_pos, "", LLColor4::orange, LLColor4::white, 4);
00186                 }
00187         }
00188 }
00189 
00190 void LLFloaterTelehub::sendTelehubInfoRequest()
00191 {
00192         gSelectMgr->sendGodlikeRequest("telehub", "info ui");
00193 }
00194 
00195 // static 
00196 void LLFloaterTelehub::onClickConnect(void* data)
00197 {
00198         gSelectMgr->sendGodlikeRequest("telehub", "connect");
00199 }
00200 
00201 // static 
00202 void LLFloaterTelehub::onClickDisconnect(void* data)
00203 {
00204         gSelectMgr->sendGodlikeRequest("telehub", "delete");
00205 }
00206 
00207 // static 
00208 void LLFloaterTelehub::onClickAddSpawnPoint(void* data)
00209 {
00210         gSelectMgr->sendGodlikeRequest("telehub", "spawnpoint add");
00211         gSelectMgr->deselectAll();
00212 }
00213 
00214 // static 
00215 void LLFloaterTelehub::onClickRemoveSpawnPoint(void* data)
00216 {
00217         if (!sInstance) return;
00218 
00219         LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(sInstance, "spawn_points_list");
00220         if (!list) return;
00221 
00222         S32 spawn_index = list->getFirstSelectedIndex();
00223         if (spawn_index < 0) return;  // nothing selected
00224 
00225         LLMessageSystem* msg = gMessageSystem;
00226 
00227         // Could be god or estate owner.  If neither, server will reject message.
00228         if (gAgent.isGodlike())
00229         {
00230                 msg->newMessage("GodlikeMessage");
00231         }
00232         else
00233         {
00234                 msg->newMessage("EstateOwnerMessage");
00235         }
00236         msg->nextBlock("AgentData");
00237         msg->addUUID("AgentID", gAgent.getID());
00238         msg->addUUID("SessionID", gAgent.getSessionID());
00239         msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
00240         msg->nextBlock("MethodData");
00241         msg->addString("Method", "telehub");
00242         msg->addUUID("Invoice", LLUUID::null);
00243 
00244         msg->nextBlock("ParamList");
00245         msg->addString("Parameter", "spawnpoint remove");
00246 
00247         char buffer[MAX_STRING];                /* Flawfinder: ignore */
00248         snprintf(buffer, MAX_STRING, "%d", spawn_index);        /* Flawfinder: ignore */
00249         msg->nextBlock("ParamList");
00250         msg->addString("Parameter", buffer);
00251 
00252         gAgent.sendReliableMessage();
00253 }
00254 
00255 // static 
00256 void LLFloaterTelehub::processTelehubInfo(LLMessageSystem* msg, void**)
00257 {
00258         if (sInstance)
00259         {
00260                 sInstance->unpackTelehubInfo(msg);
00261         }
00262 }
00263 
00264 void LLFloaterTelehub::unpackTelehubInfo(LLMessageSystem* msg)
00265 {
00266         char buffer[MAX_STRING];                /* Flawfinder: ignore */
00267 
00268         msg->getUUID("TelehubBlock", "ObjectID", mTelehubObjectID);
00269         msg->getString("TelehubBlock", "ObjectName", MAX_STRING, buffer);
00270         mTelehubObjectName = buffer;
00271         msg->getVector3("TelehubBlock", "TelehubPos", mTelehubPos);
00272         msg->getQuat("TelehubBlock", "TelehubRot", mTelehubRot);
00273 
00274         mNumSpawn = msg->getNumberOfBlocks("SpawnPointBlock");
00275         for (S32 i = 0; i < mNumSpawn; i++)
00276         {
00277                 msg->getVector3("SpawnPointBlock", "SpawnPointPos", mSpawnPointPos[i], i);
00278         }
00279 
00280         // Update parts of the UI that change only when message received.
00281 
00282         if (mTelehubObjectID.isNull())
00283         {
00284                 childSetVisible("status_text_connected", false);
00285                 childSetVisible("status_text_not_connected", true);
00286                 childSetVisible("help_text_connected", false);
00287                 childSetVisible("help_text_not_connected", true);
00288         }
00289         else
00290         {
00291                 childSetTextArg("status_text_connected", "[OBJECT]", mTelehubObjectName);
00292                 childSetVisible("status_text_connected", true);
00293                 childSetVisible("status_text_not_connected", false);
00294                 childSetVisible("help_text_connected", true);
00295                 childSetVisible("help_text_not_connected", false);
00296         }
00297 
00298         LLScrollListCtrl* list = LLUICtrlFactory::getScrollListByName(this, "spawn_points_list");
00299         if (list)
00300         {
00301                 list->deleteAllItems();
00302                 for (S32 i = 0; i < mNumSpawn; i++)
00303                 {
00304                         LLString pos = llformat("%.1f, %.1f, %.1f", 
00305                                                                         mSpawnPointPos[i].mV[VX],
00306                                                                         mSpawnPointPos[i].mV[VY],
00307                                                                         mSpawnPointPos[i].mV[VZ]);
00308                         list->addSimpleItem(pos);
00309                 }
00310                 list->selectNthItem(mNumSpawn - 1);
00311         }
00312 }

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