pbt.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. // jsEditor Manipulation
  2. var PBT = new Object();
  3. PBT.decorationStyles = new Array();
  4. PBT.decorations = new Array();
  5. PBT.ranges = new Array();
  6. PBT.prototype.clearDecorLines = function(lineRanges) {
  7. this.decorationStyles = [];
  8. this.decorations = [];
  9. for(var i = 0; i < lineRanges.length; i +=2) {
  10. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, linesDecorationsClassName: 'myLinethis.decorationOff' }});
  11. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, className: 'code-back-transparent' }});
  12. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, inlineClassName: 'code-transparent' }});
  13. }
  14. this.decorations = jsEditor.deltaDecorations.decorations(this.decorations, this.decorationStyles);
  15. }
  16. PBT.prototype.fadeLines = function(lineRanges) {
  17. this.decorationStyles = [];
  18. this.decorations = [];
  19. for(var i = 0; i < lineRanges.length; i +=2) {
  20. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, inlineClassName: 'code-transparent' }});
  21. }
  22. this.decorations = jsEditor.deltaDecorations.decorations(this.decorations, this.decorationStyles);
  23. }
  24. PBT.prototype.darkenLines = function(lineRanges) {
  25. this.decorationStyles = [];
  26. this.decorations = [];
  27. for(var i = 0; i < lineRanges.length; i +=2) {
  28. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, inlineClassName: 'code-highlight' }});
  29. }
  30. this.decorations = jsEditor.deltaDecorations.decorations(this.decorations, this.decorationStyles);
  31. }
  32. PBT.prototype.setDecorLines = function (lineRanges) {
  33. this.decorationStyles = [];
  34. this.decorations = [];
  35. for(var i = 0; i < lineRanges.length; i +=2) {
  36. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, linesDecorationsClassName: 'myLinethis.decoration' }});
  37. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, className: 'code-back-highlight' }});
  38. this.decorationStyles.push({ range: new monaco.Range(parseInt(lineRanges[i]),1,parseInt(lineRanges[i + 1]),1), options: { isWholeLine: true, inlineClassName: 'code-highlight' }});
  39. }
  40. this.decorations = jsEditor.deltaDecorations.decorations(this.decorations, this.decorationStyles);
  41. }
  42. PBT.prototype.replaceLines = function(lineRange, text) {
  43. jsEditor.executeEdits("", [
  44. { range: new monaco.Range(parseInt(lineRange[0]), 1, parseInt(lineRange[1]), 100000), text: text}
  45. ]);
  46. }
  47. PBT.prototype.hideLines = function(lineRanges) {
  48. PBT.ranges = [];
  49. for(var i = 0; i < lineRanges.length; i +=2) {
  50. PBT.ranges.push(new monaco.Range(parseInt(lineRanges[i]), 1, parseInt(lineRanges[i + 1]), 100000));
  51. }
  52. jsEditor.setHiddenAreas(ranges);
  53. }
  54. PBT.prototype.editOn = function() {
  55. jsEditor.updateOptions({readOnly: false});
  56. }
  57. PBT.prototype.editOff = function() {
  58. jsEditor.updateOptions({readOnly: true});
  59. }
  60. //Standard GUI Dialogues
  61. PBT.advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
  62. PBT.protoype.addStandardDialog = function(options) {
  63. var width = options.width||0.5;
  64. var height = options.height||0.25;
  65. var top = options.top||0;
  66. var left = options.left||0;
  67. var verticalAlignment = options.verticalAlignment||BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  68. var horizontalALignment = options.horizontalALignment||BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  69. var text = options.text||"Playground Based Tutorial";
  70. var container = new BABYLON.GUI.Rectangle();
  71. container.verticalAlignment = verticalAlignment;
  72. container.horizontalAlignment = horizontalAlignment;
  73. container.width = width;
  74. container.height = height;
  75. container.cornerRadius = 10;
  76. container.color = "#364249";
  77. container.thickness = 4;
  78. container.background = "#CDC98F9";
  79. container.top = top;
  80. container.left = left;
  81. PBT.advancedTexture.addControl(container);
  82. var logoPBT = BABYLON.GUI.Button.CreateImageOnlyButton("but", "LogoPBT.png");
  83. logoPBT.width = 0.4;
  84. logoPBT.height = 0.8;
  85. logoPBT.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  86. logoPBT.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  87. logoPBT.top = 2;
  88. logoPBT.left=2;
  89. container.addControl(logoPBT);
  90. var textBlock = new BABYLON.GUI.TextBlock("text", text);
  91. textBlock.width = 0.55;
  92. textBlock.height = 0.7
  93. textBlock.textWrapping = true;
  94. textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  95. textBlock.paddingLeft = 2;
  96. textBlock.color = "white";
  97. textBlock.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  98. textBlock.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  99. textBlock.left = 0.45;
  100. textBlock.top = 2;
  101. container.addControl(textBlock);
  102. var nextButton = BABYLON.GUI.Button.CreateSimpleButton("nextbut", "Next >");
  103. nextButton.width = 0.2
  104. nextButton.height = 0.15;
  105. nextButton.color = "white";
  106. nextButton.cornerRadius = 5;
  107. nextButton.background = "#364249";
  108. nextButton.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  109. nextButton.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  110. nextButton.left = 0.7;
  111. nextButton.top = 0.8;
  112. container.addControl(nextButton);
  113. var prevButton = BABYLON.GUI.Button.CreateSimpleButton("prevbut", "< Prev");
  114. prevButton.width = 0.2
  115. prevButton.height = 0.15;
  116. prevButton.color = "white";
  117. prevButton.cornerRadius = 5;
  118. prevButton.background = "#364249";
  119. prevButton.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  120. prevButton.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  121. prevButton.left = 0.7;
  122. prevButton.top = 0.8;
  123. container.addControl(prevButton);
  124. }
  125. /*
  126. var justStarted = true;
  127. //radio Controls
  128. var addRadio = function(text, parent, group, func, checked) {
  129. checked = checked || false;
  130. var button = new BABYLON.GUI.RadioButton();
  131. button.width = "20px";
  132. button.height = "20px";
  133. button.color = "white";
  134. button.background = "green";
  135. button.group = group;
  136. button.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  137. button.onIsCheckedChangedObservable.add(function(state) {
  138. if (state && !justStarted) {
  139. func();
  140. }
  141. });
  142. var header = BABYLON.GUI.Control.AddHeader(button, text, "80px", { isHorizontal: true, controlFirst: true });
  143. header.height = "30px";
  144. parent.addControl(header);
  145. button.isChecked = checked;
  146. }
  147. var selectContainer = new BABYLON.GUI.Rectangle();
  148. selectContainer.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_BOTTOM;
  149. selectContainer.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
  150. selectContainer.width = 0.15;
  151. selectContainer.height = 0.45;
  152. selectContainer.cornerRadius = 10;
  153. selectContainer.color = "Orange";
  154. selectContainer.thickness = 4;
  155. selectContainer.background = "green";
  156. selectContainer.top = -5;
  157. selectContainer.left = -5;
  158. advancedTexture.addControl(selectContainer);
  159. var panel = new BABYLON.GUI.StackPanel();
  160. panel.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  161. panel.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  162. panel.top = 5;
  163. panel.left = 5;
  164. selectContainer.addControl(panel);
  165. var orderHeading = new BABYLON.GUI.TextBlock("orderHead", "Order");
  166. orderHeading.width = 0.9;
  167. orderHeading.height = 0.1
  168. orderHeading.textWrapping = true;
  169. orderHeading.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  170. orderHeading.paddingLeft = 2;
  171. panel.addControl(orderHeading);
  172. addRadio("XYZ", panel, "order", XYZ, true);
  173. addRadio("YXZ", panel, "order", YXZ);
  174. addRadio("YZX", panel, "order", YZX);
  175. addRadio("ZYX", panel, "order", ZYX);
  176. addRadio("ZXY", panel, "order", ZXY);
  177. addRadio("XZY", panel, "order", XZY);
  178. var separator = new BABYLON.GUI.Rectangle();
  179. separator.width = 0.9;
  180. separator.height = 0.02;
  181. separator.background = "orange";
  182. separator.color = "orange";
  183. panel.addControl(separator);
  184. var spaceHeading = new BABYLON.GUI.TextBlock("spaceHead", "Space");
  185. spaceHeading.width = 0.9;
  186. spaceHeading.height = 0.1
  187. spaceHeading.textWrapping = true;
  188. spaceHeading.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  189. spaceHeading.paddingLeft = 2;
  190. panel.addControl(spaceHeading);
  191. addRadio("WORLD", panel, "space", worldSpace, true);
  192. addRadio("LOCAL", panel, "space", localSpace);
  193. // check box
  194. //Selection Controls
  195. var addCheckBox = function(text, parent, func, checked) {
  196. checked = checked || false;
  197. var button = new BABYLON.GUI.Checkbox();
  198. button.width = "20px";
  199. button.height = "20px";
  200. button.color = "white";
  201. button.background = "green";
  202. button.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  203. button.onIsCheckedChangedObservable.add(function(state) {
  204. func();
  205. });
  206. var header = BABYLON.GUI.Control.AddHeader(button, text, "150px", { isHorizontal: true, controlFirst: true });
  207. header.height = "30px";
  208. parent.addControl(header);
  209. button.isChecked = checked;
  210. }
  211. var hideBoxCode = function() {
  212. var ranges = [];
  213. if(boxHideCode) {
  214. ranges.push(new monaco.Range(13, 1, 33, 100000)); // box code
  215. if(!animHideCode) {
  216. ranges.push(new monaco.Range(37, 1, 48, 100000)); // animation code
  217. }
  218. }
  219. else {
  220. if(!animHideCode) {
  221. ranges.push(new monaco.Range(37, 1, 48, 100000)); // animation code
  222. }
  223. }
  224. //ranges.push(new monaco.Range(50, 1, 242, 100000)); // tutor code 2
  225. //ranges.push(new monaco.Range(246, 1, 250, 100000)); // tutor code 2
  226. jsEditor.setHiddenAreas(ranges);
  227. boxHideCode = !boxHideCode;
  228. }
  229. var hideAnimCode = function() {
  230. var ranges = [];
  231. if(animHideCode) {
  232. ranges = [];
  233. if(!boxHideCode) {
  234. ranges.push(new monaco.Range(13, 1, 33, 100000)); // animation code
  235. }
  236. ranges.push(new monaco.Range(37, 1, 48, 100000)); // animation code
  237. }
  238. else {
  239. ranges = [];
  240. if(!boxHideCode) {
  241. ranges.push(new monaco.Range(13, 1, 33, 100000)); // animation code
  242. }
  243. }
  244. //ranges.push(new monaco.Range(50, 1, 242, 100000)); // tutor code 2
  245. //ranges.push(new monaco.Range(246, 1, 250, 100000)); // tutor code 2
  246. jsEditor.setHiddenAreas(ranges);
  247. animHideCode = !animHideCode;
  248. }
  249. var selectContainer = new BABYLON.GUI.Rectangle();
  250. selectContainer.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_BOTTOM;
  251. selectContainer.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
  252. selectContainer.width = 0.22;
  253. selectContainer.height = 0.2;
  254. selectContainer.cornerRadius = 10;
  255. selectContainer.color = "Orange";
  256. selectContainer.thickness = 4;
  257. selectContainer.background = "green";
  258. selectContainer.top = -5;
  259. selectContainer.left = -5;
  260. advancedTexture.addControl(selectContainer);
  261. var panel = new BABYLON.GUI.StackPanel();
  262. panel.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;
  263. panel.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
  264. panel.top = 2;
  265. panel.left = 4;
  266. selectContainer.addControl(panel);
  267. var orderHeading = new BABYLON.GUI.TextBlock("orderHead", "Box Mesh");
  268. orderHeading.width = 0.9;
  269. orderHeading.height = 0.14
  270. orderHeading.textWrapping = true;
  271. orderHeading.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  272. orderHeading.paddingLeft = 2;
  273. panel.addControl(orderHeading);
  274. var boxHideCode = true;
  275. var animHideCode = false;
  276. addCheckBox("Hide Box Code", panel, hideBoxCode, true);
  277. var separator = new BABYLON.GUI.Rectangle();
  278. separator.width = 0.9;
  279. separator.height = 0.02;
  280. separator.background = "orange";
  281. separator.color = "orange";
  282. panel.addControl(separator);
  283. var gap = new BABYLON.GUI.Rectangle();
  284. gap.width = 0.9;
  285. gap.height = 0.1;
  286. gap.background = "green";
  287. gap.color = "green";
  288. panel.addControl(gap);
  289. var spaceHeading = new BABYLON.GUI.TextBlock("spaceHead", "Animation");
  290. spaceHeading.width = 0.9;
  291. spaceHeading.height = 0.1
  292. spaceHeading.textWrapping = true;
  293. spaceHeading.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  294. spaceHeading.paddingLeft = 2;
  295. panel.addControl(spaceHeading);
  296. animHideCode = true;
  297. addCheckBox("Hide Code", panel, hideAnimCode, true);
  298. */