//----------------------------------------------------------------------------- // 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; } //-----------------------------------------------------------------------------