JSExample.plugin.js 4.3 KB

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