2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file company_gui.cpp %Company related GUIs. */
14 #include "window_gui.h"
15 #include "textbuf_gui.h"
16 #include "viewport_func.h"
17 #include "company_func.h"
18 #include "command_func.h"
19 #include "network/network.h"
20 #include "network/network_gui.h"
21 #include "network/network_func.h"
23 #include "company_manager_face.h"
24 #include "strings_func.h"
25 #include "date_func.h"
26 #include "widgets/dropdown_type.h"
27 #include "tilehighlight_func.h"
28 #include "company_base.h"
29 #include "core/geometry_func.hpp"
30 #include "object_type.h"
33 #include "engine_base.h"
34 #include "window_func.h"
35 #include "road_func.h"
37 #include "station_func.h"
38 #include "zoom_func.h"
39 #include "sortlist_type.h"
41 #include "widgets/company_widget.h"
43 #include "safeguards.h"
46 /** Company GUI constants. */
47 static const uint EXP_LINESPACE
= 2; ///< Amount of vertical space for a horizontal (sub-)total line.
48 static const uint EXP_BLOCKSPACE
= 10; ///< Amount of vertical space between two blocks of numbers.
50 static void DoSelectCompanyManagerFace(Window
*parent
);
51 static void ShowCompanyInfrastructure(CompanyID company
);
53 /** Standard unsorted list of expenses. */
54 static ExpensesType _expenses_list_1
[] = {
55 EXPENSES_CONSTRUCTION
,
56 EXPENSES_NEW_VEHICLES
,
59 EXPENSES_AIRCRAFT_RUN
,
64 EXPENSES_AIRCRAFT_INC
,
70 /** Grouped list of expenses. */
71 static ExpensesType _expenses_list_2
[] = {
74 EXPENSES_AIRCRAFT_INC
,
79 EXPENSES_AIRCRAFT_RUN
,
84 EXPENSES_CONSTRUCTION
,
85 EXPENSES_NEW_VEHICLES
,
90 /** Expense list container. */
92 const ExpensesType
*et
; ///< Expenses items.
93 const uint length
; ///< Number of items in list.
94 const uint num_subtotals
; ///< Number of sub-totals in the list.
96 ExpensesList(ExpensesType
*et
, int length
, int num_subtotals
) : et(et
), length(length
), num_subtotals(num_subtotals
)
100 uint
GetHeight() const
102 /* heading + line + texts of expenses + sub-totals + total line + total text */
103 return FONT_HEIGHT_NORMAL
+ EXP_LINESPACE
+ this->length
* FONT_HEIGHT_NORMAL
+ num_subtotals
* (EXP_BLOCKSPACE
+ EXP_LINESPACE
) + EXP_LINESPACE
+ FONT_HEIGHT_NORMAL
;
106 /** Compute width of the expenses categories in pixels. */
107 uint
GetCategoriesWidth() const
110 bool invalid_expenses_measured
= false; // Measure 'Total' width only once.
111 for (uint i
= 0; i
< this->length
; i
++) {
112 ExpensesType et
= this->et
[i
];
113 if (et
== INVALID_EXPENSES
) {
114 if (!invalid_expenses_measured
) {
115 width
= std::max(width
, GetStringBoundingBox(STR_FINANCES_TOTAL_CAPTION
).width
);
116 invalid_expenses_measured
= true;
119 width
= std::max(width
, GetStringBoundingBox(STR_FINANCES_SECTION_CONSTRUCTION
+ et
).width
);
126 static const ExpensesList _expenses_list_types
[] = {
127 ExpensesList(_expenses_list_1
, lengthof(_expenses_list_1
), 0),
128 ExpensesList(_expenses_list_2
, lengthof(_expenses_list_2
), 3),
132 * Draw the expenses categories.
133 * @param r Available space for drawing.
134 * @note The environment must provide padding at the left and right of \a r.
136 static void DrawCategories(const Rect
&r
)
140 DrawString(r
.left
, r
.right
, y
, STR_FINANCES_EXPENDITURE_INCOME_TITLE
, TC_FROMSTRING
, SA_HOR_CENTER
, true);
141 y
+= FONT_HEIGHT_NORMAL
+ EXP_LINESPACE
;
143 int type
= _settings_client
.gui
.expenses_layout
;
144 for (uint i
= 0; i
< _expenses_list_types
[type
].length
; i
++) {
145 const ExpensesType et
= _expenses_list_types
[type
].et
[i
];
146 if (et
== INVALID_EXPENSES
) {
148 DrawString(r
.left
, r
.right
, y
, STR_FINANCES_TOTAL_CAPTION
, TC_FROMSTRING
, SA_RIGHT
);
149 y
+= FONT_HEIGHT_NORMAL
+ EXP_BLOCKSPACE
;
151 DrawString(r
.left
, r
.right
, y
, STR_FINANCES_SECTION_CONSTRUCTION
+ et
);
152 y
+= FONT_HEIGHT_NORMAL
;
156 DrawString(r
.left
, r
.right
, y
+ EXP_LINESPACE
, STR_FINANCES_TOTAL_CAPTION
, TC_FROMSTRING
, SA_RIGHT
);
160 * Draw an amount of money.
161 * @param amount Amount of money to draw,
162 * @param left Left coordinate of the space to draw in.
163 * @param right Right coordinate of the space to draw in.
164 * @param top Top coordinate of the space to draw in.
166 static void DrawPrice(Money amount
, int left
, int right
, int top
)
168 StringID str
= STR_FINANCES_NEGATIVE_INCOME
;
173 SetDParam(0, amount
);
174 DrawString(left
, right
, top
, str
, TC_FROMSTRING
, SA_RIGHT
);
178 * Draw a column with prices.
179 * @param r Available space for drawing.
180 * @param year Year being drawn.
181 * @param tbl Pointer to table of amounts for \a year.
182 * @note The environment must provide padding at the left and right of \a r.
184 static void DrawYearColumn(const Rect
&r
, int year
, const Money (*tbl
)[EXPENSES_END
])
189 DrawString(r
.left
, r
.right
, y
, STR_FINANCES_YEAR
, TC_FROMSTRING
, SA_RIGHT
, true);
190 y
+= FONT_HEIGHT_NORMAL
+ EXP_LINESPACE
;
194 int type
= _settings_client
.gui
.expenses_layout
;
195 for (uint i
= 0; i
< _expenses_list_types
[type
].length
; i
++) {
196 const ExpensesType et
= _expenses_list_types
[type
].et
[i
];
197 if (et
== INVALID_EXPENSES
) {
198 Money cost
= subtotal
;
200 GfxFillRect(r
.left
, y
, r
.right
, y
, PC_BLACK
);
202 DrawPrice(cost
, r
.left
, r
.right
, y
);
203 y
+= FONT_HEIGHT_NORMAL
+ EXP_BLOCKSPACE
;
205 Money cost
= (*tbl
)[et
];
208 if (cost
!= 0) DrawPrice(cost
, r
.left
, r
.right
, y
);
209 y
+= FONT_HEIGHT_NORMAL
;
213 GfxFillRect(r
.left
, y
, r
.right
, y
, PC_BLACK
);
215 DrawPrice(sum
, r
.left
, r
.right
, y
);
218 static const NWidgetPart _nested_company_finances_widgets
[] = {
219 NWidget(NWID_HORIZONTAL
),
220 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
221 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_CF_CAPTION
), SetDataTip(STR_FINANCES_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
222 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_CF_TOGGLE_SIZE
), SetDataTip(SPR_LARGE_SMALL_WINDOW
, STR_TOOLTIP_TOGGLE_LARGE_SMALL_WINDOW
),
223 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
224 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
226 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_CF_SEL_PANEL
),
227 NWidget(WWT_PANEL
, COLOUR_GREY
),
228 NWidget(NWID_HORIZONTAL
), SetPadding(WD_FRAMERECT_TOP
, WD_FRAMERECT_RIGHT
, WD_FRAMERECT_BOTTOM
, WD_FRAMERECT_LEFT
), SetPIP(0, 9, 0),
229 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_EXPS_CATEGORY
), SetMinimalSize(120, 0), SetFill(0, 0),
230 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_EXPS_PRICE1
), SetMinimalSize(86, 0), SetFill(0, 0),
231 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_EXPS_PRICE2
), SetMinimalSize(86, 0), SetFill(0, 0),
232 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_EXPS_PRICE3
), SetMinimalSize(86, 0), SetFill(0, 0),
236 NWidget(WWT_PANEL
, COLOUR_GREY
),
237 NWidget(NWID_HORIZONTAL
), SetPadding(WD_FRAMERECT_TOP
, WD_FRAMERECT_RIGHT
, WD_FRAMERECT_BOTTOM
, WD_FRAMERECT_LEFT
),
238 NWidget(NWID_VERTICAL
), // Vertical column with 'bank balance', 'loan'
239 NWidget(WWT_TEXT
, COLOUR_GREY
), SetDataTip(STR_FINANCES_BANK_BALANCE_TITLE
, STR_NULL
), SetFill(1, 0),
240 NWidget(WWT_TEXT
, COLOUR_GREY
), SetDataTip(STR_FINANCES_LOAN_TITLE
, STR_NULL
), SetFill(1, 0),
241 NWidget(NWID_SPACER
), SetFill(0, 1),
243 NWidget(NWID_SPACER
), SetFill(0, 0), SetMinimalSize(30, 0),
244 NWidget(NWID_VERTICAL
), // Vertical column with bank balance amount, loan amount, and total.
245 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CF_BALANCE_VALUE
), SetDataTip(STR_NULL
, STR_NULL
),
246 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CF_LOAN_VALUE
), SetDataTip(STR_NULL
, STR_NULL
),
247 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_LOAN_LINE
), SetMinimalSize(0, 2), SetFill(1, 0),
248 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CF_TOTAL_VALUE
), SetDataTip(STR_NULL
, STR_NULL
),
250 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_CF_SEL_MAXLOAN
),
251 NWidget(NWID_HORIZONTAL
),
252 NWidget(NWID_SPACER
), SetFill(0, 1), SetMinimalSize(25, 0),
253 NWidget(NWID_VERTICAL
), // Max loan information
254 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_MAXLOAN_GAP
), SetFill(0, 0),
255 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CF_MAXLOAN_VALUE
), SetDataTip(STR_FINANCES_MAX_LOAN
, STR_NULL
),
256 NWidget(NWID_SPACER
), SetFill(0, 1),
260 NWidget(NWID_SPACER
), SetFill(1, 1),
263 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_CF_SEL_BUTTONS
),
264 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
265 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_CF_INCREASE_LOAN
), SetFill(1, 0), SetDataTip(STR_FINANCES_BORROW_BUTTON
, STR_FINANCES_BORROW_TOOLTIP
),
266 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_CF_REPAY_LOAN
), SetFill(1, 0), SetDataTip(STR_FINANCES_REPAY_BUTTON
, STR_FINANCES_REPAY_TOOLTIP
),
267 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_CF_INFRASTRUCTURE
), SetFill(1, 0), SetDataTip(STR_FINANCES_INFRASTRUCTURE_BUTTON
, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP
),
272 /** Window class displaying the company finances. */
273 struct CompanyFinancesWindow
: Window
{
274 static Money max_money
; ///< The maximum amount of money a company has had this 'run'
275 bool small
; ///< Window is toggled to 'small'.
277 CompanyFinancesWindow(WindowDesc
*desc
, CompanyID company
) : Window(desc
)
280 this->CreateNestedTree();
281 this->SetupWidgets();
282 this->FinishInitNested(company
);
284 this->owner
= (Owner
)this->window_number
;
287 void SetStringParameters(int widget
) const override
291 SetDParam(0, (CompanyID
)this->window_number
);
292 SetDParam(1, (CompanyID
)this->window_number
);
295 case WID_CF_MAXLOAN_VALUE
:
296 SetDParam(0, _economy
.max_loan
);
299 case WID_CF_INCREASE_LOAN
:
300 case WID_CF_REPAY_LOAN
:
301 SetDParam(0, LOAN_INTERVAL
);
306 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
308 int type
= _settings_client
.gui
.expenses_layout
;
310 case WID_CF_EXPS_CATEGORY
:
311 size
->width
= _expenses_list_types
[type
].GetCategoriesWidth();
312 size
->height
= _expenses_list_types
[type
].GetHeight();
315 case WID_CF_EXPS_PRICE1
:
316 case WID_CF_EXPS_PRICE2
:
317 case WID_CF_EXPS_PRICE3
:
318 size
->height
= _expenses_list_types
[type
].GetHeight();
321 case WID_CF_BALANCE_VALUE
:
322 case WID_CF_LOAN_VALUE
:
323 case WID_CF_TOTAL_VALUE
:
324 SetDParamMaxValue(0, CompanyFinancesWindow::max_money
);
325 size
->width
= std::max(GetStringBoundingBox(STR_FINANCES_NEGATIVE_INCOME
).width
, GetStringBoundingBox(STR_FINANCES_POSITIVE_INCOME
).width
) + padding
.width
;
328 case WID_CF_MAXLOAN_GAP
:
329 size
->height
= FONT_HEIGHT_NORMAL
;
334 void DrawWidget(const Rect
&r
, int widget
) const override
337 case WID_CF_EXPS_CATEGORY
:
341 case WID_CF_EXPS_PRICE1
:
342 case WID_CF_EXPS_PRICE2
:
343 case WID_CF_EXPS_PRICE3
: {
344 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
345 int age
= std::min(_cur_year
- c
->inaugurated_year
, 2);
346 int wid_offset
= widget
- WID_CF_EXPS_PRICE1
;
347 if (wid_offset
<= age
) {
348 DrawYearColumn(r
, _cur_year
- (age
- wid_offset
), c
->yearly_expenses
+ (age
- wid_offset
));
353 case WID_CF_BALANCE_VALUE
: {
354 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
355 SetDParam(0, c
->money
);
356 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
360 case WID_CF_LOAN_VALUE
: {
361 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
362 SetDParam(0, c
->current_loan
);
363 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
367 case WID_CF_TOTAL_VALUE
: {
368 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
369 SetDParam(0, c
->money
- c
->current_loan
);
370 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
374 case WID_CF_LOAN_LINE
:
375 GfxFillRect(r
.left
, r
.top
, r
.right
, r
.top
, PC_BLACK
);
381 * Setup the widgets in the nested tree, such that the finances window is displayed properly.
382 * @note After setup, the window must be (re-)initialized.
386 int plane
= this->small
? SZSP_NONE
: 0;
387 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_PANEL
)->SetDisplayedPlane(plane
);
388 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_MAXLOAN
)->SetDisplayedPlane(plane
);
390 CompanyID company
= (CompanyID
)this->window_number
;
391 plane
= (company
!= _local_company
) ? SZSP_NONE
: 0;
392 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_BUTTONS
)->SetDisplayedPlane(plane
);
395 void OnPaint() override
397 if (!this->IsShaded()) {
399 /* Check that the expenses panel height matches the height needed for the layout. */
400 int type
= _settings_client
.gui
.expenses_layout
;
401 if (_expenses_list_types
[type
].GetHeight() != this->GetWidget
<NWidgetBase
>(WID_CF_EXPS_CATEGORY
)->current_y
) {
402 this->SetupWidgets();
408 /* Check that the loan buttons are shown only when the user owns the company. */
409 CompanyID company
= (CompanyID
)this->window_number
;
410 int req_plane
= (company
!= _local_company
) ? SZSP_NONE
: 0;
411 if (req_plane
!= this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_BUTTONS
)->shown_plane
) {
412 this->SetupWidgets();
417 const Company
*c
= Company::Get(company
);
418 this->SetWidgetDisabledState(WID_CF_INCREASE_LOAN
, c
->current_loan
== _economy
.max_loan
); // Borrow button only shows when there is any more money to loan.
419 this->SetWidgetDisabledState(WID_CF_REPAY_LOAN
, company
!= _local_company
|| c
->current_loan
== 0); // Repay button only shows when there is any more money to repay.
425 void OnClick(Point pt
, int widget
, int click_count
) override
428 case WID_CF_TOGGLE_SIZE
: // toggle size
429 this->small
= !this->small
;
430 this->SetupWidgets();
431 if (this->IsShaded()) {
432 /* Finances window is not resizable, so size hints given during unshading have no effect
433 * on the changed appearance of the window. */
434 this->SetShaded(false);
440 case WID_CF_INCREASE_LOAN
: // increase loan
441 DoCommandP(0, 0, _ctrl_pressed
, CMD_INCREASE_LOAN
| CMD_MSG(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY
));
444 case WID_CF_REPAY_LOAN
: // repay loan
445 DoCommandP(0, 0, _ctrl_pressed
, CMD_DECREASE_LOAN
| CMD_MSG(STR_ERROR_CAN_T_REPAY_LOAN
));
448 case WID_CF_INFRASTRUCTURE
: // show infrastructure details
449 ShowCompanyInfrastructure((CompanyID
)this->window_number
);
454 void OnHundredthTick() override
456 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
457 if (c
->money
> CompanyFinancesWindow::max_money
) {
458 CompanyFinancesWindow::max_money
= std::max(c
->money
* 2, CompanyFinancesWindow::max_money
* 4);
459 this->SetupWidgets();
465 /** First conservative estimate of the maximum amount of money */
466 Money
CompanyFinancesWindow::max_money
= INT32_MAX
;
468 static WindowDesc
_company_finances_desc(
469 WDP_AUTO
, "company_finances", 0, 0,
470 WC_FINANCES
, WC_NONE
,
472 _nested_company_finances_widgets
, lengthof(_nested_company_finances_widgets
)
476 * Open the finances window of a company.
477 * @param company Company to show finances of.
478 * @pre is company a valid company.
480 void ShowCompanyFinances(CompanyID company
)
482 if (!Company::IsValidID(company
)) return;
483 if (BringWindowToFrontById(WC_FINANCES
, company
)) return;
485 new CompanyFinancesWindow(&_company_finances_desc
, company
);
488 /* List of colours for the livery window */
489 static const StringID _colour_dropdown
[] = {
490 STR_COLOUR_DARK_BLUE
,
491 STR_COLOUR_PALE_GREEN
,
495 STR_COLOUR_LIGHT_BLUE
,
497 STR_COLOUR_DARK_GREEN
,
508 /* Association of liveries to livery classes */
509 static const LiveryClass _livery_class
[LS_END
] = {
511 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
,
514 LC_AIRCRAFT
, LC_AIRCRAFT
, LC_AIRCRAFT
,
518 class DropDownListColourItem
: public DropDownListItem
{
520 DropDownListColourItem(int result
, bool masked
) : DropDownListItem(result
, masked
) {}
522 StringID
String() const
524 return this->result
>= COLOUR_END
? STR_COLOUR_DEFAULT
: _colour_dropdown
[this->result
];
527 uint
Height(uint width
) const override
529 return std::max(FONT_HEIGHT_NORMAL
, ScaleGUITrad(12) + 2);
532 bool Selectable() const override
537 void Draw(int left
, int right
, int top
, int bottom
, bool sel
, Colours bg_colour
) const override
539 bool rtl
= _current_text_dir
== TD_RTL
;
540 int height
= bottom
- top
;
541 int icon_y_offset
= height
/ 2;
542 int text_y_offset
= (height
- FONT_HEIGHT_NORMAL
) / 2 + 1;
543 DrawSprite(SPR_VEH_BUS_SIDE_VIEW
, PALETTE_RECOLOUR_START
+ (this->result
% COLOUR_END
),
544 rtl
? right
- 2 - ScaleGUITrad(14) : left
+ ScaleGUITrad(14) + 2,
545 top
+ icon_y_offset
);
546 DrawString(rtl
? left
+ 2 : left
+ ScaleGUITrad(28) + 4,
547 rtl
? right
- ScaleGUITrad(28) - 4 : right
- 2,
548 top
+ text_y_offset
, this->String(), sel
? TC_WHITE
: TC_BLACK
);
552 static const int LEVEL_WIDTH
= 10; ///< Indenting width of a sub-group in pixels
554 typedef GUIList
<const Group
*> GUIGroupList
;
556 /** Company livery colour scheme window. */
557 struct SelectCompanyLiveryWindow
: public Window
{
560 LiveryClass livery_class
;
565 std::vector
<int> indents
;
568 void ShowColourDropDownMenu(uint32 widget
)
570 uint32 used_colours
= 0;
572 const Livery
*livery
, *default_livery
= nullptr;
573 bool primary
= widget
== WID_SCL_PRI_COL_DROPDOWN
;
576 /* Disallow other company colours for the primary colour */
577 if (this->livery_class
< LC_GROUP_RAIL
&& HasBit(this->sel
, LS_DEFAULT
) && primary
) {
578 for (const Company
*c
: Company::Iterate()) {
579 if (c
->index
!= _local_company
) SetBit(used_colours
, c
->colour
);
583 c
= Company::Get((CompanyID
)this->window_number
);
585 if (this->livery_class
< LC_GROUP_RAIL
) {
586 /* Get the first selected livery to use as the default dropdown item */
588 for (scheme
= LS_BEGIN
; scheme
< LS_END
; scheme
++) {
589 if (HasBit(this->sel
, scheme
)) break;
591 if (scheme
== LS_END
) scheme
= LS_DEFAULT
;
592 livery
= &c
->livery
[scheme
];
593 if (scheme
!= LS_DEFAULT
) default_livery
= &c
->livery
[LS_DEFAULT
];
595 const Group
*g
= Group::Get(this->sel
);
597 if (g
->parent
== INVALID_GROUP
) {
598 default_livery
= &c
->livery
[LS_DEFAULT
];
600 const Group
*pg
= Group::Get(g
->parent
);
601 default_livery
= &pg
->livery
;
606 if (default_livery
!= nullptr) {
607 /* Add COLOUR_END to put the colour out of range, but also allow us to show what the default is */
608 default_col
= (primary
? default_livery
->colour1
: default_livery
->colour2
) + COLOUR_END
;
609 list
.emplace_back(new DropDownListColourItem(default_col
, false));
611 for (uint i
= 0; i
< lengthof(_colour_dropdown
); i
++) {
612 list
.emplace_back(new DropDownListColourItem(i
, HasBit(used_colours
, i
)));
615 byte sel
= (default_livery
== nullptr || HasBit(livery
->in_use
, primary
? 0 : 1)) ? (primary
? livery
->colour1
: livery
->colour2
) : default_col
;
616 ShowDropDownList(this, std::move(list
), sel
, widget
);
619 void AddChildren(GUIGroupList
*source
, GroupID parent
, int indent
)
621 for (const Group
*g
: *source
) {
622 if (g
->parent
!= parent
) continue;
623 this->groups
.push_back(g
);
624 this->indents
.push_back(indent
);
625 AddChildren(source
, g
->index
, indent
+ 1);
629 void BuildGroupList(CompanyID owner
)
631 if (!this->groups
.NeedRebuild()) return;
633 this->groups
.clear();
634 this->indents
.clear();
636 if (this->livery_class
>= LC_GROUP_RAIL
) {
638 VehicleType vtype
= (VehicleType
)(this->livery_class
- LC_GROUP_RAIL
);
640 for (const Group
*g
: Group::Iterate()) {
641 if (g
->owner
== owner
&& g
->vehicle_type
== vtype
) {
648 /* Sort the groups by their name */
649 const Group
*last_group
[2] = { nullptr, nullptr };
650 char last_name
[2][64] = { "", "" };
651 list
.Sort([&](const Group
* const &a
, const Group
* const &b
) -> bool {
652 if (a
!= last_group
[0]) {
654 SetDParam(0, a
->index
);
655 GetString(last_name
[0], STR_GROUP_NAME
, lastof(last_name
[0]));
658 if (b
!= last_group
[1]) {
660 SetDParam(0, b
->index
);
661 GetString(last_name
[1], STR_GROUP_NAME
, lastof(last_name
[1]));
664 int r
= strnatcmp(last_name
[0], last_name
[1]); // Sort by name (natural sorting).
665 if (r
== 0) return a
->index
< b
->index
;
669 AddChildren(&list
, INVALID_GROUP
, 0);
672 this->groups
.shrink_to_fit();
673 this->groups
.RebuildDone();
678 if (this->livery_class
< LC_GROUP_RAIL
) {
680 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
681 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
686 this->rows
= (uint
)this->groups
.size();
689 this->vscroll
->SetCount(this->rows
);
693 SelectCompanyLiveryWindow(WindowDesc
*desc
, CompanyID company
, GroupID group
) : Window(desc
)
695 this->CreateNestedTree();
696 this->vscroll
= this->GetScrollbar(WID_SCL_MATRIX_SCROLLBAR
);
698 if (group
== INVALID_GROUP
) {
699 this->livery_class
= LC_OTHER
;
701 this->LowerWidget(WID_SCL_CLASS_GENERAL
);
702 this->BuildGroupList(company
);
705 this->SetSelectedGroup(company
, group
);
708 this->FinishInitNested(company
);
709 this->owner
= company
;
710 this->InvalidateData(1);
713 void SetSelectedGroup(CompanyID company
, GroupID group
)
715 this->RaiseWidget(this->livery_class
+ WID_SCL_CLASS_GENERAL
);
716 const Group
*g
= Group::Get(group
);
717 switch (g
->vehicle_type
) {
718 case VEH_TRAIN
: this->livery_class
= LC_GROUP_RAIL
; break;
719 case VEH_ROAD
: this->livery_class
= LC_GROUP_ROAD
; break;
720 case VEH_SHIP
: this->livery_class
= LC_GROUP_SHIP
; break;
721 case VEH_AIRCRAFT
: this->livery_class
= LC_GROUP_AIRCRAFT
; break;
722 default: NOT_REACHED();
725 this->LowerWidget(this->livery_class
+ WID_SCL_CLASS_GENERAL
);
727 this->groups
.ForceRebuild();
728 this->BuildGroupList(company
);
731 /* Position scrollbar to selected group */
732 for (uint i
= 0; i
< this->rows
; i
++) {
733 if (this->groups
[i
]->index
== sel
) {
734 this->vscroll
->SetPosition(Clamp(i
- this->vscroll
->GetCapacity() / 2, 0, std::max(this->vscroll
->GetCount() - this->vscroll
->GetCapacity(), 0)));
740 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
743 case WID_SCL_SPACER_DROPDOWN
: {
744 /* The matrix widget below needs enough room to print all the schemes. */
745 Dimension d
= {0, 0};
746 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
747 d
= maxdim(d
, GetStringBoundingBox(STR_LIVERY_DEFAULT
+ scheme
));
750 /* And group names */
751 for (const Group
*g
: Group::Iterate()) {
752 if (g
->owner
== (CompanyID
)this->window_number
) {
753 SetDParam(0, g
->index
);
754 d
= maxdim(d
, GetStringBoundingBox(STR_GROUP_NAME
));
758 size
->width
= std::max(size
->width
, 5 + d
.width
+ WD_FRAMERECT_RIGHT
);
762 case WID_SCL_MATRIX
: {
763 /* 11 items in the default rail class */
764 this->square
= GetSpriteSize(SPR_SQUARE
);
765 this->line_height
= std::max(this->square
.height
, (uint
)FONT_HEIGHT_NORMAL
) + 4;
767 size
->height
= 11 * this->line_height
;
769 resize
->height
= this->line_height
;
773 case WID_SCL_SEC_COL_DROPDOWN
:
774 if (!_loaded_newgrf_features
.has_2CC
) {
780 case WID_SCL_PRI_COL_DROPDOWN
: {
781 this->square
= GetSpriteSize(SPR_SQUARE
);
782 int padding
= this->square
.width
+ NWidgetScrollbar::GetVerticalDimension().width
+ 10;
783 for (const StringID
*id
= _colour_dropdown
; id
!= endof(_colour_dropdown
); id
++) {
784 size
->width
= std::max(size
->width
, GetStringBoundingBox(*id
).width
+ padding
);
786 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COLOUR_DEFAULT
).width
+ padding
);
792 void OnPaint() override
794 bool local
= (CompanyID
)this->window_number
== _local_company
;
796 /* Disable dropdown controls if no scheme is selected */
797 bool disabled
= this->livery_class
< LC_GROUP_RAIL
? (this->sel
== 0) : (this->sel
== INVALID_GROUP
);
798 this->SetWidgetDisabledState(WID_SCL_PRI_COL_DROPDOWN
, !local
|| disabled
);
799 this->SetWidgetDisabledState(WID_SCL_SEC_COL_DROPDOWN
, !local
|| disabled
);
801 this->BuildGroupList((CompanyID
)this->window_number
);
806 void SetStringParameters(int widget
) const override
809 case WID_SCL_CAPTION
:
810 SetDParam(0, (CompanyID
)this->window_number
);
813 case WID_SCL_PRI_COL_DROPDOWN
:
814 case WID_SCL_SEC_COL_DROPDOWN
: {
815 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
816 bool primary
= widget
== WID_SCL_PRI_COL_DROPDOWN
;
817 StringID colour
= STR_COLOUR_DEFAULT
;
819 if (this->livery_class
< LC_GROUP_RAIL
) {
820 if (this->sel
!= 0) {
821 LiveryScheme scheme
= LS_DEFAULT
;
822 for (scheme
= LS_BEGIN
; scheme
< LS_END
; scheme
++) {
823 if (HasBit(this->sel
, scheme
)) break;
825 if (scheme
== LS_END
) scheme
= LS_DEFAULT
;
826 const Livery
*livery
= &c
->livery
[scheme
];
827 if (scheme
== LS_DEFAULT
|| HasBit(livery
->in_use
, primary
? 0 : 1)) {
828 colour
= STR_COLOUR_DARK_BLUE
+ (primary
? livery
->colour1
: livery
->colour2
);
832 if (this->sel
!= INVALID_GROUP
) {
833 const Group
*g
= Group::Get(this->sel
);
834 const Livery
*livery
= &g
->livery
;
835 if (HasBit(livery
->in_use
, primary
? 0 : 1)) {
836 colour
= STR_COLOUR_DARK_BLUE
+ (primary
? livery
->colour1
: livery
->colour2
);
840 SetDParam(0, colour
);
846 void DrawWidget(const Rect
&r
, int widget
) const override
848 if (widget
!= WID_SCL_MATRIX
) return;
850 bool rtl
= _current_text_dir
== TD_RTL
;
852 /* Horizontal coordinates of scheme name column. */
853 const NWidgetBase
*nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_SPACER_DROPDOWN
);
854 int sch_left
= nwi
->pos_x
;
855 int sch_right
= sch_left
+ nwi
->current_x
- 1;
856 /* Horizontal coordinates of first dropdown. */
857 nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_PRI_COL_DROPDOWN
);
858 int pri_left
= nwi
->pos_x
;
859 int pri_right
= pri_left
+ nwi
->current_x
- 1;
860 /* Horizontal coordinates of second dropdown. */
861 nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_SEC_COL_DROPDOWN
);
862 int sec_left
= nwi
->pos_x
;
863 int sec_right
= sec_left
+ nwi
->current_x
- 1;
865 int text_left
= (rtl
? (uint
)WD_FRAMERECT_LEFT
: (this->square
.width
+ 5));
866 int text_right
= (rtl
? (this->square
.width
+ 5) : (uint
)WD_FRAMERECT_RIGHT
);
868 int square_offs
= (this->line_height
- this->square
.height
) / 2 + 1;
869 int text_offs
= (this->line_height
- FONT_HEIGHT_NORMAL
) / 2 + 1;
873 /* Helper function to draw livery info. */
874 auto draw_livery
= [&](StringID str
, const Livery
&liv
, bool sel
, bool def
, int indent
) {
876 DrawString(sch_left
+ WD_FRAMERECT_LEFT
+ (rtl
? 0 : indent
), sch_right
- WD_FRAMERECT_RIGHT
- (rtl
? indent
: 0), y
+ text_offs
, str
, sel
? TC_WHITE
: TC_BLACK
);
878 /* Text below the first dropdown. */
879 DrawSprite(SPR_SQUARE
, GENERAL_SPRITE_COLOUR(liv
.colour1
), (rtl
? pri_right
- (this->square
.width
+ 5) + WD_FRAMERECT_RIGHT
: pri_left
) + WD_FRAMERECT_LEFT
, y
+ square_offs
);
880 DrawString(pri_left
+ text_left
, pri_right
- text_right
, y
+ text_offs
, (def
|| HasBit(liv
.in_use
, 0)) ? STR_COLOUR_DARK_BLUE
+ liv
.colour1
: STR_COLOUR_DEFAULT
, sel
? TC_WHITE
: TC_GOLD
);
882 /* Text below the second dropdown. */
883 if (sec_right
> sec_left
) { // Second dropdown has non-zero size.
884 DrawSprite(SPR_SQUARE
, GENERAL_SPRITE_COLOUR(liv
.colour2
), (rtl
? sec_right
- (this->square
.width
+ 5) + WD_FRAMERECT_RIGHT
: sec_left
) + WD_FRAMERECT_LEFT
, y
+ square_offs
);
885 DrawString(sec_left
+ text_left
, sec_right
- text_right
, y
+ text_offs
, (def
|| HasBit(liv
.in_use
, 1)) ? STR_COLOUR_DARK_BLUE
+ liv
.colour2
: STR_COLOUR_DEFAULT
, sel
? TC_WHITE
: TC_GOLD
);
888 y
+= this->line_height
;
891 if (livery_class
< LC_GROUP_RAIL
) {
892 int pos
= this->vscroll
->GetPosition();
893 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
894 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
895 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
896 if (pos
-- > 0) continue;
897 draw_livery(STR_LIVERY_DEFAULT
+ scheme
, c
->livery
[scheme
], HasBit(this->sel
, scheme
), scheme
== LS_DEFAULT
, 0);
901 uint max
= static_cast<uint
>(std::min
<size_t>(this->vscroll
->GetPosition() + this->vscroll
->GetCapacity(), this->groups
.size()));
902 for (uint i
= this->vscroll
->GetPosition(); i
< max
; ++i
) {
903 const Group
*g
= this->groups
[i
];
904 SetDParam(0, g
->index
);
905 draw_livery(STR_GROUP_NAME
, g
->livery
, this->sel
== g
->index
, false, this->indents
[i
] * LEVEL_WIDTH
);
910 void OnClick(Point pt
, int widget
, int click_count
) override
913 /* Livery Class buttons */
914 case WID_SCL_CLASS_GENERAL
:
915 case WID_SCL_CLASS_RAIL
:
916 case WID_SCL_CLASS_ROAD
:
917 case WID_SCL_CLASS_SHIP
:
918 case WID_SCL_CLASS_AIRCRAFT
:
919 case WID_SCL_GROUPS_RAIL
:
920 case WID_SCL_GROUPS_ROAD
:
921 case WID_SCL_GROUPS_SHIP
:
922 case WID_SCL_GROUPS_AIRCRAFT
:
923 this->RaiseWidget(this->livery_class
+ WID_SCL_CLASS_GENERAL
);
924 this->livery_class
= (LiveryClass
)(widget
- WID_SCL_CLASS_GENERAL
);
925 this->LowerWidget(this->livery_class
+ WID_SCL_CLASS_GENERAL
);
927 /* Select the first item in the list */
928 if (this->livery_class
< LC_GROUP_RAIL
) {
930 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
931 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
932 this->sel
= 1 << scheme
;
937 this->sel
= INVALID_GROUP
;
938 this->groups
.ForceRebuild();
939 this->BuildGroupList((CompanyID
)this->window_number
);
941 if (this->groups
.size() > 0) {
942 this->sel
= this->groups
[0]->index
;
950 case WID_SCL_PRI_COL_DROPDOWN
: // First colour dropdown
951 ShowColourDropDownMenu(WID_SCL_PRI_COL_DROPDOWN
);
954 case WID_SCL_SEC_COL_DROPDOWN
: // Second colour dropdown
955 ShowColourDropDownMenu(WID_SCL_SEC_COL_DROPDOWN
);
958 case WID_SCL_MATRIX
: {
959 uint row
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_SCL_MATRIX
, 0, this->line_height
);
960 if (row
>= this->rows
) return;
962 if (this->livery_class
< LC_GROUP_RAIL
) {
963 LiveryScheme j
= (LiveryScheme
)row
;
965 for (LiveryScheme scheme
= LS_BEGIN
; scheme
<= j
&& scheme
< LS_END
; scheme
++) {
966 if (_livery_class
[scheme
] != this->livery_class
|| !HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) j
++;
971 ToggleBit(this->sel
, j
);
976 this->sel
= this->groups
[row
]->index
;
984 void OnResize() override
986 this->vscroll
->SetCapacityFromWidget(this, WID_SCL_MATRIX
);
989 void OnDropdownSelect(int widget
, int index
) override
991 bool local
= (CompanyID
)this->window_number
== _local_company
;
994 if (index
>= COLOUR_END
) index
= INVALID_COLOUR
;
996 if (this->livery_class
< LC_GROUP_RAIL
) {
997 /* Set company colour livery */
998 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
999 /* Changed colour for the selected scheme, or all visible schemes if CTRL is pressed. */
1000 if (HasBit(this->sel
, scheme
) || (_ctrl_pressed
&& _livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
))) {
1001 DoCommandP(0, scheme
| (widget
== WID_SCL_PRI_COL_DROPDOWN
? 0 : 256), index
, CMD_SET_COMPANY_COLOUR
);
1005 /* Setting group livery */
1006 DoCommandP(0, this->sel
, (widget
== WID_SCL_PRI_COL_DROPDOWN
? 0 : 256) | (index
<< 16), CMD_SET_GROUP_LIVERY
);
1011 * Some data on this window has become invalid.
1012 * @param data Information about the changed data.
1013 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
1015 void OnInvalidateData(int data
= 0, bool gui_scope
= true) override
1017 if (!gui_scope
) return;
1020 /* data contains a VehicleType, rebuild list if it displayed */
1021 if (this->livery_class
== data
+ LC_GROUP_RAIL
) {
1022 this->groups
.ForceRebuild();
1023 this->BuildGroupList((CompanyID
)this->window_number
);
1026 if (!Group::IsValidID(this->sel
)) {
1027 this->sel
= INVALID_GROUP
;
1028 if (this->groups
.size() > 0) this->sel
= this->groups
[0]->index
;
1036 this->SetWidgetsDisabledState(true, WID_SCL_CLASS_RAIL
, WID_SCL_CLASS_ROAD
, WID_SCL_CLASS_SHIP
, WID_SCL_CLASS_AIRCRAFT
, WIDGET_LIST_END
);
1038 bool current_class_valid
= this->livery_class
== LC_OTHER
|| this->livery_class
>= LC_GROUP_RAIL
;
1039 if (_settings_client
.gui
.liveries
== LIT_ALL
|| (_settings_client
.gui
.liveries
== LIT_COMPANY
&& this->window_number
== _local_company
)) {
1040 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
1041 if (HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
1042 if (_livery_class
[scheme
] == this->livery_class
) current_class_valid
= true;
1043 this->EnableWidget(WID_SCL_CLASS_GENERAL
+ _livery_class
[scheme
]);
1044 } else if (this->livery_class
< LC_GROUP_RAIL
) {
1045 ClrBit(this->sel
, scheme
);
1050 if (!current_class_valid
) {
1052 this->OnClick(pt
, WID_SCL_CLASS_GENERAL
, 1);
1057 static const NWidgetPart _nested_select_company_livery_widgets
[] = {
1058 NWidget(NWID_HORIZONTAL
),
1059 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1060 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_SCL_CAPTION
), SetDataTip(STR_LIVERY_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1062 NWidget(NWID_HORIZONTAL
),
1063 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_GENERAL
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_COMPANY_GENERAL
, STR_LIVERY_GENERAL_TOOLTIP
),
1064 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_RAIL
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST
, STR_LIVERY_TRAIN_TOOLTIP
),
1065 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_ROAD
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRUCKLIST
, STR_LIVERY_ROAD_VEHICLE_TOOLTIP
),
1066 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_SHIP
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIPLIST
, STR_LIVERY_SHIP_TOOLTIP
),
1067 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_AIRCRAFT
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AIRPLANESLIST
, STR_LIVERY_AIRCRAFT_TOOLTIP
),
1068 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_GROUPS_RAIL
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_GROUP_LIVERY_TRAIN
, STR_LIVERY_TRAIN_TOOLTIP
),
1069 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_GROUPS_ROAD
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_GROUP_LIVERY_ROADVEH
, STR_LIVERY_ROAD_VEHICLE_TOOLTIP
),
1070 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_GROUPS_SHIP
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_GROUP_LIVERY_SHIP
, STR_LIVERY_SHIP_TOOLTIP
),
1071 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_GROUPS_AIRCRAFT
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_GROUP_LIVERY_AIRCRAFT
, STR_LIVERY_AIRCRAFT_TOOLTIP
),
1072 NWidget(WWT_PANEL
, COLOUR_GREY
), SetMinimalSize(90, 22), SetFill(1, 1), EndContainer(),
1074 NWidget(NWID_HORIZONTAL
),
1075 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_SCL_SPACER_DROPDOWN
), SetMinimalSize(150, 12), SetFill(1, 1), EndContainer(),
1076 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_SCL_PRI_COL_DROPDOWN
), SetMinimalSize(125, 12), SetFill(0, 1), SetDataTip(STR_BLACK_STRING
, STR_LIVERY_PRIMARY_TOOLTIP
),
1077 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_SCL_SEC_COL_DROPDOWN
), SetMinimalSize(125, 12), SetFill(0, 1),
1078 SetDataTip(STR_BLACK_STRING
, STR_LIVERY_SECONDARY_TOOLTIP
),
1080 NWidget(NWID_HORIZONTAL
),
1081 NWidget(WWT_MATRIX
, COLOUR_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
),
1082 NWidget(NWID_VERTICAL
),
1083 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_SCL_MATRIX_SCROLLBAR
),
1084 NWidget(WWT_RESIZEBOX
, COLOUR_GREY
),
1089 static WindowDesc
_select_company_livery_desc(
1090 WDP_AUTO
, "company_livery", 0, 0,
1091 WC_COMPANY_COLOUR
, WC_NONE
,
1093 _nested_select_company_livery_widgets
, lengthof(_nested_select_company_livery_widgets
)
1096 void ShowCompanyLiveryWindow(CompanyID company
, GroupID group
)
1098 SelectCompanyLiveryWindow
*w
= (SelectCompanyLiveryWindow
*)BringWindowToFrontById(WC_COMPANY_COLOUR
, company
);
1100 new SelectCompanyLiveryWindow(&_select_company_livery_desc
, company
, group
);
1101 } else if (group
!= INVALID_GROUP
) {
1102 w
->SetSelectedGroup(company
, group
);
1107 * Draws the face of a company manager's face.
1108 * @param cmf the company manager's face
1109 * @param colour the (background) colour of the gradient
1110 * @param x x-position to draw the face
1111 * @param y y-position to draw the face
1113 void DrawCompanyManagerFace(CompanyManagerFace cmf
, int colour
, int x
, int y
)
1115 GenderEthnicity ge
= (GenderEthnicity
)GetCompanyManagerFaceBits(cmf
, CMFV_GEN_ETHN
, GE_WM
);
1117 bool has_moustache
= !HasBit(ge
, GENDER_FEMALE
) && GetCompanyManagerFaceBits(cmf
, CMFV_HAS_MOUSTACHE
, ge
) != 0;
1118 bool has_tie_earring
= !HasBit(ge
, GENDER_FEMALE
) || GetCompanyManagerFaceBits(cmf
, CMFV_HAS_TIE_EARRING
, ge
) != 0;
1119 bool has_glasses
= GetCompanyManagerFaceBits(cmf
, CMFV_HAS_GLASSES
, ge
) != 0;
1122 /* Modify eye colour palette only if 2 or more valid values exist */
1123 if (_cmf_info
[CMFV_EYE_COLOUR
].valid_values
[ge
] < 2) {
1126 switch (GetCompanyManagerFaceBits(cmf
, CMFV_EYE_COLOUR
, ge
)) {
1127 default: NOT_REACHED();
1128 case 0: pal
= PALETTE_TO_BROWN
; break;
1129 case 1: pal
= PALETTE_TO_BLUE
; break;
1130 case 2: pal
= PALETTE_TO_GREEN
; break;
1134 /* Draw the gradient (background) */
1135 DrawSprite(SPR_GRADIENT
, GENERAL_SPRITE_COLOUR(colour
), x
, y
);
1137 for (CompanyManagerFaceVariable cmfv
= CMFV_CHEEKS
; cmfv
< CMFV_END
; cmfv
++) {
1139 case CMFV_MOUSTACHE
: if (!has_moustache
) continue; break;
1141 case CMFV_NOSE
: if (has_moustache
) continue; break;
1142 case CMFV_TIE_EARRING
: if (!has_tie_earring
) continue; break;
1143 case CMFV_GLASSES
: if (!has_glasses
) continue; break;
1146 DrawSprite(GetCompanyManagerFaceSprite(cmf
, cmfv
, ge
), (cmfv
== CMFV_EYEBROWS
) ? pal
: PAL_NONE
, x
, y
);
1150 /** Nested widget description for the company manager face selection dialog */
1151 static const NWidgetPart _nested_select_company_manager_face_widgets
[] = {
1152 NWidget(NWID_HORIZONTAL
),
1153 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1154 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_SCMF_CAPTION
), SetDataTip(STR_FACE_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1155 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCMF_TOGGLE_LARGE_SMALL
), SetDataTip(SPR_LARGE_SMALL_WINDOW
, STR_FACE_ADVANCED_TOOLTIP
),
1157 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_SCMF_SELECT_FACE
),
1158 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1159 NWidget(NWID_HORIZONTAL
), SetPIP(2, 2, 2),
1160 NWidget(NWID_VERTICAL
),
1161 NWidget(NWID_HORIZONTAL
),
1162 NWidget(NWID_SPACER
), SetFill(1, 0),
1163 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_SCMF_FACE
), SetMinimalSize(92, 119),
1164 NWidget(NWID_SPACER
), SetFill(1, 0),
1166 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1167 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_RANDOM_NEW_FACE
), SetFill(1, 0), SetDataTip(STR_FACE_NEW_FACE_BUTTON
, STR_FACE_NEW_FACE_TOOLTIP
),
1168 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_LOADSAVE
), // Load/number/save buttons under the portrait in the advanced view.
1169 NWidget(NWID_VERTICAL
),
1170 NWidget(NWID_SPACER
), SetMinimalSize(0, 5), SetFill(0, 1),
1171 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_LOAD
), SetFill(1, 0), SetDataTip(STR_FACE_LOAD
, STR_FACE_LOAD_TOOLTIP
),
1172 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_FACECODE
), SetFill(1, 0), SetDataTip(STR_FACE_FACECODE
, STR_FACE_FACECODE_TOOLTIP
),
1173 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_SAVE
), SetFill(1, 0), SetDataTip(STR_FACE_SAVE
, STR_FACE_SAVE_TOOLTIP
),
1174 NWidget(NWID_SPACER
), SetMinimalSize(0, 5), SetFill(0, 1),
1178 NWidget(NWID_VERTICAL
),
1179 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
), SetFill(1, 0), SetDataTip(STR_FACE_ADVANCED
, STR_FACE_ADVANCED_TOOLTIP
),
1180 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1181 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_MALEFEMALE
), // Simple male/female face setting.
1182 NWidget(NWID_VERTICAL
),
1183 NWidget(NWID_SPACER
), SetFill(0, 1),
1184 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_MALE
), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON
, STR_FACE_MALE_TOOLTIP
),
1185 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_FEMALE
), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON
, STR_FACE_FEMALE_TOOLTIP
),
1186 NWidget(NWID_SPACER
), SetFill(0, 1),
1189 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_PARTS
), // Advanced face parts setting.
1190 NWidget(NWID_VERTICAL
),
1191 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1192 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1193 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_MALE2
), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON
, STR_FACE_MALE_TOOLTIP
),
1194 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_FEMALE2
), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON
, STR_FACE_FEMALE_TOOLTIP
),
1196 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1197 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1198 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_ETHNICITY_EUR
), SetFill(1, 0), SetDataTip(STR_FACE_EUROPEAN
, STR_FACE_SELECT_EUROPEAN
),
1199 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_ETHNICITY_AFR
), SetFill(1, 0), SetDataTip(STR_FACE_AFRICAN
, STR_FACE_SELECT_AFRICAN
),
1201 NWidget(NWID_SPACER
), SetMinimalSize(0, 4),
1202 NWidget(NWID_HORIZONTAL
),
1203 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
), SetFill(1, 0),
1204 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAS_MOUSTACHE_EARRING
), SetDataTip(STR_EMPTY
, STR_FACE_MOUSTACHE_EARRING_TOOLTIP
),
1206 NWidget(NWID_HORIZONTAL
),
1207 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAS_GLASSES_TEXT
), SetFill(1, 0),
1208 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAS_GLASSES
), SetDataTip(STR_EMPTY
, STR_FACE_GLASSES_TOOLTIP
),
1210 NWidget(NWID_SPACER
), SetMinimalSize(0, 2), SetFill(1, 0),
1211 NWidget(NWID_HORIZONTAL
),
1212 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAIR_TEXT
), SetFill(1, 0),
1213 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_HAIR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_HAIR_TOOLTIP
),
1214 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAIR
), SetDataTip(STR_EMPTY
, STR_FACE_HAIR_TOOLTIP
),
1215 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_HAIR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_HAIR_TOOLTIP
),
1217 NWidget(NWID_HORIZONTAL
),
1218 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_EYEBROWS_TEXT
), SetFill(1, 0),
1219 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS_L
), SetDataTip(AWV_DECREASE
, STR_FACE_EYEBROWS_TOOLTIP
),
1220 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS
), SetDataTip(STR_EMPTY
, STR_FACE_EYEBROWS_TOOLTIP
),
1221 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS_R
), SetDataTip(AWV_INCREASE
, STR_FACE_EYEBROWS_TOOLTIP
),
1223 NWidget(NWID_HORIZONTAL
),
1224 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_EYECOLOUR_TEXT
), SetFill(1, 0),
1225 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_EYECOLOUR_TOOLTIP
),
1226 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR
), SetDataTip(STR_EMPTY
, STR_FACE_EYECOLOUR_TOOLTIP
),
1227 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_EYECOLOUR_TOOLTIP
),
1229 NWidget(NWID_HORIZONTAL
),
1230 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_GLASSES_TEXT
), SetFill(1, 0),
1231 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_GLASSES_L
), SetDataTip(AWV_DECREASE
, STR_FACE_GLASSES_TOOLTIP_2
),
1232 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_GLASSES
), SetDataTip(STR_EMPTY
, STR_FACE_GLASSES_TOOLTIP_2
),
1233 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_GLASSES_R
), SetDataTip(AWV_INCREASE
, STR_FACE_GLASSES_TOOLTIP_2
),
1235 NWidget(NWID_HORIZONTAL
),
1236 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_NOSE_TEXT
), SetFill(1, 0),
1237 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_NOSE_L
), SetDataTip(AWV_DECREASE
, STR_FACE_NOSE_TOOLTIP
),
1238 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_NOSE
), SetDataTip(STR_EMPTY
, STR_FACE_NOSE_TOOLTIP
),
1239 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_NOSE_R
), SetDataTip(AWV_INCREASE
, STR_FACE_NOSE_TOOLTIP
),
1241 NWidget(NWID_HORIZONTAL
),
1242 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_LIPS_MOUSTACHE_TEXT
), SetFill(1, 0),
1243 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE_L
), SetDataTip(AWV_DECREASE
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1244 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE
), SetDataTip(STR_EMPTY
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1245 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE_R
), SetDataTip(AWV_INCREASE
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1247 NWidget(NWID_HORIZONTAL
),
1248 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_CHIN_TEXT
), SetFill(1, 0),
1249 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_CHIN_L
), SetDataTip(AWV_DECREASE
, STR_FACE_CHIN_TOOLTIP
),
1250 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_CHIN
), SetDataTip(STR_EMPTY
, STR_FACE_CHIN_TOOLTIP
),
1251 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_CHIN_R
), SetDataTip(AWV_INCREASE
, STR_FACE_CHIN_TOOLTIP
),
1253 NWidget(NWID_HORIZONTAL
),
1254 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_JACKET_TEXT
), SetFill(1, 0),
1255 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_JACKET_L
), SetDataTip(AWV_DECREASE
, STR_FACE_JACKET_TOOLTIP
),
1256 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_JACKET
), SetDataTip(STR_EMPTY
, STR_FACE_JACKET_TOOLTIP
),
1257 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_JACKET_R
), SetDataTip(AWV_INCREASE
, STR_FACE_JACKET_TOOLTIP
),
1259 NWidget(NWID_HORIZONTAL
),
1260 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_COLLAR_TEXT
), SetFill(1, 0),
1261 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_COLLAR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_COLLAR_TOOLTIP
),
1262 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_COLLAR
), SetDataTip(STR_EMPTY
, STR_FACE_COLLAR_TOOLTIP
),
1263 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_COLLAR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_COLLAR_TOOLTIP
),
1265 NWidget(NWID_HORIZONTAL
),
1266 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_TIE_EARRING_TEXT
), SetFill(1, 0),
1267 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING_L
), SetDataTip(AWV_DECREASE
, STR_FACE_TIE_EARRING_TOOLTIP
),
1268 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING
), SetDataTip(STR_EMPTY
, STR_FACE_TIE_EARRING_TOOLTIP
),
1269 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING_R
), SetDataTip(AWV_INCREASE
, STR_FACE_TIE_EARRING_TOOLTIP
),
1271 NWidget(NWID_SPACER
), SetFill(0, 1),
1276 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1278 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1279 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_CANCEL
), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL
, STR_FACE_CANCEL_TOOLTIP
),
1280 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_ACCEPT
), SetFill(1, 0), SetDataTip(STR_BUTTON_OK
, STR_FACE_OK_TOOLTIP
),
1284 /** Management class for customizing the face of the company manager. */
1285 class SelectCompanyManagerFaceWindow
: public Window
1287 CompanyManagerFace face
; ///< company manager face bits
1288 bool advanced
; ///< advanced company manager face selection window
1290 GenderEthnicity ge
; ///< Gender and ethnicity.
1291 bool is_female
; ///< Female face.
1292 bool is_moust_male
; ///< Male face with a moustache.
1294 Dimension yesno_dim
; ///< Dimension of a yes/no button of a part in the advanced face window.
1295 Dimension number_dim
; ///< Dimension of a number widget of a part in the advanced face window.
1297 static const StringID PART_TEXTS_IS_FEMALE
[]; ///< Strings depending on #is_female, used to describe parts (2 entries for a part).
1298 static const StringID PART_TEXTS
[]; ///< Fixed strings to describe parts of the face.
1301 * Draw dynamic a label to the left of the button and a value in the button
1303 * @param widget_index index of this widget in the window
1304 * @param val the value which will be draw
1305 * @param is_bool_widget is it a bool button
1307 void DrawFaceStringLabel(byte widget_index
, uint8 val
, bool is_bool_widget
) const
1310 const NWidgetCore
*nwi_widget
= this->GetWidget
<NWidgetCore
>(widget_index
);
1311 if (!nwi_widget
->IsDisabled()) {
1312 if (is_bool_widget
) {
1313 /* if it a bool button write yes or no */
1314 str
= (val
!= 0) ? STR_FACE_YES
: STR_FACE_NO
;
1316 /* else write the value + 1 */
1317 SetDParam(0, val
+ 1);
1321 /* Draw the value/bool in white (0xC). If the button clicked adds 1px to x and y text coordinates (IsWindowWidgetLowered()). */
1322 DrawString(nwi_widget
->pos_x
+ nwi_widget
->IsLowered(), nwi_widget
->pos_x
+ nwi_widget
->current_x
- 1 - nwi_widget
->IsLowered(),
1323 nwi_widget
->pos_y
+ 1 + nwi_widget
->IsLowered(), str
, TC_WHITE
, SA_HOR_CENTER
);
1329 this->ge
= (GenderEthnicity
)GB(this->face
, _cmf_info
[CMFV_GEN_ETHN
].offset
, _cmf_info
[CMFV_GEN_ETHN
].length
); // get the gender and ethnicity
1330 this->is_female
= HasBit(this->ge
, GENDER_FEMALE
); // get the gender: 0 == male and 1 == female
1331 this->is_moust_male
= !is_female
&& GetCompanyManagerFaceBits(this->face
, CMFV_HAS_MOUSTACHE
, this->ge
) != 0; // is a male face with moustache
1335 SelectCompanyManagerFaceWindow(WindowDesc
*desc
, Window
*parent
) : Window(desc
)
1337 this->advanced
= false;
1338 this->CreateNestedTree();
1339 this->SelectDisplayPlanes(this->advanced
);
1340 this->FinishInitNested(parent
->window_number
);
1341 this->parent
= parent
;
1342 this->owner
= (Owner
)this->window_number
;
1343 this->face
= Company::Get((CompanyID
)this->window_number
)->face
;
1349 * Select planes to display to the user with the #NWID_SELECTION widgets #WID_SCMF_SEL_LOADSAVE, #WID_SCMF_SEL_MALEFEMALE, and #WID_SCMF_SEL_PARTS.
1350 * @param advanced Display advanced face management window.
1352 void SelectDisplayPlanes(bool advanced
)
1354 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_LOADSAVE
)->SetDisplayedPlane(advanced
? 0 : SZSP_NONE
);
1355 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_PARTS
)->SetDisplayedPlane(advanced
? 0 : SZSP_NONE
);
1356 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_MALEFEMALE
)->SetDisplayedPlane(advanced
? SZSP_NONE
: 0);
1357 this->GetWidget
<NWidgetCore
>(WID_SCMF_RANDOM_NEW_FACE
)->widget_data
= advanced
? STR_FACE_RANDOM
: STR_FACE_NEW_FACE_BUTTON
;
1359 NWidgetCore
*wi
= this->GetWidget
<NWidgetCore
>(WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
);
1361 wi
->SetDataTip(STR_FACE_SIMPLE
, STR_FACE_SIMPLE_TOOLTIP
);
1363 wi
->SetDataTip(STR_FACE_ADVANCED
, STR_FACE_ADVANCED_TOOLTIP
);
1367 void OnInit() override
1369 /* Size of the boolean yes/no button. */
1370 Dimension yesno_dim
= maxdim(GetStringBoundingBox(STR_FACE_YES
), GetStringBoundingBox(STR_FACE_NO
));
1371 yesno_dim
.width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1372 yesno_dim
.height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1373 /* Size of the number button + arrows. */
1374 Dimension number_dim
= {0, 0};
1375 for (int val
= 1; val
<= 12; val
++) {
1377 number_dim
= maxdim(number_dim
, GetStringBoundingBox(STR_JUST_INT
));
1379 uint arrows_width
= GetSpriteSize(SPR_ARROW_LEFT
).width
+ GetSpriteSize(SPR_ARROW_RIGHT
).width
+ 2 * (WD_IMGBTN_LEFT
+ WD_IMGBTN_RIGHT
);
1380 number_dim
.width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
+ arrows_width
;
1381 number_dim
.height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1382 /* Compute width of both buttons. */
1383 yesno_dim
.width
= std::max(yesno_dim
.width
, number_dim
.width
);
1384 number_dim
.width
= yesno_dim
.width
- arrows_width
;
1386 this->yesno_dim
= yesno_dim
;
1387 this->number_dim
= number_dim
;
1390 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1393 case WID_SCMF_FACE
: {
1394 Dimension face_size
= GetSpriteSize(SPR_GRADIENT
);
1395 size
->width
= std::max(size
->width
, face_size
.width
);
1396 size
->height
= std::max(size
->height
, face_size
.height
);
1400 case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
:
1401 case WID_SCMF_TIE_EARRING_TEXT
: {
1402 int offset
= (widget
- WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
) * 2;
1403 *size
= maxdim(GetStringBoundingBox(PART_TEXTS_IS_FEMALE
[offset
]), GetStringBoundingBox(PART_TEXTS_IS_FEMALE
[offset
+ 1]));
1404 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1405 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1409 case WID_SCMF_LIPS_MOUSTACHE_TEXT
:
1410 *size
= maxdim(GetStringBoundingBox(STR_FACE_LIPS
), GetStringBoundingBox(STR_FACE_MOUSTACHE
));
1411 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1412 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1415 case WID_SCMF_HAS_GLASSES_TEXT
:
1416 case WID_SCMF_HAIR_TEXT
:
1417 case WID_SCMF_EYEBROWS_TEXT
:
1418 case WID_SCMF_EYECOLOUR_TEXT
:
1419 case WID_SCMF_GLASSES_TEXT
:
1420 case WID_SCMF_NOSE_TEXT
:
1421 case WID_SCMF_CHIN_TEXT
:
1422 case WID_SCMF_JACKET_TEXT
:
1423 case WID_SCMF_COLLAR_TEXT
:
1424 *size
= GetStringBoundingBox(PART_TEXTS
[widget
- WID_SCMF_HAS_GLASSES_TEXT
]);
1425 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1426 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1429 case WID_SCMF_HAS_MOUSTACHE_EARRING
:
1430 case WID_SCMF_HAS_GLASSES
:
1431 *size
= this->yesno_dim
;
1434 case WID_SCMF_EYECOLOUR
:
1436 case WID_SCMF_EYEBROWS
:
1437 case WID_SCMF_LIPS_MOUSTACHE
:
1440 case WID_SCMF_JACKET
:
1441 case WID_SCMF_COLLAR
:
1442 case WID_SCMF_TIE_EARRING
:
1443 case WID_SCMF_GLASSES
:
1444 *size
= this->number_dim
;
1449 void OnPaint() override
1451 /* lower the non-selected gender button */
1452 this->SetWidgetsLoweredState(!this->is_female
, WID_SCMF_MALE
, WID_SCMF_MALE2
, WIDGET_LIST_END
);
1453 this->SetWidgetsLoweredState( this->is_female
, WID_SCMF_FEMALE
, WID_SCMF_FEMALE2
, WIDGET_LIST_END
);
1455 /* advanced company manager face selection window */
1457 /* lower the non-selected ethnicity button */
1458 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_EUR
, !HasBit(this->ge
, ETHNICITY_BLACK
));
1459 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_AFR
, HasBit(this->ge
, ETHNICITY_BLACK
));
1462 /* Disable dynamically the widgets which CompanyManagerFaceVariable has less than 2 options
1463 * (or in other words you haven't any choice).
1464 * If the widgets depend on a HAS-variable and this is false the widgets will be disabled, too. */
1466 /* Eye colour buttons */
1467 this->SetWidgetsDisabledState(_cmf_info
[CMFV_EYE_COLOUR
].valid_values
[this->ge
] < 2,
1468 WID_SCMF_EYECOLOUR
, WID_SCMF_EYECOLOUR_L
, WID_SCMF_EYECOLOUR_R
, WIDGET_LIST_END
);
1471 this->SetWidgetsDisabledState(_cmf_info
[CMFV_CHIN
].valid_values
[this->ge
] < 2,
1472 WID_SCMF_CHIN
, WID_SCMF_CHIN_L
, WID_SCMF_CHIN_R
, WIDGET_LIST_END
);
1474 /* Eyebrows buttons */
1475 this->SetWidgetsDisabledState(_cmf_info
[CMFV_EYEBROWS
].valid_values
[this->ge
] < 2,
1476 WID_SCMF_EYEBROWS
, WID_SCMF_EYEBROWS_L
, WID_SCMF_EYEBROWS_R
, WIDGET_LIST_END
);
1478 /* Lips or (if it a male face with a moustache) moustache buttons */
1479 this->SetWidgetsDisabledState(_cmf_info
[this->is_moust_male
? CMFV_MOUSTACHE
: CMFV_LIPS
].valid_values
[this->ge
] < 2,
1480 WID_SCMF_LIPS_MOUSTACHE
, WID_SCMF_LIPS_MOUSTACHE_L
, WID_SCMF_LIPS_MOUSTACHE_R
, WIDGET_LIST_END
);
1482 /* Nose buttons | male faces with moustache haven't any nose options */
1483 this->SetWidgetsDisabledState(_cmf_info
[CMFV_NOSE
].valid_values
[this->ge
] < 2 || this->is_moust_male
,
1484 WID_SCMF_NOSE
, WID_SCMF_NOSE_L
, WID_SCMF_NOSE_R
, WIDGET_LIST_END
);
1487 this->SetWidgetsDisabledState(_cmf_info
[CMFV_HAIR
].valid_values
[this->ge
] < 2,
1488 WID_SCMF_HAIR
, WID_SCMF_HAIR_L
, WID_SCMF_HAIR_R
, WIDGET_LIST_END
);
1490 /* Jacket buttons */
1491 this->SetWidgetsDisabledState(_cmf_info
[CMFV_JACKET
].valid_values
[this->ge
] < 2,
1492 WID_SCMF_JACKET
, WID_SCMF_JACKET_L
, WID_SCMF_JACKET_R
, WIDGET_LIST_END
);
1494 /* Collar buttons */
1495 this->SetWidgetsDisabledState(_cmf_info
[CMFV_COLLAR
].valid_values
[this->ge
] < 2,
1496 WID_SCMF_COLLAR
, WID_SCMF_COLLAR_L
, WID_SCMF_COLLAR_R
, WIDGET_LIST_END
);
1498 /* Tie/earring buttons | female faces without earring haven't any earring options */
1499 this->SetWidgetsDisabledState(_cmf_info
[CMFV_TIE_EARRING
].valid_values
[this->ge
] < 2 ||
1500 (this->is_female
&& GetCompanyManagerFaceBits(this->face
, CMFV_HAS_TIE_EARRING
, this->ge
) == 0),
1501 WID_SCMF_TIE_EARRING
, WID_SCMF_TIE_EARRING_L
, WID_SCMF_TIE_EARRING_R
, WIDGET_LIST_END
);
1503 /* Glasses buttons | faces without glasses haven't any glasses options */
1504 this->SetWidgetsDisabledState(_cmf_info
[CMFV_GLASSES
].valid_values
[this->ge
] < 2 || GetCompanyManagerFaceBits(this->face
, CMFV_HAS_GLASSES
, this->ge
) == 0,
1505 WID_SCMF_GLASSES
, WID_SCMF_GLASSES_L
, WID_SCMF_GLASSES_R
, WIDGET_LIST_END
);
1507 this->DrawWidgets();
1510 void DrawWidget(const Rect
&r
, int widget
) const override
1513 case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
:
1514 case WID_SCMF_TIE_EARRING_TEXT
: {
1515 StringID str
= PART_TEXTS_IS_FEMALE
[(widget
- WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
) * 2 + this->is_female
];
1516 DrawString(r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, r
.top
+ WD_FRAMERECT_TOP
, str
, TC_GOLD
, SA_RIGHT
);
1520 case WID_SCMF_LIPS_MOUSTACHE_TEXT
:
1521 DrawString(r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, r
.top
+ WD_FRAMERECT_TOP
, (this->is_moust_male
) ? STR_FACE_MOUSTACHE
: STR_FACE_LIPS
, TC_GOLD
, SA_RIGHT
);
1524 case WID_SCMF_HAS_GLASSES_TEXT
:
1525 case WID_SCMF_HAIR_TEXT
:
1526 case WID_SCMF_EYEBROWS_TEXT
:
1527 case WID_SCMF_EYECOLOUR_TEXT
:
1528 case WID_SCMF_GLASSES_TEXT
:
1529 case WID_SCMF_NOSE_TEXT
:
1530 case WID_SCMF_CHIN_TEXT
:
1531 case WID_SCMF_JACKET_TEXT
:
1532 case WID_SCMF_COLLAR_TEXT
:
1533 DrawString(r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, r
.top
+ WD_FRAMERECT_TOP
, PART_TEXTS
[widget
- WID_SCMF_HAS_GLASSES_TEXT
], TC_GOLD
, SA_RIGHT
);
1537 case WID_SCMF_HAS_MOUSTACHE_EARRING
:
1538 if (this->is_female
) { // Only for female faces
1539 this->DrawFaceStringLabel(WID_SCMF_HAS_MOUSTACHE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_TIE_EARRING
, this->ge
), true);
1540 } else { // Only for male faces
1541 this->DrawFaceStringLabel(WID_SCMF_HAS_MOUSTACHE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_MOUSTACHE
, this->ge
), true);
1545 case WID_SCMF_TIE_EARRING
:
1546 this->DrawFaceStringLabel(WID_SCMF_TIE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_TIE_EARRING
, this->ge
), false);
1549 case WID_SCMF_LIPS_MOUSTACHE
:
1550 if (this->is_moust_male
) { // Only for male faces with moustache
1551 this->DrawFaceStringLabel(WID_SCMF_LIPS_MOUSTACHE
, GetCompanyManagerFaceBits(this->face
, CMFV_MOUSTACHE
, this->ge
), false);
1552 } else { // Only for female faces or male faces without moustache
1553 this->DrawFaceStringLabel(WID_SCMF_LIPS_MOUSTACHE
, GetCompanyManagerFaceBits(this->face
, CMFV_LIPS
, this->ge
), false);
1557 case WID_SCMF_HAS_GLASSES
:
1558 this->DrawFaceStringLabel(WID_SCMF_HAS_GLASSES
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_GLASSES
, this->ge
), true );
1562 this->DrawFaceStringLabel(WID_SCMF_HAIR
, GetCompanyManagerFaceBits(this->face
, CMFV_HAIR
, this->ge
), false);
1565 case WID_SCMF_EYEBROWS
:
1566 this->DrawFaceStringLabel(WID_SCMF_EYEBROWS
, GetCompanyManagerFaceBits(this->face
, CMFV_EYEBROWS
, this->ge
), false);
1569 case WID_SCMF_EYECOLOUR
:
1570 this->DrawFaceStringLabel(WID_SCMF_EYECOLOUR
, GetCompanyManagerFaceBits(this->face
, CMFV_EYE_COLOUR
, this->ge
), false);
1573 case WID_SCMF_GLASSES
:
1574 this->DrawFaceStringLabel(WID_SCMF_GLASSES
, GetCompanyManagerFaceBits(this->face
, CMFV_GLASSES
, this->ge
), false);
1578 this->DrawFaceStringLabel(WID_SCMF_NOSE
, GetCompanyManagerFaceBits(this->face
, CMFV_NOSE
, this->ge
), false);
1582 this->DrawFaceStringLabel(WID_SCMF_CHIN
, GetCompanyManagerFaceBits(this->face
, CMFV_CHIN
, this->ge
), false);
1585 case WID_SCMF_JACKET
:
1586 this->DrawFaceStringLabel(WID_SCMF_JACKET
, GetCompanyManagerFaceBits(this->face
, CMFV_JACKET
, this->ge
), false);
1589 case WID_SCMF_COLLAR
:
1590 this->DrawFaceStringLabel(WID_SCMF_COLLAR
, GetCompanyManagerFaceBits(this->face
, CMFV_COLLAR
, this->ge
), false);
1594 DrawCompanyManagerFace(this->face
, Company::Get((CompanyID
)this->window_number
)->colour
, r
.left
, r
.top
);
1599 void OnClick(Point pt
, int widget
, int click_count
) override
1602 /* Toggle size, advanced/simple face selection */
1603 case WID_SCMF_TOGGLE_LARGE_SMALL
:
1604 case WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
:
1605 this->advanced
= !this->advanced
;
1606 this->SelectDisplayPlanes(this->advanced
);
1611 case WID_SCMF_ACCEPT
:
1612 DoCommandP(0, 0, this->face
, CMD_SET_COMPANY_MANAGER_FACE
);
1616 case WID_SCMF_CANCEL
:
1622 this->face
= _company_manager_face
;
1623 ScaleAllCompanyManagerFaceBits(this->face
);
1624 ShowErrorMessage(STR_FACE_LOAD_DONE
, INVALID_STRING_ID
, WL_INFO
);
1629 /* 'Company manager face number' button, view and/or set company manager face number */
1630 case WID_SCMF_FACECODE
:
1631 SetDParam(0, this->face
);
1632 ShowQueryString(STR_JUST_INT
, STR_FACE_FACECODE_CAPTION
, 10 + 1, this, CS_NUMERAL
, QSF_NONE
);
1637 _company_manager_face
= this->face
;
1638 ShowErrorMessage(STR_FACE_SAVE_DONE
, INVALID_STRING_ID
, WL_INFO
);
1641 /* Toggle gender (male/female) button */
1643 case WID_SCMF_FEMALE
:
1644 case WID_SCMF_MALE2
:
1645 case WID_SCMF_FEMALE2
:
1646 SetCompanyManagerFaceBits(this->face
, CMFV_GENDER
, this->ge
, (widget
== WID_SCMF_FEMALE
|| widget
== WID_SCMF_FEMALE2
));
1647 ScaleAllCompanyManagerFaceBits(this->face
);
1652 /* Randomize face button */
1653 case WID_SCMF_RANDOM_NEW_FACE
:
1654 RandomCompanyManagerFaceBits(this->face
, this->ge
, this->advanced
);
1659 /* Toggle ethnicity (european/african) button */
1660 case WID_SCMF_ETHNICITY_EUR
:
1661 case WID_SCMF_ETHNICITY_AFR
:
1662 SetCompanyManagerFaceBits(this->face
, CMFV_ETHNICITY
, this->ge
, widget
- WID_SCMF_ETHNICITY_EUR
);
1663 ScaleAllCompanyManagerFaceBits(this->face
);
1669 /* Here all buttons from WID_SCMF_HAS_MOUSTACHE_EARRING to WID_SCMF_GLASSES_R are handled.
1670 * First it checks which CompanyManagerFaceVariable is being changed, and then either
1671 * a: invert the value for boolean variables, or
1672 * b: it checks inside of IncreaseCompanyManagerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
1673 if (widget
>= WID_SCMF_HAS_MOUSTACHE_EARRING
&& widget
<= WID_SCMF_GLASSES_R
) {
1674 CompanyManagerFaceVariable cmfv
; // which CompanyManagerFaceVariable shall be edited
1676 if (widget
< WID_SCMF_EYECOLOUR_L
) { // Bool buttons
1677 switch (widget
- WID_SCMF_HAS_MOUSTACHE_EARRING
) {
1678 default: NOT_REACHED();
1679 case 0: cmfv
= this->is_female
? CMFV_HAS_TIE_EARRING
: CMFV_HAS_MOUSTACHE
; break; // Has earring/moustache button
1680 case 1: cmfv
= CMFV_HAS_GLASSES
; break; // Has glasses button
1682 SetCompanyManagerFaceBits(this->face
, cmfv
, this->ge
, !GetCompanyManagerFaceBits(this->face
, cmfv
, this->ge
));
1683 ScaleAllCompanyManagerFaceBits(this->face
);
1684 } else { // Value buttons
1685 switch ((widget
- WID_SCMF_EYECOLOUR_L
) / 3) {
1686 default: NOT_REACHED();
1687 case 0: cmfv
= CMFV_EYE_COLOUR
; break; // Eye colour buttons
1688 case 1: cmfv
= CMFV_CHIN
; break; // Chin buttons
1689 case 2: cmfv
= CMFV_EYEBROWS
; break; // Eyebrows buttons
1690 case 3: cmfv
= this->is_moust_male
? CMFV_MOUSTACHE
: CMFV_LIPS
; break; // Moustache or lips buttons
1691 case 4: cmfv
= CMFV_NOSE
; break; // Nose buttons
1692 case 5: cmfv
= CMFV_HAIR
; break; // Hair buttons
1693 case 6: cmfv
= CMFV_JACKET
; break; // Jacket buttons
1694 case 7: cmfv
= CMFV_COLLAR
; break; // Collar buttons
1695 case 8: cmfv
= CMFV_TIE_EARRING
; break; // Tie/earring buttons
1696 case 9: cmfv
= CMFV_GLASSES
; break; // Glasses buttons
1698 /* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
1699 IncreaseCompanyManagerFaceBits(this->face
, cmfv
, this->ge
, (((widget
- WID_SCMF_EYECOLOUR_L
) % 3) != 0) ? 1 : -1);
1708 void OnQueryTextFinished(char *str
) override
1710 if (str
== nullptr) return;
1711 /* Set a new company manager face number */
1712 if (!StrEmpty(str
)) {
1713 this->face
= strtoul(str
, nullptr, 10);
1714 ScaleAllCompanyManagerFaceBits(this->face
);
1715 ShowErrorMessage(STR_FACE_FACECODE_SET
, INVALID_STRING_ID
, WL_INFO
);
1719 ShowErrorMessage(STR_FACE_FACECODE_ERR
, INVALID_STRING_ID
, WL_INFO
);
1724 /** Both text values of parts of the face that depend on the #is_female boolean value. */
1725 const StringID
SelectCompanyManagerFaceWindow::PART_TEXTS_IS_FEMALE
[] = {
1726 STR_FACE_MOUSTACHE
, STR_FACE_EARRING
, // WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
1727 STR_FACE_TIE
, STR_FACE_EARRING
, // WID_SCMF_TIE_EARRING_TEXT
1730 /** Textual names for parts of the face. */
1731 const StringID
SelectCompanyManagerFaceWindow::PART_TEXTS
[] = {
1732 STR_FACE_GLASSES
, // WID_SCMF_HAS_GLASSES_TEXT
1733 STR_FACE_HAIR
, // WID_SCMF_HAIR_TEXT
1734 STR_FACE_EYEBROWS
, // WID_SCMF_EYEBROWS_TEXT
1735 STR_FACE_EYECOLOUR
, // WID_SCMF_EYECOLOUR_TEXT
1736 STR_FACE_GLASSES
, // WID_SCMF_GLASSES_TEXT
1737 STR_FACE_NOSE
, // WID_SCMF_NOSE_TEXT
1738 STR_FACE_CHIN
, // WID_SCMF_CHIN_TEXT
1739 STR_FACE_JACKET
, // WID_SCMF_JACKET_TEXT
1740 STR_FACE_COLLAR
, // WID_SCMF_COLLAR_TEXT
1743 /** Company manager face selection window description */
1744 static WindowDesc
_select_company_manager_face_desc(
1745 WDP_AUTO
, "company_face", 0, 0,
1746 WC_COMPANY_MANAGER_FACE
, WC_NONE
,
1748 _nested_select_company_manager_face_widgets
, lengthof(_nested_select_company_manager_face_widgets
)
1752 * Open the simple/advanced company manager face selection window
1754 * @param parent the parent company window
1756 static void DoSelectCompanyManagerFace(Window
*parent
)
1758 if (!Company::IsValidID((CompanyID
)parent
->window_number
)) return;
1760 if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE
, parent
->window_number
)) return;
1761 new SelectCompanyManagerFaceWindow(&_select_company_manager_face_desc
, parent
);
1764 static const NWidgetPart _nested_company_infrastructure_widgets
[] = {
1765 NWidget(NWID_HORIZONTAL
),
1766 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1767 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_CI_CAPTION
), SetDataTip(STR_COMPANY_INFRASTRUCTURE_VIEW_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1768 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1769 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1771 NWidget(WWT_PANEL
, COLOUR_GREY
),
1772 NWidget(NWID_VERTICAL
), SetPIP(WD_FRAMERECT_TOP
, 4, WD_FRAMETEXT_BOTTOM
),
1773 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1774 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_RAIL_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1775 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_RAIL_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1777 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1778 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_ROAD_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1779 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_ROAD_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1781 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1782 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TRAM_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1783 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TRAM_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1785 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1786 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_WATER_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1787 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_WATER_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1789 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1790 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_STATION_DESC
), SetMinimalTextLines(3, 0), SetFill(1, 0),
1791 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_STATION_COUNT
), SetMinimalTextLines(3, 0), SetFill(0, 1),
1793 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1794 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TOTAL_DESC
), SetFill(1, 0),
1795 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TOTAL
), SetFill(0, 1),
1802 * Window with detailed information about the company's infrastructure.
1804 struct CompanyInfrastructureWindow
: Window
1806 RailTypes railtypes
; ///< Valid railtypes.
1807 RoadTypes roadtypes
; ///< Valid roadtypes.
1809 uint total_width
; ///< String width of the total cost line.
1811 CompanyInfrastructureWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
1813 this->UpdateRailRoadTypes();
1815 this->InitNested(window_number
);
1816 this->owner
= (Owner
)this->window_number
;
1819 void UpdateRailRoadTypes()
1821 this->railtypes
= RAILTYPES_NONE
;
1822 this->roadtypes
= ROADTYPES_NONE
;
1824 /* Find the used railtypes. */
1825 for (const Engine
*e
: Engine::IterateType(VEH_TRAIN
)) {
1826 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
1828 this->railtypes
|= GetRailTypeInfo(e
->u
.rail
.railtype
)->introduces_railtypes
;
1831 /* Get the date introduced railtypes as well. */
1832 this->railtypes
= AddDateIntroducedRailTypes(this->railtypes
, MAX_DAY
);
1834 /* Find the used roadtypes. */
1835 for (const Engine
*e
: Engine::IterateType(VEH_ROAD
)) {
1836 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
1838 this->roadtypes
|= GetRoadTypeInfo(e
->u
.road
.roadtype
)->introduces_roadtypes
;
1841 /* Get the date introduced roadtypes as well. */
1842 this->roadtypes
= AddDateIntroducedRoadTypes(this->roadtypes
, MAX_DAY
);
1843 this->roadtypes
&= ~_roadtypes_hidden_mask
;
1846 /** Get total infrastructure maintenance cost. */
1847 Money
GetTotalMaintenanceCost() const
1849 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
1852 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
1853 for (RailType rt
= RAILTYPE_BEGIN
; rt
!= RAILTYPE_END
; rt
++) {
1854 if (HasBit(this->railtypes
, rt
)) total
+= RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
);
1856 total
+= SignalMaintenanceCost(c
->infrastructure
.signal
);
1858 uint32 road_total
= c
->infrastructure
.GetRoadTotal();
1859 uint32 tram_total
= c
->infrastructure
.GetTramTotal();
1860 for (RoadType rt
= ROADTYPE_BEGIN
; rt
!= ROADTYPE_END
; rt
++) {
1861 if (HasBit(this->roadtypes
, rt
)) total
+= RoadMaintenanceCost(rt
, c
->infrastructure
.road
[rt
], RoadTypeIsRoad(rt
) ? road_total
: tram_total
);
1864 total
+= CanalMaintenanceCost(c
->infrastructure
.water
);
1865 total
+= StationMaintenanceCost(c
->infrastructure
.station
);
1866 total
+= AirportMaintenanceCost(c
->index
);
1871 void SetStringParameters(int widget
) const override
1874 case WID_CI_CAPTION
:
1875 SetDParam(0, (CompanyID
)this->window_number
);
1880 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1882 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
1885 case WID_CI_RAIL_DESC
: {
1886 uint lines
= 1; // Starts at 1 because a line is also required for the section title
1888 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT
).width
);
1891 FOR_ALL_SORTED_RAILTYPES(rt
) {
1892 if (HasBit(this->railtypes
, rt
)) {
1894 SetDParam(0, GetRailTypeInfo(rt
)->strings
.name
);
1895 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_WHITE_STRING
).width
+ WD_FRAMERECT_LEFT
);
1898 if (this->railtypes
!= RAILTYPES_NONE
) {
1900 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS
).width
+ WD_FRAMERECT_LEFT
);
1903 size
->height
= std::max(size
->height
, lines
* FONT_HEIGHT_NORMAL
);
1907 case WID_CI_ROAD_DESC
:
1908 case WID_CI_TRAM_DESC
: {
1909 uint lines
= 1; // Starts at 1 because a line is also required for the section title
1911 size
->width
= std::max(size
->width
, GetStringBoundingBox(widget
== WID_CI_ROAD_DESC
? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT
: STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT
).width
);
1914 FOR_ALL_SORTED_ROADTYPES(rt
) {
1915 if (HasBit(this->roadtypes
, rt
) && RoadTypeIsRoad(rt
) == (widget
== WID_CI_ROAD_DESC
)) {
1917 SetDParam(0, GetRoadTypeInfo(rt
)->strings
.name
);
1918 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_WHITE_STRING
).width
+ WD_FRAMERECT_LEFT
);
1922 size
->height
= std::max(size
->height
, lines
* FONT_HEIGHT_NORMAL
);
1926 case WID_CI_WATER_DESC
:
1927 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT
).width
);
1928 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS
).width
+ WD_FRAMERECT_LEFT
);
1931 case WID_CI_STATION_DESC
:
1932 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT
).width
);
1933 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS
).width
+ WD_FRAMERECT_LEFT
);
1934 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS
).width
+ WD_FRAMERECT_LEFT
);
1937 case WID_CI_RAIL_COUNT
:
1938 case WID_CI_ROAD_COUNT
:
1939 case WID_CI_TRAM_COUNT
:
1940 case WID_CI_WATER_COUNT
:
1941 case WID_CI_STATION_COUNT
:
1942 case WID_CI_TOTAL
: {
1943 /* Find the maximum count that is displayed. */
1944 uint32 max_val
= 1000; // Some random number to reserve enough space.
1945 Money max_cost
= 10000; // Some random number to reserve enough space.
1946 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
1947 for (RailType rt
= RAILTYPE_BEGIN
; rt
< RAILTYPE_END
; rt
++) {
1948 max_val
= std::max(max_val
, c
->infrastructure
.rail
[rt
]);
1949 max_cost
= std::max(max_cost
, RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
));
1951 max_val
= std::max(max_val
, c
->infrastructure
.signal
);
1952 max_cost
= std::max(max_cost
, SignalMaintenanceCost(c
->infrastructure
.signal
));
1953 uint32 road_total
= c
->infrastructure
.GetRoadTotal();
1954 uint32 tram_total
= c
->infrastructure
.GetTramTotal();
1955 for (RoadType rt
= ROADTYPE_BEGIN
; rt
< ROADTYPE_END
; rt
++) {
1956 max_val
= std::max(max_val
, c
->infrastructure
.road
[rt
]);
1957 max_cost
= std::max(max_cost
, RoadMaintenanceCost(rt
, c
->infrastructure
.road
[rt
], RoadTypeIsRoad(rt
) ? road_total
: tram_total
));
1960 max_val
= std::max(max_val
, c
->infrastructure
.water
);
1961 max_cost
= std::max(max_cost
, CanalMaintenanceCost(c
->infrastructure
.water
));
1962 max_val
= std::max(max_val
, c
->infrastructure
.station
);
1963 max_cost
= std::max(max_cost
, StationMaintenanceCost(c
->infrastructure
.station
));
1964 max_val
= std::max(max_val
, c
->infrastructure
.airport
);
1965 max_cost
= std::max(max_cost
, AirportMaintenanceCost(c
->index
));
1967 SetDParamMaxValue(0, max_val
);
1968 uint count_width
= GetStringBoundingBox(STR_WHITE_COMMA
).width
+ 20; // Reserve some wiggle room
1970 if (_settings_game
.economy
.infrastructure_maintenance
) {
1971 SetDParamMaxValue(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
1972 this->total_width
= GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
).width
+ 20;
1973 size
->width
= std::max(size
->width
, this->total_width
);
1975 SetDParamMaxValue(0, max_cost
* 12); // Convert to per year
1976 count_width
+= std::max(this->total_width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
).width
);
1979 size
->width
= std::max(size
->width
, count_width
);
1981 /* Set height of the total line. */
1982 if (widget
== WID_CI_TOTAL
) {
1983 size
->height
= _settings_game
.economy
.infrastructure_maintenance
? std::max(size
->height
, EXP_LINESPACE
+ FONT_HEIGHT_NORMAL
) : 0;
1991 * Helper for drawing the counts line.
1992 * @param r The bounds to draw in.
1993 * @param y The y position to draw at.
1994 * @param count The count to show on this line.
1995 * @param monthly_cost The monthly costs.
1997 void DrawCountLine(const Rect
&r
, int &y
, int count
, Money monthly_cost
) const
1999 SetDParam(0, count
);
2000 DrawString(r
.left
, r
.right
, y
+= FONT_HEIGHT_NORMAL
, STR_WHITE_COMMA
, TC_FROMSTRING
, SA_RIGHT
);
2002 if (_settings_game
.economy
.infrastructure_maintenance
) {
2003 SetDParam(0, monthly_cost
* 12); // Convert to per year
2004 int left
= _current_text_dir
== TD_RTL
? r
.right
- this->total_width
: r
.left
;
2005 DrawString(left
, left
+ this->total_width
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
, TC_FROMSTRING
, SA_RIGHT
);
2009 void DrawWidget(const Rect
&r
, int widget
) const override
2011 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2014 int offs_left
= _current_text_dir
== TD_LTR
? WD_FRAMERECT_LEFT
: 0;
2015 int offs_right
= _current_text_dir
== TD_LTR
? 0 : WD_FRAMERECT_LEFT
;
2018 case WID_CI_RAIL_DESC
:
2019 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT
);
2021 if (this->railtypes
!= RAILTYPES_NONE
) {
2022 /* Draw name of each valid railtype. */
2024 FOR_ALL_SORTED_RAILTYPES(rt
) {
2025 if (HasBit(this->railtypes
, rt
)) {
2026 SetDParam(0, GetRailTypeInfo(rt
)->strings
.name
);
2027 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_WHITE_STRING
);
2030 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS
);
2032 /* No valid railtype. */
2033 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
);
2038 case WID_CI_RAIL_COUNT
: {
2039 /* Draw infrastructure count for each valid railtype. */
2040 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
2042 FOR_ALL_SORTED_RAILTYPES(rt
) {
2043 if (HasBit(this->railtypes
, rt
)) {
2044 this->DrawCountLine(r
, y
, c
->infrastructure
.rail
[rt
], RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
));
2047 if (this->railtypes
!= RAILTYPES_NONE
) {
2048 this->DrawCountLine(r
, y
, c
->infrastructure
.signal
, SignalMaintenanceCost(c
->infrastructure
.signal
));
2053 case WID_CI_ROAD_DESC
:
2054 case WID_CI_TRAM_DESC
: {
2055 DrawString(r
.left
, r
.right
, y
, widget
== WID_CI_ROAD_DESC
? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT
: STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT
);
2057 /* Draw name of each valid roadtype. */
2059 FOR_ALL_SORTED_ROADTYPES(rt
) {
2060 if (HasBit(this->roadtypes
, rt
) && RoadTypeIsRoad(rt
) == (widget
== WID_CI_ROAD_DESC
)) {
2061 SetDParam(0, GetRoadTypeInfo(rt
)->strings
.name
);
2062 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_WHITE_STRING
);
2069 case WID_CI_ROAD_COUNT
:
2070 case WID_CI_TRAM_COUNT
: {
2071 uint32 road_tram_total
= widget
== WID_CI_ROAD_COUNT
? c
->infrastructure
.GetRoadTotal() : c
->infrastructure
.GetTramTotal();
2073 FOR_ALL_SORTED_ROADTYPES(rt
) {
2074 if (HasBit(this->roadtypes
, rt
) && RoadTypeIsRoad(rt
) == (widget
== WID_CI_ROAD_COUNT
)) {
2075 this->DrawCountLine(r
, y
, c
->infrastructure
.road
[rt
], RoadMaintenanceCost(rt
, c
->infrastructure
.road
[rt
], road_tram_total
));
2081 case WID_CI_WATER_DESC
:
2082 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT
);
2083 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS
);
2086 case WID_CI_WATER_COUNT
:
2087 this->DrawCountLine(r
, y
, c
->infrastructure
.water
, CanalMaintenanceCost(c
->infrastructure
.water
));
2091 if (_settings_game
.economy
.infrastructure_maintenance
) {
2092 int left
= _current_text_dir
== TD_RTL
? r
.right
- this->total_width
: r
.left
;
2093 GfxFillRect(left
, y
, left
+ this->total_width
, y
, PC_WHITE
);
2095 SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
2096 DrawString(left
, left
+ this->total_width
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
, TC_FROMSTRING
, SA_RIGHT
);
2100 case WID_CI_STATION_DESC
:
2101 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT
);
2102 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS
);
2103 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS
);
2106 case WID_CI_STATION_COUNT
:
2107 this->DrawCountLine(r
, y
, c
->infrastructure
.station
, StationMaintenanceCost(c
->infrastructure
.station
));
2108 this->DrawCountLine(r
, y
, c
->infrastructure
.airport
, AirportMaintenanceCost(c
->index
));
2114 * Some data on this window has become invalid.
2115 * @param data Information about the changed data.
2116 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
2118 void OnInvalidateData(int data
= 0, bool gui_scope
= true) override
2120 if (!gui_scope
) return;
2122 this->UpdateRailRoadTypes();
2127 static WindowDesc
_company_infrastructure_desc(
2128 WDP_AUTO
, "company_infrastructure", 0, 0,
2129 WC_COMPANY_INFRASTRUCTURE
, WC_NONE
,
2131 _nested_company_infrastructure_widgets
, lengthof(_nested_company_infrastructure_widgets
)
2135 * Open the infrastructure window of a company.
2136 * @param company Company to show infrastructure of.
2138 static void ShowCompanyInfrastructure(CompanyID company
)
2140 if (!Company::IsValidID(company
)) return;
2141 AllocateWindowDescFront
<CompanyInfrastructureWindow
>(&_company_infrastructure_desc
, company
);
2144 static const NWidgetPart _nested_company_widgets
[] = {
2145 NWidget(NWID_HORIZONTAL
),
2146 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
2147 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_C_CAPTION
), SetDataTip(STR_COMPANY_VIEW_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2148 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
2149 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
2151 NWidget(WWT_PANEL
, COLOUR_GREY
),
2152 NWidget(NWID_HORIZONTAL
), SetPIP(4, 6, 4),
2153 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
2154 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_FACE
), SetMinimalSize(92, 119), SetFill(1, 0),
2155 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_FACE_TITLE
), SetFill(1, 1), SetMinimalTextLines(2, 0),
2157 NWidget(NWID_VERTICAL
),
2158 NWidget(NWID_HORIZONTAL
),
2159 NWidget(NWID_VERTICAL
), SetPIP(4, 5, 5),
2160 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_INAUGURATION
), SetDataTip(STR_COMPANY_VIEW_INAUGURATED_TITLE
, STR_NULL
), SetFill(1, 0),
2161 NWidget(NWID_HORIZONTAL
), SetPIP(0, 5, 0),
2162 NWidget(WWT_LABEL
, COLOUR_GREY
, WID_C_DESC_COLOUR_SCHEME
), SetDataTip(STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE
, STR_NULL
),
2163 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_COLOUR_SCHEME_EXAMPLE
), SetMinimalSize(30, 0), SetFill(0, 1),
2164 NWidget(NWID_SPACER
), SetFill(1, 0),
2166 NWidget(NWID_HORIZONTAL
), SetPIP(0, 4, 0),
2167 NWidget(NWID_VERTICAL
),
2168 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_VEHICLE
), SetDataTip(STR_COMPANY_VIEW_VEHICLES_TITLE
, STR_NULL
),
2169 NWidget(NWID_SPACER
), SetFill(0, 1),
2171 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_VEHICLE_COUNTS
), SetMinimalTextLines(4, 0),
2172 NWidget(NWID_SPACER
), SetFill(1, 0),
2175 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
2176 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_VIEW_BUILD_HQ
),
2177 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_VIEW_HQ
), SetDataTip(STR_COMPANY_VIEW_VIEW_HQ_BUTTON
, STR_COMPANY_VIEW_VIEW_HQ_TOOLTIP
),
2178 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_C_BUILD_HQ
), SetDataTip(STR_COMPANY_VIEW_BUILD_HQ_BUTTON
, STR_COMPANY_VIEW_BUILD_HQ_TOOLTIP
),
2180 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_RELOCATE
),
2181 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_C_RELOCATE_HQ
), SetDataTip(STR_COMPANY_VIEW_RELOCATE_HQ
, STR_COMPANY_VIEW_RELOCATE_COMPANY_HEADQUARTERS
),
2182 NWidget(NWID_SPACER
),
2184 NWidget(NWID_SPACER
), SetFill(0, 1),
2187 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_COMPANY_VALUE
), SetDataTip(STR_COMPANY_VIEW_COMPANY_VALUE
, STR_NULL
), SetFill(1, 0),
2188 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
2189 NWidget(NWID_HORIZONTAL
), SetPIP(0, 4, 0),
2190 NWidget(NWID_VERTICAL
),
2191 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_INFRASTRUCTURE
), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE
, STR_NULL
),
2192 NWidget(NWID_SPACER
), SetFill(0, 1),
2194 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_INFRASTRUCTURE_COUNTS
), SetMinimalTextLines(5, 0), SetFill(1, 0),
2195 NWidget(NWID_VERTICAL
),
2196 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_VIEW_INFRASTRUCTURE
), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON
, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP
),
2197 NWidget(NWID_SPACER
),
2201 NWidget(NWID_HORIZONTAL
),
2202 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_DESC_OWNERS
),
2203 NWidget(NWID_VERTICAL
), SetPIP(5, 5, 4),
2204 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_OWNERS
), SetMinimalTextLines(3, 0),
2205 NWidget(NWID_SPACER
), SetFill(0, 1),
2208 /* Multi player buttons. */
2209 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
2210 NWidget(NWID_SPACER
), SetFill(0, 1),
2211 NWidget(NWID_HORIZONTAL
), SetPIP(0, 4, 0),
2212 NWidget(NWID_SPACER
), SetFill(1, 0),
2213 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_GIVE_MONEY
),
2214 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_GIVE_MONEY
), SetDataTip(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON
, STR_COMPANY_VIEW_GIVE_MONEY_TOOLTIP
),
2217 NWidget(NWID_HORIZONTAL
), SetPIP(0, 4, 0),
2218 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_C_HAS_PASSWORD
),
2219 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_MULTIPLAYER
),
2220 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_COMPANY_PASSWORD
), SetDataTip(STR_COMPANY_VIEW_PASSWORD
, STR_COMPANY_VIEW_PASSWORD_TOOLTIP
),
2221 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_COMPANY_JOIN
), SetDataTip(STR_COMPANY_VIEW_JOIN
, STR_COMPANY_VIEW_JOIN_TOOLTIP
),
2229 /* Button bars at the bottom. */
2230 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_BUTTONS
),
2231 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
2232 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_NEW_FACE
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_NEW_FACE_BUTTON
, STR_COMPANY_VIEW_NEW_FACE_TOOLTIP
),
2233 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_COLOUR_SCHEME
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_COLOUR_SCHEME_BUTTON
, STR_COMPANY_VIEW_COLOUR_SCHEME_TOOLTIP
),
2234 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_PRESIDENT_NAME
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_PRESIDENT_NAME_BUTTON
, STR_COMPANY_VIEW_PRESIDENT_NAME_TOOLTIP
),
2235 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_COMPANY_NAME
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_COMPANY_NAME_BUTTON
, STR_COMPANY_VIEW_COMPANY_NAME_TOOLTIP
),
2237 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
2238 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_BUY_SHARE
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_BUY_SHARE_BUTTON
, STR_COMPANY_VIEW_BUY_SHARE_TOOLTIP
),
2239 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_SELL_SHARE
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_SELL_SHARE_BUTTON
, STR_COMPANY_VIEW_SELL_SHARE_TOOLTIP
),
2244 int GetAmountOwnedBy(const Company
*c
, Owner owner
)
2246 return (c
->share_owners
[0] == owner
) +
2247 (c
->share_owners
[1] == owner
) +
2248 (c
->share_owners
[2] == owner
) +
2249 (c
->share_owners
[3] == owner
);
2252 /** Strings for the company vehicle counts */
2253 static const StringID _company_view_vehicle_count_strings
[] = {
2254 STR_COMPANY_VIEW_TRAINS
, STR_COMPANY_VIEW_ROAD_VEHICLES
, STR_COMPANY_VIEW_SHIPS
, STR_COMPANY_VIEW_AIRCRAFT
2258 * Window with general information about a company
2260 struct CompanyWindow
: Window
2262 CompanyWidgets query_widget
;
2264 /** Display planes in the company window. */
2265 enum CompanyWindowPlanes
{
2266 /* Display planes of the #WID_C_SELECT_MULTIPLAYER selection widget. */
2267 CWP_MP_C_PWD
= 0, ///< Display the company password button.
2268 CWP_MP_C_JOIN
, ///< Display the join company button.
2270 /* Display planes of the #WID_C_SELECT_VIEW_BUILD_HQ selection widget. */
2271 CWP_VB_VIEW
= 0, ///< Display the view button
2272 CWP_VB_BUILD
, ///< Display the build button
2274 /* Display planes of the #WID_C_SELECT_RELOCATE selection widget. */
2275 CWP_RELOCATE_SHOW
= 0, ///< Show the relocate HQ button.
2276 CWP_RELOCATE_HIDE
, ///< Hide the relocate HQ button.
2278 /* Display planes of the #WID_C_SELECT_BUTTONS selection widget. */
2279 CWP_BUTTONS_LOCAL
= 0, ///< Buttons of the local company.
2280 CWP_BUTTONS_OTHER
, ///< Buttons of the other companies.
2283 CompanyWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
2285 this->InitNested(window_number
);
2286 this->owner
= (Owner
)this->window_number
;
2287 this->OnInvalidateData();
2290 void OnPaint() override
2292 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2293 bool local
= this->window_number
== _local_company
;
2295 if (!this->IsShaded()) {
2296 bool reinit
= false;
2298 /* Button bar selection. */
2299 int plane
= local
? CWP_BUTTONS_LOCAL
: CWP_BUTTONS_OTHER
;
2300 NWidgetStacked
*wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_BUTTONS
);
2301 if (plane
!= wi
->shown_plane
) {
2302 wi
->SetDisplayedPlane(plane
);
2303 this->InvalidateData();
2307 /* Build HQ button handling. */
2308 plane
= (local
&& c
->location_of_HQ
== INVALID_TILE
) ? CWP_VB_BUILD
: CWP_VB_VIEW
;
2309 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_VIEW_BUILD_HQ
);
2310 if (plane
!= wi
->shown_plane
) {
2311 wi
->SetDisplayedPlane(plane
);
2315 this->SetWidgetDisabledState(WID_C_VIEW_HQ
, c
->location_of_HQ
== INVALID_TILE
);
2317 /* Enable/disable 'Relocate HQ' button. */
2318 plane
= (!local
|| c
->location_of_HQ
== INVALID_TILE
) ? CWP_RELOCATE_HIDE
: CWP_RELOCATE_SHOW
;
2319 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_RELOCATE
);
2320 if (plane
!= wi
->shown_plane
) {
2321 wi
->SetDisplayedPlane(plane
);
2325 /* Owners of company */
2326 plane
= SZSP_HORIZONTAL
;
2327 for (uint i
= 0; i
< lengthof(c
->share_owners
); i
++) {
2328 if (c
->share_owners
[i
] != INVALID_COMPANY
) {
2333 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_DESC_OWNERS
);
2334 if (plane
!= wi
->shown_plane
) {
2335 wi
->SetDisplayedPlane(plane
);
2339 /* Enable/disable 'Give money' button. */
2340 plane
= ((local
|| _local_company
== COMPANY_SPECTATOR
|| !_settings_game
.economy
.give_money
) ? SZSP_NONE
: 0);
2341 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_GIVE_MONEY
);
2342 if (plane
!= wi
->shown_plane
) {
2343 wi
->SetDisplayedPlane(plane
);
2347 /* Multiplayer buttons. */
2348 plane
= ((!_networking
) ? (int)SZSP_NONE
: (int)(local
? CWP_MP_C_PWD
: CWP_MP_C_JOIN
));
2349 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_MULTIPLAYER
);
2350 if (plane
!= wi
->shown_plane
) {
2351 wi
->SetDisplayedPlane(plane
);
2354 this->SetWidgetDisabledState(WID_C_COMPANY_JOIN
, c
->is_ai
);
2362 this->DrawWidgets();
2365 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
2369 Dimension face_size
= GetSpriteSize(SPR_GRADIENT
);
2370 size
->width
= std::max(size
->width
, face_size
.width
);
2371 size
->height
= std::max(size
->height
, face_size
.height
);
2375 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE
: {
2377 Dimension d
= GetSpriteSize(SPR_VEH_BUS_SW_VIEW
, &offset
);
2378 d
.width
-= offset
.x
;
2379 d
.height
-= offset
.y
;
2380 *size
= maxdim(*size
, d
);
2384 case WID_C_DESC_COMPANY_VALUE
:
2385 SetDParam(0, INT64_MAX
); // Arguably the maximum company value
2386 size
->width
= GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE
).width
;
2389 case WID_C_DESC_VEHICLE_COUNTS
:
2390 SetDParamMaxValue(0, 5000); // Maximum number of vehicles
2391 for (uint i
= 0; i
< lengthof(_company_view_vehicle_count_strings
); i
++) {
2392 size
->width
= std::max(size
->width
, GetStringBoundingBox(_company_view_vehicle_count_strings
[i
]).width
);
2396 case WID_C_DESC_INFRASTRUCTURE_COUNTS
:
2397 SetDParamMaxValue(0, UINT_MAX
);
2398 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL
).width
);
2399 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD
).width
);
2400 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER
).width
);
2401 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION
).width
);
2402 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT
).width
);
2403 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
).width
);
2406 case WID_C_DESC_OWNERS
: {
2407 for (const Company
*c2
: Company::Iterate()) {
2408 SetDParamMaxValue(0, 75);
2409 SetDParam(1, c2
->index
);
2411 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_SHARES_OWNED_BY
).width
);
2417 case WID_C_BUILD_HQ
:
2418 case WID_C_RELOCATE_HQ
:
2419 case WID_C_VIEW_INFRASTRUCTURE
:
2420 case WID_C_GIVE_MONEY
:
2421 case WID_C_COMPANY_PASSWORD
:
2422 case WID_C_COMPANY_JOIN
:
2423 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_VIEW_HQ_BUTTON
).width
);
2424 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_BUILD_HQ_BUTTON
).width
);
2425 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_RELOCATE_HQ
).width
);
2426 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON
).width
);
2427 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON
).width
);
2428 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_PASSWORD
).width
);
2429 size
->width
= std::max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_JOIN
).width
);
2432 case WID_C_HAS_PASSWORD
:
2433 *size
= maxdim(*size
, GetSpriteSize(SPR_LOCK
));
2438 void DrawWidget(const Rect
&r
, int widget
) const override
2440 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2443 DrawCompanyManagerFace(c
->face
, c
->colour
, r
.left
, r
.top
);
2446 case WID_C_FACE_TITLE
:
2447 SetDParam(0, c
->index
);
2448 DrawStringMultiLine(r
.left
, r
.right
, r
.top
, r
.bottom
, STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE
, TC_FROMSTRING
, SA_HOR_CENTER
);
2451 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE
: {
2453 Dimension d
= GetSpriteSize(SPR_VEH_BUS_SW_VIEW
, &offset
);
2454 d
.height
-= offset
.y
;
2455 DrawSprite(SPR_VEH_BUS_SW_VIEW
, COMPANY_SPRITE_COLOUR(c
->index
), r
.left
- offset
.x
, (r
.top
+ r
.bottom
- d
.height
) / 2 - offset
.y
);
2459 case WID_C_DESC_VEHICLE_COUNTS
: {
2461 amounts
[0] = c
->group_all
[VEH_TRAIN
].num_vehicle
;
2462 amounts
[1] = c
->group_all
[VEH_ROAD
].num_vehicle
;
2463 amounts
[2] = c
->group_all
[VEH_SHIP
].num_vehicle
;
2464 amounts
[3] = c
->group_all
[VEH_AIRCRAFT
].num_vehicle
;
2467 if (amounts
[0] + amounts
[1] + amounts
[2] + amounts
[3] == 0) {
2468 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_VEHICLES_NONE
);
2470 static_assert(lengthof(amounts
) == lengthof(_company_view_vehicle_count_strings
));
2472 for (uint i
= 0; i
< lengthof(amounts
); i
++) {
2473 if (amounts
[i
] != 0) {
2474 SetDParam(0, amounts
[i
]);
2475 DrawString(r
.left
, r
.right
, y
, _company_view_vehicle_count_strings
[i
]);
2476 y
+= FONT_HEIGHT_NORMAL
;
2483 case WID_C_DESC_INFRASTRUCTURE_COUNTS
: {
2486 /* Collect rail and road counts. */
2487 uint rail_pieces
= c
->infrastructure
.signal
;
2488 uint road_pieces
= 0;
2489 for (uint i
= 0; i
< lengthof(c
->infrastructure
.rail
); i
++) rail_pieces
+= c
->infrastructure
.rail
[i
];
2490 for (uint i
= 0; i
< lengthof(c
->infrastructure
.road
); i
++) road_pieces
+= c
->infrastructure
.road
[i
];
2492 if (rail_pieces
== 0 && road_pieces
== 0 && c
->infrastructure
.water
== 0 && c
->infrastructure
.station
== 0 && c
->infrastructure
.airport
== 0) {
2493 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
);
2495 if (rail_pieces
!= 0) {
2496 SetDParam(0, rail_pieces
);
2497 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL
);
2498 y
+= FONT_HEIGHT_NORMAL
;
2500 if (road_pieces
!= 0) {
2501 SetDParam(0, road_pieces
);
2502 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD
);
2503 y
+= FONT_HEIGHT_NORMAL
;
2505 if (c
->infrastructure
.water
!= 0) {
2506 SetDParam(0, c
->infrastructure
.water
);
2507 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER
);
2508 y
+= FONT_HEIGHT_NORMAL
;
2510 if (c
->infrastructure
.station
!= 0) {
2511 SetDParam(0, c
->infrastructure
.station
);
2512 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION
);
2513 y
+= FONT_HEIGHT_NORMAL
;
2515 if (c
->infrastructure
.airport
!= 0) {
2516 SetDParam(0, c
->infrastructure
.airport
);
2517 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT
);
2524 case WID_C_DESC_OWNERS
: {
2527 for (const Company
*c2
: Company::Iterate()) {
2528 uint amt
= GetAmountOwnedBy(c
, c2
->index
);
2530 SetDParam(0, amt
* 25);
2531 SetDParam(1, c2
->index
);
2533 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_SHARES_OWNED_BY
);
2534 y
+= FONT_HEIGHT_NORMAL
;
2540 case WID_C_HAS_PASSWORD
:
2541 if (_networking
&& NetworkCompanyIsPassworded(c
->index
)) {
2542 DrawSprite(SPR_LOCK
, PAL_NONE
, r
.left
, r
.top
);
2548 void SetStringParameters(int widget
) const override
2552 SetDParam(0, (CompanyID
)this->window_number
);
2553 SetDParam(1, (CompanyID
)this->window_number
);
2556 case WID_C_DESC_INAUGURATION
:
2557 SetDParam(0, Company::Get((CompanyID
)this->window_number
)->inaugurated_year
);
2560 case WID_C_DESC_COMPANY_VALUE
:
2561 SetDParam(0, CalculateCompanyValue(Company::Get((CompanyID
)this->window_number
)));
2566 void OnClick(Point pt
, int widget
, int click_count
) override
2569 case WID_C_NEW_FACE
: DoSelectCompanyManagerFace(this); break;
2571 case WID_C_COLOUR_SCHEME
:
2572 ShowCompanyLiveryWindow((CompanyID
)this->window_number
, INVALID_GROUP
);
2575 case WID_C_PRESIDENT_NAME
:
2576 this->query_widget
= WID_C_PRESIDENT_NAME
;
2577 SetDParam(0, this->window_number
);
2578 ShowQueryString(STR_PRESIDENT_NAME
, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION
, MAX_LENGTH_PRESIDENT_NAME_CHARS
, this, CS_ALPHANUMERAL
, QSF_ENABLE_DEFAULT
| QSF_LEN_IN_CHARS
);
2581 case WID_C_COMPANY_NAME
:
2582 this->query_widget
= WID_C_COMPANY_NAME
;
2583 SetDParam(0, this->window_number
);
2584 ShowQueryString(STR_COMPANY_NAME
, STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION
, MAX_LENGTH_COMPANY_NAME_CHARS
, this, CS_ALPHANUMERAL
, QSF_ENABLE_DEFAULT
| QSF_LEN_IN_CHARS
);
2587 case WID_C_VIEW_HQ
: {
2588 TileIndex tile
= Company::Get((CompanyID
)this->window_number
)->location_of_HQ
;
2589 if (_ctrl_pressed
) {
2590 ShowExtraViewportWindow(tile
);
2592 ScrollMainWindowToTile(tile
);
2597 case WID_C_BUILD_HQ
:
2598 if ((byte
)this->window_number
!= _local_company
) return;
2599 if (this->IsWidgetLowered(WID_C_BUILD_HQ
)) {
2600 ResetObjectToPlace();
2601 this->RaiseButtons();
2604 SetObjectToPlaceWnd(SPR_CURSOR_HQ
, PAL_NONE
, HT_RECT
, this);
2605 SetTileSelectSize(2, 2);
2606 this->LowerWidget(WID_C_BUILD_HQ
);
2607 this->SetWidgetDirty(WID_C_BUILD_HQ
);
2610 case WID_C_RELOCATE_HQ
:
2611 if (this->IsWidgetLowered(WID_C_RELOCATE_HQ
)) {
2612 ResetObjectToPlace();
2613 this->RaiseButtons();
2616 SetObjectToPlaceWnd(SPR_CURSOR_HQ
, PAL_NONE
, HT_RECT
, this);
2617 SetTileSelectSize(2, 2);
2618 this->LowerWidget(WID_C_RELOCATE_HQ
);
2619 this->SetWidgetDirty(WID_C_RELOCATE_HQ
);
2622 case WID_C_VIEW_INFRASTRUCTURE
:
2623 ShowCompanyInfrastructure((CompanyID
)this->window_number
);
2626 case WID_C_GIVE_MONEY
:
2627 this->query_widget
= WID_C_GIVE_MONEY
;
2628 ShowQueryString(STR_EMPTY
, STR_COMPANY_VIEW_GIVE_MONEY_QUERY_CAPTION
, 30, this, CS_NUMERAL
, QSF_NONE
);
2631 case WID_C_BUY_SHARE
:
2632 DoCommandP(0, this->window_number
, 0, CMD_BUY_SHARE_IN_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS
));
2635 case WID_C_SELL_SHARE
:
2636 DoCommandP(0, this->window_number
, 0, CMD_SELL_SHARE_IN_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_SELL_25_SHARE_IN
));
2639 case WID_C_COMPANY_PASSWORD
:
2640 if (this->window_number
== _local_company
) ShowNetworkCompanyPasswordWindow(this);
2643 case WID_C_COMPANY_JOIN
: {
2644 this->query_widget
= WID_C_COMPANY_JOIN
;
2645 CompanyID company
= (CompanyID
)this->window_number
;
2646 if (_network_server
) {
2647 NetworkServerDoMove(CLIENT_ID_SERVER
, company
);
2648 MarkWholeScreenDirty();
2649 } else if (NetworkCompanyIsPassworded(company
)) {
2650 /* ask for the password */
2651 ShowQueryString(STR_EMPTY
, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION
, NETWORK_PASSWORD_LENGTH
, this, CS_ALPHANUMERAL
, QSF_PASSWORD
);
2653 /* just send the join command */
2654 NetworkClientRequestMove(company
);
2661 void OnHundredthTick() override
2663 /* redraw the window every now and then */
2667 void OnPlaceObject(Point pt
, TileIndex tile
) override
2669 if (DoCommandP(tile
, OBJECT_HQ
, 0, CMD_BUILD_OBJECT
| CMD_MSG(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS
)) && !_shift_pressed
) {
2670 ResetObjectToPlace();
2671 this->RaiseButtons();
2675 void OnPlaceObjectAbort() override
2677 this->RaiseButtons();
2680 void OnQueryTextFinished(char *str
) override
2682 if (str
== nullptr) return;
2684 switch (this->query_widget
) {
2685 default: NOT_REACHED();
2687 case WID_C_GIVE_MONEY
: {
2688 Money money
= (Money
)(strtoull(str
, nullptr, 10) / _currency
->rate
);
2689 uint32 money_c
= Clamp(ClampToI32(money
), 0, 20000000); // Clamp between 20 million and 0
2691 DoCommandP(0, money_c
, this->window_number
, CMD_GIVE_MONEY
| CMD_MSG(STR_ERROR_CAN_T_GIVE_MONEY
));
2695 case WID_C_PRESIDENT_NAME
:
2696 DoCommandP(0, 0, 0, CMD_RENAME_PRESIDENT
| CMD_MSG(STR_ERROR_CAN_T_CHANGE_PRESIDENT
), nullptr, str
);
2699 case WID_C_COMPANY_NAME
:
2700 DoCommandP(0, 0, 0, CMD_RENAME_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME
), nullptr, str
);
2703 case WID_C_COMPANY_JOIN
:
2704 NetworkClientRequestMove((CompanyID
)this->window_number
, str
);
2711 * Some data on this window has become invalid.
2712 * @param data Information about the changed data.
2713 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
2715 void OnInvalidateData(int data
= 0, bool gui_scope
= true) override
2717 if (this->window_number
== _local_company
) return;
2719 if (_settings_game
.economy
.allow_shares
) { // Shares are allowed
2720 const Company
*c
= Company::Get(this->window_number
);
2722 /* If all shares are owned by someone (none by nobody), disable buy button */
2723 this->SetWidgetDisabledState(WID_C_BUY_SHARE
, GetAmountOwnedBy(c
, INVALID_OWNER
) == 0 ||
2724 /* Only 25% left to buy. If the company is human, disable buying it up.. TODO issues! */
2725 (GetAmountOwnedBy(c
, INVALID_OWNER
) == 1 && !c
->is_ai
) ||
2726 /* Spectators cannot do anything of course */
2727 _local_company
== COMPANY_SPECTATOR
);
2729 /* If the company doesn't own any shares, disable sell button */
2730 this->SetWidgetDisabledState(WID_C_SELL_SHARE
, (GetAmountOwnedBy(c
, _local_company
) == 0) ||
2731 /* Spectators cannot do anything of course */
2732 _local_company
== COMPANY_SPECTATOR
);
2733 } else { // Shares are not allowed, disable buy/sell buttons
2734 this->DisableWidget(WID_C_BUY_SHARE
);
2735 this->DisableWidget(WID_C_SELL_SHARE
);
2740 static WindowDesc
_company_desc(
2741 WDP_AUTO
, "company", 0, 0,
2742 WC_COMPANY
, WC_NONE
,
2744 _nested_company_widgets
, lengthof(_nested_company_widgets
)
2748 * Show the window with the overview of the company.
2749 * @param company The company to show the window for.
2751 void ShowCompany(CompanyID company
)
2753 if (!Company::IsValidID(company
)) return;
2755 AllocateWindowDescFront
<CompanyWindow
>(&_company_desc
, company
);
2759 * Redraw all windows with company infrastructure counts.
2760 * @param company The company to redraw the windows of.
2762 void DirtyCompanyInfrastructureWindows(CompanyID company
)
2764 SetWindowDirty(WC_COMPANY
, company
);
2765 SetWindowDirty(WC_COMPANY_INFRASTRUCTURE
, company
);
2768 struct BuyCompanyWindow
: Window
{
2769 BuyCompanyWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
2771 this->InitNested(window_number
);
2774 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
2778 *size
= GetSpriteSize(SPR_GRADIENT
);
2781 case WID_BC_QUESTION
:
2782 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2783 SetDParam(0, c
->index
);
2784 SetDParam(1, c
->bankrupt_value
);
2785 size
->height
= GetStringHeight(STR_BUY_COMPANY_MESSAGE
, size
->width
);
2790 void SetStringParameters(int widget
) const override
2793 case WID_BC_CAPTION
:
2794 SetDParam(0, STR_COMPANY_NAME
);
2795 SetDParam(1, Company::Get((CompanyID
)this->window_number
)->index
);
2800 void DrawWidget(const Rect
&r
, int widget
) const override
2804 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2805 DrawCompanyManagerFace(c
->face
, c
->colour
, r
.left
, r
.top
);
2809 case WID_BC_QUESTION
: {
2810 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2811 SetDParam(0, c
->index
);
2812 SetDParam(1, c
->bankrupt_value
);
2813 DrawStringMultiLine(r
.left
, r
.right
, r
.top
, r
.bottom
, STR_BUY_COMPANY_MESSAGE
, TC_FROMSTRING
, SA_CENTER
);
2819 void OnClick(Point pt
, int widget
, int click_count
) override
2827 DoCommandP(0, this->window_number
, 0, CMD_BUY_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_BUY_COMPANY
));
2833 static const NWidgetPart _nested_buy_company_widgets
[] = {
2834 NWidget(NWID_HORIZONTAL
),
2835 NWidget(WWT_CLOSEBOX
, COLOUR_LIGHT_BLUE
),
2836 NWidget(WWT_CAPTION
, COLOUR_LIGHT_BLUE
, WID_BC_CAPTION
), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2838 NWidget(WWT_PANEL
, COLOUR_LIGHT_BLUE
),
2839 NWidget(NWID_VERTICAL
), SetPIP(8, 8, 8),
2840 NWidget(NWID_HORIZONTAL
), SetPIP(8, 10, 8),
2841 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BC_FACE
), SetFill(0, 1),
2842 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BC_QUESTION
), SetMinimalSize(240, 0), SetFill(1, 1),
2844 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(100, 10, 100),
2845 NWidget(WWT_TEXTBTN
, COLOUR_LIGHT_BLUE
, WID_BC_NO
), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_NO
, STR_NULL
), SetFill(1, 0),
2846 NWidget(WWT_TEXTBTN
, COLOUR_LIGHT_BLUE
, WID_BC_YES
), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_YES
, STR_NULL
), SetFill(1, 0),
2852 static WindowDesc
_buy_company_desc(
2853 WDP_AUTO
, nullptr, 0, 0,
2854 WC_BUY_COMPANY
, WC_NONE
,
2856 _nested_buy_company_widgets
, lengthof(_nested_buy_company_widgets
)
2860 * Show the query to buy another company.
2861 * @param company The company to buy.
2863 void ShowBuyCompanyDialog(CompanyID company
)
2865 AllocateWindowDescFront
<BuyCompanyWindow
>(&_buy_company_desc
, company
);