Skip to content

Commit e59d44d

Browse files
authored
Merge pull request #3756 from secondlife/marchcat/lua_editor
Lua editor: #3731 follow-ups
2 parents dba481f + 39dda55 commit e59d44d

File tree

2 files changed

+115
-89
lines changed

2 files changed

+115
-89
lines changed

indra/newview/llpanelcontents.cpp

+83-67
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void LLPanelContents::onClickNewScript(void *userdata)
198198
{
199199
const bool children_ok = true;
200200
LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject(children_ok);
201-
if(object)
201+
if (object)
202202
{
203203
LLPermissions perm;
204204
perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null);
@@ -227,78 +227,94 @@ void LLPanelContents::onClickNewScript(void *userdata)
227227
// This temporary workaround should be removed after a server-side fix.
228228
// See https://github.com/secondlife/viewer/issues/3731 for more information.
229229
//
230-
if (std::string::size_type pos = desc.find("lsl2"); pos != std::string::npos)
230+
LLViewerRegion* region = object->getRegion();
231+
if (region && region->simulatorFeaturesReceived())
231232
{
232-
desc.replace(pos, 4, "SLua");
233-
}
234-
235-
auto scriptCreationCallback = [object](const LLUUID& inv_item)
233+
LLSD simulatorFeatures;
234+
region->getSimulatorFeatures(simulatorFeatures);
235+
if (simulatorFeatures["LuaScriptsEnabled"].asBoolean())
236236
{
237-
if (!inv_item.isNull())
237+
if (std::string::size_type pos = desc.find("lsl2"); pos != std::string::npos)
238238
{
239-
LLViewerInventoryItem* item = gInventory.getItem(inv_item);
240-
if (item)
241-
{
242-
const std::string hello_lua_script =
243-
"function state_entry()\n"
244-
" ll.Say(0, \"Hello, Avatar!\")\n"
245-
"end\n"
246-
"\n"
247-
"function touch_start(total_number)\n"
248-
" ll.Say(0, \"Touched.\")\n"
249-
"end\n"
250-
"\n"
251-
"-- Simulate the state_entry event\n"
252-
"state_entry()\n";
253-
254-
auto scriptUploadFinished = [object, item](LLUUID itemId, LLUUID newAssetId, LLUUID newItemId, LLSD response)
255-
{
256-
LLPointer<LLViewerInventoryItem> new_script = new LLViewerInventoryItem(item);
257-
object->saveScript(new_script, true, true);
258-
259-
// Delete the temporary item from the user's inventory after rezzing it in the object's inventory
260-
gInventory.deleteObject(item->getUUID());
261-
gInventory.notifyObservers();
262-
};
239+
desc.replace(pos, 4, "SLua");
240+
}
263241

264-
std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent");
265-
if (!url.empty())
242+
auto scriptCreationCallback = [object](const LLUUID& inv_item)
243+
{
244+
if (!inv_item.isNull())
266245
{
267-
LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLScriptAssetUpload>(
268-
item->getUUID(),
269-
"luau",
270-
hello_lua_script,
271-
scriptUploadFinished,
272-
nullptr));
273-
274-
LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo);
246+
LLViewerInventoryItem* item = gInventory.getItem(inv_item);
247+
if (item)
248+
{
249+
const std::string hello_lua_script =
250+
"function state_entry()\n"
251+
" ll.Say(0, \"Hello, Avatar!\")\n"
252+
"end\n"
253+
"\n"
254+
"function touch_start(total_number)\n"
255+
" ll.Say(0, \"Touched.\")\n"
256+
"end\n"
257+
"\n"
258+
"-- Simulate the state_entry event\n"
259+
"state_entry()\n";
260+
261+
auto scriptUploadFinished = [object, item](LLUUID itemId, LLUUID newAssetId, LLUUID newItemId, LLSD response)
262+
{
263+
LLPointer<LLViewerInventoryItem> new_script = new LLViewerInventoryItem(item);
264+
object->saveScript(new_script, true, true);
265+
266+
// Delete the temporary item from the user's inventory after rezzing it in the object's inventory
267+
ms_sleep(50);
268+
LLMessageSystem* msg = gMessageSystem;
269+
msg->newMessageFast(_PREHASH_RemoveInventoryItem);
270+
msg->nextBlockFast(_PREHASH_AgentData);
271+
msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
272+
msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
273+
msg->nextBlockFast(_PREHASH_InventoryData);
274+
msg->addUUIDFast(_PREHASH_ItemID, item->getUUID());
275+
gAgent.sendReliableMessage();
276+
277+
gInventory.deleteObject(item->getUUID());
278+
gInventory.notifyObservers();
279+
};
280+
281+
std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent");
282+
if (!url.empty())
283+
{
284+
LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLScriptAssetUpload>(
285+
item->getUUID(),
286+
"luau",
287+
hello_lua_script,
288+
scriptUploadFinished,
289+
nullptr));
290+
291+
LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo);
292+
}
293+
}
275294
}
276-
277-
gInventory.updateItem(item);
278-
gInventory.notifyObservers();
279-
}
280-
}
281-
};
282-
LLPointer<LLBoostFuncInventoryCallback> cb = new LLBoostFuncInventoryCallback(scriptCreationCallback);
283-
284-
LLMessageSystem* msg = gMessageSystem;
285-
msg->newMessageFast(_PREHASH_CreateInventoryItem);
286-
msg->nextBlock(_PREHASH_AgentData);
287-
msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
288-
msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
289-
msg->nextBlock(_PREHASH_InventoryBlock);
290-
msg->addU32Fast(_PREHASH_CallbackID, gInventoryCallbacks.registerCB(cb));
291-
msg->addUUIDFast(_PREHASH_FolderID, gInventory.getRootFolderID());
292-
msg->addUUIDFast(_PREHASH_TransactionID, LLTransactionID::tnull);
293-
msg->addU32Fast(_PREHASH_NextOwnerMask, PERM_MOVE | PERM_TRANSFER);
294-
msg->addS8Fast(_PREHASH_Type, LLAssetType::AT_LSL_TEXT);
295-
msg->addS8Fast(_PREHASH_InvType, LLInventoryType::IT_LSL);
296-
msg->addU8Fast(_PREHASH_WearableType, NO_INV_SUBTYPE);
297-
msg->addStringFast(_PREHASH_Name, "New Script");
298-
msg->addStringFast(_PREHASH_Description, desc);
299-
300-
gAgent.sendReliableMessage();
301-
return;
295+
};
296+
LLPointer<LLBoostFuncInventoryCallback> cb = new LLBoostFuncInventoryCallback(scriptCreationCallback);
297+
298+
LLMessageSystem* msg = gMessageSystem;
299+
msg->newMessageFast(_PREHASH_CreateInventoryItem);
300+
msg->nextBlock(_PREHASH_AgentData);
301+
msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
302+
msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
303+
msg->nextBlock(_PREHASH_InventoryBlock);
304+
msg->addU32Fast(_PREHASH_CallbackID, gInventoryCallbacks.registerCB(cb));
305+
msg->addUUIDFast(_PREHASH_FolderID, gInventory.getRootFolderID());
306+
msg->addUUIDFast(_PREHASH_TransactionID, LLTransactionID::tnull);
307+
msg->addU32Fast(_PREHASH_NextOwnerMask, PERM_MOVE | PERM_TRANSFER);
308+
msg->addS8Fast(_PREHASH_Type, LLAssetType::AT_LSL_TEXT);
309+
msg->addS8Fast(_PREHASH_InvType, LLInventoryType::IT_LSL);
310+
msg->addU8Fast(_PREHASH_WearableType, NO_INV_SUBTYPE);
311+
msg->addStringFast(_PREHASH_Name, "New Script");
312+
msg->addStringFast(_PREHASH_Description, desc);
313+
314+
gAgent.sendReliableMessage();
315+
return;
316+
}
317+
}
302318
//
303319
// End hack
304320
// --------------------------------------------------------------------------------------------------

indra/newview/llviewerinventory.cpp

+32-22
Original file line numberDiff line numberDiff line change
@@ -1024,29 +1024,39 @@ void create_script_cb(const LLUUID& inv_item)
10241024
// This temporary workaround should be removed after a server-side fix.
10251025
// See https://github.com/secondlife/viewer/issues/3731 for more information.
10261026
//
1027-
const std::string hello_lua_script =
1028-
"function state_entry()\n"
1029-
" ll.Say(0, \"Hello, Avatar!\")\n"
1030-
"end\n"
1031-
"\n"
1032-
"function touch_start(total_number)\n"
1033-
" ll.Say(0, \"Touched.\")\n"
1034-
"end\n"
1035-
"\n"
1036-
"-- Simulate the state_entry event\n"
1037-
"state_entry()\n";
1038-
1039-
std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent");
1040-
if (!url.empty())
1027+
LLViewerRegion* region = gAgent.getRegion();
1028+
if (region && region->simulatorFeaturesReceived())
10411029
{
1042-
LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLScriptAssetUpload>(
1043-
item->getUUID(),
1044-
"luau",
1045-
hello_lua_script,
1046-
nullptr,
1047-
nullptr));
1048-
1049-
LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo);
1030+
LLSD simulatorFeatures;
1031+
region->getSimulatorFeatures(simulatorFeatures);
1032+
if (simulatorFeatures["LuaScriptsEnabled"].asBoolean())
1033+
{
1034+
1035+
const std::string hello_lua_script =
1036+
"function state_entry()\n"
1037+
" ll.Say(0, \"Hello, Avatar!\")\n"
1038+
"end\n"
1039+
"\n"
1040+
"function touch_start(total_number)\n"
1041+
" ll.Say(0, \"Touched.\")\n"
1042+
"end\n"
1043+
"\n"
1044+
"-- Simulate the state_entry event\n"
1045+
"state_entry()\n";
1046+
1047+
std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent");
1048+
if (!url.empty())
1049+
{
1050+
LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLScriptAssetUpload>(
1051+
item->getUUID(),
1052+
"luau",
1053+
hello_lua_script,
1054+
nullptr,
1055+
nullptr));
1056+
1057+
LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo);
1058+
}
1059+
}
10501060
}
10511061
//
10521062
// End hack

0 commit comments

Comments
 (0)