tileTool.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "tileTool.h"
  2. #include "navigation/guiNavEditorCtrl.h"
  3. #include "console/consoleTypes.h"
  4. #include "gfx/gfxDrawUtil.h"
  5. #include "scene/sceneManager.h"
  6. #include "math/mathUtils.h"
  7. IMPLEMENT_CONOBJECT(TileTool);
  8. static void renderBoxOutline(const Box3F& box, const ColorI& col)
  9. {
  10. if (box != Box3F::Invalid)
  11. {
  12. GFXStateBlockDesc desc;
  13. desc.setCullMode(GFXCullNone);
  14. desc.setFillModeSolid();
  15. desc.setZReadWrite(true, false);
  16. desc.setBlend(true);
  17. GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 20));
  18. desc.setFillModeWireframe();
  19. desc.setBlend(false);
  20. GFX->getDrawUtil()->drawCube(desc, box, ColorI(col, 255));
  21. }
  22. }
  23. void TileTool::onActivated(const Gui3DMouseEvent& lastEvent)
  24. {
  25. Con::executef(this, "onActivated");
  26. }
  27. void TileTool::onDeactivated()
  28. {
  29. Con::executef(this, "onDeactivated");
  30. }
  31. void TileTool::on3DMouseDown(const Gui3DMouseEvent& evt)
  32. {
  33. if (mNavMesh.isNull())
  34. return;
  35. Point3F start = evt.pos;
  36. Point3F end = evt.pos + evt.vec * 1000.0f;
  37. RayInfo ri;
  38. if (gServerContainer.castRay(start, end, StaticObjectType, &ri))
  39. {
  40. mSelTile = mNavMesh->getTile(ri.point);
  41. }
  42. }
  43. void TileTool::on3DMouseMove(const Gui3DMouseEvent& evt)
  44. {
  45. if (mNavMesh.isNull())
  46. return;
  47. Point3F startPnt = evt.pos;
  48. Point3F endPnt = evt.pos + evt.vec * 1000.0f;
  49. RayInfo ri;
  50. if (gServerContainer.castRay(startPnt, endPnt, StaticObjectType, &ri))
  51. mCurTile = mNavMesh->getTile(ri.point);
  52. else
  53. mCurTile = -1;
  54. }
  55. void TileTool::onRender3D()
  56. {
  57. if (mNavMesh.isNull())
  58. return;
  59. if(mCurTile != -1)
  60. renderBoxOutline(mNavMesh->getTileBox(mCurTile), ColorI::BLUE);
  61. if(mSelTile != -1)
  62. renderBoxOutline(mNavMesh->getTileBox(mSelTile), ColorI::GREEN);
  63. }
  64. void TileTool::buildTile()
  65. {
  66. if (!mNavMesh.isNull() && mSelTile != -1)
  67. mNavMesh->buildTile(mSelTile);
  68. }
  69. bool TileTool::updateGuiInfo()
  70. {
  71. SimObject* statusbar;
  72. Sim::findObject("EditorGuiStatusBar", statusbar);
  73. GuiTextCtrl* selectionBar;
  74. Sim::findObject("EWorldEditorStatusBarSelection", selectionBar);
  75. String text;
  76. text = "LMB To select NavMesh Tile";
  77. if (statusbar)
  78. Con::executef(statusbar, "setInfo", text.c_str());
  79. if (mSelTile != -1)
  80. text = String::ToString("Selected Tile: %d", mSelTile);
  81. else
  82. text = "";
  83. if (selectionBar)
  84. selectionBar->setText(text);
  85. return true;
  86. }
  87. DefineEngineMethod(TileTool, buildTile, void, (), ,
  88. "@brief Build the currently selected tile.")
  89. {
  90. return object->buildTile();
  91. }