using UnityEngine;
namespace Ashwild.Settings
{
///
/// Binds the graphics widgets (quality, vsync, FPS cap, FOV) to the .
/// The panel is the only layer that knows what each widget means: it reads the authored
/// configuration from the manager's and initializes each widget
/// with its data and apply action, then pushes the current value on refresh. The widgets stay
/// pure UI.
///
public class GraphicsSettingsSubPanel : SettingsSubPanel
{
#region Serialized Fields
[Header("Widgets")]
[SerializeField] private SettingDropdownWidget qualityDropdown;
[SerializeField] private SettingToggleWidget vsyncToggle;
[SerializeField] private SettingStepperWidget targetFpsStepper;
[SerializeField] private SettingSliderWidget fovSlider;
#endregion
#region Unity Lifecycle
///
/// Initializes each widget from the definition with the action to apply to the manager.
///
private void Awake()
{
SettingsManager s = SettingsManager.Instance;
if (s == null || s.Definition == null)
{
Debug.LogError($"[GraphicsSettingsSubPanel] SettingsManager/Definition unavailable on '{name}'.", this);
return;
}
SettingsDefinition def = s.Definition;
qualityDropdown.Init(v => s.SetQualityLevel(v));
vsyncToggle.Init(v => s.SetVSync(v));
targetFpsStepper.Init(def.TargetFps.ToWidgetPresets(), false, v => s.SetTargetFps(v));
fovSlider.Init(def.Fov.Min, def.Fov.Max, def.Fov.LabelScale, def.Fov.LabelFormat, v => s.SetFov(v));
}
#endregion
#region Public API
///
/// Pushes the manager's current graphics values into the widgets.
///
public override void Refresh()
{
SettingsManager s = SettingsManager.Instance;
if (s == null) return;
qualityDropdown.SetOptions(QualitySettings.names);
qualityDropdown.SetValue(s.QualityLevel);
vsyncToggle.SetValue(s.VSync);
targetFpsStepper.SetValue(s.TargetFps);
fovSlider.SetValue(s.Fov);
}
#endregion
}
}