mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Guard access to appriopriate image items per row
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user