From 864415d2469de42e236793c721da2bb8981876b7 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 5 May 2026 05:29:30 -0700 Subject: [PATCH] feat(editor): auto-load objects/NPCs, mode buttons, number key shortcuts - Loading an ADT now auto-loads objects.json and creatures.json from the output directory if they exist (full session persistence) - Toolbar buttons now highlight active mode in blue (clearer visual) - Number keys 1-5 switch modes: 1=Sculpt 2=Paint 3=Objects 4=Water 5=NPCs - Toast shows loaded object/NPC count on zone open --- tools/editor/editor_app.cpp | 17 +++++++++++++++++ tools/editor/editor_ui.cpp | 35 ++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/tools/editor/editor_app.cpp b/tools/editor/editor_app.cpp index 00748713..c8957452 100644 --- a/tools/editor/editor_app.cpp +++ b/tools/editor/editor_app.cpp @@ -206,6 +206,14 @@ void EditorApp::processEvents() { auto sc = event.key.keysym.scancode; if (sc == SDL_SCANCODE_F3) setWireframe(!isWireframe()); if (sc == SDL_SCANCODE_F5) saveBookmark(""); + // Number keys switch modes (when not typing in ImGui) + if (!io.WantCaptureKeyboard) { + if (sc == SDL_SCANCODE_1) setMode(EditorMode::Sculpt); + if (sc == SDL_SCANCODE_2) setMode(EditorMode::Paint); + if (sc == SDL_SCANCODE_3) setMode(EditorMode::PlaceObject); + if (sc == SDL_SCANCODE_4) setMode(EditorMode::Water); + if (sc == SDL_SCANCODE_5) setMode(EditorMode::NPC); + } // F1 handled by UI (showHelp_ toggle) // Transform shortcuts (Blender-style) if (objectPlacer_.getSelected()) { @@ -542,6 +550,15 @@ void EditorApp::loadADT(const std::string& mapName, int tileX, int tileY) { camera_.setYawPitch(0.0f, -45.0f); LOG_INFO("ADT loaded: ", mapName, " [", tileX, ",", tileY, "]"); + + // Try loading objects/NPCs from output directory if they exist + std::string outBase = "output/" + mapName; + if (objectPlacer_.loadFromFile(outBase + "/objects.json")) + showToast("Loaded " + std::to_string(objectPlacer_.objectCount()) + " objects"); + if (npcSpawner_.loadFromFile(outBase + "/creatures.json")) + showToast("Loaded " + std::to_string(npcSpawner_.spawnCount()) + " NPCs"); + if (objectPlacer_.objectCount() > 0 || npcSpawner_.spawnCount() > 0) + objectsDirty_ = true; } void EditorApp::createNewTerrain(const std::string& mapName, int tileX, int tileY, float baseHeight, Biome biome) { diff --git a/tools/editor/editor_ui.cpp b/tools/editor/editor_ui.cpp index f217cb88..eee90b9c 100644 --- a/tools/editor/editor_ui.cpp +++ b/tools/editor/editor_ui.cpp @@ -212,26 +212,31 @@ void EditorUI::renderMenuBar(EditorApp& app) { void EditorUI::renderToolbar(EditorApp& app) { ImGui::SetNextWindowPos(ImVec2(300, 30), ImGuiCond_FirstUseEver); - ImGui::SetNextWindowSize(ImVec2(400, 50), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(500, 50), ImGuiCond_FirstUseEver); ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8, 8)); if (ImGui::Begin("##Toolbar", nullptr, flags)) { auto mode = app.getMode(); - if (ImGui::RadioButton("Sculpt", mode == EditorMode::Sculpt)) - app.setMode(EditorMode::Sculpt); - ImGui::SameLine(); - if (ImGui::RadioButton("Paint", mode == EditorMode::Paint)) - app.setMode(EditorMode::Paint); - ImGui::SameLine(); - if (ImGui::RadioButton("Objects", mode == EditorMode::PlaceObject)) - app.setMode(EditorMode::PlaceObject); - ImGui::SameLine(); - if (ImGui::RadioButton("Water", mode == EditorMode::Water)) - app.setMode(EditorMode::Water); - ImGui::SameLine(); - if (ImGui::RadioButton("NPCs", mode == EditorMode::NPC)) - app.setMode(EditorMode::NPC); + + auto modeButton = [&](const char* label, EditorMode m) { + bool active = (mode == m); + if (active) { + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.3f, 0.6f, 0.9f, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 1)); + } + if (ImGui::Button(label, ImVec2(70, 28))) + app.setMode(m); + if (active) + ImGui::PopStyleColor(2); + ImGui::SameLine(); + }; + + modeButton("Sculpt", EditorMode::Sculpt); + modeButton("Paint", EditorMode::Paint); + modeButton("Objects", EditorMode::PlaceObject); + modeButton("Water", EditorMode::Water); + modeButton("NPCs", EditorMode::NPC); } ImGui::End(); ImGui::PopStyleVar();