Add Basic Reworked UI

This commit is contained in:
copecone committed 2026-06-12 22:29:01 +09:00
1 parent 5c7f6ba6e8
commit d93319bf6c
13 files changed
+218 -406

No files matched your search

+18 -6
View File
@@ -13,13 +13,16 @@ namespace ADOFAIRenderer.Data
/// <typeparam name="T">The enum type to bind.</typeparam>
public class EnumDropdownBinder<T> where T : struct, Enum
{
private readonly DropdownField _dropdown;
private readonly DropdownField? _dropdown;
private readonly List<T> _values;
private Action<T>? _onValueChanged;
/// <summary>
/// The currently selected enum value.
/// </summary>
public T Value => _values[_dropdown.index >= 0 ? _dropdown.index : 0];
public T Value => _dropdown != null && _dropdown.index >= 0 && _dropdown.index < _values.Count
? _values[_dropdown.index]
: default;
/// <summary>
/// Queries a <see cref="DropdownField"/> by name from the root VisualElement,
@@ -30,18 +33,24 @@ namespace ADOFAIRenderer.Data
/// <param name="defaultValue">The initial selected value. Defaults to the first enum member.</param>
public EnumDropdownBinder(VisualElement rootVisualElement, string fieldName, T? defaultValue = null)
{
_values = Enum.GetValues(typeof(T)).Cast<T>().ToList();
_dropdown = rootVisualElement.Q<DropdownField>(fieldName);
if (_dropdown == null)
{
Melon<RenderMod>.Logger.Error(
$"DropdownField '{fieldName}'을(를) 찾을 수 없습니다.");
_values = new List<T>();
return;
}
_values = Enum.GetValues(typeof(T)).Cast<T>().ToList();
_dropdown.choices = _values.Select(v => v.ToString()).ToList();
// Register the callback BEFORE setting index so the initial selection fires it too
_dropdown.RegisterValueChangedCallback(_ =>
{
_onValueChanged?.Invoke(Value);
});
var initial = defaultValue ?? _values[0];
_dropdown.index = _values.IndexOf(initial);
}
@@ -51,10 +60,13 @@ namespace ADOFAIRenderer.Data
/// </summary>
public void OnValueChanged(Action<T> callback)
{
_dropdown?.RegisterValueChangedCallback(evt =>
_onValueChanged = callback;
// Fire immediately with current value so the caller gets the initial state
if (_dropdown != null)
{
callback(Value);
});
}
}
}
}