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:
parent
43970df494
commit
66ec111f5d
1 changed files with 65 additions and 64 deletions
129
World.cpp
129
World.cpp
|
@ -274,75 +274,76 @@ void World::step(const float& stepTime) {
|
|||
player.rotate(player.currentRotationSpeed*stepTime);
|
||||
|
||||
#ifdef IMGUI
|
||||
ImGui::Begin("MapEdit");
|
||||
static int blockToPlace = 1;
|
||||
if (ImGui::Begin("MapEdit")) {
|
||||
static int blockToPlace = 1;
|
||||
|
||||
/*
|
||||
* Group all the select boxes together : makes it a big block in the
|
||||
* 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);
|
||||
if (x > 0)
|
||||
ImGui::SameLine();
|
||||
BlockType currentBlock = map[x + w*y];
|
||||
/*
|
||||
* Group all the select boxes together : makes it a big block in the
|
||||
* 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);
|
||||
if (x > 0)
|
||||
ImGui::SameLine();
|
||||
BlockType currentBlock = map[x + w * y];
|
||||
|
||||
ImVec4 hoverColor;
|
||||
switch ((BlockType)blockToPlace) {
|
||||
case BlockType::WALL:
|
||||
hoverColor = (ImVec4)Colors::Wall;
|
||||
break;
|
||||
case BlockType::DOOR:
|
||||
hoverColor = (ImVec4)Colors::Door;
|
||||
break;
|
||||
case BlockType::WINDOW:
|
||||
hoverColor = (ImVec4)Colors::Window;
|
||||
break;
|
||||
default:
|
||||
/* Default header color, it seems ? */
|
||||
hoverColor = (ImVec4)ImColor(188, 120, 32);
|
||||
break;
|
||||
ImVec4 hoverColor;
|
||||
switch ((BlockType) blockToPlace) {
|
||||
case BlockType::WALL:
|
||||
hoverColor = (ImVec4) Colors::Wall;
|
||||
break;
|
||||
case BlockType::DOOR:
|
||||
hoverColor = (ImVec4) Colors::Door;
|
||||
break;
|
||||
case BlockType::WINDOW:
|
||||
hoverColor = (ImVec4) Colors::Window;
|
||||
break;
|
||||
default:
|
||||
/* Default header color, it seems ? */
|
||||
hoverColor = (ImVec4) ImColor(188, 120, 32);
|
||||
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();
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue