diff options
Diffstat (limited to 'linden/indra/newview/llfloaterscriptdebug.cpp')
-rw-r--r-- | linden/indra/newview/llfloaterscriptdebug.cpp | 249 |
1 files changed, 249 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterscriptdebug.cpp b/linden/indra/newview/llfloaterscriptdebug.cpp new file mode 100644 index 0000000..0781f7c --- /dev/null +++ b/linden/indra/newview/llfloaterscriptdebug.cpp | |||
@@ -0,0 +1,249 @@ | |||
1 | /** | ||
2 | * @file llfloaterscriptdebug.cpp | ||
3 | * @brief Chat window for showing script errors and warnings | ||
4 | * | ||
5 | * Copyright (c) 2006-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 "llvieweruictrlfactory.h" | ||
31 | #include "llfloaterscriptdebug.h" | ||
32 | |||
33 | #include "llfontgl.h" | ||
34 | #include "llrect.h" | ||
35 | #include "llerror.h" | ||
36 | #include "llstring.h" | ||
37 | #include "message.h" | ||
38 | |||
39 | // project include | ||
40 | #include "llviewertexteditor.h" | ||
41 | #include "llviewercontrol.h" | ||
42 | #include "llviewerobjectlist.h" | ||
43 | #include "llviewerimagelist.h" | ||
44 | |||
45 | // | ||
46 | // Statics | ||
47 | // | ||
48 | LLFloaterScriptDebug* LLFloaterScriptDebug::sInstance = NULL; | ||
49 | |||
50 | // | ||
51 | // Member Functions | ||
52 | // | ||
53 | LLFloaterScriptDebug::LLFloaterScriptDebug() | ||
54 | : LLMultiFloater() | ||
55 | { | ||
56 | |||
57 | } | ||
58 | |||
59 | LLFloaterScriptDebug::~LLFloaterScriptDebug() | ||
60 | { | ||
61 | sInstance = NULL; | ||
62 | } | ||
63 | |||
64 | void LLFloaterScriptDebug::show(const LLUUID& object_id) | ||
65 | { | ||
66 | LLFloater* floaterp = addOutputWindow(object_id); | ||
67 | if (sInstance) | ||
68 | { | ||
69 | sInstance->open(); | ||
70 | sInstance->showFloater(floaterp); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | BOOL LLFloaterScriptDebug::postBuild() | ||
75 | { | ||
76 | LLMultiFloater::postBuild(); | ||
77 | |||
78 | if (mTabContainer) | ||
79 | { | ||
80 | // *FIX: apparantly fails for tab containers? | ||
81 | // mTabContainer->requires("all_scripts", WIDGET_TYPE_FLOATER); | ||
82 | // mTabContainer->checkRequirements(); | ||
83 | return TRUE; | ||
84 | } | ||
85 | |||
86 | return FALSE; | ||
87 | } | ||
88 | |||
89 | void* getOutputWindow(void* data) | ||
90 | { | ||
91 | return new LLFloaterScriptDebugOutput(); | ||
92 | } | ||
93 | |||
94 | LLFloater* LLFloaterScriptDebug::addOutputWindow(const LLUUID &object_id) | ||
95 | { | ||
96 | if (!sInstance) | ||
97 | { | ||
98 | sInstance = new LLFloaterScriptDebug(); | ||
99 | LLCallbackMap::map_t factory_map; | ||
100 | factory_map["all_scripts"] = LLCallbackMap(getOutputWindow, NULL); | ||
101 | gUICtrlFactory->buildFloater(sInstance, "floater_script_debug.xml", &factory_map); | ||
102 | sInstance->setVisible(FALSE); | ||
103 | } | ||
104 | |||
105 | LLFloater* floaterp = NULL; | ||
106 | LLFloater::setFloaterHost(sInstance); | ||
107 | { | ||
108 | floaterp = LLFloaterScriptDebugOutput::show(object_id); | ||
109 | } | ||
110 | LLFloater::setFloaterHost(NULL); | ||
111 | |||
112 | return floaterp; | ||
113 | } | ||
114 | |||
115 | void LLFloaterScriptDebug::addScriptLine(const std::string &utf8mesg, const std::string &user_name, const LLColor4& color, const LLUUID& source_id) | ||
116 | { | ||
117 | LLViewerObject* objectp = gObjectList.findObject(source_id); | ||
118 | LLString floater_label; | ||
119 | |||
120 | if (objectp) | ||
121 | { | ||
122 | objectp->setIcon(gImageList.getImage(LLUUID(gViewerArt.getString("script_error.tga")))); | ||
123 | floater_label = llformat("%s(%.2f, %.2f)", user_name.c_str(), objectp->getPositionRegion().mV[VX], objectp->getPositionRegion().mV[VY]); | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | floater_label = user_name; | ||
128 | } | ||
129 | |||
130 | addOutputWindow(LLUUID::null); | ||
131 | addOutputWindow(source_id); | ||
132 | |||
133 | // add to "All" floater | ||
134 | LLFloaterScriptDebugOutput* floaterp = LLFloaterScriptDebugOutput::getFloaterByID(LLUUID::null); | ||
135 | floaterp->addLine(utf8mesg, user_name, color); | ||
136 | |||
137 | // add to specific script instance floater | ||
138 | floaterp = LLFloaterScriptDebugOutput::getFloaterByID(source_id); | ||
139 | floaterp->addLine(utf8mesg, floater_label, color); | ||
140 | } | ||
141 | |||
142 | // | ||
143 | // LLFloaterScriptDebugOutput | ||
144 | // | ||
145 | |||
146 | std::map<LLUUID, LLFloaterScriptDebugOutput*> LLFloaterScriptDebugOutput::sInstanceMap; | ||
147 | |||
148 | LLFloaterScriptDebugOutput::LLFloaterScriptDebugOutput() | ||
149 | : mObjectID(LLUUID::null) | ||
150 | { | ||
151 | sInstanceMap[mObjectID] = this; | ||
152 | } | ||
153 | |||
154 | LLFloaterScriptDebugOutput::LLFloaterScriptDebugOutput(const LLUUID& object_id) | ||
155 | : LLFloater("script instance floater", LLRect(0, 200, 200, 0), "Script", TRUE), mObjectID(object_id) | ||
156 | { | ||
157 | S32 y = mRect.getHeight() - LLFLOATER_HEADER_SIZE - LLFLOATER_VPAD; | ||
158 | S32 x = LLFLOATER_HPAD; | ||
159 | // History editor | ||
160 | // Give it a border on the top | ||
161 | LLRect history_editor_rect( | ||
162 | x, | ||
163 | y, | ||
164 | mRect.getWidth() - LLFLOATER_HPAD, | ||
165 | LLFLOATER_VPAD ); | ||
166 | mHistoryEditor = new LLViewerTextEditor( "Chat History Editor", | ||
167 | history_editor_rect, S32_MAX, "", LLFontGL::sSansSerif); | ||
168 | mHistoryEditor->setWordWrap( TRUE ); | ||
169 | mHistoryEditor->setFollowsAll(); | ||
170 | mHistoryEditor->setEnabled( FALSE ); | ||
171 | mHistoryEditor->setTakesFocus( TRUE ); // We want to be able to cut or copy from the history. | ||
172 | addChild(mHistoryEditor); | ||
173 | } | ||
174 | |||
175 | void LLFloaterScriptDebugOutput::init(const LLString& title, BOOL resizable, | ||
176 | S32 min_width, S32 min_height, BOOL drag_on_left, | ||
177 | BOOL minimizable, BOOL close_btn) | ||
178 | { | ||
179 | LLFloater::init(title, resizable, min_width, min_height, drag_on_left, minimizable, close_btn); | ||
180 | S32 y = mRect.getHeight() - LLFLOATER_HEADER_SIZE - LLFLOATER_VPAD; | ||
181 | S32 x = LLFLOATER_HPAD; | ||
182 | // History editor | ||
183 | // Give it a border on the top | ||
184 | LLRect history_editor_rect( | ||
185 | x, | ||
186 | y, | ||
187 | mRect.getWidth() - LLFLOATER_HPAD, | ||
188 | LLFLOATER_VPAD ); | ||
189 | mHistoryEditor = new LLViewerTextEditor( "Chat History Editor", | ||
190 | history_editor_rect, S32_MAX, "", LLFontGL::sSansSerif); | ||
191 | mHistoryEditor->setWordWrap( TRUE ); | ||
192 | mHistoryEditor->setFollowsAll(); | ||
193 | mHistoryEditor->setEnabled( FALSE ); | ||
194 | mHistoryEditor->setTakesFocus( TRUE ); // We want to be able to cut or copy from the history. | ||
195 | addChild(mHistoryEditor); | ||
196 | } | ||
197 | |||
198 | LLFloaterScriptDebugOutput::~LLFloaterScriptDebugOutput() | ||
199 | { | ||
200 | sInstanceMap.erase(mObjectID); | ||
201 | } | ||
202 | |||
203 | void LLFloaterScriptDebugOutput::addLine(const std::string &utf8mesg, const std::string &user_name, const LLColor4& color) | ||
204 | { | ||
205 | if (mObjectID.isNull()) | ||
206 | { | ||
207 | //setTitle("[All scripts]"); | ||
208 | setCanTearOff(FALSE); | ||
209 | setCanClose(FALSE); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | setTitle(user_name); | ||
214 | } | ||
215 | |||
216 | mHistoryEditor->appendColoredText(utf8mesg, false, true, color); | ||
217 | } | ||
218 | |||
219 | //static | ||
220 | LLFloaterScriptDebugOutput* LLFloaterScriptDebugOutput::show(const LLUUID& object_id) | ||
221 | { | ||
222 | LLFloaterScriptDebugOutput* floaterp = NULL; | ||
223 | instance_map_t::iterator found_it = sInstanceMap.find(object_id); | ||
224 | if (found_it == sInstanceMap.end()) | ||
225 | { | ||
226 | floaterp = new LLFloaterScriptDebugOutput(object_id); | ||
227 | sInstanceMap[object_id] = floaterp; | ||
228 | floaterp->open(); | ||
229 | } | ||
230 | else | ||
231 | { | ||
232 | floaterp = found_it->second; | ||
233 | } | ||
234 | |||
235 | return floaterp; | ||
236 | } | ||
237 | |||
238 | //static | ||
239 | LLFloaterScriptDebugOutput* LLFloaterScriptDebugOutput::getFloaterByID(const LLUUID& object_id) | ||
240 | { | ||
241 | LLFloaterScriptDebugOutput* floaterp = NULL; | ||
242 | instance_map_t::iterator found_it = sInstanceMap.find(object_id); | ||
243 | if (found_it != sInstanceMap.end()) | ||
244 | { | ||
245 | floaterp = found_it->second; | ||
246 | } | ||
247 | |||
248 | return floaterp; | ||
249 | } | ||