diff --git a/src/settings.cpp b/src/settings.cpp index a2eee6d..8d98f8f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1857,6 +1857,21 @@ void SetCompanySetting(uint index, int32 value) } /** + * Top function to save the new value of an element of the NewsSettings struct + * @param index offset in the SettingDesc array of the NewsSettings struct + * which identifies the setting member we want to change + * @param value new value of the setting + */ +void SetNewsSetting(uint index, int32 value) +{ + const SettingDesc *sd = &_news_settings[index]; + + void *var = GetVariableAddress(NULL, &sd->save); + Write_ValidateSetting(var, sd, value); + if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv)); +} + +/** * Set the company settings for a new company to their default values. */ void SetDefaultCompanySettings(CompanyID cid) @@ -1952,6 +1967,12 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i) } } + /* Check for full names of the news */ + for (*i = 0, sd = _news_settings; sd->save.cmd != SL_END; sd++, (*i)++) { + if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; + if (strcmp(sd->desc.name, name) == 0) return sd; + } + if (strncmp(name, "company.", 8) == 0) name += 8; /* And finally the company-based settings */ for (*i = 0, sd = _company_settings; sd->save.cmd != SL_END; sd++, (*i)++) { diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index ce93550..7bb0420 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1459,9 +1459,32 @@ static SettingEntry _settings_ui_interaction[] = { /** Interaction sub-page */ static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)}; +static SettingEntry _settings_ui_news[] = { + SettingEntry("news_display.arrival_player"), + SettingEntry("news_display.arrival_other"), + SettingEntry("news_display.accident"), + SettingEntry("news_display.company_info"), + SettingEntry("news_display.open"), + SettingEntry("news_display.close"), + SettingEntry("news_display.economy"), + SettingEntry("news_display.production_player"), + SettingEntry("news_display.production_other"), + SettingEntry("news_display.production_nobody"), + SettingEntry("news_display.advice"), + SettingEntry("news_display.new_vehicles"), + SettingEntry("news_display.acceptance"), + SettingEntry("news_display.subsidies"), + SettingEntry("news_display.general"), + SettingEntry("misc.news_ticker_sound"), +}; + +/** News options sub-page */ +static SettingsPage _settings_ui_news_page = {_settings_ui_news, lengthof(_settings_ui_news)}; + static SettingEntry _settings_ui[] = { SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS), SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION), + SettingEntry(&_settings_ui_news_page, STR_CONFIG_SETTING_NEWS_OPTIONS), SettingEntry("gui.show_finances"), SettingEntry("gui.errmsg_duration"), SettingEntry("gui.hover_delay"), @@ -2008,6 +2031,8 @@ struct GameSettingsWindow : Window { if (value != oldvalue) { if ((sd->desc.flags & SGF_PER_COMPANY) != 0) { SetCompanySetting(pe->d.entry.index, value); + } else if (strcmp(sd->desc.name, "misc.news_ticker_sound") == 0) { + SetNewsSetting(pe->d.entry.index, value); } else { SetSettingValue(pe->d.entry.index, value); } @@ -2091,6 +2116,9 @@ struct GameSettingsWindow : Window { if ((sd->desc.flags & SGF_PER_COMPANY) != 0) { SetCompanySetting(this->valuedropdown_entry->d.entry.index, index); + } else if (strncmp(sd->desc.name, "news_display", 12) == 0) { + /* this is a news drop down box item */ + SetNewsSetting(this->valuedropdown_entry->d.entry.index, index); } else { SetSettingValue(this->valuedropdown_entry->d.entry.index, index); } diff --git a/src/settings_internal.h b/src/settings_internal.h index 9bda96f..0cb6117 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -118,5 +118,6 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i); bool SetSettingValue(uint index, int32 value, bool force_newgame = false); bool SetSettingValue(uint index, const char *value, bool force_newgame = false); void SetCompanySetting(uint index, int32 value); +void SetNewsSetting(uint index, int32 value); #endif /* SETTINGS_INTERNAL_H */