@ -24,6 +24,7 @@
# include "settings_func.h"
# include "core/geometry_func.hpp"
# include "rail_gui.h"
# include "network/network.h"
# include "table/sprites.h"
# include "table/strings.h"
@ -60,6 +61,7 @@ enum TemplateReplaceWindowWidgets {
TRW_WIDGET_INSET_TEMPLATES ,
TRW_WIDGET_BOTTOM_MATRIX ,
TRW_WIDGET_MIDDLE_SCROLLBAR ,
TRW_WIDGET_BOTTOM_SCROLLBAR ,
TRW_WIDGET_TMPL_INFO_INSET ,
@ -76,7 +78,7 @@ enum TemplateReplaceWindowWidgets {
TRW_WIDGET_TMPL_BUTTONS_EDIT ,
TRW_WIDGET_TMPL_BUTTONS_CLONE ,
TRW_WIDGET_TMPL_BUTTONS_DELETE ,
TRW_WIDGET_TMPL_BUTTONS_RPLALL ,
//TRW_WIDGET_TMPL_BUTTONS_RPLALL,
TRW_WIDGET_TMPL_BUTTON_FLUFF ,
TRW_WIDGET_TMPL_BUTTONS_EDIT_RIGHTPANEL ,
@ -84,7 +86,7 @@ enum TemplateReplaceWindowWidgets {
TRW_WIDGET_TITLE_INFO_TEMPLATE ,
TRW_WIDGET_INFO_GROUP ,
TRW_WIDGET_INFO_TEMPLATE ,
TRW_WIDGET_INFO_TEMPLATE ,
TRW_WIDGET_TMPL_BUTTONS_SPACER ,
@ -103,11 +105,12 @@ static const NWidgetPart _widgets[] = {
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
NWidget ( WWT_CAPTION , COLOUR_GREY , TRW_CAPTION ) , SetDataTip ( STR_TMPL_RPL_TITLE , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
NWidget ( WWT_SHADEBOX , COLOUR_GREY ) ,
NWidget ( WWT_DEFSIZEBOX , COLOUR_GREY ) ,
NWidget ( WWT_STICKYBOX , COLOUR_GREY ) ,
EndContainer ( ) ,
//Top Matrix
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_ INSET , COLOUR_GREY , TRW_WIDGET_INSET_GROUPS ) , SetMinimal Size( 216 , 12 ) , SetDataTip ( STR_TMPL_MAINGUI_DEFINEDGROUPS , STR_TMPL_MAINGUI_DEFINEDGROUPS ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( WWT_ PANEL , COLOUR_GREY , TRW_WIDGET_INSET_GROUPS ) , SetMinimal TextLines( 1 , WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_MATRIX , COLOUR_GREY , TRW_WIDGET_TOP_MATRIX ) , SetMinimalSize ( 216 , 0 ) , SetFill ( 1 , 1 ) , SetDataTip ( 0x1 , STR_REPLACE_HELP_LEFT_ARRAY ) , SetResize ( 1 , 0 ) , SetScrollbar ( TRW_WIDGET_TOP_SCROLLBAR ) ,
NWidget ( NWID_VSCROLLBAR , COLOUR_GREY , TRW_WIDGET_TOP_SCROLLBAR ) ,
@ -115,16 +118,19 @@ static const NWidgetPart _widgets[] = {
EndContainer ( ) ,
// Template Display
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_ INSET , COLOUR_GREY , TRW_WIDGET_INSET_TEMPLATES ) , SetMinimal Size( 216 , 12 ) , SetDataTip ( STR_TMPL_AVAILABLE_TEMPLATES , STR_TMPL_AVAILABLE_TEMPLATES ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( WWT_ PANEL , COLOUR_GREY , TRW_WIDGET_INSET_TEMPLATES ) , SetMinimal TextLines( 1 , WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_MATRIX , COLOUR_GREY , TRW_WIDGET_BOTTOM_MATRIX ) , SetMinimalSize ( 216 , 0 ) , SetFill ( 1 , 1 ) , SetDataTip ( 0x1 , STR_REPLACE_HELP_RIGHT_ARRAY ) , SetResize ( 1 , 1 ) , SetScrollbar ( TRW_WIDGET_ BOTTO M_SCROLLBAR) ,
NWidget ( NWID_VSCROLLBAR , COLOUR_GREY , TRW_WIDGET_ BOTTO M_SCROLLBAR) ,
NWidget ( WWT_MATRIX , COLOUR_GREY , TRW_WIDGET_BOTTOM_MATRIX ) , SetMinimalSize ( 216 , 0 ) , SetFill ( 1 , 1 ) , SetDataTip ( 0x1 , STR_REPLACE_HELP_RIGHT_ARRAY ) , SetResize ( 1 , 1 ) , SetScrollbar ( TRW_WIDGET_ MIDDLE _SCROLLBAR) ,
NWidget ( NWID_VSCROLLBAR , COLOUR_GREY , TRW_WIDGET_ MIDDLE _SCROLLBAR) ,
EndContainer ( ) ,
EndContainer ( ) ,
// Info Area
NWidget ( NWID_VERTICAL ) ,
NWidget ( WWT_INSET , COLOUR_GREY , TRW_WIDGET_TMPL_INFO_INSET ) , SetMinimalSize ( 216 , 12 ) , SetResize ( 1 , 0 ) , SetDataTip ( STR_TMPL_AVAILABLE_TEMPLATES , STR_TMPL_AVAILABLE_TEMPLATES ) , EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , TRW_WIDGET_TMPL_INFO_PANEL ) , SetMinimalSize ( 216 , 50 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , TRW_WIDGET_TMPL_INFO_INSET ) , SetMinimalTextLines ( 1 , WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , TRW_WIDGET_TMPL_INFO_PANEL ) , SetMinimalSize ( 216 , 120 ) , SetResize ( 1 , 0 ) , SetScrollbar ( TRW_WIDGET_BOTTOM_SCROLLBAR ) , EndContainer ( ) ,
NWidget ( NWID_VSCROLLBAR , COLOUR_GREY , TRW_WIDGET_BOTTOM_SCROLLBAR ) ,
EndContainer ( ) ,
EndContainer ( ) ,
// Control Area
NWidget ( NWID_VERTICAL ) ,
@ -139,11 +145,10 @@ static const NWidgetPart _widgets[] = {
EndContainer ( ) ,
// Edit buttons
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_DEFINE ) , SetMinimalSize ( 75 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_DEFINE_TEMPLATE , STR_REPLACE_ENGINE_WAGON_SELECT_HELP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_EDIT ) , SetMinimalSize ( 75 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_EDIT_TEMPLATE , STR_REPLACE_ENGINE_WAGON_SELECT_HELP ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_CLONE ) , SetMinimalSize ( 75 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_CREATE_CLONE_VEH , STR_REPLACE_ENGINE_WAGON_SELECT_HELP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_DELETE ) , SetMinimalSize ( 75 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_DELETE_TEMPLATE , STR_REPLACE_ENGINE_WAGON_SELECT_HELP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_RPLALL ) , SetMinimalSize ( 150 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_RPL_ALL_TMPL , STR_REPLACE_ENGINE_WAGON_SELECT_HELP ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_DEFINE ) , SetMinimalSize ( 75 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_DEFINE_TEMPLATE , STR_TMPL_DEFINE_TEMPLATE ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_EDIT ) , SetMinimalSize ( 75 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_EDIT_TEMPLATE , STR_TMPL_EDIT_TEMPLATE ) ,
NWidget ( WWT_TEXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_CLONE ) , SetMinimalSize ( 75 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_CREATE_CLONE_VEH , STR_TMPL_CREATE_CLONE_VEH ) ,
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_DELETE ) , SetMinimalSize ( 75 , 12 ) , SetResize ( 0 , 0 ) , SetDataTip ( STR_TMPL_DELETE_TEMPLATE , STR_TMPL_DELETE_TEMPLATE ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , TRW_WIDGET_TMPL_BUTTONS_EDIT_RIGHTPANEL ) , SetMinimalSize ( 50 , 12 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
EndContainer ( ) ,
EndContainer ( ) ,
@ -174,12 +179,14 @@ private:
GUIGroupList groups ; ///< List of groups
byte unitnumber_digits ;
SmallVector < int , 16 > indents ; ///< Indentation levels
short line_height ;
short matrixContentLeftMargin ;
int details_height ; ///< Minimal needed height of the details panels (found so far).
RailType sel_railtype ; ///< Type of rail tracks selected.
Scrollbar * vscroll [ 2 ] ;
Scrollbar * vscroll [ 3 ] ;
// listing/sorting continued
GUITemplateList templates ;
GUITemplateList : : SortFunction * * template_sorter_funcs ;
@ -204,20 +211,17 @@ public:
this - > line_height = step_h ;
this - > CreateNestedTree ( wdesc ) ;
this - > CreateNestedTree ( wdesc ! = NULL ) ;
this - > vscroll [ 0 ] = this - > GetScrollbar ( TRW_WIDGET_TOP_SCROLLBAR ) ;
this - > vscroll [ 1 ] = this - > GetScrollbar ( TRW_WIDGET_BOTTOM_SCROLLBAR ) ;
this - > vscroll [ 0 ] - > SetStepSize ( step_h / 2 ) ;
this - > vscroll [ 1 ] - > SetStepSize ( step_h ) ;
this - > vscroll [ 1 ] = this - > GetScrollbar ( TRW_WIDGET_MIDDLE_SCROLLBAR ) ;
this - > vscroll [ 2 ] = this - > GetScrollbar ( TRW_WIDGET_BOTTOM_SCROLLBAR ) ;
this - > FinishInitNested ( VEH_TRAIN ) ;
this - > owner = _local_company ;
this - > groups . ForceRebuild ( ) ;
this - > groups . NeedResort ( ) ;
this - > BuildGroupList ( _local_company ) ;
this - > groups . Sort ( & GroupNameSorter ) ;
this - > BuildGroupList ( _local_company ) ;
this - > matrixContentLeftMargin = 40 ;
this - > selected_template_index = - 1 ;
@ -286,6 +290,18 @@ public:
DrawTemplateInfo ( this - > line_height , r ) ;
break ;
}
case TRW_WIDGET_INSET_GROUPS : {
DrawString ( r . left + 2 , r . right - 2 , r . top + 2 , STR_TMPL_MAINGUI_DEFINEDGROUPS ) ;
break ;
}
case TRW_WIDGET_INSET_TEMPLATES : {
DrawString ( r . left + 2 , r . right - 2 , r . top + 2 , STR_TMPL_AVAILABLE_TEMPLATES ) ;
break ;
}
case TRW_WIDGET_TMPL_INFO_INSET : {
DrawString ( r . left + 2 , r . right - 2 , r . top + 2 , STR_TMPL_TEMPLATE_INFO ) ;
break ;
}
}
}
@ -294,7 +310,6 @@ public:
BuildTemplateGuiList ( & this - > templates , this - > vscroll [ 1 ] , this - > owner , this - > sel_railtype ) ;
this - > BuildGroupList ( _local_company ) ;
this - > groups . Sort ( & GroupNameSorter ) ;
if ( templateNotice ) {
BuildTemplateGuiList ( & this - > templates , vscroll [ 1 ] , _local_company , this - > sel_railtype ) ;
@ -308,6 +323,34 @@ public:
/* Show the selected railtype in the pulldown menu */
this - > GetWidget < NWidgetCore > ( TRW_WIDGET_TRAIN_RAILTYPE_DROPDOWN ) - > widget_data = GetRailTypeInfo ( sel_railtype ) - > strings . replace_text ;
if ( ( this - > selected_template_index < 0 ) | | ( this - > selected_template_index > = ( short ) this - > templates . Length ( ) ) ) {
this - > vscroll [ 2 ] - > SetCount ( 24 ) ;
} else {
const TemplateVehicle * tmp = this - > templates [ this - > selected_template_index ] ;
uint min_height = 30 ;
uint height = 30 ;
CargoArray cargo_caps ;
short count_columns = 0 ;
short max_columns = 2 ;
for ( ; tmp ; tmp = tmp - > Next ( ) ) {
cargo_caps [ tmp - > cargo_type ] + = tmp - > cargo_cap ;
}
for ( CargoID i = 0 ; i < NUM_CARGO ; + + i ) {
if ( cargo_caps [ i ] > 0 ) {
if ( count_columns % max_columns = = 0 ) {
height + = this - > line_height / 3 ;
}
+ + count_columns ;
}
}
min_height = max ( min_height , height ) ;
this - > vscroll [ 2 ] - > SetCount ( min_height ) ;
}
this - > DrawWidgets ( ) ;
}
@ -317,31 +360,35 @@ public:
switch ( widget ) {
case TRW_WIDGET_TMPL_BUTTONS_CONFIGTMPL_REUSE : {
if ( this - > selected_template_index > = 0 ) {
TemplateVehicle * sel = TemplateVehicle : : Get ( ( ( this - > templates ) [ selected_template_index ] ) - > index ) ;
sel - > ToggleReuseDepotVehicles ( ) ;
if ( ( this - > selected_template_index > = 0 ) & & ( this - > selected_template_index < ( short ) this - > templates . Length ( ) ) ) {
uint32 template_index = ( ( this - > templates ) [ selected_template_index ] ) - > index ;
DoCommandP ( 0 , template_index , 0 , CMD_TOGGLE_REUSE_DEPOT_VEHICLES , NULL ) ;
}
break ;
}
case TRW_WIDGET_TMPL_BUTTONS_CONFIGTMPL_KEEP : {
if ( this - > selected_template_index > = 0 ) {
TemplateVehicle * sel = TemplateVehicle : : Get ( ( ( this - > templates ) [ selected_template_index ] ) - > index ) ;
sel - > ToggleKeepRemainingVehicles ( ) ;
if ( ( this - > selected_template_index > = 0 ) & & ( this - > selected_template_index < ( short ) this - > templates . Length ( ) ) ) {
uint32 template_index = ( ( this - > templates ) [ selected_template_index ] ) - > index ;
DoCommandP ( 0 , template_index , 0 , CMD_TOGGLE_KEEP_REMAINING_VEHICLES , NULL ) ;
}
break ;
}
case TRW_WIDGET_TMPL_BUTTONS_CONFIGTMPL_REFIT : {
if ( this - > selected_template_index > = 0 ) {
TemplateVehicle * sel = TemplateVehicle : : Get ( ( ( this - > templates ) [ selected_template_index ] ) - > index ) ;
sel - > ToggleRefitAsTemplate ( ) ;
if ( ( this - > selected_template_index > = 0 ) & & ( this - > selected_template_index < ( short ) this - > templates . Length ( ) ) ) {
uint32 template_index = ( ( this - > templates ) [ selected_template_index ] ) - > index ;
DoCommandP ( 0 , template_index , 0 , CMD_TOGGLE_REFIT_AS_TEMPLATE , NULL ) ;
}
break ;
}
case TRW_WIDGET_TMPL_BUTTONS_DEFINE :
case TRW_WIDGET_TMPL_BUTTONS_DEFINE : {
ShowTemplateCreateWindow ( 0 , & templateNotice , & editInProgress , this - > line_height ) ;
break ;
}
case TRW_WIDGET_TMPL_BUTTONS_EDIT : {
if ( this - > selected_template_index > = 0 ) {
if ( ( this - > selected_template_index > = 0 ) & & ( this - > selected_template_index < ( short ) this - > templates . Length ( ) ) ) {
editInProgress = true ;
TemplateVehicle * sel = TemplateVehicle : : Get ( ( ( this - > templates ) [ selected_template_index ] ) - > index ) ;
ShowTemplateCreateWindow ( sel , & templateNotice , & editInProgress , this - > line_height ) ;
@ -361,61 +408,58 @@ public:
break ;
}
case TRW_WIDGET_TMPL_BUTTONS_DELETE :
if ( selected_template_index > = 0 & & ! editInProgress ) {
// identify template to delete
TemplateVehicle * del = TemplateVehicle : : Get ( ( ( this - > templates ) [ selected_template_index ] ) - > index ) ;
// remove a corresponding template replacement if existing
TemplateReplacement * tr = GetTemplateReplacementByTemplateID ( del - > index ) ;
if ( tr ) {
delete tr ;
if ( ( this - > selected_template_index > = 0 ) & & ( this - > selected_template_index < ( short ) this - > templates . Length ( ) ) & & ! editInProgress ) {
uint32 template_index = ( ( this - > templates ) [ selected_template_index ] ) - > index ;
bool succeeded = DoCommandP ( 0 , template_index , 0 , CMD_DELETE_TEMPLATE_VEHICLE , NULL ) ;
if ( succeeded ) {
BuildTemplateGuiList ( & this - > templates , this - > vscroll [ 1 ] , this - > owner , this - > sel_railtype ) ;
selected_template_index = - 1 ;
}
delete del ;
BuildTemplateGuiList ( & this - > templates , this - > vscroll [ 1 ] , this - > owner , this - > sel_railtype ) ;
selected_template_index = - 1 ;
}
break ;
case TRW_WIDGET_TMPL_BUTTONS_RPLALL : {
ShowTemplateReplaceAllGui ( ) ;
break ;
}
case TRW_WIDGET_TRAIN_RAILTYPE_DROPDOWN : // Railtype selection dropdown menu
ShowDropDownList ( this , GetRailTypeDropDownList ( true ) , sel_railtype , TRW_WIDGET_TRAIN_RAILTYPE_DROPDOWN ) ;
break ;
case TRW_WIDGET_TOP_MATRIX : {
uint16 newindex = ( uint16 ) ( ( pt . y - this - > nested_array [ TRW_WIDGET_TOP_MATRIX ] - > pos_y ) / ( this - > line_height / 2 ) ) + this - > vscroll [ 0 ] - > GetPosition ( ) ;
uint16 newindex = ( uint16 ) ( ( pt . y - this - > nested_array [ TRW_WIDGET_TOP_MATRIX ] - > pos_y ) / ( this - > line_height / 2 ) ) + this - > vscroll [ 0 ] - > GetPosition ( ) ;
if ( newindex = = this - > selected_group_index | | newindex > = this - > groups . Length ( ) ) {
this - > selected_group_index = - 1 ;
}
else if ( newindex < this - > groups . Length ( ) ) {
else if ( ( newindex > = 0 ) & & ( newindex < this - > groups . Length ( ) ) ) {
this - > selected_group_index = newindex ;
}
break ;
}
case TRW_WIDGET_BOTTOM_MATRIX : {
uint16 newindex = ( uint16 ) ( ( pt . y - this - > nested_array [ TRW_WIDGET_BOTTOM_MATRIX ] - > pos_y ) / this - > line_height ) + this - > vscroll [ 1 ] - > GetPosition ( ) ;
uint16 newindex = ( uint16 ) ( ( pt . y - this - > nested_array [ TRW_WIDGET_BOTTOM_MATRIX ] - > pos_y ) / this - > line_height ) + this - > vscroll [ 1 ] - > GetPosition ( ) ;
if ( newindex = = this - > selected_template_index | | newindex > = templates . Length ( ) ) {
this - > selected_template_index = - 1 ;
}
else if ( newindex < templates . Length ( ) ) {
else if ( ( newindex > = 0 ) & & ( newindex < templates . Length ( ) ) ) {
this - > selected_template_index = newindex ;
}
break ;
}
case TRW_WIDGET_START : {
if ( this - > selected_template_index > = 0 & & this - > selected_group_index > = 0 ) {
if ( ( this - > selected_template_index > = 0 ) & & ( this - > selected_template_index < ( short ) this - > templates . Length ( ) ) & &
( this - > selected_group_index > = 0 ) & & ( this - > selected_group_index < ( short ) this - > groups . Length ( ) ) ) {
uint32 tv_index = ( ( this - > templates ) [ selected_template_index ] ) - > index ;
int current_group_index = ( this - > groups ) [ this - > selected_group_index ] - > index ;
IssueTemplateReplacement ( current_group_index , tv_index ) ;
DoCommandP ( 0 , current_group_index , tv_index , CMD_ISSUE_TEMPLATE_REPLACEMENT , NULL ) ;
}
break ;
}
case TRW_WIDGET_STOP :
if ( this - > selected_group_index == - 1 )
if ( ( this - > selected_group_index < 0 ) | | ( this - > selected_group_index >= ( short ) this - > groups . Length ( ) ) )
return ;
int current_group_index = ( this - > groups ) [ this - > selected_group_index ] - > index ;
TemplateReplacement * tr = GetTemplateReplacementByGroupID ( current_group_index ) ;
if ( tr )
delete tr ;
DoCommandP ( 0 , current_group_index , 0 , CMD_DELETE_TEMPLATE_REPLACEMENT , NULL ) ;
break ;
}
this - > SetDirty ( ) ;
@ -423,9 +467,9 @@ public:
virtual bool OnVehicleSelect ( const Vehicle * v )
{
// create a new template from the clicked vehicle
TemplateVehicle * tv = CloneTemplateVehicleFromTrain ( ( const Train * ) v ) ;
if ( ! tv ) return false ;
bool succeeded = DoCommandP ( 0 , v - > index , 0 , CMD_CLONE_TEMPLATE_VEHICLE_FROM_TRAIN , NULL ) ;
if ( ! succeeded ) return false ;
BuildTemplateGuiList ( & this - > templates , vscroll [ 1 ] , _local_company , this - > sel_railtype ) ;
this - > ToggleWidgetLoweredState ( TRW_WIDGET_TMPL_BUTTONS_CLONE ) ;
@ -457,6 +501,9 @@ public:
NWidgetCore * nwi2 = this - > GetWidget < NWidgetCore > ( TRW_WIDGET_BOTTOM_MATRIX ) ;
this - > vscroll [ 1 ] - > SetCapacityFromWidget ( this , TRW_WIDGET_BOTTOM_MATRIX ) ;
nwi2 - > widget_data = ( this - > vscroll [ 1 ] - > GetCapacity ( ) < < MAT_ROW_START ) + ( 1 < < MAT_COL_START ) ;
/* Info panel */
NWidgetCore * nwi3 = this - > GetWidget < NWidgetCore > ( TRW_WIDGET_TMPL_INFO_PANEL ) ;
this - > vscroll [ 2 ] - > SetCapacity ( nwi3 - > current_y ) ;
}
virtual void OnTick ( )
@ -489,6 +536,17 @@ public:
return - 1 ;
}
void AddParents ( GUIGroupList * source , GroupID parent , int indent )
{
for ( const Group * * g = source - > Begin ( ) ; g ! = source - > End ( ) ; g + + ) {
if ( ( * g ) - > parent = = parent ) {
* this - > groups . Append ( ) = * g ;
* this - > indents . Append ( ) = indent ;
AddParents ( source , ( * g ) - > index , indent + 1 ) ;
}
}
}
/** Sort the groups by their name */
static int CDECL GroupNameSorter ( const Group * const * a , const Group * const * b )
{
@ -514,18 +572,25 @@ public:
void BuildGroupList ( Owner owner )
{
if ( ! this - > groups . NeedRebuild ( ) ) {
return ;
}
if ( ! this - > groups . NeedRebuild ( ) ) return ;
this - > groups . Clear ( ) ;
this - > indents . Clear ( ) ;
GUIGroupList list ;
const Group * g ;
FOR_ALL_GROUPS ( g ) {
if ( g - > owner = = owner ) {
* this - > groups . Append ( ) = g ;
if ( g - > owner = = owner & & g - > vehicle_type = = VEH_TRAIN ) {
* list . Append ( ) = g ;
}
}
list . ForceResort ( ) ;
list . Sort ( & GroupNameSorter ) ;
AddParents ( & list , INVALID_GROUP , 0 ) ;
this - > groups . Compact ( ) ;
this - > groups . RebuildDone ( ) ;
this - > vscroll [ 0 ] - > SetCount ( groups . Length ( ) ) ;
@ -550,7 +615,7 @@ public:
SetDParam ( 0 , g_id ) ;
StringID str = STR_GROUP_NAME ;
DrawString ( left + 30 , right , y + 2 , str , TC_BLACK ) ;
DrawString ( left + 30 + this - > indents [ i ] * 10 , right , y + 2 , str , TC_BLACK ) ;
/* Draw the template in use for this group, if there is one */
short template_in_use = FindTemplateIndexForGroup ( g_id ) ;
@ -621,24 +686,24 @@ public:
/* Index of current template vehicle in the list of all templates for its company */
SetDParam ( 0 , i ) ;
DrawString ( left + 5 , left + 25 , y + line_height / 2 , STR_BLACK_INT , TC_BLACK , SA_RIGHT ) ;
DrawString ( left + 5 , left + 25 , y + 2 , STR_BLACK_INT , TC_BLACK , SA_RIGHT ) ;
/* Draw whether the current template is in use by any group */
if ( v - > NumGroupsUsingTemplate ( ) > 0 ) {
DrawString ( left + 200 , right , y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2 , STR_TMP_TEMPLATE_IN_USE , TC_GREEN , SA_LEFT ) ;
DrawString ( left + 35 , right , y + line_height - FONT_HEIGHT_SMALL * 2 - 4 - WD_FRAMERECT_BOTTOM - 2 , STR_TMP_TEMPLATE_IN_USE , TC_GREEN , SA_LEFT ) ;
}
/* Draw information about template configuration settings */
TextColour color ;
if ( v - > IsSetReuseDepotVehicles ( ) ) color = TC_LIGHT_BLUE ;
else color = TC_GREY ;
DrawString ( left + 200, right , y + 2 , STR_TMPL_CONFIG_USEDEPOT , color , SA_LEFT ) ;
DrawString ( left + 300, right , y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2 , STR_TMPL_CONFIG_USEDEPOT , color , SA_LEFT ) ;
if ( v - > IsSetKeepRemainingVehicles ( ) ) color = TC_LIGHT_BLUE ;
else color = TC_GREY ;
DrawString ( left + 275, right , y + 2 , STR_TMPL_CONFIG_KEEPREMAINDERS , color , SA_LEFT ) ;
DrawString ( left + 400, right , y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2 , STR_TMPL_CONFIG_KEEPREMAINDERS , color , SA_LEFT ) ;
if ( v - > IsSetRefitAsTemplate ( ) ) color = TC_LIGHT_BLUE ;
else color = TC_GREY ;
DrawString ( left + 3 50, right , y + 2 , STR_TMPL_CONFIG_REFIT , color , SA_LEFT ) ;
DrawString ( left + 50 0, right , y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2 , STR_TMPL_CONFIG_REFIT , color , SA_LEFT ) ;
y + = line_height ;
}
@ -646,9 +711,17 @@ public:
void DrawTemplateInfo ( int line_height , const Rect & r ) const
{
if ( this - > selected_template_index = = - 1 | | ( short ) this - > templates . Length ( ) < = this - > selected_template_index )
if ( ( this - > selected_template_index < 0 ) | | ( this - > selected_template_index > = ( short ) this - > templates . Length ( ) ) )
return ;
DrawPixelInfo tmp_dpi , * old_dpi ;
if ( ! FillDrawPixelInfo ( & tmp_dpi , r . left , r . top , r . right - r . left , r . bottom - r . top ) )
return ;
old_dpi = _cur_dpi ;
_cur_dpi = & tmp_dpi ;
const TemplateVehicle * tmp = this - > templates [ this - > selected_template_index ] ;
/* Draw vehicle performance info */
@ -656,32 +729,34 @@ public:
SetDParam ( 1 , tmp - > power ) ;
SetDParam ( 0 , tmp - > weight ) ;
SetDParam ( 3 , tmp - > max_te ) ;
DrawString ( r . left + 8 , r . right , r . top + 4 , STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE ) ;
DrawString ( 8 , r . right , 4 - this - > vscroll [ 2 ] - > GetPosition ( ) , STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE ) ;
/* Draw cargo summary */
short top = r . top + 24 ;
short left = r . left + 8 ;
short count_ row s = 0 ;
short max_ row s = 2 ;
short top = 30 - this - > vscroll [ 2 ] - > GetPosition ( ) ;
short left = 8 ;
short count_ column s = 0 ;
short max_ column s = 2 ;
CargoArray cargo_caps ;
for ( ; tmp ; tmp = tmp - > Next ( ) )
cargo_caps [ tmp - > cargo_type ] + = tmp - > cargo_cap ;
int y = top ;
int x = left ;
for ( CargoID i = 0 ; i < NUM_CARGO ; + + i ) {
if ( cargo_caps [ i ] > 0 ) {
count_ row s+ + ;
count_ column s+ + ;
SetDParam ( 0 , i ) ;
SetDParam ( 1 , cargo_caps [ i ] ) ;
SetDParam ( 2 , _settings_game . vehicle . freight_trains ) ;
DrawString ( left, r . right , y , FreightWagonMult ( i ) > 1 ? STR_TMPL_CARGO_SUMMARY_MULTI : STR_TMPL_CARGO_SUMMARY , TC_ WHIT E, SA_LEFT ) ;
y + = this - > line_height / 2 ;
if ( count_ rows % max_row s = = 0 ) {
y = top ;
left + = 150 ;
DrawString ( x, r . right , top , FreightWagonMult ( i ) > 1 ? STR_TMPL_CARGO_SUMMARY_MULTI : STR_TMPL_CARGO_SUMMARY , TC_ LIGHT_BLU E, SA_LEFT ) ;
x + = 250 ;
if ( count_ columns % max_column s = = 0 ) {
x = left ;
top + = this - > line_height / 3 ;
}
}
}
_cur_dpi = old_dpi ;
}
} ;