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

View file

@ -274,7 +274,7 @@ void World::step(const float& stepTime) {
player.rotate(player.currentRotationSpeed*stepTime);
#ifdef IMGUI
ImGui::Begin("MapEdit");
if (ImGui::Begin("MapEdit")) {
static int blockToPlace = 1;
/*
@ -282,27 +282,27 @@ void World::step(const float& stepTime) {
* Dear ImGui layout an allows adding things on the side.
*/
ImGui::BeginGroup();
for (int y = 0 ; y < h ; y++) {
for (int x = 0 ; x < w ; x++) {
ImGui::PushID(x + y*w);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
ImGui::PushID(x + y * w);
if (x > 0)
ImGui::SameLine();
BlockType currentBlock = map[x + w*y];
BlockType currentBlock = map[x + w * y];
ImVec4 hoverColor;
switch ((BlockType)blockToPlace) {
switch ((BlockType) blockToPlace) {
case BlockType::WALL:
hoverColor = (ImVec4)Colors::Wall;
hoverColor = (ImVec4) Colors::Wall;
break;
case BlockType::DOOR:
hoverColor = (ImVec4)Colors::Door;
hoverColor = (ImVec4) Colors::Door;
break;
case BlockType::WINDOW:
hoverColor = (ImVec4)Colors::Window;
hoverColor = (ImVec4) Colors::Window;
break;
default:
/* Default header color, it seems ? */
hoverColor = (ImVec4)ImColor(188, 120, 32);
hoverColor = (ImVec4) ImColor(188, 120, 32);
break;
}
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hoverColor);
@ -310,22 +310,23 @@ void World::step(const float& stepTime) {
ImVec4 blockColor;
switch (currentBlock) {
case BlockType::WALL:
blockColor = (ImVec4)Colors::Wall;
blockColor = (ImVec4) Colors::Wall;
break;
case BlockType::DOOR:
blockColor = (ImVec4)Colors::Door;
blockColor = (ImVec4) Colors::Door;
break;
case BlockType::WINDOW:
blockColor = (ImVec4)Colors::Window;
blockColor = (ImVec4) Colors::Window;
break;
default:
blockColor = (ImVec4)ImColor(188, 120, 32);
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;
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();
@ -337,12 +338,12 @@ void World::step(const float& stepTime) {
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::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();
#endif
}