mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-24 15:24:30 +01:00
Rework GuestList to use a vector. (#11014)
* Rework GuestList to use a vector. This is part of a chain of refactors that will be used to rework peep order in the sprite list * Apply comments. Remove setting var_492 as no longer required
This commit is contained in:
@@ -417,6 +417,7 @@ public:
|
||||
gToolbarDirtyFlags |= BTM_TB_DIRTY_FLAG_PEEP_COUNT;
|
||||
window_invalidate_by_class(WC_GUEST_LIST);
|
||||
window_invalidate_by_class(WC_PARK_INFORMATION);
|
||||
window_guest_list_refresh_list();
|
||||
break;
|
||||
|
||||
case INTENT_ACTION_UPDATE_PARK_RATING:
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <openrct2/sprites.h>
|
||||
#include <openrct2/util/Util.h>
|
||||
#include <openrct2/world/Sprite.h>
|
||||
#include <vector>
|
||||
|
||||
// clang-format off
|
||||
enum {
|
||||
@@ -83,6 +84,8 @@ static constexpr const uint8_t SUMMARISED_GUEST_ROW_HEIGHT = SCROLLABLE_ROW_HEIG
|
||||
static constexpr const auto GUESTS_PER_PAGE = 2000;
|
||||
static constexpr const auto GUEST_PAGE_HEIGHT = GUESTS_PER_PAGE * SCROLLABLE_ROW_HEIGHT;
|
||||
|
||||
static std::vector<uint16_t> GuestList;
|
||||
|
||||
static void window_guest_list_mouseup(rct_window *w, rct_widgetindex widgetIndex);
|
||||
static void window_guest_list_resize(rct_window *w);
|
||||
static void window_guest_list_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget* widget);
|
||||
@@ -217,20 +220,51 @@ rct_window* window_guest_list_open()
|
||||
window_guest_list_widgets[WIDX_FILTER_BY_NAME].type = WWT_FLATBTN;
|
||||
window_guest_list_widgets[WIDX_PAGE_DROPDOWN].type = WWT_EMPTY;
|
||||
window_guest_list_widgets[WIDX_PAGE_DROPDOWN_BUTTON].type = WWT_EMPTY;
|
||||
window->var_492 = 0;
|
||||
window->min_width = 350;
|
||||
window->min_height = 330;
|
||||
window->max_width = 500;
|
||||
window->max_height = 450;
|
||||
|
||||
window_guest_list_refresh_list();
|
||||
return window;
|
||||
}
|
||||
|
||||
void window_guest_list_refresh_list()
|
||||
{
|
||||
if (window_find_by_class(WC_GUEST_LIST) == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_window_guest_list_last_find_groups_wait = 0;
|
||||
_window_guest_list_last_find_groups_tick = 0;
|
||||
window_guest_list_find_groups();
|
||||
|
||||
// Only the individual tab uses the GuestList so no point calculating it
|
||||
if (_window_guest_list_selected_tab != PAGE_INDIVIDUAL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GuestList.clear();
|
||||
Peep* peep = nullptr;
|
||||
uint16_t spriteIndex;
|
||||
FOR_ALL_GUESTS (spriteIndex, peep)
|
||||
{
|
||||
sprite_set_flashing(peep, false);
|
||||
if (peep->outside_of_park != 0)
|
||||
continue;
|
||||
if (_window_guest_list_selected_filter != -1)
|
||||
{
|
||||
if (window_guest_list_is_peep_in_filter(peep))
|
||||
continue;
|
||||
gWindowMapFlashingFlags |= (1 << 0);
|
||||
sprite_set_flashing(peep, true);
|
||||
}
|
||||
if (!guest_should_be_visible(peep))
|
||||
continue;
|
||||
GuestList.push_back(spriteIndex);
|
||||
}
|
||||
|
||||
std::sort(GuestList.begin(), GuestList.end(), [](const uint16_t a, const uint16_t b) { return peep_compare(&a, &b) < 0; });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,6 +436,7 @@ static void window_guest_list_mousedown(rct_window* w, rct_widgetindex widgetInd
|
||||
_window_guest_list_selected_filter = -1;
|
||||
w->Invalidate();
|
||||
w->scrolls[0].v_top = 0;
|
||||
window_guest_list_refresh_list();
|
||||
break;
|
||||
case WIDX_PAGE_DROPDOWN_BUTTON:
|
||||
widget = &w->widgets[widgetIndex - 1];
|
||||
@@ -482,29 +517,13 @@ static void window_guest_list_update(rct_window* w)
|
||||
*/
|
||||
static void window_guest_list_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_t* width, int32_t* height)
|
||||
{
|
||||
int32_t i, y, numGuests, spriteIndex;
|
||||
Peep* peep;
|
||||
|
||||
int32_t y = 0;
|
||||
switch (_window_guest_list_selected_tab)
|
||||
{
|
||||
case PAGE_INDIVIDUAL:
|
||||
// Count the number of guests
|
||||
numGuests = 0;
|
||||
|
||||
FOR_ALL_GUESTS (spriteIndex, peep)
|
||||
{
|
||||
if (peep->outside_of_park != 0)
|
||||
continue;
|
||||
if (_window_guest_list_selected_filter != -1)
|
||||
if (window_guest_list_is_peep_in_filter(peep))
|
||||
continue;
|
||||
if (!guest_should_be_visible(peep))
|
||||
continue;
|
||||
numGuests++;
|
||||
}
|
||||
w->var_492 = numGuests;
|
||||
y = numGuests * SCROLLABLE_ROW_HEIGHT;
|
||||
_window_guest_list_num_pages = 1 + (numGuests - 1) / GUESTS_PER_PAGE;
|
||||
y = static_cast<int16_t>(GuestList.size()) * SCROLLABLE_ROW_HEIGHT;
|
||||
_window_guest_list_num_pages = 1 + (static_cast<int16_t>(GuestList.size()) - 1) / GUESTS_PER_PAGE;
|
||||
if (_window_guest_list_num_pages == 0)
|
||||
_window_guest_list_selected_page = 0;
|
||||
else if (_window_guest_list_selected_page >= _window_guest_list_num_pages)
|
||||
@@ -513,7 +532,6 @@ static void window_guest_list_scrollgetsize(rct_window* w, int32_t scrollIndex,
|
||||
case PAGE_SUMMARISED:
|
||||
// Find the groups
|
||||
window_guest_list_find_groups();
|
||||
w->var_492 = _window_guest_list_num_groups;
|
||||
y = _window_guest_list_num_groups * SUMMARISED_GUEST_ROW_HEIGHT;
|
||||
break;
|
||||
default:
|
||||
@@ -530,7 +548,7 @@ static void window_guest_list_scrollgetsize(rct_window* w, int32_t scrollIndex,
|
||||
w->Invalidate();
|
||||
}
|
||||
|
||||
i = y - window_guest_list_widgets[WIDX_GUEST_LIST].bottom + window_guest_list_widgets[WIDX_GUEST_LIST].top + 21;
|
||||
auto i = y - window_guest_list_widgets[WIDX_GUEST_LIST].bottom + window_guest_list_widgets[WIDX_GUEST_LIST].top + 21;
|
||||
if (i < 0)
|
||||
i = 0;
|
||||
if (i < w->scrolls[0].v_top)
|
||||
@@ -549,35 +567,21 @@ static void window_guest_list_scrollgetsize(rct_window* w, int32_t scrollIndex,
|
||||
*/
|
||||
static void window_guest_list_scrollmousedown(rct_window* w, int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
|
||||
{
|
||||
int32_t i, spriteIndex;
|
||||
Peep* peep;
|
||||
int32_t i = 0;
|
||||
|
||||
switch (_window_guest_list_selected_tab)
|
||||
{
|
||||
case PAGE_INDIVIDUAL:
|
||||
i = screenCoords.y / SCROLLABLE_ROW_HEIGHT;
|
||||
i += _window_guest_list_selected_page * GUESTS_PER_PAGE;
|
||||
FOR_ALL_GUESTS (spriteIndex, peep)
|
||||
for (auto spriteIndex : GuestList)
|
||||
{
|
||||
if (peep->outside_of_park != 0)
|
||||
continue;
|
||||
if (_window_guest_list_selected_filter != -1)
|
||||
if (window_guest_list_is_peep_in_filter(peep))
|
||||
continue;
|
||||
if (!guest_should_be_visible(peep))
|
||||
continue;
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
// Open guest window
|
||||
window_guest_open(peep);
|
||||
|
||||
window_guest_open(GET_PEEP(spriteIndex));
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
i--;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
break;
|
||||
case PAGE_SUMMARISED:
|
||||
@@ -714,9 +718,9 @@ static void window_guest_list_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
{
|
||||
x = w->windowPos.x + 4;
|
||||
y = w->windowPos.y + window_guest_list_widgets[WIDX_GUEST_LIST].bottom + 2;
|
||||
set_format_arg(0, int16_t, w->var_492);
|
||||
set_format_arg(0, int16_t, static_cast<int16_t>(GuestList.size()));
|
||||
gfx_draw_string_left(
|
||||
dpi, (w->var_492 == 1 ? STR_FORMAT_NUM_GUESTS_SINGULAR : STR_FORMAT_NUM_GUESTS_PLURAL), gCommonFormatArgs,
|
||||
dpi, (GuestList.size() == 1 ? STR_FORMAT_NUM_GUESTS_SINGULAR : STR_FORMAT_NUM_GUESTS_PLURAL), gCommonFormatArgs,
|
||||
COLOUR_BLACK, x, y);
|
||||
}
|
||||
}
|
||||
@@ -727,14 +731,12 @@ static void window_guest_list_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
*/
|
||||
static void window_guest_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t scrollIndex)
|
||||
{
|
||||
int32_t spriteIndex, numGuests, i, j, y;
|
||||
int32_t numGuests, i, j, y;
|
||||
rct_string_id format;
|
||||
Peep* peep;
|
||||
rct_peep_thought* thought;
|
||||
|
||||
// Background fill
|
||||
gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1, ColourMapA[w->colours[1]].mid_light);
|
||||
|
||||
switch (_window_guest_list_selected_tab)
|
||||
{
|
||||
case PAGE_INDIVIDUAL:
|
||||
@@ -742,21 +744,8 @@ static void window_guest_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi,
|
||||
y = _window_guest_list_selected_page * -GUEST_PAGE_HEIGHT;
|
||||
|
||||
// For each guest
|
||||
FOR_ALL_GUESTS (spriteIndex, peep)
|
||||
for (auto spriteIndex : GuestList)
|
||||
{
|
||||
sprite_set_flashing(peep, false);
|
||||
if (peep->outside_of_park != 0)
|
||||
continue;
|
||||
if (_window_guest_list_selected_filter != -1)
|
||||
{
|
||||
if (window_guest_list_is_peep_in_filter(peep))
|
||||
continue;
|
||||
gWindowMapFlashingFlags |= (1 << 0);
|
||||
sprite_set_flashing(peep, true);
|
||||
}
|
||||
if (!guest_should_be_visible(peep))
|
||||
continue;
|
||||
|
||||
// Check if y is beyond the scroll control
|
||||
if (y + SCROLLABLE_ROW_HEIGHT + 1 >= -0x7FFF && y + SCROLLABLE_ROW_HEIGHT + 1 > dpi->y && y < 0x7FFF
|
||||
&& y < dpi->y + dpi->height)
|
||||
@@ -770,6 +759,7 @@ static void window_guest_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi,
|
||||
}
|
||||
|
||||
// Guest name
|
||||
auto peep = GET_PEEP(spriteIndex);
|
||||
peep->FormatNameTo(gCommonFormatArgs);
|
||||
gfx_draw_string_left_clipped(dpi, format, gCommonFormatArgs, COLOUR_BLACK, 0, y, 113);
|
||||
|
||||
|
||||
@@ -3241,7 +3241,7 @@ rct_string_id get_real_name_string_id_from_id(uint32_t id)
|
||||
return dx;
|
||||
}
|
||||
|
||||
static int32_t peep_compare(const void* sprite_index_a, const void* sprite_index_b)
|
||||
int32_t peep_compare(const void* sprite_index_a, const void* sprite_index_b)
|
||||
{
|
||||
Peep const* peep_a = GET_PEEP(*(uint16_t*)sprite_index_a);
|
||||
Peep const* peep_b = GET_PEEP(*(uint16_t*)sprite_index_b);
|
||||
|
||||
@@ -988,6 +988,7 @@ void peep_window_state_update(Peep* peep);
|
||||
void peep_decrement_num_riders(Peep* peep);
|
||||
|
||||
void peep_set_map_tooltip(Peep* peep);
|
||||
int32_t peep_compare(const void* sprite_index_a, const void* sprite_index_b);
|
||||
|
||||
void SwitchToSpecialSprite(Peep* peep, uint8_t special_sprite_id);
|
||||
void peep_update_name_sort(Peep* peep);
|
||||
|
||||
Reference in New Issue
Block a user