TSExample.plugin.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. var ExamplePluginUILabel = "TS Example Plugin";
  3. var ExamplePluginTBPath = "EditorData/Example.tb.txt";
  4. var InfoboxTBPath = "EditorData/Infobox.tb.txt";
  5. var TSExamplePluginService = (function () {
  6. function TSExamplePluginService() {
  7. var _this = this;
  8. this.name = "TSExampleService";
  9. this.description = "This service demonstrates plugin functionality functionality.";
  10. this.serviceLocator = null;
  11. this.extensionWindow = null;
  12. this.lastObjectName = null;
  13. this.handleWidgetEvent = function (ev) {
  14. if (!_this.extensionWindow) {
  15. return;
  16. }
  17. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  18. if (ev.target.id == "example_cancel") {
  19. _this.extensionWindow.hide();
  20. _this.extensionWindow = null;
  21. return true;
  22. }
  23. if (ev.target.id == "example_speak") {
  24. _this.helloLabel.text = "Hello " + _this.nameField.text;
  25. return true;
  26. }
  27. }
  28. return false;
  29. };
  30. }
  31. TSExamplePluginService.prototype.initialize = function (serviceLoader) {
  32. Atomic.print("TSExamplePluginService.initialize");
  33. this.serviceLocator = (serviceLoader);
  34. if (this.serviceLocator) {
  35. this.serviceLocator.projectServices.register(this);
  36. this.serviceLocator.uiServices.register(this);
  37. }
  38. };
  39. TSExamplePluginService.prototype.projectUnloaded = function () {
  40. this.serviceLocator.uiServices.removeProjectContextMenuItemSource(ExamplePluginUILabel);
  41. this.serviceLocator.uiServices.removeHierarchyContextMenuItemSource(ExamplePluginUILabel);
  42. this.serviceLocator.uiServices.removePluginMenuItemSource(ExamplePluginUILabel);
  43. Atomic.print("TSExamplePluginService.projectUnloaded");
  44. if (this.serviceLocator) {
  45. this.serviceLocator.projectServices.unregister(this);
  46. this.serviceLocator.uiServices.unregister(this);
  47. }
  48. };
  49. TSExamplePluginService.prototype.projectLoaded = function (ev) {
  50. Atomic.print("TSExamplePluginService.projectLoaded");
  51. this.serviceLocator.uiServices.createPluginMenuItemSource(ExamplePluginUILabel, { "Open": ["tsexampleplugin open"] });
  52. this.serviceLocator.uiServices.createHierarchyContextMenuItemSource(ExamplePluginUILabel, { "Get name": ["tsexampleplugin hierarchy context"] });
  53. this.serviceLocator.uiServices.createProjectContextMenuItemSource(ExamplePluginUILabel, { "Get name": ["tsexampleplugin project context"] });
  54. };
  55. TSExamplePluginService.prototype.playerStarted = function () {
  56. Atomic.print("TSExamplePluginService.playerStarted");
  57. };
  58. TSExamplePluginService.prototype.menuItemClicked = function (refId) {
  59. Atomic.print("TSExamplePluginService.menuItemClicked: " + refId);
  60. if (refId == "tsexampleplugin open") {
  61. this.extensionWindow = this.serviceLocator.uiServices.showModalWindow(ExamplePluginUILabel, ExamplePluginTBPath, this.handleWidgetEvent);
  62. this.getWidgets();
  63. return true;
  64. }
  65. return false;
  66. };
  67. TSExamplePluginService.prototype.hierarchyContextItemClicked = function (node, refid) {
  68. Atomic.print("TSExamplePluginService.hierarchyContextItemClicked: " + node.name + " " + refid);
  69. if (refid == "tsexampleplugin hierarchy context") {
  70. this.lastObjectName = "node " + node.name;
  71. this.showInfobox("Hierarchy Item Selected ", "Node: '" + node.name + "' was selected.");
  72. return true;
  73. }
  74. return false;
  75. };
  76. TSExamplePluginService.prototype.projectContextItemClicked = function (asset, refid) {
  77. Atomic.print("TSExamplePluginService.projectContextItemClicked: " + asset.name + " " + refid);
  78. if (refid == "tsexampleplugin project context") {
  79. this.lastObjectName = "asset " + asset.name;
  80. this.showInfobox("Project Asset Selected", "Asset: '" + asset.name + "' was selected.");
  81. return true;
  82. }
  83. return false;
  84. };
  85. TSExamplePluginService.prototype.getWidgets = function () {
  86. if (!this.extensionWindow) {
  87. return;
  88. }
  89. this.helloLabel = this.extensionWindow.getWidget("example_hello");
  90. this.nameField = this.extensionWindow.getWidget("example_name");
  91. if (this.lastObjectName) {
  92. this.nameField.text = this.lastObjectName;
  93. this.lastObjectName = null;
  94. }
  95. };
  96. TSExamplePluginService.prototype.showInfobox = function (title, msg) {
  97. var infobox = this.serviceLocator.uiServices.showModalWindow(title, InfoboxTBPath, function (ev) {
  98. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK && ev.target.id == "infobox_ok") {
  99. infobox.hide();
  100. return true;
  101. }
  102. });
  103. var msgLabel = infobox.getWidget("infobox_msg");
  104. msgLabel.text = msg;
  105. };
  106. return TSExamplePluginService;
  107. }());
  108. Object.defineProperty(exports, "__esModule", { value: true });
  109. exports.default = new TSExamplePluginService();