OpenTTD Source 20241224-master-gf74b0cf984
company_gui.cpp File Reference

Company related GUIs. More...

#include "stdafx.h"
#include "currency.h"
#include "error.h"
#include "gui.h"
#include "window_gui.h"
#include "textbuf_gui.h"
#include "viewport_func.h"
#include "company_func.h"
#include "command_func.h"
#include "network/network.h"
#include "network/network_gui.h"
#include "network/network_func.h"
#include "newgrf.h"
#include "company_manager_face.h"
#include "strings_func.h"
#include "timer/timer_game_economy.h"
#include "dropdown_type.h"
#include "dropdown_common_type.h"
#include "tilehighlight_func.h"
#include "company_base.h"
#include "core/geometry_func.hpp"
#include "object_type.h"
#include "rail.h"
#include "road.h"
#include "engine_base.h"
#include "window_func.h"
#include "road_func.h"
#include "water.h"
#include "station_func.h"
#include "zoom_func.h"
#include "sortlist_type.h"
#include "company_cmd.h"
#include "economy_cmd.h"
#include "group_cmd.h"
#include "group_gui.h"
#include "misc_cmd.h"
#include "object_cmd.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "widgets/company_widget.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  ExpensesList
 Expense list container. More...
 
struct  CompanyFinancesWindow
 Window class displaying the company finances. More...
 
class  DropDownListColourItem< TSprite >
 Colour selection list item, with icon and string components. More...
 
struct  SelectCompanyLiveryWindow
 Company livery colour scheme window. More...
 
class  SelectCompanyManagerFaceWindow
 Management class for customizing the face of the company manager. More...
 
struct  CompanyInfrastructureWindow
 Window with detailed information about the company's infrastructure. More...
 
struct  CompanyWindow
 Window with general information about a company. More...
 
struct  BuyCompanyWindow
 

Functions

static void DoSelectCompanyManagerFace (Window *parent)
 Company GUI constants.
 
static void ShowCompanyInfrastructure (CompanyID company)
 Open the infrastructure window of a company.
 
static uint GetTotalCategoriesHeight ()
 Get the total height of the "categories" column.
 
static uint GetMaxCategoriesWidth ()
 Get the required width of the "categories" column, equal to the widest element.
 
static void DrawCategory (const Rect &r, int start_y, const ExpensesList &list)
 Draw a category of expenses (revenue, operating expenses, capital expenses).
 
static void DrawCategories (const Rect &r)
 Draw the expenses categories.
 
static void DrawPrice (Money amount, int left, int right, int top, TextColour colour)
 Draw an amount of money.
 
static Money DrawYearCategory (const Rect &r, int start_y, const ExpensesList &list, const Expenses &tbl)
 Draw a category of expenses/revenues in the year column.
 
static void DrawYearColumn (const Rect &r, TimerGameEconomy::Year year, const Expenses &tbl)
 Draw a column with prices.
 
void ShowCompanyFinances (CompanyID company)
 Open the finances window of a company.
 
void ShowCompanyLiveryWindow (CompanyID company, GroupID group)
 
void DrawCompanyManagerFace (CompanyManagerFace cmf, Colours colour, const Rect &r)
 Draws the face of a company manager's face.
 
void ShowCompany (CompanyID company)
 Show the window with the overview of the company.
 
void DirtyCompanyInfrastructureWindows (CompanyID company)
 Redraw all windows with company infrastructure counts.
 
void ShowBuyCompanyDialog (CompanyID company, bool hostile_takeover)
 Show the query to buy another company.
 

Variables

static const std::initializer_list< ExpensesType_expenses_list_revenue
 List of revenues.
 
static const std::initializer_list< ExpensesType_expenses_list_operating_costs
 List of operating expenses.
 
static const std::initializer_list< ExpensesType_expenses_list_capital_costs
 List of capital expenses.
 
static const std::initializer_list< ExpensesList_expenses_list_types
 Types of expense lists.
 
static constexpr NWidgetPart _nested_company_finances_widgets []
 
static WindowDesc _company_finances_desc (WDP_AUTO, "company_finances", 0, 0, WC_FINANCES, WC_NONE, 0, _nested_company_finances_widgets)
 
static const LiveryClass _livery_class [LS_END]
 
static constexpr NWidgetPart _nested_select_company_livery_widgets []
 
static WindowDesc _select_company_livery_desc (WDP_AUTO, "company_color_scheme", 0, 0, WC_COMPANY_COLOUR, WC_NONE, 0, _nested_select_company_livery_widgets)
 
static constexpr NWidgetPart _nested_select_company_manager_face_widgets []
 Nested widget description for the company manager face selection dialog.
 
static WindowDesc _select_company_manager_face_desc (WDP_AUTO, nullptr, 0, 0, WC_COMPANY_MANAGER_FACE, WC_NONE, WDF_CONSTRUCTION, _nested_select_company_manager_face_widgets)
 Company manager face selection window description.
 
static constexpr NWidgetPart _nested_company_infrastructure_widgets []
 
static WindowDesc _company_infrastructure_desc (WDP_AUTO, "company_infrastructure", 0, 0, WC_COMPANY_INFRASTRUCTURE, WC_NONE, 0, _nested_company_infrastructure_widgets)
 
static constexpr NWidgetPart _nested_company_widgets []
 
static const StringID _company_view_vehicle_count_strings []
 Strings for the company vehicle counts.
 
static WindowDesc _company_desc (WDP_AUTO, "company", 0, 0, WC_COMPANY, WC_NONE, 0, _nested_company_widgets)
 
static constexpr NWidgetPart _nested_buy_company_widgets []
 
static WindowDesc _buy_company_desc (WDP_AUTO, nullptr, 0, 0, WC_BUY_COMPANY, WC_NONE, WDF_CONSTRUCTION, _nested_buy_company_widgets)
 

Detailed Description

Company related GUIs.

Definition in file company_gui.cpp.

Function Documentation

◆ DirtyCompanyInfrastructureWindows()

◆ DoSelectCompanyManagerFace()

static void DoSelectCompanyManagerFace ( Window parent)
static

Company GUI constants.

Open the simple/advanced company manager face selection window.

Parameters
parentthe parent company window

Definition at line 1740 of file company_gui.cpp.

References _select_company_manager_face_desc, BringWindowToFrontById(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), WC_COMPANY_MANAGER_FACE, and Window::window_number.

Referenced by CompanyWindow::OnClick().

◆ DrawCategories()

static void DrawCategories ( const Rect r)
static

Draw the expenses categories.

Parameters
rAvailable space for drawing.
Note
The environment must provide padding at the left and right of r.

Definition at line 176 of file company_gui.cpp.

References _expenses_list_types, DrawCategory(), DrawString(), FS_NORMAL, GetCharacterHeight(), SA_LEFT, SA_RIGHT, WidgetDimensions::scaled, TimerGameEconomy::UsingWallclockUnits(), WidgetDimensions::vsep_normal, and WidgetDimensions::vsep_wide.

Referenced by CompanyFinancesWindow::DrawWidget().

◆ DrawCategory()

static void DrawCategory ( const Rect r,
int  start_y,
const ExpensesList list 
)
static

Draw a category of expenses (revenue, operating expenses, capital expenses).

Definition at line 159 of file company_gui.cpp.

References _current_text_dir, DrawString(), FS_NORMAL, GetCharacterHeight(), Rect::Indent(), ExpensesList::items, WidgetDimensions::scaled, and TD_RTL.

Referenced by DrawCategories().

◆ DrawCompanyManagerFace()

void DrawCompanyManagerFace ( CompanyManagerFace  cmf,
Colours  colour,
const Rect r 
)

Draws the face of a company manager's face.

Parameters
cmfthe company manager's face
colourthe (background) colour of the gradient
rposition to draw the face

Definition at line 1126 of file company_gui.cpp.

References _cmf_info, CenterBounds(), DrawSprite(), GE_WM, GENDER_FEMALE, GetCompanyManagerFaceBits(), GetCompanyManagerFaceSprite(), GetSpriteSize(), and HasBit().

Referenced by SelectCompanyManagerFaceWindow::DrawWidget(), CompanyWindow::DrawWidget(), BuyCompanyWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), and NewsWindow::DrawWidget().

◆ DrawPrice()

static void DrawPrice ( Money  amount,
int  left,
int  right,
int  top,
TextColour  colour 
)
static

Draw an amount of money.

Parameters
amountAmount of money to draw,
leftLeft coordinate of the space to draw in.
rightRight coordinate of the space to draw in.
topTop coordinate of the space to draw in.
colourThe TextColour of the string.

Definition at line 216 of file company_gui.cpp.

References DrawString(), SA_RIGHT, and SetDParam().

Referenced by DrawYearCategory(), and DrawYearColumn().

◆ DrawYearCategory()

static Money DrawYearCategory ( const Rect r,
int  start_y,
const ExpensesList list,
const Expenses tbl 
)
static

Draw a category of expenses/revenues in the year column.

Returns
The income sum of the category.

Definition at line 233 of file company_gui.cpp.

References WidgetDimensions::bevel, DrawPrice(), FS_NORMAL, GetCharacterHeight(), GfxFillRect(), ExpensesList::items, PC_BLACK, WidgetDimensions::scaled, and WidgetDimensions::vsep_normal.

Referenced by DrawYearColumn().

◆ DrawYearColumn()

static void DrawYearColumn ( const Rect r,
TimerGameEconomy::Year  year,
const Expenses tbl 
)
static

Draw a column with prices.

Parameters
rAvailable space for drawing.
yearYear being drawn.
tblReference to table of amounts for year.
Note
The environment must provide padding at the left and right of r.

Definition at line 262 of file company_gui.cpp.

References _expenses_list_types, WidgetDimensions::bevel, DrawPrice(), DrawString(), DrawYearCategory(), FS_NORMAL, GetCharacterHeight(), GfxFillRect(), PC_BLACK, SA_RIGHT, WidgetDimensions::scaled, SetDParam(), WidgetDimensions::vsep_normal, and WidgetDimensions::vsep_wide.

Referenced by CompanyFinancesWindow::DrawWidget().

◆ GetMaxCategoriesWidth()

static uint GetMaxCategoriesWidth ( )
static

Get the required width of the "categories" column, equal to the widest element.

Returns
The required width in pixels.

Definition at line 141 of file company_gui.cpp.

References _expenses_list_types, GetStringBoundingBox(), WidgetDimensions::hsep_indent, WidgetDimensions::scaled, and TimerGameEconomy::UsingWallclockUnits().

Referenced by CompanyFinancesWindow::UpdateWidgetSize().

◆ GetTotalCategoriesHeight()

static uint GetTotalCategoriesHeight ( )
static

Get the total height of the "categories" column.

Returns
The total height in pixels.

Definition at line 121 of file company_gui.cpp.

References _expenses_list_types, FS_NORMAL, GetCharacterHeight(), WidgetDimensions::scaled, WidgetDimensions::vsep_normal, and WidgetDimensions::vsep_wide.

Referenced by CompanyFinancesWindow::OnPaint(), and CompanyFinancesWindow::UpdateWidgetSize().

◆ ShowBuyCompanyDialog()

void ShowBuyCompanyDialog ( CompanyID  company,
bool  hostile_takeover 
)

Show the query to buy another company.

Parameters
companyThe company to buy.
hostile_takeoverWhether this is a hostile takeover.

Definition at line 2730 of file company_gui.cpp.

References BringWindowToFrontById(), and WC_BUY_COMPANY.

Referenced by HandleBankruptcyTakeover(), and CompanyWindow::OnClick().

◆ ShowCompany()

void ShowCompany ( CompanyID  company)

Show the window with the overview of the company.

Parameters
companyThe company to show the window for.

Definition at line 2595 of file company_gui.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID().

Referenced by GoalListWindow::HandleClick(), MenuClickCompany(), and MainToolbarWindow::OnHotkey().

◆ ShowCompanyFinances()

void ShowCompanyFinances ( CompanyID  company)

Open the finances window of a company.

Parameters
companyCompany to show finances of.
Precondition
is company a valid company.

Definition at line 568 of file company_gui.cpp.

References BringWindowToFrontById(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and WC_FINANCES.

Referenced by MenuClickFinances(), StatusBarWindow::OnClick(), and MainToolbarWindow::OnHotkey().

◆ ShowCompanyInfrastructure()

static void ShowCompanyInfrastructure ( CompanyID  company)
static

Open the infrastructure window of a company.

Parameters
companyCompany to show infrastructure of.

Definition at line 2116 of file company_gui.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID().

Referenced by CompanyFinancesWindow::OnClick(), and CompanyWindow::OnClick().

◆ ShowCompanyLiveryWindow()

void ShowCompanyLiveryWindow ( CompanyID  company,
GroupID  group 
)

Definition at line 1110 of file company_gui.cpp.

Variable Documentation

◆ _company_view_vehicle_count_strings

const StringID _company_view_vehicle_count_strings[]
static
Initial value:
= {
STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
}

Strings for the company vehicle counts.

Definition at line 2199 of file company_gui.cpp.

Referenced by CompanyWindow::UpdateWidgetSize().

◆ _expenses_list_capital_costs

const std::initializer_list<ExpensesType> _expenses_list_capital_costs
static
Initial value:
= {
}
@ EXPENSES_CONSTRUCTION
Construction costs.
@ EXPENSES_OTHER
Other expenses.
@ EXPENSES_NEW_VEHICLES
New vehicles.

List of capital expenses.

Definition at line 78 of file company_gui.cpp.

◆ _expenses_list_operating_costs

const std::initializer_list<ExpensesType> _expenses_list_operating_costs
static
Initial value:
= {
}
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
@ EXPENSES_TRAIN_RUN
Running costs trains.
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
@ EXPENSES_PROPERTY
Property costs.
@ EXPENSES_LOAN_INTEREST
Interest payments over the loan.
@ EXPENSES_SHIP_RUN
Running costs ships.

List of operating expenses.

Definition at line 68 of file company_gui.cpp.

◆ _expenses_list_revenue

const std::initializer_list<ExpensesType> _expenses_list_revenue
static
Initial value:
= {
}
@ EXPENSES_AIRCRAFT_REVENUE
Revenue from aircraft.
@ EXPENSES_ROADVEH_REVENUE
Revenue from road vehicles.
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.

List of revenues.

Definition at line 60 of file company_gui.cpp.

◆ _expenses_list_types

const std::initializer_list<ExpensesList> _expenses_list_types
static
Initial value:
= {
{ STR_FINANCES_REVENUE_TITLE, _expenses_list_revenue },
{ STR_FINANCES_OPERATING_EXPENSES_TITLE, _expenses_list_operating_costs },
{ STR_FINANCES_CAPITAL_EXPENSES_TITLE, _expenses_list_capital_costs },
}
static const std::initializer_list< ExpensesType > _expenses_list_capital_costs
List of capital expenses.
static const std::initializer_list< ExpensesType > _expenses_list_operating_costs
List of operating expenses.
static const std::initializer_list< ExpensesType > _expenses_list_revenue
List of revenues.

Types of expense lists.

Definition at line 111 of file company_gui.cpp.

Referenced by DrawCategories(), DrawYearColumn(), GetMaxCategoriesWidth(), and GetTotalCategoriesHeight().

◆ _livery_class

const LiveryClass _livery_class[LS_END]
static
Initial value:
= {
LC_OTHER,
LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL, LC_RAIL,
LC_ROAD, LC_ROAD,
LC_SHIP, LC_SHIP,
LC_AIRCRAFT, LC_AIRCRAFT, LC_AIRCRAFT,
LC_ROAD, LC_ROAD,
}

Definition at line 577 of file company_gui.cpp.

◆ _nested_buy_company_widgets

constexpr NWidgetPart _nested_buy_company_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_BC_CAPTION), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BC_FACE), SetFill(0, 1),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BC_QUESTION), SetMinimalSize(240, 0), SetFill(1, 1),
NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_BC_NO), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_NO, STR_NULL), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_LIGHT_BLUE, WID_BC_YES), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_YES, STR_NULL), SetFill(1, 0),
}
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
@ WID_BC_NO
No button.
@ WID_BC_YES
Yes button.
@ WID_BC_QUESTION
Question text.
@ WID_BC_CAPTION
Caption of window.
@ WID_BC_FACE
Face button.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:55
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:48

Definition at line 2699 of file company_gui.cpp.

◆ _nested_company_finances_widgets

constexpr NWidgetPart _nested_company_finances_widgets[]
staticconstexpr

Definition at line 286 of file company_gui.cpp.

◆ _nested_company_infrastructure_widgets

constexpr NWidgetPart _nested_company_infrastructure_widgets[]
staticconstexpr

Definition at line 1748 of file company_gui.cpp.

◆ _nested_company_widgets

constexpr NWidgetPart _nested_company_widgets[]
staticconstexpr

Definition at line 2122 of file company_gui.cpp.

◆ _nested_select_company_livery_widgets

constexpr NWidgetPart _nested_select_company_livery_widgets[]
staticconstexpr

Definition at line 1071 of file company_gui.cpp.

◆ _nested_select_company_manager_face_widgets

constexpr NWidgetPart _nested_select_company_manager_face_widgets[]
staticconstexpr

Nested widget description for the company manager face selection dialog.

Definition at line 1169 of file company_gui.cpp.