@ -2229,12 +2229,6 @@ static const NWidgetPart _nested_company_widgets[] = {
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , WID_C_SELECT_DESC_OWNERS ) ,
NWidget ( NWID_VERTICAL ) , SetPIP ( 5 , 5 , 4 ) ,
NWidget ( WWT_EMPTY , INVALID_COLOUR , WID_C_DESC_OWNERS ) , SetMinimalTextLines ( MAX_COMPANY_SHARE_OWNERS , 0 ) ,
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
EndContainer ( ) ,
EndContainer ( ) ,
/* Multi player buttons. */
NWidget ( NWID_VERTICAL ) , SetPIP ( 4 , 2 , 4 ) ,
NWidget ( NWID_SPACER ) , SetFill ( 0 , 1 ) ,
@ -2264,19 +2258,9 @@ static const NWidgetPart _nested_company_widgets[] = {
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_PRESIDENT_NAME ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_PRESIDENT_NAME_BUTTON , STR_COMPANY_VIEW_PRESIDENT_NAME_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_COMPANY_NAME ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_COMPANY_NAME_BUTTON , STR_COMPANY_VIEW_COMPANY_NAME_TOOLTIP ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL , NC_EQUALSIZE ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_BUY_SHARE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_BUY_SHARE_BUTTON , STR_COMPANY_VIEW_BUY_SHARE_TOOLTIP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , WID_C_SELL_SHARE ) , SetFill ( 1 , 0 ) , SetDataTip ( STR_COMPANY_VIEW_SELL_SHARE_BUTTON , STR_COMPANY_VIEW_SELL_SHARE_TOOLTIP ) ,
EndContainer ( ) ,
EndContainer ( ) ,
} ;
int GetAmountOwnedBy ( const Company * c , Owner owner )
{
auto share_owned_by = [ owner ] ( auto share_owner ) { return share_owner = = owner ; } ;
return std : : count_if ( c - > share_owners . begin ( ) , c - > share_owners . end ( ) , share_owned_by ) ;
}
/** 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
@ -2302,10 +2286,6 @@ struct CompanyWindow : Window
/* Display planes of the #WID_C_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 #WID_C_SELECT_BUTTONS selection widget. */
CWP_BUTTONS_LOCAL = 0 , ///< Buttons of the local company.
CWP_BUTTONS_OTHER , ///< Buttons of the other companies.
} ;
CompanyWindow ( WindowDesc * desc , WindowNumber window_number ) : Window ( desc )
@ -2324,7 +2304,7 @@ struct CompanyWindow : Window
bool reinit = false ;
/* Button bar selection. */
int plane = local ? CWP_BUTTONS_LOCAL : CWP_BUTTONS_OTHER ;
int plane = local ? 0 : SZSP_NONE ;
NWidgetStacked * wi = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_BUTTONS ) ;
if ( plane ! = wi - > shown_plane ) {
wi - > SetDisplayedPlane ( plane ) ;
@ -2349,16 +2329,6 @@ struct CompanyWindow : Window
wi - > SetDisplayedPlane ( plane ) ;
reinit = true ;
}
/* Owners of company */
auto invalid_owner = [ ] ( auto owner ) { return owner = = INVALID_COMPANY ; } ;
plane = std : : all_of ( c - > share_owners . begin ( ) , c - > share_owners . end ( ) , invalid_owner ) ? SZSP_HORIZONTAL : 0 ;
wi = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_DESC_OWNERS ) ;
if ( plane ! = wi - > shown_plane ) {
wi - > SetDisplayedPlane ( plane ) ;
reinit = true ;
}
/* Enable/disable 'Give money' button. */
plane = ( ( local | | _local_company = = COMPANY_SPECTATOR | | ! _settings_game . economy . give_money ) ? SZSP_NONE : 0 ) ;
wi = this - > GetWidget < NWidgetStacked > ( WID_C_SELECT_GIVE_MONEY ) ;
@ -2426,16 +2396,6 @@ struct CompanyWindow : Window
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_INFRASTRUCTURE_NONE ) . width ) ;
break ;
case WID_C_DESC_OWNERS : {
for ( const Company * c2 : Company : : Iterate ( ) ) {
SetDParamMaxValue ( 0 , 75 ) ;
SetDParam ( 1 , c2 - > index ) ;
size - > width = std : : max ( size - > width , GetStringBoundingBox ( STR_COMPANY_VIEW_SHARES_OWNED_BY ) . width ) ;
}
break ;
}
case WID_C_VIEW_HQ :
case WID_C_BUILD_HQ :
case WID_C_RELOCATE_HQ :
@ -2551,22 +2511,6 @@ struct CompanyWindow : Window
DrawInfrastructureCountsWidget ( r , c ) ;
break ;
case WID_C_DESC_OWNERS : {
uint y = r . top ;
for ( const Company * c2 : Company : : Iterate ( ) ) {
uint amt = GetAmountOwnedBy ( c , c2 - > index ) ;
if ( amt ! = 0 ) {
SetDParam ( 0 , amt * 25 ) ;
SetDParam ( 1 , c2 - > index ) ;
DrawString ( r . left , r . right , y , STR_COMPANY_VIEW_SHARES_OWNED_BY ) ;
y + = FONT_HEIGHT_NORMAL ;
}
}
break ;
}
case WID_C_HAS_PASSWORD :
if ( _networking & & NetworkCompanyIsPassworded ( c - > index ) ) {
DrawSprite ( SPR_LOCK , PAL_NONE , r . left , r . top ) ;
@ -2658,14 +2602,6 @@ struct CompanyWindow : Window
ShowQueryString ( STR_EMPTY , STR_COMPANY_VIEW_GIVE_MONEY_QUERY_CAPTION , 30 , this , CS_NUMERAL , QSF_NONE ) ;
break ;
case WID_C_BUY_SHARE :
Command < CMD_BUY_SHARE_IN_COMPANY > : : Post ( STR_ERROR_CAN_T_BUY_25_SHARE_IN_THIS , ( CompanyID ) this - > window_number ) ;
break ;
case WID_C_SELL_SHARE :
Command < CMD_SELL_SHARE_IN_COMPANY > : : Post ( STR_ERROR_CAN_T_SELL_25_SHARE_IN , ( CompanyID ) this - > window_number ) ;
break ;
case WID_C_COMPANY_PASSWORD :
if ( this - > window_number = = _local_company ) ShowNetworkCompanyPasswordWindow ( this ) ;
break ;
@ -2734,36 +2670,6 @@ struct CompanyWindow : Window
break ;
}
}
/**
* Some data on this window has become invalid .
* @ param data Information about the changed data .
* @ param gui_scope Whether the call is done from GUI scope . You may not do everything when not in GUI scope . See # InvalidateWindowData ( ) for details .
*/
void OnInvalidateData ( int data = 0 , bool gui_scope = true ) override
{
if ( this - > window_number = = _local_company ) return ;
if ( _settings_game . economy . allow_shares ) { // Shares are allowed
const Company * c = Company : : Get ( this - > window_number ) ;
/* If all shares are owned by someone (none by nobody), disable buy button */
this - > SetWidgetDisabledState ( WID_C_BUY_SHARE , GetAmountOwnedBy ( c , INVALID_OWNER ) = = 0 | |
/* Only 25% left to buy. If the company is human, disable buying it up.. TODO issues! */
( GetAmountOwnedBy ( c , INVALID_OWNER ) = = 1 & & ! c - > is_ai ) | |
/* Spectators cannot do anything of course */
_local_company = = COMPANY_SPECTATOR ) ;
/* If the company doesn't own any shares, disable sell button */
this - > SetWidgetDisabledState ( WID_C_SELL_SHARE , ( GetAmountOwnedBy ( c , _local_company ) = = 0 ) | |
/* Spectators cannot do anything of course */
_local_company = = COMPANY_SPECTATOR ) ;
} else { // Shares are not allowed, disable buy/sell buttons
this - > DisableWidget ( WID_C_BUY_SHARE ) ;
this - > DisableWidget ( WID_C_SELL_SHARE ) ;
}
}
} ;
static WindowDesc _company_desc (