From 29e57e1605eab97af463412ef44d53d169975cc4 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 22 Sep 2024 15:26:50 +0200 Subject: [PATCH] Recast: allow modifying brush types of existing primitive volumes --- src/naveditor/ShapeVolumeTool.cpp | 67 +++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/naveditor/ShapeVolumeTool.cpp b/src/naveditor/ShapeVolumeTool.cpp index b01011fd..994fdf82 100644 --- a/src/naveditor/ShapeVolumeTool.cpp +++ b/src/naveditor/ShapeVolumeTool.cpp @@ -81,8 +81,8 @@ static bool isValidVolumeIndex(const int index, const InputGeom* geom) void handleVolumeFlags(int& flags, const char* buttonId) { - ImGui::Text("Poly Flags"); ImGui::Indent(); + ImGui::Text("Poly Flags"); const int numPolyFlags = V_ARRAYSIZE(g_navMeshPolyFlagNames); char buttonName[64]; @@ -96,6 +96,46 @@ void handleVolumeFlags(int& flags, const char* buttonId) ImGui::Unindent(); } +static const char* getBrushNameForArea(const unsigned char area) +{ + switch (area) + { + case DT_POLYAREA_GROUND: + return "Clip"; + case DT_POLYAREA_TRIGGER: + return "Trigger"; + default: + return "Invalid"; + } +} + +bool handleBrushTypes(int& area, const char* buttonId) +{ + bool ret = false; + + char buttonName[64]; + snprintf(buttonName, sizeof(buttonName), "Brush##%s", buttonId); + + if (ImGui::BeginCombo(buttonName, getBrushNameForArea((unsigned char)area))) + { + if (ImGui::Selectable(getBrushNameForArea(DT_POLYAREA_GROUND), area == DT_POLYAREA_GROUND)) + { + area = DT_POLYAREA_GROUND; + ret = true; + } + + if (ImGui::Selectable(getBrushNameForArea(DT_POLYAREA_TRIGGER), area == DT_POLYAREA_TRIGGER)) + { + area = DT_POLYAREA_TRIGGER; + ret = true; + } + + ImGui::EndCombo(); + } + + return ret; +} + ShapeVolumeTool::ShapeVolumeTool() : m_selectedVolumeIndex(-1), m_editor(0), @@ -175,27 +215,14 @@ void ShapeVolumeTool::handleMenu() m_nhull = 0; } - ImGui::Separator(); - - ImGui::Text("Brushes"); - ImGui::Indent(); - - bool isEnabled = m_areaType == RC_NULL_AREA; - - if (ImGui::Checkbox("Clip##ShapeVolumeCreate", &isEnabled)) - m_areaType = RC_NULL_AREA; - - isEnabled = m_areaType == DT_POLYAREA_TRIGGER; - if (ImGui::Checkbox("Trigger##ShapeVolumeCreate", &isEnabled)) - m_areaType = DT_POLYAREA_TRIGGER; + handleBrushTypes(m_areaType, "ShapeVolumeCreate"); if (m_areaType == DT_POLYAREA_TRIGGER) { + ImGui::Separator(); handleVolumeFlags(m_polyFlags, "ShapeVolumeCreate"); } - ImGui::Unindent(); - InputGeom* geom = m_editor->getInputGeom(); if (!geom || !isValidVolumeIndex(m_selectedVolumeIndex, geom)) @@ -212,8 +239,16 @@ void ShapeVolumeTool::handleMenu() m_copiedShapeIndex = m_selectedVolumeIndex; } + int volArea = vol.area; + handleBrushTypes(volArea, "ShapeVolumeModify"); + + if (volArea != vol.area) + vol.area = (unsigned char)volArea; + if (vol.area == DT_POLYAREA_TRIGGER) { + ImGui::Separator(); + int flags = vol.flags; handleVolumeFlags(flags, "ShapeVolumeModify");