Merge pull request #760 from Areloch/ForestBrushGroupToolingFixes

Fixes tooling of Forest Editor to be module-friendly
This commit is contained in:
Brian Roberts 2022-04-08 01:29:06 -05:00 committed by GitHub
commit be3be2eb7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 177 additions and 88 deletions

View file

@ -68,6 +68,8 @@ namespace Sim
ImplementNamedSet(SFXAmbienceSet)
ImplementNamedSet(TerrainMaterialSet)
ImplementNamedSet(DataBlockSet);
ImplementNamedSet(ForestBrushSet);
ImplementNamedSet(ForestItemDataSet);
ImplementNamedGroup(ActionMapGroup)
ImplementNamedGroup(ClientGroup)
ImplementNamedGroup(GuiGroup)

View file

@ -107,6 +107,8 @@ namespace Sim
DeclareNamedSet(SFXAmbienceSet);
DeclareNamedSet(TerrainMaterialSet);
DeclareNamedSet(DataBlockSet);
DeclareNamedSet(ForestBrushSet);
DeclareNamedSet(ForestItemDataSet);
DeclareNamedGroup(ActionMapGroup)
DeclareNamedGroup(ClientGroup)
DeclareNamedGroup(GuiGroup)

View file

@ -565,6 +565,8 @@ void init()
InstantiateNamedSet(SFXAmbienceSet);
InstantiateNamedSet(TerrainMaterialSet);
InstantiateNamedSet(DataBlockSet);
InstantiateNamedSet(ForestBrushSet);
InstantiateNamedSet(ForestItemDataSet);
InstantiateNamedGroup(ActionMapGroup);
InstantiateNamedGroup(ClientGroup);
InstantiateNamedGroup(GuiGroup);

View file

@ -197,4 +197,78 @@ DefineEngineMethod( ForestBrush, containsItemData, bool, ( const char * obj ), ,
}
return object->containsItemData( data );
}
}
//-------------------------------------------------------------------------
// ForestBrushGroupSet
//-------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(ForestBrushGroup);
ConsoleDocClass(ForestBrushGroup,
"@brief Container class for ForestBrushes\n\n"
"Editor use only.\n\n"
"@internal"
);
ForestBrushGroup::ForestBrushGroup()
{
}
bool ForestBrushGroup::onAdd()
{
if (!Parent::onAdd())
return false;
SimSet* forestBrushSet;
if (!Sim::findObject("ForestBrushSet", forestBrushSet))
{
Con::errorf("ForestBrushGroup::onAdd() - failed to find ForestBrushSet to add new ForestBrushGroup to!");
}
forestBrushSet->addObject(this);
return true;
}
void ForestBrushGroup::addObject(SimObject* inObj)
{
ForestBrush* ele = dynamic_cast<ForestBrush*>(inObj);
if (!ele)
return;
//if ( containsItemData( ele->mData ) )
// return;
Parent::addObject(inObj);
}
bool ForestBrushGroup::containsBrushData(const ForestBrush* inData)
{
SimObjectList::iterator iter = mObjectList.begin();
for (; iter != mObjectList.end(); iter++)
{
ForestBrush* pElement = dynamic_cast<ForestBrush*>(*iter);
if (!pElement)
continue;
if (pElement == inData)
return true;
}
return false;
}
DefineEngineMethod(ForestBrushGroup, containsBrushData, bool, (const char* obj), , "( ForestBrush obj )")
{
ForestBrush* data = NULL;
if (!Sim::findObject(obj, data))
{
Con::warnf("ForestBrush::containsBrushData - invalid object passed");
return false;
}
return object->containsBrushData(data);
}

View file

@ -121,5 +121,28 @@ protected:
static SimObjectPtr<SimGroup> smGroup;
};
//-------------------------------------------------------------------------
// ForestBrushGroup
//-------------------------------------------------------------------------
#endif // _FOREST_EDITOR_BRUSHELEMENT_H_
class ForestBrushGroup : public SimGroup
{
typedef SimGroup Parent;
public:
ForestBrushGroup();
DECLARE_CONOBJECT(ForestBrushGroup);
virtual bool onAdd();
virtual void addObject(SimObject*);
bool containsBrushData(const ForestBrush* inData);
protected:
static SimObjectPtr<SimGroup> smGroup;
};
#endif // _FOREST_EDITOR_BRUSHELEMENT_H_

View file

@ -610,9 +610,14 @@ void ForestBrushTool::_collectElements()
}
// Find all ForestBrushElements that are directly or indirectly selected.
SimSet* brushSet;
if (!Sim::findObject("ForestBrushSet", brushSet))
{
Con::errorf("ForestBrushTool::_collectElements() - could not find ForestBrushSet!");
return;
}
SimGroup *brushGroup = ForestBrush::getGroup();
brushGroup->findObjectByCallback( findSelectedElements, mElements );
brushSet->findObjectByCallback( findSelectedElements, mElements );
// We just needed to flag these objects as selected for the benefit of our
// findSelectedElements callback, we can now mark them un-selected again.

View file

@ -328,10 +328,16 @@ void ForestEditorCtrl::deleteMeshSafe( ForestItemData *mesh )
}
// Find ForestBrushElement(s) referencing this datablock.
SimGroup *brushGroup = ForestBrush::getGroup();
SimSet* brushSet;
if (!Sim::findObject("ForestBrushSet", brushSet))
{
Con::errorf("ForestBrushTool::_collectElements() - could not find ForestBrushSet!");
return;
}
sKey = mesh;
Vector<SimObject*> foundElements;
brushGroup->findObjectByCallback( &findMeshReferences, foundElements );
brushSet->findObjectByCallback( &findMeshReferences, foundElements );
// Add UndoAction to delete the ForestBrushElement(s) and the ForestItemData.
MEDeleteUndoAction *elementAction = new MEDeleteUndoAction();
@ -408,4 +414,4 @@ DefineEngineMethod(ForestEditorCtrl, setActiveForest, void, (const char * obj),
return;
object->setActiveForest(forestObject);
}
}