Fix the particle editor

master
Ansariel 2025-08-19 13:34:08 +02:00
parent 70768b815f
commit 1227e538b1
2 changed files with 103 additions and 122 deletions

View File

@ -22,8 +22,6 @@
#include "llviewerprecompiledheaders.h"
#include "particleeditor.h"
#include <fstream>
#include "llagent.h"
#include "llappviewer.h"
#include "llcheckboxctrl.h"
@ -47,10 +45,7 @@
#include "llwindow.h"
#include "llviewerassetupload.h"
ParticleEditor::ParticleEditor(const LLSD& key)
: LLFloater(key),
mObject(0),
mParticleScriptInventoryItem(0)
ParticleEditor::ParticleEditor(const LLSD& key) : LLFloater(key)
{
mPatternMap["drop"] = LLPartSysData::LL_PART_SRC_PATTERN_DROP;
mPatternMap["explode"] = LLPartSysData::LL_PART_SRC_PATTERN_EXPLODE;
@ -325,11 +320,11 @@ void ParticleEditor::updateUI()
bool targetLinear = mTargetLinearCheckBox->getValue();
bool interpolateColor = mInterpolateColorCheckBox->getValue();
bool interpolateScale = mInterpolateScaleCheckBox->getValue();
bool targetEnabled = targetLinear | (mTargetPositionCheckBox->getValue().asBoolean() ? true : false);
bool targetEnabled = targetLinear || (mTargetPositionCheckBox->getValue().asBoolean() ? true : false);
mBurstRadiusSpinner->setEnabled(!(targetLinear | (mFollowSourceCheckBox->getValue().asBoolean() ? true : false) | dropPattern));
mBurstSpeedMinSpinner->setEnabled(!(targetLinear | dropPattern));
mBurstSpeedMaxSpinner->setEnabled(!(targetLinear | dropPattern));
mBurstRadiusSpinner->setEnabled(!targetLinear && !(mFollowSourceCheckBox->getValue().asBoolean() ? true : false) && !dropPattern);
mBurstSpeedMinSpinner->setEnabled(!targetLinear && !dropPattern);
mBurstSpeedMaxSpinner->setEnabled(!targetLinear && !dropPattern);
// disabling a color swatch does nothing visually, so we also set alpha
LLColor4 endColor = mEndColorSelector->get();
@ -355,8 +350,8 @@ void ParticleEditor::updateUI()
mOmegaYSpinner->setEnabled(!targetLinear);
mOmegaZSpinner->setEnabled(!targetLinear);
mAngleBeginSpinner->setEnabled(!(explodePattern | dropPattern));
mAngleEndSpinner->setEnabled(!(explodePattern | dropPattern));
mAngleBeginSpinner->setEnabled(!explodePattern && !dropPattern);
mAngleEndSpinner->setEnabled(!explodePattern && !dropPattern);
}
void ParticleEditor::onClearTargetButtonClicked()
@ -369,15 +364,13 @@ void ParticleEditor::onTargetPickerButtonClicked()
{
mPickTargetButton->setToggleState(true);
mPickTargetButton->setEnabled(false);
startPicking(this);
startPicking();
}
// inspired by the LLFloaterReporter object picker
// static
void ParticleEditor::startPicking(void* userdata)
void ParticleEditor::startPicking()
{
ParticleEditor* self = (ParticleEditor*) userdata;
LLToolObjPicker::getInstance()->setExitCallback(ParticleEditor::onTargetPicked, self);
LLToolObjPicker::getInstance()->setExitCallback(ParticleEditor::onTargetPicked, this);
LLToolMgr::getInstance()->setTransientTool(LLToolObjPicker::getInstance());
}
@ -386,14 +379,12 @@ void ParticleEditor::onTargetPicked(void* userdata)
{
ParticleEditor* self = (ParticleEditor*)userdata;
LLUUID picked = LLToolObjPicker::getInstance()->getObjectID();
LLToolMgr::getInstance()->clearTransientTool();
self->mPickTargetButton->setEnabled(true);
self->mPickTargetButton->setToggleState(false);
if (picked.notNull())
if (LLUUID picked = LLToolObjPicker::getInstance()->getObjectID(); picked.notNull())
{
self->mTargetKeyInput->setValue(picked.asString());
self->onParameterChange();
@ -522,8 +513,7 @@ default\n\
void ParticleEditor::onCopyButtonClicked()
{
std::string script = createScript();
if (!script.empty())
if (std::string script = createScript(); !script.empty())
{
getWindow()->copyTextToClipboard(utf8str_to_wstring(script));
LLNotificationsUtil::add("ParticleScriptCopiedToClipboard");
@ -608,9 +598,7 @@ void ParticleEditor::callbackReturned(const LLUUID& inventoryItemID)
gInventory.notifyObservers();
//caps import
std::string url = gAgent.getRegionCapability("UpdateScriptAgent");
if (!url.empty())
if (std::string url = gAgent.getRegionCapability("UpdateScriptAgent"); !url.empty())
{
std::string script = createScript();
@ -633,30 +621,23 @@ void ParticleEditor::callbackReturned(const LLUUID& inventoryItemID)
void ParticleEditor::scriptInjectReturned()
{
setCanClose(true);
mMainPanel->setEnabled(true);
// play it safe, because some time may have passed
LLViewerObject* object = gObjectList.findObject(mObject->getID());
if (!object || mObject->isDead())
if (LLViewerObject* object = gObjectList.findObject(mObject->getID()); object && mObject&& !mObject->isDead())
{
mObject->saveScript(mParticleScriptInventoryItem, true, false);
LLNotificationsUtil::add("ParticleScriptInjected");
}
else
{
LL_WARNS() << "Can't inject script - object is dead or went away!" << LL_ENDL;
mMainPanel->setEnabled(true);
return;
}
mObject->saveScript(mParticleScriptInventoryItem, true, false);
LLNotificationsUtil::add("ParticleScriptInjected");
delete this;
}
// ---------------------------------- Callbacks ----------------------------------
ParticleScriptCreationCallback::ParticleScriptCreationCallback(ParticleEditor* editor)
{
mEditor = editor;
}
ParticleScriptCreationCallback::~ParticleScriptCreationCallback()
ParticleScriptCreationCallback::ParticleScriptCreationCallback(ParticleEditor* editor) : mEditor(editor)
{
}

View File

@ -43,117 +43,117 @@ class ParticleEditor : public LLFloater
friend class ParticleScriptCreationCallback;
friend class ParticleScriptUploadResponder;
public:
ParticleEditor(const LLSD& key);
~ParticleEditor();
public:
ParticleEditor(const LLSD& key);
~ParticleEditor();
bool postBuild() override;
bool postBuild() override;
void setObject(LLViewerObject* objectp);
void scriptInjectReturned( );
void setObject(LLViewerObject* objectp);
void scriptInjectReturned();
protected:
void clearParticles();
void updateParticles();
void updateUI();
protected:
void clearParticles();
void updateParticles();
void updateUI();
std::string createScript();
void createScriptInventoryItem(LLUUID categoryID);
std::string createScript();
void createScriptInventoryItem(LLUUID categoryID);
void onParameterChange();
void onCopyButtonClicked();
void onInjectButtonClicked();
void onParameterChange();
void onCopyButtonClicked();
void onInjectButtonClicked();
void onClearTargetButtonClicked();
void onTargetPickerButtonClicked();
static void startPicking(void* userdata);
static void onTargetPicked(void* userdata);
void onClearTargetButtonClicked();
void onTargetPickerButtonClicked();
void startPicking();
static void onTargetPicked(void* userdata);
void callbackReturned(const LLUUID& inv_item);
void callbackReturned(const LLUUID& inv_item);
std::string lslVector(F32 x, F32 y, F32 z);
std::string lslColor(const LLColor4& color);
std::string lslVector(F32 x, F32 y, F32 z);
std::string lslColor(const LLColor4& color);
LLViewerObject* mObject;
LLViewerTexture* mTexture;
LLViewerInventoryItem* mParticleScriptInventoryItem;
LLViewerObject* mObject{ nullptr };
LLViewerTexture* mTexture{ nullptr };
LLViewerInventoryItem* mParticleScriptInventoryItem{ nullptr };
LLViewerTexture* mDefaultParticleTexture;
LLViewerTexture* mDefaultParticleTexture{ nullptr };
LLPartSysData mParticles;
LLPartSysData mParticles;
std::map<std::string, U8> mPatternMap;
std::map<std::string, std::string> mScriptPatternMap;
std::map<std::string, U8> mPatternMap;
std::map<std::string, std::string> mScriptPatternMap;
std::map<std::string, U8> mBlendMap;
std::map<std::string, std::string> mScriptBlendMap;
std::map<std::string, U8> mBlendMap;
std::map<std::string, std::string> mScriptBlendMap;
LLPanel* mMainPanel;
LLPanel* mMainPanel{ nullptr };
LLComboBox* mPatternTypeCombo;
LLTextureCtrl* mTexturePicker;
LLComboBox* mPatternTypeCombo{ nullptr };
LLTextureCtrl* mTexturePicker{ nullptr };
LLSpinCtrl* mBurstRateSpinner;
LLSpinCtrl* mBurstCountSpinner;
LLSpinCtrl* mBurstRadiusSpinner;
LLSpinCtrl* mAngleBeginSpinner;
LLSpinCtrl* mAngleEndSpinner;
LLSpinCtrl* mBurstSpeedMinSpinner;
LLSpinCtrl* mBurstSpeedMaxSpinner;
LLSpinCtrl* mStartAlphaSpinner;
LLSpinCtrl* mEndAlphaSpinner;
LLSpinCtrl* mScaleStartXSpinner;
LLSpinCtrl* mScaleStartYSpinner;
LLSpinCtrl* mScaleEndXSpinner;
LLSpinCtrl* mScaleEndYSpinner;
LLSpinCtrl* mSourceMaxAgeSpinner;
LLSpinCtrl* mParticlesMaxAgeSpinner;
LLSpinCtrl* mStartGlowSpinner;
LLSpinCtrl* mEndGlowSpinner;
LLSpinCtrl* mBurstRateSpinner{ nullptr };
LLSpinCtrl* mBurstCountSpinner{ nullptr };
LLSpinCtrl* mBurstRadiusSpinner{ nullptr };
LLSpinCtrl* mAngleBeginSpinner{ nullptr };
LLSpinCtrl* mAngleEndSpinner{ nullptr };
LLSpinCtrl* mBurstSpeedMinSpinner{ nullptr };
LLSpinCtrl* mBurstSpeedMaxSpinner{ nullptr };
LLSpinCtrl* mStartAlphaSpinner{ nullptr };
LLSpinCtrl* mEndAlphaSpinner{ nullptr };
LLSpinCtrl* mScaleStartXSpinner{ nullptr };
LLSpinCtrl* mScaleStartYSpinner{ nullptr };
LLSpinCtrl* mScaleEndXSpinner{ nullptr };
LLSpinCtrl* mScaleEndYSpinner{ nullptr };
LLSpinCtrl* mSourceMaxAgeSpinner{ nullptr };
LLSpinCtrl* mParticlesMaxAgeSpinner{ nullptr };
LLSpinCtrl* mStartGlowSpinner{ nullptr };
LLSpinCtrl* mEndGlowSpinner{ nullptr };
LLComboBox* mBlendFuncSrcCombo;
LLComboBox* mBlendFuncDestCombo;
LLComboBox* mBlendFuncSrcCombo{ nullptr };
LLComboBox* mBlendFuncDestCombo{ nullptr };
LLCheckBoxCtrl* mBounceCheckBox;
LLCheckBoxCtrl* mEmissiveCheckBox;
LLCheckBoxCtrl* mFollowSourceCheckBox;
LLCheckBoxCtrl* mFollowVelocityCheckBox;
LLCheckBoxCtrl* mInterpolateColorCheckBox;
LLCheckBoxCtrl* mInterpolateScaleCheckBox;
LLCheckBoxCtrl* mTargetPositionCheckBox;
LLCheckBoxCtrl* mTargetLinearCheckBox;
LLCheckBoxCtrl* mWindCheckBox;
LLCheckBoxCtrl* mRibbonCheckBox;
LLCheckBoxCtrl* mBounceCheckBox{ nullptr };
LLCheckBoxCtrl* mEmissiveCheckBox{ nullptr };
LLCheckBoxCtrl* mFollowSourceCheckBox{ nullptr };
LLCheckBoxCtrl* mFollowVelocityCheckBox{ nullptr };
LLCheckBoxCtrl* mInterpolateColorCheckBox{ nullptr };
LLCheckBoxCtrl* mInterpolateScaleCheckBox{ nullptr };
LLCheckBoxCtrl* mTargetPositionCheckBox{ nullptr };
LLCheckBoxCtrl* mTargetLinearCheckBox{ nullptr };
LLCheckBoxCtrl* mWindCheckBox{ nullptr };
LLCheckBoxCtrl* mRibbonCheckBox{ nullptr };
LLLineEditor* mTargetKeyInput;
LLButton* mClearTargetButton;
LLButton* mPickTargetButton;
LLLineEditor* mTargetKeyInput{ nullptr };
LLButton* mClearTargetButton{ nullptr };
LLButton* mPickTargetButton{ nullptr };
LLSpinCtrl* mAcellerationXSpinner;
LLSpinCtrl* mAcellerationYSpinner;
LLSpinCtrl* mAcellerationZSpinner;
LLSpinCtrl* mAcellerationXSpinner{ nullptr };
LLSpinCtrl* mAcellerationYSpinner{ nullptr };
LLSpinCtrl* mAcellerationZSpinner{ nullptr };
LLSpinCtrl* mOmegaXSpinner;
LLSpinCtrl* mOmegaYSpinner;
LLSpinCtrl* mOmegaZSpinner;
LLSpinCtrl* mOmegaXSpinner{ nullptr };
LLSpinCtrl* mOmegaYSpinner{ nullptr };
LLSpinCtrl* mOmegaZSpinner{ nullptr };
LLColorSwatchCtrl* mStartColorSelector;
LLColorSwatchCtrl* mEndColorSelector;
LLColorSwatchCtrl* mStartColorSelector{ nullptr };
LLColorSwatchCtrl* mEndColorSelector{ nullptr };
LLButton* mCopyToLSLButton;
LLButton* mInjectScriptButton;
LLButton* mCopyToLSLButton{ nullptr };
LLButton* mInjectScriptButton{ nullptr };
};
class ParticleScriptCreationCallback : public LLInventoryCallback
{
public:
ParticleScriptCreationCallback(ParticleEditor* editor);
void fire(const LLUUID& inventoryItem);
public:
ParticleScriptCreationCallback(ParticleEditor* editor);
void fire(const LLUUID& inventoryItem);
protected:
~ParticleScriptCreationCallback();
protected:
~ParticleScriptCreationCallback() = default;
ParticleEditor* mEditor;
ParticleEditor* mEditor;
};
#endif // PARTICLEEDITOR_H