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

Method IsVisibleByRestrictionMode

src/settingentry_gui.cpp:176–209  ·  view source on GitHub ↗

* Checks whether an entry shall be made visible based on the restriction mode. * @param mode The current status of the restriction drop down box. * @return true if the entry shall be visible. */

Source from the content-addressed store, hash-verified

174 * @return true if the entry shall be visible.
175 */
176bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
177{
178 /* There shall not be any restriction, i.e. all settings shall be visible. */
179 if (mode == RM_ALL) return true;
180
181 const IntSettingDesc *sd = this->setting;
182
183 if (mode == RM_BASIC) return (this->setting->cat & SC_BASIC_LIST) != 0;
184 if (mode == RM_ADVANCED) return (this->setting->cat & SC_ADVANCED_LIST) != 0;
185
186 /* Read the current value. */
187 const void *object = ResolveObject(&GetGameSettings(), sd);
188 int64_t current_value = sd->Read(object);
189 int64_t filter_value;
190
191 if (mode == RM_CHANGED_AGAINST_DEFAULT) {
192 /* This entry shall only be visible, if the value deviates from its default value. */
193
194 /* Read the default value. */
195 filter_value = sd->GetDefaultValue();
196 } else {
197 assert(mode == RM_CHANGED_AGAINST_NEW);
198 /* This entry shall only be visible, if the value deviates from
199 * its value is used when starting a new game. */
200
201 /* Make sure we're not comparing the new game settings against itself. */
202 assert(&GetGameSettings() != &_settings_newgame);
203
204 /* Read the new game's value. */
205 filter_value = sd->Read(ResolveObject(&_settings_newgame, sd));
206 }
207
208 return current_value != filter_value;
209}
210
211/**
212 * Update the filter state.

Callers 1

UpdateFilterStateMethod · 0.95

Calls 3

ResolveObjectFunction · 0.85
GetDefaultValueMethod · 0.80
ReadMethod · 0.45

Tested by

no test coverage detected