|
OpenTTD Source
13.0-beta1
|
Go to the documentation of this file.
72 static const StringID _start_replace_dropdown[] = {
73 STR_REPLACE_VEHICLES_NOW,
74 STR_REPLACE_VEHICLES_WHEN_OLD,
107 if ((rvi->railveh_type ==
RAILVEH_WAGON) == show_engines)
return false;
111 if (rvi->railtype != this->sel_railtype)
return false;
125 byte side = draw_left ? 0 : 1;
131 if (!draw_left && !this->show_hidden_engines && e->IsHidden(
_local_company))
continue;
141 if (e->u.road.roadtype != this->sel_roadtype)
continue;
158 list->push_back(eid);
159 if (eid == this->sel_engine[side]) selected_engine = eid;
161 this->sel_engine[side] = selected_engine;
175 if (this->engines[0].NeedRebuild()) {
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];
184 if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
188 this->engines[1].clear();
191 if (this->reset_sel_engine && this->sel_engine[0] !=
INVALID_ENGINE) {
198 this->vscroll[1]->
SetCount((uint)this->engines[1].size());
199 if (this->reset_sel_engine && this->sel_engine[1] !=
INVALID_ENGINE) {
201 for (
EngineID &eid : this->engines[1]) {
202 if (eid == this->sel_engine[1])
break;
212 this->reset_sel_engine =
false;
221 EngineID veh_from = this->sel_engine[0];
222 EngineID veh_to = this->sel_engine[1];
231 this->replace_engines =
true;
234 this->reset_sel_engine =
true;
235 this->details_height = ((vehicletype ==
VEH_TRAIN) ? 10 : 9);
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);
252 widget->
tool_tip = STR_REPLACE_HELP_RAILTYPE + vehicletype;
258 this->sel_group = id_g;
267 d.height += padding.height;
275 size->height = (this->window_number <=
VEH_ROAD ? 8 : 4) *
resize->height;
289 d.width += padding.width;
290 d.height += padding.height;
298 d.width += padding.width;
299 d.height += padding.height;
320 if (rti->
label == 0)
continue;
329 if (rti->
label == 0)
continue;
334 default: NOT_REACHED();
336 d.width += padding.width;
337 d.height += padding.height;
347 d.width += padding.width;
348 d.height += padding.height;
359 SetDParam(0, STR_REPLACE_VEHICLE_TRAIN + this->window_number);
360 switch (this->sel_group) {
362 SetDParam(1, STR_GROUP_ALL_TRAINS + this->window_number);
366 SetDParam(1, STR_GROUP_DEFAULT_TRAINS + this->window_number);
390 SetDParam(0, STR_GROUP_DEFAULT_TRAINS + this->window_number);
392 SetDParam(2, remove_wagon ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
397 SetDParam(0, this->replace_engines ? STR_REPLACE_ENGINES : STR_REPLACE_WAGONS);
414 str = STR_REPLACE_NOT_REPLACING;
416 bool when_old =
false;
418 str = when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME;
422 str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED;
433 EngineID end =
static_cast<EngineID>(std::min<size_t>(this->vscroll[side]->GetCapacity() + start, this->engines[side].size()));
437 &this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
445 if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
460 switch (this->window_number) {
476 if (!this->IsShaded()) {
477 int needed_height = this->details_height;
479 for (
int side = 0; side < 2; side++) {
494 if (needed_height != this->details_height) {
495 this->details_height = needed_height;
506 this->descending_sort_order ^=
true;
513 this->show_hidden_engines ^=
true;
516 this->SetWidgetLoweredState(widget, this->show_hidden_engines);
533 switch (this->window_number) {
556 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
558 ReplaceClick_StartReplace(
false);
567 EngineID veh_from = this->sel_engine[0];
581 size_t engine_count = this->engines[click_side].size();
594 if (e == this->sel_engine[click_side])
break;
595 this->sel_engine[click_side] = e;
596 if (click_side == 0) {
598 this->reset_sel_engine =
true;
610 if (this->sort_criteria != index) {
611 this->sort_criteria = index;
619 switch (this->window_number) {
622 if (temp == sel_railtype)
return;
629 if (temp == sel_roadtype)
return;
634 default: NOT_REACHED();
643 this->reset_sel_engine =
true;
648 this->replace_engines = index != 0;
650 this->reset_sel_engine =
true;
656 this->ReplaceClick_StartReplace(index != 0);
667 params[0] = STR_REPLACE_REMOVE_WAGON_HELP;
668 GuiShowTooltips(
this, STR_REPLACE_REMOVE_WAGON_GROUP_HELP, 1, params, close_cond);
670 GuiShowTooltips(
this, STR_REPLACE_REMOVE_WAGON_HELP, 0,
nullptr, close_cond);
697 static const NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
707 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),
710 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),
716 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),
733 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),
735 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),
742 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),
755 WDP_AUTO,
"replace_vehicle_train", 500, 140,
758 _nested_replace_rail_vehicle_widgets,
lengthof(_nested_replace_rail_vehicle_widgets)
761 static const NWidgetPart _nested_replace_road_vehicle_widgets[] = {
771 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),
774 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),
779 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),
794 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),
796 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),
813 WDP_AUTO,
"replace_vehicle_road", 500, 140,
816 _nested_replace_road_vehicle_widgets,
lengthof(_nested_replace_road_vehicle_widgets)
819 static const NWidgetPart _nested_replace_vehicle_widgets[] = {
829 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),
832 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),
849 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),
851 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),
860 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_RV_INFO_TAB),
SetMinimalSize(167, 12),
SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB),
SetResize(1, 0),
EndContainer(),
867 WDP_AUTO,
"replace_vehicle", 456, 118,
870 _nested_replace_vehicle_widgets,
lengthof(_nested_replace_vehicle_widgets)
882 switch (vehicletype) {
883 case VEH_TRAIN: desc = &_replace_rail_vehicle_desc;
break;
884 case VEH_ROAD: desc = &_replace_road_vehicle_desc;
break;
885 default: desc = &_replace_vehicle_desc;
break;
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
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-...
@ ROADTYPE_END
Used for iterations.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
static Titem * Get(size_t index)
Returns Titem with given index.
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
GroupID sel_group
Group selected to replace.
Dimensions (a width and height) of a rectangle in 2D.
bool replace_engines
If true, engines are replaced, if false, wagons are replaced (only for trains).
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
uint16 mail_capacity
Mail capacity if available.
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void GenerateReplaceVehList(bool draw_left)
Generate an engines list.
bool _engine_sort_direction
false = descending, true = ascending.
StringID replace_text
Text used in the autoreplace GUI.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
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 bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
This struct contains all the info that is needed to draw and construct tracks.
bool _ctrl_pressed
Is Ctrl pressed?
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.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
StringID replace_text
Text used in the autoreplace GUI.
@ VEH_ROAD
Road vehicle type.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
GUIEngineList engines[2]
Left and right list of engines.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
@ INVALID_ROADTYPE
flag for invalid roadtype
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
uint capacity
Cargo capacity.
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button)
Display the dropdown for the vehicle sort criteria.
static const GroupID ALL_GROUP
All vehicles are in this group.
High level window description.
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.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
void OnPaint() override
The window must be repainted.
bool renew_keep_length
sell some wagons if after autoreplace the train is longer than before
uint16 EngineID
Unique identification number of an engine.
void OnResize() override
Called after the window got resized.
Information about a rail vehicle.
const StringID _engine_sort_listing[][12]
Dropdown menu strings for the vehicle sort criteria.
@ WDP_AUTO
Find a place automatically.
RailType
Enumeration for all possible railtypes.
ResizeInfo resize
Resize information.
RoadType sel_roadtype
Type of road selected. INVALID_ROADTYPE to show all.
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
Shows a tooltip.
EngineID sel_engine[2]
Selected engine left and right.
bool descending_sort_order
Order of sorting vehicles.
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
CompanySettings settings
settings specific for each company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void GenerateLists()
Generate the lists.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Extra information about refitted cargo and capacity.
fluid_settings_t * settings
FluidSynth settings handle.
int details_height
Minimal needed height of the details panels, in text lines (found so far).
bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
Figure out if an engine should be added to a list.
bool reset_sel_engine
Also reset sel_engine while updating left and/or right and no valid engine selected.
Coordinates of a point in 2D.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
byte _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
WindowNumber window_number
Window number within the window class.
VehicleType
Available vehicle types.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ SA_HOR_CENTER
Horizontally center the text.
@ RAILVEH_WAGON
simple wagon, not motorized
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.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Window for the autoreplacing of vehicles.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
@ SBS_DOWN
Sort ascending.
uint16 GroupID
Type for all group identifiers.
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
RoadTypeLabel label
Unique 32 bit road type identifier.
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
@ RAILTYPE_END
Used for iterations.
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...
RailTypeLabel label
Unique 32 bit rail type identifier.
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
bool show_hidden_engines
Whether to show the hidden engines.
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
RoadType
The different roadtypes we support.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
RailType sel_railtype
Type of rail tracks selected. INVALID_RAILTYPE to show all.
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.
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
void ForceRebuild()
Force that a rebuild is needed.
#define lengthof(x)
Return the length of an fixed size array.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
byte sort_criteria
Criteria of sorting vehicles.
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
Data structure for an opened window.
void RebuildDone()
Notify the sortlist that the rebuild is done.
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
static bool EngineNumberSorter(const EngineID &a, const EngineID &b)
Determines order of engines by engineID.
@ GF_REPLACE_WAGON_REMOVAL
If set, autoreplace will perform wagon removal on vehicles in this group.
void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
When an engine is made buildable or is removed from being buildable, add/remove it from the build/aut...
Specification of a rectangle with absolute coordinates of all edges.
static bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
@ ROADTYPE_BEGIN
Used for iterations.
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.
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.
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void ReplaceClick_StartReplace(bool replace_when_old)
Handle click on the start replace button.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
@ INVALID_RAILTYPE
Flag for invalid railtype.
@ RAILTYPE_BEGIN
Used for iterations.