| 306 | } |
| 307 | |
| 308 | void PickerWindow::DrawWidget(const Rect &r, WidgetID widget) const |
| 309 | { |
| 310 | switch (widget) { |
| 311 | /* Class picker */ |
| 312 | case WID_PW_CLASS_LIST: { |
| 313 | Rect ir = r.Shrink(WidgetDimensions::scaled.matrix); |
| 314 | const int selected = this->callbacks.GetSelectedClass(); |
| 315 | const auto vscroll = this->GetScrollbar(WID_PW_CLASS_SCROLL); |
| 316 | const int y_step = this->GetWidget<NWidgetResizeBase>(widget)->resize_y; |
| 317 | auto [first, last] = vscroll->GetVisibleRangeIterators(this->classes); |
| 318 | for (auto it = first; it != last; ++it) { |
| 319 | DrawString(ir, this->callbacks.GetClassName(*it), *it == selected ? TC_WHITE : TC_BLACK); |
| 320 | ir.top += y_step; |
| 321 | } |
| 322 | break; |
| 323 | } |
| 324 | |
| 325 | /* Type picker */ |
| 326 | case WID_PW_TYPE_ITEM: { |
| 327 | assert(this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement() < static_cast<int>(this->types.size())); |
| 328 | const auto &item = this->types[this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement()]; |
| 329 | |
| 330 | DrawPixelInfo tmp_dpi; |
| 331 | Rect ir = r.Shrink(WidgetDimensions::scaled.bevel); |
| 332 | if (FillDrawPixelInfo(&tmp_dpi, ir)) { |
| 333 | AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); |
| 334 | int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT); |
| 335 | int y = (ir.Height() + ScaleSpriteTrad(this->preview_height)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM); |
| 336 | |
| 337 | this->callbacks.DrawType(x, y, item.class_index, item.index); |
| 338 | |
| 339 | int by = ir.Height() - ScaleGUITrad(12); |
| 340 | |
| 341 | GrfSpecFeature feature = this->callbacks.GetFeature(); |
| 342 | /* Houses have recolours but not related to the company colour and other items depend on gamemode. */ |
| 343 | PaletteID palette = _game_mode != GM_NORMAL || feature == GSF_HOUSES ? PAL_NONE : GetCompanyPalette(_local_company); |
| 344 | DrawBadgeColumn({0, by, ir.Width() - 1, ir.Height() - 1}, 0, this->badge_classes, this->callbacks.GetTypeBadges(item.class_index, item.index), feature, std::nullopt, palette); |
| 345 | |
| 346 | if (this->callbacks.saved.contains(item)) { |
| 347 | DrawSprite(SPR_BLOT, PALETTE_TO_YELLOW, 0, 0); |
| 348 | } |
| 349 | if (this->callbacks.used.contains(item)) { |
| 350 | DrawSprite(SPR_BLOT, PALETTE_TO_GREEN, ir.Width() - GetSpriteSize(SPR_BLOT).width, 0); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | if (!this->callbacks.IsTypeAvailable(item.class_index, item.index)) { |
| 355 | GfxFillRect(ir, GetColourGradient(COLOUR_GREY, SHADE_DARKER), FILLRECT_CHECKER); |
| 356 | } |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | case WID_PW_TYPE_NAME: { |
| 361 | StringID str = this->callbacks.GetTypeName(this->callbacks.GetSelectedClass(), this->callbacks.GetSelectedType()); |
| 362 | if (str != INVALID_STRING_ID) DrawString(r, str, TC_GOLD, SA_CENTER); |
| 363 | break; |
| 364 | } |
| 365 | } |
no test coverage detected