Torque3D/Templates/BaseGame/game/tools/riverEditor/main.tscript
2025-11-18 18:56:24 -06:00

259 lines
10 KiB
Plaintext

//-----------------------------------------------------------------------------
// 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 initializeRiverEditor()
{
echo(" % - Initializing River Editor");
exec( "./riverEditor." @ $TorqueScriptFileExtension );
exec( "./RiverEditorGui.gui" );
exec( "./RiverEditorToolbar.gui" );
exec( "./riverEditorGui." @ $TorqueScriptFileExtension );
// Add ourselves to EditorGui, where all the other tools reside
RiverEditorGui.setVisible( false );
RiverEditorOptionsWindow.setVisible( false );
RiverEditorTreeWindow.setVisible( false );
MainSceneTabPanel.add( RiverEditorGui );
MainSceneTabPanel.add( RiverEditorOptionsWindow );
MainSceneTabPanel.add( RiverEditorTreeWindow );
new ScriptObject( RiverEditorPlugin )
{
superClass = "EditorPlugin";
editorGui = RiverEditorGui;
};
%map = new ActionMap();
%map.bindCmd( keyboard, "backspace", "RiverEditorGui.deleteNode();", "" );
%map.bindCmd( keyboard, "1", "RiverEditorGui.prepSelectionMode();", "" );
%map.bindCmd( keyboard, "2", "ToolsPaletteArray->RiverEditorMoveMode.performClick();", "" );
%map.bindCmd( keyboard, "3", "ToolsPaletteArray->RiverEditorRotateMode.performClick();", "" );
%map.bindCmd( keyboard, "4", "ToolsPaletteArray->RiverEditorScaleMode.performClick();", "" );
%map.bindCmd( keyboard, "5", "ToolsPaletteArray->RiverEditorAddRiverMode.performClick();", "" );
%map.bindCmd( keyboard, "=", "ToolsPaletteArray->RiverEditorInsertPointMode.performClick();", "" );
%map.bindCmd( keyboard, "numpadadd", "ToolsPaletteArray->RiverEditorInsertPointMode.performClick();", "" );
%map.bindCmd( keyboard, "-", "ToolsPaletteArray->RiverEditorRemovePointMode.performClick();", "" );
%map.bindCmd( keyboard, "numpadminus", "ToolsPaletteArray->RiverEditorRemovePointMode.performClick();", "" );
%map.bindCmd( keyboard, "z", "RiverEditorShowSplineBtn.performClick();", "" );
%map.bindCmd( keyboard, "x", "RiverEditorWireframeBtn.performClick();", "" );
%map.bindCmd( keyboard, "v", "RiverEditorShowRoadBtn.performClick();", "" );
RiverEditorPlugin.map = %map;
RiverEditorPlugin.initSettings();
}
function destroyRiverEditor()
{
}
function RiverEditorPlugin::onWorldEditorStartup( %this )
{
// Add ourselves to the window menu.
%accel = EditorGui.addToEditorsMenu( "River Editor", "", RiverEditorPlugin );
// Add ourselves to the ToolsToolbar
%tooltip = "River Editor (" @ %accel @ ")";
EditorGui.addToToolsToolbar( "RiverEditorPlugin", "RiverEditorPalette", "ToolsModule:river_editor_n_image", %tooltip );
//connect editor windows
GuiWindowCtrl::attach( RiverEditorOptionsWindow, RiverEditorTreeWindow);
// Add ourselves to the Editor Settings window
exec( "./RiverEditorSettingsTab.gui" );
//ESettingsWindow.addTabPage( ERiverEditorSettingsPage );
ESettingsWindow.addEditorSettingsPage("RiverEditor", "River Editor");
}
function EditorGui::SetRiverPalletBar()
{
//Clears the button pallete stack
EWToolsPaletteWindow.setStackCtrl(ToolsPaletteArray); //legacy ctrl adhereance
EWToolsPaletteWindow.clearButtons();
EWToolsPaletteWindow.setActionMap(WorldEditorInspectorPlugin.map);
//Adds a button to the pallete stack
//Name Icon Click Command Tooltip text Keybind
EWToolsPaletteWindow.addButton("Select", "ToolsModule:arrow_n_image", "RiverEditorGui.prepSelectionMode();", "", "Select River", "1");
EWToolsPaletteWindow.addButton("MovePoint", "ToolsModule:move_point_n_image", "RiverEditorGui.setMode(\"RiverEditorMoveMode\");", "", "Move Point", "2");
EWToolsPaletteWindow.addButton("RotatePoint", "ToolsModule:rotate_point_n_image", "RiverEditorGui.setMode(\"RiverEditorRotateMode\");", "", "Rotate Point", "3");
EWToolsPaletteWindow.addButton("ScalePoint", "ToolsModule:scale_point_n_image", "RiverEditorGui.setMode(\"RiverEditorScaleMode\");", "", "Scale Point", "4");
EWToolsPaletteWindow.addButton("AddRoad", "ToolsModule:add_road_path_n_image", "RiverEditorGui.setMode(\"RiverEditorAddRiverMode\");", "", "Add River", "5");
EWToolsPaletteWindow.addButton("InsertPoint", "ToolsModule:add_point_n_image", "RiverEditorGui.setMode(\"RiverEditorInsertPointMode\");", "", "Insert Point", "+");
EWToolsPaletteWindow.addButton("RemovePoint", "ToolsModule:subtract_point_n_image", "RiverEditorGui.setMode(\"RiverEditorRemovePointMode\");", "", "Remove Point", "-");
EWToolsPaletteWindow.refresh();
}
function RiverEditorPlugin::onActivated( %this )
{
%this.readSettings();
$River::EditorOpen = true;
ToolsPaletteArray->RiverEditorAddRiverMode.performClick();
EditorGui.bringToFront( RiverEditorGui );
RiverEditorGui.setVisible(true);
RiverEditorGui.makeFirstResponder( true );
EditorGuiToolbarStack.remove( EWorldEditorToolbar );
EditorGuiToolbarStack.add( RiverEditorToolbar );
RiverEditorOptionsWindow.setVisible( true );
RiverEditorTreeWindow.setVisible( true );
RiverTreeView.open(ServerRiverSet,true);
%this.map.push();
// Store this on a dynamic field
// in order to restore whatever setting
// the user had before.
%this.prevGizmoAlignment = GlobalGizmoProfile.alignment;
// The DecalEditor always uses Object alignment.
GlobalGizmoProfile.alignment = "Object";
// Set the status bar here until all tool have been hooked up
EditorGuiStatusBar.setInfo("River editor.");
EditorGuiStatusBar.setSelection("");
// Allow the Gui to setup.
RiverEditorGui.onEditorActivated();
Parent::onActivated(%this);
EditorGui.SetRiverPalletBar();
}
function RiverEditorPlugin::onDeactivated( %this )
{
%this.writeSettings();
$River::EditorOpen = false;
RiverEditorGui.setVisible(false);
EditorGuiToolbarStack.add( EWorldEditorToolbar );
EditorGuiToolbarStack.remove( RiverEditorToolbar );
RiverEditorOptionsWindow.setVisible( false );
RiverEditorTreeWindow.setVisible( false );
%this.map.pop();
// Restore the previous Gizmo
// alignment settings.
GlobalGizmoProfile.alignment = %this.prevGizmoAlignment;
// Allow the Gui to cleanup.
RiverEditorGui.onEditorDeactivated();
Parent::onDeactivated(%this);
}
function RiverEditorPlugin::onEditMenuSelect( %this, %editMenu )
{
%hasSelection = false;
if( isObject( RiverEditorGui.river ) )
%hasSelection = true;
%editMenu.enableItem( 3, false ); // Cut
%editMenu.enableItem( 4, false ); // Copy
%editMenu.enableItem( 5, false ); // Paste
%editMenu.enableItem( 6, %hasSelection ); // Delete
%editMenu.enableItem( 8, false ); // Deselect
}
function RiverEditorPlugin::handleDelete( %this )
{
RiverEditorGui.deleteNode();
}
function RiverEditorPlugin::handleEscape( %this )
{
return RiverEditorGui.onEscapePressed();
}
function RiverEditorPlugin::isDirty( %this )
{
return RiverEditorGui.isDirty;
}
function RiverEditorPlugin::onSaveMission( %this, %missionFile )
{
if( RiverEditorGui.isDirty )
{
//Get our root scene, which would be the level
getScene(0).save( %missionFile );
RiverEditorGui.isDirty = false;
}
}
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
function RiverEditorPlugin::initSettings( %this )
{
EditorSettings.beginGroup( "RiverEditor", true );
EditorSettings.setDefaultValue( "DefaultWidth", "10" );
EditorSettings.setDefaultValue( "DefaultDepth", "5" );
EditorSettings.setDefaultValue( "DefaultNormal", "0 0 1" );
EditorSettings.setDefaultValue( "HoverSplineColor", "255 0 255 255" );
EditorSettings.setDefaultValue( "SelectedSplineColor", "192 0 192 255" );
EditorSettings.setDefaultValue( "HoverNodeColor", "255 255 255 255" ); //<-- Not currently used
EditorSettings.endGroup();
}
function RiverEditorPlugin::readSettings( %this )
{
EditorSettings.beginGroup( "RiverEditor", true );
RiverEditorGui.DefaultWidth = EditorSettings.value("DefaultWidth");
RiverEditorGui.DefaultDepth = EditorSettings.value("DefaultDepth");
RiverEditorGui.DefaultNormal = EditorSettings.value("DefaultNormal");
RiverEditorGui.HoverSplineColor = EditorSettings.value("HoverSplineColor");
RiverEditorGui.SelectedSplineColor = EditorSettings.value("SelectedSplineColor");
RiverEditorGui.HoverNodeColor = EditorSettings.value("HoverNodeColor");
EditorSettings.endGroup();
}
function RiverEditorPlugin::writeSettings( %this )
{
EditorSettings.beginGroup( "RiverEditor", true );
EditorSettings.setValue( "DefaultWidth", RiverEditorGui.DefaultWidth );
EditorSettings.setValue( "DefaultDepth", RiverEditorGui.DefaultDepth );
EditorSettings.setValue( "DefaultNormal", RiverEditorGui.DefaultNormal );
EditorSettings.setValue( "HoverSplineColor", RiverEditorGui.HoverSplineColor );
EditorSettings.setValue( "SelectedSplineColor", RiverEditorGui.SelectedSplineColor );
EditorSettings.setValue( "HoverNodeColor", RiverEditorGui.HoverNodeColor );
EditorSettings.endGroup();
}