mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-10 06:04:37 +00:00
Adds a new FieldDescriptor struct
Use the field descriptor struct to add fields instead of the overloads
Adds a visibility function to control whether a field is visible in the inspector
EG:
ADD_FIELD("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset))
.doc("Path to the sound file.")
.elements(SFXPlayList::SFXPlaylistSettings::NUM_SLOTS)
.onSet(&_setSoundFile);
the grammar can change to make these easier to work with, review changes carefully
This commit is contained in:
parent
92e32aa40a
commit
e635344fba
8 changed files with 343 additions and 16 deletions
|
|
@ -785,6 +785,59 @@ void GuiInspector::refresh()
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void GuiInspector::updateVisibility()
|
||||
{
|
||||
const U32 numTargets = getNumInspectObjects();
|
||||
|
||||
for (U32 i = 0; i < numTargets; i++)
|
||||
{
|
||||
|
||||
SimObject* target = getInspectObject(i);
|
||||
if (!target) return;
|
||||
|
||||
for (GuiInspectorGroup* group : mGroups)
|
||||
{
|
||||
const AbstractClassRep::Field* g = target->findField(group->getGroupName().c_str());
|
||||
|
||||
// if group has its own visibility function let it control it.
|
||||
bool group_visible = (!g || !g->visibilityFn) ? true : g->visibilityFn(target, "0");
|
||||
if (!group_visible)
|
||||
{
|
||||
group->setVisible(group_visible);
|
||||
return;
|
||||
}
|
||||
|
||||
bool anyVisible = false;
|
||||
for (GuiInspectorField* field : group->mChildren)
|
||||
{
|
||||
const AbstractClassRep::Field* f = field->getField();
|
||||
StringTableEntry idx = field->getArrayIndex();
|
||||
bool visible = (!f || !f->visibilityFn) ? true : f->visibilityFn(target, idx);
|
||||
|
||||
field->setVisible(visible);
|
||||
if (visible)
|
||||
anyVisible = true;
|
||||
}
|
||||
|
||||
// Per-array-element rollout visibility
|
||||
for (GuiInspectorGroup::ArrayElementEntry& elem : group->mArrayElements)
|
||||
{
|
||||
bool visible = false;
|
||||
if (!elem.arrayField || !elem.arrayField->visibilityFn || elem.elementIndex == 0)
|
||||
visible = true;
|
||||
|
||||
if (!visible)
|
||||
visible = elem.arrayField->visibilityFn(target, String::ToString(elem.elementIndex));
|
||||
|
||||
elem.rollout->setVisible(visible);
|
||||
if (visible) anyVisible = true;
|
||||
}
|
||||
|
||||
group->setVisible(anyVisible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiInspector::sendInspectPreApply()
|
||||
{
|
||||
const U32 numObjects = getNumInspectObjects();
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ public:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void updateVisibility();
|
||||
|
||||
S32 getComponentGroupTargetId() { return mComponentGroupTargetId; }
|
||||
void setComponentGroupTargetId(S32 compId) { mComponentGroupTargetId = compId; }
|
||||
|
||||
|
|
|
|||
|
|
@ -835,6 +835,8 @@ void GuiInspectorField::updateValue()
|
|||
}
|
||||
else
|
||||
setValue( getData() );
|
||||
|
||||
mInspector->updateVisibility();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@ class GuiInspectorField : public GuiControl
|
|||
|
||||
///
|
||||
StringTableEntry getArrayIndex() const { return mFieldArrayIndex; }
|
||||
AbstractClassRep::Field* getField() const { return mField; }
|
||||
|
||||
/// Called from within setData to allow child classes
|
||||
/// to perform their own verification.
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ GuiInspectorGroup::GuiInspectorGroup( const String& groupName,
|
|||
|
||||
mChildren.clear();
|
||||
mMargin.set(0,0,4,0);
|
||||
VECTOR_SET_ASSOCIATION(mArrayElements);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -229,6 +230,7 @@ void GuiInspectorGroup::clearFields()
|
|||
// that we keep for our own convenience.
|
||||
mArrayCtrls.clear();
|
||||
mChildren.clear();
|
||||
mArrayElements.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -336,7 +338,7 @@ bool GuiInspectorGroup::inspectGroup()
|
|||
GuiControlProfile* elementRolloutProfile = dynamic_cast<GuiControlProfile*>(Sim::findObject("GuiInspectorRolloutProfile0"));
|
||||
|
||||
char buf[256];
|
||||
dSprintf(buf, 256, " [%i]", i);
|
||||
dSprintf(buf, 256, " [%i/%i]", i, field->elementCount);
|
||||
|
||||
elementRollout->setControlProfile(elementRolloutProfile);
|
||||
elementRollout->setCaption(buf);
|
||||
|
|
@ -349,6 +351,8 @@ bool GuiInspectorGroup::inspectGroup()
|
|||
elementRollout->instantCollapse();
|
||||
|
||||
arrayStack->addObject(elementRollout);
|
||||
|
||||
mArrayElements.push_back({ elementRollout, (S32)i, field });
|
||||
}
|
||||
|
||||
pArrayRollout = arrayRollout;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,13 @@ private:
|
|||
typedef GuiRolloutCtrl Parent;
|
||||
public:
|
||||
// Members
|
||||
struct ArrayElementEntry
|
||||
{
|
||||
GuiRolloutCtrl* rollout;
|
||||
S32 elementIndex;
|
||||
const AbstractClassRep::Field* arrayField; // the StartArrayFieldType field
|
||||
};
|
||||
Vector<ArrayElementEntry> mArrayElements;
|
||||
SimObjectPtr<GuiInspector> mParent;
|
||||
Vector<GuiInspectorField*> mChildren;
|
||||
GuiStackControl* mStack;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue