fix(editor): Clear All, New Terrain reset, right-click menu, gizmo drag

- Clear All now actually removes all objects and NPCs (was only clearing
  selections before). Uses new ObjectPlacer::clearAll() method.
- New Terrain clears all objects/NPCs and resets viewport before creating
  fresh terrain. Fixes stale state from previous session.
- Right-click context menu works on both objects AND NPCs with
  appropriate options for each (Move/Rotate/Scale for objects,
  Fly To/Duplicate for NPCs)
- Gizmo drag: left-click now confirms the transform (ends drag) instead
  of requiring mouse-up. Right-click cancels. Camera no longer steals
  mouse events while gizmo is active.
- Right-click on unselected area passes through to camera correctly
This commit is contained in:
Kelsi 2026-05-05 05:20:53 -07:00
parent d9ed7be36c
commit befa12f9e6
3 changed files with 64 additions and 30 deletions

View file

@ -281,26 +281,32 @@ void EditorApp::processEvents() {
}
if ((event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) && !io.WantCaptureMouse) {
// Right-click context menu on selected objects
// Right-click on selected objects = context menu
if (event.button.button == SDL_BUTTON_RIGHT && event.type == SDL_MOUSEBUTTONDOWN) {
auto& giz = viewport_.getGizmo();
if (giz.isDragging()) {
giz.endDrag();
giz.setMode(TransformMode::None);
} else if (objectPlacer_.getSelected()) {
} else if (objectPlacer_.getSelected() || npcSpawner_.getSelected()) {
openContextMenu_ = true;
} else {
camera_.processMouseButton(event.button);
}
} else if (event.button.button == SDL_BUTTON_RIGHT && event.type == SDL_MOUSEBUTTONUP) {
if (!objectPlacer_.getSelected() && !npcSpawner_.getSelected())
camera_.processMouseButton(event.button);
} else {
camera_.processMouseButton(event.button);
// Only pass to camera if gizmo not active
auto& giz = viewport_.getGizmo();
if (!giz.isDragging())
camera_.processMouseButton(event.button);
}
// Left click
if (event.button.button == SDL_BUTTON_LEFT && terrain_.isLoaded()) {
// End gizmo drag on click release
auto& giz = viewport_.getGizmo();
if (giz.isDragging() && event.type == SDL_MOUSEBUTTONUP) {
// End gizmo drag on left click
if (giz.isDragging() && event.type == SDL_MOUSEBUTTONDOWN) {
giz.endDrag();
giz.setMode(TransformMode::None);
} else if (event.type == SDL_MOUSEBUTTONDOWN) {
@ -540,6 +546,12 @@ void EditorApp::loadADT(const std::string& mapName, int tileX, int tileY) {
void EditorApp::createNewTerrain(const std::string& mapName, int tileX, int tileY, float baseHeight, Biome biome) {
terrain_ = TerrainEditor::createBlankTerrain(tileX, tileY, baseHeight, biome);
// Clear previous state
objectPlacer_.clearAll();
npcSpawner_.clearSelection();
npcSpawner_.getSpawns().clear();
viewport_.clearObjects();
terrainEditor_.setTerrain(&terrain_);
terrainEditor_.history().clear();
texturePainter_.setTerrain(&terrain_);
@ -552,6 +564,8 @@ void EditorApp::createNewTerrain(const std::string& mapName, int tileX, int tile
loadedMap_ = mapName;
loadedTileX_ = tileX;
loadedTileY_ = tileY;
lastObjectCount_ = 0;
objectsDirty_ = false;
float centerX = (32.0f - tileY) * 533.33333f - 8.0f * 533.33333f / 16.0f;
float centerY = (32.0f - tileX) * 533.33333f - 8.0f * 533.33333f / 16.0f;