OpenTTD Source: src/group_gui.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Enumerations | Functions | Variables
group_gui.cpp File Reference

GUI for the group window. More...

`#include "stdafx.h"`
`#include "textbuf_gui.h"`
`#include "command_func.h"`
`#include "vehicle_gui.h"`
`#include "vehicle_base.h"`
`#include "string_func.h"`
`#include "strings_func.h"`
`#include "window_func.h"`
`#include "vehicle_func.h"`
`#include "autoreplace_gui.h"`
`#include "company_func.h"`
`#include "dropdown_func.h"`
`#include "tilehighlight_func.h"`
`#include "vehicle_gui_base.h"`
`#include "core/geometry_func.hpp"`
`#include "company_base.h"`
`#include "company_gui.h"`
`#include "gui.h"`
`#include "group_cmd.h"`
`#include "group_gui.h"`
`#include "vehicle_cmd.h"`
`#include "gfx_func.h"`
`#include "widgets/group_widget.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
class | VehicleGroupWindow

## Enumerations
enum | VehicleGroupColumns : uint8_t { VGC_FOLD , VGC_NAME , VGC_PROTECT , VGC_AUTOREPLACE , VGC_PROFIT , VGC_NUMBER , VGC_END }

## Functions
static void | SortGUIGroupList (std::vector< GUIGroupListItem > &list)
static void | GuiGroupListAddChildren (GUIGroupList &list, GUIGroupListItem &item, bool fold, uint8_t indent=1)
| Add children to GUI group list to build a hierarchical tree.
void | BuildGuiGroupList (GUIGroupList &list, bool fold, Owner owner, VehicleType veh_type)
| Build GUI group list, a sorted hierarchical list of groups for owner and vehicle type.
| DECLARE_INCREMENT_DECREMENT_OPERATORS (VehicleGroupColumns)
template<bool Tneed_existing_window>
static void | ShowCompanyGroupInternal (CompanyID company, VehicleType vehicle_type, GroupID group)
| Show the group window for the given company and vehicle type.
void | ShowCompanyGroup (CompanyID company, VehicleType vehicle_type, GroupID group)
| Show the group window for the given company and vehicle type.
void | ShowCompanyGroupForVehicle (const Vehicle *v)
| Show the group window for the given vehicle.
static VehicleGroupWindow * | FindVehicleGroupWindow (VehicleType vt, Owner owner)
| Finds a group list window determined by vehicle type and owner.
static void | CcCreateGroup (GroupID gid, VehicleType veh_type)
| Opens a 'Rename group' window for newly created group.
void | CcCreateGroup (Commands, const CommandCost &result, GroupID new_group, VehicleType vt, GroupID)
| Opens a 'Rename group' window for newly created group.
void | CcAddVehicleNewGroup (Commands, const CommandCost &result, GroupID new_group, GroupID, VehicleID, bool, const VehicleListIdentifier &)
| Open rename window after adding a vehicle to a new group via drag and drop.
void | DeleteGroupHighlightOfVehicle (const Vehicle *v)
| Removes the highlight of a vehicle in a group window.

## Variables
static constexpr std::initializer_list< NWidgetPart > | _nested_group_widgets
static WindowDesc | _vehicle_group_desc []

## Detailed Description

GUI for the group window.

Definition in file group_gui.cpp.

## Enumeration Type Documentation

## ◆ VehicleGroupColumns

enum VehicleGroupColumns : uint8_t

Enumerator
VGC_FOLD | Fold / Unfold button.
VGC_NAME | Group name.
VGC_PROTECT | Autoreplace protect icon.
VGC_AUTOREPLACE | Autoreplace active icon.
VGC_PROFIT | Profit icon.
VGC_NUMBER | Number of vehicles in the group.

Definition at line 196 of file group_gui.cpp.

## Function Documentation

## ◆ BuildGuiGroupList()

void BuildGuiGroupList | ( | GUIGroupList & | list,
|  | bool | fold,
|  | Owner | owner,
|  | VehicleType | veh_type
| ) |  |

Build GUI group list, a sorted hierarchical list of groups for owner and vehicle type.

Parameters

  dst | Destination list, owned by the caller.
  fold | Whether to handle group folding/hiding.
  owner | Owner of groups.
  veh_type | Vehicle type of groups.

Definition at line 167 of file group_gui.cpp.

References AssignBit(), GuiGroupListAddChildren(), and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Iterate().

Referenced by VehicleGroupWindow::BuildGroupList().

## ◆ CcAddVehicleNewGroup()

void CcAddVehicleNewGroup | ( | Commands | cmd,
|  | const CommandCost & | result,
|  | GroupID | new_group,
|  | GroupID | ,
|  | VehicleID | veh_id,
|  | bool | ,
|  | const VehicleListIdentifier & |
| ) |  |

Open rename window after adding a vehicle to a new group via drag and drop.

Parameters

  result | Did command succeed?
  new_group | ID of the created group.

Definition at line 1295 of file group_gui.cpp.

References CcCreateGroup(), CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), and Group::vehicle_type.

Referenced by VehicleGroupWindow::OnDropdownSelect(), and VehicleListWindow::OnDropdownSelect().

## ◆ CcCreateGroup() [1/2]

void CcCreateGroup | ( | Commands | cmd,
|  | const CommandCost & | result,
|  | GroupID | new_group,
|  | VehicleType | vt,
|  | GroupID | parent_group
| ) |  |

Opens a 'Rename group' window for newly created group.

Parameters

  result | Did command succeed?
  new_group | ID of the created group.
  vt | Vehicle type.

See also
  CmdCreateGroup

Definition at line 1282 of file group_gui.cpp.

References CcCreateGroup(), CommandCost::Failed(), and VEH_AIRCRAFT.

## ◆ CcCreateGroup() [2/2]

static void CcCreateGroup | ( | GroupID | gid,
|  | VehicleType | veh_type
| ) |  |
| static

Opens a 'Rename group' window for newly created group.

Parameters

  veh_type | Vehicle type.

Definition at line 1269 of file group_gui.cpp.

References _current_company, and FindVehicleGroupWindow().

Referenced by CcAddVehicleNewGroup(), CcCreateGroup(), and VehicleGroupWindow::OnClick().

## ◆ DeleteGroupHighlightOfVehicle()

void DeleteGroupHighlightOfVehicle | ( | const Vehicle * | v | ) |

Removes the highlight of a vehicle in a group window.

Parameters

  *v | Vehicle to remove all highlights from

Definition at line 1307 of file group_gui.cpp.

References _special_mouse_mode, FindVehicleGroupWindow(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Vehicle::owner, BaseVehicle::type, VehicleGroupWindow::UnselectVehicle(), and WSM_DRAGDROP.

Referenced by Vehicle::PreDestructor().

## ◆ FindVehicleGroupWindow()

static VehicleGroupWindow * FindVehicleGroupWindow | ( | VehicleType | vt,
|  | Owner | owner
| ) |  |
| inlinestatic

Finds a group list window determined by vehicle type and owner.

Parameters

  vt | vehicle type
  owner | owner of groups

Returns
  pointer to VehicleGroupWindow, nullptr if not found

Definition at line 1260 of file group_gui.cpp.

References FindWindowById(), GetWindowClassForVehicleType(), and VL_GROUP_LIST.

Referenced by CcCreateGroup(), and DeleteGroupHighlightOfVehicle().

## ◆ GuiGroupListAddChildren()

static void GuiGroupListAddChildren | ( | GUIGroupList & | list,
|  | GUIGroupListItem & | item,
|  | bool | fold,
|  | uint8_t | indent = `1`
| ) |  |
| static

Add children to GUI group list to build a hierarchical tree.

Parameters

  list | Destination list.
  item | Group item to add children to.
  fold | Whether to handle group folding/hiding.
  indent | Current tree indentation level (set by self with recursion).

Definition at line 140 of file group_gui.cpp.

References Group::children, Group::folded, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Get(), GuiGroupListAddChildren(), and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index.

Referenced by BuildGuiGroupList(), and GuiGroupListAddChildren().

## ◆ ShowCompanyGroup()

void ShowCompanyGroup | ( | CompanyID | company,
|  | VehicleType | vehicle_type,
|  | GroupID | group
| ) |  |

Show the group window for the given company and vehicle type.

Parameters

  company | The company to show the window for.
  vehicle_type | The type of vehicle to show it for.
  group | The group to be selected. Defaults to GroupID::Invalid().

Definition at line 1240 of file group_gui.cpp.

## ◆ ShowCompanyGroupForVehicle()

void ShowCompanyGroupForVehicle | ( | const Vehicle * | v | ) |

Show the group window for the given vehicle.

Parameters

  v | The vehicle to show the window for.

Definition at line 1249 of file group_gui.cpp.

References Vehicle::group_id, Vehicle::owner, and BaseVehicle::type.

Referenced by NewsWindow::OnClick(), VehicleListWindow::OnClick(), and VehicleViewWindow::OnClick().

## ◆ ShowCompanyGroupInternal()

template<bool Tneed_existing_window>

static void ShowCompanyGroupInternal | ( | CompanyID | company,
|  | VehicleType | vehicle_type,
|  | GroupID | group
| ) |  |
| static

Show the group window for the given company and vehicle type.

Parameters

  company | The company to show the window for.
  vehicle_type | The type of vehicle to show it for.
  group | The group to be selected. Defaults to GroupID::Invalid().

Template Parameters

  Tneed_existing_window | Whether the existing window is needed.

Definition at line 1224 of file group_gui.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), VehicleGroupWindow::SelectGroup(), VehicleListIdentifier::ToWindowNumber(), and VL_GROUP_LIST.

## ◆ SortGUIGroupList()

static void SortGUIGroupList | ( | std::vector< GUIGroupListItem > & | list | ) |
| static

Definition at line 113 of file group_gui.cpp.

## Variable Documentation

## ◆ _nested_group_widgets

constexpr std::initializer_list<NWidgetPart> _nested_group_widgets
| staticconstexpr

Definition at line 40 of file group_gui.cpp.

## ◆ _vehicle_group_desc

WindowDesc _vehicle_group_desc[]
| static

Initial value:
= {
{
WDP_AUTO, "list_groups_train", 525, 246,
WC_TRAINS_LIST, WC_NONE,
{},
_nested_group_widgets
},
{
WDP_AUTO, "list_groups_roadveh", 460, 246,
WC_ROADVEH_LIST, WC_NONE,
{},
_nested_group_widgets
},
{
WDP_AUTO, "list_groups_ship", 460, 246,
WC_SHIPS_LIST, WC_NONE,
{},
_nested_group_widgets
},
{
WDP_AUTO, "list_groups_aircraft", 460, 246,
WC_AIRCRAFT_LIST, WC_NONE,
{},
_nested_group_widgets
},
}
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition window_type.h:319
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_SHIPS_LIST
@ WC_SHIPS_LIST
Ships list; Window numbers:
Definition window_type.h:325
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition window_type.h:313
WC_AIRCRAFT_LIST
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Definition window_type.h:331

Definition at line 1189 of file group_gui.cpp.