Allow setting autosave interval to a custom number of days
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include "rev.h"
|
||||
#include "video/video_driver.hpp"
|
||||
#include "music/music_driver.hpp"
|
||||
#include "scope.h"
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
@@ -60,6 +61,7 @@ static const StringID _autosave_dropdown[] = {
|
||||
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS,
|
||||
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS,
|
||||
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS,
|
||||
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_DAYS_CUSTOM_LABEL,
|
||||
INVALID_STRING_ID,
|
||||
};
|
||||
|
||||
@@ -168,6 +170,12 @@ struct GameOptionsWindow : Window {
|
||||
GameSettings *opt;
|
||||
bool reload;
|
||||
|
||||
enum class QueryTextItem {
|
||||
None,
|
||||
AutosaveCustomDays,
|
||||
};
|
||||
QueryTextItem current_query_text_item = QueryTextItem::None;
|
||||
|
||||
GameOptionsWindow(WindowDesc *desc) : Window(desc)
|
||||
{
|
||||
this->opt = &GetGameSettings();
|
||||
@@ -307,7 +315,15 @@ struct GameOptionsWindow : Window {
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
|
||||
case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
|
||||
case WID_GO_AUTOSAVE_DROPDOWN: {
|
||||
if (_settings_client.gui.autosave == 5) {
|
||||
SetDParam(0, _settings_client.gui.autosave_custom_days == 1 ? STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_DAYS_CUSTOM_SINGULAR : STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_DAYS_CUSTOM);
|
||||
SetDParam(1, _settings_client.gui.autosave_custom_days);
|
||||
} else {
|
||||
SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
|
||||
case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[_gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom_cfg + 1 : 0]); break;
|
||||
case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[_font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom_cfg + 1 : 0]); break;
|
||||
@@ -534,8 +550,14 @@ struct GameOptionsWindow : Window {
|
||||
break;
|
||||
|
||||
case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
|
||||
_settings_client.gui.autosave = index;
|
||||
this->SetDirty();
|
||||
if (index == 5) {
|
||||
this->current_query_text_item = QueryTextItem::AutosaveCustomDays;
|
||||
SetDParam(0, _settings_client.gui.autosave_custom_days);
|
||||
ShowQueryString(STR_JUST_INT, STR_GAME_OPTIONS_AUTOSAVE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
|
||||
} else {
|
||||
_settings_client.gui.autosave = index;
|
||||
this->SetDirty();
|
||||
}
|
||||
break;
|
||||
|
||||
case WID_GO_LANG_DROPDOWN: // Change interface language
|
||||
@@ -608,6 +630,30 @@ struct GameOptionsWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
void OnQueryTextFinished(char *str) override
|
||||
{
|
||||
auto guard = scope_guard([this]() {
|
||||
this->current_query_text_item = QueryTextItem::None;
|
||||
});
|
||||
|
||||
/* Was 'cancel' pressed? */
|
||||
if (str == nullptr) return;
|
||||
|
||||
if (!StrEmpty(str)) {
|
||||
int value = atoi(str);
|
||||
switch (this->current_query_text_item) {
|
||||
case QueryTextItem::None:
|
||||
break;
|
||||
|
||||
case QueryTextItem::AutosaveCustomDays:
|
||||
_settings_client.gui.autosave = 5;
|
||||
_settings_client.gui.autosave_custom_days = Clamp(value, 1, 4000);
|
||||
this->SetDirty();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Some data on this window has become invalid.
|
||||
* @param data Information about the changed data. @see GameOptionsInvalidationData
|
||||
@@ -1836,6 +1882,7 @@ static SettingsContainer &GetSettingsTree()
|
||||
|
||||
interface->Add(new SettingEntry("gui.fast_forward_speed_limit"));
|
||||
interface->Add(new SettingEntry("gui.autosave"));
|
||||
interface->Add(new ConditionallyHiddenSettingEntry("gui.autosave_custom_days", []() -> bool { return _settings_client.gui.autosave != 5; }));
|
||||
interface->Add(new SettingEntry("gui.autosave_on_network_disconnect"));
|
||||
interface->Add(new SettingEntry("gui.savegame_overwrite_confirm"));
|
||||
interface->Add(new SettingEntry("gui.toolbar_pos"));
|
||||
|
Reference in New Issue
Block a user