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
41
World.cpp
41
World.cpp
|
@ -274,7 +274,7 @@ 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;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -282,27 +282,27 @@ void World::step(const float& stepTime) {
|
||||||
* 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);
|
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hoverColor);
|
||||||
|
@ -310,22 +310,23 @@ void World::step(const float& stepTime) {
|
||||||
ImVec4 blockColor;
|
ImVec4 blockColor;
|
||||||
switch (currentBlock) {
|
switch (currentBlock) {
|
||||||
case BlockType::WALL:
|
case BlockType::WALL:
|
||||||
blockColor = (ImVec4)Colors::Wall;
|
blockColor = (ImVec4) Colors::Wall;
|
||||||
break;
|
break;
|
||||||
case BlockType::DOOR:
|
case BlockType::DOOR:
|
||||||
blockColor = (ImVec4)Colors::Door;
|
blockColor = (ImVec4) Colors::Door;
|
||||||
break;
|
break;
|
||||||
case BlockType::WINDOW:
|
case BlockType::WINDOW:
|
||||||
blockColor = (ImVec4)Colors::Window;
|
blockColor = (ImVec4) Colors::Window;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
blockColor = (ImVec4)ImColor(188, 120, 32);
|
blockColor = (ImVec4) ImColor(188, 120, 32);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ImGui::PushStyleColor(ImGuiCol_Header, blockColor);
|
ImGui::PushStyleColor(ImGuiCol_Header, blockColor);
|
||||||
|
|
||||||
if(ImGui::Selectable("", currentBlock != BlockType::AIR, 0, ImVec2(10, 10))) {
|
if (ImGui::Selectable("", currentBlock != BlockType::AIR, 0, ImVec2(10, 10))) {
|
||||||
map[x + w*y] = currentBlock == (BlockType)blockToPlace ? BlockType::AIR : (BlockType)blockToPlace;
|
map[x + w * y] =
|
||||||
|
currentBlock == (BlockType) blockToPlace ? BlockType::AIR : (BlockType) blockToPlace;
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor(2);
|
ImGui::PopStyleColor(2);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
@ -337,12 +338,12 @@ void World::step(const float& stepTime) {
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
ImGui::Indent();
|
ImGui::Indent();
|
||||||
ImGui::Text("Place :");
|
ImGui::Text("Place :");
|
||||||
ImGui::RadioButton("Wall", &blockToPlace, (int)BlockType::WALL);
|
ImGui::RadioButton("Wall", &blockToPlace, (int) BlockType::WALL);
|
||||||
ImGui::RadioButton("Door", &blockToPlace, (int)BlockType::DOOR);
|
ImGui::RadioButton("Door", &blockToPlace, (int) BlockType::DOOR);
|
||||||
ImGui::RadioButton("Window", &blockToPlace, (int)BlockType::WINDOW);
|
ImGui::RadioButton("Window", &blockToPlace, (int) BlockType::WINDOW);
|
||||||
ImGui::Unindent();
|
ImGui::Unindent();
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue