diff --git a/src/openrct2-ui/interface/Dropdown.h b/src/openrct2-ui/interface/Dropdown.h index bf9d1217ca..7c33dc7fdc 100644 --- a/src/openrct2-ui/interface/Dropdown.h +++ b/src/openrct2-ui/interface/Dropdown.h @@ -10,10 +10,12 @@ #pragma once #include +#include #include #include #include #include +#include #include struct ImageId; @@ -32,6 +34,9 @@ namespace OpenRCT2::Dropdown constexpr int32_t kItemsMaxSize = 512; struct DropdownState; + + using CellDrawFunction = std::function; + } // namespace OpenRCT2::Dropdown namespace OpenRCT2::Ui::Windows @@ -54,6 +59,9 @@ namespace OpenRCT2::Ui::Windows void WindowDropdownShowImage( const ScreenCoordsXY& screenPos, int32_t extray, ColourWithFlags colour, uint8_t flags, int32_t numItems, int32_t itemWidth, int32_t itemHeight, int32_t numColumns); + void WindowDropdownShowCustom( + const ScreenCoordsXY& screenPos, int32_t extraY, ColourWithFlags colour, uint8_t flags, + Dropdown::CellDrawFunction drawFunction, int32_t numItems, int32_t itemWidth, int32_t itemHeight, int32_t numColumns); void WindowDropdownClose(); @@ -203,6 +211,8 @@ namespace OpenRCT2::Dropdown int32_t lastTooltipHover{}; int32_t highlightedIndex{}; int32_t defaultIndex{}; + + std::optional cellDrawFunction; }; template diff --git a/src/openrct2-ui/windows/Dropdown.cpp b/src/openrct2-ui/windows/Dropdown.cpp index e0172033b7..5531de409f 100644 --- a/src/openrct2-ui/windows/Dropdown.cpp +++ b/src/openrct2-ui/windows/Dropdown.cpp @@ -90,15 +90,8 @@ namespace OpenRCT2::Ui::Windows void drawItem(RenderTarget& rt, ScreenCoordsXY screenCoords, int32_t i) { - int32_t highlightedIndex = gDropdown.highlightedIndex; - bool highlighted = (i == highlightedIndex); - - if (highlighted) - { - // Darken the cell's background slightly when highlighted - const ScreenCoordsXY rightBottom = screenCoords + ScreenCoordsXY{ ItemWidth - 1, ItemHeight - 1 }; - Rectangle::filter(rt, { screenCoords, rightBottom }, FilterPaletteID::paletteDarken3); - } + const int32_t highlightedIndex = gDropdown.highlightedIndex; + const bool highlighted = (i == highlightedIndex); const auto& item = gDropdown.items[i]; switch (item.type) @@ -185,6 +178,8 @@ namespace OpenRCT2::Ui::Windows { drawWidgets(rt); + int32_t highlightedIndex = gDropdown.highlightedIndex; + for (int32_t i = 0; i < gDropdown.numItems; i++) { ScreenCoordsXY cellCoords; @@ -196,10 +191,26 @@ namespace OpenRCT2::Ui::Windows ScreenCoordsXY screenCoords = windowPos + ScreenCoordsXY{ 2 + (cellCoords.x * ItemWidth), 2 + (cellCoords.y * ItemHeight) }; + bool highlighted = (i == highlightedIndex); + if (highlighted) + { + // Darken the cell's background slightly when highlighted + const ScreenCoordsXY rightBottom = screenCoords + ScreenCoordsXY{ ItemWidth - 1, ItemHeight - 1 }; + Rectangle::filter(rt, { screenCoords, rightBottom }, FilterPaletteID::paletteDarken3); + } + if (gDropdown.items[i].isSeparator()) { drawSeparator(rt, screenCoords); } + else if (gDropdown.cellDrawFunction.has_value()) + { + RenderTarget clippedRT; + if (ClipRenderTarget(clippedRT, rt, screenCoords, ItemWidth, ItemHeight)) + { + gDropdown.cellDrawFunction.value()(clippedRT, gDropdown.items[i], highlighted); + } + } else { drawItem(rt, screenCoords, i); @@ -376,6 +387,8 @@ namespace OpenRCT2::Ui::Windows WindowDropdownShowTextCustomWidth( screenPos, extray, colour, 0, flags, num_items, maxStringWidth + 3, prefRowsPerColumn); + + gDropdown.cellDrawFunction = std::nullopt; } void WindowDropdownShowText( @@ -417,6 +430,8 @@ namespace OpenRCT2::Ui::Windows auto numRowsPerColumn = prefRowsPerColumn > 0 ? static_cast(prefRowsPerColumn) : Dropdown::kItemsMaxSize; w->setTextItems(screenPos, extray, colour, customItemHeight, flags, num_items, width, numRowsPerColumn); } + + gDropdown.cellDrawFunction = std::nullopt; } void WindowDropdownShowTextCustomWidth( @@ -460,6 +475,18 @@ namespace OpenRCT2::Ui::Windows { w->setImageItems(screenPos, extray, colour, numItems, itemWidth, itemHeight, numColumns); } + + gDropdown.cellDrawFunction = std::nullopt; + } + + void WindowDropdownShowCustom( + const ScreenCoordsXY& screenPos, int32_t extraY, ColourWithFlags colour, uint8_t flags, + Dropdown::CellDrawFunction drawFunction, int32_t numItems, int32_t itemWidth, int32_t itemHeight, int32_t numColumns) + { + // Fall back to image internals + WindowDropdownShowImage(screenPos, extraY, colour, flags, numItems, itemWidth, itemHeight, numColumns); + + gDropdown.cellDrawFunction = drawFunction; } void WindowDropdownClose()