llfloatergesture.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloatergesture.h"
00035 
00036 #include "lldir.h"
00037 #include "llinventory.h"
00038 #include "llmultigesture.h"
00039 
00040 #include "llagent.h"
00041 #include "llviewerwindow.h"
00042 #include "llbutton.h"
00043 #include "llcombobox.h"
00044 #include "llgesturemgr.h"
00045 #include "llinventorymodel.h"
00046 #include "llinventoryview.h"
00047 #include "llkeyboard.h"
00048 #include "lllineeditor.h"
00049 #include "llpreviewgesture.h"
00050 #include "llresizehandle.h"
00051 #include "llscrollbar.h"
00052 #include "llscrollcontainer.h"
00053 #include "llscrolllistctrl.h"
00054 #include "lltextbox.h"
00055 #include "llvieweruictrlfactory.h"
00056 #include "llviewergesture.h"
00057 #include "llviewerimagelist.h"
00058 #include "llviewerinventory.h"
00059 #include "llvoavatar.h"
00060 #include "llviewercontrol.h"
00061 
00062 // static
00063 LLFloaterGesture* LLFloaterGesture::sInstance = NULL;
00064 LLFloaterGestureObserver* LLFloaterGesture::sObserver = NULL;
00065 
00066 BOOL item_name_precedes( LLInventoryItem* a, LLInventoryItem* b )
00067 {
00068         return LLString::precedesDict( a->getName(), b->getName() );
00069 }
00070 
00071 class LLFloaterGestureObserver : public LLGestureManagerObserver
00072 {
00073 public:
00074         LLFloaterGestureObserver() {}
00075         virtual ~LLFloaterGestureObserver() {}
00076         virtual void changed() { LLFloaterGesture::refreshAll(); }
00077 };
00078 
00079 //---------------------------------------------------------------------------
00080 // LLFloaterGesture
00081 //---------------------------------------------------------------------------
00082 LLFloaterGesture::LLFloaterGesture()
00083 :       LLFloater("Gesture Floater")
00084 {
00085         sInstance = this;
00086 
00087         sObserver = new LLFloaterGestureObserver;
00088         gGestureManager.addObserver(sObserver);
00089 }
00090 
00091 // virtual
00092 LLFloaterGesture::~LLFloaterGesture()
00093 {
00094         gGestureManager.removeObserver(sObserver);
00095         delete sObserver;
00096         sObserver = NULL;
00097 
00098         sInstance = NULL;
00099 
00100         // Custom saving rectangle, since load must be done
00101         // after postBuild.
00102         gSavedSettings.setRect("FloaterGestureRect", mRect);
00103 }
00104 
00105 // virtual
00106 BOOL LLFloaterGesture::postBuild()
00107 {
00108         LLString label;
00109 
00110         // Translate title
00111         label = getTitle();
00112         
00113         setTitle(label);
00114 
00115         childSetCommitCallback("gesture_list", onCommitList, this);
00116         childSetDoubleClickCallback("gesture_list", onClickPlay);
00117 
00118         childSetAction("inventory_btn", onClickInventory, this);
00119 
00120         childSetAction("edit_btn", onClickEdit, this);
00121 
00122         childSetAction("play_btn", onClickPlay, this);
00123         childSetAction("stop_btn", onClickPlay, this);
00124 
00125         childSetAction("new_gesture_btn", onClickNew, this);
00126 
00127         childSetVisible("play_btn", true);
00128         childSetVisible("stop_btn", false);
00129         setDefaultBtn("play_btn");
00130 
00131         return TRUE;
00132 }
00133 
00134 
00135 // static
00136 void LLFloaterGesture::show()
00137 {
00138         if (sInstance)
00139         {
00140                 sInstance->open();              /*Flawfinder: ignore*/
00141                 return;
00142         }
00143 
00144         LLFloaterGesture *self = new LLFloaterGesture();
00145 
00146         // Builds and adds to gFloaterView
00147         gUICtrlFactory->buildFloater(self, "floater_gesture.xml");
00148 
00149         // Fix up rectangle
00150         LLRect rect = gSavedSettings.getRect("FloaterGestureRect");
00151         self->reshape(rect.getWidth(), rect.getHeight());
00152         self->setRect(rect);
00153 
00154         self->buildGestureList();
00155 
00156         self->childSetFocus("gesture_list");
00157 
00158         LLCtrlListInterface *list = self->childGetListInterface("gesture_list");
00159         if (list) list->selectFirstItem();
00160         
00161         self->mSelectedID = LLUUID::null;
00162 
00163         // Update button labels
00164         onCommitList(NULL, self);
00165         self->open();   /*Flawfinder: ignore*/
00166 }
00167 
00168 // static
00169 void LLFloaterGesture::toggleVisibility()
00170 {
00171         if(sInstance && sInstance->getVisible())
00172         {
00173                 sInstance->close();
00174         }
00175         else
00176         {
00177                 show();
00178         }
00179 }
00180 
00181 // static
00182 void LLFloaterGesture::refreshAll()
00183 {
00184         if (sInstance)
00185         {
00186                 sInstance->buildGestureList();
00187 
00188                 LLCtrlListInterface *list = sInstance->childGetListInterface("gesture_list");
00189                 if (!list) return;
00190 
00191                 if (sInstance->mSelectedID.isNull())
00192                 {
00193                         list->selectFirstItem();
00194                 }
00195                 else
00196                 {
00197                         if (list->setCurrentByID(sInstance->mSelectedID))
00198                         {
00199                                 LLCtrlScrollInterface *scroll = sInstance->childGetScrollInterface("gesture_list");
00200                                 if (scroll) scroll->scrollToShowSelected();
00201                         }
00202                         else
00203                         {
00204                                 list->selectFirstItem();
00205                         }
00206                 }
00207 
00208                 // Update button labels
00209                 onCommitList(NULL, sInstance);
00210         }
00211 }
00212 
00213 void LLFloaterGesture::buildGestureList()
00214 {
00215         LLCtrlListInterface *list = childGetListInterface("gesture_list");
00216         if (!list) return;
00217 
00218         list->operateOnAll(LLCtrlListInterface::OP_DELETE);
00219 
00220         LLGestureManager::item_map_t::iterator it;
00221         for (it = gGestureManager.mActive.begin(); it != gGestureManager.mActive.end(); ++it)
00222         {
00223                 const LLUUID& item_id = (*it).first;
00224                 LLMultiGesture* gesture = (*it).second;
00225 
00226                 // Note: Can have NULL item if inventory hasn't arrived yet.
00227                 std::string item_name = "Loading...";
00228                 LLInventoryItem* item = gInventory.getItem(item_id);
00229                 if (item)
00230                 {
00231                         item_name = item->getName();
00232                 }
00233 
00234                 LLString font_style = "NORMAL";
00235                 // If gesture is playing, bold it
00236 
00237                 LLSD element;
00238                 element["id"] = item_id;
00239 
00240                 if (gesture)
00241                 {
00242                         if (gesture->mPlaying)
00243                         {
00244                                 font_style = "BOLD";
00245                         }
00246 
00247                         element["columns"][0]["column"] = "trigger";
00248                         element["columns"][0]["value"] = gesture->mTrigger;
00249                         element["columns"][0]["font"] = "SANSSERIF";
00250                         element["columns"][0]["font-style"] = font_style;
00251 
00252                         LLString key_string = LLKeyboard::stringFromKey(gesture->mKey);
00253                         LLString buffer;
00254 
00255                         {
00256                                 if (gesture->mKey == KEY_NONE)
00257                                 {
00258                                         buffer = "---";
00259                                         key_string = "~~~";             // alphabetize to end
00260                                 }
00261                                 else
00262                                 {
00263                                         if (gesture->mMask & MASK_CONTROL) buffer.append("Ctrl-");
00264                                         if (gesture->mMask & MASK_ALT) buffer.append("Alt-");
00265                                         if (gesture->mMask & MASK_SHIFT) buffer.append("Shift-");
00266                                         if ((gesture->mMask & (MASK_CONTROL|MASK_ALT|MASK_SHIFT)) &&
00267                                                 (key_string[0] == '-' || key_string[0] == '='))
00268                                         {
00269                                                 buffer.append(" ");
00270                                         }
00271                                         buffer.append(key_string);
00272                                 }
00273                         }
00274                         element["columns"][1]["column"] = "shortcut";
00275                         element["columns"][1]["value"] = buffer;
00276                         element["columns"][1]["font"] = "SANSSERIF";
00277                         element["columns"][1]["font-style"] = font_style;
00278 
00279                         // hidden column for sorting
00280                         element["columns"][2]["column"] = "key";
00281                         element["columns"][2]["value"] = key_string;
00282                         element["columns"][2]["font"] = "SANSSERIF";
00283                         element["columns"][2]["font-style"] = font_style;
00284 
00285                         // Only add "playing" if we've got the name, less confusing. JC
00286                         if (item && gesture->mPlaying)
00287                         {
00288                                 item_name += " (Playing)";
00289                         }
00290                         element["columns"][3]["column"] = "name";
00291                         element["columns"][3]["value"] = item_name;
00292                         element["columns"][3]["font"] = "SANSSERIF";
00293                         element["columns"][3]["font-style"] = font_style;
00294                 }
00295                 else
00296                 {
00297                         element["columns"][0]["column"] = "trigger";
00298                         element["columns"][0]["value"] = "";
00299                         element["columns"][0]["font"] = "SANSSERIF";
00300                         element["columns"][0]["font-style"] = font_style;
00301                         element["columns"][0]["column"] = "trigger";
00302                         element["columns"][0]["value"] = "---";
00303                         element["columns"][0]["font"] = "SANSSERIF";
00304                         element["columns"][0]["font-style"] = font_style;
00305                         element["columns"][2]["column"] = "key";
00306                         element["columns"][2]["value"] = "~~~";
00307                         element["columns"][2]["font"] = "SANSSERIF";
00308                         element["columns"][2]["font-style"] = font_style;
00309                         element["columns"][3]["column"] = "name";
00310                         element["columns"][3]["value"] = item_name;
00311                         element["columns"][3]["font"] = "SANSSERIF";
00312                         element["columns"][3]["font-style"] = font_style;
00313                 }
00314                 list->addElement(element, ADD_BOTTOM);
00315         }
00316 }
00317 
00318 // static
00319 void LLFloaterGesture::onClickInventory(void* data)
00320 {
00321         LLFloaterGesture* self = (LLFloaterGesture*)data;
00322 
00323         LLCtrlListInterface *list = self->childGetListInterface("gesture_list");
00324         if (!list) return;
00325         const LLUUID& item_id = list->getCurrentID();
00326 
00327         LLInventoryView* inv = LLInventoryView::showAgentInventory();
00328         if (!inv) return;
00329         inv->getPanel()->setSelection(item_id, TRUE);
00330 }
00331 
00332 // static
00333 void LLFloaterGesture::onClickPlay(void* data)
00334 {
00335         LLFloaterGesture* self = (LLFloaterGesture*)data;
00336 
00337         LLCtrlListInterface *list = self->childGetListInterface("gesture_list");
00338         if (!list) return;
00339         const LLUUID& item_id = list->getCurrentID();
00340 
00341         if (gGestureManager.isGesturePlaying(item_id))
00342         {
00343                 gGestureManager.stopGesture(item_id);
00344         }
00345         else
00346         {
00347                 gGestureManager.playGesture(item_id);
00348         }
00349 }
00350 
00351 class GestureShowCallback : public LLInventoryCallback
00352 {
00353 public:
00354         GestureShowCallback(LLString &title)
00355         {
00356                 mTitle = title;
00357         }
00358         void fire(const LLUUID &inv_item)
00359         {
00360                 LLPreviewGesture::show(mTitle.c_str(), inv_item, LLUUID::null);
00361         }
00362 private:
00363         LLString mTitle;
00364 };
00365 
00366 // static
00367 void LLFloaterGesture::onClickNew(void* data)
00368 {
00369         LLString title("Gesture: ");
00370         title.append("New Gesture");
00371         LLPointer<LLInventoryCallback> cb = new GestureShowCallback(title);
00372         create_inventory_item(gAgent.getID(), gAgent.getSessionID(),
00373                 LLUUID::null, LLTransactionID::tnull, "New Gesture", "", LLAssetType::AT_GESTURE,
00374                 LLInventoryType::IT_GESTURE, NOT_WEARABLE, PERM_MOVE | PERM_TRANSFER, cb);
00375 }
00376 
00377 
00378 // static
00379 void LLFloaterGesture::onClickEdit(void* data)
00380 {
00381         LLFloaterGesture* self = (LLFloaterGesture*)data;
00382 
00383         LLCtrlListInterface *list = self->childGetListInterface("gesture_list");
00384         if (!list) return;
00385         const LLUUID& item_id = list->getCurrentID();
00386 
00387         LLInventoryItem* item = gInventory.getItem(item_id);
00388         if (!item) return;
00389 
00390         LLString title("Gesture: ");
00391         title.append(item->getName());
00392 
00393         LLPreviewGesture* previewp = LLPreviewGesture::show(title, item_id, LLUUID::null);
00394         if (!previewp->getHost())
00395         {
00396                 previewp->setRect(gFloaterView->findNeighboringPosition(self, previewp));
00397         }
00398 }
00399 
00400 // static
00401 void LLFloaterGesture::onCommitList(LLUICtrl* ctrl, void* data)
00402 {
00403         LLFloaterGesture* self = (LLFloaterGesture*)data;
00404 
00405         const LLUUID& item_id = self->childGetValue("gesture_list").asUUID();
00406 
00407         self->mSelectedID = item_id;
00408         if (gGestureManager.isGesturePlaying(item_id))
00409         {
00410                 self->childSetVisible("play_btn", false);
00411                 self->childSetVisible("stop_btn", true);
00412         }
00413         else
00414         {
00415                 self->childSetVisible("play_btn", true);
00416                 self->childSetVisible("stop_btn", false);
00417         }
00418 }

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