Skip to content

Commit dcc3b49

Browse files
authored
Merge pull request #1717 from Areloch/MiscParticleEdFixes
Implements misc fixes for the particle editor and particlesList inspector field
2 parents 12dddd0 + defbaea commit dcc3b49

7 files changed

Lines changed: 145 additions & 45 deletions

File tree

Engine/source/T3D/fx/particle.cpp

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -907,14 +907,17 @@ GuiControl* GuiInspectorTypeParticleDataList::constructEditControl()
907907
mNewParticleBtn->registerObject();
908908
mNewParticleBtn->_setBitmap(StringTable->insert("ToolsModule:iconAdd_image"));
909909
mNewParticleBtn->setDataField(StringTable->insert("profile"), NULL, "ToolsGuiDefaultProfile");
910+
mNewParticleBtn->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
911+
mNewParticleBtn->setDataField(StringTable->insert("hovertime"), NULL, "1000");
912+
mNewParticleBtn->setDataField(StringTable->insert("tooltip"), NULL, "Add new particle slot");
910913
mNewParticleBtn->setHorizSizing(horizResizeRight);
911914
mNewParticleBtn->mMakeIconSquare = true;
912915
mNewParticleBtn->mFitBitmapToButton = true;
913916
mNewParticleBtn->setExtent(20, 20);
914917

915918
char szBuffer[512];
916919
dSprintf(szBuffer, sizeof(szBuffer), "ParticleEditor.addParticleSlot(%s, %s);",
917-
mNewParticleBtn->getIdString(), mInspector->getInspectObject()->getIdString());
920+
this->getIdString(), mInspector->getInspectObject()->getIdString());
918921
mNewParticleBtn->setField("Command", szBuffer);
919922

920923
GuiContainer* newBtnCtnr = new GuiContainer();
@@ -924,39 +927,16 @@ GuiControl* GuiInspectorTypeParticleDataList::constructEditControl()
924927

925928
mStack->addObject(newBtnCtnr);
926929

927-
//Particle 0
928-
mParticleSlot0Ctrl = _buildParticleEntryField(0);
929-
930-
mStack->addObject(mParticleSlot0Ctrl);
931-
932-
//Now the non-default entries if we already have some
933-
Parent::updateValue();
934-
const char* data = getData();
935-
936-
if (data != NULL && !String::isEmpty(data))
937-
{
938-
U32 particlesCount = StringUnit::getUnitCount(data, " ");
939-
for (U32 i=1; i < particlesCount; i++)
940-
{
941-
GuiControl* particleSlotCtrl = _buildParticleEntryField(i);
942-
mStack->addObject(particleSlotCtrl);
943-
}
944-
}
930+
_rebuildParticleEntryList();
945931

946932
_registerEditControl(mStack);
947933

948-
//constructEditControlChildren(retCtrl, getWidth());
949-
950-
//retCtrl->addObject(mScriptValue);
951-
952-
/*char szBuffer[512];
953-
dSprintf(szBuffer, 512, "setClipboard(%d.getText());", mScriptValue->getId());
954-
mCopyButton->setField("Command", szBuffer);
955-
addObject(mCopyButton);*/
956-
957934
mUseHeightOverride = true;
958935
mHeightOverride = (mStack->getCount() * 23) + 6;
959936

937+
//Now the non-default entries if we already have some
938+
//Parent::updateValue();
939+
960940
return mStack;
961941
}
962942

@@ -980,7 +960,7 @@ GuiControl* GuiInspectorTypeParticleDataList::_buildParticleEntryField(const S32
980960

981961
char szBuffer[512];
982962
dSprintf(szBuffer, sizeof(szBuffer), "ParticleEditor.changeParticleSlot(%s, %s, %d);",
983-
listBtn->getIdString(), mInspector->getInspectObject()->getIdString(), index);
963+
this->getIdString(), mInspector->getInspectObject()->getIdString(), index);
984964
listBtn->setField("Command", szBuffer);
985965

986966
if (mField && index != -1)
@@ -1001,6 +981,9 @@ GuiControl* GuiInspectorTypeParticleDataList::_buildParticleEntryField(const S32
1001981
editSlotBtn->registerObject();
1002982
editSlotBtn->setText(StringTable->insert("..."));
1003983
editSlotBtn->setDataField(StringTable->insert("profile"), NULL, "ToolsGuiButtonProfile");
984+
editSlotBtn->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
985+
editSlotBtn->setDataField(StringTable->insert("hovertime"), NULL, "1000");
986+
editSlotBtn->setDataField(StringTable->insert("tooltip"), NULL, "Edit this particle");
1004987
editSlotBtn->setHorizSizing(horizResizeRight);
1005988
editSlotBtn->setInternalName("editBtn");
1006989
editSlotBtn->setPosition(editExtent.x - 40, 0);
@@ -1019,6 +1002,9 @@ GuiControl* GuiInspectorTypeParticleDataList::_buildParticleEntryField(const S32
10191002
deleteSlotBtn->registerObject();
10201003
deleteSlotBtn->_setBitmap(StringTable->insert("ToolsModule:iconCancel_image"));
10211004
deleteSlotBtn->setDataField(StringTable->insert("profile"), NULL, "ToolsGuiDefaultProfile");
1005+
deleteSlotBtn->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
1006+
deleteSlotBtn->setDataField(StringTable->insert("hovertime"), NULL, "1000");
1007+
deleteSlotBtn->setDataField(StringTable->insert("tooltip"), NULL, "Delete this particle slot");
10221008
deleteSlotBtn->setHorizSizing(horizResizeRight);
10231009
deleteSlotBtn->setInternalName("deleteBtn");
10241010
deleteSlotBtn->mMakeIconSquare = true;
@@ -1062,6 +1048,38 @@ void GuiInspectorTypeParticleDataList::_populateMenu(GuiPopUpMenuCtrlEx* menu)
10621048
menu->sort();
10631049
}
10641050

1051+
void GuiInspectorTypeParticleDataList::_rebuildParticleEntryList()
1052+
{
1053+
const char* data = getData();
1054+
1055+
//whoops it's misaligned, force a rebuild
1056+
mParticleSlot0Ctrl = NULL;
1057+
1058+
for (U32 i = 0; i < mParticleSlotList.size(); i++)
1059+
{
1060+
mStack->removeObject(mParticleSlotList[i]);
1061+
mParticleSlotList[i]->deleteObject();
1062+
}
1063+
mParticleSlotList.clear();
1064+
1065+
//Particle 0
1066+
mParticleSlot0Ctrl = _buildParticleEntryField(0);
1067+
mStack->addObject(mParticleSlot0Ctrl);
1068+
mParticleSlotList.push_back(mParticleSlot0Ctrl);
1069+
1070+
if (data != NULL && !String::isEmpty(data))
1071+
{
1072+
U32 particlesCount = StringUnit::getUnitCount(data, " ");
1073+
1074+
for (U32 i = 1; i < particlesCount; i++)
1075+
{
1076+
GuiControl* particleSlotCtrl = _buildParticleEntryField(i);
1077+
mStack->addObject(particleSlotCtrl);
1078+
mParticleSlotList.push_back(particleSlotCtrl);
1079+
}
1080+
}
1081+
}
1082+
10651083
bool GuiInspectorTypeParticleDataList::updateRects()
10661084
{
10671085
S32 rowSize = 18;
@@ -1109,14 +1127,43 @@ bool GuiInspectorTypeParticleDataList::updateRects()
11091127

11101128
mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
11111129

1130+
mUseHeightOverride = true;
11121131
mHeightOverride = (mStack->getCount() * 23) + 6;
11131132

1114-
//mCopyButton->resize(Point2I(mProfile->mTextOffset.x, rowSize + 3), Point2I(45, 15));
1115-
//mPasteButton->resize(Point2I(mProfile->mTextOffset.x, rowSize + rowSize + 6), Point2I(45, 15));
1133+
RectI bnds = getBounds();
1134+
setBounds(bnds.point.x, bnds.point.y, bnds.extent.x, mHeightOverride);
11161135

11171136
return true;
11181137
}
11191138

1139+
void GuiInspectorTypeParticleDataList::updateValue()
1140+
{
1141+
const char* data = getData();
1142+
1143+
if (data != NULL && !String::isEmpty(data))
1144+
{
1145+
U32 particlesCount = StringUnit::getUnitCount(data, " ");
1146+
1147+
if (particlesCount != mParticleSlotList.size())
1148+
{
1149+
_rebuildParticleEntryList();
1150+
}
1151+
else
1152+
{
1153+
for (U32 i = 0; i < particlesCount; i++)
1154+
{
1155+
GuiButtonCtrl* listBtn = dynamic_cast<GuiButtonCtrl*>(mParticleSlotList[i]->getObject(0));
1156+
if (!listBtn) //This *really* shouldn't happen
1157+
continue;
1158+
1159+
const char* particleName = StringUnit::getUnit(data, i, " ");
1160+
listBtn->setText(particleName);
1161+
}
1162+
}
1163+
}
1164+
1165+
updateRects();
1166+
}
11201167

11211168
void GuiInspectorTypeParticleDataList::consoleInit()
11221169
{

Engine/source/T3D/fx/particleInspectors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ class GuiInspectorTypeParticleDataList : public GuiInspectorField
3333

3434
GuiControl* constructEditControl() override;
3535
bool updateRects() override;
36+
void updateValue() override;
3637

3738
void _populateMenu(GuiPopUpMenuCtrlEx* menu);
3839
GuiControl* _buildParticleEntryField(const S32& index);
40+
void _rebuildParticleEntryList();
3941
};
4042
#endif

Templates/BaseGame/game/tools/datablockEditor/datablockEditor.tscript

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ function DatablockEditorPlugin::onExitMission( %this )
111111

112112
function DatablockEditorPlugin::openDatablock( %this, %datablock )
113113
{
114+
//We want to do a special-case catch here for any datablock types that have their own unique editor.
115+
//The main culprit is the particle editor, but this could be expanded later
116+
if(%datablock.isMemberOfClass("ParticleData") ||
117+
%datablock.isMemberOfClass("ParticleEmitterData") ||
118+
%datablock.isMemberOfClass("ExplosionData") ||
119+
%datablock.isMemberOfClass("RibbonData") ||
120+
%datablock.isMemberOfClass("afxZodiacData") ||
121+
%datablock.isMemberOfClass("afxChoreographerData"))
122+
{
123+
EditorGui.setEditor( ParticleEditorPlugin );
124+
return;
125+
}
126+
114127
EditorGui.setEditor( DatablockEditorPlugin );
115128
%this.selectDatablock( %datablock );
116129
DatablockEditorTreeTabBook.selectedPage = 0;
@@ -631,6 +644,21 @@ function DatablockEditorPlugin::deleteDatablock( %this )
631644
//---------------------------------------------------------------------------------------------
632645
function DatablockEditorPlugin::createNewDatablockOfType(%this, %class, %inheritFrom)
633646
{
647+
//We want to do a special-case catch here for any datablock types that have their own unique editor.
648+
//The main culprit is the particle editor, but this could be expanded later
649+
if(%class.isMemberOfClass("ParticleData") ||
650+
%class.isMemberOfClass("ParticleEmitterData") ||
651+
%class.isMemberOfClass("ExplosionData") ||
652+
%class.isMemberOfClass("RibbonData") ||
653+
%class.isMemberOfClass("afxZodiacData") ||
654+
%class.isMemberOfClass("afxChoreographerData"))
655+
{
656+
EditorGui.setEditor( ParticleEditorPlugin );
657+
658+
ParticleEditorPlugin::createNewDatablockOfType(%class, %inheritFrom);
659+
return;
660+
}
661+
634662
$DATABLOCK_EDITOR_NEWDB_CLASS = %class;
635663
$DATABLOCK_EDITOR_NEWDB_INHERITFROM = %inheritFrom;
636664

Templates/BaseGame/game/tools/particleEditor/guis/particleEditor.ed.tscript

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ function ParticleEditor::initEditor( %this )
5151

5252
if(exec("./PETabTemplate.gui"))
5353
{
54-
echo("MADE A NEW TAB PAGE: " @ $guiContent);
55-
5654
$guiContent.text = %groupName;
5755
$guiContent.typesList = %typesList;
5856
$guiContent.setName(%editorName);
@@ -199,7 +197,7 @@ function ParticleEditor::open(%this, %datablock)
199197
for(%t=0; %t < %typesListCount; %t++)
200198
{
201199
%type = getWord(%typesList, %t);
202-
200+
203201
if( %datablock.isMemberOfClass( %type ) )
204202
{
205203
PE_TabBook.selectPage(%i);

Templates/BaseGame/game/tools/particleEditor/main.tscript

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ function ParticleEditorPlugin::onActivated( %this )
113113
EditorGuiStatusBar.setInfo( "Particle editor." );
114114
EditorGuiStatusBar.setSelection( "" );
115115

116+
// Try to start with the object selected in the world editor
117+
%count = EWorldEditor.getSelectionSize();
118+
for (%i = 0; %i < %count; %i++)
119+
{
120+
%obj = EWorldEditor.getSelectedObject(%i);
121+
%datablock = ParticleEditor.getObjectParticleData(%obj);
122+
if (%datablock !$= "" && isObject(%datablock))
123+
{
124+
ParticleEditor.open(%datablock);
125+
break;
126+
}
127+
}
128+
116129
Parent::onActivated( %this );
117130
}
118131

@@ -213,3 +226,12 @@ function ParticleEditor::registerParticleEdType(%this, %groupName, %typesList, %
213226
PE_ParticleDataTypes.add(%groupName, %typesList TAB %editorName);
214227
}
215228

229+
//------------------------------------------------------------------------------
230+
function ParticleEditor::getObjectParticleData( %this, %obj )
231+
{
232+
%datablock = "";
233+
if ( %obj.isMemberOfClass( "ParticleEmitterNode" ) )
234+
%datablock = %obj.emitter;
235+
236+
return %datablock;
237+
}

Templates/BaseGame/game/tools/particleEditor/scripts/particleEmitterEditor.ed.tscript

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ function PE_EmitterEditor::selectObject(%this, %obj)
122122
&& %obj.getName() $= %this-->popupMenu.text )
123123
return;
124124

125-
//FIXME: disregards particle tab dirty state
126125
if( %this.dirty )
127126
{
128127
if( PE_ParticleEditor.dirty )
@@ -483,6 +482,8 @@ function ParticleEditor::addParticleSlot(%this, %field, %emitterObj)
483482
%action.oldValue = %emitterObj.particles;
484483

485484
ParticleEditor.submitUndo( %action );
485+
486+
%field.apply(%action.newValue);
486487
}
487488

488489
function ParticleEditor::changeParticleSlot(%this, %field, %emitterObj, %slotIdx)
@@ -495,7 +496,6 @@ function ParticleEditor::changeParticleSlot(%this, %field, %emitterObj, %slotIdx
495496

496497
foreach( %obj in DatablockGroup )
497498
{
498-
echo(%typesList);
499499
%typesListCount = getWordCount(%typesList);
500500
for(%i=0; %i < %typesListCount; %i++)
501501
{
@@ -552,7 +552,7 @@ function ParticleEditor::changeParticleSlot(%this, %field, %emitterObj, %slotIdx
552552
}
553553
}
554554

555-
ContextedDropdownListGui.show(%listSet, "Edit Particle Slot[" @ %slotIdx @ "]", "ParticleEditor.editSlot = " @ %slotIdx @ ";ParticleEditor.updateParticleSlot", %field);
555+
ContextedDropdownListGui.show(%listSet, "Edit Particle Slot[" @ %slotIdx @ "]", "ParticleEditor.fieldObj = " @ %field @ ";ParticleEditor.editSlot = " @ %slotIdx @ ";ParticleEditor.updateParticleSlot", %field);
556556
%particleData = getWord(%emitterObj.particles, %slotIdx);
557557
if(%particleData !$= "")
558558
{
@@ -562,10 +562,10 @@ function ParticleEditor::changeParticleSlot(%this, %field, %emitterObj, %slotIdx
562562

563563
function ParticleEditor::updateParticleSlot(%this, %newParticle)
564564
{
565-
if(ParticleEditor.editSlot $= "")
565+
if(ParticleEditor.editSlot $= "" || !isObject(%newParticle))
566566
return;
567567

568-
%updatedParticlesList = setWord(PE_EmitterEditor.currEmitter.particles, ParticleEditor.editSlot, %newParticle);
568+
%updatedParticlesList = setWord(PE_EmitterEditor.currEmitter.particles, ParticleEditor.editSlot, %newParticle.getName());
569569

570570
%action = ParticleEditor.createUndo(ActionUpdateActiveEmitter, "Edit Active Emitter Particle Slot");
571571
%action.emitter = PE_EmitterEditor.currEmitter;
@@ -575,16 +575,19 @@ function ParticleEditor::updateParticleSlot(%this, %newParticle)
575575

576576
ParticleEditor.submitUndo( %action );
577577

578-
ParticleEditor.editSlot = "";
578+
ParticleEditor.fieldObj.apply(%action.newValue);
579579

580-
//%field.apply(%updatedParticlesList, %slotIdx);
581-
//%this-->inspector.refresh();
580+
ParticleEditor.editSlot = "";
581+
ParticleEditor.fieldObj = "";
582582
}
583583

584584
function ParticleEditor::editParticleSlot(%this, %field, %emitterObj, %slotIdx)
585585
{
586586
%particleName = getWord(%emitterObj.particles, %slotIdx);
587587

588+
ParticleEditor.editSlot = "";
589+
ParticleEditor.fieldObj = "";
590+
588591
ParticleEditor.open(%particleName);
589592
}
590593

@@ -600,6 +603,5 @@ function ParticleEditor::clearParticleSlot(%this, %field, %emitterObj, %slotIdx)
600603

601604
ParticleEditor.submitUndo( %action );
602605

603-
//%field.apply(%updatedParticlesList, %slotIdx);
604-
//%this-->inspector.refresh();
606+
%field.apply(%action.newValue);
605607
}

Templates/BaseGame/game/tools/particleEditor/scripts/particleParticleEditor.ed.tscript

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function PE_ParticleEditor::updateVizNode(%this)
7474
function PE_ParticleEditor::selectObject(%this, %obj)
7575
{
7676
// Bail if the user selected the same particle.
77-
if( %obj == %this.currParticle )
77+
if( isObject(%obj )
78+
&& %obj.getName() $= %this-->popupMenu.text )
7879
return;
7980

8081
// Load new particle if we're not in a dirty state

0 commit comments

Comments
 (0)