* Draw the list of available refit options for a consist and highlight the selected refit option (if any). * @param refits Available refit options for each (sorted) cargo. * @param sel Selected refit option in the window * @param pos Position of the selected item in caller widow * @param rows Number of rows(capacity) in caller window * @param delta Step height in caller window * @param
| 689 | * @param r Rectangle of the matrix widget. |
| 690 | */ |
| 691 | static void DrawVehicleRefitWindow(const RefitOptions &refits, const RefitOption *sel, uint pos, uint rows, uint delta, const Rect &r) |
| 692 | { |
| 693 | Rect ir = r.Shrink(WidgetDimensions::scaled.matrix); |
| 694 | uint current = 0; |
| 695 | |
| 696 | bool rtl = _current_text_dir == TD_RTL; |
| 697 | uint iconwidth = std::max(GetSpriteSize(SPR_CIRCLE_FOLDED).width, GetSpriteSize(SPR_CIRCLE_UNFOLDED).width); |
| 698 | uint iconheight = GetSpriteSize(SPR_CIRCLE_FOLDED).height; |
| 699 | PixelColour linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL); |
| 700 | |
| 701 | int iconleft = rtl ? ir.right - iconwidth : ir.left; |
| 702 | int iconcenter = rtl ? ir.right - iconwidth / 2 : ir.left + iconwidth / 2; |
| 703 | int iconinner = rtl ? ir.right - iconwidth : ir.left + iconwidth; |
| 704 | |
| 705 | Rect tr = ir.Indent(iconwidth + WidgetDimensions::scaled.hsep_wide, rtl); |
| 706 | |
| 707 | /* Draw the list of subtypes for each cargo, and find the selected refit option (by its position). */ |
| 708 | for (const auto &pair : refits) { |
| 709 | bool has_subtypes = pair.second.size() > 1; |
| 710 | for (const RefitOption &refit : pair.second) { |
| 711 | if (current >= pos + rows) break; |
| 712 | |
| 713 | /* Hide subtypes if selected cargo type does not match */ |
| 714 | if ((sel == nullptr || sel->cargo != refit.cargo) && refit.subtype != UINT8_MAX) continue; |
| 715 | |
| 716 | /* Refit options with a position smaller than pos don't have to be drawn. */ |
| 717 | if (current < pos) { |
| 718 | current++; |
| 719 | continue; |
| 720 | } |
| 721 | |
| 722 | if (has_subtypes) { |
| 723 | if (refit.subtype != UINT8_MAX) { |
| 724 | /* Draw tree lines */ |
| 725 | int ycenter = tr.top + GetCharacterHeight(FS_NORMAL) / 2; |
| 726 | GfxDrawLine(iconcenter, tr.top - WidgetDimensions::scaled.matrix.top, iconcenter, (&refit == &pair.second.back()) ? ycenter : tr.top - WidgetDimensions::scaled.matrix.top + delta - 1, linecolour); |
| 727 | GfxDrawLine(iconcenter, ycenter, iconinner, ycenter, linecolour); |
| 728 | } else { |
| 729 | /* Draw expand/collapse icon */ |
| 730 | DrawSprite((sel != nullptr && sel->cargo == refit.cargo) ? SPR_CIRCLE_UNFOLDED : SPR_CIRCLE_FOLDED, PAL_NONE, iconleft, tr.top + (GetCharacterHeight(FS_NORMAL) - iconheight) / 2); |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | TextColour colour = (sel != nullptr && sel->cargo == refit.cargo && sel->subtype == refit.subtype) ? TC_WHITE : TC_BLACK; |
| 735 | /* Get the cargo name. */ |
| 736 | DrawString(tr, GetString(STR_JUST_STRING_STRING, CargoSpec::Get(refit.cargo)->name, refit.string), colour); |
| 737 | |
| 738 | tr.top += delta; |
| 739 | current++; |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | /** Refit cargo window. */ |
| 745 | struct RefitWindow : public Window { |
no test coverage detected