JSExample.plugin.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. var ExamplePluginUILabel = "JS Example Plugin";
  2. var ExamplePluginTBPath = "EditorData/Example.tb.txt";
  3. // Private variables
  4. var serviceLocator = null;
  5. var extensionWindow = null;
  6. var helloLabel = null;
  7. var nameField = null;
  8. // Private functions
  9. function getWidgets() {
  10. if (!extensionWindow) {
  11. return;
  12. }
  13. helloLabel = extensionWindow.getWidget("example_hello");
  14. nameField = extensionWindow.getWidget("example_name");
  15. }
  16. function handleWidgetEvent(ev) {
  17. if (!extensionWindow) {
  18. return;
  19. }
  20. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  21. if (ev.target.id == "example_cancel") {
  22. extensionWindow.hide();
  23. extensionWindow = null;
  24. return true;
  25. }
  26. if (ev.target.id == "example_speak") {
  27. helloLabel.text = "Hello " + nameField.text;
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. // Definition of the plugin
  34. var JSExamplePlugin = {
  35. name: "JSExamplePlugin",
  36. description: "This service demonstrates plugin functionality"
  37. };
  38. JSExamplePlugin.initialize = function(serviceLoader) {
  39. Atomic.print("JSExamplePluginService.initialize");
  40. serviceLocator = serviceLoader;
  41. if (serviceLocator) {
  42. serviceLocator.projectServices.register(JSExamplePlugin);
  43. serviceLocator.uiServices.register(JSExamplePlugin);
  44. }
  45. };
  46. JSExamplePlugin.projectUnloaded = function() {
  47. serviceLocator.uiServices.removePluginMenuItemSource(ExamplePluginUILabel);
  48. Atomic.print("JSExamplePluginService.projectUnloaded");
  49. if (serviceLocator) {
  50. serviceLocator.projectServices.unregister(JSExamplePlugin);
  51. serviceLocator.uiServices.unregister(JSExamplePlugin);
  52. }
  53. };
  54. JSExamplePlugin.projectLoaded = function(ev) {
  55. Atomic.print("JSExamplePluginService.projectLoaded");
  56. var menu = serviceLocator.uiServices.createPluginMenuItemSource(ExamplePluginUILabel, {
  57. "Open": ["exampleplugin open"]
  58. });
  59. };
  60. JSExamplePlugin.playerStarted = function() {
  61. Atomic.print("JSExamplePluginService.playerStarted");
  62. };
  63. JSExamplePlugin.menuItemClicked = function(refId) {
  64. Atomic.print("JSExamplePluginService.menuItemClicked: " + refId);
  65. if (refId == "exampleplugin open") {
  66. extensionWindow = serviceLocator.uiServices.showModalWindow(
  67. ExamplePluginUILabel, ExamplePluginTBPath, handleWidgetEvent);
  68. getWidgets();
  69. return true;
  70. }
  71. return false;
  72. };
  73. module.exports = JSExamplePlugin;