1
0
Fork 0

World/Debug: Properly check the MapEdit status

If a Dear ImGui window is collapsed or closed, ImGui::Begin returns false.
Check it properly to bypass rendering if is indeed not needed.
This commit is contained in:
Teo-CD 2024-01-28 22:05:20 +00:00
parent 43970df494
commit 66ec111f5d

129
World.cpp
View file

@ -274,75 +274,76 @@ void World::step(const float& stepTime) {
player.rotate(player.currentRotationSpeed*stepTime); player.rotate(player.currentRotationSpeed*stepTime);
#ifdef IMGUI #ifdef IMGUI
ImGui::Begin("MapEdit"); if (ImGui::Begin("MapEdit")) {
static int blockToPlace = 1; static int blockToPlace = 1;
/* /*
* Group all the select boxes together : makes it a big block in the * Group all the select boxes together : makes it a big block in the
* Dear ImGui layout an allows adding things on the side. * Dear ImGui layout an allows adding things on the side.
*/ */
ImGui::BeginGroup(); ImGui::BeginGroup();
for (int y = 0 ; y < h ; y++) { for (int y = 0; y < h; y++) {
for (int x = 0 ; x < w ; x++) { for (int x = 0; x < w; x++) {
ImGui::PushID(x + y*w); ImGui::PushID(x + y * w);
if (x > 0) if (x > 0)
ImGui::SameLine(); ImGui::SameLine();
BlockType currentBlock = map[x + w*y]; BlockType currentBlock = map[x + w * y];
ImVec4 hoverColor; ImVec4 hoverColor;
switch ((BlockType)blockToPlace) { switch ((BlockType) blockToPlace) {
case BlockType::WALL: case BlockType::WALL:
hoverColor = (ImVec4)Colors::Wall; hoverColor = (ImVec4) Colors::Wall;
break; break;
case BlockType::DOOR: case BlockType::DOOR:
hoverColor = (ImVec4)Colors::Door; hoverColor = (ImVec4) Colors::Door;
break; break;
case BlockType::WINDOW: case BlockType::WINDOW:
hoverColor = (ImVec4)Colors::Window; hoverColor = (ImVec4) Colors::Window;
break; break;
default: default:
/* Default header color, it seems ? */ /* Default header color, it seems ? */
hoverColor = (ImVec4)ImColor(188, 120, 32); hoverColor = (ImVec4) ImColor(188, 120, 32);
break; break;
}
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hoverColor);
ImVec4 blockColor;
switch (currentBlock) {
case BlockType::WALL:
blockColor = (ImVec4) Colors::Wall;
break;
case BlockType::DOOR:
blockColor = (ImVec4) Colors::Door;
break;
case BlockType::WINDOW:
blockColor = (ImVec4) Colors::Window;
break;
default:
blockColor = (ImVec4) ImColor(188, 120, 32);
break;
}
ImGui::PushStyleColor(ImGuiCol_Header, blockColor);
if (ImGui::Selectable("", currentBlock != BlockType::AIR, 0, ImVec2(10, 10))) {
map[x + w * y] =
currentBlock == (BlockType) blockToPlace ? BlockType::AIR : (BlockType) blockToPlace;
}
ImGui::PopStyleColor(2);
ImGui::PopID();
} }
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hoverColor);
ImVec4 blockColor;
switch (currentBlock) {
case BlockType::WALL:
blockColor = (ImVec4)Colors::Wall;
break;
case BlockType::DOOR:
blockColor = (ImVec4)Colors::Door;
break;
case BlockType::WINDOW:
blockColor = (ImVec4)Colors::Window;
break;
default:
blockColor = (ImVec4)ImColor(188, 120, 32);
break;
}
ImGui::PushStyleColor(ImGuiCol_Header, blockColor);
if(ImGui::Selectable("", currentBlock != BlockType::AIR, 0, ImVec2(10, 10))) {
map[x + w*y] = currentBlock == (BlockType)blockToPlace ? BlockType::AIR : (BlockType)blockToPlace;
}
ImGui::PopStyleColor(2);
ImGui::PopID();
} }
ImGui::EndGroup();
ImGui::SameLine();
ImGui::BeginGroup();
ImGui::Indent();
ImGui::Text("Place :");
ImGui::RadioButton("Wall", &blockToPlace, (int) BlockType::WALL);
ImGui::RadioButton("Door", &blockToPlace, (int) BlockType::DOOR);
ImGui::RadioButton("Window", &blockToPlace, (int) BlockType::WINDOW);
ImGui::Unindent();
ImGui::EndGroup();
} }
ImGui::EndGroup();
ImGui::SameLine();
ImGui::BeginGroup();
ImGui::Indent();
ImGui::Text("Place :");
ImGui::RadioButton("Wall", &blockToPlace, (int)BlockType::WALL);
ImGui::RadioButton("Door", &blockToPlace, (int)BlockType::DOOR);
ImGui::RadioButton("Window", &blockToPlace, (int)BlockType::WINDOW);
ImGui::Unindent();
ImGui::EndGroup();
ImGui::End(); ImGui::End();
#endif #endif
} }