39 static const NWidgetPart _nested_group_widgets[] = {
61 SetDataTip(SPR_GROUP_CREATE_TRAIN, STR_GROUP_CREATE_TOOLTIP),
63 SetDataTip(SPR_GROUP_DELETE_TRAIN, STR_GROUP_DELETE_TOOLTIP),
65 SetDataTip(SPR_GROUP_RENAME_TRAIN, STR_GROUP_RENAME_TOOLTIP),
68 SetDataTip(SPR_GROUP_REPLACE_OFF_TRAIN, STR_GROUP_REPLACE_PROTECTION_TOOLTIP),
79 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_GL_LIST_VEHICLE),
SetMinimalSize(248, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetResize(1, 1),
SetFill(1, 0),
SetScrollbar(
WID_GL_LIST_VEHICLE_SCROLLBAR),
85 SetDataTip(STR_BLACK_STRING, STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP),
88 SetDataTip(STR_VEHICLE_LIST_MANAGE_LIST, STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP),
90 SetDataTip(SPR_FLAG_VEH_STOPPED, STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP),
92 SetDataTip(SPR_FLAG_VEH_RUNNING, STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP),
127 for (
const Group **g = source->
Begin(); g != source->
End(); g++) {
128 if ((*g)->parent == parent) {
129 *this->groups.
Append() = *g;
130 *this->indents.
Append() = indent;
131 AddParents(source, (*g)->index, indent + 1);
139 static const Group *last_group[2] = { NULL, NULL };
140 static char last_name[2][64] = {
"",
"" };
142 if (*a != last_group[0]) {
145 GetString(last_name[0], STR_GROUP_NAME,
lastof(last_name[0]));
148 if (*b != last_group[1]) {
151 GetString(last_name[1], STR_GROUP_NAME,
lastof(last_name[1]));
154 int r =
strnatcmp(last_name[0], last_name[1]);
155 if (r == 0)
return (*a)->index - (*b)->index;
168 this->groups.
Clear();
169 this->indents.
Clear();
197 this->tiny_step_height = this->column_size[
VGC_NAME].height;
203 this->tiny_step_height =
max(this->tiny_step_height, this->column_size[
VGC_AUTOREPLACE].height);
207 static const SpriteID profit_sprites[] = {SPR_PROFIT_NA, SPR_PROFIT_NEGATIVE, SPR_PROFIT_SOME, SPR_PROFIT_LOT};
208 for (uint i = 0; i <
lengthof(profit_sprites); i++) {
212 this->tiny_step_height =
max(this->tiny_step_height, this->column_size[
VGC_PROFIT].height);
216 this->tiny_step_height =
max(this->tiny_step_height, this->column_size[
VGC_NUMBER].height);
221 this->column_size[
VGC_NAME].width + 8 +
241 if (g_id == this->group_over) {
255 str = STR_GROUP_ALL_TRAINS + this->
vli.
vtype;
256 }
else if (IsDefaultGroupID(g_id)) {
257 str = STR_GROUP_DEFAULT_TRAINS + this->
vli.
vtype;
260 str = STR_GROUP_NAME;
266 x = rtl ? x - 8 - this->column_size[
VGC_PROTECT].width : x + 8 + this->column_size[
VGC_NAME].width;
267 if (protection)
DrawSprite(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[
VGC_PROTECT].height) / 2);
279 spr = SPR_PROFIT_NEGATIVE;
281 spr = SPR_PROFIT_SOME;
283 spr = SPR_PROFIT_LOT;
285 DrawSprite(spr, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[
VGC_PROFIT].height) / 2);
288 x = rtl ? x - 2 - this->column_size[
VGC_NUMBER].width : x + 2 + this->column_size[
VGC_PROFIT].width;
302 }
else if (IsDefaultGroupID(this->group_over)) {
318 default: NOT_REACHED();
335 this->BuildVehicleList();
336 this->SortVehicleList();
342 this->GetWidget<NWidgetCore>(
WID_GL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->
vli.
vtype;
379 size->height =
Ceil(size->height - max_icon_height, tiny_step_height);
392 d.height += padding.height;
400 size->height = 4 * resize->height;
405 d.height += padding.height;
406 d.width += padding.width;
478 this->BuildVehicleList();
479 this->SortVehicleList();
518 uint16 protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
542 uint32 occupancy = 0;
545 for (uint i = 0; i < vehicle_count; i++) {
547 assert(v->
owner == this->owner);
558 DrawString(left, right, y, STR_GROUP_PROFIT_THIS_YEAR, TC_BLACK);
563 DrawString(left, right, y, STR_GROUP_PROFIT_LAST_YEAR, TC_BLACK);
568 DrawString(left, right, y, STR_GROUP_OCCUPANCY, TC_BLACK);
569 if (vehicle_count > 0) {
581 const Group *g = this->groups[i];
583 assert(g->
owner == this->owner);
606 if (v->
group_id != this->vli.index) {
618 static void DeleteGroupCallback(
Window *win,
bool confirmed)
648 if (!IsDefaultGroupID(this->
vli.
index)) {
657 if (id_g >= this->groups.
Length())
return;
659 this->group_sel = this->
vli.
index = this->groups[id_g]->index;
675 this->vehicle_sel = v->
index;
691 this->group_confirm = this->
vli.
index;
692 ShowQuery(STR_QUERY_GROUP_DELETE_CAPTION, STR_GROUP_DELETE_QUERY_TEXT,
this, DeleteGroupCallback);
697 this->ShowRenameGroupWindow(this->
vli.
index,
false);
726 void OnDragDrop_Group(
Point pt,
int widget)
746 if (this->group_sel != new_g && g->
parent != new_g) {
758 void OnDragDrop_Vehicle(
Point pt,
int widget)
803 if (this->vehicle_sel !=
INVALID_VEHICLE) OnDragDrop_Vehicle(pt, widget);
804 if (this->group_sel !=
INVALID_GROUP) OnDragDrop_Group(pt, widget);
851 default: NOT_REACHED();
855 default: NOT_REACHED();
891 new_group_over = id_g >= this->groups.
Length() ?
NEW_GROUP : this->groups[id_g]->index;
904 if (new_group_over != this->group_over) {
906 this->group_over = new_group_over;
911 void ShowRenameGroupWindow(
GroupID group,
bool empty)
914 this->group_rename = group;
919 str = STR_GROUP_NAME;
940 _nested_group_widgets,
lengthof(_nested_group_widgets)
944 WDP_AUTO,
"list_groups_train", 525, 246,
947 _nested_group_widgets,
lengthof(_nested_group_widgets)
961 AllocateWindowDescFront<VehicleGroupWindow>(&_train_group_desc, num);
964 AllocateWindowDescFront<VehicleGroupWindow>(&_other_group_desc, num);
989 if (result.
Failed())
return;
993 if (w != NULL) w->ShowRenameGroupWindow(_new_group_id,
true);
1005 if (result.
Failed())
return;
Functions related to OTTD's strings.
void DirtyHighlightedGroupWidget()
Mark the widget containing the currently highlighted group as dirty.
void UnselectVehicle(VehicleID vehicle)
Tests whether a given vehicle is selected in the window, and unselects it if necessary.
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.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
DropDownList * BuildActionDropdownList(bool show_autoreplace, bool show_group)
Display the Action dropdown window.
Definition of stuff that is very close to a company, like the company struct itself.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
bool replace_protection
If set to true, the global autoreplace have no effect on the group.
CompanyID company
The company associated with this list.
The information about a vehicle list.
ResizeInfo resize
Resize information.
GroupStatistics statistics
NOSAVE: Statistics and caches on the vehicles in the group.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
virtual void OnDragDrop(Point pt, int widget)
A dragged 'object' has been released.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Window * parent
Parent window.
High level window description.
Functions related to the autoreplace GUIs.
int left
x position of left edge of the window
bool vehchain
vehicle chain is dragged
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
bool VehicleClicked(const Vehicle *v)
Dispatch a "vehicle selected" event if any window waits for it.
void DrawWidgets() const
Paint all widgets of a window.
static Titem * Get(size_t index)
Returns Titem with given index.
virtual void OnMouseDrag(Point pt, int widget)
An 'object' is being dragged at the provided position, highlight the target if possible.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Offset at top to draw the frame rectangular area.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
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 CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Opens a 'Rename group' window for newly created group.
void ShowDropDownList(Window *w, const DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
GUIVehicleList vehicles
The list of vehicles.
Functions related to vehicles.
void Clear()
Remove all items from the list.
void Compact()
Compact the list down to the smallest block size boundary.
const T * Begin() const
Get the pointer to the first item (const)
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Tindex index
Index of this pool item.
static int CDECL GroupNameSorter(const Group *const *a, const Group *const *b)
Sort the groups by their name.
Money profit_last_year
Sum of profits for all vehicles.
Offset at top of a matrix cell.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0...
#define lastof(x)
Get the last element of an fixed size array.
bool autoreplace_finished
Have all autoreplacement finished?
uint16 num_profit_vehicle
Number of vehicles considered for profit statistics;.
Stuff related to the text buffer GUI.
Common return value for all commands.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
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.
static T max(const T a, const T b)
Returns the maximum of two values.
VehicleID vehicle_sel
Selected vehicle.
void RaiseWidget(byte widget_index)
Marks a widget as raised.
WindowClass cls
Class of the window,.
uint ComputeGroupInfoSize()
Compute tiny_step_height and column_size.
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.
void SetListing(Listing l)
Import sort conditions.
GroupID group_rename
Group being renamed, INVALID_GROUP if none.
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
bool NeedRebuild() const
Check if a rebuild is needed.
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.
Force the alignment, i.e. don't swap for RTL languages.
void ForceRebuild()
Force that a rebuild is needed.
Data structure for an opened window.
bool _ctrl_pressed
Is Ctrl pressed?
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static const GroupID NEW_GROUP
Sentinel for a to-be-created group.
dragging items in the depot windows
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
enable the 'Default' button ("\0" is returned)
static bool IsAllGroupID(GroupID id_g)
Checks if a GroupID stands for all vehicles of a company.
add all other shared vehicles to a group which are missing
static const uint MAX_LENGTH_GROUP_NAME_CHARS
The maximum length of a group name in characters including '\0'.
Functions related to low-level strings.
static const int LEVEL_WIDTH
Indenting width of a sub-group in pixels.
remove all vehicles from a group
void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const
Draw all the vehicle list items.
uint Length() const
Get the number of items in the list.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Statistics and caches on the vehicles in a group.
Listing GetListing() const
Export current sort conditions.
virtual void OnResize()
Called after the window got resized.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
VehicleType
Available vehicle types.
Dimension column_size[VGC_END]
Size of the columns in the group list.
uint32 index
A vehicle list type specific index.
uint32 VehicleID
The type all our vehicle IDs have.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Simple vector template class, with automatic delete.
Definition of base types and functions in a cross-platform compatible way.
Tells that it's a mass send to depot command (type in VLW flag)
the length of the string is counted in characters
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type)
Show the group window for the given company and vehicle type.
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
uint16 GroupID
Type for all group identifiers.
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
uint step_height
Step-size of height resize changes.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
VehicleTypeByte vehicle_type
Vehicle type of the group.
static GroupStatistics & Get(CompanyID company, GroupID id_g, VehicleType type)
Returns the GroupStatistics for a specific group.
Offset at bottom to draw the frame rectangular area.
static const GroupID INVALID_GROUP
Sentinel for invalid groups.
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.
void ShowVehicleViewWindow(const Vehicle *v)
Shows the vehicle view window of the given vehicle.
uint16 num_vehicle
Number of vehicles.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
#define lengthof(x)
Return the length of an fixed size array.
PauseModeByte _pause_mode
The current pause mode.
static T min(const T a, const T b)
Returns the minimum of two values.
Number of vehicles in the group.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
bool Sort(SortFunction *compare)
Sort the list.
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.
bool Failed() const
Did this command fail?
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
virtual void OnPaint()
The window must be repainted.
Functions/classes shared between the different vehicle list GUIs.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void BuildGroupList(Owner owner)
(Re)Build the group list.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
virtual void OnTick()
Called once per (game) tick.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Draw only every second pixel, used for greying-out.
No window, redirects to WC_MAIN_WINDOW.
int8 trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
The vehicle will leave the depot right after arrival (serivce only)
Functions related to companies.
Vehicle drawn in vehicle list, group list, ...
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...
Both numeric and alphabetic and spaces and stuff.
void SetMouseCursorVehicle(const Vehicle *v, EngineImageType image_type)
Set the mouse cursor to look like a vehicle.
GroupID parent
Parent group.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Autoreplace protect icon.
Base class for all vehicles.
static VehicleGroupWindow * FindVehicleGroupWindow(VehicleType vt, Owner owner)
Finds a group list window determined by vehicle type and owner.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
void DrawGroupInfo(int y, int left, int right, GroupID g_id, int indent=0, bool protection=false) const
Draw a row in the group list.
uint32 Pack() const
Pack a VehicleListIdentifier in a single uint32.
void DeleteGroupHighlightOfVehicle(const Vehicle *v)
Removes the highlight of a vehicle in a group window.
bool autoreplace_defined
Are any autoreplace rules set?
TextDirection _current_text_dir
Text direction of the currently selected language.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here...
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
Show the autoreplace configuration window for a particular group.
OwnerByte owner
Which company owns the vehicle?
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Trains list; Window numbers:
GroupID group_sel
Selected group (for drag/drop)
Functions related to the drop down widget.
VehicleListIdentifier vli
Identifier of the vehicle list we want to currently show.
Bottom offset of the dropdown widget string.
Functions related to commands.
Coordinates of a point in 2D.
set the autoreplace-protection for a group
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Index of the small font in the font tables.
static WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
start/stop all vehicles (in a depot)
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Offset at right to draw the frame rectangular area.
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Open rename window after adding a vehicle to a new group via drag and drop.
OwnerByte owner
Group Owner.
int width
width of the window (number of pixels to the right in x direction)
uint GetVehicleListHeight(VehicleType type, uint divisor)
Get the height of a vehicle in the vehicle list GUIs.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
GUIGroupList groups
List of groups.
bool IsDescSortOrder() const
Check if the sort order is descending.
#define CMD_MSG(x)
Used to combine a StringID with the command.
int32 WindowNumber
Number to differentiate different windows of the same class.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Specification of a rectangle with absolute coordinates of all edges.
Text is written right-to-left by default.
Right align the text (must be a single bit).
WindowNumber window_number
Window number within the window class.
Functions related to tile highlights.
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
static uint Ceil(uint a, uint b)
Computes ceil(a / b) * b for non-negative a and b.
Find a place automatically.
uint tiny_step_height
Step height for the group list.
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group)
Compute the size for the Action dropdown.
Listing * sorting
Pointer to the vehicle type related sorting.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
GroupID group_over
Group over which a vehicle is dragged, INVALID_GROUP if none.
SmallVector< int, 16 > indents
Indentation levels.
GroupID group_confirm
Group awaiting delete confirmation.
VehicleType vtype
The vehicle type associated with this list.
VehicleTypeByte type
Type of vehicle.
Dimensions (a width and height) of a rectangle in 2D.
Query string window; Window numbers:
Offset at left to draw the frame rectangular area.
This file contains all sprite-related enums and defines.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Top offset of the dropdown widget string.
GroupID group_id
Index of group Pool array.
int height
Height of the window (number of pixels down in y direction)
uint8 SortType() const
Get the sorttype of the list.
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.