convexEditorGui.tscript 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 ConvexEditorGui::onWake( %this )
  23. {
  24. convexEditorToolbar-->gridSnapSizeEdit.setText(%this.getGridSnapSize());
  25. if(ConvexEditorOptionsWindow-->matPreviewBtn.getBitmap() $= "")
  26. {
  27. //no active material, so set one
  28. ConvexEditorOptionsWindow-->matPreviewBtn.setText("");
  29. %mat = EditorSettings.Value("ConvexEditor/MaterialName");
  30. if(AssetDatabase.isDeclaredAsset(%mat))
  31. {
  32. %matName = AssetDatabase.acquireAsset(%mat).materialDefinitionName;
  33. AssetDatabase.releaseAsset(%mat);
  34. %mat = %matName;
  35. }
  36. ConvexEditorOptionsWindow-->matPreviewBtn.bitmapAsset = getAssetPreviewImage(%mat.getDiffuseMap(0));
  37. ConvexEditorOptionsWindow.activeMaterial = %mat;
  38. }
  39. %fluidWindow = ConvexEditorOptionsWindow;
  40. if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1)
  41. {
  42. // Let's dock the side panel to the right side
  43. %this.docked = false;
  44. %this.resizing = true;
  45. %this.dockSidePanel();
  46. }
  47. else
  48. {
  49. // Let's release the side panel so it can be moved
  50. %this.docked = true;
  51. %this.resizing = false;
  52. %this.releaseSidePanel();
  53. }
  54. EWorldEditor.UseGridSnap = EditorSettings.value("WorldEditor/Tools/UseGridSnap");
  55. CESnapOptions-->objectGridSnapBtn.setStateOn( EWorldEditor.UseGridSnap );
  56. %this.setGridSnap( EWorldEditor.UseGridSnap );
  57. EWorldEditor.setGridSnap( EWorldEditor.UseGridSnap );
  58. }
  59. function ConvexEditorGui::onSleep( %this )
  60. {
  61. }
  62. function ConvexEditorGui::createConvexBox( %this )
  63. {
  64. %obj = genericCreateObject( "ConvexShape" );
  65. %obj.setMaterial(%this.materialName); //set whatever the editor has as it's default material to the new one
  66. %this.handleDeselect();
  67. %this.selectConvex( %obj );
  68. %this.dropSelectionAtScreenCenter();
  69. }
  70. function ConvexEditorGui::onSelectionChanged( %this, %shape, %face )
  71. {
  72. //echo( "onSelectionChanged: " @ %shape SPC %face );
  73. ConvexEditorSplitFaceBtn.setActive( false );
  74. ConvexEditorSplitFaceBtn.ToolTip = "Split selected face [Disabled]" NL "Use Ctrl + Rotate instead for more control";
  75. ConvexEditorDeleteFaceBtn.setActive( false );
  76. ConvexEditorDeleteFaceBtn.ToolTip = "Delete selection [Disabled] (Delete)";
  77. if ( !isObject( %shape ) )
  78. {
  79. ConvexEditorOptionsWindow-->defMatPreviewBtn.setText("No Brush Selected");
  80. ConvexEditorOptionsWindow.activeShape = "";
  81. return;
  82. }
  83. ConvexEditorDeleteFaceBtn.setActive( true );
  84. ConvexEditorOptionsWindow-->defMatPreviewBtn.setText("");
  85. %shapeMat = %shape.getMaterial();
  86. ConvexEditorOptionsWindow-->defMatPreviewBtn.bitmapAsset = getAssetPreviewImage(%shapeMat.getDiffuseMap(0));
  87. ConvexEditorOptionsWindow.activeShape = %shape;
  88. if ( %face == -1 )
  89. {
  90. ConvexEditorDeleteFaceBtn.ToolTip = "Delete selected ConvexShape (Delete)";
  91. ConvexEditorOptionsWindow-->UOffset.setText("");
  92. ConvexEditorOptionsWindow-->VOffset.setText("");
  93. ConvexEditorOptionsWindow-->UScale.setText("");
  94. ConvexEditorOptionsWindow-->VScale.setText("");
  95. ConvexEditorOptionsWindow-->ZRotation.setText("");
  96. }
  97. else
  98. {
  99. ConvexEditorDeleteFaceBtn.ToolTip = "Delete selected Face (Delete)";
  100. ConvexEditorSplitFaceBtn.ToolTip = "Split selected face" NL "Use Ctrl + Rotate instead for more control";
  101. ConvexEditorSplitFaceBtn.setActive( true );
  102. %UVOffset = %this.getSelectedFaceUVOffset();
  103. ConvexEditorOptionsWindow-->UOffset.setText(%UVOffset.x);
  104. ConvexEditorOptionsWindow-->VOffset.setText(%UVOffset.y);
  105. %UVScale = %this.getSelectedFaceUVScale();
  106. ConvexEditorOptionsWindow-->UScale.setText(%UVScale.x);
  107. ConvexEditorOptionsWindow-->VScale.setText(%UVScale.y);
  108. ConvexEditorOptionsWindow-->ZRotation.setText(ConvexEditorGui.getSelectedFaceZRot());
  109. }
  110. }
  111. function ConvexEditorUVFld::onReturn(%this)
  112. {
  113. EWorldEditor.isDirty = true;
  114. %offset = "0 0";
  115. %offset.x = ConvexEditorOptionsWindow-->UOffset.getText();
  116. %offset.y = ConvexEditorOptionsWindow-->VOffset.getText();
  117. %scale = "0 0";
  118. %scale.x = ConvexEditorOptionsWindow-->UScale.getText();
  119. %scale.y = ConvexEditorOptionsWindow-->VScale.getText();
  120. %rot = ConvexEditorOptionsWindow-->ZRotation.getText();
  121. ConvexEditorGui.setSelectedFaceUVOffset(%offset);
  122. ConvexEditorGui.setSelectedFaceUVScale(%scale);
  123. ConvexEditorGui.setSelectedFaceZRot(%rot);
  124. }
  125. function ConvexEditorUVHorzFlipBtn::onClick(%this)
  126. {
  127. EWorldEditor.isDirty = true;
  128. %current = ConvexEditorGui.getSelectedFaceHorzFlip();
  129. ConvexEditorGui.setSelectedFaceHorzFlip(!%current);
  130. }
  131. function ConvexEditorUVVertFlipBtn::onClick(%this)
  132. {
  133. EWorldEditor.isDirty = true;
  134. %current = ConvexEditorGui.getSelectedFaceVertFlip();
  135. ConvexEditorGui.setSelectedFaceVertFlip(!%current);
  136. }
  137. function ConvexEditorMaterialBtn::onClick(%this)
  138. {
  139. %this.getMaterialName();
  140. }
  141. function ConvexEditorMaterialBtn::getMaterialName(%this)
  142. {
  143. AssetBrowser.showDialog("MaterialAsset", %this @ ".gotMaterialName", "", "", "");
  144. //materialSelector.showDialog(%this @ ".gotMaterialName", "name");
  145. }
  146. function ConvexEditorMaterialBtn::gotMaterialName(%this, %name)
  147. {
  148. %materialAsset = AssetDatabase.acquireAsset(%name);
  149. //eval(%this.object @ "." @ %this.targetField @ " = " @ %name @ ";");
  150. //%this.object.changeMaterial(getTrailingNumber(%this.targetField), %name);
  151. //%this.object.inspectorApply();
  152. %diffusemap = %materialAsset.materialDefinitionName.getDiffuseMapAsset(0);
  153. ConvexEditorOptionsWindow-->matPreviewBtn.bitmapAsset = getAssetPreviewImage(%diffusemap);
  154. ConvexEditorOptionsWindow.activeMaterial = %materialAsset.getAssetId();
  155. }
  156. function ConvexEditorMaterialApplyBtn::onClick(%this)
  157. {
  158. EWorldEditor.isDirty = true;
  159. ConvexEditorGui.setSelectedFaceMaterial(ConvexEditorOptionsWindow.activeMaterial);
  160. ConvexEditorGui.updateShape();
  161. }
  162. function ConvexEditorMaterialLiftBtn::onClick(%this)
  163. {
  164. %mat = ConvexEditorGui.getSelectedFaceMaterial();
  165. ConvexEditorOptionsWindow.activeMaterial = %mat;
  166. ConvexEditorOptionsWindow-->matPreviewBtn.setBitmap(getAssetPreviewImage(%mat.getDiffuseMap(0)));
  167. }
  168. function ConvexEditorMaterialResetBtn::onClick(%this)
  169. {
  170. EWorldEditor.isDirty = true;
  171. ConvexEditorGui.setSelectedFaceMaterial(ConvexEditorOptionsWindow.activeShape.material);
  172. ConvexEditorGui.updateShape();
  173. }
  174. function ConvexEditorGui::toggleGridSnap(%this)
  175. {
  176. EWorldEditor.UseGridSnap = !EWorldEditor.UseGridSnap;
  177. EditorSettings.setValue("WorldEditor/Tools/UseGridSnap", EWorldEditor.UseGridSnap );
  178. CESnapOptions-->objectGridSnapBtn.setStateOn( EWorldEditor.UseGridSnap );
  179. %this.setGridSnap( EWorldEditor.UseGridSnap );
  180. EWorldEditor.setGridSnap( EWorldEditor.UseGridSnap );
  181. }
  182. function ConvexEditorGridSnapSizeFld::onReturn(%this)
  183. {
  184. ConvexEditorGui.setGridSnapSize(%this.getText());
  185. }
  186. function ConvexEditorDefaultMaterialBtn::onClick(%this)
  187. {
  188. %this.getMaterialName();
  189. }
  190. function ConvexEditorDefaultMaterialBtn::getMaterialName(%this)
  191. {
  192. //materialSelector.showDialog(%this @ ".gotMaterialName", "name");
  193. AssetBrowser.showDialog("MaterialAsset", %this @ ".gotMaterialName", "", "", "");
  194. }
  195. function ConvexEditorDefaultMaterialBtn::gotMaterialName(%this, %name)
  196. {
  197. %materialAsset = AssetDatabase.acquireAsset(%name);
  198. //eval(%this.object @ "." @ %this.targetField @ " = " @ %name @ ";");
  199. //%this.object.changeMaterial(getTrailingNumber(%this.targetField), %name);
  200. //%this.object.inspectorApply();
  201. %diffusemap = %materialAsset.materialDefinitionName.getDiffuseMap(0);
  202. if(%diffusemap $= "")
  203. {
  204. %diffuseAsset = %materialAsset.materialDefinitionName.getDiffuseMapAsset(0);
  205. if(%diffuseAsset !$= "")
  206. {
  207. %diffuseAssetDef = AssetDatabase.acquireAsset(%diffuseAsset);
  208. %diffusemap = %diffuseAssetDef.getImagePath();
  209. }
  210. }
  211. ConvexEditorOptionsWindow-->defMatPreviewBtn.bitmapAsset = getAssetPreviewImage(%diffusemap);
  212. ConvexEditorOptionsWindow.activeShape.setMaterial(%name);
  213. ConvexEditorGui.updateShape();
  214. }
  215. function ESettingsWindow::getConvexEditorSettings(%this)
  216. {
  217. SettingsInspector.startGroup("Defaults");
  218. SettingsInspector.addSettingsField("ConvexEditor/MaterialName", "Default Material", "string",
  219. "The default material when creating a convexShape");
  220. SettingsInspector.endGroup();
  221. }
  222. //-----------------------------------------------------------------------------
  223. function ConvexEditorGui::maxSize(%this, %window)
  224. {
  225. // Resize the windows to the max height
  226. // and force these to the right side if set
  227. if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1 && %this.resizing == true)
  228. {
  229. // prevent onResize after a resize
  230. %this.resizing = false;
  231. %fluidWindow = ConvexEditorOptionsWindow;
  232. %offset = -1; // tweak the vertical offset so that it aligns neatly
  233. %top = EditorGuiToolbar.extent.y + %offset;
  234. %bottom = %top + 59;
  235. %position = Canvas.extent.x - %fluidWindow.extent.x SPC %top;
  236. %extent = %window.extent.x SPC Canvas.extent.y - %bottom;
  237. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  238. // --- AssetBrowser window ----------------------------------------------
  239. if(isObject(AssetBrowserWindow))
  240. {
  241. // Only resize the AssetBrowser if it's docked
  242. if(AssetBrowserWindow.docked == true)
  243. {
  244. // The width is relative to the sidepanel
  245. %browserWidth = Canvas.extent.x - %extent.x;
  246. %browserHeight = AssetBrowserWindow.extent.y;
  247. %browserPosY = Canvas.extent.y - AssetBrowserWindow.extent.y - 33;
  248. AssetBrowserWindow.resize(0, %browserPosY, %browserWidth, %browserHeight);
  249. }
  250. }
  251. // --- Windowed Console --------------------------------------------------
  252. if(isObject(windowConsoleControl))
  253. {
  254. // Only resize the AssetBrowser if it's docked
  255. if(windowConsoleControl.docked == true)
  256. {
  257. // The width is relative to the sidepanel
  258. %consoleWidth = Canvas.extent.x - %extent.x;
  259. %consoleHeight = windowConsoleControl.extent.y;
  260. %consolePosY = Canvas.extent.y - windowConsoleControl.extent.y - 33;
  261. windowConsoleControl.resize(0, %consolePosY, %consoleWidth, %consoleHeight);
  262. }
  263. }
  264. }
  265. }
  266. function ConvexEditorOptionsWindow::onMouseDragged(%this)
  267. {
  268. %parent = ConvexEditorGui;
  269. if(%parent.panelHidden == true)
  270. {
  271. %parent.showSidePanel();
  272. }
  273. if(%parent.resizing == false && %parent.docked == true)
  274. {
  275. %parent.resizing = true;
  276. %parent.maxSize(%this);
  277. }
  278. }
  279. function ConvexEditorGui::onResize(%this, %newPosition, %newExtent)
  280. {
  281. // Window to focus on (mostly the fluid window)
  282. %window = ConvexEditorOptionsWindow;
  283. if(%window.panelHidden == true)
  284. {
  285. %window.showSidePanel();
  286. }
  287. if(%this.resizing == false && %this.docked == true)
  288. {
  289. // Only resize once
  290. %this.resizing = true;
  291. %this.maxSize(%window);
  292. }
  293. }
  294. function ConvexEditorGui::dockSidePanel()
  295. {
  296. %parent = ConvexEditorGui;
  297. %fluidWindow = ConvexEditorOptionsWindow;
  298. if(%parent.docked == true)
  299. return;
  300. // Move and resize the window(s)
  301. %parent.resizing = true;
  302. %parent.maxSize(%fluidWindow);
  303. %parent.docked = true;
  304. %fluidWindow.onMouseDragged();
  305. // Lock the windows in place
  306. %fluidWindow.canCollapse = "0";
  307. %fluidWindow.canMove = "0";
  308. ConvexEditorGui_UnDockBtn.Visible = "1";
  309. ConvexEditorGui_DockBtn.Visible = "0";
  310. ConvexEditorGui_showBtn.Visible = "0";
  311. ConvexEditorGui_hideBtn.Visible = "1";
  312. }
  313. function ConvexEditorGui::releaseSidePanel()
  314. {
  315. %parent = ConvexEditorGui;
  316. %fluidWindow = ConvexEditorOptionsWindow;
  317. if(%parent.docked == false)
  318. return;
  319. %fluidWindow.canCollapse = "1";
  320. %fluidWindow.canMove = "1";
  321. ConvexEditorGui_UnDockBtn.Visible = "0";
  322. ConvexEditorGui_DockBtn.Visible = "1";
  323. ConvexEditorGui_showBtn.Visible = "0";
  324. ConvexEditorGui_hideBtn.Visible = "0";
  325. // Let's do a small resize so it's visually clear we're undocking
  326. %position = %fluidWindow.position.x - 6 SPC %fluidWindow.position.y + 6;
  327. %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y - 12;
  328. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  329. %parent.docked = false;
  330. %parent.resizing = false;
  331. }
  332. function ConvexEditorGui::hideSidePanel()
  333. {
  334. %parent = ConvexEditorGui;
  335. %fluidWindow = ConvexEditorOptionsWindow;
  336. ConvexEditorGui_showBtn.Visible = "1";
  337. ConvexEditorGui_hideBtn.Visible = "0";
  338. // hide the content of the panels
  339. %fluidWindow.titleText = %fluidWindow.text;
  340. %fluidWindow.text = "";
  341. ConvexEditorOptionsPanel.Visible = "0";
  342. ConvexEditorUVPanel.Visible = "0";
  343. ConvexEditorAdvPanel.Visible = "0";
  344. // Let's do a resize so that the panel is collapsed to the side
  345. %position = Canvas.extent.x - 24 SPC %fluidWindow.position.y;
  346. %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y;
  347. %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
  348. %parent.panelHidden = true;
  349. }
  350. function ConvexEditorGui::showSidePanel()
  351. {
  352. %parent = ConvexEditorGui;
  353. %fluidWindow = ConvexEditorOptionsWindow;
  354. ConvexEditorGui_showBtn.Visible = "0";
  355. ConvexEditorGui_hideBtn.Visible = "1";
  356. %fluidWindow.text = %fluidWindow.titleText;
  357. ConvexEditorOptionsPanel.Visible = "1";
  358. ConvexEditorUVPanel.Visible = "1";
  359. ConvexEditorAdvPanel.Visible = "1";
  360. %parent.resizing = true;
  361. %parent.maxSize(%fluidWindow);
  362. %parent.panelHidden = false;
  363. }
  364. //-----------------------------------------------------------------------------