convexEditorGui.tscript 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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.setBitmap( getAssetPreviewImage(%mat.getDiffuseMap(0)));
  37. ConvexEditorOptionsWindow.activeMaterial = %mat;
  38. }
  39. }
  40. function ConvexEditorGui::onSleep( %this )
  41. {
  42. }
  43. function ConvexEditorGui::createConvexBox( %this )
  44. {
  45. %obj = genericCreateObject( "ConvexShape" );
  46. %obj.setMaterial(%this.materialName); //set whatever the editor has as it's default material to the new one
  47. %this.handleDeselect();
  48. %this.selectConvex( %obj );
  49. %this.dropSelectionAtScreenCenter();
  50. }
  51. function ConvexEditorGui::onSelectionChanged( %this, %shape, %face )
  52. {
  53. //echo( "onSelectionChanged: " @ %shape SPC %face );
  54. ConvexEditorSplitFaceBtn.setActive( false );
  55. ConvexEditorSplitFaceBtn.ToolTip = "Split selected face [Disabled]" NL "Use Ctrl + Rotate instead for more control";
  56. ConvexEditorDeleteFaceBtn.setActive( false );
  57. ConvexEditorDeleteFaceBtn.ToolTip = "Delete selection [Disabled] (Delete)";
  58. if ( !isObject( %shape ) )
  59. {
  60. ConvexEditorOptionsWindow-->defMatPreviewBtn.setText("No Brush Selected");
  61. ConvexEditorOptionsWindow.activeShape = "";
  62. return;
  63. }
  64. ConvexEditorDeleteFaceBtn.setActive( true );
  65. ConvexEditorOptionsWindow-->defMatPreviewBtn.setText("");
  66. %shapeMat = %shape.getMaterial();
  67. ConvexEditorOptionsWindow-->defMatPreviewBtn.setBitmap(getAssetPreviewImage(%shapeMat.getDiffuseMap(0)));
  68. ConvexEditorOptionsWindow.activeShape = %shape;
  69. if ( %face == -1 )
  70. {
  71. ConvexEditorDeleteFaceBtn.ToolTip = "Delete selected ConvexShape (Delete)";
  72. ConvexEditorOptionsWindow-->UOffset.setText("");
  73. ConvexEditorOptionsWindow-->VOffset.setText("");
  74. ConvexEditorOptionsWindow-->UScale.setText("");
  75. ConvexEditorOptionsWindow-->VScale.setText("");
  76. ConvexEditorOptionsWindow-->ZRotation.setText("");
  77. }
  78. else
  79. {
  80. ConvexEditorDeleteFaceBtn.ToolTip = "Delete selected Face (Delete)";
  81. ConvexEditorSplitFaceBtn.ToolTip = "Split selected face" NL "Use Ctrl + Rotate instead for more control";
  82. ConvexEditorSplitFaceBtn.setActive( true );
  83. %UVOffset = %this.getSelectedFaceUVOffset();
  84. ConvexEditorOptionsWindow-->UOffset.setText(%UVOffset.x);
  85. ConvexEditorOptionsWindow-->VOffset.setText(%UVOffset.y);
  86. %UVScale = %this.getSelectedFaceUVScale();
  87. ConvexEditorOptionsWindow-->UScale.setText(%UVScale.x);
  88. ConvexEditorOptionsWindow-->VScale.setText(%UVScale.y);
  89. ConvexEditorOptionsWindow-->ZRotation.setText(ConvexEditorGui.getSelectedFaceZRot());
  90. }
  91. }
  92. function ConvexEditorUVFld::onReturn(%this)
  93. {
  94. EWorldEditor.isDirty = true;
  95. %offset = "0 0";
  96. %offset.x = ConvexEditorOptionsWindow-->UOffset.getText();
  97. %offset.y = ConvexEditorOptionsWindow-->VOffset.getText();
  98. %scale = "0 0";
  99. %scale.x = ConvexEditorOptionsWindow-->UScale.getText();
  100. %scale.y = ConvexEditorOptionsWindow-->VScale.getText();
  101. %rot = ConvexEditorOptionsWindow-->ZRotation.getText();
  102. ConvexEditorGui.setSelectedFaceUVOffset(%offset);
  103. ConvexEditorGui.setSelectedFaceUVScale(%scale);
  104. ConvexEditorGui.setSelectedFaceZRot(%rot);
  105. }
  106. function ConvexEditorUVHorzFlipBtn::onClick(%this)
  107. {
  108. EWorldEditor.isDirty = true;
  109. %current = ConvexEditorGui.getSelectedFaceHorzFlip();
  110. ConvexEditorGui.setSelectedFaceHorzFlip(!%current);
  111. }
  112. function ConvexEditorUVVertFlipBtn::onClick(%this)
  113. {
  114. EWorldEditor.isDirty = true;
  115. %current = ConvexEditorGui.getSelectedFaceVertFlip();
  116. ConvexEditorGui.setSelectedFaceVertFlip(!%current);
  117. }
  118. function ConvexEditorMaterialBtn::onClick(%this)
  119. {
  120. %this.getMaterialName();
  121. }
  122. function ConvexEditorMaterialBtn::getMaterialName(%this)
  123. {
  124. AssetBrowser.showDialog("MaterialAsset", %this @ ".gotMaterialName", "", "", "");
  125. //materialSelector.showDialog(%this @ ".gotMaterialName", "name");
  126. }
  127. function ConvexEditorMaterialBtn::gotMaterialName(%this, %name)
  128. {
  129. %materialAsset = AssetDatabase.acquireAsset(%name);
  130. //eval(%this.object @ "." @ %this.targetField @ " = " @ %name @ ";");
  131. //%this.object.changeMaterial(getTrailingNumber(%this.targetField), %name);
  132. //%this.object.inspectorApply();
  133. %diffusemap = %materialAsset.materialDefinitionName.getDiffuseMap(0);
  134. if(%diffusemap $= "")
  135. {
  136. %diffuseAsset = %materialAsset.materialDefinitionName.getDiffuseMapAsset(0);
  137. if(%diffuseAsset !$= "")
  138. {
  139. %diffuseAssetDef = AssetDatabase.acquireAsset(%diffuseAsset);
  140. %diffusemap = %diffuseAssetDef.getImagePath();
  141. }
  142. }
  143. ConvexEditorOptionsWindow-->matPreviewBtn.setBitmap(getAssetPreviewImage(%diffusemap));
  144. ConvexEditorOptionsWindow.activeMaterial = %materialAsset.materialDefinitionName;
  145. }
  146. function ConvexEditorMaterialApplyBtn::onClick(%this)
  147. {
  148. EWorldEditor.isDirty = true;
  149. ConvexEditorGui.setSelectedFaceMaterial(ConvexEditorOptionsWindow.activeMaterial);
  150. ConvexEditorGui.updateShape();
  151. }
  152. function ConvexEditorMaterialLiftBtn::onClick(%this)
  153. {
  154. %mat = ConvexEditorGui.getSelectedFaceMaterial();
  155. ConvexEditorOptionsWindow.activeMaterial = %mat;
  156. ConvexEditorOptionsWindow-->matPreviewBtn.setBitmap(getAssetPreviewImage(%mat.getDiffuseMap(0)));
  157. }
  158. function ConvexEditorMaterialResetBtn::onClick(%this)
  159. {
  160. EWorldEditor.isDirty = true;
  161. ConvexEditorGui.setSelectedFaceMaterial(ConvexEditorOptionsWindow.activeShape.material);
  162. ConvexEditorGui.updateShape();
  163. }
  164. function ConvexEditorGui::toggleGridSnap(%this)
  165. {
  166. %this.toggleGridSnapping();
  167. }
  168. function ConvexEditorGridSnapSizeFld::onReturn(%this)
  169. {
  170. ConvexEditorGui.setGridSnapSize(%this.getText());
  171. }
  172. function ConvexEditorDefaultMaterialBtn::onClick(%this)
  173. {
  174. %this.getMaterialName();
  175. }
  176. function ConvexEditorDefaultMaterialBtn::getMaterialName(%this)
  177. {
  178. //materialSelector.showDialog(%this @ ".gotMaterialName", "name");
  179. AssetBrowser.showDialog("MaterialAsset", %this @ ".gotMaterialName", "", "", "");
  180. }
  181. function ConvexEditorDefaultMaterialBtn::gotMaterialName(%this, %name)
  182. {
  183. %materialAsset = AssetDatabase.acquireAsset(%name);
  184. //eval(%this.object @ "." @ %this.targetField @ " = " @ %name @ ";");
  185. //%this.object.changeMaterial(getTrailingNumber(%this.targetField), %name);
  186. //%this.object.inspectorApply();
  187. %diffusemap = %materialAsset.materialDefinitionName.getDiffuseMap(0);
  188. if(%diffusemap $= "")
  189. {
  190. %diffuseAsset = %materialAsset.materialDefinitionName.getDiffuseMapAsset(0);
  191. if(%diffuseAsset !$= "")
  192. {
  193. %diffuseAssetDef = AssetDatabase.acquireAsset(%diffuseAsset);
  194. %diffusemap = %diffuseAssetDef.getImagePath();
  195. }
  196. }
  197. ConvexEditorOptionsWindow-->defMatPreviewBtn.setBitmap(getAssetPreviewImage(%diffusemap));
  198. ConvexEditorOptionsWindow.activeShape.setMaterial(%name);
  199. ConvexEditorGui.updateShape();
  200. }