Extending the Preferences Panel

The editor allows each extension to register its own configuration, and then displays some or all of the editor configuration within the Preferences panel. In this panel, the modifications are editor feature-related configurations.

For project-related configurations, please review the Project Settings documentation.

Description of the Preferences Panel

The Preferences panel can be opened via the top menu Cocos Creator -> Preferences.

preferences

The Preferences panel is divided into left and right sides.

  • The left side shows the names of functional extensions that provide configuration items.
  • On the right side is an action panel rendered according to the configuration.

Changes made in the panel are immediately modified to the corresponding configuration items.

Normally, the configuration is stored at the global level. If the configuration needs to be put into a project, then move the mouse over the configuration entry and select Record to project on the small icon that appears on the left side. This data will be saved to the project, and changes to it will not affect other projects.

Notes:

  1. If the auto-rendered configuration is stored in the project, the icon on the left side will turn yellow to indicate it. To reuse the global configuration, click the icon on the left side and select Restore to Global Configuration, doing so will discard the project settings.
  2. Only auto-rendered configurations will automatically add icons. If properties are not defined, implement the icon change function in the panel as needed.

Also, there are some configurations that cannot switch between global and local storage location, such as preview scenes, which must be stored in the project. This part of the configuration should use the custom panel.

For more information about the Preferences panel, please refer to the Preferences documentation.

Registration Methods

Preferences allow to display configurations in two ways.

  1. General configuration
  2. Lab configuration

General settings are displayed directly as tabs, while lab switches are displayed centrally in a separate tab.

  • When the functionality provided by the extension is more stable it is recommended to place the configuration data within the generic functionality.
  • When the functionality provided by the extension is in the development stage, it is recommended that the switch configuration data of the functionality be placed in the lab configuration.

First define the configuration in contributions.profile.editor. The data to be displayed in the Preferences panel can then be defined in contributions.preferences.

For details on how to define a profile, please review the Profile documentation.

Registering Preferences Data

package.json

  1. {
  2. "name": "hello-world",
  3. "contributions": {
  4. "profile": {
  5. "editor": {
  6. "foo": {
  7. "default": 0,
  8. "label": "foo"
  9. },
  10. "bar": {
  11. "default": false,
  12. "label": "bar"
  13. }
  14. }
  15. },
  16. "preferences": {
  17. "properties": {
  18. "foo": {
  19. "ui": "ui-num-input"
  20. }
  21. },
  22. "laboratory": ["bar"]
  23. }
  24. }
  25. }

Two editor configurations, foo and bar, have been defined and added the configurations to the preferences.

  • The foo is stored in the general profile.
  • The bar is stored in the laboratory profile.

The defined profile data will be automatically registered to default. Using Editor.Profile.getConfig will get the default values.

The contributions of package.json need to be defined like the following:

  1. interface package
  2. {
  3. "name": string;
  4. "contributions": {
  5. "profile": {
  6. "editor": {
  7. [key:string]: ProfileItem;
  8. };
  9. };
  10. "preferences": {
  11. /**
  12. * The properties data can be filled in to auto-render the configuration.
  13. * The key in properties corresponds to the editor configuration key, and the value corresponds to the information needed for auto-rendering.
  14. * If there is a ui defined in properties then it will be automatically rendered under the tab of the functional extension name.
  15. **/
  16. "properties": {
  17. [key:string]: UIInfo
  18. };
  19. /**
  20. * If the configuration is more complex and auto-rendering can't meet the demand, you can fill in custom data.
  21. * Fill in the entry for the custom panel there.
  22. * The panel will appear below the autorender (if properties are defined).
  23. **/
  24. "custom": string;
  25. /**
  26. * The labs are listed as a separate tab within the editor, mainly to provide a switch display for some experimental functions.
  27. * You can fill in laboratory data to add an editor configuration of type Boolean to the lab switches.
  28. * Laboratory is an array, the key in the array points to the key in the editor configuration, the corresponding data must be of Boolean type.
  29. * The key filled in here will be displayed in the Lab tab of Preferences.
  30. **/
  31. "laboratory": string[];
  32. };
  33. ...
  34. }
  35. ...
  36. }
  1. interface UIInfo {
  2. // which ui element to use for rendering, e.g.: "ui-num-input"
  3. ui: string;
  4. attributes: {
  5. // The attribute data allowed on the ui element, each ui allows different parameters, see the ui-kit chapter for details
  6. // Assuming the ui is "ui-num-input"
  7. // This can be filled with "step": 1
  8. [key:string]: any;
  9. };
  10. }

For more information on how to customize the panel please review the Panel Definition documentation.