49#include "table/strings.h"
88 const std::initializer_list<ExpensesType> &
items;
94 uint GetHeight()
const
197 y += list.GetHeight();
225 StringID str = STR_FINANCES_NEGATIVE_INCOME;
227 str = STR_FINANCES_ZERO_INCOME;
228 }
else if (amount < 0) {
230 str = STR_FINANCES_POSITIVE_INCOME;
249 Money cost = tbl[et];
295static constexpr std::initializer_list<NWidgetPart> _nested_company_finances_widgets = {
420 size.
width += padding.width;
503 this->small = !this->small;
528 void RefreshVisibleColumns()
530 for (uint period = 0; period < this->first_visible; ++period) {
534 if (std::ranges::any_of(expenses, [](
const Money &value) {
return value != 0; })) {
543 this->RefreshVisibleColumns();
566 WindowClass::Finances, WindowClass::None,
568 _nested_company_finances_widgets
587 LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
LiveryClass::Rail,
598template <SpriteID TSprite = SPR_SQUARE>
599class DropDownListColourItem :
public DropDownIcon<DropDownString<DropDownListItem>> {
601 DropDownListColourItem(
int colour,
bool masked) :
620struct SelectCompanyLiveryWindow :
public Window {
629 uint line_height = 0;
630 GUIGroupList groups{};
631 Scrollbar *vscroll =
nullptr;
634 void ShowColourDropDownMenu(uint32_t widget)
637 const Livery *livery, *default_livery =
nullptr;
639 uint8_t default_col{};
643 for (
const Company *c : Company::Iterate()) {
653 livery = &c->livery[scheme];
658 if (g->
parent == GroupID::Invalid()) {
662 default_livery = &pg->
livery;
667 if (default_livery !=
nullptr) {
670 list.push_back(std::make_unique<DropDownListColourItem<>>(default_col,
false));
673 list.push_back(std::make_unique<DropDownListColourItem<>>(
to_underlying(colour), used_colours.
Test(colour)));
695 void BuildGroupList(CompanyID
owner)
699 this->groups.clear();
714 this->rows = (uint)this->groups.size();
717 this->vscroll->SetCount(this->rows);
721 SelectCompanyLiveryWindow(WindowDesc &desc, CompanyID company, GroupID
group) :
Window(desc)
727 if (
group == GroupID::Invalid()) {
732 this->BuildGroupList(company);
735 this->SetSelectedGroup(company,
group);
739 this->
owner = company;
743 void SetSelectedGroup(CompanyID company, GroupID
group)
752 default: NOT_REACHED();
757 this->groups.ForceRebuild();
758 this->BuildGroupList(company);
762 for (uint i = 0; i < this->rows; i++) {
763 if (this->groups[i].
group->index == this->sel.group) {
764 this->vscroll->SetPosition(i - this->vscroll->GetCapacity() / 2);
789 size.
height = 5 * this->line_height;
791 fill.height =
resize.height = this->line_height;
816 bool disabled = this->livery_class <
LiveryClass::GroupRail ? this->sel.schemes.None() : (this->sel.group == GroupID::Invalid());
835 StringID colour = STR_COLOUR_DEFAULT;
840 const Livery &livery = c->livery[scheme];
846 if (this->sel.group != GroupID::Invalid()) {
885 int square_offs = (ir.
Height() - this->square.
height) / 2;
891 auto draw_livery = [&](std::string_view str,
const Livery &livery,
bool is_selected,
bool is_default_scheme,
int indent) {
900 if (sec.right > sec.left) {
905 y += this->line_height;
913 if (pos-- > 0)
continue;
918 for (
auto it = first; it != last; ++it) {
919 const Group *g = it->group;
923 if (this->vscroll->
GetCount() == 0) {
924 constexpr VehicleTypeIndexArray<const StringID> empty_labels = { STR_LIVERY_TRAIN_GROUP_EMPTY, STR_LIVERY_ROAD_VEHICLE_GROUP_EMPTY, STR_LIVERY_SHIP_GROUP_EMPTY, STR_LIVERY_AIRCRAFT_GROUP_EMPTY };
953 this->sel.group = GroupID::Invalid();
957 if (!this->groups.empty()) {
958 this->sel.group = this->groups[0].group->index;
977 if (row >= this->rows)
return;
982 this->sel.schemes.Flip(scheme);
984 this->sel.schemes = scheme;
988 if (it == std::end(this->groups))
return;
990 this->sel.group = it->group->index;
1030 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1032 if (!gui_scope)
return;
1042 this->sel.group = GroupID::Invalid();
1043 if (!this->groups.empty()) this->sel.group = this->groups[0].group->index;
1058 if (
_livery_class[scheme] == this->livery_class) current_class_valid =
true;
1063 if (!current_class_valid) {
1070static constexpr std::initializer_list<NWidgetPart> _nested_select_company_livery_widgets = {
1091 NWidget(
WWT_MATRIX,
Colours::Grey,
WID_SCL_MATRIX),
SetMinimalSize(275, 0),
SetResize(1, 0),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_LIVERY_PANEL_TOOLTIP),
SetScrollbar(
WID_SCL_MATRIX_SCROLLBAR),
1107 WindowClass::CompanyLivery, WindowClass::None,
1109 _nested_select_company_livery_widgets
1112void ShowCompanyLiveryWindow(CompanyID company, GroupID group)
1117 }
else if (group != GroupID::Invalid()) {
1118 w->SetSelectedGroup(company, group);
1140 std::unordered_map<uint8_t, PaletteID> palettes;
1147 switch (vars[var].GetBits(cmf)) {
1148 default: NOT_REACHED();
1153 for (uint8_t affected_var :
SetBitIterator(std::get<uint64_t>(vars[var].data))) {
1154 palettes[affected_var] = pal;
1165 auto it = palettes.find(var);
1166 PaletteID pal = (it == std::end(palettes)) ? PAL_NONE : it->second;
1167 DrawSprite(vars[var].GetSprite(cmf), pal, x, y);
1200 NWidget(
WWT_MATRIX,
Colours::Grey,
WID_SCMF_PARTS),
SetResize(1, 1),
SetFill(1, 1),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_SCMF_PARTS_SCROLLBAR),
1216class SelectCompanyManagerFaceWindow :
public Window
1237 if (vars[var].name == STR_NULL)
ClrBit(active_vars, var);
1241 this->face_vars.clear();
1243 this->face_vars.emplace_back(&vars[var]);
1280 wi->
SetStringTip(STR_FACE_SIMPLE, STR_FACE_SIMPLE_TOOLTIP);
1282 wi->
SetStringTip(STR_FACE_ADVANCED, STR_FACE_ADVANCED_TOOLTIP);
1291 static uint GetMaximumFacePartsWidth()
1293 StringID yes_no = GetLongestString(STR_FACE_YES, STR_FACE_NO);
1298 for (
const auto &info : vars) {
1299 if (info.name == STR_NULL)
continue;
1322 size.
height = this->line_height;
1326 fill.height =
resize.height = this->line_height;
1327 size.
width = GetMaximumFacePartsWidth();
1359 for (
auto it = first; it != last; ++it) {
1360 const uint8_t var =
static_cast<uint8_t
>(*it - vars.data());
1361 const FaceVar &facevar = **it;
1366 uint val = vars[var].GetBits(this->face);
1375 ir = ir.
Translate(0, this->line_height);
1388 this->advanced = !this->advanced;
1395 Command<Commands::SetCompanyManagerFace>::Post(this->face.
style, this->face.bits);
1406 if (cmf.has_value()) this->face = *cmf;
1437 this->selected_var = UINT_MAX - 1;
1440 this->click_state = 1;
1443 this->click_state = 2;
1457 this->selected_var = UINT_MAX;
1461 if (it == std::end(this->face_vars))
break;
1463 this->selected_var =
static_cast<uint8_t
>(*it - vars.data());
1464 const auto &facevar = **it;
1468 facevar.ChangeBits(this->face, 1);
1472 facevar.ChangeBits(this->face, -1);
1473 this->click_state = 1;
1475 facevar.ChangeBits(this->face, 1);
1476 this->click_state = 2;
1494 if (wid->UpdateVerticalSize((wid->current_y + wid->resize_y - 1) / wid->resize_y * wid->resize_y)) {
1505 this->click_state = 0;
1506 this->selected_var = UINT_MAX;
1512 if (!str.has_value())
return;
1515 if (cmf.has_value()) {
1529 WindowClass::CompanyManagerFace, WindowClass::None,
1547static constexpr std::initializer_list<NWidgetPart> _nested_company_infrastructure_widgets = {
1585 uint count_width = 0;
1586 uint cost_width = 0;
1588 mutable std::vector<InfrastructureItem> list;
1593 this->owner = this->window_number;
1598 this->UpdateInfrastructureList();
1601 void UpdateInfrastructureList()
1606 if (c ==
nullptr)
return;
1608 Money total_monthly_cost = 0;
1617 total_monthly_cost += monthly_cost;
1623 total_monthly_cost += monthly_cost;
1628 if (uint32_t road_total = c->
infrastructure.GetRoadTotal(); road_total > 0) {
1634 if (!RoadTypeIsRoad(rt))
continue;
1637 total_monthly_cost += monthly_cost;
1642 if (uint32_t tram_total = c->
infrastructure.GetTramTotal(); tram_total > 0) {
1648 if (!RoadTypeIsTram(rt))
continue;
1651 total_monthly_cost += monthly_cost;
1662 total_monthly_cost += monthly_cost;
1673 total_monthly_cost += monthly_cost;
1677 if (airport_cost > 0) {
1678 Money monthly_cost = airport_cost;
1679 total_monthly_cost += monthly_cost;
1707 if (def_height == 0) {
1710 int delta = std::min(20,
static_cast<int>(std::size(this->list))) - rows;
1721 uint max_count = 1000;
1722 Money max_cost = 1000000;
1725 static constexpr StringID header_strings[] = {
1726 STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT,
1727 STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT,
1728 STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT,
1729 STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT,
1730 STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT,
1733 static constexpr StringID label_strings[] = {
1734 STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS,
1735 STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS,
1736 STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS,
1737 STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS,
1748 max_count = std::max(max_count, entry.count);
1749 max_cost = std::max(max_cost, entry.cost * 12);
1758 this->cost_width = 0;
1780 for (
auto it = first; it != last; ++it) {
1805 labelr.top += line_height;
1806 countr.top += line_height;
1807 costr.top += line_height;
1812 this->UpdateInfrastructureList();
1826 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1828 if (!gui_scope)
return;
1837 WindowClass::CompanyInfrastructure, WindowClass::None,
1839 _nested_company_infrastructure_widgets
1852static constexpr std::initializer_list<NWidgetPart> _nested_company_widgets = {
1930 STR_COMPANY_VIEW_TRAINS, STR_COMPANY_VIEW_ROAD_VEHICLES, STR_COMPANY_VIEW_SHIPS, STR_COMPANY_VIEW_AIRCRAFT
1957 this->owner = this->window_number;
1967 bool reinit =
false;
2035 size.
width += padding.width;
2053 size.
width += padding.width;
2058 void DrawVehicleCountsWidget(
const Rect &r,
const Company *c)
const
2062 uint amount = c->
group_all[type].num_vehicle;
2071 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
2075 void DrawInfrastructureCountsWidget(
const Rect &r,
const Company *c)
const
2080 if (rail_pieces != 0) {
2081 DrawString(r.left, r.right, y,
GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL, rail_pieces));
2087 if (road_pieces != 0) {
2088 DrawString(r.left, r.right, y,
GetString(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD, road_pieces));
2109 DrawString(r.left, r.right, y, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE);
2134 DrawVehicleCountsWidget(r, c);
2138 DrawInfrastructureCountsWidget(r, c);
2178 ShowCompanyLiveryWindow(this->
window_number, GroupID::Invalid());
2261 if (Command<Commands::BuildObject>::Post(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS, tile,
OBJECT_HQ, 0) && !
IsShiftPressed()) {
2277 if (!str.has_value())
return;
2280 default: NOT_REACHED();
2284 if (!value.has_value())
return;
2286 Command<Commands::GiveMoney>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, this->
window_number);
2291 Command<Commands::RenamePresident>::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, *str);
2295 Command<Commands::RenameCompany>::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, *str);
2300 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2302 if (!gui_scope)
return;
2317 WindowClass::Company, WindowClass::None,
2319 _nested_company_widgets
2370 return GetString(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY,
Company::Get(this->window_number)->index);
2402 Command<Commands::BuyCompany>::Post(STR_ERROR_CAN_T_BUY_COMPANY, this->window_number, this->hostile_takeover);
2412 if (!this->hostile_takeover)
return;
2423 bool hostile_takeover =
false;
2427static constexpr std::initializer_list<NWidgetPart> _nested_buy_company_widgets = {
2449 WindowClass::BuyCompany, WindowClass::None,
2451 _nested_buy_company_widgets
2462 if (window ==
nullptr) {
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Set()
Set all bits.
std::optional< Tvalue_type > GetNthSetBit(uint n) const
Get the value of the Nth set bit.
bool masked
Masked and unselectable item.
Iterate a range of enum values.
void RebuildDone()
Notify the sortlist that the rebuild is done.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
An interval timer will fire every interval, and will continue to fire until it is deleted.
StringID name
Name of this rail type.
StringID name
Name of this rail type.
Management class for customizing the face of the company manager.
void SelectDisplayPlanes(bool advanced)
Select planes to display to the user with the NWID_SELECTION widgets WID_SCMF_SEL_LOADSAVE,...
uint click_state
Click state on selected face variable.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
std::vector< const FaceVar * > face_vars
Visible face variables.
void OnResize() override
Called after the window got resized.
bool advanced
advanced company manager face selection window
uint selected_var
Currently selected face variable. UINT_MAX for none, UINT_MAX - 1 means style is clicked instead.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
CompanyManagerFace face
company manager face bits
int line_height
Height of each face variable row.
void UpdateData()
Make face bits valid and update visible face variables.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnTimeout() override
Called when this window's timeout has been reached.
void OnInit() override
Notification that the nested widget tree gets initialized.
static Year year
Current year, starting at 0.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
StrongType::Typedef< int32_t, struct YearTag< struct Economy >, StrongType::Compare, StrongType::Integer > Year
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
Money CalculateHostileTakeoverValue(const Company *c)
Calculate what you have to pay to take over a company.
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
std::optional< CompanyManagerFace > ParseCompanyManagerFaceCode(std::string_view str)
Parse a face code into a company manager face.
FaceVars GetCompanyManagerFaceVars(uint style)
Get the face variables for a face style.
void RandomiseCompanyManagerFace(CompanyManagerFace &cmf, Randomizer &randomizer)
Completely randomise a company manager face, including style.
std::string _company_manager_face
for company manager face storage in openttd.cfg
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
void SetCompanyManagerFaceStyle(CompanyManagerFace &cmf, uint style)
Set a company face style.
uint GetNumCompanyManagerFaceStyles()
Get the number of company manager face styles.
std::string FormatCompanyManagerFaceCode(const CompanyManagerFace &cmf)
Get a face code representation of a company manager face.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Command definitions related to companies.
Functions related to companies.
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
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 uint GetMaxCategoriesWidth()
Get the required width of the "categories" column, equal to the widest element.
constexpr uint8_t GetColourOffset(const Livery &l, bool primary)
Get either the primary or secondary colour of the given Livery for offsets.
static void DrawYearColumn(const Rect &r, TimerGameEconomy::Year year, const Expenses &tbl)
Draw a column with prices.
static WindowDesc _company_desc(WindowPosition::Automatic, "company", 0, 0, WindowClass::Company, WindowClass::None, {}, _nested_company_widgets)
Window definition for the company window.
static const std::initializer_list< ExpensesType > _expenses_list_capital_costs
List of capital expenses.
void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
Show the query to buy another company.
static WindowDesc _company_finances_desc(WindowPosition::Automatic, "company_finances", 0, 0, WindowClass::Finances, WindowClass::None, {}, _nested_company_finances_widgets)
Window definition for the company finances window.
static const std::initializer_list< ExpensesList > _expenses_list_types
Types of expense lists.
static void DrawPrice(Money amount, int left, int right, int top, TextColour colour)
Draw an amount of money.
static constexpr VehicleTypeIndexArray< const StringID > _company_view_vehicle_count_strings
Strings for the company vehicle counts.
static const EnumIndexArray< LiveryClass, LiveryScheme, LiveryScheme::End > _livery_class
Association of liveries to livery classes.
static void ShowCompanyInfrastructure(CompanyID company)
Open the infrastructure window of a company.
static void DrawCategories(const Rect &r)
Draw the expenses categories.
static void DoSelectCompanyManagerFace(Window *parent)
Company GUI constants.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
static WindowDesc _buy_company_desc(WindowPosition::Automatic, {}, 0, 0, WindowClass::BuyCompany, WindowClass::None, WindowDefaultFlag::Construction, _nested_buy_company_widgets)
Window definition for the window to buy a company.
static WindowDesc _select_company_manager_face_desc(WindowPosition::Automatic, {}, 0, 0, WindowClass::CompanyManagerFace, WindowClass::None, WindowDefaultFlag::Construction, _nested_select_company_manager_face_widgets)
Company manager face selection window description.
static WindowDesc _company_infrastructure_desc(WindowPosition::Automatic, "company_infrastructure", 0, 0, WindowClass::CompanyInfrastructure, WindowClass::None, {}, _nested_company_infrastructure_widgets)
Window definition for the company infrastructure statistics window.
static const std::initializer_list< ExpensesType > _expenses_list_operating_costs
List of operating expenses.
static uint GetTotalCategoriesHeight()
Get the total height of the "categories" column.
static constexpr std::initializer_list< NWidgetPart > _nested_select_company_manager_face_widgets
Nested widget description for the company manager face selection dialog.
static const std::initializer_list< ExpensesType > _expenses_list_revenue
List of revenues.
static WindowDesc _select_company_livery_desc(WindowPosition::Automatic, "company_colour_scheme", 0, 0, WindowClass::CompanyLivery, WindowClass::None, {}, _nested_select_company_livery_widgets)
Window definition for the company livery configuration window.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
void DrawCompanyManagerFace(const CompanyManagerFace &cmf, Colours colour, const Rect &r)
Draws the face of a company manager's face.
static void DrawCategory(const Rect &r, int start_y, const ExpensesList &list)
Draw a category of expenses (revenue, operating expenses, capital expenses).
Functionality related to the company manager's face.
@ Palette
FaceVar describes a palette to apply to the given parts bitmask.
@ Sprite
FaceVar describes an offset to the given SpriteID.
@ Toggle
FaceVar describes which other FaceVars should be turned off.
uint64_t GetActiveFaceVars(const CompanyManagerFace &cmf, FaceVars vars)
Get a bitmask of currently active face variables.
void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf, FaceVars vars)
Scales all company manager's face bits to the correct scope.
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS
The maximum length of a president name in characters including '\0'.
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including '\0'.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
Functions to handle different currencies.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Common drop down list components.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Command definitions related to the economy.
EnumIndexArray< Money, ExpensesType, ExpensesType::End > Expenses
Data type for storage of Money for each ExpensesType category.
ExpensesType
Types of expenses.
@ LoanInterest
Interest payments over the loan.
@ Construction
Construction costs.
@ TrainRun
Running costs trains.
@ AircraftRevenue
Revenue from aircraft.
@ Property
Property costs.
@ RoadVehRevenue
Revenue from road vehicles.
@ NewVehicles
New vehicles.
@ AircraftRun
Running costs aircraft.
@ RoadVehRun
Running costs road vehicles.
@ ShipRevenue
Revenue from ships.
@ TrainRevenue
Revenue from trains.
@ ShipRun
Running costs ships.
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
Functions related to errors.
@ Info
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
@ ForceRight
Force align to the right.
@ Centre
Align to the centre.
@ End
Align to the end, LTR/RTL aware.
@ Start
Align to the start, LTR/RTL aware.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
@ Middle
Align to the middle.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
uint GetStringListWidth(std::span< const StringID > list, FontSize fontsize)
Get maximum width of a list of strings.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool IsShiftPressed()
Test if the shift key is pressed.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
bool IsCtrlPressed()
Test if the ctrl key is pressed.
@ Normal
Index of the normal font in the font tables.
uint32_t PaletteID
The number of the palette.
Colours
One of 16 base colours used for companies and windows/widgets.
@ End
End-of-array marker.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ FromString
Marker for telling to use the colour from the string.
@ Company
Destination is a company.
Command definitions related to engine groups.
static const CursorID SPR_CURSOR_HQ
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
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.
Functions/definitions that have something to do with groups.
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
static const uint8_t LIT_ALL
Show the liveries of all companies.
EnumBitSet< LiveryScheme, uint32_t, LiveryScheme::End > LiverySchemes
Bitset of LiveryScheme elements.
LiveryScheme
List of different livery schemes.
static const uint8_t LIT_COMPANY
Show the liveries of your own company.
LiveryClass
List of different livery classes, used only by the livery GUI.
@ Ship
Ship livery schemes.
@ Rail
Rail livery schemes.
@ Other
General livery schemes.
@ GroupAircraft
Aircraft group.
@ Aircraft
Aircraft livery schemes.
@ Road
Road livery schemes.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Miscellaneous command definitions.
@ Max
Loan/repay the maximum amount permitting money/settings.
@ Interval
Loan/repay LOAN_INTERVAL.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
void UpdateQueryStringDefault(std::string_view str)
Updates default text value of query strign window.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
bool NetworkCanJoinCompany(CompanyID company_id)
Returns whether the given company can be joined by this client.
Basic functions/variables used all over the place.
void NetworkClientRequestMove(CompanyID company_id)
Notify the server of this client wanting to be moved to another company.
Network functions used by other parts of OpenTTD.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
@ Server
Servers always have this ID.
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Base for the NewGRF implementation.
Command definitions related to objects.
Types related to object tiles.
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
static constexpr PixelColour PC_BLACK
Black palette colour.
static constexpr PixelColour PC_WHITE
White palette colour.
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
Money RailMaintenanceCost(RailType railtype, uint32_t num, uint32_t total_num)
Calculates the maintenance cost of a number of track bits.
Money SignalMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of signals.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
RailType
Enumeration for all possible railtypes.
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Functions related to roads.
Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t total_num)
Calculates the maintenance cost of a number of road bits.
RoadType
The different roadtypes we support.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
static const SpriteID SPR_IMG_COMPANY_GENERAL
static const SpriteID SPR_IMG_TRAINLIST
static const SpriteID SPR_SQUARE
Coloured square (used for newgrf compatibility).
static const SpriteID SPR_IMG_TRUCKLIST
static const PaletteID PALETTE_TO_BROWN
static const PaletteID PALETTE_TO_BLUE
static const PaletteID PALETTE_TO_GREEN
static const SpriteID SPR_IMG_AIRPLANESLIST
static const SpriteID SPR_IMG_SHIPLIST
static const SpriteID SPR_GRADIENT
Manager face sprites.
static const SpriteID SPR_VEH_BUS_SW_VIEW
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Functions related to stations.
Money StationMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of station tiles.
Definition of base types and functions in a cross-platform compatible way.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL
Only numeric ones.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Money company_value
The value of the company for which the user can buy it.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
bool hostile_takeover
Whether the window is showing a hostile takeover.
const IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the company value has changed.
Window class displaying the company finances.
const IntervalTimer< TimerWindow > rescale_interval
Check on a regular interval if the maximum amount of money has changed.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int, bool) override
Some data on this window has become invalid.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
bool small
Window is toggled to 'small'.
static Money max_money
The maximum amount of money a company has had this 'run'.
uint8_t first_visible
First visible expenses column. The last column (current) is always visible.
void SetupWidgets()
Setup the widgets in the nested tree, such that the finances window is displayed properly.
void OnPaint() override
The window must be repainted.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
@ Value
Label with values.
void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize) override
Resize window towards the default size.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnResize() override
Called after the window got resized.
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
uint32_t GetRailTotal() const
Get total sum of all owned track bits.
uint32_t station
Count of company owned station tiles.
uint32_t signal
Count of company owned signals.
std::array< uint32_t, RAILTYPE_END > rail
Count of company owned track bits for each rail type.
uint32_t airport
Count of company owned airports.
uint32_t water
Count of company owned track bits for canals.
uint style
Company manager face style.
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Money current_loan
Amount of money borrowed from the bank.
TimerGameCalendar::Year inaugurated_year_calendar
Calendar year of starting the company. Used to display proper Inauguration year while in wallclock mo...
TimerGameEconomy::Year inaugurated_year
Economy year of starting the company.
Colours colour
Company colour.
CompanyManagerFace face
Face description of the president.
std::array< Expenses, 3 > yearly_expenses
Expenses of the company for the last three years.
Money money
Money owned by the company.
Window with general information about a company.
void OnResize() override
Called after the window got resized.
const IntervalTimer< TimerWindow > redraw_interval
Redraw the window on a regular interval.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static constexpr CompanyWidgets INVALID_QUERY_WIDGET
WID_C_CAPTION does not have a query string, so it can be safely used as invalid value.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
CompanyWindowPlanes
Display planes in the company window.
@ CWP_RELOCATE_SHOW
Show the relocate HQ button.
@ CWP_RELOCATE_HIDE
Hide the relocate HQ button.
@ CWP_VB_BUILD
Display the build button.
@ CWP_VB_VIEW
Display the view button.
void OnPaint() override
The window must be repainted.
Money GetMaxLoan() const
Calculate the max allowed loan for this company.
VehicleTypeIndexArray< GroupStatistics > group_all
NOSAVE: Statistics for the ALL_GROUP group.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
uint16_t rate
The conversion rate compared to the base currency.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
bool infrastructure_maintenance
enable monthly maintenance fee for owner infrastructure
uint GetListWidth() const
Compute width of the expenses categories.
const std::initializer_list< ExpensesType > & items
List of expenses types.
const StringID title
StringID of list title.
Information about the valid values of CompanyManagerFace bitgroups as well as the sprites to draw.
uint8_t position
Position in UI.
FaceVarType type
Type of variable.
StringID name
Name of the configurable component of the face.
uint8_t valid_values
The number of valid values.
bool has_2CC
Set if any vehicle is loaded which uses 2cc (two company colours).
EconomySettings economy
settings to change the economy
Livery livery
Custom colour scheme for vehicles in this group.
GroupID parent
Parent group.
VehicleType vehicle_type
Vehicle type of the group.
Information about a particular livery.
Flags in_use
Livery flags.
Colours colour2
Second colour, for vehicles with 2CC support.
Colours colour1
First colour, for all vehicles.
@ Primary
Primary colour is set.
@ Secondary
Secondary colour is set.
static Company * Get(auto index)
static bool IsValidID(auto index)
static Company * GetIfValid(auto index)
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect CentreToHeight(int height) const
Centre a vertical dimension within this Rect.
int Height() const
Get height of Rect.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Company livery colour scheme window.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
LiverySchemes visible_schemes
Currently visible livery schemes.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void BuildLiveryList()
Build 'list' of visible livery schemes.
struct SelectCompanyLiveryWindow::@313207310206021013204234143253377076057020012134 sel
Current selection.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnPaint() override
The window must be repainted.
LiverySchemes schemes
Selected schemes.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnResize() override
Called after the window got resized.
GroupID group
Selected group.
Iterable ensemble of each set bit in a value.
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Window * parent
Parent window.
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
ResizeInfo resize
Resize information.
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
bool IsShaded() const
Is window shaded currently?
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int height
Height of the window (number of pixels down in y direction).
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
@ LengthIsInChars
the length of the string is counted in characters
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
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...
@ HT_RECT
rectangle (stations, depots, ...)
Definition of Interval and OneShot timers.
Definition of the game-economy-timer.
Definition of the Window system.
VehicleType
Available vehicle types.
@ CompanyEnd
Last company-ownable type.
@ Aircraft
Aircraft vehicle type.
@ Train
Train vehicle type.
EnumIndexArray< T, VehicleType, Tend > VehicleTypeIndexArray
Array with VehicleType as index.
@ Group
Index is the group.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
Functions related to water management.
Money CanalMaintenanceCost(uint32_t num)
Calculates the maintenance cost of a number of canal tiles.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.