Loading

Paste #prws9vuhz

  1. Index: src/autoreplace_cmd.cpp
  2. ===================================================================
  3. --- src/autoreplace_cmd.cpp (revision 27931)
  4. +++ src/autoreplace_cmd.cpp (working copy)
  5. @@ -78,11 +78,6 @@
  6.             if (HasBit(e_from->info.misc_flags, EF_ROAD_TRAM) != HasBit(e_to->info.misc_flags, EF_ROAD_TRAM)) return false;
  7.             break;
  8.  
  9. -       case VEH_AIRCRAFT:
  10. -           /* make sure that we do not replace a plane with a helicopter or vice versa */
  11. -           if ((e_from->u.air.subtype & AIR_CTOL) != (e_to->u.air.subtype & AIR_CTOL)) return false;
  12. -           break;
  13. -
  14.         default: break;
  15.     }
  16.  
  17. Index: src/autoreplace_gui.cpp
  18. ===================================================================
  19. --- src/autoreplace_gui.cpp (revision 27931)
  20. +++ src/autoreplace_gui.cpp (working copy)
  21. @@ -31,6 +31,7 @@
  22.  #include "safeguards.h"
  23.  
  24.  void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
  25. +int _autoreplace_last_selected_aircraft_type = 1; // Last aircraft type option selected by default (Same aircraft type)
  26.  
  27.  static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
  28.  {
  29. @@ -74,6 +75,15 @@
  30.     INVALID_STRING_ID
  31.  };
  32.  
  33. +static const StringID _autoreplace_aircraft_type_dropdown[] = {
  34. +   STR_REPLACE_ALL_AIRCRAFT_TYPES, // sel_air_type = 0
  35. +   STR_REPLACE_SAME_AIRCRAFT_TYPE, // sel_air_type = 1
  36. +   STR_REPLACE_HELICOPTER,         // sel_air_type = 2
  37. +   STR_REPLACE_SMALL_AEROPLANE,    // sel_air_type = 3
  38. +   STR_REPLACE_LARGE_AEROPLANE,    // sel_air_type = 4
  39. +   INVALID_STRING_ID
  40. +};
  41. +
  42.  /**
  43.   * Window for the autoreplacing of vehicles.
  44.   */
  45. @@ -87,6 +97,7 @@
  46.     byte sort_criteria;           ///< Criteria of sorting vehicles.
  47.     bool descending_sort_order;   ///< Order of sorting vehicles.
  48.     bool show_hidden_engines;     ///< Whether to show the hidden engines.
  49. +   int sel_air_type;             ///< Type of aircraft selected to list.
  50.     RailType sel_railtype;        ///< Type of rail tracks selected. #INVALID_RAILTYPE to show all.
  51.     Scrollbar *vscroll[2];
  52.  
  53. @@ -111,7 +122,41 @@
  54.         return true;
  55.     }
  56.  
  57. +   /**
  58. +    * Figure out if an aircraft should be added to the right list, regarding its type.
  59. +    * @param from The EngineID of the selected aircraft on the left list.
  60. +    * @param to   The EngineID of the aircraft to be added to the right list.
  61. +    * @return \c true if the engine should be added to the right list, else \c false.
  62. +    */
  63. +   bool GenerateReplaceAircraftList(EngineID from, EngineID to)
  64. +   {
  65. +       const Engine *e_from = Engine::Get(from);
  66. +       const Engine *e_to = Engine::Get(to);
  67.  
  68. +       switch (this->sel_air_type) {
  69. +           case 0: // All aircraft types
  70. +               return true;
  71. +
  72. +           case 1: // Match aircraft type
  73. +               if ((e_from->u.air.subtype == AIR_CTOL) != (e_to->u.air.subtype == AIR_CTOL)) return false;
  74. +               if ((e_from->u.air.subtype == AIR_HELI) != (e_to->u.air.subtype == AIR_HELI)) return false;
  75. +               if ((e_from->u.air.subtype == (AIR_CTOL | AIR_FAST)) != (e_to->u.air.subtype == (AIR_CTOL | AIR_FAST))) return false;
  76. +               return true;
  77. +
  78. +           case 2: // Helicopter
  79. +               return e_to->u.air.subtype == AIR_HELI;
  80. +
  81. +           case 3: // Small aeroplane
  82. +               return e_to->u.air.subtype == AIR_CTOL;
  83. +
  84. +           case 4: // Large aeroplane
  85. +               return e_to->u.air.subtype == (AIR_CTOL | AIR_FAST);
  86. +
  87. +           default:
  88. +               return false;
  89. +       }
  90. +   }
  91. +
  92.     /**
  93.      * Generate an engines list
  94.      * @param draw_left true if generating the left list, otherwise false
  95. @@ -138,6 +183,7 @@
  96.                 if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue;
  97.             } else {
  98.                 if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
  99. +               if (type == VEH_AIRCRAFT && !this->GenerateReplaceAircraftList(this->sel_engine[0], eid)) continue;
  100.             }
  101.  
  102.             *list->Append() = eid;
  103. @@ -220,6 +266,7 @@
  104.         this->sel_engine[0] = INVALID_ENGINE;
  105.         this->sel_engine[1] = INVALID_ENGINE;
  106.         this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype];
  107. +       this->sel_air_type = _autoreplace_last_selected_aircraft_type;
  108.  
  109.         this->CreateNestedTree();
  110.         this->vscroll[0] = this->GetScrollbar(WID_RV_LEFT_SCROLLBAR);
  111. @@ -303,6 +350,17 @@
  112.                 break;
  113.             }
  114.  
  115. +           case WID_RV_AIRCRAFT_TYPE_DROPDOWN: {
  116. +               Dimension d = GetStringBoundingBox(STR_REPLACE_ALL_AIRCRAFT_TYPES);
  117. +               for (int i = 0; _autoreplace_aircraft_type_dropdown[i] != INVALID_STRING_ID; i++) {
  118. +                   d = maxdim(d, GetStringBoundingBox(_autoreplace_aircraft_type_dropdown[i]));
  119. +               }
  120. +               d.width += padding.width;
  121. +               d.height += padding.height;
  122. +               *size = maxdim(*size, d);
  123. +               break;
  124. +           }
  125. +
  126.             case WID_RV_START_REPLACE: {
  127.                 Dimension d = GetStringBoundingBox(STR_REPLACE_VEHICLES_START);
  128.                 for (int i = 0; _start_replace_dropdown[i] != INVALID_STRING_ID; i++) {
  129. @@ -416,6 +474,11 @@
  130.             this->GetWidget<NWidgetCore>(WID_RV_TRAIN_RAILTYPE_DROPDOWN)->widget_data = sel_railtype == INVALID_RAILTYPE ? STR_REPLACE_ALL_RAILTYPE : GetRailTypeInfo(sel_railtype)->strings.replace_text;
  131.         }
  132.  
  133. +       if (this->window_number == VEH_AIRCRAFT) {
  134. +           /* Show the last selected aircraft type in the pulldown menu*/
  135. +           this->GetWidget<NWidgetCore>(WID_RV_AIRCRAFT_TYPE_DROPDOWN)->widget_data = _autoreplace_aircraft_type_dropdown[sel_air_type];
  136. +       }
  137. +
  138.         this->DrawWidgets();
  139.  
  140.         if (!this->IsShaded()) {
  141. @@ -475,6 +538,11 @@
  142.                 DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
  143.                 break;
  144.  
  145. +           case WID_RV_AIRCRAFT_TYPE_DROPDOWN: { // Aircraft type dropdown menu
  146. +               ShowDropDownMenu(this, _autoreplace_aircraft_type_dropdown, sel_air_type, WID_RV_AIRCRAFT_TYPE_DROPDOWN, 0, 0);
  147. +               break;
  148. +           }
  149. +
  150.             case WID_RV_START_REPLACE: { // Start replacing
  151.                 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
  152.                     this->HandleButtonClick(WID_RV_START_REPLACE);
  153. @@ -551,6 +619,17 @@
  154.                 break;
  155.             }
  156.  
  157. +           case WID_RV_AIRCRAFT_TYPE_DROPDOWN: {
  158. +               int temp = index;
  159. +               if (temp == sel_air_type) return; // we didn't select a new one. No need to change anything
  160. +               sel_air_type = temp;
  161. +               _autoreplace_last_selected_aircraft_type = this->sel_air_type;
  162. +               this->vscroll[1]->SetPosition(0);
  163. +               this->engines[1].ForceRebuild();
  164. +               this->SetDirty();
  165. +               break;
  166. +           }
  167. +
  168.             case WID_RV_START_REPLACE:
  169.                 this->ReplaceClick_StartReplace(index != 0);
  170.                 break;
  171. @@ -697,6 +776,60 @@
  172.     _nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets)
  173.  );
  174.  
  175. +static const NWidgetPart _nested_replace_aircraft_vehicle_widgets[] = {
  176. +   NWidget(NWID_HORIZONTAL),
  177. +       NWidget(WWT_CLOSEBOX, COLOUR_GREY),
  178. +       NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
  179. +       NWidget(WWT_SHADEBOX, COLOUR_GREY),
  180. +       NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
  181. +       NWidget(WWT_STICKYBOX, COLOUR_GREY),
  182. +   EndContainer(),
  183. +   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
  184. +       NWidget(WWT_PANEL, COLOUR_GREY),
  185. +           NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
  186. +       EndContainer(),
  187. +       NWidget(WWT_PANEL, COLOUR_GREY),
  188. +           NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
  189. +       EndContainer(),
  190. +   EndContainer(),
  191. +   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
  192. +       NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
  193. +       NWidget(NWID_VERTICAL),
  194. +           NWidget(NWID_HORIZONTAL),
  195. +               NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
  196. +               NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
  197. +           EndContainer(),
  198. +           NWidget(NWID_HORIZONTAL),
  199. +               NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
  200. +               NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_AIRCRAFT_TYPE_DROPDOWN), SetDataTip(STR_BLACK_STRING, STR_REPLACE_HELP_AIRCRAFT_TYPE_DROPDOWN), SetFill(1, 0), SetResize(1, 0),
  201. +           EndContainer(),
  202. +       EndContainer(),
  203. +   EndContainer(),
  204. +   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
  205. +       NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_LEFT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_LEFT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_LEFT_SCROLLBAR),
  206. +       NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
  207. +       NWidget(WWT_MATRIX, COLOUR_GREY, WID_RV_RIGHT_MATRIX), SetMinimalSize(216, 0), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_REPLACE_HELP_RIGHT_ARRAY), SetResize(1, 1), SetScrollbar(WID_RV_RIGHT_SCROLLBAR),
  208. +       NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
  209. +   EndContainer(),
  210. +   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
  211. +       NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
  212. +       NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
  213. +   EndContainer(),
  214. +   NWidget(NWID_HORIZONTAL),
  215. +       NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
  216. +       NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
  217. +       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
  218. +       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
  219. +   EndContainer(),
  220. +};
  221. +
  222. +static WindowDesc _replace_aircraft_vehicle_desc(
  223. +   WDP_AUTO, "replace_vehicle_aircraft", 456, 118,
  224. +   WC_REPLACE_VEHICLE, WC_NONE,
  225. +   WDF_CONSTRUCTION,
  226. +   _nested_replace_aircraft_vehicle_widgets, lengthof(_nested_replace_aircraft_vehicle_widgets)
  227. +);
  228. +
  229.  /**
  230.   * Show the autoreplace configuration window for a particular group.
  231.   * @param id_g The group to replace the vehicles for.
  232. @@ -705,5 +838,11 @@
  233.  void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
  234.  {
  235.     DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
  236. -   new ReplaceVehicleWindow(vehicletype == VEH_TRAIN ? &_replace_rail_vehicle_desc : &_replace_vehicle_desc, vehicletype, id_g);
  237. +   if (vehicletype == VEH_TRAIN) {
  238. +       new ReplaceVehicleWindow(&_replace_rail_vehicle_desc, vehicletype, id_g);
  239. +   } else if (vehicletype == VEH_AIRCRAFT) {
  240. +       new ReplaceVehicleWindow(&_replace_aircraft_vehicle_desc, vehicletype, id_g);
  241. +   } else {
  242. +       new ReplaceVehicleWindow(&_replace_vehicle_desc, vehicletype, id_g);
  243. +   }
  244.  }
  245. Index: src/engine_gui.h
  246. ===================================================================
  247. --- src/engine_gui.h    (revision 27931)
  248. +++ src/engine_gui.h    (working copy)
  249. @@ -42,4 +42,6 @@
  250.  uint GetEngineListHeight(VehicleType type);
  251.  void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button);
  252.  
  253. +extern int _autoreplace_last_selected_aircraft_type;
  254. +
  255.  #endif /* ENGINE_GUI_H */
  256. Index: src/lang/english.txt
  257. ===================================================================
  258. --- src/lang/english.txt    (revision 27931)
  259. +++ src/lang/english.txt    (working copy)
  260. @@ -3582,6 +3582,13 @@
  261.  STR_REPLACE_MONORAIL_VEHICLES                                   :Monorail Vehicles
  262.  STR_REPLACE_MAGLEV_VEHICLES                                     :Maglev Vehicles
  263.  
  264. +STR_REPLACE_HELP_AIRCRAFT_TYPE_DROPDOWN                         :{BLACK}List the type of aircraft you want the left selected aircraft to be replaced with
  265. +STR_REPLACE_ALL_AIRCRAFT_TYPES                                  :All aircraft types
  266. +STR_REPLACE_SAME_AIRCRAFT_TYPE                                  :Same aircraft type
  267. +STR_REPLACE_HELICOPTER                                          :Helicopter
  268. +STR_REPLACE_SMALL_AEROPLANE                                     :Small aeroplane
  269. +STR_REPLACE_LARGE_AEROPLANE                                     :Large aeroplane
  270. +
  271.  STR_REPLACE_REMOVE_WAGON                                        :{BLACK}Wagon removal: {ORANGE}{STRING}
  272.  STR_REPLACE_REMOVE_WAGON_HELP                                   :{BLACK}Make autoreplace keep the length of a train the same by removing wagons (starting at the front), if replacing the engine would make the train longer
  273.  
  274. Index: src/script/api/game/game_window.hpp.sq
  275. ===================================================================
  276. --- src/script/api/game/game_window.hpp.sq  (revision 27931)
  277. +++ src/script/api/game/game_window.hpp.sq  (working copy)
  278. @@ -228,6 +228,7 @@
  279.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_TRAIN_ENGINEWAGON_DROPDOWN,         "WID_RV_TRAIN_ENGINEWAGON_DROPDOWN");
  280.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_TRAIN_RAILTYPE_DROPDOWN,            "WID_RV_TRAIN_RAILTYPE_DROPDOWN");
  281.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_TRAIN_WAGONREMOVE_TOGGLE,           "WID_RV_TRAIN_WAGONREMOVE_TOGGLE");
  282. +   SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_AIRCRAFT_TYPE_DROPDOWN,             "WID_RV_AIRCRAFT_TYPE_DROPDOWN");
  283.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BB_BACKGROUND,                         "WID_BB_BACKGROUND");
  284.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BAFD_QUESTION,                         "WID_BAFD_QUESTION");
  285.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_BAFD_YES,                              "WID_BAFD_YES");
  286. Index: src/script/api/script_window.hpp
  287. ===================================================================
  288. --- src/script/api/script_window.hpp    (revision 27931)
  289. +++ src/script/api/script_window.hpp    (working copy)
  290. @@ -945,6 +945,9 @@
  291.         WID_RV_TRAIN_ENGINEWAGON_DROPDOWN            = ::WID_RV_TRAIN_ENGINEWAGON_DROPDOWN,            ///< Dropdown to select engines and/or wagons.
  292.         WID_RV_TRAIN_RAILTYPE_DROPDOWN               = ::WID_RV_TRAIN_RAILTYPE_DROPDOWN,               ///< Dropdown menu about the railtype.
  293.         WID_RV_TRAIN_WAGONREMOVE_TOGGLE              = ::WID_RV_TRAIN_WAGONREMOVE_TOGGLE,              ///< Button to toggle removing wagons.
  294. +
  295. +       /* Aircraft only widget. */
  296. +       WID_RV_AIRCRAFT_TYPE_DROPDOWN                = ::WID_RV_AIRCRAFT_TYPE_DROPDOWN,                ///< Dropdown menu to select aircraft type.
  297.     };
  298.  
  299.     /* automatically generated from ../../widgets/bootstrap_widget.h */
  300. Index: src/widgets/autoreplace_widget.h
  301. ===================================================================
  302. --- src/widgets/autoreplace_widget.h    (revision 27931)
  303. +++ src/widgets/autoreplace_widget.h    (working copy)
  304. @@ -38,6 +38,9 @@
  305.     WID_RV_TRAIN_ENGINEWAGON_DROPDOWN, ///< Dropdown to select engines and/or wagons.
  306.     WID_RV_TRAIN_RAILTYPE_DROPDOWN,  ///< Dropdown menu about the railtype.
  307.     WID_RV_TRAIN_WAGONREMOVE_TOGGLE, ///< Button to toggle removing wagons.
  308. +
  309. +   /* Aircraft only widget. */
  310. +   WID_RV_AIRCRAFT_TYPE_DROPDOWN,   ///< Dropdown menu to select aircraft type.
  311.  };
  312.  
  313.  #endif /* WIDGETS_AUTOREPLACE_WIDGET_H */

Comments