From 417c0f584f965a14003b848985069cf6b3417c08 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 4 May 2021 21:05:21 +0100 Subject: [PATCH] Handle > 255 rides in ride list window --- src/openrct2-ui/windows/RideList.cpp | 83 ++++++++++++++-------------- src/openrct2/interface/Window.cpp | 12 ---- src/openrct2/interface/Window.h | 2 - 3 files changed, 43 insertions(+), 54 deletions(-) diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 8d4ac072c2..aa932db73e 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -73,6 +73,7 @@ static rct_widget window_ride_list_widgets[] = { }; static bool _quickDemolishMode = false; +static std::vector _rideList; static void window_ride_list_mouseup(rct_window *w, rct_widgetindex widgetIndex); static void window_ride_list_resize(rct_window *w); @@ -198,7 +199,6 @@ rct_window* window_ride_list_open() } WindowInitScrollWidgets(window); window->page = PAGE_RIDES; - window->no_list_items = 0; window->selected_list_item = -1; window->frame_no = 0; window->min_width = 340; @@ -227,7 +227,6 @@ static void window_ride_list_mouseup(rct_window* w, rct_widgetindex widgetIndex) break; case WIDX_SORT: w->list_information_type = _window_ride_list_information_type; - w->no_list_items = 0; w->selected_list_item = -1; window_ride_list_refresh_list(w); break; @@ -237,7 +236,6 @@ static void window_ride_list_mouseup(rct_window* w, rct_widgetindex widgetIndex) if (w->page != widgetIndex - WIDX_TAB_1) { w->page = widgetIndex - WIDX_TAB_1; - w->no_list_items = 0; w->frame_no = 0; w->selected_list_item = -1; if (w->page != PAGE_RIDES && _window_ride_list_information_type > INFORMATION_TYPE_RUNNING_COST) @@ -407,16 +405,14 @@ static void window_ride_list_update(rct_window* w) */ static void window_ride_list_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height) { - int32_t top; - - *height = w->no_list_items * SCROLLABLE_ROW_HEIGHT; + *height = static_cast(_rideList.size() * SCROLLABLE_ROW_HEIGHT); if (w->selected_list_item != -1) { w->selected_list_item = -1; w->Invalidate(); } - top = *height - window_ride_list_widgets[WIDX_LIST].bottom + window_ride_list_widgets[WIDX_LIST].top + 21; + auto top = *height - window_ride_list_widgets[WIDX_LIST].bottom + window_ride_list_widgets[WIDX_LIST].top + 21; if (top < 0) top = 0; if (top < w->scrolls[0].v_top) @@ -432,14 +428,12 @@ static void window_ride_list_scrollgetsize(rct_window* w, int32_t scrollIndex, i */ static void window_ride_list_scrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords) { - int32_t index; - - index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; - if (index >= w->no_list_items) + auto index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + if (index < 0 || static_cast(index) >= _rideList.size()) return; // Open ride window - auto rideIndex = w->list_item_positions[index]; + auto rideIndex = _rideList[index]; auto ride = get_ride(rideIndex); if (_quickDemolishMode && network_get_mode() != NETWORK_MODE_CLIENT) { @@ -460,10 +454,8 @@ static void window_ride_list_scrollmousedown(rct_window* w, int32_t scrollIndex, */ static void window_ride_list_scrollmouseover(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords) { - int32_t index; - - index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; - if (index >= w->no_list_items) + auto index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + if (index < 0 || static_cast(index) >= _rideList.size()) return; w->selected_list_item = index; @@ -521,7 +513,7 @@ static void window_ride_list_invalidate(rct_window* w) const auto& rideManager = GetRideManager(); auto allClosed = true; auto allOpen = false; - if (w->no_list_items > 0 && std::size(rideManager) != 0) + if (_rideList.size() > 0 && std::size(rideManager) != 0) { auto c = static_cast(w->page); allClosed = std::none_of(rideManager.begin(), rideManager.end(), [c](const Ride& ride) { @@ -561,7 +553,7 @@ static void window_ride_list_paint(rct_window* w, rct_drawpixelinfo* dpi) // Draw number of attractions on bottom auto ft = Formatter(); - ft.Add(w->no_list_items); + ft.Add(static_cast(_rideList.size())); DrawTextBasic( dpi, w->windowPos + ScreenCoordsXY{ 4, w->widgets[WIDX_LIST].bottom + 2 }, ride_list_statusbar_count_strings[w->page], ft); @@ -578,10 +570,10 @@ static void window_ride_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, dpi, { dpiCoords, dpiCoords + ScreenCoordsXY{ dpi->width, dpi->height } }, ColourMapA[w->colours[1]].mid_light); auto y = 0; - for (auto i = 0; i < w->no_list_items; i++) + for (size_t i = 0; i < _rideList.size(); i++) { rct_string_id format = (_quickDemolishMode ? STR_RED_STRINGID : STR_BLACK_STRING); - if (i == w->selected_list_item) + if (i == static_cast(w->selected_list_item)) { // Background highlight gfx_filter_rect(dpi, 0, y, 800, y + SCROLLABLE_ROW_HEIGHT - 1, FilterPaletteID::PaletteDarken1); @@ -589,7 +581,7 @@ static void window_ride_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, } // Get ride - auto ride = get_ride(w->list_item_positions[i]); + auto ride = get_ride(_rideList[i]); if (ride == nullptr) continue; @@ -783,13 +775,25 @@ static void window_ride_list_draw_tab_images(rct_drawpixelinfo* dpi, rct_window* dpi, ImageId(sprite_idx), w->windowPos + ScreenCoordsXY{ w->widgets[WIDX_TAB_3].left, w->widgets[WIDX_TAB_3].top }); } +/** + * Bubbles an item one position up in the window list. This is done by swapping + * the two locations. + * rct2: New function not from rct2 + */ +static void window_bubble_list_item(rct_window* w, int32_t index) +{ + std::swap(_rideList[index], _rideList[index + 1]); +} + /** * * rct2: 0x006B39A8 */ void window_ride_list_refresh_list(rct_window* w) { - int32_t list_index = 0; + _rideList.clear(); + + size_t list_index = 0; for (auto& ridec : GetRideManager()) { auto ride = &ridec; @@ -802,8 +806,8 @@ void window_ride_list_refresh_list(rct_window* w) ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_LIST; } - w->list_item_positions[list_index] = ride->id; - int32_t current_list_position = list_index; + _rideList.push_back(ride->id); + auto current_list_position = static_cast(list_index); switch (w->list_information_type) { case INFORMATION_TYPE_STATUS: @@ -811,7 +815,7 @@ void window_ride_list_refresh_list(rct_window* w) auto strA = ride->GetName(); while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { auto strB = otherRide->GetName(); @@ -826,7 +830,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_POPULARITY: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->popularity * 4 <= otherRide->popularity * 4) @@ -839,7 +843,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_SATISFACTION: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->satisfaction * 5 <= otherRide->satisfaction * 5) @@ -852,7 +856,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_PROFIT: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->profit <= otherRide->profit) @@ -865,7 +869,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_TOTAL_CUSTOMERS: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->total_customers <= otherRide->total_customers) @@ -878,7 +882,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_TOTAL_PROFIT: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->total_profit <= otherRide->total_profit) @@ -891,7 +895,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_CUSTOMERS: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride_customers_per_hour(ride) <= ride_customers_per_hour(otherRide)) @@ -904,7 +908,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_AGE: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->build_date <= otherRide->build_date) @@ -917,7 +921,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_INCOME: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->income_per_hour <= otherRide->income_per_hour) @@ -930,7 +934,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_RUNNING_COST: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->upkeep_cost <= otherRide->upkeep_cost) @@ -943,7 +947,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_QUEUE_LENGTH: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->GetTotalQueueLength() <= otherRide->GetTotalQueueLength()) @@ -956,7 +960,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_QUEUE_TIME: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->GetMaxQueueTime() <= otherRide->GetMaxQueueTime()) @@ -969,7 +973,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_RELIABILITY: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->reliability_percentage <= otherRide->reliability_percentage) @@ -982,7 +986,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_DOWN_TIME: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->downtime <= otherRide->downtime) @@ -995,7 +999,7 @@ void window_ride_list_refresh_list(rct_window* w) case INFORMATION_TYPE_GUESTS_FAVOURITE: while (--current_list_position >= 0) { - auto otherRide = get_ride(w->list_item_positions[current_list_position]); + auto otherRide = get_ride(_rideList[current_list_position]); if (otherRide != nullptr) { if (ride->guests_favourite <= otherRide->guests_favourite) @@ -1010,7 +1014,6 @@ void window_ride_list_refresh_list(rct_window* w) list_index++; } - w->no_list_items = list_index; w->selected_list_item = -1; w->Invalidate(); } diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index d12d1b5318..2722987872 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -1631,18 +1631,6 @@ void window_event_scroll_paint_call(rct_window* w, rct_drawpixelinfo* dpi, int32 w->event_handlers->scroll_paint(w, dpi, scrollIndex); } -/** - * Bubbles an item one position up in the window list. This is done by swapping - * the two locations. - * rct2: New function not from rct2 - */ -void window_bubble_list_item(rct_window* w, int32_t item_position) -{ - char swap = w->list_item_positions[item_position]; - w->list_item_positions[item_position] = w->list_item_positions[item_position + 1]; - w->list_item_positions[item_position + 1] = swap; -} - /** * * rct2: 0x006ED710 diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index bbb9727606..9ad150c9b9 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -805,8 +805,6 @@ void ride_construction_toolupdate_entrance_exit(const ScreenCoordsXY& screenCoor void ride_construction_toolupdate_construct(const ScreenCoordsXY& screenCoords); void ride_construction_tooldown_construct(const ScreenCoordsXY& screenCoords); -void window_bubble_list_item(rct_window* w, int32_t item_position); - void window_align_tabs(rct_window* w, rct_widgetindex start_tab_id, rct_widgetindex end_tab_id); void window_staff_list_init_vars();