add select tool
cleanup more from guinaveditorctrl and scripts
This commit is contained in:
marauder2k7 2025-07-27 19:32:52 +01:00
parent 3946017556
commit 24ec55e8bc
9 changed files with 252 additions and 208 deletions

View file

@ -38,6 +38,7 @@
#include "gui/worldEditor/undoActions.h"
#include "T3D/gameBase/gameConnection.h"
#include "T3D/AI/AIController.h"
#include "navigation/navMeshTool.h"
IMPLEMENT_CONOBJECT(GuiNavEditorCtrl);
@ -47,15 +48,8 @@ ConsoleDocClass(GuiNavEditorCtrl,
"@internal"
);
// Each of the mode names directly correlates with the Nav Editor's tool palette.
const String GuiNavEditorCtrl::mSelectMode = "SelectMode";
const String GuiNavEditorCtrl::mLinkMode = "LinkMode";
const String GuiNavEditorCtrl::mCoverMode = "CoverMode";
const String GuiNavEditorCtrl::mTestMode = "TestMode";
GuiNavEditorCtrl::GuiNavEditorCtrl()
{
mMode = mSelectMode;
mIsDirty = false;
mStartDragMousePoint = InvalidMousePoint;
mMesh = NULL;
@ -101,8 +95,6 @@ void GuiNavEditorCtrl::initPersistFields()
void GuiNavEditorCtrl::onSleep()
{
Parent::onSleep();
//mMode = mSelectMode;
}
void GuiNavEditorCtrl::selectMesh(NavMesh *mesh)
@ -311,15 +303,6 @@ bool GuiNavEditorCtrl::getStaticPos(const Gui3DMouseEvent & event, Point3F &tpos
return hit;
}
void GuiNavEditorCtrl::setMode(String mode, bool sourceShortcut = false)
{
mMode = mode;
Con::executef(this, "onModeSet", mode);
if(sourceShortcut)
Con::executef(this, "paletteSync", mode);
}
void GuiNavEditorCtrl::submitUndo(const UTF8 *name)
{
// Grab the mission editor undo manager.
@ -361,6 +344,7 @@ void GuiNavEditorCtrl::setActiveTool(NavMeshTool* tool)
if (mTool)
{
mTool->setActiveEditor(this);
mTool->setActiveNavMesh(mMesh);
mTool->onActivated(mLastEvent);
}
@ -386,14 +370,4 @@ DefineEngineMethod(GuiNavEditorCtrl, setActiveTool, void, (const char* toolName)
object->setActiveTool(tool);
}
DefineEngineMethod(GuiNavEditorCtrl, getMode, const char*, (), , "")
{
return object->getMode();
}
DefineEngineMethod(GuiNavEditorCtrl, setMode, void, (String mode),, "setMode(String mode)")
{
object->setMode(mode);
}
#endif

View file

@ -34,9 +34,9 @@
#include "gui/worldEditor/gizmo.h"
#endif
#ifndef _NAVMESH_TOOL_H_
#include "navigation/navMeshTool.h"
#endif
//#ifndef _NAVMESH_TOOL_H_
//#include "navigation/navMeshTool.h"
//#endif
#include "navMesh.h"
#include "T3D/aiPlayer.h"
@ -45,6 +45,7 @@ struct ObjectRenderInst;
class SceneManager;
class SceneRenderState;
class BaseMatInstance;
class NavMeshTool;
class GuiNavEditorCtrl : public EditTSCtrl
{
@ -99,9 +100,6 @@ public:
bool getStaticPos(const Gui3DMouseEvent & event, Point3F &tpos);
void setMode(String mode, bool sourceShortcut);
String getMode() { return mMode; }
void selectMesh(NavMesh *mesh);
S32 getMeshId();
@ -122,8 +120,6 @@ protected:
bool mIsDirty;
String mMode;
/// Currently-selected NavMesh.
SimObjectPtr<NavMesh> mMesh;

View file

@ -12,6 +12,10 @@
#include "navigation/navMesh.h"
#endif
#ifndef _GUINAVEDITORCTRL_H_
#include "navigation/guiNavEditorCtrl.h"
#endif
class UndoAction;
class NavMeshTool : public SimObject
@ -19,6 +23,8 @@ class NavMeshTool : public SimObject
typedef SimObject Parent;
protected:
SimObjectPtr<NavMesh> mNavMesh;
SimObjectPtr<GuiNavEditorCtrl> mCurEditor;
void _submitUndo(UndoAction* action);
public:
@ -29,6 +35,7 @@ public:
DECLARE_CONOBJECT(NavMeshTool);
virtual void setActiveNavMesh(NavMesh* nav_mesh) { mNavMesh = nav_mesh; }
virtual void setActiveEditor(GuiNavEditorCtrl* nav_editor) { mCurEditor = nav_editor; }
virtual void onActivated(const Gui3DMouseEvent& lastEvent) {}
virtual void onDeactivated() {}

View file

@ -0,0 +1,112 @@
#include "navMeshSelectTool.h"
#include "console/consoleTypes.h"
#include "gfx/gfxDrawUtil.h"
IMPLEMENT_CONOBJECT(NavMeshSelectTool);
static void renderBoxOutline(const Box3F& box, const ColorI& col)
{
if (box != Box3F::Invalid)
{
GFXStateBlockDesc desc;
desc.setCullMode(GFXCullNone);
desc.setFillModeSolid();
desc.setZReadWrite(true, false);
desc.setBlend(true);
GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 20));
desc.setFillModeWireframe();
desc.setBlend(false);
GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 255));
}
}
NavMeshSelectTool::NavMeshSelectTool()
{
mCurMesh = NULL;
}
void NavMeshSelectTool::onActivated(const Gui3DMouseEvent& evt)
{
Con::executef(this, "onActivated");
}
void NavMeshSelectTool::onDeactivated()
{
Con::executef(this, "onDeactivated");
}
void NavMeshSelectTool::on3DMouseDown(const Gui3DMouseEvent& evt)
{
if (mCurEditor.isNull())
return;
Point3F startPnt = evt.pos;
Point3F endPnt = evt.pos + evt.vec * 1000.0f;
RayInfo ri;
if (gServerContainer.castRay(startPnt, endPnt, MarkerObjectType, &ri))
{
if (!ri.object)
return;
NavMesh* selNavMesh = dynamic_cast<NavMesh*>(ri.object);
if (selNavMesh)
{
mCurEditor->selectMesh(selNavMesh);
return;
}
}
}
void NavMeshSelectTool::on3DMouseMove(const Gui3DMouseEvent& evt)
{
if (mCurEditor.isNull())
return;
Point3F startPnt = evt.pos;
Point3F endPnt = evt.pos + evt.vec * 1000.0f;
RayInfo ri;
if (gServerContainer.castRay(startPnt, endPnt, MarkerObjectType, &ri))
{
NavMesh* selNavMesh = dynamic_cast<NavMesh*>(ri.object);
if (selNavMesh)
{
mCurMesh = selNavMesh;
}
else
{
mCurMesh = NULL;
}
}
else
{
mCurMesh = NULL;
}
}
void NavMeshSelectTool::onRender3D()
{
if (!mCurMesh.isNull())
renderBoxOutline(mCurMesh->getWorldBox(), ColorI::LIGHT);
}
bool NavMeshSelectTool::updateGuiInfo()
{
SimObject* statusbar;
Sim::findObject("EditorGuiStatusBar", statusbar);
GuiTextCtrl* selectionBar;
Sim::findObject("EWorldEditorStatusBarSelection", selectionBar);
String text;
if (statusbar)
Con::executef(statusbar, "setInfo", text.c_str());
if (selectionBar)
selectionBar->setText(text);
return true;
}

View file

@ -0,0 +1,30 @@
#ifndef _NAVMESHSELECTTOOL_H_
#define _NAVMESHSELECTTOOL_H_
#ifndef _NAVMESH_TOOL_H_
#include "navigation/navMeshTool.h"
#endif
class NavMeshSelectTool : public NavMeshTool
{
typedef NavMeshTool Parent;
protected:
SimObjectPtr<NavMesh> mCurMesh;
public:
DECLARE_CONOBJECT(NavMeshSelectTool);
NavMeshSelectTool();
virtual ~NavMeshSelectTool() {}
void onActivated(const Gui3DMouseEvent& evt) override;
void onDeactivated() override;
void on3DMouseDown(const Gui3DMouseEvent& evt) override;
void on3DMouseMove(const Gui3DMouseEvent& evt) override;
void onRender3D() override;
bool updateGuiInfo() override;
};
#endif

View file

@ -367,6 +367,9 @@ bool NavMeshTestTool::updateGuiInfo()
if (mSpawnClass != String::EmptyString && mSpawnDatablock != String::EmptyString)
text += " CTRL+LMB To spawn a new Bot.";
if (mSelectFollow)
text = "LMB To select Follow Target.";
if (statusbar)
Con::executef(statusbar, "setInfo", text.c_str());