71 static const StringID _start_replace_dropdown[] = {
72 STR_REPLACE_VEHICLES_NOW,
73 STR_REPLACE_VEHICLES_WHEN_OLD,
105 if ((rvi->railveh_type ==
RAILVEH_WAGON) == show_engines)
return false;
109 if (rvi->railtype != this->sel_railtype)
return false;
123 byte side = draw_left ? 0 : 1;
129 FOR_ALL_ENGINES_OF_TYPE(e, type) {
144 if (eid == this->sel_engine[side]) selected_engine = eid;
146 this->sel_engine[side] = selected_engine;
160 if (this->engines[0].NeedRebuild()) {
163 this->vscroll[0]->
SetCount(this->engines[0].Length());
164 if (this->reset_sel_engine && this->sel_engine[0] ==
INVALID_ENGINE && this->engines[0].Length() != 0) {
165 this->sel_engine[0] = this->engines[0][0];
169 if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) {
173 this->engines[1].
Clear();
176 if (this->reset_sel_engine && this->sel_engine[0] !=
INVALID_ENGINE) {
183 this->vscroll[1]->
SetCount(this->engines[1].Length());
184 if (this->reset_sel_engine && this->sel_engine[1] !=
INVALID_ENGINE) {
186 for (
EngineID *it = this->engines[1].Begin(); it != this->engines[1].
End(); ++it) {
187 if (*it == this->sel_engine[1])
break;
197 this->reset_sel_engine =
false;
206 EngineID veh_from = this->sel_engine[0];
207 EngineID veh_to = this->sel_engine[1];
215 this->replace_engines =
true;
218 this->reset_sel_engine =
true;
229 widget->
widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype;
230 widget->
tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + vehicletype;
231 widget->
SetLowered(this->show_hidden_engines);
237 this->sel_group = id_g;
246 d.height += padding.height;
254 size->height = (this->window_number <=
VEH_ROAD ? 8 : 4) * resize->height;
259 size->height = this->details_height;
268 d.width += padding.width;
269 d.height += padding.height;
277 d.width += padding.width;
278 d.height += padding.height;
297 if (rti->
label == 0)
continue;
300 d.width += padding.width;
301 d.height += padding.height;
311 d.width += padding.width;
312 d.height += padding.height;
368 str = STR_REPLACE_NOT_REPLACING;
370 bool when_old =
false;
372 str = when_old ? STR_REPLACE_REPLACING_WHEN_OLD : STR_ENGINE_NAME;
376 str = STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED;
387 EngineID end =
min(this->vscroll[side]->GetCapacity() + start, this->
engines[side].Length());
391 &this->engines[side], start, end, this->sel_engine[side], side == 0, this->sel_group);
424 for (
int side = 0; side < 2; side++) {
479 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
509 if (click_side == 0) {
582 static const NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
592 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),
595 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),
601 NWidget(
WWT_DROPDOWN, COLOUR_GREY,
WID_RV_TRAIN_RAILTYPE_DROPDOWN),
SetMinimalSize(136, 12),
SetDataTip(0x0, STR_REPLACE_HELP_RAILTYPE),
SetFill(1, 0),
SetResize(1, 0),
618 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),
620 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),
627 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),
640 WDP_AUTO,
"replace_vehicle_train", 500, 140,
643 _nested_replace_rail_vehicle_widgets,
lengthof(_nested_replace_rail_vehicle_widgets)
646 static const NWidgetPart _nested_replace_vehicle_widgets[] = {
656 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),
659 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),
676 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),
678 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),
687 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_RV_INFO_TAB),
SetMinimalSize(167, 12),
SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB),
SetResize(1, 0),
EndContainer(),
694 WDP_AUTO,
"replace_vehicle", 456, 118,
697 _nested_replace_vehicle_widgets,
lengthof(_nested_replace_vehicle_widgets)
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
Checks some basic properties whether autoreplace is allowed.
Functions related to OTTD's strings.
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 RebuildDone()
Notify the sortlist that the rebuild is done.
Functions for NewGRF engines.
uint GetCompanySettingIndex(const char *name)
Get the index in the _company_settings array of a setting.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Horizontally center the text.
ResizeInfo resize
Resize information.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
bool reset_sel_engine
Also reset sel_engine while updating left and/or right (#update_left and/or #update_right) and no val...
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Window for the autoreplacing of vehicles.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
RailType
Enumeration for all possible railtypes.
High level window description.
static EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old=NULL)
Retrieve the engine replacement for the given company and original engine type.
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
Draw the purchase info details of a vehicle at a given location.
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 DrawWidgets() const
Paint all widgets of a window.
static Titem * Get(size_t index)
Returns Titem with given index.
bool IsHidden(CompanyByte c) const
Check whether the engine is hidden in the GUI for the given company.
void GenerateReplaceVehList(bool draw_left)
Generate an engines list.
GroupID sel_group
Group selected to replace.
Offset at top to draw the frame rectangular area.
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button)
Display the dropdown for the vehicle sort criteria.
byte _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
Replace vehicle window; Window numbers:
void ShowDropDownList(Window *w, const DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Build vehicle; Window numbers:
void Clear()
Remove all items from the list.
Tindex index
Index of this pool item.
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' 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.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
static T max(const T a, const T b)
Returns the maximum of two values.
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
CompanySettings settings
settings specific for each company
const T * End() const
Get the pointer behind the last valid item (const)
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Functions related to the vehicle's GUIs.
bool descending_sort_order
Order of sorting vehicles.
Functions, definitions and such used only by the GUI.
virtual void OnPaint()
The window must be repainted.
This struct contains all the info that is needed to draw and construct tracks.
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
T * Append(uint to_add=1)
Append an item and return it.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void ForceRebuild()
Force that a rebuild is needed.
Data structure for an opened window.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
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...
uint Length() const
Get the number of items in the list.
This window is used for construction; close it whenever changing company.
VehicleType
Available vehicle types.
RailType sel_railtype
Type of rail tracks selected. INVALID_RAILTYPE to show all.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Simple vector template class, with automatic delete.
Functions related to setting/changing the settings.
simple wagon, not motorized
void ReplaceClick_StartReplace(bool replace_when_old)
Handle click on the start replace button.
Definition of base types and functions in a cross-platform compatible way.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
A number of safeguards to prevent using unsafe methods.
void GenerateLists()
Generate the lists.
bool replace_engines
If true, engines are replaced, if false, wagons are replaced (only for trains).
uint16 GroupID
Type for all group identifiers.
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
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.
Offset at bottom to draw the frame rectangular area.
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.
Right offset of the text of the frame.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
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.
static T min(const T a, const T b)
Returns the minimum of two values.
RailTypeLabel label
Unique 32 bit rail type identifier.
Left offset of the text of the frame.
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.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
Rebuild the left autoreplace list if an engine is removed or added.
Information about a rail vehicle.
DropDownList * GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
StringID replace_text
Text used in the autoreplace GUI.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
Determines order of engines by engineID.
bool show_hidden_engines
Whether to show the hidden engines.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Functions related to companies.
int details_height
Minimal needed height of the details panels (found so far).
uint16 EngineID
Unique identification number of an engine.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
byte sort_criteria
Criteria of sorting vehicles.
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
virtual void OnResize()
Called after the window got resized.
Functions related to the drop down widget.
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Functions related to commands.
Coordinates of a point in 2D.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
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.
Specification of a rectangle with absolute coordinates of all edges.
bool IsShaded() const
Is window shaded currently?
Flag for invalid railtype.
WindowNumber window_number
Window number within the window class.
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
Window functions not directly related to making/drawing windows.
Find a place automatically.
Functions related to autoreplacing.
GUIEngineList engines[2]
Left and right list of engines.
Dimensions (a width and height) of a rectangle in 2D.
Offset at left 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-...
AutoDeleteSmallVector< const DropDownListItem *, 4 > DropDownList
A drop down list is a collection of drop down list items.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static const GroupID ALL_GROUP
All vehicles are in this group.