* 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. */
| 174 | * @return true if the entry shall be visible. |
| 175 | */ |
| 176 | bool 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. |
no test coverage detected