Add option to sort tracks by category and speed (#282)

This commit is contained in:
Andreas Schmitt
2021-06-17 18:07:18 +02:00
committed by Jonathan G Rennison
parent 24ad8759db
commit d718ba62ef
6 changed files with 74 additions and 2 deletions

View File

@@ -1479,6 +1479,9 @@ STR_CONFIG_SETTING_DEMOLISH_CONFIRM_MODE_ALL :Industries and
STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES :Enable signals on bridges/tunnels advanced modes: {STRING2} STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES :Enable signals on bridges/tunnels advanced modes: {STRING2}
STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES_HELPTEXT :Enables use of advanced modes of signal simulation on bridges and tunnels. When disabled, bridges/tunnels which are not already in an advanced mode cannot be changed to an advanced mode, however other players may choose to enable this setting and use an advanced mode. STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES_HELPTEXT :Enables use of advanced modes of signal simulation on bridges and tunnels. When disabled, bridges/tunnels which are not already in an advanced mode cannot be changed to an advanced mode, however other players may choose to enable this setting and use an advanced mode.
STR_CONFIG_SETTING_SORT_TRACK_TYPES_BY_SPEED :Sort track types by speed: {STRING2}
STR_CONFIG_SETTING_SORT_TRACK_TYPES_BY_SPEED_HELPTEXT :Sorts track types by compatibility and by speed instead of using the default sorting.
STR_CONFIG_SETTING_LANDSCAPE :Landscape: {STRING2} STR_CONFIG_SETTING_LANDSCAPE :Landscape: {STRING2}
STR_CONFIG_SETTING_LANDSCAPE_HELPTEXT :Landscapes define basic gameplay scenarios with different cargoes and town growth requirements. NewGRF and Game Scripts allow finer control though STR_CONFIG_SETTING_LANDSCAPE_HELPTEXT :Landscapes define basic gameplay scenarios with different cargoes and town growth requirements. NewGRF and Game Scripts allow finer control though
STR_CONFIG_SETTING_LAND_GENERATOR :Land generator: {STRING2} STR_CONFIG_SETTING_LAND_GENERATOR :Land generator: {STRING2}

View File

@@ -129,7 +129,57 @@ void ResolveRailTypeGUISprites(RailtypeInfo *rti)
*/ */
static bool CompareRailTypes(const RailType &first, const RailType &second) static bool CompareRailTypes(const RailType &first, const RailType &second)
{ {
if (_settings_client.gui.sort_track_types_by_speed) {
RailType rt[2] = { first, second };
uint sort_value[2];
for (int i = 0; i < 2; ++i) {
// Last sort by speed
sort_value[i] = (GetRailTypeInfo(rt[i])->max_speed != 0) ? GetRailTypeInfo(rt[i])->max_speed : UINT16_MAX;
// Inside those categories filter by compatibility with eachother.
if (!HasPowerOnRail(rt[i], rt[(i + 1) % 2])) {
sort_value[i] += (1 << 16);
}
// We sort by Rail, Electric and others
if (!HasPowerOnRail(rt[i], RAILTYPE_RAIL)) {
sort_value[i] += (1 << 17);
if (!HasPowerOnRail(rt[i], RAILTYPE_ELECTRIC)) {
sort_value[i] += (1 << 18);
if (!HasPowerOnRail(rt[i], RAILTYPE_MONO) && HasPowerOnRail(rt[i], RAILTYPE_MAGLEV)) {
sort_value[i] += (1 << 19);
}
}
}
// Then Mono
if (HasPowerOnRail(rt[i], RAILTYPE_MONO)) {
sort_value[i] += (1 << 20);
}
// Maglev is second last
if (HasPowerOnRail(rt[i], RAILTYPE_MAGLEV)) {
sort_value[i] += (1 << 21);
}
// All no-speed tracks (like planning and lifted) go to the end
if (GetRailTypeInfo(rt[i])->max_speed == 0) {
sort_value[i] += (1 << 22);
}
}
return sort_value[0] < sort_value[1];
} else {
return GetRailTypeInfo(first)->sorting_order < GetRailTypeInfo(second)->sorting_order; return GetRailTypeInfo(first)->sorting_order < GetRailTypeInfo(second)->sorting_order;
}
}
void SortRailTypes()
{
std::sort(_sorted_railtypes.begin(), _sorted_railtypes.end(), CompareRailTypes);
} }
/** /**
@@ -149,7 +199,7 @@ void InitRailTypes()
_sorted_railtypes.push_back(rt); _sorted_railtypes.push_back(rt);
} }
} }
std::sort(_sorted_railtypes.begin(), _sorted_railtypes.end(), CompareRailTypes); SortRailTypes();
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
_railtypes[rt].all_compatible_railtypes = _railtypes[rt].compatible_railtypes; _railtypes[rt].all_compatible_railtypes = _railtypes[rt].compatible_railtypes;

View File

@@ -1529,6 +1529,13 @@ static bool VelocityUnitsChanged(int32 p1) {
return true; return true;
} }
static bool ChangeTrackTypeSortMode(int32 p1) {
extern void SortRailTypes();
SortRailTypes();
MarkWholeScreenDirty();
return true;
}
/** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */ /** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */
static void ValidateSettings() static void ValidateSettings()
{ {

View File

@@ -1837,6 +1837,7 @@ static SettingsContainer &GetSettingsTree()
interface->Add(new SettingEntry("gui.show_adv_load_mode_features")); interface->Add(new SettingEntry("gui.show_adv_load_mode_features"));
interface->Add(new SettingEntry("gui.disable_top_veh_list_mass_actions")); interface->Add(new SettingEntry("gui.disable_top_veh_list_mass_actions"));
interface->Add(new SettingEntry("gui.adv_sig_bridge_tun_modes")); interface->Add(new SettingEntry("gui.adv_sig_bridge_tun_modes"));
interface->Add(new SettingEntry("gui.sort_track_types_by_speed"));
interface->Add(new SettingEntry("gui.show_depot_sell_gui")); interface->Add(new SettingEntry("gui.show_depot_sell_gui"));
interface->Add(new SettingEntry("gui.open_vehicle_gui_clone_share")); interface->Add(new SettingEntry("gui.open_vehicle_gui_clone_share"));
interface->Add(new SettingEntry("gui.vehicle_names")); interface->Add(new SettingEntry("gui.vehicle_names"));

View File

@@ -215,6 +215,7 @@ struct GUISettings : public TimeSettings {
bool show_adv_load_mode_features; ///< enable advanced loading mode features in UI bool show_adv_load_mode_features; ///< enable advanced loading mode features in UI
bool disable_top_veh_list_mass_actions; ///< disable mass actions buttons for non-group vehicle lists bool disable_top_veh_list_mass_actions; ///< disable mass actions buttons for non-group vehicle lists
bool adv_sig_bridge_tun_modes; ///< Enable advanced modes for signals on bridges/tunnels. bool adv_sig_bridge_tun_modes; ///< Enable advanced modes for signals on bridges/tunnels.
bool sort_track_types_by_speed; ///< Sorts track types by compatibility first, and speed next, instead of newGRF slot
bool show_depot_sell_gui; ///< Show go to depot and sell in UI bool show_depot_sell_gui; ///< Show go to depot and sell in UI
bool open_vehicle_gui_clone_share; ///< Open vehicle GUI when share-cloning vehicle from depot GUI bool open_vehicle_gui_clone_share; ///< Open vehicle GUI when share-cloning vehicle from depot GUI
uint8 linkgraph_colours; ///< linkgraph overlay colours uint8 linkgraph_colours; ///< linkgraph overlay colours

View File

@@ -62,6 +62,7 @@ static bool ViewportMapLandscapeModeChanged(int32 p1);
static bool UpdateLinkgraphColours(int32 p1); static bool UpdateLinkgraphColours(int32 p1);
static bool ClimateThresholdModeChanged(int32 p1); static bool ClimateThresholdModeChanged(int32 p1);
static bool VelocityUnitsChanged(int32 p1); static bool VelocityUnitsChanged(int32 p1);
static bool ChangeTrackTypeSortMode(int32 p1);
static bool UpdateClientName(int32 p1); static bool UpdateClientName(int32 p1);
static bool UpdateServerPassword(int32 p1); static bool UpdateServerPassword(int32 p1);
@@ -5415,6 +5416,15 @@ str = STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES
strhelp = STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES_HELPTEXT strhelp = STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES_HELPTEXT
cat = SC_EXPERT cat = SC_EXPERT
[SDTC_BOOL]
var = gui.sort_track_types_by_speed
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
def = false
str = STR_CONFIG_SETTING_SORT_TRACK_TYPES_BY_SPEED
strhelp = STR_CONFIG_SETTING_SORT_TRACK_TYPES_BY_SPEED_HELPTEXT
proc = ChangeTrackTypeSortMode
cat = SC_EXPERT
[SDTC_BOOL] [SDTC_BOOL]
var = gui.show_depot_sell_gui var = gui.show_depot_sell_gui
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC