Loading

Paste #p9hlizjtm

  1. Index: src/autoreplace_cmd.cpp
  2. ===================================================================
  3. --- src/autoreplace_cmd.cpp (revision 27930)
  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 27930)
  20. +++ src/autoreplace_gui.cpp (working copy)
  21. @@ -111,7 +111,27 @@
  22.         return true;
  23.     }
  24.  
  25. +   /**
  26. +    * Figure out if an aircraft should be added to the right list, regarding its type.
  27. +    * @param from The EngineID of the selected aircraft on the left list.
  28. +    * @param to   The EngineID of the aircraft to be added to the right list.
  29. +    * @return \c true if the engine should be added to the right list, else \c false.
  30. +    */
  31. +   bool GenerateReplaceAircraftList(EngineID from, EngineID to)
  32. +   {
  33. +       const Engine *e_from = Engine::Get(from);
  34. +       const Engine *e_to = Engine::Get(to);
  35.  
  36. +       if (_settings_client.gui.autoreplace_match_aircraft_type) {
  37. +           /* make sure that we do not replace a mismatching aircraft type */
  38. +           if ((e_from->u.air.subtype == AIR_CTOL) != (e_to->u.air.subtype == AIR_CTOL)) return false;
  39. +           if ((e_from->u.air.subtype == AIR_HELI) != (e_to->u.air.subtype == AIR_HELI)) return false;
  40. +           if ((e_from->u.air.subtype == (AIR_CTOL | AIR_FAST)) != (e_to->u.air.subtype == (AIR_CTOL | AIR_FAST))) return false;
  41. +       }
  42. +
  43. +       return true;
  44. +   }
  45. +
  46.     /**
  47.      * Generate an engines list
  48.      * @param draw_left true if generating the left list, otherwise false
  49. @@ -138,6 +158,7 @@
  50.                 if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue;
  51.             } else {
  52.                 if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
  53. +               if (type == VEH_AIRCRAFT && !this->GenerateReplaceAircraftList(this->sel_engine[0], eid)) continue;
  54.             }
  55.  
  56.             *list->Append() = eid;
  57. @@ -229,6 +250,12 @@
  58.         widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + vehicletype;
  59.         widget->tool_tip    = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + vehicletype;
  60.         widget->SetLowered(this->show_hidden_engines);
  61. +
  62. +       if (vehicletype == VEH_AIRCRAFT) {
  63. +           widget = this->GetWidget<NWidgetCore>(WID_RV_MATCH_AIRCRAFT_TYPE);
  64. +           widget->SetLowered(_settings_client.gui.autoreplace_match_aircraft_type);
  65. +       }
  66. +
  67.         this->FinishInitNested(vehicletype);
  68.  
  69.         this->sort_criteria = _engine_sort_last_criteria[vehicletype];
  70. @@ -475,6 +502,13 @@
  71.                 DoCommandP(0, GetCompanySettingIndex("company.renew_keep_length"), Company::Get(_local_company)->settings.renew_keep_length ? 0 : 1, CMD_CHANGE_COMPANY_SETTING);
  72.                 break;
  73.  
  74. +           case WID_RV_MATCH_AIRCRAFT_TYPE: // toggle autoreplace_match_aircraft_type
  75. +               IConsoleSetSetting("gui.autoreplace_match_aircraft_type", !_settings_client.gui.autoreplace_match_aircraft_type);
  76. +               this->engines[1].ForceRebuild();
  77. +               this->SetWidgetLoweredState(widget, _settings_client.gui.autoreplace_match_aircraft_type);
  78. +               this->SetDirty();
  79. +               break;
  80. +
  81.             case WID_RV_START_REPLACE: { // Start replacing
  82.                 if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
  83.                     this->HandleButtonClick(WID_RV_START_REPLACE);
  84. @@ -697,6 +731,60 @@
  85.     _nested_replace_vehicle_widgets, lengthof(_nested_replace_vehicle_widgets)
  86.  );
  87.  
  88. +static const NWidgetPart _nested_replace_aircraft_vehicle_widgets[] = {
  89. +   NWidget(NWID_HORIZONTAL),
  90. +       NWidget(WWT_CLOSEBOX, COLOUR_GREY),
  91. +       NWidget(WWT_CAPTION, COLOUR_GREY, WID_RV_CAPTION), SetMinimalSize(433, 14), SetDataTip(STR_REPLACE_VEHICLES_WHITE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
  92. +       NWidget(WWT_SHADEBOX, COLOUR_GREY),
  93. +       NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
  94. +       NWidget(WWT_STICKYBOX, COLOUR_GREY),
  95. +   EndContainer(),
  96. +   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
  97. +       NWidget(WWT_PANEL, COLOUR_GREY),
  98. +           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),
  99. +       EndContainer(),
  100. +       NWidget(WWT_PANEL, COLOUR_GREY),
  101. +           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),
  102. +       EndContainer(),
  103. +   EndContainer(),
  104. +   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
  105. +       NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), EndContainer(),
  106. +       NWidget(NWID_VERTICAL),
  107. +           NWidget(NWID_HORIZONTAL),
  108. +               NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
  109. +               NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_RV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
  110. +           EndContainer(),
  111. +           NWidget(NWID_HORIZONTAL),
  112. +               NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_SHOW_HIDDEN_ENGINES), SetDataTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP),
  113. +               NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_RV_MATCH_AIRCRAFT_TYPE), SetDataTip(STR_REPLACE_MATCH_AIRCRAFT_TYPE, STR_REPLACE_MATCH_AIRCRAFT_TYPE_HELP), SetResize(1, 0), SetFill(1, 1),
  114. +           EndContainer(),
  115. +       EndContainer(),
  116. +   EndContainer(),
  117. +   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
  118. +       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),
  119. +       NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_LEFT_SCROLLBAR),
  120. +       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),
  121. +       NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_RV_RIGHT_SCROLLBAR),
  122. +   EndContainer(),
  123. +   NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
  124. +       NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_LEFT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
  125. +       NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_RIGHT_DETAILS), SetMinimalSize(228, 92), SetResize(1, 0), EndContainer(),
  126. +   EndContainer(),
  127. +   NWidget(NWID_HORIZONTAL),
  128. +       NWidget(NWID_PUSHBUTTON_DROPDOWN, COLOUR_GREY, WID_RV_START_REPLACE), SetMinimalSize(139, 12), SetDataTip(STR_REPLACE_VEHICLES_START, STR_REPLACE_HELP_START_BUTTON),
  129. +       NWidget(WWT_PANEL, COLOUR_GREY, WID_RV_INFO_TAB), SetMinimalSize(167, 12), SetDataTip(0x0, STR_REPLACE_HELP_REPLACE_INFO_TAB), SetResize(1, 0), EndContainer(),
  130. +       NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_RV_STOP_REPLACE), SetMinimalSize(138, 12), SetDataTip(STR_REPLACE_VEHICLES_STOP, STR_REPLACE_HELP_STOP_BUTTON),
  131. +       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
  132. +   EndContainer(),
  133. +};
  134. +
  135. +static WindowDesc _replace_aircraft_vehicle_desc(
  136. +   WDP_AUTO, "replace_vehicle_aircraft", 456, 118,
  137. +   WC_REPLACE_VEHICLE, WC_NONE,
  138. +   WDF_CONSTRUCTION,
  139. +   _nested_replace_aircraft_vehicle_widgets, lengthof(_nested_replace_aircraft_vehicle_widgets)
  140. +);
  141. +
  142.  /**
  143.   * Show the autoreplace configuration window for a particular group.
  144.   * @param id_g The group to replace the vehicles for.
  145. @@ -705,5 +793,11 @@
  146.  void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
  147.  {
  148.     DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
  149. -   new ReplaceVehicleWindow(vehicletype == VEH_TRAIN ? &_replace_rail_vehicle_desc : &_replace_vehicle_desc, vehicletype, id_g);
  150. +   if (vehicletype == VEH_TRAIN) {
  151. +       new ReplaceVehicleWindow(&_replace_rail_vehicle_desc, vehicletype, id_g);
  152. +   } else if (vehicletype == VEH_AIRCRAFT) {
  153. +       new ReplaceVehicleWindow(&_replace_aircraft_vehicle_desc, vehicletype, id_g);
  154. +   } else {
  155. +       new ReplaceVehicleWindow(&_replace_vehicle_desc, vehicletype, id_g);
  156. +   }
  157.  }
  158. Index: src/lang/english.txt
  159. ===================================================================
  160. --- src/lang/english.txt    (revision 27930)
  161. +++ src/lang/english.txt    (working copy)
  162. @@ -3585,6 +3585,9 @@
  163.  STR_REPLACE_REMOVE_WAGON                                        :{BLACK}Wagon removal: {ORANGE}{STRING}
  164.  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
  165.  
  166. +STR_REPLACE_MATCH_AIRCRAFT_TYPE                                 :{BLACK}Match aircraft type
  167. +STR_REPLACE_MATCH_AIRCRAFT_TYPE_HELP                            :{BLACK}By enabling this button, only aircraft matching the same type as the one selected for replacement are displayed
  168. +
  169.  # Vehicle view
  170.  STR_VEHICLE_VIEW_CAPTION                                        :{WHITE}{VEHICLE}
  171.  
  172. Index: src/script/api/game/game_window.hpp.sq
  173. ===================================================================
  174. --- src/script/api/game/game_window.hpp.sq  (revision 27930)
  175. +++ src/script/api/game/game_window.hpp.sq  (working copy)
  176. @@ -216,6 +216,7 @@
  177.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_SORT_ASCENDING_DESCENDING,          "WID_RV_SORT_ASCENDING_DESCENDING");
  178.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_SHOW_HIDDEN_ENGINES,                "WID_RV_SHOW_HIDDEN_ENGINES");
  179.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_SORT_DROPDOWN,                      "WID_RV_SORT_DROPDOWN");
  180. +   SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_MATCH_AIRCRAFT_TYPE,                "WID_RV_MATCH_AIRCRAFT_TYPE");
  181.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_LEFT_MATRIX,                        "WID_RV_LEFT_MATRIX");
  182.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_LEFT_SCROLLBAR,                     "WID_RV_LEFT_SCROLLBAR");
  183.     SQGSWindow.DefSQConst(engine, ScriptWindow::WID_RV_RIGHT_MATRIX,                       "WID_RV_RIGHT_MATRIX");
  184. Index: src/script/api/script_window.hpp
  185. ===================================================================
  186. --- src/script/api/script_window.hpp    (revision 27930)
  187. +++ src/script/api/script_window.hpp    (working copy)
  188. @@ -927,6 +927,7 @@
  189.         WID_RV_SORT_ASCENDING_DESCENDING             = ::WID_RV_SORT_ASCENDING_DESCENDING,             ///< Ascending/descending sort order button.
  190.         WID_RV_SHOW_HIDDEN_ENGINES                   = ::WID_RV_SHOW_HIDDEN_ENGINES,                   ///< Toggle whether to display the hidden vehicles.
  191.         WID_RV_SORT_DROPDOWN                         = ::WID_RV_SORT_DROPDOWN,                         ///< Dropdown for the sort criteria.
  192. +       WID_RV_MATCH_AIRCRAFT_TYPE                   = ::WID_RV_MATCH_AIRCRAFT_TYPE,                   ///< Toggle whether to match aircraft type.
  193.  
  194.         /* Left and right matrix + details. */
  195.         WID_RV_LEFT_MATRIX                           = ::WID_RV_LEFT_MATRIX,                           ///< The matrix on the left.
  196. Index: src/settings_type.h
  197. ===================================================================
  198. --- src/settings_type.h (revision 27930)
  199. +++ src/settings_type.h (working copy)
  200. @@ -133,6 +133,7 @@
  201.     bool   station_show_coverage;            ///< whether to highlight coverage area
  202.     bool   persistent_buildingtools;         ///< keep the building tools active after usage
  203.     bool   expenses_layout;                  ///< layout of expenses window
  204. +   bool   autoreplace_match_aircraft_type;  ///< whether to match aircraft type for autoreplace
  205.     uint32 last_newgrf_count;                ///< the numbers of NewGRFs we found during the last scan
  206.     byte   missing_strings_threshold;        ///< the number of missing strings before showing the warning
  207.     uint8  graph_line_thickness;             ///< the thickness of the lines in the various graph guis
  208. Index: src/table/settings.ini
  209. ===================================================================
  210. --- src/table/settings.ini  (revision 27930)
  211. +++ src/table/settings.ini  (working copy)
  212. @@ -3093,6 +3093,11 @@
  213.  strhelp  = STR_CONFIG_SETTING_EXPENSES_LAYOUT_HELPTEXT
  214.  proc     = RedrawScreen
  215.  
  216. +[SDTC_BOOL]
  217. +var      = gui.autoreplace_match_aircraft_type
  218. +flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
  219. +def      = true
  220. +
  221.  [SDTC_VAR]
  222.  var      = gui.station_gui_group_order
  223.  type     = SLE_UINT8
  224. Index: src/widgets/autoreplace_widget.h
  225. ===================================================================
  226. --- src/widgets/autoreplace_widget.h    (revision 27930)
  227. +++ src/widgets/autoreplace_widget.h    (working copy)
  228. @@ -20,6 +20,7 @@
  229.     WID_RV_SORT_ASCENDING_DESCENDING, ///< Ascending/descending sort order button.
  230.     WID_RV_SHOW_HIDDEN_ENGINES,       ///< Toggle whether to display the hidden vehicles.
  231.     WID_RV_SORT_DROPDOWN,             ///< Dropdown for the sort criteria.
  232. +   WID_RV_MATCH_AIRCRAFT_TYPE,       ///< Toggle whether to match aircraft type.
  233.  
  234.     /* Left and right matrix + details. */
  235.     WID_RV_LEFT_MATRIX,              ///< The matrix on the left.

Version history

Revision # Author Created at
puhsjpjyc Anonymous 18 Nov 2017, 15:51:46 UTC Diff

Comments