Merge pull request #1205 from Areloch/ForcedArrayIndexInspector

Adds ability to force the inspector to only show a set index of array'd fields.
This commit is contained in:
Brian Roberts 2024-02-04 11:27:50 -06:00 committed by GitHub
commit ceec0dfb5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 232 additions and 145 deletions

View file

@ -50,7 +50,8 @@ GuiInspector::GuiInspector()
mMovingDivider( false ), mMovingDivider( false ),
mHLField( NULL ), mHLField( NULL ),
mShowCustomFields( true ), mShowCustomFields( true ),
mComponentGroupTargetId(-1) mComponentGroupTargetId(-1),
mForcedArrayIndex(-1)
{ {
mPadding = 1; mPadding = 1;
} }
@ -77,6 +78,8 @@ void GuiInspector::initPersistFields()
addField( "showCustomFields", TypeBool, Offset( mShowCustomFields, GuiInspector ), addField( "showCustomFields", TypeBool, Offset( mShowCustomFields, GuiInspector ),
"If false the custom fields Name, Id, and Source Class will not be shown." ); "If false the custom fields Name, Id, and Source Class will not be shown." );
addField("forcedArrayIndex", TypeS32, Offset(mForcedArrayIndex, GuiInspector));
endGroup( "Inspector" ); endGroup( "Inspector" );
Parent::initPersistFields(); Parent::initPersistFields();
@ -622,6 +625,7 @@ void GuiInspector::refresh()
if( !group && !isGroupFiltered( itr->pGroupname ) ) if( !group && !isGroupFiltered( itr->pGroupname ) )
{ {
GuiInspectorGroup *newGroup = new GuiInspectorGroup( itr->pGroupname, this ); GuiInspectorGroup *newGroup = new GuiInspectorGroup( itr->pGroupname, this );
newGroup->setForcedArrayIndex(mForcedArrayIndex);
newGroup->registerObject(); newGroup->registerObject();
if( !newGroup->getNumFields() ) if( !newGroup->getNumFields() )
@ -640,6 +644,10 @@ void GuiInspector::refresh()
addObject(newGroup); addObject(newGroup);
} }
} }
else if(group)
{
group->setForcedArrayIndex(mForcedArrayIndex);
}
} }
} }
} }
@ -815,6 +823,12 @@ void GuiInspector::removeInspectorGroup(StringTableEntry groupName)
removeObject(group); removeObject(group);
} }
void GuiInspector::setForcedArrayIndex(S32 arrayIndex)
{
mForcedArrayIndex = arrayIndex;
refresh();
}
//============================================================================= //=============================================================================
// Console Methods. // Console Methods.
//============================================================================= //=============================================================================
@ -979,3 +993,10 @@ DefineEngineMethod(GuiInspector, removeGroup, void, (const char* groupName), ,
{ {
object->removeInspectorGroup(StringTable->insert(groupName)); object->removeInspectorGroup(StringTable->insert(groupName));
} }
DefineEngineMethod(GuiInspector, setForcedArrayIndex, void, (S32 arrayIndex), (-1),
"Sets the ForcedArrayIndex for the inspector. Used to force presentation of arrayed fields to only show a specific field index inside groups."
"@param arrayIndex The specific field index for arrayed fields to show. Use -1 or blank arg to go back to normal behavior.")
{
object->setForcedArrayIndex(arrayIndex);
}

View file

@ -169,6 +169,8 @@ public:
void removeInspectorGroup(StringTableEntry groupName); void removeInspectorGroup(StringTableEntry groupName);
void setForcedArrayIndex(S32 arrayIndex);
protected: protected:
typedef Vector< SimObjectPtr< SimObject > > TargetVector; typedef Vector< SimObjectPtr< SimObject > > TargetVector;
@ -187,6 +189,7 @@ protected:
SimObjectPtr<GuiInspectorField> mHLField; SimObjectPtr<GuiInspectorField> mHLField;
String mGroupFilters; String mGroupFilters;
bool mShowCustomFields; bool mShowCustomFields;
S32 mForcedArrayIndex;
}; };
#endif #endif

View file

@ -57,6 +57,8 @@ GuiInspectorGroup::GuiInspectorGroup()
setCanSave( false ); setCanSave( false );
mForcedArrayIndex = -1;
// Make sure we receive our ticks. // Make sure we receive our ticks.
setProcessTicks(); setProcessTicks();
mMargin.set(0,0,5,0); mMargin.set(0,0,5,0);
@ -258,83 +260,89 @@ bool GuiInspectorGroup::inspectGroup()
AbstractClassRep* commonAncestorClass = findCommonAncestorClass(); AbstractClassRep* commonAncestorClass = findCommonAncestorClass();
AbstractClassRep::FieldList& fieldList = commonAncestorClass->mFieldList; AbstractClassRep::FieldList& fieldList = commonAncestorClass->mFieldList;
for( AbstractClassRep::FieldList::iterator itr = fieldList.begin(); for (AbstractClassRep::FieldList::iterator itr = fieldList.begin();
itr != fieldList.end(); ++ itr ) itr != fieldList.end(); ++itr)
{ {
AbstractClassRep::Field* field = &( *itr ); AbstractClassRep::Field* field = &(*itr);
if( field->type == AbstractClassRep::StartGroupFieldType ) if (field->type == AbstractClassRep::StartGroupFieldType)
{ {
// If we're dealing with general fields, always set grabItems to true (to skip them) // If we're dealing with general fields, always set grabItems to true (to skip them)
if( bNoGroup == true ) if (bNoGroup == true)
bGrabItems = true; bGrabItems = true;
else if( dStricmp( field->pGroupname, mCaption ) == 0 ) else if (dStricmp(field->pGroupname, mCaption) == 0)
bGrabItems = true; bGrabItems = true;
continue; continue;
} }
else if ( field->type == AbstractClassRep::EndGroupFieldType ) else if (field->type == AbstractClassRep::EndGroupFieldType)
{ {
// If we're dealing with general fields, always set grabItems to false (to grab them) // If we're dealing with general fields, always set grabItems to false (to grab them)
if( bNoGroup == true ) if (bNoGroup == true)
bGrabItems = false; bGrabItems = false;
else if( dStricmp( field->pGroupname, mCaption ) == 0 ) else if (dStricmp(field->pGroupname, mCaption) == 0)
bGrabItems = false; bGrabItems = false;
continue; continue;
} }
// Skip field if it has the HideInInspectors flag set. // Skip field if it has the HideInInspectors flag set.
if( field->flag.test( AbstractClassRep::FIELD_HideInInspectors ) ) if (field->flag.test(AbstractClassRep::FIELD_HideInInspectors))
continue; continue;
if( ( bGrabItems == true || ( bNoGroup == true && bGrabItems == false ) ) && itr->type != AbstractClassRep::DeprecatedFieldType ) if ((bGrabItems == true || (bNoGroup == true && bGrabItems == false)) && itr->type != AbstractClassRep::DeprecatedFieldType)
{ {
if( bNoGroup == true && bGrabItems == true ) if (bNoGroup == true && bGrabItems == true)
continue; continue;
if ( field->type == AbstractClassRep::StartArrayFieldType ) if ((field->type == AbstractClassRep::StartArrayFieldType || field->type == AbstractClassRep::EndArrayFieldType) && mForcedArrayIndex != -1)
{ {
#ifdef DEBUG_SPEW continue;
Platform::outputDebugString( "[GuiInspectorGroup] Beginning array '%s'", }
else
{
if (field->type == AbstractClassRep::StartArrayFieldType)
{
#ifdef DEBUG_SPEW
Platform::outputDebugString("[GuiInspectorGroup] Beginning array '%s'",
field->pFieldname ); field->pFieldname );
#endif #endif
// Starting an array... // Starting an array...
// Create a rollout for the Array, give it the array's name. // Create a rollout for the Array, give it the array's name.
GuiRolloutCtrl *arrayRollout = new GuiRolloutCtrl(); GuiRolloutCtrl* arrayRollout = new GuiRolloutCtrl();
GuiControlProfile *arrayRolloutProfile = dynamic_cast<GuiControlProfile*>( Sim::findObject( "GuiInspectorRolloutProfile0" ) ); GuiControlProfile* arrayRolloutProfile = dynamic_cast<GuiControlProfile*>(Sim::findObject("GuiInspectorRolloutProfile0"));
arrayRollout->setControlProfile(arrayRolloutProfile); arrayRollout->setControlProfile(arrayRolloutProfile);
//arrayRollout->mCaption = StringTable->insert( String::ToString( "%s (%i)", field->pGroupname, field->elementCount ) ); //arrayRollout->mCaption = StringTable->insert( String::ToString( "%s (%i)", field->pGroupname, field->elementCount ) );
arrayRollout->setCaption( field->pGroupname ); arrayRollout->setCaption(field->pGroupname);
//arrayRollout->setMargin( 14, 0, 0, 0 ); //arrayRollout->setMargin( 14, 0, 0, 0 );
arrayRollout->registerObject(); arrayRollout->registerObject();
GuiStackControl *arrayStack = new GuiStackControl(); GuiStackControl* arrayStack = new GuiStackControl();
arrayStack->registerObject(); arrayStack->registerObject();
arrayStack->freeze(true); arrayStack->freeze(true);
arrayRollout->addObject(arrayStack); arrayRollout->addObject(arrayStack);
// Allocate a rollout for each element-count in the array // Allocate a rollout for each element-count in the array
// Give it the element count name. // Give it the element count name.
for ( U32 i = 0; i < field->elementCount; i++ ) for (U32 i = 0; i < field->elementCount; i++)
{ {
GuiRolloutCtrl *elementRollout = new GuiRolloutCtrl(); GuiRolloutCtrl* elementRollout = new GuiRolloutCtrl();
GuiControlProfile *elementRolloutProfile = dynamic_cast<GuiControlProfile*>( Sim::findObject( "GuiInspectorRolloutProfile0" ) ); GuiControlProfile* elementRolloutProfile = dynamic_cast<GuiControlProfile*>(Sim::findObject("GuiInspectorRolloutProfile0"));
char buf[256]; char buf[256];
dSprintf( buf, 256, " [%i]", i ); dSprintf(buf, 256, " [%i]", i);
elementRollout->setControlProfile(elementRolloutProfile); elementRollout->setControlProfile(elementRolloutProfile);
elementRollout->setCaption(buf); elementRollout->setCaption(buf);
//elementRollout->setMargin( 14, 0, 0, 0 ); //elementRollout->setMargin( 14, 0, 0, 0 );
elementRollout->registerObject(); elementRollout->registerObject();
GuiStackControl *elementStack = new GuiStackControl(); GuiStackControl* elementStack = new GuiStackControl();
elementStack->registerObject(); elementStack->registerObject();
elementRollout->addObject(elementStack); elementRollout->addObject(elementStack);
elementRollout->instantCollapse(); elementRollout->instantCollapse();
arrayStack->addObject( elementRollout ); arrayStack->addObject(elementRollout);
} }
pArrayRollout = arrayRollout; pArrayRollout = arrayRollout;
@ -346,17 +354,17 @@ bool GuiInspectorGroup::inspectGroup()
bMakingArray = true; bMakingArray = true;
continue; continue;
} }
else if ( field->type == AbstractClassRep::EndArrayFieldType ) else if (field->type == AbstractClassRep::EndArrayFieldType)
{ {
#ifdef DEBUG_SPEW #ifdef DEBUG_SPEW
Platform::outputDebugString( "[GuiInspectorGroup] Ending array '%s'", Platform::outputDebugString("[GuiInspectorGroup] Ending array '%s'",
field->pFieldname ); field->pFieldname );
#endif #endif
bMakingArray = false; bMakingArray = false;
continue; continue;
} }
}
if ( bMakingArray ) if ( bMakingArray )
{ {
// Add a GuiInspectorField for this field, // Add a GuiInspectorField for this field,
@ -402,21 +410,23 @@ bool GuiInspectorGroup::inspectGroup()
// This is weird, but it should work for now. - JDD // This is weird, but it should work for now. - JDD
// We are going to check to see if this item is an array // We are going to check to see if this item is an array
// if so, we're going to construct a field for each array element // if so, we're going to construct a field for each array element
if( field->elementCount > 1 ) if( field->elementCount > 1)
{
if (mForcedArrayIndex == -1)
{ {
// Make a rollout control for this array // Make a rollout control for this array
// //
GuiRolloutCtrl *rollout = new GuiRolloutCtrl(); GuiRolloutCtrl* rollout = new GuiRolloutCtrl();
rollout->setDataField( StringTable->insert("profile"), NULL, "GuiInspectorRolloutProfile0" ); rollout->setDataField(StringTable->insert("profile"), NULL, "GuiInspectorRolloutProfile0");
rollout->setCaption(String::ToString( "%s (%i)", field->pFieldname, field->elementCount)); rollout->setCaption(String::ToString("%s (%i)", field->pFieldname, field->elementCount));
rollout->setMargin( 14, 0, 0, 0 ); rollout->setMargin(14, 0, 0, 0);
rollout->registerObject(); rollout->registerObject();
mArrayCtrls.push_back(rollout); mArrayCtrls.push_back(rollout);
// Put a stack control within the rollout // Put a stack control within the rollout
// //
GuiStackControl *stack = new GuiStackControl(); GuiStackControl* stack = new GuiStackControl();
stack->setDataField( StringTable->insert("profile"), NULL, "GuiInspectorStackProfile" ); stack->setDataField(StringTable->insert("profile"), NULL, "GuiInspectorStackProfile");
stack->registerObject(); stack->registerObject();
stack->freeze(true); stack->freeze(true);
rollout->addObject(stack); rollout->addObject(stack);
@ -427,16 +437,16 @@ bool GuiInspectorGroup::inspectGroup()
// //
for (S32 nI = 0; nI < field->elementCount; nI++) for (S32 nI = 0; nI < field->elementCount; nI++)
{ {
FrameTemp<char> intToStr( 64 ); FrameTemp<char> intToStr(64);
dSprintf( intToStr, 64, "%d", nI ); dSprintf(intToStr, 64, "%d", nI);
// Construct proper ValueName[nI] format which is "ValueName0" for index 0, etc. // Construct proper ValueName[nI] format which is "ValueName0" for index 0, etc.
String fieldName = String::ToString( "%s%d", field->pFieldname, nI ); String fieldName = String::ToString("%s%d", field->pFieldname, nI);
// If the field already exists, just update it // If the field already exists, just update it
GuiInspectorField *fieldGui = findField( fieldName ); GuiInspectorField* fieldGui = findField(fieldName);
if( fieldGui != NULL ) if (fieldGui != NULL)
{ {
fieldGui->updateValue(); fieldGui->updateValue();
continue; continue;
@ -444,18 +454,18 @@ bool GuiInspectorGroup::inspectGroup()
bNewItems = true; bNewItems = true;
fieldGui = constructField( field->type ); fieldGui = constructField(field->type);
if ( fieldGui == NULL ) if (fieldGui == NULL)
fieldGui = new GuiInspectorField(); fieldGui = new GuiInspectorField();
fieldGui->init( mParent, this ); fieldGui->init(mParent, this);
StringTableEntry caption = StringTable->insert( String::ToString(" [%i]",nI) ); StringTableEntry caption = StringTable->insert(String::ToString(" [%i]", nI));
fieldGui->setInspectorField( field, caption, intToStr ); fieldGui->setInspectorField(field, caption, intToStr);
if ( fieldGui->registerObject() ) if (fieldGui->registerObject())
{ {
mChildren.push_back( fieldGui ); mChildren.push_back(fieldGui);
stack->addObject( fieldGui ); stack->addObject(fieldGui);
} }
else else
delete fieldGui; delete fieldGui;
@ -467,9 +477,16 @@ bool GuiInspectorGroup::inspectGroup()
} }
else else
{ {
FrameTemp<char> intToStr(64);
dSprintf(intToStr, 64, "%d", mForcedArrayIndex);
// Construct proper ValueName[nI] format which is "ValueName0" for index 0, etc.
String fieldName = String::ToString("%s%d", field->pFieldname, mForcedArrayIndex);
// If the field already exists, just update it // If the field already exists, just update it
GuiInspectorField *fieldGui = findField( field->pFieldname ); GuiInspectorField* fieldGui = findField(fieldName);
if ( fieldGui != NULL ) if (fieldGui != NULL)
{ {
fieldGui->updateValue(); fieldGui->updateValue();
continue; continue;
@ -477,26 +494,54 @@ bool GuiInspectorGroup::inspectGroup()
bNewItems = true; bNewItems = true;
fieldGui = constructField( field->type ); fieldGui = constructField(field->type);
if ( fieldGui == NULL ) if (fieldGui == NULL)
fieldGui = new GuiInspectorField(); fieldGui = new GuiInspectorField();
fieldGui->init( mParent, this ); fieldGui->init(mParent, this);
fieldGui->setInspectorField( field ); fieldGui->setInspectorField(field, field->pFieldname, intToStr);
if( fieldGui->registerObject() ) if (fieldGui->registerObject())
{ {
#ifdef DEBUG_SPEW mChildren.push_back(fieldGui);
Platform::outputDebugString( "[GuiInspectorGroup] Adding field '%s'", mStack->addObject(fieldGui);
field->pFieldname ); }
#endif else
delete fieldGui;
mChildren.push_back( fieldGui ); }
mStack->addObject( fieldGui );
} }
else else
{ {
SAFE_DELETE( fieldGui ); // If the field already exists, just update it
GuiInspectorField* fieldGui = findField(field->pFieldname);
if (fieldGui != NULL)
{
fieldGui->updateValue();
continue;
}
bNewItems = true;
fieldGui = constructField(field->type);
if (fieldGui == NULL)
fieldGui = new GuiInspectorField();
fieldGui->init(mParent, this);
fieldGui->setInspectorField(field);
if (fieldGui->registerObject())
{
#ifdef DEBUG_SPEW
Platform::outputDebugString("[GuiInspectorGroup] Adding field '%s'",
field->pFieldname);
#endif
mChildren.push_back(fieldGui);
mStack->addObject(fieldGui);
}
else
{
SAFE_DELETE(fieldGui);
} }
} }
} }
@ -736,3 +781,10 @@ DefineEngineMethod(GuiInspectorGroup, removeField, void, (const char* fieldName)
object->removeInspectorField(StringTable->insert(fieldName)); object->removeInspectorField(StringTable->insert(fieldName));
} }
DefineEngineMethod(GuiInspectorGroup, setForcedArrayIndex, void, (S32 arrayIndex), (-1),
"Sets the ForcedArrayIndex for the group. Used to force presentation of arrayed fields to only show a specific field index."
"@param arrayIndex The specific field index for arrayed fields to show. Use -1 or blank arg to go back to normal behavior.")
{
object->setForcedArrayIndex(arrayIndex);
}

View file

@ -49,6 +49,12 @@ public:
GuiStackControl* mStack; GuiStackControl* mStack;
Vector<GuiRolloutCtrl*> mArrayCtrls; Vector<GuiRolloutCtrl*> mArrayCtrls;
S32 mForcedArrayIndex; /// This is a special behavior variable that, when set, changes
/// the presented behavior for arrays. Instead of showing sub-rollouts
/// it instead forces showing ONLY the fields of the specific index, removing
/// the presented array controls. This is useful for wanting to edit an associated
/// 'set' of fields that are commonly arrayed, like material layers
// Constructor/Destructor/Conobject Declaration // Constructor/Destructor/Conobject Declaration
GuiInspectorGroup(); GuiInspectorGroup();
GuiInspectorGroup( const String& groupName, SimObjectPtr<GuiInspector> parent ); GuiInspectorGroup( const String& groupName, SimObjectPtr<GuiInspector> parent );
@ -81,6 +87,11 @@ public:
void addInspectorField(GuiInspectorField* field); void addInspectorField(GuiInspectorField* field);
void removeInspectorField(StringTableEntry name); void removeInspectorField(StringTableEntry name);
void setForcedArrayIndex(const S32& arrayIndex = -1)
{
mForcedArrayIndex = arrayIndex;
}
protected: protected:
// overridable method that creates our inner controls. // overridable method that creates our inner controls.
virtual bool createContent(); virtual bool createContent();