llfloaterscriptdebug.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llvieweruictrlfactory.h"
00035 #include "llfloaterscriptdebug.h"
00036 
00037 #include "llfontgl.h"
00038 #include "llrect.h"
00039 #include "llerror.h"
00040 #include "llstring.h"
00041 #include "message.h"
00042 
00043 // project include
00044 #include "llviewertexteditor.h"
00045 #include "llviewercontrol.h"
00046 #include "llviewerobjectlist.h"
00047 #include "llviewerimagelist.h"
00048 
00049 //
00050 // Statics
00051 //
00052 LLFloaterScriptDebug*   LLFloaterScriptDebug::sInstance = NULL;
00053 
00054 //
00055 // Member Functions
00056 //
00057 LLFloaterScriptDebug::LLFloaterScriptDebug() : 
00058         LLMultiFloater()
00059 {
00060         // avoid resizing of the window to match 
00061         // the initial size of the tabbed-childs, whenever a tab is opened or closed
00062         mAutoResize = FALSE;
00063 }
00064 
00065 LLFloaterScriptDebug::~LLFloaterScriptDebug()
00066 {
00067         sInstance = NULL;
00068 }
00069 
00070 void LLFloaterScriptDebug::show(const LLUUID& object_id)
00071 {
00072         LLFloater* floaterp = addOutputWindow(object_id);
00073         if (sInstance)
00074         {
00075                 sInstance->open();              /* Flawfinder: ignore */
00076                 sInstance->showFloater(floaterp);
00077         }
00078 }
00079 
00080 BOOL LLFloaterScriptDebug::postBuild()
00081 {
00082         LLMultiFloater::postBuild();
00083 
00084         if (mTabContainer)
00085         {
00086                 // *FIX: apparantly fails for tab containers?
00087 //              mTabContainer->requires("all_scripts", WIDGET_TYPE_FLOATER);
00088 //              mTabContainer->checkRequirements();
00089                 return TRUE;
00090         }
00091 
00092         return FALSE;
00093 }
00094 
00095 void* getOutputWindow(void* data)
00096 {
00097         return new LLFloaterScriptDebugOutput();
00098 }
00099 
00100 LLFloater* LLFloaterScriptDebug::addOutputWindow(const LLUUID &object_id)
00101 {
00102         if (!sInstance)
00103         {
00104                 sInstance = new LLFloaterScriptDebug();
00105                 LLCallbackMap::map_t factory_map;
00106                 factory_map["all_scripts"] = LLCallbackMap(getOutputWindow, NULL);
00107                 gUICtrlFactory->buildFloater(sInstance, "floater_script_debug.xml", &factory_map);
00108                 sInstance->setVisible(FALSE);
00109         }
00110 
00111         LLFloater* floaterp = NULL;
00112         LLFloater::setFloaterHost(sInstance);
00113         {
00114                 floaterp = LLFloaterScriptDebugOutput::show(object_id);
00115         }
00116         LLFloater::setFloaterHost(NULL);
00117 
00118         // Tabs sometimes overlap resize handle
00119         sInstance->moveResizeHandlesToFront();
00120 
00121         return floaterp;
00122 }
00123 
00124 void LLFloaterScriptDebug::addScriptLine(const std::string &utf8mesg, const std::string &user_name, const LLColor4& color, const LLUUID& source_id)
00125 {
00126         LLViewerObject* objectp = gObjectList.findObject(source_id);
00127         LLString floater_label;
00128 
00129         if (objectp)
00130         {
00131                 objectp->setIcon(gImageList.getImage(LLUUID(gViewerArt.getString("script_error.tga"))));
00132                 floater_label = llformat("%s(%.2f, %.2f)", user_name.c_str(), objectp->getPositionRegion().mV[VX], objectp->getPositionRegion().mV[VY]);
00133         }
00134         else
00135         {
00136                 floater_label = user_name;
00137         }
00138 
00139         addOutputWindow(LLUUID::null);
00140         addOutputWindow(source_id);
00141 
00142         // add to "All" floater
00143         LLFloaterScriptDebugOutput* floaterp = LLFloaterScriptDebugOutput::getFloaterByID(LLUUID::null);
00144         floaterp->addLine(utf8mesg, user_name, color);
00145 
00146         // add to specific script instance floater
00147         floaterp = LLFloaterScriptDebugOutput::getFloaterByID(source_id);
00148         floaterp->addLine(utf8mesg, floater_label, color);
00149 }
00150 
00151 //
00152 // LLFloaterScriptDebugOutput
00153 //
00154 
00155 std::map<LLUUID, LLFloaterScriptDebugOutput*> LLFloaterScriptDebugOutput::sInstanceMap;
00156 
00157 LLFloaterScriptDebugOutput::LLFloaterScriptDebugOutput()
00158 : mObjectID(LLUUID::null)
00159 {
00160         sInstanceMap[mObjectID] = this;
00161 }
00162 
00163 LLFloaterScriptDebugOutput::LLFloaterScriptDebugOutput(const LLUUID& object_id)
00164 : LLFloater("script instance floater", LLRect(0, 200, 200, 0), "Script", TRUE), mObjectID(object_id)
00165 {
00166         S32 y = mRect.getHeight() - LLFLOATER_HEADER_SIZE - LLFLOATER_VPAD;
00167         S32 x = LLFLOATER_HPAD;
00168         // History editor
00169         // Give it a border on the top
00170         LLRect history_editor_rect(
00171                 x,
00172                 y,
00173                 mRect.getWidth() - LLFLOATER_HPAD,
00174                                 LLFLOATER_VPAD );
00175         mHistoryEditor = new LLViewerTextEditor( "Chat History Editor", 
00176                                                                                 history_editor_rect, S32_MAX, "", LLFontGL::sSansSerif);
00177         mHistoryEditor->setWordWrap( TRUE );
00178         mHistoryEditor->setFollowsAll();
00179         mHistoryEditor->setEnabled( FALSE );
00180         mHistoryEditor->setTakesFocus( TRUE );  // We want to be able to cut or copy from the history.
00181         addChild(mHistoryEditor);
00182 }
00183 
00184 void LLFloaterScriptDebugOutput::init(const LLString& title, BOOL resizable, 
00185                                                 S32 min_width, S32 min_height, BOOL drag_on_left,
00186                                                 BOOL minimizable, BOOL close_btn)
00187 {
00188         LLFloater::init(title, resizable, min_width, min_height, drag_on_left, minimizable, close_btn);
00189         S32 y = mRect.getHeight() - LLFLOATER_HEADER_SIZE - LLFLOATER_VPAD;
00190         S32 x = LLFLOATER_HPAD;
00191         // History editor
00192         // Give it a border on the top
00193         LLRect history_editor_rect(
00194                 x,
00195                 y,
00196                 mRect.getWidth() - LLFLOATER_HPAD,
00197                                 LLFLOATER_VPAD );
00198         mHistoryEditor = new LLViewerTextEditor( "Chat History Editor", 
00199                                                                                 history_editor_rect, S32_MAX, "", LLFontGL::sSansSerif);
00200         mHistoryEditor->setWordWrap( TRUE );
00201         mHistoryEditor->setFollowsAll();
00202         mHistoryEditor->setEnabled( FALSE );
00203         mHistoryEditor->setTakesFocus( TRUE );  // We want to be able to cut or copy from the history.
00204         addChild(mHistoryEditor);
00205 }
00206 
00207 LLFloaterScriptDebugOutput::~LLFloaterScriptDebugOutput()
00208 {
00209         sInstanceMap.erase(mObjectID);
00210 }
00211 
00212 void LLFloaterScriptDebugOutput::addLine(const std::string &utf8mesg, const std::string &user_name, const LLColor4& color)
00213 {
00214         if (mObjectID.isNull())
00215         {
00216                 //setTitle("[All scripts]");
00217                 setCanTearOff(FALSE);
00218                 setCanClose(FALSE);
00219         }
00220         else
00221         {
00222                 setTitle(user_name);
00223         }
00224 
00225         mHistoryEditor->appendColoredText(utf8mesg, false, true, color);
00226 }
00227 
00228 //static
00229 LLFloaterScriptDebugOutput* LLFloaterScriptDebugOutput::show(const LLUUID& object_id)
00230 {
00231         LLFloaterScriptDebugOutput* floaterp = NULL;
00232         instance_map_t::iterator found_it = sInstanceMap.find(object_id);
00233         if (found_it == sInstanceMap.end())
00234         {
00235                 floaterp = new LLFloaterScriptDebugOutput(object_id);
00236                 sInstanceMap[object_id] = floaterp;
00237                 floaterp->open();               /* Flawfinder: ignore*/
00238         }
00239         else
00240         {
00241                 floaterp = found_it->second;
00242         }
00243 
00244         return floaterp;
00245 }
00246 
00247 //static 
00248 LLFloaterScriptDebugOutput* LLFloaterScriptDebugOutput::getFloaterByID(const LLUUID& object_id)
00249 {
00250         LLFloaterScriptDebugOutput* floaterp = NULL;
00251         instance_map_t::iterator found_it = sInstanceMap.find(object_id);
00252         if (found_it != sInstanceMap.end())
00253         {
00254                 floaterp = found_it->second;
00255         }
00256 
00257         return floaterp;
00258 }

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