Creating a NamedObjectSave-Editing Plugin
Last updated
Last updated
A common plugin type is one that can modify NamedObjectSave instances. Thee types of plugins exist throughout FlatRedBall. For example, the Collision tab is a plugin which allows modifying NamedObjectSave instances which are collision relationships.
This tutorial shows how to create a plugin which can display and modify custom properties on a NamedObjectSave.
The first step is to create a new plugin. This tutorial skips these steps since earlier plugins explain how to create a new plugin. This tutorial uses a plugin called ExampleNamedObjectPlugin. The class name will follow the convention of prepending the word "Main", creating a class called MainExampleNamedObjectPlugin.
This Plugin contains the following classes:
ExampleView - a WPF view which lets the user view and edit properties on the selected NamedObjectSave
ExampleViewModel - the ViewModel which binds to ExampleView using standard MVVM. It inherits from PropertyListContainerViewModel which provides automatic saving of properties to disk.
MainExampleNamedObjectPlugin - this plugin is responsible for creating the view and viewmodel, and deciding when to show the view
The ExampleView defines the UI for editing the properties on the selected NamedObjectSave. It contains a checkbox to edit a boolean property and a text box to edit a string property. The following is the XAML for this view:
The preview for this view should look like the following image:
Note that this view expects a ViewModel with properties BoolProperty and StringProperty.
The ExampleViewModel should include the two properties mentioned above. If the plugin inherits from the PropertyListContainerViewModel class, it will provide the following functionality:
Automatic notification of property changes
Setting the property on the underlying NamedObjectSave
Automatic saving of the NamedObjectSave to disk
The syntax for using the PropertyListContainerViewModel is similar to using the built-in FlatRedBall ViewModel class.
The main plugin class will respond to a selected tree node and decide whether it should create the view. Plugins can create views and viewmodels when first starting up, or they can do so lazily - only when needed. The following implementation shows how to create the view and viewmodel lazily: