diff --git a/src/openrct2-ui/interface/Dropdown.h b/src/openrct2-ui/interface/Dropdown.h index c16cb20b5c..99f6fbcc0b 100644 --- a/src/openrct2-ui/interface/Dropdown.h +++ b/src/openrct2-ui/interface/Dropdown.h @@ -23,8 +23,6 @@ enum DROPDOWN_FLAG_STAY_OPEN = (1 << 7) }; -extern int32_t gAppropriateImageDropdownItemsPerRow[]; - extern int32_t gDropdownNumItems; extern rct_string_id gDropdownItemsFormat[DROPDOWN_ITEMS_MAX_SIZE]; extern int64_t gDropdownItemsArgs[DROPDOWN_ITEMS_MAX_SIZE]; @@ -50,3 +48,4 @@ int32_t dropdown_index_from_point(const ScreenCoordsXY& loc, rct_window* w); void window_dropdown_show_colour(rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour); void window_dropdown_show_colour_available( rct_window* w, rct_widget* widget, uint8_t dropdownColour, uint8_t selectedColour, uint32_t availableColours); +uint32_t dropdown_get_appropriate_image_dropdown_items_per_row(uint32_t numItems); diff --git a/src/openrct2-ui/interface/LandTool.cpp b/src/openrct2-ui/interface/LandTool.cpp index 8f316c5e30..000ec739d5 100644 --- a/src/openrct2-ui/interface/LandTool.cpp +++ b/src/openrct2-ui/interface/LandTool.cpp @@ -80,11 +80,11 @@ void land_tool_show_surface_style_dropdown(rct_window* w, rct_widget* widget, ui itemIndex++; } } - auto surfaceCount = itemIndex; + uint32_t surfaceCount = itemIndex; window_dropdown_show_image( w->windowPos.x + widget->left, w->windowPos.y + widget->top, widget->bottom - widget->top, w->colours[2], 0, - surfaceCount, 47, 36, gAppropriateImageDropdownItemsPerRow[surfaceCount]); + surfaceCount, 47, 36, dropdown_get_appropriate_image_dropdown_items_per_row(surfaceCount)); gDropdownDefaultIndex = defaultIndex; } @@ -109,11 +109,12 @@ void land_tool_show_edge_style_dropdown(rct_window* w, rct_widget* widget, uint8 itemIndex++; } } - auto edgeCount = itemIndex; + uint32_t edgeCount = itemIndex; + auto itemsPerRow = dropdown_get_appropriate_image_dropdown_items_per_row(edgeCount); window_dropdown_show_image( w->windowPos.x + widget->left, w->windowPos.y + widget->top, widget->bottom - widget->top, w->colours[2], 0, edgeCount, - 47, 36, gAppropriateImageDropdownItemsPerRow[edgeCount]); + 47, 36, itemsPerRow); gDropdownDefaultIndex = defaultIndex; } diff --git a/src/openrct2-ui/windows/Dropdown.cpp b/src/openrct2-ui/windows/Dropdown.cpp index db4c76ac8b..892e45be8d 100644 --- a/src/openrct2-ui/windows/Dropdown.cpp +++ b/src/openrct2-ui/windows/Dropdown.cpp @@ -22,8 +22,8 @@ constexpr int32_t DROPDOWN_TEXT_MAX_ROWS = 32; constexpr int32_t DROPDOWN_ITEM_HEIGHT = 12; -int32_t gAppropriateImageDropdownItemsPerRow[] = { - 1, 1, 1, 1, 2, 2, 3, 3, 4, 3, 5, 4, 4, 5, 5, 5, 4, 5, 6, 5, 5, 7, 4, 5, 6, 5, 6, 6, 6, 6, 6, 8, 8, 0, +static int32_t _appropriateImageDropdownItemsPerRow[34] = { + 1, 1, 1, 1, 2, 2, 3, 3, 4, 3, 5, 4, 4, 5, 5, 5, 4, 5, 6, 5, 5, 7, 4, 5, 6, 5, 6, 6, 6, 6, 6, 8, 8, 8, }; enum @@ -457,9 +457,14 @@ void window_dropdown_show_colour(rct_window* w, rct_widget* widget, uint8_t drop // Show dropdown window_dropdown_show_image( w->windowPos.x + widget->left, w->windowPos.y + widget->top, widget->bottom - widget->top + 1, dropdownColour, - DROPDOWN_FLAG_STAY_OPEN, COLOUR_COUNT, 12, 12, gAppropriateImageDropdownItemsPerRow[COLOUR_COUNT]); + DROPDOWN_FLAG_STAY_OPEN, COLOUR_COUNT, 12, 12, _appropriateImageDropdownItemsPerRow[COLOUR_COUNT]); gDropdownIsColour = true; gDropdownLastColourHover = -1; gDropdownDefaultIndex = defaultIndex; } + +uint32_t dropdown_get_appropriate_image_dropdown_items_per_row(uint32_t numItems) +{ + return numItems < std::size(_appropriateImageDropdownItemsPerRow) ? _appropriateImageDropdownItemsPerRow[numItems] : 8; +} diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 7dda655bc2..3ce28c81e9 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -646,10 +646,10 @@ static void window_footpath_paint(rct_window* w, rct_drawpixelinfo* dpi) */ static void window_footpath_show_footpath_types_dialog(rct_window* w, rct_widget* widget, bool showQueues) { - int32_t i, numPathTypes, image; + int32_t i, image; PathSurfaceEntry* pathType; - numPathTypes = 0; + uint32_t numPathTypes = 0; // If the game is in sandbox mode, also show paths that are normally restricted to the scenario editor bool showEditorPaths = ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gCheatsSandboxMode); @@ -677,9 +677,10 @@ static void window_footpath_show_footpath_types_dialog(rct_window* w, rct_widget numPathTypes++; } + auto itemsPerRow = dropdown_get_appropriate_image_dropdown_items_per_row(numPathTypes); window_dropdown_show_image( w->windowPos.x + widget->left, w->windowPos.y + widget->top, widget->bottom - widget->top + 1, w->colours[1], 0, - numPathTypes, 47, 36, gAppropriateImageDropdownItemsPerRow[numPathTypes]); + numPathTypes, 47, 36, itemsPerRow); } /**