Settings window: Add mechanism for conditionally hidden settings

This commit is contained in:
Jonathan G Rennison 2021-04-10 21:33:22 +01:00
parent f3164b6ef4
commit 40203b090f

View File

@ -801,7 +801,7 @@ private:
bool IsVisibleByRestrictionMode(RestrictionMode mode) const;
};
/** Standard setting */
/** Cargodist per-cargo setting */
struct CargoDestPerCargoSettingEntry : SettingEntry {
CargoID cargo;
@ -813,6 +813,16 @@ protected:
virtual void DrawSettingString(uint left, uint right, int y, bool highlight, int32 value) const;
};
/** Conditionally hidden standard setting */
struct ConditionallyHiddenSettingEntry : SettingEntry {
std::function<bool()> hide_callback;
ConditionallyHiddenSettingEntry(const char *name, std::function<bool()> hide_callback)
: SettingEntry(name), hide_callback(hide_callback) {}
virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible);
};
/** Containers for BaseSettingEntry */
struct SettingsContainer {
typedef std::vector<BaseSettingEntry*> EntryVector;
@ -1238,6 +1248,16 @@ bool CargoDestPerCargoSettingEntry::UpdateFilterState(SettingFilter &filter, boo
}
}
bool ConditionallyHiddenSettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
{
if (this->hide_callback && this->hide_callback()) {
SETBITS(this->flags, SEF_FILTERED);
return false;
} else {
return SettingEntry::UpdateFilterState(filter, force_visible);
}
}
/* == SettingsContainer methods == */
/**