Furniture vertical offset

This commit is contained in:
2026-04-16 17:11:12 +03:00
parent 863c401230
commit 79b6af1fff
5 changed files with 38 additions and 3 deletions

View File

@@ -209,6 +209,7 @@ struct RoomComponent {
bool createWindows = false; // Convert exterior-facing walls to windows
bool fillRoomWithFurniture = false; // Automatically place furniture based on tags
unsigned int furnitureSeed = 42; // Seed for deterministic furniture placement
float furnitureYOffset = 0.05f; // Y offset for all furniture in this room
// Dirty flag - triggers regeneration of cell grid
bool dirty = true;

View File

@@ -2389,8 +2389,20 @@ void CellGridSystem::buildFurniture(flecs::entity entity,
Ogre::Vector3 pos = grid.cellToWorld(fcell.x, fcell.y,
fcell.z);
// Apply small Y offset so furniture sits on floor
pos.y += 0.05f;
// Determine Y offset from the room that contains this furniture cell
float furnitureYOffset = 0.05f;
bool foundRoom = false;
entity.children([&](flecs::entity child) {
if (foundRoom) return;
if (child.has<RoomComponent>()) {
const auto &room = child.get<RoomComponent>();
if (room.contains(fcell.x, fcell.y, fcell.z)) {
furnitureYOffset = room.furnitureYOffset;
foundRoom = true;
}
}
});
pos.y += furnitureYOffset;
Ogre::Quaternion localRot(
Ogre::Degree(90.0f * fcell.rotation),
Ogre::Vector3::UNIT_Y);

View File

@@ -223,7 +223,8 @@ void EditorUISystem::renderHierarchyWindow()
ImGuiWindowFlags windowFlags =
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_MenuBar;
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_HorizontalScrollbar;
if (ImGui::Begin("Entity Hierarchy", nullptr, windowFlags)) {
// Menu bar

View File

@@ -1409,6 +1409,7 @@ nlohmann::json SceneSerializer::serializeRoom(flecs::entity entity)
json["createWindows"] = room.createWindows;
json["fillRoomWithFurniture"] = room.fillRoomWithFurniture;
json["furnitureSeed"] = room.furnitureSeed;
json["furnitureYOffset"] = room.furnitureYOffset;
// Serialize exits (bool array for Z-, Z+, X-, X+)
nlohmann::json exits = nlohmann::json::array();
@@ -1662,6 +1663,7 @@ void SceneSerializer::deserializeRoom(flecs::entity entity, const nlohmann::json
room.createWindows = json.value("createWindows", false);
room.fillRoomWithFurniture = json.value("fillRoomWithFurniture", false);
room.furnitureSeed = json.value("furnitureSeed", 42u);
room.furnitureYOffset = json.value("furnitureYOffset", 0.05f);
// Load exits (bool array for Z-, Z+, X-, X+)
if (json.contains("exits") && json["exits"].is_array()) {

View File

@@ -50,6 +50,9 @@ bool RoomEditor::renderComponent(flecs::entity entity, RoomComponent& room)
room.furnitureSeed = static_cast<unsigned int>(seed);
modified = true;
}
if (ImGui::DragFloat("Furniture Y Offset", &room.furnitureYOffset, 0.01f, 0.0f, 0.5f)) {
modified = true;
}
ImGui::TextDisabled("Change seed for different furniture arrangement");
ImGui::TextDisabled("(Windows are created after all doors)");
@@ -196,6 +199,8 @@ bool RoomEditor::renderComponent(flecs::entity entity, RoomComponent& room)
// List current connections with remove buttons
int removeIndex = -1;
float contentRight = ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x;
float maxRowRight = 0.0f;
for (size_t i = 0; i < room.connectedRoomIds.size(); i++) {
const std::string& connectedId = room.connectedRoomIds[i];
ImGui::PushID((int)i);
@@ -224,9 +229,23 @@ bool RoomEditor::renderComponent(flecs::entity entity, RoomComponent& room)
removeIndex = (int)i;
modified = true;
}
maxRowRight = std::max(maxRowRight,
ImGui::GetItemRectMax().x - ImGui::GetWindowPos().x);
ImGui::PopID();
}
/* Ensure the horizontal scrollbar thumb appears when connection
* rows overflow the panel width. ImGui culls off-screen widgets,
* so we explicitly extend the content width with a dummy. */
float savedX = ImGui::GetCursorPosX();
float savedY = ImGui::GetCursorPosY();
if (maxRowRight > contentRight) {
ImGui::SetCursorPosX(0.0f);
ImGui::Dummy(ImVec2(maxRowRight + 1.0f, 0.0f));
ImGui::SetCursorPos(ImVec2(savedX, savedY));
}
if (removeIndex >= 0) {
// Remove from this room
std::string removedId = room.connectedRoomIds[removeIndex];