actionsbuilder.list.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. var ActionsBuilder;
  2. (function (ActionsBuilder) {
  3. var ListElement = (function () {
  4. function ListElement() {
  5. this.rect = null;
  6. this.text = null;
  7. this.name = "";
  8. this.type = ActionsBuilder.Type.TRIGGER;
  9. this.element = null;
  10. }
  11. return ListElement;
  12. })();
  13. ActionsBuilder.ListElement = ListElement;
  14. var List = (function () {
  15. function List(viewer) {
  16. var _this = this;
  17. this._listElements = new Array();
  18. this.listElement = document.getElementById("ListsElementID");
  19. this.triggersElement = document.getElementById("TriggersListID");
  20. this.actionsElement = document.getElementById("ActionsListID");
  21. this.flowControlsElement = document.getElementById("FlowActionsListID");
  22. this._parentContainer = document.getElementById("ParentContainerID");
  23. this._viewer = viewer;
  24. this.triggersList = Raphael("TriggersListID", (25 * screen.width) / 100, 400);
  25. this.actionsList = Raphael("ActionsListID", (25 * screen.width) / 100, 400);
  26. this.flowControlsList = Raphael("FlowActionsListID", (25 * screen.width) / 100, 400);
  27. window.addEventListener("resize", function (event) {
  28. _this.onResize(event);
  29. });
  30. }
  31. Object.defineProperty(List, "ELEMENT_HEIGHT", {
  32. get: function () {
  33. return 25;
  34. },
  35. enumerable: true,
  36. configurable: true
  37. });
  38. List.prototype.onResize = function (event) {
  39. var tools = document.getElementById("ToolsButtonsID");
  40. this.listElement.style.height = window.innerHeight - tools.getBoundingClientRect().height - 25 + "px";
  41. var listElementWidth = this.listElement.getBoundingClientRect().width;
  42. for (var i = 0; i < this._listElements.length; i++) {
  43. var rect = this._listElements[i].rect;
  44. rect.attr("width", listElementWidth - 40);
  45. }
  46. this.triggersList.setSize(listElementWidth, this.triggersList.height);
  47. this.actionsList.setSize(listElementWidth, this.triggersList.height);
  48. this.flowControlsList.setSize(listElementWidth, this.triggersList.height);
  49. };
  50. List.prototype.createListsElements = function () {
  51. var excludedTriggers = [6, 9, 10];
  52. var yPosition = 10;
  53. var textColor = Raphael.rgb(61, 72, 76);
  54. var whiteColor = Raphael.rgb(255, 255, 255);
  55. var configureTitle = function (listElement, rectColor) {
  56. listElement.text.attr("x", 15);
  57. listElement.rect.attr("fill", rectColor);
  58. listElement.text.attr("font-family", "Sinkin Sans Medium");
  59. listElement.text.attr("font-size", "11");
  60. };
  61. var triggers = this._createListElement(this.triggersList, yPosition, "TRIGGERS", ActionsBuilder.Type.TRIGGER, whiteColor, false);
  62. yPosition += List.ELEMENT_HEIGHT;
  63. configureTitle(triggers, Raphael.rgb(41, 129, 255));
  64. for (var i = 0; i < ActionsBuilder.Elements.TRIGGERS.length; i++) {
  65. var element = ActionsBuilder.Elements.TRIGGERS[i];
  66. if (this._viewer.root.type === ActionsBuilder.Type.OBJECT && excludedTriggers.indexOf(i) !== -1) {
  67. continue;
  68. }
  69. else if (this._viewer.root.type === ActionsBuilder.Type.SCENE && excludedTriggers.indexOf(i) === -1) {
  70. continue;
  71. }
  72. var trigger = this._createListElement(this.triggersList, yPosition, element.text, ActionsBuilder.Type.TRIGGER, textColor, true, element);
  73. trigger.rect.attr("fill", Raphael.rgb(133, 154, 185));
  74. yPosition += List.ELEMENT_HEIGHT;
  75. }
  76. yPosition += List.ELEMENT_HEIGHT;
  77. this.triggersElement.style.height = this.triggersList.canvas.style.height = yPosition + "px";
  78. this._createCollapseAnimation(this.triggersList, this.triggersElement, triggers, yPosition);
  79. yPosition = 10;
  80. var actions = this._createListElement(this.actionsList, yPosition, "ACTIONS", ActionsBuilder.Type.ACTION, textColor, false);
  81. yPosition += List.ELEMENT_HEIGHT;
  82. configureTitle(actions, Raphael.rgb(255, 220, 42));
  83. for (var i = 0; i < ActionsBuilder.Elements.ACTIONS.length; i++) {
  84. var element = ActionsBuilder.Elements.ACTIONS[i];
  85. var action = this._createListElement(this.actionsList, yPosition, element.text, ActionsBuilder.Type.ACTION, textColor, true, element);
  86. action.rect.attr("fill", Raphael.rgb(182, 185, 132));
  87. yPosition += List.ELEMENT_HEIGHT;
  88. }
  89. yPosition += List.ELEMENT_HEIGHT;
  90. this.actionsElement.style.height = this.actionsList.canvas.style.height = yPosition + "px";
  91. this._createCollapseAnimation(this.actionsList, this.actionsElement, actions, yPosition);
  92. yPosition = 10;
  93. var flowControls = this._createListElement(this.flowControlsList, yPosition, "FLOW CONTROLS", ActionsBuilder.Type.FLOW_CONTROL, whiteColor, false);
  94. yPosition += List.ELEMENT_HEIGHT;
  95. configureTitle(flowControls, Raphael.rgb(255, 41, 53));
  96. for (var i = 0; i < ActionsBuilder.Elements.FLOW_CONTROLS.length - 1; i++) {
  97. var element = ActionsBuilder.Elements.FLOW_CONTROLS[i];
  98. var flowControl = this._createListElement(this.flowControlsList, yPosition, element.text, ActionsBuilder.Type.FLOW_CONTROL, textColor, true, element);
  99. flowControl.rect.attr("fill", Raphael.rgb(185, 132, 140));
  100. yPosition += List.ELEMENT_HEIGHT;
  101. }
  102. yPosition += List.ELEMENT_HEIGHT;
  103. this.flowControlsElement.style.height = this.flowControlsList.canvas.style.height = yPosition + "px";
  104. this._createCollapseAnimation(this.flowControlsList, this.flowControlsElement, flowControls, yPosition);
  105. };
  106. List.prototype.clearLists = function () {
  107. for (var i = 0; i < this._listElements.length; i++) {
  108. this._removeListElement(this._listElements[i]);
  109. }
  110. this._listElements.splice(0, this._listElements.length - 1);
  111. };
  112. List.prototype.setColorTheme = function (color) {
  113. this.triggersList.canvas.style.backgroundColor = color;
  114. this.actionsList.canvas.style.backgroundColor = color;
  115. this.flowControlsList.canvas.style.backgroundColor = color;
  116. };
  117. List.prototype._createListElement = function (paper, yPosition, text, type, textColor, drag, element) {
  118. var object = new ListElement();
  119. object.rect = paper.rect(10, yPosition, 300, List.ELEMENT_HEIGHT);
  120. object.text = paper.text(30, yPosition + object.rect.attr("height") / 2, text);
  121. object.text.attr("fill", textColor);
  122. object.text.attr("text-anchor", "start");
  123. object.text.attr("font-size", "12");
  124. object.text.attr("text-anchor", "start");
  125. object.text.attr("font-family", "Sinkin Sans Light");
  126. if (drag) {
  127. this._createListElementAnimation(object);
  128. }
  129. object.type = type;
  130. object.element = element;
  131. this._listElements.push(object);
  132. return object;
  133. };
  134. List.prototype._removeListElement = function (element) {
  135. element.rect.remove();
  136. element.text.remove();
  137. };
  138. List.prototype._createCollapseAnimation = function (paper, htmlElement, element, expandedHeight) {
  139. var onClick = function (event) {
  140. var height = htmlElement.style.height;
  141. if (height === expandedHeight + "px") {
  142. htmlElement.style.height = paper.canvas.style.height = 35 + "px";
  143. }
  144. else {
  145. htmlElement.style.height = paper.canvas.style.height = expandedHeight + "px";
  146. }
  147. };
  148. element.rect.click(onClick);
  149. };
  150. List.prototype._createListElementAnimation = function (element) {
  151. var _this = this;
  152. var onMove = function (dx, dy, x, y) { };
  153. var onStart = function (x, y, event) {
  154. _this._parentContainer.style.cursor = "copy";
  155. element.rect.animate({
  156. x: -10,
  157. opacity: 0.25
  158. }, 500, ">");
  159. element.text.animate({
  160. x: 10,
  161. opacity: 0.25
  162. }, 500, ">");
  163. };
  164. var onEnd = function (event) {
  165. _this._parentContainer.style.cursor = "default";
  166. element.rect.animate({
  167. x: 10,
  168. opacity: 1.0
  169. }, 500, "<");
  170. element.text.animate({
  171. x: 30,
  172. opacity: 1.0
  173. }, 500, "<");
  174. var dragResult = _this._viewer.traverseGraph(null, _this._viewer.mousex, _this._viewer.mousey, false);
  175. if (dragResult.hit) {
  176. if (element.type === ActionsBuilder.Type.TRIGGER && dragResult.action !== _this._viewer.root) {
  177. alert("Triggers can be dragged only on the root node (the mesh)");
  178. return;
  179. }
  180. if (element.type === ActionsBuilder.Type.ACTION && dragResult.action === _this._viewer.root) {
  181. alert("Please add a trigger before.");
  182. return;
  183. }
  184. if (element.type === ActionsBuilder.Type.FLOW_CONTROL && dragResult.action === _this._viewer.root) {
  185. return;
  186. }
  187. if (element.type === ActionsBuilder.Type.FLOW_CONTROL && dragResult.action.combineArray !== null) {
  188. alert("A condition cannot be handled by a Combine Action.");
  189. return;
  190. }
  191. if ((element.type === ActionsBuilder.Type.FLOW_CONTROL || element.type === ActionsBuilder.Type.ACTION) && dragResult.action.type === ActionsBuilder.Type.TRIGGER && dragResult.action.children.length > 0) {
  192. alert("Triggers can have only one child. Please add another trigger of same type.");
  193. return;
  194. }
  195. if (!(dragResult.action.combineArray !== null) && dragResult.action.children.length > 0 && dragResult.action.type !== ActionsBuilder.Type.TRIGGER && dragResult.action !== _this._viewer.root) {
  196. alert("An action can have only one child.");
  197. return;
  198. }
  199. _this._viewer.addAction(dragResult.action, element.type, element.element);
  200. _this._viewer.update();
  201. }
  202. };
  203. element.rect.drag(onMove, onStart, onEnd);
  204. element.text.drag(onMove, onStart, onEnd);
  205. };
  206. return List;
  207. })();
  208. ActionsBuilder.List = List;
  209. })(ActionsBuilder || (ActionsBuilder = {}));