1 /* $Id: company_gui.cpp 26416 2014-03-18 20:53:34Z planetmaker $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file company_gui.cpp %Company related GUIs. */
15 #include "window_gui.h"
16 #include "textbuf_gui.h"
17 #include "viewport_func.h"
18 #include "company_func.h"
19 #include "command_func.h"
20 #include "network/network.h"
21 #include "network/network_gui.h"
22 #include "network/network_func.h"
24 #include "company_manager_face.h"
25 #include "strings_func.h"
26 #include "date_func.h"
27 #include "widgets/dropdown_type.h"
28 #include "tilehighlight_func.h"
29 #include "company_base.h"
30 #include "core/geometry_func.hpp"
31 #include "object_type.h"
34 #include "engine_base.h"
35 #include "window_func.h"
36 #include "road_func.h"
38 #include "station_func.h"
39 #include "zoom_func.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
= max(width
, GetStringBoundingBox(STR_FINANCES_TOTAL_CAPTION
).width
);
116 invalid_expenses_measured
= true;
119 width
= 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
),
273 * Window class displaying the company finances.
274 * @todo #money_width should be calculated dynamically.
276 struct CompanyFinancesWindow
: Window
{
277 Money max_money
; ///< The approximate maximum amount of money a company has had over the lifetime of this window
278 bool small
; ///< Window is toggled to 'small'.
280 CompanyFinancesWindow(WindowDesc
*desc
, CompanyID company
) : Window(desc
)
282 const Company
*c
= Company::Get(company
);
283 this->max_money
= max
<Money
>(c
->money
* 2, INT32_MAX
);
285 this->CreateNestedTree();
286 this->SetupWidgets();
287 this->FinishInitNested(company
);
289 this->owner
= (Owner
)this->window_number
;
292 virtual void SetStringParameters(int widget
) const
296 SetDParam(0, (CompanyID
)this->window_number
);
297 SetDParam(1, (CompanyID
)this->window_number
);
300 case WID_CF_MAXLOAN_VALUE
:
301 SetDParam(0, _economy
.max_loan
);
304 case WID_CF_INCREASE_LOAN
:
305 case WID_CF_REPAY_LOAN
:
306 SetDParam(0, LOAN_INTERVAL
);
311 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
313 int type
= _settings_client
.gui
.expenses_layout
;
315 case WID_CF_EXPS_CATEGORY
:
316 size
->width
= _expenses_list_types
[type
].GetCategoriesWidth();
317 size
->height
= _expenses_list_types
[type
].GetHeight();
320 case WID_CF_EXPS_PRICE1
:
321 case WID_CF_EXPS_PRICE2
:
322 case WID_CF_EXPS_PRICE3
:
323 size
->height
= _expenses_list_types
[type
].GetHeight();
326 case WID_CF_BALANCE_VALUE
:
327 case WID_CF_LOAN_VALUE
:
328 case WID_CF_TOTAL_VALUE
:
329 SetDParamMaxValue(0, this->max_money
);
330 size
->width
= max(GetStringBoundingBox(STR_FINANCES_NEGATIVE_INCOME
).width
, GetStringBoundingBox(STR_FINANCES_POSITIVE_INCOME
).width
) + padding
.width
;
333 case WID_CF_MAXLOAN_GAP
:
334 size
->height
= FONT_HEIGHT_NORMAL
;
339 virtual void DrawWidget(const Rect
&r
, int widget
) const
342 case WID_CF_EXPS_CATEGORY
:
346 case WID_CF_EXPS_PRICE1
:
347 case WID_CF_EXPS_PRICE2
:
348 case WID_CF_EXPS_PRICE3
: {
349 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
350 int age
= min(_cur_year
- c
->inaugurated_year
, 2);
351 int wid_offset
= widget
- WID_CF_EXPS_PRICE1
;
352 if (wid_offset
<= age
) {
353 DrawYearColumn(r
, _cur_year
- (age
- wid_offset
), c
->yearly_expenses
+ (age
- wid_offset
));
358 case WID_CF_BALANCE_VALUE
: {
359 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
360 SetDParam(0, c
->money
);
361 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
365 case WID_CF_LOAN_VALUE
: {
366 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
367 SetDParam(0, c
->current_loan
);
368 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
372 case WID_CF_TOTAL_VALUE
: {
373 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
374 SetDParam(0, c
->money
- c
->current_loan
);
375 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
379 case WID_CF_LOAN_LINE
:
380 GfxFillRect(r
.left
, r
.top
, r
.right
, r
.top
, PC_BLACK
);
386 * Setup the widgets in the nested tree, such that the finances window is displayed properly.
387 * @note After setup, the window must be (re-)initialized.
391 int plane
= this->small
? SZSP_NONE
: 0;
392 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_PANEL
)->SetDisplayedPlane(plane
);
393 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_MAXLOAN
)->SetDisplayedPlane(plane
);
395 CompanyID company
= (CompanyID
)this->window_number
;
396 plane
= (company
!= _local_company
) ? SZSP_NONE
: 0;
397 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_BUTTONS
)->SetDisplayedPlane(plane
);
400 virtual void OnPaint()
402 if (!this->IsShaded()) {
404 /* Check that the expenses panel height matches the height needed for the layout. */
405 int type
= _settings_client
.gui
.expenses_layout
;
406 if (_expenses_list_types
[type
].GetHeight() != this->GetWidget
<NWidgetBase
>(WID_CF_EXPS_CATEGORY
)->current_y
) {
407 this->SetupWidgets();
413 /* Check that the loan buttons are shown only when the user owns the company. */
414 CompanyID company
= (CompanyID
)this->window_number
;
415 int req_plane
= (company
!= _local_company
) ? SZSP_NONE
: 0;
416 if (req_plane
!= this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_BUTTONS
)->shown_plane
) {
417 this->SetupWidgets();
422 const Company
*c
= Company::Get(company
);
423 this->SetWidgetDisabledState(WID_CF_INCREASE_LOAN
, c
->current_loan
== _economy
.max_loan
); // Borrow button only shows when there is any more money to loan.
424 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.
430 virtual void OnClick(Point pt
, int widget
, int click_count
)
433 case WID_CF_TOGGLE_SIZE
: // toggle size
434 this->small
= !this->small
;
435 this->SetupWidgets();
436 if (this->IsShaded()) {
437 /* Finances window is not resizable, so size hints given during unshading have no effect
438 * on the changed appearance of the window. */
439 this->SetShaded(false);
445 case WID_CF_INCREASE_LOAN
: // increase loan
446 DoCommandP(0, 0, _ctrl_pressed
, CMD_INCREASE_LOAN
| CMD_MSG(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY
));
449 case WID_CF_REPAY_LOAN
: // repay loan
450 DoCommandP(0, 0, _ctrl_pressed
, CMD_DECREASE_LOAN
| CMD_MSG(STR_ERROR_CAN_T_REPAY_LOAN
));
453 case WID_CF_INFRASTRUCTURE
: // show infrastructure details
454 ShowCompanyInfrastructure((CompanyID
)this->window_number
);
459 virtual void OnHundredthTick()
461 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
462 if (c
->money
> this->max_money
) {
463 this->max_money
= max(c
->money
* 2, this->max_money
* 4);
464 this->SetupWidgets();
470 static WindowDesc
_company_finances_desc(
471 WDP_AUTO
, "company_finances", 0, 0,
472 WC_FINANCES
, WC_NONE
,
474 _nested_company_finances_widgets
, lengthof(_nested_company_finances_widgets
)
478 * Open the finances window of a company.
479 * @param company Company to show finances of.
480 * @pre is company a valid company.
482 void ShowCompanyFinances(CompanyID company
)
484 if (!Company::IsValidID(company
)) return;
485 if (BringWindowToFrontById(WC_FINANCES
, company
)) return;
487 new CompanyFinancesWindow(&_company_finances_desc
, company
);
490 /* List of colours for the livery window */
491 static const StringID _colour_dropdown
[] = {
492 STR_COLOUR_DARK_BLUE
,
493 STR_COLOUR_PALE_GREEN
,
497 STR_COLOUR_LIGHT_BLUE
,
499 STR_COLOUR_DARK_GREEN
,
510 /* Association of liveries to livery classes */
511 static const LiveryClass _livery_class
[LS_END
] = {
513 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
,
516 LC_AIRCRAFT
, LC_AIRCRAFT
, LC_AIRCRAFT
,
520 class DropDownListColourItem
: public DropDownListItem
{
522 DropDownListColourItem(int result
, bool masked
) : DropDownListItem(result
, masked
) {}
524 virtual ~DropDownListColourItem() {}
526 StringID
String() const
528 return _colour_dropdown
[this->result
];
531 uint
Height(uint width
) const
533 return max(FONT_HEIGHT_NORMAL
, ScaleGUITrad(12) + 2);
536 bool Selectable() const
541 void Draw(int left
, int right
, int top
, int bottom
, bool sel
, int bg_colour
) const
543 bool rtl
= _current_text_dir
== TD_RTL
;
544 int height
= bottom
- top
;
545 int icon_y_offset
= height
/ 2;
546 int text_y_offset
= (height
- FONT_HEIGHT_NORMAL
) / 2 + 1;
547 DrawSprite(SPR_VEH_BUS_SIDE_VIEW
, PALETTE_RECOLOUR_START
+ this->result
,
548 rtl
? right
- 2 - ScaleGUITrad(14) : left
+ ScaleGUITrad(14) + 2,
549 top
+ icon_y_offset
);
550 DrawString(rtl
? left
+ 2 : left
+ ScaleGUITrad(28) + 4,
551 rtl
? right
- ScaleGUITrad(28) - 4 : right
- 2,
552 top
+ text_y_offset
, this->String(), sel
? TC_WHITE
: TC_BLACK
);
556 /** Company livery colour scheme window. */
557 struct SelectCompanyLiveryWindow
: public Window
{
560 LiveryClass livery_class
;
565 void ShowColourDropDownMenu(uint32 widget
)
567 uint32 used_colours
= 0;
568 const Livery
*livery
;
571 /* Disallow other company colours for the primary colour */
572 if (HasBit(this->sel
, LS_DEFAULT
) && widget
== WID_SCL_PRI_COL_DROPDOWN
) {
574 FOR_ALL_COMPANIES(c
) {
575 if (c
->index
!= _local_company
) SetBit(used_colours
, c
->colour
);
579 /* Get the first selected livery to use as the default dropdown item */
580 for (scheme
= LS_BEGIN
; scheme
< LS_END
; scheme
++) {
581 if (HasBit(this->sel
, scheme
)) break;
583 if (scheme
== LS_END
) scheme
= LS_DEFAULT
;
584 livery
= &Company::Get((CompanyID
)this->window_number
)->livery
[scheme
];
586 DropDownList
*list
= new DropDownList();
587 for (uint i
= 0; i
< lengthof(_colour_dropdown
); i
++) {
588 *list
->Append() = new DropDownListColourItem(i
, HasBit(used_colours
, i
));
591 ShowDropDownList(this, list
, widget
== WID_SCL_PRI_COL_DROPDOWN
? livery
->colour1
: livery
->colour2
, widget
);
595 SelectCompanyLiveryWindow(WindowDesc
*desc
, CompanyID company
) : Window(desc
)
597 this->livery_class
= LC_OTHER
;
600 this->square
= GetSpriteSize(SPR_SQUARE
);
601 this->box
= maxdim(GetSpriteSize(SPR_BOX_CHECKED
), GetSpriteSize(SPR_BOX_EMPTY
));
602 this->line_height
= max(max(this->square
.height
, this->box
.height
), (uint
)FONT_HEIGHT_NORMAL
) + 4;
604 this->InitNested(company
);
605 this->owner
= company
;
606 this->LowerWidget(WID_SCL_CLASS_GENERAL
);
607 this->InvalidateData(1);
610 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
613 case WID_SCL_SPACER_DROPDOWN
: {
614 /* The matrix widget below needs enough room to print all the schemes. */
615 Dimension d
= {0, 0};
616 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
617 d
= maxdim(d
, GetStringBoundingBox(STR_LIVERY_DEFAULT
+ scheme
));
619 size
->width
= max(size
->width
, 5 + this->box
.width
+ d
.width
+ WD_FRAMERECT_RIGHT
);
623 case WID_SCL_MATRIX
: {
624 uint livery_height
= 0;
625 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
626 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
630 size
->height
= livery_height
* this->line_height
;
631 this->GetWidget
<NWidgetCore
>(WID_SCL_MATRIX
)->widget_data
= (livery_height
<< MAT_ROW_START
) | (1 << MAT_COL_START
);
635 case WID_SCL_SEC_COL_DROPDOWN
:
636 if (!_loaded_newgrf_features
.has_2CC
) {
642 case WID_SCL_PRI_COL_DROPDOWN
: {
643 int padding
= this->square
.width
+ NWidgetScrollbar::GetVerticalDimension().width
+ 10;
644 for (const StringID
*id
= _colour_dropdown
; id
!= endof(_colour_dropdown
); id
++) {
645 size
->width
= max(size
->width
, GetStringBoundingBox(*id
).width
+ padding
);
652 virtual void OnPaint()
654 /* Disable dropdown controls if no scheme is selected */
655 this->SetWidgetDisabledState(WID_SCL_PRI_COL_DROPDOWN
, this->sel
== 0);
656 this->SetWidgetDisabledState(WID_SCL_SEC_COL_DROPDOWN
, this->sel
== 0);
661 virtual void SetStringParameters(int widget
) const
664 case WID_SCL_PRI_COL_DROPDOWN
:
665 case WID_SCL_SEC_COL_DROPDOWN
: {
666 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
667 LiveryScheme scheme
= LS_DEFAULT
;
669 if (this->sel
!= 0) {
670 for (scheme
= LS_BEGIN
; scheme
< LS_END
; scheme
++) {
671 if (HasBit(this->sel
, scheme
)) break;
673 if (scheme
== LS_END
) scheme
= LS_DEFAULT
;
675 SetDParam(0, STR_COLOUR_DARK_BLUE
+ ((widget
== WID_SCL_PRI_COL_DROPDOWN
) ? c
->livery
[scheme
].colour1
: c
->livery
[scheme
].colour2
));
681 virtual void DrawWidget(const Rect
&r
, int widget
) const
683 if (widget
!= WID_SCL_MATRIX
) return;
685 bool rtl
= _current_text_dir
== TD_RTL
;
687 /* Horizontal coordinates of scheme name column. */
688 const NWidgetBase
*nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_SPACER_DROPDOWN
);
689 int sch_left
= nwi
->pos_x
;
690 int sch_right
= sch_left
+ nwi
->current_x
- 1;
691 /* Horizontal coordinates of first dropdown. */
692 nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_PRI_COL_DROPDOWN
);
693 int pri_left
= nwi
->pos_x
;
694 int pri_right
= pri_left
+ nwi
->current_x
- 1;
695 /* Horizontal coordinates of second dropdown. */
696 nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_SEC_COL_DROPDOWN
);
697 int sec_left
= nwi
->pos_x
;
698 int sec_right
= sec_left
+ nwi
->current_x
- 1;
700 int text_left
= (rtl
? (uint
)WD_FRAMERECT_LEFT
: (this->box
.width
+ 5));
701 int text_right
= (rtl
? (this->box
.width
+ 5) : (uint
)WD_FRAMERECT_RIGHT
);
703 int box_offs
= (this->line_height
- this->box
.height
) / 2;
704 int square_offs
= (this->line_height
- this->square
.height
) / 2 + 1;
705 int text_offs
= (this->line_height
- FONT_HEIGHT_NORMAL
) / 2 + 1;
708 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
709 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
710 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
711 bool sel
= HasBit(this->sel
, scheme
) != 0;
713 /* Optional check box + scheme name. */
714 if (scheme
!= LS_DEFAULT
) {
715 DrawSprite(c
->livery
[scheme
].in_use
? SPR_BOX_CHECKED
: SPR_BOX_EMPTY
, PAL_NONE
, (rtl
? sch_right
- (this->box
.width
+ 5) + WD_FRAMERECT_RIGHT
: sch_left
) + WD_FRAMERECT_LEFT
, y
+ box_offs
);
717 DrawString(sch_left
+ text_left
, sch_right
- text_right
, y
+ text_offs
, STR_LIVERY_DEFAULT
+ scheme
, sel
? TC_WHITE
: TC_BLACK
);
719 /* Text below the first dropdown. */
720 DrawSprite(SPR_SQUARE
, GENERAL_SPRITE_COLOUR(c
->livery
[scheme
].colour1
), (rtl
? pri_right
- (this->box
.width
+ 5) + WD_FRAMERECT_RIGHT
: pri_left
) + WD_FRAMERECT_LEFT
, y
+ square_offs
);
721 DrawString(pri_left
+ text_left
, pri_right
- text_right
, y
+ text_offs
, STR_COLOUR_DARK_BLUE
+ c
->livery
[scheme
].colour1
, sel
? TC_WHITE
: TC_GOLD
);
723 /* Text below the second dropdown. */
724 if (sec_right
> sec_left
) { // Second dropdown has non-zero size.
725 DrawSprite(SPR_SQUARE
, GENERAL_SPRITE_COLOUR(c
->livery
[scheme
].colour2
), (rtl
? sec_right
- (this->box
.width
+ 5) + WD_FRAMERECT_RIGHT
: sec_left
) + WD_FRAMERECT_LEFT
, y
+ square_offs
);
726 DrawString(sec_left
+ text_left
, sec_right
- text_right
, y
+ text_offs
, STR_COLOUR_DARK_BLUE
+ c
->livery
[scheme
].colour2
, sel
? TC_WHITE
: TC_GOLD
);
729 y
+= this->line_height
;
734 virtual void OnClick(Point pt
, int widget
, int click_count
)
737 /* Livery Class buttons */
738 case WID_SCL_CLASS_GENERAL
:
739 case WID_SCL_CLASS_RAIL
:
740 case WID_SCL_CLASS_ROAD
:
741 case WID_SCL_CLASS_SHIP
:
742 case WID_SCL_CLASS_AIRCRAFT
:
743 this->RaiseWidget(this->livery_class
+ WID_SCL_CLASS_GENERAL
);
744 this->livery_class
= (LiveryClass
)(widget
- WID_SCL_CLASS_GENERAL
);
745 this->LowerWidget(this->livery_class
+ WID_SCL_CLASS_GENERAL
);
747 /* Select the first item in the list */
749 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
750 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
751 this->sel
= 1 << scheme
;
759 case WID_SCL_PRI_COL_DROPDOWN
: // First colour dropdown
760 ShowColourDropDownMenu(WID_SCL_PRI_COL_DROPDOWN
);
763 case WID_SCL_SEC_COL_DROPDOWN
: // Second colour dropdown
764 ShowColourDropDownMenu(WID_SCL_SEC_COL_DROPDOWN
);
767 case WID_SCL_MATRIX
: {
768 const NWidgetBase
*wid
= this->GetWidget
<NWidgetBase
>(WID_SCL_MATRIX
);
769 LiveryScheme j
= (LiveryScheme
)((pt
.y
- wid
->pos_y
) / this->line_height
);
771 for (LiveryScheme scheme
= LS_BEGIN
; scheme
<= j
; scheme
++) {
772 if (_livery_class
[scheme
] != this->livery_class
|| !HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) j
++;
773 if (scheme
>= LS_END
) return;
775 if (j
>= LS_END
) return;
777 /* If clicking on the left edge, toggle using the livery */
778 if (_current_text_dir
== TD_RTL
? pt
.x
- wid
->pos_x
> wid
->current_x
- (this->box
.width
+ 5) : pt
.x
- wid
->pos_x
< (this->box
.width
+ 5)) {
779 DoCommandP(0, j
| (2 << 8), !Company::Get((CompanyID
)this->window_number
)->livery
[j
].in_use
, CMD_SET_COMPANY_COLOUR
);
783 ToggleBit(this->sel
, j
);
793 virtual void OnDropdownSelect(int widget
, int index
)
795 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
796 /* Changed colour for the selected scheme, or all visible schemes if CTRL is pressed. */
797 if (HasBit(this->sel
, scheme
) || (_ctrl_pressed
&& _livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
))) {
798 DoCommandP(0, scheme
| (widget
== WID_SCL_PRI_COL_DROPDOWN
? 0 : 256), index
, CMD_SET_COMPANY_COLOUR
);
804 * Some data on this window has become invalid.
805 * @param data Information about the changed data.
806 * @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.
808 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
810 if (!gui_scope
) return;
811 this->SetWidgetsDisabledState(true, WID_SCL_CLASS_RAIL
, WID_SCL_CLASS_ROAD
, WID_SCL_CLASS_SHIP
, WID_SCL_CLASS_AIRCRAFT
, WIDGET_LIST_END
);
813 bool current_class_valid
= this->livery_class
== LC_OTHER
;
814 if (_settings_client
.gui
.liveries
== LIT_ALL
|| (_settings_client
.gui
.liveries
== LIT_COMPANY
&& this->window_number
== _local_company
)) {
815 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
816 if (HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
817 if (_livery_class
[scheme
] == this->livery_class
) current_class_valid
= true;
818 this->EnableWidget(WID_SCL_CLASS_GENERAL
+ _livery_class
[scheme
]);
820 ClrBit(this->sel
, scheme
);
825 if (!current_class_valid
) {
827 this->OnClick(pt
, WID_SCL_CLASS_GENERAL
, 1);
828 } else if (data
== 0) {
834 static const NWidgetPart _nested_select_company_livery_widgets
[] = {
835 NWidget(NWID_HORIZONTAL
),
836 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
837 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_SCL_CAPTION
), SetDataTip(STR_LIVERY_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
839 NWidget(NWID_HORIZONTAL
),
840 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_GENERAL
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_COMPANY_GENERAL
, STR_LIVERY_GENERAL_TOOLTIP
),
841 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_RAIL
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST
, STR_LIVERY_TRAIN_TOOLTIP
),
842 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_ROAD
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRUCKLIST
, STR_LIVERY_ROAD_VEHICLE_TOOLTIP
),
843 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_SHIP
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIPLIST
, STR_LIVERY_SHIP_TOOLTIP
),
844 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_AIRCRAFT
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AIRPLANESLIST
, STR_LIVERY_AIRCRAFT_TOOLTIP
),
845 NWidget(WWT_PANEL
, COLOUR_GREY
), SetMinimalSize(90, 22), SetFill(1, 1), EndContainer(),
847 NWidget(NWID_HORIZONTAL
),
848 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_SCL_SPACER_DROPDOWN
), SetMinimalSize(150, 12), SetFill(1, 1), EndContainer(),
849 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_SCL_PRI_COL_DROPDOWN
), SetMinimalSize(125, 12), SetFill(0, 1), SetDataTip(STR_BLACK_STRING
, STR_LIVERY_PRIMARY_TOOLTIP
),
850 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_SCL_SEC_COL_DROPDOWN
), SetMinimalSize(125, 12), SetFill(0, 1),
851 SetDataTip(STR_BLACK_STRING
, STR_LIVERY_SECONDARY_TOOLTIP
),
853 NWidget(WWT_MATRIX
, COLOUR_GREY
, WID_SCL_MATRIX
), SetMinimalSize(275, 15), SetFill(1, 0), SetMatrixDataTip(1, 1, STR_LIVERY_PANEL_TOOLTIP
),
856 static WindowDesc
_select_company_livery_desc(
857 WDP_AUTO
, "company_livery", 0, 0,
858 WC_COMPANY_COLOUR
, WC_NONE
,
860 _nested_select_company_livery_widgets
, lengthof(_nested_select_company_livery_widgets
)
864 * Draws the face of a company manager's face.
865 * @param cmf the company manager's face
866 * @param colour the (background) colour of the gradient
867 * @param x x-position to draw the face
868 * @param y y-position to draw the face
870 void DrawCompanyManagerFace(CompanyManagerFace cmf
, int colour
, int x
, int y
)
872 GenderEthnicity ge
= (GenderEthnicity
)GetCompanyManagerFaceBits(cmf
, CMFV_GEN_ETHN
, GE_WM
);
874 bool has_moustache
= !HasBit(ge
, GENDER_FEMALE
) && GetCompanyManagerFaceBits(cmf
, CMFV_HAS_MOUSTACHE
, ge
) != 0;
875 bool has_tie_earring
= !HasBit(ge
, GENDER_FEMALE
) || GetCompanyManagerFaceBits(cmf
, CMFV_HAS_TIE_EARRING
, ge
) != 0;
876 bool has_glasses
= GetCompanyManagerFaceBits(cmf
, CMFV_HAS_GLASSES
, ge
) != 0;
879 /* Modify eye colour palette only if 2 or more valid values exist */
880 if (_cmf_info
[CMFV_EYE_COLOUR
].valid_values
[ge
] < 2) {
883 switch (GetCompanyManagerFaceBits(cmf
, CMFV_EYE_COLOUR
, ge
)) {
884 default: NOT_REACHED();
885 case 0: pal
= PALETTE_TO_BROWN
; break;
886 case 1: pal
= PALETTE_TO_BLUE
; break;
887 case 2: pal
= PALETTE_TO_GREEN
; break;
891 /* Draw the gradient (background) */
892 DrawSprite(SPR_GRADIENT
, GENERAL_SPRITE_COLOUR(colour
), x
, y
);
894 for (CompanyManagerFaceVariable cmfv
= CMFV_CHEEKS
; cmfv
< CMFV_END
; cmfv
++) {
896 case CMFV_MOUSTACHE
: if (!has_moustache
) continue; break;
898 case CMFV_NOSE
: if (has_moustache
) continue; break;
899 case CMFV_TIE_EARRING
: if (!has_tie_earring
) continue; break;
900 case CMFV_GLASSES
: if (!has_glasses
) continue; break;
903 DrawSprite(GetCompanyManagerFaceSprite(cmf
, cmfv
, ge
), (cmfv
== CMFV_EYEBROWS
) ? pal
: PAL_NONE
, x
, y
);
907 /** Nested widget description for the company manager face selection dialog */
908 static const NWidgetPart _nested_select_company_manager_face_widgets
[] = {
909 NWidget(NWID_HORIZONTAL
),
910 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
911 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_SCMF_CAPTION
), SetDataTip(STR_FACE_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
912 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCMF_TOGGLE_LARGE_SMALL
), SetDataTip(SPR_LARGE_SMALL_WINDOW
, STR_FACE_ADVANCED_TOOLTIP
),
914 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_SCMF_SELECT_FACE
),
915 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
916 NWidget(NWID_HORIZONTAL
), SetPIP(2, 2, 2),
917 NWidget(NWID_VERTICAL
),
918 NWidget(NWID_HORIZONTAL
),
919 NWidget(NWID_SPACER
), SetFill(1, 0),
920 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_SCMF_FACE
), SetMinimalSize(92, 119),
921 NWidget(NWID_SPACER
), SetFill(1, 0),
923 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
924 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_RANDOM_NEW_FACE
), SetFill(1, 0), SetDataTip(STR_FACE_NEW_FACE_BUTTON
, STR_FACE_NEW_FACE_TOOLTIP
),
925 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_LOADSAVE
), // Load/number/save buttons under the portrait in the advanced view.
926 NWidget(NWID_VERTICAL
),
927 NWidget(NWID_SPACER
), SetMinimalSize(0, 5), SetFill(0, 1),
928 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_LOAD
), SetFill(1, 0), SetDataTip(STR_FACE_LOAD
, STR_FACE_LOAD_TOOLTIP
),
929 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_FACECODE
), SetFill(1, 0), SetDataTip(STR_FACE_FACECODE
, STR_FACE_FACECODE_TOOLTIP
),
930 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_SAVE
), SetFill(1, 0), SetDataTip(STR_FACE_SAVE
, STR_FACE_SAVE_TOOLTIP
),
931 NWidget(NWID_SPACER
), SetMinimalSize(0, 5), SetFill(0, 1),
935 NWidget(NWID_VERTICAL
),
936 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
), SetFill(1, 0), SetDataTip(STR_FACE_ADVANCED
, STR_FACE_ADVANCED_TOOLTIP
),
937 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
938 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_MALEFEMALE
), // Simple male/female face setting.
939 NWidget(NWID_VERTICAL
),
940 NWidget(NWID_SPACER
), SetFill(0, 1),
941 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_MALE
), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON
, STR_FACE_MALE_TOOLTIP
),
942 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_FEMALE
), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON
, STR_FACE_FEMALE_TOOLTIP
),
943 NWidget(NWID_SPACER
), SetFill(0, 1),
946 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_PARTS
), // Advanced face parts setting.
947 NWidget(NWID_VERTICAL
),
948 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
949 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
950 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_MALE2
), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON
, STR_FACE_MALE_TOOLTIP
),
951 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_FEMALE2
), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON
, STR_FACE_FEMALE_TOOLTIP
),
953 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
954 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
955 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_ETHNICITY_EUR
), SetFill(1, 0), SetDataTip(STR_FACE_EUROPEAN
, STR_FACE_SELECT_EUROPEAN
),
956 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_ETHNICITY_AFR
), SetFill(1, 0), SetDataTip(STR_FACE_AFRICAN
, STR_FACE_SELECT_AFRICAN
),
958 NWidget(NWID_SPACER
), SetMinimalSize(0, 4),
959 NWidget(NWID_HORIZONTAL
),
960 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
), SetFill(1, 0),
961 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAS_MOUSTACHE_EARRING
), SetDataTip(STR_EMPTY
, STR_FACE_MOUSTACHE_EARRING_TOOLTIP
),
963 NWidget(NWID_HORIZONTAL
),
964 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAS_GLASSES_TEXT
), SetFill(1, 0),
965 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAS_GLASSES
), SetDataTip(STR_EMPTY
, STR_FACE_GLASSES_TOOLTIP
),
967 NWidget(NWID_SPACER
), SetMinimalSize(0, 2), SetFill(1, 0),
968 NWidget(NWID_HORIZONTAL
),
969 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAIR_TEXT
), SetFill(1, 0),
970 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_HAIR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_HAIR_TOOLTIP
),
971 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAIR
), SetDataTip(STR_EMPTY
, STR_FACE_HAIR_TOOLTIP
),
972 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_HAIR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_HAIR_TOOLTIP
),
974 NWidget(NWID_HORIZONTAL
),
975 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_EYEBROWS_TEXT
), SetFill(1, 0),
976 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS_L
), SetDataTip(AWV_DECREASE
, STR_FACE_EYEBROWS_TOOLTIP
),
977 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS
), SetDataTip(STR_EMPTY
, STR_FACE_EYEBROWS_TOOLTIP
),
978 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS_R
), SetDataTip(AWV_INCREASE
, STR_FACE_EYEBROWS_TOOLTIP
),
980 NWidget(NWID_HORIZONTAL
),
981 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_EYECOLOUR_TEXT
), SetFill(1, 0),
982 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_EYECOLOUR_TOOLTIP
),
983 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR
), SetDataTip(STR_EMPTY
, STR_FACE_EYECOLOUR_TOOLTIP
),
984 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_EYECOLOUR_TOOLTIP
),
986 NWidget(NWID_HORIZONTAL
),
987 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_GLASSES_TEXT
), SetFill(1, 0),
988 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_GLASSES_L
), SetDataTip(AWV_DECREASE
, STR_FACE_GLASSES_TOOLTIP_2
),
989 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_GLASSES
), SetDataTip(STR_EMPTY
, STR_FACE_GLASSES_TOOLTIP_2
),
990 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_GLASSES_R
), SetDataTip(AWV_INCREASE
, STR_FACE_GLASSES_TOOLTIP_2
),
992 NWidget(NWID_HORIZONTAL
),
993 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_NOSE_TEXT
), SetFill(1, 0),
994 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_NOSE_L
), SetDataTip(AWV_DECREASE
, STR_FACE_NOSE_TOOLTIP
),
995 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_NOSE
), SetDataTip(STR_EMPTY
, STR_FACE_NOSE_TOOLTIP
),
996 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_NOSE_R
), SetDataTip(AWV_INCREASE
, STR_FACE_NOSE_TOOLTIP
),
998 NWidget(NWID_HORIZONTAL
),
999 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_LIPS_MOUSTACHE_TEXT
), SetFill(1, 0),
1000 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE_L
), SetDataTip(AWV_DECREASE
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1001 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE
), SetDataTip(STR_EMPTY
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1002 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE_R
), SetDataTip(AWV_INCREASE
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1004 NWidget(NWID_HORIZONTAL
),
1005 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_CHIN_TEXT
), SetFill(1, 0),
1006 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_CHIN_L
), SetDataTip(AWV_DECREASE
, STR_FACE_CHIN_TOOLTIP
),
1007 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_CHIN
), SetDataTip(STR_EMPTY
, STR_FACE_CHIN_TOOLTIP
),
1008 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_CHIN_R
), SetDataTip(AWV_INCREASE
, STR_FACE_CHIN_TOOLTIP
),
1010 NWidget(NWID_HORIZONTAL
),
1011 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_JACKET_TEXT
), SetFill(1, 0),
1012 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_JACKET_L
), SetDataTip(AWV_DECREASE
, STR_FACE_JACKET_TOOLTIP
),
1013 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_JACKET
), SetDataTip(STR_EMPTY
, STR_FACE_JACKET_TOOLTIP
),
1014 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_JACKET_R
), SetDataTip(AWV_INCREASE
, STR_FACE_JACKET_TOOLTIP
),
1016 NWidget(NWID_HORIZONTAL
),
1017 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_COLLAR_TEXT
), SetFill(1, 0),
1018 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_COLLAR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_COLLAR_TOOLTIP
),
1019 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_COLLAR
), SetDataTip(STR_EMPTY
, STR_FACE_COLLAR_TOOLTIP
),
1020 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_COLLAR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_COLLAR_TOOLTIP
),
1022 NWidget(NWID_HORIZONTAL
),
1023 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_TIE_EARRING_TEXT
), SetFill(1, 0),
1024 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING_L
), SetDataTip(AWV_DECREASE
, STR_FACE_TIE_EARRING_TOOLTIP
),
1025 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING
), SetDataTip(STR_EMPTY
, STR_FACE_TIE_EARRING_TOOLTIP
),
1026 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING_R
), SetDataTip(AWV_INCREASE
, STR_FACE_TIE_EARRING_TOOLTIP
),
1028 NWidget(NWID_SPACER
), SetFill(0, 1),
1033 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1035 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1036 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_CANCEL
), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL
, STR_FACE_CANCEL_TOOLTIP
),
1037 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_ACCEPT
), SetFill(1, 0), SetDataTip(STR_BUTTON_OK
, STR_FACE_OK_TOOLTIP
),
1041 /** Management class for customizing the face of the company manager. */
1042 class SelectCompanyManagerFaceWindow
: public Window
1044 CompanyManagerFace face
; ///< company manager face bits
1045 bool advanced
; ///< advanced company manager face selection window
1047 GenderEthnicity ge
; ///< Gender and ethnicity.
1048 bool is_female
; ///< Female face.
1049 bool is_moust_male
; ///< Male face with a moustache.
1051 Dimension yesno_dim
; ///< Dimension of a yes/no button of a part in the advanced face window.
1052 Dimension number_dim
; ///< Dimension of a number widget of a part in the advanced face window.
1054 static const StringID PART_TEXTS_IS_FEMALE
[]; ///< Strings depending on #is_female, used to describe parts (2 entries for a part).
1055 static const StringID PART_TEXTS
[]; ///< Fixed strings to describe parts of the face.
1058 * Draw dynamic a label to the left of the button and a value in the button
1060 * @param widget_index index of this widget in the window
1061 * @param val the value which will be draw
1062 * @param is_bool_widget is it a bool button
1064 void DrawFaceStringLabel(byte widget_index
, uint8 val
, bool is_bool_widget
) const
1067 const NWidgetCore
*nwi_widget
= this->GetWidget
<NWidgetCore
>(widget_index
);
1068 if (!nwi_widget
->IsDisabled()) {
1069 if (is_bool_widget
) {
1070 /* if it a bool button write yes or no */
1071 str
= (val
!= 0) ? STR_FACE_YES
: STR_FACE_NO
;
1073 /* else write the value + 1 */
1074 SetDParam(0, val
+ 1);
1078 /* Draw the value/bool in white (0xC). If the button clicked adds 1px to x and y text coordinates (IsWindowWidgetLowered()). */
1079 DrawString(nwi_widget
->pos_x
+ nwi_widget
->IsLowered(), nwi_widget
->pos_x
+ nwi_widget
->current_x
- 1 - nwi_widget
->IsLowered(),
1080 nwi_widget
->pos_y
+ 1 + nwi_widget
->IsLowered(), str
, TC_WHITE
, SA_HOR_CENTER
);
1086 this->ge
= (GenderEthnicity
)GB(this->face
, _cmf_info
[CMFV_GEN_ETHN
].offset
, _cmf_info
[CMFV_GEN_ETHN
].length
); // get the gender and ethnicity
1087 this->is_female
= HasBit(this->ge
, GENDER_FEMALE
); // get the gender: 0 == male and 1 == female
1088 this->is_moust_male
= !is_female
&& GetCompanyManagerFaceBits(this->face
, CMFV_HAS_MOUSTACHE
, this->ge
) != 0; // is a male face with moustache
1092 SelectCompanyManagerFaceWindow(WindowDesc
*desc
, Window
*parent
) : Window(desc
)
1094 this->advanced
= false;
1095 this->CreateNestedTree();
1096 this->SelectDisplayPlanes(this->advanced
);
1097 this->FinishInitNested(parent
->window_number
);
1098 this->parent
= parent
;
1099 this->owner
= (Owner
)this->window_number
;
1100 this->face
= Company::Get((CompanyID
)this->window_number
)->face
;
1106 * 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.
1107 * @param advanced Display advanced face management window.
1109 void SelectDisplayPlanes(bool advanced
)
1111 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_LOADSAVE
)->SetDisplayedPlane(advanced
? 0 : SZSP_NONE
);
1112 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_PARTS
)->SetDisplayedPlane(advanced
? 0 : SZSP_NONE
);
1113 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_MALEFEMALE
)->SetDisplayedPlane(advanced
? SZSP_NONE
: 0);
1114 this->GetWidget
<NWidgetCore
>(WID_SCMF_RANDOM_NEW_FACE
)->widget_data
= advanced
? STR_FACE_RANDOM
: STR_FACE_NEW_FACE_BUTTON
;
1116 NWidgetCore
*wi
= this->GetWidget
<NWidgetCore
>(WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
);
1118 wi
->SetDataTip(STR_FACE_SIMPLE
, STR_FACE_SIMPLE_TOOLTIP
);
1120 wi
->SetDataTip(STR_FACE_ADVANCED
, STR_FACE_ADVANCED_TOOLTIP
);
1124 virtual void OnInit()
1126 /* Size of the boolean yes/no button. */
1127 Dimension yesno_dim
= maxdim(GetStringBoundingBox(STR_FACE_YES
), GetStringBoundingBox(STR_FACE_NO
));
1128 yesno_dim
.width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1129 yesno_dim
.height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1130 /* Size of the number button + arrows. */
1131 Dimension number_dim
= {0, 0};
1132 for (int val
= 1; val
<= 12; val
++) {
1134 number_dim
= maxdim(number_dim
, GetStringBoundingBox(STR_JUST_INT
));
1136 uint arrows_width
= GetSpriteSize(SPR_ARROW_LEFT
).width
+ GetSpriteSize(SPR_ARROW_RIGHT
).width
+ 2 * (WD_IMGBTN_LEFT
+ WD_IMGBTN_RIGHT
);
1137 number_dim
.width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
+ arrows_width
;
1138 number_dim
.height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1139 /* Compute width of both buttons. */
1140 yesno_dim
.width
= max(yesno_dim
.width
, number_dim
.width
);
1141 number_dim
.width
= yesno_dim
.width
- arrows_width
;
1143 this->yesno_dim
= yesno_dim
;
1144 this->number_dim
= number_dim
;
1147 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1150 case WID_SCMF_FACE
: {
1151 Dimension face_size
= GetSpriteSize(SPR_GRADIENT
);
1152 size
->width
= max(size
->width
, face_size
.width
);
1153 size
->height
= max(size
->height
, face_size
.height
);
1157 case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
:
1158 case WID_SCMF_TIE_EARRING_TEXT
: {
1159 int offset
= (widget
- WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
) * 2;
1160 *size
= maxdim(GetStringBoundingBox(PART_TEXTS_IS_FEMALE
[offset
]), GetStringBoundingBox(PART_TEXTS_IS_FEMALE
[offset
+ 1]));
1161 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1162 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1166 case WID_SCMF_LIPS_MOUSTACHE_TEXT
:
1167 *size
= maxdim(GetStringBoundingBox(STR_FACE_LIPS
), GetStringBoundingBox(STR_FACE_MOUSTACHE
));
1168 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1169 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1172 case WID_SCMF_HAS_GLASSES_TEXT
:
1173 case WID_SCMF_HAIR_TEXT
:
1174 case WID_SCMF_EYEBROWS_TEXT
:
1175 case WID_SCMF_EYECOLOUR_TEXT
:
1176 case WID_SCMF_GLASSES_TEXT
:
1177 case WID_SCMF_NOSE_TEXT
:
1178 case WID_SCMF_CHIN_TEXT
:
1179 case WID_SCMF_JACKET_TEXT
:
1180 case WID_SCMF_COLLAR_TEXT
:
1181 *size
= GetStringBoundingBox(PART_TEXTS
[widget
- WID_SCMF_HAS_GLASSES_TEXT
]);
1182 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1183 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1186 case WID_SCMF_HAS_MOUSTACHE_EARRING
:
1187 case WID_SCMF_HAS_GLASSES
:
1188 *size
= this->yesno_dim
;
1191 case WID_SCMF_EYECOLOUR
:
1193 case WID_SCMF_EYEBROWS
:
1194 case WID_SCMF_LIPS_MOUSTACHE
:
1197 case WID_SCMF_JACKET
:
1198 case WID_SCMF_COLLAR
:
1199 case WID_SCMF_TIE_EARRING
:
1200 case WID_SCMF_GLASSES
:
1201 *size
= this->number_dim
;
1206 virtual void OnPaint()
1208 /* lower the non-selected gender button */
1209 this->SetWidgetsLoweredState(!this->is_female
, WID_SCMF_MALE
, WID_SCMF_MALE2
, WIDGET_LIST_END
);
1210 this->SetWidgetsLoweredState( this->is_female
, WID_SCMF_FEMALE
, WID_SCMF_FEMALE2
, WIDGET_LIST_END
);
1212 /* advanced company manager face selection window */
1214 /* lower the non-selected ethnicity button */
1215 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_EUR
, !HasBit(this->ge
, ETHNICITY_BLACK
));
1216 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_AFR
, HasBit(this->ge
, ETHNICITY_BLACK
));
1219 /* Disable dynamically the widgets which CompanyManagerFaceVariable has less than 2 options
1220 * (or in other words you haven't any choice).
1221 * If the widgets depend on a HAS-variable and this is false the widgets will be disabled, too. */
1223 /* Eye colour buttons */
1224 this->SetWidgetsDisabledState(_cmf_info
[CMFV_EYE_COLOUR
].valid_values
[this->ge
] < 2,
1225 WID_SCMF_EYECOLOUR
, WID_SCMF_EYECOLOUR_L
, WID_SCMF_EYECOLOUR_R
, WIDGET_LIST_END
);
1228 this->SetWidgetsDisabledState(_cmf_info
[CMFV_CHIN
].valid_values
[this->ge
] < 2,
1229 WID_SCMF_CHIN
, WID_SCMF_CHIN_L
, WID_SCMF_CHIN_R
, WIDGET_LIST_END
);
1231 /* Eyebrows buttons */
1232 this->SetWidgetsDisabledState(_cmf_info
[CMFV_EYEBROWS
].valid_values
[this->ge
] < 2,
1233 WID_SCMF_EYEBROWS
, WID_SCMF_EYEBROWS_L
, WID_SCMF_EYEBROWS_R
, WIDGET_LIST_END
);
1235 /* Lips or (if it a male face with a moustache) moustache buttons */
1236 this->SetWidgetsDisabledState(_cmf_info
[this->is_moust_male
? CMFV_MOUSTACHE
: CMFV_LIPS
].valid_values
[this->ge
] < 2,
1237 WID_SCMF_LIPS_MOUSTACHE
, WID_SCMF_LIPS_MOUSTACHE_L
, WID_SCMF_LIPS_MOUSTACHE_R
, WIDGET_LIST_END
);
1239 /* Nose buttons | male faces with moustache haven't any nose options */
1240 this->SetWidgetsDisabledState(_cmf_info
[CMFV_NOSE
].valid_values
[this->ge
] < 2 || this->is_moust_male
,
1241 WID_SCMF_NOSE
, WID_SCMF_NOSE_L
, WID_SCMF_NOSE_R
, WIDGET_LIST_END
);
1244 this->SetWidgetsDisabledState(_cmf_info
[CMFV_HAIR
].valid_values
[this->ge
] < 2,
1245 WID_SCMF_HAIR
, WID_SCMF_HAIR_L
, WID_SCMF_HAIR_R
, WIDGET_LIST_END
);
1247 /* Jacket buttons */
1248 this->SetWidgetsDisabledState(_cmf_info
[CMFV_JACKET
].valid_values
[this->ge
] < 2,
1249 WID_SCMF_JACKET
, WID_SCMF_JACKET_L
, WID_SCMF_JACKET_R
, WIDGET_LIST_END
);
1251 /* Collar buttons */
1252 this->SetWidgetsDisabledState(_cmf_info
[CMFV_COLLAR
].valid_values
[this->ge
] < 2,
1253 WID_SCMF_COLLAR
, WID_SCMF_COLLAR_L
, WID_SCMF_COLLAR_R
, WIDGET_LIST_END
);
1255 /* Tie/earring buttons | female faces without earring haven't any earring options */
1256 this->SetWidgetsDisabledState(_cmf_info
[CMFV_TIE_EARRING
].valid_values
[this->ge
] < 2 ||
1257 (this->is_female
&& GetCompanyManagerFaceBits(this->face
, CMFV_HAS_TIE_EARRING
, this->ge
) == 0),
1258 WID_SCMF_TIE_EARRING
, WID_SCMF_TIE_EARRING_L
, WID_SCMF_TIE_EARRING_R
, WIDGET_LIST_END
);
1260 /* Glasses buttons | faces without glasses haven't any glasses options */
1261 this->SetWidgetsDisabledState(_cmf_info
[CMFV_GLASSES
].valid_values
[this->ge
] < 2 || GetCompanyManagerFaceBits(this->face
, CMFV_HAS_GLASSES
, this->ge
) == 0,
1262 WID_SCMF_GLASSES
, WID_SCMF_GLASSES_L
, WID_SCMF_GLASSES_R
, WIDGET_LIST_END
);
1264 this->DrawWidgets();
1267 virtual void DrawWidget(const Rect
&r
, int widget
) const
1270 case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
:
1271 case WID_SCMF_TIE_EARRING_TEXT
: {
1272 StringID str
= PART_TEXTS_IS_FEMALE
[(widget
- WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
) * 2 + this->is_female
];
1273 DrawString(r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, r
.top
+ WD_FRAMERECT_TOP
, str
, TC_GOLD
, SA_RIGHT
);
1277 case WID_SCMF_LIPS_MOUSTACHE_TEXT
:
1278 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
);
1281 case WID_SCMF_HAS_GLASSES_TEXT
:
1282 case WID_SCMF_HAIR_TEXT
:
1283 case WID_SCMF_EYEBROWS_TEXT
:
1284 case WID_SCMF_EYECOLOUR_TEXT
:
1285 case WID_SCMF_GLASSES_TEXT
:
1286 case WID_SCMF_NOSE_TEXT
:
1287 case WID_SCMF_CHIN_TEXT
:
1288 case WID_SCMF_JACKET_TEXT
:
1289 case WID_SCMF_COLLAR_TEXT
:
1290 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
);
1294 case WID_SCMF_HAS_MOUSTACHE_EARRING
:
1295 if (this->is_female
) { // Only for female faces
1296 this->DrawFaceStringLabel(WID_SCMF_HAS_MOUSTACHE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_TIE_EARRING
, this->ge
), true);
1297 } else { // Only for male faces
1298 this->DrawFaceStringLabel(WID_SCMF_HAS_MOUSTACHE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_MOUSTACHE
, this->ge
), true);
1302 case WID_SCMF_TIE_EARRING
:
1303 this->DrawFaceStringLabel(WID_SCMF_TIE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_TIE_EARRING
, this->ge
), false);
1306 case WID_SCMF_LIPS_MOUSTACHE
:
1307 if (this->is_moust_male
) { // Only for male faces with moustache
1308 this->DrawFaceStringLabel(WID_SCMF_LIPS_MOUSTACHE
, GetCompanyManagerFaceBits(this->face
, CMFV_MOUSTACHE
, this->ge
), false);
1309 } else { // Only for female faces or male faces without moustache
1310 this->DrawFaceStringLabel(WID_SCMF_LIPS_MOUSTACHE
, GetCompanyManagerFaceBits(this->face
, CMFV_LIPS
, this->ge
), false);
1314 case WID_SCMF_HAS_GLASSES
:
1315 this->DrawFaceStringLabel(WID_SCMF_HAS_GLASSES
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_GLASSES
, this->ge
), true );
1319 this->DrawFaceStringLabel(WID_SCMF_HAIR
, GetCompanyManagerFaceBits(this->face
, CMFV_HAIR
, this->ge
), false);
1322 case WID_SCMF_EYEBROWS
:
1323 this->DrawFaceStringLabel(WID_SCMF_EYEBROWS
, GetCompanyManagerFaceBits(this->face
, CMFV_EYEBROWS
, this->ge
), false);
1326 case WID_SCMF_EYECOLOUR
:
1327 this->DrawFaceStringLabel(WID_SCMF_EYECOLOUR
, GetCompanyManagerFaceBits(this->face
, CMFV_EYE_COLOUR
, this->ge
), false);
1330 case WID_SCMF_GLASSES
:
1331 this->DrawFaceStringLabel(WID_SCMF_GLASSES
, GetCompanyManagerFaceBits(this->face
, CMFV_GLASSES
, this->ge
), false);
1335 this->DrawFaceStringLabel(WID_SCMF_NOSE
, GetCompanyManagerFaceBits(this->face
, CMFV_NOSE
, this->ge
), false);
1339 this->DrawFaceStringLabel(WID_SCMF_CHIN
, GetCompanyManagerFaceBits(this->face
, CMFV_CHIN
, this->ge
), false);
1342 case WID_SCMF_JACKET
:
1343 this->DrawFaceStringLabel(WID_SCMF_JACKET
, GetCompanyManagerFaceBits(this->face
, CMFV_JACKET
, this->ge
), false);
1346 case WID_SCMF_COLLAR
:
1347 this->DrawFaceStringLabel(WID_SCMF_COLLAR
, GetCompanyManagerFaceBits(this->face
, CMFV_COLLAR
, this->ge
), false);
1351 DrawCompanyManagerFace(this->face
, Company::Get((CompanyID
)this->window_number
)->colour
, r
.left
, r
.top
);
1356 virtual void OnClick(Point pt
, int widget
, int click_count
)
1359 /* Toggle size, advanced/simple face selection */
1360 case WID_SCMF_TOGGLE_LARGE_SMALL
:
1361 case WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
:
1362 this->advanced
= !this->advanced
;
1363 this->SelectDisplayPlanes(this->advanced
);
1368 case WID_SCMF_ACCEPT
:
1369 DoCommandP(0, 0, this->face
, CMD_SET_COMPANY_MANAGER_FACE
);
1373 case WID_SCMF_CANCEL
:
1379 this->face
= _company_manager_face
;
1380 ScaleAllCompanyManagerFaceBits(this->face
);
1381 ShowErrorMessage(STR_FACE_LOAD_DONE
, INVALID_STRING_ID
, WL_INFO
);
1386 /* 'Company manager face number' button, view and/or set company manager face number */
1387 case WID_SCMF_FACECODE
:
1388 SetDParam(0, this->face
);
1389 ShowQueryString(STR_JUST_INT
, STR_FACE_FACECODE_CAPTION
, 10 + 1, this, CS_NUMERAL
, QSF_NONE
);
1394 _company_manager_face
= this->face
;
1395 ShowErrorMessage(STR_FACE_SAVE_DONE
, INVALID_STRING_ID
, WL_INFO
);
1398 /* Toggle gender (male/female) button */
1400 case WID_SCMF_FEMALE
:
1401 case WID_SCMF_MALE2
:
1402 case WID_SCMF_FEMALE2
:
1403 SetCompanyManagerFaceBits(this->face
, CMFV_GENDER
, this->ge
, (widget
== WID_SCMF_FEMALE
|| widget
== WID_SCMF_FEMALE2
));
1404 ScaleAllCompanyManagerFaceBits(this->face
);
1409 /* Randomize face button */
1410 case WID_SCMF_RANDOM_NEW_FACE
:
1411 RandomCompanyManagerFaceBits(this->face
, this->ge
, this->advanced
);
1416 /* Toggle ethnicity (european/african) button */
1417 case WID_SCMF_ETHNICITY_EUR
:
1418 case WID_SCMF_ETHNICITY_AFR
:
1419 SetCompanyManagerFaceBits(this->face
, CMFV_ETHNICITY
, this->ge
, widget
- WID_SCMF_ETHNICITY_EUR
);
1420 ScaleAllCompanyManagerFaceBits(this->face
);
1426 /* Here all buttons from WID_SCMF_HAS_MOUSTACHE_EARRING to WID_SCMF_GLASSES_R are handled.
1427 * First it checks which CompanyManagerFaceVariable is being changed, and then either
1428 * a: invert the value for boolean variables, or
1429 * b: it checks inside of IncreaseCompanyManagerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
1430 if (widget
>= WID_SCMF_HAS_MOUSTACHE_EARRING
&& widget
<= WID_SCMF_GLASSES_R
) {
1431 CompanyManagerFaceVariable cmfv
; // which CompanyManagerFaceVariable shall be edited
1433 if (widget
< WID_SCMF_EYECOLOUR_L
) { // Bool buttons
1434 switch (widget
- WID_SCMF_HAS_MOUSTACHE_EARRING
) {
1435 default: NOT_REACHED();
1436 case 0: cmfv
= this->is_female
? CMFV_HAS_TIE_EARRING
: CMFV_HAS_MOUSTACHE
; break; // Has earring/moustache button
1437 case 1: cmfv
= CMFV_HAS_GLASSES
; break; // Has glasses button
1439 SetCompanyManagerFaceBits(this->face
, cmfv
, this->ge
, !GetCompanyManagerFaceBits(this->face
, cmfv
, this->ge
));
1440 ScaleAllCompanyManagerFaceBits(this->face
);
1441 } else { // Value buttons
1442 switch ((widget
- WID_SCMF_EYECOLOUR_L
) / 3) {
1443 default: NOT_REACHED();
1444 case 0: cmfv
= CMFV_EYE_COLOUR
; break; // Eye colour buttons
1445 case 1: cmfv
= CMFV_CHIN
; break; // Chin buttons
1446 case 2: cmfv
= CMFV_EYEBROWS
; break; // Eyebrows buttons
1447 case 3: cmfv
= this->is_moust_male
? CMFV_MOUSTACHE
: CMFV_LIPS
; break; // Moustache or lips buttons
1448 case 4: cmfv
= CMFV_NOSE
; break; // Nose buttons
1449 case 5: cmfv
= CMFV_HAIR
; break; // Hair buttons
1450 case 6: cmfv
= CMFV_JACKET
; break; // Jacket buttons
1451 case 7: cmfv
= CMFV_COLLAR
; break; // Collar buttons
1452 case 8: cmfv
= CMFV_TIE_EARRING
; break; // Tie/earring buttons
1453 case 9: cmfv
= CMFV_GLASSES
; break; // Glasses buttons
1455 /* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
1456 IncreaseCompanyManagerFaceBits(this->face
, cmfv
, this->ge
, (((widget
- WID_SCMF_EYECOLOUR_L
) % 3) != 0) ? 1 : -1);
1465 virtual void OnQueryTextFinished(char *str
)
1467 if (str
== nullptr) return;
1468 /* Set a new company manager face number */
1469 if (!StrEmpty(str
)) {
1470 this->face
= strtoul(str
, nullptr, 10);
1471 ScaleAllCompanyManagerFaceBits(this->face
);
1472 ShowErrorMessage(STR_FACE_FACECODE_SET
, INVALID_STRING_ID
, WL_INFO
);
1476 ShowErrorMessage(STR_FACE_FACECODE_ERR
, INVALID_STRING_ID
, WL_INFO
);
1481 /** Both text values of parts of the face that depend on the #is_female boolean value. */
1482 const StringID
SelectCompanyManagerFaceWindow::PART_TEXTS_IS_FEMALE
[] = {
1483 STR_FACE_MOUSTACHE
, STR_FACE_EARRING
, // WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
1484 STR_FACE_TIE
, STR_FACE_EARRING
, // WID_SCMF_TIE_EARRING_TEXT
1487 /** Textual names for parts of the face. */
1488 const StringID
SelectCompanyManagerFaceWindow::PART_TEXTS
[] = {
1489 STR_FACE_GLASSES
, // WID_SCMF_HAS_GLASSES_TEXT
1490 STR_FACE_HAIR
, // WID_SCMF_HAIR_TEXT
1491 STR_FACE_EYEBROWS
, // WID_SCMF_EYEBROWS_TEXT
1492 STR_FACE_EYECOLOUR
, // WID_SCMF_EYECOLOUR_TEXT
1493 STR_FACE_GLASSES
, // WID_SCMF_GLASSES_TEXT
1494 STR_FACE_NOSE
, // WID_SCMF_NOSE_TEXT
1495 STR_FACE_CHIN
, // WID_SCMF_CHIN_TEXT
1496 STR_FACE_JACKET
, // WID_SCMF_JACKET_TEXT
1497 STR_FACE_COLLAR
, // WID_SCMF_COLLAR_TEXT
1500 /** Company manager face selection window description */
1501 static WindowDesc
_select_company_manager_face_desc(
1502 WDP_AUTO
, "company_face", 0, 0,
1503 WC_COMPANY_MANAGER_FACE
, WC_NONE
,
1505 _nested_select_company_manager_face_widgets
, lengthof(_nested_select_company_manager_face_widgets
)
1509 * Open the simple/advanced company manager face selection window
1511 * @param parent the parent company window
1512 * @param adv simple or advanced face selection window
1513 * @param top previous top position of the window
1514 * @param left previous left position of the window
1516 static void DoSelectCompanyManagerFace(Window
*parent
)
1518 if (!Company::IsValidID((CompanyID
)parent
->window_number
)) return;
1520 if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE
, parent
->window_number
)) return;
1521 new SelectCompanyManagerFaceWindow(&_select_company_manager_face_desc
, parent
);
1524 static const NWidgetPart _nested_company_infrastructure_widgets
[] = {
1525 NWidget(NWID_HORIZONTAL
),
1526 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1527 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_CI_CAPTION
), SetDataTip(STR_COMPANY_INFRASTRUCTURE_VIEW_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1528 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1529 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1531 NWidget(WWT_PANEL
, COLOUR_GREY
),
1532 NWidget(NWID_VERTICAL
), SetPIP(WD_FRAMERECT_TOP
, 4, WD_FRAMETEXT_BOTTOM
),
1533 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1534 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_RAIL_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1535 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_RAIL_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1537 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1538 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_ROAD_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1539 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_ROAD_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1541 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1542 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TRAM_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1543 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TRAM_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1545 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1546 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_WATER_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1547 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_WATER_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1549 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1550 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_STATION_DESC
), SetMinimalTextLines(3, 0), SetFill(1, 0),
1551 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_STATION_COUNT
), SetMinimalTextLines(3, 0), SetFill(0, 1),
1553 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1554 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TOTAL_DESC
), SetFill(1, 0),
1555 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TOTAL
), SetFill(0, 1),
1562 * Window with detailed information about the company's infrastructure.
1564 struct CompanyInfrastructureWindow
: Window
1566 RailTypes railtypes
; ///< Valid railtypes.
1567 RoadSubTypes roadtypes
[ROADTYPE_END
]; ///< Valid roadtypes.
1569 uint total_width
; ///< String width of the total cost line.
1571 CompanyInfrastructureWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
1573 this->UpdateRailRoadTypes();
1575 this->InitNested(window_number
);
1576 this->owner
= (Owner
)this->window_number
;
1579 void UpdateRailRoadTypes()
1581 this->railtypes
= RAILTYPES_NONE
;
1582 this->roadtypes
[ROADTYPE_ROAD
] = ROADSUBTYPES_NORMAL
; // Road is always available. // TODO
1583 this->roadtypes
[ROADTYPE_TRAM
] = ROADSUBTYPES_NONE
;
1585 /* Find the used railtypes. */
1587 FOR_ALL_ENGINES_OF_TYPE(e
, VEH_TRAIN
) {
1588 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
1590 this->railtypes
|= GetRailTypeInfo(e
->u
.rail
.railtype
)->introduces_railtypes
;
1593 /* Get the date introduced railtypes as well. */
1594 this->railtypes
= AddDateIntroducedRailTypes(this->railtypes
, MAX_DAY
);
1596 /* Find the used roadtypes. */
1597 FOR_ALL_ENGINES_OF_TYPE(e
, VEH_ROAD
) {
1598 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
1600 RoadTypeIdentifier rtid
= e
->GetRoadType();
1601 this->roadtypes
[rtid
.basetype
] |= GetRoadTypeInfo(rtid
)->introduces_roadtypes
;
1604 /* Get the date introduced roadtypes as well. */
1605 this->roadtypes
[ROADTYPE_ROAD
] = AddDateIntroducedRoadTypes(ROADTYPE_ROAD
, this->roadtypes
[ROADTYPE_ROAD
], MAX_DAY
);
1606 this->roadtypes
[ROADTYPE_TRAM
] = AddDateIntroducedRoadTypes(ROADTYPE_TRAM
, this->roadtypes
[ROADTYPE_TRAM
], MAX_DAY
);
1609 /** Get total infrastructure maintenance cost. */
1610 Money
GetTotalMaintenanceCost() const
1612 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
1615 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
1616 for (RailType rt
= RAILTYPE_BEGIN
; rt
!= RAILTYPE_END
; rt
++) {
1617 if (HasBit(this->railtypes
, rt
)) total
+= RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
);
1619 total
+= SignalMaintenanceCost(c
->infrastructure
.signal
);
1621 uint32 road_total
= c
->infrastructure
.GetRoadTotal(ROADTYPE_ROAD
);
1622 uint32 tram_total
= c
->infrastructure
.GetRoadTotal(ROADTYPE_TRAM
);
1623 for (RoadSubType rst
= ROADSUBTYPE_BEGIN
; rst
< ROADSUBTYPE_END
; rst
++) {
1624 if (HasBit(this->roadtypes
[ROADTYPE_ROAD
], rst
)) total
+= RoadMaintenanceCost(RoadTypeIdentifier(ROADTYPE_ROAD
, rst
), c
->infrastructure
.road
[ROADTYPE_ROAD
][rst
], road_total
);
1625 if (HasBit(this->roadtypes
[ROADTYPE_TRAM
], rst
)) total
+= RoadMaintenanceCost(RoadTypeIdentifier(ROADTYPE_TRAM
, rst
), c
->infrastructure
.road
[ROADTYPE_TRAM
][rst
], tram_total
);
1628 total
+= CanalMaintenanceCost(c
->infrastructure
.water
);
1629 total
+= StationMaintenanceCost(c
->infrastructure
.station
);
1630 total
+= AirportMaintenanceCost(c
->index
);
1635 virtual void SetStringParameters(int widget
) const
1638 case WID_CI_CAPTION
:
1639 SetDParam(0, (CompanyID
)this->window_number
);
1644 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1646 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
1649 case WID_CI_RAIL_DESC
: {
1652 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT
).width
);
1654 for (RailType rt
= RAILTYPE_BEGIN
; rt
< RAILTYPE_END
; rt
++) {
1655 if (HasBit(this->railtypes
, rt
)) {
1657 SetDParam(0, GetRailTypeInfo(rt
)->strings
.name
);
1658 size
->width
= max(size
->width
, GetStringBoundingBox(STR_WHITE_STRING
).width
+ WD_FRAMERECT_LEFT
);
1661 if (this->railtypes
!= RAILTYPES_NONE
) {
1663 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS
).width
+ WD_FRAMERECT_LEFT
);
1666 size
->height
= max(size
->height
, lines
* FONT_HEIGHT_NORMAL
);
1670 case WID_CI_ROAD_DESC
:
1671 case WID_CI_TRAM_DESC
: {
1674 size
->width
= max(size
->width
, GetStringBoundingBox(widget
== WID_CI_ROAD_DESC
? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT
: STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT
).width
);
1676 RoadTypeIdentifier rtid
;
1677 FOR_ALL_SORTED_ROADTYPES(rtid
, widget
== WID_CI_ROAD_DESC
? ROADTYPE_ROAD
: ROADTYPE_TRAM
) {
1678 if (HasBit(this->roadtypes
[rtid
.basetype
], rtid
.subtype
)) {
1680 SetDParam(0, GetRoadTypeInfo(rtid
)->strings
.name
);
1681 size
->width
= max(size
->width
, GetStringBoundingBox(STR_WHITE_STRING
).width
+ WD_FRAMERECT_LEFT
);
1685 size
->height
= max(size
->height
, lines
* FONT_HEIGHT_NORMAL
);
1689 case WID_CI_WATER_DESC
:
1690 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT
).width
);
1691 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS
).width
+ WD_FRAMERECT_LEFT
);
1694 case WID_CI_STATION_DESC
:
1695 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT
).width
);
1696 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS
).width
+ WD_FRAMERECT_LEFT
);
1697 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS
).width
+ WD_FRAMERECT_LEFT
);
1700 case WID_CI_RAIL_COUNT
:
1701 case WID_CI_ROAD_COUNT
:
1702 case WID_CI_TRAM_COUNT
:
1703 case WID_CI_WATER_COUNT
:
1704 case WID_CI_STATION_COUNT
:
1705 case WID_CI_TOTAL
: {
1706 /* Find the maximum count that is displayed. */
1707 uint32 max_val
= 1000; // Some random number to reserve enough space.
1708 Money max_cost
= 10000; // Some random number to reserve enough space.
1709 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
1710 for (RailType rt
= RAILTYPE_BEGIN
; rt
< RAILTYPE_END
; rt
++) {
1711 max_val
= max(max_val
, c
->infrastructure
.rail
[rt
]);
1712 max_cost
= max(max_cost
, RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
));
1714 max_val
= max(max_val
, c
->infrastructure
.signal
);
1715 max_cost
= max(max_cost
, SignalMaintenanceCost(c
->infrastructure
.signal
));
1716 for (RoadType rt
= ROADTYPE_BEGIN
; rt
< ROADTYPE_END
; rt
++) {
1717 uint32 road_total
= c
->infrastructure
.GetRoadTotal(rt
);
1718 for (RoadSubType rst
= ROADSUBTYPE_BEGIN
; rst
< ROADSUBTYPE_END
; rst
++) {
1719 max_val
= max(max_val
, c
->infrastructure
.road
[rt
][rst
]);
1720 max_cost
= max(max_cost
, RoadMaintenanceCost(RoadTypeIdentifier(rt
, rst
), c
->infrastructure
.road
[rt
][rst
], road_total
));
1723 max_val
= max(max_val
, c
->infrastructure
.water
);
1724 max_cost
= max(max_cost
, CanalMaintenanceCost(c
->infrastructure
.water
));
1725 max_val
= max(max_val
, c
->infrastructure
.station
);
1726 max_cost
= max(max_cost
, StationMaintenanceCost(c
->infrastructure
.station
));
1727 max_val
= max(max_val
, c
->infrastructure
.airport
);
1728 max_cost
= max(max_cost
, AirportMaintenanceCost(c
->index
));
1730 SetDParamMaxValue(0, max_val
);
1731 uint count_width
= GetStringBoundingBox(STR_WHITE_COMMA
).width
+ 20; // Reserve some wiggle room
1733 if (_settings_game
.economy
.infrastructure_maintenance
) {
1734 SetDParamMaxValue(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
1735 this->total_width
= GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
).width
+ 20;
1736 size
->width
= max(size
->width
, this->total_width
);
1738 SetDParamMaxValue(0, max_cost
* 12); // Convert to per year
1739 count_width
+= max(this->total_width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
).width
);
1742 size
->width
= max(size
->width
, count_width
);
1744 /* Set height of the total line. */
1745 if (widget
== WID_CI_TOTAL
) {
1746 size
->height
= _settings_game
.economy
.infrastructure_maintenance
? max(size
->height
, EXP_LINESPACE
+ FONT_HEIGHT_NORMAL
) : 0;
1754 * Helper for drawing the counts line.
1755 * @param r The bounds to draw in.
1756 * @param y The y position to draw at.
1757 * @param count The count to show on this line.
1758 * @param monthly_cost The monthly costs.
1760 void DrawCountLine(const Rect
&r
, int &y
, int count
, Money monthly_cost
) const
1762 SetDParam(0, count
);
1763 DrawString(r
.left
, r
.right
, y
+= FONT_HEIGHT_NORMAL
, STR_WHITE_COMMA
, TC_FROMSTRING
, SA_RIGHT
);
1765 if (_settings_game
.economy
.infrastructure_maintenance
) {
1766 SetDParam(0, monthly_cost
* 12); // Convert to per year
1767 int left
= _current_text_dir
== TD_RTL
? r
.right
- this->total_width
: r
.left
;
1768 DrawString(left
, left
+ this->total_width
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
, TC_FROMSTRING
, SA_RIGHT
);
1772 virtual void DrawWidget(const Rect
&r
, int widget
) const
1774 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
1777 int offs_left
= _current_text_dir
== TD_LTR
? WD_FRAMERECT_LEFT
: 0;
1778 int offs_right
= _current_text_dir
== TD_LTR
? 0 : WD_FRAMERECT_LEFT
;
1781 case WID_CI_RAIL_DESC
:
1782 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT
);
1784 if (this->railtypes
!= RAILTYPES_NONE
) {
1785 /* Draw name of each valid railtype. */
1787 FOR_ALL_SORTED_RAILTYPES(rt
) {
1788 if (HasBit(this->railtypes
, rt
)) {
1789 SetDParam(0, GetRailTypeInfo(rt
)->strings
.name
);
1790 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_WHITE_STRING
);
1793 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS
);
1795 /* No valid railtype. */
1796 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
);
1801 case WID_CI_RAIL_COUNT
: {
1802 /* Draw infrastructure count for each valid railtype. */
1803 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
1805 FOR_ALL_SORTED_RAILTYPES(rt
) {
1806 if (HasBit(this->railtypes
, rt
)) {
1807 this->DrawCountLine(r
, y
, c
->infrastructure
.rail
[rt
], RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
));
1810 if (this->railtypes
!= RAILTYPES_NONE
) {
1811 this->DrawCountLine(r
, y
, c
->infrastructure
.signal
, SignalMaintenanceCost(c
->infrastructure
.signal
));
1816 case WID_CI_ROAD_DESC
:
1817 case WID_CI_TRAM_DESC
: {
1818 DrawString(r
.left
, r
.right
, y
, widget
== WID_CI_ROAD_DESC
? STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT
: STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT
);
1820 /* Draw name of each valid roadtype. */
1821 RoadTypeIdentifier rtid
;
1822 FOR_ALL_SORTED_ROADTYPES(rtid
, widget
== WID_CI_ROAD_DESC
? ROADTYPE_ROAD
: ROADTYPE_TRAM
) {
1823 if (HasBit(this->roadtypes
[rtid
.basetype
], rtid
.subtype
)) {
1824 SetDParam(0, GetRoadTypeInfo(rtid
)->strings
.name
);
1825 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_WHITE_STRING
);
1832 case WID_CI_ROAD_COUNT
:
1833 case WID_CI_TRAM_COUNT
: {
1834 RoadType rt
= widget
== WID_CI_ROAD_COUNT
? ROADTYPE_ROAD
: ROADTYPE_TRAM
;
1835 uint32 road_total
= c
->infrastructure
.GetRoadTotal(rt
);
1836 RoadTypeIdentifier rtid
;
1837 FOR_ALL_SORTED_ROADTYPES(rtid
, rt
) {
1838 if (HasBit(this->roadtypes
[rtid
.basetype
], rtid
.subtype
)) {
1839 this->DrawCountLine(r
, y
, c
->infrastructure
.road
[rtid
.basetype
][rtid
.subtype
], RoadMaintenanceCost(rtid
, c
->infrastructure
.road
[rtid
.basetype
][rtid
.subtype
], road_total
));
1845 case WID_CI_WATER_DESC
:
1846 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT
);
1847 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS
);
1850 case WID_CI_WATER_COUNT
:
1851 this->DrawCountLine(r
, y
, c
->infrastructure
.water
, CanalMaintenanceCost(c
->infrastructure
.water
));
1855 if (_settings_game
.economy
.infrastructure_maintenance
) {
1856 int left
= _current_text_dir
== TD_RTL
? r
.right
- this->total_width
: r
.left
;
1857 GfxFillRect(left
, y
, left
+ this->total_width
, y
, PC_WHITE
);
1859 SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
1860 DrawString(left
, left
+ this->total_width
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
, TC_FROMSTRING
, SA_RIGHT
);
1864 case WID_CI_STATION_DESC
:
1865 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT
);
1866 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS
);
1867 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS
);
1870 case WID_CI_STATION_COUNT
:
1871 this->DrawCountLine(r
, y
, c
->infrastructure
.station
, StationMaintenanceCost(c
->infrastructure
.station
));
1872 this->DrawCountLine(r
, y
, c
->infrastructure
.airport
, AirportMaintenanceCost(c
->index
));
1878 * Some data on this window has become invalid.
1879 * @param data Information about the changed data.
1880 * @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.
1882 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
1884 if (!gui_scope
) return;
1886 this->UpdateRailRoadTypes();
1891 static WindowDesc
_company_infrastructure_desc(
1892 WDP_AUTO
, "company_infrastructure", 0, 0,
1893 WC_COMPANY_INFRASTRUCTURE
, WC_NONE
,
1895 _nested_company_infrastructure_widgets
, lengthof(_nested_company_infrastructure_widgets
)
1899 * Open the infrastructure window of a company.
1900 * @param company Company to show infrastructure of.
1902 static void ShowCompanyInfrastructure(CompanyID company
)
1904 if (!Company::IsValidID(company
)) return;
1905 AllocateWindowDescFront
<CompanyInfrastructureWindow
>(&_company_infrastructure_desc
, company
);
1908 static const NWidgetPart _nested_company_widgets
[] = {
1909 NWidget(NWID_HORIZONTAL
),
1910 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1911 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_C_CAPTION
), SetDataTip(STR_COMPANY_VIEW_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1912 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1913 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1915 NWidget(WWT_PANEL
, COLOUR_GREY
),
1916 NWidget(NWID_HORIZONTAL
), SetPIP(4, 6, 4),
1917 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
1918 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_FACE
), SetMinimalSize(92, 119), SetFill(1, 0),
1919 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_FACE_TITLE
), SetFill(1, 1), SetMinimalTextLines(2, 0),
1921 NWidget(NWID_VERTICAL
),
1922 NWidget(NWID_HORIZONTAL
),
1923 NWidget(NWID_VERTICAL
), SetPIP(4, 5, 5),
1924 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_INAUGURATION
), SetDataTip(STR_COMPANY_VIEW_INAUGURATED_TITLE
, STR_NULL
), SetFill(1, 0),
1925 NWidget(NWID_HORIZONTAL
), SetPIP(0, 5, 0),
1926 NWidget(WWT_LABEL
, COLOUR_GREY
, WID_C_DESC_COLOUR_SCHEME
), SetDataTip(STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE
, STR_NULL
),
1927 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_COLOUR_SCHEME_EXAMPLE
), SetMinimalSize(30, 0), SetFill(0, 1),
1928 NWidget(NWID_SPACER
), SetFill(1, 0),
1930 NWidget(NWID_HORIZONTAL
), SetPIP(0, 4, 0),
1931 NWidget(NWID_VERTICAL
),
1932 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_VEHICLE
), SetDataTip(STR_COMPANY_VIEW_VEHICLES_TITLE
, STR_NULL
),
1933 NWidget(NWID_SPACER
), SetFill(0, 1),
1935 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_VEHICLE_COUNTS
), SetMinimalTextLines(4, 0),
1936 NWidget(NWID_SPACER
), SetFill(1, 0),
1939 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
1940 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_VIEW_BUILD_HQ
),
1941 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_VIEW_HQ
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_VIEW_HQ_BUTTON
, STR_COMPANY_VIEW_VIEW_HQ_TOOLTIP
),
1942 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_C_BUILD_HQ
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_BUILD_HQ_BUTTON
, STR_COMPANY_VIEW_BUILD_HQ_TOOLTIP
),
1944 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_RELOCATE
),
1945 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_C_RELOCATE_HQ
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_RELOCATE_HQ
, STR_COMPANY_VIEW_RELOCATE_COMPANY_HEADQUARTERS
),
1946 NWidget(NWID_SPACER
), SetMinimalSize(90, 0),
1948 NWidget(NWID_SPACER
), SetFill(0, 1),
1951 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_COMPANY_VALUE
), SetDataTip(STR_COMPANY_VIEW_COMPANY_VALUE
, STR_NULL
), SetFill(1, 0),
1952 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
1953 NWidget(NWID_HORIZONTAL
), SetPIP(0, 4, 0),
1954 NWidget(NWID_VERTICAL
),
1955 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_INFRASTRUCTURE
), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE
, STR_NULL
),
1956 NWidget(NWID_SPACER
), SetFill(0, 1),
1958 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_INFRASTRUCTURE_COUNTS
), SetMinimalTextLines(5, 0), SetFill(1, 0),
1959 NWidget(NWID_VERTICAL
),
1960 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_VIEW_INFRASTRUCTURE
), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON
, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP
),
1961 NWidget(NWID_SPACER
), SetFill(0, 1), SetMinimalSize(90, 0),
1965 NWidget(NWID_HORIZONTAL
),
1966 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_DESC_OWNERS
),
1967 NWidget(NWID_VERTICAL
), SetPIP(5, 5, 4),
1968 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_OWNERS
), SetMinimalTextLines(3, 0),
1969 NWidget(NWID_SPACER
), SetFill(0, 1),
1972 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
1973 NWidget(NWID_SPACER
), SetMinimalSize(90, 0), SetFill(0, 1),
1974 /* Multi player buttons. */
1975 NWidget(NWID_HORIZONTAL
),
1976 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_C_HAS_PASSWORD
),
1977 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_MULTIPLAYER
),
1978 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_COMPANY_PASSWORD
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_PASSWORD
, STR_COMPANY_VIEW_PASSWORD_TOOLTIP
),
1979 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_COMPANY_JOIN
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_JOIN
, STR_COMPANY_VIEW_JOIN_TOOLTIP
),
1987 /* Button bars at the bottom. */
1988 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_BUTTONS
),
1989 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1990 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
),
1991 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
),
1992 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
),
1993 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
),
1995 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1996 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
),
1997 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
),
2002 int GetAmountOwnedBy(const Company
*c
, Owner owner
)
2004 return (c
->share_owners
[0] == owner
) +
2005 (c
->share_owners
[1] == owner
) +
2006 (c
->share_owners
[2] == owner
) +
2007 (c
->share_owners
[3] == owner
);
2010 /** Strings for the company vehicle counts */
2011 static const StringID _company_view_vehicle_count_strings
[] = {
2012 STR_COMPANY_VIEW_TRAINS
, STR_COMPANY_VIEW_ROAD_VEHICLES
, STR_COMPANY_VIEW_SHIPS
, STR_COMPANY_VIEW_AIRCRAFT
2016 * Window with general information about a company
2018 struct CompanyWindow
: Window
2020 CompanyWidgets query_widget
;
2022 /** Display planes in the company window. */
2023 enum CompanyWindowPlanes
{
2024 /* Display planes of the #WID_C_SELECT_MULTIPLAYER selection widget. */
2025 CWP_MP_C_PWD
= 0, ///< Display the company password button.
2026 CWP_MP_C_JOIN
, ///< Display the join company button.
2028 /* Display planes of the #WID_C_SELECT_VIEW_BUILD_HQ selection widget. */
2029 CWP_VB_VIEW
= 0, ///< Display the view button
2030 CWP_VB_BUILD
, ///< Display the build button
2032 /* Display planes of the #WID_C_SELECT_RELOCATE selection widget. */
2033 CWP_RELOCATE_SHOW
= 0, ///< Show the relocate HQ button.
2034 CWP_RELOCATE_HIDE
, ///< Hide the relocate HQ button.
2036 /* Display planes of the #WID_C_SELECT_BUTTONS selection widget. */
2037 CWP_BUTTONS_LOCAL
= 0, ///< Buttons of the local company.
2038 CWP_BUTTONS_OTHER
, ///< Buttons of the other companies.
2041 CompanyWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
2043 this->InitNested(window_number
);
2044 this->owner
= (Owner
)this->window_number
;
2045 this->OnInvalidateData();
2048 virtual void OnPaint()
2050 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2051 bool local
= this->window_number
== _local_company
;
2053 if (!this->IsShaded()) {
2054 bool reinit
= false;
2056 /* Button bar selection. */
2057 int plane
= local
? CWP_BUTTONS_LOCAL
: CWP_BUTTONS_OTHER
;
2058 NWidgetStacked
*wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_BUTTONS
);
2059 if (plane
!= wi
->shown_plane
) {
2060 wi
->SetDisplayedPlane(plane
);
2061 this->InvalidateData();
2065 /* Build HQ button handling. */
2066 plane
= (local
&& c
->location_of_HQ
== INVALID_TILE
) ? CWP_VB_BUILD
: CWP_VB_VIEW
;
2067 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_VIEW_BUILD_HQ
);
2068 if (plane
!= wi
->shown_plane
) {
2069 wi
->SetDisplayedPlane(plane
);
2074 this->SetWidgetDisabledState(WID_C_VIEW_HQ
, c
->location_of_HQ
== INVALID_TILE
);
2076 /* Enable/disable 'Relocate HQ' button. */
2077 plane
= (!local
|| c
->location_of_HQ
== INVALID_TILE
) ? CWP_RELOCATE_HIDE
: CWP_RELOCATE_SHOW
;
2078 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_RELOCATE
);
2079 if (plane
!= wi
->shown_plane
) {
2080 wi
->SetDisplayedPlane(plane
);
2085 /* Owners of company */
2086 plane
= SZSP_HORIZONTAL
;
2087 for (uint i
= 0; i
< lengthof(c
->share_owners
); i
++) {
2088 if (c
->share_owners
[i
] != INVALID_COMPANY
) {
2093 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_DESC_OWNERS
);
2094 if (plane
!= wi
->shown_plane
) {
2095 wi
->SetDisplayedPlane(plane
);
2099 /* Multiplayer buttons. */
2100 plane
= ((!_networking
) ? (int)SZSP_NONE
: (int)(local
? CWP_MP_C_PWD
: CWP_MP_C_JOIN
));
2101 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_MULTIPLAYER
);
2102 if (plane
!= wi
->shown_plane
) {
2103 wi
->SetDisplayedPlane(plane
);
2106 this->SetWidgetDisabledState(WID_C_COMPANY_JOIN
, c
->is_ai
);
2114 this->DrawWidgets();
2117 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
2121 Dimension face_size
= GetSpriteSize(SPR_GRADIENT
);
2122 size
->width
= max(size
->width
, face_size
.width
);
2123 size
->height
= max(size
->height
, face_size
.height
);
2127 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE
: {
2129 Dimension d
= GetSpriteSize(SPR_VEH_BUS_SW_VIEW
, &offset
);
2130 d
.width
-= offset
.x
;
2131 d
.height
-= offset
.y
;
2132 *size
= maxdim(*size
, d
);
2136 case WID_C_DESC_COMPANY_VALUE
:
2137 SetDParam(0, INT64_MAX
); // Arguably the maximum company value
2138 size
->width
= GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE
).width
;
2141 case WID_C_DESC_VEHICLE_COUNTS
:
2142 SetDParamMaxValue(0, 5000); // Maximum number of vehicles
2143 for (uint i
= 0; i
< lengthof(_company_view_vehicle_count_strings
); i
++) {
2144 size
->width
= max(size
->width
, GetStringBoundingBox(_company_view_vehicle_count_strings
[i
]).width
);
2148 case WID_C_DESC_INFRASTRUCTURE_COUNTS
:
2149 SetDParamMaxValue(0, UINT_MAX
);
2150 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL
).width
);
2151 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD
).width
);
2152 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER
).width
);
2153 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION
).width
);
2154 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT
).width
);
2155 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
).width
);
2158 case WID_C_DESC_OWNERS
: {
2161 FOR_ALL_COMPANIES(c2
) {
2162 SetDParamMaxValue(0, 75);
2163 SetDParam(1, c2
->index
);
2165 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_SHARES_OWNED_BY
).width
);
2170 #ifdef ENABLE_NETWORK
2171 case WID_C_HAS_PASSWORD
:
2172 *size
= maxdim(*size
, GetSpriteSize(SPR_LOCK
));
2174 #endif /* ENABLE_NETWORK */
2178 virtual void DrawWidget(const Rect
&r
, int widget
) const
2180 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2183 DrawCompanyManagerFace(c
->face
, c
->colour
, r
.left
, r
.top
);
2186 case WID_C_FACE_TITLE
:
2187 SetDParam(0, c
->index
);
2188 DrawStringMultiLine(r
.left
, r
.right
, r
.top
, r
.bottom
, STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE
, TC_FROMSTRING
, SA_HOR_CENTER
);
2191 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE
: {
2193 Dimension d
= GetSpriteSize(SPR_VEH_BUS_SW_VIEW
, &offset
);
2194 d
.height
-= offset
.y
;
2195 DrawSprite(SPR_VEH_BUS_SW_VIEW
, COMPANY_SPRITE_COLOUR(c
->index
), r
.left
- offset
.x
, (r
.top
+ r
.bottom
- d
.height
) / 2 - offset
.y
);
2199 case WID_C_DESC_VEHICLE_COUNTS
: {
2201 amounts
[0] = c
->group_all
[VEH_TRAIN
].num_vehicle
;
2202 amounts
[1] = c
->group_all
[VEH_ROAD
].num_vehicle
;
2203 amounts
[2] = c
->group_all
[VEH_SHIP
].num_vehicle
;
2204 amounts
[3] = c
->group_all
[VEH_AIRCRAFT
].num_vehicle
;
2207 if (amounts
[0] + amounts
[1] + amounts
[2] + amounts
[3] == 0) {
2208 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_VEHICLES_NONE
);
2210 assert_compile(lengthof(amounts
) == lengthof(_company_view_vehicle_count_strings
));
2212 for (uint i
= 0; i
< lengthof(amounts
); i
++) {
2213 if (amounts
[i
] != 0) {
2214 SetDParam(0, amounts
[i
]);
2215 DrawString(r
.left
, r
.right
, y
, _company_view_vehicle_count_strings
[i
]);
2216 y
+= FONT_HEIGHT_NORMAL
;
2223 case WID_C_DESC_INFRASTRUCTURE_COUNTS
: {
2226 /* Collect rail and road counts. */
2227 uint rail_pices
= c
->infrastructure
.signal
;
2228 uint road_pieces
= 0;
2229 for (uint i
= 0; i
< lengthof(c
->infrastructure
.rail
); i
++) rail_pices
+= c
->infrastructure
.rail
[i
];
2230 for (RoadType rt
= ROADTYPE_BEGIN
; rt
< ROADTYPE_END
; rt
++) {
2231 for (uint i
= 0; i
< lengthof(c
->infrastructure
.road
[rt
]); i
++) road_pieces
+= c
->infrastructure
.road
[rt
][i
];
2234 if (rail_pices
== 0 && road_pieces
== 0 && c
->infrastructure
.water
== 0 && c
->infrastructure
.station
== 0 && c
->infrastructure
.airport
== 0) {
2235 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
);
2237 if (rail_pices
!= 0) {
2238 SetDParam(0, rail_pices
);
2239 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL
);
2240 y
+= FONT_HEIGHT_NORMAL
;
2242 if (road_pieces
!= 0) {
2243 SetDParam(0, road_pieces
);
2244 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD
);
2245 y
+= FONT_HEIGHT_NORMAL
;
2247 if (c
->infrastructure
.water
!= 0) {
2248 SetDParam(0, c
->infrastructure
.water
);
2249 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER
);
2250 y
+= FONT_HEIGHT_NORMAL
;
2252 if (c
->infrastructure
.station
!= 0) {
2253 SetDParam(0, c
->infrastructure
.station
);
2254 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION
);
2255 y
+= FONT_HEIGHT_NORMAL
;
2257 if (c
->infrastructure
.airport
!= 0) {
2258 SetDParam(0, c
->infrastructure
.airport
);
2259 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT
);
2266 case WID_C_DESC_OWNERS
: {
2270 FOR_ALL_COMPANIES(c2
) {
2271 uint amt
= GetAmountOwnedBy(c
, c2
->index
);
2273 SetDParam(0, amt
* 25);
2274 SetDParam(1, c2
->index
);
2276 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_SHARES_OWNED_BY
);
2277 y
+= FONT_HEIGHT_NORMAL
;
2283 #ifdef ENABLE_NETWORK
2284 case WID_C_HAS_PASSWORD
:
2285 if (_networking
&& NetworkCompanyIsPassworded(c
->index
)) {
2286 DrawSprite(SPR_LOCK
, PAL_NONE
, r
.left
, r
.top
);
2289 #endif /* ENABLE_NETWORK */
2293 virtual void SetStringParameters(int widget
) const
2297 SetDParam(0, (CompanyID
)this->window_number
);
2298 SetDParam(1, (CompanyID
)this->window_number
);
2301 case WID_C_DESC_INAUGURATION
:
2302 SetDParam(0, Company::Get((CompanyID
)this->window_number
)->inaugurated_year
);
2305 case WID_C_DESC_COMPANY_VALUE
:
2306 SetDParam(0, CalculateCompanyValue(Company::Get((CompanyID
)this->window_number
)));
2311 virtual void OnClick(Point pt
, int widget
, int click_count
)
2314 case WID_C_NEW_FACE
: DoSelectCompanyManagerFace(this); break;
2316 case WID_C_COLOUR_SCHEME
:
2317 if (BringWindowToFrontById(WC_COMPANY_COLOUR
, this->window_number
)) break;
2318 new SelectCompanyLiveryWindow(&_select_company_livery_desc
, (CompanyID
)this->window_number
);
2321 case WID_C_PRESIDENT_NAME
:
2322 this->query_widget
= WID_C_PRESIDENT_NAME
;
2323 SetDParam(0, this->window_number
);
2324 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
);
2327 case WID_C_COMPANY_NAME
:
2328 this->query_widget
= WID_C_COMPANY_NAME
;
2329 SetDParam(0, this->window_number
);
2330 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
);
2333 case WID_C_VIEW_HQ
: {
2334 TileIndex tile
= Company::Get((CompanyID
)this->window_number
)->location_of_HQ
;
2335 if (_ctrl_pressed
) {
2336 ShowExtraViewPortWindow(tile
);
2338 ScrollMainWindowToTile(tile
);
2343 case WID_C_BUILD_HQ
:
2344 if ((byte
)this->window_number
!= _local_company
) return;
2345 if (this->IsWidgetLowered(WID_C_BUILD_HQ
)) {
2346 ResetObjectToPlace();
2347 this->RaiseButtons();
2350 SetObjectToPlaceWnd(SPR_CURSOR_HQ
, PAL_NONE
, HT_RECT
, this);
2351 SetTileSelectSize(2, 2);
2352 this->LowerWidget(WID_C_BUILD_HQ
);
2353 this->SetWidgetDirty(WID_C_BUILD_HQ
);
2356 case WID_C_RELOCATE_HQ
:
2357 if (this->IsWidgetLowered(WID_C_RELOCATE_HQ
)) {
2358 ResetObjectToPlace();
2359 this->RaiseButtons();
2362 SetObjectToPlaceWnd(SPR_CURSOR_HQ
, PAL_NONE
, HT_RECT
, this);
2363 SetTileSelectSize(2, 2);
2364 this->LowerWidget(WID_C_RELOCATE_HQ
);
2365 this->SetWidgetDirty(WID_C_RELOCATE_HQ
);
2368 case WID_C_VIEW_INFRASTRUCTURE
:
2369 ShowCompanyInfrastructure((CompanyID
)this->window_number
);
2372 case WID_C_BUY_SHARE
:
2373 DoCommandP(0, this->window_number
, 0, CMD_BUY_SHARE_IN_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS
));
2376 case WID_C_SELL_SHARE
:
2377 DoCommandP(0, this->window_number
, 0, CMD_SELL_SHARE_IN_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_SELL_25_SHARE_IN
));
2380 #ifdef ENABLE_NETWORK
2381 case WID_C_COMPANY_PASSWORD
:
2382 if (this->window_number
== _local_company
) ShowNetworkCompanyPasswordWindow(this);
2385 case WID_C_COMPANY_JOIN
: {
2386 this->query_widget
= WID_C_COMPANY_JOIN
;
2387 CompanyID company
= (CompanyID
)this->window_number
;
2388 if (_network_server
) {
2389 NetworkServerDoMove(CLIENT_ID_SERVER
, company
);
2390 MarkWholeScreenDirty();
2391 } else if (NetworkCompanyIsPassworded(company
)) {
2392 /* ask for the password */
2393 ShowQueryString(STR_EMPTY
, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION
, NETWORK_PASSWORD_LENGTH
, this, CS_ALPHANUMERAL
, QSF_NONE
);
2395 /* just send the join command */
2396 NetworkClientRequestMove(company
);
2400 #endif /* ENABLE_NETWORK */
2404 virtual void OnHundredthTick()
2406 /* redraw the window every now and then */
2410 virtual void OnPlaceObject(Point pt
, TileIndex tile
)
2412 if (DoCommandP(tile
, OBJECT_HQ
, 0, CMD_BUILD_OBJECT
| CMD_MSG(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS
)) && !_shift_pressed
) {
2413 ResetObjectToPlace();
2414 this->RaiseButtons();
2418 virtual void OnPlaceObjectAbort()
2420 this->RaiseButtons();
2423 virtual void OnQueryTextFinished(char *str
)
2425 if (str
== nullptr) return;
2427 switch (this->query_widget
) {
2428 default: NOT_REACHED();
2430 case WID_C_PRESIDENT_NAME
:
2431 DoCommandP(0, 0, 0, CMD_RENAME_PRESIDENT
| CMD_MSG(STR_ERROR_CAN_T_CHANGE_PRESIDENT
), nullptr, str
);
2434 case WID_C_COMPANY_NAME
:
2435 DoCommandP(0, 0, 0, CMD_RENAME_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME
), nullptr, str
);
2438 #ifdef ENABLE_NETWORK
2439 case WID_C_COMPANY_JOIN
:
2440 NetworkClientRequestMove((CompanyID
)this->window_number
, str
);
2442 #endif /* ENABLE_NETWORK */
2448 * Some data on this window has become invalid.
2449 * @param data Information about the changed data.
2450 * @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.
2452 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
2454 if (this->window_number
== _local_company
) return;
2456 if (_settings_game
.economy
.allow_shares
) { // Shares are allowed
2457 const Company
*c
= Company::Get(this->window_number
);
2459 /* If all shares are owned by someone (none by nobody), disable buy button */
2460 this->SetWidgetDisabledState(WID_C_BUY_SHARE
, GetAmountOwnedBy(c
, INVALID_OWNER
) == 0 ||
2461 /* Only 25% left to buy. If the company is human, disable buying it up.. TODO issues! */
2462 (GetAmountOwnedBy(c
, INVALID_OWNER
) == 1 && !c
->is_ai
) ||
2463 /* Spectators cannot do anything of course */
2464 _local_company
== COMPANY_SPECTATOR
);
2466 /* If the company doesn't own any shares, disable sell button */
2467 this->SetWidgetDisabledState(WID_C_SELL_SHARE
, (GetAmountOwnedBy(c
, _local_company
) == 0) ||
2468 /* Spectators cannot do anything of course */
2469 _local_company
== COMPANY_SPECTATOR
);
2470 } else { // Shares are not allowed, disable buy/sell buttons
2471 this->DisableWidget(WID_C_BUY_SHARE
);
2472 this->DisableWidget(WID_C_SELL_SHARE
);
2477 static WindowDesc
_company_desc(
2478 WDP_AUTO
, "company", 0, 0,
2479 WC_COMPANY
, WC_NONE
,
2481 _nested_company_widgets
, lengthof(_nested_company_widgets
)
2485 * Show the window with the overview of the company.
2486 * @param company The company to show the window for.
2488 void ShowCompany(CompanyID company
)
2490 if (!Company::IsValidID(company
)) return;
2492 AllocateWindowDescFront
<CompanyWindow
>(&_company_desc
, company
);
2496 * Redraw all windows with company infrastructure counts.
2497 * @param company The company to redraw the windows of.
2499 void DirtyCompanyInfrastructureWindows(CompanyID company
)
2501 SetWindowDirty(WC_COMPANY
, company
);
2502 SetWindowDirty(WC_COMPANY_INFRASTRUCTURE
, company
);
2506 * Redraw all windows with all company infrastructure counts.
2508 void DirtyAllCompanyInfrastructureWindows()
2510 SetWindowClassesDirty(WC_COMPANY
);
2511 SetWindowClassesDirty(WC_COMPANY_INFRASTRUCTURE
);
2514 struct BuyCompanyWindow
: Window
{
2515 BuyCompanyWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
2517 this->InitNested(window_number
);
2520 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
2524 *size
= GetSpriteSize(SPR_GRADIENT
);
2527 case WID_BC_QUESTION
:
2528 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2529 SetDParam(0, c
->index
);
2530 SetDParam(1, c
->bankrupt_value
);
2531 size
->height
= GetStringHeight(STR_BUY_COMPANY_MESSAGE
, size
->width
);
2536 virtual void SetStringParameters(int widget
) const
2539 case WID_BC_CAPTION
:
2540 SetDParam(0, STR_COMPANY_NAME
);
2541 SetDParam(1, Company::Get((CompanyID
)this->window_number
)->index
);
2546 virtual void DrawWidget(const Rect
&r
, int widget
) const
2550 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2551 DrawCompanyManagerFace(c
->face
, c
->colour
, r
.left
, r
.top
);
2555 case WID_BC_QUESTION
: {
2556 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2557 SetDParam(0, c
->index
);
2558 SetDParam(1, c
->bankrupt_value
);
2559 DrawStringMultiLine(r
.left
, r
.right
, r
.top
, r
.bottom
, STR_BUY_COMPANY_MESSAGE
, TC_FROMSTRING
, SA_CENTER
);
2565 virtual void OnClick(Point pt
, int widget
, int click_count
)
2573 DoCommandP(0, this->window_number
, 0, CMD_BUY_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_BUY_COMPANY
));
2579 static const NWidgetPart _nested_buy_company_widgets
[] = {
2580 NWidget(NWID_HORIZONTAL
),
2581 NWidget(WWT_CLOSEBOX
, COLOUR_LIGHT_BLUE
),
2582 NWidget(WWT_CAPTION
, COLOUR_LIGHT_BLUE
, WID_BC_CAPTION
), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2584 NWidget(WWT_PANEL
, COLOUR_LIGHT_BLUE
),
2585 NWidget(NWID_VERTICAL
), SetPIP(8, 8, 8),
2586 NWidget(NWID_HORIZONTAL
), SetPIP(8, 10, 8),
2587 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BC_FACE
), SetFill(0, 1),
2588 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BC_QUESTION
), SetMinimalSize(240, 0), SetFill(1, 1),
2590 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(100, 10, 100),
2591 NWidget(WWT_TEXTBTN
, COLOUR_LIGHT_BLUE
, WID_BC_NO
), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_NO
, STR_NULL
), SetFill(1, 0),
2592 NWidget(WWT_TEXTBTN
, COLOUR_LIGHT_BLUE
, WID_BC_YES
), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_YES
, STR_NULL
), SetFill(1, 0),
2598 static WindowDesc
_buy_company_desc(
2599 WDP_AUTO
, nullptr, 0, 0,
2600 WC_BUY_COMPANY
, WC_NONE
,
2602 _nested_buy_company_widgets
, lengthof(_nested_buy_company_widgets
)
2606 * Show the query to buy another company.
2607 * @param company The company to buy.
2609 void ShowBuyCompanyDialog(CompanyID company
)
2611 AllocateWindowDescFront
<BuyCompanyWindow
>(&_buy_company_desc
, company
);