MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ChangeValue

Method ChangeValue

src/settings.cpp:1611–1631  ·  view source on GitHub ↗

* Handle changing a value. This performs validation of the input value and * calls the appropriate callbacks, and saves it when the value is changed. * @param object The object the setting is in. * @param newval The new value for the setting. */

Source from the content-addressed store, hash-verified

1609 * @param newval The new value for the setting.
1610 */
1611void IntSettingDesc::ChangeValue(const void *object, int32_t newval) const
1612{
1613 int32_t oldval = this->Read(object);
1614 this->MakeValueValid(newval);
1615 if (this->pre_check != nullptr && !this->pre_check(newval)) return;
1616 if (oldval == newval) return;
1617
1618 this->Write(object, newval);
1619 if (this->post_callback != nullptr) this->post_callback(newval);
1620
1621 if (this->flags.Test(SettingFlag::NoNetwork) || this->flags.Test(SettingFlag::Sandbox)) {
1622 _gamelog.StartAction(GLAT_SETTING);
1623 _gamelog.Setting(this->GetName(), oldval, newval);
1624 _gamelog.StopAction();
1625 }
1626
1627 SetWindowClassesDirty(WC_GAME_OPTIONS);
1628 if (this->flags.Test(SettingFlag::Sandbox)) SetWindowClassesDirty(WC_CHEATS);
1629
1630 if (_save_config) SaveToConfig();
1631}
1632
1633/**
1634 * Given a name of setting, return a setting description from the table.

Callers 3

CmdChangeSettingFunction · 0.80
CmdChangeCompanySettingFunction · 0.80
SetSettingValueFunction · 0.80

Calls 10

ReadMethod · 0.95
MakeValueValidMethod · 0.95
WriteMethod · 0.95
SetWindowClassesDirtyFunction · 0.85
SaveToConfigFunction · 0.85
TestMethod · 0.80
StartActionMethod · 0.80
SettingMethod · 0.80
StopActionMethod · 0.80
GetNameMethod · 0.45

Tested by

no test coverage detected