Use static arrays of strings for tool and display names

This commit is contained in:
Graham Pentheny
2025-08-04 15:54:35 -04:00
parent 8428cd1525
commit 065fd54c81
6 changed files with 102 additions and 74 deletions

View File

@@ -33,18 +33,30 @@ enum class SampleToolType : uint8_t
{
NONE = 0,
TILE_EDIT,
TILE_HIGHLIGHT,
TEMP_OBSTACLE,
NAVMESH_TESTER,
NAVMESH_PRUNE,
OFFMESH_CONNECTION,
CONVEX_VOLUME,
CROWD,
TILE_EDIT = 1,
TILE_HIGHLIGHT = 2,
TEMP_OBSTACLE = 3,
NAVMESH_TESTER = 4,
NAVMESH_PRUNE = 5,
OFFMESH_CONNECTION = 6,
CONVEX_VOLUME = 7,
CROWD = 8,
MAX_TOOLS
};
static const char* toolNames[] = {
"None",
"Create Tiles",
"Highlight Tile Cache",
"Create Temp Obstacles",
"Test Navmesh",
"Prune Navmesh",
"Create Off-Mesh Connections",
"Create Convex Volumes",
"Create Crowds",
};
/// These are just sample areas to use consistent values across the samples.
/// The use should specify these base on his needs.
enum SamplePolyAreas

View File

@@ -58,6 +58,7 @@ protected:
POLYMESH_DETAIL
};
DrawMode currentDrawMode = DrawMode::NAVMESH;
static const char* drawModeNames[];
void cleanup();

View File

@@ -60,6 +60,7 @@ private:
POLYMESH_DETAIL
};
DrawMode drawMode = DrawMode::NAVMESH;
static const char* drawModeNames[];
int maxTiles = 0;
int maxPolysPerTile = 0;
@@ -76,7 +77,7 @@ private:
unsigned char* buildTileMesh(int tileX, int tileY, const float* boundsMin, const float* boundsMax, int& outDataSize);
void cleanup();
void UI_DrawModeOption(const char* name, DrawMode drawMode, bool enabled);
void UI_DrawModeOption(DrawMode drawMode, bool enabled);
public:
Sample_TileMesh();

View File

@@ -43,6 +43,26 @@
# define snprintf _snprintf
#endif
const char* Sample_SoloMesh::drawModeNames[] {
"Navmesh",
"Navmesh Trans",
"Navmesh BVTree",
"Navmesh Nodes",
"Navmesh Invis",
"Input Mesh",
"Voxels",
"Walkable Voxels",
"Compact",
"Compact Distance",
"Compact Regions",
"Region Connections",
"Raw Contours",
"Both Contours",
"Contours",
"Poly Mesh",
"Poly Mesh Detail"
};
Sample_SoloMesh::Sample_SoloMesh()
{
setTool(new NavMeshTesterTool);
@@ -91,29 +111,28 @@ void Sample_SoloMesh::handleSettings()
void Sample_SoloMesh::handleTools()
{
const SampleToolType type = !tool ? SampleToolType::NONE : tool->type();
const SampleToolType currentType = !tool ? SampleToolType::NONE : tool->type();
if (ImGui::RadioButton("Test Navmesh", type == SampleToolType::NAVMESH_TESTER)) { setTool(new NavMeshTesterTool); }
if (ImGui::RadioButton("Prune Navmesh", type == SampleToolType::NAVMESH_PRUNE)) { setTool(new NavMeshPruneTool); }
if (ImGui::RadioButton("Create Off-Mesh Connections", type == SampleToolType::OFFMESH_CONNECTION)) { setTool(new OffMeshConnectionTool); }
if (ImGui::RadioButton("Create Convex Volumes", type == SampleToolType::CONVEX_VOLUME)) { setTool(new ConvexVolumeTool); }
if (ImGui::RadioButton("Create Crowds", type == SampleToolType::CROWD)) { setTool(new CrowdTool); }
#define TOOL(toolType, toolClass) if (ImGui::RadioButton(toolNames[static_cast<uint8_t>(SampleToolType::toolType)], currentType == SampleToolType::toolType)) { setTool(new toolClass{}); }
TOOL(NAVMESH_TESTER, NavMeshTesterTool)
TOOL(NAVMESH_PRUNE, NavMeshPruneTool)
TOOL(OFFMESH_CONNECTION, OffMeshConnectionTool)
TOOL(CONVEX_VOLUME, ConvexVolumeTool)
TOOL(CROWD, CrowdTool)
#undef TOOL
ImGui::Separator();
ImGui::Indent();
if (tool)
{
tool->handleMenu();
}
ImGui::Unindent();
}
void Sample_SoloMesh::UI_DrawModeOption(const char* name, const DrawMode drawMode, const bool enabled)
{
ImGui::BeginDisabled(!enabled);
bool checked = currentDrawMode == drawMode;
if (ImGui::Checkbox(name, &checked))
if (ImGui::RadioButton(name, currentDrawMode == drawMode))
{
currentDrawMode = drawMode;
}

View File

@@ -1010,14 +1010,10 @@ void Sample_TempObstacles::handleTools()
ImGui::Separator();
ImGui::Indent();
if (tool)
{
tool->handleMenu();
}
ImGui::Unindent();
}
void Sample_TempObstacles::handleDebugMode()

View File

@@ -82,6 +82,27 @@ unsigned int ilog2(unsigned int v)
}
}
const char* Sample_TileMesh::drawModeNames[] {
"Navmesh",
"Navmesh Trans",
"Navmesh BVTree",
"Navmesh Nodes",
"Navmesh Portals",
"Navmesh Invis",
"Input Mesh",
"Voxels",
"Walkable Voxels",
"Compact",
"Compact Disatnce",
"Compact Regions",
"Region Connections",
"Raw Contours",
"Both Contours",
"Contours",
"Poly Mesh",
"Poly Mesh Detail"
};
class NavMeshTileTool : public SampleTool
{
Sample_TileMesh* m_sample = nullptr;
@@ -276,50 +297,28 @@ void Sample_TileMesh::handleSettings()
void Sample_TileMesh::handleTools()
{
const SampleToolType type = !tool ? SampleToolType::NONE : tool->type();
if (ImGui::RadioButton("Test Navmesh", type == SampleToolType::NAVMESH_TESTER))
{
setTool(new NavMeshTesterTool);
}
if (ImGui::RadioButton("Prune Navmesh", type == SampleToolType::NAVMESH_PRUNE))
{
setTool(new NavMeshPruneTool);
}
if (ImGui::RadioButton("Create Tiles", type == SampleToolType::TILE_EDIT))
{
setTool(new NavMeshTileTool);
}
if (ImGui::RadioButton("Create Off-Mesh Links", type == SampleToolType::OFFMESH_CONNECTION))
{
setTool(new OffMeshConnectionTool);
}
if (ImGui::RadioButton("Create Convex Volumes", type == SampleToolType::CONVEX_VOLUME))
{
setTool(new ConvexVolumeTool);
}
if (ImGui::RadioButton("Create Crowds", type == SampleToolType::CROWD))
{
setTool(new CrowdTool);
}
const SampleToolType currentType = !tool ? SampleToolType::NONE : tool->type();
#define TOOL(toolType, toolClass) if (ImGui::RadioButton(toolNames[static_cast<uint8_t>(SampleToolType::toolType)], currentType == SampleToolType::toolType)) { setTool(new toolClass{}); }
TOOL(NAVMESH_TESTER, NavMeshTesterTool)
TOOL(NAVMESH_PRUNE, NavMeshPruneTool)
TOOL(TILE_EDIT, NavMeshTileTool)
TOOL(OFFMESH_CONNECTION, OffMeshConnectionTool)
TOOL(CONVEX_VOLUME, ConvexVolumeTool)
TOOL(CROWD, CrowdTool)
#undef TOOL
ImGui::Separator();
ImGui::Indent();
if (tool)
{
tool->handleMenu();
}
ImGui::Unindent();
}
void Sample_TileMesh::UI_DrawModeOption(const char* name, DrawMode drawMode, bool enabled)
void Sample_TileMesh::UI_DrawModeOption(DrawMode drawMode, bool enabled)
{
ImGui::BeginDisabled(!enabled);
bool checked = this->drawMode == drawMode;
if (ImGui::Checkbox(name, &checked))
if (ImGui::RadioButton(drawModeNames[static_cast<int>(drawMode)], this->drawMode == drawMode))
{
this->drawMode = drawMode;
}
@@ -329,24 +328,24 @@ void Sample_TileMesh::UI_DrawModeOption(const char* name, DrawMode drawMode, boo
void Sample_TileMesh::handleDebugMode()
{
ImGui::Text("Draw");
UI_DrawModeOption("Input Mesh", DrawMode::MESH, true);
UI_DrawModeOption("Navmesh", DrawMode::NAVMESH, navMesh != nullptr);
UI_DrawModeOption("Navmesh Invis", DrawMode::NAVMESH_INVIS, navMesh != nullptr);
UI_DrawModeOption("Navmesh Trans", DrawMode::NAVMESH_TRANS, navMesh != nullptr);
UI_DrawModeOption("Navmesh BVTree", DrawMode::NAVMESH_BVTREE, navMesh != nullptr);
UI_DrawModeOption("Navmesh Nodes", DrawMode::NAVMESH_NODES, navQuery != nullptr);
UI_DrawModeOption("Navmesh Portals", DrawMode::NAVMESH_PORTALS, navMesh != nullptr);
UI_DrawModeOption("Voxels", DrawMode::VOXELS, heightfield != nullptr);
UI_DrawModeOption("Walkable Voxels", DrawMode::VOXELS_WALKABLE, heightfield != nullptr);
UI_DrawModeOption("Compact", DrawMode::COMPACT, compactHeightfield != nullptr);
UI_DrawModeOption("Compact Distance", DrawMode::COMPACT_DISTANCE, compactHeightfield != nullptr);
UI_DrawModeOption("Compact Regions", DrawMode::COMPACT_REGIONS, compactHeightfield != nullptr);
UI_DrawModeOption("Region Connections", DrawMode::REGION_CONNECTIONS, contourSet != nullptr);
UI_DrawModeOption("Raw Contours", DrawMode::RAW_CONTOURS, contourSet != nullptr);
UI_DrawModeOption("Both Contours", DrawMode::BOTH_CONTOURS, contourSet != nullptr);
UI_DrawModeOption("Contours", DrawMode::CONTOURS, contourSet != nullptr);
UI_DrawModeOption("Poly Mesh", DrawMode::POLYMESH, polyMesh != nullptr);
UI_DrawModeOption("Poly Mesh Detail", DrawMode::POLYMESH_DETAIL, detailPolyMesh != nullptr);
UI_DrawModeOption(DrawMode::MESH, true);
UI_DrawModeOption(DrawMode::NAVMESH, navMesh != nullptr);
UI_DrawModeOption(DrawMode::NAVMESH_INVIS, navMesh != nullptr);
UI_DrawModeOption(DrawMode::NAVMESH_TRANS, navMesh != nullptr);
UI_DrawModeOption(DrawMode::NAVMESH_BVTREE, navMesh != nullptr);
UI_DrawModeOption(DrawMode::NAVMESH_NODES, navQuery != nullptr);
UI_DrawModeOption(DrawMode::NAVMESH_PORTALS, navMesh != nullptr);
UI_DrawModeOption(DrawMode::VOXELS, heightfield != nullptr);
UI_DrawModeOption(DrawMode::VOXELS_WALKABLE, heightfield != nullptr);
UI_DrawModeOption(DrawMode::COMPACT, compactHeightfield != nullptr);
UI_DrawModeOption(DrawMode::COMPACT_DISTANCE, compactHeightfield != nullptr);
UI_DrawModeOption(DrawMode::COMPACT_REGIONS, compactHeightfield != nullptr);
UI_DrawModeOption(DrawMode::REGION_CONNECTIONS, contourSet != nullptr);
UI_DrawModeOption(DrawMode::RAW_CONTOURS, contourSet != nullptr);
UI_DrawModeOption(DrawMode::BOTH_CONTOURS, contourSet != nullptr);
UI_DrawModeOption(DrawMode::CONTOURS, contourSet != nullptr);
UI_DrawModeOption(DrawMode::POLYMESH, polyMesh != nullptr);
UI_DrawModeOption(DrawMode::POLYMESH_DETAIL, detailPolyMesh != nullptr);
}
void Sample_TileMesh::handleRender()