Skip to content

Game.Settings.GlobalQualitySettings

Assembly:
{{ Likely part of the main game assembly (Cities: Skylines 2 game code). Replace with actual assembly name if known. }}

Namespace: Game.Settings

Type: class

Base: QualitySetting

Summary:
GlobalQualitySettings aggregates multiple per-subsystem QualitySetting instances into a single compound quality configuration. It maintains a list of QualitySetting objects (one per subsystem type), supports enumerating and retrieving specific subsystem settings, propagates default values for each subsystem type, and applies global quality levels by transferring values from per-level presets. It also participates in the game's settings merge/serialization behavior via attributes (MergeByType, IgnoreEquals, Exclude, SettingsUIHidden).


Fields

  • protected static readonly System.Collections.Generic.Dictionary<System.Type, Level> s_DefaultsMap
    {{ Maps each QualitySetting type to its default Level. Populated when AddQualitySetting is called for a setting; used by SetDefaults to initialize each subsystem setting to its recorded default Level (without applying by default). }}

  • private System.Collections.Generic.List<QualitySetting> m_QualitySettings
    {{ Internal list that stores the contained QualitySetting instances for every subsystem (e.g., graphics subsystems). Exposed via the qualitySettings property for merge operations and UI/use (but the setter performs a selective transfer instead of replacing the list). }}

Properties

  • public System.Collections.Generic.List<QualitySetting> qualitySettings { get; set; }
    {{ Backed by m_QualitySettings. Marked with [MergeByType] and [IgnoreEquals]. The getter returns the internal list. The setter does not replace the list; instead, it iterates the existing m_QualitySettings and, for each existing entry, searches the provided list for an entry of the same concrete type and transfers values from that provided entry (qualitySetting.TransferValuesFrom). This allows merges/loads to update existing entries by type while keeping the internal list order and instances intact. }}

  • [Exclude] [IgnoreEquals] [SettingsUIHidden] public int countQualitySettings => m_QualitySettings.Count
    {{ Read-only convenience property returning the number of contained QualitySetting entries. Marked to be excluded from certain settings serialization/UI. }}

  • public QualitySetting lastSetting { get; }
    {{ Returns the last item in m_QualitySettings (i.e., m_QualitySettings[m_QualitySettings.Count - 1]). Useful to access the most recently added subsystem QualitySetting. Assumes the list is non-empty when called. }}

Constructors

  • public GlobalQualitySettings()
    {{ No explicit constructor is defined in the source; the compiler-provided default parameterless constructor is used. Initialization relies on field initializers (m_QualitySettings initialized to a new List). After construction, you typically call AddQualitySetting for each subsystem setting type to register them. }}

Methods

  • public override bool Equals(object obj)
    {{ Compares another object for equality. First, ensures obj is a GlobalQualitySettings and calls base.Equals(obj) (QualitySetting.Equals). Then compares each contained QualitySetting pairwise using their Equals implementations. Returns false if any contained setting differs. }}

  • public override int GetHashCode()
    {{ Computes a hash code combining base.GetHashCode() and the hash codes of all contained QualitySetting instances (enumerated via EnumerateQualitySettings). Uses a rolling combine (num = (num * 937) ^ item.GetHashCode()). }}

  • public T GetQualitySetting<T>() where T : QualitySetting
    {{ Generic retrieval helper: iterates m_QualitySettings and returns the first element whose concrete type equals typeof(T), cast to T. Returns null if not found. This matches exact types (not assignability). }}

  • public QualitySetting GetQualitySetting(System.Type type)
    {{ Non-generic equivalent that returns the first QualitySetting whose concrete type equals the provided type, or null if none. }}

  • public override void SetDefaults()
    {{ Sets each contained QualitySetting to the default Level recorded in s_DefaultsMap by calling item.SetLevel(s_DefaultsMap[item.GetType()], apply: false) for each item. Note apply: false — defaults are assigned but not applied/saved immediately; caller may apply afterwards. }}

  • public void AddQualitySetting<T>(T setting) where T : QualitySetting<T>
    {{ Registers a new QualitySetting instance for a concrete subsystem type T. Behavior:

  • If a setting of type T already exists (GetQualitySetting() != null), the method returns early (no duplicates).
  • Stores the setting's current Level into s_DefaultsMap for the type T.
  • Appends the setting to m_QualitySettings.
  • For each existing global quality level entry in QualitySetting.s_SettingsMap, the method ensures that the per-level GlobalQualitySettings object contains a corresponding per-level T value:

    • If QualitySetting.s_SettingsMap does not have an exact mapping for that Level, it searches downward for the nearest lower Level that has a mapping, and if none found, searches upward for the next available mapping < Level.Custom.
    • The resolved per-level T instance (value) is then appended to that per-level GlobalQualitySettings.m_QualitySettings list. This wiring makes sure that for every global quality Level, the per-level GlobalQualitySettings contains appropriate subsystem-level presets for the newly added subsystem type. }}
  • public System.Collections.Generic.IEnumerable<QualitySetting> EnumerateQualitySettings()
    {{ Iterator that yields each QualitySetting in m_QualitySettings. Useful for foreach iteration without exposing the internal list for modification. }}

  • public override void SetLevel(Level quality, bool apply = true)
    {{ Applies a global quality Level to the grouped settings:

  • If quality < Level.Custom, loops through m_QualitySettings and for each entry transfers values from the corresponding entry in QualitySetting.s_SettingsMap[quality].m_QualitySettings (by index).
  • After transferring values, if apply == true, calls ApplyAndSave() (inherited) to effect and persist the changes.
  • The method assumes the ordering of m_QualitySettings matches the ordering used in s_SettingsMap presets so index-based correspondence holds. }}

Usage Example

// Example: register subsystem quality settings and apply a preset level.
var global = new GlobalQualitySettings();

// Suppose MySubsystemQualitySetting : QualitySetting<MySubsystemQualitySetting>
var mySetting = new MySubsystemQualitySetting();
global.AddQualitySetting(mySetting);

// Get a specific subsystem setting
var retrieved = global.GetQualitySetting<MySubsystemQualitySetting>();
if (retrieved != null)
{
    // adjust the subsystem-level setting and apply globally
    retrieved.SetLevel(Level.High, apply: false);
}

// Apply a global quality preset (e.g., Medium) to all registered subsystems and save.
global.SetLevel(Level.Medium, apply: true);

Notes and tips: - The class uses exact type equality (GetType() == typeof(T) / == provided Type) when locating settings; derived types are not matched unless their concrete type equals what is searched for. - Order of m_QualitySettings is important: SetLevel uses index-based correspondence against the per-Level presets stored in QualitySetting.s_SettingsMap. Ensure consistent registration order across all presets. - Attributes on properties (MergeByType, IgnoreEquals, Exclude, SettingsUIHidden) control the game's settings merge/serialization and UI behavior and are important when integrating with the game's settings persistence and mod merge logic.