Fix: store autosave settings under the new names

pull/603/merge
Patric Stout 11 months ago committed by Patric Stout
parent 790c1b1b02
commit 4f4810dc28

@ -102,15 +102,6 @@ bool _save_config = false;
bool _request_newgrf_scan = false; bool _request_newgrf_scan = false;
NewGRFScanCallback *_request_newgrf_scan_callback = nullptr; NewGRFScanCallback *_request_newgrf_scan_callback = nullptr;
/** Available settings for autosave intervals. */
static const std::chrono::milliseconds _autosave_ticks[] = {
std::chrono::minutes::zero(), ///< never
std::chrono::minutes(10),
std::chrono::minutes(30),
std::chrono::minutes(60),
std::chrono::minutes(120),
};
/** /**
* Error handling for fatal user errors. * Error handling for fatal user errors.
* @param str the string to print. * @param str the string to print.
@ -1458,7 +1449,7 @@ static IntervalTimer<TimerGameRealtime> _autosave_interval({std::chrono::millise
*/ */
void ChangeAutosaveFrequency(bool reset) void ChangeAutosaveFrequency(bool reset)
{ {
_autosave_interval.SetInterval({_autosave_ticks[_settings_client.gui.autosave], TimerGameRealtime::AUTOSAVE}, reset); _autosave_interval.SetInterval({_settings_client.gui.autosave_interval, TimerGameRealtime::AUTOSAVE}, reset);
} }
/** /**

@ -161,6 +161,8 @@ enum IniFileVersion : uint32 {
IFV_LINKGRAPH_SECONDS, ///< 3 PR#10610 Store linkgraph update intervals in seconds instead of days. IFV_LINKGRAPH_SECONDS, ///< 3 PR#10610 Store linkgraph update intervals in seconds instead of days.
IFV_NETWORK_PRIVATE_SETTINGS, ///< 4 PR#10762 Move no_http_content_downloads / use_relay_service to private settings. IFV_NETWORK_PRIVATE_SETTINGS, ///< 4 PR#10762 Move no_http_content_downloads / use_relay_service to private settings.
IFV_AUTOSAVE_RENAME, ///< 5 PR#11143 Renamed values of autosave to be in minutes.
IFV_MAX_VERSION, ///< Highest possible ini-file version. IFV_MAX_VERSION, ///< Highest possible ini-file version.
}; };
@ -1318,6 +1320,20 @@ void LoadFromConfig(bool startup)
_settings_client.network.server_game_type = old_value.value_or(false) ? SERVER_GAME_TYPE_PUBLIC : SERVER_GAME_TYPE_LOCAL; _settings_client.network.server_game_type = old_value.value_or(false) ? SERVER_GAME_TYPE_PUBLIC : SERVER_GAME_TYPE_LOCAL;
} }
if (generic_version < IFV_AUTOSAVE_RENAME && IsConversionNeeded(generic_ini, "gui", "autosave", "autosave_interval", &old_item)) {
static std::vector<std::string> _old_autosave_interval{"off", "monthly", "quarterly", "half year", "yearly"};
auto old_value = OneOfManySettingDesc::ParseSingleValue(old_item->value->c_str(), old_item->value->size(), _old_autosave_interval);
switch (old_value) {
case 0: _settings_client.gui.autosave_interval = std::chrono::minutes::zero(); break;
case 1: _settings_client.gui.autosave_interval = std::chrono::minutes(10); break;
case 2: _settings_client.gui.autosave_interval = std::chrono::minutes(30); break;
case 3: _settings_client.gui.autosave_interval = std::chrono::minutes(60); break;
case 4: _settings_client.gui.autosave_interval = std::chrono::minutes(120); break;
default: break;
}
}
_grfconfig_newgame = GRFLoadConfig(generic_ini, "newgrf", false); _grfconfig_newgame = GRFLoadConfig(generic_ini, "newgrf", false);
_grfconfig_static = GRFLoadConfig(generic_ini, "newgrf-static", true); _grfconfig_static = GRFLoadConfig(generic_ini, "newgrf-static", true);
AILoadConfig(generic_ini, "ai_players"); AILoadConfig(generic_ini, "ai_players");

@ -58,6 +58,15 @@ static const StringID _autosave_dropdown[] = {
INVALID_STRING_ID, INVALID_STRING_ID,
}; };
/** Available settings for autosave intervals. */
static const std::chrono::minutes _autosave_dropdown_to_minutes[] = {
std::chrono::minutes::zero(), ///< never
std::chrono::minutes(10),
std::chrono::minutes(30),
std::chrono::minutes(60),
std::chrono::minutes(120),
};
static Dimension _circle_size; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window. static Dimension _circle_size; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.
static const void *ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd); static const void *ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd);
@ -220,7 +229,13 @@ struct GameOptionsWindow : Window {
} }
case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
*selected_index = _settings_client.gui.autosave; int index = 0;
for (auto &minutes : _autosave_dropdown_to_minutes) {
index++;
if (_settings_client.gui.autosave_interval <= minutes) break;
}
*selected_index = index - 1;
const StringID *items = _autosave_dropdown; const StringID *items = _autosave_dropdown;
for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) { for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
list.emplace_back(new DropDownListStringItem(*items, i, false)); list.emplace_back(new DropDownListStringItem(*items, i, false));
@ -301,7 +316,15 @@ struct GameOptionsWindow : Window {
} }
break; break;
} }
case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break; case WID_GO_AUTOSAVE_DROPDOWN: {
int index = 0;
for (auto &minutes : _autosave_dropdown_to_minutes) {
index++;
if (_settings_client.gui.autosave_interval <= minutes) break;
}
SetDParam(0, _autosave_dropdown[index - 1]);
break;
}
case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break; case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break; case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break; case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
@ -655,7 +678,7 @@ struct GameOptionsWindow : Window {
break; break;
case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
_settings_client.gui.autosave = index; _settings_client.gui.autosave_interval = _autosave_dropdown_to_minutes[index];
ChangeAutosaveFrequency(false); ChangeAutosaveFrequency(false);
this->SetDirty(); this->SetDirty();
break; break;
@ -1791,7 +1814,7 @@ static SettingsContainer &GetSettingsTree()
} }
interface->Add(new SettingEntry("gui.fast_forward_speed_limit")); interface->Add(new SettingEntry("gui.fast_forward_speed_limit"));
interface->Add(new SettingEntry("gui.autosave")); interface->Add(new SettingEntry("gui.autosave_interval"));
interface->Add(new SettingEntry("gui.toolbar_pos")); interface->Add(new SettingEntry("gui.toolbar_pos"));
interface->Add(new SettingEntry("gui.statusbar_pos")); interface->Add(new SettingEntry("gui.statusbar_pos"));
interface->Add(new SettingEntry("gui.prefer_teamchat")); interface->Add(new SettingEntry("gui.prefer_teamchat"));

@ -142,7 +142,7 @@ struct GUISettings {
ZoomLevel zoom_min; ///< minimum zoom out level ZoomLevel zoom_min; ///< minimum zoom out level
ZoomLevel zoom_max; ///< maximum zoom out level ZoomLevel zoom_max; ///< maximum zoom out level
ZoomLevel sprite_zoom_min; ///< maximum zoom level at which higher-resolution alternative sprites will be used (if available) instead of scaling a lower resolution sprite ZoomLevel sprite_zoom_min; ///< maximum zoom level at which higher-resolution alternative sprites will be used (if available) instead of scaling a lower resolution sprite
byte autosave; ///< how often should we do autosaves? std::chrono::minutes autosave_interval; ///< how often should we do autosaves?
bool threaded_saves; ///< should we do threaded saves? bool threaded_saves; ///< should we do threaded saves?
bool keep_all_autosave; ///< name the autosave in a different way bool keep_all_autosave; ///< name the autosave in a different way
bool autosave_on_exit; ///< save an autosave when you quit the game, but do not ask "Do you really want to quit?" bool autosave_on_exit; ///< save an autosave when you quit the game, but do not ask "Do you really want to quit?"

@ -16,7 +16,6 @@ static void InvalidateNewGRFChangeWindows(int32 new_value);
static void ZoomMinMaxChanged(int32 new_value); static void ZoomMinMaxChanged(int32 new_value);
static void SpriteZoomMinChanged(int32 new_value); static void SpriteZoomMinChanged(int32 new_value);
static constexpr std::initializer_list<const char*> _autosave_interval{"off", "monthly", "quarterly", "half year", "yearly"};
static constexpr std::initializer_list<const char*> _osk_activation{"disabled", "double", "single", "immediately"}; static constexpr std::initializer_list<const char*> _osk_activation{"disabled", "double", "single", "immediately"};
static constexpr std::initializer_list<const char*> _savegame_date{"long", "short", "iso"}; static constexpr std::initializer_list<const char*> _savegame_date{"long", "short", "iso"};
@ -48,16 +47,15 @@ extra = 0
startup = false startup = false
[SDTC_OMANY] [SDTC_VAR]
var = gui.autosave var = gui.autosave_interval
type = SLE_UINT8 type = SLE_UINT32
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = 1 def = 10
max = 4 min = 0
full = _autosave_interval max = 1440
str = STR_CONFIG_SETTING_AUTOSAVE str = STR_CONFIG_SETTING_AUTOSAVE
strhelp = STR_CONFIG_SETTING_AUTOSAVE_HELPTEXT strhelp = STR_CONFIG_SETTING_AUTOSAVE_HELPTEXT
strval = STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF
cat = SC_BASIC cat = SC_BASIC
[SDTC_BOOL] [SDTC_BOOL]

@ -142,15 +142,6 @@ min = MIN_SNOWLINE_HEIGHT * TILE_HEIGHT
max = UINT8_MAX max = UINT8_MAX
to = SLV_22 to = SLV_22
[SDTC_OMANY]
var = gui.autosave
type = SLE_UINT8
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = 1
max = 4
full = _autosave_interval
cat = SC_BASIC
[SDT_OMANY] [SDT_OMANY]
var = vehicle.road_side var = vehicle.road_side
type = SLE_UINT8 type = SLE_UINT8

Loading…
Cancel
Save