| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2014 Daniel Buckmaster
- //
- // 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.
- //-----------------------------------------------------------------------------
- $Nav::EditorOpen = false;
- function NavEditorGui::onEditorActivated(%this)
- {
- if(%this.selectedObject)
- %this.selectObject(%this.selectedObject);
- %this.prepSelectionMode();
- }
- function NavEditorGui::onEditorDeactivated(%this)
- {
- if(%this.getMesh())
- %this.deselect();
- }
- //------------------------------------------------------------------------------
- function NavEditorGui::onWake(%this)
- {
- %fixedWindow = NavEditorTreeWindow;
- %fluidWindow = NavEditorOptionsWindow;
-
- 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 NavEditorGui::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 = NavEditorTreeWindow;
- %fluidWindow = NavEditorOptionsWindow;
- %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 NavEditorTreeWindow::onMouseDragged(%this)
- {
- %parent = NavEditorGui;
-
- if(%parent.panelHidden == true)
- {
- %parent.showSidePanel();
- }
-
- if(%parent.resizing == false && %parent.docked == true)
- {
- %parent.resizing = true;
- %parent.maxSize(%this);
- }
- }
- function NavEditorOptionsWindow::onMouseDragged(%this)
- {
- %parent = NavEditorGui;
-
- if(%parent.panelHidden == true)
- {
- %parent.showSidePanel();
- }
-
- if(%parent.resizing == false && %parent.docked == true)
- {
- %parent.resizing = true;
- %parent.maxSize(%this);
- }
- }
- function NavEditorGui::onResize(%this, %newPosition, %newExtent)
- {
- // Window to focus on (mostly the fluid window)
- %window = NavEditorOptionsWindow;
-
- if(%window.panelHidden == true)
- {
- %window.showSidePanel();
- }
-
- if(%this.resizing == false && %this.docked == true)
- {
- // Only resize once
- %this.resizing = true;
- %this.maxSize(%window);
- }
- }
- function NavEditorGui::dockSidePanel()
- {
- %parent = NavEditorGui;
- %fixedWindow = NavEditorTreeWindow;
- %fluidWindow = NavEditorOptionsWindow;
-
- 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";
-
- NavEditorGui_UnDockBtn.Visible = "1";
- NavEditorGui_DockBtn.Visible = "0";
-
- NavEditorGui_showBtn.Visible = "0";
- NavEditorGui_hideBtn.Visible = "1";
- }
- function NavEditorGui::releaseSidePanel()
- {
- %parent = NavEditorGui;
- %fixedWindow = NavEditorTreeWindow;
- %fluidWindow = NavEditorOptionsWindow;
-
- if(%parent.docked == false)
- return;
-
- // Unlock the windows so that be moved
- %fixedWindow.canCollapse = "1";
- %fixedWindow.canMove = "1";
-
- %fluidWindow.canCollapse = "1";
- %fluidWindow.canMove = "1";
-
- NavEditorGui_UnDockBtn.Visible = "0";
- NavEditorGui_DockBtn.Visible = "1";
-
- NavEditorGui_showBtn.Visible = "0";
- NavEditorGui_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 NavEditorGui::hideSidePanel()
- {
- %parent = NavEditorGui;
- %fixedWindow = NavEditorTreeWindow;
- %fluidWindow = NavEditorOptionsWindow;
-
- NavEditorGui_showBtn.Visible = "1";
- NavEditorGui_hideBtn.Visible = "0";
-
- // hide the content of the panels
- %fixedWindow.titleText = %fixedWindow.text;
- %fluidWindow.titleText = %fluidWindow.text;
- %fixedWindow.text = "";
- NavEditorTreePanel.Visible = "0";
-
- %fluidWindow.text = "";
- NavEditorOptionsPanel.Visible = "0";
- NavEditorInspector.Visible = "0";
- NavEditorOptScroll.Visible = "0";
- NavFieldInfoControl.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 NavEditorGui::showSidePanel()
- {
- %parent = NavEditorGui;
- %fixedWindow = NavEditorTreeWindow;
- %fluidWindow = NavEditorOptionsWindow;
-
- NavEditorGui_showBtn.Visible = "0";
- NavEditorGui_hideBtn.Visible = "1";
-
- // showthe content of the panels
- %fixedWindow.text = %fixedWindow.titleText;
- NavEditorTreePanel.Visible = "1";
-
- %fluidWindow.text = %fluidWindow.titleText;
- NavEditorOptionsPanel.Visible = "1";
- NavEditorInspector.Visible = "1";
- NavEditorOptScroll.Visible = "1";
- NavFieldInfoControl.Visible = "1";
-
- %parent.resizing = true;
- %parent.maxSize(%fluidWindow);
-
- %parent.panelHidden = false;
- }
- //------------------------------------------------------------------------------
- function NavEditorGui::onModeSet(%this, %mode)
- {
- // Callback when the nav editor changes mode. Set the appropriate dynamic
- // GUI contents in the properties/actions boxes.
- NavInspector.setVisible(false);
- %actions = NavEditorOptionsWindow->ActionsBox;
- %actions->SelectActions.setVisible(false);
- %actions->LinkActions.setVisible(false);
- %actions->CoverActions.setVisible(false);
- %actions->TileActions.setVisible(false);
- %actions->TestActions.setVisible(false);
- %properties = NavEditorOptionsWindow->PropertiesBox;
- %properties->LinkProperties.setVisible(false);
- %properties->TileProperties.setVisible(false);
- %properties->TestProperties.setVisible(false);
- switch$(%mode)
- {
- case "SelectMode":
- NavInspector.setVisible(true);
- %actions->SelectActions.setVisible(true);
- case "LinkMode":
- %actions->LinkActions.setVisible(true);
- %properties->LinkProperties.setVisible(true);
- case "CoverMode":
- //
- %actions->CoverActions.setVisible(true);
- case "TileMode":
- %actions->TileActions.setVisible(true);
- %properties->TileProperties.setVisible(true);
- case "TestMode":
- %actions->TestActions.setVisible(true);
- %properties->TestProperties.setVisible(true);
- }
- }
- function NavEditorGui::paletteSync(%this, %mode)
- {
- // Synchronise the palette (small buttons on the left) with the actual mode
- // the nav editor is in.
- %evalShortcut = "ToolsPaletteArray-->" @ %mode @ ".setStateOn(1);";
- eval(%evalShortcut);
- }
- function NavEditorGui::onEscapePressed(%this)
- {
- return false;
- }
- function NavEditorGui::selectObject(%this, %obj)
- {
- NavTreeView.clearSelection();
- if(isObject(%obj))
- NavTreeView.selectItem(%obj);
- %this.onObjectSelected(%obj);
- }
- function NavEditorGui::onObjectSelected(%this, %obj)
- {
- if(isObject(%this.selectedObject))
- %this.deselect();
- %this.selectedObject = %obj;
- if(isObject(%obj))
- {
- %this.selectMesh(%obj);
- NavInspector.inspect(%obj);
- }
- }
- function NavEditorGui::deleteMesh(%this)
- {
- if(isObject(%this.selectedObject))
- {
- %this.selectedObject.delete();
- %this.selectObject(-1);
- }
- }
- function NavEditorGui::deleteSelected(%this)
- {
- switch$(%this.getMode())
- {
- case "SelectMode":
- // Try to delete the selected NavMesh.
- if(isObject(NavEditorGui.selectedObject))
- toolsMessageBoxYesNo("Warning",
- "Are you sure you want to delete" SPC NavEditorGui.selectedObject.getName(),
- "NavEditorGui.deleteMesh();");
- case "TestMode":
- %this.getPlayer().delete();
- %this.onPlayerDeselected();
- case "LinkMode":
- %this.deleteLink();
- %this.isDirty = true;
- }
- }
- function NavEditorGui::buildSelectedMeshes(%this)
- {
- if(isObject(%this.getMesh()))
- {
- %this.getMesh().build(NavEditorGui.backgroundBuild, NavEditorGui.saveIntermediates);
- %this.isDirty = true;
- }
- }
- function NavEditorGui::buildLinks(%this)
- {
- if(isObject(%this.getMesh()))
- {
- %this.getMesh().buildLinks();
- %this.isDirty = true;
- }
- }
- function updateLinkData(%control, %flags)
- {
- %control->LinkWalkFlag.setActive(true);
- %control->LinkJumpFlag.setActive(true);
- %control->LinkDropFlag.setActive(true);
- %control->LinkLedgeFlag.setActive(true);
- %control->LinkClimbFlag.setActive(true);
- %control->LinkTeleportFlag.setActive(true);
- %control->LinkWalkFlag.setStateOn(%flags & $Nav::WalkFlag);
- %control->LinkJumpFlag.setStateOn(%flags & $Nav::JumpFlag);
- %control->LinkDropFlag.setStateOn(%flags & $Nav::DropFlag);
- %control->LinkLedgeFlag.setStateOn(%flags & $Nav::LedgeFlag);
- %control->LinkClimbFlag.setStateOn(%flags & $Nav::ClimbFlag);
- %control->LinkTeleportFlag.setStateOn(%flags & $Nav::TeleportFlag);
- }
- function getLinkFlags(%control)
- {
- return (%control->LinkWalkFlag.isStateOn() ? $Nav::WalkFlag : 0) |
- (%control->LinkJumpFlag.isStateOn() ? $Nav::JumpFlag : 0) |
- (%control->LinkDropFlag.isStateOn() ? $Nav::DropFlag : 0) |
- (%control->LinkLedgeFlag.isStateOn() ? $Nav::LedgeFlag : 0) |
- (%control->LinkClimbFlag.isStateOn() ? $Nav::ClimbFlag : 0) |
- (%control->LinkTeleportFlag.isStateOn() ? $Nav::TeleportFlag : 0);
- }
- function disableLinkData(%control)
- {
- %control->LinkWalkFlag.setActive(false);
- %control->LinkJumpFlag.setActive(false);
- %control->LinkDropFlag.setActive(false);
- %control->LinkLedgeFlag.setActive(false);
- %control->LinkClimbFlag.setActive(false);
- %control->LinkTeleportFlag.setActive(false);
- }
- function NavEditorGui::onLinkSelected(%this, %flags)
- {
- updateLinkData(NavEditorOptionsWindow-->LinkProperties, %flags);
- }
- function NavEditorGui::onPlayerSelected(%this, %flags)
- {
- updateLinkData(NavEditorOptionsWindow-->TestProperties, %flags);
- }
- function NavEditorGui::updateLinkFlags(%this)
- {
- if(isObject(%this.getMesh()))
- {
- %properties = NavEditorOptionsWindow-->LinkProperties;
- %this.setLinkFlags(getLinkFlags(%properties));
- %this.isDirty = true;
- }
- }
- function NavEditorGui::updateTestFlags(%this)
- {
- if(isObject(%this.getPlayer()))
- {
- %properties = NavEditorOptionsWindow-->TestProperties;
- %player = %this.getPlayer();
- %player.allowWwalk = %properties->LinkWalkFlag.isStateOn();
- %player.allowJump = %properties->LinkJumpFlag.isStateOn();
- %player.allowDrop = %properties->LinkDropFlag.isStateOn();
- %player.allowLedge = %properties->LinkLedgeFlag.isStateOn();
- %player.allowClimb = %properties->LinkClimbFlag.isStateOn();
- %player.allowTeleport = %properties->LinkTeleportFlag.isStateOn();
- %this.isDirty = true;
- }
- }
- function NavEditorGui::onLinkDeselected(%this)
- {
- disableLinkData(NavEditorOptionsWindow-->LinkProperties);
- }
- function NavEditorGui::onPlayerDeselected(%this)
- {
- disableLinkData(NavEditorOptionsWindow-->TestProperties);
- }
- function NavEditorGui::createCoverPoints(%this)
- {
- if(isObject(%this.getMesh()))
- {
- %this.getMesh().createCoverPoints();
- %this.isDirty = true;
- }
- }
- function NavEditorGui::deleteCoverPoints(%this)
- {
- if(isObject(%this.getMesh()))
- {
- %this.getMesh().deleteCoverPoints();
- %this.isDirty = true;
- }
- }
- function NavEditorGui::findCover(%this)
- {
- if(%this.getMode() $= "TestMode" && isObject(%this.getPlayer()))
- {
- %pos = LocalClientConnection.getControlObject().getPosition();
- %text = NavEditorOptionsWindow-->TestProperties->CoverPosition.getText();
- if(%text !$= "")
- %pos = eval("return " @ %text);
- %this.getPlayer().findCover(%pos, NavEditorOptionsWindow-->TestProperties->CoverRadius.getText());
- }
- }
- function NavEditorGui::followObject(%this)
- {
- if(%this.getMode() $= "TestMode" && isObject(%this.getPlayer()))
- {
- %obj = LocalClientConnection.player;
- %text = NavEditorOptionsWindow-->TestProperties->FollowObject.getText();
- if(%text !$= "")
- {
- %command = "return " @ %text;
- if(!endsWith(%command, ";"))
- %command = %command @ ";";
-
- %obj = eval(%command);
- if(!isObject(%obj))
- toolsMessageBoxOk("Error", "Cannot find object" SPC %text);
- }
- if(isObject(%obj))
- %this.getPlayer().followObject(%obj, NavEditorOptionsWindow-->TestProperties->FollowRadius.getText());
- }
- }
- function NavInspector::inspect(%this, %obj)
- {
- %name = "";
- if(isObject(%obj))
- %name = %obj.getName();
- else
- NavFieldInfoControl.setText("");
- Parent::inspect(%this, %obj);
- }
- function NavInspector::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 NavInspector::onFieldSelected(%this, %fieldName, %fieldTypeStr, %fieldDoc)
- {
- NavFieldInfoControl.setText( "<font:" @ $Gui::fontTypeBold @ ":16>" @ %fieldName @ "<font:" @ $Gui::fontTypeItalic @ ":16> (" @ %fieldTypeStr @ ") " NL "<font:" @ $Gui::fontTypeRegular @ ":16>" @ %fieldDoc );
- }
- function NavTreeView::onInspect(%this, %obj)
- {
- NavInspector.inspect(%obj);
- }
- function NavTreeView::onSelect(%this, %obj)
- {
- NavInspector.inspect(%obj);
- NavEditorGui.onObjectSelected(%obj);
- }
- function NavEditorGui::prepSelectionMode(%this)
- {
- %this.setMode("SelectMode");
- ToolsPaletteArray-->NavEditorSelectMode.setStateOn(1);
- }
- //-----------------------------------------------------------------------------
- function ENavEditorPaletteButton::onClick(%this)
- {
- // When clicking on a pelette button, add its description to the bottom of
- // the editor window.
- EditorGuiStatusBar.setInfo(%this.DetailedDesc);
- }
- //-----------------------------------------------------------------------------
- function NavMeshLinkFlagButton::onClick(%this)
- {
- NavEditorGui.updateLinkFlags();
- }
- function NavMeshTestFlagButton::onClick(%this)
- {
- NavEditorGui.updateTestFlags();
- }
- singleton GuiControlProfile(NavEditorProfile)
- {
- canKeyFocus = true;
- opaque = true;
- fillColor = "192 192 192 192";
- category = "Editor";
- };
|