src/vehicle_gui.cpp
branchgamebalance
changeset 9911 0b8b245a2391
parent 9910 0b2aebc8283e
child 9913 e79cd19772dd
equal deleted inserted replaced
9910:0b2aebc8283e 9911:0b8b245a2391
    29 #include "aircraft.h"
    29 #include "aircraft.h"
    30 #include "roadveh.h"
    30 #include "roadveh.h"
    31 #include "depot.h"
    31 #include "depot.h"
    32 #include "helpers.hpp"
    32 #include "helpers.hpp"
    33 #include "cargotype.h"
    33 #include "cargotype.h"
       
    34 #include "group.h"
    34 
    35 
    35 struct Sorting {
    36 struct Sorting {
    36 	Listing aircraft;
    37 	Listing aircraft;
    37 	Listing roadveh;
    38 	Listing roadveh;
    38 	Listing ship;
    39 	Listing ship;
    39 	Listing train;
    40 	Listing train;
    40 };
    41 };
    41 
    42 
    42 static Sorting _sorting;
    43 static Sorting _sorting;
    43 
       
    44 struct vehiclelist_d {
       
    45 	const Vehicle** sort_list;  // List of vehicles (sorted)
       
    46 	Listing *_sorting;          // pointer to the appropiate subcategory of _sorting
       
    47 	uint16 length_of_sort_list; // Keeps track of how many vehicle pointers sort list got space for
       
    48 	byte vehicle_type;          // The vehicle type that is sorted
       
    49 	list_d l;                   // General list struct
       
    50 };
       
    51 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
       
    52 
    44 
    53 static bool   _internal_sort_order;     // descending/ascending
    45 static bool   _internal_sort_order;     // descending/ascending
    54 
    46 
    55 typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*);
    47 typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*);
    56 
    48 
    76 	&VehicleMaxSpeedSorter,
    68 	&VehicleMaxSpeedSorter,
    77 	&VehicleModelSorter,
    69 	&VehicleModelSorter,
    78 	&VehicleValueSorter,
    70 	&VehicleValueSorter,
    79 };
    71 };
    80 
    72 
    81 static const StringID _vehicle_sort_listing[] = {
    73 const StringID _vehicle_sort_listing[] = {
    82 	STR_SORT_BY_NUMBER,
    74 	STR_SORT_BY_NUMBER,
    83 	STR_SORT_BY_DROPDOWN_NAME,
    75 	STR_SORT_BY_DROPDOWN_NAME,
    84 	STR_SORT_BY_AGE,
    76 	STR_SORT_BY_AGE,
    85 	STR_SORT_BY_PROFIT_THIS_YEAR,
    77 	STR_SORT_BY_PROFIT_THIS_YEAR,
    86 	STR_SORT_BY_PROFIT_LAST_YEAR,
    78 	STR_SORT_BY_PROFIT_LAST_YEAR,
   132 			default: break;
   124 			default: break;
   133 		}
   125 		}
   134 	}
   126 	}
   135 }
   127 }
   136 
   128 
   137 static void BuildVehicleList(vehiclelist_d* vl, PlayerID owner, uint16 index, uint16 window_type)
   129 void BuildVehicleList(vehiclelist_d *vl, PlayerID owner, uint16 index, uint16 window_type)
   138 {
   130 {
   139 	if (!(vl->l.flags & VL_REBUILD)) return;
   131 	if (!(vl->l.flags & VL_REBUILD)) return;
   140 
   132 
   141 	DEBUG(misc, 3, "Building vehicle list for player %d at station %d", owner, index);
   133 	DEBUG(misc, 3, "Building vehicle list for player %d at station %d", owner, index);
   142 
   134 
   144 
   136 
   145 	vl->l.flags &= ~VL_REBUILD;
   137 	vl->l.flags &= ~VL_REBUILD;
   146 	vl->l.flags |= VL_RESORT;
   138 	vl->l.flags |= VL_RESORT;
   147 }
   139 }
   148 
   140 
   149 static void SortVehicleList(vehiclelist_d *vl)
   141 void SortVehicleList(vehiclelist_d *vl)
   150 {
   142 {
   151 	if (!(vl->l.flags & VL_RESORT)) return;
   143 	if (!(vl->l.flags & VL_RESORT)) return;
   152 
   144 
   153 	_internal_sort_order = (vl->l.flags & VL_DESC) != 0;
   145 	_internal_sort_order = (vl->l.flags & VL_DESC) != 0;
   154 	qsort((void*)vl->sort_list, vl->l.list_length, sizeof(vl->sort_list[0]),
   146 	qsort((void*)vl->sort_list, vl->l.list_length, sizeof(vl->sort_list[0]),
   375 
   367 
   376 						if (WP(w, refit_d).order == INVALID_VEH_ORDER_ID) {
   368 						if (WP(w, refit_d).order == INVALID_VEH_ORDER_ID) {
   377 							int command = 0;
   369 							int command = 0;
   378 
   370 
   379 							switch (v->type) {
   371 							switch (v->type) {
       
   372 								default: NOT_REACHED();
   380 								case VEH_TRAIN:    command = CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE);  break;
   373 								case VEH_TRAIN:    command = CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE);  break;
   381 								case VEH_ROAD:     command = CMD_REFIT_ROAD_VEH     | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T);  break;
   374 								case VEH_ROAD:     command = CMD_REFIT_ROAD_VEH     | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T);  break;
   382 								case VEH_SHIP:     command = CMD_REFIT_SHIP         | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP);     break;
   375 								case VEH_SHIP:     command = CMD_REFIT_SHIP         | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP);     break;
   383 								case VEH_AIRCRAFT: command = CMD_REFIT_AIRCRAFT     | CMD_MSG(STR_A042_CAN_T_REFIT_AIRCRAFT); break;
   376 								case VEH_AIRCRAFT: command = CMD_REFIT_AIRCRAFT     | CMD_MSG(STR_A042_CAN_T_REFIT_AIRCRAFT); break;
   384 							}
   377 							}
   746 			SetWindowDirty(w);
   739 			SetWindowDirty(w);
   747 		}
   740 		}
   748 	}
   741 	}
   749 }
   742 }
   750 
   743 
   751 /*
       
   752  * Start of functions regarding vehicle list windows
       
   753  */
       
   754 
       
   755 enum {
       
   756 	PLY_WND_PRC__OFFSET_TOP_WIDGET = 26,
       
   757 	PLY_WND_PRC__SIZE_OF_ROW_SMALL = 26,
       
   758 	PLY_WND_PRC__SIZE_OF_ROW_BIG   = 36,
       
   759 };
       
   760 
       
   761 enum VehicleListWindowWidgets {
   744 enum VehicleListWindowWidgets {
   762 	VLW_WIDGET_CLOSEBOX = 0,
   745 	VLW_WIDGET_CLOSEBOX = 0,
   763 	VLW_WIDGET_CAPTION,
   746 	VLW_WIDGET_CAPTION,
   764 	VLW_WIDGET_STICKY,
   747 	VLW_WIDGET_STICKY,
   765 	VLW_WIDGET_SORT_ORDER,
   748 	VLW_WIDGET_SORT_ORDER,
   806 {
   789 {
   807 	vehiclelist_d *vl = &WP(w, vehiclelist_d);
   790 	vehiclelist_d *vl = &WP(w, vehiclelist_d);
   808 	uint16 window_type = w->window_number & VLW_MASK;
   791 	uint16 window_type = w->window_number & VLW_MASK;
   809 	PlayerID player = (PlayerID)GB(w->window_number, 0, 8);
   792 	PlayerID player = (PlayerID)GB(w->window_number, 0, 8);
   810 
   793 
   811 	vl->vehicle_type = GB(w->window_number, 11, 5);
   794 	vl->vehicle_type = (VehicleType)GB(w->window_number, 11, 5);
   812 	vl->length_of_sort_list = 0;
   795 	vl->length_of_sort_list = 0;
   813 	vl->sort_list = NULL;
   796 	vl->sort_list = NULL;
   814 	w->caption_color = player;
   797 	w->caption_color = player;
   815 
   798 
   816 	/* Hide the widgets that we will not use in this window
   799 	/* Hide the widgets that we will not use in this window
   923 	vl->l.sort_type = vl->_sorting->criteria;
   906 	vl->l.sort_type = vl->_sorting->criteria;
   924 	vl->sort_list = NULL;
   907 	vl->sort_list = NULL;
   925 	vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
   908 	vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer
   926 }
   909 }
   927 
   910 
   928 static void DrawSmallOrderList(const Vehicle *v, int x, int y)
   911 void DrawSmallOrderList(const Vehicle *v, int x, int y)
   929 {
   912 {
   930 	const Order *order;
   913 	const Order *order;
   931 	int sel, i = 0;
   914 	int sel, i = 0;
   932 
   915 
   933 	sel = v->cur_order_index;
   916 	sel = v->cur_order_index;
  1233 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  1216 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  1234 	_vehicle_list_widgets,
  1217 	_vehicle_list_widgets,
  1235 	PlayerVehWndProc
  1218 	PlayerVehWndProc
  1236 };
  1219 };
  1237 
  1220 
  1238 static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, byte vehicle_type, uint16 unique_number)
  1221 static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, VehicleType vehicle_type, uint16 unique_number)
  1239 {
  1222 {
  1240 	Window *w;
  1223 	Window *w;
  1241 	WindowNumber num;
  1224 	WindowNumber num;
  1242 
  1225 
  1243 	if (!IsValidPlayer(player)) return;
  1226 	if (!IsValidPlayer(player)) return;
  1270 		w->resize.width = w->width;
  1253 		w->resize.width = w->width;
  1271 		w->resize.height = w->height;
  1254 		w->resize.height = w->height;
  1272 	}
  1255 	}
  1273 }
  1256 }
  1274 
  1257 
  1275 void ShowVehicleListWindow(PlayerID player, byte vehicle_type)
  1258 void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type)
  1276 {
  1259 {
  1277 	ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0);
  1260 	if (player == _local_player && _patches.advanced_vehicle_list) {
       
  1261 		ShowPlayerGroup(player, vehicle_type);
       
  1262 	} else {
       
  1263 		ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0);
       
  1264 	}
  1278 }
  1265 }
  1279 
  1266 
  1280 void ShowVehicleListWindow(const Vehicle *v)
  1267 void ShowVehicleListWindow(const Vehicle *v)
  1281 {
  1268 {
  1282 	if (v->orders == NULL) return; // no shared list to show
  1269 	if (v->orders == NULL) return; // no shared list to show
  1283 	ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->orders->index);
  1270 	ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->orders->index);
  1284 }
  1271 }
  1285 
  1272 
  1286 void ShowVehicleListWindow(PlayerID player, byte vehicle_type, StationID station)
  1273 void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station)
  1287 {
  1274 {
  1288 	ShowVehicleListWindowLocal(player, VLW_STATION_LIST, vehicle_type, station);
  1275 	ShowVehicleListWindowLocal(player, VLW_STATION_LIST, vehicle_type, station);
  1289 }
  1276 }
  1290 
  1277 
  1291 void ShowVehicleListWindow(PlayerID player, byte vehicle_type, TileIndex depot_tile)
  1278 void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, TileIndex depot_tile)
  1292 {
  1279 {
  1293 	uint16 depot_airport_index;
  1280 	uint16 depot_airport_index;
  1294 
  1281 
  1295 	if (vehicle_type == VEH_AIRCRAFT) {
  1282 	if (vehicle_type == VEH_AIRCRAFT) {
  1296 		depot_airport_index = GetStationIndex(depot_tile);
  1283 		depot_airport_index = GetStationIndex(depot_tile);