OpenTTD
autoreplace_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "stdafx.h"
13 #include "command_func.h"
14 #include "vehicle_gui.h"
15 #include "newgrf_engine.h"
16 #include "rail.h"
17 #include "road.h"
18 #include "strings_func.h"
19 #include "window_func.h"
20 #include "autoreplace_func.h"
21 #include "company_func.h"
22 #include "engine_base.h"
23 #include "window_gui.h"
24 #include "engine_gui.h"
25 #include "settings_func.h"
26 #include "core/geometry_func.hpp"
27 #include "rail_gui.h"
28 #include "road_gui.h"
29 #include "widgets/dropdown_func.h"
30 
32 
33 #include "safeguards.h"
34 
35 void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
36 
37 static bool EngineNumberSorter(const EngineID &a, const EngineID &b)
38 {
39  return Engine::Get(a)->list_position < Engine::Get(b)->list_position;
40 }
41 
52 {
54  /* We don't have any of this engine type.
55  * Either we just sold the last one, we build a new one or we stopped replacing it.
56  * In all cases, we need to update the left list */
58  }
59 }
60 
66 {
67  InvalidateWindowData(WC_REPLACE_VEHICLE, type, 0); // Update the autoreplace window
68  InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
69 }
70 
71 static const StringID _start_replace_dropdown[] = {
72  STR_REPLACE_VEHICLES_NOW,
73  STR_REPLACE_VEHICLES_WHEN_OLD,
75 };
76 
80 class ReplaceVehicleWindow : public Window {
92  Scrollbar *vscroll[2];
93 
101  bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
102  {
103  const RailVehicleInfo *rvi = RailVehInfo(e);
104 
105  /* Ensure that the wagon/engine selection fits the engine. */
106  if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false;
107 
108  if (draw_left && this->sel_railtype != INVALID_RAILTYPE) {
109  /* Ensure that the railtype is specific to the selected one */
110  if (rvi->railtype != this->sel_railtype) return false;
111  }
112  return true;
113  }
114 
115 
120  void GenerateReplaceVehList(bool draw_left)
121  {
122  EngineID selected_engine = INVALID_ENGINE;
123  VehicleType type = (VehicleType)this->window_number;
124  byte side = draw_left ? 0 : 1;
125 
126  GUIEngineList *list = &this->engines[side];
127  list->clear();
128 
129  const Engine *e;
130  FOR_ALL_ENGINES_OF_TYPE(e, type) {
131  if (!draw_left && !this->show_hidden_engines && e->IsHidden(_local_company)) continue;
132  EngineID eid = e->index;
133  switch (type) {
134  case VEH_TRAIN:
135  if (!this->GenerateReplaceRailList(eid, draw_left, this->replace_engines)) continue; // special rules for trains
136  break;
137 
138  case VEH_ROAD:
139  if (draw_left && this->sel_roadtype != INVALID_ROADTYPE) {
140  /* Ensure that the roadtype is specific to the selected one */
141  if (e->u.road.roadtype != this->sel_roadtype) continue;
142  }
143  break;
144 
145  default:
146  break;
147  }
148 
149  if (draw_left) {
150  const uint num_engines = GetGroupNumEngines(_local_company, this->sel_group, eid);
151 
152  /* Skip drawing the engines we don't have any of and haven't set for replacement */
153  if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue;
154  } else {
155  if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
156  }
157 
158  list->push_back(eid);
159  if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list
160  }
161  this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
162  if (draw_left) {
164  } else {
166  EngList_Sort(list, _engine_sort_functions[this->window_number][this->sort_criteria]);
167  }
168  }
169 
172  {
173  EngineID e = this->sel_engine[0];
174 
175  if (this->engines[0].NeedRebuild()) {
176  /* We need to rebuild the left engines list */
177  this->GenerateReplaceVehList(true);
178  this->vscroll[0]->SetCount((uint)this->engines[0].size());
179  if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].size() != 0) {
180  this->sel_engine[0] = this->engines[0][0];
181  }
182  }
183 
184  if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
185  /* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
186  if (this->sel_engine[0] == INVALID_ENGINE) {
187  /* Always empty the right engines list when nothing is selected in the left engines list */
188  this->engines[1].clear();
189  this->sel_engine[1] = INVALID_ENGINE;
190  } else {
191  if (this->reset_sel_engine && this->sel_engine[0] != INVALID_ENGINE) {
192  /* Select the current replacement for sel_engine[0]. */
193  const Company *c = Company::Get(_local_company);
194  this->sel_engine[1] = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group);
195  }
196  /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
197  this->GenerateReplaceVehList(false);
198  this->vscroll[1]->SetCount((uint)this->engines[1].size());
199  if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
200  int position = 0;
201  for (EngineID &eid : this->engines[1]) {
202  if (eid == this->sel_engine[1]) break;
203  ++position;
204  }
205  this->vscroll[1]->ScrollTowards(position);
206  }
207  }
208  }
209  /* Reset the flags about needed updates */
210  this->engines[0].RebuildDone();
211  this->engines[1].RebuildDone();
212  this->reset_sel_engine = false;
213  }
214 
219  void ReplaceClick_StartReplace(bool replace_when_old)
220  {
221  EngineID veh_from = this->sel_engine[0];
222  EngineID veh_to = this->sel_engine[1];
223  DoCommandP(0, (replace_when_old ? 1 : 0) | (this->sel_group << 16), veh_from + (veh_to << 16), CMD_SET_AUTOREPLACE);
224  }
225 
226 public:
227  ReplaceVehicleWindow(WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
228  {
229  this->sel_railtype = INVALID_RAILTYPE;
230  this->sel_roadtype = INVALID_ROADTYPE;
231  this->replace_engines = true; // start with locomotives (all other vehicles will not read this bool)
232  this->engines[0].ForceRebuild();
233  this->engines[1].ForceRebuild();
234  this->reset_sel_engine = true;
235  this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
236  this->sel_engine[0] = INVALID_ENGINE;
237  this->sel_engine[1] = INVALID_ENGINE;
238  this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype];
239 
240  this->CreateNestedTree();
241  this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR);
242  this->vscroll[1] = this->GetScrollbar(WID_RV_RIGHT_SCROLLBAR);
243 
244  NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_RV_SHOW_HIDDEN_ENGINES);
245  widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype;
246  widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + vehicletype;
247  widget->SetLowered(this->show_hidden_engines);
248  this->FinishInitNested(vehicletype);
249 
250  if (vehicletype == VEH_TRAIN || vehicletype == VEH_ROAD) {
251  widget = this->GetWidget<NWidgetCore>(WID_RV_RAIL_ROAD_TYPE_DROPDOWN);
252  widget->tool_tip = STR_REPLACE_HELP_RAILTYPE + vehicletype;
253  }
254 
255  this->sort_criteria = _engine_sort_last_criteria[vehicletype];
256  this->descending_sort_order = _engine_sort_last_order[vehicletype];
257  this->owner = _local_company;
258  this->sel_group = id_g;
259  }
260 
261  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
262  {
263  switch (widget) {
265  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
266  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
267  d.height += padding.height;
268  *size = maxdim(*size, d);
269  break;
270  }
271 
272  case WID_RV_LEFT_MATRIX:
273  case WID_RV_RIGHT_MATRIX:
274  resize->height = GetEngineListHeight((VehicleType)this->window_number);
275  size->height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize->height;
276  break;
277 
278  case WID_RV_LEFT_DETAILS:
280  size->height = this->details_height;
281  break;
282 
284  StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
285  SetDParam(0, STR_CONFIG_SETTING_ON);
287  SetDParam(0, STR_CONFIG_SETTING_OFF);
288  d = maxdim(d, GetStringBoundingBox(str));
289  d.width += padding.width;
290  d.height += padding.height;
291  *size = maxdim(*size, d);
292  break;
293  }
294 
296  Dimension d = GetStringBoundingBox(STR_REPLACE_ENGINES);
297  d = maxdim(d, GetStringBoundingBox(STR_REPLACE_WAGONS));
298  d.width += padding.width;
299  d.height += padding.height;
300  *size = maxdim(*size, d);
301  break;
302  }
303 
304  case WID_RV_INFO_TAB: {
305  Dimension d = GetStringBoundingBox(STR_REPLACE_NOT_REPLACING);
306  d = maxdim(d, GetStringBoundingBox(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED));
309  *size = maxdim(*size, d);
310  break;
311  }
312 
314  Dimension d = {0, 0};
315  switch (this->window_number) {
316  case VEH_TRAIN:
317  for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
318  const RailtypeInfo *rti = GetRailTypeInfo(rt);
319  /* Skip rail type if it has no label */
320  if (rti->label == 0) continue;
322  }
323  break;
324 
325  case VEH_ROAD:
326  for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
327  const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
328  /* Skip road type if it has no label */
329  if (rti->label == 0) continue;
331  }
332  break;
333 
334  default: NOT_REACHED();
335  }
336  d.width += padding.width;
337  d.height += padding.height;
338  *size = maxdim(*size, d);
339  break;
340  }
341 
342  case WID_RV_START_REPLACE: {
343  Dimension d = GetStringBoundingBox(STR_REPLACE_VEHICLES_START);
344  for (int i = 0; _start_replace_dropdown[i] != INVALID_STRING_ID; i++) {
345  d = maxdim(d, GetStringBoundingBox(_start_replace_dropdown[i]));
346  }
347  d.width += padding.width;
348  d.height += padding.height;
349  *size = maxdim(*size, d);
350  break;
351  }
352  }
353  }
354 
355  void SetStringParameters(int widget) const override
356  {
357  switch (widget) {
358  case WID_RV_CAPTION:
359  SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
360  switch (this->sel_group) {
361  case ALL_GROUP:
362  SetDParam(1, STR_GROUP_ALL_TRAINS + this->window_number);
363  break;
364 
365  case DEFAULT_GROUP:
366  SetDParam(1, STR_GROUP_DEFAULT_TRAINS + this->window_number);
367  break;
368 
369  default:
370  SetDParam(1, STR_GROUP_NAME);
371  SetDParam(2, sel_group);
372  break;
373  }
374  break;
375 
378  break;
379 
381  const Company *c = Company::Get(_local_company);
382  SetDParam(0, c->settings.renew_keep_length ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
383  break;
384  }
385 
387  SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
388  break;
389  }
390  }
391 
392  void DrawWidget(const Rect &r, int widget) const override
393  {
394  switch (widget) {
397  break;
398 
399  case WID_RV_INFO_TAB: {
400  const Company *c = Company::Get(_local_company);
401  StringID str;
402  if (this->sel_engine[0] != INVALID_ENGINE) {
403  if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) {
404  str = STR_REPLACE_NOT_REPLACING;
405  } else {
406  bool when_old = false;
407  EngineID e = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group, &when_old);
408  str = when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME;
409  SetDParam(0, e);
410  }
411  } else {
412  str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED;
413  }
414 
415  DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, str, TC_BLACK, SA_HOR_CENTER);
416  break;
417  }
418 
419  case WID_RV_LEFT_MATRIX:
420  case WID_RV_RIGHT_MATRIX: {
421  int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
422  EngineID start = this->vscroll[side]->GetPosition(); // what is the offset for the start (scrolling)
423  EngineID end = min(this->vscroll[side]->GetCapacity() + start, (uint)this->engines[side].size());
424 
425  /* Do the actual drawing */
427  &this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
428  break;
429  }
430  }
431  }
432 
433  void OnPaint() override
434  {
435  if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
436 
438 
439  /* Disable the "Start Replacing" button if:
440  * Either engines list is empty
441  * or The selected replacement engine has a replacement (to prevent loops). */
444 
445  /* Disable the "Stop Replacing" button if:
446  * The left engines list (existing vehicle) is empty
447  * or The selected vehicle has no replacement set up */
449 
450  switch (this->window_number) {
451  case VEH_TRAIN:
452  /* Show the selected railtype in the pulldown menu */
453  this->GetWidget<NWidgetCore>(WID_RV_RAIL_ROAD_TYPE_DROPDOWN)->widget_data = sel_railtype == INVALID_RAILTYPE ? STR_REPLACE_ALL_RAILTYPE : GetRailTypeInfo(sel_railtype)->strings.replace_text;
454  break;
455 
456  case VEH_ROAD:
457  /* Show the selected roadtype in the pulldown menu */
458  this->GetWidget<NWidgetCore>(WID_RV_RAIL_ROAD_TYPE_DROPDOWN)->widget_data = sel_roadtype == INVALID_ROADTYPE ? STR_REPLACE_ALL_ROADTYPE : GetRoadTypeInfo(sel_roadtype)->strings.replace_text;
459  break;
460 
461  default: break;
462  }
463 
464  this->DrawWidgets();
465 
466  if (!this->IsShaded()) {
467  int needed_height = this->details_height;
468  /* Draw details panels. */
469  for (int side = 0; side < 2; side++) {
470  if (this->sel_engine[side] != INVALID_ENGINE) {
471  /* Use default engine details without refitting */
472  const Engine *e = Engine::Get(this->sel_engine[side]);
474  ted.cost = 0;
475  ted.cargo = e->GetDefaultCargoType();
477 
478  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS);
480  nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side], ted);
481  needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
482  }
483  }
484  if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
485  this->details_height = needed_height;
486  this->ReInit();
487  return;
488  }
489  }
490  }
491 
492  void OnClick(Point pt, int widget, int click_count) override
493  {
494  switch (widget) {
496  this->descending_sort_order ^= true;
498  this->engines[1].ForceRebuild();
499  this->SetDirty();
500  break;
501 
503  this->show_hidden_engines ^= true;
505  this->engines[1].ForceRebuild();
506  this->SetWidgetLoweredState(widget, this->show_hidden_engines);
507  this->SetDirty();
508  break;
509 
511  DisplayVehicleSortDropDown(this, static_cast<VehicleType>(this->window_number), this->sort_criteria, WID_RV_SORT_DROPDOWN);
512  break;
513 
515  DropDownList list;
516  list.emplace_back(new DropDownListStringItem(STR_REPLACE_ENGINES, 1, false));
517  list.emplace_back(new DropDownListStringItem(STR_REPLACE_WAGONS, 0, false));
518  ShowDropDownList(this, std::move(list), this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
519  break;
520  }
521 
522  case WID_RV_RAIL_ROAD_TYPE_DROPDOWN: // Rail/roadtype selection dropdown menu
523  switch (this->window_number) {
524  case VEH_TRAIN:
526  break;
527 
528  case VEH_ROAD:
529  ShowDropDownList(this, GetRoadTypeDropDownList(RTTB_ROAD | RTTB_TRAM, true, true), sel_roadtype, WID_RV_RAIL_ROAD_TYPE_DROPDOWN);
530  break;
531  }
532  break;
533 
534  case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: // toggle renew_keep_length
535  DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
536  break;
537 
538  case WID_RV_START_REPLACE: { // Start replacing
539  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
542  } else {
543  bool replacment_when_old = EngineHasReplacementWhenOldForCompany(Company::Get(_local_company), this->sel_engine[0], this->sel_group);
544  ShowDropDownMenu(this, _start_replace_dropdown, replacment_when_old ? 1 : 0, WID_RV_START_REPLACE, !this->replace_engines ? 1 << 1 : 0, 0);
545  }
546  break;
547  }
548 
549  case WID_RV_STOP_REPLACE: { // Stop replacing
550  EngineID veh_from = this->sel_engine[0];
551  DoCommandP(0, this->sel_group << 16, veh_from + (INVALID_ENGINE << 16), CMD_SET_AUTOREPLACE);
552  break;
553  }
554 
555  case WID_RV_LEFT_MATRIX:
556  case WID_RV_RIGHT_MATRIX: {
557  byte click_side;
558  if (widget == WID_RV_LEFT_MATRIX) {
559  click_side = 0;
560  } else {
561  click_side = 1;
562  }
563  uint i = this->vscroll[click_side]->GetScrolledRowFromWidget(pt.y, this, widget);
564  size_t engine_count = this->engines[click_side].size();
565 
566  EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
567  if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
568  this->sel_engine[click_side] = e;
569  if (click_side == 0) {
570  this->engines[1].ForceRebuild();
571  this->reset_sel_engine = true;
572  }
573  this->SetDirty();
574  break;
575  }
576  }
577  }
578 
579  void OnDropdownSelect(int widget, int index) override
580  {
581  switch (widget) {
583  if (this->sort_criteria != index) {
584  this->sort_criteria = index;
586  this->engines[1].ForceRebuild();
587  this->SetDirty();
588  }
589  break;
590 
592  switch (this->window_number) {
593  case VEH_TRAIN: {
594  RailType temp = (RailType)index;
595  if (temp == sel_railtype) return; // we didn't select a new one. No need to change anything
596  sel_railtype = temp;
597  break;
598  }
599 
600  case VEH_ROAD: {
601  RoadType temp = (RoadType)index;
602  if (temp == sel_roadtype) return; // we didn't select a new one. No need to change anything
603  sel_roadtype = temp;
604  break;
605  }
606 
607  default: NOT_REACHED();
608  }
609 
610  /* Reset scrollbar positions */
611  this->vscroll[0]->SetPosition(0);
612  this->vscroll[1]->SetPosition(0);
613  /* Rebuild the lists */
614  this->engines[0].ForceRebuild();
615  this->engines[1].ForceRebuild();
616  this->reset_sel_engine = true;
617  this->SetDirty();
618  break;
619 
621  this->replace_engines = index != 0;
622  this->engines[0].ForceRebuild();
623  this->reset_sel_engine = true;
624  this->SetDirty();
625  break;
626  }
627 
629  this->ReplaceClick_StartReplace(index != 0);
630  break;
631  }
632  }
633 
634  void OnResize() override
635  {
636  this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
637  this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
638  }
639 
645  void OnInvalidateData(int data = 0, bool gui_scope = true) override
646  {
647  if (data != 0) {
648  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
649  this->engines[0].ForceRebuild();
650  } else {
651  this->engines[1].ForceRebuild();
652  }
653  }
654 };
655 
656 static const NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
658  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
659  NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
660  NWidget(WWT_SHADEBOX, COLOUR_GREY),
661  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
662  NWidget(WWT_STICKYBOX, COLOUR_GREY),
663  EndContainer(),
665  NWidget(WWT_PANEL, COLOUR_GREY),
666  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
667  EndContainer(),
668  NWidget(WWT_PANEL, COLOUR_GREY),
669  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
670  EndContainer(),
671  EndContainer(),
675  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_RAIL_ROAD_TYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE), SetFill(1, 0), SetResize(1, 0),
676  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN), SetDataTip(STR_BLACK_STRING, STR_REPLACE_ENGINE_WAGON_SELECT_HELP),
677  EndContainer(),
678  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
679  EndContainer(),
682  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
683  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
684  EndContainer(),
686  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
687  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
688  EndContainer(),
689  EndContainer(),
690  EndContainer(),
692  NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
694  NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
696  EndContainer(),
698  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
700  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
701  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_TRAIN_WAGONREMOVE_TOGGLE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_REMOVE_WAGON, STR_REPLACE_REMOVE_WAGON_HELP), SetFill(1, 0), SetResize(1, 0),
702  EndContainer(),
703  EndContainer(),
705  NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
706  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
707  EndContainer(),
708  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
709  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
710  EndContainer(),
711 };
712 
713 static WindowDesc _replace_rail_vehicle_desc(
714  WDP_AUTO, "replace_vehicle_train", 500, 140,
717  _nested_replace_rail_vehicle_widgets, lengthof(_nested_replace_rail_vehicle_widgets)
718 );
719 
720 static const NWidgetPart _nested_replace_road_vehicle_widgets[] = {
722  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
723  NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
724  NWidget(WWT_SHADEBOX, COLOUR_GREY),
725  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
726  NWidget(WWT_STICKYBOX, COLOUR_GREY),
727  EndContainer(),
729  NWidget(WWT_PANEL, COLOUR_GREY),
730  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
731  EndContainer(),
732  NWidget(WWT_PANEL, COLOUR_GREY),
733  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
734  EndContainer(),
735  EndContainer(),
738  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_RAIL_ROAD_TYPE_DROPDOWN), SetMinimalSize(136, 12), SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE), SetFill(1, 0), SetResize(1, 0),
739  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
740  EndContainer(),
743  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 1),
744  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
745  EndContainer(),
747  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
748  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
749  EndContainer(),
750  EndContainer(),
751  EndContainer(),
753  NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
755  NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
757  EndContainer(),
759  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
760  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
761  EndContainer(),
763  NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
764  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0),
765  EndContainer(),
766  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(150, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
767  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
768  EndContainer(),
769 };
770 
771 static WindowDesc _replace_road_vehicle_desc(
772  WDP_AUTO, "replace_vehicle_road", 500, 140,
775  _nested_replace_road_vehicle_widgets, lengthof(_nested_replace_road_vehicle_widgets)
776 );
777 
778 static const NWidgetPart _nested_replace_vehicle_widgets[] = {
780  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
781  NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
782  NWidget(WWT_SHADEBOX, COLOUR_GREY),
783  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
784  NWidget(WWT_STICKYBOX, COLOUR_GREY),
785  EndContainer(),
787  NWidget(WWT_PANEL, COLOUR_GREY),
788  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
789  EndContainer(),
790  NWidget(WWT_PANEL, COLOUR_GREY),
791  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
792  EndContainer(),
793  EndContainer(),
795  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
798  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
799  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
800  EndContainer(),
802  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
803  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
804  EndContainer(),
805  EndContainer(),
806  EndContainer(),
808  NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
810  NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
812  EndContainer(),
814  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
815  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
816  EndContainer(),
818  NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
819  NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
820  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
821  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
822  EndContainer(),
823 };
824 
825 static WindowDesc _replace_vehicle_desc(
826  WDP_AUTO, "replace_vehicle", 456, 118,
829  _nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets)
830 );
831 
838 {
839  DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
840  WindowDesc *desc;
841  switch (vehicletype) {
842  case VEH_TRAIN: desc = &_replace_rail_vehicle_desc; break;
843  case VEH_ROAD: desc = &_replace_road_vehicle_desc; break;
844  default: desc = &_replace_vehicle_desc; break;
845  }
846  new ReplaceVehicleWindow(desc, vehicletype, id_g);
847 }
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
Functions related to OTTD&#39;s strings.
Dropdown for the sort criteria.
void RebuildDone()
Notify the sortlist that the rebuild is done.
Functions for NewGRF engines.
uint32 widget_data
Data of the widget.
Definition: widget_type.h:305
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
uint GetCompanySettingIndex(const char *name)
Get the index in the _company_settings array of a setting.
Definition: settings.cpp:2029
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:306
Horizontally center the text.
Definition: gfx_func.h:97
ResizeInfo resize
Resize information.
Definition: window_gui.h:324
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:731
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1851
bool reset_sel_engine
Also reset sel_engine while updating left and/or right and no valid engine selected.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:394
Window for the autoreplacing of vehicles.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:455
High level window description.
Definition: window_gui.h:168
Toggle whether to display the hidden vehicles.
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:306
Train vehicle type.
Definition: vehicle_type.h:26
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
Get the number of engines with EngineID id_e in the group with GroupID id_g and its sub-groups...
Definition: group_cmd.cpp:801
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:604
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
void GenerateReplaceVehList(bool draw_left)
Generate an engines list.
Centered label.
Definition: widget_type.h:57
Scrollbar data structure.
Definition: widget_type.h:589
GroupID sel_group
Group selected to replace.
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
uint16 capacity
Cargo capacity.
Definition: vehicle_gui.h:44
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button)
Display the dropdown for the vehicle sort criteria.
Horizontal container.
Definition: widget_type.h:75
Functions/types related to the road GUIs.
byte _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
Replace vehicle window; Window numbers:
Definition: window_type.h:213
Rail specific functions.
Flag for invalid railtype.
Definition: rail_type.h:36
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:22
Used for iterations.
Definition: road_type.h:31
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
Road specific functions.
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
void SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:701
change a company setting
Definition: command_type.h:308
Build vehicle; Window numbers:
Definition: window_type.h:378
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
flag for invalid roadtype
Definition: road_type.h:32
Close box (at top-left of a window)
Definition: widget_type.h:69
uint GetEngineListHeight(VehicleType type)
Get the height of a single &#39;entry&#39; in the engine lists.
bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
Figure out if an engine should be added to a list.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:979
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
Definition: rail_gui.cpp:1993
RoadType
The different roadtypes we support.
Definition: road_type.h:27
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
Common string list item.
Definition: dropdown_type.h:41
Ascending/descending sort order button.
CompanySettings settings
settings specific for each company
Definition: company_base.h:129
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1812
Functions related to the vehicle&#39;s GUIs.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:81
uint16 mail_capacity
Mail capacity if available.
Definition: vehicle_gui.h:45
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Functions/types etc.
bool descending_sort_order
Order of sorting vehicles.
Functions, definitions and such used only by the GUI.
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:126
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
RoadType roadtype
Road type.
Definition: engine_type.h:127
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
void ForceRebuild()
Force that a rebuild is needed.
StringID replace_text
Text used in the autoreplace GUI.
Definition: road.h:106
Data structure for an opened window.
Definition: window_gui.h:278
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1828
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1032
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3318
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:226
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
Draw the purchase info details of a vehicle at a given location.
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1959
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
Details of the entry on the left.
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:337
RailType sel_railtype
Type of rail tracks selected. INVALID_RAILTYPE to show all.
Extra information about refitted cargo and capacity.
Definition: vehicle_gui.h:41
Sort descending.
Definition: window_gui.h:227
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:178
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
Functions related to setting/changing the settings.
simple wagon, not motorized
Definition: engine_type.h:31
The scrollbar for the matrix on the right.
void ReplaceClick_StartReplace(bool replace_when_old)
Handle click on the start replace button.
Types related to the autoreplace widgets.
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
The matrix on the right.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
Dropdown to select engines and/or wagons.
void GenerateLists()
Generate the lists.
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
bool replace_engines
If true, engines are replaced, if false, wagons are replaced (only for trains).
Dropdown menu about the rail/roadtype.
Geometry functions.
Simple depressed panel.
Definition: widget_type.h:50
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:15
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button&#39;s up or down arrow symbol.
Definition: widget.cpp:638
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:311
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:177
void OnResize() override
Called after the window got resized.
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
Engine drawing loop.
const StringID _engine_sort_listing[][12]
Dropdown menu strings for the vehicle sort criteria.
static EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old=nullptr)
Retrieve the engine replacement for the given company and original engine type.
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
Baseclass for nested widgets.
Definition: widget_type.h:126
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:499
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
Right offset of the text of the frame.
Definition: window_gui.h:73
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:534
bool renew_keep_length
sell some wagons if after autoreplace the train is longer than before
EngineID sel_engine[2]
Selected engine left and right.
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
Grid of rows and columns.
Definition: widget_type.h:59
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
RailTypeLabel label
Unique 32 bit rail type identifier.
Definition: rail.h:235
Left offset of the text of the frame.
Definition: window_gui.h:72
Details of the entry on the right.
static bool EngineHasReplacementWhenOldForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine when it gets old.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:658
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
The scrollbar for the matrix on the left.
Information about a rail vehicle.
Definition: engine_type.h:44
StringID replace_text
Text used in the autoreplace GUI.
Definition: rail.h:179
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:968
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:698
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
Definition: engine_base.h:121
bool _engine_sort_direction
false = descending, true = ascending.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1146
Button to toggle removing wagons.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:176
bool show_hidden_engines
Whether to show the hidden engines.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition: group_type.h:19
Functions related to companies.
Used for iterations.
Definition: road_type.h:28
Base class for engines.
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
Caption of the window.
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
int details_height
Minimal needed height of the details panels (found so far).
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:23
Start Replacing button.
Sort ascending.
Definition: window_gui.h:226
byte sort_criteria
Criteria of sorting vehicles.
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
Vertical container.
Definition: widget_type.h:77
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
Stop Replacing button.
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition: engine_base.h:101
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given &#39;CompareItems&#39; function.
Definition: engine_gui.cpp:328
Functions related to commands.
Coordinates of a point in 2D.
The matrix on the left.
Drop down list.
Definition: widget_type.h:70
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:326
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:619
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
When an engine is made buildable or is removed from being buildable, add/remove it from the build/aut...
static bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
RoadType sel_roadtype
Type of road selected. INVALID_ROADTYPE to show all.
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
Used for iterations.
Definition: rail_type.h:35
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget. ...
Definition: widget.cpp:1973
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:526
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:314
bool _engine_sort_show_hidden_engines[]
Last set &#39;show hidden engines&#39; setting for each vehicle type.
static bool EngineNumberSorter(const EngineID &a, const EngineID &b)
Determines order of engines by engineID.
Window functions not directly related to making/drawing windows.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Find a place automatically.
Definition: window_gui.h:156
void OnPaint() override
The window must be repainted.
Money cost
Refit cost.
Definition: vehicle_gui.h:42
set an autoreplace entry
Definition: command_type.h:310
Functions related to autoreplacing.
GUIEngineList engines[2]
Left and right list of engines.
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
CargoID cargo
Cargo type.
Definition: vehicle_gui.h:43
Road vehicle type.
Definition: vehicle_type.h:27
Used for iterations.
Definition: rail_type.h:30
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3300
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition: road.h:146
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
(Toggle) Button with text
Definition: widget_type.h:55
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:284
static const GroupID ALL_GROUP
All vehicles are in this group.
Definition: group_type.h:18