(Feat) Add Remmaping

This commit is contained in:
2026-06-26 16:23:20 +02:00
parent 931bc9c9e2
commit 7bd2aa3120
249 changed files with 23712 additions and 6898 deletions
@@ -1,64 +1,66 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Ashwild.Settings
{
/// <summary>
/// Binds the graphics widgets (quality, vsync, FPS cap, FOV) to the <see cref="SettingsManager"/>.
/// The panel is the only layer that knows what each widget means: it reads the authored
/// configuration from the manager's <see cref="SettingsDefinition"/> and initializes each widget
/// with its data and apply action, then pushes the current value on refresh. The widgets stay
/// pure UI.
/// </summary>
public class GraphicsSettingsSubPanel : SettingsSubPanel
{
[Header("Controls")]
[SerializeField] private TMP_Dropdown qualityDropdown;
[SerializeField] private Toggle vsyncToggle;
[SerializeField] private Slider targetFpsSlider;
[SerializeField] private TMP_Text targetFpsLabel;
[SerializeField] private Slider fovSlider;
[SerializeField] private TMP_Text fovLabel;
#region Serialized Fields
private bool wiring;
[Header("Widgets")]
[SerializeField] private SettingDropdownWidget qualityDropdown;
[SerializeField] private SettingToggleWidget vsyncToggle;
[SerializeField] private SettingStepperWidget targetFpsStepper;
[SerializeField] private SettingSliderWidget fovSlider;
#endregion
#region Unity Lifecycle
/// <summary>
/// Initializes each widget from the definition with the action to apply to the manager.
/// </summary>
private void Awake()
{
qualityDropdown.onValueChanged.AddListener(v => { if (!wiring) SettingsManager.Instance.SetQualityLevel(v); });
vsyncToggle.onValueChanged.AddListener(v => { if (!wiring) SettingsManager.Instance.SetVSync(v); });
targetFpsSlider.onValueChanged.AddListener(OnTargetFpsChanged);
fovSlider.onValueChanged.AddListener(OnFovChanged);
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
/// <summary>
/// Pushes the manager's current graphics values into the widgets.
/// </summary>
public override void Refresh()
{
SettingsManager s = SettingsManager.Instance;
if (s == null) return;
wiring = true;
qualityDropdown.ClearOptions();
qualityDropdown.AddOptions(new List<string>(QualitySettings.names));
qualityDropdown.value = Mathf.Clamp(s.QualityLevel, 0, qualityDropdown.options.Count - 1);
qualityDropdown.RefreshShownValue();
vsyncToggle.SetIsOnWithoutNotify(s.VSync);
targetFpsSlider.SetValueWithoutNotify(s.TargetFps);
if (targetFpsLabel != null) targetFpsLabel.text = $"{s.TargetFps} FPS";
fovSlider.SetValueWithoutNotify(s.Fov);
if (fovLabel != null) fovLabel.text = $"{s.Fov:F0}°";
wiring = false;
qualityDropdown.SetOptions(QualitySettings.names);
qualityDropdown.SetValue(s.QualityLevel);
vsyncToggle.SetValue(s.VSync);
targetFpsStepper.SetValue(s.TargetFps);
fovSlider.SetValue(s.Fov);
}
private void OnTargetFpsChanged(float v)
{
int fps = Mathf.RoundToInt(v);
if (targetFpsLabel != null) targetFpsLabel.text = $"{fps} FPS";
if (!wiring) SettingsManager.Instance.SetTargetFps(fps);
}
private void OnFovChanged(float v)
{
if (fovLabel != null) fovLabel.text = $"{v:F0}°";
if (!wiring) SettingsManager.Instance.SetFov(v);
}
#endregion
}
}