2014-08-11 02:09:17 +02:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2014-08-11 02:09:17 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2014-08-11 02:09:17 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-08-11 02:09:17 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-08-12 13:50:40 +02:00
|
|
|
#include <algorithm>
|
2018-06-22 23:21:44 +02:00
|
|
|
#include <openrct2-ui/interface/Dropdown.h>
|
|
|
|
#include <openrct2-ui/interface/Widget.h>
|
|
|
|
#include <openrct2-ui/windows/Window.h>
|
|
|
|
#include <openrct2/Game.h>
|
Split actions hpp files into separate h and cpp files (#13548)
* Split up SmallSceneryPlace/Remove
Added undo function for Remove Scenery
* Refactor: Balloon and Banner actions hpp=>h/cpp
* Refactor: rename all action *.hpp files to *.cpp
This is preparation for separation in later commits. Note that without
the complete set of commits in this branch, the code will not build.
* Refactor Clear, Climate, Custom, and Footpath actions hpp=>h/cpp
* VSCode: add src subdirectories to includePath
* Refactor Guest actions hpp=>h/cpp
* Refactor Land actions hpp=>h/cpp
* Refactor LargeScenery actions hpp=>h/cpp
* Refactor Load, Maze, Network actions hpp=>h/cpp
* Refactor Park actions hpp=>h/cpp
* Refactor/style: move private function declarations in actions *.h
Previous action .h files included private function declarations with
private member variables, before public function declarations. This
commit re-orders the header files to the following order:
- public member variables
- private member variables
- public functions
- private functions
* Refactor Pause action hpp=>h/cpp
* Refactor Peep, Place, Player actions hpp=>h/cpp
* Refactor Ride actions hpp=>h/cpp
* Refactor Scenario, Set*, Sign* actions hpp=>h/cpp
* Refactor SmallScenerySetColourAction hpp=>h/cpp
* Refactor Staff actions hpp=>h/cpp
* Refactor Surface, Tile, Track* actions hpp=>h/cpp
* Refactor Wall and Water actions hpp=>h/cpp
* Fix various includes and other compile errors
Update includes for tests.
Move static function declarations to .h files
Add explicit includes to various files that were previously implicit
(the required header was a nested include in an action hpp file, and the
action .h file does not include that header)
Move RideSetStatus string enum to the cpp file to avoid unused imports
* Xcode: modify project file for actions refactor
* Cleanup whitespace and end-of-file newlines
Co-authored-by: duncanspumpkin <duncans_pumpkin@hotmail.co.uk>
2020-12-10 07:39:10 +01:00
|
|
|
#include <openrct2/actions/ParkMarketingAction.h>
|
2017-09-06 16:09:35 +02:00
|
|
|
#include <openrct2/config/Config.h>
|
2018-05-14 19:21:43 +02:00
|
|
|
#include <openrct2/drawing/Drawing.h>
|
2018-01-06 18:32:25 +01:00
|
|
|
#include <openrct2/localisation/Localisation.h>
|
2017-12-31 13:21:34 +01:00
|
|
|
#include <openrct2/ride/Ride.h>
|
2018-01-10 00:00:09 +01:00
|
|
|
#include <openrct2/ride/RideData.h>
|
2018-05-14 19:21:43 +02:00
|
|
|
#include <openrct2/ride/ShopItem.h>
|
2014-08-12 01:27:25 +02:00
|
|
|
|
2020-05-09 18:02:16 +02:00
|
|
|
static constexpr const rct_string_id WINDOW_TITLE = STR_NONE;
|
2020-07-30 21:54:17 +02:00
|
|
|
static constexpr const int32_t WH = 109;
|
2020-05-05 22:26:14 +02:00
|
|
|
static constexpr const int32_t WW = 350;
|
2019-10-24 05:38:13 +02:00
|
|
|
constexpr uint16_t SELECTED_RIDE_UNDEFINED = 0xFFFF;
|
2014-08-12 01:27:25 +02:00
|
|
|
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format off
|
2014-08-12 01:27:25 +02:00
|
|
|
enum WINDOW_NEW_CAMPAIGN_WIDGET_IDX {
|
2017-06-06 23:24:18 +02:00
|
|
|
WIDX_BACKGROUND,
|
|
|
|
WIDX_TITLE,
|
|
|
|
WIDX_CLOSE,
|
|
|
|
WIDX_RIDE_LABEL,
|
|
|
|
WIDX_RIDE_DROPDOWN,
|
|
|
|
WIDX_RIDE_DROPDOWN_BUTTON,
|
|
|
|
WIDX_WEEKS_LABEL,
|
|
|
|
WIDX_WEEKS_SPINNER,
|
|
|
|
WIDX_WEEKS_INCREASE_BUTTON,
|
|
|
|
WIDX_WEEKS_DECREASE_BUTTON,
|
|
|
|
WIDX_START_BUTTON
|
2014-08-12 01:27:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_new_campaign_widgets[] = {
|
2020-05-09 16:44:21 +02:00
|
|
|
WINDOW_SHIM(WINDOW_TITLE, WW, WH),
|
2020-11-27 04:14:20 +01:00
|
|
|
MakeWidget ({ 14, 24}, {126, 12}, WindowWidgetType::Label, WindowColour::Primary, STR_EMPTY ), // ride label
|
|
|
|
MakeWidget ({100, 24}, {242, 12}, WindowWidgetType::DropdownMenu, WindowColour::Primary, STR_EMPTY ), // ride dropdown
|
|
|
|
MakeWidget ({330, 25}, { 11, 10}, WindowWidgetType::Button, WindowColour::Primary, STR_DROPDOWN_GLYPH ), // ride dropdown button
|
|
|
|
MakeWidget ({ 14, 41}, {126, 14}, WindowWidgetType::Label, WindowColour::Primary, STR_LENGTH_OF_TIME ), // weeks label
|
|
|
|
MakeSpinnerWidgets({120, 41}, {100, 14}, WindowWidgetType::Spinner, WindowColour::Primary, STR_EMPTY ), // weeks (3 widgets)
|
|
|
|
MakeWidget ({ 14, 89}, {322, 14}, WindowWidgetType::Button, WindowColour::Primary, STR_MARKETING_START_THIS_MARKETING_CAMPAIGN), // start button
|
2017-06-06 23:24:18 +02:00
|
|
|
{ WIDGETS_END }
|
2014-08-12 01:27:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-01 15:41:45 +02:00
|
|
|
static void window_new_campaign_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
2017-07-03 23:09:46 +02:00
|
|
|
static void window_new_campaign_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget* widget);
|
2018-06-20 17:28:51 +02:00
|
|
|
static void window_new_campaign_dropdown(rct_window *w, rct_widgetindex widgetIndex, int32_t dropdownIndex);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_new_campaign_invalidate(rct_window *w);
|
|
|
|
static void window_new_campaign_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2014-08-12 01:27:25 +02:00
|
|
|
|
2020-09-28 20:36:15 +02:00
|
|
|
static rct_window_event_list window_new_campaign_events([](auto& events)
|
|
|
|
{
|
|
|
|
events.mouse_up = &window_new_campaign_mouseup;
|
|
|
|
events.mouse_down = &window_new_campaign_mousedown;
|
|
|
|
events.dropdown = &window_new_campaign_dropdown;
|
|
|
|
events.invalidate = &window_new_campaign_invalidate;
|
|
|
|
events.paint = &window_new_campaign_paint;
|
|
|
|
});
|
2018-05-16 20:41:29 +02:00
|
|
|
// clang-format on
|
2014-08-12 01:27:25 +02:00
|
|
|
|
2019-08-03 18:27:50 +02:00
|
|
|
static std::vector<ride_id_t> window_new_campaign_rides;
|
2018-06-20 17:28:51 +02:00
|
|
|
static uint8_t window_new_campaign_shop_items[64];
|
2014-08-12 01:27:25 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static int32_t ride_value_compare(const void* a, const void* b)
|
2014-08-12 01:27:25 +02:00
|
|
|
{
|
2019-08-09 09:06:25 +02:00
|
|
|
auto valueA = 0;
|
2020-04-18 13:32:48 +02:00
|
|
|
auto rideA = get_ride(*(static_cast<const uint8_t*>(a)));
|
2019-08-09 09:06:25 +02:00
|
|
|
if (rideA != nullptr)
|
|
|
|
valueA = rideA->value;
|
|
|
|
|
|
|
|
auto valueB = 0;
|
2020-04-18 13:32:48 +02:00
|
|
|
auto rideB = get_ride(*(static_cast<const uint8_t*>(b)));
|
2019-08-09 09:06:25 +02:00
|
|
|
if (rideB != nullptr)
|
|
|
|
valueB = rideB->value;
|
2014-08-12 01:27:25 +02:00
|
|
|
|
2019-08-09 09:06:25 +02:00
|
|
|
return valueB - valueA;
|
2014-08-12 01:27:25 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
static int32_t ride_name_compare(const void* a, const void* b)
|
2014-08-12 01:27:25 +02:00
|
|
|
{
|
2019-08-09 09:06:25 +02:00
|
|
|
std::string rideAName;
|
2020-04-18 13:32:48 +02:00
|
|
|
auto rideA = get_ride(*(static_cast<const uint8_t*>(a)));
|
2019-08-09 09:06:25 +02:00
|
|
|
if (rideA != nullptr)
|
|
|
|
rideAName = rideA->GetName();
|
|
|
|
|
|
|
|
std::string rideBName;
|
2020-04-18 13:32:48 +02:00
|
|
|
auto rideB = get_ride(*(static_cast<const uint8_t*>(b)));
|
2019-08-09 09:06:25 +02:00
|
|
|
if (rideB != nullptr)
|
|
|
|
rideBName = rideB->GetName();
|
|
|
|
|
2019-07-21 02:28:33 +02:00
|
|
|
return _strcmpi(rideAName.c_str(), rideBName.c_str());
|
2014-08-12 01:27:25 +02:00
|
|
|
}
|
2014-08-11 02:09:17 +02:00
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-08-11 02:09:17 +02:00
|
|
|
* rct2: 0x0069E16F
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_window* window_new_campaign_open(int16_t campaignType)
|
2014-08-11 02:09:17 +02:00
|
|
|
{
|
2019-08-03 18:27:50 +02:00
|
|
|
auto w = window_bring_to_front_by_class(WC_NEW_CAMPAIGN);
|
2018-06-22 23:21:44 +02:00
|
|
|
if (w != nullptr)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
if (w->campaign.campaign_type == campaignType)
|
2017-09-06 16:09:35 +02:00
|
|
|
return w;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window_close(w);
|
|
|
|
}
|
|
|
|
|
2020-11-04 05:52:23 +01:00
|
|
|
w = WindowCreateAutoPos(WW, WH, &window_new_campaign_events, WC_NEW_CAMPAIGN, 0);
|
2017-06-06 23:24:18 +02:00
|
|
|
w->widgets = window_new_campaign_widgets;
|
2018-06-22 23:21:44 +02:00
|
|
|
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RIDE_DROPDOWN) | (1 << WIDX_RIDE_DROPDOWN_BUTTON)
|
|
|
|
| (1 << WIDX_WEEKS_INCREASE_BUTTON) | (1 << WIDX_WEEKS_DECREASE_BUTTON) | (1 << WIDX_START_BUTTON);
|
|
|
|
w->hold_down_widgets = (1 << WIDX_WEEKS_INCREASE_BUTTON) | (1 << WIDX_WEEKS_DECREASE_BUTTON);
|
2020-11-04 05:52:23 +01:00
|
|
|
WindowInitScrollWidgets(w);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
window_new_campaign_widgets[WIDX_TITLE].text = MarketingCampaignNames[campaignType][0];
|
|
|
|
|
|
|
|
// Campaign type
|
|
|
|
w->campaign.campaign_type = campaignType;
|
|
|
|
|
|
|
|
// Number of weeks
|
|
|
|
w->campaign.no_weeks = 2;
|
|
|
|
|
|
|
|
// Currently selected ride
|
2020-07-29 10:44:38 +02:00
|
|
|
w->campaign.RideId = SELECTED_RIDE_UNDEFINED;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-04-18 16:15:04 +02:00
|
|
|
WindowCampaignRefreshRides();
|
2017-09-06 16:09:35 +02:00
|
|
|
return w;
|
2014-08-12 01:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-08-12 01:27:25 +02:00
|
|
|
* rct2: 0x0069E320
|
|
|
|
*/
|
|
|
|
static void window_new_campaign_get_shop_items()
|
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
uint64_t items = 0;
|
2019-08-04 17:00:15 +02:00
|
|
|
for (auto& ride : GetRideManager())
|
2017-12-04 08:54:32 +01:00
|
|
|
{
|
2019-08-04 17:00:15 +02:00
|
|
|
auto rideEntry = ride.GetRideEntry();
|
|
|
|
if (rideEntry != nullptr)
|
2017-12-04 08:54:32 +01:00
|
|
|
{
|
2020-07-29 00:08:16 +02:00
|
|
|
for (const auto itemType : rideEntry->shop_item)
|
2019-08-04 17:00:15 +02:00
|
|
|
{
|
2020-12-04 01:15:59 +01:00
|
|
|
if (itemType != ShopItem::None && GetShopItemDescriptor(itemType).IsFoodOrDrink())
|
2020-07-29 00:08:16 +02:00
|
|
|
{
|
2020-12-04 01:15:59 +01:00
|
|
|
items |= EnumToFlag(itemType);
|
2020-07-29 00:08:16 +02:00
|
|
|
}
|
2019-08-04 17:00:15 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-08-04 17:00:15 +02:00
|
|
|
auto numItems = 0;
|
|
|
|
for (auto i = 0; i < 64; i++)
|
2017-06-14 15:08:56 +02:00
|
|
|
{
|
2017-12-04 08:54:32 +01:00
|
|
|
if (items & (1ULL << i))
|
2017-06-14 15:08:56 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
window_new_campaign_shop_items[numItems++] = i;
|
2017-06-14 15:08:56 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
window_new_campaign_shop_items[numItems] = 255;
|
2014-08-12 01:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-08-12 01:27:25 +02:00
|
|
|
* rct2: 0x0069E50B
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_new_campaign_mouseup(rct_window* w, rct_widgetindex widgetIndex)
|
2014-08-12 01:27:25 +02:00
|
|
|
{
|
2018-03-15 23:44:24 +01:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
case WIDX_CLOSE:
|
|
|
|
window_close(w);
|
|
|
|
break;
|
|
|
|
case WIDX_START_BUTTON:
|
2018-03-15 23:44:24 +01:00
|
|
|
{
|
2020-07-29 10:44:38 +02:00
|
|
|
auto gameAction = ParkMarketingAction(w->campaign.campaign_type, w->campaign.RideId, w->campaign.no_weeks);
|
2020-10-15 03:04:39 +02:00
|
|
|
gameAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) {
|
|
|
|
if (result->Error == GameActions::Status::Ok)
|
2018-03-15 23:44:24 +01:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
window_close_by_class(WC_NEW_CAMPAIGN);
|
|
|
|
}
|
|
|
|
});
|
2018-03-15 23:44:24 +01:00
|
|
|
GameActions::Execute(&gameAction);
|
|
|
|
break;
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-08-12 01:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-08-12 01:27:25 +02:00
|
|
|
* rct2: 0x0069E51C
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_new_campaign_mousedown(rct_window* w, rct_widgetindex widgetIndex, rct_widget* widget)
|
2014-08-12 01:27:25 +02:00
|
|
|
{
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_widget* dropdownWidget;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (widgetIndex)
|
|
|
|
{
|
|
|
|
case WIDX_RIDE_DROPDOWN_BUTTON:
|
|
|
|
dropdownWidget = widget - 1;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
if (w->campaign.campaign_type == ADVERTISING_CAMPAIGN_FOOD_OR_DRINK_FREE)
|
|
|
|
{
|
|
|
|
window_new_campaign_get_shop_items();
|
|
|
|
if (window_new_campaign_shop_items[0] != 255)
|
|
|
|
{
|
|
|
|
int32_t numItems = 0;
|
2020-11-03 09:16:06 +01:00
|
|
|
for (int32_t i = 0; i < Dropdown::ItemsMaxSize; i++)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
|
|
|
if (window_new_campaign_shop_items[i] == 255)
|
|
|
|
break;
|
|
|
|
|
|
|
|
gDropdownItemsFormat[i] = STR_DROPDOWN_MENU_LABEL;
|
2020-12-09 07:55:06 +01:00
|
|
|
gDropdownItemsArgs[i] = GetShopItemDescriptor(ShopItem(window_new_campaign_shop_items[i]))
|
|
|
|
.Naming.Plural;
|
2018-06-22 23:21:44 +02:00
|
|
|
numItems++;
|
|
|
|
}
|
|
|
|
|
2020-11-03 09:16:06 +01:00
|
|
|
WindowDropdownShowTextCustomWidth(
|
2020-05-01 20:48:20 +02:00
|
|
|
{ w->windowPos.x + dropdownWidget->left, w->windowPos.y + dropdownWidget->top },
|
2020-11-03 09:16:06 +01:00
|
|
|
dropdownWidget->height() + 1, w->colours[1], 0, Dropdown::Flag::StayOpen, numItems,
|
2020-06-25 03:44:00 +02:00
|
|
|
dropdownWidget->width() - 3);
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t numItems = 0;
|
2019-08-03 18:27:50 +02:00
|
|
|
for (auto rideId : window_new_campaign_rides)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2019-08-03 18:27:50 +02:00
|
|
|
auto ride = get_ride(rideId);
|
|
|
|
if (ride != nullptr)
|
2019-07-21 13:09:23 +02:00
|
|
|
{
|
2019-08-03 18:27:50 +02:00
|
|
|
// HACK until dropdown items have longer argument buffers
|
|
|
|
gDropdownItemsFormat[numItems] = STR_DROPDOWN_MENU_LABEL;
|
2020-04-20 07:10:33 +02:00
|
|
|
Formatter ft(reinterpret_cast<uint8_t*>(&gDropdownItemsArgs[numItems]));
|
2019-08-03 18:27:50 +02:00
|
|
|
if (ride->custom_name.empty())
|
|
|
|
{
|
2020-06-25 02:02:08 +02:00
|
|
|
ride->FormatNameTo(ft);
|
2019-08-03 18:27:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gDropdownItemsFormat[numItems] = STR_OPTIONS_DROPDOWN_ITEM;
|
2020-04-20 23:55:15 +02:00
|
|
|
ft.Add<const char*>(ride->custom_name.c_str());
|
2019-08-03 18:27:50 +02:00
|
|
|
}
|
|
|
|
numItems++;
|
2019-07-21 13:09:23 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 09:16:06 +01:00
|
|
|
WindowDropdownShowTextCustomWidth(
|
2020-05-01 20:48:20 +02:00
|
|
|
{ w->windowPos.x + dropdownWidget->left, w->windowPos.y + dropdownWidget->top },
|
2020-11-03 09:16:06 +01:00
|
|
|
dropdownWidget->height() + 1, w->colours[1], 0, Dropdown::Flag::StayOpen, numItems,
|
2020-06-25 03:44:00 +02:00
|
|
|
dropdownWidget->width() - 3);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
// In RCT2, the maximum was 6 weeks
|
|
|
|
case WIDX_WEEKS_INCREASE_BUTTON:
|
|
|
|
w->campaign.no_weeks = std::min(w->campaign.no_weeks + 1, 12);
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
|
|
|
case WIDX_WEEKS_DECREASE_BUTTON:
|
|
|
|
w->campaign.no_weeks = std::max(w->campaign.no_weeks - 1, 2);
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2018-06-22 23:21:44 +02:00
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-08-12 01:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-08-12 01:27:25 +02:00
|
|
|
* rct2: 0x0069E537
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_new_campaign_dropdown(rct_window* w, rct_widgetindex widgetIndex, int32_t dropdownIndex)
|
2014-08-12 01:27:25 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
if (widgetIndex != WIDX_RIDE_DROPDOWN_BUTTON)
|
|
|
|
return;
|
2014-08-12 01:27:25 +02:00
|
|
|
|
2020-07-29 10:44:38 +02:00
|
|
|
if (dropdownIndex < 0)
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
2016-05-26 20:43:53 +02:00
|
|
|
|
2018-06-22 23:21:44 +02:00
|
|
|
if (w->campaign.campaign_type == ADVERTISING_CAMPAIGN_FOOD_OR_DRINK_FREE)
|
|
|
|
{
|
2020-07-29 10:44:38 +02:00
|
|
|
if (static_cast<size_t>(dropdownIndex) >= std::size(window_new_campaign_shop_items))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (window_new_campaign_shop_items[dropdownIndex] == 255)
|
|
|
|
return;
|
|
|
|
|
|
|
|
w->campaign.ShopItemId = window_new_campaign_shop_items[dropdownIndex];
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-29 10:44:38 +02:00
|
|
|
if (static_cast<size_t>(dropdownIndex) >= window_new_campaign_rides.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
w->campaign.RideId = window_new_campaign_rides[dropdownIndex];
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-08-12 01:27:25 +02:00
|
|
|
|
2019-06-15 17:20:16 +02:00
|
|
|
w->Invalidate();
|
2014-08-12 01:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-08-12 01:27:25 +02:00
|
|
|
* rct2: 0x0069E397
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_new_campaign_invalidate(rct_window* w)
|
2014-08-12 01:27:25 +02:00
|
|
|
{
|
2020-11-27 04:14:20 +01:00
|
|
|
window_new_campaign_widgets[WIDX_RIDE_LABEL].type = WindowWidgetType::Empty;
|
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN].type = WindowWidgetType::Empty;
|
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN_BUTTON].type = WindowWidgetType::Empty;
|
2017-06-06 23:24:18 +02:00
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN].text = STR_MARKETING_NOT_SELECTED;
|
2018-06-22 23:21:44 +02:00
|
|
|
switch (w->campaign.campaign_type)
|
|
|
|
{
|
|
|
|
case ADVERTISING_CAMPAIGN_RIDE_FREE:
|
|
|
|
case ADVERTISING_CAMPAIGN_RIDE:
|
2020-11-27 04:14:20 +01:00
|
|
|
window_new_campaign_widgets[WIDX_RIDE_LABEL].type = WindowWidgetType::Label;
|
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN].type = WindowWidgetType::DropdownMenu;
|
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN_BUTTON].type = WindowWidgetType::Button;
|
2018-06-22 23:21:44 +02:00
|
|
|
window_new_campaign_widgets[WIDX_RIDE_LABEL].text = STR_MARKETING_RIDE;
|
2020-07-29 10:44:38 +02:00
|
|
|
if (w->campaign.RideId != SELECTED_RIDE_UNDEFINED)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2020-07-29 10:44:38 +02:00
|
|
|
auto ride = get_ride(w->campaign.RideId);
|
2019-07-21 02:28:33 +02:00
|
|
|
if (ride != nullptr)
|
|
|
|
{
|
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN].text = STR_STRINGID;
|
2020-06-25 02:02:08 +02:00
|
|
|
|
|
|
|
auto ft = Formatter::Common();
|
|
|
|
ride->FormatNameTo(ft);
|
2019-07-21 02:28:33 +02:00
|
|
|
}
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ADVERTISING_CAMPAIGN_FOOD_OR_DRINK_FREE:
|
2020-11-27 04:14:20 +01:00
|
|
|
window_new_campaign_widgets[WIDX_RIDE_LABEL].type = WindowWidgetType::Label;
|
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN].type = WindowWidgetType::DropdownMenu;
|
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN_BUTTON].type = WindowWidgetType::Button;
|
2018-06-22 23:21:44 +02:00
|
|
|
window_new_campaign_widgets[WIDX_RIDE_LABEL].text = STR_MARKETING_ITEM;
|
2020-07-29 10:44:38 +02:00
|
|
|
if (w->campaign.ShopItemId != SELECTED_RIDE_UNDEFINED)
|
2018-06-22 23:21:44 +02:00
|
|
|
{
|
2020-12-09 07:55:06 +01:00
|
|
|
window_new_campaign_widgets[WIDX_RIDE_DROPDOWN].text = GetShopItemDescriptor(ShopItem(w->campaign.ShopItemId))
|
|
|
|
.Naming.Plural;
|
2018-06-22 23:21:44 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set current number of weeks spinner (moved to paint due to required parameter)
|
|
|
|
window_new_campaign_widgets[WIDX_WEEKS_SPINNER].text = STR_NONE;
|
|
|
|
|
|
|
|
// Enable / disable start button based on ride dropdown
|
|
|
|
w->disabled_widgets &= ~(1 << WIDX_START_BUTTON);
|
2020-11-27 04:14:20 +01:00
|
|
|
if (window_new_campaign_widgets[WIDX_RIDE_DROPDOWN].type == WindowWidgetType::DropdownMenu
|
|
|
|
&& w->campaign.RideId == SELECTED_RIDE_UNDEFINED)
|
2017-06-06 23:24:18 +02:00
|
|
|
w->disabled_widgets |= 1 << WIDX_START_BUTTON;
|
2014-08-12 01:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-08-12 01:27:25 +02:00
|
|
|
* rct2: 0x0069E493
|
|
|
|
*/
|
2018-06-22 23:21:44 +02:00
|
|
|
static void window_new_campaign_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
2014-08-12 01:27:25 +02:00
|
|
|
{
|
2020-06-20 16:56:36 +02:00
|
|
|
ScreenCoordsXY screenCoords{};
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-11-04 05:52:23 +01:00
|
|
|
WindowDrawWidgets(w, dpi);
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// Number of weeks
|
2018-06-22 23:21:44 +02:00
|
|
|
rct_widget* spinnerWidget = &window_new_campaign_widgets[WIDX_WEEKS_SPINNER];
|
2021-02-27 16:49:13 +01:00
|
|
|
DrawTextBasic(
|
|
|
|
dpi, w->windowPos + ScreenCoordsXY{ spinnerWidget->left + 1, spinnerWidget->top },
|
|
|
|
w->campaign.no_weeks == 1 ? STR_MARKETING_1_WEEK : STR_X_WEEKS, &w->campaign.no_weeks, { w->colours[0] });
|
2017-06-06 23:24:18 +02:00
|
|
|
|
2020-06-20 16:56:36 +02:00
|
|
|
screenCoords = w->windowPos + ScreenCoordsXY{ 14, 60 };
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// Price per week
|
|
|
|
money32 pricePerWeek = AdvertisingCampaignPricePerWeek[w->campaign.campaign_type];
|
2021-02-27 16:49:13 +01:00
|
|
|
DrawTextBasic(dpi, screenCoords, STR_MARKETING_COST_PER_WEEK, &pricePerWeek);
|
2020-06-20 16:56:36 +02:00
|
|
|
screenCoords.y += 13;
|
2017-06-06 23:24:18 +02:00
|
|
|
|
|
|
|
// Total price
|
|
|
|
money32 totalPrice = AdvertisingCampaignPricePerWeek[w->campaign.campaign_type] * w->campaign.no_weeks;
|
2021-02-27 16:49:13 +01:00
|
|
|
DrawTextBasic(dpi, screenCoords, STR_MARKETING_TOTAL_COST, &totalPrice);
|
2015-03-22 16:01:01 +01:00
|
|
|
}
|
2020-04-18 16:15:04 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2021-02-24 13:53:01 +01:00
|
|
|
if (!ride.GetRideTypeDescriptor().HasFlag(
|
2020-04-18 16:15:04 +02:00
|
|
|
RIDE_TYPE_FLAG_IS_SHOP | RIDE_TYPE_FLAG_SELLS_FOOD | RIDE_TYPE_FLAG_SELLS_DRINKS
|
2021-02-24 13:53:01 +01:00
|
|
|
| RIDE_TYPE_FLAG_IS_TOILET))
|
2020-04-18 16:15:04 +02:00
|
|
|
{
|
|
|
|
window_new_campaign_rides.push_back(ride.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take top 128 most valuable rides
|
2020-11-03 09:16:06 +01:00
|
|
|
if (window_new_campaign_rides.size() > Dropdown::ItemsMaxSize)
|
2020-04-18 16:15:04 +02:00
|
|
|
{
|
|
|
|
qsort(window_new_campaign_rides.data(), window_new_campaign_rides.size(), sizeof(ride_id_t), ride_value_compare);
|
2020-11-03 09:16:06 +01:00
|
|
|
window_new_campaign_rides.resize(Dropdown::ItemsMaxSize);
|
2020-04-18 16:15:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sort rides by name
|
|
|
|
qsort(window_new_campaign_rides.data(), window_new_campaign_rides.size(), sizeof(ride_id_t), ride_name_compare);
|
|
|
|
}
|