summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewscript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llpreviewscript.cpp')
-rwxr-xr-xindra/newview/llpreviewscript.cpp241
1 files changed, 232 insertions, 9 deletions
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 968a912ea2..bd8f65e767 100755
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -86,6 +86,7 @@
#include "lltrans.h"
#include "llviewercontrol.h"
#include "llappviewer.h"
+#include "llexperiencecache.h"
const std::string HELLO_LSL =
"default\n"
@@ -118,6 +119,57 @@ static bool have_script_upload_cap(LLUUID& object_id)
return object && (! object->getRegion()->getCapability("UpdateScriptTask").empty());
}
+class ExperienceAssociationResponder : public LLHTTPClient::Responder
+{
+public:
+ ExperienceAssociationResponder(const LLUUID& parent):mParent(parent)
+ {
+ }
+
+ LLUUID mParent;
+
+ virtual void result(const LLSD& content)
+ {
+
+ LLLiveLSLEditor* scriptCore = LLFloaterReg::findTypedInstance<LLLiveLSLEditor>("preview_scriptedit", mParent);
+
+ if(!scriptCore)
+ return;
+
+ LLUUID id;
+ if(content.has("experience"))
+ {
+ id=content["experience"].asUUID();
+ }
+ scriptCore->setAssociatedExperience(id);
+ }
+
+ virtual void error(U32 status, const std::string& reason)
+ {
+ llinfos << "Failed to look up associated script: " << status << ": " << reason << llendl;
+ }
+
+};
+
+class ExperienceResponder : public LLHTTPClient::Responder
+{
+public:
+ ExperienceResponder(const LLHandle<LLScriptEdCore>& parent):mParent(parent)
+ {
+ }
+
+ LLHandle<LLScriptEdCore> mParent;
+
+ virtual void result(const LLSD& content)
+ {
+ LLScriptEdCore* scriptCore = mParent.get();
+ if(!scriptCore)
+ return;
+
+ scriptCore->setExperienceIds(content["experience_ids"]);
+ }
+};
+
/// ---------------------------------------------------------------------------
/// LLLiveLSLFile
/// ---------------------------------------------------------------------------
@@ -374,12 +426,50 @@ LLScriptEdCore::~LLScriptEdCore()
delete mLiveFile;
}
+void LLScriptEdCore::experienceChanged()
+{
+ if(mAssociatedExperience != mExperiences->getSelectedValue().asUUID())
+ {
+ enableSave(TRUE);
+ getChildView("Save_btn")->setEnabled(TRUE);
+ mAssociatedExperience = mExperiences->getSelectedValue().asUUID();
+ }
+}
+
+void LLScriptEdCore::onToggleExperience( LLUICtrl *ui, void* userdata )
+{
+ LLScriptEdCore* self = (LLScriptEdCore*)userdata;
+
+ LLUUID id;
+ if(self->mExperienceEnabled->get())
+ {
+ if(self->mAssociatedExperience.isNull())
+ {
+ id=self->mExperienceIds.beginArray()->asUUID();
+ }
+ }
+
+ if(id != self->mAssociatedExperience)
+ {
+ self->enableSave(TRUE);
+ }
+ self->setAssociatedExperience(id);
+}
+
BOOL LLScriptEdCore::postBuild()
{
mErrorList = getChild<LLScrollListCtrl>("lsl errors");
mFunctions = getChild<LLComboBox>( "Insert...");
+ mExperiences = getChild<LLComboBox>("Experiences...");
+ mExperiences->setCommitCallback(boost::bind(&LLScriptEdCore::experienceChanged, this));
+
+ mExperienceEnabled = getChild<LLCheckBoxCtrl>("enable_xp");
+
+ childSetCommitCallback("enable_xp", onToggleExperience, this);
+
+
childSetCommitCallback("Insert...", &LLScriptEdCore::onBtnInsertFunction, this);
mEditor = getChild<LLViewerTextEditor>("Script Editor");
@@ -389,6 +479,10 @@ BOOL LLScriptEdCore::postBuild()
childSetAction("Edit_btn", boost::bind(&LLScriptEdCore::openInExternalEditor, this));
initMenu();
+
+
+
+ requestExperiences();
std::vector<std::string> funcs;
@@ -1191,6 +1285,107 @@ bool LLScriptEdCore::enableLoadFromFileMenu(void* userdata)
return (self && self->mEditor) ? self->mEditor->canLoadOrSaveToFile() : FALSE;
}
+LLUUID LLScriptEdCore::getAssociatedExperience()const
+{
+ return mAssociatedExperience;
+}
+
+void LLScriptEdCore::setExperienceIds( const LLSD& experience_ids )
+{
+ mExperienceIds=experience_ids;
+ updateExperiencePanel();
+}
+
+
+void LLScriptEdCore::updateExperiencePanel()
+{
+ BOOL editable = mEditor->getEnabled();
+
+ if(mAssociatedExperience.isNull())
+ {
+ mExperienceEnabled->set(FALSE);
+ mExperiences->setVisible(FALSE);
+ if(mExperienceIds.size()>0)
+ {
+ mExperienceEnabled->setEnabled(TRUE);
+ mExperienceEnabled->setToolTip(getString("add_experiences"));
+ }
+ else
+ {
+ mExperienceEnabled->setEnabled(FALSE);
+ mExperienceEnabled->setToolTip(getString("no_experiences"));
+ }
+ getChild<LLButton>("view_profile")->setVisible(FALSE);
+ }
+ else
+ {
+ mExperienceEnabled->setToolTip(getString("experience_enabled"));
+ mExperienceEnabled->setEnabled(editable);
+ mExperienceEnabled->set(TRUE);
+ mExperiences->setVisible(TRUE);
+ getChild<LLButton>("view_profile")->setVisible(TRUE);
+ buildExperienceList();
+ }
+}
+
+void LLScriptEdCore::addExperienceInfo(const LLSD& experience, BOOL enabled)
+{
+ LLUUID id = experience[LLExperienceCache::EXPERIENCE_ID].asUUID();
+ EAddPosition position = (id == mAssociatedExperience)?ADD_TOP:ADD_BOTTOM;
+ LLScrollListItem* item=mExperiences->add(experience[LLExperienceCache::NAME], id, position );
+ if(!enabled)
+ {
+ item->setEnabled(FALSE);
+ }
+}
+
+void LLScriptEdCore::buildExperienceList()
+{
+ mExperiences->clear();
+ bool foundAssociated=false;
+ for(LLSD::array_const_iterator it = mExperienceIds.beginArray(); it != mExperienceIds.endArray(); ++it)
+ {
+ LLUUID id = it->asUUID();
+ foundAssociated |= (id == mAssociatedExperience);
+ LLExperienceCache::get(id, boost::bind(&LLScriptEdCore::addExperienceInfo, this, _1, TRUE));
+ }
+
+ if(!foundAssociated )
+ {
+ LLExperienceCache::get(mAssociatedExperience, boost::bind(&LLScriptEdCore::addExperienceInfo, this, _1, FALSE));
+ }
+
+}
+
+
+void LLScriptEdCore::setAssociatedExperience( const LLUUID& experience_id )
+{
+ mAssociatedExperience = experience_id;
+ updateExperiencePanel();
+}
+
+
+
+void LLScriptEdCore::requestExperiences()
+{
+ if (!mEditor->getEnabled())
+ {
+ return;
+ }
+
+ LLViewerRegion* region = gAgent.getRegion();
+ if (region)
+ {
+ std::string lookup_url=region->getCapability("GetCreatorExperiences");
+ if(!lookup_url.empty())
+ {
+ LLHTTPClient::get(lookup_url, new ExperienceResponder(getDerivedHandle<LLScriptEdCore>()));
+ }
+ }
+}
+
+
+
/// ---------------------------------------------------------------------------
/// LLScriptEdContainer
/// ---------------------------------------------------------------------------
@@ -1860,7 +2055,7 @@ void LLLiveLSLEditor::loadAsset()
LLHost host(object->getRegion()->getIP(),
object->getRegion()->getPort());
gMessageSystem->sendReliable(host);
- */
+ */
}
}
else
@@ -1893,11 +2088,15 @@ void LLLiveLSLEditor::onLoadComplete(LLVFS *vfs, const LLUUID& asset_id,
lldebugs << "LLLiveLSLEditor::onLoadComplete: got uuid " << asset_id
<< llendl;
LLUUID* xored_id = (LLUUID*)user_data;
-
+
+
LLLiveLSLEditor* instance = LLFloaterReg::findTypedInstance<LLLiveLSLEditor>("preview_scriptedit", *xored_id);
if(instance )
{
+ instance->fetchAssociatedExperience(asset_id);
+
+
if( LL_ERR_NOERR == status )
{
instance->loadScriptText(vfs, asset_id, type);
@@ -2146,8 +2345,8 @@ void LLLiveLSLEditor::saveIfNeeded(bool sync /*= true*/)
mPendingUploads++;
BOOL is_running = getChild<LLCheckBoxCtrl>( "running")->get();
if (!url.empty())
- {
- uploadAssetViaCaps(url, filename, mObjectUUID, mItemUUID, is_running);
+ {
+ uploadAssetViaCaps(url, filename, mObjectUUID, mItemUUID, is_running, mScriptEd->getAssociatedExperience());
}
else if (gAssetStorage)
{
@@ -2155,11 +2354,7 @@ void LLLiveLSLEditor::saveIfNeeded(bool sync /*= true*/)
}
}
-void LLLiveLSLEditor::uploadAssetViaCaps(const std::string& url,
- const std::string& filename,
- const LLUUID& task_id,
- const LLUUID& item_id,
- BOOL is_running)
+void LLLiveLSLEditor::uploadAssetViaCaps( const std::string& url, const std::string& filename, const LLUUID& task_id, const LLUUID& item_id, BOOL is_running, const LLUUID& experience_public_id )
{
llinfos << "Update Task Inventory via capability " << url << llendl;
LLSD body;
@@ -2167,6 +2362,7 @@ void LLLiveLSLEditor::uploadAssetViaCaps(const std::string& url,
body["item_id"] = item_id;
body["is_script_running"] = is_running;
body["target"] = monoChecked() ? "mono" : "lsl2";
+ body["experience"] = experience_public_id;
LLHTTPClient::post(url, body,
new LLUpdateTaskInventoryResponder(body, filename, LLAssetType::AT_LSL_TEXT));
}
@@ -2347,6 +2543,25 @@ void LLLiveLSLEditor::onSaveBytecodeComplete(const LLUUID& asset_uuid, void* use
delete data;
}
+void LLLiveLSLEditor::fetchAssociatedExperience(const LLUUID& asset_id)
+{
+ LLViewerRegion* region = gAgent.getRegion();
+ if (region)
+ {
+ std::string lookup_url=region->getCapability("GetMetadata");
+ if(!lookup_url.empty())
+ {
+ LLSD request;
+ request["asset-id"]=asset_id;
+ LLSD fields;
+ fields.append("experience");
+ request["fields"] = fields;
+ LLHTTPClient::post(lookup_url, request, new ExperienceAssociationResponder(getKey()));
+ }
+ }
+}
+
+
BOOL LLLiveLSLEditor::canClose()
{
return (mScriptEd->canClose());
@@ -2418,3 +2633,11 @@ BOOL LLLiveLSLEditor::monoChecked() const
}
return FALSE;
}
+
+void LLLiveLSLEditor::setAssociatedExperience( const LLUUID& experience_id )
+{
+ if(mScriptEd)
+ {
+ mScriptEd->setAssociatedExperience(experience_id);
+ }
+}