From 7c5297d7e61704c5d1812e693e2350a64bf9d221 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Sat, 1 Mar 2025 04:49:03 +0200 Subject: #3615 WIP: Improve script editor code for the inventory --- indra/newview/llpreviewscript.cpp | 84 ++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 27 deletions(-) (limited to 'indra/newview/llpreviewscript.cpp') diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 9a03b36831..82cb419c17 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -119,6 +119,29 @@ static bool have_script_upload_cap(LLUUID& object_id) return object && (! object->getRegion()->getCapability("UpdateScriptTask").empty()); } +static bool have_lua_enabled(const LLUUID& object_id) +{ + LLViewerRegion* region = nullptr; + LLViewerObject* object = gObjectList.findObject(object_id); + if (object) + { + region = object->getRegion(); + } + else + { + region = gAgent.getRegion(); + } + + if (region && region->simulatorFeaturesReceived()) + { + LLSD simulatorFeatures; + region->getSimulatorFeatures(simulatorFeatures); + return simulatorFeatures["LuaScriptsEnabled"].asBoolean(); + } + + return false; +} + /// --------------------------------------------------------------------------- /// LLLiveLSLFile /// --------------------------------------------------------------------------- @@ -497,7 +520,7 @@ bool LLScriptEdCore::postBuild() // Intialise keyword highlighting for the current simulator's version of LSL LLSyntaxIdLSL::getInstance()->initialize(); LLSyntaxLua::getInstance()->initialize(); - //processKeywords(); + processKeywords(); mCommitCallbackRegistrar.add("FontSize.Set", boost::bind(&LLScriptEdCore::onChangeFontSize, this, _2)); mEnableCallbackRegistrar.add("FontSize.Check", boost::bind(&LLScriptEdCore::isFontSizeChecked, this, _2)); @@ -506,6 +529,18 @@ bool LLScriptEdCore::postBuild() "menu_lsl_font_size.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); getChild("font_btn")->setMenu(context_menu, LLMenuButton::MP_BOTTOM_LEFT, true); + + bool lua_scripts_enabled = have_lua_enabled(LLUUID::null); + mCompileTarget = getChild("compile_target"); + if (LLScrollListItem* luau_item = mCompileTarget->findItemByValue("luau")) + { + luau_item->setEnabled(lua_scripts_enabled); + } + if (LLScrollListItem* lsl_luau_item = mCompileTarget->findItemByValue("lsl-luau")) + { + lsl_luau_item->setEnabled(lua_scripts_enabled); + } + return true; } @@ -1626,6 +1661,9 @@ bool LLPreviewLSL::postBuild() childSetCommitCallback("desc", LLPreview::onText, this); getChild("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe); + mScriptEd->mCompileTarget = getChild("compile_target"); + mScriptEd->mCompileTarget->setCommitCallback([&](LLUICtrl*, const LLSD&) { onCompileTargetChanged(); }); + return LLPreview::postBuild(); } @@ -1857,6 +1895,11 @@ void LLPreviewLSL::saveIfNeeded(bool sync /*= true*/) } } +void LLPreviewLSL::onCompileTargetChanged() +{ + mScriptEd->processKeywords(mScriptEd->mCompileTarget->getValue().asString() == "luau"); +} + // static void LLPreviewLSL::onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType type, void* user_data, S32 status, LLExtStat ext_status) @@ -1969,9 +2012,6 @@ bool LLLiveLSLEditor::postBuild() mRunningCheckbox = getChild("running"); mRunningCheckbox->setCommitCallback([&](LLUICtrl*, const LLSD&) { onRunningCheckboxClicked(); }); - mCompileTarget = getChild("compile_target"); - mCompileTarget->setCommitCallback([&](LLUICtrl*, const LLSD&) { onCompileTargetChanged(); }); - mExperiences = getChild("Experiences..."); mExperiences->setCommitCallback([&](LLUICtrl*, const LLSD&) { experienceChanged(); }); @@ -1984,6 +2024,9 @@ bool LLLiveLSLEditor::postBuild() mScriptEd->mEditor->makePristine(); mScriptEd->mEditor->setFocus(true); + mScriptEd->mCompileTarget = getChild("compile_target"); + mScriptEd->mCompileTarget->setCommitCallback([&](LLUICtrl*, const LLSD&) { onCompileTargetChanged(); }); + return LLPreview::postBuild(); } @@ -2266,7 +2309,7 @@ void LLLiveLSLEditor::draw() // incorrect after a release/claim cycle, but will be // correct after clicking on it. mRunningCheckbox->set(false); - mCompileTarget->clear(); + mScriptEd->mCompileTarget->clear(); } } else if (!object) @@ -2275,7 +2318,7 @@ void LLLiveLSLEditor::draw() // Really ought to put in main window. setTitle(LLTrans::getString("ObjectOutOfRange")); mRunningCheckbox->setEnabled(false); - mCompileTarget->setEnabled(false); + mScriptEd->mCompileTarget->setEnabled(false); // object may have fallen out of range. mHaveRunningInfo = false; } @@ -2390,7 +2433,7 @@ void LLLiveLSLEditor::saveIfNeeded(bool sync /*= true*/) if (!url.empty()) { - std::string compile_target(mCompileTarget->getValue()); + std::string compile_target(mScriptEd->mCompileTarget->getValue()); std::string buffer(mScriptEd->mEditor->getText()); LLUUID old_asset_id = mScriptEd->getAssetID(); @@ -2485,42 +2528,29 @@ void LLLiveLSLEditor::processScriptRunningReply(LLMessageSystem* msg, void**) compile_target = "lsl2"; } - instance->mCompileTarget->setValue(compile_target); + instance->mScriptEd->mCompileTarget->setValue(compile_target); instance->mScriptEd->processKeywords(luau && luau_language); // Use Luau syntax highlighting for Luau scripts - bool lua_scripts_enabled = false; - - LLViewerObject* object = gObjectList.findObject(object_id); - if (object) - { - LLViewerRegion* region = object->getRegion(); - if (region && region->simulatorFeaturesReceived()) - { - LLSD simulatorFeatures; - region->getSimulatorFeatures(simulatorFeatures); - lua_scripts_enabled = simulatorFeatures["LuaScriptsEnabled"].asBoolean(); - } - } - - if (LLScrollListItem* luau_item = instance->mCompileTarget->findItemByValue("luau")) + bool lua_scripts_enabled = have_lua_enabled(object_id); + if (LLScrollListItem* luau_item = instance->mScriptEd->mCompileTarget->findItemByValue("luau")) { luau_item->setEnabled(lua_scripts_enabled); } - if (LLScrollListItem* lsl_luau_item = instance->mCompileTarget->findItemByValue("lsl-luau")) + if (LLScrollListItem* lsl_luau_item = instance->mScriptEd->mCompileTarget->findItemByValue("lsl-luau")) { lsl_luau_item->setEnabled(lua_scripts_enabled); } - instance->mCompileTarget->setEnabled(instance->getIsModifiable() && have_script_upload_cap(object_id)); + instance->mScriptEd->mCompileTarget->setEnabled(instance->getIsModifiable() && have_script_upload_cap(object_id)); } } void LLLiveLSLEditor::onCompileTargetChanged() { - mCompileTarget->setEnabled(have_script_upload_cap(mObjectUUID)); + mScriptEd->mCompileTarget->setEnabled(have_script_upload_cap(mObjectUUID)); mScriptEd->enableSave(getIsModifiable()); - mScriptEd->processKeywords(mCompileTarget->getValue().asString() == "luau"); + mScriptEd->processKeywords(mScriptEd->mCompileTarget->getValue().asString() == "luau"); } void LLLiveLSLEditor::setAssociatedExperience( LLHandle editor, const LLSD& experience ) -- cgit v1.3 From 359f604a8d92294c782f41a4383ffe6f63753589 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Thu, 6 Mar 2025 02:00:03 +0200 Subject: #3615 WIP: Store correct script compile target in inventory --- indra/newview/llpreviewscript.cpp | 3 ++- indra/newview/llviewerassetupload.cpp | 6 +++--- indra/newview/llviewerassetupload.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'indra/newview/llpreviewscript.cpp') diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp index 82cb419c17..28988f9564 100644 --- a/indra/newview/llpreviewscript.cpp +++ b/indra/newview/llpreviewscript.cpp @@ -1879,11 +1879,12 @@ void LLPreviewLSL::saveIfNeeded(bool sync /*= true*/) mPendingUploads++; if (!url.empty()) { + std::string compile_target(mScriptEd->mCompileTarget->getValue()); std::string buffer(mScriptEd->mEditor->getText()); LLUUID old_asset_id = inv_item->getAssetUUID().isNull() ? mScriptEd->getAssetID() : inv_item->getAssetUUID(); - LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared(mItemUUID, buffer, + LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared(mItemUUID, compile_target, buffer, [old_asset_id](LLUUID itemId, LLUUID, LLUUID, LLSD response) { LLFileSystem::removeFile(old_asset_id, LLAssetType::AT_LSL_TEXT); LLPreviewLSL::finishedLSLUpload(itemId, response); diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp index 1784179237..1e74e32817 100644 --- a/indra/newview/llviewerassetupload.cpp +++ b/indra/newview/llviewerassetupload.cpp @@ -801,10 +801,10 @@ bool LLBufferedAssetUploadInfo::failedUpload(LLSD &result, std::string &reason) //========================================================================= -LLScriptAssetUpload::LLScriptAssetUpload(LLUUID itemId, std::string buffer, invnUploadFinish_f finish, uploadFailed_f failed): +LLScriptAssetUpload::LLScriptAssetUpload(LLUUID itemId, std::string compileTarget, std::string buffer, invnUploadFinish_f finish, uploadFailed_f failed) : LLBufferedAssetUploadInfo(itemId, LLAssetType::AT_LSL_TEXT, buffer, finish, failed), mExerienceId(), - mCompileTarget("mono"), + mCompileTarget(compileTarget), mIsRunning(false) { } @@ -825,7 +825,7 @@ LLSD LLScriptAssetUpload::generatePostBody() if (getTaskId().isNull()) { body["item_id"] = getItemId(); - body["target"] = "mono"; + body["target"] = getCompileTarget(); } else { diff --git a/indra/newview/llviewerassetupload.h b/indra/newview/llviewerassetupload.h index c3c570efb2..3eaba6461d 100644 --- a/indra/newview/llviewerassetupload.h +++ b/indra/newview/llviewerassetupload.h @@ -251,7 +251,7 @@ private: class LLScriptAssetUpload : public LLBufferedAssetUploadInfo { public: - LLScriptAssetUpload(LLUUID itemId, std::string buffer, invnUploadFinish_f finish, uploadFailed_f failed); + LLScriptAssetUpload(LLUUID itemId, std::string compileTarget, std::string buffer, invnUploadFinish_f finish, uploadFailed_f failed); LLScriptAssetUpload(LLUUID taskId, LLUUID itemId, std::string compileTarget, bool isRunning, LLUUID exerienceId, std::string buffer, taskUploadFinish_f finish, uploadFailed_f failed); -- cgit v1.3