//----------------------------------------------------------------------------- // 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. //----------------------------------------------------------------------------- $River::EditorOpen = false; $River::wireframe = true; $River::showSpline = true; $River::showRiver = true; $River::showWalls = true; //----------------------------------------------------------------------------- function RiverEditorGui::onWake(%this) { %fixedWindow = RiverEditorTreeWindow; %fluidWindow = RiverEditorOptionsWindow; 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(); } } function RiverEditorGui::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; %fixedWindow = RiverEditorTreeWindow; %fluidWindow = RiverEditorOptionsWindow; %offset = -1; // tweak the vertical offset so that it aligns neatly %top = EditorGuiToolbar.extent.y + %offset; %bottom = %top + 59; %maxHeight = Canvas.extent.y - %top - %bottom; // --- Fixed window (top) ------------------------------------------------ // put it back if it moved %fixedWindow.position.x = Canvas.extent.x - %fixedWindow.extent.x; %fixedWindow.position.y = %top; // don't go beyond the canvas if(%fixedWindow.extent.y > %maxHeight) %fixedWindow.extent.y = %maxHeight - %fluidWindow.extent.y; %position = %fixedWindow.position.x SPC %fixedWindow.position.y; %extent = %window.extent.x SPC %fixedWindow.extent.y; %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y); // --- Fluid window (bottom) --------------------------------------------- // position is relative to the top window %position = %fixedWindow.position.x SPC %fixedWindow.extent.y + %top; %extent = %window.extent.x SPC Canvas.extent.y - %fixedWindow.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 RiverEditorTreeWindow::onMouseDragged(%this) { %parent = RiverEditorGui; if(%parent.panelHidden == true) { %parent.showSidePanel(); } if(%parent.resizing == false && %parent.docked == true) { %parent.resizing = true; %parent.maxSize(%this); } } function RiverEditorOptionsWindow::onMouseDragged(%this) { %parent = RiverEditorGui; if(%parent.panelHidden == true) { %parent.showSidePanel(); } if(%parent.resizing == false && %parent.docked == true) { %parent.resizing = true; %parent.maxSize(%this); } } function RiverEditorGui::onResize(%this, %newPosition, %newExtent) { // Window to focus on (mostly the fluid window) %window = RiverEditorOptionsWindow; if(%window.panelHidden == true) { %window.showSidePanel(); } if(%this.resizing == false && %this.docked == true) { // Only resize once %this.resizing = true; %this.maxSize(%window); } } function RiverEditorGui::dockSidePanel() { %parent = RiverEditorGui; %fixedWindow = RiverEditorTreeWindow; %fluidWindow = RiverEditorOptionsWindow; 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 %fixedWindow.canCollapse = "0"; %fixedWindow.canMove = "0"; %fluidWindow.canCollapse = "0"; %fluidWindow.canMove = "0"; RiverEditorGui_UnDockBtn.Visible = "1"; RiverEditorGui_DockBtn.Visible = "0"; RiverEditorGui_showBtn.Visible = "0"; RiverEditorGui_hideBtn.Visible = "1"; } function RiverEditorGui::releaseSidePanel() { %parent = RiverEditorGui; %fixedWindow = RiverEditorTreeWindow; %fluidWindow = RiverEditorOptionsWindow; if(%parent.docked == false) return; // Unlock the windows so that be moved %fixedWindow.canCollapse = "1"; %fixedWindow.canMove = "1"; %fluidWindow.canCollapse = "1"; %fluidWindow.canMove = "1"; RiverEditorGui_UnDockBtn.Visible = "0"; RiverEditorGui_DockBtn.Visible = "1"; RiverEditorGui_showBtn.Visible = "0"; RiverEditorGui_hideBtn.Visible = "0"; // Let's do a small resize so it's visually clear we're undocking %position = %fixedWindow.position.x - 6 SPC %fixedWindow.position.y + 6; %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y; %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y); %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 RiverEditorGui::hideSidePanel() { %parent = RiverEditorGui; %fixedWindow = RiverEditorTreeWindow; %fluidWindow = RiverEditorOptionsWindow; RiverEditorGui_showBtn.Visible = "1"; RiverEditorGui_hideBtn.Visible = "0"; // hide the content of the panels %fixedWindow.titleText = %fixedWindow.text; %fluidWindow.titleText = %fluidWindow.text; %fixedWindow.text = ""; RiverEditorTreeWPanel.Visible = "0"; %fluidWindow.text = ""; RiverEditorOptionsPanel.Visible = "0"; RiverEditorPropPanel.Visible = "0"; RiverEditorPropScroll.Visible = "0"; // Let's do a resize so that the panel is collapsed to the side %position = Canvas.extent.x - 24 SPC %fixedWindow.position.y; %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y; %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y); %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 RiverEditorGui::showSidePanel() { %parent = RiverEditorGui; %fixedWindow = RiverEditorTreeWindow; %fluidWindow = RiverEditorOptionsWindow; RiverEditorGui_showBtn.Visible = "0"; RiverEditorGui_hideBtn.Visible = "1"; // show the content of the panels // hide the content of the panels %fixedWindow.text = %fixedWindow.titleText; RiverEditorTreeWPanel.Visible = "1"; %fluidWindow.text = %fluidWindow.titleText; RiverEditorOptionsPanel.Visible = "1"; RiverEditorPropPanel.Visible = "1"; RiverEditorPropScroll.Visible = "1"; %parent.resizing = true; %parent.maxSize(%fluidWindow); %parent.panelHidden = false; } //----------------------------------------------------------------------------- function RiverEditorGui::onEditorActivated( %this ) { %count = EWorldEditor.getSelectionSize(); for ( %i = 0; %i < %count; %i++ ) { %obj = EWorldEditor.getSelectedObject(%i); if ( %obj.getClassName() !$= "River" ) EWorldEditor.unselectObject( %obj ); else %this.setSelectedRiver( %obj ); } %this.onRiverSelected( %this.getSelectedRiver() ); %this.onNodeSelected(-1); } function RiverEditorGui::onEditorDeactivated( %this ) { } function RiverEditorGui::createRiver( %this ) { %river = new River() { rippleDir[0] = "0.000000 1.000000"; rippleDir[1] = "0.707000 0.707000"; rippleDir[2] = "0.500000 0.860000"; rippleSpeed[0] = "-0.065"; rippleSpeed[1] = "0.09"; rippleSpeed[2] = "0.04"; rippleTexScale[0] = "7.140000 7.140000"; rippleTexScale[1] = "6.250000 12.500000"; rippleTexScale[2] = "50.000000 50.000000"; waveDir[0] = "0.000000 1.000000"; waveDir[1] = "0.707000 0.707000"; waveDir[2] = "0.500000 0.860000"; waveSpeed[0] = "1"; waveSpeed[1] = "1"; waveSpeed[2] = "1"; waveMagnitude[0] = "0.2"; waveMagnitude[1] = "0.2"; waveMagnitude[2] = "0.2"; baseColor = "45 108 171 255"; rippleTex = "Core_Rendering:ripple_image"; foamTex = "Core_Rendering:foam_image"; depthGradientTex = "Core_Rendering:depthcolor_ramp_image"; }; return %river; } function RiverEditorGui::paletteSync( %this, %mode ) { %evalShortcut = "ToolsPaletteArray-->" @ %mode @ ".setStateOn(1);"; eval(%evalShortcut); } function RiverEditorGui::onEscapePressed( %this ) { if( %this.getMode() $= "RiverEditorAddNodeMode" ) { %this.prepSelectionMode(); return true; } return false; } function RiverEditorGui::onRiverSelected( %this, %river ) { %this.river = %river; RiverInspector.inspect( %river ); RiverTreeView.buildVisibleTree(true); if( RiverTreeView.getSelectedObject() != %river ) { RiverTreeView.clearSelection(); %treeId = RiverTreeView.findItemByObjectId( %river ); RiverTreeView.selectItem( %treeId ); } } function RiverEditorGui::onNodeSelected( %this, %nodeIdx ) { if ( %nodeIdx == -1 ) { RiverEditorOptionsWindow-->position.setActive( false ); RiverEditorOptionsWindow-->position.setValue( "" ); RiverEditorOptionsWindow-->rotation.setActive( false ); RiverEditorOptionsWindow-->rotation.setValue( "" ); RiverEditorOptionsWindow-->width.setActive( false ); RiverEditorOptionsWindow-->width.setValue( "" ); RiverEditorOptionsWindow-->depth.setActive( false ); RiverEditorOptionsWindow-->depth.setValue( "" ); } else { RiverEditorOptionsWindow-->position.setActive( true ); RiverEditorOptionsWindow-->position.setValue( %this.getNodePosition() ); RiverEditorOptionsWindow-->rotation.setActive( true ); RiverEditorOptionsWindow-->rotation.setValue( %this.getNodeNormal() ); RiverEditorOptionsWindow-->width.setActive( true ); RiverEditorOptionsWindow-->width.setValue( %this.getNodeWidth() ); RiverEditorOptionsWindow-->depth.setActive( true ); RiverEditorOptionsWindow-->depth.setValue( %this.getNodeDepth() ); } } function RiverEditorGui::onNodeModified( %this, %nodeIdx ) { RiverEditorOptionsWindow-->position.setValue( %this.getNodePosition() ); RiverEditorOptionsWindow-->rotation.setValue( %this.getNodeNormal() ); RiverEditorOptionsWindow-->width.setValue( %this.getNodeWidth() ); RiverEditorOptionsWindow-->depth.setValue( %this.getNodeDepth() ); } function RiverEditorGui::editNodeDetails( %this ) { %this.setNodePosition( RiverEditorOptionsWindow-->position.getText() ); %this.setNodeNormal( RiverEditorOptionsWindow-->rotation.getText() ); %this.setNodeWidth( RiverEditorOptionsWindow-->width.getText() ); %this.setNodeDepth( RiverEditorOptionsWindow-->depth.getText() ); } function RiverInspector::inspect( %this, %obj ) { %name = ""; if ( isObject( %obj ) ) %name = %obj.getName(); else RiverFieldInfoControl.setText( "" ); //RiverInspectorNameEdit.setValue( %name ); Parent::inspect( %this, %obj ); } function RiverInspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue ) { // Same work to do as for the regular WorldEditor Inspector. Inspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue ); } function RiverInspector::onFieldSelected( %this, %fieldName, %fieldTypeStr, %fieldDoc ) { RiverFieldInfoControl.setText( "" @ %fieldName @ " (" @ %fieldTypeStr @ ") " NL "" @ %fieldDoc ); } function RiverTreeView::onInspect(%this, %obj) { RiverInspector.inspect(%obj); } function RiverTreeView::onSelect(%this, %obj) { RiverEditorGui.road = %obj; RiverInspector.inspect( %obj ); if(%obj != RiverEditorGui.getSelectedRiver()) { RiverEditorGui.setSelectedRiver( %obj ); } } function RiverEditorGui::prepSelectionMode( %this ) { %mode = %this.getMode(); if ( %mode $= "RiverEditorAddNodeMode" ) { if ( isObject( %this.getSelectedRiver() ) ) %this.deleteNode(); } %this.setMode( "RiverEditorSelectMode" ); ToolsPaletteArray-->RiverEditorSelectMode.setStateOn(1); } //------------------------------------------------------------------------------ function ESettingsWindow::getRiverEditorSettings(%this) { SettingsInspector.startGroup("Defaults"); SettingsInspector.addSettingsField("RiverEditor/DefaultWidth", "Width", "string", ""); SettingsInspector.addSettingsField("RiverEditor/DefaultDepth", "Depth", "string", ""); SettingsInspector.addSettingsField("RiverEditor/DefaultNormal", "Normal", "string", ""); SettingsInspector.endGroup(); SettingsInspector.startGroup("Colors"); SettingsInspector.addSettingsField("RiverEditor/HoverSplineColor", "Hover Spline", "colorI", ""); SettingsInspector.addSettingsField("RiverEditor/SelectedSplineColor", "Selected Spline", "colorI", ""); SettingsInspector.endGroup(); } //------------------------------------------------------------------------------ function ERiverEditorSelectModeBtn::onClick(%this) { EditorGuiStatusBar.setInfo(%this.ToolTip); } function ERiverEditorAddModeBtn::onClick(%this) { EditorGuiStatusBar.setInfo(%this.ToolTip); } function ERiverEditorMoveModeBtn::onClick(%this) { EditorGuiStatusBar.setInfo(%this.ToolTip); } function ERiverEditorRotateModeBtn::onClick(%this) { EditorGuiStatusBar.setInfo(%this.ToolTip); } function ERiverEditorScaleModeBtn::onClick(%this) { EditorGuiStatusBar.setInfo(%this.ToolTip); } function ERiverEditorInsertModeBtn::onClick(%this) { EditorGuiStatusBar.setInfo(%this.ToolTip); } function ERiverEditorRemoveModeBtn::onClick(%this) { EditorGuiStatusBar.setInfo(%this.ToolTip); } function RiverDefaultWidthSliderCtrlContainer::onWake(%this) { RiverDefaultWidthSliderCtrlContainer-->slider.setValue(RiverDefaultWidthTextEditContainer-->textEdit.getText()); } function RiverDefaultDepthSliderCtrlContainer::onWake(%this) { RiverDefaultDepthSliderCtrlContainer-->slider.setValue(RiverDefaultDepthTextEditContainer-->textEdit.getText()); }