Example.plugin.js 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.lastObjectName = null;
  11. this.handleWidgetEvent = function (ev) {
  12. if (!_this.extensionWindow)
  13. return;
  14. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  15. if (ev.target.id == "example_cancel") {
  16. _this.extensionWindow.hide();
  17. _this.extensionWindow = null;
  18. return true;
  19. }
  20. if (ev.target.id == "example_speak") {
  21. _this.helloLabel.text = "Hello " + _this.nameField.text;
  22. return true;
  23. }
  24. }
  25. return false;
  26. };
  27. }
  28. ExamplePluginService.prototype.initialize = function (serviceLoader) {
  29. Atomic.print("ExamplePluginService.initialize");
  30. this.serviceLocator = (serviceLoader);
  31. if (this.serviceLocator) {
  32. this.serviceLocator.projectServices.register(this);
  33. this.serviceLocator.uiServices.register(this);
  34. }
  35. };
  36. ExamplePluginService.prototype.projectUnloaded = function () {
  37. this.serviceLocator.uiServices.removeProjectContextMenuItemSource(ExamplePluginUILabel);
  38. this.serviceLocator.uiServices.removeHierarchyContextMenuItemSource(ExamplePluginUILabel);
  39. this.serviceLocator.uiServices.removePluginMenuItemSource(ExamplePluginUILabel);
  40. Atomic.print("ExamplePluginService.projectUnloaded");
  41. if (this.serviceLocator) {
  42. this.serviceLocator.projectServices.unregister(this);
  43. this.serviceLocator.uiServices.unregister(this);
  44. }
  45. };
  46. ExamplePluginService.prototype.projectLoaded = function (ev) {
  47. Atomic.print("ExamplePluginService.projectLoaded");
  48. this.serviceLocator.uiServices.createPluginMenuItemSource(ExamplePluginUILabel, { "Open": ["exampleplugin open"] });
  49. this.serviceLocator.uiServices.createHierarchyContextMenuItemSource(ExamplePluginUILabel, { "Get name": ["exampleplugin hierarchy context"] });
  50. this.serviceLocator.uiServices.createProjectContextMenuItemSource(ExamplePluginUILabel, { "Get name": ["exampleplugin project context"] });
  51. };
  52. ExamplePluginService.prototype.playerStarted = function () {
  53. Atomic.print("ExamplePluginService.playerStarted");
  54. };
  55. ExamplePluginService.prototype.menuItemClicked = function (refId) {
  56. Atomic.print("ExamplePluginService.menuItemClicked: " + refId);
  57. if (refId == "exampleplugin open") {
  58. this.extensionWindow = this.serviceLocator.uiServices.showModalWindow(ExamplePluginUILabel, ExamplePluginTBPath, this.handleWidgetEvent);
  59. this.getWidgets();
  60. return true;
  61. }
  62. return false;
  63. };
  64. ExamplePluginService.prototype.hierarchyContextItemClicked = function (node, refid) {
  65. Atomic.print("ExamplePluginService.hierarchyContextItemClicked: " + node.name + " " + refid);
  66. if (refid == "exampleplugin hierarchy context") {
  67. this.lastObjectName = "node " + node.name;
  68. return true;
  69. }
  70. return false;
  71. };
  72. ExamplePluginService.prototype.projectContextItemClicked = function (asset, refid) {
  73. Atomic.print("ExamplePluginService.projectContextItemClicked: " + asset.name + " " + refid);
  74. if (refid == "exampleplugin project context") {
  75. this.lastObjectName = "asset " + asset.name;
  76. return true;
  77. }
  78. return false;
  79. };
  80. ExamplePluginService.prototype.getWidgets = function () {
  81. if (!this.extensionWindow)
  82. return;
  83. this.helloLabel = this.extensionWindow.getWidget("example_hello");
  84. this.nameField = this.extensionWindow.getWidget("example_name");
  85. if (this.lastObjectName) {
  86. this.nameField.text = this.lastObjectName;
  87. this.lastObjectName = null;
  88. }
  89. };
  90. return ExamplePluginService;
  91. })();
  92. var examplePluginService = new ExamplePluginService();
  93. Object.defineProperty(exports, "__esModule", { value: true });
  94. exports.default = examplePluginService;