Signed-off-by: TRAfoer <lhf190@outlook.com>

This commit is contained in:
2026-02-13 23:04:26 +08:00
parent 96a2c60e16
commit 23f3caf876
29 changed files with 12268 additions and 5779 deletions

View File

@@ -1,8 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Ichni.RhythmGame;
using Michsky.MUIP;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
@@ -11,34 +11,49 @@ namespace Ichni.Editor
{
public class DynamicUIEnumDropdown : DynamicUIElement
{
public TMP_Dropdown dropdown;
public List<int> realValues;
// public TMP_Dropdown dropdown;
public CustomDropdown dropdownComponent;
public List<int> realValues = new List<int>();
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
{
base.Initialize(baseElement, title, parameterName);
object value = ReflectionHelper.GetDeepValue(connectedBaseElement, parameterName);
dropdown.value = value != null ? (int)value : 0;
dropdown.onValueChanged.AddListener(ApplyParameters);
int targetIndex = realValues.IndexOf(value != null ? (int)value : 0);
dropdownComponent.selectedItemIndex = (targetIndex != -1) ? targetIndex : 0;
dropdownComponent.SetupDropdown();
dropdownComponent.onValueChanged.RemoveAllListeners();
dropdownComponent.onValueChanged.AddListener(OnDropdownChanged);
}
public void SetUpEnum(Type enumType)
{
dropdown.ClearOptions();
realValues.Clear();
dropdownComponent.items.Clear();
List<string> enumNameList = System.Enum.GetNames(enumType).ToList();
realValues = System.Enum.GetValues(enumType).Cast<int>().ToList();
dropdown.AddOptions(enumNameList);
foreach (var name in enumNameList)
{
dropdownComponent.CreateNewItem(name);
}
dropdownComponent.SetupDropdown();
}
private void OnDropdownChanged(int index)
{
if (index < 0 || index >= realValues.Count) return;
ApplyParameters(realValues[index]);
}
private void ApplyParameters(int value)
{
ReflectionHelper.SetDeepValue(connectedBaseElement, parameterName, realValues[value]);
ReflectionHelper.SetDeepValue(connectedBaseElement, parameterName, value);
connectedBaseElement.Refresh();
}
public override DynamicUIElement AddListenerFunction(UnityAction action)
{
dropdown.onValueChanged.AddListener(_ => action());
dropdownComponent.onValueChanged.AddListener(_ => action());
return this;
}
}