fix(editor): redo works in all modes, center uses real chunk positions

- Ctrl+Shift+Z redo now works globally (was only in Sculpt mode)
- Ctrl+Z undo works in all modes with toast confirmation
- centerOnTerrain() uses actual mesh chunk positions instead of formula
- Toast shows "Undo" / "Redo" / "Undo placement" for user feedback
This commit is contained in:
Kelsi 2026-05-05 09:00:53 -07:00
parent 66debe9cec
commit 34c06ede4e

View file

@ -261,15 +261,24 @@ void EditorApp::processEvents() {
if (sc == SDL_SCANCODE_O && (event.key.keysym.mod & KMOD_CTRL)) if (sc == SDL_SCANCODE_O && (event.key.keysym.mod & KMOD_CTRL))
ui_.openLoadDialog(); ui_.openLoadDialog();
if (sc == SDL_SCANCODE_Z && (event.key.keysym.mod & KMOD_CTRL)) { if (sc == SDL_SCANCODE_Z && (event.key.keysym.mod & KMOD_CTRL)) {
if (mode_ == EditorMode::Sculpt) { bool isRedo = (event.key.keysym.mod & KMOD_SHIFT) != 0;
if (event.key.keysym.mod & KMOD_SHIFT) if (isRedo) {
// Ctrl+Shift+Z = Redo (sculpt only for now)
if (terrainEditor_.history().canRedo()) {
terrainEditor_.redo(); terrainEditor_.redo();
else showToast("Redo");
}
} else {
// Ctrl+Z = Undo
if (mode_ == EditorMode::PlaceObject || mode_ == EditorMode::NPC) {
if (objectPlacer_.canUndoPlace()) {
objectPlacer_.undoLastPlace();
objectsDirty_ = true;
showToast("Undo placement");
}
} else if (terrainEditor_.history().canUndo()) {
terrainEditor_.undo(); terrainEditor_.undo();
} else if (mode_ == EditorMode::PlaceObject || mode_ == EditorMode::NPC) { showToast("Undo");
if (!(event.key.keysym.mod & KMOD_SHIFT) && objectPlacer_.canUndoPlace()) {
objectPlacer_.undoLastPlace();
objectsDirty_ = true;
} }
} }
} }
@ -909,9 +918,12 @@ void EditorApp::clearAllObjects() {
void EditorApp::centerOnTerrain() { void EditorApp::centerOnTerrain() {
if (!terrain_.isLoaded()) return; if (!terrain_.isLoaded()) return;
float centerX = (32.0f - loadedTileY_) * 533.33333f - 8.0f * 533.33333f / 16.0f; auto mesh = terrainEditor_.regenerateMesh();
float centerY = (32.0f - loadedTileX_) * 533.33333f - 8.0f * 533.33333f / 16.0f; if (mesh.validChunkCount > 0) {
camera_.setPosition(glm::vec3(centerX, centerY, terrain_.chunks[0].position[2] + 300.0f)); float cx = (mesh.chunks[0].worldX + mesh.chunks[255].worldX) * 0.5f;
float cy = (mesh.chunks[0].worldY + mesh.chunks[255].worldY) * 0.5f;
camera_.setPosition(glm::vec3(cx, cy, terrain_.chunks[0].position[2] + 300.0f));
}
camera_.setYawPitch(0.0f, -45.0f); camera_.setYawPitch(0.0f, -45.0f);
showToast("Camera centered on terrain"); showToast("Camera centered on terrain");
} }