From 15fcbf5463f3747b89b90999609089fcda7e8791 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 9 Jun 2021 14:05:00 +0200 Subject: [PATCH 1/2] Remove some usages of gGameCommandErrorMessage in Editor --- .../windows/EditorBottomToolbar.cpp | 9 ++--- src/openrct2/Editor.cpp | 35 +++++++------------ src/openrct2/Editor.h | 4 +-- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/openrct2-ui/windows/EditorBottomToolbar.cpp b/src/openrct2-ui/windows/EditorBottomToolbar.cpp index 9ef4fee7ea..6f25b93e43 100644 --- a/src/openrct2-ui/windows/EditorBottomToolbar.cpp +++ b/src/openrct2-ui/windows/EditorBottomToolbar.cpp @@ -176,14 +176,14 @@ static bool window_editor_bottom_toolbar_check_object_selection() { rct_window* w; - ObjectType missingObjectType = Editor::CheckObjectSelection(); + auto [missingObjectType, errorString] = Editor::CheckObjectSelection(); if (missingObjectType == ObjectType::None) { window_close_by_class(WC_EDITOR_OBJECT_SELECTION); return true; } - context_show_error(STR_INVALID_SELECTION_OF_OBJECTS, gGameCommandErrorText, {}); + context_show_error(STR_INVALID_SELECTION_OF_OBJECTS, errorString, {}); w = window_find_by_class(WC_EDITOR_OBJECT_SELECTION); if (w != nullptr) { @@ -219,7 +219,8 @@ void window_editor_bottom_toolbar_jump_forward_from_object_selection() */ void window_editor_bottom_toolbar_jump_forward_to_invention_list_set_up() { - if (Editor::CheckPark()) + auto [checksPassed, errorString] = Editor::CheckPark(); + if (checksPassed) { window_close_all(); context_open_window(WC_EDITOR_INVENTION_LIST); @@ -227,7 +228,7 @@ void window_editor_bottom_toolbar_jump_forward_to_invention_list_set_up() } else { - context_show_error(STR_CANT_ADVANCE_TO_NEXT_EDITOR_STAGE, gGameCommandErrorText, {}); + context_show_error(STR_CANT_ADVANCE_TO_NEXT_EDITOR_STAGE, errorString, {}); } gfx_invalidate_screen(); diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 11a55f0e15..fb778c1453 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -453,7 +453,7 @@ namespace Editor * * rct2: 0x006AB9B8 */ - ObjectType CheckObjectSelection() + std::pair CheckObjectSelection() { bool isTrackDesignerManager = gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER); @@ -461,52 +461,46 @@ namespace Editor { if (!editor_check_object_group_at_least_one_selected(ObjectType::Paths)) { - gGameCommandErrorText = STR_AT_LEAST_ONE_PATH_OBJECT_MUST_BE_SELECTED; - return ObjectType::Paths; + return { ObjectType::Paths, STR_AT_LEAST_ONE_PATH_OBJECT_MUST_BE_SELECTED }; } } if (!editor_check_object_group_at_least_one_selected(ObjectType::Ride)) { - gGameCommandErrorText = STR_AT_LEAST_ONE_RIDE_OBJECT_MUST_BE_SELECTED; - return ObjectType::Ride; + return { ObjectType::Ride, STR_AT_LEAST_ONE_RIDE_OBJECT_MUST_BE_SELECTED }; } if (!isTrackDesignerManager) { if (!editor_check_object_group_at_least_one_selected(ObjectType::ParkEntrance)) { - gGameCommandErrorText = STR_PARK_ENTRANCE_TYPE_MUST_BE_SELECTED; - return ObjectType::ParkEntrance; + return { ObjectType::ParkEntrance, STR_PARK_ENTRANCE_TYPE_MUST_BE_SELECTED }; } if (!editor_check_object_group_at_least_one_selected(ObjectType::Water)) { - gGameCommandErrorText = STR_WATER_TYPE_MUST_BE_SELECTED; - return ObjectType::Water; + return { ObjectType::Water, STR_WATER_TYPE_MUST_BE_SELECTED }; } } - return ObjectType::None; + return { ObjectType::None, STR_NONE }; } /** * * rct2: 0x0066FEAC */ - bool CheckPark() + std::pair CheckPark() { int32_t parkSize = park_calculate_size(); if (parkSize == 0) { - gGameCommandErrorText = STR_PARK_MUST_OWN_SOME_LAND; - return false; + return { false, STR_PARK_MUST_OWN_SOME_LAND }; } if (gParkEntrances.empty()) { - gGameCommandErrorText = STR_NO_PARK_ENTRANCES; - return false; + return { false, STR_NO_PARK_ENTRANCES }; } for (const auto& parkEntrance : gParkEntrances) @@ -516,12 +510,10 @@ namespace Editor switch (footpath_is_connected_to_map_edge(parkEntrance, direction, 0)) { case FOOTPATH_SEARCH_NOT_FOUND: - gGameCommandErrorText = STR_PARK_ENTRANCE_WRONG_DIRECTION_OR_NO_PATH; - return false; + return { false, STR_PARK_ENTRANCE_WRONG_DIRECTION_OR_NO_PATH }; case FOOTPATH_SEARCH_INCOMPLETE: case FOOTPATH_SEARCH_TOO_COMPLEX: - gGameCommandErrorText = STR_PARK_ENTRANCE_PATH_INCOMPLETE_OR_COMPLEX; - return false; + return { false, STR_PARK_ENTRANCE_PATH_INCOMPLETE_OR_COMPLEX }; case FOOTPATH_SEARCH_SUCCESS: // Run the search again and unown the path footpath_is_connected_to_map_edge(parkEntrance, direction, (1 << 5)); @@ -531,11 +523,10 @@ namespace Editor if (gPeepSpawns.empty()) { - gGameCommandErrorText = STR_PEEP_SPAWNS_NOT_SET; - return false; + return { false, STR_PEEP_SPAWNS_NOT_SET }; } - return true; + return { true, STR_NONE }; } uint8_t GetSelectedObjectFlags(ObjectType objectType, size_t index) diff --git a/src/openrct2/Editor.h b/src/openrct2/Editor.h index 3faf90f33b..cc617791b0 100644 --- a/src/openrct2/Editor.h +++ b/src/openrct2/Editor.h @@ -21,8 +21,8 @@ namespace Editor void LoadTrackManager(); bool LoadLandscape(const utf8* path); - bool CheckPark(); - ObjectType CheckObjectSelection(); + std::pair CheckPark(); + std::pair CheckObjectSelection(); void OpenWindowsForCurrentStep(); From 2da64715cc10a9cabbb768aa9a69121eee89dfe8 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 9 Jun 2021 17:55:23 +0200 Subject: [PATCH 2/2] Directly call MapCanConstructWithClearAt() --- src/openrct2/actions/FootpathPlaceAction.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.cpp b/src/openrct2/actions/FootpathPlaceAction.cpp index 2662388e1d..be84fabf90 100644 --- a/src/openrct2/actions/FootpathPlaceAction.cpp +++ b/src/openrct2/actions/FootpathPlaceAction.cpp @@ -313,14 +313,14 @@ GameActions::Result::Ptr FootpathPlaceAction::ElementInsertExecute(GameActions:: uint8_t crossingMode = (_type & FOOTPATH_ELEMENT_INSERT_QUEUE) || (_slope != TILE_ELEMENT_SLOPE_FLAT) ? CREATE_CROSSING_MODE_NONE : CREATE_CROSSING_MODE_PATH_OVER_TRACK; - if (!entrancePath - && !map_can_construct_with_clear_at( - { _loc, zLow, zHigh }, &map_place_non_scenery_clear_func, quarterTile, GAME_COMMAND_FLAG_APPLY | GetFlags(), - &res->Cost, crossingMode)) + auto canBuild = MapCanConstructWithClearAt( + { _loc, zLow, zHigh }, &map_place_non_scenery_clear_func, quarterTile, GAME_COMMAND_FLAG_APPLY | GetFlags(), + crossingMode); + if (!entrancePath && canBuild->Error != GameActions::Status::Ok) { - return MakeResult( - GameActions::Status::NoClearance, STR_CANT_BUILD_FOOTPATH_HERE, gGameCommandErrorText, gCommonFormatArgs); + return canBuild; } + res->Cost += canBuild->Cost; gFootpathGroundFlags = gMapGroundFlags;