TSExample.plugin.js 5.5 KB

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