mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-13 07:10:57 +00:00
Settings window: Add mechanism for conditionally hidden settings
This commit is contained in:
parent
f3164b6ef4
commit
40203b090f
@ -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 == */
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user