diff -r 5a8b295aa345 -r 4cc327ad39d5 src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp Tue Mar 27 23:27:27 2007 +0000 +++ b/src/vehicle_gui.cpp Sat Jun 02 19:59:29 2007 +0000 @@ -1,5 +1,7 @@ /* $Id$ */ +/** @file vehicle_gui.cpp */ + #include "stdafx.h" #include "openttd.h" #include "debug.h" @@ -29,6 +31,7 @@ #include "depot.h" #include "helpers.hpp" #include "cargotype.h" +#include "group.h" struct Sorting { Listing aircraft; @@ -39,15 +42,6 @@ static Sorting _sorting; -struct vehiclelist_d { - const Vehicle** sort_list; // List of vehicles (sorted) - Listing *_sorting; // pointer to the appropiate subcategory of _sorting - uint16 length_of_sort_list; // Keeps track of how many vehicle pointers sort list got space for - byte vehicle_type; // The vehicle type that is sorted - list_d l; // General list struct -}; -assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d)); - static bool _internal_sort_order; // descending/ascending typedef int CDECL VehicleSortListingTypeFunction(const void*, const void*); @@ -76,7 +70,7 @@ &VehicleValueSorter, }; -static const StringID _vehicle_sort_listing[] = { +const StringID _vehicle_sort_listing[] = { STR_SORT_BY_NUMBER, STR_SORT_BY_DROPDOWN_NAME, STR_SORT_BY_AGE, @@ -132,7 +126,7 @@ } } -static void BuildVehicleList(vehiclelist_d* vl, PlayerID owner, uint16 index, uint16 window_type) +void BuildVehicleList(vehiclelist_d *vl, PlayerID owner, uint16 index, uint16 window_type) { if (!(vl->l.flags & VL_REBUILD)) return; @@ -144,7 +138,7 @@ vl->l.flags |= VL_RESORT; } -static void SortVehicleList(vehiclelist_d *vl) +void SortVehicleList(vehiclelist_d *vl) { if (!(vl->l.flags & VL_RESORT)) return; @@ -162,12 +156,12 @@ qsort((void*)v, length, sizeof(v[0]), _vehicle_sorter[0]); } -// draw the vehicle profit button in the vehicle list window. +/** draw the vehicle profit button in the vehicle list window. */ void DrawVehicleProfitButton(const Vehicle *v, int x, int y) { SpriteID pal; - // draw profit-based colored icons + /* draw profit-based colored icons */ if (v->age <= 365 * 2) { pal = PALETTE_TO_GREY; } else if (v->profit_last_year < 0) { @@ -277,8 +271,11 @@ /** Draw the list of available refit options for a consist. * Draw the list and highlight the selected refit option (if any) - * @param *v first vehicle in consist to get the refit-options of + * @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 * @return the refit option that is hightlighted, NULL if none */ static RefitOption *DrawVehicleRefitWindow(const RefitList *list, int sel, uint pos, uint rows, uint delta) @@ -338,48 +335,49 @@ SetDParam(1, v->unitnumber); DrawWindowWidgets(w); - WP(w,refit_d).cargo = DrawVehicleRefitWindow(WP(w, refit_d).list, WP(w, refit_d).sel, w->vscroll.pos, w->vscroll.cap, w->resize.step_height); + WP(w, refit_d).cargo = DrawVehicleRefitWindow(WP(w, refit_d).list, WP(w, refit_d).sel, w->vscroll.pos, w->vscroll.cap, w->resize.step_height); - if (WP(w,refit_d).cargo != NULL) { + if (WP(w, refit_d).cargo != NULL) { int32 cost; - cost = DoCommand(v->tile, v->index, WP(w,refit_d).cargo->cargo | WP(w,refit_d).cargo->subtype << 8, + cost = DoCommand(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8, DC_QUERY_COST, GetCmdRefitVeh(GetVehicle(w->window_number)->type)); if (!CmdFailed(cost)) { - SetDParam(0, WP(w,refit_d).cargo->cargo); + SetDParam(0, WP(w, refit_d).cargo->cargo); SetDParam(1, _returned_refit_capacity); SetDParam(2, cost); DrawString(2, w->widget[5].top + 1, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0); } } - } break; + } break; case WE_CLICK: switch (e->we.click.widget) { case 3: { // listbox int y = e->we.click.pt.y - w->widget[3].top; if (y >= 0) { - WP(w,refit_d).sel = (y / (int)w->resize.step_height) + w->vscroll.pos; + WP(w, refit_d).sel = (y / (int)w->resize.step_height) + w->vscroll.pos; SetWindowDirty(w); } } break; case 6: // refit button - if (WP(w,refit_d).cargo != NULL) { + if (WP(w, refit_d).cargo != NULL) { const Vehicle *v = GetVehicle(w->window_number); if (WP(w, refit_d).order == INVALID_VEH_ORDER_ID) { int command = 0; switch (v->type) { + default: NOT_REACHED(); case VEH_TRAIN: command = CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE); break; case VEH_ROAD: command = CMD_REFIT_ROAD_VEH | CMD_MSG(STR_REFIT_ROAD_VEHICLE_CAN_T); break; case VEH_SHIP: command = CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP); break; case VEH_AIRCRAFT: command = CMD_REFIT_AIRCRAFT | CMD_MSG(STR_A042_CAN_T_REFIT_AIRCRAFT); break; } - if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo->cargo | WP(w,refit_d).cargo->subtype << 8, NULL, command)) DeleteWindow(w); + if (DoCommandP(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8, NULL, command)) DeleteWindow(w); } else { - if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo->cargo | WP(w,refit_d).cargo->subtype << 8 | WP(w, refit_d).order << 16, NULL, CMD_ORDER_REFIT)) DeleteWindow(w); + if (DoCommandP(v->tile, v->index, WP(w, refit_d).cargo->cargo | WP(w, refit_d).cargo->subtype << 8 | WP(w, refit_d).order << 16, NULL, CMD_ORDER_REFIT)) DeleteWindow(w); } } break; @@ -413,7 +411,7 @@ static const WindowDesc _vehicle_refit_desc = { WDP_AUTO, WDP_AUTO, 240, 174, - WC_VEHICLE_REFIT,WC_VEHICLE_VIEW, + WC_VEHICLE_REFIT, WC_VEHICLE_VIEW, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, _vehicle_refit_widgets, VehicleRefitWndProc, @@ -421,6 +419,7 @@ /** Show the refit window for a vehicle * @param *v The vehicle to show the refit window for +* @param order of the vehicle ( ? ) */ void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order) { @@ -466,18 +465,18 @@ } } -/* Display additional text from NewGRF in the purchase information window */ +/** Display additional text from NewGRF in the purchase information window */ uint ShowAdditionalText(int x, int y, uint w, EngineID engine) { uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, NULL); if (callback == CALLBACK_FAILED) return 0; - // STR_02BD is used to start the string with {BLACK} + /* STR_02BD is used to start the string with {BLACK} */ SetDParam(0, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback)); return DrawStringMultiLine(x, y, STR_02BD, w); } -/* Count the number of bits that are set in a mask */ +/** Count the number of bits that are set in a mask */ static uint CountBits(uint32 mask) { uint c = 0; @@ -485,7 +484,7 @@ return c; } -/* Display list of cargo types of the engine, for the purchase information window */ +/** Display list of cargo types of the engine, for the purchase information window */ uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine) { /* List of cargo types of this engine */ @@ -529,7 +528,7 @@ } -// if the sorting criteria had the same value, sort vehicle by unitnumber +/* if the sorting criteria had the same value, sort vehicle by unitnumber */ #define VEHICLEUNITNUMBERSORTER(r, a, b) {if (r == 0) {r = a->unitnumber - b->unitnumber;}} static int CDECL VehicleNumberSorter(const void *a, const void *b) @@ -742,16 +741,6 @@ } } -/* - * Start of functions regarding vehicle list windows - */ - -enum { - PLY_WND_PRC__OFFSET_TOP_WIDGET = 26, - PLY_WND_PRC__SIZE_OF_ROW_SMALL = 26, - PLY_WND_PRC__SIZE_OF_ROW_BIG = 36, -}; - enum VehicleListWindowWidgets { VLW_WIDGET_CLOSEBOX = 0, VLW_WIDGET_CAPTION, @@ -802,7 +791,7 @@ uint16 window_type = w->window_number & VLW_MASK; PlayerID player = (PlayerID)GB(w->window_number, 0, 8); - vl->vehicle_type = GB(w->window_number, 11, 5); + vl->vehicle_type = (VehicleType)GB(w->window_number, 11, 5); vl->length_of_sort_list = 0; vl->sort_list = NULL; w->caption_color = player; @@ -916,10 +905,10 @@ vl->l.flags = VL_REBUILD | (vl->_sorting->order ? VL_DESC : VL_NONE); vl->l.sort_type = vl->_sorting->criteria; vl->sort_list = NULL; - vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer + vl->l.resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; // Set up resort timer } -static void DrawSmallOrderList(const Vehicle *v, int x, int y) +void DrawSmallOrderList(const Vehicle *v, int x, int y) { const Order *order; int sel, i = 0; @@ -1134,13 +1123,13 @@ DoCommandP(0, GB(w->window_number, 16, 16), (w->window_number & VLW_MASK) | (1 << 6) | (e->we.click.widget == VLW_WIDGET_START_ALL ? (1 << 5) : 0) | vl->vehicle_type, NULL, CMD_MASS_START_STOP); break; } - } break; + } break; case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */ switch (e->we.dropdown.button) { case VLW_WIDGET_SORT_BY_PULLDOWN: if (vl->l.sort_type != e->we.dropdown.index) { - // value has changed -> resort + /* value has changed -> resort */ vl->l.flags |= VL_RESORT; vl->l.sort_type = e->we.dropdown.index; vl->_sorting->criteria = vl->l.sort_type; @@ -1229,7 +1218,7 @@ PlayerVehWndProc }; -static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, byte vehicle_type, uint16 unique_number) +static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, VehicleType vehicle_type, uint16 unique_number) { Window *w; WindowNumber num; @@ -1266,9 +1255,13 @@ } } -void ShowVehicleListWindow(PlayerID player, byte vehicle_type) +void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type) { - ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0); + if (player == _local_player && _patches.advanced_vehicle_list) { + ShowPlayerGroup(player, vehicle_type); + } else { + ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0); + } } void ShowVehicleListWindow(const Vehicle *v) @@ -1277,12 +1270,12 @@ ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->orders->index); } -void ShowVehicleListWindow(PlayerID player, byte vehicle_type, StationID station) +void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station) { ShowVehicleListWindowLocal(player, VLW_STATION_LIST, vehicle_type, station); } -void ShowVehicleListWindow(PlayerID player, byte vehicle_type, TileIndex depot_tile) +void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, TileIndex depot_tile) { uint16 depot_airport_index;