fix(editor): crater button now click-to-place on terrain

The "Create Crater at Cursor" button used the brush's last hover
position, which was stale by the time the user clicked the button —
the cursor had to move onto the button itself, dragging the brush
position along with it. Result: crater spawned somewhere between
where the user wanted and the button.

New flow: button arms a "click on terrain to place crater" mode
(captures the user's chosen radius/depth/rim at arm time). The next
left-click anywhere on terrain spawns the crater at the actual click
position, regardless of brush state. Button label changes to "ARMED
— click on terrain to place" while waiting, with a Cancel button +
Esc to dismiss.

Misses on terrain leave the mode armed so the user can retry without
re-pressing the button.
This commit is contained in:
Kelsi 2026-05-07 09:34:17 -07:00
parent b35c9341ec
commit 0e2b55f9fd
3 changed files with 64 additions and 4 deletions

View file

@ -1236,10 +1236,25 @@ void EditorUI::renderBrushPanel(EditorApp& app) {
ImGui::SliderFloat("Radius##crater", &craterRadius, 5.0f, 100.0f);
ImGui::SliderFloat("Depth##crater", &craterDepth, 2.0f, 50.0f);
ImGui::SliderFloat("Rim Height##crater", &craterRim, 0.0f, 15.0f);
auto& brush5 = app.getTerrainEditor().brush();
if (ImGui::Button("Create Crater at Cursor", ImVec2(-1, 0)) ) {
app.getTerrainEditor().createCrater(brush5.getPosition(), craterRadius, craterDepth, craterRim);
app.showToast("Crater created");
// Click-to-place: arm pendingCrater so the next left-click on
// terrain spawns the crater there, not at the (stale) brush
// position that was last set before the cursor moved onto the
// button.
auto& pc = app.pendingCrater();
if (pc.active) {
ImGui::TextColored(ImVec4(0.9f, 0.7f, 0.3f, 1),
"ARMED — click on terrain to place");
if (ImGui::Button("Cancel##crater", ImVec2(-1, 0))) {
pc.active = false;
}
} else {
if (ImGui::Button("Click on terrain to place crater", ImVec2(-1, 0))) {
pc.active = true;
pc.radius = craterRadius;
pc.depth = craterDepth;
pc.rim = craterRim;
app.showToast("Click on terrain to place crater (Esc to cancel)");
}
}
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "Bowl with raised rim. Fill with water for a lake.");
}