2005-07-24 14:12:37 +00:00
/* $Id$ */
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/>.
*/
2008-09-30 20:39:50 +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"
# 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"
2009-10-04 17:16:41 +00:00
# include "economy_func.h"
2010-08-06 19:56:14 +00:00
# include "vehicle_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 "sprite.h"
# include "company_base.h"
# include "core/geometry_func.hpp"
2010-08-08 10:59:30 +00:00
# include "object.h"
2004-08-09 17:04:08 +00:00
2008-01-13 01:21:35 +00:00
# include "table/strings.h"
2009-10-09 19:10:05 +00:00
/** Company GUI constants. */
2010-05-13 10:14:29 +00:00
static const int FIRST_GUI_CALL = INT_MAX ; ///< default value to specify this is the first call of the resizable gui
2009-10-09 19:10:05 +00:00
2010-05-13 10:14:29 +00:00
static const uint EXP_LINESPACE = 2 ; ///< Amount of vertical space for a horizontal (sub-)total line.
static const uint EXP_BLOCKSPACE = 10 ; ///< Amount of vertical space between two blocks of numbers.
2008-04-09 02:02:39 +00:00
2009-11-28 13:47:57 +00:00
static void DoSelectCompanyManagerFace ( Window * parent ) ;
2004-08-09 17:04:08 +00:00
2009-01-31 21:27:36 +00:00
/** Standard unsorted list of expenses. */
static ExpensesType _expenses_list_1 [ ] = {
EXPENSES_CONSTRUCTION ,
EXPENSES_NEW_VEHICLES ,
EXPENSES_TRAIN_RUN ,
EXPENSES_ROADVEH_RUN ,
EXPENSES_AIRCRAFT_RUN ,
EXPENSES_SHIP_RUN ,
EXPENSES_PROPERTY ,
EXPENSES_TRAIN_INC ,
EXPENSES_ROADVEH_INC ,
EXPENSES_AIRCRAFT_INC ,
EXPENSES_SHIP_INC ,
EXPENSES_LOAN_INT ,
EXPENSES_OTHER ,
} ;
/** Grouped list of expenses. */
static ExpensesType _expenses_list_2 [ ] = {
EXPENSES_TRAIN_INC ,
EXPENSES_ROADVEH_INC ,
EXPENSES_AIRCRAFT_INC ,
EXPENSES_SHIP_INC ,
INVALID_EXPENSES ,
EXPENSES_TRAIN_RUN ,
EXPENSES_ROADVEH_RUN ,
EXPENSES_AIRCRAFT_RUN ,
EXPENSES_SHIP_RUN ,
EXPENSES_PROPERTY ,
EXPENSES_LOAN_INT ,
INVALID_EXPENSES ,
EXPENSES_CONSTRUCTION ,
EXPENSES_NEW_VEHICLES ,
EXPENSES_OTHER ,
INVALID_EXPENSES ,
} ;
/** Expense list container. */
struct ExpensesList {
2009-10-10 13:32:44 +00:00
const ExpensesType * et ; ///< Expenses items.
const uint length ; ///< Number of items in list.
const uint num_subtotals ; ///< Number of sub-totals in the list.
2009-10-09 19:10:05 +00:00
ExpensesList ( ExpensesType * et , int length , int num_subtotals ) : et ( et ) , length ( length ) , num_subtotals ( num_subtotals )
{
}
2009-10-10 13:32:44 +00:00
uint GetHeight ( ) const
2009-05-13 17:39:00 +00:00
{
2009-10-10 15:18:20 +00:00
/* heading + line + texts of expenses + sub-totals + total line + total text */
return FONT_HEIGHT_NORMAL + EXP_LINESPACE + this - > length * FONT_HEIGHT_NORMAL + num_subtotals * ( EXP_BLOCKSPACE + EXP_LINESPACE ) + EXP_LINESPACE + FONT_HEIGHT_NORMAL ;
}
/** Compute width of the expenses categories in pixels. */
uint GetCategoriesWidth ( ) const
{
uint width = 0 ;
bool invalid_expenses_measured = false ; // Measure 'Total' width only once.
for ( uint i = 0 ; i < this - > length ; i + + ) {
ExpensesType et = this - > et [ i ] ;
if ( et = = INVALID_EXPENSES ) {
if ( ! invalid_expenses_measured ) {
width = max ( width , GetStringBoundingBox ( STR_FINANCES_TOTAL_CAPTION ) . width ) ;
invalid_expenses_measured = true ;
}
} else {
width = max ( width , GetStringBoundingBox ( STR_FINANCES_SECTION_CONSTRUCTION + et ) . width ) ;
}
}
return width ;
2009-05-13 17:39:00 +00:00
}
2009-01-31 21:27:36 +00:00
} ;
static const ExpensesList _expenses_list_types [ ] = {
2009-10-09 19:10:05 +00:00
ExpensesList ( _expenses_list_1 , lengthof ( _expenses_list_1 ) , 0 ) ,
ExpensesList ( _expenses_list_2 , lengthof ( _expenses_list_2 ) , 3 ) ,
2009-01-31 21:27:36 +00:00
} ;
2009-03-28 04:14:02 +00:00
/** Widgets of the company finances windows. */
2009-03-27 01:55:25 +00:00
enum CompanyFinancesWindowWidgets {
CFW_CAPTION , ///< Caption of the window
CFW_TOGGLE_SIZE , ///< Toggle windows size
2009-10-10 15:18:20 +00:00
CFW_SEL_PANEL , ///< Select panel or nothing
2009-03-27 01:55:25 +00:00
CFW_EXPS_CATEGORY , ///< Column for expenses category strings
CFW_EXPS_PRICE1 , ///< Column for year Y-2 expenses
CFW_EXPS_PRICE2 , ///< Column for year Y-1 expenses
CFW_EXPS_PRICE3 , ///< Column for year Y expenses
CFW_TOTAL_PANEL , ///< Panel for totals
2009-10-10 15:18:20 +00:00
CFW_SEL_MAXLOAN , ///< Selection of maxloan column
CFW_BALANCE_VALUE , ///< Bank balance value
CFW_LOAN_VALUE , ///< Loan
CFW_LOAN_LINE , ///< Line for summing bank balance and loan
CFW_TOTAL_VALUE , ///< Total
CFW_MAXLOAN_GAP , ///< Gap above max loan widget
CFW_MAXLOAN_VALUE , ///< Max loan widget
CFW_SEL_BUTTONS , ///< Selection of buttons
2009-03-27 01:55:25 +00:00
CFW_INCREASE_LOAN , ///< Increase loan
CFW_REPAY_LOAN , ///< Decrease loan
} ;
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
{
2009-10-10 15:18:20 +00:00
int y = r . top ;
2009-10-07 19:18:36 +00:00
2010-07-02 13:53:05 +00:00
DrawString ( r . left , r . right , y , STR_FINANCES_EXPENDITURE_INCOME_TITLE , TC_FROMSTRING , SA_HOR_CENTER , true ) ;
2009-10-09 19:10:05 +00:00
y + = FONT_HEIGHT_NORMAL + EXP_LINESPACE ;
2009-10-07 19:18:36 +00:00
int type = _settings_client . gui . expenses_layout ;
2009-10-10 13:32:44 +00:00
for ( uint i = 0 ; i < _expenses_list_types [ type ] . length ; i + + ) {
2009-10-07 19:18:36 +00:00
const ExpensesType et = _expenses_list_types [ type ] . et [ i ] ;
if ( et = = INVALID_EXPENSES ) {
2009-10-09 19:10:05 +00:00
y + = EXP_LINESPACE ;
2009-10-07 19:18:36 +00:00
DrawString ( r . left , r . right , y , STR_FINANCES_TOTAL_CAPTION , TC_FROMSTRING , SA_RIGHT ) ;
2009-10-09 19:10:05 +00:00
y + = FONT_HEIGHT_NORMAL + EXP_BLOCKSPACE ;
2009-10-07 19:18:36 +00:00
} else {
DrawString ( r . left , r . right , y , STR_FINANCES_SECTION_CONSTRUCTION + et ) ;
2009-10-09 19:10:05 +00:00
y + = FONT_HEIGHT_NORMAL ;
2009-10-07 19:18:36 +00:00
}
}
2009-10-09 19:10:05 +00:00
DrawString ( r . left , r . right , y + EXP_LINESPACE , STR_FINANCES_TOTAL_CAPTION , TC_FROMSTRING , SA_RIGHT ) ;
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 .
*/
static void DrawPrice ( Money amount , int left , int right , int top )
{
StringID str = STR_FINANCES_NEGATIVE_INCOME ;
if ( amount < 0 ) {
amount = - amount ;
str + + ;
}
SetDParam ( 0 , amount ) ;
DrawString ( left , right , top , str , TC_FROMSTRING , SA_RIGHT ) ;
}
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 .
* @ param tbl Pointer to table of amounts for \ a year .
* @ note The environment must provide padding at the left and right of \ a r .
*/
static void DrawYearColumn ( const Rect & r , int year , const Money ( * tbl ) [ EXPENSES_END ] )
2004-08-09 17:04:08 +00:00
{
2009-10-10 15:18:20 +00:00
int y = r . top ;
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 ) ;
2009-10-09 19:10:05 +00:00
y + = FONT_HEIGHT_NORMAL + EXP_LINESPACE ;
2009-10-07 19:18:36 +00:00
Money sum = 0 ;
Money subtotal = 0 ;
2009-01-31 21:27:36 +00:00
int type = _settings_client . gui . expenses_layout ;
2009-10-10 13:32:44 +00:00
for ( uint i = 0 ; i < _expenses_list_types [ type ] . length ; i + + ) {
2009-10-07 19:18:36 +00:00
const ExpensesType et = _expenses_list_types [ type ] . et [ i ] ;
if ( et = = INVALID_EXPENSES ) {
Money cost = subtotal ;
subtotal = 0 ;
GfxFillRect ( r . left , y , r . right , y , 215 ) ;
2009-10-09 19:10:05 +00:00
y + = EXP_LINESPACE ;
2009-10-10 13:19:38 +00:00
DrawPrice ( cost , r . left , r . right , y ) ;
2009-10-09 19:10:05 +00:00
y + = FONT_HEIGHT_NORMAL + EXP_BLOCKSPACE ;
2009-10-07 19:18:36 +00:00
} else {
Money cost = ( * tbl ) [ et ] ;
subtotal + = cost ;
sum + = cost ;
2009-10-10 13:19:38 +00:00
if ( cost ! = 0 ) DrawPrice ( cost , r . left , r . right , y ) ;
2009-10-09 19:10:05 +00:00
y + = FONT_HEIGHT_NORMAL ;
2009-10-07 19:18:36 +00:00
}
}
GfxFillRect ( r . left , y , r . right , y , 215 ) ;
2009-10-09 19:10:05 +00:00
y + = EXP_LINESPACE ;
2009-10-07 19:18:36 +00:00
DrawPrice ( sum , r . left , r . right , y ) ;
}
2009-03-27 22:59:43 +00:00
static const NWidgetPart _nested_company_finances_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2009-10-10 15:18:20 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , CFW_CAPTION ) , SetDataTip ( STR_FINANCES_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2009-11-22 11:20:12 +00:00
NWidget ( WWT_IMGBTN , COLOUR_GREY , CFW_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 ( ) ,
2009-10-10 15:18:20 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , CFW_SEL_PANEL ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) ,
2009-10-10 15:18:20 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPadding ( WD_FRAMERECT_TOP , WD_FRAMERECT_RIGHT , WD_FRAMERECT_BOTTOM , WD_FRAMERECT_LEFT ) , SetPIP ( 0 , 9 , 0 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_EMPTY , COLOUR_GREY , CFW_EXPS_CATEGORY ) , SetMinimalSize ( 120 , 0 ) , SetFill ( 0 , 0 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , CFW_EXPS_PRICE1 ) , SetMinimalSize ( 86 , 0 ) , SetFill ( 0 , 0 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , CFW_EXPS_PRICE2 ) , SetMinimalSize ( 86 , 0 ) , SetFill ( 0 , 0 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , CFW_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 ) ,
2009-10-10 15:18:20 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPadding ( WD_FRAMERECT_TOP , WD_FRAMERECT_RIGHT , WD_FRAMERECT_BOTTOM , WD_FRAMERECT_LEFT ) ,
NWidget ( NWID_VERTICAL ) , // Vertical column with 'bank balance', 'loan'
2009-11-24 21:13:36 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY ) , SetDataTip ( STR_FINANCES_BANK_BALANCE_TITLE , STR_NULL ) , SetFill ( 1 , 0 ) ,
NWidget ( WWT_TEXT , COLOUR_GREY ) , SetDataTip ( STR_FINANCES_LOAN_TITLE , STR_NULL ) , SetFill ( 1 , 0 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
2009-10-10 15:18:20 +00:00
EndContainer ( ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 0 , 0 ) , SetMinimalSize ( 30 , 0 ) ,
2009-10-10 15:18:20 +00:00
NWidget ( NWID_VERTICAL ) , // Vertical column with bank balance amount, loan amount, and total.
NWidget ( WWT_TEXT , COLOUR_GREY , CFW_BALANCE_VALUE ) , SetDataTip ( STR_NULL , STR_NULL ) ,
NWidget ( WWT_TEXT , COLOUR_GREY , CFW_LOAN_VALUE ) , SetDataTip ( STR_NULL , STR_NULL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_EMPTY , COLOUR_GREY , CFW_LOAN_LINE ) , SetMinimalSize ( 0 , 2 ) , SetFill ( 1 , 0 ) ,
2009-10-10 15:18:20 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , CFW_TOTAL_VALUE ) , SetDataTip ( STR_NULL , STR_NULL ) ,
EndContainer ( ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , CFW_SEL_MAXLOAN ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) , SetMinimalSize ( 25 , 0 ) ,
2009-10-10 15:18:20 +00:00
NWidget ( NWID_VERTICAL ) , // Max loan information
2009-11-22 18:26:01 +00:00
NWidget ( WWT_EMPTY , COLOUR_GREY , CFW_MAXLOAN_GAP ) , SetFill ( 0 , 0 ) ,
2009-10-10 15:18:20 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , CFW_MAXLOAN_VALUE ) , SetDataTip ( STR_FINANCES_MAX_LOAN , STR_NULL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
2009-10-10 15:18:20 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
EndContainer ( ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 1 , 1 ) ,
2009-03-27 22:59:43 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2009-10-10 15:18:20 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , CFW_SEL_BUTTONS ) ,
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CFW_INCREASE_LOAN ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FINANCES_BORROW_BUTTON , STR_FINANCES_BORROW_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CFW_REPAY_LOAN ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FINANCES_REPAY_BUTTON , STR_FINANCES_REPAY_TOOLTIP ) ,
2009-03-27 22:59:43 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2004-08-09 17:04:08 +00:00
} ;
2010-08-01 19:22:34 +00:00
/**
* Window class displaying the company finances .
2009-10-10 15:18:20 +00:00
* @ todo # money_width should be calculated dynamically .
*/
2008-09-30 20:39:50 +00:00
struct CompanyFinancesWindow : Window {
2009-11-24 12:42:36 +00:00
static Money max_money ; ///< The maximum amount of money a company has had this 'run'
bool small ; ///< Window is toggled to 'small'.
2004-08-09 17:04:08 +00:00
2009-10-10 15:18:20 +00:00
CompanyFinancesWindow ( const WindowDesc * desc , CompanyID company ) : Window ( )
2008-05-16 07:34:48 +00:00
{
2009-10-10 15:18:20 +00:00
this - > small = false ;
this - > CreateNestedTree ( desc ) ;
this - > SetupWidgets ( ) ;
this - > FinishInitNested ( desc , company ) ;
2009-02-09 02:33:10 +00:00
this - > owner = ( Owner ) this - > window_number ;
2009-10-10 15:18:20 +00:00
}
virtual void SetStringParameters ( int widget ) const
{
switch ( widget ) {
case CFW_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
2009-10-10 15:18:20 +00:00
case CFW_MAXLOAN_VALUE :
SetDParam ( 0 , _economy . max_loan ) ;
break ;
2004-08-09 17:04:08 +00:00
2009-10-10 15:18:20 +00:00
case CFW_INCREASE_LOAN :
case CFW_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
}
2009-11-22 18:28:14 +00:00
virtual void UpdateWidgetSize ( int widget , Dimension * size , const Dimension & padding , Dimension * fill , Dimension * resize )
2009-10-10 15:18:20 +00:00
{
int type = _settings_client . gui . expenses_layout ;
switch ( widget ) {
case CFW_EXPS_CATEGORY :
size - > width = _expenses_list_types [ type ] . GetCategoriesWidth ( ) ;
size - > height = _expenses_list_types [ type ] . GetHeight ( ) ;
break ;
case CFW_EXPS_PRICE1 :
case CFW_EXPS_PRICE2 :
case CFW_EXPS_PRICE3 :
size - > height = _expenses_list_types [ type ] . GetHeight ( ) ;
2010-07-29 14:26:28 +00:00
/* FALL THROUGH */
2009-10-10 15:18:20 +00:00
case CFW_BALANCE_VALUE :
case CFW_LOAN_VALUE :
case CFW_TOTAL_VALUE :
2009-11-24 12:42:36 +00:00
SetDParam ( 0 , CompanyFinancesWindow : : max_money ) ;
size - > width = max ( GetStringBoundingBox ( STR_FINANCES_NEGATIVE_INCOME ) . width , GetStringBoundingBox ( STR_FINANCES_POSITIVE_INCOME ) . width ) + padding . width ;
2009-10-10 15:18:20 +00:00
break ;
case CFW_MAXLOAN_GAP :
size - > height = FONT_HEIGHT_NORMAL ;
break ;
}
2008-05-16 07:34:48 +00:00
}
2004-08-09 17:04:08 +00:00
2009-10-10 15:18:20 +00:00
virtual void DrawWidget ( const Rect & r , int widget ) const
2008-05-16 07:34:48 +00:00
{
2009-10-10 15:18:20 +00:00
switch ( widget ) {
case CFW_EXPS_CATEGORY :
DrawCategories ( r ) ;
break ;
case CFW_EXPS_PRICE1 :
case CFW_EXPS_PRICE2 :
case CFW_EXPS_PRICE3 : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
int age = min ( _cur_year - c - > inaugurated_year , 2 ) ;
int wid_offset = widget - CFW_EXPS_PRICE1 ;
if ( wid_offset < = age ) {
DrawYearColumn ( r , _cur_year - ( age - wid_offset ) , c - > yearly_expenses + ( age - wid_offset ) ) ;
}
break ;
}
case CFW_BALANCE_VALUE : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > money ) ;
DrawString ( r . left , r . right , r . top , STR_FINANCES_TOTAL_CURRENCY , TC_FROMSTRING , SA_RIGHT ) ;
break ;
}
case CFW_LOAN_VALUE : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > current_loan ) ;
DrawString ( r . left , r . right , r . top , STR_FINANCES_TOTAL_CURRENCY , TC_FROMSTRING , SA_RIGHT ) ;
break ;
}
case CFW_TOTAL_VALUE : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > money - c - > current_loan ) ;
DrawString ( r . left , r . right , r . top , STR_FINANCES_TOTAL_CURRENCY , TC_FROMSTRING , SA_RIGHT ) ;
break ;
}
case CFW_LOAN_LINE :
GfxFillRect ( r . left , r . top , r . right , r . top , 215 ) ;
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 ;
2009-10-10 15:18:20 +00:00
this - > GetWidget < NWidgetStacked > ( CFW_SEL_PANEL ) - > SetDisplayedPlane ( plane ) ;
this - > GetWidget < NWidgetStacked > ( CFW_SEL_MAXLOAN ) - > SetDisplayedPlane ( plane ) ;
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 ;
2009-10-10 15:18:20 +00:00
this - > GetWidget < NWidgetStacked > ( CFW_SEL_BUTTONS ) - > SetDisplayedPlane ( plane ) ;
}
2008-05-16 07:34:48 +00:00
2009-10-10 15:18:20 +00:00
virtual void OnPaint ( )
{
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. */
int type = _settings_client . gui . expenses_layout ;
if ( _expenses_list_types [ type ] . GetHeight ( ) ! = this - > GetWidget < NWidgetBase > ( CFW_EXPS_CATEGORY ) - > current_y ) {
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 ;
2009-12-21 16:24:29 +00:00
if ( req_plane ! = this - > GetWidget < NWidgetStacked > ( CFW_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 ) ;
this - > SetWidgetDisabledState ( CFW_INCREASE_LOAN , c - > current_loan = = _economy . max_loan ) ; // Borrow button only shows when there is any more money to loan.
this - > SetWidgetDisabledState ( CFW_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
2010-01-30 18:34:48 +00:00
virtual void OnClick ( Point pt , int widget , int click_count )
2008-05-16 07:34:48 +00:00
{
switch ( widget ) {
2009-10-10 15:18:20 +00:00
case CFW_TOGGLE_SIZE : // toggle size
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
2009-03-26 02:02:11 +00:00
case CFW_INCREASE_LOAN : // increase loan
2009-04-21 23:40:56 +00:00
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 ;
2009-03-26 02:02:11 +00:00
case CFW_REPAY_LOAN : // repay loan
2009-04-21 23:40:56 +00:00
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 ;
}
2004-08-09 17:04:08 +00:00
}
2009-11-24 12:42:36 +00:00
virtual void OnHundredthTick ( )
{
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
if ( c - > money > CompanyFinancesWindow : : max_money ) {
CompanyFinancesWindow : : max_money = max ( c - > money * 2 , CompanyFinancesWindow : : max_money * 4 ) ;
this - > SetupWidgets ( ) ;
this - > ReInit ( ) ;
}
}
2008-05-16 07:34:48 +00:00
} ;
2004-08-09 17:04:08 +00:00
2009-11-24 12:42:36 +00:00
/** First conservative estimate of the maximum amount of money */
Money CompanyFinancesWindow : : max_money = INT32_MAX ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _company_finances_desc (
2009-11-28 14:42:35 +00:00
WDP_AUTO , 0 , 0 ,
2007-02-01 15:49:12 +00:00
WC_FINANCES , WC_NONE ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS ,
2009-11-15 10:26:01 +00:00
_nested_company_finances_widgets , lengthof ( _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
} ;
2008-04-12 22:19:34 +00:00
class DropDownListColourItem : public DropDownListItem {
public :
DropDownListColourItem ( int result , bool masked ) : DropDownListItem ( result , masked ) { }
virtual ~ DropDownListColourItem ( ) { }
2008-08-06 07:10:40 +00:00
StringID String ( ) const
2008-04-12 22:19:34 +00:00
{
return _colour_dropdown [ this - > result ] ;
}
2008-08-06 07:10:40 +00:00
uint Height ( uint width ) const
2008-04-12 22:19:34 +00:00
{
2009-03-28 12:47:29 +00:00
return max ( FONT_HEIGHT_NORMAL , ( byte ) 14 ) ;
2008-04-12 22:19:34 +00:00
}
2008-08-08 15:49:16 +00:00
2008-08-06 07:10:40 +00:00
bool Selectable ( ) const
{
return true ;
}
2008-04-12 22:19:34 +00:00
2009-03-21 19:31:47 +00:00
void Draw ( int left , int right , int top , int bottom , bool sel , int bg_colour ) const
2008-04-12 22:19:34 +00:00
{
2009-11-18 12:45:20 +00:00
bool rtl = _dynlang . text_dir = = TD_RTL ;
DrawSprite ( SPR_VEH_BUS_SIDE_VIEW , PALETTE_RECOLOUR_START + this - > result , rtl ? right - 16 : left + 16 , top + 7 ) ;
DrawString ( rtl ? left + 2 : left + 32 , rtl ? right - 32 : right - 2 , top + max ( 0 , 13 - FONT_HEIGHT_NORMAL ) , this - > String ( ) , sel ? TC_WHITE : TC_BLACK ) ;
2008-04-12 22:19:34 +00:00
}
} ;
2009-03-28 04:14:02 +00:00
/** Widgets of the select company livery window. */
enum SelectCompanyLiveryWindowWidgets {
SCLW_WIDGET_CAPTION ,
SCLW_WIDGET_CLASS_GENERAL ,
SCLW_WIDGET_CLASS_RAIL ,
SCLW_WIDGET_CLASS_ROAD ,
SCLW_WIDGET_CLASS_SHIP ,
SCLW_WIDGET_CLASS_AIRCRAFT ,
SCLW_WIDGET_SPACER_DROPDOWN ,
SCLW_WIDGET_PRI_COL_DROPDOWN ,
SCLW_WIDGET_SEC_COL_DROPDOWN ,
SCLW_WIDGET_MATRIX ,
} ;
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 :
2009-11-18 12:45:20 +00:00
static const uint TEXT_INDENT = 15 ; ///< Number of pixels to indent the text in each column in the #SCLW_WIDGET_MATRIX to make room for the (coloured) rectangles.
2008-05-14 22:52:12 +00:00
uint32 sel ;
LiveryClass livery_class ;
void ShowColourDropDownMenu ( uint32 widget )
{
uint32 used_colours = 0 ;
const Livery * livery ;
LiveryScheme scheme ;
2008-09-30 20:39:50 +00:00
/* Disallow other company colours for the primary colour */
if ( HasBit ( this - > sel , LS_DEFAULT ) & & widget = = SCLW_WIDGET_PRI_COL_DROPDOWN ) {
const Company * c ;
FOR_ALL_COMPANIES ( c ) {
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
2008-05-14 22:52:12 +00:00
/* Get the first selected livery to use as the default dropdown item */
for ( scheme = LS_BEGIN ; scheme < LS_END ; scheme + + ) {
if ( HasBit ( this - > sel , scheme ) ) break ;
}
if ( scheme = = LS_END ) scheme = LS_DEFAULT ;
2009-05-16 23:34:14 +00:00
livery = & Company : : Get ( ( CompanyID ) this - > window_number ) - > livery [ scheme ] ;
2006-09-15 12:27:00 +00:00
2008-05-14 22:52:12 +00:00
DropDownList * list = new DropDownList ( ) ;
for ( uint i = 0 ; i < lengthof ( _colour_dropdown ) ; i + + ) {
list - > push_back ( new DropDownListColourItem ( i , HasBit ( used_colours , i ) ) ) ;
}
2008-04-12 22:19:34 +00:00
2008-09-30 20:39:50 +00:00
ShowDropDownList ( this , list , widget = = SCLW_WIDGET_PRI_COL_DROPDOWN ? livery - > colour1 : livery - > colour2 , widget ) ;
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 :
2009-11-14 15:34:21 +00:00
SelectCompanyLiveryWindow ( const WindowDesc * desc , CompanyID company ) : Window ( )
2008-05-14 22:52:12 +00:00
{
this - > livery_class = LC_OTHER ;
this - > sel = 1 ;
2009-11-14 15:34:21 +00:00
this - > InitNested ( desc , company ) ;
this - > owner = company ;
2008-09-30 20:39:50 +00:00
this - > LowerWidget ( SCLW_WIDGET_CLASS_GENERAL ) ;
2008-05-14 22:52:12 +00:00
}
2006-10-03 20:16:20 +00:00
2009-11-22 18:28:14 +00:00
virtual void UpdateWidgetSize ( int widget , Dimension * size , const Dimension & padding , Dimension * fill , Dimension * resize )
2008-05-14 22:52:12 +00:00
{
2009-11-14 15:34:21 +00:00
/* Number of liveries in each class, used to determine the height of the livery matrix widget. */
static const byte livery_height [ ] = {
1 ,
13 ,
4 ,
2 ,
3 ,
} ;
2006-09-15 12:27:00 +00:00
2009-11-14 15:34:21 +00:00
switch ( widget ) {
case SCLW_WIDGET_SPACER_DROPDOWN : {
/* 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 ) ) ;
}
size - > width = max ( size - > width , TEXT_INDENT + d . width + WD_FRAMERECT_RIGHT ) ;
break ;
}
case SCLW_WIDGET_MATRIX :
size - > height = livery_height [ this - > livery_class ] * ( 4 + FONT_HEIGHT_NORMAL ) ;
this - > GetWidget < NWidgetCore > ( SCLW_WIDGET_MATRIX ) - > widget_data = ( livery_height [ this - > livery_class ] < < MAT_ROW_START ) | ( 1 < < MAT_COL_START ) ;
break ;
case SCLW_WIDGET_SEC_COL_DROPDOWN :
2009-11-22 13:01:07 +00:00
if ( ! _loaded_newgrf_features . has_2CC ) {
size - > width = 0 ;
break ;
}
2010-07-29 14:26:28 +00:00
/* FALL THROUGH */
2009-11-22 13:01:07 +00:00
case SCLW_WIDGET_PRI_COL_DROPDOWN : {
for ( const StringID * id = _colour_dropdown ; id ! = endof ( _colour_dropdown ) ; id + + ) {
size - > width = max ( size - > width , GetStringBoundingBox ( * id ) . width + 34 ) ;
}
2010-08-01 18:53:30 +00:00
break ;
}
2009-11-14 15:34:21 +00:00
}
}
virtual void OnPaint ( )
{
2008-05-14 22:52:12 +00:00
/* Disable dropdown controls if no scheme is selected */
2008-09-30 20:39:50 +00:00
this - > SetWidgetDisabledState ( SCLW_WIDGET_PRI_COL_DROPDOWN , this - > sel = = 0 ) ;
this - > SetWidgetDisabledState ( SCLW_WIDGET_SEC_COL_DROPDOWN , this - > sel = = 0 ) ;
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
2009-11-14 15:34:21 +00:00
virtual void SetStringParameters ( int widget ) const
{
switch ( widget ) {
case SCLW_WIDGET_PRI_COL_DROPDOWN :
case SCLW_WIDGET_SEC_COL_DROPDOWN : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
LiveryScheme scheme = LS_DEFAULT ;
2006-09-15 12:27:00 +00:00
2009-11-14 15:34:21 +00:00
if ( this - > sel ! = 0 ) {
for ( scheme = LS_BEGIN ; scheme < LS_END ; scheme + + ) {
if ( HasBit ( this - > sel , scheme ) ) break ;
}
if ( scheme = = LS_END ) scheme = LS_DEFAULT ;
}
SetDParam ( 0 , STR_COLOUR_DARK_BLUE + ( ( widget = = SCLW_WIDGET_PRI_COL_DROPDOWN ) ? c - > livery [ scheme ] . colour1 : c - > livery [ scheme ] . colour2 ) ) ;
break ;
}
}
}
2006-09-15 12:27:00 +00:00
2009-11-14 15:34:21 +00:00
virtual void DrawWidget ( const Rect & r , int widget ) const
{
if ( widget ! = SCLW_WIDGET_MATRIX ) return ;
2009-11-18 12:45:20 +00:00
bool rtl = _dynlang . text_dir = = TD_RTL ;
2009-11-14 15:34:21 +00:00
/* Horizontal coordinates of scheme name column. */
const NWidgetBase * nwi = this - > GetWidget < NWidgetBase > ( SCLW_WIDGET_SPACER_DROPDOWN ) ;
int sch_left = nwi - > pos_x ;
int sch_right = sch_left + nwi - > current_x - 1 ;
/* Horizontal coordinates of first dropdown. */
nwi = this - > GetWidget < NWidgetBase > ( SCLW_WIDGET_PRI_COL_DROPDOWN ) ;
int pri_left = nwi - > pos_x ;
int pri_right = pri_left + nwi - > current_x - 1 ;
/* Horizontal coordinates of second dropdown. */
nwi = this - > GetWidget < NWidgetBase > ( SCLW_WIDGET_SEC_COL_DROPDOWN ) ;
int sec_left = nwi - > pos_x ;
int sec_right = sec_left + nwi - > current_x - 1 ;
2009-11-18 12:45:20 +00:00
int text_left = ( rtl ? ( uint ) WD_FRAMERECT_LEFT : TEXT_INDENT ) ;
int text_right = ( rtl ? TEXT_INDENT : ( uint ) WD_FRAMERECT_RIGHT ) ;
2009-11-14 15:34:21 +00:00
int y = r . top + 3 ;
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
2008-05-14 22:52:12 +00:00
if ( _livery_class [ scheme ] = = this - > livery_class ) {
bool sel = HasBit ( this - > sel , scheme ) ! = 0 ;
2004-09-11 09:40:19 +00:00
2009-11-14 15:34:21 +00:00
/* Optional check box + scheme name. */
2008-05-14 22:52:12 +00:00
if ( scheme ! = LS_DEFAULT ) {
2009-11-18 12:45:20 +00:00
DrawSprite ( c - > livery [ scheme ] . in_use ? SPR_BOX_CHECKED : SPR_BOX_EMPTY , PAL_NONE , ( rtl ? sch_right - TEXT_INDENT + WD_FRAMERECT_RIGHT : sch_left ) + WD_FRAMERECT_LEFT , y ) ;
2008-05-14 22:52:12 +00:00
}
2009-11-18 12:45:20 +00:00
DrawString ( sch_left + text_left , sch_right - text_right , y , STR_LIVERY_DEFAULT + scheme , sel ? TC_WHITE : TC_BLACK ) ;
2004-08-09 17:04:08 +00:00
2009-11-14 15:34:21 +00:00
/* Text below the first dropdown. */
2009-11-18 12:45:20 +00:00
DrawSprite ( SPR_SQUARE , GENERAL_SPRITE_COLOUR ( c - > livery [ scheme ] . colour1 ) , ( rtl ? pri_right - TEXT_INDENT + WD_FRAMERECT_RIGHT : pri_left ) + WD_FRAMERECT_LEFT , y ) ;
DrawString ( pri_left + text_left , pri_right - text_right , y , STR_COLOUR_DARK_BLUE + c - > livery [ scheme ] . colour1 , sel ? TC_WHITE : TC_GOLD ) ;
2006-09-15 12:27:00 +00:00
2009-11-14 15:34:21 +00:00
/* Text below the second dropdown. */
if ( sec_right > sec_left ) { // Second dropdown has non-zero size.
2009-11-18 12:45:20 +00:00
DrawSprite ( SPR_SQUARE , GENERAL_SPRITE_COLOUR ( c - > livery [ scheme ] . colour2 ) , ( rtl ? sec_right - TEXT_INDENT + WD_FRAMERECT_RIGHT : sec_left ) + WD_FRAMERECT_LEFT , y ) ;
DrawString ( sec_left + text_left , sec_right - text_right , y , STR_COLOUR_DARK_BLUE + c - > livery [ scheme ] . colour2 , sel ? TC_WHITE : TC_GOLD ) ;
2006-09-15 12:27:00 +00:00
}
2008-05-14 22:52:12 +00:00
2009-11-14 15:34:21 +00:00
y + = 4 + FONT_HEIGHT_NORMAL ;
2004-08-09 17:04:08 +00:00
}
}
2008-05-14 22:52:12 +00:00
}
2004-09-11 09:40:19 +00:00
2010-01-30 18:34:48 +00:00
virtual void OnClick ( Point pt , int widget , int click_count )
2008-05-14 22:52:12 +00:00
{
switch ( widget ) {
/* Livery Class buttons */
2008-09-30 20:39:50 +00:00
case SCLW_WIDGET_CLASS_GENERAL :
case SCLW_WIDGET_CLASS_RAIL :
case SCLW_WIDGET_CLASS_ROAD :
case SCLW_WIDGET_CLASS_SHIP :
2009-11-14 15:34:21 +00:00
case SCLW_WIDGET_CLASS_AIRCRAFT :
2008-09-30 20:39:50 +00:00
this - > RaiseWidget ( this - > livery_class + SCLW_WIDGET_CLASS_GENERAL ) ;
this - > livery_class = ( LiveryClass ) ( widget - SCLW_WIDGET_CLASS_GENERAL ) ;
this - > LowerWidget ( this - > livery_class + SCLW_WIDGET_CLASS_GENERAL ) ;
2008-05-14 22:52:12 +00:00
/* Select the first item in the list */
2009-11-14 15:34:21 +00:00
this - > sel = 0 ;
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
2008-05-14 22:52:12 +00:00
if ( _livery_class [ scheme ] = = this - > livery_class ) {
this - > sel = 1 < < scheme ;
break ;
2006-09-15 12:27:00 +00:00
}
}
2009-11-14 15:34:21 +00:00
this - > ReInit ( ) ;
2008-05-14 22:52:12 +00:00
break ;
2006-09-15 12:27:00 +00:00
2009-03-15 00:32:18 +00:00
case SCLW_WIDGET_PRI_COL_DROPDOWN : // First colour dropdown
2008-09-30 20:39:50 +00:00
ShowColourDropDownMenu ( SCLW_WIDGET_PRI_COL_DROPDOWN ) ;
2008-05-14 22:52:12 +00:00
break ;
2006-09-15 12:27:00 +00:00
2009-03-15 00:32:18 +00:00
case SCLW_WIDGET_SEC_COL_DROPDOWN : // Second colour dropdown
2008-09-30 20:39:50 +00:00
ShowColourDropDownMenu ( SCLW_WIDGET_SEC_COL_DROPDOWN ) ;
2008-05-14 22:52:12 +00:00
break ;
2006-09-15 12:27:00 +00:00
2008-09-30 20:39:50 +00:00
case SCLW_WIDGET_MATRIX : {
2009-11-18 12:45:20 +00:00
const NWidgetBase * wid = this - > GetWidget < NWidgetBase > ( SCLW_WIDGET_MATRIX ) ;
LiveryScheme j = ( LiveryScheme ) ( ( pt . y - wid - > pos_y ) / ( 4 + FONT_HEIGHT_NORMAL ) ) ;
2006-09-15 12:27:00 +00:00
2009-11-14 15:34:21 +00:00
for ( LiveryScheme scheme = LS_BEGIN ; scheme < = j ; scheme + + ) {
2008-05-14 22:52:12 +00:00
if ( _livery_class [ scheme ] ! = this - > livery_class ) j + + ;
if ( scheme > = LS_END ) return ;
}
if ( j > = LS_END ) return ;
2006-09-15 12:27:00 +00:00
2008-05-14 22:52:12 +00:00
/* If clicking on the left edge, toggle using the livery */
2009-11-18 12:45:20 +00:00
if ( _dynlang . text_dir = = TD_RTL ? pt . x - wid - > pos_x > wid - > current_x - TEXT_INDENT : pt . x - wid - > pos_x < TEXT_INDENT ) {
2009-05-16 23:34:14 +00:00
DoCommandP ( 0 , j | ( 2 < < 8 ) , ! Company : : Get ( ( CompanyID ) this - > window_number ) - > livery [ j ] . in_use , CMD_SET_COMPANY_COLOUR ) ;
2008-05-14 22:52:12 +00:00
}
2006-09-15 12:27:00 +00:00
2008-05-14 22:52:12 +00:00
if ( _ctrl_pressed ) {
ToggleBit ( this - > sel , j ) ;
} else {
this - > sel = 1 < < j ;
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
2008-05-14 22:52:12 +00:00
virtual void OnDropdownSelect ( int widget , int index )
{
for ( LiveryScheme scheme = LS_DEFAULT ; scheme < LS_END ; scheme + + ) {
if ( HasBit ( this - > sel , scheme ) ) {
2009-02-09 02:57:15 +00:00
DoCommandP ( 0 , scheme | ( widget = = SCLW_WIDGET_PRI_COL_DROPDOWN ? 0 : 256 ) , index , CMD_SET_COMPANY_COLOUR ) ;
2006-09-15 12:27:00 +00:00
}
2004-08-09 17:04:08 +00:00
}
}
2008-05-14 23:02:05 +00:00
virtual void OnInvalidateData ( int data = 0 )
{
2009-11-14 15:34:21 +00:00
this - > ReInit ( ) ;
2008-05-14 23:02:05 +00:00
}
2008-05-14 22:52:12 +00:00
} ;
2004-08-09 17:04:08 +00:00
2009-03-28 04:14:02 +00:00
static const NWidgetPart _nested_select_company_livery_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2009-11-22 11:20:12 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , SCLW_WIDGET_CAPTION ) , SetDataTip ( STR_LIVERY_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_IMGBTN , COLOUR_GREY , SCLW_WIDGET_CLASS_GENERAL ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_COMPANY_GENERAL , STR_LIVERY_GENERAL_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , SCLW_WIDGET_CLASS_RAIL ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_TRAINLIST , STR_LIVERY_TRAIN_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , SCLW_WIDGET_CLASS_ROAD ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_TRUCKLIST , STR_LIVERY_ROAD_VEHICLE_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , SCLW_WIDGET_CLASS_SHIP ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_SHIPLIST , STR_LIVERY_SHIP_TOOLTIP ) ,
NWidget ( WWT_IMGBTN , COLOUR_GREY , SCLW_WIDGET_CLASS_AIRCRAFT ) , SetMinimalSize ( 22 , 22 ) , SetFill ( 0 , 1 ) , SetDataTip ( SPR_IMG_AIRPLANESLIST , STR_LIVERY_AIRCRAFT_TOOLTIP ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) , SetMinimalSize ( 90 , 22 ) , SetFill ( 1 , 1 ) , EndContainer ( ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY , SCLW_WIDGET_SPACER_DROPDOWN ) , SetMinimalSize ( 150 , 12 ) , SetFill ( 1 , 1 ) , EndContainer ( ) ,
NWidget ( WWT_DROPDOWN , COLOUR_GREY , SCLW_WIDGET_PRI_COL_DROPDOWN ) , SetMinimalSize ( 125 , 12 ) , SetFill ( 0 , 1 ) , SetDataTip ( STR_BLACK_STRING , STR_LIVERY_PRIMARY_TOOLTIP ) ,
NWidget ( WWT_DROPDOWN , COLOUR_GREY , SCLW_WIDGET_SEC_COL_DROPDOWN ) , SetMinimalSize ( 125 , 12 ) , SetFill ( 0 , 1 ) ,
2009-11-14 15:37:33 +00:00
SetDataTip ( STR_BLACK_STRING , STR_LIVERY_SECONDARY_TOOLTIP ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_MATRIX , COLOUR_GREY , SCLW_WIDGET_MATRIX ) , SetMinimalSize ( 275 , 15 ) , SetFill ( 1 , 0 ) , SetDataTip ( ( 1 < < MAT_ROW_START ) | ( 1 < < MAT_COL_START ) , STR_LIVERY_PANEL_TOOLTIP ) ,
2004-08-09 17:04:08 +00:00
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _select_company_livery_desc (
2009-11-28 14:42:35 +00:00
WDP_AUTO , 0 , 0 ,
2009-02-09 02:57:15 +00:00
WC_COMPANY_COLOUR , WC_NONE ,
2009-11-24 17:28:29 +00:00
0 ,
2009-11-15 10:26:01 +00:00
_nested_select_company_livery_widgets , lengthof ( _nested_select_company_livery_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +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
2007-03-02 01:17:11 +00:00
* @ param x x - position to draw the face
* @ param y y - position to draw the face
*/
2009-02-09 02:57:15 +00:00
void DrawCompanyManagerFace ( CompanyManagerFace cmf , int colour , int x , int y )
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
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 ;
2009-03-15 00:32:18 +00:00
case CMFV_LIPS : // FALL THROUGH
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-03-28 04:14:02 +00:00
/**
* Names of the widgets . Keep them in the same order as in the widget array .
* Do not change the order of the widgets from SCMFW_WIDGET_HAS_MOUSTACHE_EARRING to SCMFW_WIDGET_GLASSES_R ,
* this order is needed for the WE_CLICK event of DrawFaceStringLabel ( ) .
*/
enum SelectCompanyManagerFaceWidgets {
SCMFW_WIDGET_CAPTION ,
SCMFW_WIDGET_TOGGLE_LARGE_SMALL ,
SCMFW_WIDGET_SELECT_FACE ,
SCMFW_WIDGET_CANCEL ,
SCMFW_WIDGET_ACCEPT ,
2009-11-28 13:47:57 +00:00
SCMFW_WIDGET_MALE , ///< Male button in the simple view.
SCMFW_WIDGET_FEMALE , ///< Female button in the simple view.
SCMFW_WIDGET_MALE2 , ///< Male button in the advanced view.
SCMFW_WIDGET_FEMALE2 , ///< Female button in the advanced view.
2009-11-28 13:45:03 +00:00
SCMFW_WIDGET_SEL_LOADSAVE , ///< Selection to display the load/save/number buttons in the advanced view.
SCMFW_WIDGET_SEL_MALEFEMALE , ///< Selection to display the male/female buttons in the simple view.
SCMFW_WIDGET_SEL_PARTS , ///< Selection to display the buttons for setting each part of the face in the advanced view.
2009-03-28 04:14:02 +00:00
SCMFW_WIDGET_RANDOM_NEW_FACE ,
SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON ,
2009-03-28 15:20:03 +00:00
SCMFM_WIDGET_FACE ,
2009-03-28 04:14:02 +00:00
SCMFW_WIDGET_LOAD ,
SCMFW_WIDGET_FACECODE ,
SCMFW_WIDGET_SAVE ,
2009-11-28 13:34:49 +00:00
SCMFW_WIDGET_HAS_MOUSTACHE_EARRING_TEXT ,
SCMFW_WIDGET_TIE_EARRING_TEXT ,
SCMFW_WIDGET_LIPS_MOUSTACHE_TEXT ,
SCMFW_WIDGET_HAS_GLASSES_TEXT ,
SCMFW_WIDGET_HAIR_TEXT ,
SCMFW_WIDGET_EYEBROWS_TEXT ,
SCMFW_WIDGET_EYECOLOUR_TEXT ,
SCMFW_WIDGET_GLASSES_TEXT ,
SCMFW_WIDGET_NOSE_TEXT ,
SCMFW_WIDGET_CHIN_TEXT ,
SCMFW_WIDGET_JACKET_TEXT ,
SCMFW_WIDGET_COLLAR_TEXT ,
2009-03-28 04:14:02 +00:00
SCMFW_WIDGET_ETHNICITY_EUR ,
SCMFW_WIDGET_ETHNICITY_AFR ,
SCMFW_WIDGET_HAS_MOUSTACHE_EARRING ,
SCMFW_WIDGET_HAS_GLASSES ,
SCMFW_WIDGET_EYECOLOUR_L ,
SCMFW_WIDGET_EYECOLOUR ,
SCMFW_WIDGET_EYECOLOUR_R ,
SCMFW_WIDGET_CHIN_L ,
SCMFW_WIDGET_CHIN ,
SCMFW_WIDGET_CHIN_R ,
SCMFW_WIDGET_EYEBROWS_L ,
SCMFW_WIDGET_EYEBROWS ,
SCMFW_WIDGET_EYEBROWS_R ,
SCMFW_WIDGET_LIPS_MOUSTACHE_L ,
SCMFW_WIDGET_LIPS_MOUSTACHE ,
SCMFW_WIDGET_LIPS_MOUSTACHE_R ,
SCMFW_WIDGET_NOSE_L ,
SCMFW_WIDGET_NOSE ,
SCMFW_WIDGET_NOSE_R ,
SCMFW_WIDGET_HAIR_L ,
SCMFW_WIDGET_HAIR ,
SCMFW_WIDGET_HAIR_R ,
SCMFW_WIDGET_JACKET_L ,
SCMFW_WIDGET_JACKET ,
SCMFW_WIDGET_JACKET_R ,
SCMFW_WIDGET_COLLAR_L ,
SCMFW_WIDGET_COLLAR ,
SCMFW_WIDGET_COLLAR_R ,
SCMFW_WIDGET_TIE_EARRING_L ,
SCMFW_WIDGET_TIE_EARRING ,
SCMFW_WIDGET_TIE_EARRING_R ,
SCMFW_WIDGET_GLASSES_L ,
SCMFW_WIDGET_GLASSES ,
SCMFW_WIDGET_GLASSES_R ,
} ;
2009-11-28 13:47:57 +00:00
/** Nested widget description for the company manager face selection dialog */
2009-03-28 04:14:02 +00:00
static const NWidgetPart _nested_select_company_manager_face_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2009-11-22 11:20:12 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , SCMFW_WIDGET_CAPTION ) , SetDataTip ( STR_FACE_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2009-11-22 12:18:26 +00:00
NWidget ( WWT_IMGBTN , COLOUR_GREY , SCMFW_WIDGET_TOGGLE_LARGE_SMALL ) , SetDataTip ( SPR_LARGE_SMALL_WINDOW , STR_FACE_ADVANCED_TOOLTIP ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , SCMFW_WIDGET_SELECT_FACE ) ,
2009-11-28 13:40:41 +00:00
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 2 , 2 , 2 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_SPACER ) , SetFill ( 1 , 0 ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , SCMFM_WIDGET_FACE ) , SetMinimalSize ( 92 , 119 ) ,
NWidget ( NWID_SPACER ) , SetFill ( 1 , 0 ) ,
2009-11-22 12:18:26 +00:00
EndContainer ( ) ,
2009-11-28 13:40:41 +00:00
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) ,
2009-11-28 13:43:53 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_RANDOM_NEW_FACE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_NEW_FACE_BUTTON , STR_FACE_NEW_FACE_TOOLTIP ) ,
2009-11-28 13:47:57 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , SCMFW_WIDGET_SEL_LOADSAVE ) , // Load/number/save buttons under the portrait in the advanced view.
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 5 ) , SetFill ( 0 , 1 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_LOAD ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_LOAD , STR_FACE_LOAD_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_FACECODE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_FACECODE , STR_FACE_FACECODE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_SAVE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_SAVE , STR_FACE_SAVE_TOOLTIP ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 5 ) , SetFill ( 0 , 1 ) ,
EndContainer ( ) ,
EndContainer ( ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
2009-11-28 13:40:41 +00:00
NWidget ( NWID_VERTICAL ) ,
2009-11-28 13:43:53 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_ADVANCED , STR_FACE_ADVANCED_TOOLTIP ) ,
2009-11-28 13:40:41 +00:00
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) ,
2009-11-28 13:45:03 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , SCMFW_WIDGET_SEL_MALEFEMALE ) , // Simple male/female face setting.
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , SCMFW_WIDGET_MALE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_MALE_BUTTON , STR_FACE_MALE_TOOLTIP ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , SCMFW_WIDGET_FEMALE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_FEMALE_BUTTON , STR_FACE_FEMALE_TOOLTIP ) ,
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , SCMFW_WIDGET_SEL_PARTS ) , // Advanced face parts setting.
NWidget ( NWID_VERTICAL ) ,
2009-11-28 13:47:57 +00:00
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) ,
2009-11-28 13:45:03 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2009-11-28 13:47:57 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_GREY , SCMFW_WIDGET_MALE2 ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_MALE_BUTTON , STR_FACE_MALE_TOOLTIP ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , SCMFW_WIDGET_FEMALE2 ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_FEMALE_BUTTON , STR_FACE_FEMALE_TOOLTIP ) ,
2009-11-28 13:45:03 +00:00
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) ,
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , SCMFW_WIDGET_ETHNICITY_EUR ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_EUROPEAN , STR_FACE_SELECT_EUROPEAN ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , SCMFW_WIDGET_ETHNICITY_AFR ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_FACE_AFRICAN , STR_FACE_SELECT_AFRICAN ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 4 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_HAS_MOUSTACHE_EARRING_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_HAS_MOUSTACHE_EARRING ) , SetDataTip ( STR_EMPTY , STR_FACE_MOUSTACHE_EARRING_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_HAS_GLASSES_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_HAS_GLASSES ) , SetDataTip ( STR_EMPTY , STR_FACE_GLASSES_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_HAIR_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_HAIR_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_HAIR_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_HAIR ) , SetDataTip ( STR_EMPTY , STR_FACE_HAIR_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_HAIR_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_HAIR_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_EYEBROWS_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_EYEBROWS_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_EYEBROWS_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_EYEBROWS ) , SetDataTip ( STR_EMPTY , STR_FACE_EYEBROWS_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_EYEBROWS_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_EYEBROWS_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_EYECOLOUR_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_EYECOLOUR_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_EYECOLOUR_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_EYECOLOUR ) , SetDataTip ( STR_EMPTY , STR_FACE_EYECOLOUR_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_EYECOLOUR_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_EYECOLOUR_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_GLASSES_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_GLASSES_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_GLASSES_TOOLTIP_2 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_GLASSES ) , SetDataTip ( STR_EMPTY , STR_FACE_GLASSES_TOOLTIP_2 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_GLASSES_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_GLASSES_TOOLTIP_2 ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_NOSE_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_NOSE_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_NOSE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_NOSE ) , SetDataTip ( STR_EMPTY , STR_FACE_NOSE_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_NOSE_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_NOSE_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_LIPS_MOUSTACHE_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_LIPS_MOUSTACHE_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_LIPS_MOUSTACHE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_LIPS_MOUSTACHE ) , SetDataTip ( STR_EMPTY , STR_FACE_LIPS_MOUSTACHE_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_LIPS_MOUSTACHE_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_LIPS_MOUSTACHE_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_CHIN_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_CHIN_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_CHIN_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_CHIN ) , SetDataTip ( STR_EMPTY , STR_FACE_CHIN_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_CHIN_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_CHIN_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_JACKET_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_JACKET_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_JACKET_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_JACKET ) , SetDataTip ( STR_EMPTY , STR_FACE_JACKET_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_JACKET_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_JACKET_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_COLLAR_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_COLLAR_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_COLLAR_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_COLLAR ) , SetDataTip ( STR_EMPTY , STR_FACE_COLLAR_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_COLLAR_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_COLLAR_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , SCMFW_WIDGET_TIE_EARRING_TEXT ) , SetFill ( 1 , 0 ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_TIE_EARRING_L ) , SetDataTip ( AWV_DECREASE , STR_FACE_TIE_EARRING_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_TIE_EARRING ) , SetDataTip ( STR_EMPTY , STR_FACE_TIE_EARRING_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , SCMFW_WIDGET_TIE_EARRING_R ) , SetDataTip ( AWV_INCREASE , STR_FACE_TIE_EARRING_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
EndContainer ( ) ,
2009-11-28 13:40:41 +00:00
EndContainer ( ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2009-11-28 13:40:41 +00:00
NWidget ( NWID_SPACER ) , SetMinimalSize ( 0 , 2 ) ,
2009-03-28 04:14:02 +00:00
EndContainer ( ) ,
2009-11-28 13:40:41 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_CANCEL ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_BUTTON_CANCEL , STR_FACE_CANCEL_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , SCMFW_WIDGET_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.
static const StringID PART_TEXTS_IS_FEMALE [ ] ; ///< Strings depending on #is_female, used to describe parts (2 entries for a part).
static const StringID PART_TEXTS [ ] ; ///< Fixed strings to describe parts of the face.
2009-11-28 13:34:49 +00:00
2008-05-13 01:05:39 +00:00
/**
* Draw dynamic a label to the left of the button and a value in the button
*
* @ param widget_index index of this widget in the window
* @ param val the value which will be draw
* @ param is_bool_widget is it a bool button
*/
2009-11-28 13:34:49 +00:00
void DrawFaceStringLabel ( byte widget_index , uint8 val , bool is_bool_widget ) const
2008-05-13 01:05:39 +00:00
{
2009-11-28 13:34:49 +00:00
StringID str ;
2009-11-15 09:46:40 +00:00
const NWidgetCore * nwi_widget = this - > GetWidget < NWidgetCore > ( widget_index ) ;
2009-11-28 13:34:49 +00:00
if ( ! nwi_widget - > IsDisabled ( ) ) {
2008-05-13 01:05:39 +00:00
if ( is_bool_widget ) {
/* if it a bool button write yes or no */
str = ( val ! = 0 ) ? STR_FACE_YES : STR_FACE_NO ;
} else {
/* else write the value + 1 */
SetDParam ( 0 , val + 1 ) ;
str = STR_JUST_INT ;
}
/* Draw the value/bool in white (0xC). If the button clicked adds 1px to x and y text coordinates (IsWindowWidgetLowered()). */
2009-11-15 09:46:40 +00:00
DrawString ( nwi_widget - > pos_x + nwi_widget - > IsLowered ( ) , nwi_widget - > pos_x + nwi_widget - > current_x - 1 - nwi_widget - > IsLowered ( ) ,
2010-07-02 13:53:05 +00:00
nwi_widget - > pos_y + 1 + nwi_widget - > IsLowered ( ) , str , TC_WHITE , SA_HOR_CENTER ) ;
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
2007-10-15 19:59:27 +00:00
}
2008-05-13 01:05:39 +00:00
public :
2009-11-28 13:47:57 +00:00
SelectCompanyManagerFaceWindow ( const WindowDesc * desc , Window * parent ) : Window ( )
2008-05-13 01:05:39 +00:00
{
2009-11-28 13:47:57 +00:00
this - > advanced = false ;
2009-11-28 13:45:03 +00:00
this - > CreateNestedTree ( desc ) ;
this - > SelectDisplayPlanes ( this - > advanced ) ;
this - > FinishInitNested ( desc , 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
/**
* Select planes to display to the user with the # NWID_SELECTION widgets # SCMFW_WIDGET_SEL_LOADSAVE , # SCMFW_WIDGET_SEL_MALEFEMALE , and # SCMFW_WIDGET_SEL_PARTS .
2009-11-28 13:45:03 +00:00
* @ param advanced Display advanced face management window .
*/
void SelectDisplayPlanes ( bool advanced )
{
2009-12-22 20:43:25 +00:00
this - > GetWidget < NWidgetStacked > ( SCMFW_WIDGET_SEL_LOADSAVE ) - > SetDisplayedPlane ( advanced ? 0 : SZSP_NONE ) ;
this - > GetWidget < NWidgetStacked > ( SCMFW_WIDGET_SEL_PARTS ) - > SetDisplayedPlane ( advanced ? 0 : SZSP_NONE ) ;
this - > GetWidget < NWidgetStacked > ( SCMFW_WIDGET_SEL_MALEFEMALE ) - > SetDisplayedPlane ( advanced ? SZSP_NONE : 0 ) ;
2009-11-28 13:47:57 +00:00
this - > GetWidget < NWidgetCore > ( SCMFW_WIDGET_RANDOM_NEW_FACE ) - > widget_data = advanced ? STR_MAPGEN_RANDOM : STR_FACE_NEW_FACE_BUTTON ;
NWidgetCore * wi = this - > GetWidget < NWidgetCore > ( SCMFW_WIDGET_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
}
}
2009-11-29 21:16:37 +00:00
virtual void OnInit ( )
{
/* Size of the boolean yes/no button. */
Dimension yesno_dim = maxdim ( GetStringBoundingBox ( STR_FACE_YES ) , GetStringBoundingBox ( STR_FACE_NO ) ) ;
yesno_dim . width + = WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT ;
yesno_dim . height + = WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM ;
/* 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 ) ) ;
}
uint arrows_width = GetSpriteSize ( SPR_ARROW_LEFT ) . width + GetSpriteSize ( SPR_ARROW_RIGHT ) . width + 2 * ( WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT ) ;
number_dim . width + = WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + arrows_width ;
number_dim . height + = WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM ;
/* Compute width of both buttons. */
yesno_dim . width = max ( yesno_dim . width , number_dim . width ) ;
number_dim . width = yesno_dim . width - arrows_width ;
this - > yesno_dim = yesno_dim ;
this - > number_dim = number_dim ;
}
2009-11-28 13:34:49 +00:00
virtual void UpdateWidgetSize ( int widget , Dimension * size , const Dimension & padding , Dimension * fill , Dimension * resize )
{
switch ( widget ) {
case SCMFW_WIDGET_HAS_MOUSTACHE_EARRING_TEXT :
case SCMFW_WIDGET_TIE_EARRING_TEXT : {
int offset = ( widget - SCMFW_WIDGET_HAS_MOUSTACHE_EARRING_TEXT ) * 2 ;
* size = maxdim ( GetStringBoundingBox ( PART_TEXTS_IS_FEMALE [ offset ] ) , GetStringBoundingBox ( PART_TEXTS_IS_FEMALE [ offset + 1 ] ) ) ;
size - > width + = WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT ;
size - > height + = WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM ;
break ;
}
case SCMFW_WIDGET_LIPS_MOUSTACHE_TEXT :
* size = maxdim ( GetStringBoundingBox ( STR_FACE_LIPS ) , GetStringBoundingBox ( STR_FACE_MOUSTACHE ) ) ;
size - > width + = WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT ;
size - > height + = WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM ;
break ;
case SCMFW_WIDGET_HAS_GLASSES_TEXT :
case SCMFW_WIDGET_HAIR_TEXT :
case SCMFW_WIDGET_EYEBROWS_TEXT :
case SCMFW_WIDGET_EYECOLOUR_TEXT :
case SCMFW_WIDGET_GLASSES_TEXT :
case SCMFW_WIDGET_NOSE_TEXT :
case SCMFW_WIDGET_CHIN_TEXT :
case SCMFW_WIDGET_JACKET_TEXT :
case SCMFW_WIDGET_COLLAR_TEXT :
* size = GetStringBoundingBox ( PART_TEXTS [ widget - SCMFW_WIDGET_HAS_GLASSES_TEXT ] ) ;
size - > width + = WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT ;
size - > height + = WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM ;
break ;
2009-11-28 13:42:35 +00:00
case SCMFW_WIDGET_HAS_MOUSTACHE_EARRING :
case SCMFW_WIDGET_HAS_GLASSES :
2009-11-29 21:16:37 +00:00
* size = this - > yesno_dim ;
break ;
2009-11-28 13:42:35 +00:00
case SCMFW_WIDGET_EYECOLOUR :
case SCMFW_WIDGET_CHIN :
case SCMFW_WIDGET_EYEBROWS :
case SCMFW_WIDGET_LIPS_MOUSTACHE :
case SCMFW_WIDGET_NOSE :
case SCMFW_WIDGET_HAIR :
case SCMFW_WIDGET_JACKET :
case SCMFW_WIDGET_COLLAR :
case SCMFW_WIDGET_TIE_EARRING :
2009-11-29 21:16:37 +00:00
case SCMFW_WIDGET_GLASSES :
* size = this - > number_dim ;
2009-11-28 13:42:35 +00:00
break ;
2009-11-28 13:34:49 +00:00
}
}
2008-05-13 01:05:39 +00:00
virtual void OnPaint ( )
{
/* lower the non-selected gender button */
2009-11-28 13:47:57 +00:00
this - > SetWidgetsLoweredState ( ! this - > is_female , SCMFW_WIDGET_MALE , SCMFW_WIDGET_MALE2 , WIDGET_LIST_END ) ;
this - > SetWidgetsLoweredState ( this - > is_female , SCMFW_WIDGET_FEMALE , SCMFW_WIDGET_FEMALE2 , WIDGET_LIST_END ) ;
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 */
this - > SetWidgetLoweredState ( SCMFW_WIDGET_ETHNICITY_EUR , ! HasBit ( this - > ge , ETHNICITY_BLACK ) ) ;
this - > SetWidgetLoweredState ( SCMFW_WIDGET_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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_EYECOLOUR , SCMFW_WIDGET_EYECOLOUR_L , SCMFW_WIDGET_EYECOLOUR_R , WIDGET_LIST_END ) ;
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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_CHIN , SCMFW_WIDGET_CHIN_L , SCMFW_WIDGET_CHIN_R , WIDGET_LIST_END ) ;
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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_EYEBROWS , SCMFW_WIDGET_EYEBROWS_L , SCMFW_WIDGET_EYEBROWS_R , WIDGET_LIST_END ) ;
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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_LIPS_MOUSTACHE , SCMFW_WIDGET_LIPS_MOUSTACHE_L , SCMFW_WIDGET_LIPS_MOUSTACHE_R , WIDGET_LIST_END ) ;
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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_NOSE , SCMFW_WIDGET_NOSE_L , SCMFW_WIDGET_NOSE_R , WIDGET_LIST_END ) ;
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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_HAIR , SCMFW_WIDGET_HAIR_L , SCMFW_WIDGET_HAIR_R , WIDGET_LIST_END ) ;
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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_JACKET , SCMFW_WIDGET_JACKET_L , SCMFW_WIDGET_JACKET_R , WIDGET_LIST_END ) ;
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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_COLLAR , SCMFW_WIDGET_COLLAR_L , SCMFW_WIDGET_COLLAR_R , WIDGET_LIST_END ) ;
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 ) ,
SCMFW_WIDGET_TIE_EARRING , SCMFW_WIDGET_TIE_EARRING_L , SCMFW_WIDGET_TIE_EARRING_R , WIDGET_LIST_END ) ;
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 ,
2008-09-30 20:39:50 +00:00
SCMFW_WIDGET_GLASSES , SCMFW_WIDGET_GLASSES_L , SCMFW_WIDGET_GLASSES_R , WIDGET_LIST_END ) ;
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
2009-11-15 09:46:40 +00:00
virtual void DrawWidget ( const Rect & r , int widget ) const
{
switch ( widget ) {
2009-11-28 13:34:49 +00:00
case SCMFW_WIDGET_HAS_MOUSTACHE_EARRING_TEXT :
case SCMFW_WIDGET_TIE_EARRING_TEXT : {
StringID str = PART_TEXTS_IS_FEMALE [ ( widget - SCMFW_WIDGET_HAS_MOUSTACHE_EARRING_TEXT ) * 2 + this - > is_female ] ;
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , r . top + WD_FRAMERECT_TOP , str , TC_GOLD , SA_RIGHT ) ;
break ;
}
case SCMFW_WIDGET_LIPS_MOUSTACHE_TEXT :
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , r . top + WD_FRAMERECT_TOP , ( this - > is_moust_male ) ? STR_FACE_MOUSTACHE : STR_FACE_LIPS , TC_GOLD , SA_RIGHT ) ;
break ;
case SCMFW_WIDGET_HAS_GLASSES_TEXT :
case SCMFW_WIDGET_HAIR_TEXT :
case SCMFW_WIDGET_EYEBROWS_TEXT :
case SCMFW_WIDGET_EYECOLOUR_TEXT :
case SCMFW_WIDGET_GLASSES_TEXT :
case SCMFW_WIDGET_NOSE_TEXT :
case SCMFW_WIDGET_CHIN_TEXT :
case SCMFW_WIDGET_JACKET_TEXT :
case SCMFW_WIDGET_COLLAR_TEXT :
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , r . top + WD_FRAMERECT_TOP , PART_TEXTS [ widget - SCMFW_WIDGET_HAS_GLASSES_TEXT ] , TC_GOLD , SA_RIGHT ) ;
break ;
2009-11-15 09:46:40 +00:00
case SCMFW_WIDGET_HAS_MOUSTACHE_EARRING :
2010-02-10 21:06:05 +00:00
if ( this - > is_female ) { // Only for female faces
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_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
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_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
2009-11-15 09:46:40 +00:00
case SCMFW_WIDGET_TIE_EARRING :
2010-02-10 21:06:05 +00:00
if ( this - > is_female ) { // Only for female faces
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_TIE_EARRING , GetCompanyManagerFaceBits ( this - > face , CMFV_TIE_EARRING , this - > ge ) , false ) ;
2010-02-10 21:06:05 +00:00
} else { // Only for male faces
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_TIE_EARRING , GetCompanyManagerFaceBits ( this - > face , CMFV_TIE_EARRING , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
}
break ;
case SCMFW_WIDGET_LIPS_MOUSTACHE :
2010-02-10 21:06:05 +00:00
if ( this - > is_moust_male ) { // Only for male faces with moustache
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_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
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_LIPS_MOUSTACHE , GetCompanyManagerFaceBits ( this - > face , CMFV_LIPS , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
}
break ;
case SCMFW_WIDGET_HAS_GLASSES :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_HAS_GLASSES , GetCompanyManagerFaceBits ( this - > face , CMFV_HAS_GLASSES , this - > ge ) , true ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFW_WIDGET_HAIR :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_HAIR , GetCompanyManagerFaceBits ( this - > face , CMFV_HAIR , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFW_WIDGET_EYEBROWS :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_EYEBROWS , GetCompanyManagerFaceBits ( this - > face , CMFV_EYEBROWS , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFW_WIDGET_EYECOLOUR :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_EYECOLOUR , GetCompanyManagerFaceBits ( this - > face , CMFV_EYE_COLOUR , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFW_WIDGET_GLASSES :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_GLASSES , GetCompanyManagerFaceBits ( this - > face , CMFV_GLASSES , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFW_WIDGET_NOSE :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_NOSE , GetCompanyManagerFaceBits ( this - > face , CMFV_NOSE , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFW_WIDGET_CHIN :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_CHIN , GetCompanyManagerFaceBits ( this - > face , CMFV_CHIN , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFW_WIDGET_JACKET :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_JACKET , GetCompanyManagerFaceBits ( this - > face , CMFV_JACKET , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFW_WIDGET_COLLAR :
2009-11-28 13:34:49 +00:00
this - > DrawFaceStringLabel ( SCMFW_WIDGET_COLLAR , GetCompanyManagerFaceBits ( this - > face , CMFV_COLLAR , this - > ge ) , false ) ;
2009-11-15 09:46:40 +00:00
break ;
case SCMFM_WIDGET_FACE :
DrawCompanyManagerFace ( this - > face , Company : : Get ( ( CompanyID ) this - > window_number ) - > colour , r . left , r . top ) ;
break ;
}
2004-08-09 17:04:08 +00:00
}
2008-05-13 01:05:39 +00:00
2010-01-30 18:34:48 +00:00
virtual void OnClick ( Point pt , int widget , int click_count )
2008-05-13 01:05:39 +00:00
{
switch ( widget ) {
/* Toggle size, advanced/simple face selection */
2008-09-30 20:39:50 +00:00
case SCMFW_WIDGET_TOGGLE_LARGE_SMALL :
2009-11-28 13:47:57 +00:00
case SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON :
this - > advanced = ! this - > advanced ;
this - > SelectDisplayPlanes ( this - > advanced ) ;
this - > ReInit ( ) ;
break ;
2008-05-13 01:05:39 +00:00
/* OK button */
2008-09-30 20:39:50 +00:00
case SCMFW_WIDGET_ACCEPT :
2008-12-28 14:37:19 +00:00
DoCommandP ( 0 , 0 , this - > face , CMD_SET_COMPANY_MANAGER_FACE ) ;
2010-07-29 14:26:28 +00:00
/* FALL THROUGH */
2008-05-13 01:05:39 +00:00
/* Cancel button */
2008-09-30 20:39:50 +00:00
case SCMFW_WIDGET_CANCEL :
2008-05-13 01:05:39 +00:00
delete this ;
break ;
/* Load button */
2008-09-30 20:39:50 +00:00
case SCMFW_WIDGET_LOAD :
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 */
case SCMFW_WIDGET_FACECODE :
2008-05-13 01:05:39 +00:00
SetDParam ( 0 , this - > face ) ;
2008-09-15 16:29:40 +00:00
ShowQueryString ( STR_JUST_INT , STR_FACE_FACECODE_CAPTION , 10 + 1 , 0 , this , CS_NUMERAL , QSF_NONE ) ;
2008-05-13 01:05:39 +00:00
break ;
/* Save button */
2008-09-30 20:39:50 +00:00
case SCMFW_WIDGET_SAVE :
_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 */
2008-09-30 20:39:50 +00:00
case SCMFW_WIDGET_MALE :
case SCMFW_WIDGET_FEMALE :
2009-11-28 13:47:57 +00:00
case SCMFW_WIDGET_MALE2 :
case SCMFW_WIDGET_FEMALE2 :
SetCompanyManagerFaceBits ( this - > face , CMFV_GENDER , this - > ge , ( widget = = SCMFW_WIDGET_FEMALE | | widget = = SCMFW_WIDGET_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 */
2008-09-30 20:39:50 +00:00
case SCMFW_WIDGET_RANDOM_NEW_FACE :
RandomCompanyManagerFaceBits ( this - > face , this - > ge , this - > advanced ) ;
2008-05-13 01:05:39 +00:00
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
break ;
/* Toggle ethnicity (european/african) button */
2008-09-30 20:39:50 +00:00
case SCMFW_WIDGET_ETHNICITY_EUR :
case SCMFW_WIDGET_ETHNICITY_AFR :
SetCompanyManagerFaceBits ( this - > face , CMFV_ETHNICITY , this - > ge , widget - SCMFW_WIDGET_ETHNICITY_EUR ) ;
ScaleAllCompanyManagerFaceBits ( this - > face ) ;
2008-05-13 01:05:39 +00:00
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
break ;
default :
2009-11-15 09:46:40 +00:00
/* Here all buttons from SCMFW_WIDGET_HAS_MOUSTACHE_EARRING to SCMFW_WIDGET_GLASSES_R are handled.
* 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 */
2009-11-28 13:47:57 +00:00
if ( widget > = SCMFW_WIDGET_HAS_MOUSTACHE_EARRING & & widget < = SCMFW_WIDGET_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
2008-09-30 20:39:50 +00:00
if ( widget < SCMFW_WIDGET_EYECOLOUR_L ) { // Bool buttons
switch ( widget - SCMFW_WIDGET_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
2008-09-30 20:39:50 +00:00
switch ( ( widget - SCMFW_WIDGET_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 */
2008-09-30 20:39:50 +00:00
IncreaseCompanyManagerFaceBits ( this - > face , cmfv , this - > ge , ( ( ( widget - SCMFW_WIDGET_EYECOLOUR_L ) % 3 ) ! = 0 ) ? 1 : - 1 ) ;
2008-05-13 01:05:39 +00:00
}
this - > UpdateData ( ) ;
this - > SetDirty ( ) ;
}
break ;
}
}
virtual void OnQueryTextFinished ( char * str )
{
if ( str = = NULL ) 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 ) ) {
this - > face = strtoul ( str , NULL , 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:34:49 +00:00
/** Both text values of parts of the face that depend on the #is_female boolean value. */
const StringID SelectCompanyManagerFaceWindow : : PART_TEXTS_IS_FEMALE [ ] = {
STR_FACE_MOUSTACHE , STR_FACE_EARRING , // SCMFW_WIDGET_HAS_MOUSTACHE_EARRING_TEXT
STR_FACE_TIE , STR_FACE_EARRING , // SCMFW_WIDGET_TIE_EARRING_TEXT
} ;
/** Textual names for parts of the face. */
const StringID SelectCompanyManagerFaceWindow : : PART_TEXTS [ ] = {
STR_FACE_GLASSES , // SCMFW_WIDGET_HAS_GLASSES_TEXT
STR_FACE_HAIR , // SCMFW_WIDGET_HAIR_TEXT
STR_FACE_EYEBROWS , // SCMFW_WIDGET_EYEBROWS_TEXT
STR_FACE_EYECOLOUR , // SCMFW_WIDGET_EYECOLOUR_TEXT
STR_FACE_GLASSES , // SCMFW_WIDGET_GLASSES_TEXT
STR_FACE_NOSE , // SCMFW_WIDGET_NOSE_TEXT
STR_FACE_CHIN , // SCMFW_WIDGET_CHIN_TEXT
STR_FACE_JACKET , // SCMFW_WIDGET_JACKET_TEXT
STR_FACE_COLLAR , // SCMFW_WIDGET_COLLAR_TEXT
} ;
2009-11-28 13:47:57 +00:00
/** Company manager face selection window description */
2009-03-15 15:12:06 +00:00
static const WindowDesc _select_company_manager_face_desc (
2009-11-28 15:01:49 +00:00
WDP_AUTO , 0 , 0 ,
2008-09-30 20:39:50 +00:00
WC_COMPANY_MANAGER_FACE , WC_NONE ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS | WDF_CONSTRUCTION ,
2009-11-15 10:26:01 +00:00
_nested_select_company_manager_face_widgets , lengthof ( _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
* @ param adv simple or advanced face selection window
2008-04-09 02:02:39 +00:00
* @ param top previous top position of the window
* @ param left previous left position of the 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
}
2009-05-03 08:13:14 +00:00
/** Names of the widgets of the #CompanyWindow. Keep them in the same order as in the widget array */
2008-09-30 20:39:50 +00:00
enum CompanyWindowWidgets {
CW_WIDGET_CAPTION ,
2009-11-20 17:36:46 +00:00
2008-09-30 20:39:50 +00:00
CW_WIDGET_FACE ,
2009-11-20 17:36:46 +00:00
CW_WIDGET_FACE_TITLE ,
CW_WIDGET_DESC_INAUGURATION ,
CW_WIDGET_DESC_COLOUR_SCHEME ,
CW_WIDGET_DESC_COLOUR_SCHEME_EXAMPLE ,
CW_WIDGET_DESC_VEHICLE ,
CW_WIDGET_DESC_VEHICLE_COUNTS ,
CW_WIDGET_DESC_COMPANY_VALUE ,
CW_WIDGET_DESC_OWNERS ,
2009-11-15 13:31:27 +00:00
CW_WIDGET_SELECT_BUTTONS , ///< Selection widget for the button bar.
2008-09-30 20:39:50 +00:00
CW_WIDGET_NEW_FACE ,
2009-02-09 02:57:15 +00:00
CW_WIDGET_COLOUR_SCHEME ,
2008-09-30 20:39:50 +00:00
CW_WIDGET_PRESIDENT_NAME ,
CW_WIDGET_COMPANY_NAME ,
CW_WIDGET_BUY_SHARE ,
CW_WIDGET_SELL_SHARE ,
2009-11-20 17:36:46 +00:00
CW_WIDGET_SELECT_VIEW_BUILD_HQ ,
CW_WIDGET_VIEW_HQ ,
CW_WIDGET_BUILD_HQ ,
CW_WIDGET_SELECT_RELOCATE , ///< View/hide the 'Relocate HQ' button.
CW_WIDGET_RELOCATE_HQ ,
2010-01-04 23:00:19 +00:00
CW_WIDGET_HAS_PASSWORD , ///< Draw a lock when the company has a password
2009-11-15 13:31:27 +00:00
CW_WIDGET_SELECT_MULTIPLAYER , ///< Multiplayer selection panel.
2008-09-30 20:39:50 +00:00
CW_WIDGET_COMPANY_PASSWORD ,
2009-01-23 22:18:06 +00:00
CW_WIDGET_COMPANY_JOIN ,
2006-12-07 13:00:41 +00:00
} ;
2006-10-05 23:24:16 +00:00
2009-05-03 08:27:12 +00:00
static const NWidgetPart _nested_company_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2009-05-03 08:27:12 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , CW_WIDGET_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 ) ,
2009-11-20 17:36:46 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 4 , 6 , 4 ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 4 , 2 , 4 ) ,
2009-12-28 13:04:18 +00:00
NWidget ( WWT_EMPTY , INVALID_COLOUR , CW_WIDGET_FACE ) , SetMinimalSize ( 92 , 119 ) , SetFill ( 1 , 0 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_EMPTY , INVALID_COLOUR , CW_WIDGET_FACE_TITLE ) , SetFill ( 1 , 1 ) , SetMinimalTextLines ( 2 , 0 ) ,
2009-11-15 13:31:27 +00:00
EndContainer ( ) ,
2009-11-20 17:36:46 +00:00
NWidget ( NWID_VERTICAL ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 4 , 5 , 5 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , CW_WIDGET_DESC_INAUGURATION ) , SetDataTip ( STR_COMPANY_VIEW_INAUGURATED_TITLE , STR_NULL ) , SetFill ( 1 , 0 ) ,
2009-11-20 17:36:46 +00:00
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , 5 , 0 ) ,
NWidget ( WWT_LABEL , COLOUR_GREY , CW_WIDGET_DESC_COLOUR_SCHEME ) , SetDataTip ( STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE , STR_NULL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_EMPTY , INVALID_COLOUR , CW_WIDGET_DESC_COLOUR_SCHEME_EXAMPLE ) , SetMinimalSize ( 30 , 0 ) , SetFill ( 0 , 1 ) ,
NWidget ( NWID_SPACER ) , SetFill ( 1 , 0 ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 0 , 4 , 0 ) ,
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_TEXT , COLOUR_GREY , CW_WIDGET_DESC_VEHICLE ) , SetDataTip ( STR_COMPANY_VIEW_VEHICLES_TITLE , STR_NULL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , CW_WIDGET_DESC_VEHICLE_COUNTS ) , SetMinimalTextLines ( 4 , 0 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 1 , 0 ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 4 , 2 , 4 ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , CW_WIDGET_SELECT_VIEW_BUILD_HQ ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_VIEW_HQ ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_VIEW_HQ_BUTTON , STR_COMPANY_VIEW_VIEW_HQ_TOOLTIP ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , CW_WIDGET_BUILD_HQ ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_BUILD_HQ_BUTTON , STR_COMPANY_VIEW_BUILD_HQ_TOOLTIP ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , CW_WIDGET_SELECT_RELOCATE ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_GREY , CW_WIDGET_RELOCATE_HQ ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_RELOCATE_HQ , STR_COMPANY_VIEW_RELOCATE_COMPANY_HEADQUARTERS ) ,
2009-11-20 17:36:46 +00:00
NWidget ( NWID_SPACER ) , SetMinimalSize ( 90 , 0 ) ,
EndContainer ( ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_TEXT , COLOUR_GREY , CW_WIDGET_DESC_COMPANY_VALUE ) , SetDataTip ( STR_COMPANY_VIEW_COMPANY_VALUE , STR_NULL ) , SetFill ( 1 , 0 ) ,
2009-11-20 17:36:46 +00:00
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 5 , 5 , 4 ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , CW_WIDGET_DESC_OWNERS ) , SetMinimalTextLines ( 3 , 0 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
2009-11-20 17:36:46 +00:00
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 4 , 2 , 4 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( NWID_SPACER ) , SetMinimalSize ( 90 , 0 ) , SetFill ( 0 , 1 ) ,
2009-11-20 17:36:46 +00:00
/* Multi player buttons. */
2010-01-04 23:00:19 +00:00
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_EMPTY , COLOUR_GREY , CW_WIDGET_HAS_PASSWORD ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , CW_WIDGET_SELECT_MULTIPLAYER ) ,
NWidget ( NWID_SPACER ) , SetFill ( 1 , 0 ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_COMPANY_PASSWORD ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_PASSWORD , STR_COMPANY_VIEW_PASSWORD_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_COMPANY_JOIN ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_JOIN , STR_COMPANY_VIEW_JOIN_TOOLTIP ) ,
EndContainer ( ) ,
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. */
2009-11-15 13:31:27 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , CW_WIDGET_SELECT_BUTTONS ) ,
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_NEW_FACE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_NEW_FACE_BUTTON , STR_COMPANY_VIEW_NEW_FACE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_COLOUR_SCHEME ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_COLOUR_SCHEME_BUTTON , STR_COMPANY_VIEW_COLOUR_SCHEME_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_PRESIDENT_NAME ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_PRESIDENT_NAME_BUTTON , STR_COMPANY_VIEW_PRESIDENT_NAME_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_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 ( ) ,
2009-11-15 13:31:27 +00:00
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_BUY_SHARE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_BUY_SHARE_BUTTON , STR_COMPANY_VIEW_BUY_SHARE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , CW_WIDGET_SELL_SHARE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_SELL_SHARE_BUTTON , STR_COMPANY_VIEW_SELL_SHARE_TOOLTIP ) ,
2009-05-03 08:27:12 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
} ;
2007-11-21 13:50:36 +00:00
2008-09-30 20:39:50 +00:00
int GetAmountOwnedBy ( const Company * c , Owner owner )
2004-08-09 17:04:08 +00:00
{
2008-09-30 20:39:50 +00:00
return ( c - > share_owners [ 0 ] = = owner ) +
( c - > share_owners [ 1 ] = = owner ) +
( c - > share_owners [ 2 ] = = owner ) +
( c - > share_owners [ 3 ] = = owner ) ;
2004-08-09 17:04:08 +00:00
}
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
{
2008-09-30 20:39:50 +00:00
CompanyWindowWidgets 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 {
/* Display planes of the #CW_WIDGET_SELECT_MULTIPLAYER selection widget. */
CWP_MP_EMPTY = 0 , ///< Do not display any multiplayer button.
CWP_MP_C_PWD , ///< Display the company password button.
CWP_MP_C_JOIN , ///< Display the join company button.
2009-11-20 17:36:46 +00:00
/* Display planes of the #CW_WIDGET_SELECT_VIEW_BUILD_HQ selection widget. */
CWP_VB_VIEW = 0 , ///< Display the view button
CWP_VB_BUILD , ///< Display the build button
2009-11-15 13:31:27 +00:00
/* Display planes of the #CW_WIDGET_SELECT_RELOCATE selection widget. */
CWP_RELOCATE_SHOW = 0 , ///< Show the relocate HQ button.
CWP_RELOCATE_HIDE , ///< Hide the relocate HQ button.
/* Display planes of the #CW_WIDGET_SELECT_BUTTONS selection widget. */
CWP_BUTTONS_LOCAL = 0 , ///< Buttons of the local company.
CWP_BUTTONS_OTHER , ///< Buttons of the other companies.
} ;
CompanyWindow ( const WindowDesc * desc , WindowNumber window_number ) : Window ( )
2008-05-15 14:12:22 +00:00
{
2009-11-15 13:31:27 +00:00
this - > InitNested ( desc , window_number ) ;
2009-02-09 02:33:10 +00:00
this - > owner = ( Owner ) this - > window_number ;
2008-05-15 14:12:22 +00:00
}
2004-08-09 17:04:08 +00:00
2008-05-15 14:12:22 +00:00
virtual void OnPaint ( )
{
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 ( ) ) {
/* Button bar selection. */
int plane = local ? CWP_BUTTONS_LOCAL : CWP_BUTTONS_OTHER ;
NWidgetStacked * wi = this - > GetWidget < NWidgetStacked > ( CW_WIDGET_SELECT_BUTTONS ) ;
if ( plane ! = wi - > shown_plane ) {
wi - > SetDisplayedPlane ( plane ) ;
this - > SetDirty ( ) ;
return ;
}
2009-11-15 13:31:27 +00:00
2009-12-21 16:24:29 +00:00
/* Build HQ button handling. */
plane = ( local & & c - > location_of_HQ = = INVALID_TILE ) ? CWP_VB_BUILD : CWP_VB_VIEW ;
wi = this - > GetWidget < NWidgetStacked > ( CW_WIDGET_SELECT_VIEW_BUILD_HQ ) ;
if ( plane ! = wi - > shown_plane ) {
wi - > SetDisplayedPlane ( plane ) ;
this - > SetDirty ( ) ;
return ;
}
2009-11-20 17:36:46 +00:00
2009-12-21 16:24:29 +00:00
this - > SetWidgetDisabledState ( CW_WIDGET_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. */
plane = ( ! local | | c - > location_of_HQ = = INVALID_TILE ) ? CWP_RELOCATE_HIDE : CWP_RELOCATE_SHOW ;
wi = this - > GetWidget < NWidgetStacked > ( CW_WIDGET_SELECT_RELOCATE ) ;
if ( plane ! = wi - > shown_plane ) {
wi - > SetDisplayedPlane ( plane ) ;
this - > SetDirty ( ) ;
return ;
}
2009-11-15 13:31:27 +00:00
2009-12-21 16:24:29 +00:00
/* Multiplayer buttons. */
plane = ( ( ! _networking ) ? CWP_MP_EMPTY : ( local ? CWP_MP_C_PWD : CWP_MP_C_JOIN ) ) ;
wi = this - > GetWidget < NWidgetStacked > ( CW_WIDGET_SELECT_MULTIPLAYER ) ;
if ( plane ! = wi - > shown_plane ) {
wi - > SetDisplayedPlane ( plane ) ;
this - > SetDirty ( ) ;
return ;
}
this - > SetWidgetDisabledState ( CW_WIDGET_COMPANY_JOIN , c - > is_ai ) ;
2009-11-15 13:31:27 +00:00
}
2008-05-15 14:12:22 +00:00
if ( ! local ) {
2008-05-29 15:13:28 +00:00
if ( _settings_game . economy . allow_shares ) { // Shares are allowed
2008-05-15 14:12:22 +00:00
/* If all shares are owned by someone (none by nobody), disable buy button */
2008-09-30 20:39:50 +00:00
this - > SetWidgetDisabledState ( CW_WIDGET_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 ) | |
2008-05-15 14:12:22 +00:00
/* Spectators cannot do anything of course */
2008-09-30 20:39:50 +00:00
_local_company = = COMPANY_SPECTATOR ) ;
2008-05-15 14:12:22 +00:00
2008-09-30 20:39:50 +00:00
/* If the company doesn't own any shares, disable sell button */
this - > SetWidgetDisabledState ( CW_WIDGET_SELL_SHARE , ( GetAmountOwnedBy ( c , _local_company ) = = 0 ) | |
2008-05-15 14:12:22 +00:00
/* Spectators cannot do anything of course */
2008-09-30 20:39:50 +00:00
_local_company = = COMPANY_SPECTATOR ) ;
2008-05-15 14:12:22 +00:00
} else { // Shares are not allowed, disable buy/sell buttons
2008-09-30 20:39:50 +00:00
this - > DisableWidget ( CW_WIDGET_BUY_SHARE ) ;
this - > DisableWidget ( CW_WIDGET_SELL_SHARE ) ;
2008-05-15 14:12:22 +00:00
}
}
2004-08-09 17:04:08 +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
2009-11-22 18:28:14 +00:00
virtual void UpdateWidgetSize ( int widget , Dimension * size , const Dimension & padding , Dimension * fill , Dimension * resize )
2009-11-20 17:36:46 +00:00
{
switch ( widget ) {
case CW_WIDGET_DESC_COMPANY_VALUE :
SetDParam ( 0 , INT64_MAX ) ; // Arguably the maximum company value
size - > width = GetStringBoundingBox ( STR_COMPANY_VIEW_COMPANY_VALUE ) . width ;
break ;
case CW_WIDGET_DESC_VEHICLE_COUNTS :
SetDParam ( 0 , 5000 ) ; // Maximum number of vehicles
for ( uint i = 0 ; i < lengthof ( _company_view_vehicle_count_strings ) ; i + + ) {
size - > width = max ( size - > width , GetStringBoundingBox ( _company_view_vehicle_count_strings [ i ] ) . width ) ;
}
break ;
case CW_WIDGET_DESC_OWNERS : {
const Company * c2 ;
FOR_ALL_COMPANIES ( c2 ) {
SetDParam ( 0 , 25 ) ;
SetDParam ( 1 , c2 - > index ) ;
size - > width = max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_SHARES_OWNED_BY ) . width ) ;
}
2010-08-01 18:53:30 +00:00
break ;
}
2010-01-04 23:00:19 +00:00
# ifdef ENABLE_NETWORK
case CW_WIDGET_HAS_PASSWORD :
* size = maxdim ( * size , GetSpriteSize ( SPR_LOCK ) ) ;
break ;
# endif /* ENABLE_NETWORK */
2009-01-23 23:56:56 +00:00
}
2009-11-20 17:36:46 +00:00
}
2009-01-23 23:56:56 +00:00
2009-11-20 17:36:46 +00:00
virtual void DrawWidget ( const Rect & r , int widget ) const
{
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
switch ( widget ) {
case CW_WIDGET_FACE :
DrawCompanyManagerFace ( c - > face , c - > colour , r . left , r . top ) ;
break ;
2007-11-21 13:50:36 +00:00
2009-11-20 17:36:46 +00:00
case CW_WIDGET_FACE_TITLE :
SetDParam ( 0 , c - > index ) ;
DrawStringMultiLine ( r . left , r . right , r . top , r . bottom , STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE , TC_FROMSTRING , SA_CENTER ) ;
break ;
2007-11-21 13:50:36 +00:00
2009-11-20 17:36:46 +00:00
case CW_WIDGET_DESC_COLOUR_SCHEME_EXAMPLE :
DrawSprite ( SPR_VEH_BUS_SW_VIEW , COMPANY_SPRITE_COLOUR ( c - > index ) , ( r . left + r . right ) / 2 , r . top + FONT_HEIGHT_NORMAL / 10 ) ;
break ;
2004-08-09 17:04:08 +00:00
2009-11-20 17:36:46 +00:00
case CW_WIDGET_DESC_VEHICLE_COUNTS : {
2010-08-06 19:56:14 +00:00
uint amounts [ 4 ] ;
CountCompanyVehicles ( ( CompanyID ) this - > window_number , amounts ) ;
2004-08-09 17:04:08 +00:00
2010-08-06 19:56:14 +00:00
int y = r . top ;
2009-11-20 17:36:46 +00:00
if ( amounts [ 0 ] + amounts [ 1 ] + amounts [ 2 ] + amounts [ 3 ] = = 0 ) {
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_VEHICLES_NONE ) ;
} else {
assert_compile ( lengthof ( amounts ) = = lengthof ( _company_view_vehicle_count_strings ) ) ;
2004-08-09 17:04:08 +00:00
2009-11-20 17:36:46 +00:00
for ( uint i = 0 ; i < lengthof ( amounts ) ; i + + ) {
if ( amounts [ i ] ! = 0 ) {
SetDParam ( 0 , amounts [ i ] ) ;
DrawString ( r . left , r . right , y , _company_view_vehicle_count_strings [ i ] ) ;
y + = FONT_HEIGHT_NORMAL ;
}
}
}
2010-08-01 18:53:30 +00:00
break ;
}
2009-11-20 17:36:46 +00:00
case CW_WIDGET_DESC_OWNERS : {
const Company * c2 ;
uint y = r . top ;
FOR_ALL_COMPANIES ( c2 ) {
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 ) ;
y + = FONT_HEIGHT_NORMAL ;
}
}
2010-08-01 18:53:30 +00:00
break ;
}
2009-11-20 17:36:46 +00:00
# ifdef ENABLE_NETWORK
2010-01-04 23:00:19 +00:00
case CW_WIDGET_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 ;
# endif /* ENABLE_NETWORK */
}
2008-05-15 14:12:22 +00:00
}
2004-08-09 17:04:08 +00:00
2009-11-15 13:31:27 +00:00
virtual void SetStringParameters ( int widget ) const
{
2009-11-20 17:36:46 +00:00
switch ( widget ) {
case CW_WIDGET_CAPTION :
SetDParam ( 0 , ( CompanyID ) this - > window_number ) ;
SetDParam ( 1 , ( CompanyID ) this - > window_number ) ;
break ;
case CW_WIDGET_DESC_INAUGURATION :
SetDParam ( 0 , Company : : Get ( ( CompanyID ) this - > window_number ) - > inaugurated_year ) ;
break ;
case CW_WIDGET_DESC_COMPANY_VALUE :
SetDParam ( 0 , CalculateCompanyValue ( Company : : Get ( ( CompanyID ) this - > window_number ) ) ) ;
break ;
2009-11-15 13:31:27 +00:00
}
}
2010-01-30 18:34:48 +00:00
virtual void OnClick ( Point pt , int widget , int click_count )
2008-05-15 14:12:22 +00:00
{
switch ( widget ) {
2009-11-28 13:47:57 +00:00
case CW_WIDGET_NEW_FACE : DoSelectCompanyManagerFace ( this ) ; break ;
2004-08-09 17:04:08 +00:00
2009-02-09 02:57:15 +00:00
case CW_WIDGET_COLOUR_SCHEME :
if ( BringWindowToFrontById ( WC_COMPANY_COLOUR , this - > window_number ) ) break ;
2008-09-30 20:39:50 +00:00
new SelectCompanyLiveryWindow ( & _select_company_livery_desc , ( CompanyID ) this - > window_number ) ;
2008-05-15 14:12:22 +00:00
break ;
2008-09-30 20:39:50 +00:00
case CW_WIDGET_PRESIDENT_NAME :
this - > query_widget = CW_WIDGET_PRESIDENT_NAME ;
2008-05-15 14:12:22 +00:00
SetDParam ( 0 , this - > window_number ) ;
2009-08-05 17:59:21 +00:00
ShowQueryString ( STR_PRESIDENT_NAME , STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION , MAX_LENGTH_PRESIDENT_NAME_BYTES , MAX_LENGTH_PRESIDENT_NAME_PIXELS , this , CS_ALPHANUMERAL , QSF_ENABLE_DEFAULT ) ;
2008-05-15 14:12:22 +00:00
break ;
2008-09-30 20:39:50 +00:00
case CW_WIDGET_COMPANY_NAME :
this - > query_widget = CW_WIDGET_COMPANY_NAME ;
2008-05-15 14:12:22 +00:00
SetDParam ( 0 , this - > window_number ) ;
2009-08-05 17:59:21 +00:00
ShowQueryString ( STR_COMPANY_NAME , STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION , MAX_LENGTH_COMPANY_NAME_BYTES , MAX_LENGTH_COMPANY_NAME_PIXELS , this , CS_ALPHANUMERAL , QSF_ENABLE_DEFAULT ) ;
2008-05-15 14:12:22 +00:00
break ;
2005-01-06 18:54:13 +00:00
2009-11-20 17:36:46 +00:00
case CW_WIDGET_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 ) {
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
2009-11-20 17:36:46 +00:00
case CW_WIDGET_BUILD_HQ :
if ( ( byte ) this - > window_number ! = _local_company ) return ;
SetObjectToPlaceWnd ( SPR_CURSOR_HQ , PAL_NONE , HT_RECT , this ) ;
SetTileSelectSize ( 2 , 2 ) ;
this - > LowerWidget ( CW_WIDGET_BUILD_HQ ) ;
this - > SetWidgetDirty ( CW_WIDGET_BUILD_HQ ) ;
break ;
2008-09-30 20:39:50 +00:00
case CW_WIDGET_RELOCATE_HQ :
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 ) ;
2008-09-30 20:39:50 +00:00
this - > LowerWidget ( CW_WIDGET_RELOCATE_HQ ) ;
2009-09-13 19:15:59 +00:00
this - > SetWidgetDirty ( CW_WIDGET_RELOCATE_HQ ) ;
2008-05-15 14:12:22 +00:00
break ;
2004-08-09 17:04:08 +00:00
2008-09-30 20:39:50 +00:00
case CW_WIDGET_BUY_SHARE :
2009-04-21 23:40:56 +00:00
DoCommandP ( 0 , this - > window_number , 0 , CMD_BUY_SHARE_IN_COMPANY | CMD_MSG ( STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS ) ) ;
2008-05-15 14:12:22 +00:00
break ;
2004-09-01 21:54:12 +00:00
2008-09-30 20:39:50 +00:00
case CW_WIDGET_SELL_SHARE :
2009-04-21 23:40:56 +00:00
DoCommandP ( 0 , this - > window_number , 0 , CMD_SELL_SHARE_IN_COMPANY | CMD_MSG ( STR_ERROR_CAN_T_SELL_25_SHARE_IN ) ) ;
2008-05-15 14:12:22 +00:00
break ;
2004-08-09 17:04:08 +00:00
2007-12-02 14:48:26 +00:00
# ifdef ENABLE_NETWORK
2008-09-30 20:39:50 +00:00
case CW_WIDGET_COMPANY_PASSWORD :
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
case CW_WIDGET_COMPANY_JOIN : {
this - > query_widget = CW_WIDGET_COMPANY_JOIN ;
CompanyID company = ( CompanyID ) this - > window_number ;
if ( _network_server ) {
NetworkServerDoMove ( CLIENT_ID_SERVER , company ) ;
MarkWholeScreenDirty ( ) ;
} else if ( NetworkCompanyIsPassworded ( company ) ) {
/* ask for the password */
2010-06-23 00:11:11 +00:00
ShowQueryString ( STR_EMPTY , STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION , NETWORK_PASSWORD_LENGTH , 180 , this , CS_ALPHANUMERAL , QSF_NONE ) ;
2009-01-23 22:18:06 +00:00
} else {
/* just send the join command */
NetworkClientRequestMove ( company ) ;
}
break ;
}
2007-12-02 14:48:26 +00:00
# endif /* ENABLE_NETWORK */
2008-05-15 14:12:22 +00:00
}
}
2004-08-09 17:04:08 +00:00
2008-05-29 11:47:56 +00:00
virtual void OnHundredthTick ( )
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
2008-05-15 14:12:22 +00:00
virtual void OnPlaceObject ( Point pt , TileIndex tile )
{
2010-08-08 10:59:30 +00:00
if ( DoCommandP ( tile , OBJECT_HQ , 0 , CMD_BUILD_OBJECT | CMD_MSG ( STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS ) ) ) {
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
2008-05-15 14:12:22 +00:00
virtual void OnPlaceObjectAbort ( )
{
this - > RaiseButtons ( ) ;
}
2004-12-22 23:24:53 +00:00
2008-05-15 14:12:22 +00:00
virtual void OnQueryTextFinished ( char * str )
{
2008-09-15 19:02:50 +00:00
if ( str = = NULL ) 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
2008-09-30 20:39:50 +00:00
case CW_WIDGET_PRESIDENT_NAME :
2009-04-21 23:40:56 +00:00
DoCommandP ( 0 , 0 , 0 , CMD_RENAME_PRESIDENT | CMD_MSG ( STR_ERROR_CAN_T_CHANGE_PRESIDENT ) , NULL , str ) ;
2008-05-15 14:12:22 +00:00
break ;
2004-08-09 17:04:08 +00:00
2008-09-30 20:39:50 +00:00
case CW_WIDGET_COMPANY_NAME :
2009-04-21 23:40:56 +00:00
DoCommandP ( 0 , 0 , 0 , CMD_RENAME_COMPANY | CMD_MSG ( STR_ERROR_CAN_T_CHANGE_COMPANY_NAME ) , NULL , str ) ;
2008-05-15 14:12:22 +00:00
break ;
2009-01-23 22:18:06 +00:00
# ifdef ENABLE_NETWORK
case CW_WIDGET_COMPANY_JOIN :
NetworkClientRequestMove ( ( CompanyID ) this - > window_number , str ) ;
break ;
# endif /* ENABLE_NETWORK */
2008-05-15 14:12:22 +00:00
}
}
} ;
2004-08-09 17:04:08 +00:00
2009-03-15 15:12:06 +00:00
static const WindowDesc _company_desc (
2009-11-28 15:01:49 +00:00
WDP_AUTO , 0 , 0 ,
2007-02-01 15:49:12 +00:00
WC_COMPANY , WC_NONE ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS ,
2009-11-15 10:26:01 +00:00
_nested_company_widgets , lengthof ( _nested_company_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
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
}
2009-05-03 08:13:14 +00:00
/** widget numbers of the #BuyCompanyWindow. */
enum BuyCompanyWidgets {
BCW_CAPTION ,
2009-11-08 19:21:18 +00:00
BCW_FACE ,
BCW_QUESTION ,
2009-05-03 08:13:14 +00:00
BCW_NO ,
BCW_YES ,
} ;
2004-08-09 17:04:08 +00:00
2008-05-18 20:49:22 +00:00
struct BuyCompanyWindow : Window {
2009-11-08 19:21:18 +00:00
BuyCompanyWindow ( const WindowDesc * desc , WindowNumber window_number ) : Window ( )
2008-05-18 20:49:22 +00:00
{
2009-11-08 19:21:18 +00:00
this - > InitNested ( desc , window_number ) ;
2004-08-09 17:04:08 +00:00
}
2008-05-18 20:49:22 +00:00
virtual void OnPaint ( )
{
this - > DrawWidgets ( ) ;
2009-11-08 19:21:18 +00:00
}
2008-05-18 20:49:22 +00:00
2009-11-22 18:28:14 +00:00
virtual void UpdateWidgetSize ( int widget , Dimension * size , const Dimension & padding , Dimension * fill , Dimension * resize )
2009-11-08 19:21:18 +00:00
{
switch ( widget ) {
case BCW_FACE :
* size = GetSpriteSize ( SPR_GRADIENT ) ;
break ;
2008-05-18 20:49:22 +00:00
2009-11-08 19:21:18 +00:00
case BCW_QUESTION :
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > index ) ;
SetDParam ( 1 , c - > bankrupt_value ) ;
size - > height = GetStringHeight ( STR_BUY_COMPANY_MESSAGE , size - > width ) ;
break ;
}
}
virtual void SetStringParameters ( int widget ) const
{
switch ( widget ) {
case BCW_CAPTION :
SetDParam ( 0 , STR_COMPANY_NAME ) ;
SetDParam ( 1 , Company : : Get ( ( CompanyID ) this - > window_number ) - > index ) ;
break ;
}
}
virtual void DrawWidget ( const Rect & r , int widget ) const
{
switch ( widget ) {
case BCW_FACE : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
DrawCompanyManagerFace ( c - > face , c - > colour , r . left , r . top ) ;
2010-08-01 18:53:30 +00:00
break ;
}
2009-11-08 19:21:18 +00:00
case BCW_QUESTION : {
const Company * c = Company : : Get ( ( CompanyID ) this - > window_number ) ;
SetDParam ( 0 , c - > index ) ;
SetDParam ( 1 , c - > bankrupt_value ) ;
DrawStringMultiLine ( r . left , r . right , r . top , r . bottom , 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
}
2010-01-30 18:34:48 +00:00
virtual void OnClick ( Point pt , int widget , int click_count )
2008-05-18 20:49:22 +00:00
{
switch ( widget ) {
2009-05-03 08:13:14 +00:00
case BCW_NO :
2008-05-18 20:49:22 +00:00
delete this ;
break ;
2009-05-03 08:13:14 +00:00
case BCW_YES :
2009-04-21 23:40:56 +00:00
DoCommandP ( 0 , this - > window_number , 0 , CMD_BUY_COMPANY | CMD_MSG ( STR_ERROR_CAN_T_BUY_COMPANY ) ) ;
2008-05-18 20:49:22 +00:00
break ;
}
}
} ;
2004-08-09 17:04:08 +00:00
2009-05-03 08:27:12 +00:00
static const NWidgetPart _nested_buy_company_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_LIGHT_BLUE ) ,
2009-05-03 08:27:12 +00:00
NWidget ( WWT_CAPTION , COLOUR_LIGHT_BLUE , BCW_CAPTION ) , SetDataTip ( STR_ERROR_MESSAGE_CAPTION_OTHER_COMPANY , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
EndContainer ( ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_LIGHT_BLUE ) ,
2009-11-08 19:21:18 +00:00
NWidget ( NWID_VERTICAL ) , SetPIP ( 8 , 8 , 8 ) ,
NWidget ( NWID_HORIZONTAL ) , SetPIP ( 8 , 10 , 8 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_EMPTY , INVALID_COLOUR , BCW_FACE ) , SetFill ( 0 , 1 ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , BCW_QUESTION ) , SetMinimalSize ( 240 , 0 ) , SetFill ( 1 , 1 ) ,
2009-11-08 19:21:18 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) , SetPIP ( 100 , 10 , 100 ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_LIGHT_BLUE , BCW_NO ) , SetMinimalSize ( 60 , 12 ) , SetDataTip ( STR_QUIT_NO , STR_NULL ) , SetFill ( 1 , 0 ) ,
NWidget ( WWT_TEXTBTN , COLOUR_LIGHT_BLUE , BCW_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 ( ) ,
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _buy_company_desc (
2009-11-28 15:01:49 +00:00
WDP_AUTO , 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 ,
2009-11-15 10:26:01 +00:00
_nested_buy_company_widgets , lengthof ( _nested_buy_company_widgets )
2009-03-15 15:12:06 +00:00
) ;
2004-08-09 17:04:08 +00:00
2008-09-30 20:39:50 +00:00
void ShowBuyCompanyDialog ( CompanyID company )
2004-08-09 17:04:08 +00:00
{
2008-09-30 20:39:50 +00:00
AllocateWindowDescFront < BuyCompanyWindow > ( & _buy_company_desc , company ) ;
2004-08-09 17:04:08 +00:00
}