mirror of https://github.com/OpenTTD/OpenTTD
Codefix: DrawEngineList does not accept EngineID.
Replace min/max parameters of DrawEngineList with scrollbar reference, and use iterators instead of indices.pull/12190/head
parent
bf865dc536
commit
a61311fcb0
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16_t min, uint16_t max, EngineID selected_id, bool show_count, GroupID selected_group);
|
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group);
|
||||||
|
|
||||||
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
|
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
|
||||||
{
|
{
|
||||||
|
@ -487,11 +487,9 @@ public:
|
||||||
case WID_RV_LEFT_MATRIX:
|
case WID_RV_LEFT_MATRIX:
|
||||||
case WID_RV_RIGHT_MATRIX: {
|
case WID_RV_RIGHT_MATRIX: {
|
||||||
int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
|
int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
|
||||||
EngineID start = static_cast<EngineID>(this->vscroll[side]->GetPosition()); // what is the offset for the start (scrolling)
|
|
||||||
EngineID end = static_cast<EngineID>(std::min<size_t>(this->vscroll[side]->GetCapacity() + start, this->engines[side].size()));
|
|
||||||
|
|
||||||
/* Do the actual drawing */
|
/* Do the actual drawing */
|
||||||
DrawEngineList((VehicleType)this->window_number, r, this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
|
DrawEngineList((VehicleType)this->window_number, r, this->engines[side], *this->vscroll[side], this->sel_engine[side], side == 0, this->sel_group);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -998,18 +998,16 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
|
||||||
* @param type Type of vehicle (VEH_*)
|
* @param type Type of vehicle (VEH_*)
|
||||||
* @param r The Rect of the list
|
* @param r The Rect of the list
|
||||||
* @param eng_list What engines to draw
|
* @param eng_list What engines to draw
|
||||||
* @param min where to start in the list
|
* @param sb Scrollbar of list.
|
||||||
* @param max where in the list to end
|
|
||||||
* @param selected_id what engine to highlight as selected, if any
|
* @param selected_id what engine to highlight as selected, if any
|
||||||
* @param show_count Whether to show the amount of engines or not
|
* @param show_count Whether to show the amount of engines or not
|
||||||
* @param selected_group the group to list the engines of
|
* @param selected_group the group to list the engines of
|
||||||
*/
|
*/
|
||||||
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16_t min, uint16_t max, EngineID selected_id, bool show_count, GroupID selected_group)
|
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group)
|
||||||
{
|
{
|
||||||
static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
|
static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
|
||||||
|
|
||||||
/* Obligatory sanity checks! */
|
auto [first, last] = sb.GetVisibleRangeIterators(eng_list);
|
||||||
assert(max <= eng_list.size());
|
|
||||||
|
|
||||||
bool rtl = _current_text_dir == TD_RTL;
|
bool rtl = _current_text_dir == TD_RTL;
|
||||||
int step_size = GetEngineListHeight(type);
|
int step_size = GetEngineListHeight(type);
|
||||||
|
@ -1028,9 +1026,8 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
|
||||||
replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
|
replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
|
||||||
|
|
||||||
uint biggest_num_engines = 0;
|
uint biggest_num_engines = 0;
|
||||||
for (auto i = min; i < max; i++) {
|
for (auto it = first; it != last; ++it) {
|
||||||
const auto &item = eng_list[i];
|
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, it->engine_id);
|
||||||
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, item.engine_id);
|
|
||||||
biggest_num_engines = std::max(biggest_num_engines, num_engines);
|
biggest_num_engines = std::max(biggest_num_engines, num_engines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1048,8 +1045,8 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
|
||||||
int replace_icon_y_offset = (ir.Height() - replace_icon.height) / 2;
|
int replace_icon_y_offset = (ir.Height() - replace_icon.height) / 2;
|
||||||
|
|
||||||
int y = ir.top;
|
int y = ir.top;
|
||||||
for (; min < max; min++, y += step_size) {
|
for (auto it = first; it != last; ++it) {
|
||||||
const auto &item = eng_list[min];
|
const auto &item = *it;
|
||||||
uint indent = item.indent * WidgetDimensions::scaled.hsep_indent;
|
uint indent = item.indent * WidgetDimensions::scaled.hsep_indent;
|
||||||
bool has_variants = (item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None;
|
bool has_variants = (item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None;
|
||||||
bool is_folded = (item.flags & EngineDisplayFlags::IsFolded) != EngineDisplayFlags::None;
|
bool is_folded = (item.flags & EngineDisplayFlags::IsFolded) != EngineDisplayFlags::None;
|
||||||
|
@ -1085,10 +1082,11 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
|
||||||
/* Draw tree lines */
|
/* Draw tree lines */
|
||||||
Rect fr = ir.Indent(indent - WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(circle_width, rtl);
|
Rect fr = ir.Indent(indent - WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(circle_width, rtl);
|
||||||
int ycenter = y + normal_text_y_offset + GetCharacterHeight(FS_NORMAL) / 2;
|
int ycenter = y + normal_text_y_offset + GetCharacterHeight(FS_NORMAL) / 2;
|
||||||
bool continues = (min + 1U) < eng_list.size() && eng_list[min + 1].indent == item.indent;
|
bool continues = std::next(it) != std::end(eng_list) && std::next(it)->indent == item.indent;
|
||||||
GfxDrawLine(fr.left + circle_width / 2, y - WidgetDimensions::scaled.matrix.top, fr.left + circle_width / 2, continues ? y - WidgetDimensions::scaled.matrix.top + step_size - 1 : ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
|
GfxDrawLine(fr.left + circle_width / 2, y - WidgetDimensions::scaled.matrix.top, fr.left + circle_width / 2, continues ? y - WidgetDimensions::scaled.matrix.top + step_size - 1 : ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
|
||||||
GfxDrawLine(fr.left + circle_width / 2, ycenter, fr.right, ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
|
GfxDrawLine(fr.left + circle_width / 2, ycenter, fr.right, ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top);
|
||||||
}
|
}
|
||||||
|
y += step_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1791,8 +1789,7 @@ struct BuildVehicleWindow : Window {
|
||||||
this->vehicle_type,
|
this->vehicle_type,
|
||||||
r,
|
r,
|
||||||
this->eng_list,
|
this->eng_list,
|
||||||
this->vscroll->GetPosition(),
|
*this->vscroll,
|
||||||
static_cast<uint16_t>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size())),
|
|
||||||
this->sel_engine,
|
this->sel_engine,
|
||||||
false,
|
false,
|
||||||
DEFAULT_GROUP
|
DEFAULT_GROUP
|
||||||
|
|
Loading…
Reference in New Issue