mirror of https://github.com/OpenTTD/OpenTTD
Merge 3c56c0fe2e
into a46a3a97f3
commit
76f914b6dc
|
@ -325,7 +325,7 @@ struct GSConfigWindow : public Window {
|
|||
}
|
||||
} else if (!bool_item && !config_item.complete_labels) {
|
||||
/* Display a query box so users can enter a custom value. */
|
||||
ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
|
||||
ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QueryStringFlag::EnableDefault);
|
||||
}
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
@ -347,10 +347,17 @@ struct GSConfigWindow : public Window {
|
|||
|
||||
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||
{
|
||||
/* The user pressed cancel */
|
||||
if (!str.has_value()) return;
|
||||
auto value = ParseInteger<int32_t>(*str, 10, true);
|
||||
if (!value.has_value()) return;
|
||||
this->SetValue(*value);
|
||||
|
||||
if (!str->empty()) {
|
||||
auto value = ParseInteger<int32_t>(*str, 10, true);
|
||||
if (!value.has_value()) return;
|
||||
|
||||
this->SetValue(*value);
|
||||
} else {
|
||||
this->SetDefaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDropdownSelect(WidgetID widget, int index, int) override
|
||||
|
@ -419,6 +426,14 @@ private:
|
|||
this->gs_config->SetSetting(config_item.name, value);
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
void SetDefaultValue()
|
||||
{
|
||||
const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
|
||||
if (_game_mode == GM_NORMAL && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
|
||||
this->gs_config->ResetSetting(config_item.name);
|
||||
this->SetDirty();
|
||||
}
|
||||
};
|
||||
|
||||
/** Open the GS config window. */
|
||||
|
|
|
@ -106,6 +106,16 @@ void ScriptConfig::ResetSettings()
|
|||
this->settings.clear();
|
||||
}
|
||||
|
||||
void ScriptConfig::ResetSetting(std::string_view name)
|
||||
{
|
||||
if (this->info == nullptr) return;
|
||||
|
||||
const ScriptConfigItem *config_item = this->info->GetConfigItem(name);
|
||||
if (config_item == nullptr) return;
|
||||
|
||||
this->settings.erase(std::string{name});
|
||||
}
|
||||
|
||||
void ScriptConfig::ResetEditableSettings(bool yet_to_start)
|
||||
{
|
||||
if (this->info == nullptr) return ResetSettings();
|
||||
|
|
|
@ -129,6 +129,11 @@ public:
|
|||
*/
|
||||
void ResetSettings();
|
||||
|
||||
/**
|
||||
* Reset a setting to its default value.
|
||||
*/
|
||||
void ResetSetting(std::string_view name);
|
||||
|
||||
/**
|
||||
* Reset only editable and visible settings to their default value.
|
||||
*/
|
||||
|
|
|
@ -470,7 +470,7 @@ struct ScriptSettingsWindow : public Window {
|
|||
}
|
||||
} else if (!bool_item && !config_item.complete_labels) {
|
||||
/* Display a query box so users can enter a custom value. */
|
||||
ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
|
||||
ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, QueryStringFlag::EnableDefault);
|
||||
}
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
@ -485,10 +485,17 @@ struct ScriptSettingsWindow : public Window {
|
|||
|
||||
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||
{
|
||||
/* The user pressed cancel */
|
||||
if (!str.has_value()) return;
|
||||
auto value = ParseInteger<int32_t>(*str, 10, true);
|
||||
if (!value.has_value()) return;
|
||||
this->SetValue(*value);
|
||||
|
||||
if (!str->empty()) {
|
||||
auto value = ParseInteger<int32_t>(*str, 10, true);
|
||||
if (!value.has_value()) return;
|
||||
|
||||
this->SetValue(*value);
|
||||
} else {
|
||||
this->SetDefaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDropdownSelect(WidgetID widget, int index, int) override
|
||||
|
@ -552,6 +559,14 @@ private:
|
|||
this->script_config->SetSetting(config_item.name, value);
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
void SetDefaultValue()
|
||||
{
|
||||
const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
|
||||
if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
|
||||
this->script_config->ResetSetting(config_item.name);
|
||||
this->SetDirty();
|
||||
}
|
||||
};
|
||||
|
||||
/** Widgets for the Script settings window. */
|
||||
|
|
Loading…
Reference in New Issue