Settings Generator: Class Usage

PreviousNext
The following descriptions assume that your input file was named settings.xml and the classes were generated with
em_settings_generator settings.xml

Using the settings singleton

After you have generated the classes settings.e and shared_settings.e with the EM Settings Generator, you should inherit from SHARED_SETTINGS in every class you would like to access the settings from. When you inherit from SHARED_SETTINGS, you will have the object "settings" available in your class.

Using the Settings class

The values in the settings class are initialized with the default values. The first thing you should do when using the settings is read the user settings with

settings.read_user_settings
You don't have to care where this file is stored. The default directory for it is taken from EM_USER_DIRECTORY. If desired, you can set the path using
settings.set_user_file

For every setting you specified in your settings.xml (for example: <Setting type="integer" name="volume" default="50"/>), you have the following features in the settings class:

Using Widgets

If specified in settings.xml, code for widgets that are coupled with the corresponding settings are generated. You have to create these widgets before using them, for example by calling

settings.create_all_widgets
or
settings.create_audio_widgets
After that, you can display the widgets anywhere you like.
Important: When changing a setting's value, the corresponding widget won't automatically change, you have to call
settings.reset_*_widgets
first. On the other hand, changing a widget doesn't automatically change the setting, you have to call
settings.apply_*_settings
first.
You can also free widgets using
settings.free_*_widgets
Note:You could create all widgets when starting the application and use them in several scenes. Just make sure that your widgets don't subscribe the same actions more than once. Also be aware than any subscriptions you make will still be valid when leaving a scene.