|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
52 Sorting _sorting[BaseVehicleListWindow::GB_END];
56 static BaseVehicleListWindow::VehicleIndividualSortFunction
VehicleAgeSorter;
74 template <BaseVehicleListWindow::VehicleIndiv
idualSortFunction func>
80 BaseVehicleListWindow::VehicleGroupSortFunction *
const BaseVehicleListWindow::vehicle_group_none_sorter_funcs[] = {
81 &VehicleIndividualToGroupSorterWrapper<VehicleNumberSorter>,
82 &VehicleIndividualToGroupSorterWrapper<VehicleNameSorter>,
83 &VehicleIndividualToGroupSorterWrapper<VehicleAgeSorter>,
84 &VehicleIndividualToGroupSorterWrapper<VehicleProfitThisYearSorter>,
85 &VehicleIndividualToGroupSorterWrapper<VehicleProfitLastYearSorter>,
86 &VehicleIndividualToGroupSorterWrapper<VehicleCargoSorter>,
87 &VehicleIndividualToGroupSorterWrapper<VehicleReliabilitySorter>,
88 &VehicleIndividualToGroupSorterWrapper<VehicleMaxSpeedSorter>,
89 &VehicleIndividualToGroupSorterWrapper<VehicleModelSorter>,
90 &VehicleIndividualToGroupSorterWrapper<VehicleValueSorter>,
91 &VehicleIndividualToGroupSorterWrapper<VehicleLengthSorter>,
92 &VehicleIndividualToGroupSorterWrapper<VehicleTimeToLiveSorter>,
93 &VehicleIndividualToGroupSorterWrapper<VehicleTimetableDelaySorter>,
96 const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar[] = {
100 STR_SORT_BY_PROFIT_THIS_YEAR,
101 STR_SORT_BY_PROFIT_LAST_YEAR,
102 STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
103 STR_SORT_BY_RELIABILITY,
104 STR_SORT_BY_MAX_SPEED,
108 STR_SORT_BY_LIFE_TIME,
109 STR_SORT_BY_TIMETABLE_DELAY,
113 const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock[] = {
117 STR_SORT_BY_PROFIT_THIS_PERIOD,
118 STR_SORT_BY_PROFIT_LAST_PERIOD,
119 STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
120 STR_SORT_BY_RELIABILITY,
121 STR_SORT_BY_MAX_SPEED,
125 STR_SORT_BY_LIFE_TIME,
126 STR_SORT_BY_TIMETABLE_DELAY,
130 BaseVehicleListWindow::VehicleGroupSortFunction *
const BaseVehicleListWindow::vehicle_group_shared_orders_sorter_funcs[] = {
138 const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_calendar[] = {
139 STR_SORT_BY_NUM_VEHICLES,
140 STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR,
141 STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR,
142 STR_SORT_BY_AVERAGE_PROFIT_THIS_YEAR,
143 STR_SORT_BY_AVERAGE_PROFIT_LAST_YEAR,
147 const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock[] = {
148 STR_SORT_BY_NUM_VEHICLES,
149 STR_SORT_BY_TOTAL_PROFIT_THIS_PERIOD,
150 STR_SORT_BY_TOTAL_PROFIT_LAST_PERIOD,
151 STR_SORT_BY_AVERAGE_PROFIT_THIS_PERIOD,
152 STR_SORT_BY_AVERAGE_PROFIT_LAST_PERIOD,
156 const StringID BaseVehicleListWindow::vehicle_group_by_names[] = {
158 STR_GROUP_BY_SHARED_ORDERS,
162 const StringID BaseVehicleListWindow::vehicle_depot_name[] = {
163 STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT,
164 STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT,
165 STR_VEHICLE_LIST_SEND_SHIP_TO_DEPOT,
166 STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR
172 this->grouping = _grouping[vli.type][vli.vtype];
173 this->UpdateSortingFromGrouping();
176 const StringID *BaseVehicleListWindow::GetVehicleSorterNames()
181 case GB_SHARED_ORDERS:
195 if (number >= 10000)
return 5;
196 if (number >= 1000)
return 4;
197 if (number >= 100)
return 3;
215 for (
const Vehicle *v : vehicles) {
216 unitnumber = std::max<uint>(unitnumber, v->unitnumber);
222 void BaseVehicleListWindow::BuildVehicleList()
226 Debug(misc, 3,
"Building vehicle list type {} for company {} given index {}", this->
vli.
type, this->vli.company, this->vli.index);
234 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
235 if (u->cargo_cap > 0)
SetBit(used, u->cargo_type);
238 this->used_cargoes = used;
241 uint max_unitnumber = 0;
242 for (
auto it = this->vehicles.begin(); it != this->vehicles.end(); ++it) {
243 this->
vehgroups.emplace_back(it, it + 1);
245 max_unitnumber = std::max<uint>(max_unitnumber, (*it)->unitnumber);
250 std::stable_sort(this->vehicles.begin(), this->vehicles.end(), [](
const Vehicle *
const &u,
const Vehicle *
const &v) {
251 return u->FirstShared() < v->FirstShared();
254 uint max_num_vehicles = 0;
256 VehicleList::const_iterator begin = this->vehicles.begin();
257 while (begin != this->vehicles.end()) {
258 VehicleList::const_iterator end = std::find_if_not(begin, this->vehicles.cend(), [first_shared = (*begin)->FirstShared()](
const Vehicle *
const &v) {
259 return v->FirstShared() == first_shared;
262 this->
vehgroups.emplace_back(begin, end);
264 max_num_vehicles = std::max<uint>(max_num_vehicles,
static_cast<uint
>(end - begin));
289 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
290 if (w->cargo_cap > 0) {
296 bool have_capacity =
false;
297 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
298 if (w->cargo_cap > 0) {
302 have_capacity =
true;
306 return have_capacity;
308 for (
const Vehicle *w = v; w !=
nullptr; w = w->
Next()) {
309 if (w->cargo_cap > 0 && w->cargo_type == cid) {
371 if (this->vehicles.empty()) {
397 }
else if (show_create) {
439 if (!full && !
HasBit(this->used_cargoes, cs->Index()))
continue;
440 list.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false, !
HasBit(this->used_cargoes, cs->Index())));
457 if (show_autoreplace) list.push_back(std::make_unique<DropDownListStringItem>(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE,
false));
458 list.push_back(std::make_unique<DropDownListStringItem>(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE,
false));
459 list.push_back(std::make_unique<DropDownListStringItem>(this->vehicle_depot_name[this->
vli.
vtype], ADI_DEPOT,
false));
462 list.push_back(std::make_unique<DropDownListStringItem>(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED,
false));
463 list.push_back(std::make_unique<DropDownListStringItem>(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL,
false));
464 }
else if (show_create) {
465 list.push_back(std::make_unique<DropDownListStringItem>(STR_VEHICLE_LIST_CREATE_GROUP, ADI_CREATE_GROUP,
false));
472 static const Vehicle *_last_vehicle[2] = {
nullptr,
nullptr };
474 void BaseVehicleListWindow::SortVehicleList()
479 _last_vehicle[0] = _last_vehicle[1] =
nullptr;
484 if (list->size() < 2)
return;
496 }
else if (display_profit_last_year < 0) {
497 spr = SPR_PROFIT_NEGATIVE;
499 spr = SPR_PROFIT_SOME;
501 spr = SPR_PROFIT_LOT;
524 static std::vector<StringID> subtypes;
532 byte ret_refit_cyc = 0;
533 bool success =
false;
534 if (!subtypes.empty()) {
537 const Engine *e = v->GetEngine();
539 if (!
HasBit(e->info.refit_mask, dest_cargo_type) && v->cargo_type != dest_cargo_type)
continue;
541 CargoID old_cargo_type = v->cargo_type;
542 byte old_cargo_subtype = v->cargo_subtype;
545 v->cargo_type = dest_cargo_type;
549 v->cargo_subtype = refit_cyc;
552 v->First()->InvalidateNewGRFCache();
553 v->InvalidateNewGRFCache();
556 if (subtype == STR_EMPTY)
break;
558 if (std::find(subtypes.begin(), subtypes.end(), subtype) == subtypes.end())
continue;
561 ret_refit_cyc = refit_cyc;
567 v->cargo_type = old_cargo_type;
568 v->cargo_subtype = old_cargo_subtype;
571 v->First()->InvalidateNewGRFCache();
572 v->InvalidateNewGRFCache();
578 return ret_refit_cyc;
629 int iconleft = rtl ? ir.right - iconwidth : ir.left;
630 int iconcenter = rtl ? ir.right - iconwidth / 2 : ir.left + iconwidth / 2;
631 int iconinner = rtl ? ir.right - iconwidth : ir.left + iconwidth;
636 for (
const auto &pair : refits) {
637 bool has_subtypes = pair.second.size() > 1;
639 if (current >= pos + rows)
break;
642 if ((sel ==
nullptr || sel->
cargo != refit.
cargo) && refit.
subtype != UINT8_MAX)
continue;
651 if (refit.
subtype != UINT8_MAX) {
655 GfxDrawLine(iconcenter, ycenter, iconinner, ycenter, linecolour);
666 DrawString(tr, STR_JUST_STRING_STRING, colour);
697 std::optional<RefitOption> current_refit_option;
698 if (this->selected_refit !=
nullptr) current_refit_option = *(this->
selected_refit);
699 this->selected_refit =
nullptr;
701 this->refit_list.clear();
705 VehicleSet vehicles_to_refit;
709 if (v->
type ==
VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->
index) == vehicles_to_refit.end())
continue;
711 CargoTypes cmask = e->info.refit_mask;
723 if (!
HasBit(cmask, cid))
continue;
725 auto &list = this->refit_list[cid];
726 bool first_vehicle = list.empty();
729 list.push_back({cid, UINT8_MAX, STR_EMPTY});
755 if (subtype == STR_EMPTY)
break;
764 if (subtype == STR_EMPTY) {
767 for (uint i = 1; i < list.size(); i++) {
768 if (list[i].subtype >= refit_cyc) {
777 while (pos < list.size() && list[pos].subtype != refit_cyc) pos++;
778 if (pos < list.size() && list[pos].string != subtype) {
780 list.erase(list.begin() + pos);
798 if (current_refit_option.has_value()) {
799 for (
const auto &pair : this->refit_list) {
800 for (
const auto &refit : pair.second) {
801 if (refit.cargo == current_refit_option->cargo && refit.subtype == current_refit_option->subtype) {
802 this->selected_refit = &refit;
806 if (this->selected_refit !=
nullptr)
break;
818 size_t scroll_row = 0;
820 CargoID cargo = this->selected_refit ==
nullptr ? INVALID_CARGO : this->selected_refit->
cargo;
822 for (
const auto &pair : this->refit_list) {
823 if (pair.first == cargo) {
825 scroll_row = rows + (this->selected_refit - pair.second.data());
826 rows += pair.second.size();
846 if (row == click_row) {
847 this->selected_refit = &refit;
852 if (this->selected_refit ==
nullptr || this->selected_refit->
cargo != refit.
cargo)
break;
857 this->selected_refit =
nullptr;
869 this->GetWidget<NWidgetCore>(
WID_VR_MATRIX)->tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v->
type;
872 nwi->
tool_tip = STR_REFIT_TRAIN_REFIT_TOOLTIP + v->
type;
891 if (this->hscroll !=
nullptr) this->hscroll->
SetCount(this->vehicle_width);
895 int sprite_width = std::max(0, ((
int)vehicle_panel_display->
current_x - this->vehicle_width) / 2);
896 this->sprite_left = vehicle_panel_display->
pos_x;
897 this->sprite_right = vehicle_panel_display->
pos_x + vehicle_panel_display->
current_x - 1;
899 this->sprite_right -= sprite_width;
902 this->sprite_left += sprite_width;
914 size->height =
resize->height * 8;
922 size->width = this->information_width + padding.height;
927 void SetStringParameters(
WidgetID widget)
const override
948 Money money = cost.GetCost();
949 if (mail_capacity > 0) {
954 return STR_PURCHASE_INFO_AIRCRAFT_CAPACITY;
955 }
else if (money <= 0) {
957 return STR_REFIT_NEW_CAPACITY_INCOME_FROM_AIRCRAFT_REFIT;
960 return STR_REFIT_NEW_CAPACITY_COST_OF_AIRCRAFT_REFIT;
966 return STR_PURCHASE_INFO_CAPACITY;
967 }
else if (money <= 0) {
969 return STR_REFIT_NEW_CAPACITY_INCOME_FROM_REFIT;
972 return STR_REFIT_NEW_CAPACITY_COST_OF_REFIT;
977 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
990 VehicleSet vehicles_to_refit;
993 int left = INT32_MIN;
999 const int highlight_bottom = highlight_top +
height - 1;
1003 const bool contained = std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), u->index) != vehicles_to_refit.end();
1004 if (contained &&
left == INT32_MIN) {
1010 if ((!contained || u->Next() ==
nullptr) &&
left != INT32_MIN) {
1011 if (u->Next() ==
nullptr && contained) {
1012 int current_width = u->GetDisplayImageWidth();
1013 width += current_width;
1025 if (
left != right) {
1026 Rect hr = {
left, highlight_top, right, highlight_bottom};
1033 int current_width = u->GetDisplayImageWidth();
1034 width += current_width;
1050 if (this->selected_refit !=
nullptr) {
1065 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1072 this->selected_vehicle = v->
index;
1073 this->num_vehicles = UINT8_MAX;
1078 if (!gui_scope)
break;
1086 for (
const auto &list : this->refit_list) {
1091 max_width = std::max(dim.width, max_width);
1096 if (this->information_width < max_width) {
1097 this->information_width = max_width;
1104 if (!gui_scope)
break;
1110 int GetClickPosition(
int click_x)
1120 void SetSelectedVehicles(
int drag_x)
1122 drag_x = GetClickPosition(drag_x);
1124 int left_x = std::min(this->click_x, drag_x);
1125 int right_x = std::max(this->click_x, drag_x);
1126 this->num_vehicles = 0;
1135 bool start_counting =
false;
1136 for (; u !=
nullptr; u = u->
Next()) {
1138 left_x -= current_width;
1139 right_x -= current_width;
1141 if (left_x < 0 && !start_counting) {
1142 this->selected_vehicle = u->
index;
1143 start_counting =
true;
1146 this->num_vehicles++;
1149 this->num_vehicles++;
1152 if (right_x < 0)
break;
1157 if (this->num_vehicles != 0) {
1166 this->selected_vehicle = v->
index;
1167 this->num_vehicles = UINT8_MAX;
1172 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1178 this->click_x = GetClickPosition(pt.x - nwi->
pos_x);
1179 this->SetSelectedVehicles(pt.x - nwi->
pos_x);
1195 if (click_count == 1)
break;
1200 if (this->selected_refit !=
nullptr) {
1204 bool delete_window = this->selected_vehicle == v->
index && this->num_vehicles == UINT8_MAX;
1205 if (
Command<CMD_REFIT_VEHICLE>::Post(GetCmdRefitVehMsg(v), v->
tile, this->selected_vehicle, this->selected_refit->cargo, this->selected_refit->subtype,
false,
false, this->num_vehicles) && delete_window) this->
Close();
1220 this->SetSelectedVehicles(pt.x - nwi->
pos_x);
1233 this->SetSelectedVehicles(pt.x - nwi->
pos_x);
1248 static constexpr
NWidgetPart _nested_vehicle_refit_widgets[] = {
1264 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_VR_MATRIX),
SetMinimalSize(228, 112),
SetResize(1, 14),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_VR_SCROLLBAR),
1274 static WindowDesc _vehicle_refit_desc(__FILE__, __LINE__,
1275 WDP_AUTO,
"view_vehicle_refit", 240, 174,
1278 std::begin(_nested_vehicle_refit_widgets), std::end(_nested_vehicle_refit_widgets)
1306 if (cmask == lmask) {
1308 SetDParam(0, STR_PURCHASE_INFO_ALL_TYPES);
1314 SetDParam(0, STR_PURCHASE_INFO_ALL_BUT);
1343 return a.NumVehicles() < b.NumVehicles();
1349 return a.GetDisplayProfitThisYear() < b.GetDisplayProfitThisYear();
1355 return a.GetDisplayProfitLastYear() < b.GetDisplayProfitLastYear();
1361 return a.GetDisplayProfitThisYear() *
static_cast<uint
>(b.NumVehicles()) < b.GetDisplayProfitThisYear() *
static_cast<uint
>(a.NumVehicles());
1367 return a.GetDisplayProfitLastYear() *
static_cast<uint
>(b.NumVehicles()) < b.GetDisplayProfitLastYear() *
static_cast<uint
>(a.NumVehicles());
1379 static std::string last_name[2] = { {}, {} };
1381 if (a != _last_vehicle[0]) {
1382 _last_vehicle[0] = a;
1384 last_name[0] =
GetString(STR_VEHICLE_NAME);
1387 if (b != _last_vehicle[1]) {
1388 _last_vehicle[1] = b;
1390 last_name[1] =
GetString(STR_VEHICLE_NAME);
1400 auto r = a->
age - b->
age;
1429 for (uint d : diff) {
1464 for (u = a; u !=
nullptr; u = u->
Next()) diff += u->
value;
1465 for (u = b; u !=
nullptr; u = u->
Next()) diff -= u->
value;
1467 int r = ClampTo<int32_t>(diff);
1492 void InitializeGUI()
1536 static constexpr
NWidgetPart _nested_vehicle_list[] = {
1572 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_VL_LIST),
SetMinimalSize(248, 0),
SetFill(1, 0),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_VL_SCROLLBAR),
1580 SetDataTip(STR_JUST_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
1583 SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
1585 SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
1587 SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
1599 if (order ==
nullptr)
return;
1602 int l_offset = rtl ? 0 : order_arrow_width;
1603 int r_offset = rtl ? order_arrow_width : 0;
1610 if (order->
IsType(OT_GOTO_STATION)) {
1615 if (++i == 4)
break;
1619 order = order->
next;
1620 if (order ==
nullptr) {
1624 }
while (oid != start);
1631 int l_offset = rtl ? 0 : order_arrow_width;
1632 int r_offset = rtl ? order_arrow_width : 0;
1634 while (order !=
nullptr) {
1635 if (order->
IsType(OT_GOTO_STATION)) {
1640 if (++i == 4)
break;
1642 order = order->
next;
1660 default: NOT_REACHED();
1677 if (divisor == 1)
return base;
1680 uint rem = base % divisor;
1681 return base + (rem == 0 ? 0 : divisor - rem);
1702 int image_left = (rtl && show_orderlist) ? olr.right : tr.left;
1703 int image_right = (!rtl && show_orderlist) ? olr.left : tr.right;
1705 int vehicle_button_x = rtl ? ir.right - profit.width : ir.left;
1707 uint max =
static_cast<uint
>(std::min<size_t>(this->vscroll->
GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size()));
1708 for (uint i = this->vscroll->
GetPosition(); i < max; ++i) {
1712 SetDParam(0, vehgroup.GetDisplayProfitThisYear());
1713 SetDParam(1, vehgroup.GetDisplayProfitLastYear());
1721 const Vehicle *v = vehgroup.GetSingleVehicle();
1731 CargoTypes vehicle_cargoes = 0;
1733 for (
auto u = v; u !=
nullptr; u = u->
Next()) {
1739 if (!v->
name.empty()) {
1758 }
else if (!v->
name.empty()) {
1782 case GB_SHARED_ORDERS:
1783 assert(vehgroup.NumVehicles() > 0);
1785 for (
int i = 0; i < static_cast<int>(vehgroup.NumVehicles()); ++i) {
1804 void BaseVehicleListWindow::UpdateSortingFromGrouping()
1814 default: NOT_REACHED();
1822 void BaseVehicleListWindow::UpdateVehicleGroupBy(GroupBy group_by)
1831 this->UpdateSortingFromGrouping();
1868 this->GetWidget<NWidgetCore>(
WID_VL_LIST)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->
vli.
vtype;
1871 if (this->
vli.
type == VL_SHARED_ORDERS) {
1879 this->GetWidget<NWidgetCore>(
WID_VL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->
vli.
vtype;
1886 this->BuildVehicleList();
1887 this->SortVehicleList();
1904 size->height = 6 *
resize->height;
1908 size->height = 4 *
resize->height;
1910 default: NOT_REACHED();
1917 d.height += padding.height;
1918 *size =
maxdim(*size, d);
1928 size->width = std::max(size->width,
GetStringListWidth(this->vehicle_group_none_sorter_names_wallclock));
1929 size->width = std::max(size->width,
GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_calendar));
1930 size->width = std::max(size->width,
GetStringListWidth(this->vehicle_group_shared_orders_sorter_names_wallclock));
1931 size->width += padding.width;
1940 d.height += padding.height;
1941 d.width += padding.width;
1942 *size =
maxdim(*size, d);
1948 void SetStringParameters(
WidgetID widget)
const override
1962 case VL_SHARED_ORDERS:
1972 case VL_STATION_LIST:
1984 default: NOT_REACHED();
1991 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2007 this->BuildVehicleList();
2008 this->SortVehicleList();
2041 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
2045 assert(this->
vli.
type == VL_SHARED_ORDERS);
2046 assert(!this->vehicles.empty());
2047 ShowOrdersWindow(this->vehicles[0]);
2070 if (it == this->
vehgroups.end())
return;
2075 const Vehicle *v = vehgroup.GetSingleVehicle();
2086 case GB_SHARED_ORDERS: {
2087 assert(vehgroup.NumVehicles() > 0);
2091 ShowOrdersWindow(v);
2093 if (vehgroup.NumVehicles() == 1) {
2096 ShowVehicleListWindow(v);
2103 default: NOT_REACHED();
2125 void OnDropdownSelect(
WidgetID widget,
int index)
override
2129 this->UpdateVehicleGroupBy(
static_cast<GroupBy
>(index));
2141 assert(!this->vehicles.empty());
2152 case ADI_CREATE_GROUP:
2156 default: NOT_REACHED();
2160 default: NOT_REACHED();
2168 StationID station = (this->
vli.
type == VL_STATION_LIST) ? this->
vli.
index : INVALID_STATION;
2170 Debug(misc, 3,
"Periodic resort {} list company {} at station {}", this->
vli.
vtype, this->owner, station);
2185 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2187 if (!gui_scope &&
HasBit(data, 31) && this->
vli.
type == VL_SHARED_ORDERS) {
2190 this->window_number = this->
vli.
Pack();
2204 static WindowDesc _vehicle_list_other_desc(__FILE__, __LINE__,
2205 WDP_AUTO,
"list_vehicles", 260, 246,
2208 std::begin(_nested_vehicle_list), std::end(_nested_vehicle_list)
2211 static WindowDesc _vehicle_list_train_desc(__FILE__, __LINE__,
2212 WDP_AUTO,
"list_vehicles_train", 325, 246,
2215 std::begin(_nested_vehicle_list), std::end(_nested_vehicle_list)
2224 AllocateWindowDescFront<VehicleListWindow>(&_vehicle_list_train_desc, num);
2227 AllocateWindowDescFront<VehicleListWindow>(&_vehicle_list_other_desc, num);
2241 ShowVehicleListWindowLocal(company, VL_STANDARD, vehicle_type, company);
2245 void ShowVehicleListWindow(
const Vehicle *v)
2252 ShowVehicleListWindowLocal(company, VL_STATION_LIST, vehicle_type, station);
2257 uint16_t depot_airport_index;
2264 ShowVehicleListWindowLocal(company, VL_DEPOT_LIST, vehicle_type, depot_airport_index);
2292 SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2309 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_VD_MATRIX),
SetResize(1, 1),
SetMinimalSize(393, 45),
SetMatrixDataTip(1, 0, STR_NULL),
SetFill(1, 0),
SetScrollbar(
WID_VD_SCROLLBAR),
2318 SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
2325 SetDataTip(STR_VEHICLE_DETAIL_TAB_INFORMATION, STR_VEHICLE_DETAILS_TRAIN_INFORMATION_TOOLTIP),
SetFill(1, 0),
SetResize(1, 0),
2329 SetDataTip(STR_VEHICLE_DETAIL_TAB_TOTAL_CARGO, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CARGO_TOOLTIP),
SetFill(1, 0),
SetResize(1, 0),
2341 static StringID _service_interval_dropdown_calendar[] = {
2342 STR_VEHICLE_DETAILS_DEFAULT,
2343 STR_VEHICLE_DETAILS_DAYS,
2344 STR_VEHICLE_DETAILS_PERCENT,
2348 static StringID _service_interval_dropdown_wallclock[] = {
2349 STR_VEHICLE_DETAILS_DEFAULT,
2350 STR_VEHICLE_DETAILS_MINUTES,
2351 STR_VEHICLE_DETAILS_PERCENT,
2378 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2385 if (!gui_scope)
return;
2391 if (aimed_height != nwid_info->
current_y) {
2404 uint desired_height;
2409 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
2415 return desired_height;
2426 static const StringID info_strings[] = {
2427 STR_VEHICLE_INFO_MAX_SPEED,
2428 STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED,
2429 STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE,
2430 STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_MIN_PERFORMANCE,
2431 STR_VEHICLE_INFO_PROFIT_THIS_PERIOD_LAST_PERIOD_MIN_PERFORMANCE,
2432 STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS
2434 for (uint i = 0; i <
lengthof(info_strings); i++) {
2439 size->width = dim.width + padding.width;
2466 size->height = 4 *
resize->height;
2471 for (
const StringID *strs : {_service_interval_dropdown_calendar, _service_interval_dropdown_wallclock}) {
2476 d.width += padding.width;
2477 d.height += padding.height;
2478 *size =
maxdim(*size, d);
2487 SetDParam(1, STR_VEHICLE_DETAILS_LAST_SERVICE_MINUTES_AGO);
2491 SetDParam(1, STR_VEHICLE_DETAILS_LAST_SERVICE_DATE);
2495 size->width = std::max(
2508 switch (vehicle_type) {
2509 default: NOT_REACHED();
2533 default: NOT_REACHED();
2537 void SetStringParameters(
WidgetID widget)
const override
2542 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2552 SetDParam(0, (v->
age + CalendarTime::DAYS_IN_YEAR < v->max_age) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED);
2569 string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED;
2571 string = STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE;
2579 string = STR_VEHICLE_INFO_MAX_SPEED_TYPE_RANGE;
2581 string = STR_VEHICLE_INFO_MAX_SPEED_TYPE;
2584 string = STR_VEHICLE_INFO_MAX_SPEED;
2604 DrawString(tr, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS);
2641 SetDParam(1, STR_VEHICLE_DETAILS_LAST_SERVICE_MINUTES_AGO);
2644 v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_MINUTES);
2649 SetDParam(1, STR_VEHICLE_DETAILS_LAST_SERVICE_DATE);
2652 v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS);
2674 !v->ServiceIntervalIsCustom() ? STR_VEHICLE_DETAILS_DEFAULT :
2675 v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT :
2682 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
2697 if (mod == v->GetServiceInterval())
return;
2707 v->ServiceIntervalIsCustom() ? (v->ServiceIntervalIsPercent() ? 2 : 1) : 0, widget, 0, 0);
2727 bool OnTooltip([[maybe_unused]]
Point pt,
WidgetID widget, TooltipCloseCondition close_cond)
override
2732 if (v->ServiceIntervalIsPercent()) {
2733 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_PERCENT : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_PERCENT;
2735 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_MINUTES : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_MINUTES;
2737 tool_tip = widget ==
WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_DAYS : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_DAYS;
2746 void OnDropdownSelect(
WidgetID widget,
int index)
override
2751 bool iscustom = index != 0;
2752 bool ispercent = iscustom ? (index == 2) :
Company::Get(v->
owner)->settings.vehicle.servint_ispercent;
2763 if (nwi !=
nullptr) {
2771 WDP_AUTO,
"view_vehicle_details_train", 405, 178,
2779 WDP_AUTO,
"view_vehicle_details", 405, 113,
2821 SetDataTip(SPR_IGNORE_SIGNALS, STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP),
2825 SetDataTip(SPR_FORCE_VEHICLE_TURN, STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP),
2855 static const int VV_INITIAL_VIEWPORT_WIDTH = 226;
2856 static const int VV_INITIAL_VIEWPORT_HEIGHT = 84;
2857 static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102;
2861 VCT_CMD_START_STOP = 0,
2863 VCT_CMD_TURN_AROUND,
2869 STR_ERROR_CAN_T_STOP_START_TRAIN,
2870 STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE,
2871 STR_ERROR_CAN_T_STOP_START_SHIP,
2872 STR_ERROR_CAN_T_STOP_START_AIRCRAFT
2875 STR_ERROR_CAN_T_BUY_TRAIN,
2876 STR_ERROR_CAN_T_BUY_ROAD_VEHICLE,
2877 STR_ERROR_CAN_T_BUY_SHIP,
2878 STR_ERROR_CAN_T_BUY_AIRCRAFT
2881 STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN,
2882 STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN,
2895 if (result.
Failed())
return;
2942 bool mouse_over_start_stop =
false;
2973 static const SpriteID vehicle_view_goto_depot_sprites[] = {
2974 SPR_SEND_TRAIN_TODEPOT,
2975 SPR_SEND_ROADVEH_TODEPOT,
2976 SPR_SEND_SHIP_TODEPOT,
2977 SPR_SEND_AIRCRAFT_TODEPOT,
2980 this->GetWidget<NWidgetCore>(
WID_VV_GOTO_DEPOT)->widget_data = vehicle_view_goto_depot_sprites[v->
type];
2983 static const SpriteID vehicle_view_clone_sprites[] = {
2989 this->GetWidget<NWidgetCore>(
WID_VV_CLONE)->widget_data = vehicle_view_clone_sprites[v->
type];
2993 this->GetWidget<NWidgetCore>(
WID_VV_TURN_AROUND)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP;
3004 default: NOT_REACHED();
3010 this->GetWidget<NWidgetCore>(
WID_VV_START_STOP)->tool_tip = STR_VEHICLE_VIEW_TRAIN_STATUS_START_STOP_TOOLTIP + v->
type;
3011 this->GetWidget<NWidgetCore>(
WID_VV_RENAME)->tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v->
type;
3012 this->GetWidget<NWidgetCore>(
WID_VV_LOCATION)->tool_tip = STR_VEHICLE_VIEW_TRAIN_CENTER_TOOLTIP + v->
type;
3013 this->GetWidget<NWidgetCore>(
WID_VV_REFIT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP + v->
type;
3014 this->GetWidget<NWidgetCore>(
WID_VV_GOTO_DEPOT)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP + v->
type;
3015 this->GetWidget<NWidgetCore>(
WID_VV_SHOW_ORDERS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP + v->
type;
3016 this->GetWidget<NWidgetCore>(
WID_VV_SHOW_DETAILS)->tool_tip = STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP + v->
type;
3017 this->GetWidget<NWidgetCore>(
WID_VV_CLONE)->tool_tip = STR_VEHICLE_VIEW_CLONE_TRAIN_INFO + v->
type;
3019 this->UpdateButtonStatus();
3022 void Close([[maybe_unused]]
int data = 0)
override
3047 size->width = VV_INITIAL_VIEWPORT_WIDTH;
3048 size->height = (v->
type ==
VEH_TRAIN) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT;
3078 void SetStringParameters(
WidgetID widget)
const override
3086 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
3094 str = STR_VEHICLE_STATUS_CRASHED;
3096 str = STR_VEHICLE_STATUS_BROKEN_DOWN;
3101 str = STR_VEHICLE_STATUS_TRAIN_NO_POWER;
3103 str = STR_VEHICLE_STATUS_STOPPED;
3107 str = STR_VEHICLE_STATUS_TRAIN_STOPPING_VEL;
3110 str = STR_VEHICLE_STATUS_STOPPED;
3113 str = STR_VEHICLE_STATUS_TRAIN_STUCK;
3115 str = STR_VEHICLE_STATUS_AIRCRAFT_TOO_FAR;
3117 str = STR_VEHICLE_STATUS_WAITING_UNBUNCHING;
3119 if (mouse_over_start_stop) {
3127 case OT_GOTO_STATION: {
3134 case OT_GOTO_DEPOT: {
3157 str = STR_VEHICLE_STATUS_LOADING_UNLOADING;
3160 case OT_GOTO_WAYPOINT: {
3168 case OT_LEAVESTATION:
3170 str = STR_VEHICLE_STATUS_LEAVING;
3176 str = STR_VEHICLE_STATUS_NO_ORDERS_VEL;
3190 DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl),
SA_CENTER);
3195 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
3248 ShowOrdersWindow(v);
3296 void OnQueryTextFinished(
char *str)
override
3298 if (str ==
nullptr)
return;
3303 void OnMouseOver([[maybe_unused]]
Point pt,
WidgetID widget)
override
3306 if (start_stop != mouse_over_start_stop) {
3307 mouse_over_start_stop = start_stop;
3320 void UpdateButtonStatus()
3350 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
3358 this->UpdateButtonStatus();
3371 static inline HotkeyList hotkeys{
"vehicleview", {
3378 WDP_AUTO,
"view_vehicle", 250, 116,
3382 &VehicleViewWindow::hotkeys
3390 WDP_AUTO,
"view_vehicle_train", 250, 134,
3394 &VehicleViewWindow::hotkeys
3410 assert(v !=
nullptr);
3425 bool VehicleClicked(VehicleList::const_iterator begin, VehicleList::const_iterator end)
3427 assert(begin != end);
3446 void StopGlobalFollowVehicle(
const Vehicle *v)
3463 if (result.
Failed())
return;
3501 int vehicle_width = 0;
3502 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
3505 return vehicle_width;
3521 int total_width = 0;
3523 bool rotor_seq =
false;
3526 while (v !=
nullptr) {
3527 if (total_width >=
ScaleSpriteTrad(2 * (
int)VEHICLEINFO_FULL_VEHICLE_WIDTH))
break;
3534 if (!seq.
IsValid()) seq.
Set(SPR_ROTOR_STOPPED);
3545 for (uint i = 0; i < seq.count; ++i) {
3563 if (is_ground_vehicle) {
3565 int offs = (
ScaleSpriteTrad(VEHICLEINFO_FULL_VEHICLE_WIDTH) - total_width) / 2;
3566 if (rtl) offs = -offs;
@ VEH_AIRCRAFT
Aircraft vehicle type.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a train vehicle image in the GUI.
static bool IsVehicleRefitable(const Vehicle *v)
Checks whether the vehicle may be refitted at the moment.
VehicleListType
Vehicle List type flags.
static void DrawVehicleDetails(const Vehicle *v, const Rect &r, int vscroll_pos, uint vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the position of the Details windows.
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
@ TC_FORCED
Ignore colour changes from strings.
@ BP_HIDE_BUTTONS
Show the empty panel.
void OnPaint() override
The window must be repainted.
@ SEL_RT_TURN_AROUND
Display 'turn around' button in WID_VV_SELECT_REFIT_TURN stacked widget.
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
uint CountDigitsForAllocatingSpace(uint number)
Get the number of digits of space required for the given number.
static bool VehicleGroupLengthSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the number of vehicles in the group.
virtual bool OnVehicleSelect([[maybe_unused]] const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
@ WC_INVALID
Invalid window.
void SetCargoFilter(byte index)
Set cargo filter for the vehicle group list.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
bool IsType(OrderType type) const
Check whether this order is of the given type.
std::vector< const Vehicle * > VehicleList
A list of vehicles.
static Titem * Get(size_t index)
Returns Titem with given index.
PlaneSelections
Display planes available in the vehicle view window.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
@ BP_SHOW_BUTTONS
Show the buttons.
uint GetRoadVehDetailsHeight(const Vehicle *v)
Gets the desired height for the road vehicle details panel.
@ TDW_TAB_CAPACITY
Tab with cargo capacity of the vehicles.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
List of hotkeys for a window.
bool show_cargo_in_vehicle_lists
Show the cargoes the vehicles can carry in the list windows.
CompanyID company
The company associated with this list.
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Money value
Value of the vehicle.
static void DrawVehicleRefitWindow(const RefitOptions &refits, const RefitOption *sel, uint pos, uint rows, uint delta, const Rect &r)
Draw the list of available refit options for a consist and highlight the selected refit option (if an...
Dimensions (a width and height) of a rectangle in 2D.
void OnResize() override
Called after the window got resized.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
uint sprite_count
number of sprites to draw
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create)
Display the Action dropdown window.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
int click_x
Position of the first click while dragging.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
void SetFilterState(bool state)
Enable or disable the filter.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
GroupBy grouping
How we want to group the list.
static bool VehicleGroupTotalProfitThisYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the total profit this year.
The information about a vehicle list.
uint16_t cargo_cap
total capacity
@ CBID_VEHICLE_CARGO_SUFFIX
Determine the cargo "suffixes" for each refit possibility of a cargo.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Vehicle * Next() const
Get the next vehicle of this vehicle.
T * Next() const
Get next vehicle in the chain.
uint information_width
Width required for correctly displaying all cargoes in the information panel.
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
DestinationID GetDestination() const
Gets the destination of this order.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
VehicleID selected_vehicle
First vehicle in the current selection.
uint order_arrow_width
Width of the arrow in the small order list.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
void DrawTrainDetails(const Train *v, const Rect &r, int vscroll_pos, uint16_t vscroll_cap, TrainDetailsWindowTabs det_tab)
Draw the details for the given vehicle at the given position.
VehicleDetailsWindow(WindowDesc *desc, WindowNumber window_number)
Initialize a newly created vehicle details window.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
uint32_t cached_weight
Total weight of the consist (valid only for the first engine).
ViewportData * viewport
Pointer to viewport data, if present.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
static bool CargoFilterSingle(const Vehicle *v, const CargoID cid)
Check whether a single vehicle should pass the filter.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
std::string name
Name of vehicle.
void OnPaint() override
The window must be repainted.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint8_t advanced_vehicle_list
use the "advanced" vehicle list
void DrawShipDetails(const Vehicle *v, const Rect &r)
Draw the details for the given vehicle at the given position.
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
Draw the details for the given vehicle at the given position.
Class for storing amounts of cargo.
SpriteID sprite
The 'real' sprite.
GroupID group_id
Index of group Pool array.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
const RefitOption * selected_refit
Selected refit option.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Listing * sorting
Pointer to the vehicle type related sorting.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
byte subtype
Subcargo to use.
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group=INVALID_GROUP, bool need_existing_window=false)
Show the group window for the given company and vehicle type.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
static const ZoomLevel _vehicle_view_zoom_levels[]
Zoom levels for vehicle views indexed by vehicle type.
@ SEL_DC_BASEPLANE
First plane of the WID_VV_SELECT_DEPOT_CLONE stacked widget.
bool _ctrl_pressed
Is Ctrl pressed?
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
uint GetStringListWidth(const StringID *list, FontSize fontsize)
Get maximum width of a list of strings.
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
void SelectPlane(PlaneSelections plane)
Display a plane in the window.
VehicleCommandTranslation
Command indices for the _vehicle_command_translation_table.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
uint GetUnitNumberDigits(VehicleList &vehicles)
Get the number of digits the biggest unit number of a set of vehicles has.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
VehicleList::const_iterator vehicles_begin
Pointer to beginning element of this vehicle group.
ZoomLevel
All zoom levels we know.
TrainDetailsWindowTabs tab
For train vehicles: which tab is displayed.
ClientSettings _settings_client
The current settings for this game.
void ChangeVehicleViewWindow(VehicleID from_index, VehicleID to_index)
Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.
@ EIT_IN_DETAILS
Vehicle drawn in vehicle details, refit window, ...
WindowClass cls
Class of the window,.
Specification of a cargo type.
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Rect Expand(int s) const
Copy and expand Rect by s pixels.
EngineImageType
Visualisation contexts of vehicles and engines.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
@ CBM_VEHICLE_CARGO_SUFFIX
Show suffix after cargo name.
@ TDW_TAB_INFO
Tab with name and value of the vehicles.
@ VEH_ROAD
Road vehicle type.
@ CC_PASSENGERS
Passengers.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Owner owner
Which company owns the vehicle?
Owner
Enum for all companies/owners.
static bool VehicleGroupTotalProfitLastYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the total profit last year.
void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8_t num_vehicles)
Calculates the set of vehicles that will be affected by a given selection.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
uint32_t PaletteID
The number of the palette.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
static const GroupID NEW_GROUP
Sentinel for a to-be-created group.
debug_inline bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
static bool VehicleAgeSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their age.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Point sprite_pos[16]
relative position of individual sprites
Window for the (old) vehicle listing.
static WindowDesc _nontrain_vehicle_details_desc(__FILE__, __LINE__, WDP_AUTO, "view_vehicle_details", 405, 113, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, std::begin(_nested_nontrain_vehicle_details_widgets), std::end(_nested_nontrain_vehicle_details_widgets))
Vehicle details window descriptor for other vehicles than a train.
bool NeedRebuild() const
Check if a rebuild is needed.
uint GetVehicleHeight(VehicleType type)
Get the height of a single vehicle in the GUIs.
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
@ ODATFB_UNBUNCH
Service the vehicle and then unbunch it.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
int sprite_left
Left position of the vehicle sprite.
static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type, CompanyID company_id)
Checks whether service interval is enabled for the vehicle.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
int32_t x_pos
x coordinate.
bool auto_refit
Select cargo for auto-refitting.
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
void OnResize() override
Called after the window got resized.
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
OrderType GetType() const
Get the type of order of this order.
void OnInit() override
Notification that the nested widget tree gets initialized.
@ Service
The vehicle will leave the depot right after arrival (service only)
Aircraft, helicopters, rotors and their shadows belong to this class.
void UpdateCursorSize()
Update cursor dimension.
static const GroupID ALL_GROUP
All vehicles are in this group.
High level window description.
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
virtual void GetImage([[maybe_unused]] Direction direction, [[maybe_unused]] EngineImageType image_type, [[maybe_unused]] VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
void FilterVehicleList()
Filter the engine list against the currently selected cargo filter.
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
uint8_t train_acceleration_model
realistic acceleration for trains
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
uint16_t GetServiceIntervalClamped(int interval, bool ispercent)
Clamp the service interval to the correct min/max.
static void ShowVehicleDetailsWindow(const Vehicle *v)
Shows the vehicle details window of the given vehicle.
byte breakdown_ctr
Counter for managing breakdown events.
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
bool IsValid() const
Check whether the sequence contains any sprites.
@ EF_AUTO_REFIT
Automatic refitting is allowed.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
@ WDP_AUTO
Find a place automatically.
virtual int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
Cached, frequently calculated values.
static constexpr int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
ResizeInfo resize
Resize information.
Common return value for all commands.
void OnPaint() override
The window must be repainted.
void CcStartStopVehicle(Commands, const CommandCost &result, VehicleID veh_id, bool)
This is the Callback method after attempting to start/stop a vehicle.
@ VRF_TRAIN_STUCK
Train can't get a path reservation.
@ SEL_DC_GOTO_DEPOT
Display 'goto depot' button in WID_VV_SELECT_DEPOT_CLONE stacked widget.
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
int32_t WindowNumber
Number to differentiate different windows of the same class.
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
@ FS_NORMAL
Index of the normal font in the font tables.
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
void StartStopVehicle(const Vehicle *v, bool texteffect)
Executes CMD_START_STOP_VEHICLE for given vehicle.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
void ShowCompanyGroupForVehicle(const Vehicle *v)
Show the group window for the given vehicle.
static bool CargoFilter(const GUIVehicleGroup *vehgroup, const CargoID cid)
Check whether a vehicle can carry a specific cargo.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
@ VEH_COMPANY_END
Last company-ownable type.
WindowNumber window_number
The WindowNumber of the window that is responsible for the selection mode.
int height
Height of the window (number of pixels down in y direction)
uint8_t num_vehicles
Number of selected vehicles.
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
static bool VehicleModelSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by model.
TileIndex tile
Current tile index.
static bool VehicleGroupAverageProfitLastYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the average profit last year.
static bool VehicleProfitThisYearSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by this year profit.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
@ ZOOM_LVL_ROADVEH
Default zoom level for the road vehicle view.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
@ MassSend
Tells that it's a mass send to depot command (type in VLW flag)
EngineID engine_type
The type of engine used for this vehicle.
bool operator!=(const RefitOption &other) const
Inequality operator for RefitOption.
@ BP_NORMAL
Show shared orders caption and buttons.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
@ VS_CRASHED
Vehicle is crashed.
@ FS_SMALL
Index of the small font in the font tables.
uint32_t index
A vehicle list type specific index.
Sprite sequence for a vehicle part.
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
static bool VehicleMaxSpeedSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their max speed.
bool Failed() const
Did this command fail?
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
Order current_order
The current order (+ status, like: loading)
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
CargoTypes _cargo_mask
Bitmask of cargo types available.
void CcAddVehicleNewGroup(Commands cmd, const CommandCost &result, GroupID new_group, GroupID, VehicleID veh_id, bool, const VehicleListIdentifier &)
Open rename window after adding a vehicle to a new group via drag and drop.
void CcBuildPrimaryVehicle(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
Scrollbar * vscroll
The main scrollbar.
static const SpriteID SPR_CLONE_TRAIN
Clone vehicles stuff.
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
static constexpr Year DateToYear(Date date)
Calculate the year of a given date.
@ BP_SHARED_ORDERS
Show the normal caption.
uint16_t cur_speed
current speed
static bool VehicleTimetableDelaySorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by the timetable delay.
static WindowDesc _vehicle_view_desc(__FILE__, __LINE__, WDP_AUTO, "view_vehicle", 250, 116, WC_VEHICLE_VIEW, WC_NONE, 0, std::begin(_nested_vehicle_view_widgets), std::end(_nested_vehicle_view_widgets), &VehicleViewWindow::hotkeys)
Vehicle view window descriptor for all vehicles but trains.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Scrollbar * hscroll
Only used for long vehicles.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
@ SEL_DC_CLONE
Display 'clone vehicle' button in WID_VV_SELECT_DEPOT_CLONE stacked widget.
ButtonPlanes
Enumeration of planes of the button row at the bottom.
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
@ ZOOM_LVL_AIRCRAFT
Default zoom level for the aircraft view.
uint32_t Pack() const
Pack a VehicleListIdentifier in a single uint32.
@ VS_STOPPED
Vehicle is stopped by the player.
Window * parent
Parent window.
bool IsDescSortOrder() const
Check if the sort order is descending.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
DropDownList BuildCargoDropDownList(bool full) const
Build drop down list for cargo filter selection.
bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli)
Generate a list of vehicles based on window type.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
int left
x position of left edge of the window
static bool VehicleGroupAverageProfitThisYearSorter(const GUIVehicleGroup &a, const GUIVehicleGroup &b)
Sort vehicle groups by the average profit this year.
WindowFlags flags
Window flags.
'Train' is either a loco or a wagon.
static void DrawSmallOrderList(const Order *order, int left, int right, int y, uint order_arrow_width)
Draw small order list in the vehicle GUI, but without the little black arrow.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
virtual void PlayLeaveStationSound([[maybe_unused]] bool force=false) const
Play the sound associated with leaving the station.
WindowClass
Window classes.
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
Set the mouse cursor to look like a vehicle.
uint16_t servint_aircraft
service interval for aircraft
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
CaptionPlanes
Enumeration of planes of the title row at the top.
uint32_t VehicleID
The type all our vehicle IDs have.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
void DrawAircraftDetails(const Aircraft *v, const Rect &r)
Draw the details for the given vehicle at the given position.
@ ZOOM_LVL_SHIP
Default zoom level for the ship view.
Default settings for vehicles.
void OnResize() override
Called after the window got resized.
static constexpr NWidgetPart _nested_train_vehicle_details_widgets[]
Train details widgets.
Coordinates of a point in 2D.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
@ SEL_RT_BASEPLANE
First plane of the WID_VV_SELECT_REFIT_TURN stacked widget.
@ WC_TRAINS_LIST
Trains list; Window numbers:
static constexpr TimerGame< struct Economy >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
Get the width of a vehicle (part) in pixels.
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create)
Compute the size for the Action dropdown.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
int sprite_right
Right position of the vehicle sprite.
void DrawRoadVehImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a road vehicle chain.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
RefitOptions refit_list
List of refit subtypes available for each sorted cargo.
WindowNumber window_number
Window number within the window class.
VehicleType
Available vehicle types.
static void ChangeVehicleWindow(WindowClass window_class, VehicleID from_index, VehicleID to_index)
Assign a vehicle window a new vehicle.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
DepotID GetDepotIndex(Tile t)
Get the index of which depot is attached to the tile.
static bool VehicleValueSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their value.
VehicleOrderID order
If not INVALID_VEH_ORDER_ID, selection is part of a refit order (rather than execute directly).
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
byte misc_flags
Miscellaneous flags.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
static constexpr NWidgetPart _nested_vehicle_view_widgets[]
Vehicle view widgets.
@ SA_HOR_CENTER
Horizontally center the text.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
StringID string
GRF-local String to display for the cargo.
@ SEL_RT_REFIT
Display 'refit' button in WID_VV_SELECT_REFIT_TURN stacked widget.
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
@ ODATFB_HALT
Service the vehicle and then halt it.
@ WC_VEHICLE_REFIT
Vehicle refit; Window numbers:
int32_t z_pos
z coordinate.
CargoID cargo_filter_criteria
Selected cargo filter index.
@ HT_VEHICLE
vehicle is accepted as target as well (bitmask)
StringID GetCargoSubtypeText(const Vehicle *v)
Get the cargo subtype text from NewGRF for the vehicle details window.
@ HT_DRAG
dragging items in the depot windows
@ VIWD_CONSIST_CHANGED
Vehicle composition was changed.
static bool VehicleLengthSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their length.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
uint8_t roadveh_acceleration_model
realistic acceleration for road vehicles
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
HighLightStyle place_mode
Method which is used to place the selection.
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
bool operator==(const RefitOption &other) const
Equality operator for RefitOption.
void ForceRebuild()
Force that a rebuild is needed.
@ VAF_DEST_TOO_FAR
Next destination is too far away.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ SBS_DOWN
Sort ascending.
VehicleCache vcache
Cache of often used vehicle values.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
@ EIT_IN_LIST
Vehicle drawn in vehicle list, group list, ...
CompanyID _current_company
Company currently doing an action.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
void RefreshScrollbar()
Refresh scrollbar after selection changed.
Class for managing the vehicle details window.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
Get the width of a vehicle (including all parts of the consist) in pixels.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
Show a drop down list.
TimerGameCalendar::Date max_age
Maximum age.
static constexpr Date DateAtStartOfYear(Year year)
Calculate the date of the first day of a given year.
uint vehicle_margin
Margin to use while selecting vehicles when the vehicle image is centered.
bool CanCarryCargo() const
Determines whether an engine can carry something.
void OnPaint() override
Repaint vehicle details window.
static void DrawVehicleProfitButton(TimerGameCalendar::Date age, Money display_profit_last_year, uint num_vehicles, int x, int y)
draw the vehicle profit button in the vehicle list window.
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
Listing GetListing() const
Export current sort conditions.
static constexpr int MONTHS_IN_YEAR
months per year
GUIVehicleGroupList vehgroups
List of (groups of) vehicles. This stores iterators of vehicles, and should be rebuilt if vehicles is...
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
PaletteID GetVehiclePalette(const Vehicle *v)
Get the colour map for a vehicle.
static WindowDesc _train_view_desc(__FILE__, __LINE__, WDP_AUTO, "view_vehicle_train", 250, 134, WC_VEHICLE_VIEW, WC_NONE, 0, std::begin(_nested_vehicle_view_widgets), std::end(_nested_vehicle_view_widgets), &VehicleViewWindow::hotkeys)
Vehicle view window descriptor for trains.
VehicleType vtype
The vehicle type associated with this list.
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
@ VIWD_AUTOREPLACE
Autoreplace replaced the vehicle.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Window * GetMainWindow()
Get the main window, i.e.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
@ AIR_HELICOPTER
an helicopter
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
VehicleID vehicle_sel
Selected vehicle.
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
uint16_t reliability
Reliability.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
@ OWNER_NONE
The tile has no ownership.
VehicleListType type
The type of vehicle list.
StringID GetCapacityString(const RefitOption &option) const
Gets the StringID to use for displaying capacity.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
void CcCloneVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id)
This is the Callback method after the cloning attempt of a vehicle.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
TimerGameCalendar::Date age
Age in days.
static WindowDesc _train_vehicle_details_desc(__FILE__, __LINE__, WDP_AUTO, "view_vehicle_details_train", 405, 178, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, std::begin(_nested_train_vehicle_details_widgets), std::end(_nested_train_vehicle_details_widgets))
Vehicle details window descriptor.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
EventState
State of handling an event.
static bool VehicleNumberSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their number.
TrainDetailsWindowTabs
The tabs in the train details window.
static bool VehicleCargoSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their cargo.
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
StringID name
Name of this type of cargo.
static constexpr NWidgetPart _nested_nontrain_vehicle_details_widgets[]
Vehicle details widgets (other than train).
@ TE_RISING
Make the text effect slowly go upwards.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
UnitID unitnumber
unit number, for display purposes only
static bool VehicleTimeToLiveSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by the time they can still live.
uint16_t servint_trains
service interval for trains
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
int32_t y_pos
y coordinate.
@ ZOOM_LVL_TRAIN
Default zoom level for the train view.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Window manager class for viewing a vehicle.
uint32_t cached_power
Total power of the consist (valid only for the first engine).
@ SA_LEFT
Left align the text.
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
uint16_t servint_ships
service interval for ships
Order * GetFirstOrder() const
Get the first order of the order chain.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
std::map< CargoID, std::vector< RefitOption >, CargoIDComparator > RefitOptions
Available refit options (subtype and string) associated with each cargo type.
uint8_t SortType() const
Get the sorttype of the list.
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
VehicleList vehicles
List of vehicles. This is the buffer for vehgroups to point into; if this is structurally modified,...
@ SA_CENTER
Center both horizontally and vertically.
PalSpriteID sprite_seq[16]
current image of cursor
void DrawShipImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
Draws an image of a ship.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
ZoomLevel zoom
The zoom level of the viewport.
Comparator to sort CargoID by according to desired order.
void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
@ VF_PATHFINDER_LOST
Vehicle's pathfinder is lost.
WindowClass window_class
The WindowClass of the window that is responsible for the selection mode.
bool CDECL FilterFunction(const GUIVehicleGroup *, CargoID)
Signature of filter function.
CargoID cargo
Cargo to refit to.
static bool VehicleNameSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their name.
byte CargoID
Cargo slots to indicate a cargo type within a game.
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
@ TFP_SIGNAL
Ignore next signal, after the signal ignore being stuck.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
void DrawVehicleImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip)
Draws an image of a vehicle chain.
int vehicle_width
Width of the vehicle being drawn.
CargoID cargo_type
type of cargo this vehicle is carrying
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
@ TDW_TAB_TOTALS
Tab with sum of total cargo transported.
static const uint MAX_REFIT_CYCLE
Maximum number of refit cycles we try, to prevent infinite loops.
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
static bool VehicleIndividualToGroupSorterWrapper(GUIVehicleGroup const &a, GUIVehicleGroup const &b)
Wrapper to convert a VehicleIndividualSortFunction to a VehicleGroupSortFunction.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
PaletteID pal
The palette (use PAL_NONE) if not needed)
byte unitnumber_digits
The number of digits of the highest unit number.
VehicleSettings vehicle
options for vehicles
uint16_t EngineID
Unique identification number of an engine.
byte cargo_subtype
Used for livery refits (NewGRF variations)
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Data structure for an opened window.
Commands
List of commands.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
void DrawAircraftImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
Draws an image of an aircraft.
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
VehicleType type
Type of vehicle.
void DrawWidgets() const
Paint all widgets of a window.
void BuildRefitList()
Collects all (cargo, subcargo) refit options of a vehicle chain.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
@ DC_QUERY_COST
query cost only, don't build.
static bool VehicleProfitLastYearSorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by last year profit.
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
static constexpr int DAYS_IN_ECONOMY_MONTH
Days in an economy month, when in wallclock timekeeping mode.
static VehicleListIdentifier UnPack(uint32_t data)
Decode a packed vehicle list identifier into a new one.
int Width() const
Get width of Rect.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ VEH_SHIP
Ship vehicle type.
static constexpr CargoID CF_FREIGHT
Show only vehicles which carry any freight (non-passenger) cargo.
Specification of a rectangle with absolute coordinates of all edges.
bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
bool Sort(Comp compare)
Sort the list.
OrderList * orders
Pointer to the order list for this vehicle.
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
void OnInit() override
Notification that the nested widget tree gets initialized.
uint16_t cached_total_length
Length of the whole vehicle (valid only for the first engine).
Order * next
Pointer to next order. If nullptr, end of list.
void SetSelection(uint click_row)
Select a row.
uint16_t servint_roadveh
service interval for road vehicles
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
void OnGameTick() override
Called once per (game) tick.
Option to refit a vehicle chain.
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
static bool VehicleReliabilitySorter(const Vehicle *const &a, const Vehicle *const &b)
Sort vehicles by their reliability.
void SetFilterType(uint8_t n_type)
Set the filtertype of the list.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
static const StringID _vehicle_msg_translation_table[][4]
Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type.
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
VehicleList::const_iterator vehicles_end
Pointer to past-the-end element of this vehicle group.
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
Determines the number of lines in the train details window.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
@ TDW_TAB_CARGO
Tab with cargo carried by the vehicles.
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
GUISettings gui
settings related to the GUI
Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
@ FR_BORDERONLY
Draw border only, no background.
Window * GetCallbackWnd()
Get the window that started the current highlighting.
static const int VEHICLE_PROFIT_MIN_AGE
Only vehicles older than this have a meaningful profit.
void SetListing(Listing l)
Import sort conditions.
uint32_t cached_max_te
Maximum tractive effort of consist (valid only for the first engine).
static const Money VEHICLE_PROFIT_THRESHOLD
Threshold for a vehicle to be considered making good profit.
All data for a single hotkey.
void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
Draws an image of a whole train.
void OnResize() override
Called after the window got resized.
static Date date
Current date in days (day counter).
uint32_t GetDisplayMinPowerToWeight() const
Calculates the minimum power-to-weight ratio using the maximum weight of the ground vehicle.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.