| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- //-----------------------------------------------------------------------------
- // 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.bitmapAsset = getAssetPreviewImage(%mat.getDiffuseMap(0));
-
- ConvexEditorOptionsWindow.activeMaterial = %mat;
- }
- %fluidWindow = ConvexEditorOptionsWindow;
-
- if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1)
- {
- // Let's dock the side panel to the right side
- %this.docked = false;
- %this.resizing = true;
- %this.dockSidePanel();
- }
- else
- {
- // Let's release the side panel so it can be moved
- %this.docked = true;
- %this.resizing = false;
- %this.releaseSidePanel();
- }
-
- EWorldEditor.UseGridSnap = EditorSettings.value("WorldEditor/Tools/UseGridSnap");
- CESnapOptions-->objectGridSnapBtn.setStateOn( EWorldEditor.UseGridSnap );
- %this.setGridSnap( EWorldEditor.UseGridSnap );
- EWorldEditor.setGridSnap( EWorldEditor.UseGridSnap );
- }
- 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.bitmapAsset = 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.getDiffuseMapAsset(0);
- ConvexEditorOptionsWindow-->matPreviewBtn.bitmapAsset = getAssetPreviewImage(%diffusemap);
- ConvexEditorOptionsWindow.activeMaterial = %materialAsset.getAssetId();
- }
- 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)
- {
- EWorldEditor.UseGridSnap = !EWorldEditor.UseGridSnap;
- EditorSettings.setValue("WorldEditor/Tools/UseGridSnap", EWorldEditor.UseGridSnap );
- CESnapOptions-->objectGridSnapBtn.setStateOn( EWorldEditor.UseGridSnap );
- %this.setGridSnap( EWorldEditor.UseGridSnap );
- EWorldEditor.setGridSnap( EWorldEditor.UseGridSnap );
- }
- 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.bitmapAsset = getAssetPreviewImage(%diffusemap);
- ConvexEditorOptionsWindow.activeShape.setMaterial(%name);
- ConvexEditorGui.updateShape();
- }
- function ESettingsWindow::getConvexEditorSettings(%this)
- {
- SettingsInspector.startGroup("Defaults");
- SettingsInspector.addSettingsField("ConvexEditor/MaterialName", "Default Material", "string",
- "The default material when creating a convexShape");
- SettingsInspector.endGroup();
- }
- //-----------------------------------------------------------------------------
- function ConvexEditorGui::maxSize(%this, %window)
- {
- // Resize the windows to the max height
- // and force these to the right side if set
- if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1 && %this.resizing == true)
- {
- // prevent onResize after a resize
- %this.resizing = false;
-
- %fluidWindow = ConvexEditorOptionsWindow;
- %offset = -1; // tweak the vertical offset so that it aligns neatly
- %top = EditorGuiToolbar.extent.y + %offset;
- %bottom = %top + 59;
- %position = Canvas.extent.x - %fluidWindow.extent.x SPC %top;
- %extent = %window.extent.x SPC Canvas.extent.y - %bottom;
- %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
-
- // --- AssetBrowser window ----------------------------------------------
- if(isObject(AssetBrowserWindow))
- {
- // Only resize the AssetBrowser if it's docked
- if(AssetBrowserWindow.docked == true)
- {
- // The width is relative to the sidepanel
- %browserWidth = Canvas.extent.x - %extent.x;
- %browserHeight = AssetBrowserWindow.extent.y;
- %browserPosY = Canvas.extent.y - AssetBrowserWindow.extent.y - 33;
- AssetBrowserWindow.resize(0, %browserPosY, %browserWidth, %browserHeight);
- }
- }
- // --- Windowed Console --------------------------------------------------
- if(isObject(windowConsoleControl))
- {
- // Only resize the AssetBrowser if it's docked
- if(windowConsoleControl.docked == true)
- {
- // The width is relative to the sidepanel
- %consoleWidth = Canvas.extent.x - %extent.x;
- %consoleHeight = windowConsoleControl.extent.y;
- %consolePosY = Canvas.extent.y - windowConsoleControl.extent.y - 33;
- windowConsoleControl.resize(0, %consolePosY, %consoleWidth, %consoleHeight);
- }
- }
- }
- }
- function ConvexEditorOptionsWindow::onMouseDragged(%this)
- {
- %parent = ConvexEditorGui;
-
- if(%parent.panelHidden == true)
- {
- %parent.showSidePanel();
- }
-
- if(%parent.resizing == false && %parent.docked == true)
- {
- %parent.resizing = true;
- %parent.maxSize(%this);
- }
- }
- function ConvexEditorGui::onResize(%this, %newPosition, %newExtent)
- {
- // Window to focus on (mostly the fluid window)
- %window = ConvexEditorOptionsWindow;
-
- if(%window.panelHidden == true)
- {
- %window.showSidePanel();
- }
-
- if(%this.resizing == false && %this.docked == true)
- {
- // Only resize once
- %this.resizing = true;
- %this.maxSize(%window);
- }
- }
- function ConvexEditorGui::dockSidePanel()
- {
- %parent = ConvexEditorGui;
- %fluidWindow = ConvexEditorOptionsWindow;
-
- if(%parent.docked == true)
- return;
-
- // Move and resize the window(s)
- %parent.resizing = true;
- %parent.maxSize(%fluidWindow);
-
- %parent.docked = true;
- %fluidWindow.onMouseDragged();
- // Lock the windows in place
-
- %fluidWindow.canCollapse = "0";
- %fluidWindow.canMove = "0";
-
- ConvexEditorGui_UnDockBtn.Visible = "1";
- ConvexEditorGui_DockBtn.Visible = "0";
-
- ConvexEditorGui_showBtn.Visible = "0";
- ConvexEditorGui_hideBtn.Visible = "1";
- }
- function ConvexEditorGui::releaseSidePanel()
- {
- %parent = ConvexEditorGui;
- %fluidWindow = ConvexEditorOptionsWindow;
-
- if(%parent.docked == false)
- return;
-
- %fluidWindow.canCollapse = "1";
- %fluidWindow.canMove = "1";
-
- ConvexEditorGui_UnDockBtn.Visible = "0";
- ConvexEditorGui_DockBtn.Visible = "1";
-
- ConvexEditorGui_showBtn.Visible = "0";
- ConvexEditorGui_hideBtn.Visible = "0";
-
- // Let's do a small resize so it's visually clear we're undocking
- %position = %fluidWindow.position.x - 6 SPC %fluidWindow.position.y + 6;
- %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y - 12;
- %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
-
- %parent.docked = false;
- %parent.resizing = false;
- }
- function ConvexEditorGui::hideSidePanel()
- {
- %parent = ConvexEditorGui;
- %fluidWindow = ConvexEditorOptionsWindow;
-
- ConvexEditorGui_showBtn.Visible = "1";
- ConvexEditorGui_hideBtn.Visible = "0";
-
- // hide the content of the panels
- %fluidWindow.titleText = %fluidWindow.text;
-
- %fluidWindow.text = "";
- ConvexEditorOptionsPanel.Visible = "0";
- ConvexEditorUVPanel.Visible = "0";
- ConvexEditorAdvPanel.Visible = "0";
-
- // Let's do a resize so that the panel is collapsed to the side
- %position = Canvas.extent.x - 24 SPC %fluidWindow.position.y;
- %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y;
- %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
-
- %parent.panelHidden = true;
- }
- function ConvexEditorGui::showSidePanel()
- {
- %parent = ConvexEditorGui;
- %fluidWindow = ConvexEditorOptionsWindow;
-
- ConvexEditorGui_showBtn.Visible = "0";
- ConvexEditorGui_hideBtn.Visible = "1";
-
- %fluidWindow.text = %fluidWindow.titleText;
- ConvexEditorOptionsPanel.Visible = "1";
- ConvexEditorUVPanel.Visible = "1";
- ConvexEditorAdvPanel.Visible = "1";
-
- %parent.resizing = true;
- %parent.maxSize(%fluidWindow);
-
- %parent.panelHidden = false;
- }
- //-----------------------------------------------------------------------------
|