2009-08-21 20:21:05 +00:00
/*
* This file is part of OpenTTD .
* 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.
* 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 .
* 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/>.
*/
2012-01-01 17:22:32 +00:00
/** @file company_gui.cpp %Company related GUIs. */
2007-03-21 17:42:43 +00:00
2004-08-09 17:04:08 +00:00
# include "stdafx.h"
2017-03-02 00:09:19 +00:00
# include "currency.h"
2011-12-10 13:54:10 +00:00
# include "error.h"
2004-08-09 17:04:08 +00:00
# include "gui.h"
2007-12-19 20:45:46 +00:00
# include "window_gui.h"
# include "textbuf_gui.h"
2008-01-09 09:45:45 +00:00
# include "viewport_func.h"
2008-09-30 20:51:04 +00:00
# include "company_func.h"
2007-12-21 21:50:46 +00:00
# include "command_func.h"
2007-01-02 17:34:03 +00:00
# include "network/network.h"
2008-05-30 18:20:26 +00:00
# include "network/network_gui.h"
2009-01-23 22:18:06 +00:00
# include "network/network_func.h"
2006-10-05 15:07:34 +00:00
# include "newgrf.h"
2008-09-30 20:51:04 +00:00
# include "company_manager_face.h"
2007-12-21 19:49:27 +00:00
# include "strings_func.h"
2007-12-26 13:50:40 +00:00
# include "date_func.h"
2008-04-12 22:19:34 +00:00
# include "widgets/dropdown_type.h"
2008-05-07 13:10:15 +00:00
# include "tilehighlight_func.h"
2010-01-15 16:41:15 +00:00
# include "company_base.h"
# include "core/geometry_func.hpp"
2010-08-26 22:01:16 +00:00
# include "object_type.h"
2011-12-03 23:40:08 +00:00
# include "rail.h"
2019-04-06 06:46:15 +00:00
# include "road.h"
2011-12-03 23:40:08 +00:00
# include "engine_base.h"
# include "window_func.h"
2011-12-03 23:40:46 +00:00
# include "road_func.h"
# include "water.h"
# include "station_func.h"
2014-09-28 19:19:47 +00:00
# include "zoom_func.h"
2019-01-31 13:57:44 +00:00
# include "sortlist_type.h"
2023-08-19 00:13:00 +00:00
# include "group_gui_list.h"
2023-02-15 21:13:58 +00:00
# include "core/backup_type.hpp"
2004-08-09 17:04:08 +00:00
2011-12-15 22:22:55 +00:00
# include "widgets/company_widget.h"
2014-04-23 20:13:33 +00:00
# include "safeguards.h"
2008-01-13 01:21:35 +00:00
2009-11-28 13:47:57 +00:00
static void DoSelectCompanyManagerFace ( Window * parent ) ;
2011-12-03 23:40:08 +00:00
static void ShowCompanyInfrastructure ( CompanyID company ) ;
2004-08-09 17:04:08 +00:00
2022-02-23 18:03:23 +00:00
/** List of revenues. */
2023-11-03 23:15:37 +00:00
static const std : : initializer_list < ExpensesType > _expenses_list_revenue = {
2022-02-23 18:03:23 +00:00
EXPENSES_TRAIN_REVENUE ,
EXPENSES_ROADVEH_REVENUE ,
EXPENSES_AIRCRAFT_REVENUE ,
EXPENSES_SHIP_REVENUE ,
2015-08-06 21:24:24 +00:00
EXPENSES_SHARING_INC ,
2009-01-31 21:27:36 +00:00
} ;
2022-02-23 18:03:23 +00:00
/** List of operating expenses. */
2023-11-03 23:15:37 +00:00
static const std : : initializer_list < ExpensesType > _expenses_list_operating_costs = {
2009-01-31 21:27:36 +00:00
EXPENSES_TRAIN_RUN ,
EXPENSES_ROADVEH_RUN ,
EXPENSES_AIRCRAFT_RUN ,
EXPENSES_SHIP_RUN ,
EXPENSES_PROPERTY ,
2022-02-23 18:03:23 +00:00
EXPENSES_LOAN_INTEREST ,
2015-08-06 21:24:24 +00:00
EXPENSES_SHARING_COST ,
2022-02-23 18:03:23 +00:00
} ;
/** List of capital expenses. */
2023-11-03 23:15:37 +00:00
static const std : : initializer_list < ExpensesType > _expenses_list_capital_costs = {
2009-01-31 21:27:36 +00:00
EXPENSES_CONSTRUCTION ,
EXPENSES_NEW_VEHICLES ,
EXPENSES_OTHER ,
} ;
/** Expense list container. */
struct ExpensesList {
2023-11-03 23:15:37 +00:00
const StringID title ; ///< StringID of list title.
const std : : initializer_list < ExpensesType > & items ; ///< List of expenses types.
2009-10-09 19:10:05 +00:00
2023-11-03 23:15:37 +00:00
ExpensesList ( StringID title , const std : : initializer_list < ExpensesType > & list ) : title ( title ) , items ( list )
2009-10-09 19:10:05 +00:00
{
}
2009-10-10 13:32:44 +00:00
uint GetHeight ( ) const
2009-05-13 17:39:00 +00:00
{
2022-02-23 18:03:23 +00:00
/* Add up the height of all the lines. */
2023-11-21 19:04:24 +00:00
return static_cast < uint > ( this - > items . size ( ) ) * GetCharacterHeight ( FS_NORMAL ) ;
2009-10-10 15:18:20 +00:00
}
/** Compute width of the expenses categories in pixels. */
2022-02-23 18:03:23 +00:00
uint GetListWidth ( ) const
2009-10-10 15:18:20 +00:00
{
uint width = 0 ;
2023-11-03 23:15:37 +00:00
for ( const ExpensesType & et : this - > items ) {
2022-02-23 18:03:23 +00:00
width = std : : max ( width , GetStringBoundingBox ( STR_FINANCES_SECTION_CONSTRUCTION + et ) . width ) ;
2009-10-10 15:18:20 +00:00
}
return width ;
2009-05-13 17:39:00 +00:00
}
2009-01-31 21:27:36 +00:00
} ;
2022-02-23 18:03:23 +00:00
/** Types of expense lists */
2023-11-03 23:15:37 +00:00
static const std : : initializer_list < ExpensesList > _expenses_list_types = {
{ STR_FINANCES_REVENUE_TITLE , _expenses_list_revenue } ,
{ STR_FINANCES_OPERATING_EXPENSES_TITLE , _expenses_list_operating_costs } ,
{ STR_FINANCES_CAPITAL_EXPENSES_TITLE , _expenses_list_capital_costs } ,
2009-01-31 21:27:36 +00:00
} ;
2022-02-23 18:03:23 +00:00
/**
* Get the total height of the " categories " column .
* @ return The total height in pixels .
*/
static uint GetTotalCategoriesHeight ( )
{
/* There's an empty line and blockspace on the year row */
2023-11-21 19:04:24 +00:00
uint total_height = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_wide ;
2022-02-23 18:03:23 +00:00
2023-11-03 23:15:37 +00:00
for ( const ExpensesList & list : _expenses_list_types ) {
2022-02-23 18:03:23 +00:00
/* Title + expense list + total line + total + blockspace after category */
2023-11-21 19:04:24 +00:00
total_height + = GetCharacterHeight ( FS_NORMAL ) + list . GetHeight ( ) + WidgetDimensions : : scaled . vsep_normal + GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_wide ;
2022-02-23 18:03:23 +00:00
}
/* Total income */
2023-11-21 19:04:24 +00:00
total_height + = WidgetDimensions : : scaled . vsep_normal + GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_wide ;
2022-02-23 18:03:23 +00:00
return total_height ;
}
/**
* Get the required width of the " categories " column , equal to the widest element .
* @ return The required width in pixels .
*/
static uint GetMaxCategoriesWidth ( )
{
2024-02-13 23:26:24 +00:00
uint max_width = GetStringBoundingBox ( EconTime : : UsingWallclockUnits ( ) ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION ) . width ;
2022-02-23 18:03:23 +00:00
/* Loop through categories to check max widths. */
2023-11-03 23:15:37 +00:00
for ( const ExpensesList & list : _expenses_list_types ) {
2022-02-23 18:03:23 +00:00
/* Title of category */
2023-11-03 23:15:37 +00:00
max_width = std : : max ( max_width , GetStringBoundingBox ( list . title ) . width ) ;
2022-02-23 18:03:23 +00:00
/* Entries in category */
2023-11-03 23:15:37 +00:00
max_width = std : : max ( max_width , list . GetListWidth ( ) + WidgetDimensions : : scaled . hsep_indent ) ;
2022-02-23 18:03:23 +00:00
}
return max_width ;
}
/**
* Draw a category of expenses ( revenue , operating expenses , capital expenses ) .
*/
2023-11-03 23:15:37 +00:00
static void DrawCategory ( const Rect & r , int start_y , const ExpensesList & list )
2022-02-23 18:03:23 +00:00
{
2022-09-27 22:40:16 +00:00
Rect tr = r . Indent ( WidgetDimensions : : scaled . hsep_indent , _current_text_dir = = TD_RTL ) ;
2022-02-23 18:03:23 +00:00
2022-10-15 15:55:47 +00:00
tr . top = start_y ;
2022-02-23 18:03:23 +00:00
2023-11-03 23:15:37 +00:00
for ( const ExpensesType & et : list . items ) {
2022-10-15 15:55:47 +00:00
DrawString ( tr , STR_FINANCES_SECTION_CONSTRUCTION + et ) ;
2023-11-21 19:04:24 +00:00
tr . top + = GetCharacterHeight ( FS_NORMAL ) ;
2022-02-23 18:03:23 +00:00
}
}
2010-08-01 19:22:34 +00:00
/**
* Draw the expenses categories .
2009-10-07 19:18:36 +00:00
* @ param r Available space for drawing .
* @ note The environment must provide padding at the left and right of \ a r .
*/
2009-10-10 15:18:20 +00:00
static void DrawCategories ( const Rect & r )
2009-10-07 19:18:36 +00:00
{
2024-02-13 23:26:24 +00:00
int y = r . top ;
/* Draw description of 12-minute economic period. */
DrawString ( r . left , r . right , y , ( EconTime : : UsingWallclockUnits ( ) ? STR_FINANCES_PERIOD_CAPTION : STR_FINANCES_YEAR_CAPTION ) , TC_FROMSTRING , SA_LEFT , true ) ;
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_wide ;
2009-10-07 19:18:36 +00:00
2023-11-03 23:15:37 +00:00
for ( const ExpensesList & list : _expenses_list_types ) {
2022-02-23 18:03:23 +00:00
/* Draw category title and advance y */
2023-11-03 23:15:37 +00:00
DrawString ( r . left , r . right , y , list . title , TC_FROMSTRING , SA_LEFT ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2022-02-23 18:03:23 +00:00
/* Draw category items and advance y */
2023-11-03 23:15:37 +00:00
DrawCategory ( r , y , list ) ;
y + = list . GetHeight ( ) ;
2022-02-23 18:03:23 +00:00
2022-11-13 15:25:04 +00:00
/* Advance y by the height of the horizontal line between amounts and subtotal */
y + = WidgetDimensions : : scaled . vsep_normal ;
/* Draw category total and advance y */
DrawString ( r . left , r . right , y , STR_FINANCES_TOTAL_CAPTION , TC_FROMSTRING , SA_RIGHT ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2022-02-23 18:03:23 +00:00
/* Advance y by a blockspace after this category block */
2022-09-27 22:40:16 +00:00
y + = WidgetDimensions : : scaled . vsep_wide ;
2009-10-07 19:18:36 +00:00
}
2022-02-23 18:03:23 +00:00
/* Draw total profit/loss */
2022-09-27 22:40:16 +00:00
y + = WidgetDimensions : : scaled . vsep_normal ;
2022-11-13 15:32:32 +00:00
DrawString ( r . left , r . right , y , STR_FINANCES_PROFIT , TC_FROMSTRING , SA_LEFT ) ;
2009-10-07 19:18:36 +00:00
}
2010-08-01 19:22:34 +00:00
/**
* Draw an amount of money .
2009-10-07 19:18:36 +00:00
* @ param amount Amount of money to draw ,
* @ param left Left coordinate of the space to draw in .
* @ param right Right coordinate of the space to draw in .
* @ param top Top coordinate of the space to draw in .
2022-02-23 18:03:23 +00:00
* @ param colour The TextColour of the string .
2009-10-07 19:18:36 +00:00
*/
2022-02-23 18:03:23 +00:00
static void DrawPrice ( Money amount , int left , int right , int top , TextColour colour )
2009-10-07 19:18:36 +00:00
{
StringID str = STR_FINANCES_NEGATIVE_INCOME ;
2022-09-21 10:38:03 +00:00
if ( amount = = 0 ) {
str = STR_FINANCES_ZERO_INCOME ;
} else if ( amount < 0 ) {
2009-10-07 19:18:36 +00:00
amount = - amount ;
2022-09-21 10:38:03 +00:00
str = STR_FINANCES_POSITIVE_INCOME ;
2009-10-07 19:18:36 +00:00
}
SetDParam ( 0 , amount ) ;
2022-02-23 18:03:23 +00:00
DrawString ( left , right , top , str , colour , SA_RIGHT ) ;
2009-10-07 19:18:36 +00:00
}
2022-02-23 18:03:23 +00:00
/**
* Draw a category of expenses / revenues in the year column .
* @ return The income sum of the category .
*/
2023-11-03 23:15:37 +00:00
static Money DrawYearCategory ( const Rect & r , int start_y , const ExpensesList & list , const Expenses & tbl )
2022-02-23 18:03:23 +00:00
{
int y = start_y ;
Money sum = 0 ;
2023-11-03 23:15:37 +00:00
for ( const ExpensesType & et : list . items ) {
2023-01-02 22:17:24 +00:00
Money cost = tbl [ et ] ;
2022-02-23 18:03:23 +00:00
sum + = cost ;
if ( cost ! = 0 ) DrawPrice ( cost , r . left , r . right , y , TC_BLACK ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2022-02-23 18:03:23 +00:00
}
/* Draw the total at the bottom of the category. */
2023-11-13 21:54:26 +00:00
GfxFillRect ( r . left , y , r . right , y + WidgetDimensions : : scaled . bevel . top - 1 , PC_BLACK ) ;
2022-09-27 22:40:16 +00:00
y + = WidgetDimensions : : scaled . vsep_normal ;
2022-02-23 18:03:23 +00:00
if ( sum ! = 0 ) DrawPrice ( sum , r . left , r . right , y , TC_WHITE ) ;
/* Return the sum for the yearly total. */
return sum ;
2009-10-07 19:18:36 +00:00
}
2022-02-23 18:03:23 +00:00
2010-08-01 19:22:34 +00:00
/**
* Draw a column with prices .
2009-10-07 19:18:36 +00:00
* @ param r Available space for drawing .
* @ param year Year being drawn .
2023-01-02 22:17:24 +00:00
* @ param tbl Reference to table of amounts for \ a year .
2009-10-07 19:18:36 +00:00
* @ note The environment must provide padding at the left and right of \ a r .
*/
2023-11-19 12:19:17 +00:00
static void DrawYearColumn ( const Rect & r , int year , const Expenses & tbl )
2004-08-09 17:04:08 +00:00
{
2009-10-10 15:18:20 +00:00
int y = r . top ;
2022-02-23 18:03:23 +00:00
Money sum ;
2009-10-07 19:18:36 +00:00
2022-02-23 18:03:23 +00:00
/* Year header */
2009-10-07 19:18:36 +00:00
SetDParam ( 0 , year ) ;
DrawString ( r . left , r . right , y , STR_FINANCES_YEAR , TC_FROMSTRING , SA_RIGHT , true ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_wide ;
2022-02-23 18:03:23 +00:00
/* Categories */
2023-11-03 23:15:37 +00:00
for ( const ExpensesList & list : _expenses_list_types ) {
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2023-11-03 23:15:37 +00:00
sum + = DrawYearCategory ( r , y , list , tbl ) ;
2022-02-23 18:03:23 +00:00
/* Expense list + expense category title + expense category total + blockspace after category */
2023-11-21 19:04:24 +00:00
y + = list . GetHeight ( ) + WidgetDimensions : : scaled . vsep_normal + GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_wide ;
2009-10-07 19:18:36 +00:00
}
2022-02-23 18:03:23 +00:00
/* Total income. */
2023-11-13 21:54:26 +00:00
GfxFillRect ( r . left , y , r . right , y + WidgetDimensions : : scaled . bevel . top - 1 , PC_BLACK ) ;
2022-09-27 22:40:16 +00:00
y + = WidgetDimensions : : scaled . vsep_normal ;
2022-02-23 18:03:23 +00:00
DrawPrice ( sum , r . left , r . right , y , TC_WHITE ) ;
2009-10-07 19:18:36 +00:00
}
2024-01-15 22:49:24 +00:00
static constexpr NWidgetPart _nested_company_finances_widgets [ ] = {
2009-03-27 22:59:43 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , WID_CF_CAPTION ) , SetDataTip ( STR_FINANCES_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_CF_TOGGLE_SIZE ) , SetDataTip ( SPR_LARGE_SMALL_WINDOW , STR_TOOLTIP_TOGGLE_LARGE_SMALL_WINDOW ) ,
2009-12-21 16:24:29 +00:00
NWidget ( WWT_SHADEBOX , COLOUR_GREY ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_STICKYBOX , COLOUR_GREY ) ,
2009-03-27 22:59:43 +00:00
EndContainer ( ) ,
2011-12-16 16:27:45 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_CF_SEL_PANEL ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) ,
2022-09-23 08:36:22 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPadding ( WidgetDimensions : : unscaled . framerect ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_wide , 0 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_CF_EXPS_CATEGORY ) , SetMinimalSize ( 120 , 0 ) , SetFill ( 0 , 0 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_CF_EXPS_PRICE1 ) , SetMinimalSize ( 86 , 0 ) , SetFill ( 0 , 0 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_CF_EXPS_PRICE2 ) , SetMinimalSize ( 86 , 0 ) , SetFill ( 0 , 0 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_CF_EXPS_PRICE3 ) , SetMinimalSize ( 86 , 0 ) , SetFill ( 0 , 0 ) ,
2009-10-10 15:18:20 +00:00
EndContainer ( ) ,
2009-03-27 22:59:43 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPadding ( WidgetDimensions : : unscaled . framerect ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_wide , 0 ) , SetPIPRatio ( 0 , 1 , 2 ) ,
2009-10-10 15:18:20 +00:00
NWidget ( NWID_VERTICAL ) , // Vertical column with 'bank balance', 'loan'
2023-10-28 10:28:28 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY ) , SetDataTip ( STR_FINANCES_OWN_FUNDS_TITLE , STR_NULL ) ,
NWidget ( WWT_TEXT , COLOUR_GREY ) , SetDataTip ( STR_FINANCES_LOAN_TITLE , STR_NULL ) ,
NWidget ( WWT_TEXT , COLOUR_GREY ) , SetDataTip ( STR_FINANCES_BANK_BALANCE_TITLE , STR_NULL ) , SetPadding ( WidgetDimensions : : unscaled . vsep_normal , 0 , 0 , 0 ) ,
2009-10-10 15:18:20 +00:00
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) , // Vertical column with bank balance amount, loan amount, and total.
2022-02-23 18:03:23 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , WID_CF_OWN_VALUE ) , SetDataTip ( STR_FINANCES_TOTAL_CURRENCY , STR_NULL ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
2021-04-19 19:57:03 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , WID_CF_LOAN_VALUE ) , SetDataTip ( STR_FINANCES_TOTAL_CURRENCY , STR_NULL ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
2023-10-28 10:28:28 +00:00
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_CF_BALANCE_LINE ) , SetMinimalSize ( 0 , WidgetDimensions : : unscaled . vsep_normal ) ,
2022-11-13 14:49:47 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , WID_CF_BALANCE_VALUE ) , SetDataTip ( STR_FINANCES_BANK_BALANCE , STR_NULL ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
2009-10-10 15:18:20 +00:00
EndContainer ( ) ,
2011-12-16 16:27:45 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_CF_SEL_MAXLOAN ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_VERTICAL ) , SetPIPRatio ( 0 , 0 , 1 ) , // Max loan information
NWidget ( WWT_TEXT , COLOUR_GREY , WID_CF_INTEREST_RATE ) , SetDataTip ( STR_FINANCES_INTEREST_RATE , STR_NULL ) ,
NWidget ( WWT_TEXT , COLOUR_GREY , WID_CF_MAXLOAN_VALUE ) , SetDataTip ( STR_FINANCES_MAX_LOAN , STR_NULL ) ,
2009-10-10 15:18:20 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2009-03-27 22:59:43 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2011-12-16 16:27:45 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_CF_SEL_BUTTONS ) ,
2009-10-10 15:18:20 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2021-03-22 01:29:54 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_CF_INCREASE_LOAN ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FINANCES_BORROW_BUTTON , STR_NULL ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_CF_REPAY_LOAN ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FINANCES_REPAY_BUTTON , STR_NULL ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_CF_INFRASTRUCTURE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FINANCES_INFRASTRUCTURE_BUTTON , STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP ) ,
2009-03-27 22:59:43 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2004-08-09 17:04:08 +00:00
} ;
2018-10-28 02:17:36 +00:00
/** Window class displaying the company finances. */
2008-09-30 20:39:50 +00:00
struct CompanyFinancesWindow : Window {
2017-04-12 16:46:27 +00:00
Money max_money ; ///< The approximate maximum amount of money a company has had over the lifetime of this window
2009-11-24 12:42:36 +00:00
bool small ; ///< Window is toggled to 'small'.
2021-03-22 01:29:54 +00:00
int query_widget ; ///< The widget associated with the current text query input.
2004-08-09 17:04:08 +00:00
2013-05-26 19:23:42 +00:00
CompanyFinancesWindow ( WindowDesc * desc , CompanyID company ) : Window ( desc )
2008-05-16 07:34:48 +00:00
{
2017-04-11 17:59:47 +00:00
const Company * c = Company : : Get ( company ) ;
2021-02-01 17:07:34 +00:00
this - > max_money = std : : max < Money > ( abs ( c - > money ) * 2 , INT32_MAX ) ;
2009-10-10 15:18:20 +00:00
this - > small = false ;
2013-05-26 19:23:42 +00:00
this - > CreateNestedTree ( ) ;
2009-10-10 15:18:20 +00:00
this - > SetupWidgets ( ) ;
2013-05-26 19:23:42 +00:00
this - > FinishInitNested ( company ) ;
2009-10-10 15:18:20 +00:00
2009-02-09 02:33:10 +00:00
this - > owner = ( Owner ) this - > window_number ;
2009-10-10 15:18:20 +00:00
}
2023-12-29 19:11:59 +00:00
void SetStringParameters ( WidgetID widget ) const override
2009-10-10 15:18:20 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_CF_CAPTION :
2009-11-15 18:21:17 +00:00
SetDParam ( 0 , ( CompanyID ) this - > window_number ) ;
SetDParam ( 1 , ( CompanyID ) this - > window_number ) ;
2009-10-10 15:18:20 +00:00
break ;
2007-08-31 23:02:16 +00:00
2021-04-19 19:57:03 +00:00
case WID_CF_BALANCE_VALUE : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > money ) ;
break ;
}
case WID_CF_LOAN_VALUE : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > current_loan ) ;
break ;
}
2022-02-23 18:03:23 +00:00
case WID_CF_OWN_VALUE : {
2021-04-19 19:57:03 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > money - c - > current_loan ) ;
break ;
}
2022-02-23 18:03:23 +00:00
case WID_CF_INTEREST_RATE :
SetDParam ( 0 , _settings_game . difficulty . initial_interest ) ;
break ;
2024-01-30 18:15:19 +00:00
case WID_CF_MAXLOAN_VALUE : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > GetMaxLoan ( ) ) ;
2009-10-10 15:18:20 +00:00
break ;
2024-01-30 18:15:19 +00:00
}
2004-08-09 17:04:08 +00:00
2011-12-16 16:27:45 +00:00
case WID_CF_INCREASE_LOAN :
case WID_CF_REPAY_LOAN :
2009-11-29 12:52:08 +00:00
SetDParam ( 0 , LOAN_INTERVAL ) ;
2009-10-10 15:18:20 +00:00
break ;
2008-05-16 07:34:48 +00:00
}
2009-10-10 15:18:20 +00:00
}
2023-12-29 19:11:59 +00:00
void UpdateWidgetSize ( WidgetID widget , Dimension * size , [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension * resize ) override
2009-10-10 15:18:20 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_CF_EXPS_CATEGORY :
2022-02-23 18:03:23 +00:00
size - > width = GetMaxCategoriesWidth ( ) ;
size - > height = GetTotalCategoriesHeight ( ) ;
2009-10-10 15:18:20 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_CF_EXPS_PRICE1 :
case WID_CF_EXPS_PRICE2 :
case WID_CF_EXPS_PRICE3 :
2022-02-23 18:03:23 +00:00
size - > height = GetTotalCategoriesHeight ( ) ;
2024-01-31 20:03:17 +00:00
[[fallthrough]] ;
2017-08-13 18:38:42 +00:00
2011-12-16 16:27:45 +00:00
case WID_CF_BALANCE_VALUE :
case WID_CF_LOAN_VALUE :
2022-02-23 18:03:23 +00:00
case WID_CF_OWN_VALUE :
2017-04-12 16:46:27 +00:00
SetDParamMaxValue ( 0 , this - > max_money ) ;
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( GetStringBoundingBox ( STR_FINANCES_NEGATIVE_INCOME ) . width , GetStringBoundingBox ( STR_FINANCES_POSITIVE_INCOME ) . width ) + padding . width ;
2009-10-10 15:18:20 +00:00
break ;
2022-02-23 18:03:23 +00:00
case WID_CF_INTEREST_RATE :
2023-11-21 19:04:24 +00:00
size - > height = GetCharacterHeight ( FS_NORMAL ) ;
2009-10-10 15:18:20 +00:00
break ;
}
2008-05-16 07:34:48 +00:00
}
2004-08-09 17:04:08 +00:00
2023-12-29 19:11:59 +00:00
void DrawWidget ( const Rect & r , WidgetID widget ) const override
2008-05-16 07:34:48 +00:00
{
2009-10-10 15:18:20 +00:00
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_CF_EXPS_CATEGORY :
2009-10-10 15:18:20 +00:00
DrawCategories ( r ) ;
break ;
2011-12-16 16:27:45 +00:00
case WID_CF_EXPS_PRICE1 :
case WID_CF_EXPS_PRICE2 :
case WID_CF_EXPS_PRICE3 : {
2009-10-10 15:18:20 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2024-02-13 21:34:09 +00:00
YearDelta age = std : : min < YearDelta > ( CalTime : : CurYear ( ) - c - > inaugurated_year , 2 ) ;
2011-12-16 16:27:45 +00:00
int wid_offset = widget - WID_CF_EXPS_PRICE1 ;
2024-02-13 21:34:09 +00:00
if ( wid_offset < = age . base ( ) ) {
DrawYearColumn ( r , CalTime : : CurYear ( ) . base ( ) - ( age . base ( ) - wid_offset ) , c - > yearly_expenses [ age . base ( ) - wid_offset ] ) ;
2009-10-10 15:18:20 +00:00
}
break ;
}
2022-02-23 18:03:23 +00:00
case WID_CF_BALANCE_LINE :
2023-11-13 21:54:26 +00:00
GfxFillRect ( r . left , r . top , r . right , r . top + WidgetDimensions : : scaled . bevel . top - 1 , PC_BLACK ) ;
2009-10-10 15:18:20 +00:00
break ;
}
}
2010-08-01 19:22:34 +00:00
/**
* Setup the widgets in the nested tree , such that the finances window is displayed properly .
2009-10-10 15:18:20 +00:00
* @ note After setup , the window must be ( re - ) initialized .
*/
void SetupWidgets ( )
{
2009-12-22 20:43:25 +00:00
int plane = this - > small ? SZSP_NONE : 0 ;
2011-12-16 16:27:45 +00:00
this - > GetWidget < NWidgetStacked > ( WID_CF_SEL_PANEL ) - > SetDisplayedPlane ( plane ) ;
this - > GetWidget < NWidgetStacked > ( WID_CF_SEL_MAXLOAN ) - > SetDisplayedPlane ( plane ) ;
2009-10-10 15:18:20 +00:00
2008-09-30 20:39:50 +00:00
CompanyID company = ( CompanyID ) this - > window_number ;
2009-12-22 20:43:25 +00:00
plane = ( company ! = _local_company ) ? SZSP_NONE : 0 ;
2011-12-16 16:27:45 +00:00
this - > GetWidget < NWidgetStacked > ( WID_CF_SEL_BUTTONS ) - > SetDisplayedPlane ( plane ) ;
2009-10-10 15:18:20 +00:00
}
2008-05-16 07:34:48 +00:00
2019-03-04 07:49:37 +00:00
void OnPaint ( ) override
2009-10-10 15:18:20 +00:00
{
2009-12-21 16:24:29 +00:00
if ( ! this - > IsShaded ( ) ) {
2009-12-22 19:40:23 +00:00
if ( ! this - > small ) {
2009-12-21 16:24:29 +00:00
/* Check that the expenses panel height matches the height needed for the layout. */
2022-02-23 18:03:23 +00:00
if ( GetTotalCategoriesHeight ( ) ! = this - > GetWidget < NWidgetBase > ( WID_CF_EXPS_CATEGORY ) - > current_y ) {
2009-12-21 16:24:29 +00:00
this - > SetupWidgets ( ) ;
this - > ReInit ( ) ;
return ;
}
}
/* Check that the loan buttons are shown only when the user owns the company. */
CompanyID company = ( CompanyID ) this - > window_number ;
2009-12-22 20:43:25 +00:00
int req_plane = ( company ! = _local_company ) ? SZSP_NONE : 0 ;
2011-12-16 16:27:45 +00:00
if ( req_plane ! = this - > GetWidget < NWidgetStacked > ( WID_CF_SEL_BUTTONS ) - > shown_plane ) {
2009-10-10 15:18:20 +00:00
this - > SetupWidgets ( ) ;
this - > ReInit ( ) ;
2009-01-31 21:27:36 +00:00
return ;
}
2009-12-21 16:24:29 +00:00
const Company * c = Company : : Get ( company ) ;
2024-01-30 18:15:19 +00:00
this - > SetWidgetDisabledState ( WID_CF_INCREASE_LOAN , c - > current_loan > = c - > GetMaxLoan ( ) ) ; // Borrow button only shows when there is any more money to loan.
2011-12-16 16:27:45 +00:00
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.
2008-05-16 07:34:48 +00:00
}
2008-04-09 02:02:39 +00:00
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2008-05-16 07:34:48 +00:00
}
2008-04-09 02:16:04 +00:00
2023-12-29 19:11:59 +00:00
void OnClick ( [[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count ) override
2008-05-16 07:34:48 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_CF_TOGGLE_SIZE : // toggle size
2009-10-10 15:18:20 +00:00
this - > small = ! this - > small ;
this - > SetupWidgets ( ) ;
2009-12-30 08:40:05 +00:00
if ( this - > IsShaded ( ) ) {
/* Finances window is not resizable, so size hints given during unshading have no effect
* on the changed appearance of the window . */
this - > SetShaded ( false ) ;
} else {
this - > ReInit ( ) ;
}
2009-10-10 15:18:20 +00:00
break ;
2008-05-16 07:34:48 +00:00
2011-12-16 16:27:45 +00:00
case WID_CF_INCREASE_LOAN : // increase loan
2021-03-22 01:29:54 +00:00
if ( _shift_pressed ) {
this - > query_widget = WID_CF_INCREASE_LOAN ;
SetDParam ( 0 , 0 ) ;
ShowQueryString ( STR_JUST_INT , STR_FINANCES_BORROW_QUERY_CAPT , 20 , this , CS_NUMERAL , QSF_ACCEPT_UNCHANGED ) ;
} else {
DoCommandP ( 0 , 0 , _ctrl_pressed , CMD_INCREASE_LOAN | CMD_MSG ( STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY ) ) ;
}
2008-05-16 07:34:48 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_CF_REPAY_LOAN : // repay loan
2021-03-22 01:29:54 +00:00
if ( _shift_pressed ) {
this - > query_widget = WID_CF_REPAY_LOAN ;
SetDParam ( 0 , 0 ) ;
ShowQueryString ( STR_JUST_INT , STR_FINANCES_REPAY_QUERY_CAPT , 20 , this , CS_NUMERAL , QSF_ACCEPT_UNCHANGED ) ;
} else {
DoCommandP ( 0 , 0 , _ctrl_pressed , CMD_DECREASE_LOAN | CMD_MSG ( STR_ERROR_CAN_T_REPAY_LOAN ) ) ;
}
2008-05-16 07:34:48 +00:00
break ;
2011-12-03 23:40:08 +00:00
2011-12-16 16:27:45 +00:00
case WID_CF_INFRASTRUCTURE : // show infrastructure details
2011-12-03 23:40:08 +00:00
ShowCompanyInfrastructure ( ( CompanyID ) this - > window_number ) ;
break ;
2008-05-16 07:34:48 +00:00
}
2004-08-09 17:04:08 +00:00
}
2009-11-24 12:42:36 +00:00
2021-03-22 01:29:54 +00:00
void OnQueryTextFinished ( char * str ) override
{
/* Was 'cancel' pressed or nothing entered? */
if ( str = = nullptr | | StrEmpty ( str ) ) return ;
if ( this - > query_widget = = WID_CF_INCREASE_LOAN ) {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2023-05-28 09:20:03 +00:00
Money amount = std : : min < Money > ( std : : strtoull ( str , nullptr , 10 ) / _currency - > rate , _economy . max_loan - c - > current_loan ) ;
2021-03-22 01:29:54 +00:00
amount = LOAN_INTERVAL * CeilDivT < Money > ( amount , LOAN_INTERVAL ) ;
DoCommandP ( 0 , amount > > 32 , ( amount & 0xFFFFFFFC ) | 2 , CMD_INCREASE_LOAN | CMD_MSG ( STR_ERROR_CAN_T_BORROW_ANY_MORE_MONEY ) ) ;
} else if ( this - > query_widget = = WID_CF_REPAY_LOAN ) {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2023-05-28 09:20:03 +00:00
Money amount = std : : min < Money > ( std : : strtoull ( str , nullptr , 10 ) / _currency - > rate , c - > current_loan ) ;
2021-03-22 01:29:54 +00:00
amount = LOAN_INTERVAL * CeilDivT < Money > ( amount , LOAN_INTERVAL ) ;
DoCommandP ( 0 , amount > > 32 , ( amount & 0xFFFFFFFC ) | 2 , CMD_DECREASE_LOAN | CMD_MSG ( STR_ERROR_CAN_T_REPAY_LOAN ) ) ;
}
}
2019-03-04 07:49:37 +00:00
void OnHundredthTick ( ) override
2009-11-24 12:42:36 +00:00
{
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2020-10-02 16:49:22 +00:00
if ( abs ( c - > money ) > this - > max_money ) {
2021-02-01 17:07:34 +00:00
this - > max_money = std : : max < Money > ( abs ( c - > money ) * 2 , this - > max_money * 4 ) ;
2009-11-24 12:42:36 +00:00
this - > SetupWidgets ( ) ;
this - > ReInit ( ) ;
}
}
2021-03-22 01:29:54 +00:00
2024-01-02 14:31:56 +00:00
bool OnTooltip ( Point pt , WidgetID widget , TooltipCloseCondition close_cond ) override
2021-03-22 01:29:54 +00:00
{
switch ( widget ) {
case WID_CF_INCREASE_LOAN : {
2023-11-17 17:26:57 +00:00
SetDParam ( 0 , STR_FINANCES_BORROW_TOOLTIP ) ;
GuiShowTooltips ( this , STR_FINANCES_BORROW_TOOLTIP_EXTRA , close_cond , 1 ) ;
2021-03-22 01:29:54 +00:00
return true ;
}
case WID_CF_REPAY_LOAN : {
2023-11-17 17:26:57 +00:00
SetDParam ( 0 , STR_FINANCES_REPAY_TOOLTIP ) ;
GuiShowTooltips ( this , STR_FINANCES_REPAY_TOOLTIP_EXTRA , close_cond , 1 ) ;
2021-03-22 01:29:54 +00:00
return true ;
}
default :
return false ;
}
}
2008-05-16 07:34:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2023-11-02 19:33:01 +00:00
static WindowDesc _company_finances_desc ( __FILE__ , __LINE__ ,
2013-05-26 19:25:01 +00:00
WDP_AUTO , " company_finances " , 0 , 0 ,
2007-02-01 15:49:12 +00:00
WC_FINANCES , WC_NONE ,
2012-11-11 16:10:43 +00:00
0 ,
2023-09-03 20:54:13 +00:00
std : : begin ( _nested_company_finances_widgets ) , std : : end ( _nested_company_finances_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2010-08-01 19:22:34 +00:00
/**
* Open the finances window of a company .
2009-10-10 15:18:20 +00:00
* @ param company Company to show finances of .
* @ pre is company a valid company .
2008-04-09 02:02:39 +00:00
*/
2009-10-10 15:18:20 +00:00
void ShowCompanyFinances ( CompanyID company )
2004-08-09 17:04:08 +00:00
{
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( company ) ) return ;
2008-09-30 20:39:50 +00:00
if ( BringWindowToFrontById ( WC_FINANCES , company ) ) return ;
2004-08-09 17:04:08 +00:00
2009-10-10 15:18:20 +00:00
new CompanyFinancesWindow ( & _company_finances_desc , company ) ;
2004-08-09 17:04:08 +00:00
}
2006-09-15 12:27:00 +00:00
/* List of colours for the livery window */
static const StringID _colour_dropdown [ ] = {
2009-04-21 23:40:56 +00:00
STR_COLOUR_DARK_BLUE ,
STR_COLOUR_PALE_GREEN ,
STR_COLOUR_PINK ,
STR_COLOUR_YELLOW ,
STR_COLOUR_RED ,
STR_COLOUR_LIGHT_BLUE ,
STR_COLOUR_GREEN ,
STR_COLOUR_DARK_GREEN ,
STR_COLOUR_BLUE ,
STR_COLOUR_CREAM ,
STR_COLOUR_MAUVE ,
STR_COLOUR_PURPLE ,
STR_COLOUR_ORANGE ,
STR_COLOUR_BROWN ,
STR_COLOUR_GREY ,
STR_COLOUR_WHITE ,
2006-09-15 12:27:00 +00:00
} ;
/* Association of liveries to livery classes */
2008-05-14 22:52:12 +00:00
static const LiveryClass _livery_class [ LS_END ] = {
2006-09-15 12:27:00 +00:00
LC_OTHER ,
2008-01-16 11:25:15 +00:00
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 ,
2006-09-15 12:27:00 +00:00
LC_ROAD , LC_ROAD ,
LC_SHIP , LC_SHIP ,
LC_AIRCRAFT , LC_AIRCRAFT , LC_AIRCRAFT ,
2007-05-27 09:33:41 +00:00
LC_ROAD , LC_ROAD ,
2006-09-15 12:27:00 +00:00
} ;
2023-11-11 15:17:12 +00:00
/**
* Colour selection list item , with icon and string components .
* @ tparam TSprite Recolourable sprite to draw as icon .
*/
template < SpriteID TSprite = SPR_SQUARE >
class DropDownListColourItem : public DropDownIcon < DropDownString < DropDownListItem > > {
2008-04-12 22:19:34 +00:00
public :
2024-01-21 13:23:04 +00:00
DropDownListColourItem ( int colour , bool masked ) : DropDownIcon < DropDownString < DropDownListItem > > ( TSprite , GENERAL_SPRITE_COLOUR ( colour % COLOUR_END ) , colour < COLOUR_END ? _colour_dropdown [ colour ] : STR_COLOUR_DEFAULT , colour , masked )
2008-04-12 22:19:34 +00:00
{
}
} ;
2009-11-14 15:34:21 +00:00
/** Company livery colour scheme window. */
2008-09-30 20:39:50 +00:00
struct SelectCompanyLiveryWindow : public Window {
2008-05-14 22:52:12 +00:00
private :
2024-01-07 16:41:53 +00:00
uint32_t sel ;
2008-05-14 22:52:12 +00:00
LiveryClass livery_class ;
2011-10-11 17:32:17 +00:00
Dimension square ;
2019-01-31 21:43:18 +00:00
uint rows ;
2011-10-11 17:32:17 +00:00
uint line_height ;
2019-01-31 13:57:44 +00:00
GUIGroupList groups ;
2019-03-03 17:30:09 +00:00
std : : vector < int > indents ;
2019-01-31 13:57:44 +00:00
Scrollbar * vscroll ;
2008-05-14 22:52:12 +00:00
2024-01-07 16:41:53 +00:00
void ShowColourDropDownMenu ( uint32_t widget )
2008-05-14 22:52:12 +00:00
{
2024-01-07 16:41:53 +00:00
uint32_t used_colours = 0 ;
2019-04-10 21:07:06 +00:00
const Livery * livery , * default_livery = nullptr ;
2019-01-31 13:57:44 +00:00
bool primary = widget = = WID_SCL_PRI_COL_DROPDOWN ;
2023-01-03 18:02:36 +00:00
byte default_col = 0 ;
2008-05-14 22:52:12 +00:00
2008-09-30 20:39:50 +00:00
/* Disallow other company colours for the primary colour */
2019-01-31 13:57:44 +00:00
if ( this - > livery_class < LC_GROUP_RAIL & & HasBit ( this - > sel , LS_DEFAULT ) & & primary ) {
2019-12-14 16:22:38 +00:00
for ( const Company * c : Company : : Iterate ( ) ) {
2008-09-30 20:39:50 +00:00
if ( c - > index ! = _local_company ) SetBit ( used_colours , c - > colour ) ;
2008-05-14 22:52:12 +00:00
}
2004-08-09 17:04:08 +00:00
}
2006-09-15 12:27:00 +00:00
2023-01-28 19:06:51 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2019-01-31 13:57:44 +00:00
if ( this - > livery_class < LC_GROUP_RAIL ) {
/* Get the first selected livery to use as the default dropdown item */
LiveryScheme scheme ;
for ( scheme = LS_BEGIN ; scheme < LS_END ; scheme + + ) {
if ( HasBit ( this - > sel , scheme ) ) break ;
}
if ( scheme = = LS_END ) scheme = LS_DEFAULT ;
livery = & c - > livery [ scheme ] ;
if ( scheme ! = LS_DEFAULT ) default_livery = & c - > livery [ LS_DEFAULT ] ;
} else {
const Group * g = Group : : Get ( this - > sel ) ;
livery = & g - > livery ;
if ( g - > parent = = INVALID_GROUP ) {
default_livery = & c - > livery [ LS_DEFAULT ] ;
} else {
const Group * pg = Group : : Get ( g - > parent ) ;
default_livery = & pg - > livery ;
}
2008-05-14 22:52:12 +00:00
}
2006-09-15 12:27:00 +00:00
2019-04-02 19:31:24 +00:00
DropDownList list ;
2019-04-10 21:07:06 +00:00
if ( default_livery ! = nullptr ) {
2019-01-31 13:57:44 +00:00
/* Add COLOUR_END to put the colour out of range, but also allow us to show what the default is */
default_col = ( primary ? default_livery - > colour1 : default_livery - > colour2 ) + COLOUR_END ;
2023-11-11 15:17:12 +00:00
list . push_back ( std : : make_unique < DropDownListColourItem < > > ( default_col , false ) ) ;
2019-01-31 13:57:44 +00:00
}
2008-05-14 22:52:12 +00:00
for ( uint i = 0 ; i < lengthof ( _colour_dropdown ) ; i + + ) {
2023-11-11 15:17:12 +00:00
list . push_back ( std : : make_unique < DropDownListColourItem < > > ( i , HasBit ( used_colours , i ) ) ) ;
2008-05-14 22:52:12 +00:00
}
2008-04-12 22:19:34 +00:00
2024-01-21 13:23:04 +00:00
byte sel ;
if ( default_livery = = nullptr | | HasBit ( livery - > in_use , primary ? 0 : 1 ) ) {
sel = primary ? livery - > colour1 : livery - > colour2 ;
} else {
sel = default_col ;
}
2019-04-02 19:31:24 +00:00
ShowDropDownList ( this , std : : move ( list ) , sel , widget ) ;
2019-01-31 13:57:44 +00:00
}
2023-05-14 08:17:44 +00:00
void AddChildren ( GUIGroupList & source , GroupID parent , int indent )
2019-01-31 13:57:44 +00:00
{
2023-05-14 08:17:44 +00:00
for ( const Group * g : source ) {
2019-02-17 11:20:52 +00:00
if ( g - > parent ! = parent ) continue ;
this - > groups . push_back ( g ) ;
2019-02-18 22:39:06 +00:00
this - > indents . push_back ( indent ) ;
2019-02-17 11:20:52 +00:00
AddChildren ( source , g - > index , indent + 1 ) ;
2019-01-31 13:57:44 +00:00
}
}
void BuildGroupList ( CompanyID owner )
{
if ( ! this - > groups . NeedRebuild ( ) ) return ;
2018-09-20 22:44:14 +00:00
this - > groups . clear ( ) ;
this - > indents . clear ( ) ;
2019-01-31 13:57:44 +00:00
if ( this - > livery_class > = LC_GROUP_RAIL ) {
GUIGroupList list ;
VehicleType vtype = ( VehicleType ) ( this - > livery_class - LC_GROUP_RAIL ) ;
2019-12-16 17:01:57 +00:00
for ( const Group * g : Group : : Iterate ( ) ) {
2019-01-31 13:57:44 +00:00
if ( g - > owner = = owner & & g - > vehicle_type = = vtype ) {
2019-02-18 22:39:06 +00:00
list . push_back ( g ) ;
2019-01-31 13:57:44 +00:00
}
}
list . ForceResort ( ) ;
2023-08-19 00:13:00 +00:00
SortGUIGroupList ( list ) ;
2019-01-31 13:57:44 +00:00
2023-05-14 08:17:44 +00:00
AddChildren ( list , INVALID_GROUP , 0 ) ;
2019-01-31 13:57:44 +00:00
}
2018-09-21 21:45:44 +00:00
this - > groups . shrink_to_fit ( ) ;
2019-01-31 13:57:44 +00:00
this - > groups . RebuildDone ( ) ;
}
2019-01-31 21:43:18 +00:00
void SetRows ( )
2019-01-31 13:57:44 +00:00
{
if ( this - > livery_class < LC_GROUP_RAIL ) {
2019-01-31 21:43:18 +00:00
this - > rows = 0 ;
2019-01-31 13:57:44 +00:00
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
if ( _livery_class [ scheme ] = = this - > livery_class & & HasBit ( _loaded_newgrf_features . used_liveries , scheme ) ) {
2019-01-31 21:43:18 +00:00
this - > rows + + ;
2019-01-31 13:57:44 +00:00
}
}
} else {
2019-03-27 23:09:33 +00:00
this - > rows = ( uint ) this - > groups . size ( ) ;
2019-01-31 13:57:44 +00:00
}
2019-01-31 21:43:18 +00:00
this - > vscroll - > SetCount ( this - > rows ) ;
2008-05-14 22:52:12 +00:00
}
2006-09-15 12:27:00 +00:00
2008-05-14 22:52:12 +00:00
public :
2019-01-31 13:57:44 +00:00
SelectCompanyLiveryWindow ( WindowDesc * desc , CompanyID company , GroupID group ) : Window ( desc )
2008-05-14 22:52:12 +00:00
{
2019-01-31 13:57:44 +00:00
this - > CreateNestedTree ( ) ;
this - > vscroll = this - > GetScrollbar ( WID_SCL_MATRIX_SCROLLBAR ) ;
2011-10-11 17:32:17 +00:00
2019-01-31 13:57:44 +00:00
if ( group = = INVALID_GROUP ) {
this - > livery_class = LC_OTHER ;
this - > sel = 1 ;
this - > LowerWidget ( WID_SCL_CLASS_GENERAL ) ;
this - > BuildGroupList ( company ) ;
2019-01-31 21:43:18 +00:00
this - > SetRows ( ) ;
2019-01-31 13:57:44 +00:00
} else {
2019-02-26 22:13:24 +00:00
this - > SetSelectedGroup ( company , group ) ;
2019-01-31 13:57:44 +00:00
}
2011-10-11 17:32:17 +00:00
2019-01-31 13:57:44 +00:00
this - > FinishInitNested ( company ) ;
2009-11-14 15:34:21 +00:00
this - > owner = company ;
2010-09-25 22:00:49 +00:00
this - > InvalidateData ( 1 ) ;
2008-05-14 22:52:12 +00:00
}
2006-10-03 20:16:20 +00:00
2019-02-26 22:13:24 +00:00
void SetSelectedGroup ( CompanyID company , GroupID group )
2019-01-31 13:57:44 +00:00
{
2024-01-16 21:01:28 +00:00
this - > RaiseWidget ( WID_SCL_CLASS_GENERAL + this - > livery_class ) ;
2019-01-31 13:57:44 +00:00
const Group * g = Group : : Get ( group ) ;
switch ( g - > vehicle_type ) {
case VEH_TRAIN : this - > livery_class = LC_GROUP_RAIL ; break ;
case VEH_ROAD : this - > livery_class = LC_GROUP_ROAD ; break ;
case VEH_SHIP : this - > livery_class = LC_GROUP_SHIP ; break ;
case VEH_AIRCRAFT : this - > livery_class = LC_GROUP_AIRCRAFT ; break ;
default : NOT_REACHED ( ) ;
}
this - > sel = group ;
2024-01-16 21:01:28 +00:00
this - > LowerWidget ( WID_SCL_CLASS_GENERAL + this - > livery_class ) ;
2019-01-31 13:57:44 +00:00
this - > groups . ForceRebuild ( ) ;
2019-02-26 22:13:24 +00:00
this - > BuildGroupList ( company ) ;
2019-01-31 21:43:18 +00:00
this - > SetRows ( ) ;
2019-01-31 13:57:44 +00:00
/* Position scrollbar to selected group */
2019-01-31 21:43:18 +00:00
for ( uint i = 0 ; i < this - > rows ; i + + ) {
2019-01-31 13:57:44 +00:00
if ( this - > groups [ i ] - > index = = sel ) {
2023-03-09 15:19:58 +00:00
this - > vscroll - > SetPosition ( i - this - > vscroll - > GetCapacity ( ) / 2 ) ;
2019-01-31 13:57:44 +00:00
break ;
}
}
}
2023-12-29 19:11:59 +00:00
void UpdateWidgetSize ( WidgetID widget , Dimension * size , [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension * resize ) override
2008-05-14 22:52:12 +00:00
{
2009-11-14 15:34:21 +00:00
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_SCL_SPACER_DROPDOWN : {
2009-11-14 15:34:21 +00:00
/* The matrix widget below needs enough room to print all the schemes. */
Dimension d = { 0 , 0 } ;
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
d = maxdim ( d , GetStringBoundingBox ( STR_LIVERY_DEFAULT + scheme ) ) ;
}
2019-01-31 13:57:44 +00:00
/* And group names */
2019-12-16 17:01:57 +00:00
for ( const Group * g : Group : : Iterate ( ) ) {
2019-01-31 13:57:44 +00:00
if ( g - > owner = = ( CompanyID ) this - > window_number ) {
SetDParam ( 0 , g - > index ) ;
d = maxdim ( d , GetStringBoundingBox ( STR_GROUP_NAME ) ) ;
}
}
2022-09-23 08:36:22 +00:00
size - > width = std : : max ( size - > width , 5 + d . width + padding . width ) ;
2009-11-14 15:34:21 +00:00
break ;
}
2011-12-16 16:27:45 +00:00
case WID_SCL_MATRIX : {
2019-01-31 13:57:44 +00:00
/* 11 items in the default rail class */
2019-02-02 14:44:02 +00:00
this - > square = GetSpriteSize ( SPR_SQUARE ) ;
2023-11-21 19:04:24 +00:00
this - > line_height = std : : max ( this - > square . height , ( uint ) GetCharacterHeight ( FS_NORMAL ) ) + padding . height ;
2019-02-02 14:44:02 +00:00
2023-12-22 23:42:52 +00:00
size - > height = 5 * this - > line_height ;
2019-01-31 13:57:44 +00:00
resize - > width = 1 ;
resize - > height = this - > line_height ;
2009-11-14 15:34:21 +00:00
break ;
2010-09-25 22:00:49 +00:00
}
2009-11-14 15:34:21 +00:00
2011-12-16 16:27:45 +00:00
case WID_SCL_SEC_COL_DROPDOWN :
2009-11-22 13:01:07 +00:00
if ( ! _loaded_newgrf_features . has_2CC ) {
size - > width = 0 ;
break ;
}
2024-01-31 20:03:17 +00:00
[[fallthrough]] ;
2017-08-13 18:38:42 +00:00
2011-12-16 16:27:45 +00:00
case WID_SCL_PRI_COL_DROPDOWN : {
2019-02-02 14:44:02 +00:00
this - > square = GetSpriteSize ( SPR_SQUARE ) ;
2022-09-23 08:36:22 +00:00
int string_padding = this - > square . width + WidgetDimensions : : scaled . hsep_normal + padding . width ;
2009-11-22 13:01:07 +00:00
for ( const StringID * id = _colour_dropdown ; id ! = endof ( _colour_dropdown ) ; id + + ) {
2021-05-26 18:51:17 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( * id ) . width + string_padding ) ;
2009-11-22 13:01:07 +00:00
}
2021-05-26 18:51:17 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COLOUR_DEFAULT ) . width + string_padding ) ;
2010-08-01 18:53:30 +00:00
break ;
}
2009-11-14 15:34:21 +00:00
}
}
2019-03-04 07:49:37 +00:00
void OnPaint ( ) override
2009-11-14 15:34:21 +00:00
{
2019-01-27 01:34:30 +00:00
bool local = ( CompanyID ) this - > window_number = = _local_company ;
2008-05-14 22:52:12 +00:00
/* Disable dropdown controls if no scheme is selected */
2019-01-31 13:57:44 +00:00
bool disabled = this - > livery_class < LC_GROUP_RAIL ? ( this - > sel = = 0 ) : ( this - > sel = = INVALID_GROUP ) ;
this - > SetWidgetDisabledState ( WID_SCL_PRI_COL_DROPDOWN , ! local | | disabled ) ;
this - > SetWidgetDisabledState ( WID_SCL_SEC_COL_DROPDOWN , ! local | | disabled ) ;
this - > BuildGroupList ( ( CompanyID ) this - > window_number ) ;
2006-10-03 02:08:15 +00:00
2009-11-14 15:34:21 +00:00
this - > DrawWidgets ( ) ;
}
2006-09-15 12:27:00 +00:00
2023-12-29 19:11:59 +00:00
void SetStringParameters ( WidgetID widget ) const override
2009-11-14 15:34:21 +00:00
{
switch ( widget ) {
2019-01-27 01:34:30 +00:00
case WID_SCL_CAPTION :
SetDParam ( 0 , ( CompanyID ) this - > window_number ) ;
break ;
2011-12-16 16:27:45 +00:00
case WID_SCL_PRI_COL_DROPDOWN :
case WID_SCL_SEC_COL_DROPDOWN : {
2009-11-14 15:34:21 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2019-01-31 13:57:44 +00:00
bool primary = widget = = WID_SCL_PRI_COL_DROPDOWN ;
StringID colour = STR_COLOUR_DEFAULT ;
if ( this - > livery_class < LC_GROUP_RAIL ) {
if ( this - > sel ! = 0 ) {
LiveryScheme scheme = LS_DEFAULT ;
for ( scheme = LS_BEGIN ; scheme < LS_END ; scheme + + ) {
if ( HasBit ( this - > sel , scheme ) ) break ;
}
if ( scheme = = LS_END ) scheme = LS_DEFAULT ;
const Livery * livery = & c - > livery [ scheme ] ;
if ( scheme = = LS_DEFAULT | | HasBit ( livery - > in_use , primary ? 0 : 1 ) ) {
colour = STR_COLOUR_DARK_BLUE + ( primary ? livery - > colour1 : livery - > colour2 ) ;
}
}
} else {
if ( this - > sel ! = INVALID_GROUP ) {
const Group * g = Group : : Get ( this - > sel ) ;
const Livery * livery = & g - > livery ;
if ( HasBit ( livery - > in_use , primary ? 0 : 1 ) ) {
colour = STR_COLOUR_DARK_BLUE + ( primary ? livery - > colour1 : livery - > colour2 ) ;
}
2009-11-14 15:34:21 +00:00
}
}
2019-01-31 13:57:44 +00:00
SetDParam ( 0 , colour ) ;
2009-11-14 15:34:21 +00:00
break ;
}
}
}
2006-09-15 12:27:00 +00:00
2023-12-29 19:11:59 +00:00
void DrawWidget ( const Rect & r , WidgetID widget ) const override
2009-11-14 15:34:21 +00:00
{
2011-12-16 16:27:45 +00:00
if ( widget ! = WID_SCL_MATRIX ) return ;
2009-11-14 15:34:21 +00:00
2010-11-13 09:56:25 +00:00
bool rtl = _current_text_dir = = TD_RTL ;
2009-11-18 12:45:20 +00:00
2022-10-15 15:55:47 +00:00
/* Coordinates of scheme name column. */
2011-12-16 16:27:45 +00:00
const NWidgetBase * nwi = this - > GetWidget < NWidgetBase > ( WID_SCL_SPACER_DROPDOWN ) ;
2022-09-23 08:36:22 +00:00
Rect sch = nwi - > GetCurrentRect ( ) . Shrink ( WidgetDimensions : : scaled . framerect ) ;
2022-10-15 15:55:47 +00:00
/* Coordinates of first dropdown. */
2011-12-16 16:27:45 +00:00
nwi = this - > GetWidget < NWidgetBase > ( WID_SCL_PRI_COL_DROPDOWN ) ;
2022-09-23 08:36:22 +00:00
Rect pri = nwi - > GetCurrentRect ( ) . Shrink ( WidgetDimensions : : scaled . framerect ) ;
2022-10-15 15:55:47 +00:00
/* Coordinates of second dropdown. */
2011-12-16 16:27:45 +00:00
nwi = this - > GetWidget < NWidgetBase > ( WID_SCL_SEC_COL_DROPDOWN ) ;
2022-09-23 08:36:22 +00:00
Rect sec = nwi - > GetCurrentRect ( ) . Shrink ( WidgetDimensions : : scaled . framerect ) ;
2009-11-14 15:34:21 +00:00
2022-10-15 15:55:47 +00:00
Rect pri_squ = pri . WithWidth ( this - > square . width , rtl ) ;
Rect sec_squ = sec . WithWidth ( this - > square . width , rtl ) ;
2009-11-14 15:34:21 +00:00
2022-09-23 08:36:22 +00:00
pri = pri . Indent ( this - > square . width + WidgetDimensions : : scaled . hsep_normal , rtl ) ;
sec = sec . Indent ( this - > square . width + WidgetDimensions : : scaled . hsep_normal , rtl ) ;
2011-10-11 17:32:17 +00:00
2022-09-23 08:36:22 +00:00
Rect ir = r . WithHeight ( this - > resize . step_height ) . Shrink ( WidgetDimensions : : scaled . matrix ) ;
2022-10-15 15:55:47 +00:00
int square_offs = ( ir . Height ( ) - this - > square . height ) / 2 ;
2023-11-21 19:04:24 +00:00
int text_offs = ( ir . Height ( ) - GetCharacterHeight ( FS_NORMAL ) ) / 2 ;
2009-11-18 12:45:20 +00:00
2022-10-15 15:55:47 +00:00
int y = ir . top ;
2004-09-11 09:40:19 +00:00
2019-01-31 13:57:44 +00:00
/* Helper function to draw livery info. */
2023-12-27 15:26:33 +00:00
auto draw_livery = [ & ] ( StringID str , const Livery & livery , bool is_selected , bool is_default_scheme , int indent ) {
2019-01-31 13:57:44 +00:00
/* Livery Label. */
2023-12-27 15:26:33 +00:00
DrawString ( sch . left + ( rtl ? 0 : indent ) , sch . right - ( rtl ? indent : 0 ) , y + text_offs , str , is_selected ? TC_WHITE : TC_BLACK ) ;
2004-08-09 17:04:08 +00:00
2019-01-31 13:57:44 +00:00
/* Text below the first dropdown. */
2023-12-27 15:26:33 +00:00
DrawSprite ( SPR_SQUARE , GENERAL_SPRITE_COLOUR ( livery . colour1 ) , pri_squ . left , y + square_offs ) ;
DrawString ( pri . left , pri . right , y + text_offs , ( is_default_scheme | | HasBit ( livery . in_use , 0 ) ) ? STR_COLOUR_DARK_BLUE + livery . colour1 : STR_COLOUR_DEFAULT , is_selected ? TC_WHITE : TC_GOLD ) ;
2006-09-15 12:27:00 +00:00
2019-01-31 13:57:44 +00:00
/* Text below the second dropdown. */
2022-10-15 15:55:47 +00:00
if ( sec . right > sec . left ) { // Second dropdown has non-zero size.
2023-12-27 15:26:33 +00:00
DrawSprite ( SPR_SQUARE , GENERAL_SPRITE_COLOUR ( livery . colour2 ) , sec_squ . left , y + square_offs ) ;
DrawString ( sec . left , sec . right , y + text_offs , ( is_default_scheme | | HasBit ( livery . in_use , 1 ) ) ? STR_COLOUR_DARK_BLUE + livery . colour2 : STR_COLOUR_DEFAULT , is_selected ? TC_WHITE : TC_GOLD ) ;
2019-01-31 13:57:44 +00:00
}
y + = this - > line_height ;
} ;
2008-05-14 22:52:12 +00:00
2023-12-22 16:56:09 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2019-01-31 13:57:44 +00:00
if ( livery_class < LC_GROUP_RAIL ) {
2019-01-31 21:43:18 +00:00
int pos = this - > vscroll - > GetPosition ( ) ;
2019-01-31 13:57:44 +00:00
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
if ( _livery_class [ scheme ] = = this - > livery_class & & HasBit ( _loaded_newgrf_features . used_liveries , scheme ) ) {
2019-01-31 21:43:18 +00:00
if ( pos - - > 0 ) continue ;
2019-01-31 13:57:44 +00:00
draw_livery ( STR_LIVERY_DEFAULT + scheme , c - > livery [ scheme ] , HasBit ( this - > sel , scheme ) , scheme = = LS_DEFAULT , 0 ) ;
}
}
} else {
2021-01-08 10:16:18 +00:00
uint max = static_cast < uint > ( std : : min < size_t > ( this - > vscroll - > GetPosition ( ) + this - > vscroll - > GetCapacity ( ) , this - > groups . size ( ) ) ) ;
2019-01-31 13:57:44 +00:00
for ( uint i = this - > vscroll - > GetPosition ( ) ; i < max ; + + i ) {
const Group * g = this - > groups [ i ] ;
SetDParam ( 0 , g - > index ) ;
2023-12-27 15:26:33 +00:00
draw_livery ( STR_GROUP_NAME , g - > livery , this - > sel = = g - > index , false , this - > indents [ i ] * WidgetDimensions : : scaled . hsep_indent ) ;
2004-08-09 17:04:08 +00:00
}
2023-12-22 23:58:25 +00:00
if ( this - > vscroll - > GetCount ( ) = = 0 ) {
const StringID empty_labels [ ] = { STR_LIVERY_TRAIN_GROUP_EMPTY , STR_LIVERY_ROAD_VEHICLE_GROUP_EMPTY , STR_LIVERY_SHIP_GROUP_EMPTY , STR_LIVERY_AIRCRAFT_GROUP_EMPTY } ;
VehicleType vtype = ( VehicleType ) ( this - > livery_class - LC_GROUP_RAIL ) ;
DrawString ( ir . left , ir . right , y + text_offs , empty_labels [ vtype ] , TC_BLACK ) ;
}
2004-08-09 17:04:08 +00:00
}
2008-05-14 22:52:12 +00:00
}
2004-09-11 09:40:19 +00:00
2023-12-29 19:11:59 +00:00
void OnClick ( [[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count ) override
2008-05-14 22:52:12 +00:00
{
switch ( widget ) {
/* Livery Class buttons */
2011-12-16 16:27:45 +00:00
case WID_SCL_CLASS_GENERAL :
case WID_SCL_CLASS_RAIL :
case WID_SCL_CLASS_ROAD :
case WID_SCL_CLASS_SHIP :
case WID_SCL_CLASS_AIRCRAFT :
2019-01-31 13:57:44 +00:00
case WID_SCL_GROUPS_RAIL :
case WID_SCL_GROUPS_ROAD :
case WID_SCL_GROUPS_SHIP :
case WID_SCL_GROUPS_AIRCRAFT :
2024-01-16 21:01:28 +00:00
this - > RaiseWidget ( WID_SCL_CLASS_GENERAL + this - > livery_class ) ;
2011-12-16 16:27:45 +00:00
this - > livery_class = ( LiveryClass ) ( widget - WID_SCL_CLASS_GENERAL ) ;
2024-01-16 21:01:28 +00:00
this - > LowerWidget ( WID_SCL_CLASS_GENERAL + this - > livery_class ) ;
2008-05-14 22:52:12 +00:00
/* Select the first item in the list */
2019-01-31 13:57:44 +00:00
if ( this - > livery_class < LC_GROUP_RAIL ) {
this - > sel = 0 ;
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
if ( _livery_class [ scheme ] = = this - > livery_class & & HasBit ( _loaded_newgrf_features . used_liveries , scheme ) ) {
this - > sel = 1 < < scheme ;
break ;
}
}
} else {
this - > sel = INVALID_GROUP ;
this - > groups . ForceRebuild ( ) ;
this - > BuildGroupList ( ( CompanyID ) this - > window_number ) ;
2023-10-20 18:18:31 +00:00
if ( ! this - > groups . empty ( ) ) {
2019-01-31 13:57:44 +00:00
this - > sel = this - > groups [ 0 ] - > index ;
2006-09-15 12:27:00 +00:00
}
}
2009-11-14 15:34:21 +00:00
2019-01-31 21:43:18 +00:00
this - > SetRows ( ) ;
2019-01-31 13:57:44 +00:00
this - > SetDirty ( ) ;
2008-05-14 22:52:12 +00:00
break ;
2006-09-15 12:27:00 +00:00
2011-12-16 16:27:45 +00:00
case WID_SCL_PRI_COL_DROPDOWN : // First colour dropdown
ShowColourDropDownMenu ( WID_SCL_PRI_COL_DROPDOWN ) ;
2008-05-14 22:52:12 +00:00
break ;
2006-09-15 12:27:00 +00:00
2011-12-16 16:27:45 +00:00
case WID_SCL_SEC_COL_DROPDOWN : // Second colour dropdown
ShowColourDropDownMenu ( WID_SCL_SEC_COL_DROPDOWN ) ;
2008-05-14 22:52:12 +00:00
break ;
2006-09-15 12:27:00 +00:00
2011-12-16 16:27:45 +00:00
case WID_SCL_MATRIX : {
2021-04-21 14:22:45 +00:00
uint row = this - > vscroll - > GetScrolledRowFromWidget ( pt . y , this , WID_SCL_MATRIX ) ;
2019-01-31 21:43:18 +00:00
if ( row > = this - > rows ) return ;
2006-09-15 12:27:00 +00:00
2019-01-31 21:43:18 +00:00
if ( this - > livery_class < LC_GROUP_RAIL ) {
LiveryScheme j = ( LiveryScheme ) row ;
2006-09-15 12:27:00 +00:00
2019-01-31 21:43:18 +00:00
for ( LiveryScheme scheme = LS_BEGIN ; scheme < = j & & scheme < LS_END ; scheme + + ) {
2019-01-31 13:57:44 +00:00
if ( _livery_class [ scheme ] ! = this - > livery_class | | ! HasBit ( _loaded_newgrf_features . used_liveries , scheme ) ) j + + ;
}
2019-01-31 21:43:18 +00:00
assert ( j < LS_END ) ;
2006-09-15 12:27:00 +00:00
2019-01-31 13:57:44 +00:00
if ( _ctrl_pressed ) {
ToggleBit ( this - > sel , j ) ;
} else {
this - > sel = 1 < < j ;
}
2008-05-14 22:52:12 +00:00
} else {
2019-01-31 21:43:18 +00:00
this - > sel = this - > groups [ row ] - > index ;
2004-08-09 17:04:08 +00:00
}
2008-05-14 22:52:12 +00:00
this - > SetDirty ( ) ;
break ;
2004-08-09 17:04:08 +00:00
}
2006-09-15 12:27:00 +00:00
}
2008-05-14 22:52:12 +00:00
}
2006-09-15 12:27:00 +00:00
2019-03-04 07:49:37 +00:00
void OnResize ( ) override
2019-01-31 13:57:44 +00:00
{
this - > vscroll - > SetCapacityFromWidget ( this , WID_SCL_MATRIX ) ;
}
2023-12-29 19:11:59 +00:00
void OnDropdownSelect ( WidgetID widget , int index ) override
2008-05-14 22:52:12 +00:00
{
2019-01-27 01:34:30 +00:00
bool local = ( CompanyID ) this - > window_number = = _local_company ;
if ( ! local ) return ;
2024-01-21 13:23:04 +00:00
Colours colour = static_cast < Colours > ( index ) ;
if ( colour > = COLOUR_END ) colour = INVALID_COLOUR ;
2019-01-31 13:57:44 +00:00
if ( this - > livery_class < LC_GROUP_RAIL ) {
/* Set company colour livery */
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
/* Changed colour for the selected scheme, or all visible schemes if CTRL is pressed. */
if ( HasBit ( this - > sel , scheme ) | | ( _ctrl_pressed & & _livery_class [ scheme ] = = this - > livery_class & & HasBit ( _loaded_newgrf_features . used_liveries , scheme ) ) ) {
DoCommandP ( 0 , scheme | ( widget = = WID_SCL_PRI_COL_DROPDOWN ? 0 : 256 ) , index , CMD_SET_COMPANY_COLOUR ) ;
}
2006-09-15 12:27:00 +00:00
}
2019-01-31 13:57:44 +00:00
} else {
/* Setting group livery */
DoCommandP ( 0 , this - > sel , ( widget = = WID_SCL_PRI_COL_DROPDOWN ? 0 : 256 ) | ( index < < 16 ) , CMD_SET_GROUP_LIVERY ) ;
2004-08-09 17:04:08 +00:00
}
}
2008-05-14 23:02:05 +00:00
2011-03-13 21:31:29 +00:00
/**
* Some data on this window has become invalid .
* @ param data Information about the changed data .
* @ 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 .
*/
2023-09-16 20:20:53 +00:00
void OnInvalidateData ( [[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true ) override
2008-05-14 23:02:05 +00:00
{
2011-03-13 21:31:29 +00:00
if ( ! gui_scope ) return ;
2019-01-31 13:57:44 +00:00
if ( data ! = - 1 ) {
/* data contains a VehicleType, rebuild list if it displayed */
if ( this - > livery_class = = data + LC_GROUP_RAIL ) {
this - > groups . ForceRebuild ( ) ;
this - > BuildGroupList ( ( CompanyID ) this - > window_number ) ;
2019-02-26 06:45:14 +00:00
this - > SetRows ( ) ;
if ( ! Group : : IsValidID ( this - > sel ) ) {
this - > sel = INVALID_GROUP ;
2023-10-20 18:18:31 +00:00
if ( ! this - > groups . empty ( ) ) this - > sel = this - > groups [ 0 ] - > index ;
2019-02-26 06:45:14 +00:00
}
2019-01-31 13:57:44 +00:00
this - > SetDirty ( ) ;
}
return ;
}
2023-09-16 19:56:09 +00:00
this - > SetWidgetsDisabledState ( true , WID_SCL_CLASS_RAIL , WID_SCL_CLASS_ROAD , WID_SCL_CLASS_SHIP , WID_SCL_CLASS_AIRCRAFT ) ;
2010-09-25 22:00:49 +00:00
2019-01-31 13:57:44 +00:00
bool current_class_valid = this - > livery_class = = LC_OTHER | | this - > livery_class > = LC_GROUP_RAIL ;
2010-09-25 22:00:49 +00:00
if ( _settings_client . gui . liveries = = LIT_ALL | | ( _settings_client . gui . liveries = = LIT_COMPANY & & this - > window_number = = _local_company ) ) {
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
if ( HasBit ( _loaded_newgrf_features . used_liveries , scheme ) ) {
if ( _livery_class [ scheme ] = = this - > livery_class ) current_class_valid = true ;
2011-12-16 16:27:45 +00:00
this - > EnableWidget ( WID_SCL_CLASS_GENERAL + _livery_class [ scheme ] ) ;
2019-01-31 13:57:44 +00:00
} else if ( this - > livery_class < LC_GROUP_RAIL ) {
2010-09-25 22:00:49 +00:00
ClrBit ( this - > sel , scheme ) ;
}
}
}
if ( ! current_class_valid ) {
Point pt = { 0 , 0 } ;
2011-12-16 16:27:45 +00:00
this - > OnClick ( pt , WID_SCL_CLASS_GENERAL , 1 ) ;
2010-09-25 22:00:49 +00:00
}
2008-05-14 23:02:05 +00:00
}
2008-05-14 22:52:12 +00:00
} ;
2004-08-09 17:04:08 +00:00
2024-01-15 22:49:24 +00:00
static constexpr NWidgetPart _nested_select_company_livery_widgets [ ] = {
2009-03-28 04:14:02 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , WID_SCL_CAPTION ) , SetDataTip ( STR_LIVERY_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2024-02-13 15:55:13 +00:00
NWidget ( WWT_SHADEBOX , COLOUR_GREY ) ,
NWidget ( WWT_DEFSIZEBOX , COLOUR_GREY ) ,
NWidget ( WWT_STICKYBOX , COLOUR_GREY ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_CLASS_GENERAL ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_COMPANY_GENERAL , STR_LIVERY_GENERAL_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_CLASS_RAIL ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_TRAINLIST , STR_LIVERY_TRAIN_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_CLASS_ROAD ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_TRUCKLIST , STR_LIVERY_ROAD_VEHICLE_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_CLASS_SHIP ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_SHIPLIST , STR_LIVERY_SHIP_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_CLASS_AIRCRAFT ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_AIRPLANESLIST , STR_LIVERY_AIRCRAFT_TOOLTIP ) ,
2023-12-22 23:57:46 +00:00
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_GROUPS_RAIL ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_GROUP_LIVERY_TRAIN , STR_LIVERY_TRAIN_GROUP_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_GROUPS_ROAD ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_GROUP_LIVERY_ROADVEH , STR_LIVERY_ROAD_VEHICLE_GROUP_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_GROUPS_SHIP ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_GROUP_LIVERY_SHIP , STR_LIVERY_SHIP_GROUP_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCL_GROUPS_AIRCRAFT ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_GROUP_LIVERY_AIRCRAFT , STR_LIVERY_AIRCRAFT_GROUP_TOOLTIP ) ,
2023-12-22 23:42:52 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) , SetFill ( 1 , 1 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2023-12-22 23:34:23 +00:00
NWidget ( WWT_MATRIX , COLOUR_GREY , WID_SCL_MATRIX ) , SetMinimalSize ( 275 , 0 ) , SetResize ( 1 , 0 ) , SetFill ( 1 , 1 ) , SetMatrixDataTip ( 1 , 0 , STR_LIVERY_PANEL_TOOLTIP ) , SetScrollbar ( WID_SCL_MATRIX_SCROLLBAR ) ,
NWidget ( NWID_VSCROLLBAR , COLOUR_GREY , WID_SCL_MATRIX_SCROLLBAR ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
2019-01-31 13:57:44 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2023-12-22 23:42:52 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY , WID_SCL_SPACER_DROPDOWN ) , SetFill ( 1 , 1 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( WWT_DROPDOWN , COLOUR_GREY , WID_SCL_PRI_COL_DROPDOWN ) , SetFill ( 0 , 1 ) , SetDataTip ( STR_JUST_STRING , STR_LIVERY_PRIMARY_TOOLTIP ) ,
NWidget ( WWT_DROPDOWN , COLOUR_GREY , WID_SCL_SEC_COL_DROPDOWN ) , SetFill ( 0 , 1 ) , SetDataTip ( STR_JUST_STRING , STR_LIVERY_SECONDARY_TOOLTIP ) ,
2023-12-22 23:34:23 +00:00
NWidget ( WWT_RESIZEBOX , COLOUR_GREY ) ,
2019-01-31 13:57:44 +00:00
EndContainer ( ) ,
2004-08-09 17:04:08 +00:00
} ;
2023-11-02 19:33:01 +00:00
static WindowDesc _select_company_livery_desc ( __FILE__ , __LINE__ ,
2024-02-13 15:55:13 +00:00
WDP_AUTO , " company_color_scheme " , 0 , 0 ,
2009-02-09 02:57:15 +00:00
WC_COMPANY_COLOUR , WC_NONE ,
2009-11-24 17:28:29 +00:00
0 ,
2023-09-03 20:54:13 +00:00
std : : begin ( _nested_select_company_livery_widgets ) , std : : end ( _nested_select_company_livery_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2019-01-31 13:57:44 +00:00
void ShowCompanyLiveryWindow ( CompanyID company , GroupID group )
{
SelectCompanyLiveryWindow * w = ( SelectCompanyLiveryWindow * ) BringWindowToFrontById ( WC_COMPANY_COLOUR , company ) ;
2019-04-10 21:07:06 +00:00
if ( w = = nullptr ) {
2019-01-31 13:57:44 +00:00
new SelectCompanyLiveryWindow ( & _select_company_livery_desc , company , group ) ;
} else if ( group ! = INVALID_GROUP ) {
2019-02-26 22:13:24 +00:00
w - > SetSelectedGroup ( company , group ) ;
2019-01-31 13:57:44 +00:00
}
}
2007-03-02 01:17:11 +00:00
/**
2008-09-30 20:39:50 +00:00
* Draws the face of a company manager ' s face .
* @ param cmf the company manager ' s face
2009-02-09 02:57:15 +00:00
* @ param colour the ( background ) colour of the gradient
2023-04-21 18:54:04 +00:00
* @ param r position to draw the face
2007-03-02 01:17:11 +00:00
*/
2024-01-21 13:23:04 +00:00
void DrawCompanyManagerFace ( CompanyManagerFace cmf , Colours colour , const Rect & r )
2007-03-02 01:17:11 +00:00
{
2008-09-30 20:39:50 +00:00
GenderEthnicity ge = ( GenderEthnicity ) GetCompanyManagerFaceBits ( cmf , CMFV_GEN_ETHN , GE_WM ) ;
2007-03-02 01:17:11 +00:00
2023-04-21 18:54:04 +00:00
/* Determine offset from centre of drawing rect. */
Dimension d = GetSpriteSize ( SPR_GRADIENT ) ;
int x = CenterBounds ( r . left , r . right , d . width ) ;
int y = CenterBounds ( r . top , r . bottom , d . height ) ;
2008-09-30 20:39:50 +00:00
bool has_moustache = ! HasBit ( ge , GENDER_FEMALE ) & & GetCompanyManagerFaceBits ( cmf , CMFV_HAS_MOUSTACHE , ge ) ! = 0 ;
bool has_tie_earring = ! HasBit ( ge , GENDER_FEMALE ) | | GetCompanyManagerFaceBits ( cmf , CMFV_HAS_TIE_EARRING , ge ) ! = 0 ;
bool has_glasses = GetCompanyManagerFaceBits ( cmf , CMFV_HAS_GLASSES , ge ) ! = 0 ;
2010-01-21 01:38:13 +00:00
PaletteID pal ;
2007-10-15 19:59:27 +00:00
/* Modify eye colour palette only if 2 or more valid values exist */
2008-09-30 20:39:50 +00:00
if ( _cmf_info [ CMFV_EYE_COLOUR ] . valid_values [ ge ] < 2 ) {
2007-10-15 19:59:27 +00:00
pal = PAL_NONE ;
} else {
2008-09-30 20:39:50 +00:00
switch ( GetCompanyManagerFaceBits ( cmf , CMFV_EYE_COLOUR , ge ) ) {
2007-10-15 19:59:27 +00:00
default : NOT_REACHED ( ) ;
case 0 : pal = PALETTE_TO_BROWN ; break ;
case 1 : pal = PALETTE_TO_BLUE ; break ;
case 2 : pal = PALETTE_TO_GREEN ; break ;
}
2007-03-02 01:17:11 +00:00
}
/* Draw the gradient (background) */
2009-02-09 02:57:15 +00:00
DrawSprite ( SPR_GRADIENT , GENERAL_SPRITE_COLOUR ( colour ) , x , y ) ;
2007-03-02 01:17:11 +00:00
2008-09-30 20:39:50 +00:00
for ( CompanyManagerFaceVariable cmfv = CMFV_CHEEKS ; cmfv < CMFV_END ; cmfv + + ) {
switch ( cmfv ) {
case CMFV_MOUSTACHE : if ( ! has_moustache ) continue ; break ;
2017-08-13 18:38:42 +00:00
case CMFV_LIPS :
2008-09-30 20:39:50 +00:00
case CMFV_NOSE : if ( has_moustache ) continue ; break ;
case CMFV_TIE_EARRING : if ( ! has_tie_earring ) continue ; break ;
case CMFV_GLASSES : if ( ! has_glasses ) continue ; break ;
2007-03-02 01:17:11 +00:00
default : break ;
}
2008-09-30 20:39:50 +00:00
DrawSprite ( GetCompanyManagerFaceSprite ( cmf , cmfv , ge ) , ( cmfv = = CMFV_EYEBROWS ) ? pal : PAL_NONE , x , y ) ;
2007-03-02 01:17:11 +00:00
}
}
2009-11-28 13:47:57 +00:00
/** Nested widget description for the company manager face selection dialog */
2024-01-15 22:49:24 +00:00
static constexpr NWidgetPart _nested_select_company_manager_face_widgets [ ] = {
2009-03-28 04:14:02 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , WID_SCMF_CAPTION ) , SetDataTip ( STR_FACE_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , WID_SCMF_TOGGLE_LARGE_SMALL ) , SetDataTip ( SPR_LARGE_SMALL_WINDOW , STR_FACE_ADVANCED_TOOLTIP ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY , WID_SCMF_SELECT_FACE ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) , SetPadding ( 2 ) ,
/* Left side */
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_normal , 0 ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIPRatio ( 1 , 0 , 1 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_SCMF_FACE ) , SetMinimalSize ( 92 , 119 ) , SetFill ( 1 , 0 ) ,
2009-11-22 12:18:26 +00:00
EndContainer ( ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_RANDOM_NEW_FACE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_NEW_FACE_BUTTON , STR_FACE_NEW_FACE_TOOLTIP ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_SCMF_SEL_LOADSAVE ) , // Load/number/save buttons under the portrait in the advanced view.
2023-10-28 10:28:28 +00:00
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , 0 , 0 ) , SetPIPRatio ( 1 , 0 , 1 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_LOAD ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_LOAD , STR_FACE_LOAD_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_FACECODE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_FACECODE , STR_FACE_FACECODE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_SAVE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_SAVE , STR_FACE_SAVE_TOOLTIP ) ,
2009-11-28 13:47:57 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
/* Right side */
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_normal , 0 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_ADVANCED , STR_FACE_ADVANCED_TOOLTIP ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_SCMF_SEL_MALEFEMALE ) , // Simple male/female face setting.
2023-10-28 10:28:28 +00:00
NWidget ( NWID_VERTICAL ) , SetPIPRatio ( 1 , 0 , 1 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_GREY , WID_SCMF_MALE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_MALE_BUTTON , STR_FACE_MALE_TOOLTIP ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , WID_SCMF_FEMALE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_FEMALE_BUTTON , STR_FACE_FEMALE_TOOLTIP ) ,
2009-11-28 13:45:03 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2011-12-16 16:27:45 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_SCMF_SEL_PARTS ) , // Advanced face parts setting.
2023-10-28 10:28:28 +00:00
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_normal , 0 ) ,
2009-11-28 13:45:03 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_GREY , WID_SCMF_MALE2 ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_MALE_BUTTON , STR_FACE_MALE_TOOLTIP ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , WID_SCMF_FEMALE2 ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_FEMALE_BUTTON , STR_FACE_FEMALE_TOOLTIP ) ,
2009-11-28 13:45:03 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_GREY , WID_SCMF_ETHNICITY_EUR ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_EUROPEAN , STR_FACE_SELECT_EUROPEAN ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , WID_SCMF_ETHNICITY_AFR ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_AFRICAN , STR_FACE_SELECT_AFRICAN ) ,
2009-11-28 13:45:03 +00:00
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_EYECOLOUR , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_HAS_MOUSTACHE_EARRING ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_MOUSTACHE_EARRING_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_HAS_GLASSES_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_GLASSES , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_HAS_GLASSES ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_GLASSES_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
EndContainer ( ) ,
2009-11-28 13:45:03 +00:00
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_HAIR_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_HAIR , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_HAIR_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_HAIR_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_HAIR ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_HAIR_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_HAIR_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_HAIR_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_EYEBROWS_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_EYEBROWS , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_EYEBROWS_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_EYEBROWS_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_EYEBROWS ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_EYEBROWS_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_EYEBROWS_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_EYEBROWS_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_EYECOLOUR_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_EYECOLOUR , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_EYECOLOUR_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_EYECOLOUR_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_EYECOLOUR ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_EYECOLOUR_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_EYECOLOUR_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_EYECOLOUR_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_GLASSES_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_GLASSES , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_GLASSES_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_GLASSES_TOOLTIP_2 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_GLASSES ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_GLASSES_TOOLTIP_2 ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_GLASSES_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_GLASSES_TOOLTIP_2 ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_NOSE_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_NOSE , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_NOSE_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_NOSE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_NOSE ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_NOSE_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_NOSE_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_NOSE_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_LIPS_MOUSTACHE_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_MOUSTACHE , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_LIPS_MOUSTACHE_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_LIPS_MOUSTACHE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_LIPS_MOUSTACHE ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_LIPS_MOUSTACHE_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_LIPS_MOUSTACHE_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_LIPS_MOUSTACHE_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_CHIN_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_CHIN , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_CHIN_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_CHIN_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_CHIN ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_CHIN_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_CHIN_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_CHIN_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_JACKET_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_JACKET , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_JACKET_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_JACKET_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_JACKET ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_JACKET_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_JACKET_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_JACKET_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_COLLAR_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_COLLAR , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_COLLAR_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_COLLAR_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_COLLAR ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_COLLAR_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_COLLAR_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_COLLAR_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , INVALID_COLOUR , WID_SCMF_TIE_EARRING_TEXT ) , SetFill ( 1 , 0 ) ,
SetDataTip ( STR_FACE_EARRING , STR_NULL ) , SetTextStyle ( TC_GOLD ) , SetAlignment ( SA_VERT_CENTER | SA_RIGHT ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_TIE_EARRING_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_TIE_EARRING_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_TIE_EARRING ) , SetDataTip ( STR_JUST_STRING1 , STR_FACE_TIE_EARRING_TOOLTIP ) , SetTextStyle ( TC_WHITE ) ,
NWidget ( WWT_PUSHARROWBTN , COLOUR_GREY , WID_SCMF_TIE_EARRING_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_TIE_EARRING_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
2009-11-28 13:45:03 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2009-11-28 13:40:41 +00:00
EndContainer ( ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
EndContainer ( ) ,
2009-11-28 13:40:41 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_CANCEL ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_BUTTON_CANCEL , STR_FACE_CANCEL_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_SCMF_ACCEPT ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_BUTTON_OK , STR_FACE_OK_TOOLTIP ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
} ;
2009-11-15 09:46:40 +00:00
/** Management class for customizing the face of the company manager. */
2008-09-30 20:39:50 +00:00
class SelectCompanyManagerFaceWindow : public Window
2007-10-15 19:59:27 +00:00
{
2008-09-30 20:39:50 +00:00
CompanyManagerFace face ; ///< company manager face bits
bool advanced ; ///< advanced company manager face selection window
2007-10-15 19:59:27 +00:00
2009-11-15 09:46:40 +00:00
GenderEthnicity ge ; ///< Gender and ethnicity.
bool is_female ; ///< Female face.
bool is_moust_male ; ///< Male face with a moustache.
2008-05-13 01:05:39 +00:00
2009-11-29 21:16:37 +00:00
Dimension yesno_dim ; ///< Dimension of a yes/no button of a part in the advanced face window.
Dimension number_dim ; ///< Dimension of a number widget of a part in the advanced face window.
2008-05-13 01:05:39 +00:00
/**
2022-09-23 16:09:35 +00:00
* Set parameters for value of face control buttons .
2008-05-13 01:05:39 +00:00
*
* @ param widget_index index of this widget in the window
2022-09-23 16:09:35 +00:00
* @ param val the value which will be displayed
2008-05-13 01:05:39 +00:00
* @ param is_bool_widget is it a bool button
*/
2023-12-29 19:11:59 +00:00
void SetFaceStringParameters ( WidgetID widget_index , uint8_t val , bool is_bool_widget ) const
2008-05-13 01:05:39 +00:00
{
2009-11-15 09:46:40 +00:00
const NWidgetCore * nwi_widget = this - > GetWidget < NWidgetCore > ( widget_index ) ;
2022-09-23 16:09:35 +00:00
if ( nwi_widget - > IsDisabled ( ) ) {
SetDParam ( 0 , STR_EMPTY ) ;
} else {
2008-05-13 01:05:39 +00:00
if ( is_bool_widget ) {
/* if it a bool button write yes or no */
2022-09-23 16:09:35 +00:00
SetDParam ( 0 , ( val ! = 0 ) ? STR_FACE_YES : STR_FACE_NO ) ;
2008-05-13 01:05:39 +00:00
} else {
/* else write the value + 1 */
2022-09-23 16:09:35 +00:00
SetDParam ( 0 , STR_JUST_INT ) ;
SetDParam ( 1 , val + 1 ) ;
2008-05-13 01:05:39 +00:00
}
2007-10-15 19:59:27 +00:00
}
2008-05-13 01:05:39 +00:00
}
2007-10-15 19:59:27 +00:00
2008-05-13 01:05:39 +00:00
void UpdateData ( )
{
2008-09-30 20:39:50 +00:00
this - > ge = ( GenderEthnicity ) GB ( this - > face , _cmf_info [ CMFV_GEN_ETHN ] . offset , _cmf_info [ CMFV_GEN_ETHN ] . length ) ; // get the gender and ethnicity
2008-05-13 01:05:39 +00:00
this - > is_female = HasBit ( this - > ge , GENDER_FEMALE ) ; // get the gender: 0 == male and 1 == female
2008-09-30 20:39:50 +00:00
this - > is_moust_male = ! is_female & & GetCompanyManagerFaceBits ( this - > face , CMFV_HAS_MOUSTACHE , this - > ge ) ! = 0 ; // is a male face with moustache
2021-04-19 16:37:41 +00:00
this - > GetWidget < NWidgetCore > ( WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT ) - > widget_data = this - > is_female ? STR_FACE_EARRING : STR_FACE_MOUSTACHE ;
this - > GetWidget < NWidgetCore > ( WID_SCMF_TIE_EARRING_TEXT ) - > widget_data = this - > is_female ? STR_FACE_EARRING : STR_FACE_TIE ;
this - > GetWidget < NWidgetCore > ( WID_SCMF_LIPS_MOUSTACHE_TEXT ) - > widget_data = this - > is_moust_male ? STR_FACE_MOUSTACHE : STR_FACE_LIPS ;
2007-10-15 19:59:27 +00:00
}
2008-05-13 01:05:39 +00:00
public :
2013-05-26 19:23:42 +00:00
SelectCompanyManagerFaceWindow ( WindowDesc * desc , Window * parent ) : Window ( desc )
2008-05-13 01:05:39 +00:00
{
2009-11-28 13:47:57 +00:00
this - > advanced = false ;
2013-05-26 19:23:42 +00:00
this - > CreateNestedTree ( ) ;
2009-11-28 13:45:03 +00:00
this - > SelectDisplayPlanes ( this - > advanced ) ;
2013-05-26 19:23:42 +00:00
this - > FinishInitNested ( parent - > window_number ) ;
2008-05-15 19:24:15 +00:00
this - > parent = parent ;
2009-02-09 02:33:10 +00:00
this - > owner = ( Owner ) this - > window_number ;
2009-05-16 23:34:14 +00:00
this - > face = Company : : Get ( ( CompanyID ) this - > window_number ) - > face ;
2007-10-15 19:59:27 +00:00
2008-05-13 01:05:39 +00:00
this - > UpdateData ( ) ;
}
2007-10-15 19:59:27 +00:00
2010-08-01 19:22:34 +00:00
/**
2011-12-16 16:27:45 +00:00
* 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 .
2009-11-28 13:45:03 +00:00
* @ param advanced Display advanced face management window .
*/
void SelectDisplayPlanes ( bool advanced )
{
2011-12-16 16:27:45 +00:00
this - > GetWidget < NWidgetStacked > ( WID_SCMF_SEL_LOADSAVE ) - > SetDisplayedPlane ( advanced ? 0 : SZSP_NONE ) ;
this - > GetWidget < NWidgetStacked > ( WID_SCMF_SEL_PARTS ) - > SetDisplayedPlane ( advanced ? 0 : SZSP_NONE ) ;
this - > GetWidget < NWidgetStacked > ( WID_SCMF_SEL_MALEFEMALE ) - > SetDisplayedPlane ( advanced ? SZSP_NONE : 0 ) ;
2014-04-27 15:30:53 +00:00
this - > GetWidget < NWidgetCore > ( WID_SCMF_RANDOM_NEW_FACE ) - > widget_data = advanced ? STR_FACE_RANDOM : STR_FACE_NEW_FACE_BUTTON ;
2009-11-28 13:47:57 +00:00
2011-12-16 16:27:45 +00:00
NWidgetCore * wi = this - > GetWidget < NWidgetCore > ( WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON ) ;
2009-11-28 13:45:03 +00:00
if ( advanced ) {
2009-11-28 13:47:57 +00:00
wi - > SetDataTip ( STR_FACE_SIMPLE , STR_FACE_SIMPLE_TOOLTIP ) ;
2009-11-28 13:45:03 +00:00
} else {
2009-11-28 13:47:57 +00:00
wi - > SetDataTip ( STR_FACE_ADVANCED , STR_FACE_ADVANCED_TOOLTIP ) ;
2009-11-28 13:45:03 +00:00
}
}
2019-03-04 07:49:37 +00:00
void OnInit ( ) override
2009-11-29 21:16:37 +00:00
{
/* Size of the boolean yes/no button. */
Dimension yesno_dim = maxdim ( GetStringBoundingBox ( STR_FACE_YES ) , GetStringBoundingBox ( STR_FACE_NO ) ) ;
2022-09-23 08:36:22 +00:00
yesno_dim . width + = WidgetDimensions : : scaled . framerect . Horizontal ( ) ;
yesno_dim . height + = WidgetDimensions : : scaled . framerect . Vertical ( ) ;
2009-11-29 21:16:37 +00:00
/* Size of the number button + arrows. */
Dimension number_dim = { 0 , 0 } ;
for ( int val = 1 ; val < = 12 ; val + + ) {
SetDParam ( 0 , val ) ;
number_dim = maxdim ( number_dim , GetStringBoundingBox ( STR_JUST_INT ) ) ;
}
2022-09-23 08:36:22 +00:00
uint arrows_width = GetSpriteSize ( SPR_ARROW_LEFT ) . width + GetSpriteSize ( SPR_ARROW_RIGHT ) . width + 2 * ( WidgetDimensions : : scaled . imgbtn . Horizontal ( ) ) ;
number_dim . width + = WidgetDimensions : : scaled . framerect . Horizontal ( ) + arrows_width ;
number_dim . height + = WidgetDimensions : : scaled . framerect . Vertical ( ) ;
2009-11-29 21:16:37 +00:00
/* Compute width of both buttons. */
2021-01-08 10:16:18 +00:00
yesno_dim . width = std : : max ( yesno_dim . width , number_dim . width ) ;
2009-11-29 21:16:37 +00:00
number_dim . width = yesno_dim . width - arrows_width ;
this - > yesno_dim = yesno_dim ;
this - > number_dim = number_dim ;
}
2023-12-29 19:11:59 +00:00
void UpdateWidgetSize ( WidgetID widget , Dimension * size , [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension * resize ) override
2009-11-28 13:34:49 +00:00
{
switch ( widget ) {
2021-04-19 16:37:41 +00:00
case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT :
* size = maxdim ( * size , GetStringBoundingBox ( STR_FACE_EARRING ) ) ;
* size = maxdim ( * size , GetStringBoundingBox ( STR_FACE_MOUSTACHE ) ) ;
2014-09-20 09:18:22 +00:00
break ;
2021-04-19 16:37:41 +00:00
case WID_SCMF_TIE_EARRING_TEXT :
* size = maxdim ( * size , GetStringBoundingBox ( STR_FACE_EARRING ) ) ;
* size = maxdim ( * size , GetStringBoundingBox ( STR_FACE_TIE ) ) ;
2009-11-28 13:34:49 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_LIPS_MOUSTACHE_TEXT :
2021-04-19 16:37:41 +00:00
* size = maxdim ( * size , GetStringBoundingBox ( STR_FACE_LIPS ) ) ;
* size = maxdim ( * size , GetStringBoundingBox ( STR_FACE_MOUSTACHE ) ) ;
2009-11-28 13:34:49 +00:00
break ;
2023-12-03 22:23:54 +00:00
case WID_SCMF_FACE :
* size = maxdim ( * size , GetScaledSpriteSize ( SPR_GRADIENT ) ) ;
2009-11-28 13:34:49 +00:00
break ;
2009-11-28 13:42:35 +00:00
2011-12-16 16:27:45 +00:00
case WID_SCMF_HAS_MOUSTACHE_EARRING :
case WID_SCMF_HAS_GLASSES :
2009-11-29 21:16:37 +00:00
* size = this - > yesno_dim ;
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_EYECOLOUR :
case WID_SCMF_CHIN :
case WID_SCMF_EYEBROWS :
case WID_SCMF_LIPS_MOUSTACHE :
case WID_SCMF_NOSE :
case WID_SCMF_HAIR :
case WID_SCMF_JACKET :
case WID_SCMF_COLLAR :
case WID_SCMF_TIE_EARRING :
case WID_SCMF_GLASSES :
2009-11-29 21:16:37 +00:00
* size = this - > number_dim ;
2009-11-28 13:42:35 +00:00
break ;
2009-11-28 13:34:49 +00:00
}
}
2019-03-04 07:49:37 +00:00
void OnPaint ( ) override
2008-05-13 01:05:39 +00:00
{
/* lower the non-selected gender button */
2023-09-16 19:56:09 +00:00
this - > SetWidgetsLoweredState ( ! this - > is_female , WID_SCMF_MALE , WID_SCMF_MALE2 ) ;
this - > SetWidgetsLoweredState ( this - > is_female , WID_SCMF_FEMALE , WID_SCMF_FEMALE2 ) ;
2007-10-15 19:59:27 +00:00
2008-09-30 20:39:50 +00:00
/* advanced company manager face selection window */
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* lower the non-selected ethnicity button */
2011-12-16 16:27:45 +00:00
this - > SetWidgetLoweredState ( WID_SCMF_ETHNICITY_EUR , ! HasBit ( this - > ge , ETHNICITY_BLACK ) ) ;
this - > SetWidgetLoweredState ( WID_SCMF_ETHNICITY_AFR , HasBit ( this - > ge , ETHNICITY_BLACK ) ) ;
2008-04-09 02:02:39 +00:00
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Disable dynamically the widgets which CompanyManagerFaceVariable has less than 2 options
* ( or in other words you haven ' t any choice ) .
* If the widgets depend on a HAS - variable and this is false the widgets will be disabled , too . */
/* Eye colour buttons */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_EYE_COLOUR ] . valid_values [ this - > ge ] < 2 ,
2023-09-16 19:56:09 +00:00
WID_SCMF_EYECOLOUR , WID_SCMF_EYECOLOUR_L , WID_SCMF_EYECOLOUR_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Chin buttons */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_CHIN ] . valid_values [ this - > ge ] < 2 ,
2023-09-16 19:56:09 +00:00
WID_SCMF_CHIN , WID_SCMF_CHIN_L , WID_SCMF_CHIN_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Eyebrows buttons */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_EYEBROWS ] . valid_values [ this - > ge ] < 2 ,
2023-09-16 19:56:09 +00:00
WID_SCMF_EYEBROWS , WID_SCMF_EYEBROWS_L , WID_SCMF_EYEBROWS_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Lips or (if it a male face with a moustache) moustache buttons */
this - > SetWidgetsDisabledState ( _cmf_info [ this - > is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS ] . valid_values [ this - > ge ] < 2 ,
2023-09-16 19:56:09 +00:00
WID_SCMF_LIPS_MOUSTACHE , WID_SCMF_LIPS_MOUSTACHE_L , WID_SCMF_LIPS_MOUSTACHE_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Nose buttons | male faces with moustache haven't any nose options */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_NOSE ] . valid_values [ this - > ge ] < 2 | | this - > is_moust_male ,
2023-09-16 19:56:09 +00:00
WID_SCMF_NOSE , WID_SCMF_NOSE_L , WID_SCMF_NOSE_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Hair buttons */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_HAIR ] . valid_values [ this - > ge ] < 2 ,
2023-09-16 19:56:09 +00:00
WID_SCMF_HAIR , WID_SCMF_HAIR_L , WID_SCMF_HAIR_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Jacket buttons */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_JACKET ] . valid_values [ this - > ge ] < 2 ,
2023-09-16 19:56:09 +00:00
WID_SCMF_JACKET , WID_SCMF_JACKET_L , WID_SCMF_JACKET_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Collar buttons */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_COLLAR ] . valid_values [ this - > ge ] < 2 ,
2023-09-16 19:56:09 +00:00
WID_SCMF_COLLAR , WID_SCMF_COLLAR_L , WID_SCMF_COLLAR_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Tie/earring buttons | female faces without earring haven't any earring options */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_TIE_EARRING ] . valid_values [ this - > ge ] < 2 | |
2008-09-30 20:39:50 +00:00
( this - > is_female & & GetCompanyManagerFaceBits ( this - > face , CMFV_HAS_TIE_EARRING , this - > ge ) = = 0 ) ,
2023-09-16 19:56:09 +00:00
WID_SCMF_TIE_EARRING , WID_SCMF_TIE_EARRING_L , WID_SCMF_TIE_EARRING_R ) ;
2007-10-15 19:59:27 +00:00
2009-11-28 13:47:57 +00:00
/* Glasses buttons | faces without glasses haven't any glasses options */
this - > SetWidgetsDisabledState ( _cmf_info [ CMFV_GLASSES ] . valid_values [ this - > ge ] < 2 | | GetCompanyManagerFaceBits ( this - > face , CMFV_HAS_GLASSES , this - > ge ) = = 0 ,
2023-09-16 19:56:09 +00:00
WID_SCMF_GLASSES , WID_SCMF_GLASSES_L , WID_SCMF_GLASSES_R ) ;
2007-10-15 19:59:27 +00:00
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2009-11-15 09:46:40 +00:00
}
2008-05-13 01:05:39 +00:00
2023-12-29 19:11:59 +00:00
void SetStringParameters ( WidgetID widget ) const override
2009-11-15 09:46:40 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_SCMF_HAS_MOUSTACHE_EARRING :
2010-02-10 21:06:05 +00:00
if ( this - > is_female ) { // Only for female faces
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_HAS_MOUSTACHE_EARRING , GetCompanyManagerFaceBits ( this - > face , CMFV_HAS_TIE_EARRING , this - > ge ) , true ) ;
2010-02-10 21:06:05 +00:00
} else { // Only for male faces
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_HAS_MOUSTACHE_EARRING , GetCompanyManagerFaceBits ( this - > face , CMFV_HAS_MOUSTACHE , this - > ge ) , true ) ;
2009-11-15 09:46:40 +00:00
}
break ;
2008-05-13 01:05:39 +00:00
2011-12-16 16:27:45 +00:00
case WID_SCMF_TIE_EARRING :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_TIE_EARRING , GetCompanyManagerFaceBits ( this - > face , CMFV_TIE_EARRING , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_LIPS_MOUSTACHE :
2010-02-10 21:06:05 +00:00
if ( this - > is_moust_male ) { // Only for male faces with moustache
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_LIPS_MOUSTACHE , GetCompanyManagerFaceBits ( this - > face , CMFV_MOUSTACHE , this - > ge ) , false ) ;
2010-02-10 21:06:05 +00:00
} else { // Only for female faces or male faces without moustache
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_LIPS_MOUSTACHE , GetCompanyManagerFaceBits ( this - > face , CMFV_LIPS , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
}
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_HAS_GLASSES :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_HAS_GLASSES , GetCompanyManagerFaceBits ( this - > face , CMFV_HAS_GLASSES , this - > ge ) , true ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_HAIR :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_HAIR , GetCompanyManagerFaceBits ( this - > face , CMFV_HAIR , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_EYEBROWS :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_EYEBROWS , GetCompanyManagerFaceBits ( this - > face , CMFV_EYEBROWS , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_EYECOLOUR :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_EYECOLOUR , GetCompanyManagerFaceBits ( this - > face , CMFV_EYE_COLOUR , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_GLASSES :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_GLASSES , GetCompanyManagerFaceBits ( this - > face , CMFV_GLASSES , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_NOSE :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_NOSE , GetCompanyManagerFaceBits ( this - > face , CMFV_NOSE , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_CHIN :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_CHIN , GetCompanyManagerFaceBits ( this - > face , CMFV_CHIN , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_JACKET :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_JACKET , GetCompanyManagerFaceBits ( this - > face , CMFV_JACKET , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_SCMF_COLLAR :
2022-09-23 16:09:35 +00:00
this - > SetFaceStringParameters ( WID_SCMF_COLLAR , GetCompanyManagerFaceBits ( this - > face , CMFV_COLLAR , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
2022-09-23 16:09:35 +00:00
}
}
2009-11-15 09:46:40 +00:00
2023-12-29 19:11:59 +00:00
void DrawWidget ( const Rect & r , WidgetID widget ) const override
2022-09-23 16:09:35 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_SCMF_FACE :
2023-04-21 18:54:04 +00:00
DrawCompanyManagerFace ( this - > face , Company : : Get ( ( CompanyID ) this - > window_number ) - > colour , r ) ;
2009-11-15 09:46:40 +00:00
break ;
}
2004-08-09 17:04:08 +00:00
}
2008-05-13 01:05:39 +00:00
2023-12-29 19:11:59 +00:00
void OnClick ( [[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count ) override
2008-05-13 01:05:39 +00:00
{
switch ( widget ) {
/* Toggle size, advanced/simple face selection */
2011-12-16 16:27:45 +00:00
case WID_SCMF_TOGGLE_LARGE_SMALL :
case WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON :
2009-11-28 13:47:57 +00:00
this - > advanced = ! this - > advanced ;
this - > SelectDisplayPlanes ( this - > advanced ) ;
this - > ReInit ( ) ;
break ;
2008-05-13 01:05:39 +00:00
/* OK button */
2011-12-16 16:27:45 +00:00
case WID_SCMF_ACCEPT :
2008-12-28 14:37:19 +00:00
DoCommandP ( 0 , 0 , this - > face , CMD_SET_COMPANY_MANAGER_FACE ) ;
2024-01-31 20:03:17 +00:00
[[fallthrough]] ;
2008-05-13 01:05:39 +00:00
/* Cancel button */
2011-12-16 16:27:45 +00:00
case WID_SCMF_CANCEL :
2023-09-15 22:56:33 +00:00
this - > Close ( ) ;
2008-05-13 01:05:39 +00:00
break ;
/* Load button */
2011-12-16 16:27:45 +00:00
case WID_SCMF_LOAD :
2008-09-30 20:39:50 +00:00
this - > face = _company_manager_face ;
ScaleAllCompanyManagerFaceBits ( this - > face ) ;
2010-02-24 14:46:15 +00:00
ShowErrorMessage ( STR_FACE_LOAD_DONE , INVALID_STRING_ID , WL_INFO ) ;
2008-05-13 01:05:39 +00:00
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
break ;
2008-09-30 20:39:50 +00:00
/* 'Company manager face number' button, view and/or set company manager face number */
2011-12-16 16:27:45 +00:00
case WID_SCMF_FACECODE :
2008-05-13 01:05:39 +00:00
SetDParam ( 0 , this - > face ) ;
2011-04-17 18:42:17 +00:00
ShowQueryString ( STR_JUST_INT , STR_FACE_FACECODE_CAPTION , 10 + 1 , this , CS_NUMERAL , QSF_NONE ) ;
2008-05-13 01:05:39 +00:00
break ;
/* Save button */
2011-12-16 16:27:45 +00:00
case WID_SCMF_SAVE :
2008-09-30 20:39:50 +00:00
_company_manager_face = this - > face ;
2010-02-24 14:46:15 +00:00
ShowErrorMessage ( STR_FACE_SAVE_DONE , INVALID_STRING_ID , WL_INFO ) ;
2008-05-13 01:05:39 +00:00
break ;
/* Toggle gender (male/female) button */
2011-12-16 16:27:45 +00:00
case WID_SCMF_MALE :
case WID_SCMF_FEMALE :
case WID_SCMF_MALE2 :
case WID_SCMF_FEMALE2 :
SetCompanyManagerFaceBits ( this - > face , CMFV_GENDER , this - > ge , ( widget = = WID_SCMF_FEMALE | | widget = = WID_SCMF_FEMALE2 ) ) ;
2008-09-30 20:39:50 +00:00
ScaleAllCompanyManagerFaceBits ( this - > face ) ;
2008-05-13 01:05:39 +00:00
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
break ;
/* Randomize face button */
2011-12-16 16:27:45 +00:00
case WID_SCMF_RANDOM_NEW_FACE :
2023-01-13 21:30:18 +00:00
RandomCompanyManagerFaceBits ( this - > face , this - > ge , this - > advanced , _interactive_random ) ;
2008-05-13 01:05:39 +00:00
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
break ;
/* Toggle ethnicity (european/african) button */
2011-12-16 16:27:45 +00:00
case WID_SCMF_ETHNICITY_EUR :
case WID_SCMF_ETHNICITY_AFR :
SetCompanyManagerFaceBits ( this - > face , CMFV_ETHNICITY , this - > ge , widget - WID_SCMF_ETHNICITY_EUR ) ;
2008-09-30 20:39:50 +00:00
ScaleAllCompanyManagerFaceBits ( this - > face ) ;
2008-05-13 01:05:39 +00:00
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
break ;
default :
2011-12-16 16:27:45 +00:00
/* Here all buttons from WID_SCMF_HAS_MOUSTACHE_EARRING to WID_SCMF_GLASSES_R are handled.
2009-11-15 09:46:40 +00:00
* First it checks which CompanyManagerFaceVariable is being changed , and then either
* a : invert the value for boolean variables , or
* b : it checks inside of IncreaseCompanyManagerFaceBits ( ) if a left ( _L ) butten is pressed and then decrease else increase the variable */
2011-12-16 16:27:45 +00:00
if ( widget > = WID_SCMF_HAS_MOUSTACHE_EARRING & & widget < = WID_SCMF_GLASSES_R ) {
2008-09-30 20:39:50 +00:00
CompanyManagerFaceVariable cmfv ; // which CompanyManagerFaceVariable shall be edited
2008-05-13 01:05:39 +00:00
2011-12-16 16:27:45 +00:00
if ( widget < WID_SCMF_EYECOLOUR_L ) { // Bool buttons
switch ( widget - WID_SCMF_HAS_MOUSTACHE_EARRING ) {
2008-05-13 01:05:39 +00:00
default : NOT_REACHED ( ) ;
2008-09-30 20:39:50 +00:00
case 0 : cmfv = this - > is_female ? CMFV_HAS_TIE_EARRING : CMFV_HAS_MOUSTACHE ; break ; // Has earring/moustache button
case 1 : cmfv = CMFV_HAS_GLASSES ; break ; // Has glasses button
2008-05-13 01:05:39 +00:00
}
2008-09-30 20:39:50 +00:00
SetCompanyManagerFaceBits ( this - > face , cmfv , this - > ge , ! GetCompanyManagerFaceBits ( this - > face , cmfv , this - > ge ) ) ;
ScaleAllCompanyManagerFaceBits ( this - > face ) ;
2008-05-13 01:05:39 +00:00
} else { // Value buttons
2011-12-16 16:27:45 +00:00
switch ( ( widget - WID_SCMF_EYECOLOUR_L ) / 3 ) {
2008-05-13 01:05:39 +00:00
default : NOT_REACHED ( ) ;
2008-09-30 20:39:50 +00:00
case 0 : cmfv = CMFV_EYE_COLOUR ; break ; // Eye colour buttons
case 1 : cmfv = CMFV_CHIN ; break ; // Chin buttons
case 2 : cmfv = CMFV_EYEBROWS ; break ; // Eyebrows buttons
case 3 : cmfv = this - > is_moust_male ? CMFV_MOUSTACHE : CMFV_LIPS ; break ; // Moustache or lips buttons
case 4 : cmfv = CMFV_NOSE ; break ; // Nose buttons
case 5 : cmfv = CMFV_HAIR ; break ; // Hair buttons
case 6 : cmfv = CMFV_JACKET ; break ; // Jacket buttons
case 7 : cmfv = CMFV_COLLAR ; break ; // Collar buttons
case 8 : cmfv = CMFV_TIE_EARRING ; break ; // Tie/earring buttons
case 9 : cmfv = CMFV_GLASSES ; break ; // Glasses buttons
2008-05-13 01:05:39 +00:00
}
/* 0 == left (_L), 1 == middle or 2 == right (_R) - button click */
2011-12-16 16:27:45 +00:00
IncreaseCompanyManagerFaceBits ( this - > face , cmfv , this - > ge , ( ( ( widget - WID_SCMF_EYECOLOUR_L ) % 3 ) ! = 0 ) ? 1 : - 1 ) ;
2008-05-13 01:05:39 +00:00
}
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
}
break ;
}
}
2019-03-04 07:49:37 +00:00
void OnQueryTextFinished ( char * str ) override
2008-05-13 01:05:39 +00:00
{
2019-04-10 21:07:06 +00:00
if ( str = = nullptr ) return ;
2008-09-30 20:39:50 +00:00
/* Set a new company manager face number */
2008-05-13 01:05:39 +00:00
if ( ! StrEmpty ( str ) ) {
2023-04-26 11:56:14 +00:00
this - > face = std : : strtoul ( str , nullptr , 10 ) ;
2008-09-30 20:39:50 +00:00
ScaleAllCompanyManagerFaceBits ( this - > face ) ;
2010-02-24 14:46:15 +00:00
ShowErrorMessage ( STR_FACE_FACECODE_SET , INVALID_STRING_ID , WL_INFO ) ;
2008-05-13 01:05:39 +00:00
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
} else {
2010-02-24 14:46:15 +00:00
ShowErrorMessage ( STR_FACE_FACECODE_ERR , INVALID_STRING_ID , WL_INFO ) ;
2008-05-13 01:05:39 +00:00
}
}
} ;
2004-08-09 17:04:08 +00:00
2009-11-28 13:47:57 +00:00
/** Company manager face selection window description */
2023-11-02 19:33:01 +00:00
static WindowDesc _select_company_manager_face_desc ( __FILE__ , __LINE__ ,
2023-07-13 15:41:06 +00:00
WDP_AUTO , nullptr , 0 , 0 ,
2008-09-30 20:39:50 +00:00
WC_COMPANY_MANAGER_FACE , WC_NONE ,
2012-11-11 16:10:43 +00:00
WDF_CONSTRUCTION ,
2023-09-03 20:54:13 +00:00
std : : begin ( _nested_select_company_manager_face_widgets ) , std : : end ( _nested_select_company_manager_face_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2007-10-15 19:59:27 +00:00
/**
2008-09-30 20:39:50 +00:00
* Open the simple / advanced company manager face selection window
2007-10-15 19:59:27 +00:00
*
2008-09-30 20:39:50 +00:00
* @ param parent the parent company window
2007-10-15 19:59:27 +00:00
*/
2009-11-28 13:47:57 +00:00
static void DoSelectCompanyManagerFace ( Window * parent )
2007-10-15 19:59:27 +00:00
{
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( ( CompanyID ) parent - > window_number ) ) return ;
2007-10-15 19:59:27 +00:00
2008-09-30 20:39:50 +00:00
if ( BringWindowToFrontById ( WC_COMPANY_MANAGER_FACE , parent - > window_number ) ) return ;
2009-11-28 13:47:57 +00:00
new SelectCompanyManagerFaceWindow ( & _select_company_manager_face_desc , parent ) ;
2007-10-15 19:59:27 +00:00
}
2024-01-15 22:49:24 +00:00
static constexpr NWidgetPart _nested_company_infrastructure_widgets [ ] = {
2011-12-03 23:40:08 +00:00
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , WID_CI_CAPTION ) , SetDataTip ( STR_COMPANY_INFRASTRUCTURE_VIEW_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2011-12-03 23:40:08 +00:00
NWidget ( WWT_SHADEBOX , COLOUR_GREY ) ,
NWidget ( WWT_STICKYBOX , COLOUR_GREY ) ,
EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_GREY ) ,
2022-04-29 00:37:49 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2022-12-04 20:25:38 +00:00
NWidget ( NWID_VERTICAL ) , SetPIP ( WidgetDimensions : : unscaled . framerect . top , 0 , WidgetDimensions : : unscaled . framerect . bottom ) ,
2022-04-29 00:37:49 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 2 , 4 , 2 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_CI_DESC ) , SetMinimalTextLines ( 2 , 0 ) , SetFill ( 1 , 0 ) , SetResize ( 0 , 1 ) , SetScrollbar ( WID_CI_SCROLLBAR ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_CI_COUNT ) , SetMinimalTextLines ( 2 , 0 ) , SetFill ( 0 , 1 ) , SetResize ( 0 , 1 ) , SetScrollbar ( WID_CI_SCROLLBAR ) ,
EndContainer ( ) ,
2011-12-03 23:40:08 +00:00
EndContainer ( ) ,
2022-04-29 00:37:49 +00:00
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_VSCROLLBAR , COLOUR_GREY , WID_CI_SCROLLBAR ) ,
NWidget ( WWT_RESIZEBOX , COLOUR_GREY ) ,
2011-12-03 23:40:46 +00:00
EndContainer ( ) ,
2011-12-03 23:40:08 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
} ;
/**
* Window with detailed information about the company ' s infrastructure .
*/
struct CompanyInfrastructureWindow : Window
{
RailTypes railtypes ; ///< Valid railtypes.
RoadTypes roadtypes ; ///< Valid roadtypes.
2022-04-29 00:37:49 +00:00
uint total_width ; ///< String width of the total cost line.
2022-04-29 16:01:43 +00:00
uint height_extra ; ///< Default extra height above minimum.
2022-04-29 00:37:49 +00:00
Scrollbar * vscroll ; ///< Scrollbar
2011-12-03 23:40:46 +00:00
2013-05-26 19:23:42 +00:00
CompanyInfrastructureWindow ( WindowDesc * desc , WindowNumber window_number ) : Window ( desc )
2011-12-03 23:40:08 +00:00
{
this - > UpdateRailRoadTypes ( ) ;
this - > owner = ( Owner ) this - > window_number ;
2022-04-29 00:37:49 +00:00
this - > CreateNestedTree ( ) ;
this - > vscroll = this - > GetScrollbar ( WID_CI_SCROLLBAR ) ;
2023-12-17 01:16:40 +00:00
this - > vscroll - > SetStepSize ( GetCharacterHeight ( FS_NORMAL ) ) ;
2022-04-29 00:37:49 +00:00
this - > FinishInitNested ( window_number ) ;
2011-12-03 23:40:08 +00:00
}
void UpdateRailRoadTypes ( )
{
this - > railtypes = RAILTYPES_NONE ;
2019-04-06 06:46:15 +00:00
this - > roadtypes = ROADTYPES_NONE ;
2011-12-03 23:40:08 +00:00
/* Find the used railtypes. */
2019-12-15 21:45:18 +00:00
for ( const Engine * e : Engine : : IterateType ( VEH_TRAIN ) ) {
2011-12-03 23:40:08 +00:00
if ( ! HasBit ( e - > info . climates , _settings_game . game_creation . landscape ) ) continue ;
this - > railtypes | = GetRailTypeInfo ( e - > u . rail . railtype ) - > introduces_railtypes ;
}
/* Get the date introduced railtypes as well. */
2024-02-13 21:34:09 +00:00
this - > railtypes = AddDateIntroducedRailTypes ( this - > railtypes , CalTime : : MAX_DATE ) ;
2011-12-03 23:40:08 +00:00
2019-04-06 06:46:15 +00:00
/* Find the used roadtypes. */
2019-12-15 21:45:18 +00:00
for ( const Engine * e : Engine : : IterateType ( VEH_ROAD ) ) {
2011-12-03 23:40:08 +00:00
if ( ! HasBit ( e - > info . climates , _settings_game . game_creation . landscape ) ) continue ;
2019-04-06 06:46:15 +00:00
this - > roadtypes | = GetRoadTypeInfo ( e - > u . road . roadtype ) - > introduces_roadtypes ;
2011-12-03 23:40:08 +00:00
}
2019-04-06 06:46:15 +00:00
/* Get the date introduced roadtypes as well. */
2024-02-13 21:34:09 +00:00
this - > roadtypes = AddDateIntroducedRoadTypes ( this - > roadtypes , CalTime : : MAX_DATE ) ;
2019-04-06 06:46:15 +00:00
this - > roadtypes & = ~ _roadtypes_hidden_mask ;
2011-12-03 23:40:08 +00:00
}
2011-12-03 23:40:46 +00:00
/** Get total infrastructure maintenance cost. */
Money GetTotalMaintenanceCost ( ) const
{
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
Money total ;
2024-01-07 16:41:53 +00:00
uint32_t rail_total = c - > infrastructure . GetRailTotal ( ) ;
2011-12-03 23:40:46 +00:00
for ( RailType rt = RAILTYPE_BEGIN ; rt ! = RAILTYPE_END ; rt + + ) {
2012-02-11 22:43:39 +00:00
if ( HasBit ( this - > railtypes , rt ) ) total + = RailMaintenanceCost ( rt , c - > infrastructure . rail [ rt ] , rail_total ) ;
2011-12-03 23:40:46 +00:00
}
total + = SignalMaintenanceCost ( c - > infrastructure . signal ) ;
2024-01-07 16:41:53 +00:00
uint32_t road_total = c - > infrastructure . GetRoadTotal ( ) ;
uint32_t tram_total = c - > infrastructure . GetTramTotal ( ) ;
2019-04-06 06:46:15 +00:00
for ( RoadType rt = ROADTYPE_BEGIN ; rt ! = ROADTYPE_END ; rt + + ) {
if ( HasBit ( this - > roadtypes , rt ) ) total + = RoadMaintenanceCost ( rt , c - > infrastructure . road [ rt ] , RoadTypeIsRoad ( rt ) ? road_total : tram_total ) ;
}
2011-12-03 23:40:46 +00:00
total + = CanalMaintenanceCost ( c - > infrastructure . water ) ;
total + = StationMaintenanceCost ( c - > infrastructure . station ) ;
total + = AirportMaintenanceCost ( c - > index ) ;
return total ;
}
2023-12-29 19:11:59 +00:00
void SetStringParameters ( WidgetID widget ) const override
2011-12-03 23:40:08 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_CI_CAPTION :
2011-12-03 23:40:08 +00:00
SetDParam ( 0 , ( CompanyID ) this - > window_number ) ;
break ;
}
}
2023-12-29 19:11:59 +00:00
void UpdateWidgetSize ( WidgetID widget , Dimension * size , [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension * resize ) override
2011-12-03 23:40:08 +00:00
{
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
switch ( widget ) {
2022-04-29 00:37:49 +00:00
case WID_CI_DESC : {
uint rail_lines = 1 ; // Starts at 1 because a line is also required for the section title
2011-12-03 23:40:08 +00:00
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT ) . width ) ;
2011-12-04 13:27:24 +00:00
2021-04-28 20:49:58 +00:00
for ( const auto & rt : _sorted_railtypes ) {
2011-12-03 23:40:08 +00:00
if ( HasBit ( this - > railtypes , rt ) ) {
2022-04-29 00:37:49 +00:00
rail_lines + + ;
2023-04-25 09:03:48 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( GetRailTypeInfo ( rt ) - > strings . name ) . width + WidgetDimensions : : scaled . hsep_indent ) ;
2011-12-03 23:40:08 +00:00
}
}
if ( this - > railtypes ! = RAILTYPES_NONE ) {
2022-04-29 00:37:49 +00:00
rail_lines + + ;
2022-09-23 08:36:22 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS ) . width + WidgetDimensions : : scaled . hsep_indent ) ;
2011-12-03 23:40:08 +00:00
}
2022-04-29 00:37:49 +00:00
uint road_lines = 1 ; // Starts at 1 because a line is also required for the section title
uint tram_lines = 1 ;
2011-12-03 23:40:08 +00:00
2022-04-29 00:37:49 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT ) . width ) ;
2011-12-04 13:27:24 +00:00
2021-04-28 20:50:23 +00:00
for ( const auto & rt : _sorted_roadtypes ) {
2022-04-29 00:37:49 +00:00
if ( HasBit ( this - > roadtypes , rt ) ) {
if ( RoadTypeIsRoad ( rt ) ) {
road_lines + + ;
} else {
tram_lines + + ;
}
2023-04-25 09:03:48 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( GetRoadTypeInfo ( rt ) - > strings . name ) . width + WidgetDimensions : : scaled . hsep_indent ) ;
2019-04-06 06:46:15 +00:00
}
2011-12-03 23:40:08 +00:00
}
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT ) . width ) ;
2022-09-23 08:36:22 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS ) . width + WidgetDimensions : : scaled . hsep_indent ) ;
2011-12-04 13:27:24 +00:00
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT ) . width ) ;
2022-09-23 08:36:22 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS ) . width + WidgetDimensions : : scaled . hsep_indent ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS ) . width + WidgetDimensions : : scaled . hsep_indent ) ;
2022-04-29 00:37:49 +00:00
2023-09-12 17:25:49 +00:00
size - > width + = padding . width ;
2024-01-29 18:01:19 +00:00
uint total_height = ( ( rail_lines + road_lines + tram_lines + 2 + 3 ) * GetCharacterHeight ( FS_NORMAL ) ) + ( 4 * WidgetDimensions : : scaled . vsep_sparse ) ;
2022-04-29 00:37:49 +00:00
/* Set height of the total line. */
2024-01-29 18:01:19 +00:00
if ( _settings_game . economy . infrastructure_maintenance ) total_height + = WidgetDimensions : : scaled . vsep_sparse + WidgetDimensions : : scaled . vsep_normal + GetCharacterHeight ( FS_NORMAL ) ;
2022-04-29 00:37:49 +00:00
this - > vscroll - > SetCount ( total_height ) ;
2023-12-17 01:16:40 +00:00
size - > height = std : : max ( size - > height , std : : min < uint > ( 8 * GetCharacterHeight ( FS_NORMAL ) , total_height ) ) ;
uint target_height = std : : min < uint > ( 40 * GetCharacterHeight ( FS_NORMAL ) , total_height ) ;
2022-04-29 16:01:43 +00:00
this - > height_extra = ( target_height > size - > height ) ? ( target_height - size - > height ) : 0 ;
2011-12-04 13:27:24 +00:00
break ;
2022-04-29 00:37:49 +00:00
}
2011-12-04 13:27:24 +00:00
2022-04-29 00:37:49 +00:00
case WID_CI_COUNT : {
2011-12-03 23:40:08 +00:00
/* Find the maximum count that is displayed. */
2024-01-07 16:41:53 +00:00
uint32_t max_val = 1000 ; // Some random number to reserve enough space.
2011-12-04 13:27:24 +00:00
Money max_cost = 10000 ; // Some random number to reserve enough space.
2024-01-07 16:41:53 +00:00
uint32_t rail_total = c - > infrastructure . GetRailTotal ( ) ;
2011-12-03 23:40:08 +00:00
for ( RailType rt = RAILTYPE_BEGIN ; rt < RAILTYPE_END ; rt + + ) {
2021-01-08 10:16:18 +00:00
max_val = std : : max ( max_val , c - > infrastructure . rail [ rt ] ) ;
max_cost = std : : max ( max_cost , RailMaintenanceCost ( rt , c - > infrastructure . rail [ rt ] , rail_total ) ) ;
2011-12-03 23:40:08 +00:00
}
2021-01-08 10:16:18 +00:00
max_val = std : : max ( max_val , c - > infrastructure . signal ) ;
max_cost = std : : max ( max_cost , SignalMaintenanceCost ( c - > infrastructure . signal ) ) ;
2024-01-07 16:41:53 +00:00
uint32_t road_total = c - > infrastructure . GetRoadTotal ( ) ;
uint32_t tram_total = c - > infrastructure . GetTramTotal ( ) ;
2011-12-03 23:40:08 +00:00
for ( RoadType rt = ROADTYPE_BEGIN ; rt < ROADTYPE_END ; rt + + ) {
2021-01-08 10:16:18 +00:00
max_val = std : : max ( max_val , c - > infrastructure . road [ rt ] ) ;
max_cost = std : : max ( max_cost , RoadMaintenanceCost ( rt , c - > infrastructure . road [ rt ] , RoadTypeIsRoad ( rt ) ? road_total : tram_total ) ) ;
2019-04-06 06:46:15 +00:00
2011-12-03 23:40:08 +00:00
}
2021-01-08 10:16:18 +00:00
max_val = std : : max ( max_val , c - > infrastructure . water ) ;
max_cost = std : : max ( max_cost , CanalMaintenanceCost ( c - > infrastructure . water ) ) ;
max_val = std : : max ( max_val , c - > infrastructure . station ) ;
max_cost = std : : max ( max_cost , StationMaintenanceCost ( c - > infrastructure . station ) ) ;
max_val = std : : max ( max_val , c - > infrastructure . airport ) ;
max_cost = std : : max ( max_cost , AirportMaintenanceCost ( c - > index ) ) ;
2011-12-03 23:40:08 +00:00
2012-12-08 17:18:51 +00:00
SetDParamMaxValue ( 0 , max_val ) ;
2023-04-25 08:45:05 +00:00
uint count_width = GetStringBoundingBox ( STR_JUST_COMMA ) . width + WidgetDimensions : : scaled . hsep_indent ; // Reserve some wiggle room
2011-12-03 23:40:46 +00:00
if ( _settings_game . economy . infrastructure_maintenance ) {
2012-12-08 17:18:51 +00:00
SetDParamMaxValue ( 0 , this - > GetTotalMaintenanceCost ( ) * 12 ) ; // Convert to per year
2024-02-13 23:26:24 +00:00
this - > total_width = GetStringBoundingBox ( EconTime : : UsingWallclockUnits ( ) ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR ) . width + WidgetDimensions : : scaled . hsep_indent * 2 ;
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( size - > width , this - > total_width ) ;
2013-06-29 13:19:19 +00:00
SetDParamMaxValue ( 0 , max_cost * 12 ) ; // Convert to per year
2024-02-13 23:26:24 +00:00
count_width + = std : : max ( this - > total_width , GetStringBoundingBox ( EconTime : : UsingWallclockUnits ( ) ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR ) . width ) ;
2011-12-03 23:40:46 +00:00
}
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( size - > width , count_width ) ;
2011-12-03 23:40:08 +00:00
break ;
}
}
}
2013-06-29 13:11:52 +00:00
/**
* Helper for drawing the counts line .
2022-04-29 00:37:49 +00:00
* @ param width The width of the bounds to draw in .
2013-06-29 13:11:52 +00:00
* @ param y The y position to draw at .
* @ param count The count to show on this line .
* @ param monthly_cost The monthly costs .
*/
2022-04-29 00:37:49 +00:00
void DrawCountLine ( int width , int & y , int count , Money monthly_cost ) const
2013-06-29 13:11:52 +00:00
{
SetDParam ( 0 , count ) ;
2023-12-17 01:16:40 +00:00
DrawString ( 0 , width , y + = GetCharacterHeight ( FS_NORMAL ) , STR_JUST_COMMA , TC_WHITE , SA_RIGHT ) ;
2013-06-29 13:19:19 +00:00
if ( _settings_game . economy . infrastructure_maintenance ) {
SetDParam ( 0 , monthly_cost * 12 ) ; // Convert to per year
2022-04-29 00:37:49 +00:00
int left = _current_text_dir = = TD_RTL ? width - this - > total_width : 0 ;
2024-02-13 23:26:24 +00:00
DrawString ( left , left + this - > total_width , y , EconTime : : UsingWallclockUnits ( ) ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR , TC_FROMSTRING , SA_RIGHT ) ;
2013-06-29 13:19:19 +00:00
}
2013-06-29 13:11:52 +00:00
}
2023-12-29 19:11:59 +00:00
void DrawWidget ( const Rect & r , WidgetID widget ) const override
2011-12-03 23:40:08 +00:00
{
2022-04-29 00:37:49 +00:00
if ( widget ! = WID_CI_DESC & & widget ! = WID_CI_COUNT ) return ;
2011-12-03 23:40:08 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2022-12-04 20:25:38 +00:00
int offs_left = _current_text_dir = = TD_LTR ? WidgetDimensions : : scaled . framerect . left : 0 ;
int offs_right = _current_text_dir = = TD_LTR ? 0 : WidgetDimensions : : scaled . framerect . right ;
2011-12-03 23:40:08 +00:00
2022-04-29 00:37:49 +00:00
int width = r . right - r . left ;
/* Set up a clipping region for the panel. */
DrawPixelInfo tmp_dpi ;
if ( ! FillDrawPixelInfo ( & tmp_dpi , r . left , r . top , width + 1 , r . bottom - r . top + 1 ) ) return ;
2023-02-15 21:13:58 +00:00
AutoRestoreBackup dpi_backup ( _cur_dpi , & tmp_dpi ) ;
2022-04-29 00:37:49 +00:00
int y = - this - > vscroll - > GetPosition ( ) ;
2011-12-03 23:40:08 +00:00
switch ( widget ) {
2022-04-29 00:37:49 +00:00
case WID_CI_DESC : {
DrawString ( 0 , width , y , STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT ) ;
2011-12-03 23:40:08 +00:00
if ( this - > railtypes ! = RAILTYPES_NONE ) {
/* Draw name of each valid railtype. */
2021-04-28 20:49:58 +00:00
for ( const auto & rt : _sorted_railtypes ) {
2011-12-03 23:40:08 +00:00
if ( HasBit ( this - > railtypes , rt ) ) {
2023-12-17 01:16:40 +00:00
DrawString ( offs_left , width - offs_right , y + = GetCharacterHeight ( FS_NORMAL ) , GetRailTypeInfo ( rt ) - > strings . name , TC_WHITE ) ;
2011-12-03 23:40:08 +00:00
}
}
2023-12-17 01:16:40 +00:00
DrawString ( offs_left , width - offs_right , y + = GetCharacterHeight ( FS_NORMAL ) , STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS ) ;
2011-12-03 23:40:08 +00:00
} else {
/* No valid railtype. */
2023-12-17 01:16:40 +00:00
DrawString ( offs_left , width - offs_right , y + = GetCharacterHeight ( FS_NORMAL ) , STR_COMPANY_VIEW_INFRASTRUCTURE_NONE ) ;
2022-04-29 00:37:49 +00:00
}
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2022-04-29 00:37:49 +00:00
DrawString ( 0 , width , y , STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT ) ;
/* Draw name of each valid roadtype. */
for ( const auto & rt : _sorted_roadtypes ) {
if ( HasBit ( this - > roadtypes , rt ) & & RoadTypeIsRoad ( rt ) ) {
SetDParam ( 0 , GetRoadTypeInfo ( rt ) - > strings . name ) ;
2023-12-17 01:16:40 +00:00
DrawString ( offs_left , width - offs_right , y + = GetCharacterHeight ( FS_NORMAL ) , STR_JUST_STRING , TC_WHITE ) ;
2022-04-29 00:37:49 +00:00
}
2011-12-03 23:40:08 +00:00
}
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2022-04-29 00:37:49 +00:00
DrawString ( 0 , width , y , STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT ) ;
/* Draw name of each valid roadtype. */
for ( const auto & rt : _sorted_roadtypes ) {
if ( HasBit ( this - > roadtypes , rt ) & & RoadTypeIsTram ( rt ) ) {
SetDParam ( 0 , GetRoadTypeInfo ( rt ) - > strings . name ) ;
2023-12-17 01:16:40 +00:00
DrawString ( offs_left , width - offs_right , y + = GetCharacterHeight ( FS_NORMAL ) , STR_JUST_STRING , TC_WHITE ) ;
2022-04-29 00:37:49 +00:00
}
}
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2022-04-29 00:37:49 +00:00
DrawString ( 0 , width , y , STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT ) ;
2023-12-17 01:16:40 +00:00
DrawString ( offs_left , width - offs_right , y + = GetCharacterHeight ( FS_NORMAL ) , STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS ) ;
2022-04-29 00:37:49 +00:00
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2022-04-29 00:37:49 +00:00
DrawString ( 0 , width , y , STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT ) ;
2023-12-17 01:16:40 +00:00
DrawString ( offs_left , width - offs_right , y + = GetCharacterHeight ( FS_NORMAL ) , STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS ) ;
DrawString ( offs_left , width - offs_right , y + = GetCharacterHeight ( FS_NORMAL ) , STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS ) ;
2022-04-29 00:37:49 +00:00
2011-12-03 23:40:08 +00:00
break ;
2022-04-29 00:37:49 +00:00
}
2011-12-03 23:40:08 +00:00
2022-04-29 00:37:49 +00:00
case WID_CI_COUNT : {
2011-12-03 23:40:08 +00:00
/* Draw infrastructure count for each valid railtype. */
2024-01-07 16:41:53 +00:00
uint32_t rail_total = c - > infrastructure . GetRailTotal ( ) ;
2021-04-28 20:49:58 +00:00
for ( const auto & rt : _sorted_railtypes ) {
2011-12-03 23:40:08 +00:00
if ( HasBit ( this - > railtypes , rt ) ) {
2022-04-29 00:37:49 +00:00
this - > DrawCountLine ( width , y , c - > infrastructure . rail [ rt ] , RailMaintenanceCost ( rt , c - > infrastructure . rail [ rt ] , rail_total ) ) ;
2011-12-03 23:40:08 +00:00
}
}
if ( this - > railtypes ! = RAILTYPES_NONE ) {
2022-04-29 00:37:49 +00:00
this - > DrawCountLine ( width , y , c - > infrastructure . signal , SignalMaintenanceCost ( c - > infrastructure . signal ) ) ;
2011-12-03 23:40:08 +00:00
}
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2019-04-06 06:46:15 +00:00
2024-01-07 16:41:53 +00:00
uint32_t road_total = c - > infrastructure . GetRoadTotal ( ) ;
2021-04-28 20:50:23 +00:00
for ( const auto & rt : _sorted_roadtypes ) {
2022-04-29 00:37:49 +00:00
if ( HasBit ( this - > roadtypes , rt ) & & RoadTypeIsRoad ( rt ) ) {
this - > DrawCountLine ( width , y , c - > infrastructure . road [ rt ] , RoadMaintenanceCost ( rt , c - > infrastructure . road [ rt ] , road_total ) ) ;
2019-04-06 06:46:15 +00:00
}
2011-12-03 23:40:08 +00:00
}
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2011-12-03 23:40:08 +00:00
2024-01-07 16:41:53 +00:00
uint32_t tram_total = c - > infrastructure . GetTramTotal ( ) ;
2021-04-28 20:50:23 +00:00
for ( const auto & rt : _sorted_roadtypes ) {
2022-04-29 00:37:49 +00:00
if ( HasBit ( this - > roadtypes , rt ) & & RoadTypeIsTram ( rt ) ) {
this - > DrawCountLine ( width , y , c - > infrastructure . road [ rt ] , RoadMaintenanceCost ( rt , c - > infrastructure . road [ rt ] , tram_total ) ) ;
2019-04-06 06:46:15 +00:00
}
2011-12-03 23:40:08 +00:00
}
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2011-12-03 23:40:08 +00:00
2022-04-29 00:37:49 +00:00
this - > DrawCountLine ( width , y , c - > infrastructure . water , CanalMaintenanceCost ( c - > infrastructure . water ) ) ;
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2022-04-29 00:37:49 +00:00
this - > DrawCountLine ( width , y , c - > infrastructure . station , StationMaintenanceCost ( c - > infrastructure . station ) ) ;
this - > DrawCountLine ( width , y , c - > infrastructure . airport , AirportMaintenanceCost ( c - > index ) ) ;
2011-12-03 23:40:46 +00:00
if ( _settings_game . economy . infrastructure_maintenance ) {
2024-01-29 18:01:19 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) + WidgetDimensions : : scaled . vsep_sparse ;
2022-04-29 00:37:49 +00:00
int left = _current_text_dir = = TD_RTL ? width - this - > total_width : 0 ;
2023-12-16 23:54:58 +00:00
GfxFillRect ( left , y , left + this - > total_width , y + WidgetDimensions : : scaled . bevel . top - 1 , PC_WHITE ) ;
2022-09-27 22:40:16 +00:00
y + = WidgetDimensions : : scaled . vsep_normal ;
2011-12-03 23:40:46 +00:00
SetDParam ( 0 , this - > GetTotalMaintenanceCost ( ) * 12 ) ; // Convert to per year
2024-02-13 23:26:24 +00:00
DrawString ( left , left + this - > total_width , y , EconTime : : UsingWallclockUnits ( ) ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR , TC_FROMSTRING , SA_RIGHT ) ;
2011-12-03 23:40:46 +00:00
}
2011-12-03 23:40:08 +00:00
break ;
2022-04-29 00:37:49 +00:00
}
}
}
2011-12-03 23:40:08 +00:00
2022-04-29 00:37:49 +00:00
virtual void OnResize ( ) override
{
this - > vscroll - > SetCapacityFromWidget ( this , WID_CI_DESC ) ;
2011-12-03 23:40:08 +00:00
}
2022-04-29 16:01:43 +00:00
void FindWindowPlacementAndResize ( int def_width , int def_height ) override
{
if ( this - > window_desc - > GetPreferences ( ) . pref_height = = 0 ) {
def_height = this - > nested_root - > smallest_y + this - > height_extra ;
}
Window : : FindWindowPlacementAndResize ( def_width , def_height ) ;
}
2011-12-03 23:40:08 +00:00
/**
* Some data on this window has become invalid .
* @ param data Information about the changed data .
* @ 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 .
*/
2023-09-16 20:20:53 +00:00
void OnInvalidateData ( [[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true ) override
2011-12-03 23:40:08 +00:00
{
if ( ! gui_scope ) return ;
this - > UpdateRailRoadTypes ( ) ;
this - > ReInit ( ) ;
}
} ;
2023-11-02 19:33:01 +00:00
static WindowDesc _company_infrastructure_desc ( __FILE__ , __LINE__ ,
2013-05-26 19:25:01 +00:00
WDP_AUTO , " company_infrastructure " , 0 , 0 ,
2011-12-03 23:40:08 +00:00
WC_COMPANY_INFRASTRUCTURE , WC_NONE ,
2012-11-11 16:10:43 +00:00
0 ,
2023-09-03 20:54:13 +00:00
std : : begin ( _nested_company_infrastructure_widgets ) , std : : end ( _nested_company_infrastructure_widgets )
2011-12-03 23:40:08 +00:00
) ;
/**
* Open the infrastructure window of a company .
* @ param company Company to show infrastructure of .
*/
static void ShowCompanyInfrastructure ( CompanyID company )
{
if ( ! Company : : IsValidID ( company ) ) return ;
AllocateWindowDescFront < CompanyInfrastructureWindow > ( & _company_infrastructure_desc , company ) ;
}
2024-01-15 22:49:24 +00:00
static constexpr NWidgetPart _nested_company_widgets [ ] = {
2009-05-03 08:27:12 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , WID_C_CAPTION ) , SetDataTip ( STR_COMPANY_VIEW_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2009-12-21 16:24:29 +00:00
NWidget ( WWT_SHADEBOX , COLOUR_GREY ) ,
2009-12-09 17:10:57 +00:00
NWidget ( WWT_STICKYBOX , COLOUR_GREY ) ,
2009-05-03 08:27:12 +00:00
EndContainer ( ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_wide , 0 ) , SetPadding ( 4 ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_normal , 0 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_C_FACE ) , SetMinimalSize ( 92 , 119 ) , SetFill ( 1 , 0 ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_C_FACE_TITLE ) , SetFill ( 1 , 1 ) , SetMinimalTextLines ( 2 , 0 ) ,
2009-11-15 13:31:27 +00:00
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_normal , 0 ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_normal , 0 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , WID_C_DESC_INAUGURATION ) , SetDataTip ( STR_COMPANY_VIEW_INAUGURATED_TITLE , STR_NULL ) , SetFill ( 1 , 0 ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_LABEL , COLOUR_GREY , WID_C_DESC_COLOUR_SCHEME ) , SetDataTip ( STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE , STR_NULL ) ,
2023-10-28 10:28:28 +00:00
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_C_DESC_COLOUR_SCHEME_EXAMPLE ) , SetMinimalSize ( 30 , 0 ) , SetFill ( 1 , 1 ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , COLOUR_GREY , WID_C_DESC_VEHICLE ) , SetDataTip ( STR_COMPANY_VIEW_VEHICLES_TITLE , STR_NULL ) , SetAlignment ( SA_LEFT | SA_TOP ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_C_DESC_VEHICLE_COUNTS ) , SetMinimalTextLines ( 4 , 0 ) , SetFill ( 1 , 1 ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_normal , 0 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_C_SELECT_VIEW_BUILD_HQ ) ,
2021-01-05 16:11:24 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_VIEW_HQ ) , SetDataTip ( STR_COMPANY_VIEW_VIEW_HQ_BUTTON , STR_COMPANY_VIEW_VIEW_HQ_TOOLTIP ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , WID_C_BUILD_HQ ) , SetDataTip ( STR_COMPANY_VIEW_BUILD_HQ_BUTTON , STR_COMPANY_VIEW_BUILD_HQ_TOOLTIP ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
2011-12-16 16:27:45 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_C_SELECT_RELOCATE ) ,
2021-01-05 16:11:24 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_GREY , WID_C_RELOCATE_HQ ) , SetDataTip ( STR_COMPANY_VIEW_RELOCATE_HQ , STR_COMPANY_VIEW_RELOCATE_COMPANY_HEADQUARTERS ) ,
NWidget ( NWID_SPACER ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
2011-12-16 16:27:45 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , WID_C_DESC_COMPANY_VALUE ) , SetDataTip ( STR_COMPANY_VIEW_COMPANY_VALUE , STR_NULL ) , SetFill ( 1 , 0 ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) ,
NWidget ( WWT_TEXT , COLOUR_GREY , WID_C_DESC_INFRASTRUCTURE ) , SetDataTip ( STR_COMPANY_VIEW_INFRASTRUCTURE , STR_NULL ) , SetAlignment ( SA_LEFT | SA_TOP ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_C_DESC_INFRASTRUCTURE_COUNTS ) , SetMinimalTextLines ( 5 , 0 ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_VERTICAL ) , SetPIPRatio ( 0 , 0 , 1 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_VIEW_INFRASTRUCTURE ) , SetDataTip ( STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON , STR_COMPANY_VIEW_INFRASTRUCTURE_TOOLTIP ) ,
2023-09-12 18:04:03 +00:00
EndContainer ( ) ,
2023-09-12 19:06:47 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_C_SELECT_DESC_OWNERS ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 5 , 5 , 4 ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_C_DESC_OWNERS ) , SetMinimalTextLines ( MAX_COMPANY_SHARE_OWNERS , 0 ) ,
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
2021-01-05 17:06:48 +00:00
EndContainer ( ) ,
2023-09-12 19:06:47 +00:00
EndContainer ( ) ,
2017-03-02 00:09:19 +00:00
EndContainer ( ) ,
/* Multi player buttons. */
2023-10-28 10:28:28 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_normal , 0 ) , SetPIPRatio ( 1 , 0 , 0 ) ,
NWidget ( NWID_VERTICAL ) , SetPIPRatio ( 1 , 0 , 0 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , WID_C_HAS_PASSWORD ) , SetFill ( 0 , 0 ) ,
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_normal , 0 ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_C_SELECT_HOSTILE_TAKEOVER ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_HOSTILE_TAKEOVER ) , SetDataTip ( STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON , STR_COMPANY_VIEW_HOSTILE_TAKEOVER_TOOLTIP ) ,
2023-06-05 17:32:22 +00:00
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_C_SELECT_GIVE_MONEY ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_GIVE_MONEY ) , SetDataTip ( STR_COMPANY_VIEW_GIVE_MONEY_BUTTON , STR_COMPANY_VIEW_GIVE_MONEY_TOOLTIP ) ,
2021-01-05 17:06:48 +00:00
EndContainer ( ) ,
2023-10-28 10:28:28 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_C_SELECT_MULTIPLAYER ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_COMPANY_PASSWORD ) , SetDataTip ( STR_COMPANY_VIEW_PASSWORD , STR_COMPANY_VIEW_PASSWORD_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_COMPANY_JOIN ) , SetDataTip ( STR_COMPANY_VIEW_JOIN , STR_COMPANY_VIEW_JOIN_TOOLTIP ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
EndContainer ( ) ,
2009-05-03 08:27:12 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
EndContainer ( ) ,
/* Button bars at the bottom. */
2011-12-16 16:27:45 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_C_SELECT_BUTTONS ) ,
2009-11-15 13:31:27 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2011-12-16 16:27:45 +00:00
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 ) ,
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 ) ,
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 ) ,
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 ) ,
2009-05-03 08:27:12 +00:00
EndContainer ( ) ,
2023-05-30 17:57:42 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
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 ) ,
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 ) ,
EndContainer ( ) ,
2009-05-03 08:27:12 +00:00
EndContainer ( ) ,
} ;
2007-11-21 13:50:36 +00:00
2023-05-30 17:57:42 +00:00
int GetAmountOwnedBy ( const Company * c , Owner owner )
{
return ( c - > share_owners [ 0 ] = = owner ) +
( c - > share_owners [ 1 ] = = owner ) +
( c - > share_owners [ 2 ] = = owner ) +
( c - > share_owners [ 3 ] = = owner ) ;
}
2009-11-20 17:36:46 +00:00
/** Strings for the company vehicle counts */
static const StringID _company_view_vehicle_count_strings [ ] = {
STR_COMPANY_VIEW_TRAINS , STR_COMPANY_VIEW_ROAD_VEHICLES , STR_COMPANY_VIEW_SHIPS , STR_COMPANY_VIEW_AIRCRAFT
} ;
2004-08-09 17:04:08 +00:00
2007-10-15 19:59:27 +00:00
/**
2008-09-30 20:39:50 +00:00
* Window with general information about a company
2007-10-15 19:59:27 +00:00
*/
2008-09-30 20:39:50 +00:00
struct CompanyWindow : Window
2004-08-09 17:04:08 +00:00
{
2011-12-16 16:27:45 +00:00
CompanyWidgets query_widget ;
2004-08-09 17:04:08 +00:00
2009-11-15 13:31:27 +00:00
/** Display planes in the company window. */
enum CompanyWindowPlanes {
2011-12-16 16:27:45 +00:00
/* Display planes of the #WID_C_SELECT_MULTIPLAYER selection widget. */
2011-12-04 11:59:08 +00:00
CWP_MP_C_PWD = 0 , ///< Display the company password button.
2009-11-15 13:31:27 +00:00
CWP_MP_C_JOIN , ///< Display the join company button.
2011-12-16 16:27:45 +00:00
/* Display planes of the #WID_C_SELECT_VIEW_BUILD_HQ selection widget. */
2009-11-20 17:36:46 +00:00
CWP_VB_VIEW = 0 , ///< Display the view button
CWP_VB_BUILD , ///< Display the build button
2011-12-16 16:27:45 +00:00
/* Display planes of the #WID_C_SELECT_RELOCATE selection widget. */
2009-11-15 13:31:27 +00:00
CWP_RELOCATE_SHOW = 0 , ///< Show the relocate HQ button.
CWP_RELOCATE_HIDE , ///< Hide the relocate HQ button.
2023-05-30 17:57:42 +00:00
/* Display planes of the #WID_C_SELECT_BUTTONS selection widget. */
CWP_BUTTONS_LOCAL = 0 , ///< Buttons of the local company.
CWP_BUTTONS_OTHER , ///< Buttons of the other companies.
2009-11-15 13:31:27 +00:00
} ;
2013-05-26 19:23:42 +00:00
CompanyWindow ( WindowDesc * desc , WindowNumber window_number ) : Window ( desc )
2008-05-15 14:12:22 +00:00
{
2013-05-26 19:23:42 +00:00
this - > InitNested ( window_number ) ;
2009-02-09 02:33:10 +00:00
this - > owner = ( Owner ) this - > window_number ;
2013-02-04 20:29:38 +00:00
this - > OnInvalidateData ( ) ;
2008-05-15 14:12:22 +00:00
}
2004-08-09 17:04:08 +00:00
2019-03-04 07:49:37 +00:00
void OnPaint ( ) override
2008-05-15 14:12:22 +00:00
{
2009-05-16 23:34:14 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2008-09-30 20:39:50 +00:00
bool local = this - > window_number = = _local_company ;
2009-12-21 16:24:29 +00:00
if ( ! this - > IsShaded ( ) ) {
2011-12-04 11:59:08 +00:00
bool reinit = false ;
2009-12-21 16:24:29 +00:00
/* Button bar selection. */
2023-12-23 13:26:55 +00:00
reinit | = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_BUTTONS ) - > SetDisplayedPlane ( local ? CWP_BUTTONS_LOCAL : CWP_BUTTONS_OTHER ) ;
2009-11-15 13:31:27 +00:00
2009-12-21 16:24:29 +00:00
/* Build HQ button handling. */
2023-12-09 20:55:10 +00:00
reinit | = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_VIEW_BUILD_HQ ) - > SetDisplayedPlane ( ( local & & c - > location_of_HQ = = INVALID_TILE ) ? CWP_VB_BUILD : CWP_VB_VIEW ) ;
2009-11-20 17:36:46 +00:00
2011-12-16 16:27:45 +00:00
this - > SetWidgetDisabledState ( WID_C_VIEW_HQ , c - > location_of_HQ = = INVALID_TILE ) ;
2009-11-15 13:31:27 +00:00
2009-12-21 16:24:29 +00:00
/* Enable/disable 'Relocate HQ' button. */
2023-12-09 20:55:10 +00:00
reinit | = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_RELOCATE ) - > SetDisplayedPlane ( ( ! local | | c - > location_of_HQ = = INVALID_TILE ) ? CWP_RELOCATE_HIDE : CWP_RELOCATE_SHOW ) ;
2009-11-15 13:31:27 +00:00
2023-05-30 17:57:42 +00:00
/* Owners of company */
2023-12-23 13:26:55 +00:00
{
int plane = SZSP_HORIZONTAL ;
for ( uint i = 0 ; i < lengthof ( c - > share_owners ) ; i + + ) {
if ( c - > share_owners [ i ] ! = INVALID_COMPANY ) {
plane = 0 ;
break ;
}
2023-05-30 17:57:42 +00:00
}
2023-12-23 13:26:55 +00:00
reinit | = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_DESC_OWNERS ) - > SetDisplayedPlane ( plane ) ;
2023-05-30 17:57:42 +00:00
}
2017-03-02 00:09:19 +00:00
/* Enable/disable 'Give money' button. */
2023-12-09 20:55:10 +00:00
reinit | = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_GIVE_MONEY ) - > SetDisplayedPlane ( ( local | | _local_company = = COMPANY_SPECTATOR | | ! _settings_game . economy . give_money ) ? SZSP_NONE : 0 ) ;
2023-12-23 13:26:55 +00:00
2023-06-05 17:32:22 +00:00
/* Enable/disable 'Hostile Takeover' button. */
2023-12-23 13:26:55 +00:00
reinit | = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_HOSTILE_TAKEOVER ) - > SetDisplayedPlane ( ( local | | _local_company = = COMPANY_SPECTATOR | | ! c - > is_ai | | _networking | | _settings_game . economy . allow_shares ) ? SZSP_NONE : 0 ) ;
2017-03-02 00:09:19 +00:00
2009-12-21 16:24:29 +00:00
/* Multiplayer buttons. */
2023-12-09 20:55:10 +00:00
reinit | = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_MULTIPLAYER ) - > SetDisplayedPlane ( ( ! _networking ) ? ( int ) SZSP_NONE : ( int ) ( local ? CWP_MP_C_PWD : CWP_MP_C_JOIN ) ) ;
this - > SetWidgetDisabledState ( WID_C_COMPANY_JOIN , c - > is_ai ) ;
2011-12-04 11:59:08 +00:00
if ( reinit ) {
this - > ReInit ( ) ;
return ;
}
2009-11-15 13:31:27 +00:00
}
2008-05-15 14:12:22 +00:00
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2009-11-20 17:36:46 +00:00
}
2007-11-21 13:50:36 +00:00
2023-12-29 19:11:59 +00:00
void UpdateWidgetSize ( WidgetID widget , Dimension * size , [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension * resize ) override
2009-11-20 17:36:46 +00:00
{
switch ( widget ) {
2023-12-03 22:23:54 +00:00
case WID_C_FACE :
* size = maxdim ( * size , GetScaledSpriteSize ( SPR_GRADIENT ) ) ;
2014-09-20 09:18:22 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_C_DESC_COLOUR_SCHEME_EXAMPLE : {
2011-07-02 14:37:03 +00:00
Point offset ;
Dimension d = GetSpriteSize ( SPR_VEH_BUS_SW_VIEW , & offset ) ;
d . width - = offset . x ;
d . height - = offset . y ;
* size = maxdim ( * size , d ) ;
break ;
}
2011-12-16 16:27:45 +00:00
case WID_C_DESC_COMPANY_VALUE :
2009-11-20 17:36:46 +00:00
SetDParam ( 0 , INT64_MAX ) ; // Arguably the maximum company value
size - > width = GetStringBoundingBox ( STR_COMPANY_VIEW_COMPANY_VALUE ) . width ;
break ;
2011-12-16 16:27:45 +00:00
case WID_C_DESC_VEHICLE_COUNTS :
2012-12-08 17:18:51 +00:00
SetDParamMaxValue ( 0 , 5000 ) ; // Maximum number of vehicles
2009-11-20 17:36:46 +00:00
for ( uint i = 0 ; i < lengthof ( _company_view_vehicle_count_strings ) ; i + + ) {
2023-06-05 08:27:04 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( _company_view_vehicle_count_strings [ i ] ) . width + padding . width ) ;
2009-11-20 17:36:46 +00:00
}
break ;
2011-12-16 16:27:45 +00:00
case WID_C_DESC_INFRASTRUCTURE_COUNTS :
2012-12-08 17:18:51 +00:00
SetDParamMaxValue ( 0 , UINT_MAX ) ;
2023-06-05 08:27:04 +00:00
size - > width = GetStringBoundingBox ( STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL ) . width ;
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_INFRASTRUCTURE_WATER ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_INFRASTRUCTURE_STATION ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_INFRASTRUCTURE_NONE ) . width ) ;
2023-06-05 08:27:04 +00:00
size - > width + = padding . width ;
2011-12-03 23:40:08 +00:00
break ;
2023-05-30 17:57:42 +00:00
case WID_C_DESC_OWNERS : {
for ( const Company * c2 : Company : : Iterate ( ) ) {
SetDParamMaxValue ( 0 , 75 ) ;
SetDParam ( 1 , c2 - > index ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_SHARES_OWNED_BY ) . width ) ;
}
break ;
}
2021-01-05 16:11:24 +00:00
case WID_C_VIEW_HQ :
case WID_C_BUILD_HQ :
case WID_C_RELOCATE_HQ :
case WID_C_VIEW_INFRASTRUCTURE :
2021-01-05 17:06:48 +00:00
case WID_C_GIVE_MONEY :
2023-06-05 17:32:22 +00:00
case WID_C_HOSTILE_TAKEOVER :
2021-01-05 16:11:24 +00:00
case WID_C_COMPANY_PASSWORD :
case WID_C_COMPANY_JOIN :
2023-06-05 08:27:04 +00:00
size - > width = GetStringBoundingBox ( STR_COMPANY_VIEW_VIEW_HQ_BUTTON ) . width ;
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_BUILD_HQ_BUTTON ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_RELOCATE_HQ ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_GIVE_MONEY_BUTTON ) . width ) ;
2023-06-05 17:32:22 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON ) . width ) ;
2021-01-08 10:16:18 +00:00
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_PASSWORD ) . width ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_JOIN ) . width ) ;
2023-06-05 08:27:04 +00:00
size - > width + = padding . width ;
2021-01-05 16:11:24 +00:00
break ;
2021-01-31 01:10:01 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_HAS_PASSWORD :
2023-10-28 10:28:28 +00:00
if ( _networking ) * size = maxdim ( * size , GetSpriteSize ( SPR_LOCK ) ) ;
2010-01-04 23:00:19 +00:00
break ;
2009-01-23 23:56:56 +00:00
}
2009-11-20 17:36:46 +00:00
}
2009-01-23 23:56:56 +00:00
2023-02-25 18:02:22 +00:00
void DrawVehicleCountsWidget ( const Rect & r , const Company * c ) const
{
static_assert ( VEH_COMPANY_END = = lengthof ( _company_view_vehicle_count_strings ) ) ;
int y = r . top ;
for ( VehicleType type = VEH_BEGIN ; type < VEH_COMPANY_END ; type + + ) {
uint amount = c - > group_all [ type ] . num_vehicle ;
if ( amount ! = 0 ) {
SetDParam ( 0 , amount ) ;
DrawString ( r . left , r . right , y , _company_view_vehicle_count_strings [ type ] ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2023-02-25 18:02:22 +00:00
}
}
if ( y = = r . top ) {
/* No String was emited before, so there must be no vehicles at all. */
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_VEHICLES_NONE ) ;
}
}
void DrawInfrastructureCountsWidget ( const Rect & r , const Company * c ) const
{
int y = r . top ;
uint rail_pieces = c - > infrastructure . signal ;
for ( uint i = 0 ; i < lengthof ( c - > infrastructure . rail ) ; i + + ) rail_pieces + = c - > infrastructure . rail [ i ] ;
if ( rail_pieces ! = 0 ) {
SetDParam ( 0 , rail_pieces ) ;
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2023-02-25 18:02:22 +00:00
}
uint road_pieces = 0 ;
for ( uint i = 0 ; i < lengthof ( c - > infrastructure . road ) ; i + + ) road_pieces + = c - > infrastructure . road [ i ] ;
if ( road_pieces ! = 0 ) {
SetDParam ( 0 , road_pieces ) ;
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2023-02-25 18:02:22 +00:00
}
if ( c - > infrastructure . water ! = 0 ) {
SetDParam ( 0 , c - > infrastructure . water ) ;
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_INFRASTRUCTURE_WATER ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2023-02-25 18:02:22 +00:00
}
if ( c - > infrastructure . station ! = 0 ) {
SetDParam ( 0 , c - > infrastructure . station ) ;
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_INFRASTRUCTURE_STATION ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2023-02-25 18:02:22 +00:00
}
if ( c - > infrastructure . airport ! = 0 ) {
SetDParam ( 0 , c - > infrastructure . airport ) ;
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT ) ;
2023-11-21 19:04:24 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2023-02-25 18:02:22 +00:00
}
if ( y = = r . top ) {
/* No String was emited before, so there must be no infrastructure at all. */
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_INFRASTRUCTURE_NONE ) ;
}
}
2023-12-29 19:11:59 +00:00
void DrawWidget ( const Rect & r , WidgetID widget ) const override
2009-11-20 17:36:46 +00:00
{
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_C_FACE :
2023-04-21 18:54:04 +00:00
DrawCompanyManagerFace ( c - > face , c - > colour , r ) ;
2009-11-20 17:36:46 +00:00
break ;
2007-11-21 13:50:36 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_FACE_TITLE :
2009-11-20 17:36:46 +00:00
SetDParam ( 0 , c - > index ) ;
2011-12-04 10:47:57 +00:00
DrawStringMultiLine ( r . left , r . right , r . top , r . bottom , STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE , TC_FROMSTRING , SA_HOR_CENTER ) ;
2009-11-20 17:36:46 +00:00
break ;
2007-11-21 13:50:36 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_DESC_COLOUR_SCHEME_EXAMPLE : {
2011-07-02 14:37:03 +00:00
Point offset ;
Dimension d = GetSpriteSize ( SPR_VEH_BUS_SW_VIEW , & offset ) ;
d . height - = offset . y ;
2022-09-07 07:31:02 +00:00
DrawSprite ( SPR_VEH_BUS_SW_VIEW , COMPANY_SPRITE_COLOUR ( c - > index ) , r . left - offset . x , CenterBounds ( r . top , r . bottom , d . height ) - offset . y ) ;
2009-11-20 17:36:46 +00:00
break ;
2011-07-02 14:37:03 +00:00
}
2004-08-09 17:04:08 +00:00
2023-02-25 18:02:22 +00:00
case WID_C_DESC_VEHICLE_COUNTS :
DrawVehicleCountsWidget ( r , c ) ;
2010-08-01 18:53:30 +00:00
break ;
2011-12-03 23:40:08 +00:00
2023-02-25 18:02:22 +00:00
case WID_C_DESC_INFRASTRUCTURE_COUNTS :
DrawInfrastructureCountsWidget ( r , c ) ;
2011-12-03 23:40:08 +00:00
break ;
2023-05-30 17:57:42 +00:00
case WID_C_DESC_OWNERS : {
uint y = r . top ;
for ( const Company * c2 : Company : : Iterate ( ) ) {
uint amt = GetAmountOwnedBy ( c , c2 - > index ) ;
if ( amt ! = 0 ) {
SetDParam ( 0 , amt * 25 ) ;
SetDParam ( 1 , c2 - > index ) ;
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_SHARES_OWNED_BY ) ;
2023-12-17 01:16:40 +00:00
y + = GetCharacterHeight ( FS_NORMAL ) ;
2023-05-30 17:57:42 +00:00
}
}
break ;
}
2011-12-16 16:27:45 +00:00
case WID_C_HAS_PASSWORD :
2009-11-20 17:36:46 +00:00
if ( _networking & & NetworkCompanyIsPassworded ( c - > index ) ) {
2010-01-04 23:00:19 +00:00
DrawSprite ( SPR_LOCK , PAL_NONE , r . left , r . top ) ;
2009-11-20 17:36:46 +00:00
}
break ;
}
2008-05-15 14:12:22 +00:00
}
2004-08-09 17:04:08 +00:00
2023-12-29 19:11:59 +00:00
void SetStringParameters ( WidgetID widget ) const override
2009-11-15 13:31:27 +00:00
{
2009-11-20 17:36:46 +00:00
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_C_CAPTION :
2009-11-20 17:36:46 +00:00
SetDParam ( 0 , ( CompanyID ) this - > window_number ) ;
SetDParam ( 1 , ( CompanyID ) this - > window_number ) ;
break ;
2011-12-16 16:27:45 +00:00
case WID_C_DESC_INAUGURATION :
2009-11-20 17:36:46 +00:00
SetDParam ( 0 , Company : : Get ( ( CompanyID ) this - > window_number ) - > inaugurated_year ) ;
break ;
2011-12-16 16:27:45 +00:00
case WID_C_DESC_COMPANY_VALUE :
2009-11-20 17:36:46 +00:00
SetDParam ( 0 , CalculateCompanyValue ( Company : : Get ( ( CompanyID ) this - > window_number ) ) ) ;
break ;
2009-11-15 13:31:27 +00:00
}
}
2023-12-29 19:11:59 +00:00
void OnClick ( [[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count ) override
2008-05-15 14:12:22 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_C_NEW_FACE : DoSelectCompanyManagerFace ( this ) ; break ;
2004-08-09 17:04:08 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_COLOUR_SCHEME :
2019-01-31 13:57:44 +00:00
ShowCompanyLiveryWindow ( ( CompanyID ) this - > window_number , INVALID_GROUP ) ;
2008-05-15 14:12:22 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_C_PRESIDENT_NAME :
this - > query_widget = WID_C_PRESIDENT_NAME ;
2008-05-15 14:12:22 +00:00
SetDParam ( 0 , this - > window_number ) ;
2011-04-17 18:42:17 +00:00
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 ) ;
2008-05-15 14:12:22 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_C_COMPANY_NAME :
this - > query_widget = WID_C_COMPANY_NAME ;
2008-05-15 14:12:22 +00:00
SetDParam ( 0 , this - > window_number ) ;
2011-04-17 18:42:17 +00:00
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 ) ;
2008-05-15 14:12:22 +00:00
break ;
2005-01-06 18:54:13 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_VIEW_HQ : {
2009-05-16 23:34:14 +00:00
TileIndex tile = Company : : Get ( ( CompanyID ) this - > window_number ) - > location_of_HQ ;
2009-11-20 17:36:46 +00:00
if ( _ctrl_pressed ) {
2020-06-29 01:38:29 +00:00
ShowExtraViewportWindow ( tile ) ;
2008-05-15 14:12:22 +00:00
} else {
2009-11-20 17:36:46 +00:00
ScrollMainWindowToTile ( tile ) ;
2006-10-05 23:24:16 +00:00
}
2008-05-15 14:12:22 +00:00
break ;
}
2004-08-09 17:04:08 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_BUILD_HQ :
2009-11-20 17:36:46 +00:00
if ( ( byte ) this - > window_number ! = _local_company ) return ;
2011-12-16 16:27:45 +00:00
if ( this - > IsWidgetLowered ( WID_C_BUILD_HQ ) ) {
2011-11-26 12:53:05 +00:00
ResetObjectToPlace ( ) ;
this - > RaiseButtons ( ) ;
break ;
}
2009-11-20 17:36:46 +00:00
SetObjectToPlaceWnd ( SPR_CURSOR_HQ , PAL_NONE , HT_RECT , this ) ;
SetTileSelectSize ( 2 , 2 ) ;
2011-12-16 16:27:45 +00:00
this - > LowerWidget ( WID_C_BUILD_HQ ) ;
this - > SetWidgetDirty ( WID_C_BUILD_HQ ) ;
2009-11-20 17:36:46 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_C_RELOCATE_HQ :
if ( this - > IsWidgetLowered ( WID_C_RELOCATE_HQ ) ) {
2011-11-26 12:53:05 +00:00
ResetObjectToPlace ( ) ;
this - > RaiseButtons ( ) ;
break ;
}
2009-04-19 10:31:30 +00:00
SetObjectToPlaceWnd ( SPR_CURSOR_HQ , PAL_NONE , HT_RECT , this ) ;
2008-05-15 14:12:22 +00:00
SetTileSelectSize ( 2 , 2 ) ;
2011-12-16 16:27:45 +00:00
this - > LowerWidget ( WID_C_RELOCATE_HQ ) ;
this - > SetWidgetDirty ( WID_C_RELOCATE_HQ ) ;
2008-05-15 14:12:22 +00:00
break ;
2004-08-09 17:04:08 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_VIEW_INFRASTRUCTURE :
2011-12-03 23:40:08 +00:00
ShowCompanyInfrastructure ( ( CompanyID ) this - > window_number ) ;
break ;
2017-03-02 00:09:19 +00:00
case WID_C_GIVE_MONEY :
this - > query_widget = WID_C_GIVE_MONEY ;
ShowQueryString ( STR_EMPTY , STR_COMPANY_VIEW_GIVE_MONEY_QUERY_CAPTION , 30 , this , CS_NUMERAL , QSF_NONE ) ;
break ;
2023-05-30 17:57:42 +00:00
case WID_C_BUY_SHARE :
DoCommandP ( 0 , this - > window_number , 0 , CMD_BUY_SHARE_IN_COMPANY | CMD_MSG ( STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS ) ) ;
break ;
case WID_C_SELL_SHARE :
DoCommandP ( 0 , this - > window_number , 0 , CMD_SELL_SHARE_IN_COMPANY | CMD_MSG ( STR_ERROR_CAN_T_SELL_25_SHARE_IN ) ) ;
break ;
2023-06-05 17:32:22 +00:00
case WID_C_HOSTILE_TAKEOVER :
ShowBuyCompanyDialog ( ( CompanyID ) this - > window_number , true ) ;
break ;
2011-12-16 16:27:45 +00:00
case WID_C_COMPANY_PASSWORD :
2008-09-30 20:39:50 +00:00
if ( this - > window_number = = _local_company ) ShowNetworkCompanyPasswordWindow ( this ) ;
2008-05-15 14:12:22 +00:00
break ;
2009-01-23 22:18:06 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_COMPANY_JOIN : {
this - > query_widget = WID_C_COMPANY_JOIN ;
2009-01-23 22:18:06 +00:00
CompanyID company = ( CompanyID ) this - > window_number ;
if ( _network_server ) {
NetworkServerDoMove ( CLIENT_ID_SERVER , company ) ;
MarkWholeScreenDirty ( ) ;
} else if ( NetworkCompanyIsPassworded ( company ) ) {
/* ask for the password */
2019-03-31 14:08:00 +00:00
ShowQueryString ( STR_EMPTY , STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION , NETWORK_PASSWORD_LENGTH , this , CS_ALPHANUMERAL , QSF_PASSWORD ) ;
2009-01-23 22:18:06 +00:00
} else {
/* just send the join command */
NetworkClientRequestMove ( company ) ;
}
break ;
}
2008-05-15 14:12:22 +00:00
}
}
2004-08-09 17:04:08 +00:00
2019-03-04 07:49:37 +00:00
void OnHundredthTick ( ) override
2008-05-15 14:12:22 +00:00
{
/* redraw the window every now and then */
2008-05-29 11:47:56 +00:00
this - > SetDirty ( ) ;
2008-05-15 14:12:22 +00:00
}
2004-12-22 23:24:53 +00:00
2023-09-16 20:20:53 +00:00
void OnPlaceObject ( [[maybe_unused]] Point pt , TileIndex tile ) override
2008-05-15 14:12:22 +00:00
{
2017-07-11 19:37:10 +00:00
if ( DoCommandP ( tile , OBJECT_HQ , 0 , CMD_BUILD_OBJECT | CMD_MSG ( STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS ) ) & & ! _shift_pressed ) {
2008-05-15 14:12:22 +00:00
ResetObjectToPlace ( ) ;
this - > RaiseButtons ( ) ;
2009-11-15 13:31:27 +00:00
}
2008-05-15 14:12:22 +00:00
}
2006-10-11 00:48:55 +00:00
2019-03-04 07:49:37 +00:00
void OnPlaceObjectAbort ( ) override
2008-05-15 14:12:22 +00:00
{
this - > RaiseButtons ( ) ;
}
2004-12-22 23:24:53 +00:00
2019-03-04 07:49:37 +00:00
void OnQueryTextFinished ( char * str ) override
2008-05-15 14:12:22 +00:00
{
2019-04-10 21:07:06 +00:00
if ( str = = nullptr ) return ;
2006-10-05 23:24:16 +00:00
2008-05-15 14:12:22 +00:00
switch ( this - > query_widget ) {
default : NOT_REACHED ( ) ;
2006-10-05 23:24:16 +00:00
2017-03-02 00:09:19 +00:00
case WID_C_GIVE_MONEY :
2023-06-06 21:09:01 +00:00
DoCommandPEx ( 0 , this - > window_number , 0 , ( std : : strtoull ( str , nullptr , 10 ) / _currency - > rate ) , CMD_GIVE_MONEY | CMD_MSG ( STR_ERROR_CAN_T_GIVE_MONEY ) , CcGiveMoney ) ;
2017-03-02 00:09:19 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_C_PRESIDENT_NAME :
2019-04-10 21:07:06 +00:00
DoCommandP ( 0 , 0 , 0 , CMD_RENAME_PRESIDENT | CMD_MSG ( STR_ERROR_CAN_T_CHANGE_PRESIDENT ) , nullptr , str ) ;
2008-05-15 14:12:22 +00:00
break ;
2004-08-09 17:04:08 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_COMPANY_NAME :
2019-04-10 21:07:06 +00:00
DoCommandP ( 0 , 0 , 0 , CMD_RENAME_COMPANY | CMD_MSG ( STR_ERROR_CAN_T_CHANGE_COMPANY_NAME ) , nullptr , str ) ;
2008-05-15 14:12:22 +00:00
break ;
2009-01-23 22:18:06 +00:00
2011-12-16 16:27:45 +00:00
case WID_C_COMPANY_JOIN :
2009-01-23 22:18:06 +00:00
NetworkClientRequestMove ( ( CompanyID ) this - > window_number , str ) ;
break ;
2008-05-15 14:12:22 +00:00
}
}
2023-05-30 17:57:42 +00:00
/**
* Some data on this window has become invalid .
* @ param data Information about the changed data .
* @ 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 .
*/
void OnInvalidateData ( int data = 0 , bool gui_scope = true ) override
{
if ( this - > window_number = = _local_company ) return ;
if ( _settings_game . economy . allow_shares ) { // Shares are allowed
const Company * c = Company : : Get ( this - > window_number ) ;
/* If all shares are owned by someone (none by nobody), disable buy button */
this - > SetWidgetDisabledState ( WID_C_BUY_SHARE , GetAmountOwnedBy ( c , INVALID_OWNER ) = = 0 | |
/* Only 25% left to buy. If the company is human, disable buying it up.. TODO issues! */
( GetAmountOwnedBy ( c , INVALID_OWNER ) = = 1 & & ! c - > is_ai ) | |
/* Spectators cannot do anything of course */
_local_company = = COMPANY_SPECTATOR ) ;
/* If the company doesn't own any shares, disable sell button */
this - > SetWidgetDisabledState ( WID_C_SELL_SHARE , ( GetAmountOwnedBy ( c , _local_company ) = = 0 ) | |
/* Spectators cannot do anything of course */
_local_company = = COMPANY_SPECTATOR ) ;
} else { // Shares are not allowed, disable buy/sell buttons
this - > DisableWidget ( WID_C_BUY_SHARE ) ;
this - > DisableWidget ( WID_C_SELL_SHARE ) ;
}
}
2008-05-15 14:12:22 +00:00
} ;
2004-08-09 17:04:08 +00:00
2023-11-02 19:33:01 +00:00
static WindowDesc _company_desc ( __FILE__ , __LINE__ ,
2013-05-26 19:25:01 +00:00
WDP_AUTO , " company " , 0 , 0 ,
2007-02-01 15:49:12 +00:00
WC_COMPANY , WC_NONE ,
2012-11-11 16:10:43 +00:00
0 ,
2023-09-03 20:54:13 +00:00
std : : begin ( _nested_company_widgets ) , std : : end ( _nested_company_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2011-05-02 20:59:54 +00:00
/**
* Show the window with the overview of the company .
* @ param company The company to show the window for .
*/
2008-09-30 20:39:50 +00:00
void ShowCompany ( CompanyID company )
2004-08-09 17:04:08 +00:00
{
2009-05-17 01:00:56 +00:00
if ( ! Company : : IsValidID ( company ) ) return ;
2006-10-31 21:15:56 +00:00
2008-09-30 20:39:50 +00:00
AllocateWindowDescFront < CompanyWindow > ( & _company_desc , company ) ;
2004-08-09 17:04:08 +00:00
}
2011-12-03 23:40:08 +00:00
/**
* Redraw all windows with company infrastructure counts .
* @ param company The company to redraw the windows of .
*/
void DirtyCompanyInfrastructureWindows ( CompanyID company )
{
SetWindowDirty ( WC_COMPANY , company ) ;
SetWindowDirty ( WC_COMPANY_INFRASTRUCTURE , company ) ;
}
2017-02-05 18:07:10 +00:00
/**
* Redraw all windows with all company infrastructure counts .
*/
void DirtyAllCompanyInfrastructureWindows ( )
{
SetWindowClassesDirty ( WC_COMPANY ) ;
SetWindowClassesDirty ( WC_COMPANY_INFRASTRUCTURE ) ;
}
2008-05-18 20:49:22 +00:00
struct BuyCompanyWindow : Window {
2023-06-05 17:32:22 +00:00
BuyCompanyWindow ( WindowDesc * desc , WindowNumber window_number , bool hostile_takeover ) : Window ( desc ) , hostile_takeover ( hostile_takeover )
2008-05-18 20:49:22 +00:00
{
2013-05-26 19:23:42 +00:00
this - > InitNested ( window_number ) ;
2022-09-02 17:06:53 +00:00
this - > owner = _local_company ;
2023-06-05 17:32:22 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
this - > company_value = hostile_takeover ? CalculateHostileTakeoverValue ( c ) : c - > bankrupt_value ;
2004-08-09 17:04:08 +00:00
}
2008-05-18 20:49:22 +00:00
2023-11-25 13:29:58 +00:00
void Close ( int data = 0 ) override
2021-10-23 23:07:54 +00:00
{
const Company * c = Company : : GetIfValid ( ( CompanyID ) this - > window_number ) ;
2023-09-12 18:04:03 +00:00
if ( ! this - > hostile_takeover & & c ! = nullptr & & HasBit ( c - > bankrupt_asked , this - > owner ) & & _current_company = = this - > owner ) {
2022-09-14 20:57:37 +00:00
EnqueueDoCommandP ( NewCommandContainerBasic ( 0 , this - > window_number , 0 , CMD_DECLINE_BUY_COMPANY | CMD_NO_SHIFT_ESTIMATE ) ) ;
2021-10-23 23:07:54 +00:00
}
2023-09-15 22:56:33 +00:00
this - > Window : : Close ( ) ;
2021-10-23 23:07:54 +00:00
}
2024-01-02 14:31:56 +00:00
void UpdateWidgetSize ( WidgetID widget , Dimension * size , const Dimension & padding , Dimension * fill , Dimension * resize ) override
2009-11-08 19:21:18 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_BC_FACE :
2023-04-21 18:54:04 +00:00
* size = GetScaledSpriteSize ( SPR_GRADIENT ) ;
2009-11-08 19:21:18 +00:00
break ;
2008-05-18 20:49:22 +00:00
2011-12-16 16:27:45 +00:00
case WID_BC_QUESTION :
2009-11-08 19:21:18 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > index ) ;
2023-06-05 17:32:22 +00:00
SetDParam ( 1 , this - > company_value ) ;
size - > height = GetStringHeight ( this - > hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE , size - > width ) ;
2009-11-08 19:21:18 +00:00
break ;
}
}
2023-12-29 19:11:59 +00:00
void SetStringParameters ( WidgetID widget ) const override
2009-11-08 19:21:18 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_BC_CAPTION :
2009-11-08 19:21:18 +00:00
SetDParam ( 0 , STR_COMPANY_NAME ) ;
SetDParam ( 1 , Company : : Get ( ( CompanyID ) this - > window_number ) - > index ) ;
break ;
}
}
2023-12-29 19:11:59 +00:00
void DrawWidget ( const Rect & r , WidgetID widget ) const override
2009-11-08 19:21:18 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_BC_FACE : {
2009-11-08 19:21:18 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
2023-04-21 18:54:04 +00:00
DrawCompanyManagerFace ( c - > face , c - > colour , r ) ;
2010-08-01 18:53:30 +00:00
break ;
}
2009-11-08 19:21:18 +00:00
2011-12-16 16:27:45 +00:00
case WID_BC_QUESTION : {
2009-11-08 19:21:18 +00:00
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > index ) ;
2023-06-05 17:32:22 +00:00
SetDParam ( 1 , this - > company_value ) ;
DrawStringMultiLine ( r . left , r . right , r . top , r . bottom , this - > hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE , TC_FROMSTRING , SA_CENTER ) ;
2010-08-01 18:53:30 +00:00
break ;
}
2009-11-08 19:21:18 +00:00
}
2008-05-18 20:49:22 +00:00
}
2023-12-29 19:11:59 +00:00
void OnClick ( [[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count ) override
2008-05-18 20:49:22 +00:00
{
switch ( widget ) {
2011-12-16 16:27:45 +00:00
case WID_BC_NO :
2023-09-15 22:56:33 +00:00
this - > Close ( ) ;
2008-05-18 20:49:22 +00:00
break ;
2011-12-16 16:27:45 +00:00
case WID_BC_YES :
2023-09-12 18:04:03 +00:00
DoCommandP ( 0 , this - > window_number , ( this - > hostile_takeover ? 1 : 0 ) , CMD_BUY_COMPANY | CMD_MSG ( STR_ERROR_CAN_T_BUY_COMPANY ) ) ;
2008-05-18 20:49:22 +00:00
break ;
}
}
2023-06-05 17:32:22 +00:00
/**
* Check on a regular interval if the company value has changed .
*/
2023-09-12 18:04:03 +00:00
void OnHundredthTick ( ) override
{
2023-06-05 17:32:22 +00:00
/* Value can't change when in bankruptcy. */
if ( ! this - > hostile_takeover ) return ;
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
auto new_value = CalculateHostileTakeoverValue ( c ) ;
if ( new_value ! = this - > company_value ) {
this - > company_value = new_value ;
this - > ReInit ( ) ;
}
2023-09-12 18:04:03 +00:00
}
2023-06-05 17:32:22 +00:00
private :
bool hostile_takeover ; ///< Whether the window is showing a hostile takeover.
Money company_value ; ///< The value of the company for which the user can buy it.
2008-05-18 20:49:22 +00:00
} ;
2004-08-09 17:04:08 +00:00
2024-01-15 22:49:24 +00:00
static constexpr NWidgetPart _nested_buy_company_widgets [ ] = {
2009-05-03 08:27:12 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_LIGHT_BLUE ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_CAPTION , COLOUR_LIGHT_BLUE , WID_BC_CAPTION ) , SetDataTip ( STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2009-05-03 08:27:12 +00:00
EndContainer ( ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_LIGHT_BLUE ) ,
2023-10-25 21:12:38 +00:00
NWidget ( NWID_VERTICAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . vsep_wide , 0 ) , SetPadding ( WidgetDimensions : : unscaled . modalpopup ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , WidgetDimensions : : unscaled . hsep_wide , 0 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_BC_FACE ) , SetFill ( 0 , 1 ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_BC_QUESTION ) , SetMinimalSize ( 240 , 0 ) , SetFill ( 1 , 1 ) ,
2009-11-08 19:21:18 +00:00
EndContainer ( ) ,
2023-10-25 21:12:38 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) , SetPIP ( 100 , WidgetDimensions : : unscaled . hsep_wide , 100 ) ,
2011-12-16 16:27:45 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_LIGHT_BLUE , WID_BC_NO ) , SetMinimalSize ( 60 , 12 ) , SetDataTip ( STR_QUIT_NO , STR_NULL ) , SetFill ( 1 , 0 ) ,
NWidget ( WWT_TEXTBTN , COLOUR_LIGHT_BLUE , WID_BC_YES ) , SetMinimalSize ( 60 , 12 ) , SetDataTip ( STR_QUIT_YES , STR_NULL ) , SetFill ( 1 , 0 ) ,
2009-11-08 19:21:18 +00:00
EndContainer ( ) ,
2009-05-03 08:27:12 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
} ;
2023-11-02 19:33:01 +00:00
static WindowDesc _buy_company_desc ( __FILE__ , __LINE__ ,
2019-04-10 21:07:06 +00:00
WDP_AUTO , nullptr , 0 , 0 ,
2007-02-01 15:49:12 +00:00
WC_BUY_COMPANY , WC_NONE ,
2009-11-24 17:28:29 +00:00
WDF_CONSTRUCTION ,
2023-09-03 20:54:13 +00:00
std : : begin ( _nested_buy_company_widgets ) , std : : end ( _nested_buy_company_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2011-05-02 20:59:54 +00:00
/**
* Show the query to buy another company .
* @ param company The company to buy .
2023-06-05 17:32:22 +00:00
* @ param hostile_takeover Whether this is a hostile takeover .
2011-05-02 20:59:54 +00:00
*/
2023-06-05 17:32:22 +00:00
void ShowBuyCompanyDialog ( CompanyID company , bool hostile_takeover )
2004-08-09 17:04:08 +00:00
{
2023-06-05 17:32:22 +00:00
auto window = BringWindowToFrontById ( WC_BUY_COMPANY , company ) ;
if ( window = = nullptr ) {
new BuyCompanyWindow ( & _buy_company_desc , company , hostile_takeover ) ;
}
2004-08-09 17:04:08 +00:00
}