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"
33 #include "engine_base.h"
34 #include "window_func.h"
35 #include "road_func.h"
37 #include "station_func.h"
38 #include "zoom_func.h"
40 #include "widgets/company_widget.h"
42 #include "safeguards.h"
45 /** Company GUI constants. */
46 static const uint EXP_LINESPACE
= 2; ///< Amount of vertical space for a horizontal (sub-)total line.
47 static const uint EXP_BLOCKSPACE
= 10; ///< Amount of vertical space between two blocks of numbers.
49 static void DoSelectCompanyManagerFace(Window
*parent
);
50 static void ShowCompanyInfrastructure(CompanyID company
);
52 /** Standard unsorted list of expenses. */
53 static ExpensesType _expenses_list_1
[] = {
54 EXPENSES_CONSTRUCTION
,
55 EXPENSES_NEW_VEHICLES
,
58 EXPENSES_AIRCRAFT_RUN
,
63 EXPENSES_AIRCRAFT_INC
,
69 /** Grouped list of expenses. */
70 static ExpensesType _expenses_list_2
[] = {
73 EXPENSES_AIRCRAFT_INC
,
78 EXPENSES_AIRCRAFT_RUN
,
83 EXPENSES_CONSTRUCTION
,
84 EXPENSES_NEW_VEHICLES
,
89 /** Expense list container. */
91 const ExpensesType
*et
; ///< Expenses items.
92 const uint length
; ///< Number of items in list.
93 const uint num_subtotals
; ///< Number of sub-totals in the list.
95 ExpensesList(ExpensesType
*et
, int length
, int num_subtotals
) : et(et
), length(length
), num_subtotals(num_subtotals
)
99 uint
GetHeight() const
101 /* heading + line + texts of expenses + sub-totals + total line + total text */
102 return FONT_HEIGHT_NORMAL
+ EXP_LINESPACE
+ this->length
* FONT_HEIGHT_NORMAL
+ num_subtotals
* (EXP_BLOCKSPACE
+ EXP_LINESPACE
) + EXP_LINESPACE
+ FONT_HEIGHT_NORMAL
;
105 /** Compute width of the expenses categories in pixels. */
106 uint
GetCategoriesWidth() const
109 bool invalid_expenses_measured
= false; // Measure 'Total' width only once.
110 for (uint i
= 0; i
< this->length
; i
++) {
111 ExpensesType et
= this->et
[i
];
112 if (et
== INVALID_EXPENSES
) {
113 if (!invalid_expenses_measured
) {
114 width
= max(width
, GetStringBoundingBox(STR_FINANCES_TOTAL_CAPTION
).width
);
115 invalid_expenses_measured
= true;
118 width
= max(width
, GetStringBoundingBox(STR_FINANCES_SECTION_CONSTRUCTION
+ et
).width
);
125 static const ExpensesList _expenses_list_types
[] = {
126 ExpensesList(_expenses_list_1
, lengthof(_expenses_list_1
), 0),
127 ExpensesList(_expenses_list_2
, lengthof(_expenses_list_2
), 3),
131 * Draw the expenses categories.
132 * @param r Available space for drawing.
133 * @note The environment must provide padding at the left and right of \a r.
135 static void DrawCategories(const Rect
&r
)
139 DrawString(r
.left
, r
.right
, y
, STR_FINANCES_EXPENDITURE_INCOME_TITLE
, TC_FROMSTRING
, SA_HOR_CENTER
, true);
140 y
+= FONT_HEIGHT_NORMAL
+ EXP_LINESPACE
;
142 int type
= _settings_client
.gui
.expenses_layout
;
143 for (uint i
= 0; i
< _expenses_list_types
[type
].length
; i
++) {
144 const ExpensesType et
= _expenses_list_types
[type
].et
[i
];
145 if (et
== INVALID_EXPENSES
) {
147 DrawString(r
.left
, r
.right
, y
, STR_FINANCES_TOTAL_CAPTION
, TC_FROMSTRING
, SA_RIGHT
);
148 y
+= FONT_HEIGHT_NORMAL
+ EXP_BLOCKSPACE
;
150 DrawString(r
.left
, r
.right
, y
, STR_FINANCES_SECTION_CONSTRUCTION
+ et
);
151 y
+= FONT_HEIGHT_NORMAL
;
155 DrawString(r
.left
, r
.right
, y
+ EXP_LINESPACE
, STR_FINANCES_TOTAL_CAPTION
, TC_FROMSTRING
, SA_RIGHT
);
159 * Draw an amount of money.
160 * @param amount Amount of money to draw,
161 * @param left Left coordinate of the space to draw in.
162 * @param right Right coordinate of the space to draw in.
163 * @param top Top coordinate of the space to draw in.
165 static void DrawPrice(Money amount
, int left
, int right
, int top
)
167 StringID str
= STR_FINANCES_NEGATIVE_INCOME
;
172 SetDParam(0, amount
);
173 DrawString(left
, right
, top
, str
, TC_FROMSTRING
, SA_RIGHT
);
177 * Draw a column with prices.
178 * @param r Available space for drawing.
179 * @param year Year being drawn.
180 * @param tbl Pointer to table of amounts for \a year.
181 * @note The environment must provide padding at the left and right of \a r.
183 static void DrawYearColumn(const Rect
&r
, int year
, const Money (*tbl
)[EXPENSES_END
])
188 DrawString(r
.left
, r
.right
, y
, STR_FINANCES_YEAR
, TC_FROMSTRING
, SA_RIGHT
, true);
189 y
+= FONT_HEIGHT_NORMAL
+ EXP_LINESPACE
;
193 int type
= _settings_client
.gui
.expenses_layout
;
194 for (uint i
= 0; i
< _expenses_list_types
[type
].length
; i
++) {
195 const ExpensesType et
= _expenses_list_types
[type
].et
[i
];
196 if (et
== INVALID_EXPENSES
) {
197 Money cost
= subtotal
;
199 GfxFillRect(r
.left
, y
, r
.right
, y
, PC_BLACK
);
201 DrawPrice(cost
, r
.left
, r
.right
, y
);
202 y
+= FONT_HEIGHT_NORMAL
+ EXP_BLOCKSPACE
;
204 Money cost
= (*tbl
)[et
];
207 if (cost
!= 0) DrawPrice(cost
, r
.left
, r
.right
, y
);
208 y
+= FONT_HEIGHT_NORMAL
;
212 GfxFillRect(r
.left
, y
, r
.right
, y
, PC_BLACK
);
214 DrawPrice(sum
, r
.left
, r
.right
, y
);
217 static const NWidgetPart _nested_company_finances_widgets
[] = {
218 NWidget(NWID_HORIZONTAL
),
219 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
220 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_CF_CAPTION
), SetDataTip(STR_FINANCES_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
221 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_CF_TOGGLE_SIZE
), SetDataTip(SPR_LARGE_SMALL_WINDOW
, STR_TOOLTIP_TOGGLE_LARGE_SMALL_WINDOW
),
222 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
223 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
225 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_CF_SEL_PANEL
),
226 NWidget(WWT_PANEL
, COLOUR_GREY
),
227 NWidget(NWID_HORIZONTAL
), SetPadding(WD_FRAMERECT_TOP
, WD_FRAMERECT_RIGHT
, WD_FRAMERECT_BOTTOM
, WD_FRAMERECT_LEFT
), SetPIP(0, 9, 0),
228 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_EXPS_CATEGORY
), SetMinimalSize(120, 0), SetFill(0, 0),
229 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_EXPS_PRICE1
), SetMinimalSize(86, 0), SetFill(0, 0),
230 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_EXPS_PRICE2
), SetMinimalSize(86, 0), SetFill(0, 0),
231 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_EXPS_PRICE3
), SetMinimalSize(86, 0), SetFill(0, 0),
235 NWidget(WWT_PANEL
, COLOUR_GREY
),
236 NWidget(NWID_HORIZONTAL
), SetPadding(WD_FRAMERECT_TOP
, WD_FRAMERECT_RIGHT
, WD_FRAMERECT_BOTTOM
, WD_FRAMERECT_LEFT
),
237 NWidget(NWID_VERTICAL
), // Vertical column with 'bank balance', 'loan'
238 NWidget(WWT_TEXT
, COLOUR_GREY
), SetDataTip(STR_FINANCES_BANK_BALANCE_TITLE
, STR_NULL
), SetFill(1, 0),
239 NWidget(WWT_TEXT
, COLOUR_GREY
), SetDataTip(STR_FINANCES_LOAN_TITLE
, STR_NULL
), SetFill(1, 0),
240 NWidget(NWID_SPACER
), SetFill(0, 1),
242 NWidget(NWID_SPACER
), SetFill(0, 0), SetMinimalSize(30, 0),
243 NWidget(NWID_VERTICAL
), // Vertical column with bank balance amount, loan amount, and total.
244 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CF_BALANCE_VALUE
), SetDataTip(STR_NULL
, STR_NULL
),
245 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CF_LOAN_VALUE
), SetDataTip(STR_NULL
, STR_NULL
),
246 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_LOAN_LINE
), SetMinimalSize(0, 2), SetFill(1, 0),
247 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CF_TOTAL_VALUE
), SetDataTip(STR_NULL
, STR_NULL
),
249 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_CF_SEL_MAXLOAN
),
250 NWidget(NWID_HORIZONTAL
),
251 NWidget(NWID_SPACER
), SetFill(0, 1), SetMinimalSize(25, 0),
252 NWidget(NWID_VERTICAL
), // Max loan information
253 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CF_MAXLOAN_GAP
), SetFill(0, 0),
254 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_CF_MAXLOAN_VALUE
), SetDataTip(STR_FINANCES_MAX_LOAN
, STR_NULL
),
255 NWidget(NWID_SPACER
), SetFill(0, 1),
259 NWidget(NWID_SPACER
), SetFill(1, 1),
262 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_CF_SEL_BUTTONS
),
263 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
264 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_CF_INCREASE_LOAN
), SetFill(1, 0), SetDataTip(STR_FINANCES_BORROW_BUTTON
, STR_FINANCES_BORROW_TOOLTIP
),
265 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_CF_REPAY_LOAN
), SetFill(1, 0), SetDataTip(STR_FINANCES_REPAY_BUTTON
, STR_FINANCES_REPAY_TOOLTIP
),
266 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_CF_INFRASTRUCTURE
), SetFill(1, 0), SetDataTip(STR_FINANCES_INFRASTRUCTURE_BUTTON
, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP
),
272 * Window class displaying the company finances.
273 * @todo #money_width should be calculated dynamically.
275 struct CompanyFinancesWindow
: Window
{
276 Money max_money
; ///< The approximate maximum amount of money a company has had over the lifetime of this window
277 bool small
; ///< Window is toggled to 'small'.
279 CompanyFinancesWindow(WindowDesc
*desc
, CompanyID company
) : Window(desc
)
281 const Company
*c
= Company::Get(company
);
282 this->max_money
= max
<Money
>(c
->money
* 2, INT32_MAX
);
284 this->CreateNestedTree();
285 this->SetupWidgets();
286 this->FinishInitNested(company
);
288 this->owner
= (Owner
)this->window_number
;
291 virtual void SetStringParameters(int widget
) const
295 SetDParam(0, (CompanyID
)this->window_number
);
296 SetDParam(1, (CompanyID
)this->window_number
);
299 case WID_CF_MAXLOAN_VALUE
:
300 SetDParam(0, _economy
.max_loan
);
303 case WID_CF_INCREASE_LOAN
:
304 case WID_CF_REPAY_LOAN
:
305 SetDParam(0, LOAN_INTERVAL
);
310 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
312 int type
= _settings_client
.gui
.expenses_layout
;
314 case WID_CF_EXPS_CATEGORY
:
315 size
->width
= _expenses_list_types
[type
].GetCategoriesWidth();
316 size
->height
= _expenses_list_types
[type
].GetHeight();
319 case WID_CF_EXPS_PRICE1
:
320 case WID_CF_EXPS_PRICE2
:
321 case WID_CF_EXPS_PRICE3
:
322 size
->height
= _expenses_list_types
[type
].GetHeight();
325 case WID_CF_BALANCE_VALUE
:
326 case WID_CF_LOAN_VALUE
:
327 case WID_CF_TOTAL_VALUE
:
328 SetDParamMaxValue(0, this->max_money
);
329 size
->width
= max(GetStringBoundingBox(STR_FINANCES_NEGATIVE_INCOME
).width
, GetStringBoundingBox(STR_FINANCES_POSITIVE_INCOME
).width
) + padding
.width
;
332 case WID_CF_MAXLOAN_GAP
:
333 size
->height
= FONT_HEIGHT_NORMAL
;
338 virtual void DrawWidget(const Rect
&r
, int widget
) const
341 case WID_CF_EXPS_CATEGORY
:
345 case WID_CF_EXPS_PRICE1
:
346 case WID_CF_EXPS_PRICE2
:
347 case WID_CF_EXPS_PRICE3
: {
348 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
349 int age
= min(_cur_year
- c
->inaugurated_year
, 2);
350 int wid_offset
= widget
- WID_CF_EXPS_PRICE1
;
351 if (wid_offset
<= age
) {
352 DrawYearColumn(r
, _cur_year
- (age
- wid_offset
), c
->yearly_expenses
+ (age
- wid_offset
));
357 case WID_CF_BALANCE_VALUE
: {
358 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
359 SetDParam(0, c
->money
);
360 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
364 case WID_CF_LOAN_VALUE
: {
365 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
366 SetDParam(0, c
->current_loan
);
367 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
371 case WID_CF_TOTAL_VALUE
: {
372 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
373 SetDParam(0, c
->money
- c
->current_loan
);
374 DrawString(r
.left
, r
.right
, r
.top
, STR_FINANCES_TOTAL_CURRENCY
, TC_FROMSTRING
, SA_RIGHT
);
378 case WID_CF_LOAN_LINE
:
379 GfxFillRect(r
.left
, r
.top
, r
.right
, r
.top
, PC_BLACK
);
385 * Setup the widgets in the nested tree, such that the finances window is displayed properly.
386 * @note After setup, the window must be (re-)initialized.
390 int plane
= this->small
? SZSP_NONE
: 0;
391 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_PANEL
)->SetDisplayedPlane(plane
);
392 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_MAXLOAN
)->SetDisplayedPlane(plane
);
394 CompanyID company
= (CompanyID
)this->window_number
;
395 plane
= (company
!= _local_company
) ? SZSP_NONE
: 0;
396 this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_BUTTONS
)->SetDisplayedPlane(plane
);
399 virtual void OnPaint()
401 if (!this->IsShaded()) {
403 /* Check that the expenses panel height matches the height needed for the layout. */
404 int type
= _settings_client
.gui
.expenses_layout
;
405 if (_expenses_list_types
[type
].GetHeight() != this->GetWidget
<NWidgetBase
>(WID_CF_EXPS_CATEGORY
)->current_y
) {
406 this->SetupWidgets();
412 /* Check that the loan buttons are shown only when the user owns the company. */
413 CompanyID company
= (CompanyID
)this->window_number
;
414 int req_plane
= (company
!= _local_company
) ? SZSP_NONE
: 0;
415 if (req_plane
!= this->GetWidget
<NWidgetStacked
>(WID_CF_SEL_BUTTONS
)->shown_plane
) {
416 this->SetupWidgets();
421 const Company
*c
= Company::Get(company
);
422 this->SetWidgetDisabledState(WID_CF_INCREASE_LOAN
, c
->current_loan
== _economy
.max_loan
); // Borrow button only shows when there is any more money to loan.
423 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.
429 virtual void OnClick(Point pt
, int widget
, int click_count
)
432 case WID_CF_TOGGLE_SIZE
: // toggle size
433 this->small
= !this->small
;
434 this->SetupWidgets();
435 if (this->IsShaded()) {
436 /* Finances window is not resizable, so size hints given during unshading have no effect
437 * on the changed appearance of the window. */
438 this->SetShaded(false);
444 case WID_CF_INCREASE_LOAN
: // increase loan
445 DoCommandP(0, 0, _ctrl_pressed
, CMD_INCREASE_LOAN
| CMD_MSG(STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY
));
448 case WID_CF_REPAY_LOAN
: // repay loan
449 DoCommandP(0, 0, _ctrl_pressed
, CMD_DECREASE_LOAN
| CMD_MSG(STR_ERROR_CAN_T_REPAY_LOAN
));
452 case WID_CF_INFRASTRUCTURE
: // show infrastructure details
453 ShowCompanyInfrastructure((CompanyID
)this->window_number
);
458 virtual void OnHundredthTick()
460 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
461 if (c
->money
> this->max_money
) {
462 this->max_money
= max(c
->money
* 2, this->max_money
* 4);
463 this->SetupWidgets();
469 static WindowDesc
_company_finances_desc(
470 WDP_AUTO
, "company_finances", 0, 0,
471 WC_FINANCES
, WC_NONE
,
473 _nested_company_finances_widgets
, lengthof(_nested_company_finances_widgets
)
477 * Open the finances window of a company.
478 * @param company Company to show finances of.
479 * @pre is company a valid company.
481 void ShowCompanyFinances(CompanyID company
)
483 if (!Company::IsValidID(company
)) return;
484 if (BringWindowToFrontById(WC_FINANCES
, company
)) return;
486 new CompanyFinancesWindow(&_company_finances_desc
, company
);
489 /* List of colours for the livery window */
490 static const StringID _colour_dropdown
[] = {
491 STR_COLOUR_DARK_BLUE
,
492 STR_COLOUR_PALE_GREEN
,
496 STR_COLOUR_LIGHT_BLUE
,
498 STR_COLOUR_DARK_GREEN
,
509 /* Association of liveries to livery classes */
510 static const LiveryClass _livery_class
[LS_END
] = {
512 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
,
515 LC_AIRCRAFT
, LC_AIRCRAFT
, LC_AIRCRAFT
,
519 class DropDownListColourItem
: public DropDownListItem
{
521 DropDownListColourItem(int result
, bool masked
) : DropDownListItem(result
, masked
) {}
523 virtual ~DropDownListColourItem() {}
525 StringID
String() const
527 return _colour_dropdown
[this->result
];
530 uint
Height(uint width
) const
532 return max(FONT_HEIGHT_NORMAL
, ScaleGUITrad(12) + 2);
535 bool Selectable() const
540 void Draw(int left
, int right
, int top
, int bottom
, bool sel
, int bg_colour
) const
542 bool rtl
= _current_text_dir
== TD_RTL
;
543 int height
= bottom
- top
;
544 int icon_y_offset
= height
/ 2;
545 int text_y_offset
= (height
- FONT_HEIGHT_NORMAL
) / 2 + 1;
546 DrawSprite(SPR_VEH_BUS_SIDE_VIEW
, PALETTE_RECOLOUR_START
+ this->result
,
547 rtl
? right
- 2 - ScaleGUITrad(14) : left
+ ScaleGUITrad(14) + 2,
548 top
+ icon_y_offset
);
549 DrawString(rtl
? left
+ 2 : left
+ ScaleGUITrad(28) + 4,
550 rtl
? right
- ScaleGUITrad(28) - 4 : right
- 2,
551 top
+ text_y_offset
, this->String(), sel
? TC_WHITE
: TC_BLACK
);
555 /** Company livery colour scheme window. */
556 struct SelectCompanyLiveryWindow
: public Window
{
559 LiveryClass livery_class
;
564 void ShowColourDropDownMenu(uint32 widget
)
566 uint32 used_colours
= 0;
567 const Livery
*livery
;
570 /* Disallow other company colours for the primary colour */
571 if (HasBit(this->sel
, LS_DEFAULT
) && widget
== WID_SCL_PRI_COL_DROPDOWN
) {
573 FOR_ALL_COMPANIES(c
) {
574 if (c
->index
!= _local_company
) SetBit(used_colours
, c
->colour
);
578 /* Get the first selected livery to use as the default dropdown item */
579 for (scheme
= LS_BEGIN
; scheme
< LS_END
; scheme
++) {
580 if (HasBit(this->sel
, scheme
)) break;
582 if (scheme
== LS_END
) scheme
= LS_DEFAULT
;
583 livery
= &Company::Get((CompanyID
)this->window_number
)->livery
[scheme
];
585 DropDownList
*list
= new DropDownList();
586 for (uint i
= 0; i
< lengthof(_colour_dropdown
); i
++) {
587 *list
->Append() = new DropDownListColourItem(i
, HasBit(used_colours
, i
));
590 ShowDropDownList(this, list
, widget
== WID_SCL_PRI_COL_DROPDOWN
? livery
->colour1
: livery
->colour2
, widget
);
594 SelectCompanyLiveryWindow(WindowDesc
*desc
, CompanyID company
) : Window(desc
)
596 this->livery_class
= LC_OTHER
;
599 this->square
= GetSpriteSize(SPR_SQUARE
);
600 this->box
= maxdim(GetSpriteSize(SPR_BOX_CHECKED
), GetSpriteSize(SPR_BOX_EMPTY
));
601 this->line_height
= max(max(this->square
.height
, this->box
.height
), (uint
)FONT_HEIGHT_NORMAL
) + 4;
603 this->InitNested(company
);
604 this->owner
= company
;
605 this->LowerWidget(WID_SCL_CLASS_GENERAL
);
606 this->InvalidateData(1);
609 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
612 case WID_SCL_SPACER_DROPDOWN
: {
613 /* The matrix widget below needs enough room to print all the schemes. */
614 Dimension d
= {0, 0};
615 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
616 d
= maxdim(d
, GetStringBoundingBox(STR_LIVERY_DEFAULT
+ scheme
));
618 size
->width
= max(size
->width
, 5 + this->box
.width
+ d
.width
+ WD_FRAMERECT_RIGHT
);
622 case WID_SCL_MATRIX
: {
623 uint livery_height
= 0;
624 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
625 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
629 size
->height
= livery_height
* this->line_height
;
630 this->GetWidget
<NWidgetCore
>(WID_SCL_MATRIX
)->widget_data
= (livery_height
<< MAT_ROW_START
) | (1 << MAT_COL_START
);
634 case WID_SCL_SEC_COL_DROPDOWN
:
635 if (!_loaded_newgrf_features
.has_2CC
) {
641 case WID_SCL_PRI_COL_DROPDOWN
: {
642 int padding
= this->square
.width
+ NWidgetScrollbar::GetVerticalDimension().width
+ 10;
643 for (const StringID
*id
= _colour_dropdown
; id
!= endof(_colour_dropdown
); id
++) {
644 size
->width
= max(size
->width
, GetStringBoundingBox(*id
).width
+ padding
);
651 virtual void OnPaint()
653 /* Disable dropdown controls if no scheme is selected */
654 this->SetWidgetDisabledState(WID_SCL_PRI_COL_DROPDOWN
, this->sel
== 0);
655 this->SetWidgetDisabledState(WID_SCL_SEC_COL_DROPDOWN
, this->sel
== 0);
660 virtual void SetStringParameters(int widget
) const
663 case WID_SCL_PRI_COL_DROPDOWN
:
664 case WID_SCL_SEC_COL_DROPDOWN
: {
665 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
666 LiveryScheme scheme
= LS_DEFAULT
;
668 if (this->sel
!= 0) {
669 for (scheme
= LS_BEGIN
; scheme
< LS_END
; scheme
++) {
670 if (HasBit(this->sel
, scheme
)) break;
672 if (scheme
== LS_END
) scheme
= LS_DEFAULT
;
674 SetDParam(0, STR_COLOUR_DARK_BLUE
+ ((widget
== WID_SCL_PRI_COL_DROPDOWN
) ? c
->livery
[scheme
].colour1
: c
->livery
[scheme
].colour2
));
680 virtual void DrawWidget(const Rect
&r
, int widget
) const
682 if (widget
!= WID_SCL_MATRIX
) return;
684 bool rtl
= _current_text_dir
== TD_RTL
;
686 /* Horizontal coordinates of scheme name column. */
687 const NWidgetBase
*nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_SPACER_DROPDOWN
);
688 int sch_left
= nwi
->pos_x
;
689 int sch_right
= sch_left
+ nwi
->current_x
- 1;
690 /* Horizontal coordinates of first dropdown. */
691 nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_PRI_COL_DROPDOWN
);
692 int pri_left
= nwi
->pos_x
;
693 int pri_right
= pri_left
+ nwi
->current_x
- 1;
694 /* Horizontal coordinates of second dropdown. */
695 nwi
= this->GetWidget
<NWidgetBase
>(WID_SCL_SEC_COL_DROPDOWN
);
696 int sec_left
= nwi
->pos_x
;
697 int sec_right
= sec_left
+ nwi
->current_x
- 1;
699 int text_left
= (rtl
? (uint
)WD_FRAMERECT_LEFT
: (this->box
.width
+ 5));
700 int text_right
= (rtl
? (this->box
.width
+ 5) : (uint
)WD_FRAMERECT_RIGHT
);
702 int box_offs
= (this->line_height
- this->box
.height
) / 2;
703 int square_offs
= (this->line_height
- this->square
.height
) / 2 + 1;
704 int text_offs
= (this->line_height
- FONT_HEIGHT_NORMAL
) / 2 + 1;
707 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
708 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
709 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
710 bool sel
= HasBit(this->sel
, scheme
) != 0;
712 /* Optional check box + scheme name. */
713 if (scheme
!= LS_DEFAULT
) {
714 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
);
716 DrawString(sch_left
+ text_left
, sch_right
- text_right
, y
+ text_offs
, STR_LIVERY_DEFAULT
+ scheme
, sel
? TC_WHITE
: TC_BLACK
);
718 /* Text below the first dropdown. */
719 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
);
720 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
);
722 /* Text below the second dropdown. */
723 if (sec_right
> sec_left
) { // Second dropdown has non-zero size.
724 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
);
725 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
);
728 y
+= this->line_height
;
733 virtual void OnClick(Point pt
, int widget
, int click_count
)
736 /* Livery Class buttons */
737 case WID_SCL_CLASS_GENERAL
:
738 case WID_SCL_CLASS_RAIL
:
739 case WID_SCL_CLASS_ROAD
:
740 case WID_SCL_CLASS_SHIP
:
741 case WID_SCL_CLASS_AIRCRAFT
:
742 this->RaiseWidget(this->livery_class
+ WID_SCL_CLASS_GENERAL
);
743 this->livery_class
= (LiveryClass
)(widget
- WID_SCL_CLASS_GENERAL
);
744 this->LowerWidget(this->livery_class
+ WID_SCL_CLASS_GENERAL
);
746 /* Select the first item in the list */
748 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
749 if (_livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
750 this->sel
= 1 << scheme
;
758 case WID_SCL_PRI_COL_DROPDOWN
: // First colour dropdown
759 ShowColourDropDownMenu(WID_SCL_PRI_COL_DROPDOWN
);
762 case WID_SCL_SEC_COL_DROPDOWN
: // Second colour dropdown
763 ShowColourDropDownMenu(WID_SCL_SEC_COL_DROPDOWN
);
766 case WID_SCL_MATRIX
: {
767 const NWidgetBase
*wid
= this->GetWidget
<NWidgetBase
>(WID_SCL_MATRIX
);
768 LiveryScheme j
= (LiveryScheme
)((pt
.y
- wid
->pos_y
) / this->line_height
);
770 for (LiveryScheme scheme
= LS_BEGIN
; scheme
<= j
; scheme
++) {
771 if (_livery_class
[scheme
] != this->livery_class
|| !HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) j
++;
772 if (scheme
>= LS_END
) return;
774 if (j
>= LS_END
) return;
776 /* If clicking on the left edge, toggle using the livery */
777 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)) {
778 DoCommandP(0, j
| (2 << 8), !Company::Get((CompanyID
)this->window_number
)->livery
[j
].in_use
, CMD_SET_COMPANY_COLOUR
);
782 ToggleBit(this->sel
, j
);
792 virtual void OnDropdownSelect(int widget
, int index
)
794 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
795 /* Changed colour for the selected scheme, or all visible schemes if CTRL is pressed. */
796 if (HasBit(this->sel
, scheme
) || (_ctrl_pressed
&& _livery_class
[scheme
] == this->livery_class
&& HasBit(_loaded_newgrf_features
.used_liveries
, scheme
))) {
797 DoCommandP(0, scheme
| (widget
== WID_SCL_PRI_COL_DROPDOWN
? 0 : 256), index
, CMD_SET_COMPANY_COLOUR
);
803 * Some data on this window has become invalid.
804 * @param data Information about the changed data.
805 * @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.
807 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
809 if (!gui_scope
) return;
810 this->SetWidgetsDisabledState(true, WID_SCL_CLASS_RAIL
, WID_SCL_CLASS_ROAD
, WID_SCL_CLASS_SHIP
, WID_SCL_CLASS_AIRCRAFT
, WIDGET_LIST_END
);
812 bool current_class_valid
= this->livery_class
== LC_OTHER
;
813 if (_settings_client
.gui
.liveries
== LIT_ALL
|| (_settings_client
.gui
.liveries
== LIT_COMPANY
&& this->window_number
== _local_company
)) {
814 for (LiveryScheme scheme
= LS_DEFAULT
; scheme
< LS_END
; scheme
++) {
815 if (HasBit(_loaded_newgrf_features
.used_liveries
, scheme
)) {
816 if (_livery_class
[scheme
] == this->livery_class
) current_class_valid
= true;
817 this->EnableWidget(WID_SCL_CLASS_GENERAL
+ _livery_class
[scheme
]);
819 ClrBit(this->sel
, scheme
);
824 if (!current_class_valid
) {
826 this->OnClick(pt
, WID_SCL_CLASS_GENERAL
, 1);
827 } else if (data
== 0) {
833 static const NWidgetPart _nested_select_company_livery_widgets
[] = {
834 NWidget(NWID_HORIZONTAL
),
835 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
836 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_SCL_CAPTION
), SetDataTip(STR_LIVERY_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
838 NWidget(NWID_HORIZONTAL
),
839 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_GENERAL
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_COMPANY_GENERAL
, STR_LIVERY_GENERAL_TOOLTIP
),
840 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_RAIL
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST
, STR_LIVERY_TRAIN_TOOLTIP
),
841 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_ROAD
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRUCKLIST
, STR_LIVERY_ROAD_VEHICLE_TOOLTIP
),
842 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_SHIP
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SHIPLIST
, STR_LIVERY_SHIP_TOOLTIP
),
843 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCL_CLASS_AIRCRAFT
), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_AIRPLANESLIST
, STR_LIVERY_AIRCRAFT_TOOLTIP
),
844 NWidget(WWT_PANEL
, COLOUR_GREY
), SetMinimalSize(90, 22), SetFill(1, 1), EndContainer(),
846 NWidget(NWID_HORIZONTAL
),
847 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_SCL_SPACER_DROPDOWN
), SetMinimalSize(150, 12), SetFill(1, 1), EndContainer(),
848 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_SCL_PRI_COL_DROPDOWN
), SetMinimalSize(125, 12), SetFill(0, 1), SetDataTip(STR_BLACK_STRING
, STR_LIVERY_PRIMARY_TOOLTIP
),
849 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_SCL_SEC_COL_DROPDOWN
), SetMinimalSize(125, 12), SetFill(0, 1),
850 SetDataTip(STR_BLACK_STRING
, STR_LIVERY_SECONDARY_TOOLTIP
),
852 NWidget(WWT_MATRIX
, COLOUR_GREY
, WID_SCL_MATRIX
), SetMinimalSize(275, 15), SetFill(1, 0), SetMatrixDataTip(1, 1, STR_LIVERY_PANEL_TOOLTIP
),
855 static WindowDesc
_select_company_livery_desc(
856 WDP_AUTO
, "company_livery", 0, 0,
857 WC_COMPANY_COLOUR
, WC_NONE
,
859 _nested_select_company_livery_widgets
, lengthof(_nested_select_company_livery_widgets
)
863 * Draws the face of a company manager's face.
864 * @param cmf the company manager's face
865 * @param colour the (background) colour of the gradient
866 * @param x x-position to draw the face
867 * @param y y-position to draw the face
869 void DrawCompanyManagerFace(CompanyManagerFace cmf
, int colour
, int x
, int y
)
871 GenderEthnicity ge
= (GenderEthnicity
)GetCompanyManagerFaceBits(cmf
, CMFV_GEN_ETHN
, GE_WM
);
873 bool has_moustache
= !HasBit(ge
, GENDER_FEMALE
) && GetCompanyManagerFaceBits(cmf
, CMFV_HAS_MOUSTACHE
, ge
) != 0;
874 bool has_tie_earring
= !HasBit(ge
, GENDER_FEMALE
) || GetCompanyManagerFaceBits(cmf
, CMFV_HAS_TIE_EARRING
, ge
) != 0;
875 bool has_glasses
= GetCompanyManagerFaceBits(cmf
, CMFV_HAS_GLASSES
, ge
) != 0;
878 /* Modify eye colour palette only if 2 or more valid values exist */
879 if (_cmf_info
[CMFV_EYE_COLOUR
].valid_values
[ge
] < 2) {
882 switch (GetCompanyManagerFaceBits(cmf
, CMFV_EYE_COLOUR
, ge
)) {
883 default: NOT_REACHED();
884 case 0: pal
= PALETTE_TO_BROWN
; break;
885 case 1: pal
= PALETTE_TO_BLUE
; break;
886 case 2: pal
= PALETTE_TO_GREEN
; break;
890 /* Draw the gradient (background) */
891 DrawSprite(SPR_GRADIENT
, GENERAL_SPRITE_COLOUR(colour
), x
, y
);
893 for (CompanyManagerFaceVariable cmfv
= CMFV_CHEEKS
; cmfv
< CMFV_END
; cmfv
++) {
895 case CMFV_MOUSTACHE
: if (!has_moustache
) continue; break;
897 case CMFV_NOSE
: if (has_moustache
) continue; break;
898 case CMFV_TIE_EARRING
: if (!has_tie_earring
) continue; break;
899 case CMFV_GLASSES
: if (!has_glasses
) continue; break;
902 DrawSprite(GetCompanyManagerFaceSprite(cmf
, cmfv
, ge
), (cmfv
== CMFV_EYEBROWS
) ? pal
: PAL_NONE
, x
, y
);
906 /** Nested widget description for the company manager face selection dialog */
907 static const NWidgetPart _nested_select_company_manager_face_widgets
[] = {
908 NWidget(NWID_HORIZONTAL
),
909 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
910 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_SCMF_CAPTION
), SetDataTip(STR_FACE_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
911 NWidget(WWT_IMGBTN
, COLOUR_GREY
, WID_SCMF_TOGGLE_LARGE_SMALL
), SetDataTip(SPR_LARGE_SMALL_WINDOW
, STR_FACE_ADVANCED_TOOLTIP
),
913 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_SCMF_SELECT_FACE
),
914 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
915 NWidget(NWID_HORIZONTAL
), SetPIP(2, 2, 2),
916 NWidget(NWID_VERTICAL
),
917 NWidget(NWID_HORIZONTAL
),
918 NWidget(NWID_SPACER
), SetFill(1, 0),
919 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_SCMF_FACE
), SetMinimalSize(92, 119),
920 NWidget(NWID_SPACER
), SetFill(1, 0),
922 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
923 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_RANDOM_NEW_FACE
), SetFill(1, 0), SetDataTip(STR_FACE_NEW_FACE_BUTTON
, STR_FACE_NEW_FACE_TOOLTIP
),
924 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_LOADSAVE
), // Load/number/save buttons under the portrait in the advanced view.
925 NWidget(NWID_VERTICAL
),
926 NWidget(NWID_SPACER
), SetMinimalSize(0, 5), SetFill(0, 1),
927 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_LOAD
), SetFill(1, 0), SetDataTip(STR_FACE_LOAD
, STR_FACE_LOAD_TOOLTIP
),
928 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_FACECODE
), SetFill(1, 0), SetDataTip(STR_FACE_FACECODE
, STR_FACE_FACECODE_TOOLTIP
),
929 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_SAVE
), SetFill(1, 0), SetDataTip(STR_FACE_SAVE
, STR_FACE_SAVE_TOOLTIP
),
930 NWidget(NWID_SPACER
), SetMinimalSize(0, 5), SetFill(0, 1),
934 NWidget(NWID_VERTICAL
),
935 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
), SetFill(1, 0), SetDataTip(STR_FACE_ADVANCED
, STR_FACE_ADVANCED_TOOLTIP
),
936 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
937 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_MALEFEMALE
), // Simple male/female face setting.
938 NWidget(NWID_VERTICAL
),
939 NWidget(NWID_SPACER
), SetFill(0, 1),
940 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_MALE
), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON
, STR_FACE_MALE_TOOLTIP
),
941 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_FEMALE
), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON
, STR_FACE_FEMALE_TOOLTIP
),
942 NWidget(NWID_SPACER
), SetFill(0, 1),
945 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_SCMF_SEL_PARTS
), // Advanced face parts setting.
946 NWidget(NWID_VERTICAL
),
947 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
948 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
949 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_MALE2
), SetFill(1, 0), SetDataTip(STR_FACE_MALE_BUTTON
, STR_FACE_MALE_TOOLTIP
),
950 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_FEMALE2
), SetFill(1, 0), SetDataTip(STR_FACE_FEMALE_BUTTON
, STR_FACE_FEMALE_TOOLTIP
),
952 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
953 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
954 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_ETHNICITY_EUR
), SetFill(1, 0), SetDataTip(STR_FACE_EUROPEAN
, STR_FACE_SELECT_EUROPEAN
),
955 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_SCMF_ETHNICITY_AFR
), SetFill(1, 0), SetDataTip(STR_FACE_AFRICAN
, STR_FACE_SELECT_AFRICAN
),
957 NWidget(NWID_SPACER
), SetMinimalSize(0, 4),
958 NWidget(NWID_HORIZONTAL
),
959 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
), SetFill(1, 0),
960 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAS_MOUSTACHE_EARRING
), SetDataTip(STR_EMPTY
, STR_FACE_MOUSTACHE_EARRING_TOOLTIP
),
962 NWidget(NWID_HORIZONTAL
),
963 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAS_GLASSES_TEXT
), SetFill(1, 0),
964 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAS_GLASSES
), SetDataTip(STR_EMPTY
, STR_FACE_GLASSES_TOOLTIP
),
966 NWidget(NWID_SPACER
), SetMinimalSize(0, 2), SetFill(1, 0),
967 NWidget(NWID_HORIZONTAL
),
968 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_HAIR_TEXT
), SetFill(1, 0),
969 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_HAIR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_HAIR_TOOLTIP
),
970 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_HAIR
), SetDataTip(STR_EMPTY
, STR_FACE_HAIR_TOOLTIP
),
971 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_HAIR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_HAIR_TOOLTIP
),
973 NWidget(NWID_HORIZONTAL
),
974 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_EYEBROWS_TEXT
), SetFill(1, 0),
975 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS_L
), SetDataTip(AWV_DECREASE
, STR_FACE_EYEBROWS_TOOLTIP
),
976 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS
), SetDataTip(STR_EMPTY
, STR_FACE_EYEBROWS_TOOLTIP
),
977 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYEBROWS_R
), SetDataTip(AWV_INCREASE
, STR_FACE_EYEBROWS_TOOLTIP
),
979 NWidget(NWID_HORIZONTAL
),
980 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_EYECOLOUR_TEXT
), SetFill(1, 0),
981 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_EYECOLOUR_TOOLTIP
),
982 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR
), SetDataTip(STR_EMPTY
, STR_FACE_EYECOLOUR_TOOLTIP
),
983 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_EYECOLOUR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_EYECOLOUR_TOOLTIP
),
985 NWidget(NWID_HORIZONTAL
),
986 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_GLASSES_TEXT
), SetFill(1, 0),
987 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_GLASSES_L
), SetDataTip(AWV_DECREASE
, STR_FACE_GLASSES_TOOLTIP_2
),
988 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_GLASSES
), SetDataTip(STR_EMPTY
, STR_FACE_GLASSES_TOOLTIP_2
),
989 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_GLASSES_R
), SetDataTip(AWV_INCREASE
, STR_FACE_GLASSES_TOOLTIP_2
),
991 NWidget(NWID_HORIZONTAL
),
992 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_NOSE_TEXT
), SetFill(1, 0),
993 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_NOSE_L
), SetDataTip(AWV_DECREASE
, STR_FACE_NOSE_TOOLTIP
),
994 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_NOSE
), SetDataTip(STR_EMPTY
, STR_FACE_NOSE_TOOLTIP
),
995 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_NOSE_R
), SetDataTip(AWV_INCREASE
, STR_FACE_NOSE_TOOLTIP
),
997 NWidget(NWID_HORIZONTAL
),
998 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_LIPS_MOUSTACHE_TEXT
), SetFill(1, 0),
999 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE_L
), SetDataTip(AWV_DECREASE
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1000 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE
), SetDataTip(STR_EMPTY
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1001 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_LIPS_MOUSTACHE_R
), SetDataTip(AWV_INCREASE
, STR_FACE_LIPS_MOUSTACHE_TOOLTIP
),
1003 NWidget(NWID_HORIZONTAL
),
1004 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_CHIN_TEXT
), SetFill(1, 0),
1005 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_CHIN_L
), SetDataTip(AWV_DECREASE
, STR_FACE_CHIN_TOOLTIP
),
1006 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_CHIN
), SetDataTip(STR_EMPTY
, STR_FACE_CHIN_TOOLTIP
),
1007 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_CHIN_R
), SetDataTip(AWV_INCREASE
, STR_FACE_CHIN_TOOLTIP
),
1009 NWidget(NWID_HORIZONTAL
),
1010 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_JACKET_TEXT
), SetFill(1, 0),
1011 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_JACKET_L
), SetDataTip(AWV_DECREASE
, STR_FACE_JACKET_TOOLTIP
),
1012 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_JACKET
), SetDataTip(STR_EMPTY
, STR_FACE_JACKET_TOOLTIP
),
1013 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_JACKET_R
), SetDataTip(AWV_INCREASE
, STR_FACE_JACKET_TOOLTIP
),
1015 NWidget(NWID_HORIZONTAL
),
1016 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_COLLAR_TEXT
), SetFill(1, 0),
1017 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_COLLAR_L
), SetDataTip(AWV_DECREASE
, STR_FACE_COLLAR_TOOLTIP
),
1018 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_COLLAR
), SetDataTip(STR_EMPTY
, STR_FACE_COLLAR_TOOLTIP
),
1019 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_COLLAR_R
), SetDataTip(AWV_INCREASE
, STR_FACE_COLLAR_TOOLTIP
),
1021 NWidget(NWID_HORIZONTAL
),
1022 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_SCMF_TIE_EARRING_TEXT
), SetFill(1, 0),
1023 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING_L
), SetDataTip(AWV_DECREASE
, STR_FACE_TIE_EARRING_TOOLTIP
),
1024 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING
), SetDataTip(STR_EMPTY
, STR_FACE_TIE_EARRING_TOOLTIP
),
1025 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_SCMF_TIE_EARRING_R
), SetDataTip(AWV_INCREASE
, STR_FACE_TIE_EARRING_TOOLTIP
),
1027 NWidget(NWID_SPACER
), SetFill(0, 1),
1032 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1034 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1035 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_CANCEL
), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL
, STR_FACE_CANCEL_TOOLTIP
),
1036 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SCMF_ACCEPT
), SetFill(1, 0), SetDataTip(STR_BUTTON_OK
, STR_FACE_OK_TOOLTIP
),
1040 /** Management class for customizing the face of the company manager. */
1041 class SelectCompanyManagerFaceWindow
: public Window
1043 CompanyManagerFace face
; ///< company manager face bits
1044 bool advanced
; ///< advanced company manager face selection window
1046 GenderEthnicity ge
; ///< Gender and ethnicity.
1047 bool is_female
; ///< Female face.
1048 bool is_moust_male
; ///< Male face with a moustache.
1050 Dimension yesno_dim
; ///< Dimension of a yes/no button of a part in the advanced face window.
1051 Dimension number_dim
; ///< Dimension of a number widget of a part in the advanced face window.
1053 static const StringID PART_TEXTS_IS_FEMALE
[]; ///< Strings depending on #is_female, used to describe parts (2 entries for a part).
1054 static const StringID PART_TEXTS
[]; ///< Fixed strings to describe parts of the face.
1057 * Draw dynamic a label to the left of the button and a value in the button
1059 * @param widget_index index of this widget in the window
1060 * @param val the value which will be draw
1061 * @param is_bool_widget is it a bool button
1063 void DrawFaceStringLabel(byte widget_index
, uint8 val
, bool is_bool_widget
) const
1066 const NWidgetCore
*nwi_widget
= this->GetWidget
<NWidgetCore
>(widget_index
);
1067 if (!nwi_widget
->IsDisabled()) {
1068 if (is_bool_widget
) {
1069 /* if it a bool button write yes or no */
1070 str
= (val
!= 0) ? STR_FACE_YES
: STR_FACE_NO
;
1072 /* else write the value + 1 */
1073 SetDParam(0, val
+ 1);
1077 /* Draw the value/bool in white (0xC). If the button clicked adds 1px to x and y text coordinates (IsWindowWidgetLowered()). */
1078 DrawString(nwi_widget
->pos_x
+ nwi_widget
->IsLowered(), nwi_widget
->pos_x
+ nwi_widget
->current_x
- 1 - nwi_widget
->IsLowered(),
1079 nwi_widget
->pos_y
+ 1 + nwi_widget
->IsLowered(), str
, TC_WHITE
, SA_HOR_CENTER
);
1085 this->ge
= (GenderEthnicity
)GB(this->face
, _cmf_info
[CMFV_GEN_ETHN
].offset
, _cmf_info
[CMFV_GEN_ETHN
].length
); // get the gender and ethnicity
1086 this->is_female
= HasBit(this->ge
, GENDER_FEMALE
); // get the gender: 0 == male and 1 == female
1087 this->is_moust_male
= !is_female
&& GetCompanyManagerFaceBits(this->face
, CMFV_HAS_MOUSTACHE
, this->ge
) != 0; // is a male face with moustache
1091 SelectCompanyManagerFaceWindow(WindowDesc
*desc
, Window
*parent
) : Window(desc
)
1093 this->advanced
= false;
1094 this->CreateNestedTree();
1095 this->SelectDisplayPlanes(this->advanced
);
1096 this->FinishInitNested(parent
->window_number
);
1097 this->parent
= parent
;
1098 this->owner
= (Owner
)this->window_number
;
1099 this->face
= Company::Get((CompanyID
)this->window_number
)->face
;
1105 * 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.
1106 * @param advanced Display advanced face management window.
1108 void SelectDisplayPlanes(bool advanced
)
1110 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_LOADSAVE
)->SetDisplayedPlane(advanced
? 0 : SZSP_NONE
);
1111 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_PARTS
)->SetDisplayedPlane(advanced
? 0 : SZSP_NONE
);
1112 this->GetWidget
<NWidgetStacked
>(WID_SCMF_SEL_MALEFEMALE
)->SetDisplayedPlane(advanced
? SZSP_NONE
: 0);
1113 this->GetWidget
<NWidgetCore
>(WID_SCMF_RANDOM_NEW_FACE
)->widget_data
= advanced
? STR_FACE_RANDOM
: STR_FACE_NEW_FACE_BUTTON
;
1115 NWidgetCore
*wi
= this->GetWidget
<NWidgetCore
>(WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
);
1117 wi
->SetDataTip(STR_FACE_SIMPLE
, STR_FACE_SIMPLE_TOOLTIP
);
1119 wi
->SetDataTip(STR_FACE_ADVANCED
, STR_FACE_ADVANCED_TOOLTIP
);
1123 virtual void OnInit()
1125 /* Size of the boolean yes/no button. */
1126 Dimension yesno_dim
= maxdim(GetStringBoundingBox(STR_FACE_YES
), GetStringBoundingBox(STR_FACE_NO
));
1127 yesno_dim
.width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1128 yesno_dim
.height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1129 /* Size of the number button + arrows. */
1130 Dimension number_dim
= {0, 0};
1131 for (int val
= 1; val
<= 12; val
++) {
1133 number_dim
= maxdim(number_dim
, GetStringBoundingBox(STR_JUST_INT
));
1135 uint arrows_width
= GetSpriteSize(SPR_ARROW_LEFT
).width
+ GetSpriteSize(SPR_ARROW_RIGHT
).width
+ 2 * (WD_IMGBTN_LEFT
+ WD_IMGBTN_RIGHT
);
1136 number_dim
.width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
+ arrows_width
;
1137 number_dim
.height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1138 /* Compute width of both buttons. */
1139 yesno_dim
.width
= max(yesno_dim
.width
, number_dim
.width
);
1140 number_dim
.width
= yesno_dim
.width
- arrows_width
;
1142 this->yesno_dim
= yesno_dim
;
1143 this->number_dim
= number_dim
;
1146 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1149 case WID_SCMF_FACE
: {
1150 Dimension face_size
= GetSpriteSize(SPR_GRADIENT
);
1151 size
->width
= max(size
->width
, face_size
.width
);
1152 size
->height
= max(size
->height
, face_size
.height
);
1156 case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
:
1157 case WID_SCMF_TIE_EARRING_TEXT
: {
1158 int offset
= (widget
- WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
) * 2;
1159 *size
= maxdim(GetStringBoundingBox(PART_TEXTS_IS_FEMALE
[offset
]), GetStringBoundingBox(PART_TEXTS_IS_FEMALE
[offset
+ 1]));
1160 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1161 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1165 case WID_SCMF_LIPS_MOUSTACHE_TEXT
:
1166 *size
= maxdim(GetStringBoundingBox(STR_FACE_LIPS
), GetStringBoundingBox(STR_FACE_MOUSTACHE
));
1167 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1168 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1171 case WID_SCMF_HAS_GLASSES_TEXT
:
1172 case WID_SCMF_HAIR_TEXT
:
1173 case WID_SCMF_EYEBROWS_TEXT
:
1174 case WID_SCMF_EYECOLOUR_TEXT
:
1175 case WID_SCMF_GLASSES_TEXT
:
1176 case WID_SCMF_NOSE_TEXT
:
1177 case WID_SCMF_CHIN_TEXT
:
1178 case WID_SCMF_JACKET_TEXT
:
1179 case WID_SCMF_COLLAR_TEXT
:
1180 *size
= GetStringBoundingBox(PART_TEXTS
[widget
- WID_SCMF_HAS_GLASSES_TEXT
]);
1181 size
->width
+= WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
;
1182 size
->height
+= WD_FRAMERECT_TOP
+ WD_FRAMERECT_BOTTOM
;
1185 case WID_SCMF_HAS_MOUSTACHE_EARRING
:
1186 case WID_SCMF_HAS_GLASSES
:
1187 *size
= this->yesno_dim
;
1190 case WID_SCMF_EYECOLOUR
:
1192 case WID_SCMF_EYEBROWS
:
1193 case WID_SCMF_LIPS_MOUSTACHE
:
1196 case WID_SCMF_JACKET
:
1197 case WID_SCMF_COLLAR
:
1198 case WID_SCMF_TIE_EARRING
:
1199 case WID_SCMF_GLASSES
:
1200 *size
= this->number_dim
;
1205 virtual void OnPaint()
1207 /* lower the non-selected gender button */
1208 this->SetWidgetsLoweredState(!this->is_female
, WID_SCMF_MALE
, WID_SCMF_MALE2
, WIDGET_LIST_END
);
1209 this->SetWidgetsLoweredState( this->is_female
, WID_SCMF_FEMALE
, WID_SCMF_FEMALE2
, WIDGET_LIST_END
);
1211 /* advanced company manager face selection window */
1213 /* lower the non-selected ethnicity button */
1214 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_EUR
, !HasBit(this->ge
, ETHNICITY_BLACK
));
1215 this->SetWidgetLoweredState(WID_SCMF_ETHNICITY_AFR
, HasBit(this->ge
, ETHNICITY_BLACK
));
1218 /* Disable dynamically the widgets which CompanyManagerFaceVariable has less than 2 options
1219 * (or in other words you haven't any choice).
1220 * If the widgets depend on a HAS-variable and this is false the widgets will be disabled, too. */
1222 /* Eye colour buttons */
1223 this->SetWidgetsDisabledState(_cmf_info
[CMFV_EYE_COLOUR
].valid_values
[this->ge
] < 2,
1224 WID_SCMF_EYECOLOUR
, WID_SCMF_EYECOLOUR_L
, WID_SCMF_EYECOLOUR_R
, WIDGET_LIST_END
);
1227 this->SetWidgetsDisabledState(_cmf_info
[CMFV_CHIN
].valid_values
[this->ge
] < 2,
1228 WID_SCMF_CHIN
, WID_SCMF_CHIN_L
, WID_SCMF_CHIN_R
, WIDGET_LIST_END
);
1230 /* Eyebrows buttons */
1231 this->SetWidgetsDisabledState(_cmf_info
[CMFV_EYEBROWS
].valid_values
[this->ge
] < 2,
1232 WID_SCMF_EYEBROWS
, WID_SCMF_EYEBROWS_L
, WID_SCMF_EYEBROWS_R
, WIDGET_LIST_END
);
1234 /* Lips or (if it a male face with a moustache) moustache buttons */
1235 this->SetWidgetsDisabledState(_cmf_info
[this->is_moust_male
? CMFV_MOUSTACHE
: CMFV_LIPS
].valid_values
[this->ge
] < 2,
1236 WID_SCMF_LIPS_MOUSTACHE
, WID_SCMF_LIPS_MOUSTACHE_L
, WID_SCMF_LIPS_MOUSTACHE_R
, WIDGET_LIST_END
);
1238 /* Nose buttons | male faces with moustache haven't any nose options */
1239 this->SetWidgetsDisabledState(_cmf_info
[CMFV_NOSE
].valid_values
[this->ge
] < 2 || this->is_moust_male
,
1240 WID_SCMF_NOSE
, WID_SCMF_NOSE_L
, WID_SCMF_NOSE_R
, WIDGET_LIST_END
);
1243 this->SetWidgetsDisabledState(_cmf_info
[CMFV_HAIR
].valid_values
[this->ge
] < 2,
1244 WID_SCMF_HAIR
, WID_SCMF_HAIR_L
, WID_SCMF_HAIR_R
, WIDGET_LIST_END
);
1246 /* Jacket buttons */
1247 this->SetWidgetsDisabledState(_cmf_info
[CMFV_JACKET
].valid_values
[this->ge
] < 2,
1248 WID_SCMF_JACKET
, WID_SCMF_JACKET_L
, WID_SCMF_JACKET_R
, WIDGET_LIST_END
);
1250 /* Collar buttons */
1251 this->SetWidgetsDisabledState(_cmf_info
[CMFV_COLLAR
].valid_values
[this->ge
] < 2,
1252 WID_SCMF_COLLAR
, WID_SCMF_COLLAR_L
, WID_SCMF_COLLAR_R
, WIDGET_LIST_END
);
1254 /* Tie/earring buttons | female faces without earring haven't any earring options */
1255 this->SetWidgetsDisabledState(_cmf_info
[CMFV_TIE_EARRING
].valid_values
[this->ge
] < 2 ||
1256 (this->is_female
&& GetCompanyManagerFaceBits(this->face
, CMFV_HAS_TIE_EARRING
, this->ge
) == 0),
1257 WID_SCMF_TIE_EARRING
, WID_SCMF_TIE_EARRING_L
, WID_SCMF_TIE_EARRING_R
, WIDGET_LIST_END
);
1259 /* Glasses buttons | faces without glasses haven't any glasses options */
1260 this->SetWidgetsDisabledState(_cmf_info
[CMFV_GLASSES
].valid_values
[this->ge
] < 2 || GetCompanyManagerFaceBits(this->face
, CMFV_HAS_GLASSES
, this->ge
) == 0,
1261 WID_SCMF_GLASSES
, WID_SCMF_GLASSES_L
, WID_SCMF_GLASSES_R
, WIDGET_LIST_END
);
1263 this->DrawWidgets();
1266 virtual void DrawWidget(const Rect
&r
, int widget
) const
1269 case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
:
1270 case WID_SCMF_TIE_EARRING_TEXT
: {
1271 StringID str
= PART_TEXTS_IS_FEMALE
[(widget
- WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
) * 2 + this->is_female
];
1272 DrawString(r
.left
+ WD_FRAMERECT_LEFT
, r
.right
- WD_FRAMERECT_RIGHT
, r
.top
+ WD_FRAMERECT_TOP
, str
, TC_GOLD
, SA_RIGHT
);
1276 case WID_SCMF_LIPS_MOUSTACHE_TEXT
:
1277 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
);
1280 case WID_SCMF_HAS_GLASSES_TEXT
:
1281 case WID_SCMF_HAIR_TEXT
:
1282 case WID_SCMF_EYEBROWS_TEXT
:
1283 case WID_SCMF_EYECOLOUR_TEXT
:
1284 case WID_SCMF_GLASSES_TEXT
:
1285 case WID_SCMF_NOSE_TEXT
:
1286 case WID_SCMF_CHIN_TEXT
:
1287 case WID_SCMF_JACKET_TEXT
:
1288 case WID_SCMF_COLLAR_TEXT
:
1289 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
);
1293 case WID_SCMF_HAS_MOUSTACHE_EARRING
:
1294 if (this->is_female
) { // Only for female faces
1295 this->DrawFaceStringLabel(WID_SCMF_HAS_MOUSTACHE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_TIE_EARRING
, this->ge
), true);
1296 } else { // Only for male faces
1297 this->DrawFaceStringLabel(WID_SCMF_HAS_MOUSTACHE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_MOUSTACHE
, this->ge
), true);
1301 case WID_SCMF_TIE_EARRING
:
1302 this->DrawFaceStringLabel(WID_SCMF_TIE_EARRING
, GetCompanyManagerFaceBits(this->face
, CMFV_TIE_EARRING
, this->ge
), false);
1305 case WID_SCMF_LIPS_MOUSTACHE
:
1306 if (this->is_moust_male
) { // Only for male faces with moustache
1307 this->DrawFaceStringLabel(WID_SCMF_LIPS_MOUSTACHE
, GetCompanyManagerFaceBits(this->face
, CMFV_MOUSTACHE
, this->ge
), false);
1308 } else { // Only for female faces or male faces without moustache
1309 this->DrawFaceStringLabel(WID_SCMF_LIPS_MOUSTACHE
, GetCompanyManagerFaceBits(this->face
, CMFV_LIPS
, this->ge
), false);
1313 case WID_SCMF_HAS_GLASSES
:
1314 this->DrawFaceStringLabel(WID_SCMF_HAS_GLASSES
, GetCompanyManagerFaceBits(this->face
, CMFV_HAS_GLASSES
, this->ge
), true );
1318 this->DrawFaceStringLabel(WID_SCMF_HAIR
, GetCompanyManagerFaceBits(this->face
, CMFV_HAIR
, this->ge
), false);
1321 case WID_SCMF_EYEBROWS
:
1322 this->DrawFaceStringLabel(WID_SCMF_EYEBROWS
, GetCompanyManagerFaceBits(this->face
, CMFV_EYEBROWS
, this->ge
), false);
1325 case WID_SCMF_EYECOLOUR
:
1326 this->DrawFaceStringLabel(WID_SCMF_EYECOLOUR
, GetCompanyManagerFaceBits(this->face
, CMFV_EYE_COLOUR
, this->ge
), false);
1329 case WID_SCMF_GLASSES
:
1330 this->DrawFaceStringLabel(WID_SCMF_GLASSES
, GetCompanyManagerFaceBits(this->face
, CMFV_GLASSES
, this->ge
), false);
1334 this->DrawFaceStringLabel(WID_SCMF_NOSE
, GetCompanyManagerFaceBits(this->face
, CMFV_NOSE
, this->ge
), false);
1338 this->DrawFaceStringLabel(WID_SCMF_CHIN
, GetCompanyManagerFaceBits(this->face
, CMFV_CHIN
, this->ge
), false);
1341 case WID_SCMF_JACKET
:
1342 this->DrawFaceStringLabel(WID_SCMF_JACKET
, GetCompanyManagerFaceBits(this->face
, CMFV_JACKET
, this->ge
), false);
1345 case WID_SCMF_COLLAR
:
1346 this->DrawFaceStringLabel(WID_SCMF_COLLAR
, GetCompanyManagerFaceBits(this->face
, CMFV_COLLAR
, this->ge
), false);
1350 DrawCompanyManagerFace(this->face
, Company::Get((CompanyID
)this->window_number
)->colour
, r
.left
, r
.top
);
1355 virtual void OnClick(Point pt
, int widget
, int click_count
)
1358 /* Toggle size, advanced/simple face selection */
1359 case WID_SCMF_TOGGLE_LARGE_SMALL
:
1360 case WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON
:
1361 this->advanced
= !this->advanced
;
1362 this->SelectDisplayPlanes(this->advanced
);
1367 case WID_SCMF_ACCEPT
:
1368 DoCommandP(0, 0, this->face
, CMD_SET_COMPANY_MANAGER_FACE
);
1372 case WID_SCMF_CANCEL
:
1378 this->face
= _company_manager_face
;
1379 ScaleAllCompanyManagerFaceBits(this->face
);
1380 ShowErrorMessage(STR_FACE_LOAD_DONE
, INVALID_STRING_ID
, WL_INFO
);
1385 /* 'Company manager face number' button, view and/or set company manager face number */
1386 case WID_SCMF_FACECODE
:
1387 SetDParam(0, this->face
);
1388 ShowQueryString(STR_JUST_INT
, STR_FACE_FACECODE_CAPTION
, 10 + 1, this, CS_NUMERAL
, QSF_NONE
);
1393 _company_manager_face
= this->face
;
1394 ShowErrorMessage(STR_FACE_SAVE_DONE
, INVALID_STRING_ID
, WL_INFO
);
1397 /* Toggle gender (male/female) button */
1399 case WID_SCMF_FEMALE
:
1400 case WID_SCMF_MALE2
:
1401 case WID_SCMF_FEMALE2
:
1402 SetCompanyManagerFaceBits(this->face
, CMFV_GENDER
, this->ge
, (widget
== WID_SCMF_FEMALE
|| widget
== WID_SCMF_FEMALE2
));
1403 ScaleAllCompanyManagerFaceBits(this->face
);
1408 /* Randomize face button */
1409 case WID_SCMF_RANDOM_NEW_FACE
:
1410 RandomCompanyManagerFaceBits(this->face
, this->ge
, this->advanced
);
1415 /* Toggle ethnicity (european/african) button */
1416 case WID_SCMF_ETHNICITY_EUR
:
1417 case WID_SCMF_ETHNICITY_AFR
:
1418 SetCompanyManagerFaceBits(this->face
, CMFV_ETHNICITY
, this->ge
, widget
- WID_SCMF_ETHNICITY_EUR
);
1419 ScaleAllCompanyManagerFaceBits(this->face
);
1425 /* Here all buttons from WID_SCMF_HAS_MOUSTACHE_EARRING to WID_SCMF_GLASSES_R are handled.
1426 * First it checks which CompanyManagerFaceVariable is being changed, and then either
1427 * a: invert the value for boolean variables, or
1428 * b: it checks inside of IncreaseCompanyManagerFaceBits() if a left (_L) butten is pressed and then decrease else increase the variable */
1429 if (widget
>= WID_SCMF_HAS_MOUSTACHE_EARRING
&& widget
<= WID_SCMF_GLASSES_R
) {
1430 CompanyManagerFaceVariable cmfv
; // which CompanyManagerFaceVariable shall be edited
1432 if (widget
< WID_SCMF_EYECOLOUR_L
) { // Bool buttons
1433 switch (widget
- WID_SCMF_HAS_MOUSTACHE_EARRING
) {
1434 default: NOT_REACHED();
1435 case 0: cmfv
= this->is_female
? CMFV_HAS_TIE_EARRING
: CMFV_HAS_MOUSTACHE
; break; // Has earring/moustache button
1436 case 1: cmfv
= CMFV_HAS_GLASSES
; break; // Has glasses button
1438 SetCompanyManagerFaceBits(this->face
, cmfv
, this->ge
, !GetCompanyManagerFaceBits(this->face
, cmfv
, this->ge
));
1439 ScaleAllCompanyManagerFaceBits(this->face
);
1440 } else { // Value buttons
1441 switch ((widget
- WID_SCMF_EYECOLOUR_L
) / 3) {
1442 default: NOT_REACHED();
1443 case 0: cmfv
= CMFV_EYE_COLOUR
; break; // Eye colour buttons
1444 case 1: cmfv
= CMFV_CHIN
; break; // Chin buttons
1445 case 2: cmfv
= CMFV_EYEBROWS
; break; // Eyebrows buttons
1446 case 3: cmfv
= this->is_moust_male
? CMFV_MOUSTACHE
: CMFV_LIPS
; break; // Moustache or lips buttons
1447 case 4: cmfv
= CMFV_NOSE
; break; // Nose buttons
1448 case 5: cmfv
= CMFV_HAIR
; break; // Hair buttons
1449 case 6: cmfv
= CMFV_JACKET
; break; // Jacket buttons
1450 case 7: cmfv
= CMFV_COLLAR
; break; // Collar buttons
1451 case 8: cmfv
= CMFV_TIE_EARRING
; break; // Tie/earring buttons
1452 case 9: cmfv
= CMFV_GLASSES
; break; // Glasses buttons
1454 /* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
1455 IncreaseCompanyManagerFaceBits(this->face
, cmfv
, this->ge
, (((widget
- WID_SCMF_EYECOLOUR_L
) % 3) != 0) ? 1 : -1);
1464 virtual void OnQueryTextFinished(char *str
)
1466 if (str
== NULL
) return;
1467 /* Set a new company manager face number */
1468 if (!StrEmpty(str
)) {
1469 this->face
= strtoul(str
, NULL
, 10);
1470 ScaleAllCompanyManagerFaceBits(this->face
);
1471 ShowErrorMessage(STR_FACE_FACECODE_SET
, INVALID_STRING_ID
, WL_INFO
);
1475 ShowErrorMessage(STR_FACE_FACECODE_ERR
, INVALID_STRING_ID
, WL_INFO
);
1480 /** Both text values of parts of the face that depend on the #is_female boolean value. */
1481 const StringID
SelectCompanyManagerFaceWindow::PART_TEXTS_IS_FEMALE
[] = {
1482 STR_FACE_MOUSTACHE
, STR_FACE_EARRING
, // WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT
1483 STR_FACE_TIE
, STR_FACE_EARRING
, // WID_SCMF_TIE_EARRING_TEXT
1486 /** Textual names for parts of the face. */
1487 const StringID
SelectCompanyManagerFaceWindow::PART_TEXTS
[] = {
1488 STR_FACE_GLASSES
, // WID_SCMF_HAS_GLASSES_TEXT
1489 STR_FACE_HAIR
, // WID_SCMF_HAIR_TEXT
1490 STR_FACE_EYEBROWS
, // WID_SCMF_EYEBROWS_TEXT
1491 STR_FACE_EYECOLOUR
, // WID_SCMF_EYECOLOUR_TEXT
1492 STR_FACE_GLASSES
, // WID_SCMF_GLASSES_TEXT
1493 STR_FACE_NOSE
, // WID_SCMF_NOSE_TEXT
1494 STR_FACE_CHIN
, // WID_SCMF_CHIN_TEXT
1495 STR_FACE_JACKET
, // WID_SCMF_JACKET_TEXT
1496 STR_FACE_COLLAR
, // WID_SCMF_COLLAR_TEXT
1499 /** Company manager face selection window description */
1500 static WindowDesc
_select_company_manager_face_desc(
1501 WDP_AUTO
, "company_face", 0, 0,
1502 WC_COMPANY_MANAGER_FACE
, WC_NONE
,
1504 _nested_select_company_manager_face_widgets
, lengthof(_nested_select_company_manager_face_widgets
)
1508 * Open the simple/advanced company manager face selection window
1510 * @param parent the parent company window
1511 * @param adv simple or advanced face selection window
1512 * @param top previous top position of the window
1513 * @param left previous left position of the window
1515 static void DoSelectCompanyManagerFace(Window
*parent
)
1517 if (!Company::IsValidID((CompanyID
)parent
->window_number
)) return;
1519 if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE
, parent
->window_number
)) return;
1520 new SelectCompanyManagerFaceWindow(&_select_company_manager_face_desc
, parent
);
1523 static const NWidgetPart _nested_company_infrastructure_widgets
[] = {
1524 NWidget(NWID_HORIZONTAL
),
1525 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1526 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_CI_CAPTION
), SetDataTip(STR_COMPANY_INFRASTRUCTURE_VIEW_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1527 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1528 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1530 NWidget(WWT_PANEL
, COLOUR_GREY
),
1531 NWidget(NWID_VERTICAL
), SetPIP(WD_FRAMERECT_TOP
, 4, WD_FRAMETEXT_BOTTOM
),
1532 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1533 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_RAIL_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1534 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_RAIL_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1536 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1537 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_ROAD_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1538 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_ROAD_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1540 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1541 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_WATER_DESC
), SetMinimalTextLines(2, 0), SetFill(1, 0),
1542 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_WATER_COUNT
), SetMinimalTextLines(2, 0), SetFill(0, 1),
1544 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1545 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_STATION_DESC
), SetMinimalTextLines(3, 0), SetFill(1, 0),
1546 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_STATION_COUNT
), SetMinimalTextLines(3, 0), SetFill(0, 1),
1548 NWidget(NWID_HORIZONTAL
), SetPIP(2, 4, 2),
1549 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TOTAL_DESC
), SetFill(1, 0),
1550 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_CI_TOTAL
), SetFill(0, 1),
1557 * Window with detailed information about the company's infrastructure.
1559 struct CompanyInfrastructureWindow
: Window
1561 RailTypes railtypes
; ///< Valid railtypes.
1562 RoadTypes roadtypes
; ///< Valid roadtypes.
1564 uint total_width
; ///< String width of the total cost line.
1566 CompanyInfrastructureWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
1568 this->UpdateRailRoadTypes();
1570 this->InitNested(window_number
);
1571 this->owner
= (Owner
)this->window_number
;
1574 void UpdateRailRoadTypes()
1576 this->railtypes
= RAILTYPES_NONE
;
1577 this->roadtypes
= ROADTYPES_ROAD
; // Road is always available.
1579 /* Find the used railtypes. */
1581 FOR_ALL_ENGINES_OF_TYPE(e
, VEH_TRAIN
) {
1582 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
1584 this->railtypes
|= GetRailTypeInfo(e
->u
.rail
.railtype
)->introduces_railtypes
;
1587 /* Get the date introduced railtypes as well. */
1588 this->railtypes
= AddDateIntroducedRailTypes(this->railtypes
, MAX_DAY
);
1590 /* Tram is only visible when there will be a tram. */
1591 FOR_ALL_ENGINES_OF_TYPE(e
, VEH_ROAD
) {
1592 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
1593 if (!HasBit(e
->info
.misc_flags
, EF_ROAD_TRAM
)) continue;
1595 this->roadtypes
|= ROADTYPES_TRAM
;
1600 /** Get total infrastructure maintenance cost. */
1601 Money
GetTotalMaintenanceCost() const
1603 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
1606 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
1607 for (RailType rt
= RAILTYPE_BEGIN
; rt
!= RAILTYPE_END
; rt
++) {
1608 if (HasBit(this->railtypes
, rt
)) total
+= RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
);
1610 total
+= SignalMaintenanceCost(c
->infrastructure
.signal
);
1612 if (HasBit(this->roadtypes
, ROADTYPE_ROAD
)) total
+= RoadMaintenanceCost(ROADTYPE_ROAD
, c
->infrastructure
.road
[ROADTYPE_ROAD
]);
1613 if (HasBit(this->roadtypes
, ROADTYPE_TRAM
)) total
+= RoadMaintenanceCost(ROADTYPE_TRAM
, c
->infrastructure
.road
[ROADTYPE_TRAM
]);
1615 total
+= CanalMaintenanceCost(c
->infrastructure
.water
);
1616 total
+= StationMaintenanceCost(c
->infrastructure
.station
);
1617 total
+= AirportMaintenanceCost(c
->index
);
1622 virtual void SetStringParameters(int widget
) const
1625 case WID_CI_CAPTION
:
1626 SetDParam(0, (CompanyID
)this->window_number
);
1631 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1633 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
1636 case WID_CI_RAIL_DESC
: {
1639 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT
).width
);
1641 for (RailType rt
= RAILTYPE_BEGIN
; rt
< RAILTYPE_END
; rt
++) {
1642 if (HasBit(this->railtypes
, rt
)) {
1644 SetDParam(0, GetRailTypeInfo(rt
)->strings
.name
);
1645 size
->width
= max(size
->width
, GetStringBoundingBox(STR_WHITE_STRING
).width
+ WD_FRAMERECT_LEFT
);
1648 if (this->railtypes
!= RAILTYPES_NONE
) {
1650 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS
).width
+ WD_FRAMERECT_LEFT
);
1653 size
->height
= max(size
->height
, lines
* FONT_HEIGHT_NORMAL
);
1657 case WID_CI_ROAD_DESC
: {
1660 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT
).width
);
1662 if (HasBit(this->roadtypes
, ROADTYPE_ROAD
)) {
1664 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD
).width
+ WD_FRAMERECT_LEFT
);
1666 if (HasBit(this->roadtypes
, ROADTYPE_TRAM
)) {
1668 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TRAMWAY
).width
+ WD_FRAMERECT_LEFT
);
1671 size
->height
= max(size
->height
, lines
* FONT_HEIGHT_NORMAL
);
1675 case WID_CI_WATER_DESC
:
1676 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT
).width
);
1677 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS
).width
+ WD_FRAMERECT_LEFT
);
1680 case WID_CI_STATION_DESC
:
1681 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT
).width
);
1682 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS
).width
+ WD_FRAMERECT_LEFT
);
1683 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS
).width
+ WD_FRAMERECT_LEFT
);
1686 case WID_CI_RAIL_COUNT
:
1687 case WID_CI_ROAD_COUNT
:
1688 case WID_CI_WATER_COUNT
:
1689 case WID_CI_STATION_COUNT
:
1690 case WID_CI_TOTAL
: {
1691 /* Find the maximum count that is displayed. */
1692 uint32 max_val
= 1000; // Some random number to reserve enough space.
1693 Money max_cost
= 10000; // Some random number to reserve enough space.
1694 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
1695 for (RailType rt
= RAILTYPE_BEGIN
; rt
< RAILTYPE_END
; rt
++) {
1696 max_val
= max(max_val
, c
->infrastructure
.rail
[rt
]);
1697 max_cost
= max(max_cost
, RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
));
1699 max_val
= max(max_val
, c
->infrastructure
.signal
);
1700 max_cost
= max(max_cost
, SignalMaintenanceCost(c
->infrastructure
.signal
));
1701 for (RoadType rt
= ROADTYPE_BEGIN
; rt
< ROADTYPE_END
; rt
++) {
1702 max_val
= max(max_val
, c
->infrastructure
.road
[rt
]);
1703 max_cost
= max(max_cost
, RoadMaintenanceCost(rt
, c
->infrastructure
.road
[rt
]));
1705 max_val
= max(max_val
, c
->infrastructure
.water
);
1706 max_cost
= max(max_cost
, CanalMaintenanceCost(c
->infrastructure
.water
));
1707 max_val
= max(max_val
, c
->infrastructure
.station
);
1708 max_cost
= max(max_cost
, StationMaintenanceCost(c
->infrastructure
.station
));
1709 max_val
= max(max_val
, c
->infrastructure
.airport
);
1710 max_cost
= max(max_cost
, AirportMaintenanceCost(c
->index
));
1712 SetDParamMaxValue(0, max_val
);
1713 uint count_width
= GetStringBoundingBox(STR_WHITE_COMMA
).width
+ 20; // Reserve some wiggle room
1715 if (_settings_game
.economy
.infrastructure_maintenance
) {
1716 SetDParamMaxValue(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
1717 this->total_width
= GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
).width
+ 20;
1718 size
->width
= max(size
->width
, this->total_width
);
1720 SetDParamMaxValue(0, max_cost
* 12); // Convert to per year
1721 count_width
+= max(this->total_width
, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
).width
);
1724 size
->width
= max(size
->width
, count_width
);
1726 /* Set height of the total line. */
1727 if (widget
== WID_CI_TOTAL
) {
1728 size
->height
= _settings_game
.economy
.infrastructure_maintenance
? max(size
->height
, EXP_LINESPACE
+ FONT_HEIGHT_NORMAL
) : 0;
1736 * Helper for drawing the counts line.
1737 * @param r The bounds to draw in.
1738 * @param y The y position to draw at.
1739 * @param count The count to show on this line.
1740 * @param monthly_cost The monthly costs.
1742 void DrawCountLine(const Rect
&r
, int &y
, int count
, Money monthly_cost
) const
1744 SetDParam(0, count
);
1745 DrawString(r
.left
, r
.right
, y
+= FONT_HEIGHT_NORMAL
, STR_WHITE_COMMA
, TC_FROMSTRING
, SA_RIGHT
);
1747 if (_settings_game
.economy
.infrastructure_maintenance
) {
1748 SetDParam(0, monthly_cost
* 12); // Convert to per year
1749 int left
= _current_text_dir
== TD_RTL
? r
.right
- this->total_width
: r
.left
;
1750 DrawString(left
, left
+ this->total_width
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
, TC_FROMSTRING
, SA_RIGHT
);
1754 virtual void DrawWidget(const Rect
&r
, int widget
) const
1756 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
1759 int offs_left
= _current_text_dir
== TD_LTR
? WD_FRAMERECT_LEFT
: 0;
1760 int offs_right
= _current_text_dir
== TD_LTR
? 0 : WD_FRAMERECT_LEFT
;
1763 case WID_CI_RAIL_DESC
:
1764 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT
);
1766 if (this->railtypes
!= RAILTYPES_NONE
) {
1767 /* Draw name of each valid railtype. */
1769 FOR_ALL_SORTED_RAILTYPES(rt
) {
1770 if (HasBit(this->railtypes
, rt
)) {
1771 SetDParam(0, GetRailTypeInfo(rt
)->strings
.name
);
1772 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_WHITE_STRING
);
1775 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS
);
1777 /* No valid railtype. */
1778 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
);
1783 case WID_CI_RAIL_COUNT
: {
1784 /* Draw infrastructure count for each valid railtype. */
1785 uint32 rail_total
= c
->infrastructure
.GetRailTotal();
1787 FOR_ALL_SORTED_RAILTYPES(rt
) {
1788 if (HasBit(this->railtypes
, rt
)) {
1789 this->DrawCountLine(r
, y
, c
->infrastructure
.rail
[rt
], RailMaintenanceCost(rt
, c
->infrastructure
.rail
[rt
], rail_total
));
1792 if (this->railtypes
!= RAILTYPES_NONE
) {
1793 this->DrawCountLine(r
, y
, c
->infrastructure
.signal
, SignalMaintenanceCost(c
->infrastructure
.signal
));
1798 case WID_CI_ROAD_DESC
:
1799 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT
);
1801 if (this->roadtypes
!= ROADTYPES_NONE
) {
1802 if (HasBit(this->roadtypes
, ROADTYPE_ROAD
)) DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD
);
1803 if (HasBit(this->roadtypes
, ROADTYPE_TRAM
)) DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_TRAMWAY
);
1805 /* No valid roadtypes. */
1806 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
);
1811 case WID_CI_ROAD_COUNT
:
1812 if (HasBit(this->roadtypes
, ROADTYPE_ROAD
)) {
1813 this->DrawCountLine(r
, y
, c
->infrastructure
.road
[ROADTYPE_ROAD
], RoadMaintenanceCost(ROADTYPE_ROAD
, c
->infrastructure
.road
[ROADTYPE_ROAD
]));
1815 if (HasBit(this->roadtypes
, ROADTYPE_TRAM
)) {
1816 this->DrawCountLine(r
, y
, c
->infrastructure
.road
[ROADTYPE_TRAM
], RoadMaintenanceCost(ROADTYPE_TRAM
, c
->infrastructure
.road
[ROADTYPE_TRAM
]));
1820 case WID_CI_WATER_DESC
:
1821 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT
);
1822 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS
);
1825 case WID_CI_WATER_COUNT
:
1826 this->DrawCountLine(r
, y
, c
->infrastructure
.water
, CanalMaintenanceCost(c
->infrastructure
.water
));
1830 if (_settings_game
.economy
.infrastructure_maintenance
) {
1831 int left
= _current_text_dir
== TD_RTL
? r
.right
- this->total_width
: r
.left
;
1832 GfxFillRect(left
, y
, left
+ this->total_width
, y
, PC_WHITE
);
1834 SetDParam(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year
1835 DrawString(left
, left
+ this->total_width
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL
, TC_FROMSTRING
, SA_RIGHT
);
1839 case WID_CI_STATION_DESC
:
1840 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT
);
1841 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS
);
1842 DrawString(r
.left
+ offs_left
, r
.right
- offs_right
, y
+= FONT_HEIGHT_NORMAL
, STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS
);
1845 case WID_CI_STATION_COUNT
:
1846 this->DrawCountLine(r
, y
, c
->infrastructure
.station
, StationMaintenanceCost(c
->infrastructure
.station
));
1847 this->DrawCountLine(r
, y
, c
->infrastructure
.airport
, AirportMaintenanceCost(c
->index
));
1853 * Some data on this window has become invalid.
1854 * @param data Information about the changed data.
1855 * @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.
1857 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
1859 if (!gui_scope
) return;
1861 this->UpdateRailRoadTypes();
1866 static WindowDesc
_company_infrastructure_desc(
1867 WDP_AUTO
, "company_infrastructure", 0, 0,
1868 WC_COMPANY_INFRASTRUCTURE
, WC_NONE
,
1870 _nested_company_infrastructure_widgets
, lengthof(_nested_company_infrastructure_widgets
)
1874 * Open the infrastructure window of a company.
1875 * @param company Company to show infrastructure of.
1877 static void ShowCompanyInfrastructure(CompanyID company
)
1879 if (!Company::IsValidID(company
)) return;
1880 AllocateWindowDescFront
<CompanyInfrastructureWindow
>(&_company_infrastructure_desc
, company
);
1883 static const NWidgetPart _nested_company_widgets
[] = {
1884 NWidget(NWID_HORIZONTAL
),
1885 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
1886 NWidget(WWT_CAPTION
, COLOUR_GREY
, WID_C_CAPTION
), SetDataTip(STR_COMPANY_VIEW_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1887 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
1888 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
1890 NWidget(WWT_PANEL
, COLOUR_GREY
),
1891 NWidget(NWID_HORIZONTAL
), SetPIP(4, 6, 4),
1892 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
1893 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_FACE
), SetMinimalSize(92, 119), SetFill(1, 0),
1894 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_FACE_TITLE
), SetFill(1, 1), SetMinimalTextLines(2, 0),
1896 NWidget(NWID_VERTICAL
),
1897 NWidget(NWID_HORIZONTAL
),
1898 NWidget(NWID_VERTICAL
), SetPIP(4, 5, 5),
1899 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_INAUGURATION
), SetDataTip(STR_COMPANY_VIEW_INAUGURATED_TITLE
, STR_NULL
), SetFill(1, 0),
1900 NWidget(NWID_HORIZONTAL
), SetPIP(0, 5, 0),
1901 NWidget(WWT_LABEL
, COLOUR_GREY
, WID_C_DESC_COLOUR_SCHEME
), SetDataTip(STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE
, STR_NULL
),
1902 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_COLOUR_SCHEME_EXAMPLE
), SetMinimalSize(30, 0), SetFill(0, 1),
1903 NWidget(NWID_SPACER
), SetFill(1, 0),
1905 NWidget(NWID_HORIZONTAL
), SetPIP(0, 4, 0),
1906 NWidget(NWID_VERTICAL
),
1907 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_VEHICLE
), SetDataTip(STR_COMPANY_VIEW_VEHICLES_TITLE
, STR_NULL
),
1908 NWidget(NWID_SPACER
), SetFill(0, 1),
1910 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_VEHICLE_COUNTS
), SetMinimalTextLines(4, 0),
1911 NWidget(NWID_SPACER
), SetFill(1, 0),
1914 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
1915 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_VIEW_BUILD_HQ
),
1916 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
),
1917 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
),
1919 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_RELOCATE
),
1920 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_C_RELOCATE_HQ
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_RELOCATE_HQ
, STR_COMPANY_VIEW_RELOCATE_COMPANY_HEADQUARTERS
),
1921 NWidget(NWID_SPACER
), SetMinimalSize(90, 0),
1923 NWidget(NWID_SPACER
), SetFill(0, 1),
1926 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_COMPANY_VALUE
), SetDataTip(STR_COMPANY_VIEW_COMPANY_VALUE
, STR_NULL
), SetFill(1, 0),
1927 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
1928 NWidget(NWID_HORIZONTAL
), SetPIP(0, 4, 0),
1929 NWidget(NWID_VERTICAL
),
1930 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_C_DESC_INFRASTRUCTURE
), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE
, STR_NULL
),
1931 NWidget(NWID_SPACER
), SetFill(0, 1),
1933 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_INFRASTRUCTURE_COUNTS
), SetMinimalTextLines(5, 0), SetFill(1, 0),
1934 NWidget(NWID_VERTICAL
),
1935 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_VIEW_INFRASTRUCTURE
), SetDataTip(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON
, STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP
),
1936 NWidget(NWID_SPACER
), SetFill(0, 1), SetMinimalSize(90, 0),
1940 NWidget(NWID_HORIZONTAL
),
1941 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_DESC_OWNERS
),
1942 NWidget(NWID_VERTICAL
), SetPIP(5, 5, 4),
1943 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_C_DESC_OWNERS
), SetMinimalTextLines(3, 0),
1944 NWidget(NWID_SPACER
), SetFill(0, 1),
1947 NWidget(NWID_VERTICAL
), SetPIP(4, 2, 4),
1948 NWidget(NWID_SPACER
), SetMinimalSize(90, 0), SetFill(0, 1),
1949 /* Multi player buttons. */
1950 NWidget(NWID_HORIZONTAL
),
1951 NWidget(WWT_EMPTY
, COLOUR_GREY
, WID_C_HAS_PASSWORD
),
1952 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_MULTIPLAYER
),
1953 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_COMPANY_PASSWORD
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_PASSWORD
, STR_COMPANY_VIEW_PASSWORD_TOOLTIP
),
1954 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_C_COMPANY_JOIN
), SetFill(1, 0), SetDataTip(STR_COMPANY_VIEW_JOIN
, STR_COMPANY_VIEW_JOIN_TOOLTIP
),
1962 /* Button bars at the bottom. */
1963 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_C_SELECT_BUTTONS
),
1964 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1965 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
),
1966 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
),
1967 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
),
1968 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
),
1970 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1971 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
),
1972 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
),
1977 int GetAmountOwnedBy(const Company
*c
, Owner owner
)
1979 return (c
->share_owners
[0] == owner
) +
1980 (c
->share_owners
[1] == owner
) +
1981 (c
->share_owners
[2] == owner
) +
1982 (c
->share_owners
[3] == owner
);
1985 /** Strings for the company vehicle counts */
1986 static const StringID _company_view_vehicle_count_strings
[] = {
1987 STR_COMPANY_VIEW_TRAINS
, STR_COMPANY_VIEW_ROAD_VEHICLES
, STR_COMPANY_VIEW_SHIPS
, STR_COMPANY_VIEW_AIRCRAFT
1991 * Window with general information about a company
1993 struct CompanyWindow
: Window
1995 CompanyWidgets query_widget
;
1997 /** Display planes in the company window. */
1998 enum CompanyWindowPlanes
{
1999 /* Display planes of the #WID_C_SELECT_MULTIPLAYER selection widget. */
2000 CWP_MP_C_PWD
= 0, ///< Display the company password button.
2001 CWP_MP_C_JOIN
, ///< Display the join company button.
2003 /* Display planes of the #WID_C_SELECT_VIEW_BUILD_HQ selection widget. */
2004 CWP_VB_VIEW
= 0, ///< Display the view button
2005 CWP_VB_BUILD
, ///< Display the build button
2007 /* Display planes of the #WID_C_SELECT_RELOCATE selection widget. */
2008 CWP_RELOCATE_SHOW
= 0, ///< Show the relocate HQ button.
2009 CWP_RELOCATE_HIDE
, ///< Hide the relocate HQ button.
2011 /* Display planes of the #WID_C_SELECT_BUTTONS selection widget. */
2012 CWP_BUTTONS_LOCAL
= 0, ///< Buttons of the local company.
2013 CWP_BUTTONS_OTHER
, ///< Buttons of the other companies.
2016 CompanyWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
2018 this->InitNested(window_number
);
2019 this->owner
= (Owner
)this->window_number
;
2020 this->OnInvalidateData();
2023 virtual void OnPaint()
2025 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2026 bool local
= this->window_number
== _local_company
;
2028 if (!this->IsShaded()) {
2029 bool reinit
= false;
2031 /* Button bar selection. */
2032 int plane
= local
? CWP_BUTTONS_LOCAL
: CWP_BUTTONS_OTHER
;
2033 NWidgetStacked
*wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_BUTTONS
);
2034 if (plane
!= wi
->shown_plane
) {
2035 wi
->SetDisplayedPlane(plane
);
2036 this->InvalidateData();
2040 /* Build HQ button handling. */
2041 plane
= (local
&& c
->location_of_HQ
== INVALID_TILE
) ? CWP_VB_BUILD
: CWP_VB_VIEW
;
2042 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_VIEW_BUILD_HQ
);
2043 if (plane
!= wi
->shown_plane
) {
2044 wi
->SetDisplayedPlane(plane
);
2049 this->SetWidgetDisabledState(WID_C_VIEW_HQ
, c
->location_of_HQ
== INVALID_TILE
);
2051 /* Enable/disable 'Relocate HQ' button. */
2052 plane
= (!local
|| c
->location_of_HQ
== INVALID_TILE
) ? CWP_RELOCATE_HIDE
: CWP_RELOCATE_SHOW
;
2053 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_RELOCATE
);
2054 if (plane
!= wi
->shown_plane
) {
2055 wi
->SetDisplayedPlane(plane
);
2060 /* Owners of company */
2061 plane
= SZSP_HORIZONTAL
;
2062 for (uint i
= 0; i
< lengthof(c
->share_owners
); i
++) {
2063 if (c
->share_owners
[i
] != INVALID_COMPANY
) {
2068 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_DESC_OWNERS
);
2069 if (plane
!= wi
->shown_plane
) {
2070 wi
->SetDisplayedPlane(plane
);
2074 /* Multiplayer buttons. */
2075 plane
= ((!_networking
) ? (int)SZSP_NONE
: (int)(local
? CWP_MP_C_PWD
: CWP_MP_C_JOIN
));
2076 wi
= this->GetWidget
<NWidgetStacked
>(WID_C_SELECT_MULTIPLAYER
);
2077 if (plane
!= wi
->shown_plane
) {
2078 wi
->SetDisplayedPlane(plane
);
2081 this->SetWidgetDisabledState(WID_C_COMPANY_JOIN
, c
->is_ai
);
2089 this->DrawWidgets();
2092 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
2096 Dimension face_size
= GetSpriteSize(SPR_GRADIENT
);
2097 size
->width
= max(size
->width
, face_size
.width
);
2098 size
->height
= max(size
->height
, face_size
.height
);
2102 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE
: {
2104 Dimension d
= GetSpriteSize(SPR_VEH_BUS_SW_VIEW
, &offset
);
2105 d
.width
-= offset
.x
;
2106 d
.height
-= offset
.y
;
2107 *size
= maxdim(*size
, d
);
2111 case WID_C_DESC_COMPANY_VALUE
:
2112 SetDParam(0, INT64_MAX
); // Arguably the maximum company value
2113 size
->width
= GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE
).width
;
2116 case WID_C_DESC_VEHICLE_COUNTS
:
2117 SetDParamMaxValue(0, 5000); // Maximum number of vehicles
2118 for (uint i
= 0; i
< lengthof(_company_view_vehicle_count_strings
); i
++) {
2119 size
->width
= max(size
->width
, GetStringBoundingBox(_company_view_vehicle_count_strings
[i
]).width
);
2123 case WID_C_DESC_INFRASTRUCTURE_COUNTS
:
2124 SetDParamMaxValue(0, UINT_MAX
);
2125 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL
).width
);
2126 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD
).width
);
2127 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER
).width
);
2128 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION
).width
);
2129 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT
).width
);
2130 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
).width
);
2133 case WID_C_DESC_OWNERS
: {
2136 FOR_ALL_COMPANIES(c2
) {
2137 SetDParamMaxValue(0, 75);
2138 SetDParam(1, c2
->index
);
2140 size
->width
= max(size
->width
, GetStringBoundingBox(STR_COMPANY_VIEW_SHARES_OWNED_BY
).width
);
2145 #ifdef ENABLE_NETWORK
2146 case WID_C_HAS_PASSWORD
:
2147 *size
= maxdim(*size
, GetSpriteSize(SPR_LOCK
));
2149 #endif /* ENABLE_NETWORK */
2153 virtual void DrawWidget(const Rect
&r
, int widget
) const
2155 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2158 DrawCompanyManagerFace(c
->face
, c
->colour
, r
.left
, r
.top
);
2161 case WID_C_FACE_TITLE
:
2162 SetDParam(0, c
->index
);
2163 DrawStringMultiLine(r
.left
, r
.right
, r
.top
, r
.bottom
, STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE
, TC_FROMSTRING
, SA_HOR_CENTER
);
2166 case WID_C_DESC_COLOUR_SCHEME_EXAMPLE
: {
2168 Dimension d
= GetSpriteSize(SPR_VEH_BUS_SW_VIEW
, &offset
);
2169 d
.height
-= offset
.y
;
2170 DrawSprite(SPR_VEH_BUS_SW_VIEW
, COMPANY_SPRITE_COLOUR(c
->index
), r
.left
- offset
.x
, (r
.top
+ r
.bottom
- d
.height
) / 2 - offset
.y
);
2174 case WID_C_DESC_VEHICLE_COUNTS
: {
2176 amounts
[0] = c
->group_all
[VEH_TRAIN
].num_vehicle
;
2177 amounts
[1] = c
->group_all
[VEH_ROAD
].num_vehicle
;
2178 amounts
[2] = c
->group_all
[VEH_SHIP
].num_vehicle
;
2179 amounts
[3] = c
->group_all
[VEH_AIRCRAFT
].num_vehicle
;
2182 if (amounts
[0] + amounts
[1] + amounts
[2] + amounts
[3] == 0) {
2183 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_VEHICLES_NONE
);
2185 assert_compile(lengthof(amounts
) == lengthof(_company_view_vehicle_count_strings
));
2187 for (uint i
= 0; i
< lengthof(amounts
); i
++) {
2188 if (amounts
[i
] != 0) {
2189 SetDParam(0, amounts
[i
]);
2190 DrawString(r
.left
, r
.right
, y
, _company_view_vehicle_count_strings
[i
]);
2191 y
+= FONT_HEIGHT_NORMAL
;
2198 case WID_C_DESC_INFRASTRUCTURE_COUNTS
: {
2201 /* Collect rail and road counts. */
2202 uint rail_pices
= c
->infrastructure
.signal
;
2203 uint road_pieces
= 0;
2204 for (uint i
= 0; i
< lengthof(c
->infrastructure
.rail
); i
++) rail_pices
+= c
->infrastructure
.rail
[i
];
2205 for (uint i
= 0; i
< lengthof(c
->infrastructure
.road
); i
++) road_pieces
+= c
->infrastructure
.road
[i
];
2207 if (rail_pices
== 0 && road_pieces
== 0 && c
->infrastructure
.water
== 0 && c
->infrastructure
.station
== 0 && c
->infrastructure
.airport
== 0) {
2208 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_NONE
);
2210 if (rail_pices
!= 0) {
2211 SetDParam(0, rail_pices
);
2212 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL
);
2213 y
+= FONT_HEIGHT_NORMAL
;
2215 if (road_pieces
!= 0) {
2216 SetDParam(0, road_pieces
);
2217 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD
);
2218 y
+= FONT_HEIGHT_NORMAL
;
2220 if (c
->infrastructure
.water
!= 0) {
2221 SetDParam(0, c
->infrastructure
.water
);
2222 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_WATER
);
2223 y
+= FONT_HEIGHT_NORMAL
;
2225 if (c
->infrastructure
.station
!= 0) {
2226 SetDParam(0, c
->infrastructure
.station
);
2227 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_STATION
);
2228 y
+= FONT_HEIGHT_NORMAL
;
2230 if (c
->infrastructure
.airport
!= 0) {
2231 SetDParam(0, c
->infrastructure
.airport
);
2232 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT
);
2239 case WID_C_DESC_OWNERS
: {
2243 FOR_ALL_COMPANIES(c2
) {
2244 uint amt
= GetAmountOwnedBy(c
, c2
->index
);
2246 SetDParam(0, amt
* 25);
2247 SetDParam(1, c2
->index
);
2249 DrawString(r
.left
, r
.right
, y
, STR_COMPANY_VIEW_SHARES_OWNED_BY
);
2250 y
+= FONT_HEIGHT_NORMAL
;
2256 #ifdef ENABLE_NETWORK
2257 case WID_C_HAS_PASSWORD
:
2258 if (_networking
&& NetworkCompanyIsPassworded(c
->index
)) {
2259 DrawSprite(SPR_LOCK
, PAL_NONE
, r
.left
, r
.top
);
2262 #endif /* ENABLE_NETWORK */
2266 virtual void SetStringParameters(int widget
) const
2270 SetDParam(0, (CompanyID
)this->window_number
);
2271 SetDParam(1, (CompanyID
)this->window_number
);
2274 case WID_C_DESC_INAUGURATION
:
2275 SetDParam(0, Company::Get((CompanyID
)this->window_number
)->inaugurated_year
);
2278 case WID_C_DESC_COMPANY_VALUE
:
2279 SetDParam(0, CalculateCompanyValue(Company::Get((CompanyID
)this->window_number
)));
2284 virtual void OnClick(Point pt
, int widget
, int click_count
)
2287 case WID_C_NEW_FACE
: DoSelectCompanyManagerFace(this); break;
2289 case WID_C_COLOUR_SCHEME
:
2290 if (BringWindowToFrontById(WC_COMPANY_COLOUR
, this->window_number
)) break;
2291 new SelectCompanyLiveryWindow(&_select_company_livery_desc
, (CompanyID
)this->window_number
);
2294 case WID_C_PRESIDENT_NAME
:
2295 this->query_widget
= WID_C_PRESIDENT_NAME
;
2296 SetDParam(0, this->window_number
);
2297 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
);
2300 case WID_C_COMPANY_NAME
:
2301 this->query_widget
= WID_C_COMPANY_NAME
;
2302 SetDParam(0, this->window_number
);
2303 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
);
2306 case WID_C_VIEW_HQ
: {
2307 TileIndex tile
= Company::Get((CompanyID
)this->window_number
)->location_of_HQ
;
2308 if (_ctrl_pressed
) {
2309 ShowExtraViewPortWindow(tile
);
2311 ScrollMainWindowToTile(tile
);
2316 case WID_C_BUILD_HQ
:
2317 if ((byte
)this->window_number
!= _local_company
) return;
2318 if (this->IsWidgetLowered(WID_C_BUILD_HQ
)) {
2319 ResetObjectToPlace();
2320 this->RaiseButtons();
2323 SetObjectToPlaceWnd(SPR_CURSOR_HQ
, PAL_NONE
, HT_RECT
, this);
2324 SetTileSelectSize(2, 2);
2325 this->LowerWidget(WID_C_BUILD_HQ
);
2326 this->SetWidgetDirty(WID_C_BUILD_HQ
);
2329 case WID_C_RELOCATE_HQ
:
2330 if (this->IsWidgetLowered(WID_C_RELOCATE_HQ
)) {
2331 ResetObjectToPlace();
2332 this->RaiseButtons();
2335 SetObjectToPlaceWnd(SPR_CURSOR_HQ
, PAL_NONE
, HT_RECT
, this);
2336 SetTileSelectSize(2, 2);
2337 this->LowerWidget(WID_C_RELOCATE_HQ
);
2338 this->SetWidgetDirty(WID_C_RELOCATE_HQ
);
2341 case WID_C_VIEW_INFRASTRUCTURE
:
2342 ShowCompanyInfrastructure((CompanyID
)this->window_number
);
2345 case WID_C_BUY_SHARE
:
2346 DoCommandP(0, this->window_number
, 0, CMD_BUY_SHARE_IN_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS
));
2349 case WID_C_SELL_SHARE
:
2350 DoCommandP(0, this->window_number
, 0, CMD_SELL_SHARE_IN_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_SELL_25_SHARE_IN
));
2353 #ifdef ENABLE_NETWORK
2354 case WID_C_COMPANY_PASSWORD
:
2355 if (this->window_number
== _local_company
) ShowNetworkCompanyPasswordWindow(this);
2358 case WID_C_COMPANY_JOIN
: {
2359 this->query_widget
= WID_C_COMPANY_JOIN
;
2360 CompanyID company
= (CompanyID
)this->window_number
;
2361 if (_network_server
) {
2362 NetworkServerDoMove(CLIENT_ID_SERVER
, company
);
2363 MarkWholeScreenDirty();
2364 } else if (NetworkCompanyIsPassworded(company
)) {
2365 /* ask for the password */
2366 ShowQueryString(STR_EMPTY
, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION
, NETWORK_PASSWORD_LENGTH
, this, CS_ALPHANUMERAL
, QSF_NONE
);
2368 /* just send the join command */
2369 NetworkClientRequestMove(company
);
2373 #endif /* ENABLE_NETWORK */
2377 virtual void OnHundredthTick()
2379 /* redraw the window every now and then */
2383 virtual void OnPlaceObject(Point pt
, TileIndex tile
)
2385 if (DoCommandP(tile
, OBJECT_HQ
, 0, CMD_BUILD_OBJECT
| CMD_MSG(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS
)) && !_shift_pressed
) {
2386 ResetObjectToPlace();
2387 this->RaiseButtons();
2391 virtual void OnPlaceObjectAbort()
2393 this->RaiseButtons();
2396 virtual void OnQueryTextFinished(char *str
)
2398 if (str
== NULL
) return;
2400 switch (this->query_widget
) {
2401 default: NOT_REACHED();
2403 case WID_C_PRESIDENT_NAME
:
2404 DoCommandP(0, 0, 0, CMD_RENAME_PRESIDENT
| CMD_MSG(STR_ERROR_CAN_T_CHANGE_PRESIDENT
), NULL
, str
);
2407 case WID_C_COMPANY_NAME
:
2408 DoCommandP(0, 0, 0, CMD_RENAME_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME
), NULL
, str
);
2411 #ifdef ENABLE_NETWORK
2412 case WID_C_COMPANY_JOIN
:
2413 NetworkClientRequestMove((CompanyID
)this->window_number
, str
);
2415 #endif /* ENABLE_NETWORK */
2421 * Some data on this window has become invalid.
2422 * @param data Information about the changed data.
2423 * @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.
2425 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
2427 if (this->window_number
== _local_company
) return;
2429 if (_settings_game
.economy
.allow_shares
) { // Shares are allowed
2430 const Company
*c
= Company::Get(this->window_number
);
2432 /* If all shares are owned by someone (none by nobody), disable buy button */
2433 this->SetWidgetDisabledState(WID_C_BUY_SHARE
, GetAmountOwnedBy(c
, INVALID_OWNER
) == 0 ||
2434 /* Only 25% left to buy. If the company is human, disable buying it up.. TODO issues! */
2435 (GetAmountOwnedBy(c
, INVALID_OWNER
) == 1 && !c
->is_ai
) ||
2436 /* Spectators cannot do anything of course */
2437 _local_company
== COMPANY_SPECTATOR
);
2439 /* If the company doesn't own any shares, disable sell button */
2440 this->SetWidgetDisabledState(WID_C_SELL_SHARE
, (GetAmountOwnedBy(c
, _local_company
) == 0) ||
2441 /* Spectators cannot do anything of course */
2442 _local_company
== COMPANY_SPECTATOR
);
2443 } else { // Shares are not allowed, disable buy/sell buttons
2444 this->DisableWidget(WID_C_BUY_SHARE
);
2445 this->DisableWidget(WID_C_SELL_SHARE
);
2450 static WindowDesc
_company_desc(
2451 WDP_AUTO
, "company", 0, 0,
2452 WC_COMPANY
, WC_NONE
,
2454 _nested_company_widgets
, lengthof(_nested_company_widgets
)
2458 * Show the window with the overview of the company.
2459 * @param company The company to show the window for.
2461 void ShowCompany(CompanyID company
)
2463 if (!Company::IsValidID(company
)) return;
2465 AllocateWindowDescFront
<CompanyWindow
>(&_company_desc
, company
);
2469 * Redraw all windows with company infrastructure counts.
2470 * @param company The company to redraw the windows of.
2472 void DirtyCompanyInfrastructureWindows(CompanyID company
)
2474 SetWindowDirty(WC_COMPANY
, company
);
2475 SetWindowDirty(WC_COMPANY_INFRASTRUCTURE
, company
);
2479 * Redraw all windows with all company infrastructure counts.
2481 void DirtyAllCompanyInfrastructureWindows()
2483 SetWindowClassesDirty(WC_COMPANY
);
2484 SetWindowClassesDirty(WC_COMPANY_INFRASTRUCTURE
);
2487 struct BuyCompanyWindow
: Window
{
2488 BuyCompanyWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
2490 this->InitNested(window_number
);
2493 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
2497 *size
= GetSpriteSize(SPR_GRADIENT
);
2500 case WID_BC_QUESTION
:
2501 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2502 SetDParam(0, c
->index
);
2503 SetDParam(1, c
->bankrupt_value
);
2504 size
->height
= GetStringHeight(STR_BUY_COMPANY_MESSAGE
, size
->width
);
2509 virtual void SetStringParameters(int widget
) const
2512 case WID_BC_CAPTION
:
2513 SetDParam(0, STR_COMPANY_NAME
);
2514 SetDParam(1, Company::Get((CompanyID
)this->window_number
)->index
);
2519 virtual void DrawWidget(const Rect
&r
, int widget
) const
2523 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2524 DrawCompanyManagerFace(c
->face
, c
->colour
, r
.left
, r
.top
);
2528 case WID_BC_QUESTION
: {
2529 const Company
*c
= Company::Get((CompanyID
)this->window_number
);
2530 SetDParam(0, c
->index
);
2531 SetDParam(1, c
->bankrupt_value
);
2532 DrawStringMultiLine(r
.left
, r
.right
, r
.top
, r
.bottom
, STR_BUY_COMPANY_MESSAGE
, TC_FROMSTRING
, SA_CENTER
);
2538 virtual void OnClick(Point pt
, int widget
, int click_count
)
2546 DoCommandP(0, this->window_number
, 0, CMD_BUY_COMPANY
| CMD_MSG(STR_ERROR_CAN_T_BUY_COMPANY
));
2552 static const NWidgetPart _nested_buy_company_widgets
[] = {
2553 NWidget(NWID_HORIZONTAL
),
2554 NWidget(WWT_CLOSEBOX
, COLOUR_LIGHT_BLUE
),
2555 NWidget(WWT_CAPTION
, COLOUR_LIGHT_BLUE
, WID_BC_CAPTION
), SetDataTip(STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2557 NWidget(WWT_PANEL
, COLOUR_LIGHT_BLUE
),
2558 NWidget(NWID_VERTICAL
), SetPIP(8, 8, 8),
2559 NWidget(NWID_HORIZONTAL
), SetPIP(8, 10, 8),
2560 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BC_FACE
), SetFill(0, 1),
2561 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BC_QUESTION
), SetMinimalSize(240, 0), SetFill(1, 1),
2563 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(100, 10, 100),
2564 NWidget(WWT_TEXTBTN
, COLOUR_LIGHT_BLUE
, WID_BC_NO
), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_NO
, STR_NULL
), SetFill(1, 0),
2565 NWidget(WWT_TEXTBTN
, COLOUR_LIGHT_BLUE
, WID_BC_YES
), SetMinimalSize(60, 12), SetDataTip(STR_QUIT_YES
, STR_NULL
), SetFill(1, 0),
2571 static WindowDesc
_buy_company_desc(
2572 WDP_AUTO
, NULL
, 0, 0,
2573 WC_BUY_COMPANY
, WC_NONE
,
2575 _nested_buy_company_widgets
, lengthof(_nested_buy_company_widgets
)
2579 * Show the query to buy another company.
2580 * @param company The company to buy.
2582 void ShowBuyCompanyDialog(CompanyID company
)
2584 AllocateWindowDescFront
<BuyCompanyWindow
>(&_buy_company_desc
, company
);