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-05-06 15:11:33 +00:00
/** @file vehicle_gui.cpp The base GUI for all vehicles. */
2007-04-04 04:08:47 +00:00
2004-09-06 18:15:13 +00:00
# include "stdafx.h"
2005-02-05 15:58:59 +00:00
# include "debug.h"
2008-09-30 20:51:04 +00:00
# include "company_func.h"
2005-01-02 17:23:04 +00:00
# include "gui.h"
2007-12-19 20:45:46 +00:00
# include "textbuf_gui.h"
2007-12-21 21:50:46 +00:00
# include "command_func.h"
2005-07-21 22:15:02 +00:00
# include "vehicle_gui.h"
2008-09-13 10:04:36 +00:00
# include "vehicle_gui_base.h"
2008-01-09 09:45:45 +00:00
# include "viewport_func.h"
2006-02-03 12:55:21 +00:00
# include "newgrf_engine.h"
2006-04-23 22:33:10 +00:00
# include "newgrf_text.h"
2009-07-22 10:18:19 +00:00
# include "waypoint_base.h"
2006-08-29 17:41:13 +00:00
# include "roadveh.h"
2009-05-22 22:22:46 +00:00
# include "train.h"
2009-07-13 16:37:27 +00:00
# include "aircraft.h"
2008-04-17 19:10:30 +00:00
# include "depot_base.h"
2007-12-21 07:38:36 +00:00
# include "group_gui.h"
2007-12-21 19:49:27 +00:00
# include "strings_func.h"
2007-12-25 11:26:07 +00:00
# include "window_func.h"
2007-12-27 13:35:39 +00:00
# include "vehicle_func.h"
2008-01-07 09:19:53 +00:00
# include "autoreplace_gui.h"
2008-01-07 14:23:25 +00:00
# include "string_func.h"
2008-01-14 16:10:58 +00:00
# include "widgets/dropdown_func.h"
2008-05-06 22:17:12 +00:00
# include "timetable.h"
2008-05-28 11:56:21 +00:00
# include "vehiclelist.h"
2009-02-27 20:40:39 +00:00
# include "articulated_vehicles.h"
2009-06-24 21:33:11 +00:00
# include "cargotype.h"
2009-11-17 15:05:12 +00:00
# include "spritecache.h"
2010-01-15 16:41:15 +00:00
# include "core/geometry_func.hpp"
# include "company_base.h"
# include "engine_base.h"
# include "engine_func.h"
2005-07-21 22:15:02 +00:00
2008-01-13 01:21:35 +00:00
# include "table/sprites.h"
# include "table/strings.h"
2008-05-11 14:23:45 +00:00
Sorting _sorting ;
2004-09-06 18:15:13 +00:00
2008-06-19 19:58:30 +00:00
static GUIVehicleList : : SortFunction VehicleNumberSorter ;
static GUIVehicleList : : SortFunction VehicleNameSorter ;
static GUIVehicleList : : SortFunction VehicleAgeSorter ;
static GUIVehicleList : : SortFunction VehicleProfitThisYearSorter ;
static GUIVehicleList : : SortFunction VehicleProfitLastYearSorter ;
static GUIVehicleList : : SortFunction VehicleCargoSorter ;
static GUIVehicleList : : SortFunction VehicleReliabilitySorter ;
static GUIVehicleList : : SortFunction VehicleMaxSpeedSorter ;
static GUIVehicleList : : SortFunction VehicleModelSorter ;
static GUIVehicleList : : SortFunction VehicleValueSorter ;
static GUIVehicleList : : SortFunction VehicleLengthSorter ;
2008-09-17 02:30:24 +00:00
static GUIVehicleList : : SortFunction VehicleTimeToLiveSorter ;
2009-08-15 10:51:33 +00:00
static GUIVehicleList : : SortFunction VehicleTimetableDelaySorter ;
2008-06-19 19:58:30 +00:00
2009-01-10 00:31:47 +00:00
GUIVehicleList : : SortFunction * const BaseVehicleListWindow : : vehicle_sorter_funcs [ ] = {
2004-11-25 06:05:47 +00:00
& VehicleNumberSorter ,
& VehicleNameSorter ,
& VehicleAgeSorter ,
& VehicleProfitThisYearSorter ,
& VehicleProfitLastYearSorter ,
& VehicleCargoSorter ,
& VehicleReliabilitySorter ,
2006-02-03 18:32:59 +00:00
& VehicleMaxSpeedSorter ,
& VehicleModelSorter ,
& VehicleValueSorter ,
2008-04-18 10:58:11 +00:00
& VehicleLengthSorter ,
2008-09-17 02:30:24 +00:00
& VehicleTimeToLiveSorter ,
2009-08-15 10:51:33 +00:00
& VehicleTimetableDelaySorter ,
2004-11-25 06:05:47 +00:00
} ;
2008-09-13 10:04:36 +00:00
const StringID BaseVehicleListWindow : : vehicle_sorter_names [ ] = {
2004-11-25 06:05:47 +00:00
STR_SORT_BY_NUMBER ,
2009-07-23 19:31:50 +00:00
STR_SORT_BY_NAME ,
2004-11-25 06:05:47 +00:00
STR_SORT_BY_AGE ,
STR_SORT_BY_PROFIT_THIS_YEAR ,
STR_SORT_BY_PROFIT_LAST_YEAR ,
STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE ,
STR_SORT_BY_RELIABILITY ,
STR_SORT_BY_MAX_SPEED ,
2006-02-03 18:32:59 +00:00
STR_SORT_BY_MODEL ,
STR_SORT_BY_VALUE ,
2008-04-18 10:58:11 +00:00
STR_SORT_BY_LENGTH ,
2008-09-17 02:30:24 +00:00
STR_SORT_BY_LIFE_TIME ,
2009-08-15 10:51:33 +00:00
STR_SORT_BY_TIMETABLE_DELAY ,
2004-11-25 06:05:47 +00:00
INVALID_STRING_ID
} ;
2008-09-30 20:39:50 +00:00
void BaseVehicleListWindow : : BuildVehicleList ( Owner owner , uint16 index , uint16 window_type )
2004-12-10 18:16:08 +00:00
{
2008-09-13 10:04:36 +00:00
if ( ! this - > vehicles . NeedRebuild ( ) ) return ;
2004-12-10 18:16:08 +00:00
2008-09-30 20:39:50 +00:00
DEBUG ( misc , 3 , " Building vehicle list for company %d at station %d " , owner , index ) ;
2004-12-10 18:16:08 +00:00
2008-09-13 10:04:36 +00:00
GenerateVehicleSortList ( & this - > vehicles , this - > vehicle_type , owner , index , window_type ) ;
2004-12-10 18:16:08 +00:00
2009-11-17 09:09:20 +00:00
uint unitnumber = 0 ;
for ( const Vehicle * * v = this - > vehicles . Begin ( ) ; v ! = this - > vehicles . End ( ) ; v + + ) {
unitnumber = max < uint > ( unitnumber , ( * v ) - > unitnumber ) ;
}
/* Because 111 is much less wide than e.g. 999 we use the
* wider numbers to determine the width instead of just
* the random number that it seems to be . */
if ( unitnumber > = 1000 ) {
2009-12-20 16:44:41 +00:00
this - > unitnumber_digits = 4 ;
2009-11-17 09:09:20 +00:00
} else if ( unitnumber > = 100 ) {
2009-12-20 16:44:41 +00:00
this - > unitnumber_digits = 3 ;
2009-11-17 09:09:20 +00:00
} else {
2009-12-20 16:44:41 +00:00
this - > unitnumber_digits = 2 ;
2009-11-17 09:09:20 +00:00
}
2008-09-13 10:04:36 +00:00
this - > vehicles . RebuildDone ( ) ;
2009-09-02 08:48:29 +00:00
this - > vscroll . SetCount ( this - > vehicles . Length ( ) ) ;
2004-12-10 18:16:08 +00:00
}
2008-03-02 00:25:54 +00:00
/* cached values for VehicleNameSorter to spare many GetString() calls */
static const Vehicle * _last_vehicle [ 2 ] = { NULL , NULL } ;
2008-09-13 10:04:36 +00:00
void BaseVehicleListWindow : : SortVehicleList ( )
2004-12-10 18:16:08 +00:00
{
2008-09-13 10:04:36 +00:00
if ( this - > vehicles . Sort ( ) ) return ;
2004-12-10 18:16:08 +00:00
2008-03-02 00:25:54 +00:00
/* invalidate cached values for name sorter - vehicle names could change */
_last_vehicle [ 0 ] = _last_vehicle [ 1 ] = NULL ;
2004-12-10 18:16:08 +00:00
}
2008-05-25 17:22:49 +00:00
void DepotSortList ( VehicleList * list )
2006-10-05 13:11:17 +00:00
{
2008-05-25 17:22:49 +00:00
if ( list - > Length ( ) < 2 ) return ;
2008-06-19 19:58:30 +00:00
QSortT ( list - > Begin ( ) , list - > Length ( ) , & VehicleNumberSorter ) ;
2006-10-05 13:11:17 +00:00
}
2004-12-10 18:16:08 +00:00
2007-04-04 04:08:47 +00:00
/** draw the vehicle profit button in the vehicle list window. */
2009-11-09 10:40:33 +00:00
static void DrawVehicleProfitButton ( const Vehicle * v , int x , int y )
2004-09-06 18:15:13 +00:00
{
2007-01-14 19:57:49 +00:00
SpriteID pal ;
2004-09-06 18:15:13 +00:00
2009-02-09 02:57:15 +00:00
/* draw profit-based coloured icons */
2009-01-13 22:58:03 +00:00
if ( v - > age < = DAYS_IN_YEAR * 2 ) {
2007-01-14 19:57:49 +00:00
pal = PALETTE_TO_GREY ;
2008-02-20 17:06:58 +00:00
} else if ( v - > GetDisplayProfitLastYear ( ) < 0 ) {
2007-01-14 19:57:49 +00:00
pal = PALETTE_TO_RED ;
2008-02-20 17:06:58 +00:00
} else if ( v - > GetDisplayProfitLastYear ( ) < 10000 ) {
2007-01-14 19:57:49 +00:00
pal = PALETTE_TO_YELLOW ;
2005-11-14 19:48:04 +00:00
} else {
2007-01-14 19:57:49 +00:00
pal = PALETTE_TO_GREEN ;
2005-11-14 19:48:04 +00:00
}
2007-01-14 19:57:49 +00:00
DrawSprite ( SPR_BLOT , pal , x , y ) ;
2004-09-06 18:15:13 +00:00
}
2010-01-10 20:33:10 +00:00
/** Maximum number of refit cycles we try, to prevent infinite loops. And we store only a byte anyway */
static const uint MAX_REFIT_CYCLE = 256 ;
2009-12-13 22:19:19 +00:00
2009-12-14 19:17:18 +00:00
/**
* Get the best fitting subtype when ' cloning ' / ' replacing ' v_from with v_for .
* Assuming they are going to carry the same cargo ofcourse !
* @ param v_from the vehicle to match the subtype from
* @ param v_for the vehicle to get the subtype for
* @ return the best sub type
*/
byte GetBestFittingSubType ( Vehicle * v_from , Vehicle * v_for )
{
const Engine * e_from = Engine : : Get ( v_from - > engine_type ) ;
const Engine * e_for = Engine : : Get ( v_for - > engine_type ) ;
/* If one them doesn't carry cargo, there's no need to find a sub type */
if ( ! e_from - > CanCarryCargo ( ) | | ! e_for - > CanCarryCargo ( ) ) return 0 ;
if ( ! HasBit ( e_from - > info . callback_mask , CBM_VEHICLE_CARGO_SUFFIX ) | |
! HasBit ( e_for - > info . callback_mask , CBM_VEHICLE_CARGO_SUFFIX ) ) {
/* One of the engines doesn't have cargo suffixes, i.e. sub types. */
return 0 ;
}
/* It has to be possible for v_for to carry the cargo of v_from. */
2009-12-21 17:45:02 +00:00
if ( ! HasBit ( e_for - > info . refit_mask , v_from - > cargo_type ) ) return 0 ;
2009-12-14 19:17:18 +00:00
StringID expected_string = GetCargoSubtypeText ( v_from ) ;
CargoID old_cargo_type = v_for - > cargo_type ;
byte old_cargo_subtype = v_for - > cargo_subtype ;
byte ret_refit_cyc = 0 ;
/* Set the 'destination' cargo */
v_for - > cargo_type = v_from - > cargo_type ;
/* Cycle through the refits */
2010-01-10 20:33:10 +00:00
for ( uint refit_cyc = 0 ; refit_cyc < MAX_REFIT_CYCLE ; refit_cyc + + ) {
2009-12-14 19:17:18 +00:00
v_for - > cargo_subtype = refit_cyc ;
/* Make sure we don't pick up anything cached. */
v_for - > First ( ) - > InvalidateNewGRFCache ( ) ;
v_for - > InvalidateNewGRFCache ( ) ;
uint16 callback = GetVehicleCallback ( CBID_VEHICLE_CARGO_SUFFIX , 0 , 0 , v_for - > engine_type , v_for ) ;
if ( callback = = 0xFF ) callback = CALLBACK_FAILED ;
if ( callback = = CALLBACK_FAILED ) break ;
if ( GetCargoSubtypeText ( v_for ) ! = expected_string ) continue ;
/* We found something matching. */
ret_refit_cyc = refit_cyc ;
break ;
}
/* Reset the vehicle's cargo type */
v_for - > cargo_type = old_cargo_type ;
v_for - > cargo_subtype = old_cargo_subtype ;
/* Make sure we don't taint the vehicle. */
v_for - > First ( ) - > InvalidateNewGRFCache ( ) ;
v_for - > InvalidateNewGRFCache ( ) ;
return ret_refit_cyc ;
}
2010-01-10 21:45:32 +00:00
/** Option to refit a vehicle chain */
2007-03-07 12:11:48 +00:00
struct RefitOption {
2010-01-10 21:45:32 +00:00
CargoID cargo ; ///< Cargo to refit to
byte subtype ; ///< Subcargo to use
uint16 value ; ///< GRF-local String to display for the cargo
EngineID engine ; ///< Engine for which to resolve #value
2006-10-01 12:00:32 +00:00
2010-01-10 21:45:32 +00:00
FORCEINLINE bool operator ! = ( const RefitOption & other ) const
{
return other . cargo ! = this - > cargo | | other . subtype ! = this - > subtype ;
}
2007-03-07 12:11:48 +00:00
} ;
2006-10-01 12:00:32 +00:00
2010-01-10 21:45:32 +00:00
typedef SmallVector < RefitOption , 32 > RefitList ;
/**
* Collects all ( cargo , subcargo ) refit - options of a vehicle chain
* @ param v front vehicle
* @ param refit_list container to store result
*/
static void BuildRefitList ( const Vehicle * v , RefitList * refit_list )
2006-10-01 12:00:32 +00:00
{
2010-01-10 21:45:32 +00:00
refit_list - > Clear ( ) ;
2009-05-24 21:09:00 +00:00
Vehicle * u = const_cast < Vehicle * > ( v ) ;
2006-10-01 12:00:32 +00:00
do {
2009-10-06 19:17:07 +00:00
const Engine * e = Engine : : Get ( u - > engine_type ) ;
uint32 cmask = e - > info . refit_mask ;
byte callback_mask = e - > info . callback_mask ;
2006-10-01 12:00:32 +00:00
2010-01-10 21:45:32 +00:00
/* Skip this engine if it does not carry anything */
if ( ! e - > CanCarryCargo ( ) ) continue ;
2006-10-24 07:10:37 +00:00
2006-10-01 12:00:32 +00:00
/* Loop through all cargos in the refit mask */
2010-01-10 21:45:32 +00:00
const CargoSpec * cs ;
FOR_ALL_CARGOSPECS ( cs ) {
CargoID cid = cs - > Index ( ) ;
2006-10-01 12:00:32 +00:00
/* Skip cargo type if it's not listed */
2007-11-19 21:02:30 +00:00
if ( ! HasBit ( cmask , cid ) ) continue ;
2006-10-08 19:28:55 +00:00
2006-10-01 12:00:32 +00:00
/* Check the vehicle's callback mask for cargo suffixes */
2009-09-14 12:22:57 +00:00
if ( HasBit ( callback_mask , CBM_VEHICLE_CARGO_SUFFIX ) ) {
2006-10-01 12:00:32 +00:00
/* Make a note of the original cargo type. It has to be
* changed to test the cargo & subtype . . . */
CargoID temp_cargo = u - > cargo_type ;
byte temp_subtype = u - > cargo_subtype ;
2007-02-22 22:09:51 +00:00
u - > cargo_type = cid ;
2006-10-01 12:00:32 +00:00
2010-01-10 21:45:32 +00:00
for ( uint refit_cyc = 0 ; refit_cyc < MAX_REFIT_CYCLE ; refit_cyc + + ) {
2006-10-01 12:00:32 +00:00
u - > cargo_subtype = refit_cyc ;
2009-12-13 22:19:19 +00:00
/* Make sure we don't pick up anything cached. */
u - > First ( ) - > InvalidateNewGRFCache ( ) ;
u - > InvalidateNewGRFCache ( ) ;
2010-01-10 21:45:32 +00:00
uint16 callback = GetVehicleCallback ( CBID_VEHICLE_CARGO_SUFFIX , 0 , 0 , u - > engine_type , u ) ;
2006-10-01 12:00:32 +00:00
if ( callback = = 0xFF ) callback = CALLBACK_FAILED ;
if ( refit_cyc ! = 0 & & callback = = CALLBACK_FAILED ) break ;
2010-01-10 21:45:32 +00:00
RefitOption option ;
option . cargo = cid ;
option . subtype = refit_cyc ;
option . value = callback ;
option . engine = u - > engine_type ;
refit_list - > Include ( option ) ;
2006-10-01 12:00:32 +00:00
}
/* Reset the vehicle's cargo type */
u - > cargo_type = temp_cargo ;
u - > cargo_subtype = temp_subtype ;
2009-12-13 22:19:19 +00:00
/* And make sure we haven't tainted the cache */
u - > First ( ) - > InvalidateNewGRFCache ( ) ;
u - > InvalidateNewGRFCache ( ) ;
2006-10-01 12:00:32 +00:00
} else {
/* No cargo suffix callback -- use no subtype */
2010-01-10 21:45:32 +00:00
RefitOption option ;
option . cargo = cid ;
option . subtype = 0 ;
option . value = CALLBACK_FAILED ;
option . engine = INVALID_ENGINE ;
refit_list - > Include ( option ) ;
2006-10-01 12:00:32 +00:00
}
}
2010-01-10 21:45:32 +00:00
} while ( ( v - > type = = VEH_TRAIN | | v - > type = = VEH_ROAD ) & & ( u = u - > Next ( ) ) ! = NULL ) ;
2006-10-01 12:00:32 +00:00
}
2009-10-24 21:10:57 +00:00
/** Draw the list of available refit options for a consist and highlight the selected refit option (if any).
* @ param * list First vehicle in consist to get the refit - options of
* @ param sel Selected refit cargo - type in the window
* @ param pos Position of the selected item in caller widow
* @ param rows Number of rows ( capacity ) in caller window
* @ param delta Step height in caller window
* @ param r Rectangle of the matrix widget .
2005-05-14 12:36:16 +00:00
*/
2010-01-10 21:45:32 +00:00
static void DrawVehicleRefitWindow ( const RefitList & list , int sel , uint pos , uint rows , uint delta , const Rect & r )
2005-05-14 12:36:16 +00:00
{
2009-10-24 21:10:57 +00:00
uint y = r . top + WD_MATRIX_TOP ;
2006-10-01 12:00:32 +00:00
/* Draw the list, and find the selected cargo (by its position in list) */
2010-01-10 21:45:32 +00:00
for ( uint i = pos ; i < pos + rows & & i < list . Length ( ) ; i + + ) {
2009-10-24 18:37:23 +00:00
TextColour colour = ( sel = = ( int ) i ) ? TC_WHITE : TC_BLACK ;
2010-01-10 21:45:32 +00:00
const RefitOption * refit = & list [ i ] ;
2005-05-14 12:36:16 +00:00
2009-11-16 13:19:39 +00:00
/* Get the cargo name */
SetDParam ( 0 , CargoSpec : : Get ( refit - > cargo ) - > name ) ;
2006-10-01 12:00:32 +00:00
2009-10-24 18:37:23 +00:00
/* If the callback succeeded, draw the cargo suffix */
if ( refit - > value ! = CALLBACK_FAILED ) {
2009-11-16 13:19:39 +00:00
SetDParam ( 1 , GetGRFStringID ( GetEngineGRFID ( refit - > engine ) , 0xD000 + refit - > value ) ) ;
DrawString ( r . left + WD_MATRIX_LEFT , r . right - WD_MATRIX_RIGHT , y , STR_JUST_STRING_SPACE_STRING , colour ) ;
} else {
DrawString ( r . left + WD_MATRIX_LEFT , r . right - WD_MATRIX_RIGHT , y , STR_JUST_STRING , colour ) ;
2005-05-14 12:36:16 +00:00
}
2009-11-16 13:19:39 +00:00
2009-10-24 18:37:23 +00:00
y + = delta ;
2006-02-14 09:31:05 +00:00
}
2005-05-14 12:36:16 +00:00
}
2009-04-13 08:40:40 +00:00
/** Widget numbers of the vehicle refit window. */
enum VehicleRefitWidgets {
VRW_CAPTION ,
VRW_SELECTHEADER ,
VRW_MATRIX ,
VRW_SCROLLBAR ,
VRW_INFOPANEL ,
VRW_REFITBUTTON ,
} ;
2009-10-24 20:26:18 +00:00
/** Refit cargo window. */
2008-05-16 23:23:38 +00:00
struct RefitWindow : public Window {
2009-10-24 20:26:18 +00:00
int sel ; ///< Index in refit options, \c -1 if nothing is selected.
RefitOption * cargo ; ///< Refit option selected by \v sel.
2010-01-10 21:45:32 +00:00
RefitList list ; ///< List of cargo types available for refitting.
2009-10-24 20:26:18 +00:00
uint length ; ///< For trains, the number of vehicles.
VehicleOrderID order ; ///< If not #INVALID_VEH_ORDER_ID, selection is part of a refit order (rather than execute directly).
2008-05-16 23:23:38 +00:00
2009-10-24 20:26:18 +00:00
RefitWindow ( const WindowDesc * desc , const Vehicle * v , VehicleOrderID order ) : Window ( )
2008-05-16 23:23:38 +00:00
{
2009-10-24 20:26:18 +00:00
this - > CreateNestedTree ( desc ) ;
this - > GetWidget < NWidgetCore > ( VRW_SELECTHEADER ) - > tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v - > type ;
this - > GetWidget < NWidgetCore > ( VRW_MATRIX ) - > tool_tip = STR_REFIT_TRAIN_LIST_TOOLTIP + v - > type ;
NWidgetCore * nwi = this - > GetWidget < NWidgetCore > ( VRW_REFITBUTTON ) ;
nwi - > widget_data = STR_REFIT_TRAIN_REFIT_BUTTON + v - > type ;
nwi - > tool_tip = STR_REFIT_TRAIN_REFIT_TOOLTIP + v - > type ;
this - > FinishInitNested ( desc , v - > index ) ;
2009-02-09 02:33:10 +00:00
this - > owner = v - > owner ;
2008-05-16 23:23:38 +00:00
this - > order = order ;
this - > sel = - 1 ;
2010-01-10 21:45:32 +00:00
BuildRefitList ( v , & this - > list ) ;
2008-05-16 23:23:38 +00:00
if ( v - > type = = VEH_TRAIN ) this - > length = CountVehiclesInChain ( v ) ;
2010-01-10 21:45:32 +00:00
this - > vscroll . SetCount ( this - > list . Length ( ) ) ;
2008-05-16 23:23:38 +00:00
}
virtual void OnPaint ( )
{
2009-05-16 23:34:14 +00:00
Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2008-05-16 23:23:38 +00:00
if ( v - > type = = VEH_TRAIN ) {
uint length = CountVehiclesInChain ( v ) ;
if ( length ! = this - > length ) {
/* Consist length has changed, so rebuild the refit list */
2010-01-10 21:45:32 +00:00
BuildRefitList ( v , & this - > list ) ;
2008-05-16 23:23:38 +00:00
this - > length = length ;
2006-10-01 12:00:32 +00:00
}
2008-05-16 23:23:38 +00:00
}
2010-01-10 21:45:32 +00:00
this - > vscroll . SetCount ( this - > list . Length ( ) ) ;
2006-09-27 07:23:38 +00:00
2010-01-10 21:45:32 +00:00
this - > cargo = ( this - > sel > = 0 & & this - > sel < ( int ) this - > list . Length ( ) ) ? & this - > list [ this - > sel ] : NULL ;
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2009-10-24 20:26:18 +00:00
}
2006-10-01 15:03:15 +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-24 20:26:18 +00:00
{
switch ( widget ) {
case VRW_MATRIX :
resize - > height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM ;
size - > height = resize - > height * 8 ;
break ;
}
}
2006-09-27 07:23:38 +00:00
2009-10-24 20:26:18 +00:00
virtual void SetStringParameters ( int widget ) const
{
if ( widget = = VRW_CAPTION ) SetDParam ( 0 , Vehicle : : Get ( this - > window_number ) - > index ) ;
}
2006-09-27 07:23:38 +00:00
2009-10-24 20:26:18 +00:00
virtual void DrawWidget ( const Rect & r , int widget ) const
{
switch ( widget ) {
case VRW_MATRIX :
2009-10-24 21:10:57 +00:00
DrawVehicleRefitWindow ( this - > list , this - > sel , this - > vscroll . GetPosition ( ) , this - > vscroll . GetCapacity ( ) , this - > resize . step_height , r ) ;
2009-10-24 20:26:18 +00:00
break ;
2007-02-17 17:12:19 +00:00
2009-10-24 20:26:18 +00:00
case VRW_INFOPANEL :
if ( this - > cargo ! = NULL ) {
Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
CommandCost cost = DoCommand ( v - > tile , v - > index , this - > cargo - > cargo | this - > cargo - > subtype < < 8 , DC_QUERY_COST , GetCmdRefitVeh ( v - > type ) ) ;
2010-01-18 22:57:21 +00:00
if ( cost . Succeeded ( ) ) {
2009-10-24 20:26:18 +00:00
SetDParam ( 0 , this - > cargo - > cargo ) ;
SetDParam ( 1 , _returned_refit_capacity ) ;
SetDParam ( 2 , cost . GetCost ( ) ) ;
DrawStringMultiLine ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT ,
r . top + WD_FRAMERECT_TOP , r . bottom - WD_FRAMERECT_BOTTOM , STR_REFIT_NEW_CAPACITY_COST_OF_REFIT ) ;
}
}
break ;
2008-05-16 23:23:38 +00:00
}
}
2006-09-27 07:23:38 +00:00
2009-10-27 19:21:42 +00:00
virtual void OnDoubleClick ( Point pt , int widget )
{
if ( widget = = VRW_MATRIX ) this - > OnClick ( pt , VRW_REFITBUTTON ) ;
}
2008-05-16 23:23:38 +00:00
virtual void OnClick ( Point pt , int widget )
{
switch ( widget ) {
2009-04-13 14:04:10 +00:00
case VRW_MATRIX : { // listbox
2009-10-24 20:26:18 +00:00
int y = pt . y - this - > GetWidget < NWidgetBase > ( VRW_MATRIX ) - > pos_y ;
2008-05-16 23:23:38 +00:00
if ( y > = 0 ) {
2009-09-02 08:48:29 +00:00
this - > sel = ( y / ( int ) this - > resize . step_height ) + this - > vscroll . GetPosition ( ) ;
2008-05-16 23:23:38 +00:00
this - > SetDirty ( ) ;
2006-09-27 07:23:38 +00:00
}
2008-05-16 23:23:38 +00:00
break ;
2006-09-27 07:23:38 +00:00
}
2008-05-16 23:23:38 +00:00
2009-04-13 14:04:10 +00:00
case VRW_REFITBUTTON : // refit button
2008-05-16 23:23:38 +00:00
if ( this - > cargo ! = NULL ) {
2009-05-16 23:34:14 +00:00
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2008-05-16 23:23:38 +00:00
if ( this - > order = = INVALID_VEH_ORDER_ID ) {
2009-07-22 23:39:35 +00:00
if ( DoCommandP ( v - > tile , v - > index , this - > cargo - > cargo | this - > cargo - > subtype < < 8 , GetCmdRefitVeh ( v ) ) ) delete this ;
2008-05-16 23:23:38 +00:00
} else {
2008-12-28 14:37:19 +00:00
if ( DoCommandP ( v - > tile , v - > index , this - > cargo - > cargo | this - > cargo - > subtype < < 8 | this - > order < < 16 , CMD_ORDER_REFIT ) ) delete this ;
2006-09-27 07:23:38 +00:00
}
2008-05-16 23:23:38 +00:00
}
break ;
}
}
2006-10-01 12:00:32 +00:00
2009-10-24 14:53:55 +00:00
virtual void OnResize ( )
2008-05-16 23:23:38 +00:00
{
2009-12-20 20:08:39 +00:00
this - > vscroll . SetCapacityFromWidget ( this , VRW_MATRIX ) ;
this - > GetWidget < NWidgetCore > ( VRW_MATRIX ) - > widget_data = ( this - > vscroll . GetCapacity ( ) < < MAT_ROW_START ) + ( 1 < < MAT_COL_START ) ;
2006-09-27 07:23:38 +00:00
}
2008-05-16 23:23:38 +00:00
} ;
2006-09-27 07:23:38 +00:00
2009-04-13 14:09:56 +00:00
static const NWidgetPart _nested_vehicle_refit_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2009-04-21 23:40:56 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , VRW_CAPTION ) , SetDataTip ( STR_REFIT_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2009-04-13 14:09:56 +00:00
EndContainer ( ) ,
2009-11-22 19:40:48 +00:00
NWidget ( WWT_TEXTBTN , COLOUR_GREY , VRW_SELECTHEADER ) , SetDataTip ( STR_REFIT_TITLE , STR_NULL ) , SetResize ( 1 , 0 ) ,
2009-04-13 14:09:56 +00:00
/* Matrix + scrollbar. */
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 19:40:48 +00:00
NWidget ( WWT_MATRIX , COLOUR_GREY , VRW_MATRIX ) , SetMinimalSize ( 228 , 112 ) , SetResize ( 1 , 14 ) , SetFill ( 1 , 1 ) , SetDataTip ( 0x801 , STR_NULL ) ,
2009-04-13 14:09:56 +00:00
NWidget ( WWT_SCROLLBAR , COLOUR_GREY , VRW_SCROLLBAR ) ,
EndContainer ( ) ,
2009-11-22 19:40:48 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY , VRW_INFOPANEL ) , SetMinimalTextLines ( 2 , WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
2009-04-13 14:09:56 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 19:40:48 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VRW_REFITBUTTON ) , SetFill ( 1 , 0 ) , SetResize ( 1 , 0 ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_RESIZEBOX , COLOUR_GREY ) ,
2009-04-13 14:09:56 +00:00
EndContainer ( ) ,
} ;
2009-03-15 15:12:06 +00:00
static const WindowDesc _vehicle_refit_desc (
2009-11-28 14:42:35 +00:00
WDP_AUTO , 240 , 174 ,
2007-04-18 22:10:36 +00:00
WC_VEHICLE_REFIT , WC_VEHICLE_VIEW ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS | WDF_CONSTRUCTION ,
2009-11-15 10:26:01 +00:00
_nested_vehicle_refit_widgets , lengthof ( _nested_vehicle_refit_widgets )
2009-03-15 15:12:06 +00:00
) ;
2006-09-27 07:23:38 +00:00
/** Show the refit window for a vehicle
2009-03-14 18:16:29 +00:00
* @ param * v The vehicle to show the refit window for
* @ param order of the vehicle ( ? )
2009-09-19 09:51:14 +00:00
* @ param parent the parent window of the refit window
2009-03-14 18:16:29 +00:00
*/
2008-09-24 16:40:06 +00:00
void ShowVehicleRefitWindow ( const Vehicle * v , VehicleOrderID order , Window * parent )
2006-09-27 07:23:38 +00:00
{
DeleteWindowById ( WC_VEHICLE_REFIT , v - > index ) ;
2008-09-24 16:40:06 +00:00
RefitWindow * w = new RefitWindow ( & _vehicle_refit_desc , v , order ) ;
w - > parent = parent ;
2006-09-27 07:23:38 +00:00
}
2007-04-04 04:08:47 +00:00
/** Display list of cargo types of the engine, for the purchase information window */
2009-03-22 11:06:25 +00:00
uint ShowRefitOptionsList ( int left , int right , int y , EngineID engine )
2006-10-23 21:39:15 +00:00
{
/* List of cargo types of this engine */
2009-10-06 19:52:38 +00:00
uint32 cmask = GetUnionOfArticulatedRefitMasks ( engine , false ) ;
2006-10-23 21:39:15 +00:00
/* List of cargo types available in this climate */
2007-02-22 22:09:51 +00:00
uint32 lmask = _cargo_mask ;
2008-07-17 13:47:04 +00:00
char string [ 512 ] ;
char * b = string ;
2006-10-23 21:39:15 +00:00
/* Draw nothing if the engine is not refittable */
2009-03-22 11:06:25 +00:00
if ( CountBits ( cmask ) < = 1 ) return y ;
2006-10-23 21:39:15 +00:00
b = InlineString ( b , STR_PURCHASE_INFO_REFITTABLE_TO ) ;
if ( cmask = = lmask ) {
/* Engine can be refitted to all types in this climate */
b = InlineString ( b , STR_PURCHASE_INFO_ALL_TYPES ) ;
} else {
/* Check if we are able to refit to more cargo types and unable to. If
* so , invert the cargo types to list those that we can ' t refit to . */
2007-11-04 22:47:34 +00:00
if ( CountBits ( cmask ^ lmask ) < CountBits ( cmask ) ) {
2006-10-23 21:39:15 +00:00
cmask ^ = lmask ;
b = InlineString ( b , STR_PURCHASE_INFO_ALL_BUT ) ;
}
2007-02-22 22:09:51 +00:00
bool first = true ;
2006-10-23 21:39:15 +00:00
/* Add each cargo type to the list */
2007-02-22 22:09:51 +00:00
for ( CargoID cid = 0 ; cid < NUM_CARGO ; cid + + ) {
2007-11-19 21:02:30 +00:00
if ( ! HasBit ( cmask , cid ) ) continue ;
2007-02-22 22:09:51 +00:00
2008-07-17 13:47:04 +00:00
if ( b > = lastof ( string ) - ( 2 + 2 * 4 ) ) break ; // ", " and two calls to Utf8Encode()
2007-12-08 18:50:39 +00:00
2008-07-17 13:47:04 +00:00
if ( ! first ) b = strecpy ( b , " , " , lastof ( string ) ) ;
2007-02-22 22:09:51 +00:00
first = false ;
2006-10-23 21:39:15 +00:00
2009-07-16 19:00:13 +00:00
b = InlineString ( b , CargoSpec : : Get ( cid ) - > name ) ;
2006-10-23 21:39:15 +00:00
}
}
/* Terminate and display the completed string */
* b = ' \0 ' ;
2007-12-08 18:50:39 +00:00
/* Make sure we detect any buffer overflow */
2008-07-17 13:47:04 +00:00
assert ( b < endof ( string ) ) ;
2007-12-08 18:50:39 +00:00
2008-07-17 21:15:57 +00:00
SetDParamStr ( 0 , string ) ;
2009-03-22 11:06:25 +00:00
return DrawStringMultiLine ( left , right , y , INT32_MAX , STR_JUST_RAW_STRING ) ;
2006-10-23 21:39:15 +00:00
}
2009-02-14 18:42:03 +00:00
/** Get the cargo subtype text from NewGRF for the vehicle details window. */
StringID GetCargoSubtypeText ( const Vehicle * v )
{
2009-09-14 12:22:57 +00:00
if ( HasBit ( EngInfo ( v - > engine_type ) - > callback_mask , CBM_VEHICLE_CARGO_SUFFIX ) ) {
2009-02-14 18:42:03 +00:00
uint16 cb = GetVehicleCallback ( CBID_VEHICLE_CARGO_SUFFIX , 0 , 0 , v - > engine_type , v ) ;
if ( cb ! = CALLBACK_FAILED ) {
return GetGRFStringID ( GetEngineGRFID ( v - > engine_type ) , 0xD000 + cb ) ;
}
}
return STR_EMPTY ;
}
2004-09-06 18:15:13 +00:00
2008-06-15 22:10:22 +00:00
/** Sort vehicles by their number */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleNumberSorter ( const Vehicle * const * a , const Vehicle * const * b )
2004-09-06 21:20:01 +00:00
{
2008-06-15 22:10:22 +00:00
return ( * a ) - > unitnumber - ( * b ) - > unitnumber ;
2004-09-06 21:20:01 +00:00
}
2008-06-15 22:10:22 +00:00
/** Sort vehicles by their name */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleNameSorter ( const Vehicle * const * a , const Vehicle * const * b )
2004-09-06 18:15:13 +00:00
{
2008-06-15 22:10:22 +00:00
static char last_name [ 2 ] [ 64 ] ;
2004-09-06 18:15:13 +00:00
2008-06-15 22:10:22 +00:00
if ( * a ! = _last_vehicle [ 0 ] ) {
_last_vehicle [ 0 ] = * a ;
SetDParam ( 0 , ( * a ) - > index ) ;
GetString ( last_name [ 0 ] , STR_VEHICLE_NAME , lastof ( last_name [ 0 ] ) ) ;
2004-09-06 18:15:13 +00:00
}
2008-06-15 22:10:22 +00:00
if ( * b ! = _last_vehicle [ 1 ] ) {
_last_vehicle [ 1 ] = * b ;
SetDParam ( 0 , ( * b ) - > index ) ;
GetString ( last_name [ 1 ] , STR_VEHICLE_NAME , lastof ( last_name [ 1 ] ) ) ;
}
2004-09-06 21:20:01 +00:00
2008-06-15 22:10:22 +00:00
int r = strcmp ( last_name [ 0 ] , last_name [ 1 ] ) ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2004-09-06 18:15:13 +00:00
}
2008-06-15 22:10:22 +00:00
/** Sort vehicles by their age */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleAgeSorter ( const Vehicle * const * a , const Vehicle * const * b )
2004-09-06 18:15:13 +00:00
{
2008-06-15 22:10:22 +00:00
int r = ( * a ) - > age - ( * b ) - > age ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2004-09-06 21:20:01 +00:00
}
2008-06-15 22:10:22 +00:00
/** Sort vehicles by this year profit */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleProfitThisYearSorter ( const Vehicle * const * a , const Vehicle * const * b )
2004-09-06 21:20:01 +00:00
{
2008-06-15 22:10:22 +00:00
int r = ClampToI32 ( ( * a ) - > GetDisplayProfitThisYear ( ) - ( * b ) - > GetDisplayProfitThisYear ( ) ) ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2004-09-06 21:20:01 +00:00
}
2008-06-15 22:10:22 +00:00
/** Sort vehicles by last year profit */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleProfitLastYearSorter ( const Vehicle * const * a , const Vehicle * const * b )
2004-09-06 21:20:01 +00:00
{
2008-06-15 22:10:22 +00:00
int r = ClampToI32 ( ( * a ) - > GetDisplayProfitLastYear ( ) - ( * b ) - > GetDisplayProfitLastYear ( ) ) ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2004-09-06 21:20:01 +00:00
}
2008-06-15 22:10:22 +00:00
/** Sort vehicles by their cargo */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleCargoSorter ( const Vehicle * const * a , const Vehicle * const * b )
2004-09-06 21:20:01 +00:00
{
2008-06-15 22:10:22 +00:00
const Vehicle * v ;
2009-06-27 18:26:50 +00:00
CargoArray diff ;
2004-09-06 21:20:01 +00:00
2008-06-15 22:10:22 +00:00
/* Append the cargo of the connected weagons */
for ( v = * a ; v ! = NULL ; v = v - > Next ( ) ) diff [ v - > cargo_type ] + = v - > cargo_cap ;
for ( v = * b ; v ! = NULL ; v = v - > Next ( ) ) diff [ v - > cargo_type ] - = v - > cargo_cap ;
2004-09-06 21:20:01 +00:00
2008-06-15 22:10:22 +00:00
int r = 0 ;
2007-03-21 13:19:01 +00:00
for ( CargoID i = 0 ; i < NUM_CARGO ; i + + ) {
2008-06-15 22:10:22 +00:00
r = diff [ i ] ;
2005-10-23 13:04:44 +00:00
if ( r ! = 0 ) break ;
2004-09-06 18:15:13 +00:00
}
2004-09-06 21:20:01 +00:00
2008-06-15 22:10:22 +00:00
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2004-09-06 21:20:01 +00:00
}
2008-06-15 22:10:22 +00:00
/** Sort vehicles by their reliability */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleReliabilitySorter ( const Vehicle * const * a , const Vehicle * const * b )
2004-09-06 21:20:01 +00:00
{
2008-06-15 22:10:22 +00:00
int r = ( * a ) - > reliability - ( * b ) - > reliability ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2004-09-06 18:15:13 +00:00
}
2004-09-06 21:20:01 +00:00
2008-06-15 22:10:22 +00:00
/** Sort vehicles by their max speed */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleMaxSpeedSorter ( const Vehicle * const * a , const Vehicle * const * b )
2004-09-06 21:20:01 +00:00
{
2008-06-15 22:10:22 +00:00
int r = 0 ;
if ( ( * a ) - > type = = VEH_TRAIN & & ( * b ) - > type = = VEH_TRAIN ) {
2009-06-06 16:54:22 +00:00
r = Train : : From ( * a ) - > tcache . cached_max_speed - Train : : From ( * b ) - > tcache . cached_max_speed ;
2005-01-27 11:33:14 +00:00
} else {
2008-06-15 22:10:22 +00:00
r = ( * a ) - > max_speed - ( * b ) - > max_speed ;
2005-01-27 11:33:14 +00:00
}
2008-06-15 22:10:22 +00:00
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2004-09-10 19:02:27 +00:00
}
2005-01-02 17:23:04 +00:00
2008-06-15 22:10:22 +00:00
/** Sort vehicles by model */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleModelSorter ( const Vehicle * const * a , const Vehicle * const * b )
2006-02-03 18:32:59 +00:00
{
2008-06-15 22:10:22 +00:00
int r = ( * a ) - > engine_type - ( * b ) - > engine_type ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2006-02-03 18:32:59 +00:00
}
2008-06-15 22:10:22 +00:00
/** Sort vehciles by their value */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleValueSorter ( const Vehicle * const * a , const Vehicle * const * b )
2006-02-03 18:32:59 +00:00
{
const Vehicle * u ;
2008-06-15 22:10:22 +00:00
Money diff = 0 ;
2006-02-03 18:32:59 +00:00
2008-06-15 22:10:22 +00:00
for ( u = * a ; u ! = NULL ; u = u - > Next ( ) ) diff + = u - > value ;
for ( u = * b ; u ! = NULL ; u = u - > Next ( ) ) diff - = u - > value ;
2006-02-03 18:32:59 +00:00
2008-06-15 22:10:22 +00:00
int r = ClampToI32 ( diff ) ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2006-02-03 18:32:59 +00:00
}
2008-06-15 22:10:22 +00:00
/** Sort vehicles by their length */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleLengthSorter ( const Vehicle * const * a , const Vehicle * const * b )
2008-04-18 10:58:11 +00:00
{
int r = 0 ;
2008-06-15 22:10:22 +00:00
switch ( ( * a ) - > type ) {
2008-04-18 10:58:11 +00:00
case VEH_TRAIN :
2009-06-06 16:54:22 +00:00
r = Train : : From ( * a ) - > tcache . cached_total_length - Train : : From ( * b ) - > tcache . cached_total_length ;
2008-04-18 10:58:11 +00:00
break ;
2008-06-15 22:10:22 +00:00
case VEH_ROAD : {
2009-05-22 20:22:20 +00:00
const RoadVehicle * u ;
2009-06-06 16:54:22 +00:00
for ( u = RoadVehicle : : From ( * a ) ; u ! = NULL ; u = u - > Next ( ) ) r + = u - > rcache . cached_veh_length ;
for ( u = RoadVehicle : : From ( * b ) ; u ! = NULL ; u = u - > Next ( ) ) r - = u - > rcache . cached_veh_length ;
2008-06-15 22:10:22 +00:00
} break ;
2008-04-18 10:58:11 +00:00
default : NOT_REACHED ( ) ;
}
2008-06-15 22:10:22 +00:00
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
2008-04-18 10:58:11 +00:00
}
2008-09-17 02:30:24 +00:00
/** Sort vehicles by the time they can still live */
2009-01-10 00:31:47 +00:00
static int CDECL VehicleTimeToLiveSorter ( const Vehicle * const * a , const Vehicle * const * b )
2008-09-17 02:30:24 +00:00
{
int r = ClampToI32 ( ( ( * a ) - > max_age - ( * a ) - > age ) - ( ( * b ) - > max_age - ( * b ) - > age ) ) ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
}
2009-08-15 10:51:33 +00:00
/** Sort vehicles by the timetable delay */
static int CDECL VehicleTimetableDelaySorter ( const Vehicle * const * a , const Vehicle * const * b )
{
int r = ( * a ) - > lateness_counter - ( * b ) - > lateness_counter ;
return ( r ! = 0 ) ? r : VehicleNumberSorter ( a , b ) ;
}
2007-03-07 11:47:46 +00:00
void InitializeGUI ( )
2005-01-31 11:03:23 +00:00
{
2008-06-15 22:10:22 +00:00
MemSetT ( & _sorting , 0 ) ;
2005-01-31 11:03:23 +00:00
}
2005-10-24 19:40:48 +00:00
2008-08-06 18:57:37 +00:00
/**
* Assign a vehicle window a new vehicle
* @ param window_class WindowClass to search for
* @ param from_index the old vehicle ID
* @ param to_index the new vehicle ID
2005-11-14 19:48:04 +00:00
*/
2008-08-06 18:57:37 +00:00
static inline void ChangeVehicleWindow ( WindowClass window_class , VehicleID from_index , VehicleID to_index )
2005-10-24 19:40:48 +00:00
{
2008-08-06 18:57:37 +00:00
Window * w = FindWindowById ( window_class , from_index ) ;
2005-10-24 19:40:48 +00:00
if ( w ! = NULL ) {
2008-04-27 18:05:48 +00:00
w - > window_number = to_index ;
2008-08-06 18:57:37 +00:00
if ( w - > viewport ! = NULL ) w - > viewport - > follow_vehicle = to_index ;
2009-09-30 21:00:35 +00:00
if ( to_index ! = INVALID_VEHICLE ) w - > InvalidateData ( ) ;
2005-10-24 19:40:48 +00:00
}
}
2006-08-29 17:41:13 +00:00
2008-08-06 18:57:37 +00:00
/**
* Report a change in vehicle IDs ( due to autoreplace ) to affected vehicle windows .
* @ param from_index the old vehicle ID
* @ param to_index the new vehicle ID
*/
void ChangeVehicleViewWindow ( VehicleID from_index , VehicleID to_index )
{
ChangeVehicleWindow ( WC_VEHICLE_VIEW , from_index , to_index ) ;
ChangeVehicleWindow ( WC_VEHICLE_ORDERS , from_index , to_index ) ;
ChangeVehicleWindow ( WC_VEHICLE_REFIT , from_index , to_index ) ;
ChangeVehicleWindow ( WC_VEHICLE_DETAILS , from_index , to_index ) ;
ChangeVehicleWindow ( WC_VEHICLE_TIMETABLE , from_index , to_index ) ;
}
2006-12-07 00:51:20 +00:00
enum VehicleListWindowWidgets {
2006-09-28 23:05:03 +00:00
VLW_WIDGET_CAPTION ,
VLW_WIDGET_SORT_ORDER ,
VLW_WIDGET_SORT_BY_PULLDOWN ,
VLW_WIDGET_LIST ,
VLW_WIDGET_SCROLLBAR ,
2009-10-25 15:08:16 +00:00
VLW_WIDGET_HIDE_BUTTONS ,
2007-01-26 19:24:02 +00:00
VLW_WIDGET_AVAILABLE_VEHICLES ,
2006-12-07 14:03:55 +00:00
VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN ,
2006-09-29 11:30:48 +00:00
VLW_WIDGET_STOP_ALL ,
VLW_WIDGET_START_ALL ,
2006-09-28 23:05:03 +00:00
} ;
2009-03-22 21:16:57 +00:00
static const NWidgetPart _nested_vehicle_list [ ] = {
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 , VLW_WIDGET_CAPTION ) ,
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-22 21:16:57 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VLW_WIDGET_SORT_ORDER ) , SetMinimalSize ( 81 , 12 ) , SetFill ( 0 , 1 ) , SetDataTip ( STR_BUTTON_SORT_BY , STR_TOOLTIP_SORT_ORDER ) ,
NWidget ( WWT_DROPDOWN , COLOUR_GREY , VLW_WIDGET_SORT_BY_PULLDOWN ) , SetMinimalSize ( 167 , 12 ) , SetFill ( 0 , 1 ) , SetDataTip ( 0x0 , STR_TOOLTIP_SORT_CRITERIAP ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) , SetMinimalSize ( 12 , 12 ) , SetFill ( 1 , 1 ) , SetResize ( 1 , 0 ) ,
2009-03-22 21:16:57 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_MATRIX , COLOUR_GREY , VLW_WIDGET_LIST ) , SetMinimalSize ( 248 , 0 ) , SetFill ( 1 , 0 ) ,
2009-11-22 11:24:30 +00:00
NWidget ( WWT_SCROLLBAR , COLOUR_GREY , VLW_WIDGET_SCROLLBAR ) ,
2009-03-22 21:16:57 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-10-25 15:08:16 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , VLW_WIDGET_HIDE_BUTTONS ) ,
2009-03-22 21:16:57 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VLW_WIDGET_AVAILABLE_VEHICLES ) , SetMinimalSize ( 106 , 12 ) , SetFill ( 0 , 1 ) ,
2009-08-05 17:59:21 +00:00
SetDataTip ( 0x0 , STR_VEHICLE_LIST_AVAILABLE_ENGINES_TOOLTIP ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_DROPDOWN , COLOUR_GREY , VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN ) , SetMinimalSize ( 118 , 12 ) , SetFill ( 0 , 1 ) ,
2009-08-05 17:59:21 +00:00
SetDataTip ( STR_VEHICLE_LIST_MANAGE_LIST , STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VLW_WIDGET_STOP_ALL ) , SetMinimalSize ( 12 , 12 ) , SetFill ( 0 , 1 ) ,
2009-08-05 17:59:21 +00:00
SetDataTip ( SPR_FLAG_VEH_STOPPED , STR_VEHICLE_LIST_MASS_STOP_LIST_TOOLTIP ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VLW_WIDGET_START_ALL ) , SetMinimalSize ( 12 , 12 ) , SetFill ( 0 , 1 ) ,
2009-08-05 17:59:21 +00:00
SetDataTip ( SPR_FLAG_VEH_RUNNING , STR_VEHICLE_LIST_MASS_START_LIST_TOOLTIP ) ,
2009-12-09 08:23:10 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) , SetMinimalSize ( 0 , 12 ) , SetResize ( 1 , 0 ) , SetFill ( 1 , 1 ) , EndContainer ( ) ,
2009-03-22 21:16:57 +00:00
EndContainer ( ) ,
2009-10-25 15:08:16 +00:00
/* Widget to be shown for other companies hiding the previous 5 widgets. */
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) , SetFill ( 1 , 1 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
2009-03-22 21:16:57 +00:00
EndContainer ( ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_RESIZEBOX , COLOUR_GREY ) ,
2009-03-22 21:16:57 +00:00
EndContainer ( ) ,
} ;
2009-11-26 11:34:12 +00:00
static void DrawSmallOrderList ( const Vehicle * v , int left , int right , int y , VehicleOrderID start = 0 )
2006-10-05 08:15:51 +00:00
{
2009-11-26 11:34:12 +00:00
const Order * order = v - > GetOrder ( start ) ;
if ( order = = NULL ) return ;
2006-10-05 08:15:51 +00:00
2009-11-26 11:34:12 +00:00
int i = 0 ;
VehicleOrderID oid = start ;
2006-10-05 08:15:51 +00:00
2009-11-26 11:34:12 +00:00
do {
if ( oid = = v - > cur_order_index ) DrawString ( left , right , y , STR_TINY_RIGHT_ARROW , TC_BLACK ) ;
2006-10-05 08:15:51 +00:00
2008-04-05 23:36:54 +00:00
if ( order - > IsType ( OT_GOTO_STATION ) ) {
2008-04-06 07:48:51 +00:00
SetDParam ( 0 , order - > GetDestination ( ) ) ;
2009-11-17 11:36:36 +00:00
DrawString ( left + 6 , right - 6 , y , STR_TINY_BLACK_STATION ) ;
2006-10-05 08:15:51 +00:00
2009-11-16 21:39:47 +00:00
y + = FONT_HEIGHT_SMALL ;
2006-10-05 08:15:51 +00:00
if ( + + i = = 4 ) break ;
}
2009-11-26 11:34:12 +00:00
oid + + ;
order = order - > next ;
if ( order = = NULL ) {
order = v - > orders . list - > GetFirstOrder ( ) ;
oid = 0 ;
}
} while ( oid ! = start ) ;
2006-10-05 08:15:51 +00:00
}
2009-07-12 16:00:11 +00:00
/**
* Draws an image of a vehicle chain
2009-11-16 22:25:01 +00:00
* @ param v Front vehicle
* @ param left The minimum horizontal position
* @ param right The maximum horizontal position
* @ param y Vertical position to draw at
2009-09-19 09:51:14 +00:00
* @ param selection Selected vehicle to draw a frame around
2009-11-16 22:25:01 +00:00
* @ param skip Number of pixels to skip at the front ( for scrolling )
2009-07-12 16:00:11 +00:00
*/
2009-11-16 22:25:01 +00:00
static void DrawVehicleImage ( const Vehicle * v , int left , int right , int y , VehicleID selection , int skip )
2008-09-13 10:04:36 +00:00
{
switch ( v - > type ) {
2009-11-16 22:25:01 +00:00
case VEH_TRAIN : DrawTrainImage ( Train : : From ( v ) , left , right , y , selection , skip ) ; break ;
case VEH_ROAD : DrawRoadVehImage ( v , left , right , y , selection ) ; break ;
case VEH_SHIP : DrawShipImage ( v , left , right , y , selection ) ; break ;
case VEH_AIRCRAFT : DrawAircraftImage ( v , left , right , y , selection ) ; break ;
2008-09-13 10:04:36 +00:00
default : NOT_REACHED ( ) ;
}
}
2009-11-16 21:28:12 +00:00
/**
* Get the height of a vehicle in the vehicle list GUIs .
* @ param type the vehicle type to look at
* @ param divisor the resulting height must be dividable by this
* @ return the height
*/
uint GetVehicleListHeight ( VehicleType type , uint divisor )
{
2009-11-16 21:39:47 +00:00
/* Name + vehicle + profit */
2009-11-16 21:28:12 +00:00
uint base = GetVehicleHeight ( type ) + 2 * FONT_HEIGHT_SMALL ;
2009-11-16 21:39:47 +00:00
/* Drawing of the 4 small orders + profit*/
if ( type > = VEH_SHIP ) base = max ( base , 5U * FONT_HEIGHT_SMALL ) ;
2009-11-16 21:28:12 +00:00
if ( divisor = = 1 ) return base ;
/* Make sure the height is dividable by divisor */
uint rem = base % divisor ;
return base + ( rem = = 0 ? 0 : divisor - rem ) ;
}
2008-09-13 10:04:36 +00:00
/**
* Draw all the vehicle list items .
2009-10-25 13:33:56 +00:00
* @ param selected_vehicle The vehicle that is to be highlighted .
* @ param line_height Height of a single item line .
* @ param r Rectangle with edge positions of the matrix widget .
2008-09-13 10:04:36 +00:00
*/
2009-10-25 14:52:46 +00:00
void BaseVehicleListWindow : : DrawVehicleListItems ( VehicleID selected_vehicle , int line_height , const Rect & r ) const
2008-09-13 10:04:36 +00:00
{
2009-10-25 13:33:56 +00:00
int left = r . left + WD_MATRIX_LEFT ;
int right = r . right - WD_MATRIX_RIGHT ;
2009-11-17 11:36:36 +00:00
int width = right - left ;
2009-11-16 21:28:12 +00:00
bool rtl = _dynlang . text_dir = = TD_RTL ;
2009-12-20 16:44:41 +00:00
int text_offset = GetDigitWidth ( ) * this - > unitnumber_digits + WD_FRAMERECT_RIGHT ;
2009-11-17 09:09:20 +00:00
int text_left = left + ( rtl ? 0 : text_offset ) ;
int text_right = right - ( rtl ? text_offset : 0 ) ;
2009-11-16 21:28:12 +00:00
2009-11-17 11:36:36 +00:00
bool show_orderlist = vehicle_type > = VEH_SHIP ;
int orderlist_left = left + ( rtl ? 0 : max ( 100 + text_offset , width / 2 ) ) ;
int orderlist_right = right - ( rtl ? max ( 100 + text_offset , width / 2 ) : 0 ) ;
int image_left = ( rtl & & show_orderlist ) ? orderlist_right : text_left ;
int image_right = ( ! rtl & & show_orderlist ) ? orderlist_left : text_right ;
2009-11-16 21:28:12 +00:00
int vehicle_button_x = rtl ? right - 8 : left ;
2009-10-25 13:33:56 +00:00
int y = r . top ;
2009-09-02 08:48:29 +00:00
uint max = min ( this - > vscroll . GetPosition ( ) + this - > vscroll . GetCapacity ( ) , this - > vehicles . Length ( ) ) ;
for ( uint i = this - > vscroll . GetPosition ( ) ; i < max ; + + i ) {
2008-09-13 10:04:36 +00:00
const Vehicle * v = this - > vehicles [ i ] ;
StringID str ;
SetDParam ( 0 , v - > GetDisplayProfitThisYear ( ) ) ;
SetDParam ( 1 , v - > GetDisplayProfitLastYear ( ) ) ;
2009-11-17 11:36:36 +00:00
DrawVehicleImage ( v , image_left , image_right , y + FONT_HEIGHT_SMALL - 1 , selected_vehicle , 0 ) ;
2009-11-16 21:28:12 +00:00
DrawString ( text_left , text_right , y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1 , STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR ) ;
2008-09-13 10:04:36 +00:00
if ( v - > name ! = NULL ) {
/* The vehicle got a name so we will print it */
SetDParam ( 0 , v - > index ) ;
2009-11-16 21:28:12 +00:00
DrawString ( text_left , text_right , y , STR_TINY_BLACK_VEHICLE ) ;
2008-11-20 16:48:22 +00:00
} else if ( v - > group_id ! = DEFAULT_GROUP ) {
/* The vehicle has no name, but is member of a group, so print group name */
SetDParam ( 0 , v - > group_id ) ;
2009-11-16 21:28:12 +00:00
DrawString ( text_left , text_right , y , STR_TINY_GROUP , TC_BLACK ) ;
2008-09-13 10:04:36 +00:00
}
2009-11-26 11:34:12 +00:00
if ( show_orderlist ) DrawSmallOrderList ( v , orderlist_left , orderlist_right , y , v - > cur_order_index ) ;
2008-09-13 10:04:36 +00:00
if ( v - > IsInDepot ( ) ) {
2009-07-23 19:31:50 +00:00
str = STR_BLUE_COMMA ;
2008-09-13 10:04:36 +00:00
} else {
2009-04-21 23:40:56 +00:00
str = ( v - > age > v - > max_age - DAYS_IN_LEAP_YEAR ) ? STR_RED_COMMA : STR_BLACK_COMMA ;
2008-09-13 10:04:36 +00:00
}
SetDParam ( 0 , v - > unitnumber ) ;
2009-08-15 11:47:11 +00:00
DrawString ( left , right , y + 2 , str ) ;
2008-09-13 10:04:36 +00:00
2009-11-16 21:28:12 +00:00
DrawVehicleProfitButton ( v , vehicle_button_x , y + FONT_HEIGHT_NORMAL + 3 ) ;
2008-09-13 10:04:36 +00:00
2009-10-25 13:33:56 +00:00
y + = line_height ;
2008-09-13 10:04:36 +00:00
}
}
2008-05-11 15:00:11 +00:00
/**
* Window for the ( old ) vehicle listing .
*
* bitmask for w - > window_number
2008-09-30 20:39:50 +00:00
* 0 - 7 CompanyID ( owner )
2008-05-11 15:00:11 +00:00
* 8 - 10 window type ( use flags in vehicle_gui . h )
* 11 - 15 vehicle type ( using VEH_ , but can be compressed to fewer bytes if needed )
* 16 - 31 StationID or OrderID depending on window type ( bit 8 - 10 )
*/
2008-09-13 10:04:36 +00:00
struct VehicleListWindow : public BaseVehicleListWindow {
2009-10-25 15:08:16 +00:00
private :
/** Enumeration of planes of the button row at the bottom. */
enum ButtonPlanes {
BP_SHOW_BUTTONS , ///< Show the buttons.
BP_HIDE_BUTTONS , ///< Show the empty panel.
} ;
public :
VehicleListWindow ( const WindowDesc * desc , WindowNumber window_number ) : BaseVehicleListWindow ( )
2008-05-11 15:00:11 +00:00
{
2009-10-25 15:08:16 +00:00
uint16 window_type = window_number & VLW_MASK ;
CompanyID company = ( CompanyID ) GB ( window_number , 0 , 8 ) ;
2008-05-11 15:00:11 +00:00
2009-10-25 15:08:16 +00:00
this - > vehicle_type = ( VehicleType ) GB ( window_number , 11 , 5 ) ;
2009-10-30 20:51:36 +00:00
/* Set up sorting. Make the window-specific _sorting variable
* point to the correct global _sorting struct so we are freed
* from having conditionals during window operation */
switch ( this - > vehicle_type ) {
case VEH_TRAIN : this - > sorting = & _sorting . train ; break ;
case VEH_ROAD : this - > sorting = & _sorting . roadveh ; break ;
case VEH_SHIP : this - > sorting = & _sorting . ship ; break ;
case VEH_AIRCRAFT : this - > sorting = & _sorting . aircraft ; break ;
default : NOT_REACHED ( ) ;
}
this - > vehicles . SetListing ( * this - > sorting ) ;
this - > vehicles . ForceRebuild ( ) ;
this - > vehicles . NeedResort ( ) ;
this - > BuildVehicleList ( company , GB ( window_number , 16 , 16 ) , window_type ) ;
this - > SortVehicleList ( ) ;
2009-10-25 15:08:16 +00:00
this - > CreateNestedTree ( desc ) ;
2008-05-11 15:00:11 +00:00
/* Set up the window widgets */
2009-10-25 15:08:16 +00:00
this - > GetWidget < NWidgetCore > ( VLW_WIDGET_LIST ) - > tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this - > vehicle_type ;
this - > GetWidget < NWidgetCore > ( VLW_WIDGET_AVAILABLE_VEHICLES ) - > widget_data = STR_VEHICLE_LIST_AVAILABLE_TRAINS + this - > vehicle_type ;
2006-09-28 18:13:31 +00:00
2009-07-20 11:12:59 +00:00
if ( window_type = = VLW_SHARED_ORDERS ) {
2009-10-25 15:08:16 +00:00
this - > GetWidget < NWidgetCore > ( VLW_WIDGET_CAPTION ) - > widget_data = STR_VEHICLE_LIST_SHARED_ORDERS_LIST_CAPTION ;
2009-07-20 11:12:59 +00:00
} else {
2009-10-25 15:08:16 +00:00
this - > GetWidget < NWidgetCore > ( VLW_WIDGET_CAPTION ) - > widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this - > vehicle_type ;
2006-10-05 08:15:51 +00:00
}
2006-09-28 18:13:31 +00:00
2009-10-25 15:08:16 +00:00
this - > FinishInitNested ( desc , window_number ) ;
this - > owner = company ;
2006-09-03 23:27:38 +00:00
2008-09-12 21:58:36 +00:00
if ( this - > vehicle_type = = VEH_TRAIN ) ResizeWindow ( this , 65 , 0 ) ;
2008-05-11 15:00:11 +00:00
}
2006-08-29 17:41:13 +00:00
2008-05-11 15:00:11 +00:00
~ VehicleListWindow ( )
{
2008-06-16 17:09:52 +00:00
* this - > sorting = this - > vehicles . GetListing ( ) ;
2006-09-28 18:13:31 +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-11 15:00:11 +00:00
{
2009-10-25 15:08:16 +00:00
if ( widget ! = VLW_WIDGET_LIST ) return ;
2008-05-11 15:00:11 +00:00
2009-10-25 15:08:16 +00:00
resize - > width = 0 ;
2009-11-16 21:28:12 +00:00
resize - > height = GetVehicleListHeight ( this - > vehicle_type , 1 ) ;
2009-10-25 15:08:16 +00:00
switch ( this - > vehicle_type ) {
case VEH_TRAIN :
resize - > width = 1 ;
/* Fallthrough */
case VEH_ROAD :
size - > height = 6 * resize - > height ;
break ;
case VEH_SHIP :
case VEH_AIRCRAFT :
size - > height = 4 * resize - > height ;
break ;
default : NOT_REACHED ( ) ;
}
}
2008-05-11 15:00:11 +00:00
2009-10-25 15:08:16 +00:00
virtual void SetStringParameters ( int widget ) const
{
if ( widget ! = VLW_WIDGET_CAPTION ) return ;
2008-08-22 22:54:38 +00:00
2009-10-25 15:08:16 +00:00
const uint16 index = GB ( this - > window_number , 16 , 16 ) ;
switch ( this - > window_number & VLW_MASK ) {
2009-03-15 00:32:18 +00:00
case VLW_SHARED_ORDERS : // Shared Orders
2008-05-26 16:23:23 +00:00
if ( this - > vehicles . Length ( ) = = 0 ) {
2008-05-11 15:00:11 +00:00
/* We can't open this window without vehicles using this order
2009-03-14 18:16:29 +00:00
* and we should close the window when deleting the order */
2008-05-11 15:00:11 +00:00
NOT_REACHED ( ) ;
}
2009-09-02 08:48:29 +00:00
SetDParam ( 0 , this - > vscroll . GetCount ( ) ) ;
2008-05-11 15:00:11 +00:00
break ;
2006-09-28 18:13:31 +00:00
2009-03-15 00:32:18 +00:00
case VLW_STANDARD : // Company Name
2009-07-20 11:12:59 +00:00
SetDParam ( 0 , STR_COMPANY_NAME ) ;
2009-10-31 10:07:40 +00:00
SetDParam ( 1 , index ) ;
2009-09-02 08:48:29 +00:00
SetDParam ( 2 , this - > vscroll . GetCount ( ) ) ;
2008-05-11 15:00:11 +00:00
break ;
2006-09-28 18:13:31 +00:00
2008-08-21 01:42:21 +00:00
case VLW_WAYPOINT_LIST :
2009-07-20 11:21:57 +00:00
SetDParam ( 0 , STR_WAYPOINT_NAME ) ;
2009-07-20 11:12:59 +00:00
SetDParam ( 1 , index ) ;
2009-09-02 08:48:29 +00:00
SetDParam ( 2 , this - > vscroll . GetCount ( ) ) ;
2008-08-20 01:29:05 +00:00
break ;
2009-03-15 00:32:18 +00:00
case VLW_STATION_LIST : // Station Name
2009-07-20 11:21:57 +00:00
SetDParam ( 0 , STR_STATION_NAME ) ;
2009-07-20 11:12:59 +00:00
SetDParam ( 1 , index ) ;
2009-09-02 08:48:29 +00:00
SetDParam ( 2 , this - > vscroll . GetCount ( ) ) ;
2008-05-11 15:00:11 +00:00
break ;
2006-08-29 17:41:13 +00:00
2008-05-11 15:00:11 +00:00
case VLW_DEPOT_LIST :
2009-07-22 20:17:07 +00:00
SetDParam ( 0 , STR_DEPOT_TRAIN_CAPTION + this - > vehicle_type ) ;
2008-05-11 15:00:11 +00:00
if ( this - > vehicle_type = = VEH_AIRCRAFT ) {
SetDParam ( 1 , index ) ; // Airport name
} else {
2009-05-16 23:34:14 +00:00
SetDParam ( 1 , Depot : : Get ( index ) - > town_index ) ;
2008-05-11 15:00:11 +00:00
}
2009-09-02 08:48:29 +00:00
SetDParam ( 2 , this - > vscroll . GetCount ( ) ) ;
2008-05-11 15:00:11 +00:00
break ;
2009-05-26 15:46:24 +00:00
default : NOT_REACHED ( ) ;
2008-05-11 15:00:11 +00:00
}
2009-10-25 15:08:16 +00:00
}
virtual void DrawWidget ( const Rect & r , int widget ) const
{
switch ( widget ) {
case VLW_WIDGET_SORT_ORDER :
/* draw arrow pointing up/down for ascending/descending sorting */
this - > DrawSortButtonState ( widget , this - > vehicles . IsDescSortOrder ( ) ? SBS_DOWN : SBS_UP ) ;
break ;
case VLW_WIDGET_LIST :
this - > DrawVehicleListItems ( INVALID_VEHICLE , this - > resize . step_height , r ) ;
break ;
}
}
virtual void OnPaint ( )
{
const uint16 window_type = this - > window_number & VLW_MASK ;
this - > BuildVehicleList ( this - > owner , GB ( this - > window_number , 16 , 16 ) , window_type ) ;
this - > SortVehicleList ( ) ;
if ( this - > vehicles . Length ( ) = = 0 ) HideDropDownMenu ( this ) ;
2006-09-04 15:13:49 +00:00
2009-04-13 17:19:43 +00:00
/* Hide the widgets that we will not use in this window
* Some windows contains actions only fit for the owner */
2009-10-25 15:08:16 +00:00
int plane_to_show = ( this - > owner = = _local_company ) ? BP_SHOW_BUTTONS : BP_HIDE_BUTTONS ;
NWidgetStacked * nwi = this - > GetWidget < NWidgetStacked > ( VLW_WIDGET_HIDE_BUTTONS ) ;
if ( plane_to_show ! = nwi - > shown_plane ) {
nwi - > SetDisplayedPlane ( plane_to_show ) ;
nwi - > SetDirty ( this ) ;
}
2009-04-13 17:19:43 +00:00
if ( this - > owner = = _local_company ) {
this - > SetWidgetDisabledState ( VLW_WIDGET_AVAILABLE_VEHICLES , window_type ! = VLW_STANDARD ) ;
this - > SetWidgetsDisabledState ( this - > vehicles . Length ( ) = = 0 ,
VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN ,
VLW_WIDGET_STOP_ALL ,
VLW_WIDGET_START_ALL ,
WIDGET_LIST_END ) ;
}
2009-03-22 21:56:40 +00:00
/* Set text of sort by dropdown widget. */
2009-10-25 15:08:16 +00:00
this - > GetWidget < NWidgetCore > ( VLW_WIDGET_SORT_BY_PULLDOWN ) - > widget_data = this - > vehicle_sorter_names [ this - > vehicles . SortType ( ) ] ;
2009-03-22 21:56:40 +00:00
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2008-05-11 15:00:11 +00:00
}
2006-09-04 15:13:49 +00:00
2008-05-11 15:00:11 +00:00
virtual void OnClick ( Point pt , int widget )
{
switch ( widget ) {
2009-03-15 00:32:18 +00:00
case VLW_WIDGET_SORT_ORDER : // Flip sorting method ascending/descending
2008-06-16 17:09:52 +00:00
this - > vehicles . ToggleSortOrder ( ) ;
2008-05-11 15:00:11 +00:00
this - > SetDirty ( ) ;
break ;
2009-10-25 15:08:16 +00:00
2009-03-15 00:32:18 +00:00
case VLW_WIDGET_SORT_BY_PULLDOWN : // Select sorting criteria dropdown menu
2009-10-25 15:08:16 +00:00
ShowDropDownMenu ( this , this - > vehicle_sorter_names , this - > vehicles . SortType ( ) , VLW_WIDGET_SORT_BY_PULLDOWN , 0 ,
( this - > vehicle_type = = VEH_TRAIN | | this - > vehicle_type = = VEH_ROAD ) ? 0 : ( 1 < < 10 ) ) ;
2008-05-11 15:00:11 +00:00
return ;
2009-10-25 15:08:16 +00:00
2009-03-15 00:32:18 +00:00
case VLW_WIDGET_LIST : { // Matrix to show vehicles
2009-11-14 08:44:12 +00:00
uint32 id_v = ( pt . y - this - > GetWidget < NWidgetBase > ( VLW_WIDGET_LIST ) - > pos_y ) / this - > resize . step_height ;
2008-05-11 15:00:11 +00:00
const Vehicle * v ;
2009-09-02 08:48:29 +00:00
if ( id_v > = this - > vscroll . GetCapacity ( ) ) return ; // click out of bounds
2008-05-11 15:00:11 +00:00
2009-09-02 08:48:29 +00:00
id_v + = this - > vscroll . GetPosition ( ) ;
2008-05-11 15:00:11 +00:00
2008-05-26 16:23:23 +00:00
if ( id_v > = this - > vehicles . Length ( ) ) return ; // click out of list bound
2008-05-11 15:00:11 +00:00
2008-05-26 16:23:23 +00:00
v = this - > vehicles [ id_v ] ;
2008-05-11 15:00:11 +00:00
ShowVehicleViewWindow ( v ) ;
} break ;
case VLW_WIDGET_AVAILABLE_VEHICLES :
2009-01-03 16:06:58 +00:00
ShowBuildVehicleWindow ( INVALID_TILE , this - > vehicle_type ) ;
2008-05-11 15:00:11 +00:00
break ;
case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN : {
static StringID action_str [ ] = {
2009-08-05 17:59:21 +00:00
STR_VEHICLE_LIST_REPLACE_VEHICLES ,
STR_VEHICLE_LIST_SEND_FOR_SERVICING ,
2008-05-11 15:00:11 +00:00
STR_NULL ,
INVALID_STRING_ID
} ;
static const StringID depot_name [ ] = {
2009-08-05 17:59:21 +00:00
STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT ,
STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT ,
STR_VEHICLE_LIST_SEND_SHIP_TO_DEPOT ,
STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR
2008-05-11 15:00:11 +00:00
} ;
/* XXX - Substite string since the dropdown cannot handle dynamic strings */
action_str [ 2 ] = depot_name [ this - > vehicle_type ] ;
ShowDropDownMenu ( this , action_str , 0 , VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN , 0 , ( this - > window_number & VLW_MASK ) = = VLW_STANDARD ? 0 : 1 ) ;
break ;
2006-08-29 17:41:13 +00:00
}
2008-05-11 15:00:11 +00:00
case VLW_WIDGET_STOP_ALL :
case VLW_WIDGET_START_ALL :
2009-10-25 15:08:16 +00:00
DoCommandP ( 0 , GB ( this - > window_number , 16 , 16 ) ,
( this - > window_number & VLW_MASK ) | ( 1 < < 6 ) | ( widget = = VLW_WIDGET_START_ALL ? ( 1 < < 5 ) : 0 ) | this - > vehicle_type , CMD_MASS_START_STOP ) ;
2008-05-11 15:00:11 +00:00
break ;
}
2006-08-29 17:41:13 +00:00
}
2008-05-11 15:00:11 +00:00
virtual void OnDropdownSelect ( int widget , int index )
{
switch ( widget ) {
case VLW_WIDGET_SORT_BY_PULLDOWN :
2008-06-16 17:09:52 +00:00
this - > vehicles . SetSortType ( index ) ;
2008-05-11 15:00:11 +00:00
break ;
case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN :
2008-05-26 16:23:23 +00:00
assert ( this - > vehicles . Length ( ) ! = 0 ) ;
2008-05-11 15:00:11 +00:00
switch ( index ) {
2009-03-15 00:32:18 +00:00
case 0 : // Replace window
2008-05-11 15:00:11 +00:00
ShowReplaceGroupVehicleWindow ( DEFAULT_GROUP , this - > vehicle_type ) ;
break ;
2009-03-15 00:32:18 +00:00
case 1 : // Send for servicing
2008-05-11 15:00:11 +00:00
DoCommandP ( 0 , GB ( this - > window_number , 16 , 16 ) /* StationID or OrderID (depending on VLW) */ ,
2009-10-25 15:08:16 +00:00
( this - > window_number & VLW_MASK ) | DEPOT_MASS_SEND | DEPOT_SERVICE , GetCmdSendToDepot ( this - > vehicle_type ) ) ;
2008-05-11 15:00:11 +00:00
break ;
2009-03-15 00:32:18 +00:00
case 2 : // Send to Depots
2008-05-11 15:00:11 +00:00
DoCommandP ( 0 , GB ( this - > window_number , 16 , 16 ) /* StationID or OrderID (depending on VLW) */ ,
2009-10-25 15:08:16 +00:00
( this - > window_number & VLW_MASK ) | DEPOT_MASS_SEND , GetCmdSendToDepot ( this - > vehicle_type ) ) ;
2008-05-11 15:00:11 +00:00
break ;
default : NOT_REACHED ( ) ;
}
break ;
default : NOT_REACHED ( ) ;
}
this - > SetDirty ( ) ;
}
virtual void OnTick ( )
{
2009-05-06 15:06:57 +00:00
if ( _pause_mode ! = PM_UNPAUSED ) return ;
2008-06-16 17:09:52 +00:00
if ( this - > vehicles . NeedResort ( ) ) {
2008-05-11 15:00:11 +00:00
StationID station = ( ( this - > window_number & VLW_MASK ) = = VLW_STATION_LIST ) ? GB ( this - > window_number , 16 , 16 ) : INVALID_STATION ;
2009-02-09 02:33:10 +00:00
DEBUG ( misc , 3 , " Periodic resort %d list company %d at station %d " , this - > vehicle_type , this - > owner , station ) ;
2008-05-11 15:00:11 +00:00
this - > SetDirty ( ) ;
}
}
2009-10-24 14:53:55 +00:00
virtual void OnResize ( )
2008-05-11 15:00:11 +00:00
{
2009-12-20 20:08:39 +00:00
this - > vscroll . SetCapacityFromWidget ( this , VLW_WIDGET_LIST ) ;
2009-10-25 15:08:16 +00:00
this - > GetWidget < NWidgetCore > ( VLW_WIDGET_LIST ) - > widget_data = ( this - > vscroll . GetCapacity ( ) < < MAT_ROW_START ) + ( 1 < < MAT_COL_START ) ;
2008-05-11 15:00:11 +00:00
}
2008-05-18 16:51:44 +00:00
virtual void OnInvalidateData ( int data )
{
2008-08-17 21:07:09 +00:00
if ( HasBit ( data , 15 ) & & ( this - > window_number & VLW_MASK ) = = VLW_SHARED_ORDERS ) {
SB ( this - > window_number , 16 , 16 , GB ( data , 16 , 16 ) ) ;
this - > vehicles . ForceRebuild ( ) ;
return ;
}
2008-06-16 17:09:52 +00:00
if ( data = = 0 ) {
this - > vehicles . ForceRebuild ( ) ;
} else {
this - > vehicles . ForceResort ( ) ;
}
2008-05-18 16:51:44 +00:00
}
2008-05-11 15:00:11 +00:00
} ;
2006-09-28 23:05:03 +00:00
2009-03-15 15:12:06 +00:00
static WindowDesc _vehicle_list_desc (
2009-11-28 14:42:35 +00:00
WDP_AUTO , 260 , 246 ,
2008-09-12 21:58:36 +00:00
WC_INVALID , WC_NONE ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS ,
2009-11-15 10:26:01 +00:00
_nested_vehicle_list , lengthof ( _nested_vehicle_list )
2009-03-15 15:12:06 +00:00
) ;
2006-09-28 23:05:03 +00:00
2008-09-30 20:39:50 +00:00
static void ShowVehicleListWindowLocal ( CompanyID company , uint16 VLW_flag , VehicleType vehicle_type , uint16 unique_number )
2006-09-28 23:05:03 +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-12 21:58:36 +00:00
_vehicle_list_desc . cls = GetWindowClassForVehicleType ( vehicle_type ) ;
2008-09-30 20:39:50 +00:00
WindowNumber num = ( unique_number < < 16 ) | ( vehicle_type < < 11 ) | VLW_flag | company ;
2008-09-12 21:58:36 +00:00
AllocateWindowDescFront < VehicleListWindow > ( & _vehicle_list_desc , num ) ;
2006-09-28 23:05:03 +00:00
}
2008-09-30 20:39:50 +00:00
void ShowVehicleListWindow ( CompanyID company , VehicleType vehicle_type )
2006-09-28 23:05:03 +00:00
{
2008-05-29 15:13:28 +00:00
/* If _settings_client.gui.advanced_vehicle_list > 1, display the Advanced list
2008-09-30 20:39:50 +00:00
* if _settings_client . gui . advanced_vehicle_list = = 1 , display Advanced list only for local company
2007-09-09 10:34:32 +00:00
* if _ctrl_pressed , do the opposite action ( Advanced list x Normal list )
*/
2008-09-30 20:39:50 +00:00
if ( ( _settings_client . gui . advanced_vehicle_list > ( uint ) ( company ! = _local_company ) ) ! = _ctrl_pressed ) {
ShowCompanyGroup ( company , vehicle_type ) ;
2007-05-19 09:40:18 +00:00
} else {
2009-10-31 10:07:40 +00:00
ShowVehicleListWindowLocal ( company , VLW_STANDARD , vehicle_type , company ) ;
2007-05-19 09:40:18 +00:00
}
2006-09-28 23:05:03 +00:00
}
2009-07-21 16:30:01 +00:00
void ShowVehicleListWindow ( CompanyID company , VehicleType vehicle_type , const Waypoint * wp )
2008-08-20 01:29:05 +00:00
{
if ( wp = = NULL ) return ;
2009-07-21 16:30:01 +00:00
ShowVehicleListWindowLocal ( company , VLW_WAYPOINT_LIST , vehicle_type , wp - > index ) ;
2008-08-20 01:29:05 +00:00
}
2007-01-21 00:01:47 +00:00
void ShowVehicleListWindow ( const Vehicle * v )
2006-09-28 23:05:03 +00:00
{
2008-08-17 21:07:09 +00:00
ShowVehicleListWindowLocal ( v - > owner , VLW_SHARED_ORDERS , v - > type , v - > FirstShared ( ) - > index ) ;
2007-01-21 00:01:47 +00:00
}
2008-09-30 20:39:50 +00:00
void ShowVehicleListWindow ( CompanyID company , VehicleType vehicle_type , StationID station )
2007-01-21 00:01:47 +00:00
{
2008-09-30 20:39:50 +00:00
ShowVehicleListWindowLocal ( company , VLW_STATION_LIST , vehicle_type , station ) ;
2006-09-30 13:39:34 +00:00
}
2008-09-30 20:39:50 +00:00
void ShowVehicleListWindow ( CompanyID company , VehicleType vehicle_type , TileIndex depot_tile )
2006-09-30 13:39:34 +00:00
{
uint16 depot_airport_index ;
2007-03-08 16:27:54 +00:00
if ( vehicle_type = = VEH_AIRCRAFT ) {
2006-09-30 13:39:34 +00:00
depot_airport_index = GetStationIndex ( depot_tile ) ;
} else {
2009-09-10 14:37:55 +00:00
depot_airport_index = GetDepotIndex ( depot_tile ) ;
2006-09-30 13:39:34 +00:00
}
2008-09-30 20:39:50 +00:00
ShowVehicleListWindowLocal ( company , VLW_DEPOT_LIST , vehicle_type , depot_airport_index ) ;
2006-09-29 07:30:44 +00:00
}
2007-08-29 20:50:58 +00:00
2007-09-05 23:26:45 +00:00
/* Unified vehicle GUI - Vehicle Details Window */
/** Constants of vehicle details widget indices */
enum VehicleDetailsWindowWidgets {
VLD_WIDGET_CAPTION ,
VLD_WIDGET_RENAME_VEHICLE ,
VLD_WIDGET_TOP_DETAILS ,
VLD_WIDGET_INCREASE_SERVICING_INTERVAL ,
VLD_WIDGET_DECREASE_SERVICING_INTERVAL ,
2009-10-25 21:42:04 +00:00
VLD_WIDGET_SERVICING_INTERVAL ,
2007-09-05 23:26:45 +00:00
VLD_WIDGET_MIDDLE_DETAILS ,
2009-10-25 21:42:04 +00:00
VLD_WIDGET_MATRIX ,
2007-09-05 23:26:45 +00:00
VLD_WIDGET_SCROLLBAR ,
VLD_WIDGET_DETAILS_CARGO_CARRIED ,
VLD_WIDGET_DETAILS_TRAIN_VEHICLES ,
VLD_WIDGET_DETAILS_CAPACITY_OF_EACH ,
VLD_WIDGET_DETAILS_TOTAL_CARGO ,
} ;
2009-05-31 14:04:19 +00:00
assert_compile ( VLD_WIDGET_DETAILS_CARGO_CARRIED = = VLD_WIDGET_DETAILS_CARGO_CARRIED + TDW_TAB_CARGO ) ;
assert_compile ( VLD_WIDGET_DETAILS_TRAIN_VEHICLES = = VLD_WIDGET_DETAILS_CARGO_CARRIED + TDW_TAB_INFO ) ;
assert_compile ( VLD_WIDGET_DETAILS_CAPACITY_OF_EACH = = VLD_WIDGET_DETAILS_CARGO_CARRIED + TDW_TAB_CAPACITY ) ;
assert_compile ( VLD_WIDGET_DETAILS_TOTAL_CARGO = = VLD_WIDGET_DETAILS_CARGO_CARRIED + TDW_TAB_TOTALS ) ;
2009-10-25 21:42:04 +00:00
/** Vehicle details widgets (other than train). */
static const NWidgetPart _nested_nontrain_vehicle_details_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2009-10-25 21:42:04 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , VLD_WIDGET_CAPTION ) , SetDataTip ( STR_VEHICLE_DETAILS_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2009-11-17 13:17:09 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VLD_WIDGET_RENAME_VEHICLE ) , SetMinimalSize ( 40 , 0 ) , SetMinimalTextLines ( 1 , WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2 ) , SetDataTip ( STR_VEHICLE_NAME_BUTTON , STR_NULL /* filled in later */ ) ,
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-10-25 21:42:04 +00:00
EndContainer ( ) ,
2009-11-23 16:18:01 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY , VLD_WIDGET_TOP_DETAILS ) , SetMinimalSize ( 405 , 42 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , VLD_WIDGET_MIDDLE_DETAILS ) , SetMinimalSize ( 405 , 45 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , VLD_WIDGET_DECREASE_SERVICING_INTERVAL ) , SetFill ( 0 , 1 ) ,
SetDataTip ( AWV_DECREASE , STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , VLD_WIDGET_INCREASE_SERVICING_INTERVAL ) , SetFill ( 0 , 1 ) ,
SetDataTip ( AWV_INCREASE , STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , VLD_WIDGET_SERVICING_INTERVAL ) , SetFill ( 1 , 1 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_RESIZEBOX , COLOUR_GREY ) ,
2009-10-25 21:42:04 +00:00
EndContainer ( ) ,
2007-09-05 23:26:45 +00:00
} ;
2009-10-25 21:42:04 +00:00
/** Train details widgets. */
static const NWidgetPart _nested_train_vehicle_details_widgets [ ] = {
2009-04-13 14:09:56 +00:00
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2009-04-21 23:40:56 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , VLD_WIDGET_CAPTION ) , SetDataTip ( STR_VEHICLE_DETAILS_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
2009-11-17 13:17:09 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VLD_WIDGET_RENAME_VEHICLE ) , SetMinimalSize ( 40 , 0 ) , SetMinimalTextLines ( 1 , WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2 ) , SetDataTip ( STR_VEHICLE_NAME_BUTTON , STR_NULL /* filled in later */ ) ,
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-04-13 14:09:56 +00:00
EndContainer ( ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , VLD_WIDGET_TOP_DETAILS ) , SetResize ( 1 , 0 ) , SetMinimalSize ( 405 , 42 ) , EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_MATRIX , COLOUR_GREY , VLD_WIDGET_MATRIX ) , SetResize ( 1 , 1 ) , SetMinimalSize ( 393 , 45 ) , SetDataTip ( 0x701 , STR_NULL ) , SetFill ( 1 , 0 ) ,
2009-04-13 14:09:56 +00:00
NWidget ( WWT_SCROLLBAR , COLOUR_GREY , VLD_WIDGET_SCROLLBAR ) ,
EndContainer ( ) ,
2009-11-23 16:18:01 +00:00
NWidget ( NWID_HORIZONTAL ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , VLD_WIDGET_DECREASE_SERVICING_INTERVAL ) , SetFill ( 0 , 1 ) ,
SetDataTip ( AWV_DECREASE , STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP ) ,
NWidget ( NWID_BUTTON_ARROW , COLOUR_GREY , VLD_WIDGET_INCREASE_SERVICING_INTERVAL ) , SetFill ( 0 , 1 ) ,
SetDataTip ( AWV_INCREASE , STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP ) ,
NWidget ( WWT_PANEL , COLOUR_GREY , VLD_WIDGET_SERVICING_INTERVAL ) , SetFill ( 1 , 1 ) , SetResize ( 1 , 0 ) , EndContainer ( ) ,
2009-04-13 14:09:56 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-10-25 21:42:04 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VLD_WIDGET_DETAILS_CARGO_CARRIED ) , SetMinimalSize ( 96 , 12 ) ,
2009-11-23 16:18:01 +00:00
SetDataTip ( STR_VEHICLE_DETAIL_TAB_CARGO , STR_VEHICLE_DETAILS_TRAIN_CARGO_TOOLTIP ) , SetFill ( 1 , 0 ) , SetResize ( 1 , 0 ) ,
2009-10-25 21:42:04 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VLD_WIDGET_DETAILS_TRAIN_VEHICLES ) , SetMinimalSize ( 99 , 12 ) ,
2009-11-23 16:18:01 +00:00
SetDataTip ( STR_VEHICLE_DETAIL_TAB_INFORMATION , STR_VEHICLE_DETAILS_TRAIN_INFORMATION_TOOLTIP ) , SetFill ( 1 , 0 ) , SetResize ( 1 , 0 ) ,
2009-10-25 21:42:04 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VLD_WIDGET_DETAILS_CAPACITY_OF_EACH ) , SetMinimalSize ( 99 , 12 ) ,
2009-11-23 16:18:01 +00:00
SetDataTip ( STR_VEHICLE_DETAIL_TAB_CAPACITIES , STR_VEHICLE_DETAILS_TRAIN_CAPACITIES_TOOLTIP ) , SetFill ( 1 , 0 ) , SetResize ( 1 , 0 ) ,
2009-10-25 21:42:04 +00:00
NWidget ( WWT_PUSHTXTBTN , COLOUR_GREY , VLD_WIDGET_DETAILS_TOTAL_CARGO ) , SetMinimalSize ( 99 , 12 ) ,
2009-11-23 16:18:01 +00:00
SetDataTip ( STR_VEHICLE_DETAIL_TAB_TOTAL_CARGO , STR_VEHICLE_DETAILS_TRAIN_TOTAL_CARGO_TOOLTIP ) , SetFill ( 1 , 0 ) , SetResize ( 1 , 0 ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_RESIZEBOX , COLOUR_GREY ) ,
2009-04-13 14:09:56 +00:00
EndContainer ( ) ,
} ;
2007-09-05 23:26:45 +00:00
2009-05-31 14:04:19 +00:00
extern int GetTrainDetailsWndVScroll ( VehicleID veh_id , TrainDetailsWindowTabs det_tab ) ;
2009-07-01 23:57:20 +00:00
extern void DrawTrainDetails ( const Train * v , int left , int right , int y , int vscroll_pos , uint16 vscroll_cap , TrainDetailsWindowTabs det_tab ) ;
2009-03-22 10:37:51 +00:00
extern void DrawRoadVehDetails ( const Vehicle * v , int left , int right , int y ) ;
extern void DrawShipDetails ( const Vehicle * v , int left , int right , int y ) ;
2009-07-13 16:37:27 +00:00
extern void DrawAircraftDetails ( const Aircraft * v , int left , int right , int y ) ;
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
/** Class for managing the vehicle details window. */
2008-05-16 17:33:09 +00:00
struct VehicleDetailsWindow : Window {
2009-10-25 21:42:04 +00:00
TrainDetailsWindowTabs tab ; ///< For train vehicles: which tab is displayed.
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
/** Initialize a newly created vehicle details window */
2009-10-25 21:42:04 +00:00
VehicleDetailsWindow ( const WindowDesc * desc , WindowNumber window_number ) : Window ( )
2008-05-16 17:33:09 +00:00
{
2009-10-25 21:42:04 +00:00
this - > InitNested ( desc , window_number ) ;
2009-05-16 23:34:14 +00:00
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
this - > GetWidget < NWidgetCore > ( VLD_WIDGET_RENAME_VEHICLE ) - > tool_tip = STR_VEHICLE_DETAILS_TRAIN_RENAME + v - > type ;
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
this - > owner = v - > owner ;
this - > tab = TDW_TAB_CARGO ;
}
2007-09-05 23:26:45 +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-25 21:42:04 +00:00
{
switch ( widget ) {
2009-12-09 22:25:12 +00:00
case VLD_WIDGET_TOP_DETAILS : {
Dimension dim = { 0 , 0 } ;
2009-10-25 21:42:04 +00:00
size - > height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM ;
2009-12-09 22:25:12 +00:00
for ( uint i = 0 ; i < 4 ; i + + ) SetDParam ( i , INT16_MAX ) ;
static const StringID info_strings [ ] = {
STR_VEHICLE_INFO_MAX_SPEED ,
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED ,
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE ,
STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR ,
STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS
} ;
for ( uint i = 0 ; i < lengthof ( info_strings ) ; i + + ) {
dim = maxdim ( dim , GetStringBoundingBox ( info_strings [ i ] ) ) ;
}
SetDParam ( 0 , STR_VEHICLE_INFO_AGE ) ;
dim = maxdim ( dim , GetStringBoundingBox ( STR_VEHICLE_INFO_AGE_RUNNING_COST_YR ) ) ;
size - > width = dim . width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT ;
} break ;
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
case VLD_WIDGET_MIDDLE_DETAILS : {
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
switch ( v - > type ) {
case VEH_ROAD :
if ( RoadVehicle : : From ( v ) - > HasArticulatedPart ( ) ) {
/* An articulated RV has its text drawn under the sprite instead of after it, hence 15 pixels extra. */
size - > height = WD_FRAMERECT_TOP + 15 + 3 * FONT_HEIGHT_NORMAL + 2 + WD_FRAMERECT_BOTTOM ;
/* Add space for the cargo amount for each part. */
for ( const Vehicle * u = v ; u ! = NULL ; u = u - > Next ( ) ) {
if ( u - > cargo_cap ! = 0 ) size - > height + = FONT_HEIGHT_NORMAL + 1 ;
}
} else {
size - > height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM ;
}
break ;
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
case VEH_SHIP :
size - > height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + 3 + WD_FRAMERECT_BOTTOM ;
break ;
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
case VEH_AIRCRAFT :
size - > height = WD_FRAMERECT_TOP + 5 * FONT_HEIGHT_NORMAL + 4 + WD_FRAMERECT_BOTTOM ;
break ;
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
default :
NOT_REACHED ( ) ; // Train uses VLD_WIDGET_MATRIX instead.
}
2008-05-16 17:33:09 +00:00
break ;
2009-10-25 21:42:04 +00:00
}
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
case VLD_WIDGET_MATRIX :
2009-11-16 21:10:23 +00:00
resize - > height = WD_MATRIX_TOP + FONT_HEIGHT_NORMAL + WD_MATRIX_BOTTOM ;
2009-10-25 21:42:04 +00:00
size - > height = 4 * resize - > height ;
2008-05-16 17:33:09 +00:00
break ;
2007-09-05 23:26:45 +00:00
2009-10-25 21:42:04 +00:00
case VLD_WIDGET_SERVICING_INTERVAL :
2009-11-23 16:18:01 +00:00
SetDParam ( 0 , 9999 ) ; // Roughly the maximum interval
SetDParam ( 1 , MAX_YEAR * DAYS_IN_YEAR ) ; // Roughly the maximum year
size - > width = max ( GetStringBoundingBox ( STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT ) . width , GetStringBoundingBox ( STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS ) . width ) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT ;
2009-10-25 21:42:04 +00:00
size - > height = WD_FRAMERECT_TOP + FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM ;
break ;
2008-05-16 17:33:09 +00:00
}
2007-09-05 23:26:45 +00:00
}
2008-05-16 17:33:09 +00:00
/** Checks whether service interval is enabled for the vehicle. */
2009-05-26 21:59:49 +00:00
static bool IsVehicleServiceIntervalEnabled ( const VehicleType vehicle_type , CompanyID company_id )
2008-05-16 17:33:09 +00:00
{
2009-05-26 21:59:49 +00:00
const VehicleDefaultSettings * vds = & Company : : Get ( company_id ) - > settings . vehicle ;
2008-05-16 17:33:09 +00:00
switch ( vehicle_type ) {
default : NOT_REACHED ( ) ;
2009-05-26 21:59:49 +00:00
case VEH_TRAIN : return vds - > servint_trains ! = 0 ;
case VEH_ROAD : return vds - > servint_roadveh ! = 0 ;
case VEH_SHIP : return vds - > servint_ships ! = 0 ;
case VEH_AIRCRAFT : return vds - > servint_aircraft ! = 0 ;
2008-05-16 17:33:09 +00:00
}
}
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
/**
2009-03-22 10:37:51 +00:00
* Draw the details for the given vehicle at the position of the Details windows
2008-05-16 17:33:09 +00:00
*
2009-03-22 10:37:51 +00:00
* @ param v current vehicle
* @ param left The left most coordinate to draw
* @ param right The right most coordinate to draw
* @ param y The y coordinate
2009-05-31 14:04:19 +00:00
* @ param vscroll_pos Position of scrollbar ( train only )
* @ param vscroll_cap Number of lines currently displayed ( train only )
* @ param det_tab Selected details tab ( train only )
2008-05-16 17:33:09 +00:00
*/
2009-05-31 14:04:19 +00:00
static void DrawVehicleDetails ( const Vehicle * v , int left , int right , int y , int vscroll_pos , uint vscroll_cap , TrainDetailsWindowTabs det_tab )
2008-05-16 17:33:09 +00:00
{
switch ( v - > type ) {
2009-07-01 23:57:20 +00:00
case VEH_TRAIN : DrawTrainDetails ( Train : : From ( v ) , left , right , y , vscroll_pos , vscroll_cap , det_tab ) ; break ;
2009-03-22 10:37:51 +00:00
case VEH_ROAD : DrawRoadVehDetails ( v , left , right , y ) ; break ;
case VEH_SHIP : DrawShipDetails ( v , left , right , y ) ; break ;
2009-07-13 16:37:27 +00:00
case VEH_AIRCRAFT : DrawAircraftDetails ( Aircraft : : From ( v ) , left , right , y ) ; break ;
2008-05-16 17:33:09 +00:00
default : NOT_REACHED ( ) ;
}
2007-09-05 23:26:45 +00:00
}
2009-10-25 21:42:04 +00:00
virtual void SetStringParameters ( int widget ) const
{
if ( widget = = VLD_WIDGET_CAPTION ) SetDParam ( 0 , Vehicle : : Get ( this - > window_number ) - > index ) ;
}
virtual void DrawWidget ( const Rect & r , int widget ) const
{
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2009-10-27 20:50:47 +00:00
switch ( widget ) {
case VLD_WIDGET_TOP_DETAILS : {
int y = r . top + WD_FRAMERECT_TOP ;
/* Draw running cost */
SetDParam ( 1 , v - > age / DAYS_IN_LEAP_YEAR ) ;
SetDParam ( 0 , ( v - > age + DAYS_IN_YEAR < v - > max_age ) ? STR_VEHICLE_INFO_AGE : STR_VEHICLE_INFO_AGE_RED ) ;
SetDParam ( 2 , v - > max_age / DAYS_IN_LEAP_YEAR ) ;
SetDParam ( 3 , v - > GetDisplayRunningCost ( ) ) ;
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , y , STR_VEHICLE_INFO_AGE_RUNNING_COST_YR ) ;
y + = FONT_HEIGHT_NORMAL ;
/* Draw max speed */
switch ( v - > type ) {
case VEH_TRAIN :
SetDParam ( 2 , v - > GetDisplayMaxSpeed ( ) ) ;
SetDParam ( 1 , Train : : From ( v ) - > tcache . cached_power ) ;
SetDParam ( 0 , Train : : From ( v ) - > tcache . cached_weight ) ;
SetDParam ( 3 , Train : : From ( v ) - > tcache . cached_max_te / 1000 ) ;
2010-01-15 22:21:50 +00:00
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , y , ( _settings_game . vehicle . train_acceleration_model ! = TAM_ORIGINAL & & GetRailTypeInfo ( Train : : From ( v ) - > railtype ) - > acceleration_type ! = 2 ) ?
2009-10-27 20:50:47 +00:00
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE : STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED ) ;
break ;
case VEH_ROAD :
case VEH_SHIP :
case VEH_AIRCRAFT :
SetDParam ( 0 , v - > GetDisplayMaxSpeed ( ) ) ;
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , y , STR_VEHICLE_INFO_MAX_SPEED ) ;
break ;
default : NOT_REACHED ( ) ;
}
y + = FONT_HEIGHT_NORMAL ;
/* Draw profit */
SetDParam ( 0 , v - > GetDisplayProfitThisYear ( ) ) ;
SetDParam ( 1 , v - > GetDisplayProfitLastYear ( ) ) ;
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , y , STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR ) ;
y + = FONT_HEIGHT_NORMAL ;
/* Draw breakdown & reliability */
SetDParam ( 0 , ToPercent16 ( v - > reliability ) ) ;
SetDParam ( 1 , v - > breakdowns_since_last_service ) ;
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , y , STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS ) ;
break ;
}
case VLD_WIDGET_MATRIX :
/* For trains only. */
2009-11-16 21:10:23 +00:00
DrawVehicleDetails ( v , r . left + WD_MATRIX_LEFT , r . right - WD_MATRIX_RIGHT , r . top + WD_MATRIX_TOP , this - > vscroll . GetPosition ( ) , this - > vscroll . GetCapacity ( ) , this - > tab ) ;
2009-10-27 20:50:47 +00:00
break ;
2009-11-17 15:05:12 +00:00
case VLD_WIDGET_MIDDLE_DETAILS : {
2009-10-27 20:50:47 +00:00
/* For other vehicles, at the place of the matrix. */
2009-11-17 15:05:12 +00:00
bool rtl = _dynlang . text_dir = = TD_RTL ;
uint sprite_width = max < uint > ( GetSprite ( v - > GetImage ( rtl ? DIR_E : DIR_W ) , ST_NORMAL ) - > width , 70U ) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT ;
uint text_left = r . left + ( rtl ? 0 : sprite_width ) ;
uint text_right = r . right - ( rtl ? sprite_width : 0 ) ;
uint sprite_left = rtl ? text_right : r . left ;
uint sprite_right = rtl ? r . right : text_left ;
DrawVehicleImage ( v , sprite_left + WD_FRAMERECT_LEFT , sprite_right - WD_FRAMERECT_RIGHT , r . top + WD_FRAMERECT_TOP , INVALID_VEHICLE , 0 ) ;
DrawVehicleDetails ( v , text_left + WD_FRAMERECT_LEFT , text_right - WD_FRAMERECT_RIGHT , r . top + WD_FRAMERECT_TOP , this - > vscroll . GetPosition ( ) , this - > vscroll . GetCapacity ( ) , this - > tab ) ;
} break ;
2009-10-27 20:50:47 +00:00
case VLD_WIDGET_SERVICING_INTERVAL :
/* Draw service interval text */
SetDParam ( 0 , v - > service_interval ) ;
SetDParam ( 1 , v - > date_of_last_service ) ;
DrawString ( r . left + WD_FRAMERECT_LEFT , r . right - WD_FRAMERECT_RIGHT , r . top + ( r . bottom - r . top + 1 - FONT_HEIGHT_NORMAL ) / 2 ,
Company : : Get ( v - > owner ) - > settings . vehicle . servint_ispercent ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS ) ;
break ;
}
2009-10-25 21:42:04 +00:00
}
2008-05-16 17:33:09 +00:00
/** Repaint vehicle details window. */
virtual void OnPaint ( )
{
2009-05-16 23:34:14 +00:00
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2007-09-05 23:26:45 +00:00
2008-09-30 20:39:50 +00:00
this - > SetWidgetDisabledState ( VLD_WIDGET_RENAME_VEHICLE , v - > owner ! = _local_company ) ;
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
if ( v - > type = = VEH_TRAIN ) {
2009-10-27 20:50:47 +00:00
this - > DisableWidget ( this - > tab + VLD_WIDGET_DETAILS_CARGO_CARRIED ) ;
this - > vscroll . SetCount ( GetTrainDetailsWndVScroll ( v - > index , this - > tab ) ) ;
2008-05-16 17:33:09 +00:00
}
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
/* Disable service-scroller when interval is set to disabled */
2009-05-26 21:59:49 +00:00
this - > SetWidgetsDisabledState ( ! IsVehicleServiceIntervalEnabled ( v - > type , v - > owner ) ,
2008-05-16 17:33:09 +00:00
VLD_WIDGET_INCREASE_SERVICING_INTERVAL ,
VLD_WIDGET_DECREASE_SERVICING_INTERVAL ,
WIDGET_LIST_END ) ;
2007-09-05 23:26:45 +00:00
2008-05-17 12:48:06 +00:00
this - > DrawWidgets ( ) ;
2008-05-16 17:33:09 +00:00
}
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
virtual void OnClick ( Point pt , int widget )
{
switch ( widget ) {
2009-10-25 21:42:04 +00:00
case VLD_WIDGET_RENAME_VEHICLE : { // rename
2009-05-16 23:34:14 +00:00
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2008-05-16 17:33:09 +00:00
SetDParam ( 0 , v - > index ) ;
2009-10-25 21:42:04 +00:00
ShowQueryString ( STR_VEHICLE_NAME , STR_QUERY_RENAME_TRAIN_CAPTION + v - > type ,
MAX_LENGTH_VEHICLE_NAME_BYTES , MAX_LENGTH_VEHICLE_NAME_PIXELS , this , CS_ALPHANUMERAL , QSF_ENABLE_DEFAULT ) ;
2008-05-16 17:33:09 +00:00
} break ;
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
case VLD_WIDGET_INCREASE_SERVICING_INTERVAL : // increase int
case VLD_WIDGET_DECREASE_SERVICING_INTERVAL : { // decrease int
int mod = _ctrl_pressed ? 5 : 10 ;
2009-05-16 23:34:14 +00:00
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
mod = ( widget = = VLD_WIDGET_DECREASE_SERVICING_INTERVAL ) ? - mod : mod ;
2009-05-26 21:59:49 +00:00
mod = GetServiceIntervalClamped ( mod + v - > service_interval , v - > owner ) ;
2008-05-16 17:33:09 +00:00
if ( mod = = v - > service_interval ) return ;
2007-09-05 23:26:45 +00:00
2009-04-21 23:40:56 +00:00
DoCommandP ( v - > tile , v - > index , mod , CMD_CHANGE_SERVICE_INT | CMD_MSG ( STR_ERROR_CAN_T_CHANGE_SERVICING ) ) ;
2008-05-16 17:33:09 +00:00
} break ;
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
case VLD_WIDGET_DETAILS_CARGO_CARRIED :
case VLD_WIDGET_DETAILS_TRAIN_VEHICLES :
case VLD_WIDGET_DETAILS_CAPACITY_OF_EACH :
case VLD_WIDGET_DETAILS_TOTAL_CARGO :
this - > SetWidgetsDisabledState ( false ,
VLD_WIDGET_DETAILS_CARGO_CARRIED ,
VLD_WIDGET_DETAILS_TRAIN_VEHICLES ,
VLD_WIDGET_DETAILS_CAPACITY_OF_EACH ,
VLD_WIDGET_DETAILS_TOTAL_CARGO ,
widget ,
WIDGET_LIST_END ) ;
2009-05-31 14:04:19 +00:00
this - > tab = ( TrainDetailsWindowTabs ) ( widget - VLD_WIDGET_DETAILS_CARGO_CARRIED ) ;
2008-05-16 17:33:09 +00:00
this - > SetDirty ( ) ;
break ;
}
}
2007-09-05 23:26:45 +00:00
2008-05-16 17:33:09 +00:00
virtual void OnQueryTextFinished ( char * str )
{
2008-09-15 19:02:50 +00:00
if ( str = = NULL ) return ;
2009-07-22 20:17:07 +00:00
DoCommandP ( 0 , this - > window_number , 0 , CMD_RENAME_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle : : Get ( this - > window_number ) - > type ) , NULL , str ) ;
2007-09-05 23:26:45 +00:00
}
2008-05-16 17:33:09 +00:00
2009-10-24 14:53:55 +00:00
virtual void OnResize ( )
2008-05-16 17:33:09 +00:00
{
2009-10-25 21:42:04 +00:00
NWidgetCore * nwi = this - > GetWidget < NWidgetCore > ( VLD_WIDGET_MATRIX ) ;
if ( nwi ! = NULL ) {
2009-12-20 20:08:39 +00:00
this - > vscroll . SetCapacityFromWidget ( this , VLD_WIDGET_MATRIX ) ;
2009-10-25 21:42:04 +00:00
nwi - > widget_data = ( this - > vscroll . GetCapacity ( ) < < MAT_ROW_START ) + ( 1 < < MAT_COL_START ) ;
}
2008-05-16 17:33:09 +00:00
}
} ;
2007-09-05 23:26:45 +00:00
/** Vehicle details window descriptor. */
2009-10-25 21:42:04 +00:00
static const WindowDesc _train_vehicle_details_desc (
2009-11-28 14:42:35 +00:00
WDP_AUTO , 405 , 178 ,
2009-10-25 21:42:04 +00:00
WC_VEHICLE_DETAILS , WC_VEHICLE_VIEW ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS ,
2009-11-15 10:26:01 +00:00
_nested_train_vehicle_details_widgets , lengthof ( _nested_train_vehicle_details_widgets )
2009-10-25 21:42:04 +00:00
) ;
/** Vehicle details window descriptor for other vehicles than a train. */
static const WindowDesc _nontrain_vehicle_details_desc (
2009-11-28 14:42:35 +00:00
WDP_AUTO , 405 , 113 ,
2007-09-05 23:26:45 +00:00
WC_VEHICLE_DETAILS , WC_VEHICLE_VIEW ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS ,
2009-11-15 10:26:01 +00:00
_nested_nontrain_vehicle_details_widgets , lengthof ( _nested_nontrain_vehicle_details_widgets )
2009-03-15 15:12:06 +00:00
) ;
2007-09-05 23:26:45 +00:00
/** Shows the vehicle details window of the given vehicle. */
static void ShowVehicleDetailsWindow ( const Vehicle * v )
{
2009-01-03 23:32:59 +00:00
DeleteWindowById ( WC_VEHICLE_ORDERS , v - > index , false ) ;
DeleteWindowById ( WC_VEHICLE_TIMETABLE , v - > index , false ) ;
2009-10-25 21:42:04 +00:00
AllocateWindowDescFront < VehicleDetailsWindow > ( ( v - > type = = VEH_TRAIN ) ? & _train_vehicle_details_desc : & _nontrain_vehicle_details_desc , v - > index ) ;
2007-09-05 23:26:45 +00:00
}
2007-08-29 20:50:58 +00:00
/* Unified vehicle GUI - Vehicle View Window */
/** Vehicle view widgets. */
2009-05-03 13:13:41 +00:00
static const NWidgetPart _nested_vehicle_view_widgets [ ] = {
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_CLOSEBOX , COLOUR_GREY ) ,
2009-05-03 13:13:41 +00:00
NWidget ( WWT_CAPTION , COLOUR_GREY , VVW_WIDGET_CAPTION ) , SetDataTip ( STR_VEHICLE_VIEW_CAPTION , STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS ) ,
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-05-03 13:13:41 +00:00
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) ,
NWidget ( WWT_INSET , COLOUR_GREY ) , SetPadding ( 2 , 2 , 2 , 2 ) ,
2009-10-24 13:58:18 +00:00
NWidget ( NWID_VIEWPORT , INVALID_COLOUR , VVW_WIDGET_VIEWPORT ) , SetMinimalSize ( 226 , 84 ) , SetResize ( 1 , 1 ) , SetPadding ( 1 , 1 , 1 , 1 ) ,
EndContainer ( ) ,
2009-05-03 13:13:41 +00:00
EndContainer ( ) ,
NWidget ( NWID_VERTICAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VVW_WIDGET_CENTER_MAIN_VIEH ) , SetMinimalSize ( 18 , 18 ) , SetFill ( 1 , 1 ) , SetDataTip ( SPR_CENTRE_VIEW_VEHICLE , 0x0 /* filled later */ ) ,
2009-10-24 13:49:04 +00:00
NWidget ( NWID_SELECTION , INVALID_COLOUR , VVW_WIDGET_SELECT_DEPOT_CLONE ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VVW_WIDGET_GOTO_DEPOT ) , SetMinimalSize ( 18 , 18 ) , SetFill ( 1 , 1 ) , SetDataTip ( 0x0 /* filled later */ , 0x0 /* filled later */ ) ,
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VVW_WIDGET_CLONE_VEH ) , SetMinimalSize ( 18 , 18 ) , SetFill ( 1 , 1 ) , SetDataTip ( 0x0 /* filled later */ , 0x0 /* filled later */ ) ,
2009-05-03 13:13:41 +00:00
EndContainer ( ) ,
2009-10-24 13:49:04 +00:00
/* For trains only, 'ignore signal' button. */
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VVW_WIDGET_FORCE_PROCEED ) , SetMinimalSize ( 18 , 18 ) , SetFill ( 1 , 1 ) ,
2009-10-24 13:49:04 +00:00
SetDataTip ( SPR_IGNORE_SIGNALS , STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP ) ,
NWidget ( NWID_SELECTION , INVALID_COLOUR , VVW_WIDGET_SELECT_REFIT_TURN ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VVW_WIDGET_REFIT_VEH ) , SetMinimalSize ( 18 , 18 ) , SetFill ( 1 , 1 ) , SetDataTip ( SPR_REFIT_VEHICLE , 0x0 /* filled later */ ) ,
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VVW_WIDGET_TURN_AROUND ) , SetMinimalSize ( 18 , 18 ) , SetFill ( 1 , 1 ) ,
2009-07-22 22:44:56 +00:00
SetDataTip ( SPR_FORCE_VEHICLE_TURN , STR_VEHICLE_VIEW_ROAD_VEHICLE_REVERSE_TOOLTIP ) ,
2009-05-03 13:13:41 +00:00
EndContainer ( ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VVW_WIDGET_SHOW_ORDERS ) , SetFill ( 1 , 1 ) , SetMinimalSize ( 18 , 18 ) , SetDataTip ( SPR_SHOW_ORDERS , 0x0 /* filled later */ ) ,
NWidget ( WWT_PUSHIMGBTN , COLOUR_GREY , VVW_WIDGET_SHOW_DETAILS ) , SetFill ( 1 , 1 ) , SetMinimalSize ( 18 , 18 ) , SetDataTip ( SPR_SHOW_VEHICLE_DETAILS , 0x0 /* filled later */ ) ,
2009-11-24 21:13:36 +00:00
NWidget ( WWT_PANEL , COLOUR_GREY ) , SetFill ( 1 , 1 ) , SetMinimalSize ( 18 , 0 ) , SetResize ( 0 , 1 ) , EndContainer ( ) ,
2009-05-03 13:13:41 +00:00
EndContainer ( ) ,
EndContainer ( ) ,
NWidget ( NWID_HORIZONTAL ) ,
2009-11-22 18:26:01 +00:00
NWidget ( WWT_PUSHBTN , COLOUR_GREY , VVW_WIDGET_START_STOP_VEH ) , SetMinimalTextLines ( 1 , WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM ) , SetResize ( 1 , 0 ) , SetFill ( 1 , 0 ) ,
2009-11-24 18:05:55 +00:00
NWidget ( WWT_RESIZEBOX , COLOUR_GREY ) ,
2009-05-03 13:13:41 +00:00
EndContainer ( ) ,
} ;
2007-08-29 20:50:58 +00:00
/** Vehicle view window descriptor for all vehicles but trains. */
2009-03-15 15:12:06 +00:00
static const WindowDesc _vehicle_view_desc (
2009-11-28 14:42:35 +00:00
WDP_AUTO , 250 , 116 ,
2007-08-29 20:50:58 +00:00
WC_VEHICLE_VIEW , WC_NONE ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS ,
2009-11-15 10:26:01 +00:00
_nested_vehicle_view_widgets , lengthof ( _nested_vehicle_view_widgets )
2009-03-15 15:12:06 +00:00
) ;
2007-08-29 20:50:58 +00:00
/** Vehicle view window descriptor for trains. Only minimum_height and
* default_height are different for train view .
*/
2009-03-15 15:12:06 +00:00
static const WindowDesc _train_view_desc (
2009-11-28 14:42:35 +00:00
WDP_AUTO , 250 , 134 ,
2007-08-29 20:50:58 +00:00
WC_VEHICLE_VIEW , WC_NONE ,
2009-11-24 17:28:29 +00:00
WDF_UNCLICK_BUTTONS ,
2009-11-15 10:26:01 +00:00
_nested_vehicle_view_widgets , lengthof ( _nested_vehicle_view_widgets )
2009-03-15 15:12:06 +00:00
) ;
2007-08-29 20:50:58 +00:00
/* Just to make sure, nobody has changed the vehicle type constants, as we are
using them for array indexing in a number of places here . */
assert_compile ( VEH_TRAIN = = 0 ) ;
assert_compile ( VEH_ROAD = = 1 ) ;
assert_compile ( VEH_SHIP = = 2 ) ;
assert_compile ( VEH_AIRCRAFT = = 3 ) ;
/** Zoom levels for vehicle views indexed by vehicle type. */
static const ZoomLevel _vehicle_view_zoom_levels [ ] = {
ZOOM_LVL_TRAIN ,
ZOOM_LVL_ROADVEH ,
ZOOM_LVL_SHIP ,
ZOOM_LVL_AIRCRAFT ,
} ;
/* Constants for geometry of vehicle view viewport */
static const int VV_INITIAL_VIEWPORT_WIDTH = 226 ;
static const int VV_INITIAL_VIEWPORT_HEIGHT = 84 ;
static const int VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102 ;
2008-05-19 09:39:05 +00:00
/** Command indices for the _vehicle_command_translation_table. */
enum VehicleCommandTranslation {
VCT_CMD_START_STOP = 0 ,
VCT_CMD_CLONE_VEH ,
VCT_CMD_TURN_AROUND ,
} ;
2007-08-29 20:50:58 +00:00
2008-05-19 09:39:05 +00:00
/** Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type. */
static const uint32 _vehicle_command_translation_table [ ] [ 4 ] = {
{ // VCT_CMD_START_STOP
2009-04-21 23:40:56 +00:00
CMD_START_STOP_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_STOP_START_TRAIN ) ,
CMD_START_STOP_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE ) ,
CMD_START_STOP_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_STOP_START_SHIP ) ,
CMD_START_STOP_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_STOP_START_AIRCRAFT )
2008-05-19 09:39:05 +00:00
} ,
{ // VCT_CMD_CLONE_VEH
2009-09-07 08:59:43 +00:00
CMD_CLONE_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_BUY_TRAIN ) ,
CMD_CLONE_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_BUY_ROAD_VEHICLE ) ,
CMD_CLONE_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_BUY_SHIP ) ,
CMD_CLONE_VEHICLE | CMD_MSG ( STR_ERROR_CAN_T_BUY_AIRCRAFT )
2008-05-19 09:39:05 +00:00
} ,
{ // VCT_CMD_TURN_AROUND
2009-07-08 22:11:55 +00:00
CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG ( STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN ) ,
2009-07-22 19:12:20 +00:00
CMD_TURN_ROADVEH | CMD_MSG ( STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN ) ,
2008-05-19 09:39:05 +00:00
0xffffffff , // invalid for ships
0xffffffff // invalid for aircrafts
} ,
} ;
2007-08-29 20:50:58 +00:00
2008-05-19 09:39:05 +00:00
/** Checks whether the vehicle may be refitted at the moment.*/
static bool IsVehicleRefitable ( const Vehicle * v )
2007-08-29 20:50:58 +00:00
{
2008-12-16 22:02:12 +00:00
if ( ! v - > IsStoppedInDepot ( ) ) return false ;
do {
if ( IsEngineRefittable ( v - > engine_type ) ) return true ;
} while ( ( v - > type = = VEH_TRAIN | | v - > type = = VEH_ROAD ) & & ( v = v - > Next ( ) ) ! = NULL ) ;
return false ;
2008-05-19 09:39:05 +00:00
}
2009-10-24 15:19:06 +00:00
/** Window manager class for viewing a vehicle. */
2008-05-19 09:39:05 +00:00
struct VehicleViewWindow : Window {
2009-10-24 13:49:04 +00:00
private :
/** Display planes available in the vehicle view window. */
enum PlaneSelections {
SEL_DC_GOTO_DEPOT , ///< Display 'goto depot' button in #VVW_WIDGET_SELECT_DEPOT_CLONE stacked widget.
SEL_DC_CLONE , ///< Display 'clone vehicle' button in #VVW_WIDGET_SELECT_DEPOT_CLONE stacked widget.
SEL_RT_REFIT , ///< Display 'refit' button in #VVW_WIDGET_SELECT_REFIT_TURN stacked widget.
SEL_RT_TURN_AROUND , ///< Display 'turn around' button in #VVW_WIDGET_SELECT_REFIT_TURN stacked widget.
SEL_DC_BASEPLANE = SEL_DC_GOTO_DEPOT , ///< First plane of the #VVW_WIDGET_SELECT_DEPOT_CLONE stacked widget.
SEL_RT_BASEPLANE = SEL_RT_REFIT , ///< First plane of the #VVW_WIDGET_SELECT_REFIT_TURN stacked widget.
} ;
/** Display a plane in the window.
* @ param plane Plane to show .
*/
void SelectPlane ( PlaneSelections plane )
2008-05-19 09:39:05 +00:00
{
2009-10-24 13:49:04 +00:00
switch ( plane ) {
case SEL_DC_GOTO_DEPOT :
case SEL_DC_CLONE :
this - > GetWidget < NWidgetStacked > ( VVW_WIDGET_SELECT_DEPOT_CLONE ) - > SetDisplayedPlane ( plane - SEL_DC_BASEPLANE ) ;
break ;
2008-05-19 09:39:05 +00:00
2009-10-24 13:49:04 +00:00
case SEL_RT_REFIT :
case SEL_RT_TURN_AROUND :
this - > GetWidget < NWidgetStacked > ( VVW_WIDGET_SELECT_REFIT_TURN ) - > SetDisplayedPlane ( plane - SEL_RT_BASEPLANE ) ;
break ;
2007-08-29 20:50:58 +00:00
2009-10-24 13:49:04 +00:00
default :
NOT_REACHED ( ) ;
}
}
public :
VehicleViewWindow ( const WindowDesc * desc , WindowNumber window_number ) : Window ( )
{
2009-10-24 15:19:06 +00:00
this - > CreateNestedTree ( desc ) ;
/* Sprites for the 'send to depot' button indexed by vehicle type. */
static const SpriteID vehicle_view_goto_depot_sprites [ ] = {
SPR_SEND_TRAIN_TODEPOT ,
SPR_SEND_ROADVEH_TODEPOT ,
SPR_SEND_SHIP_TODEPOT ,
SPR_SEND_AIRCRAFT_TODEPOT ,
} ;
2009-10-24 13:49:04 +00:00
const Vehicle * v = Vehicle : : Get ( window_number ) ;
2009-10-24 15:19:06 +00:00
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_GOTO_DEPOT ) - > widget_data = vehicle_view_goto_depot_sprites [ v - > type ] ;
2009-10-24 13:49:04 +00:00
2009-10-24 15:19:06 +00:00
/* Sprites for the 'clone vehicle' button indexed by vehicle type. */
static const SpriteID vehicle_view_clone_sprites [ ] = {
SPR_CLONE_TRAIN ,
SPR_CLONE_ROADVEH ,
SPR_CLONE_SHIP ,
SPR_CLONE_AIRCRAFT ,
} ;
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_CLONE_VEH ) - > widget_data = vehicle_view_clone_sprites [ v - > type ] ;
2009-07-22 20:17:07 +00:00
2008-05-19 09:39:05 +00:00
switch ( v - > type ) {
case VEH_TRAIN :
2009-10-24 13:49:04 +00:00
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_TURN_AROUND ) - > tool_tip = STR_VEHICLE_VIEW_TRAIN_REVERSE_TOOLTIP ;
2008-05-19 09:39:05 +00:00
break ;
2007-08-29 20:50:58 +00:00
2008-05-19 09:39:05 +00:00
case VEH_ROAD :
break ;
2007-08-29 20:50:58 +00:00
2008-05-19 09:39:05 +00:00
case VEH_SHIP :
case VEH_AIRCRAFT :
2009-10-24 13:49:04 +00:00
this - > SelectPlane ( SEL_RT_REFIT ) ;
2008-05-19 09:39:05 +00:00
break ;
2009-07-22 20:17:07 +00:00
default : NOT_REACHED ( ) ;
2008-05-19 09:39:05 +00:00
}
2009-10-24 13:49:04 +00:00
this - > FinishInitNested ( desc , window_number ) ;
this - > owner = v - > owner ;
2009-10-24 13:58:18 +00:00
this - > GetWidget < NWidgetViewport > ( VVW_WIDGET_VIEWPORT ) - > InitializeViewport ( this , this - > window_number | ( 1 < < 31 ) , _vehicle_view_zoom_levels [ v - > type ] ) ;
2008-05-23 23:02:13 +00:00
2009-10-24 13:49:04 +00:00
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_START_STOP_VEH ) - > tool_tip = STR_VEHICLE_VIEW_TRAIN_STATE_START_STOP_TOOLTIP + v - > type ;
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_CENTER_MAIN_VIEH ) - > tool_tip = STR_VEHICLE_VIEW_TRAIN_LOCATION_TOOLTIP + v - > type ;
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_REFIT_VEH ) - > tool_tip = STR_VEHICLE_VIEW_TRAIN_REFIT_TOOLTIP + v - > type ;
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_GOTO_DEPOT ) - > tool_tip = STR_VEHICLE_VIEW_TRAIN_SEND_TO_DEPOT_TOOLTIP + v - > type ;
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_SHOW_ORDERS ) - > tool_tip = STR_VEHICLE_VIEW_TRAIN_ORDERS_TOOLTIP + v - > type ;
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_SHOW_DETAILS ) - > tool_tip = STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP + v - > type ;
this - > GetWidget < NWidgetCore > ( VVW_WIDGET_CLONE_VEH ) - > tool_tip = STR_VEHICLE_VIEW_CLONE_TRAIN_INFO + v - > type ;
2007-08-29 20:50:58 +00:00
}
2008-05-19 09:39:05 +00:00
~ VehicleViewWindow ( )
{
2009-01-02 20:59:04 +00:00
DeleteWindowById ( WC_VEHICLE_ORDERS , this - > window_number , false ) ;
DeleteWindowById ( WC_VEHICLE_REFIT , this - > window_number , false ) ;
DeleteWindowById ( WC_VEHICLE_DETAILS , this - > window_number , false ) ;
DeleteWindowById ( WC_VEHICLE_TIMETABLE , this - > window_number , false ) ;
2007-08-29 20:50:58 +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-24 13:49:04 +00:00
{
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
switch ( widget ) {
case VVW_WIDGET_FORCE_PROCEED :
if ( v - > type ! = VEH_TRAIN ) {
size - > height = 0 ;
size - > width = 0 ;
} break ;
2009-10-24 13:58:18 +00:00
case VVW_WIDGET_VIEWPORT :
size - > width = VV_INITIAL_VIEWPORT_WIDTH ;
size - > height = ( v - > type = = VEH_TRAIN ) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT ;
break ;
2009-10-24 13:49:04 +00:00
}
}
2008-05-19 09:39:05 +00:00
virtual void OnPaint ( )
{
2009-05-16 23:34:14 +00:00
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2008-09-30 20:39:50 +00:00
bool is_localcompany = v - > owner = = _local_company ;
2008-05-19 09:39:05 +00:00
bool refitable_and_stopped_in_depot = IsVehicleRefitable ( v ) ;
2008-09-30 20:39:50 +00:00
this - > SetWidgetDisabledState ( VVW_WIDGET_GOTO_DEPOT , ! is_localcompany ) ;
2009-10-24 13:49:04 +00:00
this - > SetWidgetDisabledState ( VVW_WIDGET_REFIT_VEH , ! refitable_and_stopped_in_depot | | ! is_localcompany ) ;
2008-09-30 20:39:50 +00:00
this - > SetWidgetDisabledState ( VVW_WIDGET_CLONE_VEH , ! is_localcompany ) ;
2008-05-19 09:39:05 +00:00
if ( v - > type = = VEH_TRAIN ) {
2009-12-16 16:23:44 +00:00
this - > SetWidgetLoweredState ( VVW_WIDGET_FORCE_PROCEED , Train : : From ( v ) - > force_proceed = = 2 ) ;
2008-09-30 20:39:50 +00:00
this - > SetWidgetDisabledState ( VVW_WIDGET_FORCE_PROCEED , ! is_localcompany ) ;
this - > SetWidgetDisabledState ( VVW_WIDGET_TURN_AROUND , ! is_localcompany ) ;
2007-08-29 20:50:58 +00:00
}
2008-05-19 09:39:05 +00:00
this - > DrawWidgets ( ) ;
2009-10-24 13:49:04 +00:00
}
virtual void SetStringParameters ( int widget ) const
{
if ( widget ! = VVW_WIDGET_CAPTION ) return ;
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
SetDParam ( 0 , v - > index ) ;
}
virtual void DrawWidget ( const Rect & r , int widget ) const
{
if ( widget ! = VVW_WIDGET_START_STOP_VEH ) return ;
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
StringID str ;
2008-05-19 09:39:05 +00:00
if ( v - > vehstatus & VS_CRASHED ) {
2009-04-21 23:40:56 +00:00
str = STR_VEHICLE_STATUS_CRASHED ;
2008-05-19 09:39:05 +00:00
} else if ( v - > type ! = VEH_AIRCRAFT & & v - > breakdown_ctr = = 1 ) { // check for aircraft necessary?
2009-04-21 23:40:56 +00:00
str = STR_VEHICLE_STATUS_BROKEN_DOWN ;
2008-05-19 09:39:05 +00:00
} else if ( v - > vehstatus & VS_STOPPED ) {
if ( v - > type = = VEH_TRAIN ) {
if ( v - > cur_speed = = 0 ) {
2009-06-06 16:54:22 +00:00
if ( Train : : From ( v ) - > tcache . cached_power = = 0 ) {
2009-08-05 17:59:21 +00:00
str = STR_VEHICLE_STATUS_TRAIN_NO_POWER ;
2008-05-19 09:39:05 +00:00
} else {
2009-04-21 23:40:56 +00:00
str = STR_VEHICLE_STATUS_STOPPED ;
2008-05-19 09:39:05 +00:00
}
2007-08-29 20:50:58 +00:00
} else {
2008-05-19 09:39:05 +00:00
SetDParam ( 0 , v - > GetDisplaySpeed ( ) ) ;
2009-08-05 17:59:21 +00:00
str = STR_VEHICLE_STATUS_TRAIN_STOPPING + _settings_client . gui . vehicle_speed ;
2007-08-29 20:50:58 +00:00
}
2008-05-19 09:39:05 +00:00
} else { // no train
2009-04-21 23:40:56 +00:00
str = STR_VEHICLE_STATUS_STOPPED ;
2007-08-29 20:50:58 +00:00
}
2009-07-21 17:14:05 +00:00
} else if ( v - > type = = VEH_TRAIN & & HasBit ( Train : : From ( v ) - > flags , VRF_TRAIN_STUCK ) & & ! v - > current_order . IsType ( OT_LOADING ) ) {
2009-08-05 17:59:21 +00:00
str = STR_VEHICLE_STATUS_TRAIN_STUCK ;
2008-05-19 09:39:05 +00:00
} else { // vehicle is in a "normal" state, show current order
switch ( v - > current_order . GetType ( ) ) {
case OT_GOTO_STATION : {
2008-04-06 07:48:51 +00:00
SetDParam ( 0 , v - > current_order . GetDestination ( ) ) ;
2007-08-29 20:50:58 +00:00
SetDParam ( 1 , v - > GetDisplaySpeed ( ) ) ;
2009-08-05 17:59:21 +00:00
str = STR_VEHICLE_STATUS_HEADING_FOR_STATION + _settings_client . gui . vehicle_speed ;
2008-05-19 09:39:05 +00:00
} break ;
case OT_GOTO_DEPOT : {
if ( v - > type = = VEH_AIRCRAFT ) {
/* Aircrafts always go to a station, even if you say depot */
SetDParam ( 0 , v - > current_order . GetDestination ( ) ) ;
SetDParam ( 1 , v - > GetDisplaySpeed ( ) ) ;
} else {
2009-05-16 23:34:14 +00:00
Depot * depot = Depot : : Get ( v - > current_order . GetDestination ( ) ) ;
2008-05-19 09:39:05 +00:00
SetDParam ( 0 , depot - > town_index ) ;
SetDParam ( 1 , v - > GetDisplaySpeed ( ) ) ;
}
2008-10-24 14:49:45 +00:00
if ( v - > current_order . GetDepotActionType ( ) & ODATFB_HALT ) {
2009-08-05 17:59:21 +00:00
str = STR_VEHICLE_STATUS_HEADING_FOR_TRAIN_DEPOT + 2 * v - > type + _settings_client . gui . vehicle_speed ;
2008-05-19 09:39:05 +00:00
} else {
2009-08-05 17:59:21 +00:00
str = STR_VEHICLE_STATUS_HEADING_FOR_TRAIN_DEPOT_SERVICE + 2 * v - > type + _settings_client . gui . vehicle_speed ;
2008-05-19 09:39:05 +00:00
}
} break ;
case OT_LOADING :
2009-04-21 23:40:56 +00:00
str = STR_VEHICLE_STATUS_LOADING_UNLOADING ;
2008-05-19 09:39:05 +00:00
break ;
case OT_GOTO_WAYPOINT : {
2009-07-10 18:30:02 +00:00
assert ( v - > type = = VEH_TRAIN | | v - > type = = VEH_SHIP ) ;
2008-05-19 09:39:05 +00:00
SetDParam ( 0 , v - > current_order . GetDestination ( ) ) ;
2009-08-05 17:59:21 +00:00
str = STR_VEHICLE_STATUS_HEADING_FOR_WAYPOINT + _settings_client . gui . vehicle_speed ;
2007-08-29 20:50:58 +00:00
SetDParam ( 1 , v - > GetDisplaySpeed ( ) ) ;
2008-05-19 09:39:05 +00:00
break ;
2007-08-29 20:50:58 +00:00
}
2008-05-19 09:39:05 +00:00
case OT_LEAVESTATION :
if ( v - > type ! = VEH_AIRCRAFT ) {
2009-04-21 23:40:56 +00:00
str = STR_VEHICLE_STATUS_LEAVING ;
2008-05-19 09:39:05 +00:00
break ;
}
/* fall-through if aircraft. Does this even happen? */
2007-08-29 20:50:58 +00:00
2008-05-19 09:39:05 +00:00
default :
2009-01-03 13:20:32 +00:00
if ( v - > GetNumOrders ( ) = = 0 ) {
2009-08-05 17:59:21 +00:00
str = STR_VEHICLE_STATUS_NO_ORDERS + _settings_client . gui . vehicle_speed ;
2008-05-19 09:39:05 +00:00
SetDParam ( 0 , v - > GetDisplaySpeed ( ) ) ;
} else {
str = STR_EMPTY ;
}
break ;
2007-08-29 20:50:58 +00:00
}
2008-05-19 09:39:05 +00:00
}
2007-08-29 20:50:58 +00:00
2008-05-19 09:39:05 +00:00
/* draw the flag plus orders */
2009-10-24 13:49:04 +00:00
DrawSprite ( v - > vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING , PAL_NONE , WD_FRAMERECT_LEFT , r . top + WD_FRAMERECT_TOP ) ;
DrawString ( r . left + WD_FRAMERECT_LEFT + 6 , r . right - WD_FRAMERECT_RIGHT , r . top + WD_FRAMERECT_TOP , str , TC_FROMSTRING , SA_CENTER ) ;
2008-05-19 09:39:05 +00:00
}
virtual void OnClick ( Point pt , int widget )
{
2009-05-16 23:34:14 +00:00
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2008-05-19 09:39:05 +00:00
switch ( widget ) {
case VVW_WIDGET_START_STOP_VEH : // start stop
2008-12-28 14:37:19 +00:00
DoCommandP ( v - > tile , v - > index , 0 ,
2008-05-19 09:39:05 +00:00
_vehicle_command_translation_table [ VCT_CMD_START_STOP ] [ v - > type ] ) ;
break ;
2009-03-15 00:32:18 +00:00
case VVW_WIDGET_CENTER_MAIN_VIEH : { // center main view
2008-05-19 09:39:05 +00:00
const Window * mainwindow = FindWindowById ( WC_MAIN_WINDOW , 0 ) ;
/* code to allow the main window to 'follow' the vehicle if the ctrl key is pressed */
if ( _ctrl_pressed & & mainwindow - > viewport - > zoom = = ZOOM_LVL_NORMAL ) {
mainwindow - > viewport - > follow_vehicle = v - > index ;
} else {
2009-03-15 15:25:18 +00:00
ScrollMainWindowTo ( v - > x_pos , v - > y_pos , v - > z_pos ) ;
2007-08-29 20:50:58 +00:00
}
2008-05-19 09:39:05 +00:00
} break ;
2007-08-29 20:50:58 +00:00
2008-05-19 09:39:05 +00:00
case VVW_WIDGET_GOTO_DEPOT : // goto hangar
2009-07-22 23:39:35 +00:00
DoCommandP ( v - > tile , v - > index , _ctrl_pressed ? DEPOT_SERVICE : 0 , GetCmdSendToDepot ( v ) ) ;
2008-05-19 09:39:05 +00:00
break ;
case VVW_WIDGET_REFIT_VEH : // refit
2008-09-24 16:40:06 +00:00
ShowVehicleRefitWindow ( v , INVALID_VEH_ORDER_ID , this ) ;
2008-05-19 09:39:05 +00:00
break ;
case VVW_WIDGET_SHOW_ORDERS : // show orders
if ( _ctrl_pressed ) {
ShowTimetableWindow ( v ) ;
2007-08-29 20:50:58 +00:00
} else {
2008-05-19 09:39:05 +00:00
ShowOrdersWindow ( v ) ;
2007-08-29 20:50:58 +00:00
}
break ;
2008-05-19 09:39:05 +00:00
case VVW_WIDGET_SHOW_DETAILS : // show details
ShowVehicleDetailsWindow ( v ) ;
break ;
case VVW_WIDGET_CLONE_VEH : // clone vehicle
2008-12-28 14:37:19 +00:00
DoCommandP ( v - > tile , v - > index , _ctrl_pressed ? 1 : 0 ,
_vehicle_command_translation_table [ VCT_CMD_CLONE_VEH ] [ v - > type ] ,
CcCloneVehicle ) ;
2008-05-19 09:39:05 +00:00
break ;
case VVW_WIDGET_TURN_AROUND : // turn around
assert ( v - > type = = VEH_TRAIN | | v - > type = = VEH_ROAD ) ;
2008-12-28 14:37:19 +00:00
DoCommandP ( v - > tile , v - > index , 0 ,
2008-05-19 09:39:05 +00:00
_vehicle_command_translation_table [ VCT_CMD_TURN_AROUND ] [ v - > type ] ) ;
break ;
case VVW_WIDGET_FORCE_PROCEED : // force proceed
assert ( v - > type = = VEH_TRAIN ) ;
2009-04-21 23:40:56 +00:00
DoCommandP ( v - > tile , v - > index , 0 , CMD_FORCE_TRAIN_PROCEED | CMD_MSG ( STR_ERROR_CAN_T_MAKE_TRAIN_PASS_SIGNAL ) ) ;
2008-05-19 09:39:05 +00:00
break ;
2007-08-29 20:50:58 +00:00
}
}
2009-10-24 14:53:55 +00:00
virtual void OnResize ( )
2008-05-19 09:39:05 +00:00
{
2009-10-24 13:58:18 +00:00
if ( this - > viewport ! = NULL ) {
NWidgetViewport * nvp = this - > GetWidget < NWidgetViewport > ( VVW_WIDGET_VIEWPORT ) ;
nvp - > UpdateViewportCoordinates ( this ) ;
}
2008-05-19 09:39:05 +00:00
}
2007-08-29 20:50:58 +00:00
2008-05-19 09:39:05 +00:00
virtual void OnTick ( )
{
2009-05-16 23:34:14 +00:00
const Vehicle * v = Vehicle : : Get ( this - > window_number ) ;
2008-05-19 09:39:05 +00:00
bool veh_stopped = v - > IsStoppedInDepot ( ) ;
2009-10-24 13:49:04 +00:00
/* Widget VVW_WIDGET_GOTO_DEPOT must be hidden if the vehicle is already stopped in depot.
* Widget VVW_WIDGET_CLONE_VEH should then be shown , since cloning is allowed only while in depot and stopped .
*/
PlaneSelections plane = veh_stopped ? SEL_DC_CLONE : SEL_DC_GOTO_DEPOT ;
NWidgetStacked * nwi = this - > GetWidget < NWidgetStacked > ( VVW_WIDGET_SELECT_DEPOT_CLONE ) ; // Selection widget 'send to depot' / 'clone'.
if ( nwi - > shown_plane + SEL_DC_BASEPLANE ! = plane ) {
this - > SelectPlane ( plane ) ;
this - > SetWidgetDirty ( VVW_WIDGET_SELECT_DEPOT_CLONE ) ;
}
/* The same system applies to widget VVW_WIDGET_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/
if ( v - > type = = VEH_ROAD | | v - > type = = VEH_TRAIN ) {
PlaneSelections plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND ;
NWidgetStacked * nwi = this - > GetWidget < NWidgetStacked > ( VVW_WIDGET_SELECT_REFIT_TURN ) ;
if ( nwi - > shown_plane + SEL_RT_BASEPLANE ! = plane ) {
this - > SelectPlane ( plane ) ;
this - > SetWidgetDirty ( VVW_WIDGET_SELECT_REFIT_TURN ) ;
2008-05-19 09:39:05 +00:00
}
}
}
2007-08-29 20:50:58 +00:00
} ;
2008-05-19 09:39:05 +00:00
/** Shows the vehicle view window of the given vehicle. */
void ShowVehicleViewWindow ( const Vehicle * v )
2007-08-29 20:50:58 +00:00
{
2008-05-19 09:39:05 +00:00
AllocateWindowDescFront < VehicleViewWindow > ( ( v - > type = = VEH_TRAIN ) ? & _train_view_desc : & _vehicle_view_desc , v - > index ) ;
2007-08-29 20:50:58 +00:00
}
2007-12-27 13:35:39 +00:00
2008-05-17 13:01:30 +00:00
void StopGlobalFollowVehicle ( const Vehicle * v )
{
Window * w = FindWindowById ( WC_MAIN_WINDOW , 0 ) ;
if ( w ! = NULL & & w - > viewport - > follow_vehicle = = v - > index ) {
2009-03-15 15:25:18 +00:00
ScrollMainWindowTo ( v - > x_pos , v - > y_pos , v - > z_pos , true ) ; // lock the main view on the vehicle's last position
2008-05-17 13:01:30 +00:00
w - > viewport - > follow_vehicle = INVALID_VEHICLE ;
}
}
2010-01-11 18:34:02 +00:00
/**
* This is the Callback method after the construction attempt of a primary vehicle
2010-01-11 18:46:09 +00:00
* @ param result indicates completion ( or not ) of the operation
2010-01-11 18:34:02 +00:00
* @ param tile unused
* @ param p1 unused
* @ param p2 unused
*/
2010-01-11 18:46:09 +00:00
void CcBuildPrimaryVehicle ( const CommandCost & result , TileIndex tile , uint32 p1 , uint32 p2 )
2010-01-11 18:34:02 +00:00
{
2010-01-11 18:46:09 +00:00
if ( result . Failed ( ) ) return ;
2010-01-11 18:34:02 +00:00
const Vehicle * v = Vehicle : : Get ( _new_vehicle_id ) ;
if ( v - > tile = = _backup_orders_tile ) {
_backup_orders_tile = 0 ;
RestoreVehicleOrders ( v ) ;
}
ShowVehicleViewWindow ( v ) ;
}