Example.plugin.js 3.0 KB

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