From 06eb4484458c2dc2dc3c3b03307713b985358f6a Mon Sep 17 00:00:00 2001 From: frozensnowy Date: Sun, 29 Mar 2026 00:40:42 +0100 Subject: [PATCH] Fix #25927: Wall drag tool error sound stacks and shows wrong cost (#25929) Query all tiles before execution to calculate total cost and detect errors upfront. Show a single combined error with the accumulated total cost instead of per tile errors with stacking sounds --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Scenery.cpp | 60 ++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index f22b3b047c..1ece36a74c 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -11,6 +11,7 @@ - Fix: [#25735] Ride synchronisation z-check works incorrectly. - Fix: [#25919] Path drag tool error sound stacks when placement fails. - Fix: [#25926] Path drag tool shows cost for single tile instead of total. +- Fix: [#25927] Wall drag tool error sound stacks and shows wrong cost. - Fix: [#25962] Dropdown triangle glyphs are not optically centred. - Fix: [#25993] Toggling “allow arbitrary ride type changes” does not resize open ride windows. - Fix: [#26111] Vehicle colours tab can go out of bounds in certain edge cases. diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 4f5a6348ff..7bb9db0efd 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -3243,15 +3243,64 @@ namespace OpenRCT2::Ui::Windows } auto mapRange = getMapSelectRange(); - bool anySuccessful = false; CoordsXYZ lastLocation = { mapRange.Point2, gSceneryPlaceZ }; + auto& gameState = getGameState(); + + // First query all tiles to get total cost and check for errors + money64 totalCost = 0; + GameActions::Result lastError; + bool anyQueryFailed = false; + + for (const auto& tile : _provisionalTiles) + { + auto wallPlaceAction = GameActions::WallPlaceAction( + selectedScenery, tile.location, tile.location.direction, _sceneryPrimaryColour, _scenerySecondaryColour, + _sceneryTertiaryColour); + + auto result = GameActions::Query(&wallPlaceAction, gameState); + totalCost += result.cost; + if (result.error != GameActions::Status::ok) + { + anyQueryFailed = true; + lastError = result; + } + } + + // If any query failed, show a single combined error with total cost + if (anyQueryFailed) + { + Audio::Play3D(Audio::SoundId::error, lastLocation); + + // Show error with accumulated cost for insufficient funds + auto* windowMgr = GetWindowManager(); + if (lastError.error == GameActions::Status::insufficientFunds) + { + Formatter ft; + ft.Add(totalCost); + windowMgr->ShowError(STR_CANT_BUILD_THIS_HERE, STR_NOT_ENOUGH_CASH_REQUIRES, ft); + } + else + { + windowMgr->ShowError(lastError.getErrorTitle(), lastError.getErrorMessage()); + } + + _provisionalTiles.clear(); + _inDragMode = false; + return; + } + + // All queries passed, now execute + bool anySuccessful = false; + + // Disable error sound during loop to prevent stacking sounds for each failed tile + gDisableErrorWindowSound = true; + for (const auto& tile : _provisionalTiles) { auto wallPlaceAction = GameActions::WallPlaceAction( selectedScenery, tile.location, tile.location.direction, _sceneryPrimaryColour, _scenerySecondaryColour, _sceneryTertiaryColour); - auto& gameState = getGameState(); auto result = GameActions::Execute(&wallPlaceAction, gameState); if (result.error == GameActions::Status::ok) { @@ -3260,6 +3309,8 @@ namespace OpenRCT2::Ui::Windows } } + gDisableErrorWindowSound = false; + _provisionalTiles.clear(); _inDragMode = false; @@ -3267,6 +3318,11 @@ namespace OpenRCT2::Ui::Windows { Audio::Play3D(Audio::SoundId::placeItem, lastLocation); } + else + { + // Play error sound once for the entire failed operation + Audio::Play3D(Audio::SoundId::error, lastLocation); + } } void onToolDownLargeScenery(WidgetIndex widgetIndex, const ScreenCoordsXY& screenCoords, uint16_t selectedScenery)