GuiEditor.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function GuiEditor::create( %this )
  23. {
  24. exec("./scripts/GuiEditorBrain.cs");
  25. exec("./scripts/GuiEditorControlListWindow.cs");
  26. exec("./scripts/GuiEditorControlListBox.cs");
  27. exec("./scripts/GuiEditorInspectorWindow.cs");
  28. exec("./scripts/GuiEditorInspector.cs");
  29. exec("./scripts/GuiEditorExplorerWindow.cs");
  30. exec("./scripts/GuiEditorExplorerTree.cs");
  31. exec("./scripts/GuiEditorSaveGuiDialog.cs");
  32. exec("./scripts/GuiEditorGridSizeDialog.cs");
  33. exec("./scripts/GuiEditorColorWindow.cs");
  34. %this.guiPage = EditorCore.RegisterEditor("Gui Editor", %this);
  35. %this.content = %this.createFrameSet();
  36. %this.brain = new GuiEditCtrl()
  37. {
  38. Class = "GuiEditorBrain";
  39. HorizSizing = "width";
  40. VertSizing = "height";
  41. Position = "0 0";
  42. Extent = "100 100";
  43. };
  44. ThemeManager.setProfile(%this.brain, "guiEditorProfile");
  45. %this.inspectorWindow = new GuiWindowCtrl()
  46. {
  47. Class = "GuiEditorInspectorWindow";
  48. HorizSizing = "right";
  49. VertSizing = "bottom";
  50. Position = "0 0";
  51. Extent = "360 380";
  52. MinExtent = "100 100";
  53. text = "Gui Inspector";
  54. canMove = true;
  55. canClose = false;
  56. canMinimize = true;
  57. canMaximize = false;
  58. resizeWidth = true;
  59. resizeHeight = true;
  60. };
  61. ThemeManager.setProfile(%this.inspectorWindow, "windowProfile");
  62. ThemeManager.setProfile(%this.inspectorWindow, "windowContentProfile", "ContentProfile");
  63. ThemeManager.setProfile(%this.inspectorWindow, "windowButtonProfile", "CloseButtonProfile");
  64. ThemeManager.setProfile(%this.inspectorWindow, "windowButtonProfile", "MinButtonProfile");
  65. ThemeManager.setProfile(%this.inspectorWindow, "windowButtonProfile", "MaxButtonProfile");
  66. %this.content.add(%this.inspectorWindow);
  67. %this.inspectorWindow.startListening(%this.brain);
  68. %this.background = new GuiSpriteCtrl() {
  69. HorizSizing = "right";
  70. VertSizing = "bottom";
  71. Position = "0 0";
  72. Extent = "100 100";
  73. imageColor = "255 255 255 255";
  74. Image = "EditorCore:editorGrid";
  75. singleFrameBitmap = "1";
  76. tileImage = "1";
  77. positionOffset = "0 0";
  78. imageSize = "128 128";
  79. fullSize = "0";
  80. constrainProportions = "1";
  81. };
  82. ThemeManager.setProfile(%this.background, "emptyProfile");
  83. %this.content.add(%this.background);
  84. %this.ctrlListWindow = new GuiWindowCtrl()
  85. {
  86. Class = "GuiEditorControlListWindow";
  87. HorizSizing = "right";
  88. VertSizing = "bottom";
  89. Position = "360 0";
  90. Extent = "250 380";
  91. MinExtent = "100 100";
  92. text = "Control List";
  93. canMove = true;
  94. canClose = false;
  95. canMinimize = true;
  96. canMaximize = false;
  97. resizeWidth = true;
  98. resizeHeight = true;
  99. };
  100. ThemeManager.setProfile(%this.ctrlListWindow, "windowProfile");
  101. ThemeManager.setProfile(%this.ctrlListWindow, "windowContentProfile", "ContentProfile");
  102. ThemeManager.setProfile(%this.ctrlListWindow, "windowButtonProfile", "CloseButtonProfile");
  103. ThemeManager.setProfile(%this.ctrlListWindow, "windowButtonProfile", "MinButtonProfile");
  104. ThemeManager.setProfile(%this.ctrlListWindow, "windowButtonProfile", "MaxButtonProfile");
  105. %this.content.add(%this.ctrlListWindow);
  106. %this.explorerWindow = new GuiWindowCtrl()
  107. {
  108. Class = "GuiEditorExplorerWindow";
  109. HorizSizing = "right";
  110. VertSizing = "bottom";
  111. Position = "610 0";
  112. Extent = "400 380";
  113. MinExtent = "100 100";
  114. text = "Explorer";
  115. canMove = true;
  116. canClose = false;
  117. canMinimize = true;
  118. canMaximize = false;
  119. resizeWidth = true;
  120. resizeHeight = true;
  121. };
  122. ThemeManager.setProfile(%this.explorerWindow, "windowProfile");
  123. ThemeManager.setProfile(%this.explorerWindow, "windowContentProfile", "ContentProfile");
  124. ThemeManager.setProfile(%this.explorerWindow, "windowButtonProfile", "CloseButtonProfile");
  125. ThemeManager.setProfile(%this.explorerWindow, "windowButtonProfile", "MinButtonProfile");
  126. ThemeManager.setProfile(%this.explorerWindow, "windowButtonProfile", "MaxButtonProfile");
  127. %this.content.add(%this.explorerWindow);
  128. %this.explorerWindow.startListening(%this.brain);
  129. %this.rootGui = new GuiControl()
  130. {
  131. HorizSizing = "width";
  132. VertSizing = "height";
  133. Position = "0 0";
  134. Extent = %this.background.getExtent();
  135. Profile = GuiDefaultProfile;
  136. class = "SimulatedCanvas";
  137. };
  138. %this.background.add(%this.rootGui);
  139. %this.brain.extent = %this.background.getExtent();
  140. %this.background.add(%this.brain);
  141. %this.fileName = "";
  142. %this.filePath = "";
  143. %this.formatIndex = 0;
  144. %this.folder = "";
  145. %this.module = "";
  146. %this.brain.setRoot(%this.rootGui);
  147. %this.brain.root = %this.rootGui;
  148. %this.explorerWindow.inspect(%this.rootGui);
  149. /* %this.colorWindow = new GuiWindowCtrl()
  150. {
  151. Class = "GuiEditorColorWindow";
  152. HorizSizing = "right";
  153. VertSizing = "bottom";
  154. Position = "610 0";
  155. Extent = "400 380";
  156. MinExtent = "100 100";
  157. text = "Color Test";
  158. canMove = true;
  159. canClose = false;
  160. canMinimize = true;
  161. canMaximize = false;
  162. resizeWidth = true;
  163. resizeHeight = true;
  164. };
  165. ThemeManager.setProfile(%this.colorWindow, "windowProfile");
  166. ThemeManager.setProfile(%this.colorWindow, "windowContentProfile", "ContentProfile");
  167. ThemeManager.setProfile(%this.colorWindow, "windowButtonProfile", "CloseButtonProfile");
  168. ThemeManager.setProfile(%this.colorWindow, "windowButtonProfile", "MinButtonProfile");
  169. ThemeManager.setProfile(%this.colorWindow, "windowButtonProfile", "MaxButtonProfile");
  170. %this.guiPage.add(%this.colorWindow); */
  171. EditorCore.FinishRegistration(%this.guiPage);
  172. }
  173. function GuiEditor::createFrameSet(%this)
  174. {
  175. %content = new GuiFrameSetCtrl() {
  176. HorizSizing = "width";
  177. VertSizing = "height";
  178. Position = "0 0";
  179. Extent = %this.guiPage.getExtent();
  180. DividerThickness = 6;
  181. };
  182. ThemeManager.setProfile(%content, "frameSetProfile");
  183. ThemeManager.setProfile(%content, "dropButtonProfile", "dropButtonProfile");
  184. ThemeManager.setProfile(%content, "frameSetTabBookProfile", "tabBookProfile");
  185. ThemeManager.setProfile(%content, "frameSetTabProfile", "tabProfile");
  186. ThemeManager.setProfile(%content, "frameSetTabPageProfile", "tabPageProfile");
  187. %this.guiPage.add(%content);
  188. %idList = %content.createHorizontalSplit(1);
  189. %leftID = getWord(%idList, 0);
  190. %rightID = getWord(%idList, 1);
  191. %content.anchorFrame(%rightID);
  192. %content.setFrameSize(%rightID, 300);
  193. %ids = %content.createHorizontalSplit(%leftID);
  194. %inspectorFrameID = getWord(%ids, 0);
  195. %centerFrameID = getWord(%ids, 1);
  196. %content.setFrameSize(%inspectorFrameID, 360);
  197. %ids = %content.createVerticalSplit(%rightID);
  198. %toolFrameID = getWord(%ids, 0);
  199. %explorerFrameID = getWord(%ids, 1);
  200. %content.setFrameSize(%toolFrameID, 380);
  201. return %content;
  202. }
  203. //-----------------------------------------------------------------------------
  204. function GuiEditor::destroy( %this )
  205. {
  206. }
  207. function GuiEditor::open(%this, %content)
  208. {
  209. EditorCore.menuBar.setMenuActive("File", true);
  210. //EditorCore.menuBar.setMenuActive("Edit", true); //These features still need development
  211. EditorCore.menuBar.setMenuActive("Layout", true);
  212. EditorCore.menuBar.setMenuActive("Select", true);
  213. editorMode(true);
  214. }
  215. function GuiEditor::close(%this)
  216. {
  217. editorMode(false);
  218. EditorCore.menuBar.setMenuActive("File", false);
  219. EditorCore.menuBar.setMenuActive("Edit", false);
  220. EditorCore.menuBar.setMenuActive("Layout", false);
  221. EditorCore.menuBar.setMenuActive("Select", false);
  222. }
  223. //MENU FUNCTIONS---------------------------------------------------------------
  224. function GuiEditor::NewGui(%this)
  225. {
  226. %this.rootGui.clear();
  227. %this.fileName = "";
  228. %this.filePath = "";
  229. %this.formatIndex = 0;
  230. %this.folder = "";
  231. %this.module = "";
  232. %this.brain.clearSelection();
  233. %this.explorerWindow.tree.refresh();
  234. }
  235. function GuiEditor::OpenGui(%this)
  236. {
  237. %path = pathConcat(getMainDotCsDir(), ProjectManager.getProjectFolder());
  238. %dialog = new OpenFileDialog()
  239. {
  240. Filters = "ALL (*.GUI;*.GUI.DSO;*.GUI.TAML)|*.GUI;*.GUI.DSO;*.GUI.TAML|GUI (*.GUI;*.GUI.DSO)|*.GUI;*.GUI.DSO|TAML (*.GUI.TAML)|*.GUI.TAML";
  241. ChangePath = false;
  242. MultipleFiles = false;
  243. DefaultFile = "";
  244. defaultPath = %path;
  245. title = "Open Gui File";
  246. };
  247. %result = %dialog.execute();
  248. if ( %result )
  249. {
  250. if(fileExt(%dialog.fileName) $= ".taml")
  251. {
  252. %guiContent = TAMLRead(%dialog.fileName);
  253. %includesSimulatedCanvas = (%guiContent.class $= "SimulatedCanvas");
  254. }
  255. else
  256. {
  257. exec(%dialog.fileName);
  258. }
  259. if(%includesSimulatedCanvas $= "")
  260. {
  261. %includesSimulatedCanvas = true;
  262. }
  263. if(isObject(%guiContent))
  264. {
  265. %this.fileName = fileName(%dialog.fileName);
  266. %this.filePath = %dialog.fileName;
  267. %this.formatIndex = 0;
  268. if(getSubStr(%dialog.fileName, strlen(%dialog.fileName) - 5, 5) $= ".taml")
  269. {
  270. %this.formatIndex = 1;
  271. }
  272. %this.folder = makeRelativePath(filePath(%dialog.fileName), getMainDotCsDir());
  273. %this.module = EditorCore.findModuleOfPath(%dialog.fileName);
  274. %this.DisplayGuiContent(%guiContent, %includesSimulatedCanvas);
  275. }
  276. else
  277. {
  278. EditorCore.alert("Something went wrong while opening the Gui File. Gui Files should be structures with the root object assigned to %guiContent. If this file was made outside of the editor, you can change it manually and then open it in the Gui Editor.");
  279. }
  280. }
  281. // Cleanup
  282. %dialog.delete();
  283. }
  284. function GuiEditor::DisplayGuiContent(%this, %content, %includesSimulatedCanvas)
  285. {
  286. %this.rootGui.deleteObjects();
  287. %this.brain.clearSelection();
  288. if(%includesSimulatedCanvas)
  289. {
  290. %count = %content.getCount();
  291. for(%i = 0; %i < %count; %i++)
  292. {
  293. %obj[%i] = %content.getObject(%i);
  294. }
  295. for(%i = 0; %i < %count; %i++)
  296. {
  297. %this.rootGui.add(%obj[%i]);
  298. }
  299. %content.delete();
  300. %this.explorerWindow.tree.refresh();
  301. %this.brain.onSelect(%this.rootGui.getObject(0));
  302. }
  303. else
  304. {
  305. %this.rootGui.add(%content);
  306. %this.explorerWindow.tree.refresh();
  307. %this.brain.onSelect(%content);
  308. }
  309. }
  310. function GuiEditor::SaveGui(%this)
  311. {
  312. if(%this.fileName $= "")
  313. {
  314. %this.SaveGuiAs();
  315. }
  316. else
  317. {
  318. %this.SaveCore(%this.filePath, %this.formatIndex, %this.folder, %this.module);
  319. }
  320. }
  321. function GuiEditor::SaveGuiAs(%this)
  322. {
  323. %width = 700;
  324. %height = 390;
  325. %dialog = new GuiControl()
  326. {
  327. class = "GuiEditorSaveGuiDialog";
  328. superclass = "EditorDialog";
  329. dialogSize = (%width + 8) SPC (%height + 8);
  330. dialogCanClose = true;
  331. dialogText = "Save Gui";
  332. defaultFileName = %this.fileName;
  333. formatIndex = %this.formatIndex;
  334. defaultFolder = %this.folder;
  335. defaultModule = %this.module;
  336. };
  337. %dialog.init(%width, %height);
  338. Canvas.pushDialog(%dialog);
  339. }
  340. function GuiEditor::SaveCore(%this, %filePath, %formatIndex, %folder, %module)
  341. {
  342. if(%formatIndex == 0)
  343. {
  344. %fo = new FileObject();
  345. %fo.openForWrite(%filePath);
  346. %fo.writeLine("//--- Created with the GuiEditor ---//");
  347. if(%this.rootGui.getCount() == 1)
  348. {
  349. //Saved without the simulated canvas
  350. %fo.writeLine("%includesSimulatedCanvas = false;");
  351. %fo.writeObject(%this.rootGui.getObject(0), "%guiContent = ");
  352. }
  353. else
  354. {
  355. //We have multiple top level objects so include the containing simulated canvas
  356. %fo.writeLine("%includesSimulatedCanvas = true;");
  357. %fo.writeObject(%this.rootGui, "%guiContent = ");
  358. }
  359. %fo.writeLine("//--- GuiEditor End ---//");
  360. %fo.close();
  361. %fo.delete();
  362. }
  363. else
  364. {
  365. if(GuiEditor.rootGui.getCount() == 1)
  366. {
  367. //Saved without the Simulated Canvas
  368. TAMLWrite(%this.rootGui.getObject(0), %filePath);
  369. }
  370. else
  371. {
  372. TAMLWrite(%this.rootGui, %filePath);
  373. }
  374. }
  375. %this.fileName = fileName(%filePath);
  376. %this.filePath = %filePath;
  377. %this.formatIndex = %formatIndex;
  378. %this.folder = %folder;
  379. %this.module = %module;
  380. }
  381. function GuiEditor::Undo(%this)
  382. {
  383. %undoManager = %this.brain.getUndoManager();
  384. %undoManager.undo();
  385. }
  386. function GuiEditor::Redo(%this)
  387. {
  388. %undoManager = %this.brain.getUndoManager();
  389. %undoManager.redo();
  390. %count = %undoManager.getRedoCount();
  391. }
  392. function GuiEditor::Cut(%this)
  393. {
  394. }
  395. function GuiEditor::Copy(%this)
  396. {
  397. }
  398. function GuiEditor::Paste(%this)
  399. {
  400. }
  401. function GuiEditor::changeExtent(%this, %x, %y)
  402. {
  403. %set = %this.brain.getSelected();
  404. if(%set.getCount() >= 1)
  405. {
  406. %obj = %set.getObject(0);
  407. %ext = %obj.getExtent();
  408. %obj.setExtent(getWord(%ext, 0) + %x, getWord(%ext, 1) + %y);
  409. }
  410. }
  411. function GuiEditor::SetGridSize(%this)
  412. {
  413. %width = 300;
  414. %height = 140;
  415. %dialog = new GuiControl()
  416. {
  417. class = "GuiEditorGridSizeDialog";
  418. superclass = "EditorDialog";
  419. dialogSize = (%width + 8) SPC (%height + 8);
  420. dialogCanClose = true;
  421. dialogText = "Grid Size";
  422. };
  423. %dialog.init(%width, %height);
  424. Canvas.pushDialog(%dialog);
  425. }
  426. function GuiEditor::SnapToGrid(%this, %gridOn)
  427. {
  428. if(%gridOn)
  429. {
  430. %this.brain.setSnapToGrid(10);
  431. }
  432. else
  433. {
  434. %this.brain.setSnapToGrid(0);
  435. }
  436. }
  437. //METHODS-----------------------------------------------------------------