From e2be89648e202adbf1133ed253ece0e91a6a632a Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 18 Apr 2020 11:15:04 -0300 Subject: [PATCH] Fix #6119: Advertising campaign for ride window not updated properly (#11335) --- distribution/changelog.txt | 1 + src/openrct2-ui/WindowManager.cpp | 6 ++ src/openrct2-ui/windows/NewCampaign.cpp | 61 ++++++++++++--------- src/openrct2-ui/windows/Window.h | 1 + src/openrct2/actions/RideDemolishAction.hpp | 1 + src/openrct2/actions/RideSetName.hpp | 1 + src/openrct2/actions/RideSetStatus.hpp | 5 ++ src/openrct2/windows/Intent.h | 1 + 8 files changed, 52 insertions(+), 25 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index af76c6ac12..75bd4f512a 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -2,6 +2,7 @@ ------------------------------------------------------------------------ - Feature: [#9029] Open doors with the tile inspector. - Feature: [#11231] Change shortcut window list order to be more intuitive, and split it into logical sections. +- Fix: [#6119]: Advertising campaign for ride window not updated properly (original bug). - Fix: [#11072] Land and water tools working out of bounds (original bug). - Fix: [#11315] Ride that has never opened is shown as favorite ride of many guests. - Improved: [#6530] Allow water and land height changes on park borders. diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 6eb5a04f01..869626a465 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -302,6 +302,12 @@ public: window_new_ride_init_vars(); break; + case INTENT_ACTION_REFRESH_CAMPAIGN_RIDE_LIST: + { + WindowCampaignRefreshRides(); + break; + } + case INTENT_ACTION_REFRESH_RIDE_LIST: { auto window = window_find_by_class(WC_RIDE_LIST); diff --git a/src/openrct2-ui/windows/NewCampaign.cpp b/src/openrct2-ui/windows/NewCampaign.cpp index e01b607d6d..981bf0ea52 100644 --- a/src/openrct2-ui/windows/NewCampaign.cpp +++ b/src/openrct2-ui/windows/NewCampaign.cpp @@ -155,31 +155,7 @@ rct_window* window_new_campaign_open(int16_t campaignType) // Currently selected ride w->campaign.ride_id = SELECTED_RIDE_UNDEFINED; - // Get all applicable rides - window_new_campaign_rides.clear(); - for (const auto& ride : GetRideManager()) - { - if (ride.status == RIDE_STATUS_OPEN) - { - if (!ride_type_has_flag( - ride.type, - RIDE_TYPE_FLAG_IS_SHOP | RIDE_TYPE_FLAG_SELLS_FOOD | RIDE_TYPE_FLAG_SELLS_DRINKS - | RIDE_TYPE_FLAG_IS_TOILET)) - { - window_new_campaign_rides.push_back(ride.id); - } - } - } - - // Take top 128 most valuable rides - if (window_new_campaign_rides.size() > DROPDOWN_ITEMS_MAX_SIZE) - { - qsort(window_new_campaign_rides.data(), window_new_campaign_rides.size(), sizeof(ride_id_t), ride_value_compare); - window_new_campaign_rides.resize(DROPDOWN_ITEMS_MAX_SIZE); - } - - // Sort rides by name - qsort(window_new_campaign_rides.data(), window_new_campaign_rides.size(), sizeof(ride_id_t), ride_name_compare); + WindowCampaignRefreshRides(); return w; } @@ -420,3 +396,38 @@ static void window_new_campaign_paint(rct_window* w, rct_drawpixelinfo* dpi) money32 totalPrice = AdvertisingCampaignPricePerWeek[w->campaign.campaign_type] * w->campaign.no_weeks; gfx_draw_string_left(dpi, STR_MARKETING_TOTAL_COST, &totalPrice, COLOUR_BLACK, x, y); } + +void WindowCampaignRefreshRides() +{ + auto window = window_find_by_class(WC_NEW_CAMPAIGN); + if (window == nullptr) + { + return; + } + + // Get all applicable rides + window_new_campaign_rides.clear(); + for (const auto& ride : GetRideManager()) + { + if (ride.status == RIDE_STATUS_OPEN) + { + if (!ride_type_has_flag( + ride.type, + RIDE_TYPE_FLAG_IS_SHOP | RIDE_TYPE_FLAG_SELLS_FOOD | RIDE_TYPE_FLAG_SELLS_DRINKS + | RIDE_TYPE_FLAG_IS_TOILET)) + { + window_new_campaign_rides.push_back(ride.id); + } + } + } + + // Take top 128 most valuable rides + if (window_new_campaign_rides.size() > DROPDOWN_ITEMS_MAX_SIZE) + { + qsort(window_new_campaign_rides.data(), window_new_campaign_rides.size(), sizeof(ride_id_t), ride_value_compare); + window_new_campaign_rides.resize(DROPDOWN_ITEMS_MAX_SIZE); + } + + // Sort rides by name + qsort(window_new_campaign_rides.data(), window_new_campaign_rides.size(), sizeof(ride_id_t), ride_name_compare); +} diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index 9c6953c098..75c7f67d77 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -34,6 +34,7 @@ extern colour_t gWindowSceneryTertiaryColour; extern bool gWindowSceneryEyedropperEnabled; rct_window* window_about_open(); +void WindowCampaignRefreshRides(); rct_window* window_changelog_open(); rct_window* window_cheats_open(); rct_window* window_clear_scenery_open(); diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index fac682348a..9d8d59533d 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -259,6 +259,7 @@ private: // Refresh windows that display the ride name auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_CAMPAIGN_RIDE_LIST)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_RIDE_LIST)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_GUEST_LIST)); diff --git a/src/openrct2/actions/RideSetName.hpp b/src/openrct2/actions/RideSetName.hpp index 9458124209..cfb73dda81 100644 --- a/src/openrct2/actions/RideSetName.hpp +++ b/src/openrct2/actions/RideSetName.hpp @@ -91,6 +91,7 @@ public: // Refresh windows that display ride name auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_CAMPAIGN_RIDE_LIST)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_RIDE_LIST)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_GUEST_LIST)); diff --git a/src/openrct2/actions/RideSetStatus.hpp b/src/openrct2/actions/RideSetStatus.hpp index 55632896eb..2d6a5e61d8 100644 --- a/src/openrct2/actions/RideSetStatus.hpp +++ b/src/openrct2/actions/RideSetStatus.hpp @@ -17,6 +17,8 @@ #include "../localisation/StringIds.h" #include "../management/Finance.h" #include "../ride/Ride.h" +#include "../ui/UiContext.h" +#include "../ui/WindowManager.h" #include "../world/Park.h" #include "../world/Sprite.h" #include "GameAction.h" @@ -219,6 +221,9 @@ public: Guard::Assert(false, "Invalid status passed: %u", _status); break; } + auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_CAMPAIGN_RIDE_LIST)); + return res; } }; diff --git a/src/openrct2/windows/Intent.h b/src/openrct2/windows/Intent.h index 37887065e0..9f09f3cdfb 100644 --- a/src/openrct2/windows/Intent.h +++ b/src/openrct2/windows/Intent.h @@ -80,6 +80,7 @@ enum { INTENT_ACTION_MAP, INTENT_ACTION_NEW_RIDE_OF_TYPE, + INTENT_ACTION_REFRESH_CAMPAIGN_RIDE_LIST, INTENT_ACTION_REFRESH_NEW_RIDES, INTENT_ACTION_REFRESH_RIDE_LIST, INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION,