SonyWWS / ATF

Authoring Tools Framework (ATF) is a set of C#/.NET components for making tools on Windows. ATF has been in continuous development in Sony Computer Entertainment's (SCE) Worldwide Studios central tools group since early 2005. ATF has been used by most SCE first party studios to make many custom tools such as Naughty Dog’s level editor and shader editor for The Last of Us, Guerrilla Games’ sequence editor for Killzone games (including the Killzone: Shadow Fall PS4 launch title), an animation blending tool at Santa Monica Studio, a level editor at Bend Studio, a visual state machine editor for Quantic Dream, sound editing tools, and many others.
Apache License 2.0
1.89k stars 262 forks source link

Show/Hide properties on the PropertyGrid #51

Closed nrvllrgrs closed 7 years ago

nrvllrgrs commented 8 years ago

Is there a way to show or hide properties on the PropertyGrid based on the values of other properties? For example, in the DomPropertyEditor, if the Emotion property were set to Happy then the Goals property would display; otherwise, that property would not be drawn.

abeckus commented 8 years ago

Yes there is: Please see the following class in CircuitEditor example for reference. public class ModuleProperties : CustomTypeDescriptorNodeAdapter, IDynamicTypeDescriptor Basically you need to subclass CustomTypeDescriptorNodeAdapter and override projected method GetPropertyDescriptors(). you can inspect the object and create list of descriptors using any conditions you like.

Alan

nrvllrgrs commented 8 years ago

That works perfectly for attributes on the selected DomNode. Any suggestions for if the DomNode is in an EmbeddedCollectionEditor?

abeckus commented 8 years ago

It should work fine for child DomNodes too as long as you register CustomTypeDescriptorNodeAdapter for each DomNodeTypes that have dynamic properties. If this is not case then there is a bug, please let me know so I can fix it in next update.

Alan

nrvllrgrs commented 8 years ago

I have a CustomTypeDescriptorNodeAdapter for the child DomNode, which it is registered to in SchemaLoader using Schema.childNodeName.Type.Define(new ExtensionInfo<DynamicChildNodeProperties>()) Updating the child DomNode's properties in an embedded collection does not update its dynamic properties.

abeckus commented 8 years ago

Here is a quick suggestion until I can address this issue with next Update. I haven't setup a use case to reproduce this bug yet. But tracing the code path it seems the problem is the property descriptors is cached for optimization purpose.. Try to comment out the code that caches the property descriptors and let me know if it is the case.

change GetPropertyDescriptors() method in class PropertyEditingContext located at ..\Framework\Atf.Gui\Controls\PropertyEditing

// comment out caching public static PropertyDescriptor[] GetPropertyDescriptors(PropertyEditingContext context) { if (context == null || context.m_selection.Length == 0) return new PropertyDescriptor[0];

        // don't use cach
        //if (context.m_propertyDescriptors != null)
        //    return context.m_propertyDescriptors;

        PropertyDescriptor[] result = context.CreatePropertyDescriptors();

       // don't cache the result.
       // context.m_propertyDescriptors = result;
        return result;
    }

Also comment out //private PropertyDescriptor[] m_propertyDescriptors; to avoid compiler warning as error.

Alan