# autoreplace_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: autoreplace_gui.cpp 12054 2008-02-04 11:28:12Z peter1138 $ */
    00002
    00005 #include "stdafx.h"
    00006 #include "openttd.h"
    00007 #include "debug.h"
    00008 #include "gui.h"
    00009 #include "command_func.h"
    00010 #include "variables.h"
    00011 #include "vehicle_gui.h"
    00012 #include "newgrf_engine.h"
    00013 #include "group.h"
    00014 #include "rail.h"
    00015 #include "strings_func.h"
    00016 #include "window_func.h"
    00017 #include "vehicle_func.h"
    00018 #include "autoreplace_func.h"
    00019 #include "gfx_func.h"
    00020 #include "player_func.h"
    00021 #include "widgets/dropdown_func.h"
    00022
    00023 #include "table/sprites.h"
    00024 #include "table/strings.h"
    00025
    00026 static RailType _railtype_selected_in_replace_gui;
    00027
    00028 static bool _rebuild_left_list;
    00029 static bool _rebuild_right_list;
    00030
    00031 static const StringID _rail_types_list[] = {
    00032   STR_RAIL_VEHICLES,
    00033   STR_ELRAIL_VEHICLES,
    00034   STR_MONORAIL_VEHICLES,
    00035   STR_MAGLEV_VEHICLES,
    00036   INVALID_STRING_ID
    00037 };
    00038
    00039 enum ReplaceVehicleWindowWidgets {
    00040   RVW_WIDGET_LEFT_DETAILS = 3,
    00041   RVW_WIDGET_START_REPLACE,
    00042   RVW_WIDGET_INFO_TAB,
    00043   RVW_WIDGET_STOP_REPLACE,
    00044   RVW_WIDGET_LEFT_MATRIX,
    00045   RVW_WIDGET_LEFT_SCROLLBAR,
    00046   RVW_WIDGET_RIGHT_MATRIX,
    00047   RVW_WIDGET_RIGHT_SCROLLBAR,
    00048   RVW_WIDGET_RIGHT_DETAILS,
    00049
    00050   RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE,
    00051   RVW_WIDGET_TRAIN_FLUFF_LEFT,
    00052   RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN,
    00053   RVW_WIDGET_TRAIN_FLUFF_RIGHT,
    00054   RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE,
    00055 };
    00056
    00057 static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
    00058 {
    00059   const EngineID va = *(const EngineID*)a;
    00060   const EngineID vb = *(const EngineID*)b;
    00061   int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
    00062
    00063   return r;
    00064 }
    00065
    00066 /* General Vehicle GUI based procedures that are independent of vehicle types */
    00067 void InitializeVehiclesGuiList()
    00068 {
    00069   _railtype_selected_in_replace_gui = RAILTYPE_RAIL;
    00070 }
    00071
    00080 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
    00081 {
    00082   Player *p = GetPlayer(_local_player);
    00083   VehicleType type = GetEngine(e)->type;
    00084   uint num_engines = GetGroupNumEngines(_local_player, id_g, e);
    00085
    00086   if (num_engines == 0 || p->num_engines[e] == 0) {
    00087     /* We don't have any of this engine type.
    00088      * Either we just sold the last one, we build a new one or we stopped replacing it.
    00089      * In all cases, we need to update the left list */
    00090     _rebuild_left_list = true;
    00091   } else {
    00092     _rebuild_left_list = false;
    00093   }
    00094   _rebuild_right_list = false;
    00095   InvalidateWindowData(WC_REPLACE_VEHICLE, type);
    00096 }
    00097
    00101 void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type)
    00102 {
    00103   _rebuild_left_list = false; // left list is only for the vehicles the player owns and is not related to being buildable
    00104   _rebuild_right_list = true;
    00105   InvalidateWindowData(WC_REPLACE_VEHICLE, type); // Update the autoreplace window
    00106   InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
    00107 }
    00108
    00113 static CargoID EngineCargo(EngineID engine)
    00114 {
    00115   if (engine == INVALID_ENGINE) return CT_INVALID; // surely INVALID_ENGINE can't carry anything but CT_INVALID
    00116
    00117   switch (GetEngine(engine)->type) {
    00118     default: NOT_REACHED();
    00119     case VEH_TRAIN:
    00120       if (RailVehInfo(engine)->capacity == 0) return CT_INVALID; // no capacity -> can't carry cargo
    00121       return RailVehInfo(engine)->cargo_type;
    00122     case VEH_ROAD:       return RoadVehInfo(engine)->cargo_type;
    00123     case VEH_SHIP:       return ShipVehInfo(engine)->cargo_type;
    00124     case VEH_AIRCRAFT:   return CT_PASSENGERS; // all planes are build with passengers by default
    00125   }
    00126 }
    00127
    00134 static bool GenerateReplaceRailList(EngineID e, bool draw_left, bool show_engines)
    00135 {
    00136   const RailVehicleInfo *rvi = RailVehInfo(e);
    00137
    00138   /* Ensure that the wagon/engine selection fits the engine. */
    00139   if ((rvi->railveh_type == RAILVEH_WAGON) == show_engines) return false;
    00140
    00141   if (draw_left && show_engines) {
    00142     /* Ensure that the railtype is specific to the selected one */
    00143     if (rvi->railtype != _railtype_selected_in_replace_gui) return false;
    00144   } else {
    00145     /* Ensure that it's a compatible railtype to the selected one (like electric <-> diesel)
    00146      * The vehicle do not have to have power on the railtype in question, only able to drive (pulled if needed) */
    00147     if (!IsCompatibleRail(rvi->railtype, _railtype_selected_in_replace_gui)) return false;
    00148   }
    00149   return true;
    00150 }
    00151
    00157 static bool EnginesGotCargoInCommon(EngineID engine_a, EngineID engine_b)
    00158 {
    00159   CargoID a = EngineCargo(engine_a);
    00160   CargoID b = EngineCargo(engine_b);
    00161
    00162    /* we should always be able to refit to/from locomotives without capacity
    00163     * Because of that, CT_INVALID shoudl always return true */
    00164   if (a == CT_INVALID || b == CT_INVALID || a == b) return true; // they carry no ro the same type by default
    00165   if (EngInfo(engine_a)->refit_mask & EngInfo(engine_b)->refit_mask) return true; // both can refit to the same
    00166   if (CanRefitTo(engine_a, b) || CanRefitTo(engine_b, a)) return true; // one can refit to what the other one carries
    00167   return false;
    00168 }
    00169
    00174 static void GenerateReplaceVehList(Window *w, bool draw_left)
    00175 {
    00176   EngineID e;
    00177   EngineID selected_engine = INVALID_ENGINE;
    00178   VehicleType type = (VehicleType)w->window_number;
    00179   byte i = draw_left ? 0 : 1;
    00180
    00181   EngineList *list = &WP(w, replaceveh_d).list[i];
    00182   EngList_RemoveAll(list);
    00183
    00184   FOR_ALL_ENGINEIDS_OF_TYPE(e, type) {
    00185     if (type == VEH_TRAIN && !GenerateReplaceRailList(e, draw_left, WP(w, replaceveh_d).wagon_btnstate)) continue; // special rules for trains
    00186
    00187     if (draw_left) {
    00188       const GroupID selected_group = WP(w, replaceveh_d).sel_group;
    00189       const uint num_engines = GetGroupNumEngines(_local_player, selected_group, e);
    00190
    00191       /* Skip drawing the engines we don't have any of and haven't set for replacement */
    00192       if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), e, selected_group) == INVALID_ENGINE) continue;
    00193     } else {
    00194       /* This is for engines we can replace to and they should depend on what we selected to replace from */
    00195       if (!IsEngineBuildable(e, type, _local_player)) continue; // we need to be able to build the engine
    00196       if (!EnginesGotCargoInCommon(e, WP(w, replaceveh_d).sel_engine[0])) continue; // the engines needs to be able to carry the same cargo
    00197
    00198       /* Road vehicles can't be replaced by trams and vice-versa */
    00199       if (type == VEH_ROAD && HasBit(EngInfo(WP(w, replaceveh_d).sel_engine[0])->misc_flags, EF_ROAD_TRAM) != HasBit(EngInfo(e)->misc_flags, EF_ROAD_TRAM)) continue;
    00200       if (e == WP(w, replaceveh_d).sel_engine[0]) continue; // we can't replace an engine into itself (that would be autorenew)
    00201     }
    00202
    00203     EngList_Add(list, e);
    00204     if (e == WP(w, replaceveh_d).sel_engine[i]) selected_engine = e; // The selected engine is still in the list
    00205   }
    00206   WP(w, replaceveh_d).sel_engine[i] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
    00207   if (type == VEH_TRAIN) EngList_Sort(list, &TrainEngineNumberSorter);
    00208 }
    00209
    00213 static void GenerateLists(Window *w)
    00214 {
    00215   EngineID e = WP(w, replaceveh_d).sel_engine[0];
    00216
    00217   if (WP(w, replaceveh_d).update_left == true) {
    00218     /* We need to rebuild the left list */
    00219     GenerateReplaceVehList(w, true);
    00220     SetVScrollCount(w, EngList_Count(&WP(w, replaceveh_d).list[0]));
    00221     if (WP(w, replaceveh_d).init_lists && WP(w, replaceveh_d).sel_engine[0] == INVALID_ENGINE && EngList_Count(&WP(w, replaceveh_d).list[0]) != 0) {
    00222       WP(w, replaceveh_d).sel_engine[0] = WP(w, replaceveh_d).list[0][0];
    00223     }
    00224   }
    00225
    00226   if (WP(w, replaceveh_d).update_right || e != WP(w, replaceveh_d).sel_engine[0]) {
    00227     /* Either we got a request to rebuild the right list or the left list selected a different engine */
    00228     if (WP(w, replaceveh_d).sel_engine[0] == INVALID_ENGINE) {
    00229       /* Always empty the right list when nothing is selected in the left list */
    00230       EngList_RemoveAll(&WP(w, replaceveh_d).list[1]);
    00231       WP(w, replaceveh_d).sel_engine[1] = INVALID_ENGINE;
    00232     } else {
    00233       GenerateReplaceVehList(w, false);
    00234       SetVScroll2Count(w, EngList_Count(&WP(w, replaceveh_d).list[1]));
    00235       if (WP(w, replaceveh_d).init_lists && WP(w, replaceveh_d).sel_engine[1] == INVALID_ENGINE && EngList_Count(&WP(w, replaceveh_d).list[1]) != 0) {
    00236         WP(w, replaceveh_d).sel_engine[1] = WP(w, replaceveh_d).list[1][0];
    00237       }
    00238     }
    00239   }
    00240   /* Reset the flags about needed updates */
    00241   WP(w, replaceveh_d).update_left  = false;
    00242   WP(w, replaceveh_d).update_right = false;
    00243   WP(w, replaceveh_d).init_lists   = false;
    00244 }
    00245
    00246
    00247 void DrawEngineList(VehicleType type, int x, int y, const EngineList eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
    00248
    00249 static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
    00250 {
    00251   /* Strings for the pulldown menu */
    00252   static const StringID _vehicle_type_names[] = {
    00253     STR_019F_TRAIN,
    00254     STR_019C_ROAD_VEHICLE,
    00255     STR_019E_SHIP,
    00256     STR_019D_AIRCRAFT
    00257   };
    00258
    00259   switch (e->event) {
    00260     case WE_CREATE:
    00261       WP(w, replaceveh_d).wagon_btnstate = true; // start with locomotives (all other vehicles will not read this bool)
    00262       EngList_Create(&WP(w, replaceveh_d).list[0]);
    00263       EngList_Create(&WP(w, replaceveh_d).list[1]);
    00264       WP(w, replaceveh_d).update_left   = true;
    00265       WP(w, replaceveh_d).update_right  = true;
    00266       WP(w, replaceveh_d).init_lists    = true;
    00267       WP(w, replaceveh_d).sel_engine[0] = INVALID_ENGINE;
    00268       WP(w, replaceveh_d).sel_engine[1] = INVALID_ENGINE;
    00269       break;
    00270
    00271     case WE_PAINT: {
    00272       if (WP(w, replaceveh_d).update_left || WP(w, replaceveh_d).update_right) GenerateLists(w);
    00273
    00274       Player *p = GetPlayer(_local_player);
    00275       EngineID selected_id[2];
    00276       const GroupID selected_group = WP(w, replaceveh_d).sel_group;
    00277
    00278       selected_id[0] = WP(w, replaceveh_d).sel_engine[0];
    00279       selected_id[1] = WP(w, replaceveh_d).sel_engine[1];
    00280
    00281       /* Disable the "Start Replacing" button if:
    00282        *    Either list is empty
    00283        * or The selected replacement engine has a replacement (to prevent loops)
    00284        * or The right list (new replacement) has the existing replacement vehicle selected */
    00285       w->SetWidgetDisabledState(RVW_WIDGET_START_REPLACE,
    00286                      selected_id[0] == INVALID_ENGINE ||
    00287                      selected_id[1] == INVALID_ENGINE ||
    00288                      EngineReplacementForPlayer(p, selected_id[1], selected_group) != INVALID_ENGINE ||
    00289                      EngineReplacementForPlayer(p, selected_id[0], selected_group) == selected_id[1]);
    00290
    00291       /* Disable the "Stop Replacing" button if:
    00292        *   The left list (existing vehicle) is empty
    00293        *   or The selected vehicle has no replacement set up */
    00294       w->SetWidgetDisabledState(RVW_WIDGET_STOP_REPLACE,
    00295                      selected_id[0] == INVALID_ENGINE ||
    00296                      !EngineHasReplacementForPlayer(p, selected_id[0], selected_group));
    00297
    00298       /* now the actual drawing of the window itself takes place */
    00299       SetDParam(0, _vehicle_type_names[w->window_number]);
    00300
    00301       if (w->window_number == VEH_TRAIN) {
    00302         /* set on/off for renew_keep_length */
    00303         SetDParam(1, p->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
    00304
    00305         /* set wagon/engine button */
    00306         SetDParam(2, WP(w, replaceveh_d).wagon_btnstate ? STR_ENGINES : STR_WAGONS);
    00307
    00308         /* sets the colour of that art thing */
    00309         w->widget[RVW_WIDGET_TRAIN_FLUFF_LEFT].color  = _player_colors[_local_player];
    00310         w->widget[RVW_WIDGET_TRAIN_FLUFF_RIGHT].color = _player_colors[_local_player];
    00311       }
    00312
    00313       if (w->window_number == VEH_TRAIN) {
    00314         /* Show the selected railtype in the pulldown menu */
    00315         RailType railtype = _railtype_selected_in_replace_gui;
    00316         w->widget[RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN].data = _rail_types_list[railtype];
    00317       }
    00318
    00319       DrawWindowWidgets(w);
    00320
    00321       /* sets up the string for the vehicle that is being replaced to */
    00322       if (selected_id[0] != INVALID_ENGINE) {
    00323         if (!EngineHasReplacementForPlayer(p, selected_id[0], selected_group)) {
    00324           SetDParam(0, STR_NOT_REPLACING);
    00325         } else {
    00326           SetDParam(0, STR_ENGINE_NAME);
    00327           SetDParam(1, EngineReplacementForPlayer(p, selected_id[0], selected_group));
    00328         }
    00329       } else {
    00330         SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
    00331       }
    00332
    00333       DrawString(145, w->widget[RVW_WIDGET_INFO_TAB].top + 1, STR_02BD, TC_BLACK);
    00334
    00335       /* Draw the lists */
    00336       for(byte i = 0; i < 2; i++) {
    00337         uint widget     = (i == 0) ? RVW_WIDGET_LEFT_MATRIX : RVW_WIDGET_RIGHT_MATRIX;
    00338         EngineList list = WP(w, replaceveh_d).list[i]; // which list to draw
    00339         EngineID start  = i == 0 ? w->vscroll.pos : w->vscroll2.pos; // what is the offset for the start (scrolling)
    00340         EngineID end    = min((i == 0 ? w->vscroll.cap : w->vscroll2.cap) + start, EngList_Count(&list));
    00341
    00342         /* Do the actual drawing */
    00343         DrawEngineList((VehicleType)w->window_number, w->widget[widget].left + 2, w->widget[widget].top + 1, list, start, end, WP(w, replaceveh_d).sel_engine[i], i == 0, selected_group);
    00344
    00345         /* Also draw the details if an engine is selected */
    00346         if (WP(w, replaceveh_d).sel_engine[i] != INVALID_ENGINE) {
    00347           const Widget *wi = &w->widget[i == 0 ? RVW_WIDGET_LEFT_DETAILS : RVW_WIDGET_RIGHT_DETAILS];
    00348           int text_end = DrawVehiclePurchaseInfo(wi->left + 2, wi->top + 1, wi->right - wi->left - 2, WP(w, replaceveh_d).sel_engine[i]);
    00349
    00350           if (text_end > wi->bottom) {
    00351             SetWindowDirty(w);
    00352             ResizeWindowForWidget(w, i == 0 ? RVW_WIDGET_LEFT_DETAILS : RVW_WIDGET_RIGHT_DETAILS, 0, text_end - wi->bottom);
    00353             SetWindowDirty(w);
    00354           }
    00355         }
    00356       }
    00357
    00358     } break;   // end of paint
    00359
    00360     case WE_CLICK: {
    00361       switch (e->we.click.widget) {
    00362         case RVW_WIDGET_TRAIN_ENGINEWAGON_TOGGLE:
    00363           WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate);
    00364           WP(w, replaceveh_d).update_left = true;
    00365           WP(w, replaceveh_d).init_lists  = true;
    00366           SetWindowDirty(w);
    00367           break;
    00368
    00369         case RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN: /* Railtype selection dropdown menu */
    00370           ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN, 0, ~GetPlayer(_local_player)->avail_railtypes);
    00371           break;
    00372
    00373         case RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE: /* toggle renew_keep_length */
    00374           DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE);
    00375           break;
    00376
    00377         case RVW_WIDGET_START_REPLACE: { /* Start replacing */
    00378           EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
    00379           EngineID veh_to = WP(w, replaceveh_d).sel_engine[1];
    00380           DoCommandP(0, 3 + (WP(w, replaceveh_d).sel_group << 16) , veh_from + (veh_to << 16), NULL, CMD_SET_AUTOREPLACE);
    00381         } break;
    00382
    00383         case RVW_WIDGET_STOP_REPLACE: { /* Stop replacing */
    00384           EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
    00385           DoCommandP(0, 3 + (WP(w, replaceveh_d).sel_group << 16), veh_from + (INVALID_ENGINE << 16), NULL, CMD_SET_AUTOREPLACE);
    00386         } break;
    00387
    00388         case RVW_WIDGET_LEFT_MATRIX:
    00389         case RVW_WIDGET_RIGHT_MATRIX: {
    00390           uint i = (e->we.click.pt.y - 14) / w->resize.step_height;
    00391           uint16 click_scroll_pos = e->we.click.widget == RVW_WIDGET_LEFT_MATRIX ? w->vscroll.pos : w->vscroll2.pos;
    00392           uint16 click_scroll_cap = e->we.click.widget == RVW_WIDGET_LEFT_MATRIX ? w->vscroll.cap : w->vscroll2.cap;
    00393           byte click_side         = e->we.click.widget == RVW_WIDGET_LEFT_MATRIX ? 0 : 1;
    00394           uint16 engine_count     = EngList_Count(&WP(w, replaceveh_d).list[click_side]);
    00395
    00396           if (i < click_scroll_cap) {
    00397             i += click_scroll_pos;
    00398             EngineID e = engine_count > i ? WP(w, replaceveh_d).list[click_side][i] : INVALID_ENGINE;
    00399             if (e == WP(w, replaceveh_d).sel_engine[click_side]) break; // we clicked the one we already selected
    00400             WP(w, replaceveh_d).sel_engine[click_side] = e;
    00401             if (click_side == 0) {
    00402               WP(w, replaceveh_d).update_right = true;
    00403               WP(w, replaceveh_d).init_lists   = true;
    00404             }
    00405             SetWindowDirty(w);
    00406             }
    00407           break;
    00408           }
    00409       }
    00410       break;
    00411     }
    00412
    00413     case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */
    00414       RailType temp = (RailType)e->we.dropdown.index;
    00415       if (temp == _railtype_selected_in_replace_gui) break; // we didn't select a new one. No need to change anything
    00416       _railtype_selected_in_replace_gui = temp;
    00417       /* Reset scrollbar positions */
    00418       w->vscroll.pos  = 0;
    00419       w->vscroll2.pos = 0;
    00420       /* Rebuild the lists */
    00421       WP(w, replaceveh_d).update_left  = true;
    00422       WP(w, replaceveh_d).update_right = true;
    00423       WP(w, replaceveh_d).init_lists   = true;
    00424       SetWindowDirty(w);
    00425     } break;
    00426
    00427     case WE_RESIZE:
    00428       w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
    00429       w->vscroll2.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
    00430
    00431       w->widget[RVW_WIDGET_LEFT_MATRIX].data  = (w->vscroll.cap  << 8) + 1;
    00432       w->widget[RVW_WIDGET_RIGHT_MATRIX].data = (w->vscroll2.cap << 8) + 1;
    00433       break;
    00434
    00435     case WE_INVALIDATE_DATA:
    00436       if (_rebuild_left_list) WP(w, replaceveh_d).update_left = true;
    00437       if (_rebuild_right_list) WP(w, replaceveh_d).update_right = true;
    00438       SetWindowDirty(w);
    00439       break;
    00440
    00441     case WE_DESTROY:
    00442       EngList_RemoveAll(&WP(w, replaceveh_d).list[0]);
    00443       EngList_RemoveAll(&WP(w, replaceveh_d).list[1]);
    00444     break;
    00445   }
    00446 }
    00447
    00448 static const Widget _replace_rail_vehicle_widgets[] = {
    00449 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,       STR_018B_CLOSE_WINDOW},
    00450 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE, STR_018C_WINDOW_TITLE_DRAG_THIS},
    00451 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,       STR_STICKY_BUTTON},
    00452 {      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   227, 0x0,            STR_NULL},
    00453 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   240,   251, STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON},
    00454 {      WWT_PANEL,     RESIZE_TB,    14,   139,   316,   228,   239, 0x0,            STR_REPLACE_HELP_REPLACE_INFO_TAB},
    00455 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   240,   251, STR_REPLACE_VEHICLES_STOP,  STR_REPLACE_HELP_STOP_BUTTON},
    00456 {     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,          STR_REPLACE_HELP_LEFT_ARRAY},
    00457 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,       STR_0190_SCROLL_BAR_SCROLLS_LIST},
    00458 {     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,          STR_REPLACE_HELP_RIGHT_ARRAY},
    00459 { WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,       STR_0190_SCROLL_BAR_SCROLLS_LIST},
    00460 {      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   227, 0x0,            STR_NULL},
    00461 // train specific stuff
    00462 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   228,   239, STR_REPLACE_ENGINE_WAGON_SELECT,       STR_REPLACE_ENGINE_WAGON_SELECT_HELP},  // widget 12
    00463 {      WWT_PANEL,     RESIZE_TB,    14,   139,   153,   240,   251, 0x0,            STR_NULL},
    00464 {   WWT_DROPDOWN,     RESIZE_TB,    14,   154,   289,   240,   251, 0x0,            STR_REPLACE_HELP_RAILTYPE},
    00465 {      WWT_PANEL,     RESIZE_TB,    14,   290,   305,   240,   251, 0x0,            STR_NULL},
    00466 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   317,   455,   228,   239, STR_REPLACE_REMOVE_WAGON,       STR_REPLACE_REMOVE_WAGON_HELP},
    00467 // end of train specific stuff
    00468 {  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   240,   251, STR_NULL,       STR_RESIZE_BUTTON},
    00469 {   WIDGETS_END},
    00470 };
    00471
    00472 static const Widget _replace_road_vehicle_widgets[] = {
    00473 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
    00474 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
    00475 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
    00476 {      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   126,   217, 0x0,                         STR_NULL},
    00477 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   218,   229, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
    00478 {      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   218,   229, 0x0,                         STR_REPLACE_HELP_REPLACE_INFO_TAB},
    00479 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   218,   229, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
    00480 {     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   125, 0x801,                       STR_REPLACE_HELP_LEFT_ARRAY},
    00481 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
    00482 {     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   125, 0x801,                       STR_REPLACE_HELP_RIGHT_ARRAY},
    00483 { WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   125, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
    00484 {      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   126,   217, 0x0,                         STR_NULL},
    00485 {  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   218,   229, STR_NULL,                    STR_RESIZE_BUTTON},
    00486 {   WIDGETS_END},
    00487 };
    00488
    00489 static const Widget _replace_ship_aircraft_vehicle_widgets[] = {
    00490 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
    00491 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   443,     0,    13, STR_REPLACE_VEHICLES_WHITE,  STR_018C_WINDOW_TITLE_DRAG_THIS},
    00492 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   444,   455,     0,    13, STR_NULL,                    STR_STICKY_BUTTON},
    00493 {      WWT_PANEL,     RESIZE_TB,    14,     0,   227,   110,   201, 0x0,                         STR_NULL},
    00494 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   138,   202,   213, STR_REPLACE_VEHICLES_START,  STR_REPLACE_HELP_START_BUTTON},
    00495 {      WWT_PANEL,     RESIZE_TB,    14,   139,   305,   202,   213, 0x0,                         STR_REPLACE_HELP_REPLACE_INFO_TAB},
    00496 { WWT_PUSHTXTBTN,     RESIZE_TB,    14,   306,   443,   202,   213, STR_REPLACE_VEHICLES_STOP,   STR_REPLACE_HELP_STOP_BUTTON},
    00497 {     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   215,    14,   109, 0x401,                       STR_REPLACE_HELP_LEFT_ARRAY},
    00498 {  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   216,   227,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
    00499 {     WWT_MATRIX, RESIZE_BOTTOM,    14,   228,   443,    14,   109, 0x401,                       STR_REPLACE_HELP_RIGHT_ARRAY},
    00500 { WWT_SCROLL2BAR, RESIZE_BOTTOM,    14,   444,   455,    14,   109, STR_NULL,                    STR_0190_SCROLL_BAR_SCROLLS_LIST},
    00501 {      WWT_PANEL,     RESIZE_TB,    14,   228,   455,   110,   201, 0x0,                         STR_NULL},
    00502 {  WWT_RESIZEBOX,     RESIZE_TB,    14,   444,   455,   202,   213, STR_NULL,                    STR_RESIZE_BUTTON},
    00503 {   WIDGETS_END},
    00504 };
    00505
    00506 static const WindowDesc _replace_rail_vehicle_desc = {
    00507   WDP_AUTO, WDP_AUTO, 456, 252, 456, 252,
    00508   WC_REPLACE_VEHICLE, WC_NONE,
    00509   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
    00510   _replace_rail_vehicle_widgets,
    00511   ReplaceVehicleWndProc
    00512 };
    00513
    00514 static const WindowDesc _replace_road_vehicle_desc = {
    00515   WDP_AUTO, WDP_AUTO, 456, 230, 456, 230,
    00516   WC_REPLACE_VEHICLE, WC_NONE,
    00517   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
    00518   _replace_road_vehicle_widgets,
    00519   ReplaceVehicleWndProc
    00520 };
    00521
    00522 static const WindowDesc _replace_ship_aircraft_vehicle_desc = {
    00523   WDP_AUTO, WDP_AUTO, 456, 214, 456, 214,
    00524   WC_REPLACE_VEHICLE, WC_NONE,
    00525   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
    00526   _replace_ship_aircraft_vehicle_widgets,
    00527   ReplaceVehicleWndProc
    00528 };
    00529
    00530
    00531 void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
    00532 {
    00533   Window *w;
    00534
    00535   DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
    00536
    00537   switch (vehicletype) {
    00538     default: NOT_REACHED();
    00539     case VEH_TRAIN:
    00540       w = AllocateWindowDescFront(&_replace_rail_vehicle_desc, vehicletype);
    00541       w->vscroll.cap  = 8;
    00542       w->resize.step_height = 14;
    00543       WP(w, replaceveh_d).wagon_btnstate = true;
    00544       break;
    00545     case VEH_ROAD:
    00546       w = AllocateWindowDescFront(&_replace_road_vehicle_desc, vehicletype);
    00547       w->vscroll.cap  = 8;
    00548       w->resize.step_height = 14;
    00549       break;
    00550     case VEH_SHIP:
    00551     case VEH_AIRCRAFT:
    00552       w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
    00553       w->vscroll.cap  = 4;
    00554       w->resize.step_height = 24;
    00555       break;
    00556   }
    00557
    00558   w->caption_color = _local_player;
    00559   WP(w, replaceveh_d).sel_group = id_g;
    00560   w->vscroll2.cap = w->vscroll.cap;   // these two are always the same
    00561 }