123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
-
- function ConvexEditorGui::onWake( %this )
- {
- convexEditorToolbar-->gridSnapSizeEdit.setText(%this.getGridSnapSize());
-
- if(ConvexEditorOptionsWindow-->matPreviewBtn.getBitmap() $= "")
- {
- //no active material, so set one
- ConvexEditorOptionsWindow-->matPreviewBtn.setText("");
-
- %mat = EditorSettings.Value("ConvexEditor/MaterialName");
-
- if(AssetDatabase.isDeclaredAsset(%mat))
- {
- %matName = AssetDatabase.acquireAsset(%mat).materialDefinitionName;
- AssetDatabase.releaseAsset(%mat);
- %mat = %matName;
- }
-
- ConvexEditorOptionsWindow-->matPreviewBtn.setBitmap( getAssetPreviewImage(%mat.getDiffuseMap(0)));
-
- ConvexEditorOptionsWindow.activeMaterial = %mat;
- }
- }
- function ConvexEditorGui::onSleep( %this )
- {
- }
- function ConvexEditorGui::createConvexBox( %this )
- {
- %obj = genericCreateObject( "ConvexShape" );
- %obj.setMaterial(%this.materialName); //set whatever the editor has as it's default material to the new one
-
- %this.handleDeselect();
- %this.selectConvex( %obj );
- %this.dropSelectionAtScreenCenter();
- }
- function ConvexEditorGui::onSelectionChanged( %this, %shape, %face )
- {
- //echo( "onSelectionChanged: " @ %shape SPC %face );
-
- ConvexEditorSplitFaceBtn.setActive( false );
- ConvexEditorSplitFaceBtn.ToolTip = "Split selected face [Disabled]" NL "Use Ctrl + Rotate instead for more control";
- ConvexEditorDeleteFaceBtn.setActive( false );
- ConvexEditorDeleteFaceBtn.ToolTip = "Delete selection [Disabled] (Delete)";
-
- if ( !isObject( %shape ) )
- {
- ConvexEditorOptionsWindow-->defMatPreviewBtn.setText("No Brush Selected");
- ConvexEditorOptionsWindow.activeShape = "";
- return;
- }
-
- ConvexEditorDeleteFaceBtn.setActive( true );
- ConvexEditorOptionsWindow-->defMatPreviewBtn.setText("");
- %shapeMat = %shape.getMaterial();
- ConvexEditorOptionsWindow-->defMatPreviewBtn.setBitmap(getAssetPreviewImage(%shapeMat.getDiffuseMap(0)));
- ConvexEditorOptionsWindow.activeShape = %shape;
-
- if ( %face == -1 )
- {
- ConvexEditorDeleteFaceBtn.ToolTip = "Delete selected ConvexShape (Delete)";
-
- ConvexEditorOptionsWindow-->UOffset.setText("");
- ConvexEditorOptionsWindow-->VOffset.setText("");
-
- ConvexEditorOptionsWindow-->UScale.setText("");
- ConvexEditorOptionsWindow-->VScale.setText("");
-
- ConvexEditorOptionsWindow-->ZRotation.setText("");
- }
- else
- {
- ConvexEditorDeleteFaceBtn.ToolTip = "Delete selected Face (Delete)";
-
- ConvexEditorSplitFaceBtn.ToolTip = "Split selected face" NL "Use Ctrl + Rotate instead for more control";
- ConvexEditorSplitFaceBtn.setActive( true );
-
- %UVOffset = %this.getSelectedFaceUVOffset();
-
- ConvexEditorOptionsWindow-->UOffset.setText(%UVOffset.x);
- ConvexEditorOptionsWindow-->VOffset.setText(%UVOffset.y);
-
- %UVScale = %this.getSelectedFaceUVScale();
-
- ConvexEditorOptionsWindow-->UScale.setText(%UVScale.x);
- ConvexEditorOptionsWindow-->VScale.setText(%UVScale.y);
-
- ConvexEditorOptionsWindow-->ZRotation.setText(ConvexEditorGui.getSelectedFaceZRot());
- }
- }
- function ConvexEditorUVFld::onReturn(%this)
- {
- EWorldEditor.isDirty = true;
- %offset = "0 0";
- %offset.x = ConvexEditorOptionsWindow-->UOffset.getText();
- %offset.y = ConvexEditorOptionsWindow-->VOffset.getText();
- %scale = "0 0";
- %scale.x = ConvexEditorOptionsWindow-->UScale.getText();
- %scale.y = ConvexEditorOptionsWindow-->VScale.getText();
- %rot = ConvexEditorOptionsWindow-->ZRotation.getText();
- ConvexEditorGui.setSelectedFaceUVOffset(%offset);
- ConvexEditorGui.setSelectedFaceUVScale(%scale);
- ConvexEditorGui.setSelectedFaceZRot(%rot);
- }
- function ConvexEditorUVHorzFlipBtn::onClick(%this)
- {
- EWorldEditor.isDirty = true;
- %current = ConvexEditorGui.getSelectedFaceHorzFlip();
- ConvexEditorGui.setSelectedFaceHorzFlip(!%current);
- }
- function ConvexEditorUVVertFlipBtn::onClick(%this)
- {
- EWorldEditor.isDirty = true;
- %current = ConvexEditorGui.getSelectedFaceVertFlip();
- ConvexEditorGui.setSelectedFaceVertFlip(!%current);
- }
- function ConvexEditorMaterialBtn::onClick(%this)
- {
- %this.getMaterialName();
- }
- function ConvexEditorMaterialBtn::getMaterialName(%this)
- {
- AssetBrowser.showDialog("MaterialAsset", %this @ ".gotMaterialName", "", "", "");
- //materialSelector.showDialog(%this @ ".gotMaterialName", "name");
- }
- function ConvexEditorMaterialBtn::gotMaterialName(%this, %name)
- {
- %materialAsset = AssetDatabase.acquireAsset(%name);
-
- //eval(%this.object @ "." @ %this.targetField @ " = " @ %name @ ";");
- //%this.object.changeMaterial(getTrailingNumber(%this.targetField), %name);
- //%this.object.inspectorApply();
- %diffusemap = %materialAsset.materialDefinitionName.getDiffuseMap(0);
- if(%diffusemap $= "")
- {
- %diffuseAsset = %materialAsset.materialDefinitionName.getDiffuseMapAsset(0);
- if(%diffuseAsset !$= "")
- {
- %diffuseAssetDef = AssetDatabase.acquireAsset(%diffuseAsset);
- %diffusemap = %diffuseAssetDef.getImagePath();
- }
- }
- ConvexEditorOptionsWindow-->matPreviewBtn.setBitmap(getAssetPreviewImage(%diffusemap));
- ConvexEditorOptionsWindow.activeMaterial = %materialAsset.materialDefinitionName;
- }
- function ConvexEditorMaterialApplyBtn::onClick(%this)
- {
- EWorldEditor.isDirty = true;
- ConvexEditorGui.setSelectedFaceMaterial(ConvexEditorOptionsWindow.activeMaterial);
- ConvexEditorGui.updateShape();
- }
- function ConvexEditorMaterialLiftBtn::onClick(%this)
- {
- %mat = ConvexEditorGui.getSelectedFaceMaterial();
- ConvexEditorOptionsWindow.activeMaterial = %mat;
- ConvexEditorOptionsWindow-->matPreviewBtn.setBitmap(getAssetPreviewImage(%mat.getDiffuseMap(0)));
- }
- function ConvexEditorMaterialResetBtn::onClick(%this)
- {
- EWorldEditor.isDirty = true;
- ConvexEditorGui.setSelectedFaceMaterial(ConvexEditorOptionsWindow.activeShape.material);
- ConvexEditorGui.updateShape();
- }
- function ConvexEditorGui::toggleGridSnap(%this)
- {
- %this.toggleGridSnapping();
- }
- function ConvexEditorGridSnapSizeFld::onReturn(%this)
- {
- ConvexEditorGui.setGridSnapSize(%this.getText());
- }
- function ConvexEditorDefaultMaterialBtn::onClick(%this)
- {
- %this.getMaterialName();
- }
- function ConvexEditorDefaultMaterialBtn::getMaterialName(%this)
- {
- //materialSelector.showDialog(%this @ ".gotMaterialName", "name");
- AssetBrowser.showDialog("MaterialAsset", %this @ ".gotMaterialName", "", "", "");
- }
- function ConvexEditorDefaultMaterialBtn::gotMaterialName(%this, %name)
- {
- %materialAsset = AssetDatabase.acquireAsset(%name);
-
- //eval(%this.object @ "." @ %this.targetField @ " = " @ %name @ ";");
- //%this.object.changeMaterial(getTrailingNumber(%this.targetField), %name);
- //%this.object.inspectorApply();
- %diffusemap = %materialAsset.materialDefinitionName.getDiffuseMap(0);
- if(%diffusemap $= "")
- {
- %diffuseAsset = %materialAsset.materialDefinitionName.getDiffuseMapAsset(0);
- if(%diffuseAsset !$= "")
- {
- %diffuseAssetDef = AssetDatabase.acquireAsset(%diffuseAsset);
- %diffusemap = %diffuseAssetDef.getImagePath();
- }
- }
- ConvexEditorOptionsWindow-->defMatPreviewBtn.setBitmap(getAssetPreviewImage(%diffusemap));
- ConvexEditorOptionsWindow.activeShape.setMaterial(%name);
- ConvexEditorGui.updateShape();
- }
|